]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
Remove access-filter support.
[vlc] / src / input / input.c
index a4a1dd11086086e3ef79f2fc15952491a78cb2e9..151d4566225c5d9fa6a233fa0f4eb7c88a1e470b 100644 (file)
@@ -42,6 +42,7 @@
 #include "access.h"
 #include "demux.h"
 #include "stream.h"
+#include "item.h"
 
 #include <vlc_sout.h>
 #include "../stream_output/stream_output.h"
@@ -180,17 +181,20 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     p_input->i_state = INIT_S;
     p_input->p->i_rate = INPUT_RATE_DEFAULT;
     p_input->p->b_recording = false;
-    TAB_INIT( p_input->p->i_bookmark, p_input->p->bookmark );
+    memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
+    TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
     TAB_INIT( p_input->p->i_attachment, p_input->p->attachment );
     p_input->p->p_es_out_display = NULL;
     p_input->p->p_es_out = NULL;
     p_input->p->p_sout   = NULL;
     p_input->p->b_out_pace_control = false;
     p_input->i_pts_delay = 0;
+    p_input->p->i_cr_average = 0;
 
-    /* Init Input fields */
     vlc_gc_incref( p_item ); /* Released in Destructor() */
-    p_input->p->input.p_item = p_item;
+    p_input->p->p_item = p_item;
+
+    /* Init Input fields */
     p_input->p->input.p_access = NULL;
     p_input->p->input.p_stream = NULL;
     p_input->p->input.p_demux  = NULL;
@@ -202,7 +206,6 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     p_input->p->input.b_can_rate_control = true;
     p_input->p->input.b_rescale_ts = true;
     p_input->p->input.b_eof = false;
-    p_input->p->input.i_cr_average = 0;
 
     vlc_mutex_lock( &p_item->lock );
 
@@ -234,7 +237,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     input_ControlVarInit( p_input );
 
     /* */
