]> git.sesse.net Git - vlc/commitdiff
aout mixer: do output buffer packetization in core, simplify
authorRémi Denis-Courmont <remi@remlab.net>
Tue, 7 Jun 2011 17:11:41 +0000 (20:11 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 7 Jun 2011 17:12:20 +0000 (20:12 +0300)
Now the mixer can focus on applying to volume. Dummy mixers for
S/PDIF and linear are now merged.

include/vlc_aout_mixer.h
modules/audio_mixer/Modules.am
modules/audio_mixer/float32.c
modules/audio_mixer/spdif.c [deleted file]
modules/audio_mixer/trivial.c
src/audio_output/mixer.c

index e332851e395f3d89f3b8fbb405a1105ea6efb514..92b524440fe6c560d65b52eaa51fc9c3185b22e3 100644 (file)
@@ -72,8 +72,8 @@ struct aout_mixer_t {
     /* Array of mixer inputs */
     aout_mixer_input_t    *input;
 
-    /* Mix requested number of samples (mandatory) */
-    aout_buffer_t *(*mix)(aout_mixer_t *, unsigned, float);
+    /* Mix buffer (mandatory) */
+    void (*mix)(aout_mixer_t *, aout_buffer_t *, float);
 
     /* Private place holder for the aout_mixer_t module (optional)
      *
index c6e67e9c06c7d8ca371d1e1e6ed46349b44a09e0..f9f5efa331c583edf44eb690ae8a7f904a4ab0dc 100644 (file)
@@ -1,8 +1,6 @@
 SOURCES_trivial_mixer = trivial.c
 SOURCES_float32_mixer = float32.c
-SOURCES_spdif_mixer = spdif.c
 
 libvlc_LTLIBRARIES += \
        libfloat32_mixer_plugin.la \
-       libspdif_mixer_plugin.la \
        libtrivial_mixer_plugin.la
index 8619fd4da71fbbeb1f5e87a4054e2c299dfcf8ad..27cc1de0daab28ee01d42f6b2ae7640b5077c8e2 100644 (file)
@@ -38,8 +38,8 @@
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  Create    ( vlc_object_t * );
-static aout_buffer_t *DoWork( aout_mixer_t *, unsigned, float );
+static int Create( vlc_object_t * );
+static void DoWork( aout_mixer_t *, aout_buffer_t *, float );
 
 /*****************************************************************************
  * Module descriptor
@@ -52,9 +52,9 @@ vlc_module_begin ()
     set_callbacks( Create, NULL )
 vlc_module_end ()
 
-/*****************************************************************************
- * Create: allocate mixer
- *****************************************************************************/
+/**
+ * Initializes the mixer
+ */
 static int Create( vlc_object_t *p_this )
 {
     aout_mixer_t * p_mixer = (aout_mixer_t *)p_this;
@@ -66,76 +66,18 @@ static int Create( vlc_object_t *p_this )
     return 0;
 }
 
-/*****************************************************************************
- * ScaleWords: prepare input words for averaging
- *****************************************************************************/
-static void ScaleWords( float * p_out, const float * p_in, size_t i_nb_words,
-                        float f_multiplier )
-{
-    if( f_multiplier == 1.0 )
-    {
-        vlc_memcpy( p_out, p_in, i_nb_words * sizeof(float) );
-        return;
-    }
-
-    for( size_t i = 0; i < i_nb_words; i++ )
-        *p_out++ = *p_in++ * f_multiplier;
-}
-
-/*****************************************************************************
- * DoWork: mix a new output buffer
- *****************************************************************************
- * Terminology : in this function a word designates a single float32, eg.
- * a stereo sample is consituted of two words.
- *****************************************************************************/
-static aout_buffer_t *DoWork( aout_mixer_t * p_mixer, unsigned samples,
-                              float f_multiplier )
+/**
+ * Mixes a new output buffer
+ */
+static void DoWork( aout_mixer_t * p_mixer, aout_buffer_t *p_buffer,
+                    float f_multiplier )
 {
-    aout_mixer_input_t * p_input = p_mixer->input;
-    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;
+    f_multiplier *= p_mixer->input->multiplier;
 
-    f_multiplier *= p_input->multiplier;
-
-    for( ; ; )
-    {
-        ptrdiff_t i_available_words = (
-            (float *)p_input->fifo.p_first->p_buffer - p_in)
-                               + p_input->fifo.p_first->i_nb_samples
-                               * i_nb_channels;
-
-        if( i_available_words < i_nb_words )
-        {
-            aout_buffer_t * p_old_buffer;
-
-            ScaleWords( p_out, p_in, i_available_words, f_multiplier );
-            i_nb_words -= i_available_words;
-            p_out += i_available_words;
+    if( f_multiplier == 1.0 )
+        return; /* nothing to do */
 
-            /* Next buffer */
-            p_old_buffer = aout_FifoPop( &p_input->fifo );
-            aout_BufferFree( p_old_buffer );
-            if( p_input->fifo.p_first == NULL )
-            {
-                msg_Err( p_mixer, "internal amix error" );
-                break;
-            }
-            p_in = (float *)p_input->fifo.p_first->p_buffer;
-        }
-        else
-        {
-            ScaleWords( p_out, p_in, i_nb_words, f_multiplier );
-            p_input->begin = (void *)(p_in + i_nb_words);
-            break;
-        }
-    }
-    return p_buffer;
+    float *p = (float *)p_buffer->p_buffer;
+    for( size_t i = p_buffer->i_buffer / sizeof(float); i > 0; i-- )
+        *(p++) *= f_multiplier;
 }
diff --git a/modules/audio_mixer/spdif.c b/modules/audio_mixer/spdif.c
deleted file mode 100644 (file)
index 62fb204..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*****************************************************************************
- * spdif.c : dummy mixer for S/PDIF output (1 input only)
- *****************************************************************************
- * Copyright (C) 2002 the VideoLAN team
- * $Id$
- *
- * Authors: Christophe Massiot <massiot@via.ecp.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <assert.h>
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_aout.h>
-#include <vlc_aout_mixer.h>
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int  Create    ( vlc_object_t * );
-
-static aout_buffer_t *DoWork( aout_mixer_t *, unsigned, float );
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-vlc_module_begin ()
-    set_category( CAT_AUDIO )
-    set_subcategory( SUBCAT_AUDIO_MISC )
-    set_description( N_("Dummy S/PDIF audio mixer") )
-    set_capability( "audio mixer", 1 )
-    set_callbacks( Create, NULL )
-vlc_module_end ()
-
-/*****************************************************************************
- * Create: allocate spdif mixer
- *****************************************************************************/
-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;
-    return 0;
-}
-
-/*****************************************************************************
- * DoWork: mix a new output buffer - this does nothing, indeed
- *****************************************************************************/
-static aout_buffer_t *DoWork( aout_mixer_t * p_mixer, unsigned samples,
-                              float multiplier )
-{
-    aout_mixer_input_t * p_input = p_mixer->input;
-    aout_buffer_t * p_old_buffer = aout_FifoPop( &p_input->fifo );
-
-    (void) samples; (void) multiplier;
-    return p_old_buffer;
-}
index 688ac62529b7a723289c752975c6d66426a1dffc..7fb0ea8ae5a4a8ec053503841983afe91ab47546 100644 (file)
@@ -29,7 +29,6 @@
 # include "config.h"
 #endif
 
-#include <stddef.h>
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_aout.h>
@@ -38,9 +37,8 @@
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  Create    ( vlc_object_t * );
-
-static aout_buffer_t *DoWork( aout_mixer_t *, unsigned samples, float );
+static int Create( vlc_object_t * );
+static void DoNothing( aout_mixer_t *, aout_buffer_t *p_buffer, float );
 
 /*****************************************************************************
  * Module descriptor
@@ -48,7 +46,7 @@ static aout_buffer_t *DoWork( aout_mixer_t *, unsigned samples, float );
 vlc_module_begin ()
     set_category( CAT_AUDIO )
     set_subcategory( SUBCAT_AUDIO_MISC )
-    set_description( N_("Trivial audio mixer") )
+    set_description( N_("Dummy audio mixer") )
     set_capability( "audio mixer", 1 )
     set_callbacks( Create, NULL )
 vlc_module_end ()
@@ -60,60 +58,14 @@ 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;
+    p_mixer->mix = DoNothing;
     return 0;
 }
 
-/*****************************************************************************
- * DoWork: mix a new output buffer
- *****************************************************************************/
-static aout_buffer_t *DoWork( aout_mixer_t *p_mixer, unsigned samples,
-                              float multiplier )
+static void DoNothing( aout_mixer_t *p_mixer, aout_buffer_t *p_buffer,
+                       float multiplier )
 {
-    aout_mixer_input_t *p_input = p_mixer->input;
-    unsigned framesize = aout_FormatNbChannels( &p_mixer->fmt )
-                   * (p_mixer->fmt.i_bitspersample / 8);
-    size_t needed = samples * framesize;
-    aout_buffer_t *p_buffer = block_Alloc( needed );
-
-    if( unlikely(p_buffer == NULL) )
-        return NULL;
-    p_buffer->i_nb_samples = samples;
-
-    uint8_t * p_in = p_input->begin;
-    uint8_t * p_out = p_buffer->p_buffer;
-
-    for ( ; ; )
-    {
-        size_t avail = p_input->fifo.p_first->i_nb_samples * framesize
-                     - (p_in - p_input->fifo.p_first->p_buffer);
-
-        if ( avail < needed )
-        {
-            vlc_memcpy( p_out, p_in, avail );
-            needed -= avail;
-            p_out += avail;
-
-            /* Next buffer */
-            aout_buffer_t *p_old_buffer = aout_FifoPop( &p_input->fifo );
-            aout_BufferFree( p_old_buffer );
-            if ( p_input->fifo.p_first == NULL )
-            {
-                msg_Err( p_mixer, "internal amix error" );
-                break;
-            }
-            p_in = p_input->fifo.p_first->p_buffer;
-        }
-        else
-        {
-            vlc_memcpy( p_out, p_in, needed );
-            p_input->begin = p_in + needed;
-            break;
-        }
-    }
+    (void) p_mixer;
+    (void) p_buffer;
     (void) multiplier;
-    return p_buffer;
 }
index 08aa2de5929afdafb5649d3666134aed69a21a9a..355838de28bd48078160e81c3626a230501dd66d 100644 (file)
@@ -190,15 +190,14 @@ static int MixBuffer( aout_instance_t * p_aout, float volume )
         prev_date = p_buffer->i_pts + p_buffer->i_length;
     }
 
