Commit 3eb5817a authored by Francois Cartegnie's avatar Francois Cartegnie

stream_filter: dash: refactor adaptation logic classes

and clean useless includes
parent 9df6750e
......@@ -28,11 +28,13 @@
#include "AbstractAdaptationLogic.h"
using namespace dash::logic;
using namespace dash::xml;
using namespace dash::mpd;
using namespace dash::http;
AbstractAdaptationLogic::AbstractAdaptationLogic (MPD *mpd_) :
mpd (mpd_),
currentPeriod (mpd->getFirstPeriod()),
count (0),
bpsAvg (0),
bpsLastChunk (0),
bufferedMicroSec (0),
......@@ -44,6 +46,36 @@ AbstractAdaptationLogic::~AbstractAdaptationLogic ()
{
}
Chunk* AbstractAdaptationLogic::getNextChunk(Streams::Type type)
{
if(!currentPeriod)
return NULL;
const Representation *rep = getCurrentRepresentation(type);
if ( rep == NULL )
return NULL;
std::vector<ISegment *> segments = rep->getSegments();
if ( count == segments.size() )
{
currentPeriod = mpd->getNextPeriod(currentPeriod);
count = 0;
return getNextChunk(type);
}
if ( segments.size() > count )
{
ISegment *seg = segments.at( count );
Chunk *chunk = seg->toChunk();
//In case of UrlTemplate, we must stay on the same segment.
if ( seg->isSingleShot() == true )
count++;
seg->done();
return chunk;
}
return NULL;
}
void AbstractAdaptationLogic::bufferLevelChanged (mtime_t bufferedMicroSec, int bufferedPercent)
{
this->bufferedMicroSec = bufferedMicroSec;
......
......@@ -26,12 +26,10 @@
#define ABSTRACTADAPTATIONLOGIC_H_
#include "adaptationlogic/IAdaptationLogic.h"
#include "xml/Node.h"
#include "http/Chunk.h"
#include "mpd/MPD.h"
#include "mpd/Period.h"
#include "mpd/Representation.h"
#include "mpd/Segment.h"
struct stream_t;
......@@ -45,6 +43,8 @@ namespace dash
AbstractAdaptationLogic (mpd::MPD *mpd);
virtual ~AbstractAdaptationLogic ();
virtual dash::http::Chunk* getNextChunk (Streams::Type);
virtual void downloadRateChanged (uint64_t bpsAvg, uint64_t bpsLastChunk);
virtual void bufferLevelChanged (mtime_t bufferedMicroSec, int bufferedPercent);
......@@ -54,6 +54,8 @@ namespace dash
protected:
dash::mpd::MPD *mpd;
dash::mpd::Period *currentPeriod;
size_t count;
private:
int bpsAvg;
......
......@@ -31,7 +31,6 @@
#include "adaptationlogic/AlwaysLowestAdaptationLogic.hpp"
using namespace dash::logic;
using namespace dash::xml;
using namespace dash::mpd;
IAdaptationLogic* AdaptationLogicFactory::create ( IAdaptationLogic::LogicType logic,
......
......@@ -26,7 +26,6 @@
#define ADAPTATIONLOGICFACTORY_H_
#include "adaptationlogic/IAdaptationLogic.h"
#include "xml/Node.h"
struct stream_t;
......
......@@ -26,65 +26,18 @@
#endif
#include "AlwaysBestAdaptationLogic.h"
#include "Representationselectors.hpp"
using namespace dash::logic;
using namespace dash::xml;
using namespace dash::http;
using namespace dash::mpd;
AlwaysBestAdaptationLogic::AlwaysBestAdaptationLogic (MPD *mpd) :
AbstractAdaptationLogic (mpd)
{
initSchedule();
}
AlwaysBestAdaptationLogic::~AlwaysBestAdaptationLogic ()
{
}
Chunk* AlwaysBestAdaptationLogic::getNextChunk(Streams::Type type)
{
if ( streams[type].count < streams[type].schedule.size() )
{
Chunk *chunk = new Chunk();
chunk->setUrl(streams[type].schedule.at( streams[type].count )->getUrlSegment());
streams[type].count++;
return chunk;
}
return NULL;
}
const Representation *AlwaysBestAdaptationLogic::getCurrentRepresentation(Streams::Type type) const
{
if ( streams[type].count < streams[type].schedule.size() )
return streams[type].schedule.at( streams[type].count )->getRepresentation();
return NULL;
}
void AlwaysBestAdaptationLogic::initSchedule ()
{
if(mpd)
{
std::vector<Period *> periods = mpd->getPeriods();
if (periods.empty())
return;
RepresentationSelector selector;
for(int type=0; type<Streams::count; type++)
{
streams[type].count = 0;
Representation *best = selector.select(periods.front(),
static_cast<Streams::Type>(type));
if(best)
{
std::vector<ISegment *> segments = best->getSegments();
std::vector<ISegment *>::const_iterator segIt;
for(segIt=segments.begin(); segIt!=segments.end(); segIt++)
{
streams[type].schedule.push_back(*segIt);
}
}
}
}
RepresentationSelector selector;
return selector.select(currentPeriod, type);
}
......@@ -26,13 +26,6 @@
#define ALWAYSBESTADAPTATIONLOGIC_H_
#include "adaptationlogic/AbstractAdaptationLogic.h"
#include "Representationselectors.hpp"
#include "http/Chunk.h"
#include "xml/Node.h"
#include "mpd/Period.h"
#include "mpd/Segment.h"
#include "Streams.hpp"
#include <vector>
namespace dash
{
......@@ -42,19 +35,8 @@ namespace dash
{
public:
AlwaysBestAdaptationLogic (mpd::MPD *mpd);
virtual ~AlwaysBestAdaptationLogic ();
virtual dash::http::Chunk* getNextChunk(Streams::Type);
const mpd::Representation *getCurrentRepresentation(Streams::Type) const;
private:
struct
{
std::vector<mpd::ISegment *> schedule;
size_t count;
mpd::Representation *bestRepresentation;
} streams[Streams::count];
void initSchedule ();
virtual const mpd::Representation *getCurrentRepresentation(Streams::Type) const;
};
}
}
......
......@@ -21,46 +21,13 @@
#include "Representationselectors.hpp"
using namespace dash::logic;
using namespace dash::http;
using namespace dash::mpd;
AlwaysLowestAdaptationLogic::AlwaysLowestAdaptationLogic(mpd::MPD *mpd):
AbstractAdaptationLogic(mpd),
currentPeriod(mpd->getFirstPeriod()),
count(0)
AbstractAdaptationLogic(mpd)
{
}
Chunk* AlwaysLowestAdaptationLogic::getNextChunk(Streams::Type type)
{
if(!currentPeriod)
return NULL;
const Representation *rep = getCurrentRepresentation(type);
if ( rep == NULL )
return NULL;
std::vector<ISegment *> segments = rep->getSegments();
if ( count == segments.size() )
{
currentPeriod = mpd->getNextPeriod(currentPeriod);
count = 0;
return getNextChunk(type);
}
if ( segments.size() > count )
{
ISegment *seg = segments.at( count );
Chunk *chunk = seg->toChunk();
//In case of UrlTemplate, we must stay on the same segment.
if ( seg->isSingleShot() == true )
count++;
seg->done();
return chunk;
}
return NULL;
}
const Representation *AlwaysLowestAdaptationLogic::getCurrentRepresentation(Streams::Type type) const
{
RepresentationSelector selector;
......
......@@ -31,12 +31,7 @@ namespace dash
public:
AlwaysLowestAdaptationLogic(mpd::MPD *mpd);
virtual dash::http::Chunk* getNextChunk (Streams::Type);
virtual const dash::mpd::Representation* getCurrentRepresentation(Streams::Type) const;
private:
dash::mpd::Period *currentPeriod;
size_t count;
};
}
}
......
......@@ -32,50 +32,15 @@
#include <vlc_variables.h>
using namespace dash::logic;
using namespace dash::xml;
using namespace dash::http;
using namespace dash::mpd;
RateBasedAdaptationLogic::RateBasedAdaptationLogic (MPD *mpd) :
AbstractAdaptationLogic (mpd),
count (0),
currentPeriod (mpd->getFirstPeriod())
AbstractAdaptationLogic (mpd)
{
width = var_InheritInteger(mpd->getVLCObject(), "dash-prefwidth");
height = var_InheritInteger(mpd->getVLCObject(), "dash-prefheight");
}
Chunk* RateBasedAdaptationLogic::getNextChunk(Streams::Type type)
{
if(this->currentPeriod == NULL)
return NULL;
const Representation *rep = getCurrentRepresentation(type);
if (!rep)
return NULL;
std::vector<ISegment *> segments = rep->getSegments();
if ( this->count == segments.size() )
{
currentPeriod = mpd->getNextPeriod(currentPeriod);
this->count = 0;
return getNextChunk(type);
}
if ( segments.size() > this->count )
{
ISegment *seg = segments.at( this->count );
Chunk *chunk = seg->toChunk();
//In case of UrlTemplate, we must stay on the same segment.
if ( seg->isSingleShot() == true )
this->count++;
seg->done();
return chunk;
}
return NULL;
}
const Representation *RateBasedAdaptationLogic::getCurrentRepresentation(Streams::Type type) const
{
if(currentPeriod == NULL)
......
......@@ -26,8 +26,6 @@
#define RATEBASEDADAPTATIONLOGIC_H_
#include "adaptationlogic/AbstractAdaptationLogic.h"
#include "xml/Node.h"
#include "http/Chunk.h"
#define MINBUFFER 30
......@@ -40,12 +38,9 @@ namespace dash
public:
RateBasedAdaptationLogic (mpd::MPD *mpd);
virtual dash::http::Chunk* getNextChunk(Streams::Type);
const dash::mpd::Representation *getCurrentRepresentation(Streams::Type) const;
private:
size_t count;
dash::mpd::Period *currentPeriod;
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