]> git.sesse.net Git - vlc/blobdiff - src/audio_output/input.c
aout: privatize some attributes
[vlc] / src / audio_output / input.c
index 4c2cafca5600a74e234231952b317186a2cb63ed..fcacdbf45ba11f34a0c4f61228b2254716cf32c4 100644 (file)
 
 #include <vlc_input.h>
 #include <vlc_vout.h>                  /* for vout_Request */
+#include <vlc_modules.h>
 
 #include <vlc_aout.h>
+#include <vlc_filter.h>
 #include <libvlc.h>
 
 #include "aout_internal.h"
 
-#define AOUT_ASSERT_MIXER_LOCKED vlc_assert_locked( &p_aout->mixer_lock )
-#define AOUT_ASSERT_INPUT_LOCKED vlc_assert_locked( &p_input->lock )
+#define AOUT_ASSERT_LOCKED vlc_assert_locked( &p_aout->lock )
 
-static void inputFailure( aout_instance_t *, aout_input_t *, const char * );
+static void inputFailure( audio_output_t *, aout_input_t *, const char * );
 static void inputDrop( aout_input_t *, aout_buffer_t * );
 static void inputResamplingStop( aout_input_t *p_input );
 
@@ -59,7 +60,7 @@ static int EqualizerCallback( vlc_object_t *, char const *,
                               vlc_value_t, vlc_value_t, void * );
 static int ReplayGainCallback( vlc_object_t *, char const *,
                                vlc_value_t, vlc_value_t, void * );
-static void ReplayGainSelect( aout_instance_t *, aout_input_t * );
+static void ReplayGainSelect( audio_output_t *, aout_input_t * );
 
 static vout_thread_t *RequestVout( void *,
                                    vout_thread_t *, video_format_t *, bool );
@@ -67,8 +68,9 @@ static vout_thread_t *RequestVout( void *,
 /*****************************************************************************
  * aout_InputNew : allocate a new input and rework the filter pipeline
  *****************************************************************************/
-int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_request_vout_t *p_request_vout )
+int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_request_vout_t *p_request_vout )
 {
+    aout_owner_t *owner = aout_owner (p_aout);
     audio_sample_format_t chain_input_format;
     audio_sample_format_t chain_output_format;
     vlc_value_t val, text;
@@ -80,8 +82,7 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
     p_input->i_nb_resamplers = p_input->i_nb_filters = 0;
 
     /* Prepare FIFO. */
-    aout_FifoInit( p_aout, &p_input->mixer.fifo, p_aout->mixer_format.i_rate );
-    p_input->mixer.begin = NULL;
+    aout_FifoInit (p_aout, &p_input->fifo, owner->mixer_format.i_rate);
 
     /* */
     if( p_request_vout )
@@ -96,7 +97,7 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
 
     /* Prepare format structure */
     chain_input_format  = p_input->input;
-    chain_output_format = p_aout->mixer_format;
+    chain_output_format = owner->mixer_format;
     chain_output_format.i_rate = p_input->input.i_rate;
     aout_FormatPrepare( &chain_output_format );
 
@@ -222,15 +223,10 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
         var_Create( p_aout, "audio-replay-gain-peak-protection",
                     VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     }
-    if( var_Type( p_aout, "audio-time-stretch" ) == 0 )
-    {
-        var_Create( p_aout, "audio-time-stretch",
-                    VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    }
 
     psz_filters = var_GetString( p_aout, "audio-filter" );
     psz_visual = var_GetString( p_aout, "audio-visual");
-    psz_scaletempo = var_GetBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
+    psz_scaletempo = var_InheritBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
 
     p_input->b_recycle_vout = psz_visual && *psz_visual;
 
@@ -248,7 +244,7 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
 
         while( psz_parser && *psz_parser )
         {
-            aout_filter_t * p_filter = NULL;
+            filter_t * p_filter = NULL;
 
             if( p_input->i_nb_filters >= AOUT_MAX_FILTERS )
             {
@@ -270,9 +266,8 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
             }
 
             /* Create a VLC object */
-            static const char typename[] = "audio filter";
             p_filter = vlc_custom_create( p_aout, sizeof(*p_filter),
-                                          VLC_OBJECT_GENERIC, typename );
+                                          "audio filter" );
             if( p_filter == NULL )
             {
                 msg_Err( p_aout, "cannot add user filter %s (skipped)",
@@ -281,8 +276,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
                 continue;
             }
 
-            vlc_object_attach( p_filter , p_aout );
-
             p_filter->p_owner = malloc( sizeof(*p_filter->p_owner) );
             p_filter->p_owner->p_aout  = p_aout;
             p_filter->p_owner->p_input = p_input;
@@ -290,14 +283,16 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
             /* request format */
             memcpy( &p_filter->fmt_in.audio, &chain_output_format,
                     sizeof(audio_sample_format_t) );
+            p_filter->fmt_in.i_codec = chain_output_format.i_format;
             memcpy( &p_filter->fmt_out.audio, &chain_output_format,
                     sizeof(audio_sample_format_t) );
-
+            p_filter->fmt_out.i_codec = chain_output_format.i_format;
+            p_filter->pf_audio_buffer_new = aout_FilterBufferNew;
 
             /* try to find the requested filter */
             if( i_visual == 2 ) /* this can only be a visualization module */
             {
-                p_filter->p_module = module_need( p_filter, "visualization",
+                p_filter->p_module = module_need( p_filter, "visualization2",
                                                   psz_parser, true );
             }
             else /* this can be a audio filter module as well as a visualization module */
@@ -327,7 +322,7 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
                         memcpy( &p_filter->fmt_out.audio, &chain_output_format,
                                 sizeof(audio_sample_format_t) );
                         p_filter->p_module = module_need( p_filter,
-                                                          "visualization",
+                                                          "visualization2",
                                                           psz_parser, true );
                     }
                 }
@@ -340,7 +335,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
                          psz_parser );
 
                 free( p_filter->p_owner );
-                vlc_object_detach( p_filter );
                 vlc_object_release( p_filter );
 
                 psz_parser = psz_next;
@@ -348,29 +342,23 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
             }
 
             /* complete the filter chain if necessary */
-            if ( !AOUT_FMTS_IDENTICAL( &chain_input_format,
-                                       &p_filter->fmt_in.audio ) )
+            if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
+                                             &p_input->i_nb_filters,
+                                             &chain_input_format,
+                                             &p_filter->fmt_in.audio ) < 0 )
             {
-                if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
-                                                 &p_input->i_nb_filters,
-                                                 &chain_input_format,
-                                                 &p_filter->fmt_in.audio ) < 0 )
-                {
-                    msg_Err( p_aout, "cannot add user filter %s (skipped)",
-                             psz_parser );
+                msg_Err( p_aout, "cannot add user filter %s (skipped)",
+                         psz_parser );
 
-                    module_unneed( p_filter, p_filter->p_module );
-                    free( p_filter->p_owner );
-                    vlc_object_detach( p_filter );
-                    vlc_object_release( p_filter );
+                module_unneed( p_filter, p_filter->p_module );
+                free( p_filter->p_owner );
+                vlc_object_release( p_filter );
 
-                    psz_parser = psz_next;
-                    continue;
-                }
+                psz_parser = psz_next;
+                continue;
             }
 
             /* success */
-            p_filter->b_continuity = false;
             p_input->pp_filters[p_input->i_nb_filters++] = p_filter;
             memcpy( &chain_input_format, &p_filter->fmt_out.audio,
                     sizeof( audio_sample_format_t ) );
@@ -387,47 +375,35 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
     free( psz_scaletempo );
 
     /* complete the filter chain if necessary */
-    if ( !AOUT_FMTS_IDENTICAL( &chain_input_format, &chain_output_format ) )
+    if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
+                                     &p_input->i_nb_filters,
+                                     &chain_input_format,
+                                     &chain_output_format ) < 0 )
     {
-        if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
-                                         &p_input->i_nb_filters,
-                                         &chain_input_format,
-                                         &chain_output_format ) < 0 )
-        {
-            inputFailure( p_aout, p_input, "couldn't set an input pipeline" );
-            return -1;
-        }
+        inputFailure( p_aout, p_input, "couldn't set an input pipeline" );
+        return -1;
     }
 
-    /* Prepare hints for the buffer allocator. */
-    p_input->input_alloc.b_alloc = true;
-    p_input->input_alloc.i_bytes_per_sec = -1;
-
     /* Create resamplers. */
-    if ( !AOUT_FMT_NON_LINEAR( &p_aout->mixer_format ) )
+    if (!AOUT_FMT_NON_LINEAR(&owner->mixer_format))
     {
         chain_output_format.i_rate = (__MAX(p_input->input.i_rate,
-                                            p_aout->mixer_format.i_rate)
+                                            owner->mixer_format.i_rate)
                                  * (100 + AOUT_MAX_RESAMPLING)) / 100;
-        if ( chain_output_format.i_rate == p_aout->mixer_format.i_rate )
+        if ( chain_output_format.i_rate == owner->mixer_format.i_rate )
         {
             /* Just in case... */
             chain_output_format.i_rate++;
         }
-        if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_resamplers,
-                                         &p_input->i_nb_resamplers,
-                                         &chain_output_format,
-                                         &p_aout->mixer_format ) < 0 )
+        if (aout_FiltersCreatePipeline (p_aout, p_input->pp_resamplers,
+                                        &p_input->i_nb_resamplers,
+                                        &chain_output_format,
+                                        &owner->mixer_format) < 0)
         {
             inputFailure( p_aout, p_input, "couldn't set a resampler pipeline");
             return -1;
         }
 
-        aout_FiltersHintBuffers( p_aout, p_input->pp_resamplers,
-                                 p_input->i_nb_resamplers,
-                                 &p_input->input_alloc );
-        p_input->input_alloc.b_alloc = true;
-
         /* Setup the initial rate of the resampler */
         p_input->pp_resamplers[0]->fmt_in.audio.i_rate = p_input->input.i_rate;
     }
@@ -438,23 +414,10 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
         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 );
-    p_input->input_alloc.b_alloc = true;
-
-    /* i_bytes_per_sec is still == -1 if no filters */
-    p_input->input_alloc.i_bytes_per_sec = __MAX(
-                                    p_input->input_alloc.i_bytes_per_sec,
-                                    (int)(p_input->input.i_bytes_per_frame
-                                     * p_input->input.i_rate
-                                     / p_input->input.i_frame_length) );
-
     ReplayGainSelect( p_aout, p_input );
 
     /* Success */
     p_input->b_error = false;
-    p_input->b_restart = false;
     p_input->i_last_input_rate = INPUT_RATE_DEFAULT;
 
     return 0;
@@ -465,9 +428,9 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
  *****************************************************************************
  * This function must be entered with the mixer lock.
  *****************************************************************************/
-int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input )
+int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input )
 {
-    AOUT_ASSERT_MIXER_LOCKED;
+    AOUT_ASSERT_LOCKED;
     if ( p_input->b_error )
         return 0;
 
@@ -479,71 +442,69 @@ int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input )
     p_input->b_recycle_vout = psz_visual && *psz_visual;
     free( psz_visual );
 
-    aout_FiltersDestroyPipeline( p_aout, p_input->pp_filters,
-                                 p_input->i_nb_filters );
+    aout_FiltersDestroyPipeline( p_input->pp_filters, p_input->i_nb_filters );
     p_input->i_nb_filters = 0;
-    aout_FiltersDestroyPipeline( p_aout, p_input->pp_resamplers,
+    aout_FiltersDestroyPipeline( p_input->pp_resamplers,
                                  p_input->i_nb_resamplers );
     p_input->i_nb_resamplers = 0;
-    aout_FifoDestroy( p_aout, &p_input->mixer.fifo );
+    aout_FifoDestroy( &p_input->fifo );
 
     return 0;
 }
 
 /*****************************************************************************
- * aout_InputPlay : play a buffer
+ * aout_InputCheckAndRestart : restart an input
  *****************************************************************************
- * This function must be entered with the input lock.
+ * This function must be entered with the input and mixer lock.
  *****************************************************************************/
-/* XXX Do not activate it !! */
-//#define AOUT_PROCESS_BEFORE_CHEKS
-int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
-                    aout_buffer_t * p_buffer, int i_input_rate )
+void aout_InputCheckAndRestart( audio_output_t * p_aout, aout_input_t * p_input )
 {
-    mtime_t start_date;
-    AOUT_ASSERT_INPUT_LOCKED;
+    aout_owner_t *owner = aout_owner (p_aout);
+    AOUT_ASSERT_LOCKED;
 
-    if( p_input->b_restart )
-    {
-        aout_fifo_t fifo;
-        uint8_t     *p_first_byte_to_mix;
-        bool        b_paused;
-        mtime_t     i_pause_date;
-
-        aout_lock_mixer( p_aout );
-        aout_lock_input_fifos( p_aout );
+    if( !p_input->b_restart )
+        return;
 
-        /* A little trick to avoid loosing our input fifo and properties */
+    /* A little trick to avoid loosing our input fifo and properties */
 
-        p_first_byte_to_mix = p_input->mixer.begin;
-        fifo = p_input->mixer.fifo;
-        b_paused = p_input->b_paused;
-        i_pause_date = p_input->i_pause_date;
+    aout_fifo_t fifo = p_input->fifo;
+    mtime_t i_pause_date = p_input->i_pause_date;
 
-        aout_FifoInit( p_aout, &p_input->mixer.fifo, p_aout->mixer_format.i_rate );
+    aout_FifoInit (p_aout, &p_input->fifo, owner->mixer_format.i_rate);
 
-        aout_InputDelete( p_aout, p_input );
+    aout_InputDelete( p_aout, p_input );
 
-        aout_InputNew( p_aout, p_input, &p_input->request_vout );
-        p_input->mixer.begin = p_first_byte_to_mix;
-        p_input->mixer.fifo = fifo;
-        p_input->b_paused = b_paused;
-        p_input->i_pause_date = i_pause_date;
+    aout_InputNew( p_aout, p_input, &p_input->request_vout );
+    p_input->fifo = fifo;
+    p_input->i_pause_date = i_pause_date;
 
-        aout_unlock_input_fifos( p_aout );
-        aout_unlock_mixer( p_aout );
-    }
+    p_input->b_restart = false;
+}
+/*****************************************************************************
+ * aout_InputPlay : play a buffer
+ *****************************************************************************
+ * This function must be entered with the input lock.
+ *****************************************************************************/
+/* XXX Do not activate it !! */
+//#define AOUT_PROCESS_BEFORE_CHEKS
+block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
+                         block_t *p_buffer, int i_input_rate )
+{
+    mtime_t start_date;
+    AOUT_ASSERT_LOCKED;
 
     if( i_input_rate != INPUT_RATE_DEFAULT && p_input->p_playback_rate_filter == NULL )
     {
         inputDrop( p_input, p_buffer );
-        return 0;
+        return NULL;
     }
 
 #ifdef AOUT_PROCESS_BEFORE_CHEKS
     /* Run pre-filters. */
     aout_FiltersPlay( p_aout, p_input->pp_filters, p_input->i_nb_filters,
                       &p_buffer );
+    if( !p_buffer )
+        return NULL;
 
     /* Actually run the resampler now. */
     if ( p_input->i_nb_resamplers > 0 )
@@ -554,10 +515,12 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
                           &p_buffer );
     }
 
+    if( !p_buffer )
+        return NULL;
     if( p_buffer->i_nb_samples <= 0 )
     {
-        aout_BufferFree( p_buffer );
-        return 0;
+        block_Release( p_buffer );
+        return NULL;
     }
 #endif
 
@@ -572,81 +535,80 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         p_input->i_last_input_rate = i_input_rate;
     }
 
+    mtime_t now = mdate();
+
     /* We don't care if someone changes the start date behind our back after
      * this. We'll deal with that when pushing the buffer, and compensate
      * with the next incoming buffer. */
-    aout_lock_input_fifos( p_aout );
-    start_date = aout_FifoNextStart( p_aout, &p_input->mixer.fifo );
-    aout_unlock_input_fifos( p_aout );
+    start_date = aout_FifoNextStart( &p_input->fifo );
 
-    if ( start_date != 0 && start_date < mdate() )
+    if ( start_date != VLC_TS_INVALID && start_date < now )
     {
         /* 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 (%"PRId64"), "
-                  "clearing out", mdate() - start_date );
-        aout_lock_input_fifos( p_aout );
-        aout_FifoSet( p_aout, &p_input->mixer.fifo, 0 );
-        p_input->mixer.begin = NULL;
-        aout_unlock_input_fifos( p_aout );
+                  "clearing out", now - start_date );
+        aout_FifoReset( &p_input->fifo );
+        aout_OutputFlush( p_aout, false );
         if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
             msg_Warn( p_aout, "timing screwed, stopping resampling" );
         inputResamplingStop( p_input );
-        start_date = 0;
+        p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY;
+        start_date = VLC_TS_INVALID;
     }
 
-    if ( p_buffer->i_pts < mdate() + AOUT_MIN_PREPARE_TIME )
+    if ( p_buffer->i_pts < now + AOUT_MIN_PREPARE_TIME )
     {
         /* 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 (%"PRId64"), dropping buffer",
-                  mdate() - p_buffer->i_pts );
-
+                  now - p_buffer->i_pts );
         inputDrop( p_input, p_buffer );
         inputResamplingStop( p_input );
-        return 0;
+        return NULL;
     }
 
     /* 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->i_pts - i_pts_tolerance ) )
-    {
-        msg_Warn( p_aout, "audio drift is too big (%"PRId64"), clearing out",
-                  start_date - p_buffer->i_pts );
-        aout_lock_input_fifos( p_aout );
-        aout_FifoSet( p_aout, &p_input->mixer.fifo, 0 );
-        p_input->mixer.begin = NULL;
-        aout_unlock_input_fifos( p_aout );
+    if( start_date == VLC_TS_INVALID )
+        start_date = p_buffer->i_pts;
+
+    mtime_t drift = start_date - p_buffer->i_pts;
+
+    if( drift < -i_input_rate * 3 * AOUT_MAX_PTS_ADVANCE / INPUT_RATE_DEFAULT )
+    {
+        msg_Warn( p_aout, "buffer way too early (%"PRId64"), clearing queue",
+                  drift );
+        aout_FifoReset( &p_input->fifo );
+        aout_OutputFlush( p_aout, false );
         if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
             msg_Warn( p_aout, "timing screwed, stopping resampling" );
         inputResamplingStop( p_input );
-        start_date = 0;
+        p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY;
+        start_date = p_buffer->i_pts;
+        drift = 0;
     }
-    else if ( start_date != 0 &&
-              ( start_date > p_buffer->i_pts + i_pts_tolerance) )
+    else
+    if( drift > +i_input_rate * 3 * AOUT_MAX_PTS_DELAY / INPUT_RATE_DEFAULT )
     {
-        msg_Warn( p_aout, "audio drift is too big (%"PRId64"), dropping buffer",
-                  start_date - p_buffer->i_pts );
+        msg_Warn( p_aout, "buffer way too late (%"PRId64"), dropping buffer",
+                  drift );
         inputDrop( p_input, p_buffer );
-        return 0;
+        return NULL;
     }
 
-    if ( start_date == 0 ) start_date = p_buffer->i_pts;
-
 #ifndef AOUT_PROCESS_BEFORE_CHEKS
     /* Run pre-filters. */
-    aout_FiltersPlay( p_aout, p_input->pp_filters, p_input->i_nb_filters,
-                      &p_buffer );
+    aout_FiltersPlay( p_input->pp_filters, p_input->i_nb_filters, &p_buffer );
+    if( !p_buffer )
+        return NULL;
 #endif
 
     /* Run the resampler if needed.
      * We first need to calculate the output rate of this resampler. */
     if ( ( p_input->i_resampling_type == AOUT_RESAMPLING_NONE ) &&
-         ( start_date < p_buffer->i_pts - AOUT_PTS_TOLERANCE
-           || start_date > p_buffer->i_pts + AOUT_PTS_TOLERANCE ) &&
+         ( drift < -AOUT_MAX_PTS_ADVANCE || drift > +AOUT_MAX_PTS_DELAY ) &&
          p_input->i_nb_resamplers > 0 )
     {
         /* Can happen in several circumstances :
@@ -656,20 +618,13 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
          *    synchronization
          * Solution : resample the buffer to avoid a scratch.
          */
-        mtime_t drift = p_buffer->i_pts - start_date;
-
-        p_input->i_resamp_start_date = mdate();
-        p_input->i_resamp_start_drift = (int)drift;
-
-        if ( drift > 0 )
-            p_input->i_resampling_type = AOUT_RESAMPLING_DOWN;
-        else
-            p_input->i_resampling_type = AOUT_RESAMPLING_UP;
-
-        msg_Warn( p_aout, "buffer is %"PRId64" %s, triggering %ssampling",
-                          drift > 0 ? drift : -drift,
-                          drift > 0 ? "in advance" : "late",
-                          drift > 0 ? "down" : "up");
+        p_input->i_resamp_start_date = now;
+        p_input->i_resamp_start_drift = (int)-drift;
+        p_input->i_resampling_type = (drift < 0) ? AOUT_RESAMPLING_DOWN
+                                                 : AOUT_RESAMPLING_UP;
+        msg_Warn( p_aout, (drift < 0)
+                  ? "buffer too early (%"PRId64"), down-sampling"
+                  : "buffer too late  (%"PRId64"), up-sampling", drift );
     }
 
     if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
@@ -679,13 +634,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
          * it isn't too audible to the listener. */
 
         if( p_input->i_resampling_type == AOUT_RESAMPLING_UP )
-        {
             p_input->pp_resamplers[0]->fmt_in.audio.i_rate += 2; /* Hz */
-        }
         else
-        {
             p_input->pp_resamplers[0]->fmt_in.audio.i_rate -= 2; /* Hz */
-        }
 
         /* Check if everything is back to normal, in which case we can stop the
          * resampling */
@@ -698,7 +649,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
             p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
             msg_Warn( p_aout, "resampling stopped after %"PRIi64" usec "
                       "(drift: %"PRIi64")",
-                      mdate() - p_input->i_resamp_start_date,
+                      now - p_input->i_resamp_start_date,
                       p_buffer->i_pts - start_date);
         }
         else if( abs( (int)(p_buffer->i_pts - start_date) ) <
@@ -720,6 +671,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
              * is bad. We'd better stop the resampling right now. */
             msg_Warn( p_aout, "timing screwed, stopping resampling" );
             inputResamplingStop( p_input );
+            p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY;
         }
     }
 
@@ -727,43 +679,39 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
     /* Actually run the resampler now. */
     if ( p_input->i_nb_resamplers > 0 )
     {
-        aout_FiltersPlay( p_aout, p_input->pp_resamplers,
-                          p_input->i_nb_resamplers,
+        aout_FiltersPlay( p_input->pp_resamplers, p_input->i_nb_resamplers,
                           &p_buffer );
     }
 
+    if( !p_buffer )
+        return NULL;
     if( p_buffer->i_nb_samples <= 0 )
     {
-        aout_BufferFree( p_buffer );
-        return 0;
+        block_Release( p_buffer );
+        return NULL;
     }
 #endif
 
     /* Adding the start date will be managed by aout_FifoPush(). */
     p_buffer->i_pts = start_date;
-
-    aout_lock_input_fifos( p_aout );
-    aout_FifoPush( p_aout, &p_input->mixer.fifo, p_buffer );
-    aout_unlock_input_fifos( p_aout );
-    return 0;
+    return p_buffer;
 }
 
 /*****************************************************************************
  * static functions
  *****************************************************************************/
 
-static void inputFailure( aout_instance_t * p_aout, aout_input_t * p_input,
+static void inputFailure( audio_output_t * p_aout, aout_input_t * p_input,
                           const char * psz_error_message )
 {
     /* error message */
     msg_Err( p_aout, "%s", psz_error_message );
 
     /* clean up */
-    aout_FiltersDestroyPipeline( p_aout, p_input->pp_filters,
-                                 p_input->i_nb_filters );
-    aout_FiltersDestroyPipeline( p_aout, p_input->pp_resamplers,
+    aout_FiltersDestroyPipeline( p_input->pp_filters, p_input->i_nb_filters );
+    aout_FiltersDestroyPipeline( p_input->pp_resamplers,
                                  p_input->i_nb_resamplers );
-    aout_FifoDestroy( p_aout, &p_input->mixer.fifo );
+    aout_FifoDestroy( &p_input->fifo );
     var_Destroy( p_aout, "visual" );
     var_Destroy( p_aout, "equalizer" );
     var_Destroy( p_aout, "audio-filter" );
@@ -794,19 +742,25 @@ static void inputResamplingStop( aout_input_t *p_input )
             ( 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;
     }
 }
 
 static vout_thread_t *RequestVout( void *p_private,
                                    vout_thread_t *p_vout, video_format_t *p_fmt, bool b_recycle )
 {
-    aout_instance_t *p_aout = p_private;
+    audio_output_t *p_aout = p_private;
     VLC_UNUSED(b_recycle);
-    return vout_Request( p_aout, p_vout, p_fmt );
+    vout_configuration_t cfg = {
+        .vout       = p_vout,
+        .input      = NULL,
+        .change_fmt = true,
+        .fmt        = p_fmt,
+        .dpb_size   = 1,
+    };
+    return vout_Request( p_aout, &cfg );
 }
 
-vout_thread_t *aout_filter_RequestVout( aout_filter_t *p_filter,
+vout_thread_t *aout_filter_RequestVout( filter_t *p_filter,
                                         vout_thread_t *p_vout, video_format_t *p_fmt )
 {
     aout_input_t *p_input = p_filter->p_owner->p_input;
@@ -821,17 +775,17 @@ vout_thread_t *aout_filter_RequestVout( aout_filter_t *p_filter,
                                        p_vout, p_fmt, p_input->b_recycle_vout );
 }
 
-static int ChangeFiltersString( aout_instance_t * p_aout, const char* psz_variable,
+static int ChangeFiltersString( audio_output_t * p_aout, const char* psz_variable,
                                  const char *psz_name, bool b_add )
 {
-    return AoutChangeFilterString( VLC_OBJECT(p_aout), p_aout,
-                                   psz_variable, psz_name, b_add ) ? 1 : 0;
+    return aout_ChangeFilterString( 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,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
-    aout_instance_t *p_aout = (aout_instance_t *)p_this;
+    audio_output_t *p_aout = (audio_output_t *)p_this;
     char *psz_mode = newval.psz_string;
     (void)psz_cmd; (void)oldval; (void)p_data;
 
@@ -875,7 +829,7 @@ static int VisualizationCallback( vlc_object_t *p_this, char const *psz_cmd,
 static int EqualizerCallback( vlc_object_t *p_this, char const *psz_cmd,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
-    aout_instance_t *p_aout = (aout_instance_t *)p_this;
+    audio_output_t *p_aout = (audio_output_t *)p_this;
     char *psz_mode = newval.psz_string;
     int i_ret;
     (void)psz_cmd; (void)oldval; (void)p_data;
@@ -904,22 +858,18 @@ static int ReplayGainCallback( vlc_object_t *p_this, char const *psz_cmd,
 {
     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
     VLC_UNUSED(newval); VLC_UNUSED(p_data);
-    aout_instance_t *p_aout = (aout_instance_t *)p_this;
-    int i;
+    audio_output_t *aout = (audio_output_t *)p_this;
+    aout_owner_t *owner = aout_owner (aout);
 
-    aout_lock_mixer( p_aout );
-    for( i = 0; i < p_aout->i_nb_inputs; i++ )
-        ReplayGainSelect( p_aout, p_aout->pp_inputs[i] );
-
-    /* Restart the mixer (a trivial mixer may be in use) */
-    if( p_aout->p_mixer )
-        aout_MixerMultiplierSet( p_aout, p_aout->mixer_multiplier );
-    aout_unlock_mixer( p_aout );
+    aout_lock (aout);
+    if (owner->input != NULL)
+        ReplayGainSelect (aout, owner->input);
+    aout_unlock (aout);
 
     return VLC_SUCCESS;
 }
 
-static void ReplayGainSelect( aout_instance_t *p_aout, aout_input_t *p_input )
+static void ReplayGainSelect( audio_output_t *p_aout, aout_input_t *p_input )
 {
     char *psz_replay_gain = var_GetNonEmptyString( p_aout,
                                                    "audio-replay-gain-mode" );
@@ -927,7 +877,7 @@ static void ReplayGainSelect( aout_instance_t *p_aout, aout_input_t *p_input )
     int i_use;
     float f_gain;
 
-    p_input->mixer.multiplier = 1.0;
+    p_input->multiplier = 1.0;
 
     if( !psz_replay_gain )
         return;
@@ -958,16 +908,15 @@ static void ReplayGainSelect( aout_instance_t *p_aout, aout_input_t *p_input )
         f_gain = var_GetFloat( p_aout, "audio-replay-gain-default" );
     else
         f_gain = 0.0;
-    p_input->mixer.multiplier = pow( 10.0, f_gain / 20.0 );
+    p_input->multiplier = pow( 10.0, f_gain / 20.0 );
 
     /* */
     if( p_input->replay_gain.pb_peak[i_use] &&
         var_GetBool( p_aout, "audio-replay-gain-peak-protection" ) &&
-        p_input->replay_gain.pf_peak[i_use] * p_input->mixer.multiplier > 1.0 )
+        p_input->replay_gain.pf_peak[i_use] * p_input->multiplier > 1.0 )
     {
-        p_input->mixer.multiplier = 1.0f / p_input->replay_gain.pf_peak[i_use];
+        p_input->multiplier = 1.0f / p_input->replay_gain.pf_peak[i_use];
     }
 
     free( psz_replay_gain );
 }
-