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

block_helper: add startcode helper callback

parent 000d5d3f
......@@ -438,9 +438,12 @@ static inline int block_PeekOffsetBytes( block_bytestream_t *p_bytestream,
return VLC_SUCCESS;
}
typedef const uint8_t * (*block_startcode_helper_t)( const uint8_t *, const uint8_t * );
static inline int block_FindStartcodeFromOffset(
block_bytestream_t *p_bytestream, size_t *pi_offset,
const uint8_t *p_startcode, int i_startcode_length )
const uint8_t *p_startcode, int i_startcode_length,
block_startcode_helper_t p_startcode_helper )
{
block_t *p_block, *p_block_backup = 0;
int i_size = 0;
......@@ -472,6 +475,21 @@ static inline int block_FindStartcodeFromOffset(
{
for( i_offset = i_size; i_offset < p_block->i_buffer; i_offset++ )
{
/* Use optimized helper when possible */
if( p_startcode_helper && !i_match &&
(p_block->i_buffer - i_offset) > ((size_t)i_startcode_length - 1) )
{
const uint8_t *p_res = p_startcode_helper( &p_block->p_buffer[i_offset],
&p_block->p_buffer[p_block->i_buffer] );
if( p_res )
{
*pi_offset += i_offset + (p_res - &p_block->p_buffer[i_offset]);
return VLC_SUCCESS;
}
/* Then parsing boundary with legacy code */
i_offset = p_block->i_buffer - (i_startcode_length - 1);
}
if( p_block->p_buffer[i_offset] == p_startcode[i_match] )
{
if( !i_match )
......
......@@ -677,7 +677,7 @@ static block_t *dirac_DoSync( decoder_t *p_dec )
case NOT_SYNCED:
{
if( VLC_SUCCESS !=
block_FindStartcodeFromOffset( &p_sys->bytestream, &p_sys->i_offset, p_parsecode, 4 ) )
block_FindStartcodeFromOffset( &p_sys->bytestream, &p_sys->i_offset, p_parsecode, 4, NULL ) )
{
/* p_sys->i_offset will have been set to:
* end of bytestream - amount of prefix found
......
......@@ -132,7 +132,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
case STATE_NOSYNC:
/* Find a startcode */
if( !block_FindStartcodeFromOffset( &p_pack->bytestream, &p_pack->i_offset,
p_pack->p_startcode, p_pack->i_startcode ) )
p_pack->p_startcode, p_pack->i_startcode, NULL ) )
p_pack->i_state = STATE_NEXT_SYNC;
if( p_pack->i_offset )
......@@ -150,7 +150,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
case STATE_NEXT_SYNC:
/* Find the next startcode */
if( block_FindStartcodeFromOffset( &p_pack->bytestream, &p_pack->i_offset,
p_pack->p_startcode, p_pack->i_startcode ) )
p_pack->p_startcode, p_pack->i_startcode, NULL ) )
{
if( !p_pack->b_flushing || !p_pack->bytestream.p_chain )
return NULL; /* Need more data */
......
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