diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-03-04 20:11:48 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-03-04 20:11:48 +0100 |
| commit | ec2228f6ee9349c0866483abc21124dae31f2b52 (patch) | |
| tree | 89ac03ad42437ac00f06769f2c3a7ea5889985eb /ui/client-scripts/src/player/mediacaps.ts | |
| parent | 7ded052e22df1be30b29a2943b2bbe9196152a2d (diff) | |
| download | jellything-ec2228f6ee9349c0866483abc21124dae31f2b52.tar jellything-ec2228f6ee9349c0866483abc21124dae31f2b52.tar.bz2 jellything-ec2228f6ee9349c0866483abc21124dae31f2b52.tar.zst | |
use codec param in js player
Diffstat (limited to 'ui/client-scripts/src/player/mediacaps.ts')
| -rw-r--r-- | ui/client-scripts/src/player/mediacaps.ts | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/ui/client-scripts/src/player/mediacaps.ts b/ui/client-scripts/src/player/mediacaps.ts index 9b0e934..4393fe9 100644 --- a/ui/client-scripts/src/player/mediacaps.ts +++ b/ui/client-scripts/src/player/mediacaps.ts @@ -7,24 +7,22 @@ import { FormatInfo, StreamContainer } from "./types_stream.ts"; -const cache = new Map<string, boolean>() +const cache = new Map<string, CodecSupport>() -// TODO this testing method makes the assumption, that if the codec is supported on its own, it can be -// TODO arbitrarly combined with others that are supported. in reality this is true but the spec does not gurantee it. +export type CodecSupport = "unsupported" | "supported" | "supported_smooth" -export async function test_media_capability(format: FormatInfo, container: StreamContainer): Promise<boolean> { +export async function test_media_capability(format: FormatInfo, container: StreamContainer): Promise<CodecSupport> { const cache_key = JSON.stringify(format) + container const cached = cache.get(cache_key); if (cached !== undefined) return cached const r = await test_media_capability_inner(format, container) - console.log(`${r ? "positive" : "negative"} media capability test finished for codec=${format.codec}`); + console.log(`media caps: codec=${format.codec} sup=${r}`); cache.set(cache_key, r) return r } -async function test_media_capability_inner(format: FormatInfo, container: StreamContainer) { - if (format.codec.startsWith("S_") || format.codec.startsWith("D_")) { - // TODO do we need to check this? - return format.codec == "S_TEXT/WEBVTT" || format.codec == "S_TEXT/UTF8" || format.codec == "D_WEBVTT/SUBTITLES" +async function test_media_capability_inner(format: FormatInfo, container: StreamContainer): Promise<CodecSupport> { + if (format.codec == "S_TEXT/WEBVTT" || format.codec == "S_TEXT/UTF8" || format.codec == "D_WEBVTT/SUBTITLES") { + return "supported" } let res; if (format.codec.startsWith("A_")) { @@ -37,39 +35,29 @@ async function test_media_capability_inner(format: FormatInfo, container: Stream bitrate: format.bitrate, } }) - } - if (format.codec.startsWith("V_")) { + } else if (format.codec.startsWith("V_")) { res = await navigator.mediaCapabilities.decodingInfo({ type: "media-source", video: { contentType: track_to_content_type(format, container), - framerate: 30, // TODO get average framerate from server + framerate: format.samplerate ?? 60, width: format.width ?? 1920, height: format.height ?? 1080, bitrate: format.bitrate } }) + } else { + res = { supported: false, smooth: false } } - return res?.supported ?? false + return res.supported ? (res.smooth ? "supported_smooth" : "supported") : "unsupported" } export function track_to_content_type(format: FormatInfo, container: StreamContainer): string { let c = CONTAINER_TO_MIME_TYPE[container]; if (format.codec.startsWith("A_")) c = c.replace("video/", "audio/") - return `${c}; codecs="${MASTROSKA_CODEC_MAP[format.codec]}"` + return `${c}; codecs="${format.codec_param}"` } -const MASTROSKA_CODEC_MAP: { [key: string]: string } = { - "V_VP9": "vp9", - "V_VP8": "vp8", - "V_AV1": "av1", - "V_MPEG4/ISO/AVC": "avc1.42C01F", - "V_MPEGH/ISO/HEVC": "hev1.1.6.L93.90", - "A_OPUS": "opus", - "A_VORBIS": "vorbis", - "S_TEXT/WEBVTT": "webvtt", - "D_WEBVTT/SUBTITLES": "webvtt", -} const CONTAINER_TO_MIME_TYPE: { [key in StreamContainer]: string } = { webvtt: "text/webvtt", webm: "video/webm", |