[vlc-devel] [PATCH 1/3] input: es_out: split es selection matching functions
Francois Cartegnie
fcvlcdev at free.fr
Mon Jun 15 15:15:41 CEST 2020
---
src/input/es_out.c | 92 +++++++++++++++++++++++++++-------------------
1 file changed, 55 insertions(+), 37 deletions(-)
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 97c8774eb5..c1c9615195 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2400,6 +2400,53 @@ static void EsOutUnselectEs( es_out_t *out, es_out_id_t *es, bool b_update )
EsOutSendEsEvent(out, es, VLC_INPUT_ES_UNSELECTED, false);
}
+static bool EsOutSelectMatchPrioritized( const es_out_es_props_t *p_esprops,
+ const es_out_id_t *es )
+{
+ /* If demux has specified a default track */
+ if( p_esprops->i_demux_id >= 0 && es->fmt.i_id == p_esprops->i_demux_id )
+ {
+ return true;
+ }
+ /* Otherwise, fallback by priority */
+ else if( p_esprops->p_main_es == NULL ||
+ es->fmt.i_priority > p_esprops->p_main_es->fmt.i_priority )
+ {
+ return true;
+ }
+
+ return false;
+}
+
+static bool EsOutSelectMatchExplicitParams( const es_out_es_props_t *p_esprops,
+ const es_out_id_t *es )
+{
+ /* user designated by ID ES have higher prio than everything */
+ if( p_esprops->str_ids )
+ {
+ char *saveptr, *str_ids = strdup( p_esprops->str_ids );
+ if( str_ids )
+ {
+ for( const char *str_id = strtok_r( str_ids, ",", &saveptr );
+ str_id != NULL ;
+ str_id = strtok_r( NULL, ",", &saveptr ) )
+ {
+ if( strcmp( str_id, es->id.str_id ) == 0 )
+ return true;
+ }
+ }
+ free( str_ids );
+ }
+
+ /* then channel index */
+ if( p_esprops->i_channel >= 0 && es->i_channel == p_esprops->i_channel )
+ {
+ return true;
+ }
+
+ return false;
+}
+
/**
* Select an ES given the current mode
* XXX: you need to take a the lock before (stream.stream_lock)
@@ -2471,30 +2518,13 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
{
const es_out_id_t *wanted_es = NULL;
- if( es->p_pgrm != p_sys->p_pgrm || !p_esprops )
+ if( es->p_pgrm != p_sys->p_pgrm )
return;
- /* user designated by ID ES have higher prio than everything */
- if ( p_esprops->str_ids )
+ if( wanted_es != es &&
+ EsOutSelectMatchExplicitParams( p_esprops, es ) )
{
- char *saveptr, *str_ids = strdup( p_esprops->str_ids );
- if( str_ids )
- {
- for( const char *str_id = strtok_r( str_ids, ",", &saveptr );
- str_id != NULL && wanted_es != es;
- str_id = strtok_r( NULL, ",", &saveptr ) )
- {
- if( strcmp( str_id, es->id.str_id ) == 0 )
- wanted_es = es;
- }
- }
- free( str_ids );
- }
- /* then per pos */
- else if( p_esprops->i_channel >= 0 )
- {
- if( p_esprops->i_channel == es->i_channel )
- wanted_es = es;
+ wanted_es = es;
}
else if( p_esprops->ppsz_language )
{
@@ -2524,18 +2554,11 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
/* Select if asked by demuxer */
if( current_es_idx < 0 ) /* No es is currently selected by lang pref */
{
- /* If demux has specified a track */
- if( p_esprops->i_demux_id >= 0 && es->fmt.i_id == p_esprops->i_demux_id )
+ if( b_auto_selected &&
+ EsOutSelectMatchPrioritized( p_esprops, es ) )
{
wanted_es = es;
}
- /* Otherwise, fallback by priority */
- else if( p_esprops->p_main_es == NULL ||
- es->fmt.i_priority > p_esprops->p_main_es->fmt.i_priority )
- {
- if( b_auto_selected )
- wanted_es = es;
- }
}
}
}
@@ -2543,16 +2566,11 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
}
/* If there is no user preference, select the default subtitle
* or adapt by ES priority */
- else if( p_esprops->i_demux_id >= 0 && es->fmt.i_id == p_esprops->i_demux_id )
+ else if( b_auto_selected &&
+ EsOutSelectMatchPrioritized( p_esprops, es ) )
{
wanted_es = es;
}
- else if( p_esprops->p_main_es == NULL ||
- es->fmt.i_priority > p_esprops->p_main_es->fmt.i_priority )
- {
- if( b_auto_selected )
- wanted_es = es;
- }
if( wanted_es == es && !EsIsSelected( es ) )
{
--
2.25.4
More information about the vlc-devel
mailing list