[vlc-commits] demux: hls: EXTINF as modifier tag, and add URI

Francois Cartegnie git at videolan.org
Tue Sep 22 00:38:49 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Sep 16 22:14:50 2015 +0200| [ebcae016ce41339c89f9ed87bada6c32a7519b41] | committer: Francois Cartegnie

demux: hls: EXTINF as modifier tag, and add URI

Otherwise breaks if modifiers between EXTINF and
uri value line.

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

 modules/demux/hls/playlist/Parser.cpp |   51 ++++++++++++++++++++++++---------
 modules/demux/hls/playlist/Tags.cpp   |   16 ++++++-----
 modules/demux/hls/playlist/Tags.hpp   |    9 +++---
 3 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/modules/demux/hls/playlist/Parser.cpp b/modules/demux/hls/playlist/Parser.cpp
index e9802ff..80d8861 100644
--- a/modules/demux/hls/playlist/Parser.cpp
+++ b/modules/demux/hls/playlist/Parser.cpp
@@ -192,6 +192,7 @@ void Parser::parseSegments(Representation *rep, const std::list<Tag *> &tagslist
     std::size_t prevbyterangeoffset = 0;
     const SingleValueTag *ctx_byterange = NULL;
     SegmentEncryption encryption;
+    const ValuesListTag *ctx_extinf = NULL;
 
     std::list<Tag *>::const_iterator it;
     for(it = tagslist.begin(); it != tagslist.end(); ++it)
@@ -206,22 +207,38 @@ void Parser::parseSegments(Representation *rep, const std::list<Tag *> &tagslist
             }
             break;
 
-            case URITag::EXTINF:
+            case ValuesListTag::EXTINF:
             {
-                const URITag *uritag = static_cast<const URITag *>(tag);
+                ctx_extinf = static_cast<const ValuesListTag *>(tag);
+            }
+            break;
+
+            case SingleValueTag::URI:
+            {
+                const SingleValueTag *uritag = static_cast<const SingleValueTag *>(tag);
+                if(uritag->getValue().value.empty())
+                {
+                    ctx_extinf = NULL;
+                    ctx_byterange = NULL;
+                    break;
+                }
+
                 HLSSegment *segment = new (std::nothrow) HLSSegment(rep, sequenceNumber++);
                 if(!segment)
                     break;
 
-                if(uritag->getAttributeByName("URI"))
-                    segment->setSourceUrl(uritag->getAttributeByName("URI")->value);
+                segment->setSourceUrl(uritag->getValue().value);
 
-                if(uritag->getAttributeByName("DURATION"))
+                if(ctx_extinf)
                 {
-                    segment->duration.Set(uritag->getAttributeByName("DURATION")->floatingPoint() * rep->timescale.Get());
-                    segment->startTime.Set(nzStartTime);
-                    nzStartTime += segment->duration.Get();
-                    totalduration += segment->duration.Get();
+                    if(ctx_extinf->getAttributeByName("DURATION"))
+                    {
+                        segment->duration.Set(ctx_extinf->getAttributeByName("DURATION")->floatingPoint() * rep->timescale.Get());
+                        segment->startTime.Set(nzStartTime);
+                        nzStartTime += segment->duration.Get();
+                        totalduration += segment->duration.Get();
+                    }
+                    ctx_extinf = NULL;
                 }
 
                 segmentList->addSegment(segment);
@@ -453,14 +470,22 @@ std::list<Tag *> Parser::parseEntries(stream_t *stream)
                 }
             }
         }
-        else if(*psz_line && lastTag)
+        else if(*psz_line)
         {
-            AttributesTag *attrTag = dynamic_cast<AttributesTag *>(lastTag);
-            if(attrTag)
+            /* URI */
+            if(lastTag && lastTag->getType() == AttributesTag::EXTXSTREAMINF)
             {
+                AttributesTag *streaminftag = static_cast<AttributesTag *>(lastTag);
+                /* master playlist uri, merge as attribute */
                 Attribute *uriAttr = new (std::nothrow) Attribute("URI", std::string(psz_line));
                 if(uriAttr)
-                    attrTag->addAttribute(uriAttr);
+                    streaminftag->addAttribute(uriAttr);
+            }
+            else /* playlist tag, will take modifiers */
+            {
+                Tag *tag = TagFactory::createTagByName("", std::string(psz_line));
+                if(tag)
+                    entrieslist.push_back(tag);
             }
             lastTag = NULL;
         }
