]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
remove those two filers from the prefs in 0.8.2 since we don't have
[vlc] / src / input / input.c
index fd3bcc70b64af4c9bf4acdd9b4cda4f6f950c6ce..fb02a6ff40538584a5b2d2256a7750f3b0b39b57 100644 (file)
@@ -62,7 +62,6 @@ static void UpdateItemLength( input_thread_t *, int64_t i_length, vlc_bool_t );
 static void ParseOption( input_thread_t *p_input, const char *psz_option );
 
 static void DecodeUrl( char * );
-static void MRLSplit( input_thread_t *, char *, char **, char **, char ** );
 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
 
 static input_source_t *InputSourceNew( input_thread_t *);
@@ -162,7 +161,6 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
     vlc_mutex_lock( &p_item->lock );
     for( i = 0; i < p_item->i_options; i++ )
     {
-//        msg_Dbg( p_input, "option: %s", p_item->ppsz_options[i] );
         ParseOption( p_input, p_item->ppsz_options[i] );
     }
     vlc_mutex_unlock( &p_item->lock );
@@ -183,7 +181,7 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
         psz_parser = val.psz_string;
         while( (psz_start = strchr( psz_parser, '{' ) ) )
         {
-            seekpoint_t seekpoint;
+            seekpoint_t *p_seekpoint = vlc_seekpoint_New();
             char backup;
             psz_start++;
             psz_end = strchr( psz_start, '}' );
@@ -193,35 +191,37 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
             *psz_parser = 0;
             *psz_end = ',';
 
-            seekpoint.psz_name = 0;
-            seekpoint.i_byte_offset = 0;
-            seekpoint.i_time_offset = 0;
             while( (psz_end = strchr( psz_start, ',' ) ) )
             {
                 *psz_end = 0;
                 if( !strncmp( psz_start, "name=", 5 ) )
                 {
-                    seekpoint.psz_name = psz_start + 5;
+                    p_seekpoint->psz_name = psz_start + 5;
                 }
                 else if( !strncmp( psz_start, "bytes=", 6 ) )
                 {
-                    seekpoint.i_byte_offset = atoll(psz_start + 6);
+                    p_seekpoint->i_byte_offset = atoll(psz_start + 6);
                 }
                 else if( !strncmp( psz_start, "time=", 5 ) )
                 {
-                    seekpoint.i_time_offset = atoll(psz_start + 5) * 1000000;
+                    p_seekpoint->i_time_offset = atoll(psz_start + 5) * 1000000;
                 }
                 psz_start = psz_end + 1;
             }
             msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
-                     seekpoint.psz_name, seekpoint.i_byte_offset,
-                     seekpoint.i_time_offset );
-            input_Control( p_input, INPUT_ADD_BOOKMARK, &seekpoint );
+                     p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
+                     p_seekpoint->i_time_offset );
+            input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
+            vlc_seekpoint_Delete( p_seekpoint );
             *psz_parser = backup;
         }
         free( val.psz_string );
     }
 
+    /* Remove 'Now playing' info as it is probably outdated */
+    input_Control( p_input, INPUT_DEL_INFO, _("Meta-information"),
+                   VLC_META_NOW_PLAYING );
+
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
 
@@ -611,11 +611,17 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
     int i_es_out_mode;
     int i, i_delay;
 
