fix(playback): advertise only webview-decodable audio for video (DR-148, 0.4.7)

The audio codec list sent to Jellyfin comes from MediaCodecList, which
describes ExoPlayer — but video does not play through ExoPlayer. Android
force-renders every video in the webview <video> element (the interim
override in VideoPlayer.svelte) and Linux always has, and Chromium/WebKit
decode a far narrower set than the platform does.

A motorola edge 30 ships /vendor/etc/media_codecs_dolby_audio.xml, so it
reported ac3,eac3; the server direct-played an E-AC-3 track with
static=true and the webview built a video decoder and no audio decoder at
all — full picture, no sound. The defect is triggered by capability rather
than the lack of it, which is why a Fairphone and an Honor tablet play the
same file on the same build: without the Dolby decoder they never claim the
codec, so the server transcodes to AAC. Confirmed by A/B on the failing
device — hevc+eac3 silent, hevc+aac audible, same session, same profile,
same direct-play path, audio codec the only variable.

video_audio_codecs narrows the platform list to the webview-decodable set
for the video direct-play profile only. Audio-only playback really is the
native player's, so that profile keeps the full list rather than
transcoding music that plays perfectly well. A list with nothing decodable
still claims aac, since a profile claiming nothing invites the server to
give up instead of transcoding. The video codec list is deliberately
untouched: HEVC direct-plays through the webview correctly, so the
constraint is specific to audio.

Test-first: the tests failed against the old behaviour before the filter
existed, including the case built from the phone's real codec list. The
requirement-count assertion in extract-traces.test.ts moves 280 -> 281 for
the added DR, which is the deliberate edit that test exists to force.

Not yet verified on device — the 0.4.7 APK was still building.
This commit is contained in:
2026-08-11 19:13:46 +02:00
parent 1b70926c36
commit 2c3955914e
10 changed files with 232 additions and 89 deletions
@@ -50,10 +50,100 @@ pub fn max_audio_channels() -> u32 {
clamp_max_audio_channels(reported)
}
/// Audio codecs the webview's `<video>` element can decode.
///
/// Deliberately narrower than what the platform reports: see
/// [`video_audio_codecs`].
const WEBVIEW_AUDIO_CODECS: &[&str] = &["aac", "mp3", "opus", "vorbis", "flac"];
/// The codec claimed when a device reports nothing we can use. Every renderer
/// decodes AAC, and claiming *something* is what makes the server transcode to
/// it rather than give up.
const FALLBACK_AUDIO_CODEC: &str = "aac";
/// Narrow a detected audio-codec list to what the renderer that will actually
/// play the **video** can decode.
///
/// The platform list comes from `MediaCodecList`, which describes ExoPlayer —
/// but video does not play through ExoPlayer. Both Android and Linux render it
/// in a webview `<video>` element, and Chromium/WebKit decode a much smaller set
/// than the platform does. Advertising the raw list makes Jellyfin direct-play a
/// track the webview cannot decode, and the user gets picture with no sound.
///
/// The gap is widest on devices whose vendor licenses Dolby: a phone with
/// `c2.dolby.eac3.decoder` reports `eac3`, so it — and only it — gets a silent
/// direct play where a leaner device is transcoded to AAC and plays fine.
///
/// This applies to the *video* direct-play profile only. Audio-only playback
/// really is ExoPlayer's, so its profile keeps the full platform list.
///
/// TRACES: UR-004 | DR-148 | UT-142
pub fn video_audio_codecs(detected: &str) -> String {
let kept: Vec<&str> = detected
.split(',')
.filter_map(|codec| {
let codec = codec.trim();
// Match case-insensitively but emit our own spelling: the platform
// list is assembled from MIME strings and its casing is not ours to
// forward to the server.
WEBVIEW_AUDIO_CODECS
.iter()
.copied()
.find(|supported| supported.eq_ignore_ascii_case(codec))
})
.collect();
if kept.is_empty() {
FALLBACK_AUDIO_CODEC.to_string()
} else {
kept.join(",")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_dolby_device_does_not_advertise_dolby_for_video() {
// The bug: a Motorola reporting c2.dolby.eac3.decoder direct-played
// E-AC-3 into a webview that cannot decode it — silent video, on that
// device only.
let codecs = video_audio_codecs("aac,ac3,amrnb,amrwb,eac3,flac,mp3,opus,pcm,vorbis");
assert_eq!(codecs, "aac,flac,mp3,opus,vorbis");
}
#[test]
fn codecs_the_webview_cannot_decode_are_dropped() {
// AMR and raw PCM come from the AOSP set, so this is not a Dolby-only
// problem — it is just rarer content.
assert_eq!(video_audio_codecs("amrnb,amrwb,pcm,aac"), "aac");
assert_eq!(video_audio_codecs("dts,truehd,mp3"), "mp3");
}
#[test]
fn a_list_the_webview_fully_supports_is_untouched() {
assert_eq!(
video_audio_codecs("aac,mp3,opus,vorbis,flac"),
"aac,mp3,opus,vorbis,flac"
);
}
#[test]
fn nothing_decodable_still_claims_aac() {
// Claiming an empty list invites the server to give up rather than
// transcode. AAC is universally decodable, so ask for it.
assert_eq!(video_audio_codecs("eac3,dts"), "aac");
assert_eq!(video_audio_codecs(""), "aac");
}
#[test]
fn spacing_and_case_in_the_platform_list_are_tolerated() {
// The list is assembled from MediaCodecList strings; do not let
// whitespace decide whether the user gets sound.
assert_eq!(video_audio_codecs("aac, EAC3 , Mp3"), "aac,mp3");
}
#[test]
fn an_unknown_route_falls_back_to_stereo() {
// Codec detection has not run yet, or the platform has no answer. Never