The VP8 decode seat is ec-vp8 native -- libvpx and its hand-written FFI are deleted, the plugin links the decoder as ordinary Rust (56 ec_vp8 symbols, no DT_NEEDED, no dlopen)
Browse files at this commit36bd0e7aac892873e9d5789b089aba0a309726c4Parent: ccfe87c- refactor
- the VP8 decode seat is ec-vp8 native -- libvpx and its hand-written FFI are deleted, the plugin links the decoder as ordinary Rust (56 ec_vp8 symbols, no DT_NEEDED, no dlopen)
- VpxSession keeps its five-verb boundary (init/decode/flush/get_frame, destroy now the drop of an owned decoder) and everything above it is untouched
- CAP_VP8 lights unconditionally and still never reads as a GPU seat
- A/B byte-exact against the libvpx seat on the 1280x720 fixture (60/60 frames), the 2560x1321 odd-size webm (270/270) and a two-pass auto-altref stream (90/90 shown, 6 hidden produce none, seek landings identical)
- vp8 twins 4/4, capability_matrix+backends+caps green, --all-targets 0 warnings
9 changed files +177 -396
- Cargo.lock +8 -1
- crates/engine-hw/Cargo.toml +4 -4
- crates/engine-hw/src/lib.rs +69 -102
- crates/engine-hw/src/vpx.rs +63 -258
- crates/engine/src/caps.rs +10 -9
- crates/engine/src/decode.rs +2 -2
- crates/engine/src/demux.rs +6 -6
- crates/engine/src/hw.rs +6 -5
- crates/engine/tests/vp8.rs +9 -9
Cargo.lockmodified+8 -1
| @@ -1648,6 +1648,13 @@ dependencies = [ | |||
| 1648 | "wide", | 1648 | "wide", |
| 1649 | ] | 1649 | ] |
| 1650 | 1650 | ||
| 1651 | +[[package]] | ||
| 1652 | +name = "ec-vp8" | ||
| 1653 | +version = "0.1.0" | ||
| 1654 | +dependencies = [ | ||
| 1655 | + "ec-core", | ||
| 1656 | +] | ||
| 1657 | + | ||
| 1651 | [[package]] | 1658 | [[package]] |
| 1652 | name = "edith" | 1659 | name = "edith" |
| 1653 | version = "0.1.0" | 1660 | version = "0.1.0" |
| @@ -1738,9 +1745,9 @@ name = "engine-hw" | |||
| 1738 | version = "0.1.0" | 1745 | version = "0.1.0" |
| 1739 | dependencies = [ | 1746 | dependencies = [ |
| 1740 | "cros-codecs", | 1747 | "cros-codecs", |
| 1748 | + "ec-vp8", | ||
| 1741 | "engine", | 1749 | "engine", |
| 1742 | "gbm", | 1750 | "gbm", |
| 1743 | - "libloading", | ||
| 1744 | ] | 1751 | ] |
| 1745 | 1752 | ||
| 1746 | [[package]] | 1753 | [[package]] |
crates/engine-hw/Cargo.tomlmodified+4 -4
| @@ -14,7 +14,7 @@ engine = { path = "../engine" } | |||
| 14 | cros-codecs = { version = "0.0.6", features = ["vaapi"] } | 14 | cros-codecs = { version = "0.0.6", features = ["vaapi"] } |
| 15 | # Same version cros-codecs already pulls in; we allocate output frames ourselves. | 15 | # Same version cros-codecs already pulls in; we allocate output frames ourselves. |
| 16 | gbm = { version = "0.15", default-features = false, features = ["drm-support"] } | 16 | gbm = { version = "0.15", default-features = false, features = ["drm-support"] } |
| 17 | -# Same version `engine` pins for its own dlopens (`hw.rs`, `ao.rs`); this is | 17 | +# The software VP8 seat, this project's own (`ec-vp8`, RFC 6386): linked in |
| 18 | -# the plugin's half of the same philosophy, one level down: `libvpx` for the | 18 | +# as ordinary Rust, the one codec with no runtime dlopen behind it -- the |
| 19 | -# software VP8 seat (`src/vpx.rs`), resolved at runtime like libva itself. | 19 | +# `libloading` the old libvpx FFI needed is gone with the FFI. |
| 20 | -libloading = "0.8" | 20 | +ec-vp8 = { path = "../../../edith_codecs/crates/ec-vp8" } |
crates/engine-hw/src/lib.rsmodified+69 -102
| @@ -1,10 +1,11 @@ | |||
| 1 | //! VA-API decode (H.264, HEVC, VP9 and AV1) -- and VP8, which decodes on | 1 | //! VA-API decode (H.264, HEVC, VP9 and AV1) -- and VP8, which decodes on |
| 2 | -//! `libvpx`, dlopen'd by this plugin in turn ([`vpx`], software, no VA-API | 2 | +//! `ec-vp8` ([`vpx`], this project's own, software, no VA-API anything), |
| 3 | -//! anything) -- and encode (H.264 and HEVC, and AV1 where the GPU has an | 3 | +//! linked into the plugin itself -- and encode (H.264 and HEVC, and AV1 |
| 4 | -//! entrypoint for it), shipped as a | 4 | +//! where the GPU has an entrypoint for it), shipped as a |
| 5 | //! `dlopen`-able plugin so the main binary never gets a DT_NEEDED on | 5 | //! `dlopen`-able plugin so the main binary never gets a DT_NEEDED on |
| 6 | -//! libva/gbm/drm -- nor on libvpx, the same rule one level down. Every entry | 6 | +//! libva/gbm/drm. VP8's seat is the one codec with no runtime dlopen |
| 7 | -//! point is | 7 | +//! behind it anywhere: the old libvpx FFI is gone with the library it |
| 8 | +//! loaded. Every entry point is | ||
| 8 | //! `extern "C"`, catches unwinds and reports failure as a null pointer or a | 9 | //! `extern "C"`, catches unwinds and reports failure as a null pointer or a |
| 9 | //! negative code: the caller's contract is "any failure means use the software | 10 | //! negative code: the caller's contract is "any failure means use the software |
| 10 | //! codec". | 11 | //! codec". |
| @@ -71,10 +72,7 @@ use cros_codecs::{Fourcc, FrameLayout, PlaneLayout, Resolution}; | |||
| 71 | use gbm::{BufferObjectFlags, Format as GbmFormat}; | 72 | use gbm::{BufferObjectFlags, Format as GbmFormat}; |
| 72 | 73 | ||
| 73 | use engine::demux::{Codec, Demuxer, VideoMeta}; | 74 | use engine::demux::{Codec, Demuxer, VideoMeta}; |
| 74 | -use engine::hw::{ | 75 | +use engine::hw::{CAP_AV1, CAP_H264, CAP_HEVC, CAP_VP8, CAP_VP9, VhCaps, VhDma, VhFrame, VhMeta}; |
| 75 | - CAP_AV1, CAP_H264, CAP_HEVC, CAP_VP8, CAP_VP9, VhCaps, VhDma, VhFrame, VhMeta, | ||
| 76 | -}; | ||
| 77 | -use vpx::VpxCtx; | ||
| 78 | 76 | ||
| 79 | type PooledFrame = PooledVideoFrame<GenericDmaVideoFrame>; | 77 | type PooledFrame = PooledVideoFrame<GenericDmaVideoFrame>; |
| 80 | type Dec<C> = StatelessDecoder<C, VaapiBackend<PooledFrame>>; | 78 | type Dec<C> = StatelessDecoder<C, VaapiBackend<PooledFrame>>; |
| @@ -872,19 +870,19 @@ impl OpenSession { | |||
| 872 | } | 870 | } |
| 873 | } | 871 | } |
| 874 | 872 | ||
| 875 | -/// One libvpx decode session: the VP8 half of the plugin, the whole of the | 873 | +/// One VP8 decode session: the VP8 half of the plugin, the whole of the |
| 876 | /// same job [`Session`] does for the VA-API codecs. No display, no GBM, no | 874 | /// same job [`Session`] does for the VA-API codecs. No display, no GBM, no |
| 877 | -/// surface pool -- libvpx hands the planes back in memory, and the only | 875 | +/// surface pool -- `ec-vp8` hands the planes back in memory, and the only |
| 878 | /// shapes worth carrying over from the other half are the ones the caller | 876 | /// shapes worth carrying over from the other half are the ones the caller |
| 879 | /// sees: [`VhMeta`], one picture per `pump`, the same [`VhFrame`] layout, the | 877 | /// sees: [`VhMeta`], one picture per `pump`, the same [`VhFrame`] layout, the |
| 880 | /// same skip/position arithmetic a seek is. | 878 | /// same skip/position arithmetic a seek is. |
| 881 | /// | 879 | /// |
| 882 | -/// VP8 reorders nothing: every access unit fed is one picture out, in feed | 880 | +/// VP8 reorders nothing: every access unit fed is *at most* one picture out, |
| 883 | -/// order, which is why `position` advances exactly as the VA-API half's does | 881 | +/// in feed order (a hidden altref frame produces none), which is why |
| 884 | -/// without any of its drain machinery. | 882 | +/// `position` advances exactly as the VA-API half's does without any of its |
| 883 | +/// drain machinery. | ||
| 885 | struct VpxSession { | 884 | struct VpxSession { |
| 886 | - vpx: &'static vpx::Vpx, | 885 | + dec: vpx::Decoder, |
| 887 | - ctx: VpxCtx, | ||
| 888 | demuxer: Demuxer, | 886 | demuxer: Demuxer, |
| 889 | meta: VhMeta, | 887 | meta: VhMeta, |
| 890 | flushed: bool, | 888 | flushed: bool, |
| @@ -905,10 +903,11 @@ struct VpxSession { | |||
| 905 | 903 | ||
| 906 | impl VpxSession { | 904 | impl VpxSession { |
| 907 | fn opened(meta: VideoMeta, demuxer: Demuxer) -> Option<Self> { | 905 | fn opened(meta: VideoMeta, demuxer: Demuxer) -> Option<Self> { |
| 908 | - let vpx = vpx::vpx()?; | 906 | + // The decoder cannot refuse to exist any more: it is linked in. The |
| 909 | - let mut session = Self { | 907 | + // `Option` is the shape [`OpenSession::open_at`] routes on, shared |
| 910 | - vpx, | 908 | + // with [`Session::opened`], whose failures are real. |
| 911 | - ctx: VpxCtx::default(), | 909 | + Some(Self { |
| 910 | + dec: vpx::Decoder::new(), | ||
| 912 | demuxer, | 911 | demuxer, |
| 913 | meta: VhMeta { | 912 | meta: VhMeta { |
| 914 | width: meta.width, | 913 | width: meta.width, |
| @@ -922,50 +921,30 @@ impl VpxSession { | |||
| 922 | out: Vec::new(), | 921 | out: Vec::new(), |
| 923 | luma: 0, | 922 | luma: 0, |
| 924 | chroma: 0, | 923 | chroma: 0, |
| 925 | - }; | 924 | + }) |
| 926 | - if let Err(e) = session.init() { | ||
| 927 | - eprintln!("engine_hw: {e}"); | ||
| 928 | - return None; | ||
| 929 | - } | ||
| 930 | - Some(session) | ||
| 931 | - } | ||
| 932 | - | ||
| 933 | - /// (Re-)initialises the decoder. libvpx has no mid-stream reset, so this | ||
| 934 | - /// *is* the flush: a seek pays destroy + init, and what makes that safe | ||
| 935 | - /// is the demuxer's sync-sample seek, which restarts the feed where the | ||
| 936 | - /// reference chain restarts -- the same discipline [`Session`]'s VA-API | ||
| 937 | - /// flush leans on. | ||
| 938 | - fn init(&mut self) -> Result<(), String> { | ||
| 939 | - self.vpx.dec_init(&mut self.ctx) | ||
| 940 | } | 925 | } |
| 941 | 926 | ||
| 942 | /// Feeds one access unit. VP8 emits at most one picture per unit, so the | 927 | /// Feeds one access unit. VP8 emits at most one picture per unit, so the |
| 943 | /// pull belongs to the `pump` loop, not here. | 928 | /// pull belongs to the `pump` loop, not here. |
| 944 | fn decode(&mut self, au: &[u8]) -> Result<(), String> { | 929 | fn decode(&mut self, au: &[u8]) -> Result<(), String> { |
| 945 | - if au.is_empty() { | 930 | + self.dec.decode(au) |
| 946 | - return Ok(()); | ||
| 947 | - } | ||
| 948 | - self.vpx.decode(&mut self.ctx, au) | ||
| 949 | } | 931 | } |
| 950 | 932 | ||
| 951 | fn pump(&mut self) -> Result<bool, String> { | 933 | fn pump(&mut self) -> Result<bool, String> { |
| 952 | loop { | 934 | loop { |
| 953 | // Whatever the last fed unit produced is the picture this call | 935 | // Whatever the last fed unit produced is the picture this call |
| 954 | - // hands back. The iterator starts fresh per feed because VP8 | 936 | + // hands back. The slot is taken, not peeked -- the next fed unit |
| 955 | - // queues nothing: one unit in, at most one picture out. | 937 | + // overwrites it, because VP8 queues nothing: one unit in, at |
| 956 | - let mut iter: *const c_void = std::ptr::null(); | 938 | + // most one picture out. |
| 957 | - while let Some(img) = self.vpx.get_frame(&mut self.ctx, &mut iter) { | 939 | + if let Some(pic) = self.dec.get_frame() { |
| 958 | // One picture further along, shown or skipped past alike -- | 940 | // One picture further along, shown or skipped past alike -- |
| 959 | - // the same walk [`Session::pump`] makes. The fields the copy | 941 | + // the same walk [`Session::pump`] makes. |
| 960 | - // needs are taken by value, which ends the context's borrow | ||
| 961 | - // before `emit` may take the session again. | ||
| 962 | - let (planes, stride, (w, h)) = (img.planes, img.stride, img.display()); | ||
| 963 | self.position += 1; | 942 | self.position += 1; |
| 964 | if self.skip > 0 { | 943 | if self.skip > 0 { |
| 965 | self.skip -= 1; | 944 | self.skip -= 1; |
| 966 | continue; | 945 | continue; |
| 967 | } | 946 | } |
| 968 | - self.emit(planes, stride, w, h); | 947 | + self.emit(&pic); |
| 969 | return Ok(true); | 948 | return Ok(true); |
| 970 | } | 949 | } |
| 971 | if self.flushed { | 950 | if self.flushed { |
| @@ -974,11 +953,12 @@ impl VpxSession { | |||
| 974 | match self.demuxer.next_access_unit() { | 953 | match self.demuxer.next_access_unit() { |
| 975 | Ok(Some(au)) => self.decode(&au)?, | 954 | Ok(Some(au)) => self.decode(&au)?, |
| 976 | Ok(None) => { | 955 | Ok(None) => { |
| 977 | - // End of the track: the empty `vpx_codec_decode` that | 956 | + // End of the track. VP8 holds nothing back -- the flush |
| 978 | - // releases anything held back is this decoder's flush, | 957 | + // is the formality [`vpx::Decoder::flush`] documents -- |
| 979 | - // and it costs no iteration of its own -- the pull at the | 958 | + // and it costs no iteration of its own: the pull at the |
| 980 | - // top of the loop drains it. | 959 | + // top of the loop finds the slot empty and ends the |
| 981 | - self.vpx.flush(&mut self.ctx)?; | 960 | + // stream. |
| 961 | + self.dec.flush()?; | ||
| 982 | self.flushed = true; | 962 | self.flushed = true; |
| 983 | } | 963 | } |
| 984 | Err(e) => return Err(e.to_string()), | 964 | Err(e) => return Err(e.to_string()), |
| @@ -990,27 +970,24 @@ impl VpxSession { | |||
| 990 | /// for a decoder that hands the planes back in memory rather than behind | 970 | /// for a decoder that hands the planes back in memory rather than behind |
| 991 | /// a `vaGetImage`. VP8 output is always 8-bit 4:2:0, so there is no | 971 | /// a `vaGetImage`. VP8 output is always 8-bit 4:2:0, so there is no |
| 992 | /// 10-bit branch to mirror. | 972 | /// 10-bit branch to mirror. |
| 993 | - fn emit(&mut self, planes: [*mut u8; 4], stride: [std::ffi::c_int; 4], w: u32, h: u32) { | 973 | + fn emit(&mut self, pic: &vpx::Picture) { |
| 994 | - let (w, h) = (w as usize, h as usize); | 974 | + let (w, h) = (usize::from(pic.width), usize::from(pic.height)); |
| 995 | let (cw, ch) = (w.div_ceil(2), h.div_ceil(2)); | 975 | let (cw, ch) = (w.div_ceil(2), h.div_ceil(2)); |
| 996 | if self.luma != w * h || self.chroma != cw * ch { | 976 | if self.luma != w * h || self.chroma != cw * ch { |
| 997 | self.luma = w * h; | 977 | self.luma = w * h; |
| 998 | self.chroma = cw * ch; | 978 | self.chroma = cw * ch; |
| 999 | self.out = vec![0u8; self.luma + 2 * self.chroma]; | 979 | self.out = vec![0u8; self.luma + 2 * self.chroma]; |
| 1000 | } | 980 | } |
| 1001 | - self.meta.width = w as u32; | 981 | + self.meta.width = u32::from(pic.width); |
| 1002 | - self.meta.height = h as u32; | 982 | + self.meta.height = u32::from(pic.height); |
| 1003 | let (dst_y, rest) = self.out.split_at_mut(self.luma); | 983 | let (dst_y, rest) = self.out.split_at_mut(self.luma); |
| 1004 | let (dst_u, dst_v) = rest.split_at_mut(self.chroma); | 984 | let (dst_u, dst_v) = rest.split_at_mut(self.chroma); |
| 1005 | - // SAFETY: libvpx guarantees the planes stride-cover the *display* | 985 | + // The planes stride-cover the visible frame by the `Picture` |
| 1006 | - // size (4:2:0, so the chroma planes cover cw x ch) for the life of | 986 | + // contract (4:2:0, so the chroma planes cover cw x ch), and they are |
| 1007 | - // the image, which ends at this session's next `get_frame` -- after | 987 | + // owned by this session -- no lifetime to out-think, no unsafe. |
| 1008 | - // the copies below. | 988 | + copy_plane(&pic.y, pic.stride, dst_y, w, h); |
| 1009 | - unsafe { | 989 | + copy_plane(&pic.u, pic.uv_stride, dst_u, cw, ch); |
| 1010 | - copy_plane(planes[0], stride[0] as usize, dst_y, w, h); | 990 | + copy_plane(&pic.v, pic.uv_stride, dst_v, cw, ch); |
| 1011 | - copy_plane(planes[1], stride[1] as usize, dst_u, cw, ch); | ||
| 1012 | - copy_plane(planes[2], stride[2] as usize, dst_v, cw, ch); | ||
| 1013 | - } | ||
| 1014 | } | 991 | } |
| 1015 | 992 | ||
| 1016 | fn fill(&self, out: &mut VhFrame) { | 993 | fn fill(&self, out: &mut VhFrame) { |
| @@ -1031,9 +1008,9 @@ impl VpxSession { | |||
| 1031 | 1008 | ||
| 1032 | /// Repositions the session, exactly [`Session::seek_to`]: the same | 1009 | /// Repositions the session, exactly [`Session::seek_to`]: the same |
| 1033 | /// forward walk within [`FORWARD_SECS`], the same demuxer seek to a sync | 1010 | /// forward walk within [`FORWARD_SECS`], the same demuxer seek to a sync |
| 1034 | - /// sample otherwise -- and for the decoder, destroy + re-init where the | 1011 | + /// sample otherwise -- and for the decoder, a fresh [`vpx::Decoder`] |
| 1035 | - /// VA-API half pays a flush, because VP8 is stateful to its last inter | 1012 | + /// where the VA-API half pays a flush, because VP8 is stateful to its |
| 1036 | - /// frame and libvpx offers no softer reset. | 1013 | + /// last inter frame. |
| 1037 | fn seek_to(&mut self, target_sample: u32) -> Result<(), String> { | 1014 | fn seek_to(&mut self, target_sample: u32) -> Result<(), String> { |
| 1038 | let target_frame = target_sample.saturating_sub(1); | 1015 | let target_frame = target_sample.saturating_sub(1); |
| 1039 | if let Reposition::Forward(ahead) = reposition( | 1016 | if let Reposition::Forward(ahead) = reposition( |
| @@ -1045,11 +1022,11 @@ impl VpxSession { | |||
| 1045 | self.skip = forward_skip(self.skip, ahead); | 1022 | self.skip = forward_skip(self.skip, ahead); |
| 1046 | return Ok(()); | 1023 | return Ok(()); |
| 1047 | } | 1024 | } |
| 1048 | - // Dropping every reference the decoder holds. The destroy's answer is | 1025 | + // Dropping every reference the decoder holds: the whole of what the |
| 1049 | - // not checked against `Ok` because the init below re-zeroes the | 1026 | + // FFI seat paid as destroy + re-init is now the assignment of an |
| 1050 | - // context either way; a destroy that failed has nothing to leak. | 1027 | + // owned value. What makes it safe is unchanged -- the demuxer's |
| 1051 | - self.vpx.destroy(&mut self.ctx); | 1028 | + // sync-sample seek restarts the feed where the reference chain does. |
| 1052 | - self.init()?; | 1029 | + self.dec = vpx::Decoder::new(); |
| 1053 | self.flushed = false; | 1030 | self.flushed = false; |
| 1054 | let first = self.demuxer.seek_to_sync_at_or_before(target_frame); | 1031 | let first = self.demuxer.seek_to_sync_at_or_before(target_frame); |
| 1055 | self.skip = (i64::from(target_frame) - first).max(0) as u32; | 1032 | self.skip = (i64::from(target_frame) - first).max(0) as u32; |
| @@ -1058,20 +1035,11 @@ impl VpxSession { | |||
| 1058 | } | 1035 | } |
| 1059 | } | 1036 | } |
| 1060 | 1037 | ||
| 1061 | -impl Drop for VpxSession { | ||
| 1062 | - fn drop(&mut self) { | ||
| 1063 | - self.vpx.destroy(&mut self.ctx); | ||
| 1064 | - } | ||
| 1065 | -} | ||
| 1066 | - | ||
| 1067 | /// One strided plane down to tightly packed rows: the whole of the read-back | 1038 | /// One strided plane down to tightly packed rows: the whole of the read-back |
| 1068 | /// a VP8 picture costs, where the VA-API half pays `vaGetImage` for the same. | 1039 | /// a VP8 picture costs, where the VA-API half pays `vaGetImage` for the same. |
| 1069 | -/// | 1040 | +fn copy_plane(src: &[u8], src_stride: usize, dst: &mut [u8], w: usize, h: usize) { |
| 1070 | -/// # Safety | ||
| 1071 | -/// `src` must stride-cover `w` x `h`, and `dst` must be `w` x `h`. | ||
| 1072 | -unsafe fn copy_plane(src: *const u8, stride: usize, dst: &mut [u8], w: usize, h: usize) { | ||
| 1073 | for row in 0..h { | 1041 | for row in 0..h { |
| 1074 | - let s = unsafe { std::slice::from_raw_parts(src.add(row * stride), w) }; | 1042 | + let s = &src[row * src_stride..row * src_stride + w]; |
| 1075 | dst[row * w..(row + 1) * w].copy_from_slice(s); | 1043 | dst[row * w..(row + 1) * w].copy_from_slice(s); |
| 1076 | } | 1044 | } |
| 1077 | } | 1045 | } |
| @@ -1079,8 +1047,8 @@ unsafe fn copy_plane(src: *const u8, stride: usize, dst: &mut [u8], w: usize, h: | |||
| 1079 | /// Opens `path` for hardware decode, positioned so the first | 1047 | /// Opens `path` for hardware decode, positioned so the first |
| 1080 | /// [`vh_next_frame`] returns sample `target_sample` (1-based; 0 and 1 both mean | 1048 | /// [`vh_next_frame`] returns sample `target_sample` (1-based; 0 and 1 both mean |
| 1081 | /// the start of the stream). Returns null on any failure at all: no libva | 1049 | /// the start of the stream). Returns null on any failure at all: no libva |
| 1082 | -/// runtime, no render node, no libvpx for a VP8 file, unsupported profile, | 1050 | +/// runtime, no render node, unsupported profile, unreadable file, a VP8 |
| 1083 | -/// unreadable file. | 1051 | +/// stream the decoder rejects. |
| 1084 | /// | 1052 | /// |
| 1085 | /// # Safety | 1053 | /// # Safety |
| 1086 | /// `path` must be a valid NUL-terminated C string. | 1054 | /// `path` must be a valid NUL-terminated C string. |
| @@ -1215,7 +1183,7 @@ pub unsafe extern "C" fn vh_next_frame_dma( | |||
| 1215 | let session = unsafe { &mut *(session as *mut OpenSession) }; | 1183 | let session = unsafe { &mut *(session as *mut OpenSession) }; |
| 1216 | // SAFETY: as above. | 1184 | // SAFETY: as above. |
| 1217 | unsafe { *dma = VhDma::default() }; | 1185 | unsafe { *dma = VhDma::default() }; |
| 1218 | - // A libvpx picture has no GPU buffer to hand over: this session reads | 1186 | + // A VP8 picture has no GPU buffer to hand over: this session reads |
| 1219 | // back, exactly as `vh_next_frame` does, and the caller's `dma` keeps | 1187 | // back, exactly as `vh_next_frame` does, and the caller's `dma` keeps |
| 1220 | // the fd-below-zero default that says so. | 1188 | // the fd-below-zero default that says so. |
| 1221 | match session { | 1189 | match session { |
| @@ -1333,12 +1301,13 @@ const CAP_TABLE: [(u32, &[VAProfile::Type], &[VAProfile::Type], Option<VAProfile | |||
| 1333 | /// codecs this plugin actually implements can light up -- `CAP_TABLE` is that | 1301 | /// codecs this plugin actually implements can light up -- `CAP_TABLE` is that |
| 1334 | /// half of the intersection. | 1302 | /// half of the intersection. |
| 1335 | /// | 1303 | /// |
| 1336 | -/// VP8 is the one bit asked of nobody: it is this plugin's libvpx seat, lit | 1304 | +/// VP8 is the one bit asked of nobody: it is this plugin's own native seat |
| 1337 | -/// when the library loads and nothing else -- no profile, no entrypoint, no | 1305 | +/// (`vpx`, `ec-vp8` linked in), lit unconditionally -- no profile, no |
| 1338 | -/// display. It rides along only when the display *is* answerable, because | 1306 | +/// entrypoint, no display, no library to load. It rides along only when the |
| 1339 | -/// this symbol's shape says a displayless machine has nothing to report at | 1307 | +/// display *is* answerable, because this symbol's shape says a displayless |
| 1340 | -/// all; the decode path itself needs no display for it | 1308 | +/// machine has nothing to report at all; the decode path itself needs no |
| 1341 | -/// ([`OpenSession::open_at`] routes VP8 before any device opens). | 1309 | +/// display for it ([`OpenSession::open_at`] routes VP8 before any device |
| 1310 | +/// opens). | ||
| 1342 | /// | 1311 | /// |
| 1343 | /// `None` when there is no display to ask at all, which is the same "software | 1312 | /// `None` when there is no display to ask at all, which is the same "software |
| 1344 | /// only" a missing plugin means. | 1313 | /// only" a missing plugin means. |
| @@ -1354,10 +1323,8 @@ fn query_caps() -> Option<VhCaps> { | |||
| 1354 | .query_config_entrypoints(profile) | 1323 | .query_config_entrypoints(profile) |
| 1355 | .is_ok_and(|e| e.contains(&entrypoint)) | 1324 | .is_ok_and(|e| e.contains(&entrypoint)) |
| 1356 | }; | 1325 | }; |
| 1357 | - let decodes = |list: &[VAProfile::Type]| { | 1326 | + let decodes = |
| 1358 | - list.iter() | 1327 | + |list: &[VAProfile::Type]| list.iter().any(|&p| has(p, VAEntrypoint::VAEntrypointVLD)); |
| 1359 | - .any(|&p| has(p, VAEntrypoint::VAEntrypointVLD)) | ||
| 1360 | - }; | ||
| 1361 | let mut caps = VhCaps::default(); | 1328 | let mut caps = VhCaps::default(); |
| 1362 | for (bit, eight, ten, encode) in CAP_TABLE { | 1329 | for (bit, eight, ten, encode) in CAP_TABLE { |
| 1363 | if decodes(eight) { | 1330 | if decodes(eight) { |
| @@ -1374,10 +1341,10 @@ fn query_caps() -> Option<VhCaps> { | |||
| 1374 | } | 1341 | } |
| 1375 | } | 1342 | } |
| 1376 | // The plugin's own software decoder, on its own account rather than the | 1343 | // The plugin's own software decoder, on its own account rather than the |
| 1377 | - // driver's -- the plugin's capability, never a GPU feat. | 1344 | + // driver's -- the plugin's capability, never a GPU feat. Native now, so |
| 1378 | - if vpx::vpx().is_some() { | 1345 | + // the bit has no "when it loads" condition left: it lights on every |
| 1379 | - caps.decode |= CAP_VP8; | 1346 | + // machine this plugin runs on. |
| 1380 | - } | 1347 | + caps.decode |= CAP_VP8; |
| 1381 | Some(caps) | 1348 | Some(caps) |
| 1382 | } | 1349 | } |
| 1383 | 1350 | ||
crates/engine-hw/src/vpx.rsmodified+63 -258
| @@ -1,273 +1,78 @@ | |||
| 1 | -//! `libvpx`, dlopen'd: the software VP8 decoder, and the reason a VP8 file | 1 | +//! The software VP8 decoder: `ec-vp8`, this project's own implementation of |
| 2 | -//! decodes on a machine whose GPU has no VP8 profile -- or whose GPU is | 2 | +//! RFC 6386 -- the reason a VP8 file decodes on a machine whose GPU has no |
| 3 | -//! absent altogether. | 3 | +//! VP8 profile, or whose GPU is absent altogether. |
| 4 | //! | 4 | //! |
| 5 | -//! The plugin's own libva linkage, one level down: this plugin keeps no | 5 | +//! The seat was `libvpx`, resolved at runtime behind a hand-written FFI; the |
| 6 | -//! DT_NEEDED on `libvpx` any more than the main binary does. The symbols are | 6 | +//! native crate replaces it outright, and with it the whole dlopen layer |
| 7 | -//! resolved lazily, once, and a machine without the library is a machine | 7 | +//! goes: the plugin links the decoder as ordinary Rust, so there is no |
| 8 | -//! without the codec -- answered as `None` at [`vpx`] before any file is | 8 | +//! library to look for, no ABI to pin, and no machine where the codec is |
| 9 | -//! opened, which is what [`crate::query_caps`] reports as the absence of | 9 | +//! absent from a build that carries this plugin. What survives from the FFI |
| 10 | -//! `CAP_VP8`. | 10 | +//! days is the seat's shape -- the five verbs the session above lives on: |
| 11 | //! | 11 | //! |
| 12 | -//! The extern declarations are hand-written against `vpx_decoder.h`, | 12 | +//! - `init` -- a fresh [`Decoder`], infallible now that there is no ABI to |
| 13 | -//! `vpx_codec.h` and `vpx_image.h` as this soname has carried them since | 13 | +//! negotiate; |
| 14 | -//! libvpx 1.14: `VPX_DECODER_ABI_VERSION` 12. A libvpx from another ABI | 14 | +//! - `decode` -- one access unit in, the picture (if any) held for the next |
| 15 | -//! answers `vpx_codec_dec_init_ver` with `VPX_CODEC_ABI_MISMATCH`, which | 15 | +//! `get_frame`; |
| 16 | -//! surfaces as a refused session -- loudly, in the eprintln, never as a | 16 | +//! - `get_frame` -- the picture the last `decode` produced, taken once; |
| 17 | -//! wrong picture. The struct layouts below are the ABI, not an assumption: | 17 | +//! - `flush` -- a formality: VP8 reorders nothing and holds nothing back, so |
| 18 | -//! `vpx_codec_ctx_t`'s fields have not moved since the library's first | 18 | +//! end of stream has nothing to release (libvpx wanted the empty |
| 19 | -//! release, and `vpx_image_t`'s prefix is what every decoder in the field | 19 | +//! `vpx_codec_decode`; the native decoder has no equivalent need, and the |
| 20 | -//! reads. | 20 | +//! verb stays because the session's pump is written around it); |
| 21 | - | 21 | +//! - `destroy` -- now simply the drop of an owned value, which is why a |
| 22 | -use std::ffi::{CStr, c_char, c_int, c_long, c_uint, c_void}; | 22 | +//! seek is `self.decoder = Decoder::new()` where the FFI seat paid a |
| 23 | -use std::sync::LazyLock; | 23 | +//! destroy + re-init round trip. |
| 24 | - | 24 | + |
| 25 | -use libloading::Library; | 25 | +use ec_vp8::decode; |
| 26 | - | 26 | + |
| 27 | -/// `VPX_DECODER_ABI_VERSION`: `3 + VPX_CODEC_ABI_VERSION`, and | 27 | +/// The VP8 decoder: [`decode::Decoder`] plus the one-picture slot between |
| 28 | -/// `VPX_CODEC_ABI_VERSION = 4 + VPX_IMAGE_ABI_VERSION` with | 28 | +/// `decode` and `get_frame`. |
| 29 | -/// `VPX_IMAGE_ABI_VERSION = 5` -- the three headers this module mirrors. | 29 | +pub(super) struct Decoder { |
| 30 | -const VPX_DECODER_ABI_VERSION: c_int = 12; | 30 | + inner: decode::Decoder, |
| 31 | - | 31 | + pending: Option<Picture>, |
| 32 | -/// `VPX_CODEC_OK`, the one return code that is not a refusal. | ||
| 33 | -const VPX_CODEC_OK: c_int = 0; | ||
| 34 | - | ||
| 35 | -/// `VPX_DL_REALTIME`, the decode `deadline` argument -- which `vpx_decoder.h` | ||
| 36 | -/// states this API ignores; passed because the type demands a value, and the | ||
| 37 | -/// constant because it is the documented one. | ||
| 38 | -const VPX_DL_REALTIME: c_long = 1; | ||
| 39 | - | ||
| 40 | -/// The decoder context, `vpx_codec_ctx_t` field for field. Nothing here is | ||
| 41 | -/// read: the struct exists so the context is laid out exactly as libvpx | ||
| 42 | -/// lays it out, and so the `&mut` handoffs to the C side are the whole of | ||
| 43 | -/// the story. | ||
| 44 | -#[repr(C)] | ||
| 45 | -pub struct VpxCtx { | ||
| 46 | - name: *const c_char, | ||
| 47 | - iface: *const c_void, | ||
| 48 | - err: c_int, | ||
| 49 | - err_detail: *const c_char, | ||
| 50 | - init_flags: c_uint, | ||
| 51 | - config: *const c_void, | ||
| 52 | - priv_: *mut c_void, | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -impl Default for VpxCtx { | ||
| 56 | - fn default() -> Self { | ||
| 57 | - // SAFETY: all-pointer/zero initialisation is what libvpx's own init | ||
| 58 | - // performs on the context before it fills it; `vpx_codec_dec_init_ver` | ||
| 59 | - // re-zeroes it anyway. | ||
| 60 | - unsafe { std::mem::zeroed() } | ||
| 61 | - } | ||
| 62 | } | 32 | } |
| 63 | 33 | ||
| 64 | -/// `vpx_codec_dec_cfg_t`: thread count and a best-known size the caller may | 34 | +/// One decoded picture: the visible frame's planes, 8-bit 4:2:0, strided |
| 65 | -/// leave at zero. | 35 | +/// (`stride` may exceed `width`) and owned by whoever holds it -- what |
| 66 | -#[repr(C)] | 36 | +/// [`crate::VhFrame`] hands on is the packed copy the session makes. |
| 67 | -struct VpxDecCfg { | 37 | +pub(super) use decode::Picture; |
| 68 | - threads: c_uint, | 38 | + |
| 69 | - w: c_uint, | 39 | +impl Decoder { |
| 70 | - h: c_uint, | 40 | + /// `init`: a decoder holding no references yet; the first key frame |
| 71 | -} | 41 | + /// sets the size. |
| 72 | - | 42 | + pub(super) fn new() -> Self { |
| 73 | -/// `vpx_image_t` complete: the planes of one decoded picture and the strides | 43 | + Self { |
| 74 | -/// they sit at. The decoder owns the bytes -- they stay valid only until the | 44 | + inner: decode::Decoder::new(), |
| 75 | -/// next `get_frame` or `decode` on the same context, which is exactly the | 45 | + pending: None, |
| 76 | -/// [`crate::VhFrame`] contract the caller already lives with. | ||
| 77 | -#[repr(C)] | ||
| 78 | -pub struct VpxImage { | ||
| 79 | - fmt: c_int, | ||
| 80 | - cs: c_int, | ||
| 81 | - range: c_int, | ||
| 82 | - w: c_uint, | ||
| 83 | - h: c_uint, | ||
| 84 | - bit_depth: c_uint, | ||
| 85 | - d_w: c_uint, | ||
| 86 | - d_h: c_uint, | ||
| 87 | - r_w: c_uint, | ||
| 88 | - r_h: c_uint, | ||
| 89 | - x_chroma_shift: c_uint, | ||
| 90 | - y_chroma_shift: c_uint, | ||
| 91 | - pub planes: [*mut u8; 4], | ||
| 92 | - pub stride: [c_int; 4], | ||
| 93 | - bps: c_int, | ||
| 94 | - user_priv: *mut c_void, | ||
| 95 | - img_data: *mut u8, | ||
| 96 | - img_data_owner: c_int, | ||
| 97 | - self_allocd: c_int, | ||
| 98 | - fb_priv: *mut c_void, | ||
| 99 | -} | ||
| 100 | - | ||
| 101 | -impl VpxImage { | ||
| 102 | - /// Displayed dimensions: what [`crate::VhFrame`] describes, not the | ||
| 103 | - /// macroblock-padded storage the planes actually cover. | ||
| 104 | - pub fn display(&self) -> (u32, u32) { | ||
| 105 | - (self.d_w, self.d_h) | ||
| 106 | - } | ||
| 107 | -} | ||
| 108 | - | ||
| 109 | -type Dx = unsafe extern "C" fn() -> *const c_void; | ||
| 110 | -type DecInitVer = | ||
| 111 | - unsafe extern "C" fn(*mut VpxCtx, *const c_void, *const VpxDecCfg, c_uint, c_int) -> c_int; | ||
| 112 | -type Decode = unsafe extern "C" fn(*mut VpxCtx, *const u8, c_uint, *mut c_void, c_long) -> c_int; | ||
| 113 | -type GetFrame = unsafe extern "C" fn(*mut VpxCtx, *mut *const c_void) -> *mut VpxImage; | ||
| 114 | -type Destroy = unsafe extern "C" fn(*mut VpxCtx) -> c_int; | ||
| 115 | -type ErrorFn = unsafe extern "C" fn(*const VpxCtx) -> *const c_char; | ||
| 116 | - | ||
| 117 | -/// The resolved symbols, held with the library that carries them -- exactly | ||
| 118 | -/// the shape `engine::hw`'s `Plugin` has on the other side of the ABI. | ||
| 119 | -pub struct Vpx { | ||
| 120 | - vp8_dx: Dx, | ||
| 121 | - dec_init_ver: DecInitVer, | ||
| 122 | - decode: Decode, | ||
| 123 | - get_frame: GetFrame, | ||
| 124 | - destroy: Destroy, | ||
| 125 | - error: ErrorFn, | ||
| 126 | - // Never dropped (the struct lives in a static), so the pointers above | ||
| 127 | - // stay valid for the life of the process. | ||
| 128 | - _lib: Library, | ||
| 129 | -} | ||
| 130 | - | ||
| 131 | -/// The library, loaded once per process. `None` -- no `libvpx.so` on this | ||
| 132 | -/// machine, or one missing a symbol this module names -- is the one answer, | ||
| 133 | -/// asked before any file is opened. | ||
| 134 | -static VPX: LazyLock<Option<Vpx>> = LazyLock::new(load); | ||
| 135 | - | ||
| 136 | -/// The loaded library, or `None` on a machine without one this module can | ||
| 137 | -/// use. Asked before any file is opened. | ||
| 138 | -pub fn vpx() -> Option<&'static Vpx> { | ||
| 139 | - VPX.as_ref() | ||
| 140 | -} | ||
| 141 | - | ||
| 142 | -fn load() -> Option<Vpx> { | ||
| 143 | - // The versioned soname first -- the name every distribution actually | ||
| 144 | - // ships -- then the unversioned development name for the odd link that | ||
| 145 | - // has it. | ||
| 146 | - for name in ["libvpx.so.9", "libvpx.so"] { | ||
| 147 | - let lib = match unsafe { Library::new(name) } { | ||
| 148 | - Ok(lib) => lib, | ||
| 149 | - Err(_) => continue, | ||
| 150 | - }; | ||
| 151 | - // SAFETY: the symbols are type-checked against the declarations above; | ||
| 152 | - // a missing one unloads the library with the dropped closure and the | ||
| 153 | - // next candidate gets its turn. | ||
| 154 | - let vpx = unsafe { | ||
| 155 | - (|| { | ||
| 156 | - Some(Vpx { | ||
| 157 | - vp8_dx: *lib.get(b"vpx_codec_vp8_dx\0").ok()?, | ||
| 158 | - dec_init_ver: *lib.get(b"vpx_codec_dec_init_ver\0").ok()?, | ||
| 159 | - decode: *lib.get(b"vpx_codec_decode\0").ok()?, | ||
| 160 | - get_frame: *lib.get(b"vpx_codec_get_frame\0").ok()?, | ||
| 161 | - destroy: *lib.get(b"vpx_codec_destroy\0").ok()?, | ||
| 162 | - error: *lib.get(b"vpx_codec_error\0").ok()?, | ||
| 163 | - _lib: lib, | ||
| 164 | - }) | ||
| 165 | - })() | ||
| 166 | - }; | ||
| 167 | - if vpx.is_some() { | ||
| 168 | - return vpx; | ||
| 169 | } | 46 | } |
| 170 | } | 47 | } |
| 171 | - None | ||
| 172 | -} | ||
| 173 | 48 | ||
| 174 | -impl Vpx { | 49 | + /// `decode`: one access unit in -- one complete VP8 frame payload, |
| 175 | - /// `vpx_codec_error`'s line about the context's last answer: what an init | 50 | + /// exactly what a container demuxer hands over for `V_VP8`/`vp08`. A |
| 176 | - /// or decode refusal says instead of a bare `vpx_codec_err_t` number. | 51 | + /// hidden frame (an alternate reference, `show_frame == 0`) updates the |
| 177 | - fn last_error(&self, ctx: &VpxCtx) -> String { | 52 | + /// reference buffers and produces no picture: the same nothing libvpx |
| 178 | - // SAFETY: `ctx` is a live libvpx context; the string it names is | 53 | + /// emitted for one, so the seat's picture accounting does not move. |
| 179 | - // static and read before anything else touches the context. | 54 | + pub(super) fn decode(&mut self, au: &[u8]) -> Result<(), String> { |
| 180 | - let msg = unsafe { (self.error)(ctx) }; | 55 | + if au.is_empty() { |
| 181 | - if msg.is_null() { | 56 | + return Ok(()); |
| 182 | - return "no description".to_string(); | ||
| 183 | } | 57 | } |
| 184 | - // SAFETY: non-null per the check above, NUL-terminated per libvpx. | 58 | + match self.inner.decode(au) { |
| 185 | - unsafe { CStr::from_ptr(msg) }.to_string_lossy().into_owned() | 59 | + Ok(picture) => self.pending = picture, |
| 186 | - } | 60 | + Err(e) => return Err(format!("vp8 decode failed: {e}")), |
| 187 | - | ||
| 188 | - /// The VP8 decoder interface, `vpx_codec_vp8_dx`: the argument every | ||
| 189 | - /// `dec_init_ver` on this context takes. | ||
| 190 | - fn iface(&self) -> *const c_void { | ||
| 191 | - // SAFETY: a pure lookup in libvpx's own tables. | ||
| 192 | - unsafe { (self.vp8_dx)() } | ||
| 193 | - } | ||
| 194 | - | ||
| 195 | - /// `vpx_codec_dec_init_ver` with the ABI version this module was written | ||
| 196 | - /// against -- the check a mismatched libvpx fails rather than a call it | ||
| 197 | - /// misreads. | ||
| 198 | - pub(super) fn dec_init(&self, ctx: &mut VpxCtx) -> Result<(), String> { | ||
| 199 | - let cfg = VpxDecCfg { | ||
| 200 | - threads: threads(), | ||
| 201 | - w: 0, | ||
| 202 | - h: 0, | ||
| 203 | - }; | ||
| 204 | - // SAFETY: the context is ours and live for the session; `cfg` is read | ||
| 205 | - // only during the call; the version pins the ABI. | ||
| 206 | - let rc = unsafe { (self.dec_init_ver)(ctx, self.iface(), &cfg, 0, VPX_DECODER_ABI_VERSION) }; | ||
| 207 | - match rc { | ||
| 208 | - VPX_CODEC_OK => Ok(()), | ||
| 209 | - _ => Err(format!("libvpx init failed: {}", self.last_error(ctx))), | ||
| 210 | } | 61 | } |
| 62 | + Ok(()) | ||
| 211 | } | 63 | } |
| 212 | 64 | ||
| 213 | - /// `vpx_codec_decode`: one access unit in. `VPX_DL_REALTIME` is the | 65 | + /// `get_frame`: the picture the last `decode` produced, if that frame |
| 214 | - /// documented-but-ignored deadline. | 66 | + /// was shown. Taken, not peeked -- the slot is empty again afterwards, |
| 215 | - pub(super) fn decode(&self, ctx: &mut VpxCtx, au: &[u8]) -> Result<(), String> { | 67 | + /// which is what lets the pump loop feed the next unit. |
| 216 | - // SAFETY: `au` outlives the call; the context is live and used from | 68 | + pub(super) fn get_frame(&mut self) -> Option<Picture> { |
| 217 | - // the one thread the session lives on. | 69 | + self.pending.take() |
| 218 | - let rc = unsafe { | ||
| 219 | - (self.decode)( | ||
| 220 | - ctx, | ||
| 221 | - au.as_ptr(), | ||
| 222 | - au.len() as c_uint, | ||
| 223 | - std::ptr::null_mut(), | ||
| 224 | - VPX_DL_REALTIME, | ||
| 225 | - ) | ||
| 226 | - }; | ||
| 227 | - match rc { | ||
| 228 | - VPX_CODEC_OK => Ok(()), | ||
| 229 | - _ => Err(format!("libvpx decode failed: {}", self.last_error(ctx))), | ||
| 230 | - } | ||
| 231 | - } | ||
| 232 | - | ||
| 233 | - /// `vpx_codec_decode` with a null, empty frame: the end-of-stream signal | ||
| 234 | - /// that releases whatever the decoder held back. | ||
| 235 | - pub(super) fn flush(&self, ctx: &mut VpxCtx) -> Result<(), String> { | ||
| 236 | - // SAFETY: as `decode`, with the nulls libvpx reads as "no more data". | ||
| 237 | - let rc = unsafe { | ||
| 238 | - (self.decode)(ctx, std::ptr::null(), 0, std::ptr::null_mut(), VPX_DL_REALTIME) | ||
| 239 | - }; | ||
| 240 | - match rc { | ||
| 241 | - VPX_CODEC_OK => Ok(()), | ||
| 242 | - _ => Err(format!("libvpx flush failed: {}", self.last_error(ctx))), | ||
| 243 | - } | ||
| 244 | } | 70 | } |
| 245 | 71 | ||
| 246 | - /// `vpx_codec_get_frame`: the next picture of the current iteration, or | 72 | + /// `flush`: end of the track. VP8 queues nothing -- one unit in, at |
| 247 | - /// `None` when the iteration is done. The bytes belong to the decoder | 73 | + /// most one picture out, feed order -- so there is nothing held back to |
| 248 | - /// until the next `decode`/`flush`. | 74 | + /// drain; the answer is always ok, immediately. |
| 249 | - pub(super) fn get_frame<'a>( | 75 | + pub(super) fn flush(&mut self) -> Result<(), String> { |
| 250 | - &self, | 76 | + Ok(()) |
| 251 | - ctx: &'a mut VpxCtx, | ||
| 252 | - iter: &mut *const c_void, | ||
| 253 | - ) -> Option<&'a VpxImage> { | ||
| 254 | - // SAFETY: the context is live; the returned pointer is libvpx's own | ||
| 255 | - // image, borrowed for exactly as long as the lifetime above says. | ||
| 256 | - unsafe { (self.get_frame)(ctx, iter).as_ref() } | ||
| 257 | } | 77 | } |
| 258 | - | ||
| 259 | - /// `vpx_codec_destroy`: the context's half of `VpxSession`'s `Drop`. | ||
| 260 | - pub(super) fn destroy(&self, ctx: &mut VpxCtx) { | ||
| 261 | - // SAFETY: called once per live context; libvpx frees what the context | ||
| 262 | - // holds, and a context whose init never completed reads as an | ||
| 263 | - // `INVALID_PARAM` refusal rather than a crash. | ||
| 264 | - unsafe { (self.destroy)(ctx) }; | ||
| 265 | - } | ||
| 266 | -} | ||
| 267 | - | ||
| 268 | -/// VP8's row-based multithreaded decode stops paying past a handful of | ||
| 269 | -/// threads -- the row sync costs what the parallelism buys -- so this is not | ||
| 270 | -/// the machine's whole core count. | ||
| 271 | -pub(super) fn threads() -> c_uint { | ||
| 272 | - std::thread::available_parallelism().map_or(1, |n| n.get().min(4) as c_uint) | ||
| 273 | } | 78 | } |
crates/engine/src/caps.rsmodified+10 -9
| @@ -12,12 +12,13 @@ | |||
| 12 | //! driver all read the same way -- "software only" -- because that is what they | 12 | //! driver all read the same way -- "software only" -- because that is what they |
| 13 | //! mean for the file a user is about to write. | 13 | //! mean for the file a user is about to write. |
| 14 | //! | 14 | //! |
| 15 | -//! VP8 is deliberately on neither line: the plugin decodes it on libvpx, | 15 | +//! VP8 is deliberately on neither line: the plugin decodes it on its own |
| 16 | -//! dlopen'd at runtime, and reports `CAP_VP8` for it -- the plugin's seat, | 16 | +//! native `ec-vp8`, always present, and reports `CAP_VP8` for it -- the |
| 17 | -//! never the GPU's. [`HW_CODECS`] does not carry the bit, because this file's | 17 | +//! plugin's seat, never the GPU's. [`HW_CODECS`] does not carry the bit, |
| 18 | -//! one job is not presenting a seat as a GPU feat that no GPU has. | 18 | +//! because this file's one job is not presenting a seat as a GPU feat that |
| 19 | +//! no GPU has. | ||
| 19 | 20 | ||
| 20 | -use crate::hw::{VhCaps, CAP_AV1, CAP_H264, CAP_HEVC, CAP_VP9}; | 21 | +use crate::hw::{CAP_AV1, CAP_H264, CAP_HEVC, CAP_VP9, VhCaps}; |
| 21 | 22 | ||
| 22 | /// The codecs a hardware line can name, in the order it lists them. | 23 | /// The codecs a hardware line can name, in the order it lists them. |
| 23 | const HW_CODECS: [(u32, &str); 4] = [ | 24 | const HW_CODECS: [(u32, &str); 4] = [ |
| @@ -136,10 +137,10 @@ mod tests { | |||
| 136 | assert_eq!(hw_line(Some(h264_only)), "H.264 dec"); | 137 | assert_eq!(hw_line(Some(h264_only)), "H.264 dec"); |
| 137 | } | 138 | } |
| 138 | 139 | ||
| 139 | - /// The plugin's VP8 bit is its own libvpx software decoder. However lit | 140 | + /// The plugin's VP8 bit is its own native decoder (`ec-vp8`), lit |
| 140 | - /// the mask is, the hardware line never reads it as a GPU seat -- and a | 141 | + /// unconditionally. However lit the mask is, the hardware line never |
| 141 | - /// mask holding nothing *but* it still reads as the nothing a driver | 142 | + /// reads it as a GPU seat -- and a mask holding nothing *but* it still |
| 142 | - /// without seats would answer. | 143 | + /// reads as the nothing a driver without seats would answer. |
| 143 | #[test] | 144 | #[test] |
| 144 | fn the_plugin_s_software_vp8_never_reads_as_a_gpu_seat() { | 145 | fn the_plugin_s_software_vp8_never_reads_as_a_gpu_seat() { |
| 145 | let vpx_only = VhCaps { | 146 | let vpx_only = VhCaps { |
crates/engine/src/decode.rsmodified+2 -2
| @@ -1016,8 +1016,8 @@ fn run_span( | |||
| 1016 | } | 1016 | } |
| 1017 | // ...except where there is nothing to fall back to. Feeding HEVC, VP9 or | 1017 | // ...except where there is nothing to fall back to. Feeding HEVC, VP9 or |
| 1018 | // VP8 bytes to either software seat would be garbage, not a fallback -- | 1018 | // VP8 bytes to either software seat would be garbage, not a fallback -- |
| 1019 | - // VP8's software decoder is libvpx, inside the plugin. H.264 and AV1 each | 1019 | + // VP8's decoder is `ec-vp8`, inside the plugin. H.264 and AV1 each |
| 1020 | - // have one of this project's own: `ec-h264`, `ec-av1`. | 1020 | + // have one of this project's own here: `ec-h264`, `ec-av1`. |
| 1021 | match opened.meta.codec { | 1021 | match opened.meta.codec { |
| 1022 | Codec::H264 => { | 1022 | Codec::H264 => { |
| 1023 | eprintln!("decode backend: software (ec-h264)"); | 1023 | eprintln!("decode backend: software (ec-h264)"); |
crates/engine/src/demux.rsmodified+6 -6
| @@ -110,8 +110,8 @@ pub fn cancelled_read_error() -> crate::Error { | |||
| 110 | CANCELLED.into() | 110 | CANCELLED.into() |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | -/// What the video track is coded with. Not a decoder choice by itself: only | 113 | +/// What the video track is coded with. Not a decoder choice by itself: H.264 |
| 114 | -/// H.264 has a software decoder in this binary, and VP8's (libvpx) lives | 114 | +/// and AV1 have software decoders in this binary, and VP8's (`ec-vp8`) lives |
| 115 | /// inside the plugin -- which is what [`Codec::needs_plugin`] says for the | 115 | /// inside the plugin -- which is what [`Codec::needs_plugin`] says for the |
| 116 | /// rest, per codec, in the words that stay true. | 116 | /// rest, per codec, in the words that stay true. |
| 117 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 117 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -140,9 +140,9 @@ impl Codec { | |||
| 140 | /// own (`ec-h264`, `ec-av1`) and are never refused for missing hardware on | 140 | /// own (`ec-h264`, `ec-av1`) and are never refused for missing hardware on |
| 141 | /// the *playback* path; HEVC and VP9 have no software decoder at all, so | 141 | /// the *playback* path; HEVC and VP9 have no software decoder at all, so |
| 142 | /// the refusal names the plugin as the only way. VP8's software decoder | 142 | /// the refusal names the plugin as the only way. VP8's software decoder |
| 143 | - /// *is* libvpx inside the plugin, so "there is no software decoder" would | 143 | + /// *is* this project's own `ec-vp8`, inside the plugin, so "there is no |
| 144 | - /// be a lie the day the plugin grew that arm -- the refusal keeps naming | 144 | + /// software decoder" would be a lie -- the refusal keeps naming the |
| 145 | - /// the plugin, because that is still the thing to make present. AV1's arm | 145 | + /// plugin, because that is still the thing to make present. AV1's arm |
| 146 | /// is the one refusal left that can reach it: the software *export* | 146 | /// is the one refusal left that can reach it: the software *export* |
| 147 | /// decoder is H.264-only (`export::SwDecoder`), so an AV1 source on a | 147 | /// decoder is H.264-only (`export::SwDecoder`), so an AV1 source on a |
| 148 | /// machine with no plugin exports through nothing. Shared so playback and | 148 | /// machine with no plugin exports through nothing. Shared so playback and |
| @@ -150,7 +150,7 @@ impl Codec { | |||
| 150 | pub fn needs_plugin(self) -> String { | 150 | pub fn needs_plugin(self) -> String { |
| 151 | match self { | 151 | match self { |
| 152 | Self::Vp8 => { | 152 | Self::Vp8 => { |
| 153 | - "VP8 needs the VA-API plugin (libengine_hw.so) — its decoder is libvpx, inside the plugin" | 153 | + "VP8 needs the VA-API plugin (libengine_hw.so) — its decoder is ec-vp8, inside the plugin" |
| 154 | .to_string() | 154 | .to_string() |
| 155 | } | 155 | } |
| 156 | Self::Av1 => { | 156 | Self::Av1 => { |
crates/engine/src/hw.rsmodified+6 -5
| @@ -178,10 +178,11 @@ pub const CAP_HEVC: u32 = 1 << 1; | |||
| 178 | pub const CAP_VP9: u32 = 1 << 2; | 178 | pub const CAP_VP9: u32 = 1 << 2; |
| 179 | pub const CAP_AV1: u32 = 1 << 3; | 179 | pub const CAP_AV1: u32 = 1 << 3; |
| 180 | 180 | ||
| 181 | -/// VP8 decodes on libvpx inside the plugin -- software, dlopen'd at runtime, | 181 | +/// VP8 decodes on `ec-vp8` inside the plugin -- software, linked into the |
| 182 | -/// no GPU and no VA-API profile anywhere in it -- so this bit is the | 182 | +/// plugin itself, no GPU and no VA-API profile anywhere in it -- so this bit |
| 183 | -/// *plugin's* seat, never the driver's. It lights up [`VhCaps::decode`] when | 183 | +/// is the *plugin's* seat, never the driver's, and it lights up |
| 184 | -/// the library is present; the hardware line in [`crate::caps`] deliberately | 184 | +/// [`VhCaps::decode`] unconditionally: there is no library whose presence the |
| 185 | +/// bit depends on any more. The hardware line in [`crate::caps`] deliberately | ||
| 185 | /// keeps it off, being a line about what the GPU takes. | 186 | /// keeps it off, being a line about what the GPU takes. |
| 186 | pub const CAP_VP8: u32 = 1 << 4; | 187 | pub const CAP_VP8: u32 = 1 << 4; |
| 187 | 188 | ||
| @@ -263,7 +264,7 @@ fn load() -> Option<Plugin> { | |||
| 263 | /// "software only" for all of them, which is what they mean. | 264 | /// "software only" for all of them, which is what they mean. |
| 264 | /// | 265 | /// |
| 265 | /// VP8 sits outside that reading on a driverless machine: its decoder is | 266 | /// VP8 sits outside that reading on a driverless machine: its decoder is |
| 266 | -/// libvpx inside the plugin, so the plugin may open a VP8 file where this | 267 | +/// `ec-vp8` inside the plugin, so the plugin may open a VP8 file where this |
| 267 | /// table answers `None`. Nothing here promises otherwise -- the decode path | 268 | /// table answers `None`. Nothing here promises otherwise -- the decode path |
| 268 | /// asks the plugin, not this table -- and the one display-dependent half the | 269 | /// asks the plugin, not this table -- and the one display-dependent half the |
| 269 | /// front-end draws from this stays exactly as truthful as it was. | 270 | /// front-end draws from this stays exactly as truthful as it was. |
crates/engine/tests/vp8.rsmodified+9 -9
| @@ -1,7 +1,7 @@ | |||
| 1 | //! VP8 import: the container half, and the decode half -- software, on the | 1 | //! VP8 import: the container half, and the decode half -- software, on the |
| 2 | -//! libvpx the plugin dlopens (`engine-hw`'s `vpx.rs`), which is why these | 2 | +//! plugin's own native decoder (`ec-vp8`, `engine-hw`'s `vpx.rs`), which is |
| 3 | -//! twins need a built `libengine_hw.so` and a `libvpx.so` but **no VA-API | 3 | +//! why these twins need a built `libengine_hw.so` but **no VA-API VP8 |
| 4 | -//! VP8 profile**: no such profile exists on this GPU, and none is asked for. | 4 | +//! profile**: no such profile exists on this GPU, and none is asked for. |
| 5 | //! | 5 | //! |
| 6 | //! ```text | 6 | //! ```text |
| 7 | //! cargo build -p engine -p engine-hw --release | 7 | //! cargo build -p engine -p engine-hw --release |
| @@ -55,9 +55,9 @@ fn the_demuxer_reports_a_vp8_track() { | |||
| 55 | /// There is no software VP8 decoder *in this binary*, so the software path | 55 | /// There is no software VP8 decoder *in this binary*, so the software path |
| 56 | /// must refuse by name rather than feed VP8 bytes to `ec-h264` -- and it | 56 | /// must refuse by name rather than feed VP8 bytes to `ec-h264` -- and it |
| 57 | /// must refuse where a caller can still show it, i.e. out of `open`, not from | 57 | /// must refuse where a caller can still show it, i.e. out of `open`, not from |
| 58 | -/// inside the worker. The decoder the refusal names is the plugin's libvpx | 58 | +/// inside the worker. The decoder the refusal names is the plugin's own |
| 59 | -/// arm, which is why the sentence names the plugin and not a nonexistent | 59 | +/// (`ec-vp8`), which is why the sentence names the plugin and not a |
| 60 | -/// absence. | 60 | +/// nonexistent absence. |
| 61 | #[test] | 61 | #[test] |
| 62 | fn the_software_path_refuses_vp8_by_name() { | 62 | fn the_software_path_refuses_vp8_by_name() { |
| 63 | // SAFETY: the suite is documented to run with --test-threads=1. | 63 | // SAFETY: the suite is documented to run with --test-threads=1. |
| @@ -73,10 +73,10 @@ fn the_software_path_refuses_vp8_by_name() { | |||
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | /// The end-to-end user path: opening the file yields pictures, all of them, | 75 | /// The end-to-end user path: opening the file yields pictures, all of them, |
| 76 | -/// through the plugin's libvpx arm. The `.webm` is the file this decodes, | 76 | +/// through the plugin's VP8 arm. The `.webm` is the file this decodes, |
| 77 | /// the container half being the Matroska demuxer's `V_VP8` row. | 77 | /// the container half being the Matroska demuxer's `V_VP8` row. |
| 78 | #[test] | 78 | #[test] |
| 79 | -#[ignore = "needs a built libengine_hw.so and libvpx.so.9 -- no VA-API profile involved"] | 79 | +#[ignore = "needs a built libengine_hw.so -- no VA-API profile involved"] |
| 80 | fn the_plugin_decodes_every_vp8_frame() { | 80 | fn the_plugin_decodes_every_vp8_frame() { |
| 81 | let start = Instant::now(); | 81 | let start = Instant::now(); |
| 82 | let (meta, frames) = DecodeSession::open(asset("test_vp8.webm")).expect("open test_vp8.webm"); | 82 | let (meta, frames) = DecodeSession::open(asset("test_vp8.webm")).expect("open test_vp8.webm"); |
| @@ -117,7 +117,7 @@ fn the_plugin_decodes_every_vp8_frame() { | |||
| 117 | /// Export re-encodes to H.264 whatever the source was coded with: the packet | 117 | /// Export re-encodes to H.264 whatever the source was coded with: the packet |
| 118 | /// copy path is audio-only, so no VP8 byte can reach an `avc1` track. | 118 | /// copy path is audio-only, so no VP8 byte can reach an `avc1` track. |
| 119 | #[test] | 119 | #[test] |
| 120 | -#[ignore = "needs a built libengine_hw.so and libvpx.so.9 -- no VA-API profile involved"] | 120 | +#[ignore = "needs a built libengine_hw.so -- no VA-API profile involved"] |
| 121 | fn a_vp8_source_exports_as_h264() { | 121 | fn a_vp8_source_exports_as_h264() { |
| 122 | let session = PlaybackSession::open(asset("test_vp8.webm")).expect("open test_vp8.webm"); | 122 | let session = PlaybackSession::open(asset("test_vp8.webm")).expect("open test_vp8.webm"); |
| 123 | let meta = *session.meta(); | 123 | let meta = *session.meta(); |