From 5fcf58fa784e328c5940a0a532855086a4500dba Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Sat, 22 Aug 2026 22:12:51 +0200 Subject: [PATCH] feat(player): the controller talks to one contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DR-245. PlayerController now holds a MediaPlayer instead of a PlayerBackend, and every engine reaches it through that contract. Deliberately a seam swap, not four rewrites: the existing backends are carried across by LegacyPlayer, so MPV keeps its EQ and normalisation, ExoPlayer keeps its media session, and nothing loses a feature to the migration. MpvPlayer stays available for conformance until it grows the audio-settings half. The substantive change is at the load site. Where the controller used to call load() and then play(), it now issues one open() carrying the item and where to begin — so the window a start position could be lost in is gone from the controller as well as from the engines. `state()` maps the engine's Phase back onto PlayerState using the queue, which is what knows the item. External behaviour is unchanged. Supporting pieces: - The contract gains set_audio_settings/audio_settings as *provided* methods. Engines that cannot honour them say so through Capabilities and inherit a no-op, rather than every implementation carrying an Ok(()) it does not mean. - PlayerBackend is implemented for Box, without which the boxed engine built at the composition root cannot be handed to anything generic over the trait. - StreamSelection::for_queued_item rebuilds a selection for an item already in the queue, without re-negotiating. The transport falls back rather than being sniffed out of the URL — that substring check is what DR-230 removed — and needs_transcoding is an exact stand-in because every transcode this app requests is HLS (DR-140). - default-run = "jellytau". The conformance binary made a bare `cargo run` ambiguous, which broke `tauri dev` outright. Caught by running the app rather than by any suite, which is the argument for doing both. 789 tests, clippy -D warnings clean with and without the feature. --- docs/requirements.md | 2 +- src-tauri/Cargo.toml | 4 ++ src-tauri/src/lib.rs | 6 +- src-tauri/src/player/backend.rs | 50 ++++++++++++++ src-tauri/src/player/legacy_player.rs | 17 +++-- src-tauri/src/player/media.rs | 13 ++++ src-tauri/src/player/media_player.rs | 14 ++++ src-tauri/src/player/mod.rs | 68 ++++++++++++++------ src-tauri/src/repository/stream_selection.rs | 39 +++++++++++ 9 files changed, 187 insertions(+), 26 deletions(-) diff --git a/docs/requirements.md b/docs/requirements.md index 35737f06..70801534 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -440,7 +440,7 @@ Internal architecture, components, and application logic. | DR-242 | The player contract expresses intent, not device operations. `MediaPlayer::open` carries the start position, so no caller sequences load-then-seek and none can race an engine's asynchronous load; `seek` states a destination and leaves in-place-vs-re-open to the engine, which is the only layer that knows its own transport; `snapshot` is one coherent read; and `Phase::Opening` names the window a seek used to be lost in. Replaces `PlayerBackend`, which abstracted a device and required each of the three engines to re-derive the same rules | Player | UR-081 | In Progress | | DR-243 | Every engine passes one conformance suite, and a `FakePlayer` implements the contract deterministically. The suite is written before the second engine so it cannot encode whatever the first happened to do, and it drives readiness through a harness rather than sleeping. `FakePlayer` models the one behaviour that matters — opening is not instantaneous — so the load/seek race can be expressed on purpose, and lets the controller, queue, autoplay and session logic be tested with no engine at all | Player | UR-081 | In Progress | | DR-244 | `MpvPlayer` implements `MediaPlayer` over libmpv, applying the start position at load time via mpv's own `start` option rather than seeking after an asynchronous `loadfile`, and holding a seek that arrives during `Opening` until the file loads. A standalone `player-conformance` binary runs the suite against it with audio and video routed to null, so a wrapper is verifiable without building or launching the app | Player | UR-081, UR-040 | Done | -| DR-245 | `LegacyPlayer` drives the old `PlayerBackend` through the `MediaPlayer` contract, so engines not yet ported keep working during the migration and the two designs can be compared on one engine and one file. It reproduces the old load-then-play-then-seek sequence faithfully rather than a fixed-up version, because making it pass would defeat its purpose | Player | UR-081 | In Progress | +| DR-245 | `PlayerController` holds a `MediaPlayer` rather than a `PlayerBackend`, and every engine reaches it through that one contract — `LegacyPlayer` carries the not-yet-ported ones across unchanged, so the port swaps a seam rather than four implementations. Loading an item is now a single `open` carrying its start position, and the controller maps the engine's `Phase` back onto `PlayerState` using the queue, so nothing outside changes. `LegacyPlayer` drives the old `PlayerBackend` through the `MediaPlayer` contract, so engines not yet ported keep working during the migration and the two designs can be compared on one engine and one file. It reproduces the old load-then-play-then-seek sequence faithfully rather than a fixed-up version, because making it pass would defeat its purpose | Player | UR-081 | Done | | DR-247 | ExoPlayer can be told where to start. `JellyTauPlayer.load(url, mediaId)` had no way to express a start position, so every caller loaded and then seeked; the position is now handed to ExoPlayer with the media item via `setMediaItem(item, startPositionMs)`, and the two-argument form delegates to it. Running the conformance cases on a device also settled which half of DR-241 was engine-specific: ExoPlayer already queues a seek issued before `prepare()` completes, so it never had the lost-seek defect mpv did — only the missing vocabulary for a start position | Player | UR-081, UR-005 | Done | | DR-198 | The webview runs under a real Content-Security-Policy, and the asset protocol is scoped to the one directory it still serves. `csp` was `null`, which disables CSP entirely: any script that reached the web layer — through a future `{@html}`, a dependency, or a devtools paste — would have inherited the whole IPC surface, and with it the user's session. `script-src 'self'` (Tauri injects a nonce for SvelteKit's inline bootstrap script at build time, so no `'unsafe-inline'` is needed) plus `object-src`/`frame-src 'none'` and `base-uri 'self'` is the part that is genuinely restrictive. `img-src`/`media-src`/`connect-src` cannot be: the Jellyfin origin is typed in by the user at run time and is commonly plain `http` on a LAN, so they allow `http:`/`https:` — a wide grant for *data*, but one that still bars `file:`, `filesystem:` and scripting schemes, and leaves `script-src` untouched. `style-src` keeps `'unsafe-inline'` because Svelte compiles `style="…"` attributes (including `app.html`'s `display: contents` wrapper) into markup; this is safe only while no `