-    p_input->p->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
+    p_input->p->i_cr_average = var_GetInteger( p_input, "cr-average" );
 
     if( !p_input->b_preparsing )
     {
@@ -316,7 +319,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
 static void Destructor( input_thread_t * p_input )
 {
 #ifndef NDEBUG
-    char * psz_name = input_item_GetName( p_input->p->input.p_item );
+    char * psz_name = input_item_GetName( p_input->p->p_item );
     msg_Dbg( p_input, "Destroying the input for '%s'", psz_name);
     free( psz_name );
 #endif
@@ -329,7 +332,7 @@ static void Destructor( input_thread_t * p_input )
     if( p_input->p->p_sout )
         sout_DeleteInstance( p_input->p->p_sout );
 #endif
-    vlc_gc_decref( p_input->p->input.p_item );
+    vlc_gc_decref( p_input->p->p_item );
 
     vlc_mutex_destroy( &p_input->p->counters.counters_lock );
 
@@ -464,6 +467,18 @@ sout_instance_t *input_DetachSout( input_thread_t *p_input )
     return p_sout;
 }
 
+/**
+ * Get the item from an input thread
+ * FIXME it does not increase ref count of the item.
+ * if it is used after p_input is destroyed nothing prevent it from
+ * being freed.
+ */
+input_item_t *input_GetItem( input_thread_t *p_input )
+{
+    assert( p_input && p_input->p );
+    return p_input->p->p_item;
+}
+
 /*****************************************************************************
  * ObjectKillChildrens
  *****************************************************************************/
@@ -676,6 +691,13 @@ static void MainLoopInterface( input_thread_t *p_input )
         i_length = 0;
 
     es_out_SetTimes( p_input->p->p_es_out, f_position, i_time, i_length );
+
+    /* update current bookmark */
+    vlc_mutex_lock( &p_input->p->p_item->lock );
+    p_input->p->bookmark.i_time_offset = i_time;
+    if( p_input->p->input.p_stream )
+        p_input->p->bookmark.i_byte_offset = stream_Tell( p_input->p->input.p_stream );
+    vlc_mutex_unlock( &p_input->p->p_item->lock );
 }
 
 /**
@@ -684,7 +706,7 @@ static void MainLoopInterface( input_thread_t *p_input )
  */
 static void MainLoopStatistic( input_thread_t *p_input )
 {
-    stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats );
+    stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
     /* Are we the thread responsible for computing global stats ? */
     if( libvlc_priv( p_input->p_libvlc )->p_stats_computer == p_input )
     {
@@ -831,7 +853,7 @@ static int InitSout( input_thread_t * p_input )
 
     /* Find a usable sout and attach it to p_input */
     psz = var_GetNonEmptyString( p_input, "sout" );
-    if( psz && strncasecmp( p_input->p->input.p_item->psz_uri, "vlc:", 4 ) )
+    if( psz && strncasecmp( p_input->p->p_item->psz_uri, "vlc:", 4 ) )
     {
         /* Check the validity of the provided sout */
         if( p_input->p->p_sout )
@@ -924,10 +946,10 @@ static void InitTitle( input_thread_t * p_input )
         p_input->i_pts_delay -= i_desynch * 1000;
 
     /* Update cr_average depending on the caching */
-    p_master->i_cr_average *= (10 * p_input->i_pts_delay / 200000);
-    p_master->i_cr_average /= 10;
-    if( p_master->i_cr_average < 10 )
-        p_master->i_cr_average = 10;
+    p_input->p->i_cr_average *= (10 * p_input->i_pts_delay / 200000);
+    p_input->p->i_cr_average /= 10;
+    if( p_input->p->i_cr_average < 10 )
+        p_input->p->i_cr_average = 10;
 }
 
 static void StartTitle( input_thread_t * p_input )
@@ -984,9 +1006,8 @@ static void LoadSubtitles( input_thread_t *p_input )
 {
     /* Load subtitles */
     /* Get fps and set it if not already set */
-    double f_fps;
-    if( !demux_Control( p_input->p->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
-        f_fps > 1.0 )
+    const double f_fps = p_input->p->f_fps;
+    if( f_fps > 1.0 )
     {
         float f_requested_fps;
 
@@ -1018,7 +1039,7 @@ static void LoadSubtitles( input_thread_t *p_input )
     {
         char *psz_autopath = var_GetNonEmptyString( p_input, "sub-autodetect-path" );
         char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
-                                             p_input->p->input.p_item->psz_uri );
+                                             p_input->p->p_item->psz_uri );
         free( psz_autopath );
 
         for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
@@ -1059,7 +1080,7 @@ static void LoadSlaves( input_thread_t *p_input )
         msg_Dbg( p_input, "adding slave input '%s'", psz );
 
         input_source_t *p_slave = InputSourceNew( p_input );
-        if( !InputSourceInit( p_input, p_slave, psz, NULL ) )
+        if( p_slave && !InputSourceInit( p_input, p_slave, psz, NULL ) )
             TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave );
         else
             free( p_slave );
@@ -1125,9 +1146,9 @@ static int Init( input_thread_t * p_input )
     vlc_meta_t *p_meta;
     int i, ret;
 
-    for( i = 0; i < p_input->p->input.p_item->i_options; i++ )
+    for( i = 0; i < p_input->p->p_item->i_options; i++ )
     {
-        if( !strncmp( p_input->p->input.p_item->ppsz_options[i], "meta-file", 9 ) )
+        if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) )
         {
             msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
             var_SetString( p_input, "sout", "" );
@@ -1155,8 +1176,13 @@ static int Init( input_thread_t * p_input )
     var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
     var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
 
+    /* */
+    input_ChangeState( p_input, OPENING_S );
+    input_SendEventCache( p_input, 0.0 );
+
+    /* */
     if( InputSourceInit( p_input, &p_input->p->input,
-                         p_input->p->input.p_item->psz_uri, NULL ) )
+                         p_input->p->p_item->psz_uri, NULL ) )
     {
         goto error;
     }
@@ -1170,7 +1196,7 @@ static int Init( input_thread_t * p_input )
                          &i_length ) )
         i_length = 0;
     if( i_length <= 0 )
-        i_length = input_item_GetDuration( p_input->p->input.p_item );
+        i_length = input_item_GetDuration( p_input->p->p_item );
     input_SendEventTimes( p_input, 0.0, 0, i_length );
 
     if( !p_input->b_preparsing )
