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.
248 lines
8.6 KiB
TypeScript
248 lines
8.6 KiB
TypeScript
/**
|
|
* Behavioural regression tests for the video tap surface — rendered against the
|
|
* REAL component, not a hand-modelled DOM.
|
|
*
|
|
* TRACES: UR-005, UR-061 | DR-098 | UT-092
|
|
*
|
|
* Why this file exists:
|
|
*
|
|
* `tapGestures.test.ts` tests `registerTap` / `isControlSurfaceTouch` /
|
|
* `isSynthesizedTouchClick` as isolated pure functions. Every one of those tests
|
|
* passed while, on the device, in sequence: the player pause-looped, then
|
|
* pausing became impossible, then the bottom controls went dead, then
|
|
* double-tap-to-seek stopped working. The helpers were each behaving exactly as
|
|
* specified — the bugs were all in the *composition*: which element actually
|
|
* receives a tap once Svelte has re-rendered.
|
|
*
|
|
* Testing my own helpers could not catch that, and modelling the DOM by hand in
|
|
* a test just re-encodes the same wrong assumption. So these tests render
|
|
* VideoPlayer and dispatch real touch/click events at whatever element is
|
|
* genuinely on top, asserting user-visible outcomes ("a double tap seeks")
|
|
* rather than internals.
|
|
*
|
|
* The specific traps encoded here, each a bug that shipped:
|
|
* - pausing renders a full-screen <button> play overlay OVER the video, so the
|
|
* second tap of a double tap lands on a button, not the video;
|
|
* - the browser synthesizes a `click` after a touch tap, which must not toggle
|
|
* a second time, on ANY layered target;
|
|
* - the bottom controls bar must drive its own buttons and NOT the container's
|
|
* tap gestures.
|
|
*/
|
|
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render } from "@testing-library/svelte";
|
|
import { tick } from "svelte";
|
|
import { invoke } from "@tauri-apps/api/core";
|
|
import VideoPlayer from "./VideoPlayer.svelte";
|
|
import { SEEK_FORWARD_SECONDS } from "./tapGestures";
|
|
|
|
/**
|
|
* A `StreamSelection` for tests that only care about the URL. Transcoded HLS is
|
|
* what these paths exercised before the contract carried a transport.
|
|
*/
|
|
function testSelection(url: string, transport: "hls" | "progressive" | "localFile" = "hls") {
|
|
return {
|
|
url,
|
|
transport: { type: transport },
|
|
playbackKind: { type: transport === "hls" ? "transcode" : "directPlay" },
|
|
rendition: null,
|
|
available: [],
|
|
mediaSourceId: null,
|
|
playSessionId: null,
|
|
needsTranscoding: transport === "hls",
|
|
} as import("$lib/api/bindings").StreamSelection;
|
|
}
|
|
|
|
// --- Mocks: everything VideoPlayer reaches for that is not the tap surface. ---
|
|
|
|
const toggleSpy = vi.fn();
|
|
const seekVideoSpy = vi.fn();
|
|
const seekSpy = vi.fn();
|
|
|
|
vi.mock("$app/navigation", () => ({ goto: vi.fn() }));
|
|
|
|
vi.mock("$lib/player", () => ({
|
|
playerController: {
|
|
toggle: (...a: unknown[]) => {
|
|
toggleSpy(...a);
|
|
return Promise.resolve();
|
|
},
|
|
seekVideo: (...a: unknown[]) => {
|
|
seekVideoSpy(...a);
|
|
return Promise.resolve();
|
|
},
|
|
seek: (...a: unknown[]) => {
|
|
seekSpy(...a);
|
|
return Promise.resolve();
|
|
},
|
|
setActiveAdapter: vi.fn(),
|
|
clearActiveAdapter: vi.fn(),
|
|
getActiveAdapter: vi.fn(() => null),
|
|
},
|
|
}));
|
|
|
|
vi.mock("$lib/player/adapters/rustReportHost", () => ({
|
|
createRustReportHost: () => ({
|
|
onState: vi.fn(),
|
|
onPosition: vi.fn(),
|
|
onMediaLoaded: vi.fn(),
|
|
onEnded: vi.fn(),
|
|
onError: vi.fn(),
|
|
onStreamUrlChanged: vi.fn(),
|
|
onBuffering: vi.fn(),
|
|
onReady: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
vi.mock("$lib/player/html5Adapter", () => ({
|
|
reportState: vi.fn(),
|
|
reportPosition: vi.fn(),
|
|
reportMediaLoaded: vi.fn(),
|
|
resetReporting: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("$lib/utils/pictureInPicture", () => ({
|
|
isPipSupported: () => false,
|
|
enterPip: vi.fn(),
|
|
setAutoEnterEnabled: vi.fn(),
|
|
setHtml5VideoState: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("$lib/stores/auth", () => ({
|
|
auth: {
|
|
getRepository: () => ({ getHandle: () => "h", jrayActorsAt: async () => [] }),
|
|
subscribe: (fn: (v: unknown) => void) => {
|
|
fn({ isAuthenticated: true });
|
|
return () => {};
|
|
},
|
|
},
|
|
}));
|
|
|
|
const MEDIA = {
|
|
id: "item-1",
|
|
name: "Test Episode",
|
|
type: "Episode",
|
|
runTimeTicks: 6_000_000_000, // 600s
|
|
} as any;
|
|
|
|
/** Dispatch a touch at (x, y) on whatever element is topmost there. */
|
|
function touchAt(el: Element, x: number) {
|
|
const touch = { clientX: x, clientY: 300 } as Touch;
|
|
el.dispatchEvent(
|
|
new TouchEvent("touchstart", {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
touches: [touch] as unknown as Touch[],
|
|
}),
|
|
);
|
|
}
|
|
|
|
function renderPlayer() {
|
|
return render(VideoPlayer, {
|
|
props: { media: MEDIA, selection: testSelection("http://x/master.m3u8"), onClose: vi.fn() },
|
|
});
|
|
}
|
|
|
|
describe("VideoPlayer tap surface (real component)", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
// This file deliberately does NOT mock `$lib/api/bindings` — it renders the
|
|
// real component against the real bindings, which bottom out in the globally
|
|
// mocked `invoke`. That mock resolves `undefined` for every command, so the
|
|
// commands whose results are *rendered* have to be answered here: the
|
|
// quality picker assigns the result straight to state and then does
|
|
// `streamingQualities.length` in the template, which throws (asynchronously,
|
|
// outside any test) on undefined and fails the run with an unhandled error.
|
|
vi.mocked(invoke).mockImplementation(async (cmd: string) => {
|
|
switch (cmd) {
|
|
case "player_get_streaming_qualities":
|
|
return [];
|
|
case "player_get_video_settings":
|
|
return { streamingQuality: "original" };
|
|
default:
|
|
return undefined;
|
|
}
|
|
});
|
|
});
|
|
|
|
it("a single tap on the video toggles play/pause exactly once", async () => {
|
|
const { container } = renderPlayer();
|
|
const video = container.querySelector("video");
|
|
expect(video).toBeTruthy();
|
|
|
|
touchAt(video!, 900);
|
|
|
|
expect(toggleSpy).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("the synthesized click after a tap does not toggle a second time", async () => {
|
|
const { container } = renderPlayer();
|
|
const video = container.querySelector("video")!;
|
|
|
|
touchAt(video, 900);
|
|
// The compatibility click the browser fires after a touch tap. detail=0 is
|
|
// how engines mark it; a late real-detail click is covered by the recency
|
|
// guard, which this exercises too since it lands immediately.
|
|
video.dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 0 }));
|
|
|
|
expect(toggleSpy).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("a double tap seeks even though the first tap raised the play overlay", async () => {
|
|
// THE regression this file exists for. On device the first tap pauses, which
|
|
// makes Svelte render a full-screen <button> play overlay over the video —
|
|
// so the SECOND tap lands on a button, not the video. A control-surface
|
|
// guard that does not know about that overlay discards it and seeking dies.
|
|
//
|
|
// Reproducing it requires the overlay to actually render, which means
|
|
// driving `isPlaying` the way the real element does: via its `pause` event.
|
|
vi.useFakeTimers();
|
|
try {
|
|
const { container } = renderPlayer();
|
|
const video = container.querySelector("video")!;
|
|
|
|
// Tap 1 on the video.
|
|
touchAt(video, 900);
|
|
|
|
// The element reports it paused → isPlaying=false → overlay renders.
|
|
video.dispatchEvent(new Event("pause"));
|
|
await Promise.resolve();
|
|
await tick();
|
|
|
|
const overlay = container.querySelector("[data-player-surface]");
|
|
expect(overlay, "the play overlay should be covering the video").toBeTruthy();
|
|
|
|
vi.advanceTimersByTime(120); // inside DOUBLE_TAP_WINDOW_MS
|
|
// Tap 2 lands on the OVERLAY, exactly as on device.
|
|
touchAt(overlay!, 900);
|
|
|
|
// Either seek route is acceptable — which one runs depends on whether a
|
|
// video adapter is registered. What must hold is that a seek happened, to
|
|
// roughly the forward-skip target.
|
|
const calls = [...seekVideoSpy.mock.calls, ...seekSpy.mock.calls];
|
|
expect(calls.length).toBe(1);
|
|
const [position] = calls[0];
|
|
expect(position).toBeGreaterThan(0);
|
|
expect(position).toBeLessThanOrEqual(SEEK_FORWARD_SECONDS);
|
|
} finally {
|
|
vi.useRealTimers();
|
|
}
|
|
});
|
|
|
|
it("tapping the bottom play/pause button toggles once, not twice", async () => {
|
|
const { container } = renderPlayer();
|
|
const controls = container.querySelector("[data-player-controls]");
|
|
expect(controls).toBeTruthy();
|
|
|
|
const playBtn = controls!.querySelector("button");
|
|
expect(playBtn).toBeTruthy();
|
|
|
|
// A real press: touchstart bubbles to the container's gesture handler, then
|
|
// the button's own click fires. Only ONE toggle may result.
|
|
touchAt(playBtn!, 40);
|
|
playBtn!.dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 1 }));
|
|
|
|
expect(toggleSpy).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|