[vlc-commits] input: improve INPUT_CONTROL_ADD_SLAVE

Thomas Guillem git at videolan.org
Tue May 31 16:23:35 CEST 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri May 27 11:41:06 2016 +0200| [04cffe78c16232f0dace7aaf98d251653bbbff11] | committer: Thomas Guillem

input: improve INPUT_CONTROL_ADD_SLAVE

It can now handle a slave type (via input_item_slave_t) and update the
input_item_t slave list.

This control is unused for now.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=04cffe78c16232f0dace7aaf98d251653bbbff11
---

 src/input/control.c |   19 ++++++++++++++-----
 src/input/input.c   |   26 +++++++++++++++++++++++---
 2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/src/input/control.c b/src/input/control.c
index 7a2a5d3..16f5186 100644
--- a/src/input/control.c
+++ b/src/input/control.c
@@ -430,13 +430,22 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
         }
 
         case INPUT_ADD_SLAVE:
+        {
+            enum slave_type type =  (enum slave_type) va_arg( args, enum slave_type );
             psz = (char*)va_arg( args, char * );
-            if( psz && *psz )
-            {
-                val.psz_string = strdup( psz );
-                input_ControlPush( p_input, INPUT_CONTROL_ADD_SLAVE, &val );
-            }
+
+            if( !psz || ( type != SLAVE_TYPE_SPU && type != SLAVE_TYPE_AUDIO ) )
+                return VLC_EGENERIC;
+
+            input_item_slave_t *p_slave =
+                input_item_slave_New( psz, type, SLAVE_PRIORITY_USER );
+            if( !p_slave )
+                return VLC_ENOMEM;
+
+            val.p_address = p_slave;
+            input_ControlPush( p_input, INPUT_CONTROL_ADD_SLAVE, &val );
             return VLC_SUCCESS;
+        }
 
         case INPUT_ADD_SUBTITLE:
             psz = (char*)va_arg( args, char * );
diff --git a/src/input/input.c b/src/input/input.c
index 81ebe22..951358f 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -1618,9 +1618,12 @@ static void ControlRelease( int i_type, vlc_value_t val )
     switch( i_type )
     {
     case INPUT_CONTROL_ADD_SUBTITLE:
-    case INPUT_CONTROL_ADD_SLAVE:
         free( val.psz_string );
         break;
+    case INPUT_CONTROL_ADD_SLAVE:
+        if( val.p_address )
+            input_item_slave_Delete( val.p_address );
+        break;
 
     default:
         break;
@@ -1986,9 +1989,21 @@ static bool Control( input_thread_t *p_input,
             break;
 
         case INPUT_CONTROL_ADD_SLAVE:
-            if( val.psz_string )
+            if( val.p_address )
             {
-                const char *uri = val.psz_string;
+                input_item_slave_t *p_item_slave  = val.p_address;
+                if( p_item_slave->i_type == SLAVE_TYPE_SPU )
+                {
+                    input_SubtitleAdd( p_input, p_item_slave->psz_uri,
+                                       SUB_CANFAIL | SUB_FORCED );
+
+                    /* Update item slaves */
+                    input_item_AddSlave( p_input->p->p_item, p_item_slave );
+                    /* The slave is now owned by the ite */
+                    val.p_address = NULL;
+                    break;
+                }
+                const char *uri = p_item_slave->psz_uri;
                 input_source_t *slave = InputSourceNew( p_input, uri, NULL,
                                                         false );
                 if( slave == NULL )
@@ -2023,6 +2038,11 @@ static bool Control( input_thread_t *p_input,
                 InputUpdateMeta( p_input, slave->p_demux );
 
                 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
+
+                /* Update item slaves */
+                input_item_AddSlave( p_input->p->p_item, p_item_slave );
+                /* The slave is now owned by the ite */
+                val.p_address = NULL;
             }
             break;
 



More information about the vlc-commits mailing list