]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
Fix opening of file:// URIs (not tested on Windows)
[vlc] / src / input / input.c
index c40b9f0f306094585ca80e2a366ce77255fe28a6..b9882edb90e1681a6beb32e096d2522528587aea 100644 (file)
@@ -296,7 +296,7 @@ static void ObjectKillChildrens( input_thread_t *p_input, vlc_object_t *p_obj )
     i = vlc_internals( p_obj )->i_object_type;
     if( i == VLC_OBJECT_VOUT ||i == VLC_OBJECT_AOUT ||
         p_obj == VLC_OBJECT(p_input->p->p_sout) ||
-        i == VLC_OBJECT_DECODER || i == VLC_OBJECT_PACKETIZER )
+        i == VLC_OBJECT_DECODER )
         return;
 
     vlc_object_kill( p_obj );
@@ -592,14 +592,14 @@ exit:
  * MainLoopDemux
  * It asks the demuxer to demux some data
  */
-static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *pi_start_mdate )
+static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t i_start_mdate )
 {
     int i_ret;
 
     *pb_changed = false;
 
     if( ( p_input->p->i_stop > 0 && p_input->p->i_time >= p_input->p->i_stop ) ||
-        ( p_input->p->i_run > 0 && *pi_start_mdate+p_input->p->i_run < mdate() ) )
+        ( p_input->p->i_run > 0 && i_start_mdate+p_input->p->i_run < mdate() ) )
         i_ret = 0; /* EOF */
     else
         i_ret = demux_Demux( p_input->p->input.p_demux );
@@ -629,56 +629,8 @@ static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *p
 
     if( i_ret == 0 )    /* EOF */
     {
-        int i_repeat = var_GetInteger( p_input, "input-repeat" );
-        if( i_repeat == 0 )
-        {
-            /* End of file - we do not set b_die because only the
-             * playlist is allowed to do so. */
-            msg_Dbg( p_input, "EOF reached" );
-            p_input->p->input.b_eof = true;
-        }
-        else
-        {
-            vlc_value_t val;
-
-            msg_Dbg( p_input, "repeating the same input (%d)", i_repeat );
-            if( i_repeat > 0 )
-            {
-                i_repeat--;
-                var_SetInteger( p_input, "input-repeat", i_repeat );
-            }
-
-            /* Seek to start title/seekpoint */
-            val.i_int = p_input->p->input.i_title_start -
-                p_input->p->input.i_title_offset;
-            if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
-                val.i_int = 0;
-            input_ControlPush( p_input,
-                               INPUT_CONTROL_SET_TITLE, &val );
-
-            val.i_int = p_input->p->input.i_seekpoint_start -
-                p_input->p->input.i_seekpoint_offset;
-            if( val.i_int > 0 /* TODO: check upper boundary */ )
-                input_ControlPush( p_input,
-                                   INPUT_CONTROL_SET_SEEKPOINT, &val );
-
-            /* Seek to start position */
-            if( p_input->p->i_start > 0 )
-            {
-                val.i_time = p_input->p->i_start;
-                input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
-                                   &val );
-            }
-            else
-            {
-                val.f_float = 0.0;
-                input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
-                                   &val );
-            }
-
-            /* */
-            *pi_start_mdate = mdate();
-        }
+        msg_Dbg( p_input, "EOF reached" );
+        p_input->p->input.b_eof = true;
     }
     else if( i_ret < 0 )
     {
@@ -691,6 +643,52 @@ static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *p
     }
 }
 
