diff options
author | metamuffin <metamuffin@disroot.org> | 2024-05-14 00:24:58 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-05-14 00:24:58 +0200 |
commit | 8752a12e954600152e9eaa60ed29af585ed06c64 (patch) | |
tree | 700fedf7d82e940b256ca828e5c98bd1ce0ada44 /web/script/player/download.ts | |
parent | 07fc74f4d8fcd3137e3cdbc462c06c50acccb31e (diff) | |
download | jellything-8752a12e954600152e9eaa60ed29af585ed06c64.tar jellything-8752a12e954600152e9eaa60ed29af585ed06c64.tar.bz2 jellything-8752a12e954600152e9eaa60ed29af585ed06c64.tar.zst |
better jsp debuggability
Diffstat (limited to 'web/script/player/download.ts')
-rw-r--r-- | web/script/player/download.ts | 10 |
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 } } |