@@ -1216,7 +1242,7 @@ static int Init( input_thread_t * p_input )
     if( !p_input->b_preparsing )
     {
         msg_Dbg( p_input, "`%s' successfully opened",
-                 p_input->p->input.p_item->psz_uri );
+                 p_input->p->p_item->psz_uri );
 
     }
 
@@ -1336,7 +1362,7 @@ static void End( input_thread_t * p_input )
             libvlc_priv_t *p_private = libvlc_priv( p_input->p_libvlc );
 
             /* make sure we are up to date */
-            stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats );
+            stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
             if( p_private->p_stats_computer == p_input )
             {
                 stats_ComputeGlobalStats( p_input->p_libvlc,
@@ -1907,8 +1933,8 @@ static bool Control( input_thread_t *p_input, int i_type,
                 {
                     es_out_SetTime( p_input->p->p_es_out, -1 );
 
-                    access_Control( p_access, ACCESS_SET_TITLE, i_title );
-                    stream_AccessReset( p_input->p->input.p_stream );
+                    stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
+                                    ACCESS_SET_TITLE, i_title );
                 }
             }
             break;
@@ -1986,9 +2012,8 @@ static bool Control( input_thread_t *p_input, int i_type,
                 {
                     es_out_SetTime( p_input->p->p_es_out, -1 );
 
-                    access_Control( p_access, ACCESS_SET_SEEKPOINT,
-                                    i_seekpoint );
-                    stream_AccessReset( p_input->p->input.p_stream );
+                    stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
+                                    ACCESS_SET_SEEKPOINT, i_seekpoint );
                 }
             }
             break;
