Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
72ea961
ALI-2420: The shared libmpv playback crate, with colour tests
michaelaguiar Dec 2, 2026
24c2c60
Review fixes: jailed exe, hidden file reads, stale duration, GL thread
michaelaguiar Dec 2, 2026
827a83c
Review fixes: clear the end with the file, and always load a file
michaelaguiar Dec 2, 2026
823293b
GPU helper prototype: libmpv on the card, frames handed over as dmabufs
michaelaguiar Dec 2, 2026
a144571
GPU helper prototype: show its dmabufs on a compositor
michaelaguiar Dec 2, 2026
356a4bc
GPU helper: hardware decoding and jail grants chosen per card maker
michaelaguiar Dec 2, 2026
6206e15
GPU helper: lock down first, start libmpv beside OpenGL, buffers read…
michaelaguiar Dec 2, 2026
65507db
GPU colour bench: Alias View's own path, the jailed helper's dmabufs
michaelaguiar Dec 2, 2026
708d7dd
GPU helper: draw before reporting the state, so the last frame isn't …
michaelaguiar Dec 2, 2026
5cb98b2
GPU helper: run on Debian and on Intel (found on the Proxmox UHD 770)
michaelaguiar Dec 2, 2026
d875f80
Merge remote-tracking branch 'origin/main' into ali-2358-gpu-helper
michaelaguiar Dec 2, 2026
8bd9374
GPU jail: no new user namespaces, no mounts
michaelaguiar Dec 2, 2026
9e283a3
GPU helper: a debug mode that sends libmpv's log and start-up timings
michaelaguiar Dec 2, 2026
da3be7f
GPU jail: seccomp instead of --disable-userns, so it starts in LXC
michaelaguiar Dec 2, 2026
de0ac55
GPU helper: hardware decoding that ends a file early falls back to so…
michaelaguiar Dec 2, 2026
cead247
GPU helper: VA-API gets the card opened again, not OpenGL's descriptor
michaelaguiar Dec 2, 2026
06114d8
GPU helper: fixes from #3's review
michaelaguiar Dec 2, 2026
ecae017
GPU helper prototype: start warm, before a file is chosen
michaelaguiar Dec 2, 2026
2e9495d
GPU helper: make buffers with an iterator, for Rust 1.100's clippy
michaelaguiar Dec 2, 2026
237de75
GPU helper: fixes from the first review round of #2
michaelaguiar Dec 2, 2026
7f6a58d
GPU helper: draw the current frame when playback starts, so covers show
michaelaguiar Dec 2, 2026
a8024d8
Player: watch the picture's size, decoder and dropped frames
michaelaguiar Dec 2, 2026
8937853
Player: requests and reads that never wait on libmpv's core
michaelaguiar Dec 2, 2026
df646d2
Player: answers belong to the file they were asked about
michaelaguiar Dec 2, 2026
15e5e9e
Player and GPU helper: fixes from review round 3
michaelaguiar Dec 2, 2026
6c0187c
Release GPU setup on every error path and check the framebuffer when …
michaelaguiar Dec 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ harness = false

[dev-dependencies]
# The helper test's cancel signal, an eventfd, as an app's would be.
rustix = { version = "1.1.6", features = ["event"] }
rustix = { version = "1.1.6", features = ["event", "pipe"] }
# The GPU colour bench opens EGL at run time, as the crate opens libmpv.
libc = "0.2.191"
# The GPU helper prototype's Wayland app (examples/gpu-show.rs), as Alias View uses them.
wayland-client = "0.31.15"
wayland-protocols = { version = "0.32.13", features = ["client", "unstable", "staging"] }
86 changes: 80 additions & 6 deletions examples/colour-gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::process::ExitCode;
use std::sync::OnceLock;
use std::time::{Duration, Instant};

