[vlc-commits] demux: adptative: add missing remainder doing stats

Francois Cartegnie git at videolan.org
Sat Jul 25 22:30:44 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Jul 24 17:57:28 2015 +0200| [ee31841e38873574b714618812f5a9ac5ce6514f] | committer: Francois Cartegnie

demux: adptative: add missing remainder doing stats

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ee31841e38873574b714618812f5a9ac5ce6514f
---

 .../demux/adaptative/logic/RateBasedAdaptationLogic.cpp  |   14 ++++++++++----
 .../demux/adaptative/logic/RateBasedAdaptationLogic.h    |    1 +
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp
index 9914c9d..e6c0e72 100644
--- a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp
+++ b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp
@@ -38,7 +38,7 @@ using namespace adaptative::logic;
 
 RateBasedAdaptationLogic::RateBasedAdaptationLogic  (int w, int h) :
                           AbstractAdaptationLogic   (),
-                          bpsAvg(0), bpsSamplecount(0),
+                          bpsAvg(0), bpsRemainder(0), bpsSamplecount(0),
                           currentBps(0)
 {
     width  = w;
@@ -68,12 +68,18 @@ void RateBasedAdaptationLogic::updateDownloadRate(size_t size, mtime_t time)
     if(unlikely(time == 0))
         return;
 
-    size_t current = size * 8000 / time;
+    size_t current = bpsRemainder + size * 8000 / time;
 
     if (current >= bpsAvg)
-        bpsAvg = bpsAvg + (current - bpsAvg) / ++bpsSamplecount;
+    {
+        bpsAvg += (current - bpsAvg) / ++bpsSamplecount;
+        bpsRemainder = (current - bpsAvg) % bpsSamplecount;
+    }
     else
-        bpsAvg = bpsAvg - (bpsAvg - current) / ++bpsSamplecount;
+    {
+        bpsAvg -= (bpsAvg - current) / ++bpsSamplecount;
+        bpsRemainder = (bpsAvg - current) % bpsSamplecount;
+    }
 
     cumulatedTime += time;
     if(cumulatedTime > 4 * CLOCK_FREQ / stabilizer)
diff --git a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h
index 854375e..3018a59 100644
--- a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h
+++ b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h
@@ -46,6 +46,7 @@ namespace adaptative
                 int                     width;
                 int                     height;
                 size_t                  bpsAvg;
+                size_t                  bpsRemainder;
                 size_t                  bpsSamplecount;
                 size_t                  currentBps;
                 mtime_t                 cumulatedTime;



More information about the vlc-commits mailing list