Commit 63506d5a authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: add inertia to rate based logic

parent bbf89a9f
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
* along with this program; if not, write to the Free Software Foundation, * along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#define __STDC_CONSTANT_MACROS
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
...@@ -40,6 +43,8 @@ RateBasedAdaptationLogic::RateBasedAdaptationLogic (int w, int h) : ...@@ -40,6 +43,8 @@ RateBasedAdaptationLogic::RateBasedAdaptationLogic (int w, int h) :
{ {
width = w; width = w;
height = h; height = h;
cumulatedTime = 0;
stabilizer = 16;
} }
BaseRepresentation *RateBasedAdaptationLogic::getCurrentRepresentation(StreamType type, BasePeriod *period) const BaseRepresentation *RateBasedAdaptationLogic::getCurrentRepresentation(StreamType type, BasePeriod *period) const
...@@ -66,14 +71,25 @@ void RateBasedAdaptationLogic::updateDownloadRate(size_t size, mtime_t time) ...@@ -66,14 +71,25 @@ void RateBasedAdaptationLogic::updateDownloadRate(size_t size, mtime_t time)
size_t current = size * 8000 / time; size_t current = size * 8000 / time;
if (current >= bpsAvg) if (current >= bpsAvg)
bpsAvg = bpsAvg + (current - bpsAvg) / (bpsSamplecount + 1); bpsAvg = bpsAvg + (current - bpsAvg) / ++bpsSamplecount;
else else
bpsAvg = bpsAvg - (bpsAvg - current) / (bpsSamplecount + 1); bpsAvg = bpsAvg - (bpsAvg - current) / ++bpsSamplecount;
bpsSamplecount++; cumulatedTime += time;
if(cumulatedTime > 4 * CLOCK_FREQ / stabilizer)
{
if( currentBps <= bpsAvg * 3/4 && stabilizer < 16 )
{
stabilizer++;
}
else if( currentBps > bpsAvg * 3/4 && stabilizer > 1 )
{
stabilizer /= 2;
}
if(bpsSamplecount % 5 == 0) currentBps = bpsAvg * 3/4;
currentBps = bpsAvg; cumulatedTime = 0;
}
} }
FixedRateAdaptationLogic::FixedRateAdaptationLogic(size_t bps) : FixedRateAdaptationLogic::FixedRateAdaptationLogic(size_t bps) :
......
...@@ -48,6 +48,8 @@ namespace adaptative ...@@ -48,6 +48,8 @@ namespace adaptative
size_t bpsAvg; size_t bpsAvg;
size_t bpsSamplecount; size_t bpsSamplecount;
size_t currentBps; size_t currentBps;
mtime_t cumulatedTime;
int stabilizer;
}; };
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