#include <vlc_common.h>
-#ifdef HAVE_ALLOCA_H
-# include <alloca.h>
-#endif
-
#include <vlc_aout.h>
#include <vlc_input.h>
#include "aout_internal.h"
-/*****************************************************************************
- * aout_DecNew : create a decoder
- *****************************************************************************/
-static aout_input_t * DecNew( aout_instance_t * p_aout,
- audio_sample_format_t *p_format,
- const audio_replay_gain_t *p_replay_gain,
- const aout_request_vout_t *p_request_vout )
+#undef aout_DecNew
+/**
+ * Creates an audio output
+ */
+aout_input_t *aout_DecNew( aout_instance_t *p_aout,
+ audio_sample_format_t *p_format,
+ const audio_replay_gain_t *p_replay_gain,
+ const aout_request_vout_t *p_request_vout )
{
aout_input_t * p_input;
/* We can only be called by the decoder, so no need to lock
* p_input->lock. */
aout_lock_mixer( p_aout );
-
- if ( p_aout->i_nb_inputs >= AOUT_MAX_INPUTS )
- {
- msg_Err( p_aout, "too many inputs already (%d)", p_aout->i_nb_inputs );
- goto error;
- }
+ assert( p_aout->i_nb_inputs == 0 );
p_input = calloc( 1, sizeof(aout_input_t));
if( !p_input )
vlc_mutex_init( &p_input->lock );
- p_input->b_changed = false;
p_input->b_error = true;
p_input->b_paused = false;
p_input->i_pause_date = 0;
return NULL;
}
-aout_input_t * __aout_DecNew( vlc_object_t * p_this,
- aout_instance_t ** pp_aout,
- audio_sample_format_t * p_format,
- const audio_replay_gain_t *p_replay_gain,
- const aout_request_vout_t *p_request_video )
-{
- aout_instance_t *p_aout = *pp_aout;
- if ( p_aout == NULL )
- {
- msg_Dbg( p_this, "no aout present, spawning one" );
- p_aout = aout_New( p_this );
-
- /* Everything failed, I'm a loser, I just wanna die */
- if( p_aout == NULL )
- return NULL;
-
- vlc_object_attach( p_aout, p_this );
- *pp_aout = p_aout;
- }
-
- return DecNew( p_aout, p_format, p_replay_gain, p_request_video );
-}
-
/*****************************************************************************
* aout_DecDelete : delete a decoder
*****************************************************************************/
}
/* Remove the input from the list. */
- memmove( &p_aout->pp_inputs[i_input], &p_aout->pp_inputs[i_input + 1],
- (AOUT_MAX_INPUTS - i_input - 1) * sizeof(aout_input_t *) );
p_aout->i_nb_inputs--;
+ assert( p_aout->i_nb_inputs == 0 );
aout_InputDelete( p_aout, p_input );
aout_buffer_t * aout_DecNewBuffer( aout_input_t * p_input,
size_t i_nb_samples )
{
- aout_buffer_t * p_buffer;
- mtime_t duration;
+ block_t *block;
+ size_t length;
aout_lock_input( NULL, p_input );
return NULL;
}
- duration = (1000000 * (mtime_t)i_nb_samples) / p_input->input.i_rate;
-
- /* This necessarily allocates in the heap. */
- aout_BufferAlloc( &p_input->input_alloc, duration, NULL, p_buffer );
- if( p_buffer != NULL )
- p_buffer->i_nb_bytes = i_nb_samples * p_input->input.i_bytes_per_frame
- / p_input->input.i_frame_length;
-
- /* Suppose the decoder doesn't have more than one buffered buffer */
- p_input->b_changed = false;
+ length = i_nb_samples * p_input->input.i_bytes_per_frame
+ / p_input->input.i_frame_length;
+ block = block_Alloc( length );
aout_unlock_input( NULL, p_input );
- if( p_buffer == NULL )
- return NULL;
-
- p_buffer->i_nb_samples = i_nb_samples;
- p_buffer->start_date = p_buffer->end_date = 0;
- return p_buffer;
+ if( likely(block != NULL) )
+ {
+ block->i_nb_samples = i_nb_samples;
+ block->i_pts = block->i_length = 0;
+ }
+ return block;
}
/*****************************************************************************
assert( i_input_rate >= INPUT_RATE_DEFAULT / AOUT_MAX_INPUT_RATE &&
i_input_rate <= INPUT_RATE_DEFAULT * AOUT_MAX_INPUT_RATE );
- assert( p_buffer->start_date > 0 );
+ assert( p_buffer->i_pts > 0 );
- p_buffer->end_date = p_buffer->start_date
- + (mtime_t)p_buffer->i_nb_samples * 1000000
+ p_buffer->i_length = (mtime_t)p_buffer->i_nb_samples * 1000000
/ p_input->input.i_rate;
+ aout_lock_mixer( p_aout );
aout_lock_input( p_aout, p_input );
if( p_input->b_error )
{
aout_unlock_input( p_aout, p_input );
+ aout_unlock_mixer( p_aout );
+
aout_BufferFree( p_buffer );
return -1;
}
- if( p_input->b_changed )
- {
- /* Maybe the allocation size has changed. Re-allocate a buffer. */
- aout_buffer_t * p_new_buffer;
- mtime_t duration = (1000000 * (mtime_t)p_buffer->i_nb_samples)
- / p_input->input.i_rate;
-
- aout_BufferAlloc( &p_input->input_alloc, duration, NULL, p_new_buffer );
- vlc_memcpy( p_new_buffer->p_buffer, p_buffer->p_buffer,
- p_buffer->i_nb_bytes );
- p_new_buffer->i_nb_samples = p_buffer->i_nb_samples;
- p_new_buffer->i_nb_bytes = p_buffer->i_nb_bytes;
- p_new_buffer->start_date = p_buffer->start_date;
- p_new_buffer->end_date = p_buffer->end_date;
- aout_BufferFree( p_buffer );
- p_buffer = p_new_buffer;
- p_input->b_changed = false;
- }
+ aout_InputCheckAndRestart( p_aout, p_input );
+ aout_unlock_mixer( p_aout );
int i_ret = aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate );
aout_lock_mixer( p_aout );
for( aout_buffer_t *p = p_input->mixer.fifo.p_first; p != NULL; p = p->p_next )
{
- p->start_date += i_duration;
- p->end_date += i_duration;
+ p->i_pts += i_duration;
}
aout_unlock_mixer( p_aout );
}