Repository navigation
ALI-2420: The shared libmpv playback crate, with colour tests - #1
Conversation
One crate for Alias View, Gannet and Nitrate to play through libmpv: - Player: libmpv opened at run time, the shared options, commands, and events for position, duration, pause, volume, mute, end and failure. - SwRender and GlRender: libmpv's CPU and OpenGL render APIs. - options::colour: the colour settings for each render path in one place. The CPU path keeps Gannet's BT.1886 relabel (ALI-2418). - helper and jail: Gannet's jailed CPU player, with frames in shared memory, moved here so any app can use it. Every app stops on a video's last frame instead of closing. Hardware decoding tries NVDEC, VA-API and V4L2 by name. VDPAU is left out because it stalls on H.264 4:4:4 on NVIDIA. The colour tests play 51 clips of solid patches, made from Y'CbCr worked out from source RGB and encoded losslessly. The clips cover range, matrix, transfer tag, bit depth, chroma and codec. CI runs them on the CPU renderer, and examples/colour-gpu.rs runs them on a graphics card.
ALI-2420 One shared libmpv playback crate for Alias View, Gannet and Nitrate, with colour tests that prove exact colour
WhyThree of our apps play video through libmpv, each set up its own way:
On 2026-11-30 an M1 screen recording drew lighter and greyer in Gannet's preview than in the mpv window (ALI-2417, ALI-2418). libmpv wasn't at fault: one rendering mode (the CPU renderer's zimg path) handled one tag (an sRGB transfer) differently, and nothing tested for it. Decision (Mike, 2026-11-30): keep libmpv, the standard. Don't write our own decoder or player. Build one shared crate that all three apps use, and prove its colour with tests. What the crate does
Colour testsA set of test clips whose correct pixel values are known, played through every rendering mode we ship. A clip passes when every patch lands within the tolerance of its expected colour. The clips. Solid colour patches, generated from known RGB values. They include black, white, greys, the primaries, skin tones, and real theme colours such as Tarnished's
Real recordings are included too: one from each of our screen recorders (wf-recorder on the M1, gpu-screen-recorder on the desktop), checked against a screenshot taken at the same moment. Expected values come from the source RGB, not from another player's output, so the tests can't inherit someone else's bug. Tolerance:
Where they run:
When a case fails: first look for an mpv option that fixes it (for example Done when
Open questions for Mike
+++ Agent notes
+++ |
- jail::own_exe no longer falls back to /proc/self/exe. bubblewrap resolves that path in its own process and binds itself, so a video opened after the app's file was removed ran bwrap as the helper and failed as a jail error. It now fails plainly instead. - ordered-chapters and access-references are off. A Matroska file could otherwise make an unjailed player read other files for its chapters, and a playlist could name anything. - When a file closes, the position and duration go back to 0 rather than keeping the last file's values (new helper test, which fails without this change). - GlRender can't move between threads. Dropping it frees libmpv's GL state, which needs its context current. - watch stops the player when try_wait fails, as its documentation says. - start's documentation says the player dies with the thread that started it. - The GPU bench skips a case only when the machine's encoder can't make it. A missing FFmpeg or a clip that fails its check is now a failure. - The CPU colour setting's comment covers full-range video with no transfer tag too. - The unused rustix process feature is removed.
|
Review round 1 (fresh reviewer; Fixed
Declined
Checked and held (by the reviewer):
|
- When a file closes, the end also goes back to not reached (Ended(false)), as the position and duration already do. Before, an app that had shown "ended" kept showing it with nothing loaded. The helper test now checks it, and fails without this. - Player::load always passes a path libmpv reads as a file: a relative one gets "./" in front. A relative path shaped like "http://host/x" or "edl://..." would otherwise be fetched or built by libmpv.
|
Review round 2 (fresh reviewer; Fixed in 827a83c
Declined
|
|
Review round 3 (final, limited to 827a83c). The
No P1 or P2 findings. The review is clean, and CI is green on 827a83c. |
Linear: ALI-2420
The first version of the crate Alias View, Gannet and Nitrate share for playback through libmpv. Alias View's video and music (ALI-2358) build on it next. Gannet and Nitrate each get a follow-up ticket to move onto it.
What's in it
Player: opens libmpv at run time (libmpv.so.2, client API 2.x), so an app starts without it. It sets the shared options and runs commands (load, play, pause, seek, volume, mute). Its events report position, duration, pause, volume, mute, the end and failure.SwRender,GlRender: libmpv's CPU render API (frames asXRGB8888, ready forwl_shm) and its OpenGL render API.Optionsandoptions::colour: the setup every app shares, plus the colour settings for each render path in one place.helperandjail: Gannet's jailed CPU player, moved here. It covers both sides: the app'sstart,watch,FramesandRemote, and the player'srun, which takes the app's seccomp filter aslock_down. The jail rules are Gannet's. Changes from Gannet's version:seekatseeks to a time (for MPRIS);Every app behaves the same where it should:
Hardware decoding tries NVDEC, VA-API and V4L2 by name, then falls back to the CPU. The software renderer gets the copy-back methods only. libmpv's own
auto-safelist wasn't used because it includes VDPAU. On the RTX 4090, VDPAU accepts H.264 4:4:4, fails every frame and never falls back, so the video never starts. The GPU colour bench found this.Colour tests
51 clips, each a 4x4 grid of solid patches: black, white, greys, primaries, secondaries, skin tones and Tarnished's
#121C24.yuvj), matrix (601, 709, 2020) and transfer tag (709, sRGB, none) on H.264;The M1's 2 skipped clips are 10-bit HEVC, which its 8-bit-only libx265 can't make.
Without the CPU colour setting (
vf=format=gamma=bt.1886, from ALI-2418), the sRGB-tagged clips draw up to 13 steps too light (#121C24→#1E2831). The tests also found the same lift in full-range clips with no transfer tag, which the setting fixes too. The CPU run prints this for each case.Not yet covered:
CI
CI runs on GitHub's hosted runners in an Arch container, with Arch's libmpv and FFmpeg. It runs
cargo fmt --check,clippy -D warnings, andcargo test: unit tests, a real out-of-process helper test (without bubblewrap, because CI containers have no user namespaces) and the CPU colour tests.Review
Three review rounds; the findings and decisions are in the PR comments. The fixes:
GlRenderkept on its thread;loadalways reads a file;watchcleanup.How to check