Commit 422cceae authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: change rate based algorithm

Drops the current long term average to a moving
average/vertical horizontal filter with an
observation window of 250ms.
parent 8f114b49
...@@ -37,13 +37,18 @@ using namespace adaptative::logic; ...@@ -37,13 +37,18 @@ using namespace adaptative::logic;
RateBasedAdaptationLogic::RateBasedAdaptationLogic (vlc_object_t *p_obj_, int w, int h) : RateBasedAdaptationLogic::RateBasedAdaptationLogic (vlc_object_t *p_obj_, int w, int h) :
AbstractAdaptationLogic (), AbstractAdaptationLogic (),
bpsAvg(0), bpsRemainder(0), bpsSamplecount(0), bpsAvg(0),
currentBps(0) currentBps(0)
{ {
width = w; width = w;
height = h; height = h;
usedBps = 0; usedBps = 0;
dllength = 0;
p_obj = p_obj_; p_obj = p_obj_;
for(unsigned i=0; i<10; i++) window[i].bw = window[i].diff = 0;
window_idx = 0;
prevbps = 0;
dlsize = 0;
} }
BaseRepresentation *RateBasedAdaptationLogic::getNextRepresentation(BaseAdaptationSet *adaptSet, BaseRepresentation *currep) const BaseRepresentation *RateBasedAdaptationLogic::getNextRepresentation(BaseAdaptationSet *adaptSet, BaseRepresentation *currep) const
...@@ -71,26 +76,62 @@ BaseRepresentation *RateBasedAdaptationLogic::getNextRepresentation(BaseAdaptati ...@@ -71,26 +76,62 @@ BaseRepresentation *RateBasedAdaptationLogic::getNextRepresentation(BaseAdaptati
void RateBasedAdaptationLogic::updateDownloadRate(size_t size, mtime_t time) void RateBasedAdaptationLogic::updateDownloadRate(size_t size, mtime_t time)
{ {
if(unlikely(time == 0) || size < (HTTPChunkSource::CHUNK_SIZE>>1) ) if(unlikely(time == 0))
return; return;
/* Accumulate up to observation window */
dllength += time;
dlsize += size;
size_t current = bpsRemainder + CLOCK_FREQ * size * 8 / time; if(dllength < CLOCK_FREQ / 4)
return;
const size_t bps = CLOCK_FREQ * dlsize * 8 / dllength;
if (current >= bpsAvg) /* set window value */
if(window[0].bw == 0)
{ {
bpsAvg += (current - bpsAvg) / ++bpsSamplecount; for(unsigned i=0; i<TOTALOBS; i++) window[i].bw = bps;
bpsRemainder = (current - bpsAvg) % bpsSamplecount;
} }
else else
{ {
bpsAvg -= (bpsAvg - current) / ++bpsSamplecount; window_idx = (window_idx + 1) % TOTALOBS;
bpsRemainder = (bpsAvg - current) % bpsSamplecount; window[window_idx].bw = bps;
window[window_idx].diff = bps >= prevbps ? bps - prevbps : prevbps - bps;
}
/* compute for deltamax */
size_t diffsum = 0;
size_t omin = SIZE_MAX;
size_t omax = 0;
for(unsigned i=0; i < TOTALOBS; i++)
{
/* Find max and min */
if(window[i].bw > omax)
omax = window[i].bw;
if(window[i].bw < omin)
omin = window[i].bw;
diffsum += window[i].diff;
} }
/* Vertical Horizontal Filter / Moving Average
*
* Bandwith stability during observation window alters the alpha parameter
* and then defines how fast we adapt to current bandwidth */
const size_t deltamax = omax - omin;
double alpha = (diffsum) ? 0.33 * ((double)deltamax / diffsum) : 0.5;
bpsAvg = alpha * bpsAvg + (1.0 - alpha) * bps;
BwDebug(msg_Dbg(p_obj, "alpha1 %lf alpha0 %lf dmax %ld ds %ld", alpha,
(double)deltamax / diffsum, deltamax, diffsum));
BwDebug(msg_Dbg(p_obj, "bw estimation bps %zu -> avg %zu",
bps / 8192, bpsAvg / 8192));
currentBps = bpsAvg * 3/4; currentBps = bpsAvg * 3/4;
dlsize = dllength = 0;
prevbps = bps;
BwDebug(msg_Info(p_obj, "Current bandwidth %zu KiB/s using %u%%", BwDebug(msg_Info(p_obj, "Current bandwidth %zu KiB/s using %u%%",
(bpsAvg / 8192), (bpsAvg) ? (unsigned)(usedBps * 100.0 / bpsAvg) : 0 )); (bpsAvg / 8192), (bpsAvg) ? (unsigned)(usedBps * 100.0 / bpsAvg) : 0));
} }
void RateBasedAdaptationLogic::trackerEvent(const SegmentTrackerEvent &event) void RateBasedAdaptationLogic::trackerEvent(const SegmentTrackerEvent &event)
......
...@@ -45,11 +45,21 @@ namespace adaptative ...@@ -45,11 +45,21 @@ namespace adaptative
int width; int width;
int height; int height;
size_t bpsAvg; size_t bpsAvg;
size_t bpsRemainder;
size_t bpsSamplecount;
size_t currentBps; size_t currentBps;
size_t usedBps; size_t usedBps;
vlc_object_t * p_obj; vlc_object_t * p_obj;
static const unsigned TOTALOBS = 10;
struct
{
size_t bw;
size_t diff;
} window[TOTALOBS];
unsigned window_idx;
size_t prevbps;
size_t dlsize;
mtime_t dllength;
}; };
class FixedRateAdaptationLogic : public AbstractAdaptationLogic class FixedRateAdaptationLogic : public AbstractAdaptationLogic
......
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