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
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);
{
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
{
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;
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);
size_t endByte;
int bitrate;
int port;
- bool isHostname;
uint64_t length;
uint64_t bytesRead;
uint64_t bytesToRead;
#include "Chunk.h"
#include <sstream>
-#include <vlc_stream.h>
using namespace dash::http;
if(chunk_ == chunk)
return;
if (chunk_)
- {
chunk_->setConnection(this);
- if(!chunk->hasHostname())
- chunk->setUrl(getUrlRelative(chunk));
- }
chunk = chunk_;
}
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;
Chunk *chunk;
virtual std::string extraRequestHeaders() const;
virtual std::string buildRequestHeader(const std::string &path) const;
-
- std::string getUrlRelative(const Chunk *chunk) const;
};
}
}
#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 )
{
return this->isBitstreamSwitching;
}
+
+std::string AdaptationSet::getUrlSegment() const
+{
+ return getParentUrlSegment();
+}
#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*/
void setBitstreamSwitching(bool value);
bool getBitstreamSwitching() const;
void addRepresentation( Representation *rep );
+ virtual std::string getUrlSegment() const; /* reimpl */
private:
bool subsegmentAlignmentFlag;
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;
{
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 )
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);
}
for(it = adaptationSets.begin(); it != adaptationSets.end(); it++)
{
- AdaptationSet *adaptationSet = new AdaptationSet();
+ AdaptationSet *adaptationSet = new AdaptationSet(period);
if(!adaptationSet)
continue;
if((*it)->hasAttribute("mimeType"))
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");
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
#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 )
{
}
}
return NULL;
}
+
+std::string Period::getUrlSegment() const
+{
+ return getParentUrlSegment();
+}
#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;
AdaptationSet * getAdaptationSet (Streams::Type) const;
void addAdaptationSet (AdaptationSet *AdaptationSet);
+ virtual std::string getUrlSegment() const; /* reimpl */
+
private:
std::vector<AdaptationSet *> adaptationSets;
};
#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 ),
public ICanonicalUrl
{
public:
- Representation( MPD *mpd );
+ Representation( AdaptationSet *, MPD *mpd );
virtual ~Representation ();
const std::string& getId () const;
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)
{
chunk->setEndByte(endByte);
}
- chunk->setUrl(getUrlSegment());
-
return chunk;
}
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_;
}
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)
{
}
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
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