[vlc-commits] demux: hls: set demux only from file extensions

Francois Cartegnie git at videolan.org
Thu Jul 14 19:26:06 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jul 14 19:10:44 2016 +0200| [b4b87526cdfec5a3e9280657b5462e04489501b0] | committer: Francois Cartegnie

demux: hls: set demux only from file extensions

we can no longer rely on codecs to guess format

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

 modules/demux/adaptive/SegmentTracker.cpp |   27 ++++++++++++++++++-
 modules/demux/adaptive/SegmentTracker.hpp |    2 +-
 modules/demux/adaptive/Streams.cpp        |    2 +-
 modules/demux/hls/HLSStreams.cpp          |    3 ---
 modules/demux/hls/playlist/Parser.cpp     |   41 ++++-------------------------
 modules/demux/hls/playlist/Parser.hpp     |    1 -
 6 files changed, 33 insertions(+), 43 deletions(-)

diff --git a/modules/demux/adaptive/SegmentTracker.cpp b/modules/demux/adaptive/SegmentTracker.cpp
index e0d209b..7ce4c1d 100644
--- a/modules/demux/adaptive/SegmentTracker.cpp
+++ b/modules/demux/adaptive/SegmentTracker.cpp
@@ -77,13 +77,18 @@ void SegmentTracker::setAdaptationLogic(AbstractAdaptationLogic *logic_)
     registerListener(logic);
 }
 
-StreamFormat SegmentTracker::initialFormat() const
+StreamFormat SegmentTracker::getCurrentFormat() const
 {
     BaseRepresentation *rep = curRepresentation;
     if(!rep)
         rep = logic->getNextRepresentation(adaptationSet, NULL);
     if(rep)
+    {
+        /* Ensure ephemere content is updated/loaded */
+        if(rep->needsUpdate())
+            (void) rep->runLocalUpdates(0, curNumber, false);
         return rep->getStreamFormat();
+    }
     return StreamFormat();
 }
 
@@ -167,6 +172,26 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed, HTTPConnectionM
         curRepresentation->scheduleNextUpdate(next);
     }
 
