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;
using namespace dash::exception;
DASHManager::DASHManager ( HTTPConnectionManager *conManager, MPD *mpd,
IAdaptationLogic::LogicType type ) :
IAdaptationLogic::LogicType type, stream_t *stream) :
conManager( conManager ),
currentChunk( NULL ),
adaptationLogic( NULL ),
logicType( type ),
mpdManager( NULL ),
mpd( mpd )
mpd( mpd ),
stream(stream)
{
this->mpdManager = mpd::MPDManagerFactory::create( mpd );
if ( this->mpdManager == NULL )
return ;
this->adaptationLogic = AdaptationLogicFactory::create( this->logicType, this->mpdManager );
this->adaptationLogic = AdaptationLogicFactory::create( this->logicType, this->mpdManager, this->stream);
if ( this->adaptationLogic == NULL )
return ;
this->conManager->attach(this->adaptationLogic);
......
......@@ -40,7 +40,7 @@ namespace dash
{
public:
DASHManager( http::HTTPConnectionManager *conManager, mpd::MPD *mpd,
logic::IAdaptationLogic::LogicType type );
logic::IAdaptationLogic::LogicType type, stream_t *stream);
virtual ~DASHManager ();
int read( void *p_buffer, size_t len );
......@@ -56,6 +56,7 @@ namespace dash
logic::IAdaptationLogic::LogicType logicType;
mpd::IMPDManager *mpdManager;
mpd::MPD *mpd;
stream_t *stream;
};
}
......
......@@ -32,11 +32,13 @@ using namespace dash::xml;
using namespace dash::mpd;
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 ()
{
......
......@@ -35,6 +35,8 @@
#include "mpd/Segment.h"
#include "exceptions/EOFException.h"
struct stream_t;
namespace dash
{
namespace logic
......@@ -42,7 +44,7 @@ namespace dash
class AbstractAdaptationLogic : public IAdaptationLogic
{
public:
AbstractAdaptationLogic (dash::mpd::IMPDManager *mpdManager);
AbstractAdaptationLogic (dash::mpd::IMPDManager *mpdManager, stream_t *stream);
virtual ~AbstractAdaptationLogic ();
virtual void downloadRateChanged (long bpsAvg, long bpsLastChunk);
......@@ -54,6 +56,7 @@ namespace dash
int bpsAvg;
long bpsLastChunk;
dash::mpd::IMPDManager *mpdManager;
stream_t *stream;
};
}
}
......
......@@ -32,12 +32,12 @@ using namespace dash::xml;
using namespace dash::mpd;
IAdaptationLogic* AdaptationLogicFactory::create ( IAdaptationLogic::LogicType logic,
IMPDManager *mpdManager )
IMPDManager *mpdManager, stream_t *stream)
{
switch(logic)
{
case IAdaptationLogic::AlwaysBest: return new AlwaysBestAdaptationLogic (mpdManager);
case IAdaptationLogic::RateBased: return new RateBasedAdaptationLogic (mpdManager);
case IAdaptationLogic::AlwaysBest: return new AlwaysBestAdaptationLogic (mpdManager, stream);
case IAdaptationLogic::RateBased: return new RateBasedAdaptationLogic (mpdManager, stream);
case IAdaptationLogic::Default:
case IAdaptationLogic::AlwaysLowest:
default:
......
......@@ -31,6 +31,8 @@
#include "adaptationlogic/AlwaysBestAdaptationLogic.h"
#include "adaptationlogic/RateBasedAdaptationLogic.h"
struct stream_t;
namespace dash
{
namespace logic
......@@ -38,7 +40,7 @@ namespace dash
class AdaptationLogicFactory
{
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;
using namespace dash::mpd;
using namespace dash::exception;
AlwaysBestAdaptationLogic::AlwaysBestAdaptationLogic (IMPDManager *mpdManager) : AbstractAdaptationLogic(mpdManager)
AlwaysBestAdaptationLogic::AlwaysBestAdaptationLogic (IMPDManager *mpdManager, stream_t *stream) :
AbstractAdaptationLogic (mpdManager, stream)
{
this->mpdManager = mpdManager;
this->count = 0;
......
......@@ -42,7 +42,7 @@ namespace dash
class AlwaysBestAdaptationLogic : public AbstractAdaptationLogic
{
public:
AlwaysBestAdaptationLogic (dash::mpd::IMPDManager *mpdManager);
AlwaysBestAdaptationLogic (dash::mpd::IMPDManager *mpdManager, stream_t *stream);
virtual ~AlwaysBestAdaptationLogic ();
dash::http::Chunk* getNextChunk() throw(dash::exception::EOFException);
......
......@@ -33,12 +33,16 @@ using namespace dash::http;
using namespace dash::mpd;
using namespace dash::exception;
RateBasedAdaptationLogic::RateBasedAdaptationLogic (IMPDManager *mpdManager) :
AbstractAdaptationLogic( mpdManager ),
mpdManager( mpdManager ),
count( 0 ),
currentPeriod( mpdManager->getFirstPeriod() )
RateBasedAdaptationLogic::RateBasedAdaptationLogic (IMPDManager *mpdManager, stream_t *stream) :
AbstractAdaptationLogic (mpdManager, stream),
mpdManager (mpdManager),
count (0),
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)
......@@ -51,7 +55,7 @@ Chunk* RateBasedAdaptationLogic::getNextChunk() throw(EOFException)
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 )
throw EOFException();
......
......@@ -32,6 +32,9 @@
#include "exceptions/EOFException.h"
#include "mpd/BasicCMManager.h"
#include <vlc_common.h>
#include <vlc_stream.h>
namespace dash
{
namespace logic
......@@ -39,7 +42,7 @@ namespace dash
class RateBasedAdaptationLogic : public AbstractAdaptationLogic
{
public:
RateBasedAdaptationLogic (dash::mpd::IMPDManager *mpdManager);
RateBasedAdaptationLogic (dash::mpd::IMPDManager *mpdManager, stream_t *stream);
dash::http::Chunk* getNextChunk() throw(dash::exception::EOFException);
const dash::mpd::Representation *getCurrentRepresentation() const;
......@@ -48,6 +51,8 @@ namespace dash
dash::mpd::IMPDManager *mpdManager;
size_t count;
dash::mpd::Period *currentPeriod;
int width;
int height;
};
}
}
......
......@@ -48,12 +48,20 @@
static int Open (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 ()
set_shortname( N_("DASH"))
set_description( N_("Dynamic Adaptive Streaming over HTTP") )
set_capability( "stream_filter", 19 )
set_category( CAT_INPUT )
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 )
vlc_module_end ()
......@@ -106,7 +114,7 @@ static int Open(vlc_object_t *p_obj)
new dash::http::HTTPConnectionManager( p_stream );
dash::DASHManager*p_dashManager =
new dash::DASHManager( p_conManager, p_sys->p_mpd,
dash::logic::IAdaptationLogic::RateBased );
dash::logic::IAdaptationLogic::RateBased, p_stream);
if ( p_dashManager->getMpdManager() == NULL ||
p_dashManager->getMpdManager()->getMPD() == NULL ||
......
......@@ -91,7 +91,7 @@ Period* BasicCMManager::getFirstPeriod ()
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();
......@@ -134,4 +134,7 @@ const MPD* BasicCMManager::getMPD() const
{
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
Period* getNextPeriod( Period *period );
Representation* getBestRepresentation( Period *period );
std::vector<Segment *> getSegments( const Representation *rep );
Representation* getRepresentation( Period *period, int bitrate );
Representation* getRepresentation( Period *period, int bitrate ) const;
const MPD* getMPD() const;
Representation* getRepresentation (Period *period, int bitrate,
int width, int height) const;
private:
MPD *mpd;
......
......@@ -45,14 +45,17 @@ namespace dash
class IMPDManager
{
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 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 ()
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();
......@@ -126,3 +126,48 @@ const MPD* IsoffMainManager::getMPD () const
{
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
Period* getNextPeriod (Period *period);
Representation* getBestRepresentation (Period *period);
std::vector<Segment *> getSegments (const Representation *rep);
Representation* getRepresentation (Period *period, int bitrate);
Representation* getRepresentation (Period *period, int bitrate) const;
const MPD* getMPD () const;
Representation* getRepresentation (Period *period, int bitrate,
int width, int height) const;
private:
MPD *mpd;
......
......@@ -113,12 +113,21 @@ void IsoffMainParser::setRepresentations (Node *adaptationSetNode, Adaptation
for(size_t i = 0; i < representations.size(); i++)
{
Representation *rep = new Representation;
this->currentRepresentation = rep;
this->setSegmentBase(representations.at(i), rep);
this->setSegmentList(representations.at(i), rep);
rep->setBandwidth(atoi(representations.at(i)->getAttributeValue("bandwidth").c_str()));
adaptationSet->addRepresentation(rep);
this->currentRepresentation = new Representation;
Node *repNode = representations.at(i);
if(repNode->hasAttribute("width"))
this->currentRepresentation->setWidth(atoi(repNode->getAttributeValue("width").c_str()));
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)
......
......@@ -37,7 +37,9 @@ Representation::Representation () :
trickModeType ( NULL ),
parentGroup ( NULL ),
segmentBase ( NULL ),
segmentList ( NULL )
segmentList ( NULL ),
width (0),
height (0)
{
}
......@@ -139,3 +141,19 @@ void Representation::setSegmentBase (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
void setSegmentList (SegmentList *list);
SegmentBase* getSegmentBase () const;
void setSegmentBase (SegmentBase *base);
void setWidth (int width);
int getWidth () const;
void setHeight (int height);
int getHeight () const;
private:
int bandwidth;
......@@ -87,6 +91,8 @@ namespace dash
const Group *parentGroup;
SegmentBase *segmentBase;
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