aboutsummaryrefslogtreecommitdiff
path: root/web/script/player/download.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/script/player/download.ts')
-rw-r--r--web/script/player/download.ts10
1 files changed, 7 insertions, 3 deletions
diff --git a/web/script/player/download.ts b/web/script/player/download.ts
index e394ba3..fa3bf1b 100644
--- a/web/script/player/download.ts
+++ b/web/script/player/download.ts
@@ -10,7 +10,9 @@ interface Measurement { time: number, duration: number, size: number }
export class SegmentDownloader {
private measurements: Measurement[] = []
- public bandwidth = new OVar(Infinity)
+ public bandwidth_avail = new OVar(Infinity)
+ public bandwidth_used = new OVar(Infinity)
+ public total_downloaded = new OVar(0)
constructor() { }
@@ -22,6 +24,7 @@ export class SegmentDownloader {
const buf = await res.arrayBuffer()
const dl_body = performance.now();
+ this.total_downloaded.value += buf.byteLength
if (buf.byteLength > 100 * 1000) {
const m = {
time: dl_start,
@@ -37,9 +40,10 @@ export class SegmentDownloader {
update_bandwidth() {
while (this.measurements.length > 32)
this.measurements.splice(0, 1)
+ const total_elapsed = (performance.now() - this.measurements.reduce((a, v) => Math.min(a, v.time), 0)) / 1000;
const total_size = this.measurements.reduce((a, v) => v.size + a, 0)
const total_duration = this.measurements.reduce((a, v) => v.duration + a, 0)
- const average = total_size / total_duration
- this.bandwidth.value = average
+ this.bandwidth_avail.value = total_size / total_duration
+ this.bandwidth_used.value = total_size / total_elapsed
}
}