From: Steinar Gunderson Date: Sat, 25 Sep 2010 22:44:31 +0000 (+0200) Subject: Send one buffer per packet/frame. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=fcad9fc4e99616301554d1772a23fbe0101f3b70;p=vlc Send one buffer per packet/frame. --- diff --git a/modules/codec/lpcm.c b/modules/codec/lpcm.c index 01cbbbc6a6..f323304c9e 100644 --- a/modules/codec/lpcm.c +++ b/modules/codec/lpcm.c @@ -485,7 +485,7 @@ static void CloseEncoder ( vlc_object_t *p_this ) static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) { encoder_sys_t *p_sys = p_enc->p_sys; - block_t *p_block = NULL; + block_t *p_first_block = NULL, *p_last_block = NULL; if( !p_aout_buf || !p_aout_buf->i_buffer ) return NULL; @@ -495,10 +495,6 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) p_sys->i_frame_samples; const int i_frame_size = p_sys->i_frame_samples * p_sys->i_channels * 2 + LPCM_VOB_HEADER_LEN; - p_block = block_New( p_enc, i_num_frames * i_frame_size ); - if( !p_block ) - return NULL; - uint8_t i_freq_code = 0; switch( p_sys->i_rate ) { @@ -520,7 +516,11 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) for ( int i = 0; i < i_num_frames; ++i ) { - uint8_t *frame = (uint8_t *)p_block->p_buffer + i * i_frame_size; + block_t *p_block = block_New( p_enc, i_frame_size ); + if( !p_block ) + return NULL; + + uint8_t *frame = (uint8_t *)p_block->p_buffer; frame[0] = 1; /* one frame in packet */ frame[1] = 0; frame[2] = 0; /* no first access unit */ @@ -538,6 +538,18 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) p_sys->i_frame_num++; p_sys->i_buffer_used = 0; i_bytes_consumed += i_consume_bytes; + + /* + * The pts is strictly not correct if we have samples kept from + * a previous buffer, but the frames are so small it should be OK. + */ + p_block->i_dts = p_block->i_pts = p_aout_buf->i_pts + i * p_sys->i_frame_samples * CLOCK_FREQ / p_sys->i_rate; + p_block->i_length = p_sys->i_frame_samples * CLOCK_FREQ / p_sys->i_rate; + + if( !p_first_block ) + p_first_block = p_last_block = p_block; + else + block_ChainLastAppend( &p_last_block, p_block ); } memcpy( p_sys->p_buffer, @@ -545,14 +557,7 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) i_leftover_samples * p_sys->i_channels * 2 ); p_sys->i_buffer_used = i_leftover_samples; - /* - * The pts is strictly not correct if we have samples kept from - * a previous buffer, but the frames are so small it should be OK. - */ - p_block->i_dts = p_block->i_pts = p_aout_buf->i_pts; - p_block->i_length = (int64_t)i_num_frames * p_sys->i_frame_samples * CLOCK_FREQ / p_sys->i_rate; - - return p_block; + return p_first_block; } /*****************************************************************************