Commit 95157742 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Manage buffer allocation in the mixers, remove aout_mixer_t.b_alloc

parent b914b985
......@@ -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)
*
......
......@@ -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;
}
......@@ -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;
}
......@@ -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;
}
......@@ -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;
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 )
{
p_outbuf = p_aout->p_mixer->mix( p_aout->p_mixer,
p_aout->output.i_nb_samples );
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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment