Skip to main content

jellytau_lib/player/
native_video.rs

1//! Whether this process renders video natively, answered once.
2//!
3//! Three things need this and must agree: the mpv backend (which has to be
4//! configured for video *at construction*, before anything plays), the video
5//! surface (which has nothing to draw otherwise), and the device profile.
6//!
7//! It is a function rather than three `env::var` checks for the reason this
8//! codebase keeps rediscovering: a capability answered in several places is a
9//! capability whose answers drift. Four separate bugs this cycle came from
10//! exactly that shape — a webview's decode limits applied to ExoPlayer, a
11//! transcode target contradicting a direct-play claim, a codec list hardcoded in
12//! a URL builder. One source, read by everyone.
13//!
14//! TRACES: UR-080 | DR-231, DR-235
15
16/// Whether mpv should decode and draw video in this process.
17///
18/// True wherever mpv is the desktop video renderer: Linux since DR-235 phase 1,
19/// Windows since DR-237. There is no opt-out and no webview fallback — the
20/// webview `<video>` path is gone, so "off" would leave nothing drawing the
21/// picture. It was the `JELLYTAU_NATIVE_VIDEO` opt-in while the render path was
22/// being proven; the variable is ignored.
23///
24/// TRACES: UR-080 | DR-231, DR-235
25pub fn enabled() -> bool {
26    // On Android ExoPlayer draws video and `use_html5_element` is false for
27    // entirely separate reasons.
28    cfg!(any(target_os = "linux", target_os = "windows"))
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    /// mpv draws video on Linux and Windows with nothing to opt into, and the retired
36    /// variable cannot opt back out: with the webview path gone, "off"
37    /// would configure mpv for audio only with nothing else to draw the picture.
38    ///
39    /// TRACES: UR-080 | DR-235, DR-237 | UT-271
40    #[test]
41    fn desktop_always_renders_video_natively() {
42        let restore = std::env::var("JELLYTAU_NATIVE_VIDEO").ok();
43
44        for value in [None, Some("0"), Some("false"), Some("1")] {
45            match value {
46                Some(v) => std::env::set_var("JELLYTAU_NATIVE_VIDEO", v),
47                None => std::env::remove_var("JELLYTAU_NATIVE_VIDEO"),
48            }
49            assert_eq!(
50                enabled(),
51                cfg!(any(target_os = "linux", target_os = "windows")),
52                "JELLYTAU_NATIVE_VIDEO={value:?} must not decide the renderer"
53            );
54        }
55
56        match restore {
57            Some(v) => std::env::set_var("JELLYTAU_NATIVE_VIDEO", v),
58            None => std::env::remove_var("JELLYTAU_NATIVE_VIDEO"),
59        }
60    }
61}