[vlc-devel] [PATCH 11/11] input/input: also load unknown/audio slaves from demuxers

Thomas Guillem thomas at gllm.fr
Fri Apr 1 10:31:10 CEST 2016


---
 src/input/input.c | 75 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 37 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index fce2694..406d518 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -1005,6 +1005,18 @@ static void SlaveSort( input_item_slave **pp_slaves, int i_slaves )
     qsort( pp_slaves, i_slaves, sizeof(input_item_slave*), SlaveCompare );
 }
 
+static bool SlaveExists( input_item_slave **pp_slaves, int i_slaves,
+                         const char *psz_uri)
+{
+    for( int i = 0; i < i_slaves; i++ )
+    {
+        if( pp_slaves[i] != NULL
+         && !strcmp( pp_slaves[i]->psz_uri, psz_uri ) )
+            return true;
+    }
+    return false;
+}
+
 static void SetSubtitlesOptions( input_thread_t *p_input )
 {
     /* Get fps and set it if not already set */
@@ -1028,9 +1040,9 @@ static void SetSubtitlesOptions( input_thread_t *p_input )
         var_SetInteger( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
 }
 
-static void LoadSubtitles( input_thread_t *p_input )
+static void LoadSlaves( input_thread_t *p_input )
 {
-    /* Look for and add subtitle files */
+    /* Look for and add slaves */
 
     char *psz_subtitle = var_GetNonEmptyString( p_input, "sub-file" );
     if( psz_subtitle != NULL )
@@ -1077,36 +1089,14 @@ static void LoadSubtitles( input_thread_t *p_input )
         for( int i = 0; i < p_item->i_slaves; i++ )
         {
             input_item_slave *p_slave = p_item->pp_slaves[i];
-            if( p_slave->i_type == SLAVE_TYPE_SPU )
+            if( !SlaveExists( pp_slaves, i_slaves, p_slave->psz_uri )
+             && ( !psz_subtitle || strcmp( psz_subtitle, p_slave->psz_uri ) ) )
             {
-                bool added = false;
-                const char *psz_uri = strstr( p_slave->psz_uri, "file://" );
-                if( psz_uri )
-                {
-                    psz_uri += strlen( "file://" );
-
-                    /* check that we did not add the slave through sub-autodetect-path */
-                    for( int i = 0; i < i_slaves; i++ )
-                    {
-                        if( !strcmp( pp_slaves[i]->psz_uri, psz_uri ) )
-                        {
-                            added = true;
-                            break;
-                        }
-                    }
-
-                    /* check that we did not add the slave through sub-file */
-                    if( psz_subtitle && !strcmp( psz_subtitle, psz_uri ) )
-                        added = true;
-                }
-                if( !added )
-                {
-                    input_item_slave *p_sub = input_item_slave_New( p_slave->psz_uri,
-                                                                    p_slave->i_type,
-                                                                    p_slave->i_priority );
-                    if( p_sub )
-                        INSERT_ELEM( pp_slaves, i_slaves, i_slaves, p_sub );
-                }
+                input_item_slave *p_sub = input_item_slave_New( p_slave->psz_uri,
+                                                                p_slave->i_type,
+                                                                p_slave->i_priority );
+                if( p_sub )
+                    INSERT_ELEM( pp_slaves, i_slaves, i_slaves, p_sub );
             }
         }
         vlc_mutex_unlock( &p_input->p->p_item->lock );
@@ -1116,12 +1106,23 @@ static void LoadSubtitles( input_thread_t *p_input )
         /* add all detected subtitles */
         for( int i = 0; i < i_slaves && pp_slaves[i] != NULL; i++ )
         {
-            const char *psz_uri = pp_slaves[i]->psz_uri;
-            input_SubtitleAdd( p_input, psz_uri, SUB_CANFAIL );
-
+            input_item_slave *p_slave = pp_slaves[i];
+            if( p_slave->i_type == SLAVE_TYPE_SPU )
+            {
+                msg_Err( p_input, "Loading spu slave: %s", p_slave->psz_uri );
+                input_SubtitleAdd( p_input, p_slave->psz_uri, SUB_CANFAIL );
+            }
+            else
+            {
+                msg_Err( p_input, "Loading slave: %s", p_slave->psz_uri );
+                input_source_t *p_source = InputSourceNew( p_input,
+                                                           p_slave->psz_uri,
+                                                           NULL, true );
+                if( p_source )
+                    TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_source );
+            }
             input_item_slave_Delete( pp_slaves[i] );
         }
-
         TAB_CLEAN( i_slaves, pp_slaves );
     }
     free( psz_subtitle );
@@ -1165,7 +1166,7 @@ static void LoadSubtitles( input_thread_t *p_input )
         var_Destroy( p_input, "sub-description" );
 }
 
-static void LoadSlaves( input_thread_t *p_input )
+static void LoadVarSlaves( input_thread_t *p_input )
 {
     char *psz = var_GetNonEmptyString( p_input, "input-slave" );
     if( !psz )
@@ -1340,8 +1341,8 @@ static int Init( input_thread_t * p_input )
     {
         StartTitle( p_input );
         SetSubtitlesOptions( p_input );
-        LoadSubtitles( p_input );
         LoadSlaves( p_input );
+        LoadVarSlaves( p_input );
         InitPrograms( p_input );
 
         double f_rate = var_InheritFloat( p_input, "rate" );
-- 
2.8.0.rc3



More information about the vlc-devel mailing list