mirror of
https://code.videolan.org/videolan/vlc
synced 2024-10-03 01:31:53 +02:00
aout mixer: do output buffer packetization in core, simplify
Now the mixer can focus on applying to volume. Dummy mixers for S/PDIF and linear are now merged.
This commit is contained in:
parent
fefde73eb4
commit
402c532028
@ -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)
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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 )
|
||||
/**
|
||||
* Mixes a new output buffer
|
||||
*/
|
||||
static void DoWork( aout_mixer_t * p_mixer, aout_buffer_t *p_buffer,
|
||||
float f_multiplier )
|
||||
{
|
||||
f_multiplier *= p_mixer->input->multiplier;
|
||||
|
||||
if( f_multiplier == 1.0 )
|
||||
{
|
||||
vlc_memcpy( p_out, p_in, i_nb_words * sizeof(float) );
|
||||
return;
|
||||
}
|
||||
return; /* nothing to do */
|
||||
|
||||
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 )
|
||||
{
|
||||
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_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;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Run the mixer. */
|
||||
p_buffer = p_mixer->mix( p_mixer, p_aout->output.i_nb_samples, volume );
|
||||
aout_unlock_input_fifos( p_aout );
|
||||
|
||||
if( unlikely(p_buffer == NULL) )
|
||||
return -1;
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user