]> git.sesse.net Git - vlc/blobdiff - modules/stream_filter/dash/mpd/Representation.cpp
stream_filter: dash: always get segments through representation
[vlc] / modules / stream_filter / dash / mpd / Representation.cpp
index 160e763e87b184cc1489e09c430cca5fb77a2fa8..765509cd59c816e1d30fc199d3693b00ace706b7 100644 (file)
  * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
  *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
  *
- * 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
+ * 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 General Public License for more details.
+ * 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.
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
+#include <cstdlib>
+
 #include "Representation.h"
 
 using namespace dash::mpd;
-using namespace dash::exception;
 
-Representation::Representation  (std::map<std::string, std::string>  attributes)
+Representation::Representation  () :
+                bandwidth       (0),
+                qualityRanking  ( -1 ),
+                segmentInfo     ( NULL ),
+                trickModeType   ( NULL ),
+                parentGroup     ( NULL ),
+                segmentBase     ( NULL ),
+                segmentList     ( NULL ),
+                baseUrl         ( NULL ),
+                width           (0),
+                height          (0)
+
 {
-    this->attributes        = attributes;
-    this->contentProtection = NULL;
-    this->trickModeType     = NULL;
-    this->segmentInfo       = NULL;
 }
+
 Representation::~Representation ()
 {
     delete(this->segmentInfo);
-    delete(this->contentProtection);
     delete(this->trickModeType);
+    delete baseUrl;
 }
 
-std::string         Representation::getFrameRate            () throw(AttributeNotPresentException)
+const std::string&  Representation::getId                   () const
 {
-    if(this->attributes.find("frameRate") == this->attributes.end())
-        throw AttributeNotPresentException();
-
-    return this->attributes["frameRate"];
-
+    return this->id;
 }
-std::string         Representation::getSamplingRate         () throw(AttributeNotPresentException)
-{
-    if(this->attributes.find("samplingRate") == this->attributes.end())
-        throw AttributeNotPresentException();
-
-    return this->attributes["samplingRate"];
 
-}
-std::string         Representation::getDependencyId         () throw(AttributeNotPresentException)
+void    Representation::setId(const std::string &id)
 {
-    if(this->attributes.find("dependencyId") == this->attributes.end())
-        throw AttributeNotPresentException();
-
-    return this->attributes["dependencyId"];
-
+    if ( id.empty() == false )
+        this->id = id;
 }
