[vlc-devel] [PATCH 05/14] es_out: allow multi selection from "cat-track-id"

Thomas Guillem thomas at gllm.fr
Fri Feb 21 16:59:36 CET 2020


Example: --sub-track-id "spu/3,spu/4"

A track-id can't contain the ',' character.
---
 src/input/es_out.c | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/src/input/es_out.c b/src/input/es_out.c
index 3f17098ad2c..b645dc21e7a 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -162,7 +162,7 @@ typedef struct
 
     /* Parameters used for es selection */
     bool        b_autoselect; /* if we want to select an es when no user prefs */
-    char        *str_id;       /* String id generated by EsOutCreateStrId() */
+    char        *str_ids; /* List of string id generated by EsOutCreateStrId() (delimited by ',') */
     int         i_demux_id; /* same as previous, demuxer set default value */
     int         i_channel;  /* es number in creation order */
     char        **ppsz_language;
@@ -439,7 +439,7 @@ static es_out_es_props_t * GetPropsByCat( es_out_sys_t *p_sys, int i_cat )
 
 static void EsOutPropsCleanup( es_out_es_props_t *p_props )
 {
-    free( p_props->str_id );
+    free( p_props->str_ids );
     if( p_props->ppsz_language )
     {
         for( int i = 0; p_props->ppsz_language[i]; i++ )
@@ -460,7 +460,7 @@ static void EsOutPropsInit( es_out_es_props_t *p_props,
     p_props->e_policy = e_default_policy;
     p_props->i_count = 0;
     p_props->b_autoselect = autoselect;
-    p_props->str_id = (psz_trackidvar) ? var_GetNonEmptyString( p_input, psz_trackidvar ): -1;
+    p_props->str_ids = (psz_trackidvar) ? var_GetNonEmptyString( p_input, psz_trackidvar ) : NULL;
     p_props->i_channel = (psz_trackvar) ? var_GetInteger( p_input, psz_trackvar ): -1;
     p_props->i_demux_id = -1;
     p_props->p_main_es = NULL;
@@ -1965,6 +1965,9 @@ static char *EsOutCreateStrId( es_out_id_t *es, bool stable, const char *id,
     }
     else if ( id )
     {
+        /* ',' is used as a delimiter */
+        assert( strchr( id, ',' ) == NULL);
+
         vlc_memstream_puts( &ms, id );
         vlc_memstream_putc( &ms, '/' );
     }
@@ -2449,8 +2452,17 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
         return;
     }
 
+    enum es_out_policy_e policy = p_esprops->e_policy;
+    if( policy == ES_OUT_ES_POLICY_AUTO )
+    {
+        if( p_esprops->str_ids && strchr( p_esprops->str_ids, ',' ) != NULL )
+            policy = ES_OUT_ES_POLICY_SIMULTANEOUS;
+        else
+            policy = ES_OUT_ES_POLICY_EXCLUSIVE;
+    }
+
     bool b_auto_unselect = p_esprops && p_sys->i_mode == ES_OUT_MODE_AUTO &&
-                           p_esprops->e_policy == ES_OUT_ES_POLICY_EXCLUSIVE &&
+                           policy == ES_OUT_ES_POLICY_EXCLUSIVE &&
                            p_esprops->p_main_es && p_esprops->p_main_es != es;
 
     if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
@@ -2492,10 +2504,20 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
             return;
 
         /* user designated by ID ES have higher prio than everything */
-        if ( p_esprops->str_id )
+        if ( p_esprops->str_ids )
         {
-            if( strcmp( p_esprops->str_id, es->id.str_id ) == 0 )
-                wanted_es = 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 )
-- 
2.20.1



More information about the vlc-devel mailing list