]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
Revert "Keep p_input->i_state when adding a subtitle on the fly.
[vlc] / src / input / input.c
index cc5e82813212de27d1785821d6f8537a86a7bc99..971284bcf013e2a7d7b96438c8549eeeee4ea63e 100644 (file)
@@ -53,8 +53,8 @@
  *****************************************************************************/
 static void Destructor( input_thread_t * p_input );
 
-static  int Run  ( input_thread_t *p_input );
-static  int RunAndDestroy  ( input_thread_t *p_input );
+static  void* Run            ( vlc_object_t *p_this );
+static  void* RunAndDestroy  ( vlc_object_t *p_this );
 
 static input_thread_t * Create  ( vlc_object_t *, input_item_t *,
                                   const char *, bool, sout_instance_t * );
@@ -223,7 +223,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
 
     /* Parse input options */
     vlc_mutex_lock( &p_item->lock );
-    assert( p_item->optflagc == p_item->i_options );
+    assert( (int)p_item->optflagc == p_item->i_options );
     for( i = 0; i < p_item->i_options; i++ )
         var_OptionParse( VLC_OBJECT(p_input), p_item->ppsz_options[i],
                          !!(p_item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED) );
@@ -396,7 +396,7 @@ int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
 
     if( b_block )
     {
-        RunAndDestroy( p_input );
+        RunAndDestroy( VLC_OBJECT(p_input) );
         return VLC_SUCCESS;
     }
     else
@@ -484,8 +484,9 @@ sout_instance_t * input_DetachSout( input_thread_t *p_input )
  * This is the "normal" thread that spawns the input processing chain,
  * reads the stream, cleans up and waits
  *****************************************************************************/
-static int Run( input_thread_t *p_input )
+static void* Run( vlc_object_t *p_this )
 {
+    input_thread_t *p_input = (input_thread_t *)p_this;
     /* Signal that the thread is launched */
     vlc_thread_ready( p_input );
 
@@ -499,7 +500,7 @@ static int Run( input_thread_t *p_input )
         /* Tell we're dead */
         p_input->b_dead = true;
 
-        return 0;
+        return NULL;
     }
 
     MainLoop( p_input );
@@ -531,7 +532,7 @@ static int Run( input_thread_t *p_input )
     /* Clean up */
     End( p_input );
 
-    return 0;
+    return NULL;
 }
 
 /*****************************************************************************
@@ -539,8 +540,9 @@ static int Run( input_thread_t *p_input )
  * This is the "just forget me" thread that spawns the input processing chain,
  * reads the stream, cleans up and releases memory
  *****************************************************************************/
-static int RunAndDestroy( input_thread_t *p_input )
+static void* RunAndDestroy( vlc_object_t *p_this )
 {
+    input_thread_t *p_input = (input_thread_t *)p_this;
     /* Signal that the thread is launched */
     vlc_thread_ready( p_input );
 
@@ -2054,6 +2056,7 @@ static void UpdateItemLength( input_thread_t *p_input, int64_t i_length )
  *****************************************************************************/
 static input_source_t *InputSourceNew( input_thread_t *p_input )
 {
+    (void)p_input;
     input_source_t *in = (input_source_t*) malloc( sizeof( input_source_t ) );
     if( in )
         memset( in, 0, sizeof( input_source_t ) );
@@ -2082,7 +2085,7 @@ static int InputSourceInit( input_thread_t *p_input,
     if( !p_input ) return VLC_EGENERIC;
 
     /* Split uri */
-    MRLSplit( psz_dup, &psz_access, &psz_demux, &psz_path );
+    input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
 
     msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
              psz_mrl, psz_access, psz_demux, psz_path );
@@ -2289,7 +2292,7 @@ static int InputSourceInit( input_thread_t *p_input,
             {
                 const char *psz_a, *psz_d;
                 psz_buf = strdup( in->p_access->psz_path );
-                MRLSplit( psz_buf, &psz_a, &psz_d, &psz_real_path );
+                input_SplitMRL( &psz_a, &psz_d, &psz_real_path, psz_buf );
             }
             else
             {
@@ -2671,8 +2674,8 @@ static void DemuxMeta( input_thread_t *p_input, vlc_meta_t *p_meta, demux_t *p_d
  * MRLSplit: parse the access, demux and url part of the
  *           Media Resource Locator.
  *****************************************************************************/
-void MRLSplit( char *psz_dup, const char **ppsz_access, const char **ppsz_demux,
-               char **ppsz_path )
+void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux, char **ppsz_path,
+                     char *psz_dup )
 {
     char *psz_access = NULL;
     char *psz_demux  = NULL;
@@ -2702,10 +2705,23 @@ void MRLSplit( char *psz_dup, const char **ppsz_access, const char **ppsz_demux,
     {
         psz_path = psz_dup;
     }
+    *ppsz_access = psz_access ? psz_access : (char*)"";
+    *ppsz_demux = psz_demux ? psz_demux : (char*)"";
+    *ppsz_path = psz_path;
+}
 
-    *ppsz_access = psz_access ? psz_access : "";
-    *ppsz_demux = psz_demux ? psz_demux : "";
-    *ppsz_path = psz_path ? psz_path : "";
+static inline bool next(char ** src)
+{
+    char *end;
+    errno = 0;
+    long result = strtol( *src, &end, 0 );
+    if( errno != 0 || result >= LONG_MAX || result <= LONG_MIN ||
+        end == *src )
+    {
+        return false;
+    }
+    *src = end;
+    return true;
 }
 
 /*****************************************************************************
@@ -2726,19 +2742,30 @@ static void MRLSections( input_thread_t *p_input, char *psz_source,
     /* Start by parsing titles and chapters */
     if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
 
+
     /* Check we are really dealing with a title/chapter section */
     psz_check = psz + 1;
     if( !*psz_check ) return;
-    if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
+    if( isdigit(*psz_check) )
+        if(!next(&psz_check)) return;
     if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
     if( *psz_check == ':' && ++psz_check )
-        if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
+    {
+        if( isdigit(*psz_check) )
+            if(!next(&psz_check)) return;
+    }
     if( *psz_check != '-' && *psz_check ) return;
     if( *psz_check == '-' && ++psz_check )
-        if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
+    {
+        if( isdigit(*psz_check) )
+            if(!next(&psz_check)) return;
+    }
     if( *psz_check != ':' && *psz_check ) return;
     if( *psz_check == ':' && ++psz_check )
-        if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
+    {
+        if( isdigit(*psz_check) )
+            if(!next(&psz_check)) return;
+    }
     if( *psz_check ) return;
 
     /* Separate start and end */
@@ -2844,8 +2871,7 @@ bool input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
 /*****************************************************************************
  * input_get_event_manager
  *****************************************************************************/
-vlc_event_manager_t *
-input_get_event_manager( input_thread_t *p_input )
+vlc_event_manager_t *input_get_event_manager( input_thread_t *p_input )
 {
     return &p_input->p->event_manager;
 }