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

mixer: cleanup packetization

parent 789f1724
...@@ -194,18 +194,11 @@ static int MixBuffer( aout_instance_t * p_aout, float volume ) ...@@ -194,18 +194,11 @@ static int MixBuffer( aout_instance_t * p_aout, float volume )
/* Additionally check that p_first_byte_to_mix is well located. */ /* Additionally check that p_first_byte_to_mix is well located. */
const unsigned framesize = p_mixer->fmt.i_bytes_per_frame; const unsigned framesize = p_mixer->fmt.i_bytes_per_frame;
mtime_t i_buffer = (start_date - p_buffer->i_pts) ssize_t delta = (start_date - p_buffer->i_pts)
* framesize * p_mixer->fmt.i_rate / CLOCK_FREQ; * p_mixer->fmt.i_rate / CLOCK_FREQ;
if( delta != 0 )
if( !((i_buffer + framesize > 0) && (i_buffer < framesize)) ) msg_Warn( p_mixer, "mixer start is not output end (%zd)", delta );
{ if( delta < 0 )
msg_Warn( p_mixer, "mixer start is not output start (%"PRId64")",
i_buffer );
/* Round to the nearest multiple */
i_buffer /= p_mixer->fmt.i_bytes_per_frame;
i_buffer *= p_mixer->fmt.i_bytes_per_frame;
if( i_buffer < 0 )
{ {
/* Is it really the best way to do it ? */ /* Is it really the best way to do it ? */
aout_lock_output_fifo( p_aout ); aout_lock_output_fifo( p_aout );
...@@ -214,12 +207,14 @@ static int MixBuffer( aout_instance_t * p_aout, float volume ) ...@@ -214,12 +207,14 @@ static int MixBuffer( aout_instance_t * p_aout, float volume )
aout_unlock_output_fifo( p_aout ); aout_unlock_output_fifo( p_aout );
goto giveup; goto giveup;
} }
p_buffer->p_buffer += i_buffer; if( delta > 0 )
p_buffer->i_buffer -= i_buffer; {
i_buffer /= framesize; p_buffer->i_nb_samples -= delta;
p_buffer->i_nb_samples -= i_buffer; p_buffer->i_pts += delta * CLOCK_FREQ / p_mixer->fmt.i_rate;
p_buffer->i_pts += i_buffer * CLOCK_FREQ / p_mixer->fmt.i_rate; p_buffer->i_length -= delta * CLOCK_FREQ / p_mixer->fmt.i_rate;
p_buffer->i_length -= i_buffer * CLOCK_FREQ / p_mixer->fmt.i_rate; delta *= framesize;
p_buffer->p_buffer += delta;
p_buffer->i_buffer -= delta;
} }
/* Build packet with adequate number of samples */ /* Build packet with adequate number of samples */
...@@ -231,28 +226,19 @@ static int MixBuffer( aout_instance_t * p_aout, float volume ) ...@@ -231,28 +226,19 @@ static int MixBuffer( aout_instance_t * p_aout, float volume )
goto giveup; goto giveup;
p_buffer->i_nb_samples = samples; p_buffer->i_nb_samples = samples;
for( uint8_t *p_out = p_buffer->p_buffer;; ) for( uint8_t *p_out = p_buffer->p_buffer; needed > 0; )
{ {
uint8_t *p_in = p_fifo->p_first->p_buffer; aout_buffer_t *p_inbuf = p_fifo->p_first;
size_t avail = p_fifo->p_first->i_nb_samples * framesize; if( unlikely(p_inbuf == NULL) )
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" ); msg_Err( p_mixer, "internal amix error" );
vlc_memset( p_out, 0, needed ); vlc_memset( p_out, 0, needed );
break; break;
} }
p_in = p_fifo->p_first->p_buffer;
} const uint8_t *p_in = p_inbuf->p_buffer;
else size_t avail = p_inbuf->i_nb_samples * framesize;
if( avail > needed )
{ {
vlc_memcpy( p_out, p_in, needed ); vlc_memcpy( p_out, p_in, needed );
p_fifo->p_first->p_buffer += needed; p_fifo->p_first->p_buffer += needed;
...@@ -263,6 +249,12 @@ static int MixBuffer( aout_instance_t * p_aout, float volume ) ...@@ -263,6 +249,12 @@ static int MixBuffer( aout_instance_t * p_aout, float volume )
p_fifo->p_first->i_length -= needed * CLOCK_FREQ / p_mixer->fmt.i_rate; p_fifo->p_first->i_length -= needed * CLOCK_FREQ / p_mixer->fmt.i_rate;
break; break;
} }
vlc_memcpy( p_out, p_in, avail );
needed -= avail;
p_out += avail;
/* Next buffer */
aout_BufferFree( aout_FifoPop( p_fifo ) );
} }
} }
else else
......
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