*/
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.
*/
/* 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)
*
* 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
* 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;
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;
}
break;
}
}
+ return p_buffer;
}
-
*****************************************************************************/
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
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;
}
*****************************************************************************/
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
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 ( ; ; )
{
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;
}
break;
}
}
+ return p_buffer;
}
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;
/* 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;
}