//! What this editor can really decode and encode, in one place and in two //! halves. //! //! The *software* half is what this binary was built with: a table, because //! "is `rav1e` linked into this build" is a question the build already answered //! and probing for it would only be a slower way of reading the manifest. //! //! The *hardware* half is a different answer on every machine and is therefore //! never a table: [`crate::hw::caps`] asks the plugin, the plugin asks the //! driver, and what comes back is the intersection of the GPU's entrypoints //! with the codecs the plugin implements. No plugin, an older plugin or no //! driver all read the same way -- "software only" -- because that is what they //! mean for the file a user is about to write. //! //! VP8 is deliberately on neither line: the plugin decodes it on its own //! native `ec-vp8`, always present, and reports `CAP_VP8` for it -- the //! plugin's seat, never the GPU's. [`HW_CODECS`] does not carry the bit, //! because this file's one job is not presenting a seat as a GPU feat that //! no GPU has. use crate::hw::{CAP_AV1, CAP_H264, CAP_HEVC, CAP_VP9, VhCaps}; /// The codecs a hardware line can name, in the order it lists them. const HW_CODECS: [(u32, &str); 4] = [ (CAP_H264, "H.264"), (CAP_HEVC, "HEVC"), (CAP_VP9, "VP9"), (CAP_AV1, "AV1"), ]; /// The software half: the codec, the crate that carries it here, and which /// halves of the job that crate does. Named crates rather than a bare "SW", /// because the answer to "why is my HEVC file so large" is `ec-h265 intra`, /// and the row that says so is the row that answers it. const SW_CODECS: [(&str, &str, bool, bool); 10] = [ ("H.264", "ec-h264", true, true), ("HEVC", "ec-h265 intra", false, true), ("AV1", "rav1e", false, true), // Decode is split by width: symphonia carries stereo and narrower, `ec-aac` // everything wider; the encoder is `ec-aac` as well. ("AAC", "symphonia / ec-aac / ec-aac", true, true), ("MP3", "symphonia / ec-mp3", true, true), ("FLAC", "symphonia / flacenc", true, true), ("PCM", "symphonia / hound", true, true), ("AC-3", "ec-ac3", true, false), ("Vorbis", "symphonia / ec-vorbis", true, true), ("ALAC", "symphonia", true, false), ]; /// The hardware line as a front-end shows it: one measurement per process, /// costing the plugin's VA-API init (~90 ms) the first time. Ask it off a /// render thread. pub fn hardware() -> String { hw_line(crate::hw::caps()) } /// The software line. Pure and constant -- a caller may ask it per repaint. pub fn software() -> String { SW_CODECS .iter() .map(|&(name, krate, decodes, encodes)| { format!("{name} {} ({krate})", seats(decodes, encodes)) }) .collect::>() .join(" · ") } /// What the plugin answered, in words. Separate from [`hardware`] so the /// wording can be tested against a machine this test suite does not have. fn hw_line(caps: Option) -> String { let Some(caps) = caps else { return "none — no plugin, no driver, or a plugin too old to say".to_string(); }; let listed: Vec = HW_CODECS .iter() .filter(|&&(bit, _)| caps.decode & bit != 0 || caps.encode & bit != 0) .map(|&(bit, name)| { let seats = seats(caps.decode & bit != 0, caps.encode & bit != 0); match caps.decode_10bit & bit != 0 { true => format!("{name} {seats} (10-bit)"), false => format!("{name} {seats}"), } }) .collect(); match listed.is_empty() { // A driver answered and takes none of the codecs this build carries: // not the same thing as no driver, and worth saying so. true => "none — the driver takes none of these codecs".to_string(), false => listed.join(" · "), } } /// Which halves of the job one seat does. Never both empty: a codec with /// neither is not listed at all. fn seats(decodes: bool, encodes: bool) -> &'static str { match (decodes, encodes) { (true, true) => "dec+enc", (true, false) => "dec", _ => "enc", } } #[cfg(test)] mod tests { use super::*; use crate::hw::CAP_VP8; #[test] fn the_hardware_line_says_what_the_plugin_answered_and_nothing_more() { // No answer at all -- no plugin, no driver, or one older than the // symbol -- is one line, and never an empty listing that would read as // "still loading". assert!(hw_line(None).starts_with("none —")); // A driver that answers with nothing is its own sentence. assert!(hw_line(Some(VhCaps::default())).starts_with("none —")); // This project's own GPU as `vainfo` lists it: H.264, HEVC and AV1 both // ways, VP9 decode only, and the 10-bit profiles on three of the four. // HEVC is an encode seat here as of the plugin's // `vh_enc_hevc_open_colour` -- // the 10-bit note beside it stays a *decode* claim, that seat coding // 8-bit Main whatever the source was. let radeonsi = VhCaps { decode: CAP_H264 | CAP_HEVC | CAP_VP9 | CAP_AV1, encode: CAP_H264 | CAP_HEVC | CAP_AV1, decode_10bit: CAP_HEVC | CAP_VP9 | CAP_AV1, }; assert_eq!( hw_line(Some(radeonsi)), "H.264 dec+enc · HEVC dec+enc (10-bit) · VP9 dec (10-bit) · AV1 dec+enc (10-bit)" ); // A codec the driver has neither seat for is left out rather than // listed as a refusal: this line is what the machine *can* do. let h264_only = VhCaps { decode: CAP_H264, ..Default::default() }; assert_eq!(hw_line(Some(h264_only)), "H.264 dec"); } /// The plugin's VP8 bit is its own native decoder (`ec-vp8`), lit /// unconditionally. However lit the mask is, the hardware line never /// reads it as a GPU seat -- and a mask holding nothing *but* it still /// reads as the nothing a driver without seats would answer. #[test] fn the_plugin_s_software_vp8_never_reads_as_a_gpu_seat() { let vpx_only = VhCaps { decode: CAP_VP8, ..Default::default() }; assert!(hw_line(Some(vpx_only)).starts_with("none —")); let with_gpu = VhCaps { decode: CAP_H264 | CAP_VP8, encode: CAP_H264, ..Default::default() }; assert_eq!(hw_line(Some(with_gpu)), "H.264 dec+enc"); } #[test] fn the_software_line_names_every_encoder_this_build_carries() { let line = software(); for name in ["ec-h264", "ec-h265 intra", "rav1e", "ec-aac"] { assert!(line.contains(name), "{name} missing from {line}"); } // Decode-only crates must not read as encoders, and the seat words are // the only thing saying which is which. assert!(line.contains("AC-3 dec (ec-ac3)")); assert!(line.contains("H.264 dec+enc (ec-h264)")); assert!(line.contains("HEVC enc (ec-h265 intra)")); } }