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.
89 lines
3.4 KiB
TypeScript
89 lines
3.4 KiB
TypeScript
/**
|
|
* Which loader opens a stream in the webview `<video>` element.
|
|
*
|
|
* Extracted from `VideoPlayer.svelte` so the decision can be unit-tested — the
|
|
* same pattern as `episodeStrip.ts` and `TrackList.logic.test.ts`.
|
|
*
|
|
* TRACES: UR-079 | DR-225 | UT-214
|
|
*/
|
|
|
|
import type { StreamSelection, Transport } from "$lib/api/bindings";
|
|
|
|
/** How the element should be fed. */
|
|
export type VideoLoader =
|
|
/** hls.js drives a MediaSource; the element's own `src` stays empty. */
|
|
| "hlsjs"
|
|
/** The element loads the playlist itself (Safari/WebKit native HLS). */
|
|
| "nativeHls"
|
|
/** The element loads the URL directly — a progressive file or a local one. */
|
|
| "direct";
|
|
|
|
/** What the running browser can do, passed in so the decision stays pure. */
|
|
export interface LoaderCapabilities {
|
|
/** `Hls.isSupported()` */
|
|
hlsJsSupported: boolean;
|
|
/** `video.canPlayType("application/vnd.apple.mpegurl")` was non-empty */
|
|
nativeHlsSupported: boolean;
|
|
}
|
|
|
|
/**
|
|
* Pick the loader from the backend's tagged `transport`.
|
|
*
|
|
* This used to read `url.includes(".m3u8")`, in two places in
|
|
* `VideoPlayer.svelte`. Rust *builds* that URL and knows exactly what it is;
|
|
* re-deriving the answer here by substring match is a domain fact reconstructed
|
|
* in the presentation layer — the same error as leaking item-type taxonomy, and
|
|
* one that fails silently in both directions: a progressive file served from a
|
|
* path containing `.m3u8` gets an HLS loader, and a playlist served from a path
|
|
* without it does not.
|
|
*
|
|
* The transport is the *stream's* property; whether a given loader exists is the
|
|
* *browser's*. Only the second is decided here.
|
|
*/
|
|
export function videoLoaderFor(
|
|
selection: Pick<StreamSelection, "url" | "transport">,
|
|
capabilities: LoaderCapabilities,
|
|
): VideoLoader {
|
|
return loaderForTransport(selection.transport.type, capabilities);
|
|
}
|
|
|
|
/**
|
|
* The same decision, taken from the transport *tag* alone.
|
|
*
|
|
* Exists because a Svelte `$effect` that reads the whole selection re-runs
|
|
* whenever the selection **object** is replaced — even with an identical URL and
|
|
* transport — and the HLS effect's teardown/rebuild is not idempotent: it
|
|
* destroys the hls.js instance and reattaches, which leaves the element with no
|
|
* video until something forces another cycle. The pre-DR-225 code read a plain
|
|
* URL *string*, so re-assigning the same value was a no-op and the effect stayed
|
|
* put. Passing primitives restores that.
|
|
*
|
|
* TRACES: UR-079 | DR-225 | UT-214
|
|
*/
|
|
export function loaderForTransport(
|
|
transport: Transport["type"],
|
|
capabilities: LoaderCapabilities,
|
|
): VideoLoader {
|
|
if (transport !== "hls") {
|
|
// Progressive and local files are what the element loads natively. No
|
|
// MediaSource, no playlist parsing.
|
|
return "direct";
|
|
}
|
|
if (capabilities.hlsJsSupported) return "hlsjs";
|
|
if (capabilities.nativeHlsSupported) return "nativeHls";
|
|
// Nothing here can parse a playlist. Handing the URL to the element is very
|
|
// likely to fail, but it is the only remaining move and it surfaces a real
|
|
// media error rather than silently doing nothing.
|
|
return "direct";
|
|
}
|
|
|
|
/** Convenience for the template: does the element's `src` stay empty? */
|
|
export function elementSrcFor(
|
|
selection: Pick<StreamSelection, "url" | "transport">,
|
|
capabilities: LoaderCapabilities,
|
|
): string {
|
|
return videoLoaderFor(selection, capabilities) === "hlsjs" ? "" : selection.url;
|
|
}
|
|
|
|
export type { Transport };
|