diff --git a/modules/demux/hls/playlist/Tags.cpp b/modules/demux/hls/playlist/Tags.cpp
index 32a54a3..c8b0361 100644
--- a/modules/demux/hls/playlist/Tags.cpp
+++ b/modules/demux/hls/playlist/Tags.cpp
@@ -245,16 +245,16 @@ void AttributesTag::parseAttributes(const std::string &field)
 }
 
 
-URITag::URITag(const std::string &v) : AttributesTag(URITag::EXTINF, v)
+ValuesListTag::ValuesListTag(int type, const std::string &v) : AttributesTag(type, v)
 {
     parseAttributes(v);
 }
 
-URITag::~URITag()
+ValuesListTag::~ValuesListTag()
 {
 }
 
-void URITag::parseAttributes(const std::string &field)
+void ValuesListTag::parseAttributes(const std::string &field)
 {
     std::size_t pos = field.find(',');
     if(pos != std::string::npos)
@@ -289,7 +289,8 @@ Tag * TagFactory::createTagByName(const std::string &name, const std::string &va
         {"EXT-X-I-FRAMES-ONLY",             Tag::EXTXIFRAMESONLY},
         {"EXT-X-MEDIA",                     AttributesTag::EXTXMEDIA},
         {"EXT-X-STREAM-INF",                AttributesTag::EXTXSTREAMINF},
-        {"EXTINF",                          URITag::EXTINF},
+        {"EXTINF",                          ValuesListTag::EXTINF},
+        {"",                                SingleValueTag::URI},
         {NULL,                              0},
     };
 
@@ -306,6 +307,7 @@ Tag * TagFactory::createTagByName(const std::string &name, const std::string &va
         case Tag::EXTXIFRAMESONLY:
             return new (std::nothrow) Tag(exttagmapping[i].i);
 
+        case SingleValueTag::URI:
         case SingleValueTag::EXTXVERSION:
         case SingleValueTag::EXTXBYTERANGE:
         case SingleValueTag::EXTXPROGRAMDATETIME:
@@ -315,14 +317,14 @@ Tag * TagFactory::createTagByName(const std::string &name, const std::string &va
         case SingleValueTag::EXTXPLAYLISTTYPE:
             return new (std::nothrow) SingleValueTag(exttagmapping[i].i, value);
 
+        case ValuesListTag::EXTINF:
+            return new (std::nothrow) ValuesListTag(exttagmapping[i].i, value);
+
         case AttributesTag::EXTXKEY:
         case AttributesTag::EXTXMAP:
         case AttributesTag::EXTXMEDIA:
         case AttributesTag::EXTXSTREAMINF:
             return new (std::nothrow) AttributesTag(exttagmapping[i].i, value);
-
-        case URITag::EXTINF:
-            return new URITag(value);
         }
 
     }
diff --git a/modules/demux/hls/playlist/Tags.hpp b/modules/demux/hls/playlist/Tags.hpp
index c7cacaa..259215f 100644
--- a/modules/demux/hls/playlist/Tags.hpp
+++ b/modules/demux/hls/playlist/Tags.hpp
@@ -75,7 +75,8 @@ namespace hls
             public:
                 enum
                 {
-                    EXTXVERSION = 10,
+                    URI = 10,
+                    EXTXVERSION,
                     EXTXBYTERANGE,
                     EXTXPROGRAMDATETIME,
                     EXTXTARGETDURATION,
@@ -110,15 +111,15 @@ namespace hls
                 std::list<Attribute *> attributes;
         };
 
-        class URITag : public AttributesTag
+        class ValuesListTag : public AttributesTag
         {
             public:
                 enum
                 {
                     EXTINF = 30
                 };
-                URITag(const std::string &);
-                virtual ~URITag();
+                ValuesListTag(int, const std::string &);
+                virtual ~ValuesListTag();
 
             protected:
                 virtual void parseAttributes(const std::string &);



More information about the vlc-commits mailing list