feat(player): native video on Linux, and one contract for every player (v0.11.0)
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.
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
//! A [`MediaPlayer`] over the old [`PlayerBackend`] trait.
|
||||
//!
|
||||
//! Two purposes.
|
||||
//!
|
||||
//! **Migration.** Engines not yet ported — ExoPlayer, the webview element, the
|
||||
//! null backend — keep working while `PlayerController` moves onto the new
|
||||
//! contract (DR-245). Without this the port would have to land all four engines
|
||||
//! at once.
|
||||
//!
|
||||
//! **Evidence.** It reproduces exactly what every caller used to do: `load`,
|
||||
//! then `play`, then `seek` for a start position. Running the conformance suite
|
||||
//! against it therefore shows the old path failing the cases the new one passes,
|
||||
//! on the same engine and the same media — which is the difference between
|
||||
//! asserting that a design was wrong and demonstrating it.
|
||||
//!
|
||||
//! It is deliberately a faithful reproduction, not a fixed-up one. Making it
|
||||
//! pass would defeat the point.
|
||||
//!
|
||||
//! TRACES: UR-081 | DR-245
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use super::backend::{PlayerBackend, PlayerError};
|
||||
use super::media_player::{
|
||||
duration_from_secs, Capabilities, MediaPlayer, OpenRequest, Phase, PlaybackSnapshot,
|
||||
};
|
||||
use super::state::PlayerState;
|
||||
|
||||
pub struct LegacyPlayer<B: PlayerBackend> {
|
||||
inner: B,
|
||||
/// Declared at construction: this wrapper is generic over engines with very
|
||||
/// different abilities, and only the composition root knows which one it
|
||||
/// just built. Guessing here would reintroduce exactly the inference DR-238
|
||||
/// removed.
|
||||
capabilities: Capabilities,
|
||||
/// The old trait has no notion of "opening", so this is the best the wrapper
|
||||
/// can do: it knows an item was handed over, not whether the engine is ready
|
||||
/// for one. That gap is the whole problem.
|
||||
has_item: bool,
|
||||
}
|
||||
|
||||
impl<B: PlayerBackend> LegacyPlayer<B> {
|
||||
pub fn new(inner: B, capabilities: Capabilities) -> Self {
|
||||
Self {
|
||||
inner,
|
||||
capabilities,
|
||||
has_item: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: PlayerBackend + Send> MediaPlayer for LegacyPlayer<B> {
|
||||
/// Load, play, then seek — the sequence every caller used to write.
|
||||
///
|
||||
/// The seek is issued immediately, because a caller has no way to know when
|
||||
/// the engine becomes ready. On an engine whose load is asynchronous it
|
||||
/// fails and is discarded, and playback begins at zero: DR-241, reproduced.
|
||||
fn open(&mut self, req: OpenRequest) -> Result<(), PlayerError> {
|
||||
self.inner.load(&req.media)?;
|
||||
self.has_item = true;
|
||||
if req.autoplay {
|
||||
self.inner.play()?;
|
||||
}
|
||||
if !req.start.is_zero() {
|
||||
// Faithfully ignoring the failure, exactly as the old callers did.
|
||||
let _ = self.inner.seek(req.start.as_secs_f64());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn play(&mut self) -> Result<(), PlayerError> {
|
||||
self.inner.play()
|
||||
}
|
||||
|
||||
fn pause(&mut self) -> Result<(), PlayerError> {
|
||||
self.inner.pause()
|
||||
}
|
||||
|
||||
fn close(&mut self) -> Result<(), PlayerError> {
|
||||
self.has_item = false;
|
||||
self.inner.stop()
|
||||
}
|
||||
|
||||
fn seek(&mut self, to: Duration) -> Result<(), PlayerError> {
|
||||
self.inner.seek(to.as_secs_f64())
|
||||
}
|
||||
|
||||
fn set_volume(&mut self, volume: f32) -> Result<(), PlayerError> {
|
||||
self.inner.set_volume(volume)
|
||||
}
|
||||
|
||||
/// The old trait has no mute. Folding it into volume would lose the user's
|
||||
/// level, so this reports unsupported rather than pretending.
|
||||
fn set_muted(&mut self, _muted: bool) -> Result<(), PlayerError> {
|
||||
Err(PlayerError {
|
||||
message: "mute is not supported by this backend".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn set_rate(&mut self, _rate: f64) -> Result<(), PlayerError> {
|
||||
Err(PlayerError {
|
||||
message: "playback rate is not supported by this backend".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn select_audio_track(&mut self, index: Option<i32>) -> Result<(), PlayerError> {
|
||||
self.inner.set_audio_track(index.unwrap_or(-1))
|
||||
}
|
||||
|
||||
fn select_subtitle_track(&mut self, index: Option<i32>) -> Result<(), PlayerError> {
|
||||
self.inner.set_subtitle_track(index)
|
||||
}
|
||||
|
||||
fn snapshot(&self) -> PlaybackSnapshot {
|
||||
let phase = match self.inner.state() {
|
||||
_ if !self.has_item => Phase::Idle,
|
||||
PlayerState::Playing { .. } => Phase::Playing,
|
||||
PlayerState::Paused { .. } => Phase::Paused,
|
||||
PlayerState::Idle => Phase::Idle,
|
||||
PlayerState::Error { error, .. } => Phase::Failed(error),
|
||||
// `Loading` is the closest the old trait comes to an opening state,
|
||||
// but it is set once the engine has accepted the item rather than
|
||||
// while it is still accepting it — which is precisely the window it
|
||||
// cannot describe.
|
||||
PlayerState::Loading { .. } | PlayerState::Seeking { .. } => Phase::Ready,
|
||||
};
|
||||
PlaybackSnapshot {
|
||||
phase,
|
||||
position: duration_from_secs(self.inner.position()).unwrap_or(Duration::ZERO),
|
||||
duration: self.inner.duration().and_then(duration_from_secs),
|
||||
seekable: true,
|
||||
volume: self.inner.volume(),
|
||||
muted: false,
|
||||
rate: 1.0,
|
||||
audio_track: None,
|
||||
subtitle_track: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn set_audio_settings(
|
||||
&mut self,
|
||||
settings: &crate::settings::AudioSettings,
|
||||
) -> Result<(), PlayerError> {
|
||||
self.inner.set_audio_settings(settings)
|
||||
}
|
||||
|
||||
fn audio_settings(&self) -> crate::settings::AudioSettings {
|
||||
self.inner.audio_settings()
|
||||
}
|
||||
|
||||
fn capabilities(&self) -> Capabilities {
|
||||
self.capabilities
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user