X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Faudio_output%2Fmixer.c;h=108e815a112148acd97fc86bdda6704bfe9f0100;hb=8c390d9ba7b2915d2f32fa28efe0e4a267717825;hp=7857dfa86ee6734a9a04ca487d3b01bfcc8861b4;hpb=f76500382dc059091e0d811ed55a22337d2fe04f;p=vlc diff --git a/src/audio_output/mixer.c b/src/audio_output/mixer.c index 7857dfa86e..108e815a11 100644 --- a/src/audio_output/mixer.c +++ b/src/audio_output/mixer.c @@ -33,9 +33,6 @@ #include #include -#ifdef HAVE_ALLOCA_H -# include -#endif #include #include "aout_internal.h" /***************************************************************************** @@ -68,7 +65,6 @@ int aout_MixerNew( aout_instance_t * p_aout ) if( !p_mixer->module ) { msg_Err( p_aout, "no suitable audio mixer" ); - vlc_object_detach( p_mixer ); free( p_mixer->input ); vlc_object_release( p_mixer ); return VLC_EGENERIC; @@ -89,8 +85,6 @@ void aout_MixerDelete( aout_instance_t * p_aout ) if( !p_aout->p_mixer ) return; - vlc_object_detach( p_aout->p_mixer ); - module_unneed( p_aout->p_mixer, p_aout->p_mixer->module ); free( p_aout->p_mixer->input ); @@ -133,8 +127,8 @@ static int MixBuffer( aout_instance_t * p_aout ) } - aout_lock_output_fifo( p_aout ); aout_lock_input_fifos( p_aout ); + aout_lock_output_fifo( p_aout ); /* Retrieve the date of the next buffer. */ exact_start_date = p_aout->output.fifo.end_date; @@ -169,10 +163,10 @@ static int MixBuffer( aout_instance_t * p_aout ) continue; p_buffer = p_fifo->p_first; - while ( p_buffer != NULL && p_buffer->start_date < mdate() ) + while ( p_buffer != NULL && p_buffer->i_pts < mdate() ) { msg_Warn( p_aout, "input PTS is out of range (%"PRId64"), " - "trashing", mdate() - p_buffer->start_date ); + "trashing", mdate() - p_buffer->i_pts ); p_buffer = aout_FifoPop( p_aout, p_fifo ); aout_BufferFree( p_buffer ); p_buffer = p_fifo->p_first; @@ -184,10 +178,10 @@ static int MixBuffer( aout_instance_t * p_aout ) break; } - if ( !start_date || start_date < p_buffer->start_date ) + if ( !start_date || start_date < p_buffer->i_pts ) { - date_Set( &exact_start_date, p_buffer->start_date ); - start_date = p_buffer->start_date; + date_Set( &exact_start_date, p_buffer->i_pts ); + start_date = p_buffer->i_pts; } } @@ -225,13 +219,14 @@ static int MixBuffer( aout_instance_t * p_aout ) } /* Check for the continuity of start_date */ - while ( p_buffer != NULL && p_buffer->end_date < start_date - 1 ) + while ( p_buffer != NULL + && p_buffer->i_pts + p_buffer->i_length < start_date - 1 ) { /* We authorize a +-1 because rounding errors get compensated * regularly. */ aout_buffer_t * p_next = p_buffer->p_next; msg_Warn( p_aout, "the mixer got a packet in the past (%"PRId64")", - start_date - p_buffer->end_date ); + start_date - (p_buffer->i_pts + p_buffer->i_length) ); aout_BufferFree( p_buffer ); p_fifo->p_first = p_buffer = p_next; p_input->mixer.begin = NULL; @@ -247,24 +242,24 @@ static int MixBuffer( aout_instance_t * p_aout ) { p_buffer = p_fifo->p_first; if ( p_buffer == NULL ) break; - if ( p_buffer->end_date >= end_date ) break; + if ( p_buffer->i_pts + p_buffer->i_length >= end_date ) break; /* Check that all buffers are contiguous. */ - prev_date = p_fifo->p_first->end_date; + prev_date = p_fifo->p_first->i_pts + p_fifo->p_first->i_length; p_buffer = p_buffer->p_next; b_drop_buffers = 0; for ( ; p_buffer != NULL; p_buffer = p_buffer->p_next ) { - if ( prev_date != p_buffer->start_date ) + if ( prev_date != p_buffer->i_pts ) { msg_Warn( p_aout, "buffer hole, dropping packets (%"PRId64")", - p_buffer->start_date - prev_date ); + p_buffer->i_pts - prev_date ); b_drop_buffers = 1; break; } - if ( p_buffer->end_date >= end_date ) break; - prev_date = p_buffer->end_date; + if ( p_buffer->i_pts + p_buffer->i_length >= end_date ) break; + prev_date = p_buffer->i_pts + p_buffer->i_length; } if ( b_drop_buffers ) { @@ -286,7 +281,7 @@ static int MixBuffer( aout_instance_t * p_aout ) { /* Additionally check that p_first_byte_to_mix is well * located. */ - mtime_t i_nb_bytes = (start_date - p_buffer->start_date) + mtime_t i_buffer = (start_date - p_buffer->i_pts) * p_aout->p_mixer->fmt.i_bytes_per_frame * p_aout->p_mixer->fmt.i_rate / p_aout->p_mixer->fmt.i_frame_length @@ -299,18 +294,18 @@ static int MixBuffer( aout_instance_t * p_aout ) } mixer_nb_bytes = p_input->mixer.begin - p_buffer->p_buffer; - if ( !((i_nb_bytes + p_aout->p_mixer->fmt.i_bytes_per_frame + if ( !((i_buffer + p_aout->p_mixer->fmt.i_bytes_per_frame > mixer_nb_bytes) && - (i_nb_bytes < p_aout->p_mixer->fmt.i_bytes_per_frame + (i_buffer < p_aout->p_mixer->fmt.i_bytes_per_frame + mixer_nb_bytes)) ) { msg_Warn( p_aout, "mixer start isn't output start (%"PRId64")", - i_nb_bytes - mixer_nb_bytes ); + i_buffer - mixer_nb_bytes ); /* Round to the nearest multiple */ - i_nb_bytes /= p_aout->p_mixer->fmt.i_bytes_per_frame; - i_nb_bytes *= p_aout->p_mixer->fmt.i_bytes_per_frame; - if( i_nb_bytes < 0 ) + i_buffer /= p_aout->p_mixer->fmt.i_bytes_per_frame; + i_buffer *= p_aout->p_mixer->fmt.i_bytes_per_frame; + if( i_buffer < 0 ) { /* Is it really the best way to do it ? */ aout_lock_output_fifo( p_aout ); @@ -320,7 +315,7 @@ static int MixBuffer( aout_instance_t * p_aout ) break; } - p_input->mixer.begin = p_buffer->p_buffer + i_nb_bytes; + p_input->mixer.begin = p_buffer->p_buffer + i_buffer; } } } @@ -333,13 +328,12 @@ static int MixBuffer( aout_instance_t * p_aout ) } /* Run the mixer. */ - aout_BufferAlloc( &p_aout->p_mixer->allocation, - ((uint64_t)p_aout->output.i_nb_samples * 1000000) - / p_aout->output.output.i_rate, - /* This is a bit kludgy, but is actually only used - * for the S/PDIF dummy mixer : */ - p_aout->pp_inputs[i_first_input]->mixer.fifo.p_first, - &p_output_buffer ); + p_output_buffer = aout_BufferAlloc( &p_aout->p_mixer->allocation, + ((uint64_t)p_aout->output.i_nb_samples * 1000000) + / p_aout->output.output.i_rate, + /* This is a bit kludgy, but is actually only used + * for the S/PDIF dummy mixer : */ + p_aout->pp_inputs[i_first_input]->mixer.fifo.p_first); if ( p_output_buffer == NULL ) { aout_unlock_input_fifos( p_aout ); @@ -349,12 +343,12 @@ static int MixBuffer( aout_instance_t * p_aout ) if ( p_aout->p_mixer->allocation.b_alloc ) { p_output_buffer->i_nb_samples = p_aout->output.i_nb_samples; - p_output_buffer->i_nb_bytes = p_aout->output.i_nb_samples + p_output_buffer->i_buffer = p_aout->output.i_nb_samples * p_aout->p_mixer->fmt.i_bytes_per_frame / p_aout->p_mixer->fmt.i_frame_length; } - p_output_buffer->start_date = start_date; - p_output_buffer->end_date = end_date; + p_output_buffer->i_pts = start_date; + p_output_buffer->i_length = end_date - start_date; p_aout->p_mixer->mix( p_aout->p_mixer, p_output_buffer );