]> git.sesse.net Git - vlc/commitdiff
Manage buffer allocation in the mixers, remove aout_mixer_t.b_alloc
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 30 May 2011 18:35:19 +0000 (21:35 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 30 May 2011 18:35:19 +0000 (21:35 +0300)
include/vlc_aout_mixer.h
modules/audio_mixer/float32.c
modules/audio_mixer/spdif.c
modules/audio_mixer/trivial.c
src/audio_output/mixer.c

index fbe55ce9ce32a19364dad439e381728dd7b034c4..002a712c02e1ab24b2c6397afe2e853dd63b3b91 100644 (file)
@@ -72,12 +72,6 @@ struct aout_mixer_t {
      */
     audio_sample_format_t fmt;
 
-    /* Mixer output buffer allocation method.
-     *
-     * You can override it in the open function only.
-     */
-    bool b_alloc;
-
     /* Multiplier used to raise or lower the volume of the sound in
      * software.
      */
@@ -86,8 +80,8 @@ struct aout_mixer_t {
     /* Array of mixer inputs */
     aout_mixer_input_t    *input;
 
-    /* Mix input into the given buffer (mandatory) */
-    void (*mix)(aout_mixer_t *, aout_buffer_t *);
+    /* Mix requested number of samples (mandatory) */
+    aout_buffer_t *(*mix)(aout_mixer_t *, unsigned);
 
     /* Private place holder for the aout_mixer_t module (optional)
      *
index 60a02c5e4598ae477c7183303453cc3c1a9eb796..d2f3174430b354d2ffc07773705d214c562c3191 100644 (file)
@@ -39,8 +39,7 @@
  * Local prototypes
  *****************************************************************************/
 static int  Create    ( vlc_object_t * );
-
-static void DoWork    ( aout_mixer_t *, aout_buffer_t * );
+static aout_buffer_t *DoWork( aout_mixer_t *, unsigned );
 
 /*****************************************************************************
  * Module descriptor
@@ -89,13 +88,17 @@ static void ScaleWords( float * p_out, const float * p_in, size_t i_nb_words,
  * Terminology : in this function a word designates a single float32, eg.
  * a stereo sample is consituted of two words.
  *****************************************************************************/
-static void DoWork( aout_mixer_t * p_mixer, aout_buffer_t * p_buffer )
+static aout_buffer_t *DoWork( aout_mixer_t * p_mixer, unsigned samples )
 {
-    const int i_nb_channels = aout_FormatNbChannels( &p_mixer->fmt );
-
-    int i_nb_words = p_buffer->i_nb_samples * i_nb_channels;
     aout_mixer_input_t * p_input = p_mixer->input;
     float f_multiplier = p_mixer->multiplier * p_input->multiplier;
+    const int i_nb_channels = aout_FormatNbChannels( &p_mixer->fmt );
+    int i_nb_words = samples * i_nb_channels;
+
+    block_t *p_buffer = block_Alloc( i_nb_words * sizeof(float) );
+    if( unlikely( p_buffer == NULL ) )
+        return NULL;
+    p_buffer->i_nb_samples = samples;
 
     float * p_out = (float *)p_buffer->p_buffer;
     float * p_in = (float *)p_input->begin;
@@ -121,7 +124,7 @@ static void DoWork( aout_mixer_t * p_mixer, aout_buffer_t * p_buffer )
             if( p_input->fifo.p_first == NULL )
             {
                 msg_Err( p_mixer, "internal amix error" );
-                return;
+                break;
             }
             p_in = (float *)p_input->fifo.p_first->p_buffer;
         }
@@ -132,5 +135,5 @@ static void DoWork( aout_mixer_t * p_mixer, aout_buffer_t * p_buffer )
             break;
         }
     }
+    return p_buffer;
 }
-
index 253dfae5d133198e41482c7f975db674c5ea941d..cd1906a7335aecc64b71cfca7d1225c220abd3cd 100644 (file)
@@ -41,7 +41,7 @@
  *****************************************************************************/
 static int  Create    ( vlc_object_t * );
 
-static void DoWork    ( aout_mixer_t *, aout_buffer_t * );
+static aout_buffer_t *DoWork( aout_mixer_t *, unsigned );
 
 /*****************************************************************************
  * Module descriptor
@@ -62,31 +62,20 @@ static int Create( vlc_object_t *p_this )
     aout_mixer_t *p_mixer = (aout_mixer_t *)p_this;
 
     if ( !AOUT_FMT_NON_LINEAR(&p_mixer->fmt) )
-    {
         return -1;
-    }
 
     p_mixer->mix = DoWork;
-    /* This is a bit kludgy - do not ask for a new buffer, since the one
-     * provided by the first input will be good enough. */
-    p_mixer->b_alloc = false;
-
     return 0;
 }
 
 /*****************************************************************************
  * DoWork: mix a new output buffer - this does nothing, indeed
  *****************************************************************************/