use alias_playback::{Event, GlRender, Hwdec, Options, Player, RenderPath};
use alias_playback::{Event, GlRender, Hwdec, Native, Options, Player, RenderPath};
use clips::{HEIGHT, TOLERANCE, WIDTH, cases, check_the_maths, decoder, make_clip, misses, play_cpu};

type EglDisplay = *mut c_void;
Expand Down Expand Up @@ -181,7 +181,7 @@ fn play(gl: &Gl, clip: &Path, hwdec: Hwdec) -> Result<(Vec<u32>, String), String
let player = Player::new(&options).map_err(|e| e.to_string())?;
// SAFETY: the context is current on this thread for as long as the renderer lives, and the
// lookup finds its functions.
let mut render = unsafe { GlRender::new(&player, get_proc_address, std::ptr::null_mut(), None) }.map_err(|e| e.to_string())?;
let mut render = unsafe { GlRender::new(&player, get_proc_address, std::ptr::null_mut(), Native::None) }.map_err(|e| e.to_string())?;
// `COLOUR_GPU_LOG=FILE` keeps libmpv's log of the last case run, for a case that fails.
if let Some(log) = std::env::var_os("COLOUR_GPU_LOG") {
use std::os::unix::ffi::OsStrExt;
Expand All @@ -206,7 +206,53 @@ fn play(gl: &Gl, clip: &Path, hwdec: Hwdec) -> Result<(Vec<u32>, String), String
Err("no frame within 20 seconds".into())
}

const HELPER_ARG: &str = "--gpu-helper";

/// The first frame of `clip` as the jailed GPU helper draws it into a dmabuf, read back by
/// `reader` on this side, as Alias View will show it, and the decoder it used.
fn play_helper(reader: &alias_playback::gpu::Gpu, clip: &Path, vendor: alias_playback::Vendor, hwdec: bool) -> Result<(Vec<u32>, String), String> {
use alias_playback::gpu_helper::{self, Said};
let exe = alias_playback::jail::own_exe().map_err(|e| e.to_string())?;
let mut command = std::process::Command::new("bwrap");
command.args(alias_playback::jail::gpu_arguments(&exe, vendor)).arg(HELPER_ARG).arg(if hwdec { format!("{vendor:?}") } else { "software".into() });
let node = alias_playback::gpu::first_render_node()?;
let file = std::fs::File::open(clip).map_err(|e| e.to_string())?;
let mut started = gpu_helper::start(command, file, node, (WIDTH as u32, HEIGHT as u32), false).map_err(|e| e.to_string())?;
let mut buffers: Vec<Option<(Said, std::os::fd::OwnedFd)>> = vec![None, None, None];
let mut pixels = None;
let result = loop {
let Ok(Some((text, mut fds))) = gpu_helper::receive(&started.socket) else { break Err("the helper stopped".to_owned()) };
match gpu_helper::parse_said(&text) {
Some(said @ Said::Buffer { slot, .. }) if fds.len() == 1 => buffers[slot] = Some((said, fds.remove(0))),
Some(Said::Frame { slot }) if pixels.is_none() => {
let Some((Said::Buffer { width, height, modifier, stride, offset, .. }, fd)) = &buffers[slot] else { break Err("a frame in no buffer".into()) };
let planes = [alias_playback::gpu::Plane { fd: fd.try_clone().map_err(|e| e.to_string())?, stride: *stride, offset: *offset }];
pixels = Some(reader.read_dmabuf(*width, *height, *modifier, &planes)?);
}
Some(Said::Decoder(name)) => break pixels.take().map(|p| (p, name)).ok_or_else(|| "no frame".to_owned()),
Some(Said::CantPlay | Said::NoVideo) => break Err(text),
_ => {}
}
};
drop(started.socket);
let _ = started.child.wait();
result
}

