]> git.sesse.net Git - vlc/commitdiff
stream_filter: dash: ensure chunks have hostname and fully chain build url
authorFrancois Cartegnie <fcvlcdev@free.fr>
Thu, 4 Dec 2014 15:18:43 +0000 (16:18 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Thu, 18 Dec 2014 20:23:50 +0000 (21:23 +0100)
Otherwise, connection can never be reused, and late url fix is ugly

16 files changed:
modules/stream_filter/dash/http/Chunk.cpp
modules/stream_filter/dash/http/Chunk.h
modules/stream_filter/dash/http/HTTPConnection.cpp
modules/stream_filter/dash/http/HTTPConnection.h
modules/stream_filter/dash/mpd/AdaptationSet.cpp
modules/stream_filter/dash/mpd/AdaptationSet.h
modules/stream_filter/dash/mpd/BasicCMParser.cpp
modules/stream_filter/dash/mpd/IMPDParser.cpp
modules/stream_filter/dash/mpd/IsoffMainParser.cpp
modules/stream_filter/dash/mpd/MPD.cpp
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

index d39cb279c7df3bda64d95e96f39291afcadca194..0e3f157f3c832639b711d4b8c3e688c3cbb9cf47 100644 (file)
 
 using namespace dash::http;
 
-Chunk::Chunk        () :
+Chunk::Chunk        (const std::string& url) :
        startByte    (0),
        endByte      (0),
        bitrate      (1),
        port         (0),
-       isHostname   (false),
        length       (0),
        bytesRead    (0),
        bytesToRead  (0),
        connection   (NULL)
 {
+    this->url = url;
+
+    if(url.compare(0, 7, "http://"))
+        throw VLC_EGENERIC;
+
+    vlc_url_t url_components;
+    vlc_UrlParse(&url_components, url.c_str(), 0);
+
+    if(url_components.psz_path)
+        path = url_components.psz_path;
+    port = url_components.i_port ? url_components.i_port : 80;
+    if(url_components.psz_host)
+        hostname = url_components.psz_host;
+
+    vlc_UrlClean(&url_components);
+
+    if(path.empty() || hostname.empty())
+        throw VLC_EGENERIC;
 }
 
 size_t              Chunk::getEndByte           () const
@@ -66,26 +83,6 @@ void                Chunk::setStartByte         (size_t startByte)
     if (endByte > startByte)
         bytesToRead = endByte - startByte;
 }
-void                Chunk::setUrl               (const std::string& url )
-{
-    this->url = url;
-
-    if(this->url.compare(0, 4, "http"))
-    {
-        this->isHostname = false;
-        return;
-    }
-
-    vlc_url_t url_components;
-    vlc_UrlParse(&url_components, url.c_str(), 0);
-
-    this->path          = url_components.psz_path;
-    this->port          = url_components.i_port ? url_components.i_port : 80;
-    this->hostname      = url_components.psz_host;
-    this->isHostname    = true;
-
-    vlc_UrlClean(&url_components);
-}
 void                Chunk::addOptionalUrl       (const std::string& url)
 {
     this->optionalUrls.push_back(url);
@@ -103,13 +100,9 @@ int                 Chunk::getBitrate           ()
 {
     return this->bitrate;
 }
-bool                Chunk::hasHostname          () const
-{
-    return this->isHostname;
-}
 const std::string&  Chunk::getHostname          () const
 {
-    return this->hostname;
+    return hostname;
 }
 const std::string&  Chunk::getPath              () const
 {
index 94d41eef9a1645a115b9a7d2cc70838fe69e666b..86a5aba42e1c0e2045fce32d5ac02afcf8d5f73f 100644 (file)
@@ -45,13 +45,12 @@ namespace dash
         class Chunk
         {
             public:
-                Chunk           ();
+                Chunk           (const std::string &url);
                 virtual ~Chunk  () {}
 
                 size_t              getEndByte              () const;
                 size_t              getStartByte            () const;
                 const std::string&  getUrl                  () const;
-                bool                hasHostname             () const;
                 const std::string&  getHostname             () const;
                 const std::string&  getPath                 () const;
                 int                 getPort                 () const;
@@ -67,7 +66,6 @@ namespace dash
                 void                setLength       (uint64_t length);
                 void                setEndByte      (size_t endByte);
                 void                setStartByte    (size_t startByte);
-                void                setUrl          (const std::string& url);
                 void                addOptionalUrl  (const std::string& url);
                 bool                usesByteRange   () const;
                 void                setBitrate      (uint64_t bitrate);
@@ -84,7 +82,6 @@ namespace dash
                 size_t                      endByte;
                 int                         bitrate;
                 int                         port;
-                bool                        isHostname;
                 uint64_t                    length;
                 uint64_t                    bytesRead;
                 uint64_t                    bytesToRead;
index b921d085a61eb7e4aa5e95fb5abadebfe92642ba..32746f0f1daa98434fff40f5c49f3fa1b8f5a82a 100644 (file)
@@ -29,7 +29,6 @@
 #include "Chunk.h"
 
 #include <sstream>
-#include <vlc_stream.h>
 
 using namespace dash::http;
 
@@ -52,11 +51,7 @@ void HTTPConnection::bindChunk(Chunk *chunk_)
     if(chunk_ == chunk)
         return;
     if (chunk_)
-    {
         chunk_->setConnection(this);
-        if(!chunk->hasHostname())
-            chunk->setUrl(getUrlRelative(chunk));
-    }
     chunk = chunk_;
 }
 
@@ -95,13 +90,6 @@ std::string HTTPConnection::extraRequestHeaders() const
     return ss.str();
 }
 
-std::string HTTPConnection::getUrlRelative(const Chunk *chunk) const
-{
-    std::stringstream ss;
-    ss << stream->psz_access << "://" << Helper::combinePaths(Helper::getDirectoryPath(stream->psz_path), chunk->getUrl());
-    return ss.str();
-}
-
 bool HTTPConnection::isAvailable() const
 {
     return chunk == NULL;
index 0bfec19a4c7f9384ee800fada37a2858a23cc568..817101293852b30278f3e5c28693b19b5213e848 100644 (file)
@@ -51,8 +51,6 @@ namespace dash
                 Chunk *chunk;
                 virtual std::string extraRequestHeaders() const;
                 virtual std::string buildRequestHeader(const std::string &path) const;
-
-                std::string getUrlRelative(const Chunk *chunk) const;
         };
     }
 }
index 39123f14c644bb66ba26f9f93d2694b3fe0329df..91b2224b8d39258d9870c22bda862b4c1003f58c 100644 (file)
 #include <vlc_arrays.h>
 
 #include "SegmentInfoDefault.h"
+#include "Period.h"
 
 using namespace dash::mpd;
 
-AdaptationSet::AdaptationSet() :
+AdaptationSet::AdaptationSet(Period *period) :
+    ICanonicalUrl( period ),
     subsegmentAlignmentFlag( false ),
     segmentInfoDefault( NULL ),
     isBitstreamSwitching( false )
@@ -110,3 +112,8 @@ bool AdaptationSet::getBitstreamSwitching  () const
 {
     return this->isBitstreamSwitching;
 }
+
+std::string AdaptationSet::getUrlSegment() const
+{
+    return getParentUrlSegment();
+}
index 5e52a8fdce80583c488c065bf7ce87dde7eec10d..0e402516739d1fb928aed5bd827c54cae926a778 100644 (file)
 
 #include "mpd/Representation.h"
 #include "mpd/CommonAttributesElements.h"
+#include "mpd/ICanonicalUrl.hpp"
 
 namespace dash
 {
     namespace mpd
     {
         class SegmentInfoDefault;
+        class Period;
 
-        class AdaptationSet : public CommonAttributesElements
+        class AdaptationSet : public CommonAttributesElements, public ICanonicalUrl
         {
             public:
-                AdaptationSet();
+                AdaptationSet(Period *);
                 virtual ~AdaptationSet();
 
                 virtual const std::string&      getMimeType() const; /*reimpl*/
@@ -54,6 +56,7 @@ namespace dash
                 void                            setBitstreamSwitching(bool value);
                 bool                            getBitstreamSwitching() const;
                 void                            addRepresentation( Representation *rep );
+                virtual std::string             getUrlSegment() const; /* reimpl */
 
             private:
                 bool                            subsegmentAlignmentFlag;
index 677c26950a7d5d6ebe8def1060470bf20f568c7c..f18058534a50cc6fce00899740b225e89fc27521 100644 (file)
@@ -222,7 +222,7 @@ void    BasicCMParser::setAdaptationSets(Node *root, Period *period)
     for(size_t i = 0; i < adaptSets.size(); i++)
     {
         const std::map<std::string, std::string>    attr = adaptSets.at(i)->getAttributes();
-        AdaptationSet *adaptSet = new AdaptationSet;
+        AdaptationSet *adaptSet = new AdaptationSet(period);
         if ( this->parseCommonAttributesElements( adaptSets.at( i ), adaptSet, NULL ) == false )
         {
             delete adaptSet;
@@ -264,7 +264,7 @@ void    BasicCMParser::setRepresentations   (Node *root, AdaptationSet *group)
     {
         const std::map<std::string, std::string>    attributes = representations.at(i)->getAttributes();
 
-        Representation *rep = new Representation(getMPD());
+        Representation *rep = new Representation(group, getMPD());
         rep->setParentGroup( group );
         this->currentRepresentation = rep;
         if ( this->parseCommonAttributesElements( representations.at( i ), rep, group ) == false )
index 630677bb6c33feca5ccb38a59bed95b5baa06ef8..a51045d065c4af3b28c60bea3a9848f0aa5f2796 100644 (file)
@@ -48,7 +48,7 @@ void IMPDParser::setPeriods(Node *root_)
 
     for(size_t i = 0; i < periods.size(); i++)
     {
-        Period *period = new Period();
+        Period *period = new Period(mpd);
         setAdaptationSets(periods.at(i), period);
         mpd->addPeriod(period);
     }
index 045c198b219bb4aecd14aeaaa3de5b291287283f..e2f22429cc60f868b932be35edda16c4001c7a7e 100644 (file)
@@ -76,7 +76,7 @@ void    IsoffMainParser::setAdaptationSets  (Node *periodNode, Period *period)
 
     for(it = adaptationSets.begin(); it != adaptationSets.end(); it++)
     {
-        AdaptationSet *adaptationSet = new AdaptationSet();
+        AdaptationSet *adaptationSet = new AdaptationSet(period);
         if(!adaptationSet)
             continue;
         if((*it)->hasAttribute("mimeType"))
@@ -91,7 +91,7 @@ void    IsoffMainParser::setRepresentations (Node *adaptationSetNode, Adaptation
 
     for(size_t i = 0; i < representations.size(); i++)
     {
-        this->currentRepresentation = new Representation(getMPD());
+        this->currentRepresentation = new Representation(adaptationSet, getMPD());
         Node *repNode = representations.at(i);
 
         std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(repNode, "BaseURL");
index ffcd88fde257f01aeb87706758a989b59776f606..80d7f29335d4a64fec959d39c1214fe9c8a9a36b 100644 (file)
@@ -166,7 +166,11 @@ std::string MPD::getUrlSegment() const
     if (!baseUrls.empty())
         return baseUrls.front()->getUrl();
     else
-        return std::string();
+    {
+        std::stringstream ss;
+        ss << stream->psz_access << "://" << Helper::getDirectoryPath(stream->psz_path) << "/";
+        return ss.str();
+    }
 }
 
 vlc_object_t * MPD::getVLCObject() const
index 220db82a7155b52e60d94e6490f77453689fbd9e..94ec3822674c597fe49e991d119c9582528ecbb5 100644 (file)
 #endif
 
 #include "Period.h"
+#include "MPD.h"
 
 #include <vlc_common.h>
 #include <vlc_arrays.h>
 
 using namespace dash::mpd;
 
-Period::Period()
+Period::Period(MPD *mpd) :
+    ICanonicalUrl( mpd )
 {
 }
 
@@ -75,3 +77,8 @@ AdaptationSet * Period::getAdaptationSet(Streams::Type type) const
     }
     return NULL;
 }
+
+std::string Period::getUrlSegment() const
+{
+    return getParentUrlSegment();
+}
index b92737b1bc580f633ebcd1f28064fe06e10e37e5..f586b3ebe3738f632e5e7d80fb58ac2884dc9a86 100644 (file)
 #include <string>
 
 #include "mpd/AdaptationSet.h"
+#include "mpd/ICanonicalUrl.hpp"
 #include "Streams.hpp"
 
 namespace dash
 {
     namespace mpd
     {
-        class Period
+        class MPD;
+        class Period : public ICanonicalUrl
         {
             public:
-                Period();
+                Period(MPD *);
                 virtual ~Period ();
 
                 const std::vector<AdaptationSet *>& getAdaptationSets   () const;
@@ -45,6 +47,8 @@ namespace dash
                 AdaptationSet *                     getAdaptationSet    (Streams::Type) const;
                 void                                addAdaptationSet    (AdaptationSet *AdaptationSet);
 
+                virtual std::string getUrlSegment() const; /* reimpl */
+
             private:
                 std::vector<AdaptationSet *>    adaptationSets;
         };
index ffbe46cfcd5c9ada884a9a87ab1e6e698d18c864..ecdb32646c1f303df5a99cfd78c3461cc633fd81 100644 (file)
 #include <cstdlib>
 
 #include "Representation.h"
+#include "mpd/AdaptationSet.h"
 #include "mpd/MPD.h"
 
 using namespace dash::mpd;
 
-Representation::Representation  ( MPD *mpd_ ) :
-                ICanonicalUrl   ( mpd_ ),
+Representation::Representation  ( AdaptationSet *set, MPD *mpd_ ) :
+                ICanonicalUrl   ( set ),
                 mpd             ( mpd_ ),
                 bandwidth       (0),
                 qualityRanking  ( -1 ),
index 68b360f96c993004a3f5ae2dd848a4e9584d9589..80c3add69dc46be7c8dfd3906dcb44fcd24201a1 100644 (file)
@@ -46,7 +46,7 @@ namespace dash
                                public ICanonicalUrl
         {
             public:
-                Representation( MPD *mpd );
+                Representation( AdaptationSet *, MPD *mpd );
                 virtual ~Representation ();
 
                 const std::string&  getId                   () const;
index 4557dae99991f3f9c195044c5d45cc07b9dc7355..98af3bb414baada5285f1251784c30441d7004a9 100644 (file)
@@ -47,16 +47,24 @@ ISegment::ISegment(const ICanonicalUrl *parent):
     classId = CLASSID_ISEGMENT;
 }
 
-dash::http::Chunk * ISegment::getChunk()
+dash::http::Chunk * ISegment::getChunk(const std::string &url)
 {
-    return new SegmentChunk(this);
+    return new (std::nothrow) SegmentChunk(this, url);
 }
 
 dash::http::Chunk* ISegment::toChunk()
 {
-    Chunk *chunk = getChunk();
-    if (!chunk)
+    Chunk *chunk;
+    try
+    {
+        chunk = getChunk(getUrlSegment());
+        if (!chunk)
+            return NULL;
+    }
+    catch (int)
+    {
         return NULL;
+    }
 
     if(startByte != endByte)
     {
@@ -64,8 +72,6 @@ dash::http::Chunk* ISegment::toChunk()
         chunk->setEndByte(endByte);
     }
 
-    chunk->setUrl(getUrlSegment());
-
     return chunk;
 }
 
@@ -121,8 +127,8 @@ int ISegment::getClassId() const
     return classId;
 }
 
-ISegment::SegmentChunk::SegmentChunk(ISegment *segment_) :
-    dash::http::Chunk()
+ISegment::SegmentChunk::SegmentChunk(ISegment *segment_, const std::string &url) :
+    dash::http::Chunk(url)
 {
     segment = segment_;
 }
@@ -232,13 +238,13 @@ IndexSegment::IndexSegment(Representation *parent) :
     classId = CLASSID_INDEXSEGMENT;
 }
 
-dash::http::Chunk * IndexSegment::getChunk()
+dash::http::Chunk * IndexSegment::getChunk(const std::string &url)
 {
-    return new IndexSegmentChunk(this);
+    return new IndexSegmentChunk(this, url);
 }
 
-IndexSegment::IndexSegmentChunk::IndexSegmentChunk(ISegment *segment)
-    : SegmentChunk(segment)
+IndexSegment::IndexSegmentChunk::IndexSegmentChunk(ISegment *segment, const std::string &url)
+    : SegmentChunk(segment, url)
 {
 
 }
index ae77aced56446fb57f6c0d831d9318bb23d81f93..0531a535a641773525755363715f94d4ab3293bd 100644 (file)
@@ -74,14 +74,14 @@ namespace dash
                 class SegmentChunk : public dash::http::Chunk
                 {
                     public:
-                        SegmentChunk(ISegment *segment);
+                        SegmentChunk(ISegment *segment, const std::string &url);
                         virtual void onDownload(void *, size_t);
 
                     protected:
                         ISegment *segment;
                 };
 
-                virtual dash::http::Chunk * getChunk();
+                virtual dash::http::Chunk * getChunk(const std::string &);
         };
 
         class Segment : public ISegment
@@ -122,11 +122,11 @@ namespace dash
                 class IndexSegmentChunk : public SegmentChunk
                 {
                     public:
-                        IndexSegmentChunk(ISegment *segment);
+                        IndexSegmentChunk(ISegment *segment, const std::string &);
                         virtual void onDownload(void *, size_t);
                 };
 
-                virtual dash::http::Chunk * getChunk();
+                virtual dash::http::Chunk * getChunk(const std::string &);
         };
 
         class SubSegment : public ISegment