vlc_block_helper: allow non raw byte matching on startcodes
authorFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 8 Feb 2017 18:04:56 +0000 (19:04 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 8 Feb 2017 18:24:51 +0000 (19:24 +0100)
required for optimizations in packetizers with bitmask sequence

include/vlc_block_helper.h
modules/packetizer/dirac.c
modules/packetizer/packetizer_helper.h

index 0e9e6bf..b94b461 100644 (file)
@@ -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 bool (*block_startcode_matcher_t)( uint8_t, size_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,
-    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;
     ssize_t i_size = 0;
@@ -328,9 +330,12 @@ static inline int block_FindStartcodeFromOffset(
                 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;
                     i_offset_backup = i_offset;
@@ -346,7 +351,7 @@ static inline int block_FindStartcodeFromOffset(
 
                 i_match++;
             }
-            else if ( i_match )
+            else if ( i_match > 0 )
             {
                 /* False positive */
                 p_block = p_block_backup;
index d18e1e5..359a046 100644 (file)
@@ -677,7 +677,8 @@ 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, NULL ) )
+                block_FindStartcodeFromOffset( &p_sys->bytestream, &p_sys->i_offset,
+                                               p_parsecode, 4, NULL, NULL ) )
             {
                 /* p_sys->i_offset will have been set to:
                  *   end of bytestream - amount of prefix found
index 171ca5c..14642a4 100644 (file)
@@ -141,7 +141,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
             /* Find a startcode */
             if( !block_FindStartcodeFromOffset( &p_pack->bytestream, &p_pack->i_offset,
                                                 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;
 
             if( p_pack->i_offset )
@@ -160,7 +160,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
             /* Find the next startcode */
             if( block_FindStartcodeFromOffset( &p_pack->bytestream, &p_pack->i_offset,
                                                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 )
                     return NULL; /* Need more data */