+static int MainLoopTryRepeat( input_thread_t *p_input, mtime_t *pi_start_mdate )
+{
+    int i_repeat = var_GetInteger( p_input, "input-repeat" );
+    if( i_repeat == 0 )
+        return VLC_EGENERIC;
+
+    vlc_value_t val;
+
+    msg_Dbg( p_input, "repeating the same input (%d)", i_repeat );
+    if( i_repeat > 0 )
+    {
+        i_repeat--;
+        var_SetInteger( p_input, "input-repeat", i_repeat );
+    }
+
+    /* Seek to start title/seekpoint */
+    val.i_int = p_input->p->input.i_title_start -
+        p_input->p->input.i_title_offset;
+    if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
+        val.i_int = 0;
+    input_ControlPush( p_input,
+                       INPUT_CONTROL_SET_TITLE, &val );
+
+    val.i_int = p_input->p->input.i_seekpoint_start -
+        p_input->p->input.i_seekpoint_offset;
+    if( val.i_int > 0 /* TODO: check upper boundary */ )
+        input_ControlPush( p_input,
+                           INPUT_CONTROL_SET_SEEKPOINT, &val );
+
+    /* Seek to start position */
+    if( p_input->p->i_start > 0 )
+    {
+        val.i_time = p_input->p->i_start;
+        input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &val );
+    }
+    else
+    {
+        val.f_float = 0.0;
+        input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &val );
+    }
+
+    /* */
+    *pi_start_mdate = mdate();
+    return VLC_SUCCESS;
+}
+
 /**
  * MainLoopInterface
  * It update the variables used by the interfaces
@@ -771,7 +769,7 @@ static void MainLoop( input_thread_t *p_input )
         {
             if( !p_input->p->input.b_eof )
             {
-                MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
+                MainLoopDemux( p_input, &b_force_update, i_start_mdate );
 
                 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
             }
@@ -782,7 +780,8 @@ static void MainLoop( input_thread_t *p_input )
             }
             else
             {
-                break;
+                if( MainLoopTryRepeat( p_input, &i_start_mdate ) )
+                    break;
             }
         }
 
@@ -1138,7 +1137,6 @@ static void InitPrograms( input_thread_t * p_input )
     {
         demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
                         val.p_list );
-        var_FreeList( &val, NULL );
     }
     else
     {
@@ -2347,6 +2345,36 @@ static int InputSourceInit( input_thread_t *p_input,
     /* Split uri */
     input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
 
+    /* FIXME: file:// handling plugins do not support URIs properly...
+     * So we pre-decoded the URI to a path for them. Note that we do not do it
+     * for non-standard VLC-specific schemes. */
+    if( !strcmp( psz_access, "file" ) )
+    {
+        if( psz_path[0] != '/' )
+        {   /* host specified -> not supported currently */
+            msg_Err( p_input, "cannot open remote file `%s://%s'",
+                     psz_access, psz_path );
+            msg_Info( p_input, "Did you mean `%s:///%s'?",
+                      psz_access, psz_path );
+            goto error;
+        }
+        /* Remove HTML anchor if present (not supported). */
+        char *p = strchr( psz_path, '#' );
+        if( p )
+            *p = '\0';
+        /* Then URI-decode the path. */
+        decode_URI( psz_path );
+#ifdef WIN32
+        /* Strip leading slash in front of the drive letter */
+        psz_path++;
+#endif
+#if (DIR_SEP_CHAR != '/')
+        /* Turn slashes into anti-slashes */
+        for( char *s = strchr( psz_path, '/' ); s; s = strchr( s + 1, '/' ) )
+            *s = DIR_SEP_CHAR;
+#endif
+    }
+
     msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
              psz_mrl, psz_access, psz_demux, psz_path );
     if( !p_input->b_preparsing )
@@ -2446,18 +2474,6 @@ static int InputSourceInit( input_thread_t *p_input,
     {
         /* Now try a real access */
         in->p_access = access_New( p_input, psz_access, psz_demux, psz_path );
-
-        /* Access failed, URL encoded ? */
-        if( in->p_access == NULL && strchr( psz_path, '%' ) )
-        {
-            decode_URI( psz_path );
-
-            msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
-                     psz_access, psz_demux, psz_path );
-
-            in->p_access = access_New( p_input,
-                                        psz_access, psz_demux, psz_path );
-        }
         if( in->p_access == NULL )
         {
             msg_Err( p_input, "open of `%s' failed: %s", psz_mrl,
@@ -2993,7 +3009,7 @@ static void InputGetExtraFiles( input_thread_t *p_input,
         { ".part1.rar",   "%s.part%.1d.rar",2, 9 },
         { ".part01.rar",  "%s.part%.2d.rar",2, 99, },
         { ".part001.rar", "%s.part%.3d.rar",2, 999 },
-        { ".rar",         "%s.r%.2d",       1, 99 },
+        { ".rar",         "%s.r%.2d",       0, 99 },
         { NULL, NULL, 0, 0 }
     };