@@ -2006,7 +2031,7 @@ static bool Control( input_thread_t *p_input, int i_type,
             {
                 input_source_t *slave = InputSourceNew( p_input );
 
-                if( !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
+                if( slave && !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
                 {
                     vlc_meta_t *p_meta;
                     int64_t i_time;
@@ -2094,6 +2119,45 @@ static bool Control( input_thread_t *p_input, int i_type,
             break;
 
         case INPUT_CONTROL_SET_BOOKMARK:
+        {
+            seekpoint_t bookmark;
+
+            bookmark.i_time_offset = -1;
+            bookmark.i_byte_offset = -1;
+
+            vlc_mutex_lock( &p_input->p->p_item->lock );
+            if( val.i_int >= 0 && val.i_int < p_input->p->i_bookmark )
+            {
+                const seekpoint_t *p_bookmark = p_input->p->pp_bookmark[val.i_int];
+                bookmark.i_time_offset = p_bookmark->i_time_offset;
+                bookmark.i_byte_offset = p_bookmark->i_byte_offset;
+            }
+            vlc_mutex_unlock( &p_input->p->p_item->lock );
+
+            if( bookmark.i_time_offset < 0 && bookmark.i_byte_offset < 0 )
+            {
+                msg_Err( p_input, "invalid bookmark %d", val.i_int );
+                break;
+            }
+
+            if( bookmark.i_time_offset >= 0 )
+            {
+                val.i_time = bookmark.i_time_offset;
+                b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );
+            }
+            else if( bookmark.i_byte_offset >= 0 &&
+                     p_input->p->input.p_stream )
+            {
+                const int64_t i_size = stream_Size( p_input->p->input.p_stream );
+                if( i_size > 0 && bookmark.i_byte_offset <= i_size )
+                {
+                    val.f_float = (double)bookmark.i_byte_offset / i_size;
+                    b_force_update = Control( p_input, INPUT_CONTROL_SET_POSITION, val );
+                }
+            }
+            break;
+        }
+
         default:
             msg_Err( p_input, "not yet implemented" );
             break;
@@ -2191,7 +2255,7 @@ static int UpdateTitleSeekpointFromAccess( input_thread_t *p_input )
     {
         input_SendEventTitle( p_input, p_access->info.i_title );
 
-        stream_AccessUpdate( p_input->p->input.p_stream );
+        stream_Control( p_input->p->input.p_stream, STREAM_UPDATE_SIZE );
 
         p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
     }
@@ -2257,8 +2321,6 @@ static int InputSourceInit( input_thread_t *p_input,
                             input_source_t *in, const char *psz_mrl,
                             const char *psz_forced_demux )
 {
-    const bool b_master = in == &p_input->p->input;
-
     char psz_dup[strlen(psz_mrl) + 1];
     const char *psz_access;
     const char *psz_demux;
@@ -2270,9 +2332,6 @@ static int InputSourceInit( input_thread_t *p_input,
 
     strcpy( psz_dup, psz_mrl );
 
-    if( !in ) return VLC_EGENERIC;
-    if( !p_input ) return VLC_EGENERIC;
-
     /* Split uri */
     input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
 
@@ -2377,9 +2436,6 @@ static int InputSourceInit( input_thread_t *p_input,
     {
         int64_t i_pts_delay;
 
-        if( b_master )
-            input_ChangeState( p_input, OPENING_S );
-
         /* Now try a real access */
         in->p_access = access_New( p_input, psz_access, psz_demux, psz_path );
 
@@ -2405,28 +2461,6 @@ static int InputSourceInit( input_thread_t *p_input,
             goto error;
         }
 
-        /* */
-        psz_tmp = psz = var_GetNonEmptyString( p_input, "access-filter" );
-        while( psz && *psz )
-        {
-            access_t *p_access = in->p_access;
-            char *end = strchr( psz, ':' );
-
-            if( end )
-                *end++ = '\0';
-
-            in->p_access = access_FilterNew( in->p_access, psz );
-            if( in->p_access == NULL )
-            {
-                in->p_access = p_access;
-                msg_Warn( p_input, "failed to insert access filter %s",
-                          psz );
-            }
-
-            psz = end;
-        }
-        free( psz_tmp );
-
         /* Get infos from access */
         if( !p_input->b_preparsing )
         {
@@ -2458,8 +2492,9 @@ static int InputSourceInit( input_thread_t *p_input,
             var_Set( p_input, "can-seek", val );
         }
 
-        if( b_master )
-            input_ChangeState( p_input, BUFFERING_S );
+        /* TODO (maybe)
+         * do not let stream_AccessNew access input-list
+         * but give it a list of access ? */
 
         /* Autodetect extra files if none specified */
         char *psz_input_list = var_CreateGetNonEmptyString( p_input, "input-list" );
@@ -2474,7 +2509,7 @@ static int InputSourceInit( input_thread_t *p_input,
         /* Create the stream_t */
         in->p_stream = stream_AccessNew( in->p_access, p_input->b_preparsing );
 
-        /* Restor old value */
+        /* Restore old value */
         if( !psz_input_list )
             var_SetString( p_input, "input-list", "" );
         free( psz_input_list );
@@ -2485,6 +2520,49 @@ static int InputSourceInit( input_thread_t *p_input,
             goto error;
         }
 
+        /* Add auto stream filter */
+        for( ;; )
+        {
+            stream_t *p_filter = stream_FilterNew( in->p_stream, NULL );
+            if( !p_filter )
+                break;
+
+            msg_Dbg( p_input, "Inserted a stream filter" );
+            in->p_stream = p_filter;
+        }
+
+        /* Add user stream filter */
+        psz_tmp = psz = var_GetNonEmptyString( p_input, "stream-filter" );
+        while( psz && *psz )
+        {
+            stream_t *p_filter;
+            char *psz_end = strchr( psz, ':' );
+
+            if( psz_end )
+                *psz_end++ = '\0';
+
+            p_filter = stream_FilterNew( in->p_stream, psz );
+            if( p_filter )
+                in->p_stream = p_filter;
+            else
+                msg_Warn( p_input, "failed to insert stream filter %s", psz );
+
+            psz = psz_end;
+        }
+        free( psz_tmp );
+
+        /* Add record filter if usefull */
+        if( var_GetBool( p_input, "input-record-native" ) )
+        {
+            stream_t *p_filter;
+
+            p_filter = stream_FilterNew( in->p_stream, "stream_filter_record" );
+            if( p_filter )
+                in->p_stream = p_filter;
+            else
+                var_SetBool( p_input, "input-record-native", false );
+        }
+
         /* Open a demuxer */
         if( *psz_demux == '\0' && *in->p_access->psz_demux )
         {
@@ -2543,7 +2621,7 @@ static int InputSourceInit( input_thread_t *p_input,
     if( demux_Control( in->p_demux, DEMUX_CAN_RECORD, &in->b_can_stream_record ) )
         in->b_can_stream_record = false;
 #ifdef ENABLE_SOUT
-    if( !var_CreateGetBool( p_input, "input-record-native" ) )
+    if( !var_GetBool( p_input, "input-record-native" ) )
         in->b_can_stream_record = false;
     var_SetBool( p_input, "can-record", true );
 #else
@@ -2559,17 +2637,17 @@ static int InputSourceInit( input_thread_t *p_input,
         if( !demux_Control( in->p_demux, DEMUX_GET_ATTACHMENTS,
                              &attachment, &i_attachment ) )
         {
-            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            vlc_mutex_lock( &p_input->p->p_item->lock );
             AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
                               i_attachment, attachment );
-            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+            vlc_mutex_unlock( &p_input->p->p_item->lock );
         }
     }
-    if( !demux_Control( in->p_demux, DEMUX_GET_FPS, &f_fps ) )
+    if( !demux_Control( in->p_demux, DEMUX_GET_FPS, &f_fps ) && f_fps > 0.0 )
     {
-        vlc_mutex_lock( &p_input->p->input.p_item->lock );
-        in->f_fps = f_fps;
-        vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+        vlc_mutex_lock( &p_input->p->p_item->lock );
+        p_input->p->f_fps = f_fps;
+        vlc_mutex_unlock( &p_input->p->p_item->lock );
     }
 
     if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
@@ -2578,9 +2656,6 @@ static int InputSourceInit( input_thread_t *p_input,
     return VLC_SUCCESS;
 
 error:
-    if( b_master )
-        input_ChangeState( p_input, ERROR_S );
-
     if( in->p_demux )
         demux_Delete( in->p_demux );
 
@@ -2658,10 +2733,10 @@ static void InputSourceMeta( input_thread_t *p_input,
 
         if( p_demux_meta->i_attachments > 0 )
         {
-            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            vlc_mutex_lock( &p_input->p->p_item->lock );
             AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
                               p_demux_meta->i_attachments, p_demux_meta->attachments );
-            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+            vlc_mutex_unlock( &p_input->p->p_item->lock );
         }
         module_unneed( p_demux, p_id3 );
     }
@@ -2780,7 +2855,7 @@ static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta )
  *****************************************************************************/
 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
 {
-    input_item_t *p_item = p_input->p->input.p_item;
+    input_item_t *p_item = p_input->p->p_item;
 
     char *psz_title = NULL;
     char *psz_arturl = input_item_GetArtURL( p_item );
@@ -2910,7 +2985,7 @@ static void input_ChangeState( input_thread_t *p_input, int i_state )
 
     if( b_changed )
     {
-        input_item_SetErrorWhenReading( p_input->p->input.p_item, p_input->b_error );
+        input_item_SetErrorWhenReading( p_input->p->p_item, p_input->b_error );
         input_SendEventState( p_input, i_state );
     }
 }
@@ -3083,7 +3158,7 @@ static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_for
     var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
 
     sub = InputSourceNew( p_input );
-    if( InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
+    if( !sub || InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
     {
         free( sub );
         return;
@@ -3108,22 +3183,6 @@ static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_for
     }
 }
 
-bool input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
-                               bool b_check_extension )
-{
-    vlc_value_t val;
-
-    if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
-        return false;
-
-    assert( psz_subtitle != NULL );
-
-    val.psz_string = strdup( psz_subtitle );
-    if( val.psz_string )
-        input_ControlPush( p_input, INPUT_CONTROL_ADD_SUBTITLE, &val );
-    return true;
-}
-
 /*****************************************************************************
  * Statistics
  *****************************************************************************/
@@ -3164,9 +3223,9 @@ void input_UpdateStatistic( input_thread_t *p_input,
     vlc_mutex_unlock( &p_input->p->counters.counters_lock);
 }
 /*****************************************************************************
- * input_get_event_manager
+ * input_GetEventManager
  *****************************************************************************/
-vlc_event_manager_t *input_get_event_manager( input_thread_t *p_input )
+vlc_event_manager_t *input_GetEventManager( input_thread_t *p_input )
 {
     return &p_input->p->event_manager;
 }