]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
Some more const
[vlc] / src / input / input.c
index 3f12c76d33018e92f181d86f7f60b75f2cf4ba57..790bd6366ef827315b4031830f9bdd9b09f6bc7e 100644 (file)
@@ -39,6 +39,7 @@
 #include "vlc_playlist.h"
 #include "vlc_interface.h"
 #include "vlc_interaction.h"
+#include "vlc_url.h"
 
 #include "charset.h"
 
@@ -69,12 +70,11 @@ static int  UpdateMeta( input_thread_t * );
 
 static void UpdateItemLength( input_thread_t *, int64_t i_length );
 
-static void DecodeUrl( char * );
 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
 
 static input_source_t *InputSourceNew( input_thread_t *);
 static int  InputSourceInit( input_thread_t *, input_source_t *,
-                             char *, char *psz_forced_demux );
+                             char *, const char *psz_forced_demux );
 static void InputSourceClean( input_thread_t *, input_source_t * );
 
 static void SlaveDemux( input_thread_t *p_input );
@@ -270,7 +270,6 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
     return __input_CreateThread2( p_parent, p_item, NULL );
 }
 
-
 /* Gruik ! */
 input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
                                        input_item_t *p_item,
@@ -279,6 +278,9 @@ input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
     input_thread_t *p_input = NULL;      /* thread descriptor */
 
     p_input = Create( p_parent, p_item, psz_header, VLC_FALSE );
+    if( !p_input )
+        return NULL;
+
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
 
