Commit 4497a587 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: account and split bandwidth usage

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