Commit 6c8bc5c2 authored by François Cartegnie's avatar François Cartegnie 🤞

stream_filter: dash: build urls using class

We'll need this for templates
parent 26beaad6
......@@ -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 \
......
......@@ -113,7 +113,7 @@ bool AdaptationSet::getBitstreamSwitching () const
return this->isBitstreamSwitching;
}
std::string AdaptationSet::getUrlSegment() const
Url AdaptationSet::getUrlSegment() const
{
return getParentUrlSegment();
}
......@@ -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;
......
......@@ -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:
......
......@@ -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++)
......
......@@ -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());
}
}
......
......@@ -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;
......
......@@ -78,7 +78,7 @@ AdaptationSet * Period::getAdaptationSet(Streams::Type type) const
return NULL;
}
std::string Period::getUrlSegment() const
Url Period::getUrlSegment() const
{
return getParentUrlSegment();
}
......@@ -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;
......
......@@ -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;
......
......@@ -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
{
......
......@@ -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();
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
/*
* 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;
}
/*
* 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment