]> git.sesse.net Git - vlc/commitdiff
stream_filter: dash: build urls using class
authorFrancois Cartegnie <fcvlcdev@free.fr>
Thu, 11 Dec 2014 20:38:10 +0000 (21:38 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Thu, 18 Dec 2014 20:23:50 +0000 (21:23 +0100)
We'll need this for templates

17 files changed:
modules/stream_filter/Makefile.am
modules/stream_filter/dash/mpd/AdaptationSet.cpp
modules/stream_filter/dash/mpd/AdaptationSet.h
modules/stream_filter/dash/mpd/ICanonicalUrl.hpp
modules/stream_filter/dash/mpd/IsoffMainParser.cpp
modules/stream_filter/dash/mpd/MPD.cpp
modules/stream_filter/dash/mpd/MPD.h
modules/stream_filter/dash/mpd/Period.cpp
modules/stream_filter/dash/mpd/Period.h
modules/stream_filter/dash/mpd/Representation.cpp
modules/stream_filter/dash/mpd/Representation.h
modules/stream_filter/dash/mpd/Segment.cpp
modules/stream_filter/dash/mpd/Segment.h
modules/stream_filter/dash/mpd/SegmentInfoCommon.cpp
modules/stream_filter/dash/mpd/SegmentInfoCommon.h
modules/stream_filter/dash/mpd/Url.cpp [new file with mode: 0644]
modules/stream_filter/dash/mpd/Url.hpp [new file with mode: 0644]

index 9980a3d28c05d7f13861f25b5de43c06c22e544a..5b0a1920b9f8cf11aa2ca6b4610e71de57b2d5d1 100644 (file)
@@ -80,6 +80,8 @@ libdash_plugin_la_SOURCES = \
     stream_filter/dash/mpd/SegmentTimeline.h \
     stream_filter/dash/mpd/TrickModeType.cpp \
     stream_filter/dash/mpd/TrickModeType.h \
+    stream_filter/dash/mpd/Url.cpp \
+    stream_filter/dash/mpd/Url.hpp \
     stream_filter/dash/mp4/AtomsReader.cpp \
     stream_filter/dash/mp4/AtomsReader.hpp \
     stream_filter/dash/xml/DOMHelper.cpp \
index 91b2224b8d39258d9870c22bda862b4c1003f58c..fbca3bccf88b90b5dad4b925500f96931a5447bc 100644 (file)
@@ -113,7 +113,7 @@ bool AdaptationSet::getBitstreamSwitching  () const
     return this->isBitstreamSwitching;
 }
 
-std::string AdaptationSet::getUrlSegment() const
+Url AdaptationSet::getUrlSegment() const
 {
     return getParentUrlSegment();
 }
index 0e402516739d1fb928aed5bd827c54cae926a778..693822d491952075bdeebcfd4b41c699ba755f92 100644 (file)
@@ -56,7 +56,7 @@ namespace dash
                 void                            setBitstreamSwitching(bool value);
                 bool                            getBitstreamSwitching() const;
                 void                            addRepresentation( Representation *rep );
-                virtual std::string             getUrlSegment() const; /* reimpl */
+                virtual Url                     getUrlSegment() const; /* reimpl */
 
             private:
                 bool                            subsegmentAlignmentFlag;
index 32cd8c6563853d88999be56977748e4efcd06c77..7f0a3e3438a72a1e647006099454449c8e84dad6 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef CANONICALURL_HPP
 #define CANONICALURL_HPP
 
