]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
Parse input specific options earlier to enable using :rate=something
[vlc] / src / input / input.c
index 9f99b60cc5aaf1efca5280ee50791e3ef7bb62d2..4672cd7e1da49252b92fb8b6856b89d2a9631bac 100644 (file)
@@ -335,6 +335,14 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     if( !p_input->p )
         return NULL;
 
+    /* Parse input options */
+    vlc_mutex_lock( &p_item->lock );
+    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) );
+    vlc_mutex_unlock( &p_item->lock );
+
     p_input->b_preparsing = b_quick;
     p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
 
@@ -349,11 +357,13 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     p_input->p->title = NULL;
     p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
     p_input->p->i_state = INIT_S;
-    p_input->p->i_rate = INPUT_RATE_DEFAULT
-                         / var_CreateGetFloat( p_input, "rate" );
-    /* Currently, the input rate variable is an integer. So we need to destroy
-     * the float variable inherited from the configuration. */
-    var_Destroy( p_input, "rate" );
+    double f_rate = var_InheritFloat( p_input, "rate" );
+    if( f_rate <= 0. )
+    {
+        msg_Warn( p_input, "Negative or zero rate values are forbidden" );
+        f_rate = 1.;
+    }
+    p_input->p->i_rate = INPUT_RATE_DEFAULT / f_rate;
     p_input->p->b_recording = false;
     memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
     TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
@@ -400,14 +410,6 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     p_input->p->i_control = 0;
     p_input->p->b_abort = false;
 
-    /* Parse input options */
-    vlc_mutex_lock( &p_item->lock );
-    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) );
-    vlc_mutex_unlock( &p_item->lock );
-
     /* Create Object Variables for private use only */
     input_ConfigVarInit( p_input );
 
@@ -1138,6 +1140,8 @@ static void UpdatePtsDelay( input_thread_t *p_input )
     const int i_cr_average = var_GetInteger( p_input, "cr-average" ) * i_pts_delay / DEFAULT_PTS_DELAY;
 
     /* */
+    es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, i_audio_delay );
+    es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, i_spu_delay );
     es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, i_cr_average );
 }
 
@@ -1920,19 +1924,13 @@ static bool Control( input_thread_t *p_input,
             break;
 
         case INPUT_CONTROL_SET_AUDIO_DELAY:
-            if( !es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, val.i_time ) )
-            {
-                input_SendEventAudioDelay( p_input, val.i_time );
-                UpdatePtsDelay( p_input );
-            }
+            input_SendEventAudioDelay( p_input, val.i_time );
+            UpdatePtsDelay( p_input );
             break;
 
         case INPUT_CONTROL_SET_SPU_DELAY:
-            if( !es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, val.i_time ) )
-            {
-                input_SendEventSubtitleDelay( p_input, val.i_time );
-                UpdatePtsDelay( p_input );
-            }
+            input_SendEventSubtitleDelay( p_input, val.i_time );
+            UpdatePtsDelay( p_input );
             break;
 
         case INPUT_CONTROL_SET_TITLE:
@@ -2639,26 +2637,11 @@ static int InputSourceInit( input_thread_t *p_input,
             psz_demux = in->p_access->psz_demux;
         }
 
-        {
-            /* Take access/stream redirections into account */
-            char *psz_real_path;
-            char *psz_buf = NULL;
-            if( in->p_stream->psz_path )
-            {
-                const char *psz_a, *psz_d;
-                psz_buf = strdup( in->p_stream->psz_path );
-                input_SplitMRL( &psz_a, &psz_d, &psz_real_path, psz_buf );
-            }
-            else
-            {
-                psz_real_path = psz_path;
-            }
-            in->p_demux = demux_New( p_input, p_input, psz_access, psz_demux,
-                                      psz_real_path,
-                                      in->p_stream, p_input->p->p_es_out,
-                                      p_input->b_preparsing );
-            free( psz_buf );
-        }
+        in->p_demux = demux_New( p_input, p_input, psz_access, psz_demux,
+                   /* Take access/stream redirections into account: */
+                   in->p_stream->psz_path ? in->p_stream->psz_path : psz_path,
+                                 in->p_stream, p_input->p->p_es_out,
+                                 p_input->b_preparsing );
 
         if( in->p_demux == NULL )
         {
@@ -3095,11 +3078,11 @@ static void input_ChangeState( input_thread_t *p_input, int i_state )
  * MRLSplit: parse the access, demux and url part of the
  *           Media Resource Locator.
  *****************************************************************************/
-void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux, char **ppsz_path,
-                     char *psz_dup )
+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;
+    const char *psz_access;
+    const char *psz_demux = "";
     char *psz_path;
 
     /* Either there is an access/demux specification before ://
@@ -3112,22 +3095,32 @@ void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux, char **p
 
         /* Separate access from demux (<access>/<demux>://<path>) */
         psz_access = psz_dup;
-        psz_demux = strchr( psz_access, '/' );
-        if( psz_demux )
-            *psz_demux++ = '\0';
 
         /* We really don't want module name substitution here! */
         if( psz_access[0] == '$' )
             psz_access++;
-        if( psz_demux && psz_demux[0] == '$' )
-            psz_demux++;
+
+        char *p = strchr( psz_access, '/' );
+        if( p )
+        {
+            *p = '\0';
+            psz_demux = p + 1;
+            if( psz_demux[0] == '$' )
+                psz_demux++;
+        }
     }
     else
     {
+#ifndef NDEBUG
+        fprintf( stderr, "%s(\"%s\"): not a valid URI!\n", __func__,
+                 psz_dup );
+#endif
         psz_path = psz_dup;
+        psz_access = "";
     }
-    *ppsz_access = psz_access ? psz_access : "";
-    *ppsz_demux = psz_demux ? psz_demux : "";
+
+    *ppsz_access = psz_access;
+    *ppsz_demux = psz_demux;
     *ppsz_path = psz_path;
 }