Commit da513a4e authored by Christopher Mueller's avatar Christopher Mueller Committed by Hugo Beauzée-Luyssen

dash: added resolution interpretation

Signed-off-by: default avatarHugo Beauzée-Luyssen <beauze.h@gmail.com>
parent 62748a33
...@@ -35,18 +35,19 @@ using namespace dash::mpd; ...@@ -35,18 +35,19 @@ using namespace dash::mpd;
using namespace dash::exception; using namespace dash::exception;
DASHManager::DASHManager ( HTTPConnectionManager *conManager, MPD *mpd, DASHManager::DASHManager ( HTTPConnectionManager *conManager, MPD *mpd,
IAdaptationLogic::LogicType type ) : IAdaptationLogic::LogicType type, stream_t *stream) :
conManager( conManager ), conManager( conManager ),
currentChunk( NULL ), currentChunk( NULL ),
adaptationLogic( NULL ), adaptationLogic( NULL ),
logicType( type ), logicType( type ),
mpdManager( NULL ), mpdManager( NULL ),
mpd( mpd ) mpd( mpd ),
stream(stream)
{ {
this->mpdManager = mpd::MPDManagerFactory::create( mpd ); this->mpdManager = mpd::MPDManagerFactory::create( mpd );
if ( this->mpdManager == NULL ) if ( this->mpdManager == NULL )
return ; return ;
this->adaptationLogic = AdaptationLogicFactory::create( this->logicType, this->mpdManager ); this->adaptationLogic = AdaptationLogicFactory::create( this->logicType, this->mpdManager, this->stream);
if ( this->adaptationLogic == NULL ) if ( this->adaptationLogic == NULL )
return ; return ;
this->conManager->attach(this->adaptationLogic); this->conManager->attach(this->adaptationLogic);
......
...@@ -40,7 +40,7 @@ namespace dash ...@@ -40,7 +40,7 @@ namespace dash
{ {
public: public:
DASHManager( http::HTTPConnectionManager *conManager, mpd::MPD *mpd, DASHManager( http::HTTPConnectionManager *conManager, mpd::MPD *mpd,
logic::IAdaptationLogic::LogicType type ); logic::IAdaptationLogic::LogicType type, stream_t *stream);
virtual ~DASHManager (); virtual ~DASHManager ();
int read( void *p_buffer, size_t len ); int read( void *p_buffer, size_t len );
...@@ -56,6 +56,7 @@ namespace dash ...@@ -56,6 +56,7 @@ namespace dash
logic::IAdaptationLogic::LogicType logicType; logic::IAdaptationLogic::LogicType logicType;
mpd::IMPDManager *mpdManager; mpd::IMPDManager *mpdManager;
mpd::MPD *mpd; mpd::MPD *mpd;
stream_t *stream;
}; };
} }
......
...@@ -32,11 +32,13 @@ using namespace dash::xml; ...@@ -32,11 +32,13 @@ using namespace dash::xml;
using namespace dash::mpd; using namespace dash::mpd;
using namespace dash::exception; using namespace dash::exception;
AbstractAdaptationLogic::AbstractAdaptationLogic (IMPDManager *mpdManager) AbstractAdaptationLogic::AbstractAdaptationLogic (IMPDManager *mpdManager, stream_t *stream) :
bpsAvg (-1),
bpsLastChunk (0),
mpdManager (mpdManager),
stream (stream)
{ {
this->bpsAvg = -1;
this->bpsLastChunk = 0;
this->mpdManager = mpdManager;
} }
AbstractAdaptationLogic::~AbstractAdaptationLogic () AbstractAdaptationLogic::~AbstractAdaptationLogic ()
{ {
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include "mpd/Segment.h" #include "mpd/Segment.h"
#include "exceptions/EOFException.h" #include "exceptions/EOFException.h"
struct stream_t;
namespace dash namespace dash
{ {
namespace logic namespace logic
...@@ -42,7 +44,7 @@ namespace dash ...@@ -42,7 +44,7 @@ namespace dash
class AbstractAdaptationLogic : public IAdaptationLogic class AbstractAdaptationLogic : public IAdaptationLogic
{ {
public: public:
AbstractAdaptationLogic (dash::mpd::IMPDManager *mpdManager); AbstractAdaptationLogic (dash::mpd::IMPDManager *mpdManager, stream_t *stream);
virtual ~AbstractAdaptationLogic (); virtual ~AbstractAdaptationLogic ();
virtual void downloadRateChanged (long bpsAvg, long bpsLastChunk); virtual void downloadRateChanged (long bpsAvg, long bpsLastChunk);
...@@ -54,6 +56,7 @@ namespace dash ...@@ -54,6 +56,7 @@ namespace dash
int bpsAvg; int bpsAvg;
long bpsLastChunk; long bpsLastChunk;
dash::mpd::IMPDManager *mpdManager; dash::mpd::IMPDManager *mpdManager;
stream_t *stream;
}; };
} }
} }
......
...@@ -32,12 +32,12 @@ using namespace dash::xml; ...@@ -32,12 +32,12 @@ using namespace dash::xml;
using namespace dash::mpd; using namespace dash::mpd;
IAdaptationLogic* AdaptationLogicFactory::create ( IAdaptationLogic::LogicType logic, IAdaptationLogic* AdaptationLogicFactory::create ( IAdaptationLogic::LogicType logic,
IMPDManager *mpdManager ) IMPDManager *mpdManager, stream_t *stream)
{ {
switch(logic) switch(logic)
{ {
case IAdaptationLogic::AlwaysBest: return new AlwaysBestAdaptationLogic (mpdManager); case IAdaptationLogic::AlwaysBest: return new AlwaysBestAdaptationLogic (mpdManager, stream);
case IAdaptationLogic::RateBased: return new RateBasedAdaptationLogic (mpdManager); case IAdaptationLogic::RateBased: return new RateBasedAdaptationLogic (mpdManager, stream);
case IAdaptationLogic::Default: case IAdaptationLogic::Default:
case IAdaptationLogic::AlwaysLowest: case IAdaptationLogic::AlwaysLowest:
default: default:
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include "adaptationlogic/AlwaysBestAdaptationLogic.h" #include "adaptationlogic/AlwaysBestAdaptationLogic.h"
#include "adaptationlogic/RateBasedAdaptationLogic.h" #include "adaptationlogic/RateBasedAdaptationLogic.h"
struct stream_t;
namespace dash namespace dash
{ {
namespace logic namespace logic
...@@ -38,7 +40,7 @@ namespace dash ...@@ -38,7 +40,7 @@ namespace dash
class AdaptationLogicFactory class AdaptationLogicFactory
{ {
public: public:
static IAdaptationLogic* create (IAdaptationLogic::LogicType logic, dash::mpd::IMPDManager *mpdManager); static IAdaptationLogic* create (IAdaptationLogic::LogicType logic, dash::mpd::IMPDManager *mpdManager, stream_t *stream);
}; };
} }
} }
......
...@@ -33,7 +33,8 @@ using namespace dash::http; ...@@ -33,7 +33,8 @@ using namespace dash::http;
using namespace dash::mpd; using namespace dash::mpd;
using namespace dash::exception; using namespace dash::exception;
AlwaysBestAdaptationLogic::AlwaysBestAdaptationLogic (IMPDManager *mpdManager) : AbstractAdaptationLogic(mpdManager) AlwaysBestAdaptationLogic::AlwaysBestAdaptationLogic (IMPDManager *mpdManager, stream_t *stream) :
AbstractAdaptationLogic (mpdManager, stream)
{ {
this->mpdManager = mpdManager; this->mpdManager = mpdManager;
this->count = 0; this->count = 0;
......
...@@ -42,7 +42,7 @@ namespace dash ...@@ -42,7 +42,7 @@ namespace dash
class AlwaysBestAdaptationLogic : public AbstractAdaptationLogic class AlwaysBestAdaptationLogic : public AbstractAdaptationLogic
{ {
public: public:
AlwaysBestAdaptationLogic (dash::mpd::IMPDManager *mpdManager); AlwaysBestAdaptationLogic (dash::mpd::IMPDManager *mpdManager, stream_t *stream);
virtual ~AlwaysBestAdaptationLogic (); virtual ~AlwaysBestAdaptationLogic ();
dash::http::Chunk* getNextChunk() throw(dash::exception::EOFException); dash::http::Chunk* getNextChunk() throw(dash::exception::EOFException);
......
...@@ -33,12 +33,16 @@ using namespace dash::http; ...@@ -33,12 +33,16 @@ using namespace dash::http;
using namespace dash::mpd; using namespace dash::mpd;
using namespace dash::exception; using namespace dash::exception;
RateBasedAdaptationLogic::RateBasedAdaptationLogic (IMPDManager *mpdManager) : RateBasedAdaptationLogic::RateBasedAdaptationLogic (IMPDManager *mpdManager, stream_t *stream) :
AbstractAdaptationLogic( mpdManager ), AbstractAdaptationLogic (mpdManager, stream),
mpdManager( mpdManager ), mpdManager (mpdManager),
count( 0 ), count (0),
currentPeriod( mpdManager->getFirstPeriod() ) currentPeriod (mpdManager->getFirstPeriod()),
width (0),
height (0)
{ {
this->width = var_InheritInteger(stream, "dash-prefwidth");
this->height = var_InheritInteger(stream, "dash-prefheight");
} }
Chunk* RateBasedAdaptationLogic::getNextChunk() throw(EOFException) Chunk* RateBasedAdaptationLogic::getNextChunk() throw(EOFException)
...@@ -51,7 +55,7 @@ Chunk* RateBasedAdaptationLogic::getNextChunk() throw(EOFException) ...@@ -51,7 +55,7 @@ Chunk* RateBasedAdaptationLogic::getNextChunk() throw(EOFException)
long bitrate = this->getBpsAvg(); long bitrate = this->getBpsAvg();
Representation *rep = this->mpdManager->getRepresentation(this->currentPeriod, bitrate); Representation *rep = this->mpdManager->getRepresentation(this->currentPeriod, bitrate, this->width, this->height);
if ( rep == NULL ) if ( rep == NULL )
throw EOFException(); throw EOFException();
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#include "exceptions/EOFException.h" #include "exceptions/EOFException.h"
#include "mpd/BasicCMManager.h" #include "mpd/BasicCMManager.h"
#include <vlc_common.h>
#include <vlc_stream.h>
namespace dash namespace dash
{ {
namespace logic namespace logic
...@@ -39,7 +42,7 @@ namespace dash ...@@ -39,7 +42,7 @@ namespace dash
class RateBasedAdaptationLogic : public AbstractAdaptationLogic class RateBasedAdaptationLogic : public AbstractAdaptationLogic
{ {
public: public:
RateBasedAdaptationLogic (dash::mpd::IMPDManager *mpdManager); RateBasedAdaptationLogic (dash::mpd::IMPDManager *mpdManager, stream_t *stream);
dash::http::Chunk* getNextChunk() throw(dash::exception::EOFException); dash::http::Chunk* getNextChunk() throw(dash::exception::EOFException);
const dash::mpd::Representation *getCurrentRepresentation() const; const dash::mpd::Representation *getCurrentRepresentation() const;
...@@ -48,6 +51,8 @@ namespace dash ...@@ -48,6 +51,8 @@ namespace dash
dash::mpd::IMPDManager *mpdManager; dash::mpd::IMPDManager *mpdManager;
size_t count; size_t count;
dash::mpd::Period *currentPeriod; dash::mpd::Period *currentPeriod;
int width;
int height;
}; };
} }
} }
......
...@@ -48,12 +48,20 @@ ...@@ -48,12 +48,20 @@
static int Open (vlc_object_t *); static int Open (vlc_object_t *);
static void Close (vlc_object_t *); static void Close (vlc_object_t *);
#define DASH_WIDTH_TEXT N_("Preferred Width")
#define DASH_WIDTH_LONGTEXT N_("Preferred Width")
#define DASH_HEIGHT_TEXT N_("Preferred Height")
#define DASH_HEIGHT_LONGTEXT N_("Preferred Height")
vlc_module_begin () vlc_module_begin ()
set_shortname( N_("DASH")) set_shortname( N_("DASH"))
set_description( N_("Dynamic Adaptive Streaming over HTTP") ) set_description( N_("Dynamic Adaptive Streaming over HTTP") )
set_capability( "stream_filter", 19 ) set_capability( "stream_filter", 19 )
set_category( CAT_INPUT ) set_category( CAT_INPUT )
set_subcategory( SUBCAT_INPUT_STREAM_FILTER ) set_subcategory( SUBCAT_INPUT_STREAM_FILTER )
add_integer( "dash-prefwidth", 480, DASH_WIDTH_TEXT, DASH_WIDTH_LONGTEXT, true )
add_integer( "dash-prefheight", 360, DASH_HEIGHT_TEXT, DASH_HEIGHT_LONGTEXT, true )
set_callbacks( Open, Close ) set_callbacks( Open, Close )
vlc_module_end () vlc_module_end ()
...@@ -106,7 +114,7 @@ static int Open(vlc_object_t *p_obj) ...@@ -106,7 +114,7 @@ static int Open(vlc_object_t *p_obj)
new dash::http::HTTPConnectionManager( p_stream ); new dash::http::HTTPConnectionManager( p_stream );
dash::DASHManager*p_dashManager = dash::DASHManager*p_dashManager =
new dash::DASHManager( p_conManager, p_sys->p_mpd, new dash::DASHManager( p_conManager, p_sys->p_mpd,
dash::logic::IAdaptationLogic::RateBased ); dash::logic::IAdaptationLogic::RateBased, p_stream);
if ( p_dashManager->getMpdManager() == NULL || if ( p_dashManager->getMpdManager() == NULL ||
p_dashManager->getMpdManager()->getMPD() == NULL || p_dashManager->getMpdManager()->getMPD() == NULL ||
......
...@@ -91,7 +91,7 @@ Period* BasicCMManager::getFirstPeriod () ...@@ -91,7 +91,7 @@ Period* BasicCMManager::getFirstPeriod ()
return periods.at(0); return periods.at(0);
} }
Representation* BasicCMManager::getRepresentation(Period *period, int bitrate ) Representation* BasicCMManager::getRepresentation(Period *period, int bitrate ) const
{ {
std::vector<Group *> groups = period->getGroups(); std::vector<Group *> groups = period->getGroups();
...@@ -134,4 +134,7 @@ const MPD* BasicCMManager::getMPD() const ...@@ -134,4 +134,7 @@ const MPD* BasicCMManager::getMPD() const
{ {
return this->mpd; return this->mpd;
} }
Representation* BasicCMManager::getRepresentation (Period *period, int bitrate, int width, int height) const
{
return this->getRepresentation(period, bitrate);
}
...@@ -52,8 +52,10 @@ namespace dash ...@@ -52,8 +52,10 @@ namespace dash
Period* getNextPeriod( Period *period ); Period* getNextPeriod( Period *period );
Representation* getBestRepresentation( Period *period ); Representation* getBestRepresentation( Period *period );
std::vector<Segment *> getSegments( const Representation *rep ); std::vector<Segment *> getSegments( const Representation *rep );
Representation* getRepresentation( Period *period, int bitrate ); Representation* getRepresentation( Period *period, int bitrate ) const;
const MPD* getMPD() const; const MPD* getMPD() const;
Representation* getRepresentation (Period *period, int bitrate,
int width, int height) const;
private: private:
MPD *mpd; MPD *mpd;
......
...@@ -45,14 +45,17 @@ namespace dash ...@@ -45,14 +45,17 @@ namespace dash
class IMPDManager class IMPDManager
{ {
public: public:
virtual const std::vector<Period *>& getPeriods () const = 0;
virtual Period* getFirstPeriod () = 0;
virtual Period* getNextPeriod (Period *period) = 0;
virtual Representation* getBestRepresentation (Period *period) = 0;
virtual std::vector<Segment *> getSegments( const Representation *rep ) = 0;
virtual Representation* getRepresentation (Period *period, int bitrate) = 0;
virtual const MPD* getMPD () const = 0;
virtual ~IMPDManager(){} virtual ~IMPDManager(){}
virtual const std::vector<Period *>& getPeriods () const = 0;
virtual Period* getFirstPeriod () = 0;
virtual Period* getNextPeriod (Period *period) = 0;
virtual Representation* getBestRepresentation (Period *period) = 0;
virtual std::vector<Segment *> getSegments (const Representation *rep) = 0;
virtual Representation* getRepresentation (Period *period, int bitrate) const = 0;
virtual const MPD* getMPD () const = 0;
virtual Representation* getRepresentation (Period *period, int bitrate,
int width, int height) const = 0;
}; };
} }
} }
......
...@@ -87,7 +87,7 @@ Period* IsoffMainManager::getFirstPeriod () ...@@ -87,7 +87,7 @@ Period* IsoffMainManager::getFirstPeriod ()
return periods.at(0); return periods.at(0);
} }
Representation* IsoffMainManager::getRepresentation (Period *period, int bitrate ) Representation* IsoffMainManager::getRepresentation (Period *period, int bitrate) const
{ {
std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets(); std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
...@@ -126,3 +126,48 @@ const MPD* IsoffMainManager::getMPD () const ...@@ -126,3 +126,48 @@ const MPD* IsoffMainManager::getMPD () const
{ {
return this->mpd; return this->mpd;
} }
Representation* IsoffMainManager::getRepresentation (Period *period, int bitrate, int width, int height) const
{
std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
std::cout << "Searching for best representation with bitrate: " << bitrate << " and resolution: " << width << "x" << height << std::endl;
std::vector<Representation *> resMatchReps;
int lowerWidth = 0;
int lowerHeight = 0;
for(size_t i = 0; i < adaptationSets.size(); i++)
{
std::vector<Representation *> reps = adaptationSets.at(i)->getRepresentations();
for( size_t j = 0; j < reps.size(); j++ )
{
if(reps.at(j)->getWidth() == width && reps.at(j)->getHeight() == height)
resMatchReps.push_back(reps.at(j));
if(reps.at(j)->getHeight() < height)
{
lowerWidth = reps.at(j)->getWidth();
lowerHeight = reps.at(j)->getHeight();
}
}
}
if(resMatchReps.size() == 0)
return this->getRepresentation(period, bitrate, lowerWidth, lowerHeight);
Representation *best = NULL;
for( size_t j = 0; j < resMatchReps.size(); j++ )
{
int currentBitrate = resMatchReps.at(j)->getBandwidth();
if(best == NULL || (currentBitrate > best->getBandwidth() && currentBitrate < bitrate))
{
std::cout << "Found a better Representation bandwidth=" << resMatchReps.at(j)->getBandwidth()
<< " and resolution: " << resMatchReps.at(j)->getWidth() << "x" << resMatchReps.at(j)->getHeight() << std::endl;
best = resMatchReps.at(j);
}
}
return best;
}
...@@ -52,8 +52,10 @@ namespace dash ...@@ -52,8 +52,10 @@ namespace dash
Period* getNextPeriod (Period *period); Period* getNextPeriod (Period *period);
Representation* getBestRepresentation (Period *period); Representation* getBestRepresentation (Period *period);
std::vector<Segment *> getSegments (const Representation *rep); std::vector<Segment *> getSegments (const Representation *rep);
Representation* getRepresentation (Period *period, int bitrate); Representation* getRepresentation (Period *period, int bitrate) const;
const MPD* getMPD () const; const MPD* getMPD () const;
Representation* getRepresentation (Period *period, int bitrate,
int width, int height) const;
private: private:
MPD *mpd; MPD *mpd;
......
...@@ -113,12 +113,21 @@ void IsoffMainParser::setRepresentations (Node *adaptationSetNode, Adaptation ...@@ -113,12 +113,21 @@ void IsoffMainParser::setRepresentations (Node *adaptationSetNode, Adaptation
for(size_t i = 0; i < representations.size(); i++) for(size_t i = 0; i < representations.size(); i++)
{ {
Representation *rep = new Representation; this->currentRepresentation = new Representation;
this->currentRepresentation = rep; Node *repNode = representations.at(i);
this->setSegmentBase(representations.at(i), rep);
this->setSegmentList(representations.at(i), rep); if(repNode->hasAttribute("width"))
rep->setBandwidth(atoi(representations.at(i)->getAttributeValue("bandwidth").c_str())); this->currentRepresentation->setWidth(atoi(repNode->getAttributeValue("width").c_str()));
adaptationSet->addRepresentation(rep);
if(repNode->hasAttribute("height"))
this->currentRepresentation->setHeight(atoi(repNode->getAttributeValue("height").c_str()));
if(repNode->hasAttribute("bandwidth"))
this->currentRepresentation->setBandwidth(atoi(repNode->getAttributeValue("bandwidth").c_str()));
this->setSegmentBase(repNode, this->currentRepresentation);
this->setSegmentList(repNode, this->currentRepresentation);
adaptationSet->addRepresentation(this->currentRepresentation);
} }
} }
void IsoffMainParser::setSegmentBase (dash::xml::Node *repNode, Representation *rep) void IsoffMainParser::setSegmentBase (dash::xml::Node *repNode, Representation *rep)
......
...@@ -37,7 +37,9 @@ Representation::Representation () : ...@@ -37,7 +37,9 @@ Representation::Representation () :
trickModeType ( NULL ), trickModeType ( NULL ),
parentGroup ( NULL ), parentGroup ( NULL ),
segmentBase ( NULL ), segmentBase ( NULL ),
segmentList ( NULL ) segmentList ( NULL ),
width (0),
height (0)
{ {
} }
...@@ -139,3 +141,19 @@ void Representation::setSegmentBase (SegmentBase *base) ...@@ -139,3 +141,19 @@ void Representation::setSegmentBase (SegmentBase *base)
{ {
this->segmentBase = base; this->segmentBase = base;
} }
void Representation::setWidth (int width)
{
this->width = width;
}
int Representation::getWidth () const
{
return this->width;
}
void Representation::setHeight (int height)
{
this->height = height;
}
int Representation::getHeight () const
{
return this->height;
}
...@@ -76,6 +76,10 @@ namespace dash ...@@ -76,6 +76,10 @@ namespace dash
void setSegmentList (SegmentList *list); void setSegmentList (SegmentList *list);
SegmentBase* getSegmentBase () const; SegmentBase* getSegmentBase () const;
void setSegmentBase (SegmentBase *base); void setSegmentBase (SegmentBase *base);
void setWidth (int width);
int getWidth () const;
void setHeight (int height);
int getHeight () const;
private: private:
int bandwidth; int bandwidth;
...@@ -87,6 +91,8 @@ namespace dash ...@@ -87,6 +91,8 @@ namespace dash
const Group *parentGroup; const Group *parentGroup;
SegmentBase *segmentBase; SegmentBase *segmentBase;
SegmentList *segmentList; SegmentList *segmentList;
int width;
int height;
}; };
} }
} }
......
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