[vlc-commits] [Git][videolan/vlc][master] 4 commits: es_out: refactor es_out_id_t list matching

Thomas Guillem (@tguillem) gitlab at videolan.org
Tue Aug 3 11:27:47 UTC 2021



Thomas Guillem pushed to branch master at VideoLAN / VLC


Commits:
55a4c763 by Thomas Guillem at 2021-08-03T10:48:40+00:00
es_out: refactor es_out_id_t list matching

- - - - -
45891bc0 by Thomas Guillem at 2021-08-03T10:48:40+00:00
es_out: fix ES unselect order from EsOutSelectList

1/ Unselect all ESes not matching the list
2/ Select all ESes matching the list

This avoids having more than one ESes selected when avoidable. Having
more than one ESes selected is supported for VIDEO_ES and SPU_ES but not
for AUDIO_ES (EXCLUSIVE policy).

This commit fixes the EXCLUSIVE policy that was not respected by
EsOutSelectList().

- - - - -
24caf912 by Thomas Guillem at 2021-08-03T10:48:40+00:00
es_out: refactor str_ids matching code

- - - - -
c8fa3af6 by Thomas Guillem at 2021-08-03T10:48:40+00:00
es_out: fix ES unselect order from EsOutSelectListFromProps

1/ Unselect all ESes not matching the list
2/ Select all ESes matching the list

This avoids having more than one ESes selected when avoidable. Having
more than one ESes selected is supported for VIDEO_ES and SPU_ES but not
for AUDIO_ES (EXCLUSIVE policy).

This commit fixes the EXCLUSIVE policy that was not respected by
EsOutSelectListFromProps().

- - - - -


1 changed file:

- src/input/es_out.c


Changes:

=====================================
src/input/es_out.c
=====================================
@@ -2570,27 +2570,37 @@ static bool EsOutSelectHasExplicitParams( const es_out_es_props_t *p_esprops )
     return p_esprops->str_ids || p_esprops->i_channel >= 0;
 }
 
+static bool EsOutIdMatchStrIds( const es_out_id_t *es, char *str_ids )
+{
+    char *saveptr;
+
+    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;
+    }
+
+    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 );
+        /* EsOutIdMatchStrIds will modify str_ids */
+        char *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 )
-                {
-                    free( str_ids );
-                    return true;
-                }
-            }
+            bool matching = EsOutIdMatchStrIds( es, str_ids );
+            free( str_ids );
+
+            if( matching )
+                return true;
         }
-        free( str_ids );
     }
 
     /* then channel index */
@@ -2743,6 +2753,7 @@ static void EsOutSelectListFromProps( es_out_t *out, enum es_format_category_e c
 {
     es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
     es_out_es_props_t *esprops = GetPropsByCat( p_sys, cat );
+    es_out_id_t *other;
     if( !esprops || !esprops->str_ids )
         return;
 
@@ -2750,48 +2761,51 @@ static void EsOutSelectListFromProps( es_out_t *out, enum es_format_category_e c
     if( !buffer )
         return;
 
-    bool unselect_others = false;
-    es_out_id_t *other;
+    /* Unselect all ES that are not on the str_ids list.
+     * This step need to be done before the selection step, specially
+     * for the EXCLUSIVE ES policy. Indeed, having multiple ES selected is not
+     * supported for this policy. */
+    foreach_es_then_es_slaves(other)
+    {
+        if( other->fmt.i_cat != cat )
+            continue;
+
+        /* EsOutIdMatchStrIds will modify str_ids */
+        strcpy( buffer, esprops->str_ids );
+        if( !EsOutIdMatchStrIds( other, buffer ) && EsIsSelected( other ) ) 
+            EsOutUnselectEs( out, other, other->p_pgrm == p_sys->p_pgrm );
+    }
+
+    /* Now, select all ES from the str_ids list */
     foreach_es_then_es_slaves( other )
     {
         if( other->fmt.i_cat != cat )
             continue;
 
-        bool select = false;
-        if( !unselect_others )
+        /* EsOutIdMatchStrIds will modify str_ids */
+        strcpy( buffer, esprops->str_ids );
+        if( EsOutIdMatchStrIds( other, buffer ) && !EsIsSelected( other ) )
         {
-            /* strtok_r will modify str_ids */
-            strcpy( buffer, esprops->str_ids );
-            char *saveptr;
-            for( const char *str_id = strtok_r( buffer, ",", &saveptr );
-                 str_id != NULL;
-                 str_id = strtok_r( NULL, ",", &saveptr ) )
-            {
-                if( strcmp( other->id.str_id, str_id ) == 0 )
-                {
-                    select = true;
-                    break;
-                }
-            }
-        }
+            EsOutSelectEs( out, other, true );
 
-        if( !select )
-        {
-            if( EsIsSelected( other ) )
-                EsOutUnselectEs( out, other, other->p_pgrm == p_sys->p_pgrm );
-        }
-        else
-        {
-            if( !EsIsSelected( other ) )
-                EsOutSelectEs( out, other, true );
             if( esprops->e_policy == ES_OUT_ES_POLICY_EXCLUSIVE )
-                unselect_others = true;
+                break;
         }
     }
 
     free( buffer );
 }
 
+static bool EsOutIdMatchEsList( const es_out_id_t *es, vlc_es_id_t * const*es_id_list )
+{
+    for( size_t i = 0; es_id_list[i] != NULL; i++ )
+    {
+        if( es_id_list[i] == &es->id )
+            return true;
+    }
+    return false;
+}
+
 static void EsOutSelectList( es_out_t *out, enum es_format_category_e cat,
                              vlc_es_id_t * const*es_id_list )
 {
@@ -2799,38 +2813,31 @@ static void EsOutSelectList( es_out_t *out, enum es_format_category_e cat,
     es_out_id_t *other;
     es_out_es_props_t *p_esprops = GetPropsByCat( p_sys, cat );
 
-    bool unselect_others = false;
+    /* Unselect all ES that are not on es_id_list.
+     * This step need to be done before the selection step, specially
+     * for the EXCLUSIVE ES policy. Indeed, having multiple ES selected is not
+     * supported for this policy. */
     foreach_es_then_es_slaves(other)
     {
         if( other->fmt.i_cat != cat )
             continue;
 
-        bool select = false;
-        if( !unselect_others )
-        {
-            for( size_t i = 0; ; i++ )
-            {
-                vlc_es_id_t *es_id = es_id_list[i];
-                if( es_id == NULL )
-                    break;
-                else if( es_id == &other->id )
-                {
-                    select = true;
-                    break;
-                }
-            }
-        }
-        if( !select )
-        {
-            if( EsIsSelected( other ) )
-                EsOutUnselectEs( out, other, other->p_pgrm == p_sys->p_pgrm );
-        }
-        else
+        if( !EsOutIdMatchEsList( other, es_id_list ) && EsIsSelected( other ) )
+            EsOutUnselectEs( out, other, other->p_pgrm == p_sys->p_pgrm );
+    }
+
+    /* Now, select all ES from es_id_list */
+    foreach_es_then_es_slaves(other)
+    {
+        if( other->fmt.i_cat != cat )
+            continue;
+
+        if( EsOutIdMatchEsList( other, es_id_list ) && !EsIsSelected( other ) )
         {
-            if( !EsIsSelected( other ) )
-                EsOutSelectEs( out, other, true );
+            EsOutSelectEs( out, other, true );
+
             if( p_esprops->e_policy == ES_OUT_ES_POLICY_EXCLUSIVE )
-                unselect_others = true;
+                break;
         }
     }
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/161bad93f73c71b8a290b966256bf9b8023085c5...c8fa3af6d6ace70d659e49798aa62e6f084f33ef

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/161bad93f73c71b8a290b966256bf9b8023085c5...c8fa3af6d6ace70d659e49798aa62e6f084f33ef
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list