aboutsummaryrefslogtreecommitdiff
path: root/web/script/player/profiles.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-10-02 22:58:44 +0200
committermetamuffin <metamuffin@disroot.org>2023-10-02 22:58:44 +0200
commit1f11c16aefe71d68605d2cd0ad5da9c016aa3570 (patch)
tree39a5cdc211c6f5da660acb4a8da36e88f88863c7 /web/script/player/profiles.ts
parente52890060edb988cf16f184d5711e539b1c1dd01 (diff)
downloadjellything-1f11c16aefe71d68605d2cd0ad5da9c016aa3570.tar
jellything-1f11c16aefe71d68605d2cd0ad5da9c016aa3570.tar.bz2
jellything-1f11c16aefe71d68605d2cd0ad5da9c016aa3570.tar.zst
testing profile autoselect
Diffstat (limited to 'web/script/player/profiles.ts')
-rw-r--r--web/script/player/profiles.ts38
1 files changed, 31 insertions, 7 deletions
diff --git a/web/script/player/profiles.ts b/web/script/player/profiles.ts
index 3b3379a..b4de534 100644
--- a/web/script/player/profiles.ts
+++ b/web/script/player/profiles.ts
@@ -1,22 +1,46 @@
import { OVar } from "../jshelper/mod.ts";
import { EncodingProfile, JhlsMetadata } from "./jhls.d.ts";
-export interface EncodingProfileExt extends EncodingProfile { id: number }
+export interface EncodingProfileExt extends EncodingProfile { id: number, order: number }
export class ProfileSelector {
profiles_video: EncodingProfileExt[] = []
profiles_audio: EncodingProfileExt[] = []
profiles_subtitles: EncodingProfileExt[] = []
+ remux_bandwidth = new Map<number, { size: number, duration: number }>()
constructor(private bandwidth: OVar<number>, private metadata: JhlsMetadata) {
for (let id = 0; id < metadata.extra_profiles.length; id++) {
const p = metadata.extra_profiles[id];
- if (p.audio) this.profiles_audio.push({ id, ...p })
- if (p.video) this.profiles_video.push({ id, ...p })
- if (p.subtitles) this.profiles_subtitles.push({ id, ...p })
+ if (p.audio) this.profiles_audio.push({ id, order: 0, ...p })
+ if (p.video) this.profiles_video.push({ id, order: 0, ...p })
+ if (p.subtitles) this.profiles_subtitles.push({ id, order: 0, ...p })
}
+ this.profiles_audio.sort((a, b) => profile_bw(b) - profile_bw(a))
+ this.profiles_video.sort((a, b) => profile_bw(b) - profile_bw(a))
+ this.profiles_subtitles.sort((a, b) => profile_bw(b) - profile_bw(a))
+ for (let i = 0; i < this.profiles_audio.length; i++) this.profiles_audio[i].order = i
+ for (let i = 0; i < this.profiles_video.length; i++) this.profiles_video[i].order = i
+ for (let i = 0; i < this.profiles_subtitles.length; i++) this.profiles_subtitles[i].order = i
}
-
- select_optimal_profile(track: number, profile: OVar<EncodingProfileExt>) {
- // TODO
+ profile_list_for_track(track: number): EncodingProfileExt[] {
+ const i = this.metadata.tracks[track].info.kind
+ if (i.audio) return this.profiles_audio
+ if (i.video) return this.profiles_video
+ if (i.subtitles) return this.profiles_subtitles
+ 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
+ }
}
}
+
+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
+}