From e89582162ed896d50a2e292e51c335ee26a7a9c1 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 2 Oct 2010 00:06:00 +0200 Subject: [PATCH] Fix roundoff issues in i_length. --- modules/codec/lpcm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/codec/lpcm.c b/modules/codec/lpcm.c index 73b9078096..2d5c6126f5 100644 --- a/modules/codec/lpcm.c +++ b/modules/codec/lpcm.c @@ -559,9 +559,14 @@ static block_t *EncodeFrames( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) p_sys->i_buffer_used = 0; i_bytes_consumed += i_consume_bytes; - p_block->i_dts = p_block->i_pts = p_aout_buf->i_pts + + /* We need to find i_length by means of next_pts due to possible roundoff errors. */ + mtime_t this_pts = p_aout_buf->i_pts + (i * p_sys->i_frame_samples + i_start_offset) * CLOCK_FREQ / p_sys->i_rate; - p_block->i_length = p_sys->i_frame_samples * CLOCK_FREQ / p_sys->i_rate; + mtime_t next_pts = p_aout_buf->i_pts + + ((i + 1) * p_sys->i_frame_samples + i_start_offset) * CLOCK_FREQ / p_sys->i_rate; + + p_block->i_pts = p_block->i_dts = this_pts; + p_block->i_length = next_pts - this_pts; if( !p_first_block ) p_first_block = p_last_block = p_block; -- 2.39.2