Browse Source

vlc_spu: make spu_private_t private

pull/176/head
Steve Lhomme 2 years ago
parent
commit
0598bf165d
  1. 3
      include/vlc_spu.h
  2. 106
      src/video_output/vout_subpictures.c

3
include/vlc_spu.h

@ -41,7 +41,6 @@ struct vout_display_place_t;
* \file * \file
*/ */
typedef struct spu_private_t spu_private_t;
struct vlc_render_subpicture; struct vlc_render_subpicture;
/** /**
@ -50,8 +49,6 @@ struct vlc_render_subpicture;
struct spu_t struct spu_t
{ {
struct vlc_object_t obj; struct vlc_object_t obj;
spu_private_t *p;
}; };
VLC_API spu_t * spu_Create( vlc_object_t *, vout_thread_t * ); VLC_API spu_t * spu_Create( vlc_object_t *, vout_thread_t * );

106
src/video_output/vout_subpictures.c

@ -84,7 +84,11 @@ struct subtitle_position_cache
}; };
typedef struct VLC_VECTOR(struct subtitle_position_cache) subtitles_positions_vector; typedef struct VLC_VECTOR(struct subtitle_position_cache) subtitles_positions_vector;
typedef struct spu_private_t spu_private_t;
struct spu_private_t { struct spu_private_t {
spu_t spu;
vlc_mutex_t lock; /* lock to protect all following fields */ vlc_mutex_t lock; /* lock to protect all following fields */
input_thread_t *input; input_thread_t *input;
@ -246,7 +250,7 @@ static void spu_channel_EarlyRemoveLate(spu_private_t *sys,
static struct spu_channel *spu_GetChannel(spu_t *spu, size_t channel_id, size_t *index) static struct spu_channel *spu_GetChannel(spu_t *spu, size_t channel_id, size_t *index)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
for (size_t i = 0; i < sys->channels.size; ++i) for (size_t i = 0; i < sys->channels.size; ++i)
{ {
@ -262,7 +266,7 @@ static struct spu_channel *spu_GetChannel(spu_t *spu, size_t channel_id, size_t
static ssize_t spu_GetFreeChannelId(spu_t *spu, enum vlc_vout_order *order) static ssize_t spu_GetFreeChannelId(spu_t *spu, enum vlc_vout_order *order)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
if (unlikely(sys->channels.size > SSIZE_MAX)) if (unlikely(sys->channels.size > SSIZE_MAX))
return VOUT_SPU_CHANNEL_INVALID; return VOUT_SPU_CHANNEL_INVALID;
@ -294,10 +298,11 @@ static int spu_get_attachments(filter_t *filter,
int *attachment_count) int *attachment_count)
{ {
spu_t *spu = filter->owner.sys; spu_t *spu = filter->owner.sys;
spu_private_t *sys = container_of(spu, spu_private_t, spu);
if (spu->p->input) if (sys->input)
{ {
int count = input_GetAttachments(spu->p->input, attachment_ptr); int count = input_GetAttachments(sys->input, attachment_ptr);
if (count <= 0) if (count <= 0)
return VLC_EGENERIC; return VLC_EGENERIC;
*attachment_count = count; *attachment_count = count;
@ -404,7 +409,7 @@ static subpicture_region_t *SpuRenderText(spu_t *spu,
unsigned output_height, unsigned output_height,
const vlc_fourcc_t *chroma_list) const vlc_fourcc_t *chroma_list)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
assert(subpicture_region_IsText( region )); assert(subpicture_region_IsText( region ));
if ( region->p_text == NULL ) if ( region->p_text == NULL )
return NULL; return NULL;
@ -829,7 +834,7 @@ spu_SelectSubpictures(spu_t *spu, vlc_tick_t system_now,
vlc_tick_t render_subtitle_date, vlc_tick_t render_subtitle_date,
bool ignore_osd, size_t *subpicture_count) bool ignore_osd, size_t *subpicture_count)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
assert(sys->channels.size >= VOUT_SPU_CHANNEL_OSD_COUNT); assert(sys->channels.size >= VOUT_SPU_CHANNEL_OSD_COUNT);
@ -962,7 +967,7 @@ static struct subpicture_region_rendered *SpuRenderRegion(spu_t *spu,
vlc_tick_t render_date) vlc_tick_t render_date)
{ {
assert(!subpicture_region_IsText( region )); assert(!subpicture_region_IsText( region ));
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
if (scale_size.h == SCALE_UNIT && scale_size.w == SCALE_UNIT) if (scale_size.h == SCALE_UNIT && scale_size.w == SCALE_UNIT)
apply_scale = false; apply_scale = false;
@ -1360,6 +1365,8 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
vlc_tick_t render_subtitle_date, vlc_tick_t render_subtitle_date,
bool external_scale) bool external_scale)
{ {
spu_private_t *sys = container_of(spu, spu_private_t, spu);
/* Count the number of regions and subtitle regions */ /* Count the number of regions and subtitle regions */
size_t subtitle_region_count = 0; size_t subtitle_region_count = 0;
size_t region_count = 0; size_t region_count = 0;
@ -1390,7 +1397,7 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
spu_area_t *subtitle_area; spu_area_t *subtitle_area;
size_t subtitle_area_count = 0; size_t subtitle_area_count = 0;
subtitles_positions_StartUpdate(&spu->p->subs_pos); subtitles_positions_StartUpdate(&sys->subs_pos);
subtitle_area = subtitle_area_buffer; subtitle_area = subtitle_area_buffer;
if (subtitle_region_count > ARRAY_SIZE(subtitle_area_buffer)) if (subtitle_region_count > ARRAY_SIZE(subtitle_area_buffer))
@ -1477,7 +1484,7 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
subpicture_t forced_subpic = *subpic; subpicture_t forced_subpic = *subpic;
struct subtitle_position_cache *cache_pos = struct subtitle_position_cache *cache_pos =
subtitles_positions_FindRegion(&spu->p->subs_pos, subpic, region); subtitles_positions_FindRegion(&sys->subs_pos, subpic, region);
if (cache_pos != NULL) if (cache_pos != NULL)
{ {
region->i_x = cache_pos->x; region->i_x = cache_pos->x;
@ -1515,7 +1522,7 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
area = spu_area_unscaled(area, scale); area = spu_area_unscaled(area, scale);
if (subtitle_area) if (subtitle_area)
subtitle_area[subtitle_area_count++] = area; subtitle_area[subtitle_area_count++] = area;
subtitles_positions_AddRegion(&spu->p->subs_pos, subpic, region, &area); subtitles_positions_AddRegion(&sys->subs_pos, subpic, region, &area);
} }
} }
} }
@ -1524,7 +1531,7 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
if (subtitle_area != subtitle_area_buffer) if (subtitle_area != subtitle_area_buffer)
free(subtitle_area); free(subtitle_area);
subtitles_positions_FinishUpdate(&spu->p->subs_pos); subtitles_positions_FinishUpdate(&sys->subs_pos);
return output; return output;
} }
@ -1538,7 +1545,7 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
*****************************************************************************/ *****************************************************************************/
static void SetHighlights(spu_t *spu, const vlc_spu_highlight_t *hl) static void SetHighlights(spu_t *spu, const vlc_spu_highlight_t *hl)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_assert(&sys->lock); vlc_mutex_assert(&sys->lock);
@ -1756,7 +1763,7 @@ static void spu_PrerenderText(spu_t *spu, subpicture_t *p_subpic,
static void * spu_PrerenderThread(void *priv) static void * spu_PrerenderThread(void *priv)
{ {
spu_t *spu = priv; spu_t *spu = priv;
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_fourcc_t chroma_list[SPU_CHROMALIST_COUNT+1]; vlc_fourcc_t chroma_list[SPU_CHROMALIST_COUNT+1];
vlc_thread_set_name("vlc-spu-prerend"); vlc_thread_set_name("vlc-spu-prerend");
@ -1823,7 +1830,7 @@ static void * spu_PrerenderThread(void *priv)
static void spu_Cleanup(spu_t *spu) static void spu_Cleanup(spu_t *spu)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
if (sys->text) if (sys->text)
vlc_filter_Delete(sys->text); vlc_filter_Delete(sys->text);
@ -1868,7 +1875,7 @@ static void spu_Cleanup(spu_t *spu)
*/ */
void spu_Destroy(spu_t *spu) void spu_Destroy(spu_t *spu)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
/* stop prerendering */ /* stop prerendering */
vlc_mutex_lock(&sys->prerender.lock); vlc_mutex_lock(&sys->prerender.lock);
sys->prerender.live = false; sys->prerender.live = false;
@ -1889,14 +1896,14 @@ void spu_Destroy(spu_t *spu)
*/ */
spu_t *spu_Create(vlc_object_t *object, vout_thread_t *vout) spu_t *spu_Create(vlc_object_t *object, vout_thread_t *vout)
{ {
spu_t *spu = vlc_custom_create(object, spu_private_t *sys = vlc_custom_create(object,
sizeof(spu_t) + sizeof(spu_private_t), sizeof(spu_private_t),
"subpicture"); "subpicture");
if (!spu) if (!sys)
return NULL; return NULL;
/* Initialize spu fields */ /* Initialize spu fields */
spu_private_t *sys = spu->p = (spu_private_t*)&spu[1]; spu_t *spu = &sys->spu;
vlc_vector_init(&sys->channels); vlc_vector_init(&sys->channels);
if (!vlc_vector_reserve(&sys->channels, VOUT_SPU_CHANNEL_OSD_COUNT)) if (!vlc_vector_reserve(&sys->channels, VOUT_SPU_CHANNEL_OSD_COUNT))
@ -1980,19 +1987,20 @@ spu_t *spu_Create(vlc_object_t *object, vout_thread_t *vout)
*/ */
void spu_Attach(spu_t *spu, input_thread_t *input) void spu_Attach(spu_t *spu, input_thread_t *input)
{ {
vlc_mutex_lock(&spu->p->lock); spu_private_t *sys = container_of(spu, spu_private_t, spu);
if (spu->p->input != input) { vlc_mutex_lock(&sys->lock);
if (sys->input != input) {
SetHighlights(spu, NULL); SetHighlights(spu, NULL);
spu->p->input = input; sys->input = input;
vlc_mutex_lock(&spu->p->textlock); vlc_mutex_lock(&sys->textlock);
if (spu->p->text) if (sys->text)
vlc_filter_Delete(spu->p->text); vlc_filter_Delete(sys->text);
spu->p->text = SpuRenderCreateAndLoadText(spu); sys->text = SpuRenderCreateAndLoadText(spu);
vlc_mutex_unlock(&spu->p->textlock); vlc_mutex_unlock(&sys->textlock);
} }
vlc_mutex_unlock(&spu->p->lock); vlc_mutex_unlock(&sys->lock);
} }
/** /**
@ -2000,15 +2008,16 @@ void spu_Attach(spu_t *spu, input_thread_t *input)
*/ */
void spu_Detach(spu_t *spu) void spu_Detach(spu_t *spu)
{ {
vlc_mutex_lock(&spu->p->lock); spu_private_t *sys = container_of(spu, spu_private_t, spu);
spu_PrerenderPause(spu->p); vlc_mutex_lock(&sys->lock);
spu->p->input = NULL; spu_PrerenderPause(sys);
vlc_mutex_unlock(&spu->p->lock); sys->input = NULL;
vlc_mutex_unlock(&sys->lock);
} }
void spu_SetClockDelay(spu_t *spu, size_t channel_id, vlc_tick_t delay) void spu_SetClockDelay(spu_t *spu, size_t channel_id, vlc_tick_t delay)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_lock(&sys->lock); vlc_mutex_lock(&sys->lock);
struct spu_channel *channel = spu_GetChannel(spu, channel_id, NULL); struct spu_channel *channel = spu_GetChannel(spu, channel_id, NULL);
@ -2022,7 +2031,7 @@ void spu_SetClockDelay(spu_t *spu, size_t channel_id, vlc_tick_t delay)
void spu_SetClockRate(spu_t *spu, size_t channel_id, float rate) void spu_SetClockRate(spu_t *spu, size_t channel_id, float rate)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_lock(&sys->lock); vlc_mutex_lock(&sys->lock);
struct spu_channel *channel = spu_GetChannel(spu, channel_id, NULL); struct spu_channel *channel = spu_GetChannel(spu, channel_id, NULL);
@ -2050,7 +2059,7 @@ static int SubFilter( filter_t *p_filter, void *opaque )
*/ */
void spu_PutSubpicture(spu_t *spu, subpicture_t *subpic) void spu_PutSubpicture(spu_t *spu, subpicture_t *subpic)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
/* Update sub-filter chain */ /* Update sub-filter chain */
vlc_mutex_lock(&sys->lock); vlc_mutex_lock(&sys->lock);
@ -2069,7 +2078,7 @@ void spu_PutSubpicture(spu_t *spu, subpicture_t *subpic)
sys->vout); sys->vout);
filter_chain_Clear(sys->filter_chain); filter_chain_Clear(sys->filter_chain);
filter_chain_AppendFromString(spu->p->filter_chain, chain_update); filter_chain_AppendFromString(sys->filter_chain, chain_update);
if (sys->vout) if (sys->vout)
filter_chain_ForEach(sys->filter_chain, filter_chain_ForEach(sys->filter_chain,
SubFilterAddProxyCallbacks, SubFilterAddProxyCallbacks,
@ -2081,7 +2090,7 @@ void spu_PutSubpicture(spu_t *spu, subpicture_t *subpic)
/* "sub-source" was formerly "sub-filter", so now the "sub-filter" /* "sub-source" was formerly "sub-filter", so now the "sub-filter"
configuration may contain sub-filters or sub-sources configurations. configuration may contain sub-filters or sub-sources configurations.
if the filters chain was left empty it may indicate that it's a sub-source configuration */ if the filters chain was left empty it may indicate that it's a sub-source configuration */
is_left_empty = filter_chain_IsEmpty(spu->p->filter_chain); is_left_empty = filter_chain_IsEmpty(sys->filter_chain);
} }
vlc_mutex_unlock(&sys->filter_chain_lock); vlc_mutex_unlock(&sys->filter_chain_lock);
@ -2203,7 +2212,7 @@ vlc_render_subpicture *spu_Render(spu_t *spu,
vlc_tick_t render_subtitle_date, vlc_tick_t render_subtitle_date,
bool ignore_osd) bool ignore_osd)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
const bool external_scale = chroma_list != NULL; const bool external_scale = chroma_list != NULL;
/* Update sub-source chain */ /* Update sub-source chain */
@ -2220,7 +2229,7 @@ vlc_render_subpicture *spu_Render(spu_t *spu,
sys->vout); sys->vout);
filter_chain_Clear(sys->source_chain); filter_chain_Clear(sys->source_chain);
filter_chain_AppendFromString(spu->p->source_chain, chain_update); filter_chain_AppendFromString(sys->source_chain, chain_update);
if (sys->vout) if (sys->vout)
filter_chain_ForEach(sys->source_chain, filter_chain_ForEach(sys->source_chain,
SubSourceAddProxyCallbacks, sys->vout); SubSourceAddProxyCallbacks, sys->vout);
@ -2334,7 +2343,7 @@ vlc_render_subpicture *spu_Render(spu_t *spu,
ssize_t spu_RegisterChannelInternal(spu_t *spu, vlc_clock_t *clock, ssize_t spu_RegisterChannelInternal(spu_t *spu, vlc_clock_t *clock,
enum vlc_vout_order *order) enum vlc_vout_order *order)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_lock(&sys->lock); vlc_mutex_lock(&sys->lock);
@ -2365,7 +2374,7 @@ ssize_t spu_RegisterChannel(spu_t *spu)
void spu_ClearChannel(spu_t *spu, size_t channel_id) void spu_ClearChannel(spu_t *spu, size_t channel_id)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_lock(&sys->lock); vlc_mutex_lock(&sys->lock);
struct spu_channel *channel = spu_GetChannel(spu, channel_id, NULL); struct spu_channel *channel = spu_GetChannel(spu, channel_id, NULL);
spu_channel_Clean(sys, channel); spu_channel_Clean(sys, channel);
@ -2381,7 +2390,7 @@ void spu_ClearChannel(spu_t *spu, size_t channel_id)
void spu_UnregisterChannel(spu_t *spu, size_t channel_id) void spu_UnregisterChannel(spu_t *spu, size_t channel_id)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_lock(&sys->lock); vlc_mutex_lock(&sys->lock);
size_t channel_index = 0; size_t channel_index = 0;
@ -2393,7 +2402,7 @@ void spu_UnregisterChannel(spu_t *spu, size_t channel_id)
void spu_ChangeSources(spu_t *spu, const char *filters) void spu_ChangeSources(spu_t *spu, const char *filters)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_lock(&sys->lock); vlc_mutex_lock(&sys->lock);
@ -2412,7 +2421,7 @@ void spu_ChangeSources(spu_t *spu, const char *filters)
void spu_ChangeFilters(spu_t *spu, const char *filters) void spu_ChangeFilters(spu_t *spu, const char *filters)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_lock(&sys->lock); vlc_mutex_lock(&sys->lock);
@ -2432,7 +2441,7 @@ void spu_ChangeFilters(spu_t *spu, const char *filters)
void spu_ChangeChannelOrderMargin(spu_t *spu, enum vlc_vout_order order, void spu_ChangeChannelOrderMargin(spu_t *spu, enum vlc_vout_order order,
int margin) int margin)
{ {
spu_private_t *sys = spu->p; spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_lock(&sys->lock); vlc_mutex_lock(&sys->lock);
switch (order) switch (order)
@ -2451,7 +2460,8 @@ void spu_ChangeChannelOrderMargin(spu_t *spu, enum vlc_vout_order order,
void spu_SetHighlight(spu_t *spu, const vlc_spu_highlight_t *hl) void spu_SetHighlight(spu_t *spu, const vlc_spu_highlight_t *hl)
{ {
vlc_mutex_lock(&spu->p->lock); spu_private_t *sys = container_of(spu, spu_private_t, spu);
vlc_mutex_lock(&sys->lock);
SetHighlights(spu, hl); SetHighlights(spu, hl);
vlc_mutex_unlock(&spu->p->lock); vlc_mutex_unlock(&sys->lock);
} }

Loading…
Cancel
Save