fn main() -> ExitCode {
let args: Vec<String> = std::env::args().skip(1).collect();
if args.first().map(String::as_str) == Some(HELPER_ARG) {
let hwdec = match args.get(1).map(String::as_str) {
Some("Nvidia") => Hwdec::For(alias_playback::Vendor::Nvidia),
Some("Amd") => Hwdec::For(alias_playback::Vendor::Amd),
Some("Intel") => Hwdec::For(alias_playback::Vendor::Intel),
Some("Apple") => Hwdec::For(alias_playback::Vendor::Apple),
Some("Other") => Hwdec::For(alias_playback::Vendor::Other),
_ => Hwdec::Off,
};
let options = Options { render: RenderPath::Gpu, hwdec, ..Options::cpu() };
alias_playback::gpu_helper::run(&args[2..], &options, 6, alias_playback::jail::lock_down_gpu_helper);
}
check_the_maths();
let filters: Vec<String> = std::env::args().skip(1).filter(|a| !a.starts_with('-')).collect();
// SAFETY: this thread keeps the context current until the process ends.
Expand All @@ -223,8 +269,25 @@ fn main() -> ExitCode {
eprintln!("can't make {}: {e}", dir.display());
return ExitCode::FAILURE;
}
println!("\n{} colour cases, GPU renderer on {}, tolerance {TOLERANCE} steps:\n", cases.len(), gl.renderer);
let vendor = alias_playback::gpu::first_render_node().map_or(alias_playback::Vendor::Other, |node| alias_playback::gpu::vendor(&node));
println!("\n{} colour cases, GPU renderer on {} ({vendor:?}), tolerance {TOLERANCE} steps:\n", cases.len(), gl.renderer);
let (mut failed, mut skipped) = (0, 0);
// The jailed helper's frames are read back on a thread of their own, with an OpenGL
// context of its own on the same card.
let (to_reader, clips) = std::sync::mpsc::channel::<(std::path::PathBuf, bool)>();
let (to_main, read) = std::sync::mpsc::channel::<Result<(Vec<u32>, String), String>>();
std::thread::spawn(move || {
let reader = alias_playback::gpu::first_render_node().and_then(alias_playback::gpu::Gpu::new);
for (clip, hwdec) in clips {
let result = match &reader {
Ok(reader) => play_helper(reader, &clip, vendor, hwdec),
Err(e) => Err(e.clone()),
};
if to_main.send(result).is_err() {
break;
}
}
});
for case in &cases {
let name = case.name();
let clip = match make_clip(case, &dir) {
Expand All @@ -249,10 +312,21 @@ fn main() -> ExitCode {
let mut problems = Vec::new();
// The GPU renderer with and without hardware decoding, and the software renderer with
// it, which CI can't try.
for (mode, render, hwdec) in [("GPU", RenderPath::Gpu, Hwdec::Off), ("GPU hwdec", RenderPath::Gpu, Hwdec::Auto), ("CPU hwdec", RenderPath::Cpu, Hwdec::Auto)] {
// Hardware decoding the way this card's maker does it, as a jailed player would.
let hwdec = Hwdec::For(vendor);
let modes = [
("GPU", Some(RenderPath::Gpu), Hwdec::Off),
("GPU hwdec", Some(RenderPath::Gpu), hwdec),
("CPU hwdec", Some(RenderPath::Cpu), hwdec),
("jailed helper", None, Hwdec::Off),
("jailed helper hwdec", None, hwdec),
];
for (mode, render, hwdec) in modes {
let played = match render {
RenderPath::Gpu => play(&gl, &clip, hwdec),
RenderPath::Cpu => play_cpu(&clip, (WIDTH, HEIGHT), hwdec, true),
Some(RenderPath::Gpu) => play(&gl, &clip, hwdec),
Some(RenderPath::Cpu) => play_cpu(&clip, (WIDTH, HEIGHT), hwdec, true),
// Alias View's own path: a jailed helper's dmabuf, read back on this side.
None => to_reader.send((clip.clone(), hwdec != Hwdec::Off)).map_err(|e| e.to_string()).and_then(|()| read.recv().map_err(|e| e.to_string())?),
};
match played {
Ok((pixels, decoder)) => {
Expand Down
Loading
Loading