aboutsummaryrefslogtreecommitdiff
path: root/web/script/player/profiles.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/script/player/profiles.ts')
-rw-r--r--web/script/player/profiles.ts29
1 files changed, 20 insertions, 9 deletions
diff --git a/web/script/player/profiles.ts b/web/script/player/profiles.ts
index b4de534..50be9d3 100644
--- a/web/script/player/profiles.ts
+++ b/web/script/player/profiles.ts
@@ -1,6 +1,8 @@
import { OVar } from "../jshelper/mod.ts";
import { EncodingProfile, JhlsMetadata } from "./jhls.d.ts";
+const PROFILE_UP_FAC = 0.7
+
export interface EncodingProfileExt extends EncodingProfile { id: number, order: number }
export class ProfileSelector {
profiles_video: EncodingProfileExt[] = []
@@ -30,17 +32,26 @@ export class ProfileSelector {
return []
}
select_optimal_profile(track: number, profile: OVar<EncodingProfileExt | undefined>) {
- if (this.bandwidth.value < 5000 * 1000) {
- profile.value = this.profile_list_for_track(track)[0]
- } else {
- profile.value = undefined
+ const profs = this.profile_list_for_track(track)
+
+ const co = profile.value?.order ?? -1
+ const current_bitrate = profile_bw(profs[co], 5000 * 1000)
+ const next_bitrate = profile_bw(profs[co - 1], 5000 * 1000)
+ console.log({ current_bitrate, next_bitrate, co, bandwidth: this.bandwidth.value * 8 });
+ if (current_bitrate > this.bandwidth.value * 8 && co + 1 < profs.length) {
+ console.log("profile up");
+ profile.value = profs[co + 1]
+ }
+ if (next_bitrate < this.bandwidth.value * 8 * PROFILE_UP_FAC && co >= 0) {
+ console.log("profile down");
+ profile.value = profs[co - 1]
}
}
}
-function profile_bw(p: EncodingProfile): number {
- if (p.audio) return p.audio.bitrate / 8
- if (p.video) return p.video.bitrate / 8
- if (p.subtitles) return 100
- return 0
+function profile_bw(p?: EncodingProfile, fallback = 0): number {
+ if (p?.audio) return p.audio.bitrate / 8
+ if (p?.video) return p.video.bitrate / 8
+ if (p?.subtitles) return 100
+ return fallback
}