[vlc-commits] demux: adaptative: account and split bandwidth usage
Francois Cartegnie
git at videolan.org
Mon Nov 9 11:04:51 CET 2015
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Nov 7 20:57:14 2015 +0100| [4497a587c5039edec5905b14aff5b2369dded159] | committer: Francois Cartegnie
demux: adaptative: account and split bandwidth usage
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4497a587c5039edec5905b14aff5b2369dded159
---
modules/demux/adaptative/SegmentTracker.cpp | 1 +
.../adaptative/logic/AbstractAdaptationLogic.h | 7 ++++--
.../adaptative/logic/AlwaysBestAdaptationLogic.cpp | 2 +-
.../adaptative/logic/AlwaysBestAdaptationLogic.h | 2 +-
.../logic/AlwaysLowestAdaptationLogic.cpp | 2 +-
.../logic/AlwaysLowestAdaptationLogic.hpp | 2 +-
.../adaptative/logic/RateBasedAdaptationLogic.cpp | 24 +++++++++++++++++---
.../adaptative/logic/RateBasedAdaptationLogic.h | 8 ++++---
8 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/modules/demux/adaptative/SegmentTracker.cpp b/modules/demux/adaptative/SegmentTracker.cpp
index 9ef9968..07717f1 100644
--- a/modules/demux/adaptative/SegmentTracker.cpp
+++ b/modules/demux/adaptative/SegmentTracker.cpp
@@ -60,6 +60,7 @@ SegmentTracker::~SegmentTracker()
void SegmentTracker::setAdaptationLogic(AbstractAdaptationLogic *logic_)
{
logic = logic_;
+ registerListener(logic);
}
void SegmentTracker::reset()
diff --git a/modules/demux/adaptative/logic/AbstractAdaptationLogic.h b/modules/demux/adaptative/logic/AbstractAdaptationLogic.h
index cfa0fc1..a456a3d 100644
--- a/modules/demux/adaptative/logic/AbstractAdaptationLogic.h
+++ b/modules/demux/adaptative/logic/AbstractAdaptationLogic.h
@@ -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
{
diff --git a/modules/demux/adaptative/logic/AlwaysBestAdaptationLogic.cpp b/modules/demux/adaptative/logic/AlwaysBestAdaptationLogic.cpp
index d22fa05..bc43a4d 100644
--- a/modules/demux/adaptative/logic/AlwaysBestAdaptationLogic.cpp
+++ b/modules/demux/adaptative/logic/AlwaysBestAdaptationLogic.cpp
@@ -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);
diff --git a/modules/demux/adaptative/logic/AlwaysBestAdaptationLogic.h b/modules/demux/adaptative/logic/AlwaysBestAdaptationLogic.h
index f7e22ab..4495946 100644
--- a/modules/demux/adaptative/logic/AlwaysBestAdaptationLogic.h
+++ b/modules/demux/adaptative/logic/AlwaysBestAdaptationLogic.h
@@ -36,7 +36,7 @@ namespace adaptative
public:
AlwaysBestAdaptationLogic ();
- virtual BaseRepresentation *getCurrentRepresentation(BaseAdaptationSet *) const;
+ virtual BaseRepresentation *getNextRepresentation(BaseAdaptationSet *, BaseRepresentation *) const;
};
}
}
diff --git a/modules/demux/adaptative/logic/AlwaysLowestAdaptationLogic.cpp b/modules/demux/adaptative/logic/AlwaysLowestAdaptationLogic.cpp
index b0cc609..38bb821 100644
--- a/modules/demux/adaptative/logic/AlwaysLowestAdaptationLogic.cpp
+++ b/modules/demux/adaptative/logic/AlwaysLowestAdaptationLogic.cpp
@@ -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);
diff --git a/modules/demux/adaptative/logic/AlwaysLowestAdaptationLogic.hpp b/modules/demux/adaptative/logic/AlwaysLowestAdaptationLogic.hpp
index 38b0d0c..4876d2d 100644
--- a/modules/demux/adaptative/logic/AlwaysLowestAdaptationLogic.hpp
+++ b/modules/demux/adaptative/logic/AlwaysLowestAdaptationLogic.hpp
@@ -31,7 +31,7 @@ namespace adaptative
public:
AlwaysLowestAdaptationLogic();
- virtual BaseRepresentation* getCurrentRepresentation(BaseAdaptationSet *) const;
+ virtual BaseRepresentation* getNextRepresentation(BaseAdaptationSet *, BaseRepresentation *) const;
};
}
}
diff --git a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp
index a936f95..0f71559 100644
--- a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp
+++ b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp
@@ -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;
diff --git a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h
index 9fa1385..166db2f 100644
--- a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h
+++ b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h
@@ -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;
More information about the vlc-commits
mailing list