-    /* Initialize optional stream output. (before access/demuxer) */
+    /* Initialize optional stream output. (before access/demuxer)
+     * XXX: we add a special case if the uri starts by vlc.
+     * else 'vlc in.file --sout "" vlc:quit'  cannot work (the output will
+     * be destroyed in case of a file).
+     * (this will break playing of file starting by 'vlc:' but I don't
+     * want to add more logic, just force file by file:// or code it ;)
+     */
     if( !b_quick )
     {
         psz = var_GetString( p_input, "sout" );
-        if( *psz )
+        if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
         {
             p_input->p_sout = sout_NewInstance( p_input, psz );
             if( p_input->p_sout == NULL )
@@ -712,7 +718,7 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
             {
                 vlc_value_t s;
 
-                msg_Dbg( p_input, "start-time: %ds",
+                msg_Dbg( p_input, "starting at time: %ds",
                                   (int)( p_input->i_start / I64C(1000000) ) );
 
                 s.i_time = p_input->i_start;
@@ -837,7 +843,7 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
                     break;
                 }
 
-                msg_Dbg( p_input, "adding slave '%s'", psz );
+                msg_Dbg( p_input, "adding slave input '%s'", psz );
                 slave = InputSourceNew( p_input );
                 if( !InputSourceInit( p_input, slave, psz, NULL, VLC_FALSE ) )
                 {
@@ -909,6 +915,14 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
             {
                 p_input->b_out_pace_control = VLC_TRUE;
             }
+
+            if( p_input->b_can_pace_control && p_input->b_out_pace_control )
+            {
+                /* We don't want a high input priority here or we'll
+                 * end-up sucking up all the CPU time */
+                vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
+            }
+
             msg_Dbg( p_input, "starting in %s mode",
                      p_input->b_out_pace_control ? "asynch" : "synch" );
         }
@@ -991,7 +1005,7 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
 
     if( !b_quick )
     {
-        msg_Dbg( p_input, "`%s' sucessfully opened",
+        msg_Dbg( p_input, "`%s' successfully opened",
                  p_input->input.p_item->psz_uri );
 
     }
@@ -1143,8 +1157,9 @@ static void ControlReduce( input_thread_t *p_input )
         const int i_ct = p_input->control[i].i_type;
 
         /* XXX We can't merge INPUT_CONTROL_SET_ES */
-        msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
+/*        msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
                  i_lt, i_ct );
+*/
         if( i_lt == i_ct &&
             ( i_ct == INPUT_CONTROL_SET_STATE ||
               i_ct == INPUT_CONTROL_SET_RATE ||
@@ -1156,7 +1171,7 @@ static void ControlReduce( input_thread_t *p_input )
               i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
         {
             int j;
-            msg_Dbg( p_input, "merged at %d", i );
+//            msg_Dbg( p_input, "merged at %d", i );
             /* Remove the i-1 */
             for( j = i; j <  p_input->i_control; j++ )
                 p_input->control[j-1] = p_input->control[j];
@@ -1182,7 +1197,7 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
     switch( i_type )
     {
         case INPUT_CONTROL_SET_DIE:
-            msg_Dbg( p_input, "control: INPUT_CONTROL_SET_DIE proceed" );
+            msg_Dbg( p_input, "control: stopping input" );
             /* Mark all submodules to die */
             if( p_input->input.p_access )
                 p_input->input.p_access->b_die = VLC_TRUE;
@@ -1493,15 +1508,17 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
             {
                 demux_t *p_demux = p_input->input.p_demux;
                 int i_seekpoint;
-                mtime_t i_input_time;
-                mtime_t i_seekpoint_time; 
+                int64_t i_input_time;
+                int64_t i_seekpoint_time;
 
                 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
                 {
                     i_seekpoint = p_demux->info.i_seekpoint;
-                    if (demux2_Control( p_demux, DEMUX_GET_SEEKPOINT_TIME, p_demux->info.i_seekpoint, &i_seekpoint_time) == VLC_SUCCESS)
+                    i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
+                    if( i_seekpoint_time >= 0 &&
+                         !demux2_Control( p_demux,
+                                          DEMUX_GET_TIME, &i_input_time ) )
                     {
-                        demux2_Control( p_demux, INPUT_GET_TIME, &i_input_time );
                         if ( i_input_time < i_seekpoint_time + 3000000 )
                             i_seekpoint--;
                     }
@@ -1524,11 +1541,26 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
             }
             else if( p_input->input.i_title > 0 )
             {
+                demux_t *p_demux = p_input->input.p_demux;
                 access_t *p_access = p_input->input.p_access;
                 int i_seekpoint;
+                int64_t i_input_time;
+                int64_t i_seekpoint_time;
 
                 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
-                    i_seekpoint = p_access->info.i_seekpoint - 1;
+                {
+                    i_seekpoint = p_access->info.i_seekpoint;
+                    i_seekpoint_time = p_input->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
+                    if( i_seekpoint_time >= 0 &&
+                        demux2_Control( p_demux,
+                                        DEMUX_GET_TIME, &i_input_time ) )
+                    {
+                        if ( i_input_time < i_seekpoint_time + 3000000 )
+                            i_seekpoint--;
+                    }
+                    else
+                        i_seekpoint--;
+                }
                 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT ) 
                     i_seekpoint = p_access->info.i_seekpoint + 1;
                 else
@@ -1883,12 +1915,15 @@ static int InputSourceInit( input_thread_t *p_input,
     char *psz_access;
     char *psz_demux;
     char *psz_path;
+    char *psz_tmp;
+    char *psz;
     vlc_value_t val;
 
     /* Split uri */
     if( !b_quick )
     {
-        MRLSplit( p_input, psz_dup, &psz_access, &psz_demux, &psz_path );
+        MRLSplit( VLC_OBJECT(p_input), psz_dup,
+                  &psz_access, &psz_demux, &psz_path );
 
         msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
                  psz_mrl, psz_access, psz_demux, psz_path );
@@ -1992,6 +2027,28 @@ static int InputSourceInit( input_thread_t *p_input,
             goto error;
         }
 
+        /* */
+        psz_tmp = psz = var_GetString( 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 = access2_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( !b_quick )
         {
@@ -2067,7 +2124,7 @@ error:
         demux2_Delete( in->p_demux );
 
     if( in->p_stream )
-        stream_AccessDelete( in->p_stream );
+        stream_Delete( in->p_stream );
 
     if( in->p_access )
         access2_Delete( in->p_access );
@@ -2085,7 +2142,7 @@ static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
         demux2_Delete( in->p_demux );
 
     if( in->p_stream )
-        stream_AccessDelete( in->p_stream );
+        stream_Delete( in->p_stream );
 
     if( in->p_access )
         access2_Delete( in->p_access );
@@ -2346,8 +2403,8 @@ static void ParseOption( input_thread_t *p_input, const char *psz_option )
  * MRLSplit: parse the access, demux and url part of the
  *           Media Resource Locator.
  *****************************************************************************/
-static void MRLSplit( input_thread_t *p_input, char *psz_dup,
-                      char **ppsz_access, char **ppsz_demux, char **ppsz_path )
+void MRLSplit( vlc_object_t *p_input, char *psz_dup,
+               char **ppsz_access, char **ppsz_demux, char **ppsz_path )
 {
     char *psz_access = NULL;
     char *psz_demux  = NULL;
@@ -2471,6 +2528,16 @@ static void MRLSections( input_thread_t *p_input, char *psz_source,
 /***********************************************************************
  * Info management functions
  ***********************************************************************/
+/**
+ * Get a info item from a given category in a given input item.
+ *
+ * \param p_i The input item to get info from
+ * \param psz_cat String representing the category for the info
+ * \param psz_name String representing the name of the desired info
+ * \return A pointer to the string with the given info if found, or an
+ *         empty string otherwise. The caller should free the returned
+ *         pointer.
+ */
 char *vlc_input_item_GetInfo( input_item_t *p_i,
                               const char *psz_cat,
                               const char *psz_name )
@@ -2490,8 +2557,9 @@ char *vlc_input_item_GetInfo( input_item_t *p_i,
         {
             if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
             {
+                char *psz_ret = strdup( p_cat->pp_infos[j]->psz_value );
                 vlc_mutex_unlock( &p_i->lock );
-                return strdup( p_cat->pp_infos[j]->psz_value );
+                return psz_ret;
             }
         }
     }
@@ -2521,8 +2589,7 @@ int vlc_input_item_AddInfo( input_item_t *p_i,
     }
     if( !p_cat )
     {
-        if( ( p_cat = (info_category_t *)malloc(
-                                     sizeof( info_category_t ) ) )  == NULL )
+        if( !(p_cat = (info_category_t *)malloc( sizeof(info_category_t) )) )
         {
             vlc_mutex_unlock( &p_i->lock );
             return VLC_EGENERIC;