-std::string         Representation::getId                   () throw(AttributeNotPresentException)
-{
-    if(this->attributes.find("id") == this->attributes.end())
-        throw AttributeNotPresentException();
-
-    return this->attributes["id"];
 
+uint64_t     Representation::getBandwidth            () const
+{
+    return this->bandwidth;
 }
-std::string         Representation::getLang                 () throw(AttributeNotPresentException)
+
+void    Representation::setBandwidth( uint64_t bandwidth )
 {
-    if(this->attributes.find("lang") == this->attributes.end())
-        throw AttributeNotPresentException();
+    this->bandwidth = bandwidth;
+}
 
-    return this->attributes["lang"];
+SegmentInfo*        Representation::getSegmentInfo() const
+{
+    return this->segmentInfo;
+}
 
+TrickModeType*      Representation::getTrickModeType        () const
+{
+    return this->trickModeType;
 }
-std::string         Representation::getParX                 () throw(AttributeNotPresentException)
+
+void                Representation::setTrickMode        (TrickModeType *trickModeType)
 {
-    if(this->attributes.find("parx") == this->attributes.end())
-        throw AttributeNotPresentException();
+    this->trickModeType = trickModeType;
+}
 
-    return this->attributes["parx"];
+const AdaptationSet *Representation::getParentGroup() const
+{
+    return this->parentGroup;
+}
 
+void Representation::setParentGroup(const AdaptationSet *group)
+{
+    if ( group != NULL )
+        this->parentGroup = group;
 }
-std::string         Representation::getParY                 () throw(AttributeNotPresentException)
+
+void                Representation::setSegmentInfo          (SegmentInfo *info)
 {
-    if(this->attributes.find("pary") == this->attributes.end())
-        throw AttributeNotPresentException();
+    this->segmentInfo = info;
+}
 
-    return this->attributes["pary"];
 
+int Representation::getQualityRanking() const
+{
+    return this->qualityRanking;
 }
-std::string         Representation::getHeight               () throw(AttributeNotPresentException)
+
+void Representation::setQualityRanking( int qualityRanking )
 {
-    if(this->attributes.find("height") == this->attributes.end())
-        throw AttributeNotPresentException();
+    if ( qualityRanking > 0 )
+        this->qualityRanking = qualityRanking;
+}
 
-    return this->attributes["height"];
+const std::list<const Representation*>&     Representation::getDependencies() const
+{
+    return this->dependencies;
+}
 
+void Representation::addDependency(const Representation *dep)
+{
+    if ( dep != NULL )
+        this->dependencies.push_back( dep );
 }
-std::string         Representation::getWidth                () throw(AttributeNotPresentException)
+
+std::vector<Segment *> Representation::getSegments() const
 {
-    if(this->attributes.find("width") == this->attributes.end())
-        throw AttributeNotPresentException();
+    std::vector<Segment *>  retSegments;
 
-    return this->attributes["width"];
+    if ( segmentInfo )
+    {
+        retSegments.push_back( segmentInfo->getInitialisationSegment() );
 
-}
-std::string         Representation::getBandwidth            () throw(AttributeNotPresentException)
-{
-    if(this->attributes.find("bandwidth") == this->attributes.end())
-        throw AttributeNotPresentException();
+        if ( !segmentInfo->getSegments().empty() )
+            retSegments.insert( retSegments.end(),
+                                segmentInfo->getSegments().begin(),
+                                segmentInfo->getSegments().end() );
+    }
+    else
+    {
+        if( segmentBase && segmentBase->getInitSegment() )
+            retSegments.push_back( segmentBase->getInitSegment() );
 
-    return this->attributes["bandwidth"];
+        if ( segmentList )
+            retSegments.insert( retSegments.end(),
+                                segmentList->getSegments().begin(),
+                                segmentList->getSegments().end() );
+    }
 
+    return retSegments;
 }
-std::string         Representation::getNumberOfChannels     () throw(AttributeNotPresentException)
-{
-    if(this->attributes.find("numberOfChannels") == this->attributes.end())
-        throw AttributeNotPresentException();
-
-    return this->attributes["numberOfChannels"];
 
+void                Representation::setSegmentList          (SegmentList *list)
+{
+    this->segmentList = list;
 }
-SegmentInfo*        Representation::getSegmentInfo          () throw(ElementNotPresentException)
+
+void                Representation::setSegmentBase          (SegmentBase *base)
 {
-    if(this->segmentInfo == NULL)
-        throw ElementNotPresentException();
+    this->segmentBase = base;
+}
 
-    return this->segmentInfo;
+BaseUrl* Representation::getBaseUrl() const
+{
+    return baseUrl;
 }
-TrickModeType*      Representation::getTrickModeType        () throw(ElementNotPresentException)
+
+void Representation::setBaseUrl(BaseUrl *base)
 {
-    if(this->segmentInfo == NULL)
-        throw ElementNotPresentException();
+    baseUrl = base;
+}
 
-    return this->trickModeType;
+void                Representation::setWidth                (int width)
+{
+    this->width = width;
 }
-ContentProtection*  Representation::getContentProtection    () throw(ElementNotPresentException)
+int                 Representation::getWidth                () const
 {
-    if(this->contentProtection == NULL)
-        throw ElementNotPresentException();
-
-    return this->contentProtection;
+    return this->width;
 }
-void                Representation::setTrickModeType        (TrickModeType *trickModeType)
+void                Representation::setHeight               (int height)
 {
-    this->trickModeType = trickModeType;
+    this->height = height;
 }
-void                Representation::setContentProtection    (ContentProtection *protection)
+int                 Representation::getHeight               () const
 {
-    this->contentProtection = protection;
+    return this->height;
 }
-void                Representation::setSegmentInfo          (SegmentInfo *info)
+
+std::vector<std::string> Representation::toString() const
 {
-    this->segmentInfo = info;
+    std::vector<std::string> ret;
+    ret.push_back(std::string("  Representation"));
+    ret.push_back(std::string("    InitSeg url=")
+                  .append(segmentBase->getInitSegment()->getSourceUrl()));
+    if (segmentList)
+    {
+        std::vector<Segment *>::const_iterator l;
+        for(l = segmentList->getSegments().begin();
+            l < segmentList->getSegments().end(); l++)
+        {
+            ret.push_back(std::string("    Segment url=")
+                          .append((*l)->getSourceUrl()));
+        }
+    }
+    return ret;
 }