From f2bf7651e76fe503dc644947e896c2ec4b5663fc Mon Sep 17 00:00:00 2001 From: Andriy Lysnevych Date: Wed, 10 Jan 2024 15:40:35 +0200 Subject: [PATCH] Rename methods --- .../src/bandwidth-calculator.ts | 22 +++++++++---------- .../src/hybrid-loader.ts | 22 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/p2p-media-loader-core/src/bandwidth-calculator.ts b/packages/p2p-media-loader-core/src/bandwidth-calculator.ts index 35129d1b..c8cc5e54 100644 --- a/packages/p2p-media-loader-core/src/bandwidth-calculator.ts +++ b/packages/p2p-media-loader-core/src/bandwidth-calculator.ts @@ -1,7 +1,7 @@ export class BandwidthCalculator { private simultaneousLoadingsCount = 0; private readonly bytes: number[] = []; - private readonly shiftedTimestamps: number[] = []; + private readonly loadingOnlyTimestamps: number[] = []; private readonly timestamps: number[] = []; private noLoadingsTotalTime = 0; private allLoadingsStoppedTimestamp = 0; @@ -10,7 +10,7 @@ export class BandwidthCalculator { addBytes(bytesLength: number, now = performance.now()) { this.bytes.push(bytesLength); - this.shiftedTimestamps.push(now - this.noLoadingsTotalTime); + this.loadingOnlyTimestamps.push(now - this.noLoadingsTotalTime); this.timestamps.push(now); } @@ -30,20 +30,20 @@ export class BandwidthCalculator { this.allLoadingsStoppedTimestamp = now; } - getBandwidthForLastNSplicedSeconds( + getBandwidthLoadingOnly( seconds: number, ignoreThresholdTimestamp = Number.NEGATIVE_INFINITY ) { - if (!this.shiftedTimestamps.length) return 0; + if (!this.loadingOnlyTimestamps.length) return 0; const milliseconds = seconds * 1000; const lastItemTimestamp = - this.shiftedTimestamps[this.shiftedTimestamps.length - 1]; + this.loadingOnlyTimestamps[this.loadingOnlyTimestamps.length - 1]; let lastCountedTimestamp = lastItemTimestamp; const threshold = lastItemTimestamp - milliseconds; let totalBytes = 0; for (let i = this.bytes.length - 1; i >= 0; i--) { - const timestamp = this.shiftedTimestamps[i]; + const timestamp = this.loadingOnlyTimestamps[i]; if ( timestamp < threshold || this.timestamps[i] < ignoreThresholdTimestamp @@ -57,7 +57,7 @@ export class BandwidthCalculator { return (totalBytes * 8000) / (lastItemTimestamp - lastCountedTimestamp); } - getBandwidthForLastNSeconds( + getBandwidth( seconds: number, ignoreThresholdTimestamp = Number.NEGATIVE_INFINITY, now = performance.now() @@ -79,19 +79,19 @@ export class BandwidthCalculator { } clearStale() { - if (!this.shiftedTimestamps.length) return; + if (!this.loadingOnlyTimestamps.length) return; const threshold = - this.shiftedTimestamps[this.shiftedTimestamps.length - 1] - + this.loadingOnlyTimestamps[this.loadingOnlyTimestamps.length - 1] - this.clearThresholdMs; let samplesToRemove = 0; - for (const timestamp of this.shiftedTimestamps) { + for (const timestamp of this.loadingOnlyTimestamps) { if (timestamp > threshold) break; samplesToRemove++; } this.bytes.splice(0, samplesToRemove); - this.shiftedTimestamps.splice(0, samplesToRemove); + this.loadingOnlyTimestamps.splice(0, samplesToRemove); this.timestamps.splice(0, samplesToRemove); } } diff --git a/packages/p2p-media-loader-core/src/hybrid-loader.ts b/packages/p2p-media-loader-core/src/hybrid-loader.ts index a965d307..5b3d0ec0 100644 --- a/packages/p2p-media-loader-core/src/hybrid-loader.ts +++ b/packages/p2p-media-loader-core/src/hybrid-loader.ts @@ -102,7 +102,7 @@ export class HybridLoader { if (data) { engineRequest.resolve( data, - this.bandwidthCalculators.all.getBandwidthForLastNSplicedSeconds(3) + this.bandwidthCalculators.all.getBandwidthLoadingOnly(3) ); } } else { @@ -439,26 +439,26 @@ export class HybridLoader { const { http, all } = this.bandwidthCalculators; const { activeLevelBitrate } = this.streamDetails; if (this.streamDetails.activeLevelBitrate === 0) { - return all.getBandwidthForLastNSplicedSeconds(3); + return all.getBandwidthLoadingOnly(3); } const { levelChangedTimestamp } = this; const bandwidth = Math.max( - all.getBandwidthForLastNSeconds(30, levelChangedTimestamp), - all.getBandwidthForLastNSeconds(60, levelChangedTimestamp), - all.getBandwidthForLastNSeconds(90, levelChangedTimestamp) + all.getBandwidth(30, levelChangedTimestamp), + all.getBandwidth(60, levelChangedTimestamp), + all.getBandwidth(90, levelChangedTimestamp) ); if (loadedPercentOfQueue >= 80 || bandwidth >= activeLevelBitrate * 0.9) { return Math.max( - all.getBandwidthForLastNSplicedSeconds(1), - all.getBandwidthForLastNSplicedSeconds(3), - all.getBandwidthForLastNSplicedSeconds(5) + all.getBandwidthLoadingOnly(1), + all.getBandwidthLoadingOnly(3), + all.getBandwidthLoadingOnly(5) ); } const httpRealBandwidth = Math.max( - http.getBandwidthForLastNSplicedSeconds(1), - http.getBandwidthForLastNSplicedSeconds(3), - http.getBandwidthForLastNSplicedSeconds(5) + http.getBandwidthLoadingOnly(1), + http.getBandwidthLoadingOnly(3), + http.getBandwidthLoadingOnly(5) ); return Math.max(bandwidth, httpRealBandwidth); }