[vlc-commits] vlc_block_helper: allow non raw byte matching on startcodes

Francois Cartegnie git at videolan.org
Wed Feb 8 19:26:09 CET 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Feb  8 19:04:56 2017 +0100| [5e99694de8e7c794434803c943dc0ea12a9a9e4f] | committer: Francois Cartegnie

vlc_block_helper: allow non raw byte matching on startcodes

required for optimizations in packetizers with bitmask sequence

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5e99694de8e7c794434803c943dc0ea12a9a9e4f
---

 include/vlc_block_helper.h             | 13 +++++++++----
 modules/packetizer/dirac.c             |  3 ++-
 modules/packetizer/packetizer_helper.h |  4 ++--
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/include/vlc_block_helper.h b/include/vlc_block_helper.h
index 0e9e6bf..b94b461 100644
--- a/include/vlc_block_helper.h
+++ b/include/vlc_block_helper.h
@@ -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;
diff --git a/modules/packetizer/dirac.c b/modules/packetizer/dirac.c
index d18e1e5..359a046 100644
--- a/modules/packetizer/dirac.c
+++ b/modules/packetizer/dirac.c
@@ -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
diff --git a/modules/packetizer/packetizer_helper.h b/modules/packetizer/packetizer_helper.h
index 171ca5c..14642a4 100644
--- a/modules/packetizer/packetizer_helper.h
+++ b/modules/packetizer/packetizer_helper.h
@@ -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 */



More information about the vlc-commits mailing list