-static void DoWork( aout_mixer_t * p_mixer, aout_buffer_t * p_buffer )
+static aout_buffer_t *DoWork( aout_mixer_t * p_mixer, unsigned samples )
 {
-    VLC_UNUSED( p_buffer );
-
     aout_mixer_input_t * p_input = p_mixer->input;
-
     aout_buffer_t * p_old_buffer = aout_FifoPop( NULL, &p_input->fifo );
-    /* We don't free the old buffer because,
-     * The aout core use a hack to avoid useless memcpy: the buffer in which
-     * to mix is the same as the one in the first active input fifo.
-     * So the ownership of that buffer belongs to our caller */
-    assert( p_old_buffer == p_buffer );
+
+    (void) samples;
+    return p_old_buffer;
 }
index 7c1f8bf67f2e5cd164504075cb2932d5c23393b0..01581ac7bec2ca920af7c3577b90692198c76284 100644 (file)
@@ -40,7 +40,7 @@
  *****************************************************************************/
 static int  Create    ( vlc_object_t * );
 
-static void DoWork    ( aout_mixer_t *, aout_buffer_t * );
+static aout_buffer_t *DoWork( aout_mixer_t *, unsigned samples );
 
 /*****************************************************************************
  * Module descriptor
@@ -62,29 +62,28 @@ static int Create( vlc_object_t *p_this )
 
     if ( p_mixer->fmt.i_format != VLC_CODEC_FL32
           && p_mixer->fmt.i_format != VLC_CODEC_FI32 )
-    {
         return -1;
-    }
 
     p_mixer->mix = DoWork;
-
     return 0;
 }
 
 /*****************************************************************************
  * DoWork: mix a new output buffer
  *****************************************************************************/
-static void DoWork( aout_mixer_t *p_mixer, aout_buffer_t * p_buffer )
+static aout_buffer_t *DoWork( aout_mixer_t *p_mixer, unsigned samples )
 {
     aout_mixer_input_t *p_input = p_mixer->input;
     int i_nb_channels = aout_FormatNbChannels( &p_mixer->fmt );
-    int i_buffer = p_buffer->i_nb_samples * sizeof(int32_t)
-                      * i_nb_channels;
-    uint8_t * p_in;
-    uint8_t * p_out;
+    ssize_t i_buffer = samples * i_nb_channels * sizeof(int32_t);
+    aout_buffer_t *p_buffer = block_Alloc( i_buffer );
+
+    if( unlikely(p_buffer == NULL) )
+        return NULL;
+    p_buffer->i_nb_samples = samples;
 
-    p_in = p_input->begin;
-    p_out = p_buffer->p_buffer;
+    uint8_t * p_in = p_input->begin;
+    uint8_t * p_out = p_buffer->p_buffer;
 
     for ( ; ; )
     {
@@ -108,7 +107,7 @@ static void DoWork( aout_mixer_t *p_mixer, aout_buffer_t * p_buffer )
             if ( p_input->fifo.p_first == NULL )
             {
                 msg_Err( p_mixer, "internal amix error" );
-                return;
+                break;
             }
             p_in = p_input->fifo.p_first->p_buffer;
         }
@@ -119,4 +118,5 @@ static void DoWork( aout_mixer_t *p_mixer, aout_buffer_t * p_buffer )
             break;
         }
     }
+    return p_buffer;
 }
index 90e396c59c6ff0425b1f9f07a9524bf15d01f20b..cda7b5814548d8aa3d5fdd3d036c1e560eab24ab 100644 (file)
@@ -51,7 +51,6 @@ int aout_MixerNew( aout_instance_t * p_aout )
         return VLC_EGENERIC;
 
     p_mixer->fmt = p_aout->mixer_format;
-    p_mixer->b_alloc = true;
     p_mixer->multiplier = p_aout->mixer_multiplier;
     p_mixer->input = &p_aout->pp_inputs[0]->mixer;
     p_mixer->mix = NULL;
@@ -322,31 +321,16 @@ static int MixBuffer( aout_instance_t * p_aout )
 
     /* Run the mixer. */
     aout_buffer_t * p_outbuf;
+    p_outbuf = p_aout->p_mixer->mix( p_aout->p_mixer,
+                                     p_aout->output.i_nb_samples );
+    aout_unlock_input_fifos( p_aout );
 
-    if( p_aout->p_mixer->b_alloc )
-    {
-        p_outbuf = block_Alloc( p_aout->output.i_nb_samples
-                              * p_aout->p_mixer->fmt.i_bytes_per_frame
-                              / p_aout->p_mixer->fmt.i_frame_length );
-        if( likely(p_outbuf != NULL) )
-            p_outbuf->i_nb_samples = p_aout->output.i_nb_samples;
-    }
-    else
-        p_outbuf = p_aout->pp_inputs[i_first_input]->mixer.fifo.p_first;
-    if ( p_outbuf == NULL )
-    {
-        aout_unlock_input_fifos( p_aout );
+    if( unlikely(p_outbuf == NULL) )
         return -1;
-    }
+
     p_outbuf->i_pts = start_date;
     p_outbuf->i_length = end_date - start_date;
-
-    p_aout->p_mixer->mix( p_aout->p_mixer, p_outbuf );
-
-    aout_unlock_input_fifos( p_aout );
-
     aout_OutputPlay( p_aout, p_outbuf );
-
     return 0;
 }