[vlc-commits] demux: adaptative: add inertia to rate based logic

Francois Cartegnie git at videolan.org
Wed Jun 17 22:01:08 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jun 17 13:49:58 2015 +0200| [63506d5add8aafe2c6767dc37d014d14e71529b3] | committer: Francois Cartegnie

demux: adaptative: add inertia to rate based logic

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

 .../adaptative/logic/RateBasedAdaptationLogic.cpp  |   26 ++++++++++++++++----
 .../adaptative/logic/RateBasedAdaptationLogic.h    |    2 ++
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp
index 7394d63..98f139b 100644
--- a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp
+++ b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.cpp
@@ -21,6 +21,9 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
+#define __STDC_CONSTANT_MACROS
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -40,6 +43,8 @@ RateBasedAdaptationLogic::RateBasedAdaptationLogic  (int w, int h) :
 {
     width  = w;
     height = h;
+    cumulatedTime = 0;
+    stabilizer = 16;
 }
 
 BaseRepresentation *RateBasedAdaptationLogic::getCurrentRepresentation(StreamType type, BasePeriod *period) const
@@ -66,14 +71,25 @@ void RateBasedAdaptationLogic::updateDownloadRate(size_t size, mtime_t time)
     size_t current = size * 8000 / time;
 
     if (current >= bpsAvg)
-        bpsAvg = bpsAvg + (current - bpsAvg) / (bpsSamplecount + 1);
+        bpsAvg = bpsAvg + (current - bpsAvg) / ++bpsSamplecount;
     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;
+        currentBps = bpsAvg * 3/4;
+        cumulatedTime = 0;
+    }
 }
 
 FixedRateAdaptationLogic::FixedRateAdaptationLogic(size_t bps) :
diff --git a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h
index 82c89e9..76377f0 100644
--- a/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h
+++ b/modules/demux/adaptative/logic/RateBasedAdaptationLogic.h
@@ -48,6 +48,8 @@ namespace adaptative
                 size_t                  bpsAvg;
                 size_t                  bpsSamplecount;
                 size_t                  currentBps;
+                mtime_t                 cumulatedTime;
+                int                     stabilizer;
         };
 
         class FixedRateAdaptationLogic : public AbstractAdaptationLogic



More information about the vlc-commits mailing list