[vlc-commits] demux: hls: probe content

Francois Cartegnie git at videolan.org
Mon Mar 30 16:15:14 CEST 2020


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Apr 23 14:34:37 2019 +0200| [223dec0f42a7fa4ea2ae52b5681f2163d9334017] | committer: Francois Cartegnie

demux: hls: probe content

Solves issues when the server does not sends proper MIME
and the file does not match known extension.

(cherry picked from commit dfe4aca1f22265115e07c501a77c870cfea4cd52)

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

 modules/demux/Makefile.am               |  5 ++++-
 modules/demux/adaptive/StreamFormat.cpp | 40 ++++++++++++++++++++++++++++++---
 modules/demux/adaptive/StreamFormat.hpp |  3 ++-
 3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 77acf5713e..4058bcc721 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -385,6 +385,10 @@ libadaptive_plugin_la_SOURCES = \
     demux/adaptive/xml/DOMParser.h \
     demux/adaptive/xml/Node.cpp \
     demux/adaptive/xml/Node.h
+libadaptive_plugin_la_SOURCES += \
+     demux/mp4/libmp4.c \
+     demux/mp4/libmp4.h \
+     meta_engine/ID3Tag.h
 
 libadaptive_dash_SOURCES = \
     demux/dash/mpd/AdaptationSet.cpp \
@@ -460,7 +464,6 @@ libadaptive_plugin_la_SOURCES += $(libadaptive_hls_SOURCES)
 libadaptive_plugin_la_SOURCES += $(libadaptive_dash_SOURCES)
 libadaptive_plugin_la_SOURCES += $(libadaptive_smooth_SOURCES)
 libadaptive_plugin_la_SOURCES += demux/adaptive/adaptive.cpp
-libadaptive_plugin_la_SOURCES += demux/mp4/libmp4.c demux/mp4/libmp4.h
 libadaptive_plugin_la_CXXFLAGS = $(AM_CXXFLAGS) -I$(srcdir)/demux/adaptive
 libadaptive_plugin_la_LIBADD = $(SOCKET_LIBS) $(LIBM)
 if HAVE_ZLIB
diff --git a/modules/demux/adaptive/StreamFormat.cpp b/modules/demux/adaptive/StreamFormat.cpp
index d31cc1800c..927a8a71a9 100644
--- a/modules/demux/adaptive/StreamFormat.cpp
+++ b/modules/demux/adaptive/StreamFormat.cpp
@@ -25,6 +25,12 @@
 #include "StreamFormat.hpp"
 
 #include <vlc_common.h>
+
+extern "C"
+{
+    #include "../../meta_engine/ID3Tag.h"
+}
+
 #include <algorithm>
 
 using namespace adaptive;
@@ -48,6 +54,8 @@ std::string StreamFormat::str() const
             return "Timed Text";
         case PACKEDAAC:
             return "Packed AAC";
+        case WEBM:
+            return "WebM";
         case UNSUPPORTED:
             return "Unsupported";
         default:
@@ -72,15 +80,24 @@ StreamFormat::StreamFormat( const std::string &mimetype )
         std::string tail = mime.substr(pos + 1);
         if(tail == "mp4")
             formatid = StreamFormat::MP4;
+        else if(tail == "aac")
+            formatid = StreamFormat::PACKEDAAC;
         else if (tail == "mp2t")
             formatid = StreamFormat::MPEG2TS;
         else if (tail == "vtt")
             formatid = StreamFormat::WEBVTT;
         else if (tail == "ttml+xml")
             formatid = StreamFormat::TTML;
+        else if (tail == "webm")
+            formatid = StreamFormat::WEBM;
     }
 }
 
+static int ID3Callback(uint32_t, const uint8_t *, size_t, void *)
+{
+    return VLC_EGENERIC;
+}
+
 StreamFormat::StreamFormat(const void *data_, size_t sz)
 {
     const uint8_t *data = reinterpret_cast<const uint8_t *>(data_);
@@ -96,9 +113,26 @@ StreamFormat::StreamFormat(const void *data_, size_t sz)
     else if(sz > 7 && !memcmp("WEBVTT", data, 6) &&
             std::isspace(static_cast<unsigned char>(data[7])))
         formatid = StreamFormat::WEBVTT;
-    else if(sz > 3 && (!memcmp("\xFF\xF1", data, 2)||
-                       !memcmp("\xFF\xF9", data, 2)))
-        formatid = StreamFormat::PACKEDAAC;
+    else if(sz > 4 && !memcmp("\x1A\x45\xDF\xA3", data, 4))
+        formatid = StreamFormat::WEBM;
+    else /* Check Packet Audio formats */
+    {
+        /* It MUST have ID3 header, but HLS spec is an oxymoron */
+        if(sz > 10 && ID3TAG_IsTag(data, false))
+        {
+            size_t tagsize = ID3TAG_Parse(data, sz, ID3Callback, this);
+            if(tagsize >= sz)
+                return; /* not enough peek */
+            data += tagsize;
+            sz -= tagsize;
+        }
+        /* Skipped ID3 if any */
+        if(sz > 3 && (!memcmp("\xFF\xF1", data, 2) ||
+                      !memcmp("\xFF\xF9", data, 2)))
+        {
+            formatid = StreamFormat::PACKEDAAC;
+        }
+    }
 }
 
 StreamFormat::~StreamFormat()
diff --git a/modules/demux/adaptive/StreamFormat.hpp b/modules/demux/adaptive/StreamFormat.hpp
index 738e04574b..10d7fba92a 100644
--- a/modules/demux/adaptive/StreamFormat.hpp
+++ b/modules/demux/adaptive/StreamFormat.hpp
@@ -34,8 +34,9 @@ namespace adaptive
             static const unsigned WEBVTT      = 3;
             static const unsigned TTML        = 4;
             static const unsigned PACKEDAAC   = 5;
+            static const unsigned WEBM        = 6;
             static const unsigned UNKNOWN     = 0xFF; /* will probe */
-            static const unsigned PEEK_SIZE   = 189;
+            static const unsigned PEEK_SIZE   = 4096;
 
             StreamFormat( unsigned = UNSUPPORTED );
             explicit StreamFormat( const std::string &mime );



More information about the vlc-commits mailing list