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.
172 lines
6.0 KiB
Rust
172 lines
6.0 KiB
Rust
//! Runs the `MediaPlayer` conformance suite against a real engine.
|
|
//!
|
|
//! A separate binary on purpose: it links libmpv and nothing else, so a wrapper
|
|
//! can be verified without building or launching the app — which is what made
|
|
//! the previous round of playback debugging so slow. Every failure here is a
|
|
//! wrapper bug, with no UI, no webview and no server in the way.
|
|
//!
|
|
//! cargo run --features conformance --bin player-conformance -- <media-file>
|
|
//!
|
|
//! Audio and video are routed to null, so it is safe on a headless runner and
|
|
//! does not claim the speakers.
|
|
//!
|
|
//! TRACES: UR-081 | DR-244
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
use crate::player::conformance::Harness;
|
|
use crate::player::legacy_player::LegacyPlayer;
|
|
use crate::player::media::MediaItem;
|
|
use crate::player::media_player::{MediaPlayer, OpenRequest, Phase};
|
|
use crate::player::mpv_backend::MpvBackend;
|
|
use crate::player::mpv_player::{MpvPlayer, Output};
|
|
use crate::repository::stream_selection::StreamSelection;
|
|
|
|
struct EngineHarness<P: MediaPlayer> {
|
|
player: P,
|
|
url: String,
|
|
}
|
|
|
|
impl<P: MediaPlayer> Harness for EngineHarness<P> {
|
|
type Player = P;
|
|
|
|
fn player(&mut self) -> &mut P {
|
|
&mut self.player
|
|
}
|
|
|
|
fn request(&self, start: Duration) -> OpenRequest {
|
|
let selection = StreamSelection::local_file(self.url.clone());
|
|
let media = MediaItem::sample("conformance", &self.url);
|
|
OpenRequest::new(media, selection).starting_at(start)
|
|
}
|
|
|
|
/// Wait for mpv to leave `Opening`.
|
|
///
|
|
/// Polling a phase the engine publishes, not a fixed sleep: a suite whose
|
|
/// result depends on how fast the machine is will eventually be ignored.
|
|
fn settle(&mut self) {
|
|
let deadline = Instant::now() + Duration::from_secs(15);
|
|
while Instant::now() < deadline {
|
|
if self.player.snapshot().phase != Phase::Opening {
|
|
// Let the deferred seek land and one position tick arrive.
|
|
std::thread::sleep(Duration::from_millis(300));
|
|
return;
|
|
}
|
|
std::thread::sleep(Duration::from_millis(25));
|
|
}
|
|
eprintln!(" ! settle timed out - engine stayed in Opening");
|
|
}
|
|
|
|
/// mpv is on a null audio device here, so silence cannot be observed.
|
|
/// Reporting `None` skips those assertions rather than passing them
|
|
/// vacuously — an assertion that cannot fail is worse than an absent one.
|
|
fn audible(&mut self) -> Option<bool> {
|
|
None
|
|
}
|
|
|
|
/// Keyframe granularity: mpv lands on the nearest one, not on the request.
|
|
fn seek_tolerance(&self) -> Duration {
|
|
Duration::from_secs(10)
|
|
}
|
|
|
|
/// Poll until the decoder reports the new position, rather than assuming a
|
|
/// seek is visible the instant it is accepted.
|
|
fn await_seek(&mut self, target: Duration) {
|
|
let deadline = Instant::now() + Duration::from_secs(10);
|
|
while Instant::now() < deadline {
|
|
let pos = self.player.snapshot().position;
|
|
if pos.abs_diff(target) <= self.seek_tolerance() {
|
|
return;
|
|
}
|
|
std::thread::sleep(Duration::from_millis(50));
|
|
}
|
|
}
|
|
}
|
|
|
|
macro_rules! run {
|
|
($failed:ident, $url:expr, $make:expr, $case:path) => {{
|
|
let name = stringify!($case).rsplit("::").next().unwrap();
|
|
print!(" {name:.<52}");
|
|
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
|
let mut h = EngineHarness {
|
|
player: $make,
|
|
url: $url.to_string(),
|
|
};
|
|
$case(&mut h);
|
|
// Leave nothing playing behind for the next case.
|
|
let _ = h.player.close();
|
|
}));
|
|
match result {
|
|
Ok(()) => println!(" ok"),
|
|
Err(_) => {
|
|
println!(" FAILED");
|
|
$failed += 1;
|
|
}
|
|
}
|
|
}};
|
|
}
|
|
|
|
/// Which engine to interrogate.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum Engine {
|
|
/// The `MediaPlayer` implementation.
|
|
Mpv,
|
|
/// The old `PlayerBackend`, driven through `LegacyPlayer`.
|
|
///
|
|
/// Present so the difference between the two designs can be *demonstrated*
|
|
/// on the same engine and the same media, rather than argued.
|
|
Legacy,
|
|
}
|
|
|
|
/// Run every conformance case against `engine`. Returns the failure count.
|
|
pub fn run_engine(url: &str, engine: Engine) -> u32 {
|
|
println!("MediaPlayer conformance - {engine:?}");
|
|
println!("media: {url}\n");
|
|
|
|
let mut failed = 0u32;
|
|
use crate::player::conformance as c;
|
|
|
|
macro_rules! all_cases {
|
|
($make:expr) => {
|
|
run!(failed, url, $make, c::opens_from_the_beginning);
|
|
run!(failed, url, $make, c::opens_at_a_start_position);
|
|
run!(failed, url, $make, c::seek_while_opening_is_honoured);
|
|
run!(failed, url, $make, c::seek_while_opening_overrides_start);
|
|
run!(failed, url, $make, c::seeks_after_open);
|
|
run!(failed, url, $make, c::pause_and_play_are_observable);
|
|
run!(failed, url, $make, c::close_is_silent_and_idempotent);
|
|
run!(failed, url, $make, c::close_during_open_never_plays);
|
|
run!(failed, url, $make, c::transport_settings_round_trip);
|
|
};
|
|
}
|
|
|
|
match engine {
|
|
Engine::Mpv => {
|
|
all_cases!(MpvPlayer::new(Output::Null).expect("could not create mpv"));
|
|
}
|
|
Engine::Legacy => {
|
|
all_cases!(LegacyPlayer::new(
|
|
MpvBackend::new(
|
|
None,
|
|
std::sync::Arc::new(tokio::sync::Mutex::new(None)),
|
|
std::sync::Arc::new(crate::playback_reporting::throttle::EventThrottler::new()),
|
|
)
|
|
.expect("could not create the legacy backend"),
|
|
crate::player::media_player::Capabilities::mpv(),
|
|
));
|
|
}
|
|
}
|
|
|
|
if failed == 0 {
|
|
println!("\nall cases passed");
|
|
} else {
|
|
println!("\n{failed} case(s) failed");
|
|
}
|
|
failed
|
|
}
|
|
|
|
/// Default entry point: the new engine.
|
|
pub fn run(url: &str) -> u32 {
|
|
run_engine(url, Engine::Mpv)
|
|
}
|