<html><head></head><body>Hi,<br><br>Identification with a tuple of a (reference-counted) pointer and an ID seems like the worse of both worlds. It's not serial, but it's not a single value and its uniqueness depends on the demuxer.<br><br>Why can't we identify an ES by its ID pointer, which already exists (though it might be missing a reference count)??<br><br><div class="gmail_quote">Le 18 février 2020 18:11:18 GMT+02:00, Thomas Guillem <thomas@gllm.fr> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">A specified program (group > 0) is identified by its group id and by its<br>context pointer. The default program (group = 0) can be used by more than one<br>contexts.<br><br>An ES track is now identified by its i_id and by its context pointer. In case<br>of automatic track ids, the id counter will be handled by each contexts (or<br>input source). This mean that the id counter starts at 0 for each new source.<br><br>A slave specifying its group won't be able to be played alongside the master<br>source by default (except if we play more than one programs at a time).<hr> src/input/es_out.c | 106 ++++++++++++++++++++++++++++++++-------------<br> 1 file changed, 75 insertions(+), 31 deletions(-)<br><br>diff --git a/src/input/es_out.c b/src/input/es_out.c<br>index 1c98d85add4..4ae27b63734 100644<br>--- a/src/input/es_out.c<br>+++ b/src/input/es_out.c<br>@@ -61,6 +61,9 @@<br> *****************************************************************************/<br> typedef struct<br> {<br>+ /* Program context */<br>+ es_out_ctx_t *ctx;<br>+<br> /* Program ID */<br> int i_id;<br> <br>@@ -98,6 +101,10 @@ struct es_out_id_t<br> /* weak reference, used by input_decoder_callbacks and vlc_clock_cbs */<br> es_out_t *out;<br> <br>+ /* Context used to create this ES. Equals to p_pgrm->ctx when not using a<br>+ * default program id. */<br>+ es_out_ctx_t *ctx;<br>+<br> /* ES ID */<br> es_out_pgrm_t *p_pgrm;<br> <br>@@ -165,6 +172,9 @@ typedef struct<br> {<br> input_thread_t *p_input;<br> <br>+ /* Main source context */<br>+ es_out_ctx_t *main_ctx;<br>+<br> /* */<br> vlc_mutex_t lock;<br> <br>@@ -481,6 +491,13 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, float rate )<br> <br> p_sys->out.cbs = &es_out_cbs;<br> <br>+ p_sys->main_ctx = es_out_ctx_New(NULL);<br>+ if( !p_sys->main_ctx )<br>+ {<br>+ free( p_sys );<br>+ return NULL;<br>+ }<br>+<br> vlc_mutex_init( &p_sys->lock );<br> p_sys->p_input = p_input;<br> <br>@@ -578,6 +595,7 @@ static void EsRelease(es_out_id_t *es)<br> free(es->psz_language);<br> free(es->psz_language_code);<br> es_format_Clean(&es->fmt);<br>+ es_out_ctx_Release(es->ctx);<br> free(es);<br> }<br> }<br>@@ -600,6 +618,8 @@ static void EsOutDelete( es_out_t *out )<br> <br> vlc_mutex_destroy( &p_sys->lock );<br> <br>+ es_out_ctx_Release( p_sys->main_ctx );<br>+<br> free( p_sys );<br> }<br> <br>@@ -609,6 +629,7 @@ static void ProgramDelete( es_out_pgrm_t *p_pgrm )<br> vlc_clock_main_Delete( p_pgrm->p_main_clock );<br> if( p_pgrm->p_meta )<br> vlc_meta_Delete( p_pgrm->p_meta );<br>+ es_out_ctx_Release( p_pgrm->ctx );<br> <br> free( p_pgrm );<br> }<br>@@ -1245,10 +1266,11 @@ static void EsOutSendEsEvent(es_out_t *out, es_out_id_t *es, int action)<br> });<br> }<br> <br>-static bool EsOutIsProgramVisible( es_out_t *out, int i_group )<br>+static bool EsOutIsProgramVisible( es_out_t *out, es_out_ctx_t *ctx, int i_group )<br> {<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br>- return p_sys->i_group_id == 0 || p_sys->i_group_id == i_group;<br>+ return p_sys->i_group_id == 0<br>+ || (p_sys->i_group_id == i_group && p_sys->p_pgrm->ctx == ctx);<br> }<br> <br> /* EsOutProgramSelect:<br>@@ -1333,7 +1355,7 @@ static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )<br> /* EsOutAddProgram:<br> * Add a program<br> */<br>-static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )<br>+static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, es_out_ctx_t *ctx, int i_group )<br> {<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br> input_thread_t *p_input = p_sys->p_input;<br>@@ -1343,6 +1365,7 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )<br> return NULL;<br> <br> /* Init */<br>+ p_pgrm->ctx = es_out_ctx_Hold( ctx );<br> p_pgrm->i_id = i_group;<br> p_pgrm->i_es = 0;<br> p_pgrm->b_selected = false;<br>@@ -1376,7 +1399,7 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )<br> vlc_list_append(&p_pgrm->node, &p_sys->programs);<br> <br> /* Update "program" variable */<br>- if( EsOutIsProgramVisible( out, i_group ) )<br>+ if( EsOutIsProgramVisible( out, ctx, i_group ) )<br> input_SendEventProgramAdd( p_input, i_group, NULL );<br> <br> if( i_group == p_sys->i_group_id || ( !p_sys->p_pgrm && p_sys->i_group_id == 0 ) )<br>@@ -1387,34 +1410,37 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )<br> <br> /* EsOutProgramSearch<br> */<br>-static es_out_pgrm_t *EsOutProgramSearch( es_out_t *p_out, int i_group )<br>+static es_out_pgrm_t *EsOutProgramSearch( es_out_t *p_out, es_out_ctx_t *ctx,<br>+ int i_group )<br> {<br> es_out_sys_t *p_sys = container_of(p_out, es_out_sys_t, out);<br> es_out_pgrm_t *pgrm;<br> <br> vlc_list_foreach(pgrm, &p_sys->programs, node)<br>- if (pgrm->i_id == i_group)<br>+ if (pgrm->i_id == i_group && (pgrm->ctx == ctx || i_group == 0))<br> return pgrm;<br>+<br> return NULL;<br> }<br> <br> /* EsOutProgramInsert<br> */<br>-static es_out_pgrm_t *EsOutProgramInsert( es_out_t *p_out, int i_group )<br>+static es_out_pgrm_t *EsOutProgramInsert( es_out_t *p_out, es_out_ctx_t *ctx,<br>+ int i_group )<br> {<br>- es_out_pgrm_t *pgrm = EsOutProgramSearch( p_out, i_group );<br>- return pgrm ? pgrm : EsOutProgramAdd( p_out, i_group );<br>+ es_out_pgrm_t *pgrm = EsOutProgramSearch( p_out, ctx, i_group );<br>+ return pgrm ? pgrm : EsOutProgramAdd( p_out, ctx, i_group );<br> }<br> <br> /* EsOutDelProgram:<br> * Delete a program<br> */<br>-static int EsOutProgramDel( es_out_t *out, int i_group )<br>+static int EsOutProgramDel( es_out_t *out, es_out_ctx_t *ctx, int i_group )<br> {<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br> input_thread_t *p_input = p_sys->p_input;<br> <br>- es_out_pgrm_t *p_pgrm = EsOutProgramSearch( out, i_group );<br>+ es_out_pgrm_t *p_pgrm = EsOutProgramSearch( out, ctx, i_group );<br> if( p_pgrm == NULL )<br> return VLC_EGENERIC;<br> <br>@@ -1483,7 +1509,8 @@ static char *EsInfoCategoryName( es_out_id_t* es )<br> return psz_category;<br> }<br> <br>-static void EsOutProgramMeta( es_out_t *out, int i_group, const vlc_meta_t *p_meta )<br>+static void EsOutProgramMeta( es_out_t *out, es_out_ctx_t *ctx,<br>+ int i_group, const vlc_meta_t *p_meta )<br> {<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br> es_out_pgrm_t *p_pgrm;<br>@@ -1511,9 +1538,9 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, const vlc_meta_t *p_me<br> }<br> <br> /* Find program */<br>- if( !EsOutIsProgramVisible( out, i_group ) )<br>+ if( !EsOutIsProgramVisible( out, ctx, i_group ) )<br> return;<br>- p_pgrm = EsOutProgramInsert( out, i_group );<br>+ p_pgrm = EsOutProgramInsert( out, ctx, i_group );<br> if( !p_pgrm )<br> return;<br> <br>@@ -1612,7 +1639,8 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, const vlc_meta_t *p_me<br> input_SendEventMetaInfo( p_input );<br> }<br> <br>-static void EsOutProgramEpgEvent( es_out_t *out, int i_group, const vlc_epg_event_t *p_event )<br>+static void EsOutProgramEpgEvent( es_out_t *out, es_out_ctx_t *ctx,<br>+ int i_group, const vlc_epg_event_t *p_event )<br> {<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br> input_thread_t *p_input = p_sys->p_input;<br>@@ -1620,16 +1648,17 @@ static void EsOutProgramEpgEvent( es_out_t *out, int i_group, const vlc_epg_even<br> es_out_pgrm_t *p_pgrm;<br> <br> /* Find program */<br>- if( !EsOutIsProgramVisible( out, i_group ) )<br>+ if( !EsOutIsProgramVisible( out, ctx, i_group ) )<br> return;<br>- p_pgrm = EsOutProgramInsert( out, i_group );<br>+ p_pgrm = EsOutProgramInsert( out, ctx, i_group );<br> if( !p_pgrm )<br> return;<br> <br> input_item_SetEpgEvent( p_item, p_event );<br> }<br> <br>-static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg )<br>+static void EsOutProgramEpg( es_out_t *out, es_out_ctx_t *ctx,<br>+ int i_group, const vlc_epg_t *p_epg )<br> {<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br> input_thread_t *p_input = p_sys->p_input;<br>@@ -1638,9 +1667,9 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg<br> char *psz_cat;<br> <br> /* Find program */<br>- if( !EsOutIsProgramVisible( out, i_group ) )<br>+ if( !EsOutIsProgramVisible( out, ctx, i_group ) )<br> return;<br>- p_pgrm = EsOutProgramInsert( out, i_group );<br>+ p_pgrm = EsOutProgramInsert( out, ctx, i_group );<br> if( !p_pgrm )<br> return;<br> <br>@@ -1874,7 +1903,8 @@ static void EsOutFillEsFmt(es_out_t *out, es_format_t *fmt)<br> }<br> }<br> <br>-static es_out_id_t *EsOutAddLocked( es_out_t *out, const es_format_t *fmt,<br>+static es_out_id_t *EsOutAddLocked( es_out_t *out, es_out_ctx_t *ctx,<br>+ const es_format_t *fmt,<br> es_out_id_t *p_master )<br> {<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br>@@ -1893,26 +1923,32 @@ static es_out_id_t *EsOutAddLocked( es_out_t *out, const es_format_t *fmt,<br> return NULL;<br> <br> es->out = out;<br>+ es->ctx = es_out_ctx_Hold( ctx );<br> <br> if( es_format_Copy( &es->fmt, fmt ) != VLC_SUCCESS )<br> {<br> free( es );<br> return NULL;<br> }<br>+<br> if( es->fmt.i_id < 0 )<br>- es->fmt.i_id = p_sys->i_id;<br>+ es->fmt.i_id = es_out_ctx_GetNewEsID( ctx );<br> if( !es->fmt.i_original_fourcc )<br> es->fmt.i_original_fourcc = es->fmt.i_codec;<br> <br> /* Search the program */<br>- p_pgrm = EsOutProgramInsert( out, fmt->i_group );<br>+ p_pgrm = EsOutProgramInsert( out, ctx, fmt->i_group );<br> if( !p_pgrm )<br> {<br> es_format_Clean( &es->fmt );<br>+ es_out_ctx_Release( es->ctx );<br> free( es );<br> return NULL;<br> }<br> <br>+ /* The group 0 is the default one and can be used by different contexts */<br>+ assert( fmt->i_group == 0 || p_pgrm->ctx == es->ctx );<br>+<br> /* Get the number of ES already added in order to get the position of the es */<br> es->i_pos = 0;<br> es_out_id_t *it;<br>@@ -1989,8 +2025,12 @@ static es_out_id_t *EsOutAdd( es_out_t *out, es_out_ctx_t *ctx, const es_format_<br> {<br> VLC_UNUSED(ctx);<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br>+<br>+ if( !ctx )<br>+ ctx = p_sys->main_ctx;<br>+<br> vlc_mutex_lock( &p_sys->lock );<br>- es_out_id_t *es = EsOutAddLocked( out, fmt, NULL );<br>+ es_out_id_t *es = EsOutAddLocked( out, ctx, fmt, NULL );<br> vlc_mutex_unlock( &p_sys->lock );<br> return es;<br> }<br>@@ -2481,7 +2521,7 @@ static void EsOutCreateCCChannels( es_out_t *out, vlc_fourcc_t codec, uint64_t i<br> fmt.psz_description = NULL;<br> <br> es_out_id_t **pp_es = &parent->cc.pp_es[i];<br>- *pp_es = EsOutAddLocked( out, &fmt, parent );<br>+ *pp_es = EsOutAddLocked( out, parent->p_pgrm->ctx, &fmt, parent );<br> es_format_Clean( &fmt );<br> <br> /* */<br>@@ -2750,6 +2790,7 @@ static int EsOutVaControlLocked( es_out_t *out, es_out_ctx_t *ctx,<br> int i_query, va_list args )<br> {<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br>+ assert( ctx ); /* == p_sys->main_ctx if the given ctx is NULL */<br> <br> switch( i_query )<br> {<br>@@ -3024,12 +3065,12 @@ static int EsOutVaControlLocked( es_out_t *out, es_out_ctx_t *ctx,<br> {<br> p_pgrm = p_sys->p_pgrm;<br> if( !p_pgrm )<br>- p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */<br>+ p_pgrm = EsOutProgramAdd( out, ctx, i_group ); /* Create it */<br> }<br> else<br> {<br> i_group = va_arg( args, int );<br>- p_pgrm = EsOutProgramInsert( out, i_group );<br>+ p_pgrm = EsOutProgramInsert( out, ctx, i_group );<br> }<br> if( !p_pgrm )<br> return VLC_EGENERIC;<br>@@ -3202,7 +3243,7 @@ static int EsOutVaControlLocked( es_out_t *out, es_out_ctx_t *ctx,<br> int i_group = va_arg( args, int );<br> const vlc_meta_t *p_meta = va_arg( args, const vlc_meta_t * );<br> <br>- EsOutProgramMeta( out, i_group, p_meta );<br>+ EsOutProgramMeta( out, ctx, i_group, p_meta );<br> return VLC_SUCCESS;<br> }<br> case ES_OUT_SET_GROUP_EPG:<br>@@ -3210,7 +3251,7 @@ static int EsOutVaControlLocked( es_out_t *out, es_out_ctx_t *ctx,<br> int i_group = va_arg( args, int );<br> const vlc_epg_t *p_epg = va_arg( args, const vlc_epg_t * );<br> <br>- EsOutProgramEpg( out, i_group, p_epg );<br>+ EsOutProgramEpg( out, ctx, i_group, p_epg );<br> return VLC_SUCCESS;<br> }<br> case ES_OUT_SET_GROUP_EPG_EVENT:<br>@@ -3218,7 +3259,7 @@ static int EsOutVaControlLocked( es_out_t *out, es_out_ctx_t *ctx,<br> int i_group = va_arg( args, int );<br> const vlc_epg_event_t *p_evt = va_arg( args, const vlc_epg_event_t * );<br> <br>- EsOutProgramEpgEvent( out, i_group, p_evt );<br>+ EsOutProgramEpgEvent( out, ctx, i_group, p_evt );<br> return VLC_SUCCESS;<br> }<br> case ES_OUT_SET_EPG_TIME:<br>@@ -3233,7 +3274,7 @@ static int EsOutVaControlLocked( es_out_t *out, es_out_ctx_t *ctx,<br> {<br> int i_group = va_arg( args, int );<br> <br>- return EsOutProgramDel( out, i_group );<br>+ return EsOutProgramDel( out, ctx, i_group );<br> }<br> <br> case ES_OUT_SET_META:<br>@@ -3559,6 +3600,9 @@ static int EsOutControl( es_out_t *out, es_out_ctx_t *ctx,<br> es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);<br> int i_ret;<br> <br>+ if( !ctx )<br>+ ctx = p_sys->main_ctx;<br>+<br> vlc_mutex_lock( &p_sys->lock );<br> i_ret = EsOutVaControlLocked( out, ctx, i_query, args );<br> vlc_mutex_unlock( &p_sys->lock );</pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>