@svta/common-media-library
Version:
A common library for media playback in JavaScript
34 lines • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZlemaEstimator = void 0;
const getBandwidthBps_js_1 = require("../utils/getBandwidthBps.js");
/**
* Zero-Lag Exponential Moving Average (ZLEMA) throughput estimator
*
* @group Throughput
*
* @beta
*/
class ZlemaEstimator {
constructor() {
this.samples = [];
}
sample(sample) {
this.samples.push(sample);
}
getEstimate() {
if (this.samples.length === 0) {
return NaN;
}
const alpha = 2 / (this.samples.length + 1);
let ema, zlema;
ema = zlema = (0, getBandwidthBps_js_1.getBandwidthBps)(this.samples[this.samples.length - 1]);
for (let i = 0; i < this.samples.length; i++) {
ema = alpha * (0, getBandwidthBps_js_1.getBandwidthBps)(this.samples[i]) + (1 - alpha) * ema;
zlema = alpha * ema + (1 - alpha) * zlema;
}
return zlema;
}
}
exports.ZlemaEstimator = ZlemaEstimator;
//# sourceMappingURL=ZlemaEstimator.js.map