+    if(rep->getStreamFormat() != format)
+    {
+        /* Initial format ? */
+        if(format == StreamFormat(StreamFormat::UNSUPPORTED))
+        {
+            format = rep->getStreamFormat();
+        }
+        else
+        {
+            format = rep->getStreamFormat();
+            notify(SegmentTrackerEvent(&format)); /* Notify new demux format */
+            return NULL; /* Force current demux to end */
+        }
+    }
+
+    if(format == StreamFormat(StreamFormat::UNSUPPORTED))
+    {
+        return NULL; /* Can't return chunk because no demux will be created */
+    }
+
     if(!init_sent)
     {
         init_sent = true;
diff --git a/modules/demux/adaptive/SegmentTracker.hpp b/modules/demux/adaptive/SegmentTracker.hpp
index 8b3aad2..5adfe1b 100644
--- a/modules/demux/adaptive/SegmentTracker.hpp
+++ b/modules/demux/adaptive/SegmentTracker.hpp
@@ -91,7 +91,7 @@ namespace adaptive
             ~SegmentTracker();
 
             void setAdaptationLogic(AbstractAdaptationLogic *);
-            StreamFormat initialFormat() const;
+            StreamFormat getCurrentFormat() const;
             bool segmentsListReady() const;
             void reset();
             SegmentChunk* getNextChunk(bool, HTTPConnectionManager *);
diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index 9fa986e..586d7f8 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -274,7 +274,7 @@ AbstractStream::buffering_status AbstractStream::bufferize(mtime_t nz_deadline,
 
     if(!demuxer)
     {
-        format = segmentTracker->initialFormat();
+        format = segmentTracker->getCurrentFormat();
         if(!startDemux())
         {
             /* If demux fails because of probing failure / wrong format*/
diff --git a/modules/demux/hls/HLSStreams.cpp b/modules/demux/hls/HLSStreams.cpp
index 9a9e19e..e767852 100644
--- a/modules/demux/hls/HLSStreams.cpp
+++ b/modules/demux/hls/HLSStreams.cpp
@@ -58,9 +58,6 @@ AbstractDemuxer * HLSStream::createDemux(const StreamFormat &format)
     AbstractDemuxer *ret = NULL;
     switch((unsigned)format)
     {
-        case StreamFormat::UNKNOWN:
-            ret = new Demuxer(p_realdemux, "any", fakeesout->getEsOut(), demuxersource);
-            break;
 
         case StreamFormat::PACKEDAAC:
             ret = new Demuxer(p_realdemux, "avformat", fakeesout->getEsOut(), demuxersource);
diff --git a/modules/demux/hls/playlist/Parser.cpp b/modules/demux/hls/playlist/Parser.cpp
index 38f8338..bc7d1f1 100644
--- a/modules/demux/hls/playlist/Parser.cpp
+++ b/modules/demux/hls/playlist/Parser.cpp
@@ -73,37 +73,6 @@ static void releaseTagsList(std::list<Tag *> &list)
     list.clear();
 }
 
-void M3U8Parser::setFormatFromCodecs(Representation *rep, const std::string codecsstring)
-{
-    std::list<std::string> codecs;
-    std::list<std::string> tokens = Helper::tokenize(codecsstring, ',');
-    std::list<std::string>::const_iterator it;
-    for(it=tokens.begin(); it!=tokens.end(); ++it)
-    {
-        /* Truncate init data */
-        std::size_t pos = (*it).find_first_of('.', 0);
-        if(pos != std::string::npos)
-            codecs.push_back((*it).substr(0, pos));
-        else
-            codecs.push_back(*it);
-    }
-
-    if(!codecs.empty())
-    {
-        if(codecs.size() == 1)
-        {
-            std::string codec = codecs.front();
-            transform(codec.begin(), codec.end(), codec.begin(), (int (*)(int))std::tolower);
-            if(codec == "mp4a")
-                rep->streamFormat = StreamFormat(StreamFormat::PACKEDAAC);
-        }
-        else
-        {
-            rep->streamFormat = StreamFormat(StreamFormat::MPEG2TS);
-        }
-    }
-}
-
 void M3U8Parser::setFormatFromExtension(Representation *rep, const std::string &filename)
 {
     std::size_t pos = filename.find_last_of('.');
@@ -115,10 +84,14 @@ void M3U8Parser::setFormatFromExtension(Representation *rep, const std::string &
         {
             rep->streamFormat = StreamFormat(StreamFormat::PACKEDAAC);
         }
-        else if(extension == "ts" || extension == "mp2t" || extension == "mpeg")
+        else if(extension == "ts" || extension == "mp2t" || extension == "mpeg" || extension == "m2ts")
         {
             rep->streamFormat = StreamFormat(StreamFormat::MPEG2TS);
         }
+        else
+        {
+            rep->streamFormat = StreamFormat(StreamFormat::UNSUPPORTED);
+        }
     }
 }
 
@@ -126,7 +99,6 @@ Representation * M3U8Parser::createRepresentation(BaseAdaptationSet *adaptSet, c
 {
     const Attribute *uriAttr = tag->getAttributeByName("URI");
     const Attribute *bwAttr = tag->getAttributeByName("BANDWIDTH");
-    const Attribute *codecsAttr = tag->getAttributeByName("CODECS");
     const Attribute *resAttr = tag->getAttributeByName("RESOLUTION");
 
     Representation *rep = new (std::nothrow) Representation(adaptSet);
@@ -156,9 +128,6 @@ Representation * M3U8Parser::createRepresentation(BaseAdaptationSet *adaptSet, c
         if(bwAttr)
             rep->setBandwidth(bwAttr->decimal());
 
-        if(codecsAttr)
-            setFormatFromCodecs(rep, codecsAttr->quotedString());
-
         if(resAttr)
         {
             std::pair<int, int> res = resAttr->getResolution();
diff --git a/modules/demux/hls/playlist/Parser.hpp b/modules/demux/hls/playlist/Parser.hpp
index 9fd6bcd..e1baf27 100644
--- a/modules/demux/hls/playlist/Parser.hpp
+++ b/modules/demux/hls/playlist/Parser.hpp
@@ -63,7 +63,6 @@ namespace hls
                 void createAndFillRepresentation(vlc_object_t *, BaseAdaptationSet *,
                                                  const AttributesTag *, const std::list<Tag *>&);
                 void parseSegments(vlc_object_t *, Representation *, const std::list<Tag *>&);
-                void setFormatFromCodecs(Representation *, const std::string);
                 void setFormatFromExtension(Representation *rep, const std::string &);
                 std::list<Tag *> parseEntries(stream_t *);
         };



More information about the vlc-commits mailing list