From ec2228f6ee9349c0866483abc21124dae31f2b52 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 4 Mar 2026 20:11:48 +0100 Subject: use codec param in js player --- ui/client-scripts/src/player/mediacaps.ts | 38 +++++++++++-------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'ui/client-scripts/src/player/mediacaps.ts') 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() +const cache = new Map() -// 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 { +export async function test_media_capability(format: FormatInfo, container: StreamContainer): Promise { 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 { + 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", -- cgit v1.3