Skip to content

About

One libmpv playback crate for Alias View, Gannet and Nitrate, with colour tests

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

alias-playback

One libmpv playback crate for Alias View, Gannet and Nitrate (ALI-2420). It wraps libmpv once, keeps the colour settings in one place so a fix reaches every app at once, and proves the colours with tests.

libmpv stays the decoder and player (decided 2026-11-30). This crate doesn't decode anything itself.

What's in it

Module What it does
Player (player.rs) One libmpv player, set up from Options. Commands (load, play, pause, seek, volume, mute) and the events every app needs: position, duration, pause, volume, mute, end, failure.
SwRender, GlRender (render.rs) Drawing frames on the CPU into memory (Wayland's XRGB8888, ready for wl_shm), or with OpenGL into the app's framebuffer.
Options, options::colour (options.rs) The setup every app shares, the few choices that differ (render path, hardware decoding, sound, cover art), and the colour settings for each render path.
helper (helper.rs) A player in another process, drawing on the CPU into shared memory, with its state as short lines of text. Both sides: the app's (start, watch, Frames, Remote) and the player's (run). Moved here from Gannet's preview.
jail (jail.rs) The bubblewrap jail for that process, as Gannet's preview uses it. The app adds its own seccomp filter through helper::run's lock_down.

The same in every app

  • A video stops on its last frame, paused, instead of closing (keep-open). Play after the end starts again from the beginning.
  • Nothing of the user's own mpv setup is read: no mpv.conf, scripts, profiles or saved positions. Nothing beside the file is looked for (subtitles, sound, cover art, the chapters a Matroska file can borrow from others, the files a playlist names), and nothing is fetched online.
  • No on-screen display or key bindings: the app draws the controls.
  • Hardware decoding, when on, tries NVDEC, VA-API, then V4L2, and falls back to the CPU. VDPAU is left out: on NVIDIA it takes H.264 4:4:4, fails every frame, and never falls back, so the video never starts. The software renderer gets the copy-back methods only.

libmpv is opened at run time (libmpv.so.2, client API 2.x), so an app using this starts without it and only loses playback.

Colour

options::colour holds the colour settings for each render path:

Path Setting Why
CPU vf=format=gamma=bt.1886 The software renderer's converter, zimg, lifts the darks of video tagged with the sRGB transfer (ALI-2418). It also lifts full-range video with no transfer tag, which the colour tests found. Labelling every picture BT.1886 first fixes both; the other SDR tags come out the same either way.
GPU none The OpenGL renderer draws every SDR tag correctly as it is.

The colour tests

tests/colour.rs (CPU, in CI) and examples/colour-gpu.rs (GPU, a bench step) play the same 51 clips. Each clip is a 4x4 grid of solid patches: black, white, greys, the primaries and secondaries, three skin tones, and Tarnished's #121C24.

  • Cases: all 27 combinations of range (limited, full, full as yuvj), matrix (BT.601, BT.709, BT.2020) and transfer tag (BT.709, sRGB, none) on H.264; H.264, HEVC, VP9 and AV1 each at 8 and 10 bits, 4:2:0 and 4:4:4; and each codec with full range and with the sRGB tag.
  • Expected values come from the source RGB. The test works out each clip's Y'CbCr itself (ITU-T H.273) and FFmpeg encodes it losslessly, converting nothing. Before a clip is played, ffprobe must read back the case's tags, and FFmpeg must decode it back to that Y'CbCr exactly. A failure is then the player's, never the clip's.
  • Pass: every pixel inside every patch (16 px in from the edges) within 2 steps per channel of its source colour.
  • The CPU run draws each clip at full and half size, and once more without the colour settings, printing what they fix.
  • The GPU run draws each clip with OpenGL (no hardware decoding, then hardware decoding) and with the software renderer plus hardware decoding. It runs off-screen on EGL's device platform, with no window or compositor. It reports which decoder libmpv used.

Not covered yet: HDR (PQ, HLG), which tone-maps by design and needs its own reference with a wider tolerance; real recordings from wf-recorder (M1) and gpu-screen-recorder (desktop) checked against screenshots taken at the same moment; and primaries other than BT.709.

Results, 2026-12-02 (libmpv 0.42.0, FFmpeg 9.1)

Machine Renderer Result
Desktop, x86_64 CPU, no hardware decoding (as CI runs it) 51 of 51
Desktop, RTX 4090 GPU, no hardware decoding 51 of 51
Desktop, RTX 4090 GPU, hardware decoding (NVDEC for 44 clips, the CPU for 7 it can't take) 51 of 51
Desktop, RTX 4090 CPU, hardware decoding (NVDEC copy-back) 51 of 51
M1 Max, Asahi GPU, with and without hardware decoding; CPU with it (all decoded on the CPU) 49 of 49; 2 skipped

The M1's 2 skipped clips are 10-bit HEVC: its libx265 is 8-bit only, so it can't make them. Without the CPU colour setting, the sRGB-tagged clips and the full-range clips with no transfer tag draw up to 13 steps too light (#121C24 as #1E2831).

Using it

use alias_playback::{Event, Options, Player, SwFormat, SwRender};

let player = Player::new(&Options::cpu())?;
let mut render = SwRender::new(&player)?;
player.on_wakeup(|| { /* wake the thread that reads events */ });
render.on_update(|| { /* wake the thread that draws */ });
player.load(path)?;
player.set_paused(false)?;
// On the drawing thread, when woken:
if render.new_frame() {
    render.render(width, height, stride, SwFormat::Bgr0, buffer)?;
}
// On the event thread, when woken:
while let Some(event) = player.next_event() {
    match event {
        Event::Position(seconds) => { /* … */ }
        Event::Ended(true) => { /* stopped on its last frame */ }
        _ => {}
    }
}

A jailed player: the app's main calls helper::run(args, &options, SANDBOX_CODE, lock_down) when started with its helper argument, and starts one with helper::start(jail::command(HELPER_ARG, sound)?, file, size, sound).

A jailed GPU player (gpu_helper) is started with jail::gpu_arguments(exe, vendor, jail::sound_socket().as_deref()) and plays sound with Audio::Pulse. That binds the session's PulseAudio socket read-only, as the CPU helper does, and never PipeWire's own socket. Once a file has loaded, it says the file's title, artist and album, if it has them, as meta messages, cleaned by gpu_helper::clean_meta. Control characters, bidirectional overrides, isolates and marks are taken out, and each tag is cut to 160 bytes.

Checks

make check        # fmt, clippy, unit tests, the helper test and the CPU colour tests
make colour-gpu   # the GPU bench, on a machine with a graphics card

Both need ffmpeg and ffprobe (with libx264, libx265, libvpx and libaom) and libmpv. The helper test runs a real player in another process, without the jail: bubblewrap needs user namespaces, which CI's containers don't give.

Dependencies

Crate Why
libc dlopen for libmpv, and the calls a helper needs: dup2, close_range, prctl.
rustix Shared memory (memfd, mmap), pipes and poll for a helper's frames and messages.

Licence

MIT. Copyright (c) 2026 Alias Project, Inc.

About

One libmpv playback crate for Alias View, Gannet and Nitrate, with colour tests

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages