[vlc-commits] aout: mix and convert before slicing the audio packets

Rémi Denis-Courmont git at videolan.org
Tue Aug 2 18:27:25 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug  2 19:26:31 2011 +0300| [74d6bb34359111ef858f7f7d93b5f9cc25fc906c] | committer: Rémi Denis-Courmont

aout: mix and convert before slicing the audio packets

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=74d6bb34359111ef858f7f7d93b5f9cc25fc906c
---

 src/audio_output/aout_internal.h |    6 ++----
 src/audio_output/dec.c           |   11 ++++++++---
 src/audio_output/input.c         |   24 ++++++++++++------------
 src/audio_output/output.c        |   25 +++++++++++++++++--------
 4 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 9fdf512..cfd6c6b 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -102,8 +102,8 @@ struct aout_input_t
 /* From input.c : */
 int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_request_vout_t * );
 int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
-void aout_InputPlay( audio_output_t * p_aout, aout_input_t * p_input,
-                     aout_buffer_t * p_buffer, int i_input_rate );
+block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
+                         block_t *p_buffer, int i_input_rate );
 void aout_InputCheckAndRestart( audio_output_t * p_aout, aout_input_t * p_input );
 
 /* From filters.c : */
@@ -118,8 +118,6 @@ audio_mixer_t *aout_MixerNew(vlc_object_t *, const audio_sample_format_t * );
 void aout_MixerDelete(audio_mixer_t *);
 void aout_MixerRun(audio_mixer_t *, block_t *, float);
 
-block_t *aout_OutputSlice( audio_output_t *, aout_fifo_t * );
-
 /* From output.c : */
 int aout_OutputNew( audio_output_t * p_aout,
                     const audio_sample_format_t * p_format );
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index bbbf7f0..68b4fa3 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -195,15 +195,20 @@ int aout_DecPlay( audio_output_t * p_aout, aout_input_t * p_input,
         return -1;
     }
 
+    /* Input */
     aout_InputCheckAndRestart( p_aout, p_input );
-    aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate );
+    p_buffer = aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate );
 
-    const float amp = p_aout->mixer_multiplier * p_input->multiplier;
-    while( (p_buffer = aout_OutputSlice( p_aout, &p_input->fifo ) ) != NULL )
+    if( p_buffer != NULL )
     {
+        /* Mixer */
+        float amp = p_aout->mixer_multiplier * p_input->multiplier;
         aout_MixerRun( p_aout->mixer, p_buffer, amp );
+
+        /* Output */
         aout_OutputPlay( p_aout, p_buffer );
     }
+
     aout_unlock( p_aout );
     return 0;
 }
diff --git a/src/audio_output/input.c b/src/audio_output/input.c
index 1ef4c70..5e50be4 100644
--- a/src/audio_output/input.c
+++ b/src/audio_output/input.c
@@ -485,8 +485,8 @@ void aout_InputCheckAndRestart( audio_output_t * p_aout, aout_input_t * p_input
  *****************************************************************************/
 /* XXX Do not activate it !! */
 //#define AOUT_PROCESS_BEFORE_CHEKS
-void aout_InputPlay( audio_output_t * p_aout, aout_input_t * p_input,
-                     aout_buffer_t * p_buffer, int i_input_rate )
+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;
@@ -494,7 +494,7 @@ void aout_InputPlay( audio_output_t * p_aout, aout_input_t * p_input,
     if( i_input_rate != INPUT_RATE_DEFAULT && p_input->p_playback_rate_filter == NULL )
     {
         inputDrop( p_input, p_buffer );
-        return;
+        return NULL;
     }
 
 #ifdef AOUT_PROCESS_BEFORE_CHEKS
@@ -502,7 +502,7 @@ void aout_InputPlay( audio_output_t * p_aout, aout_input_t * p_input,
     aout_FiltersPlay( p_aout, p_input->pp_filters, p_input->i_nb_filters,
                       &p_buffer );
     if( !p_buffer )
-        return;
+        return NULL;
 
     /* Actually run the resampler now. */
     if ( p_input->i_nb_resamplers > 0 )
@@ -514,11 +514,11 @@ void aout_InputPlay( audio_output_t * p_aout, aout_input_t * p_input,
     }
 
     if( !p_buffer )
-        return;
+        return NULL;
     if( p_buffer->i_nb_samples <= 0 )
     {
         block_Release( p_buffer );
-        return;
+        return NULL;
     }
 #endif
 
@@ -564,7 +564,7 @@ void aout_InputPlay( audio_output_t * p_aout, aout_input_t * p_input,
                   now - p_buffer->i_pts );
         inputDrop( p_input, p_buffer );
         inputResamplingStop( p_input );
-        return;
+        return NULL;
     }
 
     /* If the audio drift is too big then it's not worth trying to resample
@@ -593,14 +593,14 @@ void aout_InputPlay( audio_output_t * p_aout, aout_input_t * p_input,
         msg_Warn( p_aout, "buffer way too late (%"PRId64"), dropping buffer",
                   drift );
         inputDrop( p_input, p_buffer );
-        return;
+        return NULL;
     }
 
 #ifndef AOUT_PROCESS_BEFORE_CHEKS
     /* Run pre-filters. */
     aout_FiltersPlay( p_input->pp_filters, p_input->i_nb_filters, &p_buffer );
     if( !p_buffer )
-        return;
+        return NULL;
 #endif
 
     /* Run the resampler if needed.
@@ -682,17 +682,17 @@ void aout_InputPlay( audio_output_t * p_aout, aout_input_t * p_input,
     }
 
     if( !p_buffer )
-        return;
+        return NULL;
     if( p_buffer->i_nb_samples <= 0 )
     {
         block_Release( p_buffer );
-        return;
+        return NULL;
     }
 #endif
 
     /* Adding the start date will be managed by aout_FifoPush(). */
     p_buffer->i_pts = start_date;
-    aout_FifoPush( &p_input->fifo, p_buffer );
+    return p_buffer;
 }
 
 /*****************************************************************************
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 55fd7b3..8cac4af 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -218,6 +218,8 @@ void aout_OutputDelete( audio_output_t * p_aout )
     aout_FifoDestroy( &p_aout->fifo );
 }
 
+static block_t *aout_OutputSlice( audio_output_t *, aout_fifo_t * );
+
 /*****************************************************************************
  * aout_OutputPlay : play a buffer
  *****************************************************************************
@@ -236,8 +238,15 @@ void aout_OutputPlay( audio_output_t * p_aout, aout_buffer_t * p_buffer )
         return;
     }
 
-    aout_FifoPush( &p_aout->fifo, p_buffer );
-    p_aout->pf_play( p_aout );
+    aout_fifo_t *fifo = &p_aout->p_input->fifo;
+    /* XXX: cleanup */
+    aout_FifoPush( fifo, p_buffer );
+
+    while( (p_buffer = aout_OutputSlice( p_aout, fifo ) ) != NULL )
+    {
+        aout_FifoPush( &p_aout->fifo, p_buffer );
+        p_aout->pf_play( p_aout );
+    }
 }
 
 /**
@@ -375,7 +384,7 @@ void aout_VolumeHardSet (audio_output_t *aout, float volume, bool mute)
  * @note (FIXME) This is left here for historical reasons. It belongs in the
  * output code. Besides, this operation should be avoided if possible.
  */
-block_t *aout_OutputSlice( audio_output_t * p_aout, aout_fifo_t *p_fifo )
+static block_t *aout_OutputSlice (audio_output_t *p_aout, aout_fifo_t *p_fifo)
 {
     const unsigned samples = p_aout->i_nb_samples;
     /* FIXME: Remove this silly constraint. Just pass buffers as they come to
@@ -443,14 +452,14 @@ block_t *aout_OutputSlice( audio_output_t * p_aout, aout_fifo_t *p_fifo )
         prev_date = p_buffer->i_pts + p_buffer->i_length;
     }
 
-    if( !AOUT_FMT_NON_LINEAR( &p_aout->mixer_format ) )
+    if( !AOUT_FMT_NON_LINEAR( &p_aout->format ) )
     {
         p_buffer = p_fifo->p_first;
 
         /* Additionally check that p_first_byte_to_mix is well located. */
-        const unsigned framesize = p_aout->mixer_format.i_bytes_per_frame;
+        const unsigned framesize = p_aout->format.i_bytes_per_frame;
         ssize_t delta = (start_date - p_buffer->i_pts)
-                      * p_aout->mixer_format.i_rate / CLOCK_FREQ;
+                      * p_aout->format.i_rate / CLOCK_FREQ;
         if( delta != 0 )
             msg_Warn( p_aout, "input start is not output end (%zd)", delta );
         if( delta < 0 )
@@ -461,7 +470,7 @@ block_t *aout_OutputSlice( audio_output_t * p_aout, aout_fifo_t *p_fifo )
         }
         if( delta > 0 )
         {
-            mtime_t t = delta * CLOCK_FREQ / p_aout->mixer_format.i_rate;
+            mtime_t t = delta * CLOCK_FREQ / p_aout->format.i_rate;
             p_buffer->i_nb_samples -= delta;
             p_buffer->i_pts += t;
             p_buffer->i_length -= t;
@@ -498,7 +507,7 @@ block_t *aout_OutputSlice( audio_output_t * p_aout, aout_fifo_t *p_fifo )
                 needed /= framesize;
                 p_fifo->p_first->i_nb_samples -= needed;
 
-                mtime_t t = needed * CLOCK_FREQ / p_aout->mixer_format.i_rate;
+                mtime_t t = needed * CLOCK_FREQ / p_aout->format.i_rate;
                 p_fifo->p_first->i_pts += t;
                 p_fifo->p_first->i_length -= t;
                 break;



More information about the vlc-commits mailing list