-    p_buffer = p_fifo->p_first;
     if( !AOUT_FMT_NON_LINEAR( &p_mixer->fmt ) )
     {
+        p_buffer = p_fifo->p_first;
+
         /* Additionally check that p_first_byte_to_mix is well located. */
+        const unsigned framesize = p_mixer->fmt.i_bytes_per_frame;
         mtime_t i_buffer = (start_date - p_buffer->i_pts)
-                         * p_mixer->fmt.i_bytes_per_frame
-                         * p_mixer->fmt.i_rate
-                         / p_mixer->fmt.i_frame_length
-                         / CLOCK_FREQ;
+                         * framesize * p_mixer->fmt.i_rate / CLOCK_FREQ;
         if( p_input->begin == NULL )
             p_input->begin = p_buffer->p_buffer;
 
@@ -223,17 +222,57 @@ static int MixBuffer( aout_instance_t * p_aout, float volume )
             }
             p_input->begin = p_buffer->p_buffer + i_buffer;
         }
-    }
 
-    /* Run the mixer. */
-    p_buffer = p_mixer->mix( p_mixer, p_aout->output.i_nb_samples, volume );
-    aout_unlock_input_fifos( p_aout );
+        /* Build packet with adequate number of samples */
+        const unsigned samples = p_aout->output.i_nb_samples;
+        unsigned needed = samples * framesize;
+        p_buffer = block_Alloc( needed );
+        if( unlikely(p_buffer == NULL) )
+            /* XXX: should free input buffers */
+            goto giveup;
+        p_buffer->i_nb_samples = samples;
+
+        uint8_t *p_in = p_input->begin;
+        uint8_t *p_out = p_buffer->p_buffer;
+
+        for( ;; )
+        {
+            size_t avail = p_fifo->p_first->i_nb_samples * framesize
+                         - (p_in - p_fifo->p_first->p_buffer);
+
+            if( avail < needed )
+            {
+                vlc_memcpy( p_out, p_in, avail );
+                needed -= avail;
+                p_out += avail;
 
-    if( unlikely(p_buffer == NULL) )
-        return -1;
+                /* Next buffer */
+                aout_BufferFree( aout_FifoPop( p_fifo ) );
+                if( p_input->fifo.p_first == NULL )
+                {
+                    msg_Err( p_mixer, "internal amix error" );
+                    vlc_memset( p_out, 0, needed );
+                    break;
+                }
+                p_in = p_fifo->p_first->p_buffer;
+            }
+            else
+            {
+                vlc_memcpy( p_out, p_in, needed );
+                p_input->begin = p_in + needed;
+                break;
+            }
+        }
+    }
+    else
+        p_buffer = aout_FifoPop( p_fifo );
 
     p_buffer->i_pts = start_date;
     p_buffer->i_length = end_date - start_date;
+
+    /* Run the mixer. */
+    p_mixer->mix( p_mixer, p_buffer, volume );
+    aout_unlock_input_fifos( p_aout );
     aout_OutputPlay( p_aout, p_buffer );
     return 0;