]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
Backport of [11331]
[vlc] / src / input / input.c
index 96ba03bdc2ccb07ceafd84f43d013ce8661aa9d8..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 *);
@@ -219,6 +218,10 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
         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 );
 
@@ -608,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 )
@@ -906,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" );
         }
@@ -988,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 );
 
     }
@@ -1491,16 +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;
                     i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
-                    if ( i_seekpoint_time != -1 )
+                    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--;
                     }
@@ -1523,18 +1541,20 @@ 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;
-                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_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 != -1 )
+                    if( i_seekpoint_time >= 0 &&
+                        demux2_Control( p_demux,
+                                        DEMUX_GET_TIME, &i_input_time ) )
                     {
-                        access2_Control( p_access, INPUT_GET_TIME, &i_input_time );
                         if ( i_input_time < i_seekpoint_time + 3000000 )
                             i_seekpoint--;
                     }
@@ -1895,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 );
@@ -2004,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 )
         {
@@ -2079,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 );
@@ -2097,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 );
@@ -2358,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;
@@ -2483,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 )
@@ -2502,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;
             }
         }
     }