Commit 4497a587 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: account and split bandwidth usage

parent 62cbf970
......@@ -60,6 +60,7 @@ SegmentTracker::~SegmentTracker()
void SegmentTracker::setAdaptationLogic(AbstractAdaptationLogic *logic_)
{
logic = logic_;
registerListener(logic);
}
void SegmentTracker::reset()
......
......@@ -26,6 +26,7 @@
#define ABSTRACTADAPTATIONLOGIC_H_
#include "IDownloadRateObserver.h"
#include "../SegmentTracker.hpp"
namespace adaptative
{
......@@ -39,14 +40,16 @@ namespace adaptative
{
using namespace playlist;
class AbstractAdaptationLogic : public IDownloadRateObserver
class AbstractAdaptationLogic : public IDownloadRateObserver,
public SegmentTrackerListenerInterface
{
public:
AbstractAdaptationLogic ();
virtual ~AbstractAdaptationLogic ();
virtual BaseRepresentation* getCurrentRepresentation(BaseAdaptationSet *) const = 0;
virtual BaseRepresentation* getNextRepresentation(BaseAdaptationSet *, BaseRepresentation *) const = 0;
virtual void updateDownloadRate (size_t, mtime_t);
virtual void trackerEvent (const SegmentTrackerEvent &) {}
enum LogicType
{
......
......@@ -36,7 +36,7 @@ AlwaysBestAdaptationLogic::AlwaysBestAdaptationLogic () :
{
}
BaseRepresentation *AlwaysBestAdaptationLogic::getCurrentRepresentation(BaseAdaptationSet *adaptSet) const
BaseRepresentation *AlwaysBestAdaptationLogic::getNextRepresentation(BaseAdaptationSet *adaptSet, BaseRepresentation *) const
{
RepresentationSelector selector;
return selector.select(adaptSet);
......
......@@ -36,7 +36,7 @@ namespace adaptative
public:
AlwaysBestAdaptationLogic ();
virtual BaseRepresentation *getCurrentRepresentation(BaseAdaptationSet *) const;
virtual BaseRepresentation *getNextRepresentation(BaseAdaptationSet *, BaseRepresentation *) const;
};
}
}
......
......@@ -28,7 +28,7 @@ AlwaysLowestAdaptationLogic::AlwaysLowestAdaptationLogic():
{
}
BaseRepresentation *AlwaysLowestAdaptationLogic::getCurrentRepresentation(BaseAdaptationSet *adaptSet) const
BaseRepresentation *AlwaysLowestAdaptationLogic::getNextRepresentation(BaseAdaptationSet *adaptSet, BaseRepresentation *) const
{
RepresentationSelector selector;
return selector.select(adaptSet, 0);
......
......@@ -31,7 +31,7 @@ namespace adaptative
public:
AlwaysLowestAdaptationLogic();
virtual BaseRepresentation* getCurrentRepresentation(BaseAdaptationSet *) const;
virtual BaseRepresentation* getNextRepresentation(BaseAdaptationSet *, BaseRepresentation *) const;
};
}
}
......
......@@ -40,15 +40,22 @@ RateBasedAdaptationLogic::RateBasedAdaptationLogic (int w, int h) :
{
width = w;
height = h;
usedBps = 0;
}
BaseRepresentation *RateBasedAdaptationLogic::getCurrentRepresentation(BaseAdaptationSet *adaptSet) const
BaseRepresentation *RateBasedAdaptationLogic::getNextRepresentation(BaseAdaptationSet *adaptSet, BaseRepresentation *currep) const
{
if(adaptSet == NULL)
return NULL;
size_t availBps = currentBps + ((currep) ? currep->getBandwidth() : 0);
if(availBps > usedBps)
availBps -= usedBps;
else
availBps = 0;
RepresentationSelector selector;
BaseRepresentation *rep = selector.select(adaptSet, currentBps, width, height);
BaseRepresentation *rep = selector.select(adaptSet, availBps, width, height);
if ( rep == NULL )
{
rep = selector.select(adaptSet);
......@@ -79,13 +86,24 @@ void RateBasedAdaptationLogic::updateDownloadRate(size_t size, mtime_t time)
currentBps = bpsAvg * 3/4;
}
void RateBasedAdaptationLogic::trackerEvent(const SegmentTrackerEvent &event)
{
if(event.type == SegmentTrackerEvent::SWITCHING)
{
if(event.u.switching.prev)
usedBps -= event.u.switching.prev->getBandwidth();
if(event.u.switching.next)
usedBps += event.u.switching.next->getBandwidth();
}
}
FixedRateAdaptationLogic::FixedRateAdaptationLogic(size_t bps) :
AbstractAdaptationLogic()
{
currentBps = bps;
}
BaseRepresentation *FixedRateAdaptationLogic::getCurrentRepresentation(BaseAdaptationSet *adaptSet) const
BaseRepresentation *FixedRateAdaptationLogic::getNextRepresentation(BaseAdaptationSet *adaptSet, BaseRepresentation *) const
{
if(adaptSet == NULL)
return NULL;
......
......@@ -39,8 +39,9 @@ namespace adaptative
public:
RateBasedAdaptationLogic (int, int);
BaseRepresentation *getCurrentRepresentation(BaseAdaptationSet *) const;
virtual void updateDownloadRate(size_t, mtime_t);
BaseRepresentation *getNextRepresentation(BaseAdaptationSet *, BaseRepresentation *) const;
virtual void updateDownloadRate(size_t, mtime_t); /* reimpl */
virtual void trackerEvent(const SegmentTrackerEvent &); /* reimpl */
private:
int width;
......@@ -49,6 +50,7 @@ namespace adaptative
size_t bpsRemainder;
size_t bpsSamplecount;
size_t currentBps;
size_t usedBps;
};
class FixedRateAdaptationLogic : public AbstractAdaptationLogic
......@@ -56,7 +58,7 @@ namespace adaptative
public:
FixedRateAdaptationLogic(size_t);
BaseRepresentation *getCurrentRepresentation(BaseAdaptationSet *) const;
BaseRepresentation *getNextRepresentation(BaseAdaptationSet *, BaseRepresentation *) const;
private:
size_t currentBps;
......
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