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;
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 ) {
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 */
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,
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;
}
/*****************************************************************************