[vlc-commits] demux: adaptive: use ID3tag helper

Francois Cartegnie git at videolan.org
Mon Sep 5 15:31:31 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Sep  5 15:16:50 2016 +0200| [15aec716bd08eb392d9c5035f95258bd95b590fa] | committer: Francois Cartegnie

demux: adaptive: use ID3tag helper

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

 modules/demux/Makefile.am        |  1 +
 modules/demux/hls/HLSStreams.cpp | 66 ++++++++++++++++------------------------
 modules/demux/hls/HLSStreams.hpp |  1 +
 3 files changed, 28 insertions(+), 40 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index ceb20fd..61aa82b 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -413,6 +413,7 @@ libadaptive_hls_SOURCES = \
     demux/hls/HLSManager.cpp \
     demux/hls/HLSStreams.hpp \
     demux/hls/HLSStreams.cpp
+libadaptive_hls_SOURCES += meta_engine/ID3Tag.h
 
 libadaptive_smooth_SOURCES = \
     demux/smooth/mp4/IndexReader.cpp \
diff --git a/modules/demux/hls/HLSStreams.cpp b/modules/demux/hls/HLSStreams.cpp
index c8a8833..5cf90fc 100644
--- a/modules/demux/hls/HLSStreams.cpp
+++ b/modules/demux/hls/HLSStreams.cpp
@@ -24,6 +24,11 @@
 #include "HLSStreams.hpp"
 #include <vlc_demux.h>
 
+extern "C"
+{
+    #include "../meta_engine/ID3Tag.h"
+}
+
 using namespace hls;
 
 HLSStream::HLSStream(demux_t *demux)
@@ -101,58 +106,39 @@ void HLSStream::prepareRestart(bool b_discontinuity)
     }
 }
 
-static uint32_t ReadID3Size(const uint8_t *p_buffer)
+int HLSStream::ID3PrivTagHandler(const uint8_t *p_payload, size_t i_payload)
 {
-    return ( (uint32_t)p_buffer[3] & 0x7F ) |
-          (( (uint32_t)p_buffer[2] & 0x7F ) << 7) |
-          (( (uint32_t)p_buffer[1] & 0x7F ) << 14) |
-          (( (uint32_t)p_buffer[0] & 0x7F ) << 21);
+    if(i_payload == 53 &&
+       !memcmp( p_payload, "com.apple.streaming.transportStreamTimestamp", 45))
+    {
+        i_aac_offset = GetQWBE(&p_payload[45]) * 100 / 9;
+        b_timestamps_offset_set = true;
+        return VLC_EGENERIC; /* stop parsing */
+    }
+    return VLC_SUCCESS;
 }
 
-static bool IsID3Tag(const uint8_t *p_buffer, bool b_footer)
+static int ID3TAG_Parse_Handler(uint32_t i_tag, const uint8_t *p_payload, size_t i_payload, void *p_priv)
 {
-    return( memcmp(p_buffer, (b_footer) ? "3DI" : "ID3", 3) == 0 &&
-            p_buffer[3] < 0xFF &&
-            p_buffer[4] < 0xFF &&
-           ((GetDWBE(&p_buffer[6]) & 0x80808080) == 0) );
+    HLSStream *hlsstream = static_cast<HLSStream *>(p_priv);
+
+    if(i_tag == VLC_FOURCC('P', 'R', 'I', 'V'))
+        return hlsstream->ID3PrivTagHandler(p_payload, i_payload);
+
+    return VLC_SUCCESS;
 }
 
 block_t * HLSStream::checkBlock(block_t *p_block, bool b_first)
 {
     if(b_first && p_block &&
-       p_block->i_buffer >= 10 && IsID3Tag(p_block->p_buffer, false))
+       p_block->i_buffer >= 10 && ID3TAG_IsTag(p_block->p_buffer, false))
     {
-        uint32_t size = ReadID3Size(&p_block->p_buffer[6]);
-        size = __MIN(p_block->i_buffer, size + 10);
-        const uint8_t *p_frame = &p_block->p_buffer[10];
-        uint32_t i_left = (size >= 10) ? size - 10 : 0;
-        while(i_left >= 10 && !b_timestamps_offset_set)
-        {
-            uint32_t i_framesize = ReadID3Size(&p_frame[4]) + 10;
-            if( i_framesize > i_left )
-                break;
-            if(i_framesize == 63 && !memcmp(p_frame, "PRIV", 4))
-            {
-                if(!memcmp(&p_frame[10], "com.apple.streaming.transportStreamTimestamp", 45))
-                {
-                    i_aac_offset = GetQWBE(&p_frame[55]) * 100 / 9;
-                    b_timestamps_offset_set = true;
-                }
-            }
-            i_left -= i_framesize;
-            p_frame += i_framesize;
-        }
+        size_t i_size = ID3TAG_Parse( p_block->p_buffer, p_block->i_buffer,
+                                      ID3TAG_Parse_Handler, static_cast<void *>(this) );
 
         /* Skip ID3 for demuxer */
-        p_block->p_buffer += size;
-        p_block->i_buffer -= size;
-
-        /* Skip ID3 footer */
-        if(p_block->i_buffer >= 10 && IsID3Tag(p_block->p_buffer, true))
-        {
-            p_block->p_buffer += 10;
-            p_block->i_buffer -= 10;
-        }
+        p_block->p_buffer += i_size;
+        p_block->i_buffer -= i_size;
     }
 
     return p_block;
diff --git a/modules/demux/hls/HLSStreams.hpp b/modules/demux/hls/HLSStreams.hpp
index 97e0b8d..4cdf99f 100644
--- a/modules/demux/hls/HLSStreams.hpp
+++ b/modules/demux/hls/HLSStreams.hpp
@@ -31,6 +31,7 @@ namespace hls
         public:
             HLSStream(demux_t *);
             virtual bool setPosition(mtime_t, bool); /* reimpl */
+            int ID3PrivTagHandler( const uint8_t *, size_t );
 
         protected:
             virtual AbstractDemuxer * createDemux(const StreamFormat &); /* reimpl */



More information about the vlc-commits mailing list