]> git.sesse.net Git - vlc/blobdiff - src/audio_output/input.c
Sync PO files
[vlc] / src / audio_output / input.c
index 6a93b9b584d84d7406527f92f012a18b2c1186a7..b1798d566888da0369c5c7dae8b9fa2950cd37b4 100644 (file)
@@ -29,7 +29,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 
 #include <stdio.h>
 #include <string.h>
@@ -99,6 +99,8 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input )
         var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
         val.psz_string = (char*)"spectrum"; text.psz_string = _("Spectrum");
         var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
+        val.psz_string = (char*)"vuMeter"; text.psz_string = _("Vu meter");
+        var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
 
         /* Look for goom plugin */
         if( module_Exists( VLC_OBJECT(p_aout), "goom" ) )
@@ -244,7 +246,9 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input )
             }
 
             /* Create a VLC object */
-            p_filter = vlc_object_create( p_aout, sizeof(aout_filter_t) );
+            static const char typename[] = "audio filter";
+            p_filter = vlc_custom_create( p_aout, sizeof(*p_filter),
+                                          VLC_OBJECT_GENERIC, typename );
             if( p_filter == NULL )
             {
                 msg_Err( p_aout, "cannot add user filter %s (skipped)",
@@ -399,6 +403,21 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input )
     }
     p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
 
+    p_input->p_playback_rate_filter = NULL;
+    for( int i = 0; i < p_input->i_nb_filters; i++ )
+    {
+        aout_filter_t *p_filter = p_input->pp_filters[i];
+        if( strcmp( "scaletempo", p_filter->psz_object_name ) == 0 )
+        {
+          p_input->p_playback_rate_filter = p_filter;
+          break;
+        }
+    }
+    if( ! p_input->p_playback_rate_filter && p_input->i_nb_resamplers > 0 )
+    {
+        p_input->p_playback_rate_filter = p_input->pp_resamplers[0];
+    }
+
     aout_FiltersHintBuffers( p_aout, p_input->pp_filters,
                              p_input->i_nb_filters,
                              &p_input->input_alloc );
@@ -473,7 +492,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         vlc_mutex_unlock( &p_aout->mixer_lock );
     }
 
-    if( i_input_rate != INPUT_RATE_DEFAULT && p_input->i_nb_resamplers <= 0 )
+    if( i_input_rate != INPUT_RATE_DEFAULT && p_input->p_playback_rate_filter == NULL )
     {
         inputDrop( p_aout, p_input, p_buffer );
         return 0;
@@ -500,10 +519,10 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
     }
 #endif
 
-    /* Handle input rate change by modifying resampler input rate */
+    /* Handle input rate change, but keep drift correction */
     if( i_input_rate != p_input->i_last_input_rate )
     {
-        unsigned int * const pi_rate = &p_input->pp_resamplers[0]->input.i_rate;
+        unsigned int * const pi_rate = &p_input->p_playback_rate_filter->input.i_rate;
 #define F(r,ir) ( INPUT_RATE_DEFAULT * (r) / (ir) )
         const int i_delta = *pi_rate - F(p_input->input.i_rate,p_input->i_last_input_rate);
         *pi_rate = F(p_input->input.i_rate + i_delta, i_input_rate);
@@ -523,7 +542,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         /* The decoder is _very_ late. This can only happen if the user
          * pauses the stream (or if the decoder is buggy, which cannot
          * happen :). */
-        msg_Warn( p_aout, "computed PTS is out of range ("I64Fd"), "
+        msg_Warn( p_aout, "computed PTS is out of range (%"PRId64"), "
                   "clearing out", mdate() - start_date );
         vlc_mutex_lock( &p_aout->input_fifos_lock );
         aout_FifoSet( p_aout, &p_input->fifo, 0 );
@@ -539,7 +558,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
     {
         /* The decoder gives us f*cked up PTS. It's its business, but we
          * can't present it anyway, so drop the buffer. */
-        msg_Warn( p_aout, "PTS is out of range ("I64Fd"), dropping buffer",
+        msg_Warn( p_aout, "PTS is out of range (%"PRId64"), dropping buffer",
                   mdate() - p_buffer->start_date );
 
         inputDrop( p_aout, p_input, p_buffer );
@@ -549,10 +568,11 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
 
     /* If the audio drift is too big then it's not worth trying to resample
      * the audio. */
+    mtime_t i_pts_tolerance = 3 * AOUT_PTS_TOLERANCE * i_input_rate / INPUT_RATE_DEFAULT;
     if ( start_date != 0 &&
-         ( start_date < p_buffer->start_date - 3 * AOUT_PTS_TOLERANCE ) )
+         ( start_date < p_buffer->start_date - i_pts_tolerance ) )
     {
-        msg_Warn( p_aout, "audio drift is too big ("I64Fd"), clearing out",
+        msg_Warn( p_aout, "audio drift is too big (%"PRId64"), clearing out",
                   start_date - p_buffer->start_date );
         vlc_mutex_lock( &p_aout->input_fifos_lock );
         aout_FifoSet( p_aout, &p_input->fifo, 0 );
@@ -564,9 +584,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         start_date = 0;
     }
     else if ( start_date != 0 &&
-              ( start_date > p_buffer->start_date + 3 * AOUT_PTS_TOLERANCE ) )
+              ( start_date > p_buffer->start_date + i_pts_tolerance) )
     {
-        msg_Warn( p_aout, "audio drift is too big ("I64Fd"), dropping buffer",
+        msg_Warn( p_aout, "audio drift is too big (%"PRId64"), dropping buffer",
                   start_date - p_buffer->start_date );
         inputDrop( p_aout, p_input, p_buffer );
         return 0;
@@ -604,7 +624,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         else
             p_input->i_resampling_type = AOUT_RESAMPLING_UP;
 
-        msg_Warn( p_aout, "buffer is "I64Fd" %s, triggering %ssampling",
+        msg_Warn( p_aout, "buffer is %"PRId64" %s, triggering %ssampling",
                           drift > 0 ? drift : -drift,
                           drift > 0 ? "in advance" : "late",
                           drift > 0 ? "down" : "up");
@@ -627,11 +647,15 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
 
         /* Check if everything is back to normal, in which case we can stop the
          * resampling */
-        if( p_input->pp_resamplers[0]->input.i_rate == 1000 * p_input->input.i_rate / i_input_rate )
+        unsigned int i_nominal_rate =
+          (p_input->pp_resamplers[0] == p_input->p_playback_rate_filter)
+          ? INPUT_RATE_DEFAULT * p_input->input.i_rate / i_input_rate
+          : p_input->input.i_rate;
+        if( p_input->pp_resamplers[0]->input.i_rate == i_nominal_rate )
         {
             p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
-            msg_Warn( p_aout, "resampling stopped after "I64Fi" usec "
-                      "(drift: "I64Fi")",
+            msg_Warn( p_aout, "resampling stopped after %"PRIi64" usec "
+                      "(drift: %"PRIi64")",
                       mdate() - p_input->i_resamp_start_date,
                       p_buffer->start_date - start_date);
         }
@@ -731,8 +755,10 @@ static void inputResamplingStop( aout_input_t *p_input )
     p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
     if( p_input->i_nb_resamplers != 0 )
     {
-        p_input->pp_resamplers[0]->input.i_rate = INPUT_RATE_DEFAULT *
-                            p_input->input.i_rate / p_input->i_last_input_rate;
+        p_input->pp_resamplers[0]->input.i_rate =
+            ( p_input->pp_resamplers[0] == p_input->p_playback_rate_filter )
+            ? INPUT_RATE_DEFAULT * p_input->input.i_rate / p_input->i_last_input_rate
+            : p_input->input.i_rate;
         p_input->pp_resamplers[0]->b_continuity = false;
     }
 }
@@ -740,47 +766,8 @@ static void inputResamplingStop( aout_input_t *p_input )
 static int ChangeFiltersString( aout_instance_t * p_aout, const char* psz_variable,
                                  const char *psz_name, bool b_add )
 {
-    vlc_value_t val;
-    char *psz_parser;
-
-    var_Get( p_aout, psz_variable, &val );
-
-    if( !val.psz_string ) val.psz_string = strdup("");
-
-    psz_parser = strstr( val.psz_string, psz_name );
-
-    if( b_add )
-    {
-        if( !psz_parser )
-        {
-            psz_parser = val.psz_string;
-            asprintf( &val.psz_string, (*val.psz_string) ? "%s:%s" : "%s%s",
-                      val.psz_string, psz_name );
-            free( psz_parser );
-        }
-        else
-        {
-            return 0;
-        }
-    }
-    else
-    {
-        if( psz_parser )
-        {
-            memmove( psz_parser, psz_parser + strlen(psz_name) +
-                     (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
-                     strlen(psz_parser + strlen(psz_name)) + 1 );
-        }
-        else
-        {
-            free( val.psz_string );
-            return 0;
-        }
-    }
-
-    var_Set( p_aout, psz_variable, val );
-    free( val.psz_string );
-    return 1;
+    return AoutChangeFilterString( VLC_OBJECT(p_aout), p_aout,
+                                   psz_variable, psz_name, b_add ) ? 1 : 0;
 }
 
 static int VisualizationCallback( vlc_object_t *p_this, char const *psz_cmd,
@@ -789,7 +776,6 @@ static int VisualizationCallback( vlc_object_t *p_this, char const *psz_cmd,
     aout_instance_t *p_aout = (aout_instance_t *)p_this;
     char *psz_mode = newval.psz_string;
     vlc_value_t val;
-    int i;
     (void)psz_cmd; (void)oldval; (void)p_data;
 
     if( !psz_mode || !*psz_mode )
@@ -825,10 +811,7 @@ static int VisualizationCallback( vlc_object_t *p_this, char const *psz_cmd,
     }
 
     /* That sucks */
-    for( i = 0; i < p_aout->i_nb_inputs; i++ )
-    {
-        p_aout->pp_inputs[i]->b_restart = true;
-    }
+    AoutInputsMarkToRestart( p_aout );
 
     return VLC_SUCCESS;
 }
@@ -839,7 +822,6 @@ static int EqualizerCallback( vlc_object_t *p_this, char const *psz_cmd,
     aout_instance_t *p_aout = (aout_instance_t *)p_this;
     char *psz_mode = newval.psz_string;
     vlc_value_t val;
-    int i;
     int i_ret;
     (void)psz_cmd; (void)oldval; (void)p_data;
 
@@ -860,13 +842,7 @@ static int EqualizerCallback( vlc_object_t *p_this, char const *psz_cmd,
 
     /* That sucks */
     if( i_ret == 1 )
-    {
-        for( i = 0; i < p_aout->i_nb_inputs; i++ )
-        {
-            p_aout->pp_inputs[i]->b_restart = true;
-        }
-    }
-
+        AoutInputsMarkToRestart( p_aout );
     return VLC_SUCCESS;
 }