[vlc-commits] block_helper: add startcode helper callback

Francois Cartegnie git at videolan.org
Tue Jan 5 19:19:52 CET 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jan  5 16:08:09 2016 +0100| [c064a7f712a31cb85cfd64c07e8a19473d9cb61c] | committer: Francois Cartegnie

block_helper: add startcode helper callback

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

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

diff --git a/include/vlc_block_helper.h b/include/vlc_block_helper.h
index 4414307..444286f 100644
--- a/include/vlc_block_helper.h
+++ b/include/vlc_block_helper.h
@@ -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 )
diff --git a/modules/packetizer/dirac.c b/modules/packetizer/dirac.c
index 59b9474..f950535 100644
--- a/modules/packetizer/dirac.c
+++ b/modules/packetizer/dirac.c
@@ -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
diff --git a/modules/packetizer/packetizer_helper.h b/modules/packetizer/packetizer_helper.h
index c38c255..7503ed1 100644
--- a/modules/packetizer/packetizer_helper.h
+++ b/modules/packetizer/packetizer_helper.h
@@ -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 */



More information about the vlc-commits mailing list