Skip to content

Commit

Permalink
Merge pull request #521 from nhjm449/ewma-undefined-fix-2
Browse files Browse the repository at this point in the history
EwmaBandWidthEstimator undefined object fix #2
  • Loading branch information
mangui committed Jun 24, 2016
2 parents 878b91d + db47fd1 commit 91c001d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
20 changes: 15 additions & 5 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,36 +477,46 @@ parameter should be a boolean
#### ```abrEwmaFastLive```
(default : 5.0)
Fast bitrate Exponential moving average half-life , used to compute average bitrate for Live streams
Fast bitrate Exponential moving average half-life, used to compute average bitrate for Live streams
Half of the estimate is based on the last abrEwmaFastLive seconds of sample history.
Each of the sample is weighted by the fragment loading duration.
parameter should be a float greater than 0
#### ```abrEwmaSlowLive```
(default : 9.0)
Slow bitrate Exponential moving average half-life , used to compute average bitrate for Live streams
Slow bitrate Exponential moving average half-life, used to compute average bitrate for Live streams
Half of the estimate is based on the last abrEwmaSlowLive seconds of sample history.
Each of the sample is weighted by the fragment loading duration.
parameter should be a float greater than abrEwmaFastLive
parameter should be a float greater than abrEwmaFastLive
#### ```abrEwmaFastVoD```
(default : 4.0)
Fast bitrate Exponential moving average half-life , used to compute average bitrate for VoD streams
Fast bitrate Exponential moving average half-life, used to compute average bitrate for VoD streams
Half of the estimate is based on the last abrEwmaFastVoD seconds of sample history.
Each of the sample is weighted by the fragment loading duration.
parameter should be a float greater than 0
#### ```abrEwmaSlowVoD```
(default : 15.0)
Slow bitrate Exponential moving average half-life , used to compute average bitrate for VoD streams
Slow bitrate Exponential moving average half-life, used to compute average bitrate for VoD streams
Half of the estimate is based on the last abrEwmaSlowVoD seconds of sample history.
Each of the sample is weighted by the fragment loading duration.
parameter should be a float greater than abrEwmaFastVoD
#### ```abrEwmaDefaultEstimate```
(default : 500000)
Default bandwidth estimate in bits/second prior to collecting fragment bandwidth samples.
parameter should be a float
#### ```abrBandWidthFactor```
(default : 0.8)
Expand Down
2 changes: 1 addition & 1 deletion design.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ design idea is pretty simple :

- [src/controller/abr-controller.js][]
- in charge of determining auto quality level.
- auto quality switch algorithm is bitrate based : fragment loading bitrate is monitored and smoothed using 2 exponential weighted moving average (a fast one, to adapt quickly on bandwidth drop and a slow one, to avoid ramping up to quickly on bandwidth increase)
- auto quality switch algorithm is bitrate based : fragment loading bitrate is monitored and smoothed using 2 exponential weighted moving average (a fast one, to adapt quickly on bandwidth drop and a slow one, to avoid ramping up too quickly on bandwidth increase)
- in charge of **monitoring fragment loading speed** (by monitoring data received from FRAG_LOAD_PROGRESS event)
- "expected time of fragment load completion" is computed using "fragment loading instant bandwidth".
- this time is compared to the "expected time of buffer starvation".
Expand Down
5 changes: 3 additions & 2 deletions src/controller/abr-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AbrController extends EventHandler {
ewmaFast = config.abrEwmaFastVoD;
ewmaSlow = config.abrEwmaSlowVoD;
}
this.bwEstimator = new EwmaBandWidthEstimator(hls,ewmaSlow,ewmaFast);
this.bwEstimator = new EwmaBandWidthEstimator(hls,ewmaSlow,ewmaFast,config.abrEwmaDefaultEstimate);
}

let frag = data.frag;
Expand Down Expand Up @@ -184,7 +184,8 @@ class AbrController extends EventHandler {
return Math.min(this._nextAutoLevel,maxAutoLevel);
}

let avgbw = this.bwEstimator.getEstimate(),adjustedbw;
let avgbw = this.bwEstimator ? this.bwEstimator.getEstimate() : config.abrEwmaDefaultEstimate,
adjustedbw;
// follow algorithm captured from stagefright :
// https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/httplive/LiveSession.cpp
// Pick the highest bandwidth stream below or equal to estimated bandwidth.
Expand Down
6 changes: 3 additions & 3 deletions src/controller/ewma-bandwidth-estimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import EWMA from '../utils/ewma';

class EwmaBandWidthEstimator {

constructor(hls,slow,fast) {
constructor(hls,slow,fast,defaultEstimate) {
this.hls = hls;
this.defaultEstimate_ = 5e5; // 500kbps
this.defaultEstimate_ = defaultEstimate;
this.minWeight_ = 0.001;
this.minDelayMs_ = 50;
this.slow_ = new EWMA(slow);
Expand All @@ -32,7 +32,7 @@ class EwmaBandWidthEstimator {


getEstimate() {
if (!this.fast_ || this.fast_.getTotalWeight() < this.minWeight_) {
if (!this.fast_ || !this.slow_ || this.fast_.getTotalWeight() < this.minWeight_) {
return this.defaultEstimate_;
}
//console.log('slow estimate:'+ Math.round(this.slow_.getEstimate()));
Expand Down
1 change: 1 addition & 0 deletions src/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Hls {
abrEwmaSlowLive: 9,
abrEwmaFastVoD: 4,
abrEwmaSlowVoD: 15,
abrEwmaDefaultEstimate: 5e5, // 500 kbps
abrBandWidthFactor : 0.8,
abrBandWidthUpFactor : 0.7
};
Expand Down

0 comments on commit 91c001d

Please sign in to comment.