Commit 5e99694d authored by François Cartegnie's avatar François Cartegnie 🤞

vlc_block_helper: allow non raw byte matching on startcodes

required for optimizations in packetizers with bitmask sequence
parent 1af7965c
...@@ -277,11 +277,13 @@ static inline int block_PeekOffsetBytes( block_bytestream_t *p_bytestream, ...@@ -277,11 +277,13 @@ static inline int block_PeekOffsetBytes( block_bytestream_t *p_bytestream,
} }
typedef const uint8_t * (*block_startcode_helper_t)( const uint8_t *, const uint8_t * ); typedef const uint8_t * (*block_startcode_helper_t)( const uint8_t *, const uint8_t * );
typedef bool (*block_startcode_matcher_t)( uint8_t, size_t, const uint8_t * );
static inline int block_FindStartcodeFromOffset( static inline int block_FindStartcodeFromOffset(
block_bytestream_t *p_bytestream, size_t *pi_offset, 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_startcode_helper_t p_startcode_helper,
block_startcode_matcher_t p_startcode_matcher )
{ {
block_t *p_block, *p_block_backup = 0; block_t *p_block, *p_block_backup = 0;
ssize_t i_size = 0; ssize_t i_size = 0;
...@@ -328,9 +330,12 @@ static inline int block_FindStartcodeFromOffset( ...@@ -328,9 +330,12 @@ static inline int block_FindStartcodeFromOffset(
i_offset = p_block->i_buffer - (i_startcode_length - 1); i_offset = p_block->i_buffer - (i_startcode_length - 1);
} }
if( p_block->p_buffer[i_offset] == p_startcode[i_match] ) bool b_matched = ( p_startcode_matcher )
? p_startcode_matcher( p_block->p_buffer[i_offset], i_match, p_startcode )
: p_block->p_buffer[i_offset] == p_startcode[i_match];
if( b_matched )
{ {
if( !i_match ) if( i_match == 0 )
{ {
p_block_backup = p_block; p_block_backup = p_block;
i_offset_backup = i_offset; i_offset_backup = i_offset;
...@@ -346,7 +351,7 @@ static inline int block_FindStartcodeFromOffset( ...@@ -346,7 +351,7 @@ static inline int block_FindStartcodeFromOffset(
i_match++; i_match++;
} }
else if ( i_match ) else if ( i_match > 0 )
{ {
/* False positive */ /* False positive */
p_block = p_block_backup; p_block = p_block_backup;
......
...@@ -677,7 +677,8 @@ static block_t *dirac_DoSync( decoder_t *p_dec ) ...@@ -677,7 +677,8 @@ static block_t *dirac_DoSync( decoder_t *p_dec )
case NOT_SYNCED: case NOT_SYNCED:
{ {
if( VLC_SUCCESS != if( VLC_SUCCESS !=
block_FindStartcodeFromOffset( &p_sys->bytestream, &p_sys->i_offset, p_parsecode, 4, NULL ) ) block_FindStartcodeFromOffset( &p_sys->bytestream, &p_sys->i_offset,
p_parsecode, 4, NULL, NULL ) )
{ {
/* p_sys->i_offset will have been set to: /* p_sys->i_offset will have been set to:
* end of bytestream - amount of prefix found * end of bytestream - amount of prefix found
......
...@@ -141,7 +141,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_ ...@@ -141,7 +141,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
/* Find a startcode */ /* Find a startcode */
if( !block_FindStartcodeFromOffset( &p_pack->bytestream, &p_pack->i_offset, 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,
p_pack->pf_startcode_helper ) ) p_pack->pf_startcode_helper, NULL ) )
p_pack->i_state = STATE_NEXT_SYNC; p_pack->i_state = STATE_NEXT_SYNC;
if( p_pack->i_offset ) if( p_pack->i_offset )
...@@ -160,7 +160,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_ ...@@ -160,7 +160,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
/* Find the next startcode */ /* Find the next startcode */
if( block_FindStartcodeFromOffset( &p_pack->bytestream, &p_pack->i_offset, 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,
p_pack->pf_startcode_helper ) ) p_pack->pf_startcode_helper, NULL ) )
{ {
if( pp_block /* not flushing */ || !p_pack->bytestream.p_chain ) if( pp_block /* not flushing */ || !p_pack->bytestream.p_chain )
return NULL; /* Need more data */ 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