all: implemented INPUT_ADD_SLAVE.
authorLaurent Aimar <fenrir@videolan.org>
Mon, 22 Nov 2004 09:57:50 +0000 (09:57 +0000)
committerLaurent Aimar <fenrir@videolan.org>
Mon, 22 Nov 2004 09:57:50 +0000 (09:57 +0000)
src/input/control.c
src/input/input.c
src/input/input_internal.h

index a63e4b4..faade0b 100644 (file)
@@ -63,6 +63,9 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
     double f, *pf;
     int64_t i_64, *pi_64;
 
+    char *psz;
+    vlc_value_t val;
+
     switch( i_query )
     {
         case INPUT_GET_POSITION:
@@ -279,7 +282,6 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             UpdateBookmarksOption( p_input );
 
             return VLC_SUCCESS;
-            break;
 
         case INPUT_CHANGE_BOOKMARK:
             p_bkmk = (seekpoint_t *)va_arg( args, seekpoint_t * );
@@ -308,7 +310,6 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             UpdateBookmarksOption( p_input );
 
             return VLC_SUCCESS;
-            break;
 
         case INPUT_DEL_BOOKMARK:
             i_bkmk = (int)va_arg( args, int );
@@ -342,7 +343,6 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             vlc_mutex_unlock( &p_input->input.p_item->lock );
 
             return VLC_EGENERIC;
-            break;
 
         case INPUT_GET_BOOKMARKS:
             ppp_bkmk = (seekpoint_t ***)va_arg( args, seekpoint_t *** );
@@ -396,7 +396,6 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             UpdateBookmarksOption( p_input );
 
             return VLC_SUCCESS;
-            break;
 
         case INPUT_SET_BOOKMARK:
             i_bkmk = (int)va_arg( args, int );
@@ -469,7 +468,6 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             vlc_mutex_unlock( &p_input->input.p_item->lock );
 
             return VLC_SUCCESS;
-            break;
         }
 
         case INPUT_GET_BYTE_POSITION:
@@ -477,14 +475,21 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             *pi_64 = !p_input->input.p_stream ? 0 :
                 stream_Tell( p_input->input.p_stream );
             return VLC_SUCCESS;
-            break;
 
         case INPUT_SET_BYTE_SIZE:
             pi_64 = (int64_t*)va_arg( args, int64_t * );
             *pi_64 = !p_input->input.p_stream ? 0 :
                 stream_Size( p_input->input.p_stream );
             return VLC_SUCCESS;
-            break;
+
+        case INPUT_ADD_SLAVE:
+            psz = (char*)va_arg( args, char * );
+            if( psz && *psz )
+            {
+                val.psz_string = strdup( psz );
+                input_ControlPush( p_input, INPUT_CONTROL_ADD_SLAVE, &val );
+            }
+            return VLC_SUCCESS;
 
         default:
             msg_Err( p_input, "unknown query in input_vaControl" );
index 0773038..d08d645 100644 (file)
@@ -1405,6 +1405,84 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
             }
             break;
 
+        case INPUT_CONTROL_ADD_SLAVE:
+            if( val.psz_string )
+            {
+                input_source_t *slave = InputSourceNew( p_input );
+
+                if( !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
+                {
+                    vlc_meta_t *p_meta_new = NULL;
+                    vlc_meta_t *p_meta;
+                    int64_t i_time;
+
+                    /* Add the slave */
+                    msg_Dbg( p_input, "adding %s as slave on the fly",
+                             val.psz_string );
+
+                    /* Set position */
+                    if( demux2_Control( p_input->input.p_demux,
+                                        DEMUX_GET_TIME, &i_time ) )
+                    {
+                        msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
+                        InputSourceClean( p_input, slave );
+                        free( slave );
+                        break;
+                    }
+                    if( demux2_Control( slave->p_demux,
+                                        DEMUX_SET_TIME, i_time ) )
+                    {
+                        msg_Err( p_input, "seek failed for new slave" );
+                        InputSourceClean( p_input, slave );
+                        free( slave );
+                        break;
+                    }
+
+
+                    /* Get meta (access and demux) */
+                    if( access2_Control( slave->p_access,
+                                          ACCESS_GET_META, &p_meta_new ) )
+                        p_meta_new = NULL;
+                    if( !demux2_Control( slave->p_demux,
+                                         DEMUX_GET_META, &p_meta ) )
+                    {
+                        if( p_meta_new )
+                        {
+                            vlc_meta_Merge( p_meta_new, p_meta );
+                            vlc_meta_Delete( p_meta );
+                        }
+                        else
+                        {
+                            p_meta_new = p_meta;
+                        }
+                    }
+                    /* Update meta */
+                    if( p_meta_new )
+                    {
+                        if( p_input->p_meta )
+                        {
+                            vlc_meta_Merge( p_input->p_meta, p_meta_new );
+                            vlc_meta_Delete( p_meta_new );
+                        }
+                        else
+                        {
+                            p_input->p_meta = p_meta_new;
+                        }
+                        UpdateMeta( p_input );
+                    }
+
+                    TAB_APPEND( p_input->i_slave, p_input->slave, slave );
+                }
+                else
+                {
+                    msg_Warn( p_input, "failed to add %s as slave",
+                              val.psz_string );
+                }
+
+                free( val.psz_string );
+            }
+            break;
+
         case INPUT_CONTROL_SET_BOOKMARK:
         default:
             msg_Err( p_input, "not yet implemented" );
index 17a49c8..fc5d4af 100644 (file)
@@ -56,6 +56,8 @@ enum input_control_e
 
     INPUT_CONTROL_SET_AUDIO_DELAY,
     INPUT_CONTROL_SET_SPU_DELAY,
+
+    INPUT_CONTROL_ADD_SLAVE,
 };
 
 /* Internal helpers */