Commit 4afa2867 authored by Thomas Guillem's avatar Thomas Guillem
Browse files

decoder: merge format and desc functions

In order to merge the usage of the same lock and avoid locking it twice
in a row. This new status struct be used to get the status of sub ES
tracks created by decoder modules.
parent 1afefbc0
......@@ -2351,14 +2351,6 @@ void vlc_input_decoder_Flush( vlc_input_decoder_t *p_owner )
}
}
void vlc_input_decoder_GetCcDesc( vlc_input_decoder_t *p_owner,
decoder_cc_desc_t *p_desc )
{
vlc_mutex_lock( &p_owner->lock );
*p_desc = p_owner->cc.desc;
vlc_mutex_unlock( &p_owner->lock );
}
static bool vlc_input_decoder_HasCCChanFlag( vlc_input_decoder_t *p_owner,
vlc_fourcc_t codec, int i_channel )
{
......@@ -2541,37 +2533,36 @@ void vlc_input_decoder_FrameNext( vlc_input_decoder_t *p_owner,
vlc_mutex_unlock( &p_owner->lock );
}
bool vlc_input_decoder_HasFormatChanged( vlc_input_decoder_t *p_owner,
es_format_t *p_fmt, vlc_meta_t **pp_meta )
void vlc_input_decoder_GetStatus( vlc_input_decoder_t *p_owner,
struct vlc_input_decoder_status *status )
{
if( !atomic_exchange_explicit( &p_owner->b_fmt_description, false,
memory_order_acquire ) )
return false;
vlc_mutex_lock( &p_owner->lock );
if( p_owner->fmt.i_cat == UNKNOWN_ES )
status->format.changed =
atomic_exchange_explicit( &p_owner->b_fmt_description, false,
memory_order_acquire );
if( status->format.changed && p_owner->fmt.i_cat == UNKNOWN_ES )
{
/* The format changed but the output creation failed */
vlc_mutex_unlock( &p_owner->lock );
return false;
status->format.changed = false;
}
if( p_fmt != NULL )
es_format_Copy( p_fmt, &p_owner->fmt );
if( pp_meta )
if( status->format.changed )
{
*pp_meta = NULL;
es_format_Copy( &status->format.fmt, &p_owner->fmt );
status->format.meta = NULL;
if( p_owner->p_description )
{
*pp_meta = vlc_meta_New();
if( *pp_meta )
vlc_meta_Merge( *pp_meta, p_owner->p_description );
status->format.meta = vlc_meta_New();
if( status->format.meta )
vlc_meta_Merge( status->format.meta, p_owner->p_description );
}
}
status->cc.desc = p_owner->cc.desc;
vlc_mutex_unlock( &p_owner->lock );
return true;
}
size_t vlc_input_decoder_GetFifoSize( vlc_input_decoder_t *p_owner )
......
......@@ -119,15 +119,30 @@ void vlc_input_decoder_GetCcDesc( vlc_input_decoder_t *, decoder_cc_desc_t * );
*/
void vlc_input_decoder_FrameNext( vlc_input_decoder_t *p_dec, vlc_tick_t *pi_duration );
struct vlc_input_decoder_status
{
struct {
/* True if the ES format or meta data have changed since the last call.
* */
bool changed;
/* If changed is true, a copy of the current es_format_t, MUST be freed
* with es_format_Clean() */
es_format_t fmt;
/* If changed is true, a copy of the current description, can be NULL,
* MUST be freed with vlc_meta_Delete.() */
vlc_meta_t *meta;
} format;
struct {
decoder_cc_desc_t desc;
} cc;
};
/**
* This function will return true if the ES format or meta data have changed since
* the last call. In which case, it will do a copy of the current es_format_t if p_fmt
* is not NULL and will do a copy of the current description if pp_meta is non NULL.
* The es_format_t MUST be freed by es_format_Clean and *pp_meta MUST be freed by
* vlc_meta_Delete.
* Otherwise it will return false and will not initialize p_fmt and *pp_meta.
* Get the last status of the decoder.
*/
bool vlc_input_decoder_HasFormatChanged( vlc_input_decoder_t *p_dec, es_format_t *p_fmt, vlc_meta_t **pp_meta );
void vlc_input_decoder_GetStatus( vlc_input_decoder_t *p_dec,
struct vlc_input_decoder_status *status );
/**
* This function returns the current size in bytes of the decoder fifo
......
......@@ -2921,28 +2921,26 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
vlc_input_decoder_Decode( es->p_dec, p_block,
input_priv(p_input)->b_out_pace_control );
es_format_t fmt_dsc;
vlc_meta_t *p_meta_dsc;
if( vlc_input_decoder_HasFormatChanged( es->p_dec, &fmt_dsc, &p_meta_dsc ) )
struct vlc_input_decoder_status status;
vlc_input_decoder_GetStatus( es->p_dec, &status );
if( status.format.changed )
{
if (EsOutEsUpdateFmt( out, es, &fmt_dsc) == VLC_SUCCESS)
if (EsOutEsUpdateFmt( out, es, &status.format.fmt ) == VLC_SUCCESS)
EsOutSendEsEvent(out, es, VLC_INPUT_ES_UPDATED, false);
EsOutUpdateInfo(out, es, p_meta_dsc);
EsOutUpdateInfo(out, es, status.format.meta);
es_format_Clean( &fmt_dsc );
if( p_meta_dsc )
vlc_meta_Delete( p_meta_dsc );
es_format_Clean( &status.format.fmt );
if( status.format.meta )
vlc_meta_Delete( status.format.meta );
}
/* Check CC status */
decoder_cc_desc_t desc;
vlc_input_decoder_GetCcDesc( es->p_dec, &desc );
if( p_sys->cc_decoder == 708 )
EsOutCreateCCChannels( out, VLC_CODEC_CEA708, desc.i_708_channels,
EsOutCreateCCChannels( out, VLC_CODEC_CEA708, status.cc.desc.i_708_channels,
_("DTVCC Closed captions %u"), es );
EsOutCreateCCChannels( out, VLC_CODEC_CEA608, desc.i_608_channels,
EsOutCreateCCChannels( out, VLC_CODEC_CEA608, status.cc.desc.i_608_channels,
_("Closed captions %u"), es );
vlc_mutex_unlock( &p_sys->lock );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment