Commit 8de506e9 authored by François Cartegnie's avatar François Cartegnie 🤞

packetizer: mpegaudio: implement draining and proper discontinuity handling

parent ce02dd5c
...@@ -291,16 +291,18 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -291,16 +291,18 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
{ {
if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{ {
/* First always drain complete blocks before discontinuity */
block_t *p_drain = DecodeBlock( p_dec, NULL );
if( p_drain )
return p_drain;
Flush( p_dec );
if( p_block->i_flags & BLOCK_FLAG_CORRUPTED ) if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
{ {
Flush( p_dec );
block_Release( p_block ); block_Release( p_block );
*pp_block = NULL;
return NULL; return NULL;
} }
else /* BLOCK_FLAG_DISCONTINUITY */
date_Set( &p_sys->end_date, 0 );
p_sys->b_discontinuity = true;
} }
if( !date_Get( &p_sys->end_date ) && p_block->i_pts <= VLC_TS_INVALID ) if( !date_Get( &p_sys->end_date ) && p_block->i_pts <= VLC_TS_INVALID )
...@@ -312,10 +314,7 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -312,10 +314,7 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
} }
block_BytestreamPush( &p_sys->bytestream, p_block ); block_BytestreamPush( &p_sys->bytestream, p_block );
} else if (p_sys->i_frame_size) }
p_sys->i_state = STATE_SEND_DATA; /* return all the data we have left */
else
return NULL;
while( 1 ) while( 1 )
{ {
...@@ -406,14 +405,16 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -406,14 +405,16 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_sys->i_state = STATE_NEXT_SYNC; p_sys->i_state = STATE_NEXT_SYNC;
case STATE_NEXT_SYNC: case STATE_NEXT_SYNC:
/* TODO: If p_block == NULL, flush the buffer without checking the
* next sync word */
/* Check if next expected frame contains the sync word */ /* Check if next expected frame contains the sync word */
if( block_PeekOffsetBytes( &p_sys->bytestream, if( block_PeekOffsetBytes( &p_sys->bytestream,
p_sys->i_frame_size, p_header, p_sys->i_frame_size, p_header,
MAD_BUFFER_GUARD ) != VLC_SUCCESS ) MAD_BUFFER_GUARD ) != VLC_SUCCESS )
{ {
if( p_block == NULL ) /* drain */
{
p_sys->i_state = STATE_SEND_DATA;
break;
}
/* Need more data */ /* Need more data */
return NULL; return NULL;
} }
......
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