feat(player): native video on Linux, and one contract for every player (v0.11.0)
mpv now decodes video on Linux, drawn into a framebuffer we own and blitted
into the default vbox's draw handler. Tauri's widget tree is untouched, so an
upgrade that assumes its own layout cannot invalidate this. Direct play means
the original file, hardware decoding, and no server transcode at all — where
previously every desktop video was re-encoded to h264 for the browser engine,
whatever the file actually was. Off by default: JELLYTAU_NATIVE_VIDEO=1.
That settles finding 2 of playback-backend-unification.md — "native video
cannot be composited with a Tauri webview" — by demonstration rather than
argument, on X11 and Wayland both.
Turning it on exposed nine defects, none of them mpv's. Each was the same
mistake in a different place: a capability written down as a compile-time fact
about the platform, or a state asserted instead of confirmed.
DR-238/246 a seek routed by the stream's container rather than by what the
engine could do with it - correct only while one player handled
those streams, silent the moment another did
DR-239 a property handled but never observed, so the play/pause button
waited for an event that could not arrive
DR-240 fullscreen expanding the document while the window stayed put
DR-241 a seek issued before the engine had a file, failed, and discarded
- which is why resume began at zero
DR-247 a Linux-only gate outliving the caller that made it Linux-only,
breaking the Android build outright
DR-250 a stop aimed at whichever renderer bookkeeping believed was in
charge, missing the one actually making sound
DR-251 a duration of zero believed, leaving the seek bar no scale
DR-252 a junk float converted to a Duration, panicking the backend the
instant a length-less stream appeared
So the MediaPlayer contract (DR-242 … DR-247): `open` carries a start position,
so no caller sequences load-then-seek and none can race an engine's load;
`seek` states a destination and leaves in-place-versus-re-open to the engine;
`snapshot` is one coherent read; and `Phase::Opening` names the window where
intent used to be lost. One conformance suite runs against every engine —
FakePlayer and mpv under cargo test, ExoPlayer instrumented on a device — so an
engine is either correct or visibly failing.
Two of the nine were introduced during this work and caught on hardware, not by
any suite: an over-broad capability that grouped ExoPlayer with mpv, and the
Duration panic. The suites test engines that behave. That is recorded in
docs/native-player-verification.md, which asks for the exact action sequences
that found them.
Verified: all automated gates, conformance (mpv 9/9, legacy 8/9 by design,
ExoPlayer 7/7 on device), and manual desktop and Android passes on real
hardware.
Known open and deliberately shipped: resume reads local progress and never the
server's; the background-audio handoff still declares a state swap it does not
confirm (the symptom is now impossible, the race is not); and `bun run
android:dev` builds an APK carrying the release application id, whose failure
message advises an uninstall that would destroy app data. Fix that last one
before anyone else builds for Android.
Squashed from worktree-linux-native-video, which keeps the per-defect history.
This commit is contained in:
@@ -212,6 +212,16 @@ pub fn subtitle_supports_external_delivery(codec: Option<&str>) -> bool {
|
||||
///
|
||||
/// TRACES: UR-004 | DR-148 | UT-142
|
||||
pub fn video_audio_codecs(detected: &str) -> String {
|
||||
// Where the video renderer decodes the audio itself (ExoPlayer), the
|
||||
// platform list *is* the answer and narrowing it to the webview's throws
|
||||
// away codecs the device genuinely plays — dts, on the tablet this was
|
||||
// found on. TRACES: UR-004, UR-080 | DR-234
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
return detected.to_string();
|
||||
}
|
||||
|
||||
#[allow(unreachable_code)]
|
||||
let kept: Vec<&str> = detected
|
||||
.split(',')
|
||||
.filter_map(|codec| {
|
||||
@@ -233,6 +243,83 @@ pub fn video_audio_codecs(detected: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// What the renderer that will actually decode video on this platform can play.
|
||||
///
|
||||
/// Returns `(video_codecs, audio_codecs)` as Jellyfin-style comma lists.
|
||||
///
|
||||
/// This exists because the answer was previously derived in four places and
|
||||
/// hardcoded in a fifth, each of them assuming the *webview* was decoding:
|
||||
/// the device profile, the transcoding targets, the direct-play audio
|
||||
/// narrowing, the client-side audio override, and `get_video_stream_url`'s
|
||||
/// `VideoCodec`. On Android the decoder is ExoPlayer, so every one of those was
|
||||
/// wrong there — the observed cost being an hevc source re-encoded to h264
|
||||
/// because its *audio* was eac3, and dts forced to transcode though the device
|
||||
/// decodes it.
|
||||
///
|
||||
/// One source, so the copies cannot disagree again.
|
||||
///
|
||||
/// TRACES: UR-004, UR-080 | DR-234
|
||||
pub fn renderer_codecs() -> (String, String) {
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
// ExoPlayer, and the device itself answers via MediaCodecList.
|
||||
crate::player::get_detected_codecs()
|
||||
.map(|(video, audio, _channels)| (video, audio))
|
||||
.unwrap_or_else(|| {
|
||||
log::warn!(
|
||||
"[DeviceProfile] Codec detection not complete, using conservative defaults"
|
||||
);
|
||||
("h264,hevc".to_string(), "aac,mp3".to_string())
|
||||
})
|
||||
}
|
||||
|
||||
// Linux desktop draws video in the WebKitGTK HTML5 <video> element, which
|
||||
// cannot reliably decode HEVC/AV1/VP9. Claim only what it decodes, so
|
||||
// Jellyfin transcodes the rest to h264 HLS. (Audio-only playback goes
|
||||
// through MPV and is unaffected — that is a different renderer and a
|
||||
// different profile.)
|
||||
//
|
||||
// When mpv draws the picture here this stops being a platform constant and
|
||||
// becomes a question about the active renderer — which is the whole point of
|
||||
// returning it from a function rather than a `cfg` block.
|
||||
#[cfg(all(not(target_os = "android"), target_os = "linux"))]
|
||||
{
|
||||
("h264".to_string(), "aac,mp3,opus,vorbis,flac".to_string())
|
||||
}
|
||||
|
||||
#[cfg(all(not(target_os = "android"), not(target_os = "linux")))]
|
||||
{
|
||||
(
|
||||
"h264,hevc,vp8,vp9,av1,mpeg4".to_string(),
|
||||
"aac,mp3,opus,vorbis,flac".to_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the renderer that decodes *video* on this platform can also decode
|
||||
/// this audio codec.
|
||||
///
|
||||
/// On a webview platform this is the webview's narrow list, because the element
|
||||
/// decodes both halves. On Android it is the device's own list: ExoPlayer plays
|
||||
/// the audio, so judging it against the webview's capabilities transcodes files
|
||||
/// that would have played.
|
||||
///
|
||||
/// TRACES: UR-004, UR-080 | DR-234
|
||||
pub fn renderer_can_decode_audio(codec: &str) -> bool {
|
||||
let codec = codec.trim();
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
let (_video, audio) = renderer_codecs();
|
||||
return audio
|
||||
.split(',')
|
||||
.any(|supported| supported.trim().eq_ignore_ascii_case(codec));
|
||||
}
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
webview_can_decode_audio(codec)
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the webview `<video>` element can decode this audio codec.
|
||||
///
|
||||
/// TRACES: UR-004 | DR-149 | UT-148
|
||||
@@ -260,7 +347,9 @@ pub fn webview_can_decode_audio(codec: &str) -> bool {
|
||||
/// TRACES: UR-004 | DR-149 | UT-148
|
||||
pub fn audio_forces_transcode(streams: &[(Option<&str>, bool)]) -> bool {
|
||||
match served_audio_codec(streams) {
|
||||
Some(codec) => !webview_can_decode_audio(codec),
|
||||
// The renderer that will decode it, not always the webview — see
|
||||
// `renderer_can_decode_audio`. TRACES: UR-004, UR-080 | DR-234
|
||||
Some(codec) => !renderer_can_decode_audio(codec),
|
||||
// No audio at all, or a codec the server did not name: leave it alone.
|
||||
None => false,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user