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

aout_buffer_t: store length instead of end timestamp

aout_buffer_t now looks very much like a subset of block_t at the
source code level. By the way, we might want to revisit the return value
of date_Increment()...
parent e9eb5d5e
......@@ -134,7 +134,7 @@ struct aout_buffer_t
size_t i_size, i_nb_bytes;
unsigned int i_nb_samples;
uint32_t i_flags;
mtime_t i_pts, end_date;
mtime_t i_pts, i_length;
struct aout_buffer_t * p_next;
void *p_sys;
......
......@@ -220,9 +220,9 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
p_sys->i_old_wing;
p_out_buf->i_pts = date_Get( &p_sys->end_date );
p_out_buf->end_date =
p_out_buf->i_length =
date_Increment( &p_sys->end_date,
p_out_buf->i_nb_samples );
p_out_buf->i_nb_samples ) - p_out_buf->i_pts;
p_out_buf->i_nb_bytes = p_out_buf->i_nb_samples *
p_filter->input.i_bytes_per_frame;
......@@ -455,8 +455,8 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
/* Finalize aout buffer */
p_out_buf->i_nb_samples = i_out;
p_out_buf->i_pts = date_Get( &p_sys->end_date );
p_out_buf->end_date = date_Increment( &p_sys->end_date,
p_out_buf->i_nb_samples );
p_out_buf->i_length = date_Increment( &p_sys->end_date,
p_out_buf->i_nb_samples ) - p_out_buf->i_pts;
p_out_buf->i_nb_bytes = p_out_buf->i_nb_samples *
i_nb_channels * sizeof(int32_t);
......
......@@ -231,8 +231,8 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
date_Set( &p_sys->end_date, p_in_buf->i_pts );
}
p_out_buf->end_date = date_Increment( &p_sys->end_date,
p_out_buf->i_nb_samples );
p_out_buf->i_length = date_Increment( &p_sys->end_date,
p_out_buf->i_nb_samples ) - p_out_buf->i_pts;
p_out_buf->i_nb_bytes = p_out_buf->i_nb_samples *
i_nb_channels * sizeof(int32_t);
......
......@@ -113,6 +113,6 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
p_out_buf->i_nb_samples = i_out_nb;
p_out_buf->i_nb_bytes = i_out_nb * i_sample_bytes;
p_out_buf->i_pts = p_in_buf->i_pts;
p_out_buf->end_date = p_out_buf->i_pts + p_out_buf->i_nb_samples *
p_out_buf->i_length = p_out_buf->i_nb_samples *
1000000 / p_filter->output.i_rate;
}
......@@ -126,6 +126,6 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
p_out_buf->i_nb_samples = i_out_nb;
p_out_buf->i_nb_bytes = i_out_nb * i_sample_bytes;
p_out_buf->i_pts = p_in_buf->i_pts;
p_out_buf->end_date = p_out_buf->i_pts + p_out_buf->i_nb_samples *
p_out_buf->i_length = p_out_buf->i_nb_samples *
1000000 / p_filter->output.i_rate;
}
......@@ -663,7 +663,7 @@ static void* OSSThread( vlc_object_t *p_this )
i_size = p_buffer->i_nb_bytes;
/* This is theoretical ... we'll see next iteration whether
* we're drifting */
next_date += p_buffer->end_date - p_buffer->i_pts;
next_date += p_buffer->i_length;
}
else
{
......
......@@ -1062,8 +1062,7 @@ static void* WaveOutThread( vlc_object_t *p_this )
if( p_buffer )
{
mtime_t buffer_length = (p_buffer->end_date
- p_buffer->i_pts);
mtime_t buffer_length = p_buffer->i_length;
next_date = next_date + buffer_length;
i_buffer_length = buffer_length/1000;
}
......
......@@ -394,7 +394,8 @@ static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
if( p_buf == NULL ) return NULL;
p_buf->i_pts = date_Get( &p_sys->end_date );
p_buf->end_date = date_Increment( &p_sys->end_date, p_sys->frame.i_samples );
p_buf->i_length = date_Increment( &p_sys->end_date,
p_sys->frame.i_samples ) - p_buf->i_pts;
return p_buf;
}
......
......@@ -301,8 +301,8 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
p_out->i_pts = date_Get( &p_sys->end_date );
p_out->end_date =
date_Increment( &p_sys->end_date, p_sys->i_samplesperblock );
p_out->i_length = date_Increment( &p_sys->end_date,
p_sys->i_samplesperblock ) - p_out->i_pts;
switch( p_sys->codec )
{
......
......@@ -135,7 +135,8 @@ static aout_buffer_t *Decode( decoder_t *p_dec, block_t **pp_block )
goto exit;
p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
p_aout_buffer->end_date = date_Increment( &p_sys->end_date, i_frame_length );
p_aout_buffer->i_length = date_Increment( &p_sys->end_date,
i_frame_length ) - p_aout_buffer->i_pts;
p_block->i_buffer -= AES3_HEADER_LEN;
p_block->p_buffer += AES3_HEADER_LEN;
......
......@@ -371,7 +371,8 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
p_out->i_pts = date_Get( &p_sys->end_date );
p_out->end_date = date_Increment( &p_sys->end_date, i_samples );
p_out->i_length = date_Increment( &p_sys->end_date, i_samples )
- p_out->i_pts;
if( p_sys->p_logtos16 )
{
......
......@@ -243,7 +243,8 @@ static aout_buffer_t *SplitBuffer( decoder_t *p_dec )
return NULL;
p_buffer->i_pts = date_Get( &p_sys->end_date );
p_buffer->end_date = date_Increment( &p_sys->end_date, i_samples );
p_buffer->i_length = date_Increment( &p_sys->end_date, i_samples )
- p_buffer->i_pts;
if( p_sys->b_extract )
aout_ChannelExtract( p_buffer->p_buffer, p_dec->fmt_out.audio.i_channels,
......
......@@ -982,8 +982,9 @@ static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
block_out.p_buffer, block_out.i_buffer );
/* Date management */
p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
p_aout_buffer->end_date =
date_Increment( &p_sys->end_date, i_samples );
p_aout_buffer->i_length =
date_Increment( &p_sys->end_date, i_samples )
- p_aout_buffer->i_pts;
}
p_out->vt->Release( (IUnknown *)p_out );
......
......@@ -411,8 +411,8 @@ static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
p_buf->i_nb_bytes = p_sys->i_frame_size;
p_buf->i_pts = date_Get( &p_sys->end_date );
p_buf->end_date =
date_Increment( &p_sys->end_date, p_sys->i_frame_length );
p_buf->i_length = date_Increment( &p_sys->end_date, p_sys->i_frame_length )
- p_buf->i_pts;
return p_buf;
}
......
......@@ -415,7 +415,9 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
p_out->i_pts = date_Get( &p_sys->date );
p_out->end_date = date_Increment( &p_sys->date, frame.samples / frame.channels );
p_out->i_length = date_Increment( &p_sys->date,
frame.samples / frame.channels ),
- p_out->i_pts;
DoReordering( (uint32_t *)p_out->p_buffer, samples,
frame.samples / frame.channels, frame.channels,
......
......@@ -663,8 +663,7 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder,
/* Date management (already done by packetizer) */
p_sys->p_aout_buffer->i_pts = p_sys->p_block->i_pts;
p_sys->p_aout_buffer->end_date =
p_sys->p_block->i_pts + p_sys->p_block->i_length;
p_sys->p_aout_buffer->i_length = p_sys->p_block->i_length;
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
......
......@@ -198,7 +198,8 @@ static aout_buffer_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block)
goto drop;
p_out->i_pts = date_Get (&p_sys->end_date );
p_out->end_date = date_Increment (&p_sys->end_date, samples);
p_out->i_length = date_Increment (&p_sys->end_date, samples)
- p_out->i_pts;
if (!p_sys->fixed)
fluid_synth_write_float (p_sys->synth, samples,
p_out->p_buffer, 0, 2,
......
......@@ -361,8 +361,9 @@ static void *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
return NULL;
p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
p_aout_buffer->end_date =
date_Increment( &p_sys->end_date, i_frame_length );
p_aout_buffer->i_length =
date_Increment( &p_sys->end_date, i_frame_length )
- p_aout_buffer->i_pts;
p_block->p_buffer += p_sys->i_header_size + i_padding;
p_block->i_buffer -= p_sys->i_header_size + i_padding;
......
......@@ -539,8 +539,8 @@ static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
if( p_buf == NULL ) return NULL;
p_buf->i_pts = date_Get( &p_sys->end_date );
p_buf->end_date =
date_Increment( &p_sys->end_date, p_sys->i_frame_length );
p_buf->i_length = date_Increment( &p_sys->end_date, p_sys->i_frame_length )
- p_buf->i_pts;
if( p_sys->b_discontinuity )
p_buf->i_flags |= BLOCK_FLAG_DISCONTINUITY;
p_sys->b_discontinuity = false;
......
......@@ -647,7 +647,8 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
if( p_out )
{
p_out->i_pts = date_Get( &p_sys->date );
p_out->end_date = date_Increment( &p_sys->date, i_frames );
p_out->i_length = date_Increment( &p_sys->date, i_frames )
- p_out->i_pts;
memcpy( p_out->p_buffer,
&p_sys->out_buffer[2 * p_sys->i_out * p_dec->fmt_out.audio.i_channels],
......
......@@ -724,8 +724,8 @@ static aout_buffer_t *Decode( decoder_t *p_dec, block_t **pp_block )
/* Date management */
p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
p_aout_buffer->end_date =
date_Increment( &p_sys->end_date, i_samples );
p_aout_buffer->i_length = date_Increment( &p_sys->end_date, i_samples )
- p_aout_buffer->i_pts;
}
block_Release( p_block );
......
......@@ -713,7 +713,7 @@ static aout_buffer_t *DecodeRtpSpeexPacket( decoder_t *p_dec, block_t **pp_block
*/
p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
p_aout_buffer->end_date = date_Increment( &p_sys->end_date,
p_sys->p_header->frame_size );
p_sys->p_header->frame_size ) - p_aout_buffer->i_pts;
p_sys->i_frame_in_packet++;
......@@ -772,8 +772,9 @@ static aout_buffer_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
/* Date management */
p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
p_aout_buffer->end_date =
date_Increment( &p_sys->end_date, p_sys->p_header->frame_size );
p_aout_buffer->i_length =
date_Increment( &p_sys->end_date, p_sys->p_header->frame_size )
- p_aout_buffer->i_pts;
p_sys->i_frame_in_packet++;
......
......@@ -560,7 +560,8 @@ static aout_buffer_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
/* Date management */
p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
p_aout_buffer->end_date = date_Increment( &p_sys->end_date, i_samples );
p_aout_buffer->i_length = date_Increment( &p_sys->end_date,
i_samples ) - p_aout_buffer->i_pts;
return p_aout_buffer;
}
else
......
......@@ -102,7 +102,8 @@ static aout_buffer_t *SplitBuffer( decoder_t *p_dec )
return NULL;
p_buffer->i_pts = date_Get( &p_sys->end_date );
p_buffer->end_date = date_Increment( &p_sys->end_date, i_samples );
p_buffer->i_length = date_Increment( &p_sys->end_date, i_samples )
- p_buffer->i_pts;
memcpy( p_buffer->p_buffer, p_sys->p_samples, p_buffer->i_nb_bytes );
p_sys->p_samples += p_buffer->i_nb_bytes;
......
......@@ -1305,15 +1305,13 @@ static int transcode_audio_process( sout_stream_t *p_stream,
p_sys->i_master_drift = p_audio_buf->i_pts - i_dts;
date_Increment( &id->interpolated_pts, p_audio_buf->i_nb_samples );
p_audio_buf->i_pts -= p_sys->i_master_drift;
p_audio_buf->end_date -= p_sys->i_master_drift;
}
p_audio_block = p_audio_buf->p_sys;
p_audio_block->i_buffer = p_audio_buf->i_nb_bytes;
p_audio_block->i_dts = p_audio_block->i_pts =
p_audio_buf->i_pts;
p_audio_block->i_length = p_audio_buf->end_date -
p_audio_buf->i_pts;
p_audio_block->i_length = p_audio_buf->i_length;
p_audio_block->i_nb_samples = p_audio_buf->i_nb_samples;
/* Run filter chain */
......@@ -1330,7 +1328,7 @@ static int transcode_audio_process( sout_stream_t *p_stream,
p_audio_buf->i_nb_bytes = p_audio_block->i_buffer;
p_audio_buf->i_nb_samples = p_audio_block->i_nb_samples;
p_audio_buf->i_pts = p_audio_block->i_dts;
p_audio_buf->end_date = p_audio_block->i_dts + p_audio_block->i_length;
p_audio_buf->i_length = p_audio_block->i_length;
audio_timer_start( id->p_encoder );
p_block = id->p_encoder->pf_encode_audio( id->p_encoder, p_audio_buf );
......
......@@ -375,7 +375,7 @@ static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter,
#undef p_effect
}
p_outpic->date = ( p_in_buf->i_pts + p_in_buf->end_date ) / 2;
p_outpic->date = p_in_buf->i_pts + (p_in_buf->i_length / 2);
vout_DisplayPicture( p_sys->p_vout, p_outpic );
}
......
......@@ -370,12 +370,13 @@ void aout_FifoPush( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
if ( date_Get( &p_fifo->end_date ) )
{
p_buffer->i_pts = date_Get( &p_fifo->end_date );
p_buffer->end_date = date_Increment( &p_fifo->end_date,
p_buffer->i_length = date_Increment( &p_fifo->end_date,
p_buffer->i_nb_samples );
p_buffer->i_length -= p_buffer->i_pts;
}
else
{
date_Set( &p_fifo->end_date, p_buffer->end_date );
date_Set( &p_fifo->end_date, p_buffer->i_pts + p_buffer->i_length );
}
}
......@@ -417,7 +418,6 @@ void aout_FifoMoveDates( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
while ( p_buffer != NULL )
{
p_buffer->i_pts += difference;
p_buffer->end_date += difference;
p_buffer = p_buffer->p_next;
}
}
......
......@@ -281,7 +281,7 @@ aout_buffer_t * aout_DecNewBuffer( aout_input_t * p_input,
return NULL;
p_buffer->i_nb_samples = i_nb_samples;
p_buffer->i_pts = p_buffer->end_date = 0;
p_buffer->i_pts = p_buffer->i_length = 0;
return p_buffer;
}
......@@ -306,8 +306,7 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
assert( p_buffer->i_pts > 0 );
p_buffer->end_date = p_buffer->i_pts
+ (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_input( p_aout, p_input );
......@@ -332,7 +331,7 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
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->i_pts = p_buffer->i_pts;
p_new_buffer->end_date = p_buffer->end_date;
p_new_buffer->i_length = p_buffer->i_length;
aout_BufferFree( p_buffer );
p_buffer = p_new_buffer;
p_input->b_changed = false;
......@@ -384,7 +383,6 @@ void aout_DecChangePause( aout_instance_t *p_aout, aout_input_t *p_input, bool b
for( aout_buffer_t *p = p_input->mixer.fifo.p_first; p != NULL; p = p->p_next )
{
p->i_pts += i_duration;
p->end_date += i_duration;
}
aout_unlock_mixer( p_aout );
}
......
......@@ -354,7 +354,7 @@ void aout_FiltersPlay( aout_instance_t * p_aout,
if( p_output_buffer == NULL )
return;
p_output_buffer->i_pts = (*pp_input_buffer)->i_pts;
p_output_buffer->end_date = (*pp_input_buffer)->end_date;
p_output_buffer->i_length = (*pp_input_buffer)->i_length;
/* Please note that p_output_buffer->i_nb_samples & i_nb_bytes
* shall be set by the filter plug-in. */
......
......@@ -744,8 +744,6 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
#endif
/* Adding the start date will be managed by aout_FifoPush(). */
p_buffer->end_date = start_date +
(p_buffer->end_date - p_buffer->i_pts);
p_buffer->i_pts = start_date;
aout_lock_input_fifos( p_aout );
......
......@@ -225,13 +225,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,10 +248,10 @@ 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 )
......@@ -263,8 +264,8 @@ static int MixBuffer( aout_instance_t * p_aout )
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 )
{
......@@ -353,7 +354,7 @@ static int MixBuffer( aout_instance_t * p_aout )
/ p_aout->p_mixer->fmt.i_frame_length;
}
p_output_buffer->i_pts = start_date;
p_output_buffer->end_date = end_date;
p_output_buffer->i_length = end_date - start_date;
p_aout->p_mixer->mix( p_aout->p_mixer, p_output_buffer );
......
......@@ -288,7 +288,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
{
msg_Dbg( p_aout, "audio output is too slow (%"PRId64"), "
"trashing %"PRId64"us", mdate() - p_buffer->i_pts,
p_buffer->end_date - p_buffer->i_pts );
p_buffer->i_length );
p_buffer = p_buffer->p_next;
aout_BufferFree( p_aout->output.fifo.p_first );
p_aout->output.fifo.p_first = p_buffer;
......@@ -317,8 +317,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
/* Here we suppose that all buffers have the same duration - this is
* generally true, and anyway if it's wrong it won't be a disaster.
*/
if ( p_buffer->i_pts > start_date
+ (p_buffer->end_date - p_buffer->i_pts) )
if ( p_buffer->i_pts > start_date + p_buffer->i_length )
/*
* + AOUT_PTS_TOLERANCE )
* There is no reason to want that, it just worsen the scheduling of
......
......@@ -1171,7 +1171,7 @@ static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
const bool b_dated = p_audio->i_pts > VLC_TS_INVALID;
int i_rate = INPUT_RATE_DEFAULT;
DecoderFixTs( p_dec, &p_audio->i_pts, &p_audio->end_date, NULL,
DecoderFixTs( p_dec, &p_audio->i_pts, NULL, &p_audio->i_length,
&i_rate, AOUT_MAX_ADVANCE_TIME, false );
vlc_mutex_unlock( &p_owner->lock );
......
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