Commit ab77df12 authored by François Cartegnie's avatar François Cartegnie 🤞

packetizer_helper: implement draining

parent 8de506e9
......@@ -45,7 +45,6 @@ typedef struct
int i_state;
block_bytestream_t bytestream;
size_t i_offset;
bool b_flushing;
int i_startcode;
const uint8_t *p_startcode;
......@@ -76,7 +75,6 @@ static inline void packetizer_Init( packetizer_t *p_pack,
p_pack->i_state = STATE_NOSYNC;
block_BytestreamInit( &p_pack->bytestream );
p_pack->i_offset = 0;
p_pack->b_flushing = false;
p_pack->i_au_prepend = i_au_prepend;
p_pack->p_au_prepend = p_au_prepend;
......@@ -106,24 +104,31 @@ static inline void packetizer_Flush( packetizer_t *p_pack )
static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_block )
{
if( !pp_block || !*pp_block )
return NULL;
block_t *p_block = ( pp_block ) ? *pp_block : NULL;
if( unlikely( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
if( p_block == NULL && p_pack->bytestream.p_block == NULL )
return NULL; /* nothing to do */
if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
{
const bool b_broken = ( (*pp_block)->i_flags&BLOCK_FLAG_CORRUPTED ) != 0;
block_t *p_drained = packetizer_Packetize( p_pack, NULL );
if( p_drained )
return p_drained;
const bool b_broken = !!( p_block->i_flags&BLOCK_FLAG_CORRUPTED );
p_pack->i_state = STATE_NOSYNC;
block_BytestreamEmpty( &p_pack->bytestream );
p_pack->i_offset = 0;
p_pack->pf_reset( p_pack->p_private, b_broken );
if( b_broken )
{
block_Release( *pp_block );
block_Release( p_block );
return NULL;
}
}
block_BytestreamPush( &p_pack->bytestream, *pp_block );
if( p_block )
block_BytestreamPush( &p_pack->bytestream, p_block );
for( ;; )
{
......@@ -157,7 +162,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
p_pack->p_startcode, p_pack->i_startcode,
p_pack->pf_startcode_helper ) )
{
if( !p_pack->b_flushing || !p_pack->bytestream.p_chain )
if( pp_block /* not flushing */ || !p_pack->bytestream.p_chain )
return NULL; /* Need more data */
/* When flusing and we don't find a startcode, suppose that
......@@ -215,7 +220,8 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
}
/* So p_block doesn't get re-added several times */
*pp_block = block_BytestreamPop( &p_pack->bytestream );
if( pp_block )
*pp_block = block_BytestreamPop( &p_pack->bytestream );
p_pack->i_state = STATE_NOSYNC;
......@@ -233,16 +239,15 @@ static inline void packetizer_Header( packetizer_t *p_pack,
memcpy( p_init->p_buffer, p_header, i_header );
p_pack->b_flushing = true;
block_t *p_pic;
while( ( p_pic = packetizer_Packetize( p_pack, &p_init ) ) )
block_Release( p_pic ); /* Should not happen (only sequence header) */
while( ( p_pic = packetizer_Packetize( p_pack, NULL ) ) )
block_Release( p_pic );
p_pack->i_state = STATE_NOSYNC;
block_BytestreamEmpty( &p_pack->bytestream );
p_pack->i_offset = 0;
p_pack->b_flushing = false;
}
#endif
......
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