[vlc-commits] packetizer: mpeg4audio: factorize header check

Francois Cartegnie git at videolan.org
Sat Jul 22 01:44:38 CEST 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Jul 22 01:26:25 2017 +0200| [15ff8883e4eca54a440397ad0a3a8b5e84753cdd] | committer: Francois Cartegnie

packetizer: mpeg4audio: factorize header check

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

 modules/packetizer/mpeg4audio.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/modules/packetizer/mpeg4audio.c b/modules/packetizer/mpeg4audio.c
index bb7e5663a5..9c5fc15503 100644
--- a/modules/packetizer/mpeg4audio.c
+++ b/modules/packetizer/mpeg4audio.c
@@ -1000,6 +1000,16 @@ static void Flush(decoder_t *p_dec)
     p_sys->b_discontuinity = true;
 }
 
+static inline bool HasADTSHeader( const uint8_t *p_header )
+{
+    return p_header[0] == 0xff && (p_header[1] & 0xf6) == 0xf0;
+}
+
+static inline bool HasLoasHeader( const uint8_t *p_header )
+{
+    return p_header[0] == 0x56 && (p_header[1] & 0xe0) == 0xe0;
+}
+
 /****************************************************************************
  * PacketizeStreamBlock: ADTS/LOAS packetizer
  ****************************************************************************/
@@ -1023,7 +1033,7 @@ static block_t *PacketizeStreamBlock(decoder_t *p_dec, block_t **pp_block)
         while (block_PeekBytes(&p_sys->bytestream, p_header, 2) == VLC_SUCCESS) {
             /* Look for sync word - should be 0xfff(adts) or 0x2b7(loas) */
             if ((p_sys->i_type == TYPE_ADTS || p_sys->i_type == TYPE_UNKNOWN_NONRAW) &&
-                p_header[0] == 0xff && (p_header[1] & 0xf6) == 0xf0)
+                HasADTSHeader( p_header ) )
             {
                 if (p_sys->i_type != TYPE_ADTS)
                     msg_Dbg(p_dec, "detected ADTS format");
@@ -1033,7 +1043,7 @@ static block_t *PacketizeStreamBlock(decoder_t *p_dec, block_t **pp_block)
                 break;
             }
             else if ((p_sys->i_type == TYPE_LOAS || p_sys->i_type == TYPE_UNKNOWN_NONRAW) &&
-                      p_header[0] == 0x56 && (p_header[1] & 0xe0) == 0xe0)
+                      HasLoasHeader( p_header ) )
             {
                 if (p_sys->i_type != TYPE_LOAS)
                     msg_Dbg(p_dec, "detected LOAS format");
@@ -1113,10 +1123,9 @@ static block_t *PacketizeStreamBlock(decoder_t *p_dec, block_t **pp_block)
         }
 
         assert((p_sys->i_type == TYPE_ADTS) || (p_sys->i_type == TYPE_LOAS));
-        if (((p_sys->i_type == TYPE_ADTS) &&
-                    (p_header[0] != 0xff || (p_header[1] & 0xf6) != 0xf0)) ||
-                ((p_sys->i_type == TYPE_LOAS) &&
-                 (p_header[0] != 0x56 || (p_header[1] & 0xe0) != 0xe0))) {
+        if ( (p_sys->i_type == TYPE_ADTS && !HasADTSHeader( p_header )) ||
+             (p_sys->i_type == TYPE_LOAS && !HasLoasHeader( p_header )) )
+        {
             msg_Dbg(p_dec, "emulated sync word "
                     "(no sync on following frame)");
             p_sys->i_state = STATE_NOSYNC;



More information about the vlc-commits mailing list