@@ -286,6 +288,7 @@ input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
     if( vlc_thread_create( p_input, "input", Run,
                             VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
     {
+        input_ChangeState( p_input, ERROR_S );
         msg_Err( p_input, "cannot create input thread" );
         vlc_object_detach( p_input );
         vlc_object_destroy( p_input );
@@ -295,7 +298,6 @@ input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
     return p_input;
 }
 
-
 /**
  * Initialize an input thread and run it. This thread will clean after himself,
  * you can forget about it. It can work either in blocking or non-blocking mode
@@ -311,6 +313,9 @@ int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
     input_thread_t *p_input = NULL;         /* thread descriptor */
 
     p_input = Create( p_parent, p_item, NULL, VLC_FALSE );
+    if( !p_input )
+        return VLC_EGENERIC;
+
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
 
@@ -324,6 +329,7 @@ int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
         if( vlc_thread_create( p_input, "input", RunAndClean,
                                VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
         {
+            input_ChangeState( p_input, ERROR_S );
             msg_Err( p_input, "cannot create input thread" );
             vlc_object_detach( p_input );
             vlc_object_destroy( p_input );
@@ -347,6 +353,9 @@ int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
 
     /* Allocate descriptor */
     p_input = Create( p_parent, p_item, NULL, VLC_TRUE );
+    if( !p_input )
+        return VLC_EGENERIC;
+
     p_input->i_flags |= OBJECT_FLAGS_QUIET;
     p_input->i_flags |= OBJECT_FLAGS_NOINTERACT;
 
@@ -380,7 +389,7 @@ void input_StopThread( input_thread_t *p_input )
     /* Set die for input */
     p_input->b_die = VLC_TRUE;
 
-    /* We cannot touch p_input fields directly (we can from another thread),
+    /* We cannot touch p_input fields directly (we come from another thread),
      * so use the vlc_object_find way, it's perfectly safe */
 
     /* Set die for all access */
@@ -442,6 +451,7 @@ static int Run( input_thread_t *p_input )
     {
         /* If we failed, wait before we are killed, and exit */
         p_input->b_error = VLC_TRUE;
+        playlist_Signal( pl_Get( p_input ) );
 
         Error( p_input );
 
@@ -468,6 +478,7 @@ static int Run( input_thread_t *p_input )
 
         /* We have finished */
         p_input->b_eof = VLC_TRUE;
+        playlist_Signal( pl_Get( p_input ) );
     }
 
     /* Wait until we are asked to die */
@@ -527,7 +538,6 @@ static int RunAndClean( input_thread_t *p_input )
     return 0;
 }
 
-
 /*****************************************************************************
  * Main loop: Fill buffers from access, and demux
  *****************************************************************************/
@@ -577,6 +587,7 @@ static void MainLoop( input_thread_t *p_input )
                 {
                     /* End of file - we do not set b_die because only the
                      * playlist is allowed to do so. */
+                    input_ChangeState( p_input, END_S );
                     msg_Dbg( p_input, "EOF reached" );
                     p_input->input.b_eof = VLC_TRUE;
                 }
@@ -696,7 +707,6 @@ static void MainLoop( input_thread_t *p_input )
     }
 }
 
-
 static int Init( input_thread_t * p_input )
 {
     char *psz;
@@ -752,6 +762,7 @@ static int Init( input_thread_t * p_input )
             p_input->p_sout = sout_NewInstance( p_input, psz );
             if( p_input->p_sout == NULL )
             {
+                input_ChangeState( p_input, ERROR_S );
                 msg_Err( p_input, "cannot start stream output instance, " \
                                   "aborting" );
                 free( psz );
@@ -869,7 +880,6 @@ static int Init( input_thread_t * p_input )
             p_input->i_stop = 0;
         }
 
-
         /* Load subtitles */
         /* Get fps and set it if not already set */
         if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
@@ -895,7 +905,6 @@ static int Init( input_thread_t * p_input )
             var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
         }
 
-
         /* Look for and add subtitle files */
         psz_subtitle = var_GetString( p_input, "sub-file" );
         if( *psz_subtitle )
@@ -911,7 +920,6 @@ static int Init( input_thread_t * p_input )
             char **subs = subtitles_Detect( p_input, psz_autopath,
                                             p_input->input.p_item->psz_uri );
             input_source_t *sub;
-
             i = 0;
 
             /* Try to autoselect the first autodetected subtitles file
@@ -1085,11 +1093,13 @@ static int Init( input_thread_t * p_input )
     }
 
     /* initialization is complete */
-    input_ChangeState(p_input, PLAYING_S);
+    input_ChangeState( p_input, PLAYING_S );
 
     return VLC_SUCCESS;
 
 error:
+    input_ChangeState( p_input, ERROR_S );
+
     if( p_input->p_es_out )
         input_EsOutDelete( p_input->p_es_out );
 
@@ -1116,6 +1126,7 @@ static void Error( input_thread_t *p_input )
     while( !p_input->b_die )
     {
         /* Sleep a while */
+        input_ChangeState( p_input, ERROR_S );
         msleep( INPUT_IDLE_SLEEP );
     }
 }
@@ -1130,7 +1141,7 @@ static void End( input_thread_t * p_input )
     msg_Dbg( p_input, "closing input" );
 
     /* We are at the end */
-    input_ChangeState(p_input, END_S);
+    input_ChangeState( p_input, END_S );
 
     /* Clean control variables */
     input_ControlVarClean( p_input );
@@ -1237,6 +1248,10 @@ static inline int ControlPopNoLock( input_thread_t *p_input,
 static void ControlReduce( input_thread_t *p_input )
 {
     int i;
+
+    if( !p_input )
+        return;
+
     for( i = 1; i < p_input->i_control; i++ )
     {
         const int i_lt = p_input->control[i-1].i_type;
@@ -1907,7 +1922,7 @@ static input_source_t *InputSourceNew( input_thread_t *p_input )
  *****************************************************************************/
 static int InputSourceInit( input_thread_t *p_input,
                             input_source_t *in, char *psz_mrl,
-                            char *psz_forced_demux )
+                            const char *psz_forced_demux )
 {
     char *psz_dup = strdup( psz_mrl );
     char *psz_access;
@@ -1918,6 +1933,7 @@ static int InputSourceInit( input_thread_t *p_input,
     vlc_value_t val;
 
     if( !in ) return VLC_EGENERIC;
+    if( !p_input ) return VLC_EGENERIC;
 
     /* Split uri */
     if( !p_input->b_preparsing )
@@ -2007,7 +2023,7 @@ static int InputSourceInit( input_thread_t *p_input,
     {
         int64_t i_pts_delay;
 
-        input_ChangeState( p_input, OPENING_S);
+        input_ChangeState( p_input, OPENING_S );
 
         /* Now try a real access */
         in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
@@ -2016,7 +2032,7 @@ static int InputSourceInit( input_thread_t *p_input,
         /* Access failed, URL encoded ? */
         if( in->p_access == NULL && strchr( psz_path, '%' ) )
         {
-            DecodeUrl( psz_path );
+            decode_URI( psz_path );
 
             msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
                      psz_access, psz_demux, psz_path );
@@ -2105,7 +2121,7 @@ static int InputSourceInit( input_thread_t *p_input,
             var_Set( p_input, "seekable", val );
         }
 
-        input_ChangeState( p_input, BUFFERING_S);
+        input_ChangeState( p_input, BUFFERING_S );
 
         /* Create the stream_t */
         in->p_stream = stream_AccessNew( in->p_access, p_input->b_preparsing );
@@ -2158,6 +2174,8 @@ static int InputSourceInit( input_thread_t *p_input,
     return VLC_SUCCESS;
 
 error:
+    input_ChangeState( p_input, ERROR_S );
+
     if( in->p_demux )
         demux2_Delete( in->p_demux );
 
@@ -2200,7 +2218,7 @@ static void SlaveDemux( input_thread_t *p_input )
 {
     int64_t i_time;
     int i;
+
     if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
     {
         msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
@@ -2253,6 +2271,8 @@ static void SlaveSeek( input_thread_t *p_input )
     int64_t i_time;
     int i;
 
+    if( !p_input ) return;
+
     if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
     {
         msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
@@ -2270,6 +2290,7 @@ static void SlaveSeek( input_thread_t *p_input )
         }
     }
 }
+
 /*****************************************************************************
  * InputMetaUser:
  *****************************************************************************/
@@ -2299,51 +2320,13 @@ static void InputMetaUser( input_thread_t *p_input )
 #undef GET_META
 }
 
-/*****************************************************************************
- * DecodeUrl: decode a given encoded url
- *****************************************************************************/
-static void DecodeUrl( char *psz )
-{
-    char *dup = strdup( psz );
-    char *p = dup;
-
-    while( *p )
-    {
-        if( *p == '%' )
-        {
-            char val[3];
-            p++;
-            if( !*p )
-            {
-                break;
-            }
-
-            val[0] = *p++;
-            val[1] = *p++;
-            val[2] = '\0';
-
-            *psz++ = strtol( val, NULL, 16 );
-        }
-        else if( *p == '+' )
-        {
-            *psz++ = ' ';
-            p++;
-        }
-        else
-        {
-            *psz++ = *p++;
-        }
-    }
-    if( psz ) *psz++  ='\0';
-    if( dup ) free( dup );
-}
-
 /*****************************************************************************
  * MRLSplit: parse the access, demux and url part of the
  *           Media Resource Locator.
  *****************************************************************************/
 void MRLSplit( vlc_object_t *p_input, char *psz_dup,
-               char **ppsz_access, char **ppsz_demux, char **ppsz_path )
+               const char **ppsz_access, const char **ppsz_demux,
+               const char **ppsz_path )
 {
     char *psz_access = NULL;
     char *psz_demux  = NULL;
@@ -2528,3 +2511,4 @@ vlc_bool_t input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
 
     return VLC_TRUE;
 }
+