-#include <string>
+#include "Url.hpp"
 
 namespace dash
 {
@@ -30,12 +30,12 @@ namespace dash
         {
             public:
                 ICanonicalUrl( const ICanonicalUrl *parent = NULL ) { parentUrlMember = parent; }
-                virtual std::string getUrlSegment() const = 0;
+                virtual Url getUrlSegment() const = 0;
 
             protected:
-                std::string getParentUrlSegment() const {
+                Url getParentUrlSegment() const {
                     return (parentUrlMember) ? parentUrlMember->getUrlSegment()
-                                             : std::string();
+                                             : Url();
                 }
 
             private:
index fe8f98a6091611a1004b0b1e3366e27d94fa536b..d3ec489467222d97377daf6a551c34f5dc567337 100644 (file)
@@ -101,6 +101,9 @@ void    IsoffMainParser::setRepresentations (Node *adaptationSetNode, Adaptation
         if(!baseUrls.empty())
             currentRepresentation->setBaseUrl( new BaseUrl( baseUrls.front()->getText() ) );
 
+        if(repNode->hasAttribute("id"))
+            currentRepresentation->setId(repNode->getAttributeValue("id"));
+
         if(repNode->hasAttribute("width"))
             this->currentRepresentation->setWidth(atoi(repNode->getAttributeValue("width").c_str()));
 
@@ -242,7 +245,7 @@ void    IsoffMainParser::print              ()
                 static_cast<std::string>(mpd->getProfile()).c_str(),
                 mpd->getDuration(),
                 mpd->getMinBufferTime());
-        msg_Dbg(p_stream, "BaseUrl=%s", mpd->getUrlSegment().c_str());
+        msg_Dbg(p_stream, "BaseUrl=%s", mpd->getUrlSegment().toString().c_str());
 
         std::vector<Period *>::const_iterator i;
         for(i = mpd->getPeriods().begin(); i != mpd->getPeriods().end(); i++)
index 12befa34efb64b6be7309d7abbad46618235be9b..517c646ccb6542fe684537100f8c41b963595477 100644 (file)
@@ -165,16 +165,15 @@ Profile MPD::getProfile() const
 {
     return profile;
 }
-
-std::string MPD::getUrlSegment() const
+Url MPD::getUrlSegment() const
 {
     if (!baseUrls.empty())
-        return baseUrls.front()->getUrl();
+        return Url(baseUrls.front()->getUrl());
     else
     {
         std::stringstream ss;
         ss << stream->psz_access << "://" << Helper::getDirectoryPath(stream->psz_path) << "/";
-        return ss.str();
+        return Url(ss.str());
     }
 }
 
index b9f961b84688c3a5ca661e6f0b31d22e2c863469..08469428558eaa6c3acc2e8a9132228727bd88cd 100644 (file)
@@ -66,7 +66,7 @@ namespace dash
                 void    addBaseUrl              (BaseUrl *url);
                 void    setProgramInformation   (ProgramInformation *progInfo);
 
-                virtual std::string getUrlSegment() const; /* impl */
+                virtual Url         getUrlSegment() const; /* impl */
                 vlc_object_t *      getVLCObject()  const;
 
                 virtual const std::vector<Period *>&    getPeriods() const;
index 94ec3822674c597fe49e991d119c9582528ecbb5..26b3ec5ef569d553171465be15dc89bbd225709f 100644 (file)
@@ -78,7 +78,7 @@ AdaptationSet * Period::getAdaptationSet(Streams::Type type) const
     return NULL;
 }
 
-std::string Period::getUrlSegment() const
+Url Period::getUrlSegment() const
 {
     return getParentUrlSegment();
 }
index f586b3ebe3738f632e5e7d80fb58ac2884dc9a86..794022f9239c4b203868c71d4c0ce09386387e10 100644 (file)
@@ -47,7 +47,7 @@ namespace dash
                 AdaptationSet *                     getAdaptationSet    (Streams::Type) const;
                 void                                addAdaptationSet    (AdaptationSet *AdaptationSet);
 
-                virtual std::string getUrlSegment() const; /* reimpl */
+                virtual Url getUrlSegment() const; /* reimpl */
 
             private:
                 std::vector<AdaptationSet *>    adaptationSets;
index ecdb32646c1f303df5a99cfd78c3461cc633fd81..675fbcd890a2e40f04a510a06d68957d9bbe09d0 100644 (file)
@@ -218,9 +218,9 @@ std::vector<std::string> Representation::toString() const
     return ret;
 }
 
-std::string Representation::getUrlSegment() const
+Url Representation::getUrlSegment() const
 {
-    std::string ret = getParentUrlSegment();
+    Url ret = getParentUrlSegment();
     if (baseUrl)
         ret.append(baseUrl->getUrl());
     return ret;
index 80c3add69dc46be7c8dfd3906dcb44fcd24201a1..d51c74c930273d3bf1915cb44c1535878ec3fcc2 100644 (file)
@@ -87,7 +87,7 @@ namespace dash
                 MPD*                getMPD                  () const;
 
                 std::vector<std::string> toString() const;
-                virtual std::string getUrlSegment           () const; /* impl */
+                virtual Url         getUrlSegment           () const; /* impl */
 
                 class SplitPoint
                 {
index 98af3bb414baada5285f1251784c30441d7004a9..c6b53cdedee884686483aa3e03e9cbab3c3799c8 100644 (file)
@@ -108,7 +108,7 @@ size_t ISegment::getOffset() const
 std::string ISegment::toString() const
 {
     std::stringstream ss("    ");
-    ss << debugName << " url=" << getUrlSegment();
+    ss << debugName << " url=" << getUrlSegment().toString();
     if(startByte!=endByte)
         ss << " @" << startByte << ".." << endByte;
     return ss.str();
@@ -263,7 +263,7 @@ SubSegment::SubSegment(Segment *main, size_t start, size_t end) :
     classId = CLASSID_SUBSEGMENT;
 }
 
-std::string SubSegment::getUrlSegment() const
+Url SubSegment::getUrlSegment() const
 {
     return getParentUrlSegment();
 }
index 0531a535a641773525755363715f94d4ab3293bd..52bce3467484178e4951ec1f3a72283f676328f4 100644 (file)
@@ -88,9 +88,10 @@ namespace dash
         {
             public:
                 Segment( Representation *parent );
+                explicit Segment( ICanonicalUrl *parent );
                 ~Segment();
                 virtual void setSourceUrl( const std::string &url );
-                virtual std::string getUrlSegment() const; /* impl */
+                virtual Url getUrlSegment() const; /* impl */
                 virtual dash::http::Chunk* toChunk();
                 virtual std::vector<ISegment*> subSegments();
                 virtual Representation* getRepresentation() const;
@@ -133,7 +134,7 @@ namespace dash
         {
             public:
                 SubSegment(Segment *, size_t start, size_t end);
-                virtual std::string getUrlSegment() const; /* impl */
+                virtual Url getUrlSegment() const; /* impl */
                 virtual std::vector<ISegment*> subSegments();
                 virtual Representation* getRepresentation() const;
                 static const int CLASSID_SUBSEGMENT = 4;
index 85a3d750f78dc925cf567b7bff0d4ffb0a848d0d..29a423aa8d68ab09ce8ded845c057614f935ab72 100644 (file)
@@ -96,9 +96,9 @@ void SegmentInfoCommon::setSegmentTimeline( const SegmentTimeline *segTl )
         this->segmentTimeline = segTl;
 }
 
-std::string SegmentInfoCommon::getUrlSegment() const
+Url SegmentInfoCommon::getUrlSegment() const
 {
-    std::string ret = getParentUrlSegment();
+    Url ret = getParentUrlSegment();
     if (!baseURLs.empty())
         ret.append(baseURLs.front());
     return ret;
index b37d72dc731696ae921f792b9532c3820763f897..2e4dbda02a041a33f37f5090f1a3afcc5ef68d1e 100644 (file)
@@ -51,7 +51,7 @@ namespace dash
                 void                    appendBaseURL( const std::string& url );
                 const SegmentTimeline*  getSegmentTimeline() const;
                 void                    setSegmentTimeline( const SegmentTimeline *segTl );
-                virtual std::string     getUrlSegment() const; /* impl */
+                virtual Url             getUrlSegment() const; /* impl */
 
             private:
                 time_t                  duration;
diff --git a/modules/stream_filter/dash/mpd/Url.cpp b/modules/stream_filter/dash/mpd/Url.cpp
new file mode 100644 (file)
index 0000000..25c5a60
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Url.cpp
+ *****************************************************************************
+ * Copyright (C) 2014 - VideoLAN Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#include "Url.hpp"
+#include "Representation.h"
+#include "SegmentTemplate.h"
+
+#include <sstream>
+using namespace dash::mpd;
+
+Url::Url()
+{
+}
+
+Url::Url(const Component & comp)
+{
+    prepend(comp);
+}
+
+Url::Url(const std::string &str)
+{
+    prepend(Component(str));
+}
+
+Url & Url::prepend(const Component & comp)
+{
+    components.insert(components.begin(), comp);
+    return *this;
+}
+
+Url & Url::append(const Component & comp)
+{
+    components.push_back(comp);
+    return *this;
+}
+
+Url & Url::prepend(const Url &url)
+{
+    components.insert(components.begin(), url.components.begin(), url.components.end());
+    return *this;
+}
+
+Url & Url::append(const Url &url)
+{
+    components.insert(components.end(), url.components.begin(), url.components.end());
+    return *this;
+}
+
+std::string Url::toString() const
+{
+    return toString(0, NULL);
+}
+
+std::string Url::toString(size_t index, const Representation *rep) const
+{
+    std::string ret;
+    std::vector<Component>::const_iterator it;
+    for(it = components.begin(); it != components.end(); it++)
+    {
+        ret.append((*it).contextualize(index, rep));
+    }
+    return ret;
+}
+
+Url::Component::Component(const std::string & str, const SegmentTemplate *templ_)
+{
+    component = str;
+    templ = templ_;
+}
+
+std::string Url::Component::contextualize(size_t index, const Representation *rep) const
+{
+    std::string ret(component);
+
+    if(!rep || !templ)
+        return ret;
+
+    size_t pos = ret.find("$Time$");
+    if(pos != std::string::npos)
+    {
+        std::stringstream ss;
+        ss << (templ->getDuration() * index);
+        ret.replace(pos, std::string("$Time$").length(), ss.str());
+    }
+
+    pos = ret.find("$Index$");
+    if(pos != std::string::npos)
+    {
+        std::stringstream ss;
+        ss << index;
+        ret.replace(pos, std::string("$Index$").length(), ss.str());
+    }
+
+    pos = ret.find("$Number$");
+    if(pos != std::string::npos)
+    {
+        std::stringstream ss;
+        ss << index;
+        ret.replace(pos, std::string("$Number$").length(), ss.str());
+    }
+
+    pos = ret.find("$Bandwidth$");
+    if(pos != std::string::npos)
+    {
+        std::stringstream ss;
+        ss << rep->getBandwidth();
+        ret.replace(pos, std::string("$Bandwidth$").length(), ss.str());
+    }
+
+    pos = ret.find("$RepresentationID$");
+    if(pos != std::string::npos)
+    {
+        std::stringstream ss;
+        ss << rep->getId();
+        ret.replace(pos, std::string("$RepresentationID$").length(), ss.str());
+    }
+
+    return ret;
+}
diff --git a/modules/stream_filter/dash/mpd/Url.hpp b/modules/stream_filter/dash/mpd/Url.hpp
new file mode 100644 (file)
index 0000000..9f73237
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Url.hpp
+ *****************************************************************************
+ * Copyright (C) 2014 - VideoLAN Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef URL_HPP
+#define URL_HPP
+
+#include <string>
+#include <vector>
+
+namespace dash
+{
+    namespace mpd
+    {
+        class Representation;
+        class SegmentTemplate;
+
+        class Url
+        {
+            public:
+                class Component
+                {
+                    friend class Url;
+                    public:
+                        Component(const std::string &, const SegmentTemplate * = NULL);
+
+                    protected:
+                        std::string contextualize(size_t, const Representation *) const;
+                        std::string component;
+                        const SegmentTemplate *templ;
+                };
+
+                Url();
+                Url(const Component &);
+                explicit Url(const std::string &);
+                Url & prepend(const Component &);
+                Url & append(const Component &);
+                Url & append(const Url &);
+                Url & prepend(const Url &);
+                std::string toString(size_t, const Representation *) const;
+                std::string toString() const;
+
+            private:
+                std::vector<Component> components;
+        };
+    }
+}
+
+#endif // URL_HPP