Merge branch 'simplify/u17' into simplify/w1b
Browse files at this commit31 changed files +12 -4057
- Cargo.lock +0 -4
- crates/ec-va/abi-probe.c +0 -90
- crates/ec-va/src/cacheline.rs +0 -78
- crates/ec-va/src/caps.rs +0 -19
- crates/ec-va/src/config.rs +2 -18
- crates/ec-va/src/display.rs +0 -9
- crates/ec-va/src/error.rs +0 -8
- crates/ec-va/src/lib.rs +1 -2
- crates/ec-va/tests/gpu.rs +1 -385
- shims/cros-libva/Android.bp +0 -63
- shims/cros-libva/Cargo.toml +0 -3
- shims/cros-libva/src/buffer.rs +7 -129
- shims/cros-libva/src/buffer/enc_jpeg.rs +0 -159
- shims/cros-libva/src/buffer/jpeg_baseline.rs +0 -220
- shims/cros-libva/src/buffer/mpeg2.rs +0 -172
- shims/cros-libva/src/buffer/proc_pipeline.rs +1 -1
- shims/cros-libva/src/buffer/vp8.rs +0 -397
- shims/cros-libva/src/lib.rs +0 -465
- shims/cros-libva/src/test_frame.nv12 +0 -0
- shims/vk-video-ffi/Cargo.toml +0 -5
- shims/vk-video-ffi/examples/av1_decode_smoke.rs +0 -320
- shims/vk-video-ffi/examples/d3d11_pool.rs +0 -111
- shims/vk-video-ffi/examples/dmabuf_smoke.rs +0 -767
- shims/vk-video-ffi/examples/h264_decode_smoke.rs +0 -182
- shims/vk-video-ffi/examples/h265_decode_smoke.rs +0 -284
- shims/vk-video-ffi/src/av1_encode.rs +0 -52
- shims/vk-video-ffi/src/d3d11.rs +0 -2
- shims/vk-video-ffi/src/dmabuf.rs +0 -2
- shims/vk-video-ffi/src/h264_encode.rs +0 -46
- shims/vk-video-ffi/src/h265_encode.rs +0 -52
- shims/vk-video-ffi/src/session.rs +0 -12
Cargo.lockmodified+0 -4
| @@ -308,7 +308,6 @@ version = "0.0.13" | ||
| 308 | 308 | dependencies = [ |
| 309 | 309 | "bindgen", |
| 310 | 310 | "bitflags 2.13.1", |
| 311 | - "crc32fast", | |
| 312 | 311 | "log", |
| 313 | 312 | "pkg-config", |
| 314 | 313 | "regex", |
| @@ -1908,9 +1907,6 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" | ||
| 1908 | 1907 | name = "vk-video-ffi" |
| 1909 | 1908 | version = "0.1.0" |
| 1910 | 1909 | dependencies = [ |
| 1911 | - "ec-av1-syntax", | |
| 1912 | - "ec-h264-syntax", | |
| 1913 | - "ec-h265-syntax", | |
| 1914 | 1910 | "vulkanalia", |
| 1915 | 1911 | "windows", |
| 1916 | 1912 | ] |
crates/ec-va/abi-probe.cdeleted+0 -90
| @@ -1,90 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * ABI probe for the hand-written libva FFI in src/sys.rs. | |
| 3 | - * | |
| 4 | - * src/sys.rs transcribes libva struct layouts by hand (no bindgen, family rule). | |
| 5 | - * This probe is the evidence for that transcription: it prints the sizes, | |
| 6 | - * alignments and field offsets that the *system* headers produce, so the | |
| 7 | - * `const _: () = assert!(...)` block in sys.rs can be checked against a real | |
| 8 | - * compiler instead of against a reading of the header. | |
| 9 | - * | |
| 10 | - * Run: | |
| 11 | - * cc -o /tmp/ec-va-abi-probe crates/ec-va/abi-probe.c $(pkg-config --cflags --libs libva) \ | |
| 12 | - * && /tmp/ec-va-abi-probe | |
| 13 | - * | |
| 14 | - * Recorded output (libva 1.23.0, x86_64-unknown-linux-gnu, gcc 15) is pasted | |
| 15 | - * into the assertion block in sys.rs. Any mismatch after a libva upgrade means | |
| 16 | - * the transcription drifted — the exact failure mode that broke cros-libva at | |
| 17 | - * libva >= 1.23. | |
| 18 | - */ | |
| 19 | -#include <stdio.h> | |
| 20 | -#include <stddef.h> | |
| 21 | -#include <va/va.h> | |
| 22 | -#include <va/va_drmcommon.h> | |
| 23 | - | |
| 24 | -#define SA(T) printf("%-32s size=%-5zu align=%zu\n", #T, sizeof(T), _Alignof(T)) | |
| 25 | -#define OF(T, F) printf(" %-30s offset=%zu\n", #T "." #F, offsetof(T, F)) | |
| 26 | - | |
| 27 | -int main(void) | |
| 28 | -{ | |
| 29 | - printf("libva headers: %s\n", VA_VERSION_S); | |
| 30 | - | |
| 31 | - SA(VAStatus); | |
| 32 | - SA(VAGenericID); | |
| 33 | - SA(VAProfile); | |
| 34 | - SA(VAEntrypoint); | |
| 35 | - SA(VAConfigAttribType); | |
| 36 | - SA(VAConfigAttrib); | |
| 37 | - OF(VAConfigAttrib, type); | |
| 38 | - OF(VAConfigAttrib, value); | |
| 39 | - | |
| 40 | - SA(VAGenericValue); | |
| 41 | - OF(VAGenericValue, type); | |
| 42 | - OF(VAGenericValue, value); | |
| 43 | - | |
| 44 | - SA(VASurfaceAttrib); | |
| 45 | - OF(VASurfaceAttrib, type); | |
| 46 | - OF(VASurfaceAttrib, flags); | |
| 47 | - OF(VASurfaceAttrib, value); | |
| 48 | - | |
| 49 | - SA(VAImageFormat); | |
| 50 | - OF(VAImageFormat, fourcc); | |
| 51 | - OF(VAImageFormat, byte_order); | |
| 52 | - OF(VAImageFormat, bits_per_pixel); | |
| 53 | - OF(VAImageFormat, depth); | |
| 54 | - OF(VAImageFormat, red_mask); | |
| 55 | - OF(VAImageFormat, alpha_mask); | |
| 56 | - OF(VAImageFormat, va_reserved); | |
| 57 | - | |
| 58 | - SA(VAImage); | |
| 59 | - OF(VAImage, image_id); | |
| 60 | - OF(VAImage, format); | |
| 61 | - OF(VAImage, buf); | |
| 62 | - OF(VAImage, width); | |
| 63 | - OF(VAImage, height); | |
| 64 | - OF(VAImage, data_size); | |
| 65 | - OF(VAImage, num_planes); | |
| 66 | - OF(VAImage, pitches); | |
| 67 | - OF(VAImage, offsets); | |
| 68 | - OF(VAImage, num_palette_entries); | |
| 69 | - OF(VAImage, entry_bytes); | |
| 70 | - OF(VAImage, component_order); | |
| 71 | - OF(VAImage, va_reserved); | |
| 72 | - | |
| 73 | - SA(VADRMPRIMESurfaceDescriptor); | |
| 74 | - OF(VADRMPRIMESurfaceDescriptor, fourcc); | |
| 75 | - OF(VADRMPRIMESurfaceDescriptor, width); | |
| 76 | - OF(VADRMPRIMESurfaceDescriptor, height); | |
| 77 | - OF(VADRMPRIMESurfaceDescriptor, num_objects); | |
| 78 | - OF(VADRMPRIMESurfaceDescriptor, objects); | |
| 79 | - OF(VADRMPRIMESurfaceDescriptor, num_layers); | |
| 80 | - OF(VADRMPRIMESurfaceDescriptor, layers); | |
| 81 | - printf(" object elem size=%zu align=%zu\n", | |
| 82 | - sizeof(((VADRMPRIMESurfaceDescriptor *)0)->objects[0]), | |
| 83 | - _Alignof(((VADRMPRIMESurfaceDescriptor *)0)->objects[0])); | |
| 84 | - printf(" layer elem size=%zu align=%zu\n", | |
| 85 | - sizeof(((VADRMPRIMESurfaceDescriptor *)0)->layers[0]), | |
| 86 | - _Alignof(((VADRMPRIMESurfaceDescriptor *)0)->layers[0])); | |
| 87 | - | |
| 88 | - SA(VARectangle); | |
| 89 | - return 0; | |
| 90 | -} |
crates/ec-va/src/cacheline.rsdeleted+0 -78
| @@ -1,78 +0,0 @@ | ||
| 1 | -//! Which cache lines a CPU write-back of a mapped DMA-BUF has to visit. | |
| 2 | -//! | |
| 3 | -//! `CLFLUSH` takes an address and writes back the whole cache line holding it, | |
| 4 | -//! so a buffer needs one flush per line, not one per byte. The incumbent | |
| 5 | -//! stack flushed every byte (64 instructions per line, 6.2 ms per 1080p | |
| 6 | -//! picture on radeonsi). The base of a mapping is not guaranteed to be cache | |
| 7 | -//! aligned, so the last byte's line is flushed too: a range that starts | |
| 8 | -//! mid-line can straddle one more line than its length suggests. | |
| 9 | - | |
| 10 | -/// Bytes per cache line on every x86-64 part this crate targets. | |
| 11 | -pub const CACHE_LINE: usize = 64; | |
| 12 | - | |
| 13 | -/// Offsets from a mapping's base at which to issue a flush for a buffer of | |
| 14 | -/// `len` bytes: one per [`CACHE_LINE`], plus the last byte when the stride | |
| 15 | -/// does not land on it. Empty for `len == 0`, which has no line to flush. | |
| 16 | -pub fn flush_offsets(len: usize) -> Vec<usize> { | |
| 17 | - if len == 0 { | |
| 18 | - return Vec::new(); | |
| 19 | - } | |
| 20 | - let last = len - 1; | |
| 21 | - let mut offsets: Vec<usize> = (0..len).step_by(CACHE_LINE).collect(); | |
| 22 | - if offsets.last() != Some(&last) { | |
| 23 | - offsets.push(last); | |
| 24 | - } | |
| 25 | - offsets | |
| 26 | -} | |
| 27 | - | |
| 28 | -#[cfg(test)] | |
| 29 | -mod tests { | |
| 30 | - use super::*; | |
| 31 | - | |
| 32 | - /// The absolute cache-line indices a flush at `offsets` writes back, for a | |
| 33 | - /// mapping whose base sits `base_mod` bytes into a line. | |
| 34 | - fn lines_flushed(base_mod: usize, offsets: &[usize]) -> Vec<usize> { | |
| 35 | - let base = 1000 * CACHE_LINE + base_mod; | |
| 36 | - let mut lines: Vec<usize> = offsets.iter().map(|o| (base + o) / CACHE_LINE).collect(); | |
| 37 | - lines.sort_unstable(); | |
| 38 | - lines.dedup(); | |
| 39 | - lines | |
| 40 | - } | |
| 41 | - | |
| 42 | - #[test] | |
| 43 | - fn empty_buffer_has_nothing_to_flush() { | |
| 44 | - assert!(flush_offsets(0).is_empty()); | |
| 45 | - } | |
| 46 | - | |
| 47 | - #[test] | |
| 48 | - fn one_flush_per_line_not_per_byte() { | |
| 49 | - assert_eq!(flush_offsets(1), vec![0]); | |
| 50 | - // 64 bytes from an unaligned base can still straddle two lines: the last byte too. | |
| 51 | - assert_eq!(flush_offsets(64), vec![0, 63]); | |
| 52 | - assert_eq!(flush_offsets(65), vec![0, 64]); | |
| 53 | - assert_eq!(flush_offsets(128), vec![0, 64, 127]); | |
| 54 | - // A 1080p NV12 picture (~3.1 MB) is ~48K flushes, not ~3.1M. | |
| 55 | - assert!(flush_offsets(1920 * 1620).len() <= 1920 * 1620 / CACHE_LINE + 2); | |
| 56 | - } | |
| 57 | - | |
| 58 | - // Regression for the straddle: with an unaligned base, the bytes of a | |
| 59 | - // range can sit in one more line than a stride from the base reaches, so | |
| 60 | - // every byte's line must be among the flushed lines for every alignment. | |
| 61 | - #[test] | |
| 62 | - fn every_byte_is_covered_for_every_base_alignment() { | |
| 63 | - for base_mod in 0..CACHE_LINE { | |
| 64 | - for len in 0..=300 { | |
| 65 | - let offsets = flush_offsets(len); | |
| 66 | - let flushed = lines_flushed(base_mod, &offsets); | |
| 67 | - let base = 1000 * CACHE_LINE + base_mod; | |
| 68 | - for i in 0..len { | |
| 69 | - let line = (base + i) / CACHE_LINE; | |
| 70 | - assert!( | |
| 71 | - flushed.contains(&line), | |
| 72 | - "base_mod {base_mod} len {len}: byte {i} (line {line}) not flushed" | |
| 73 | - ); | |
| 74 | - } | |
| 75 | - } | |
| 76 | - } | |
| 77 | - } | |
| 78 | -} |
crates/ec-va/src/caps.rsmodified+0 -19
| @@ -127,25 +127,6 @@ va_enum! { | ||
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | -impl Profile { | |
| 131 | - /// True for the profiles the family decodes or encodes in hardware. | |
| 132 | - pub fn is_family_codec(self) -> bool { | |
| 133 | - matches!( | |
| 134 | - self, | |
| 135 | - Profile::H264ConstrainedBaseline | |
| 136 | - | Profile::H264Main | |
| 137 | - | Profile::H264High | |
| 138 | - | Profile::H264High10 | |
| 139 | - | Profile::HEVCMain | |
| 140 | - | Profile::HEVCMain10 | |
| 141 | - | Profile::VP9Profile0 | |
| 142 | - | Profile::VP9Profile2 | |
| 143 | - | Profile::AV1Profile0 | |
| 144 | - | Profile::AV1Profile2 | |
| 145 | - ) | |
| 146 | - } | |
| 147 | -} | |
| 148 | - | |
| 149 | 130 | /// What one (profile, entrypoint) pair supports. |
| 150 | 131 | /// One supported (profile, entrypoint) pair and what the driver says about it. |
| 151 | 132 | #[derive(Debug, Clone)] |
crates/ec-va/src/config.rsmodified+2 -18
| @@ -64,11 +64,9 @@ impl SurfaceCaps { | ||
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | -/// A live `VAConfigID`, remembering the profile and entrypoint it was made for. | |
| 67 | +/// A live `VAConfigID`. | |
| 68 | 68 | pub struct Config { |
| 69 | 69 | inner: cros_libva::Config, |
| 70 | - profile: Profile, | |
| 71 | - entrypoint: Entrypoint, | |
| 72 | 70 | } |
| 73 | 71 | |
| 74 | 72 | impl Config { |
| @@ -90,21 +88,7 @@ impl Config { | ||
| 90 | 88 | "vaCreateConfig", |
| 91 | 89 | display.create_config(attrs, profile.as_raw(), entrypoint.as_raw()), |
| 92 | 90 | )?; |
| 93 | - Ok(Config { | |
| 94 | - inner, | |
| 95 | - profile, | |
| 96 | - entrypoint, | |
| 97 | - }) | |
| 98 | - } | |
| 99 | - | |
| 100 | - /// The profile this config decodes or encodes. | |
| 101 | - pub fn profile(&self) -> Profile { | |
| 102 | - self.profile | |
| 103 | - } | |
| 104 | - | |
| 105 | - /// The entrypoint this config was created for. | |
| 106 | - pub fn entrypoint(&self) -> Entrypoint { | |
| 107 | - self.entrypoint | |
| 91 | + Ok(Config { inner }) | |
| 108 | 92 | } |
| 109 | 93 | |
| 110 | 94 | /// The cros-libva handle, for the calls that take one. |
crates/ec-va/src/display.rsmodified+0 -9
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | //! Opening a VA display on a DRM render node. |
| 2 | 2 | |
| 3 | -use std::path::Path; | |
| 4 | 3 | use std::rc::Rc; |
| 5 | 4 | |
| 6 | 5 | use crate::error::{Error, Result}; |
| @@ -14,14 +13,6 @@ pub fn open() -> Result<Rc<Display>> { | ||
| 14 | 13 | Display::open().ok_or(Error::NoDevice) |
| 15 | 14 | } |
| 16 | 15 | |
| 17 | -/// Open a specific DRM render node. | |
| 18 | -pub fn open_path(path: &Path) -> Result<Rc<Display>> { | |
| 19 | - Display::open_drm_display(path).map_err(|e| Error::Drm { | |
| 20 | - path: path.display().to_string(), | |
| 21 | - message: format!("{e:?}"), | |
| 22 | - }) | |
| 23 | -} | |
| 24 | - | |
| 25 | 16 | /// The driver's vendor string (`vaQueryVendorString`). |
| 26 | 17 | pub fn vendor(display: &Display) -> Result<String> { |
| 27 | 18 | display |
crates/ec-va/src/error.rsmodified+0 -8
| @@ -21,13 +21,6 @@ pub enum Error { | ||
| 21 | 21 | /// libva's description of `status`. |
| 22 | 22 | message: String, |
| 23 | 23 | }, |
| 24 | - /// A DRM render node could not be opened as a VA display. | |
| 25 | - Drm { | |
| 26 | - /// The node that was tried. | |
| 27 | - path: String, | |
| 28 | - /// Why it failed. | |
| 29 | - message: String, | |
| 30 | - }, | |
| 31 | 24 | /// No usable `/dev/dri/renderD*` VA display exists. |
| 32 | 25 | NoDevice, |
| 33 | 26 | /// libva returned a value this crate cannot interpret. |
| @@ -66,7 +59,6 @@ impl fmt::Display for Error { | ||
| 66 | 59 | status, |
| 67 | 60 | message, |
| 68 | 61 | } => write!(f, "{op} failed: {message} (VAStatus 0x{status:08x})"), |
| 69 | - Error::Drm { path, message } => write!(f, "opening DRM node {path}: {message}"), | |
| 70 | 62 | Error::NoDevice => write!(f, "no usable /dev/dri/renderD* VA display"), |
| 71 | 63 | Error::Protocol(what) => write!(f, "libva returned an uninterpretable value: {what}"), |
| 72 | 64 | } |
crates/ec-va/src/lib.rsmodified+1 -2
| @@ -34,7 +34,6 @@ | ||
| 34 | 34 | #![forbid(unsafe_code)] |
| 35 | 35 | #![deny(missing_docs)] |
| 36 | 36 | |
| 37 | -pub mod cacheline; | |
| 38 | 37 | pub mod caps; |
| 39 | 38 | pub mod config; |
| 40 | 39 | pub mod display; |
| @@ -47,7 +46,7 @@ pub use cros_libva as va; | ||
| 47 | 46 | |
| 48 | 47 | pub use caps::{CapEntry, CapReport, Entrypoint, Profile, fourcc_str}; |
| 49 | 48 | pub use config::{Config, ConfigAttrib, SurfaceCaps, caps_of}; |
| 50 | -pub use display::{Display, open, open_path}; | |
| 49 | +pub use display::{Display, open}; | |
| 51 | 50 | pub use error::{Error, Result}; |
| 52 | 51 | pub use picture::{Buffer, Context, Picture, create_context}; |
| 53 | 52 | pub use surface::{ |
crates/ec-va/tests/gpu.rsmodified+1 -385
| @@ -9,14 +9,12 @@ | ||
| 9 | 9 | //! |
| 10 | 10 | //! Reference: `vainfo` on this box (Mesa 26.1.6, radeonsi gfx1200, RX 9060 XT). |
| 11 | 11 | |
| 12 | -use std::os::fd::AsRawFd; | |
| 13 | 12 | use std::rc::Rc; |
| 14 | 13 | use std::sync::{Mutex, MutexGuard, OnceLock}; |
| 15 | -use std::time::Duration; | |
| 16 | 14 | |
| 17 | 15 | use ec_va::caps::{Entrypoint, Profile}; |
| 18 | 16 | use ec_va::va; |
| 19 | -use ec_va::{CapReport, Config, Display, Image, Surface, SurfaceExt, SurfaceSpec, create_pool}; | |
| 17 | +use ec_va::{CapReport, Display, Image, Surface, SurfaceExt, SurfaceSpec, create_pool}; | |
| 20 | 18 | |
| 21 | 19 | /// Runs the tests in this binary one at a time. |
| 22 | 20 | /// |
| @@ -57,28 +55,6 @@ fn one(display: &Rc<Display>, spec: &SurfaceSpec) -> Surface { | ||
| 57 | 55 | |
| 58 | 56 | // -------------------------------------------------------------------------- |
| 59 | 57 | // Display |
| 60 | -// -------------------------------------------------------------------------- | |
| 61 | - | |
| 62 | -// The raw `Display::version` / `device_path` / `is_valid` checks no longer | |
| 63 | -// exist in cros-libva; what remains observable is that the open succeeded and | |
| 64 | -// the driver answers real queries. | |
| 65 | -#[test] | |
| 66 | -fn display_opens_on_a_render_node() { | |
| 67 | - let _serial = serial(); | |
| 68 | - let display = display(); | |
| 69 | - let vendor = ec_va::display::vendor(&display).expect("vendor string"); | |
| 70 | - assert!(!vendor.is_empty(), "driver reported an empty vendor string"); | |
| 71 | - assert!( | |
| 72 | - !display | |
| 73 | - .query_config_profiles() | |
| 74 | - .expect("profiles") | |
| 75 | - .is_empty() | |
| 76 | - ); | |
| 77 | -} | |
| 78 | - | |
| 79 | -// -------------------------------------------------------------------------- | |
| 80 | -// Capabilities — the table must match `vainfo` on this GPU | |
| 81 | -// -------------------------------------------------------------------------- | |
| 82 | 58 | |
| 83 | 59 | #[test] |
| 84 | 60 | fn caps_match_vainfo_on_this_gpu() { |
| @@ -170,351 +146,6 @@ fn caps_match_vainfo_on_this_gpu() { | ||
| 170 | 146 | ); |
| 171 | 147 | } |
| 172 | 148 | |
| 173 | -#[test] | |
| 174 | -fn caps_report_driver_legal_surface_sizes() { | |
| 175 | - let _serial = serial(); | |
| 176 | - let display = display(); | |
| 177 | - let caps = CapReport::probe(&display).expect("probe"); | |
| 178 | - let entry = caps | |
| 179 | - .entry(Profile::H264Main, Entrypoint::VLD) | |
| 180 | - .expect("H264 Main VLD"); | |
| 181 | - let surfaces = entry.surfaces.as_ref().expect("surface caps"); | |
| 182 | - | |
| 183 | - // radeonsi rejects decode surfaces below 64x64. Probing with a hardcoded | |
| 184 | - // 16x16 config is what used to panic here, so the minimum is reported | |
| 185 | - // rather than assumed. | |
| 186 | - assert_eq!(surfaces.min_width, Some(64)); | |
| 187 | - assert_eq!(surfaces.min_height, Some(64)); | |
| 188 | - assert!(surfaces.max_width.unwrap() >= 4096); | |
| 189 | - assert!( | |
| 190 | - !surfaces.allows(16, 16), | |
| 191 | - "16x16 must be refused by the caps" | |
| 192 | - ); | |
| 193 | - assert!(surfaces.allows(1920, 1088)); | |
| 194 | - | |
| 195 | - // DRM PRIME 2 export must be advertised: that is how frames leave the GPU. | |
| 196 | - assert!( | |
| 197 | - surfaces.memory_types & va::VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 != 0, | |
| 198 | - "memory types 0x{:08x} lack DRM_PRIME_2", | |
| 199 | - surfaces.memory_types | |
| 200 | - ); | |
| 201 | -} | |
| 202 | - | |
| 203 | -#[test] | |
| 204 | -fn unsupported_pair_is_refused_by_the_driver() { | |
| 205 | - let _serial = serial(); | |
| 206 | - // A refusal is a claim: prove the capability is genuinely absent rather | |
| 207 | - // than assumed absent. | |
| 208 | - let display = display(); | |
| 209 | - let caps = CapReport::probe(&display).expect("probe"); | |
| 210 | - assert!(!caps.supports(Profile::VP9Profile1, Entrypoint::VLD)); | |
| 211 | - | |
| 212 | - let err = Config::new(&display, Profile::VP9Profile1, Entrypoint::VLD, &[]) | |
| 213 | - .err() | |
| 214 | - .expect("VP9 Profile1 decode does not exist on this GPU"); | |
| 215 | - let status = err.status().expect("a VAStatus-carrying error"); | |
| 216 | - assert!( | |
| 217 | - status == va::VA_STATUS_ERROR_UNSUPPORTED_PROFILE as i32 | |
| 218 | - || status == va::VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT as i32, | |
| 219 | - "unexpected refusal: {err}" | |
| 220 | - ); | |
| 221 | - assert!(err.to_string().contains("vaCreateConfig"), "{err}"); | |
| 222 | -} | |
| 223 | - | |
| 224 | -// -------------------------------------------------------------------------- | |
| 225 | -// Surfaces | |
| 226 | -// -------------------------------------------------------------------------- | |
| 227 | - | |
| 228 | -#[test] | |
| 229 | -fn surface_pool_create_and_destroy_is_leak_free() { | |
| 230 | - let _serial = serial(); | |
| 231 | - let display = display(); | |
| 232 | - let spec = SurfaceSpec::nv12(64, 64); | |
| 233 | - | |
| 234 | - // Warm up so first-touch allocations are not counted as a leak. | |
| 235 | - for _ in 0..4 { | |
| 236 | - let p = pool(&display, &spec, 16); | |
| 237 | - assert_eq!(p.len(), 16); | |
| 238 | - drop(p); | |
| 239 | - } | |
| 240 | - | |
| 241 | - let before = vm_rss_kb(); | |
| 242 | - for _ in 0..100 { | |
| 243 | - let p = pool(&display, &spec, 16); | |
| 244 | - // Every id must be distinct and valid, or the pool is aliasing memory. | |
| 245 | - let mut ids: Vec<_> = p.iter().map(|s| s.id()).collect(); | |
| 246 | - ids.sort_unstable(); | |
| 247 | - ids.dedup(); | |
| 248 | - assert_eq!(ids.len(), 16, "vaCreateSurfaces returned duplicate ids"); | |
| 249 | - assert!(ids.iter().all(|&id| id != va::VA_INVALID_SURFACE)); | |
| 250 | - drop(p); | |
| 251 | - } | |
| 252 | - let after = vm_rss_kb(); | |
| 253 | - | |
| 254 | - // 1600 surfaces created and destroyed. A per-surface leak would be obvious | |
| 255 | - // at this scale; the incumbent's unmatched map leaked ~3MB per frame. | |
| 256 | - let delta_kb = after.saturating_sub(before); | |
| 257 | - assert!( | |
| 258 | - delta_kb < 50 * 1024, | |
| 259 | - "VmRSS grew {delta_kb} kB over 100 create/destroy cycles" | |
| 260 | - ); | |
| 261 | -} | |
| 262 | - | |
| 263 | -#[test] | |
| 264 | -fn derive_image_maps_and_reads_back() { | |
| 265 | - let _serial = serial(); | |
| 266 | - let display = display(); | |
| 267 | - let surface = one(&display, &SurfaceSpec::nv12(64, 64)); | |
| 268 | - let mut image = Image::derive_from(&surface, (64, 64)).expect("vaDeriveImage"); | |
| 269 | - | |
| 270 | - let va_image = *image.image(); | |
| 271 | - assert_eq!(va_image.format.fourcc, va::VA_FOURCC_NV12); | |
| 272 | - assert_eq!(image.display_resolution(), (64, 64)); | |
| 273 | - assert!(image.is_derived()); | |
| 274 | - assert_eq!(va_image.num_planes, 2, "NV12 is luma + interleaved chroma"); | |
| 275 | - let pitch = va_image.pitches[0] as usize; | |
| 276 | - assert!(pitch >= 64, "luma pitch {pitch} is narrower than the image"); | |
| 277 | - assert!(va_image.pitches[1] > 0, "chroma pitch missing"); | |
| 278 | - let luma_off = va_image.offsets[0] as usize; | |
| 279 | - let chroma_off = va_image.offsets[1] as usize; | |
| 280 | - assert!( | |
| 281 | - chroma_off >= luma_off + pitch * 64, | |
| 282 | - "luma plane must be at least pitch * height" | |
| 283 | - ); | |
| 284 | - | |
| 285 | - { | |
| 286 | - let bytes: &mut [u8] = image.as_mut(); | |
| 287 | - assert!( | |
| 288 | - bytes.len() > chroma_off, | |
| 289 | - "mapping shorter than chroma plane" | |
| 290 | - ); | |
| 291 | - for (i, byte) in bytes[luma_off..luma_off + pitch * 64] | |
| 292 | - .iter_mut() | |
| 293 | - .enumerate() | |
| 294 | - { | |
| 295 | - *byte = (i % 251) as u8; | |
| 296 | - } | |
| 297 | - let luma = &bytes[luma_off..]; | |
| 298 | - assert_eq!(luma[0], 0); | |
| 299 | - assert_eq!(luma[250], 250); | |
| 300 | - assert_eq!(luma[251], 0, "write did not survive within the mapping"); | |
| 301 | - } | |
| 302 | - drop(image); | |
| 303 | - | |
| 304 | - // Re-deriving after the drop proves the unmap/destroy actually happened. | |
| 305 | - // | |
| 306 | - // What is deliberately *not* asserted: that the bytes written above are | |
| 307 | - // readable through this second mapping. On radeonsi 26.1 a derived-image | |
| 308 | - // mapping is write-oriented staging — the write reaches the surface (see | |
| 309 | - // `created_image_reads_a_surface_back`), but a fresh map reads back zeros. | |
| 310 | - let again = Image::derive_from(&surface, (64, 64)).expect("second vaDeriveImage"); | |
| 311 | - assert_eq!( | |
| 312 | - again.image().pitches[0] as usize, | |
| 313 | - pitch, | |
| 314 | - "second mapping has a different geometry" | |
| 315 | - ); | |
| 316 | - assert!(!AsRef::<[u8]>::as_ref(&again).is_empty()); | |
| 317 | -} | |
| 318 | - | |
| 319 | -#[test] | |
| 320 | -fn created_image_reads_a_surface_back() { | |
| 321 | - let _serial = serial(); | |
| 322 | - let display = display(); | |
| 323 | - let surface = one(&display, &SurfaceSpec::nv12(64, 64)); | |
| 324 | - // Paint through the derived image so there is something known to read back. | |
| 325 | - { | |
| 326 | - let mut derived = Image::derive_from(&surface, (64, 64)).expect("derive"); | |
| 327 | - let luma_off = derived.image().offsets[0] as usize; | |
| 328 | - let pitch = derived.image().pitches[0] as usize; | |
| 329 | - let bytes: &mut [u8] = derived.as_mut(); | |
| 330 | - for byte in &mut bytes[luma_off..luma_off + pitch * 64] { | |
| 331 | - *byte = 0x5a; | |
| 332 | - } | |
| 333 | - } | |
| 334 | - surface.sync().expect("sync"); | |
| 335 | - | |
| 336 | - let fmt = image_format(&display, va::VA_FOURCC_NV12); | |
| 337 | - let image = Image::create_from(&surface, fmt, (64, 64), (64, 64)).expect("vaGetImage"); | |
| 338 | - let luma_off = image.image().offsets[0] as usize; | |
| 339 | - let bytes: &[u8] = image.as_ref(); | |
| 340 | - assert!( | |
| 341 | - bytes[luma_off..luma_off + 64].iter().all(|&b| b == 0x5a), | |
| 342 | - "vaGetImage did not return the painted luma" | |
| 343 | - ); | |
| 344 | - drop(image); | |
| 345 | - | |
| 346 | - // A region larger than the surface must be refused, not read out of bounds. | |
| 347 | - let fmt = image_format(&display, va::VA_FOURCC_NV12); | |
| 348 | - let refused = Image::create_from(&surface, fmt, (128, 128), (128, 128)); | |
| 349 | - assert!( | |
| 350 | - refused.is_err(), | |
| 351 | - "region larger than the surface must be refused" | |
| 352 | - ); | |
| 353 | -} | |
| 354 | - | |
| 355 | -#[test] | |
| 356 | -fn prime_export_owns_and_releases_its_descriptors() { | |
| 357 | - let _serial = serial(); | |
| 358 | - let display = display(); | |
| 359 | - let surface = one(&display, &SurfaceSpec::nv12(64, 64)); | |
| 360 | - surface | |
| 361 | - .sync_timeout(Duration::from_secs(5)) | |
| 362 | - .expect("sync before export"); | |
| 363 | - | |
| 364 | - let baseline = open_fd_count(); | |
| 365 | - let exported = surface.export().expect("vaExportSurfaceHandle"); | |
| 366 | - | |
| 367 | - assert_eq!(exported.fourcc, va::VA_FOURCC_NV12); | |
| 368 | - assert_eq!((exported.width, exported.height), (64, 64)); | |
| 369 | - assert!(!exported.objects.is_empty(), "no DRM objects exported"); | |
| 370 | - assert!(!exported.layers.is_empty(), "no layers exported"); | |
| 371 | - for object in &exported.objects { | |
| 372 | - assert!(object.fd.as_raw_fd() >= 0); | |
| 373 | - assert!(object.size > 0); | |
| 374 | - } | |
| 375 | - for layer in &exported.layers { | |
| 376 | - assert!(!layer.planes.is_empty()); | |
| 377 | - for &(object_index, _offset, pitch) in &layer.planes { | |
| 378 | - assert!((object_index as usize) < exported.objects.len()); | |
| 379 | - assert!(pitch > 0); | |
| 380 | - } | |
| 381 | - } | |
| 382 | - | |
| 383 | - let with_export = open_fd_count(); | |
| 384 | - assert_eq!( | |
| 385 | - with_export - baseline, | |
| 386 | - exported.objects.len(), | |
| 387 | - "exported fd count does not match the descriptor" | |
| 388 | - ); | |
| 389 | - drop(exported); | |
| 390 | - assert_eq!( | |
| 391 | - open_fd_count(), | |
| 392 | - baseline, | |
| 393 | - "dropping the export leaked file descriptors" | |
| 394 | - ); | |
| 395 | -} | |
| 396 | - | |
| 397 | -// -------------------------------------------------------------------------- | |
| 398 | -// Context / picture protocol | |
| 399 | -// -------------------------------------------------------------------------- | |
| 400 | - | |
| 401 | -#[test] | |
| 402 | -fn picture_typestate_walks_the_va_protocol() { | |
| 403 | - let _serial = serial(); | |
| 404 | - let display = display(); | |
| 405 | - let config = Config::new(&display, Profile::H264Main, Entrypoint::VLD, &[]).expect("config"); | |
| 406 | - let targets = pool(&display, &SurfaceSpec::nv12(1920, 1088), 2); | |
| 407 | - let context = ec_va::create_context(&display, &config, 1920, 1088, Some(&targets), true) | |
| 408 | - .expect("context"); | |
| 409 | - let targets: Vec<Rc<Surface>> = targets.into_iter().map(Rc::new).collect(); | |
| 410 | - | |
| 411 | - // New -> Begin. Each transition consumes the picture, so nothing can call | |
| 412 | - // `begin` twice or reach `sync` without `end`. | |
| 413 | - let picture = ec_va::Picture::new(0, Rc::clone(&context), Rc::clone(&targets[0])); | |
| 414 | - let picture = picture.begin::<()>().expect("vaBeginPicture"); | |
| 415 | - assert_eq!(picture.surface::<()>().id(), targets[0].id()); | |
| 416 | - | |
| 417 | - // Begin -> Render -> End. Submitting a picture with no parameter buffers | |
| 418 | - // is a driver-level error here (mesa creates the decoder lazily from the | |
| 419 | - // picture parameters); what matters is that it surfaces as a typed error | |
| 420 | - // instead of a panic, an abort or a GPU hang. Real submissions carry | |
| 421 | - // parameter/slice buffers and are `ec-hw`'s job. | |
| 422 | - let failed = picture.render().and_then(|p| p.end()); | |
| 423 | - let err = failed | |
| 424 | - .err() | |
| 425 | - .expect("empty submission is rejected by radeonsi"); | |
| 426 | - assert_eq!( | |
| 427 | - err.va_status(), | |
| 428 | - va::VA_STATUS_ERROR_INVALID_CONTEXT as i32, | |
| 429 | - "{err}" | |
| 430 | - ); | |
| 431 | - | |
| 432 | - // The display is still usable afterwards: an abandoned picture must not | |
| 433 | - // wedge the context. | |
| 434 | - let picture = ec_va::Picture::new(0, Rc::clone(&context), Rc::clone(&targets[1])) | |
| 435 | - .begin::<()>() | |
| 436 | - .expect("second vaBeginPicture after a failed end"); | |
| 437 | - drop(picture); | |
| 438 | - assert!(display.query_vendor_string().is_ok()); | |
| 439 | -} | |
| 440 | - | |
| 441 | -#[test] | |
| 442 | -fn buffers_map_unmap_and_destroy() { | |
| 443 | - let _serial = serial(); | |
| 444 | - let display = display(); | |
| 445 | - let config = | |
| 446 | - Config::new(&display, Profile::H264Main, Entrypoint::EncSlice, &[]).expect("config"); | |
| 447 | - let targets = pool(&display, &SurfaceSpec::nv12(1920, 1088), 1); | |
| 448 | - let context = ec_va::create_context(&display, &config, 1920, 1088, Some(&targets), true) | |
| 449 | - .expect("context"); | |
| 450 | - | |
| 451 | - // Coded-output buffer: allocated empty, mapped, unmapped, dropped. | |
| 452 | - const CODED_SIZE: usize = 1 << 20; | |
| 453 | - let coded = context | |
| 454 | - .create_enc_coded(CODED_SIZE) | |
| 455 | - .expect("vaCreateBuffer"); | |
| 456 | - assert_ne!(coded.id(), va::VA_INVALID_ID); | |
| 457 | - { | |
| 458 | - let mapped = va::MappedCodedBuffer::new(&coded).expect("vaMapBuffer"); | |
| 459 | - // Never filled by an encode: no segment carries payload bytes. | |
| 460 | - assert!(mapped.iter().all(|s| s.buf.is_empty())); | |
| 461 | - } | |
| 462 | - // Mapping again proves the guard released the mapping. | |
| 463 | - drop(va::MappedCodedBuffer::new(&coded).expect("second vaMapBuffer after unmap")); | |
| 464 | - | |
| 465 | - // Parameter buffer: data is copied into driver memory during the call. | |
| 466 | - let buffer = ec_va::picture::buffer( | |
| 467 | - &context, | |
| 468 | - va::BufferType::EncMiscParameter(va::EncMiscParameter::FrameRate( | |
| 469 | - va::EncMiscParameterFrameRate::new(30, 0), | |
| 470 | - )), | |
| 471 | - ) | |
| 472 | - .expect("vaCreateBuffer from a typed parameter"); | |
| 473 | - drop(buffer); | |
| 474 | - drop(coded); | |
| 475 | -} | |
| 476 | - | |
| 477 | -#[test] | |
| 478 | -fn context_keeps_its_dependencies_alive() { | |
| 479 | - let _serial = serial(); | |
| 480 | - // Dropping the config and the surfaces while the context lives must be | |
| 481 | - // safe: the context holds `Rc`s, so libva's destruction order (buffers -> | |
| 482 | - // context -> surfaces -> config -> display) cannot be violated. | |
| 483 | - let display = display(); | |
| 484 | - let config = Config::new(&display, Profile::H264Main, Entrypoint::VLD, &[]).expect("config"); | |
| 485 | - let targets = pool(&display, &SurfaceSpec::nv12(1920, 1088), 2); | |
| 486 | - let context = ec_va::create_context(&display, &config, 1920, 1088, Some(&targets), true) | |
| 487 | - .expect("context"); | |
| 488 | - let target = Rc::new(targets.into_iter().next().expect("target")); | |
| 489 | - drop(config); | |
| 490 | - | |
| 491 | - let picture = ec_va::Picture::new(0, Rc::clone(&context), target) | |
| 492 | - .begin::<()>() | |
| 493 | - .expect("begin"); | |
| 494 | - drop(picture); | |
| 495 | - drop(context); | |
| 496 | - assert!(display.query_vendor_string().is_ok()); | |
| 497 | -} | |
| 498 | - | |
| 499 | -// -------------------------------------------------------------------------- | |
| 500 | -// VPP | |
| 501 | -// -------------------------------------------------------------------------- | |
| 502 | - | |
| 503 | -// `vaQueryVideoProcFilters` is no longer wrapped (cros-libva has no such | |
| 504 | -// call), so the filter list cannot be printed. The equivalent: a pipeline | |
| 505 | -// still opens on the real display and runs a whole-surface NV12 pass. | |
| 506 | -#[test] | |
| 507 | -fn vpp_filters_probe() { | |
| 508 | - let _serial = serial(); | |
| 509 | - let display = display(); | |
| 510 | - let targets = pool(&display, &SurfaceSpec::nv12(1920, 1080), 2); | |
| 511 | - let vpp = ec_va::Vpp::new(&display, va::VA_RT_FORMAT_YUV420, 1920, 1080).expect("vpp opens"); | |
| 512 | - let mut it = targets.into_iter(); | |
| 513 | - let src = it.next().expect("src"); | |
| 514 | - let dst = Rc::new(it.next().expect("dst")); | |
| 515 | - vpp.convert(&src, dst).expect("vpp pipeline runs"); | |
| 516 | -} | |
| 517 | - | |
| 518 | 149 | /// `Vpp::convert` end to end: a P010 source surface into an NV12 destination, |
| 519 | 150 | /// no readback — the conversion `ec-hw`'s `encode_frame` relies on for a |
| 520 | 151 | /// 10-bit source. |
| @@ -537,21 +168,6 @@ fn vpp_converts_p010_to_nv12() { | ||
| 537 | 168 | |
| 538 | 169 | // -------------------------------------------------------------------------- |
| 539 | 170 | // helpers |
| 540 | -// -------------------------------------------------------------------------- | |
| 541 | - | |
| 542 | -fn vm_rss_kb() -> u64 { | |
| 543 | - let status = std::fs::read_to_string("/proc/self/status").expect("/proc/self/status"); | |
| 544 | - for line in status.lines() { | |
| 545 | - if let Some(rest) = line.strip_prefix("VmRSS:") { | |
| 546 | - return rest | |
| 547 | - .split_whitespace() | |
| 548 | - .next() | |
| 549 | - .and_then(|v| v.parse().ok()) | |
| 550 | - .expect("VmRSS value"); | |
| 551 | - } | |
| 552 | - } | |
| 553 | - panic!("VmRSS not found in /proc/self/status"); | |
| 554 | -} | |
| 555 | 171 | |
| 556 | 172 | fn open_fd_count() -> usize { |
| 557 | 173 | std::fs::read_dir("/proc/self/fd") |
shims/cros-libva/Android.bpdeleted+0 -63
| @@ -1,63 +0,0 @@ | ||
| 1 | -// Copyright 2024 The ChromiumOS Authors | |
| 2 | -// Use of this source code is governed by a BSD-style license that can be | |
| 3 | -// found in the LICENSE file. | |
| 4 | - | |
| 5 | -// This file is generated by cargo_embargo. | |
| 6 | -// Do not modify this file because the changes will be overridden on upgrade. | |
| 7 | - | |
| 8 | -package { | |
| 9 | - default_applicable_licenses: ["external_rust_cros-libva_license"], | |
| 10 | -} | |
| 11 | - | |
| 12 | -soong_config_module_type_import { | |
| 13 | - from: "system/cros-codecs/Android.bp", | |
| 14 | - module_types: [ | |
| 15 | - "rust_defaults_cros_codecs_protected_content", | |
| 16 | - ], | |
| 17 | -} | |
| 18 | - | |
| 19 | -rust_defaults_cros_codecs_protected_content { | |
| 20 | - name: "cros_libva_protected_content_rust_library_defaults", | |
| 21 | - soong_config_variables: { | |
| 22 | - intel_protected_content: { | |
| 23 | - features: ["intel-protected-content-headers"], | |
| 24 | - }, | |
| 25 | - }, | |
| 26 | -} | |
| 27 | - | |
| 28 | -rust_library { | |
| 29 | - name: "libcros_libva", | |
| 30 | - crate_name: "cros_libva", | |
| 31 | - cargo_env_compat: true, | |
| 32 | - cargo_pkg_version: "0.0.8", | |
| 33 | - crate_root: "src/lib.rs", | |
| 34 | - edition: "2021", | |
| 35 | - defaults: ["cros_libva_protected_content_rust_library_defaults"], | |
| 36 | - rustlibs: [ | |
| 37 | - "libbitflags", | |
| 38 | - "liblog_rust", | |
| 39 | - "libthiserror", | |
| 40 | - ], | |
| 41 | - apex_available: [ | |
| 42 | - "//apex_available:platform", | |
| 43 | - "//apex_available:anyapex", | |
| 44 | - ], | |
| 45 | - | |
| 46 | - cfgs: [ | |
| 47 | - "libva_1_21_or_higher", | |
| 48 | - "libva_1_20_or_higher", | |
| 49 | - "libva_1_19_or_higher", | |
| 50 | - "libva_1_16_or_higher", | |
| 51 | - ], | |
| 52 | - | |
| 53 | - vendor: true, | |
| 54 | - enabled: false, | |
| 55 | - arch: { | |
| 56 | - x86_64: { | |
| 57 | - enabled: true, | |
| 58 | - // Bindgen-generated bindings of our local libva headers. | |
| 59 | - srcs: [":libcros_libva_bindgen"], | |
| 60 | - shared_libs: ["libva"], | |
| 61 | - }, | |
| 62 | - }, | |
| 63 | -} |
shims/cros-libva/Cargo.tomlmodified+0 -3
| @@ -21,6 +21,3 @@ log = { version = "0", features = ["release_max_level_debug"] } | ||
| 21 | 21 | bindgen = "0.70.1" |
| 22 | 22 | pkg-config = "0.3.31" |
| 23 | 23 | regex = "1.11.1" |
| 24 | - | |
| 25 | -[dev-dependencies] | |
| 26 | -crc32fast = "1.2.1" |
shims/cros-libva/src/buffer.rsmodified+7 -129
| @@ -5,25 +5,17 @@ | ||
| 5 | 5 | //! Wrappers and helpers around `VABuffer`s. |
| 6 | 6 | |
| 7 | 7 | mod av1; |
| 8 | -mod enc_jpeg; | |
| 9 | 8 | mod enc_misc; |
| 10 | 9 | mod h264; |
| 11 | 10 | mod hevc; |
| 12 | -mod jpeg_baseline; | |
| 13 | -mod mpeg2; | |
| 14 | 11 | mod proc_pipeline; |
| 15 | -mod vp8; | |
| 16 | 12 | mod vp9; |
| 17 | 13 | |
| 18 | 14 | pub use av1::*; |
| 19 | -pub use enc_jpeg::*; | |
| 20 | 15 | pub use enc_misc::*; |
| 21 | 16 | pub use h264::*; |
| 22 | 17 | pub use hevc::*; |
| 23 | -pub use jpeg_baseline::*; | |
| 24 | -pub use mpeg2::*; | |
| 25 | 18 | pub use proc_pipeline::*; |
| 26 | -pub use vp8::*; | |
| 27 | 19 | pub use vp9::*; |
| 28 | 20 | |
| 29 | 21 | use std::rc::Rc; |
| @@ -61,14 +53,6 @@ impl Buffer { | ||
| 61 | 53 | |
| 62 | 54 | let (ptr, size) = match type_ { |
| 63 | 55 | BufferType::PictureParameter(ref mut picture_param) => match picture_param { |
| 64 | - PictureParameter::MPEG2(ref mut wrapper) => ( | |
| 65 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 66 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 67 | - ), | |
| 68 | - PictureParameter::VP8(ref mut wrapper) => ( | |
| 69 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 70 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 71 | - ), | |
| 72 | 56 | PictureParameter::VP9(ref mut wrapper) => ( |
| 73 | 57 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 74 | 58 | std::mem::size_of_val(wrapper.inner_mut()), |
| @@ -93,25 +77,9 @@ impl Buffer { | ||
| 93 | 77 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 94 | 78 | std::mem::size_of_val(wrapper.inner_mut()), |
| 95 | 79 | ), |
| 96 | - PictureParameter::JPEGBaseline(ref mut wrapper) => ( | |
| 97 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 98 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 99 | - ), | |
| 100 | - PictureParameter::EncJPEG(ref mut wrapper) => ( | |
| 101 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 102 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 103 | - ), | |
| 104 | 80 | }, |
| 105 | 81 | |
| 106 | 82 | BufferType::SliceParameter(ref mut slice_param) => match slice_param { |
| 107 | - SliceParameter::MPEG2(ref mut wrapper) => ( | |
| 108 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 109 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 110 | - ), | |
| 111 | - SliceParameter::VP8(ref mut wrapper) => ( | |
| 112 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 113 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 114 | - ), | |
| 115 | 83 | SliceParameter::VP9(ref mut wrapper) => ( |
| 116 | 84 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 117 | 85 | std::mem::size_of_val(wrapper.inner_mut()), |
| @@ -132,25 +100,9 @@ impl Buffer { | ||
| 132 | 100 | wrapper.inner_mut().as_mut_ptr() as *mut std::ffi::c_void, |
| 133 | 101 | std::mem::size_of::<bindings::VASliceParameterBufferAV1>(), |
| 134 | 102 | ), |
| 135 | - SliceParameter::JPEGBaseline(ref mut wrapper) => ( | |
| 136 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 137 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 138 | - ), | |
| 139 | - SliceParameter::EncJpeg(ref mut wrapper) => ( | |
| 140 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 141 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 142 | - ), | |
| 143 | 103 | }, |
| 144 | 104 | |
| 145 | 105 | BufferType::IQMatrix(ref mut iq_matrix) => match iq_matrix { |
| 146 | - IQMatrix::MPEG2(ref mut wrapper) => ( | |
| 147 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 148 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 149 | - ), | |
| 150 | - IQMatrix::VP8(ref mut wrapper) => ( | |
| 151 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 152 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 153 | - ), | |
| 154 | 106 | IQMatrix::H264(ref mut wrapper) => ( |
| 155 | 107 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 156 | 108 | std::mem::size_of_val(wrapper.inner_mut()), |
| @@ -159,23 +111,9 @@ impl Buffer { | ||
| 159 | 111 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 160 | 112 | std::mem::size_of_val(wrapper.inner_mut()), |
| 161 | 113 | ), |
| 162 | - IQMatrix::JPEGBaseline(ref mut wrapper) => ( | |
| 163 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 164 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 165 | - ), | |
| 166 | 114 | }, |
| 167 | 115 | |
| 168 | - BufferType::HuffmanTable(ref mut huffman_table) => match huffman_table { | |
| 169 | - HuffmanTable::JPEGBaseline(ref mut wrapper) => ( | |
| 170 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 171 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 172 | - ), | |
| 173 | - }, | |
| 174 | 116 | |
| 175 | - BufferType::Probability(ref mut wrapper) => ( | |
| 176 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 177 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 178 | - ), | |
| 179 | 117 | |
| 180 | 118 | BufferType::SliceData(ref mut data) => { |
| 181 | 119 | (data.as_mut_ptr() as *mut std::ffi::c_void, data.len()) |
| @@ -190,10 +128,6 @@ impl Buffer { | ||
| 190 | 128 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 191 | 129 | std::mem::size_of_val(wrapper.inner_mut()), |
| 192 | 130 | ), |
| 193 | - EncSequenceParameter::VP8(ref mut wrapper) => ( | |
| 194 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 195 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 196 | - ), | |
| 197 | 131 | EncSequenceParameter::VP9(ref mut wrapper) => ( |
| 198 | 132 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 199 | 133 | std::mem::size_of_val(wrapper.inner_mut()), |
| @@ -213,10 +147,6 @@ impl Buffer { | ||
| 213 | 147 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 214 | 148 | std::mem::size_of_val(wrapper.inner_mut()), |
| 215 | 149 | ), |
| 216 | - EncPictureParameter::VP8(ref mut wrapper) => ( | |
| 217 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 218 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 219 | - ), | |
| 220 | 150 | EncPictureParameter::VP9(ref mut wrapper) => ( |
| 221 | 151 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 222 | 152 | std::mem::size_of_val(wrapper.inner_mut()), |
| @@ -289,12 +219,6 @@ impl Buffer { | ||
| 289 | 219 | proc_pipeline_param.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 290 | 220 | std::mem::size_of_val(proc_pipeline_param.inner_mut()), |
| 291 | 221 | ), |
| 292 | - BufferType::QMatrix(ref mut q_matrix) => match q_matrix { | |
| 293 | - QMatrix::JPEG(ref mut wrapper) => ( | |
| 294 | - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 295 | - std::mem::size_of_val(wrapper.inner_mut()), | |
| 296 | - ), | |
| 297 | - }, | |
| 298 | 222 | BufferType::EncPackedHeaderParameter(ref mut wrapper) => ( |
| 299 | 223 | wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, |
| 300 | 224 | std::mem::size_of_val(wrapper.inner_mut()), |
| @@ -419,34 +343,28 @@ impl Drop for Buffer { | ||
| 419 | 343 | |
| 420 | 344 | /// Abstraction over `VABufferType`s. |
| 421 | 345 | pub enum BufferType { |
| 422 | - /// Abstraction over `VAPictureParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, JPEGBaseline. | |
| 346 | + /// Abstraction over `VAPictureParameterBufferType`. Needed for VP9, H264. | |
| 423 | 347 | PictureParameter(PictureParameter), |
| 424 | - /// Abstraction over `VASliceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, JPEGBaseline. | |
| 348 | + /// Abstraction over `VASliceParameterBufferType`. Needed for VP9, H264. | |
| 425 | 349 | SliceParameter(SliceParameter), |
| 426 | - /// Abstraction over `VAIQMatrixBufferType`. Needed for VP8, H264, JPEGBaseline. | |
| 350 | + /// Abstraction over `VAIQMatrixBufferType`. Needed for H264. | |
| 427 | 351 | IQMatrix(IQMatrix), |
| 428 | - /// Abstraction over `HuffmanTableBufferType`. Needed for JPEGBaseline. | |
| 429 | - HuffmanTable(HuffmanTable), | |
| 430 | - /// Abstraction over `VAProbabilityDataBufferType`. Needed for VP8. | |
| 431 | - Probability(vp8::ProbabilityDataBufferVP8), | |
| 432 | 352 | /// Abstraction over `VASliceDataBufferType`. Needed for VP9, H264. |
| 433 | 353 | SliceData(Vec<u8>), |
| 434 | - /// Abstraction over `VAEncSequenceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. | |
| 354 | + /// Abstraction over `VAEncSequenceParameterBufferType`. Needed for VP9, H264, HEVC. | |
| 435 | 355 | EncSequenceParameter(EncSequenceParameter), |
| 436 | - /// Abstraction over `VAEncPictureParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. | |
| 356 | + /// Abstraction over `VAEncPictureParameterBufferType`. Needed for VP9, H264, HEVC. | |
| 437 | 357 | EncPictureParameter(EncPictureParameter), |
| 438 | - /// Abstraction over `VAEncSliceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. | |
| 358 | + /// Abstraction over `VAEncSliceParameterBufferType`. Needed for VP9, H264, HEVC. | |
| 439 | 359 | EncSliceParameter(EncSliceParameter), |
| 440 | 360 | /// Abstraction over `VAEncMacroblockMapBufferType`. Needed for H264. |
| 441 | 361 | EncMacroblockParameterBuffer(EncMacroblockParameterBuffer), |
| 442 | - /// Abstraction over `VAEncCodedBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. | |
| 362 | + /// Abstraction over `VAEncCodedBufferType`. Needed for VP9, H264, HEVC. | |
| 443 | 363 | EncCodedBuffer(usize), |
| 444 | 364 | /// Abstraction over `VAEncMiscParameterBuffer`. |
| 445 | 365 | EncMiscParameter(EncMiscParameter), |
| 446 | 366 | /// Abstraction over `VAProcPipelineParameterBuffer`. |
| 447 | 367 | ProcPipelineParameter(proc_pipeline::ProcPipelineParameterBuffer), |
| 448 | - /// Abstraction over `VAQMatrixBufferType`. | |
| 449 | - QMatrix(QMatrix), | |
| 450 | 368 | /// Abstraction over `VAEncPackedHeaderParameterBufferType`. |
| 451 | 369 | EncPackedHeaderParameter(EncPackedHeaderParameter), |
| 452 | 370 | /// Abstraction over `VAEncPackedHeaderDataBufferType`. |
| @@ -460,8 +378,6 @@ impl BufferType { | ||
| 460 | 378 | BufferType::PictureParameter(_) => bindings::VABufferType::VAPictureParameterBufferType, |
| 461 | 379 | BufferType::SliceParameter(_) => bindings::VABufferType::VASliceParameterBufferType, |
| 462 | 380 | BufferType::IQMatrix(_) => bindings::VABufferType::VAIQMatrixBufferType, |
| 463 | - BufferType::HuffmanTable(_) => bindings::VABufferType::VAHuffmanTableBufferType, | |
| 464 | - BufferType::Probability(_) => bindings::VABufferType::VAProbabilityBufferType, | |
| 465 | 381 | BufferType::SliceData { .. } => bindings::VABufferType::VASliceDataBufferType, |
| 466 | 382 | |
| 467 | 383 | BufferType::EncSequenceParameter(_) => { |
| @@ -488,7 +404,6 @@ impl BufferType { | ||
| 488 | 404 | bindings::VABufferType::VAProcPipelineParameterBufferType |
| 489 | 405 | } |
| 490 | 406 | |
| 491 | - BufferType::QMatrix(_) => bindings::VABufferType::VAQMatrixBufferType, | |
| 492 | 407 | |
| 493 | 408 | BufferType::EncPackedHeaderParameter(_) => { |
| 494 | 409 | bindings::VABufferType::VAEncPackedHeaderParameterBufferType |
| @@ -503,10 +418,6 @@ impl BufferType { | ||
| 503 | 418 | |
| 504 | 419 | /// Abstraction over the `PictureParameterBuffer` types we support. |
| 505 | 420 | pub enum PictureParameter { |
| 506 | - /// Wrapper over VAPictureParameterBufferMPEG2. | |
| 507 | - MPEG2(mpeg2::PictureParameterBufferMPEG2), | |
| 508 | - /// Wrapper over VAPictureParameterBufferVP8. | |
| 509 | - VP8(vp8::PictureParameterBufferVP8), | |
| 510 | 421 | /// Wrapper over VAPictureParameterBufferVP9. |
| 511 | 422 | VP9(vp9::PictureParameterBufferVP9), |
| 512 | 423 | /// Wrapper over VAPictureParameterBufferH264. |
| @@ -519,18 +430,10 @@ pub enum PictureParameter { | ||
| 519 | 430 | HEVCScc(hevc::PictureParameterBufferHEVCScc), |
| 520 | 431 | /// Wrapper over VADecPictureParameterBufferAV1 |
| 521 | 432 | AV1(av1::PictureParameterBufferAV1), |
| 522 | - /// Wrapper over VAPictureParameterBufferJPEGBaseline | |
| 523 | - JPEGBaseline(jpeg_baseline::PictureParameterBufferJPEGBaseline), | |
| 524 | - /// Wrapper over VAEncPictureParameterBufferJPEG | |
| 525 | - EncJPEG(enc_jpeg::EncPictureParameterBufferJPEG), | |
| 526 | 433 | } |
| 527 | 434 | |
| 528 | 435 | /// Abstraction over the `SliceParameterBuffer` types we support |
| 529 | 436 | pub enum SliceParameter { |
| 530 | - /// Wrapper over VASliceParameterBufferMPEG2 | |
| 531 | - MPEG2(mpeg2::SliceParameterBufferMPEG2), | |
| 532 | - /// Wrapper over VASliceParameterBufferVP8 | |
| 533 | - VP8(vp8::SliceParameterBufferVP8), | |
| 534 | 437 | /// Wrapper over VASliceParameterBufferVP9 |
| 535 | 438 | VP9(vp9::SliceParameterBufferVP9), |
| 536 | 439 | /// Wrapper over VASliceParameterBufferH264 |
| @@ -541,37 +444,16 @@ pub enum SliceParameter { | ||
| 541 | 444 | HEVCRext(hevc::SliceParameterBufferHEVCRext), |
| 542 | 445 | /// Wrapper over VASliceParameterBufferAV1 |
| 543 | 446 | AV1(av1::SliceParameterBufferAV1), |
| 544 | - /// Wrapper over VASliceParameterBufferJPEGBaseline | |
| 545 | - JPEGBaseline(jpeg_baseline::SliceParameterBufferJPEGBaseline), | |
| 546 | - /// Wrapper over VAEncSliceParameterBufferJPEG | |
| 547 | - EncJpeg(enc_jpeg::EncSliceParameterBufferJPEG), | |
| 548 | 447 | } |
| 549 | 448 | |
| 550 | 449 | /// Abstraction over the `IQMatrixBuffer` types we support. |
| 551 | 450 | pub enum IQMatrix { |
| 552 | - /// Abstraction over `VAIQMatrixBufferMPEG2` | |
| 553 | - MPEG2(mpeg2::IQMatrixBufferMPEG2), | |
| 554 | - /// Abstraction over `VAIQMatrixBufferVP8` | |
| 555 | - VP8(vp8::IQMatrixBufferVP8), | |
| 556 | 451 | /// Abstraction over `VAIQMatrixBufferH264` |
| 557 | 452 | H264(h264::IQMatrixBufferH264), |
| 558 | 453 | /// Abstraction over `VAIQMatrixBufferHEVC` |
| 559 | 454 | HEVC(hevc::IQMatrixBufferHEVC), |
| 560 | - /// Abstraction over `VAIQMatrixBufferJPEGBaseline`` | |
| 561 | - JPEGBaseline(jpeg_baseline::IQMatrixBufferJPEGBaseline), | |
| 562 | 455 | } |
| 563 | 456 | |
| 564 | -/// Abstraction over the `HuffmanTable` types we support. | |
| 565 | -pub enum HuffmanTable { | |
| 566 | - /// Abstraction over `VAHuffmanTableBufferJPEGBaseline` | |
| 567 | - JPEGBaseline(jpeg_baseline::HuffmanTableBufferJPEGBaseline), | |
| 568 | -} | |
| 569 | - | |
| 570 | -/// Abstraction over the `QMatrix` types we support. | |
| 571 | -pub enum QMatrix { | |
| 572 | - /// Abstraction over `VAQMatrixBufferJPEG` | |
| 573 | - JPEG(enc_jpeg::QMatrixBufferJPEG), | |
| 574 | -} | |
| 575 | 457 | |
| 576 | 458 | /// Abstraction over the `EncSequenceParameter` types we support. |
| 577 | 459 | pub enum EncSequenceParameter { |
| @@ -579,8 +461,6 @@ pub enum EncSequenceParameter { | ||
| 579 | 461 | H264(h264::EncSequenceParameterBufferH264), |
| 580 | 462 | /// Abstraction over `VAEncSequenceParameterBufferHEVC` |
| 581 | 463 | HEVC(hevc::EncSequenceParameterBufferHEVC), |
| 582 | - /// Abstraction over `VAEncSequenceParameterBufferVP8` | |
| 583 | - VP8(vp8::EncSequenceParameterBufferVP8), | |
| 584 | 464 | /// Abstraction over `VAEncSequenceParameterBufferVP9` |
| 585 | 465 | VP9(vp9::EncSequenceParameterBufferVP9), |
| 586 | 466 | /// Abstraction over `VAEncSequenceParameterBufferAV1` |
| @@ -593,8 +473,6 @@ pub enum EncPictureParameter { | ||
| 593 | 473 | H264(h264::EncPictureParameterBufferH264), |
| 594 | 474 | /// Abstraction over `VAEncPictureParameterBufferHEVC` |
| 595 | 475 | HEVC(hevc::EncPictureParameterBufferHEVC), |
| 596 | - /// Abstraction over `VAEncPictureParameterBufferVP8` | |
| 597 | - VP8(vp8::EncPictureParameterBufferVP8), | |
| 598 | 476 | /// Abstraction over `VAEncPictureParameterBufferVP9` |
| 599 | 477 | VP9(vp9::EncPictureParameterBufferVP9), |
| 600 | 478 | /// Abstraction over `VAEncPictureParameterBufferAV1` |
shims/cros-libva/src/buffer/enc_jpeg.rsdeleted+0 -159
| @@ -1,159 +0,0 @@ | ||
| 1 | -// Copyright 2025 The ChromiumOS Authors | |
| 2 | -// Use of this source code is governed by a BSD-style license that can be | |
| 3 | -// found in the LICENSE file. | |
| 4 | - | |
| 5 | -//! Wrappers around JPEG-Encoding `VABuffer` types. | |
| 6 | - | |
| 7 | -use crate::bindings; | |
| 8 | - | |
| 9 | -/// Wrapper over the `pic_flags` bindgen field in `VAEncPictureParameterBufferJPEG` | |
| 10 | -pub struct PicFlags(bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1); | |
| 11 | - | |
| 12 | -impl PicFlags { | |
| 13 | - pub fn new( | |
| 14 | - profile: u32, | |
| 15 | - progressive: u32, | |
| 16 | - huffman: u32, | |
| 17 | - interleaved: u32, | |
| 18 | - differential: u32, | |
| 19 | - ) -> Self { | |
| 20 | - let _bitfield_1 = | |
| 21 | - bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 22 | - profile, | |
| 23 | - progressive, | |
| 24 | - huffman, | |
| 25 | - interleaved, | |
| 26 | - differential, | |
| 27 | - ); | |
| 28 | - Self(bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1 { | |
| 29 | - bits: bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1__bindgen_ty_1 { | |
| 30 | - _bitfield_align_1: Default::default(), | |
| 31 | - _bitfield_1, | |
| 32 | - __bindgen_padding_0: Default::default(), | |
| 33 | - }, | |
| 34 | - }) | |
| 35 | - } | |
| 36 | -} | |
| 37 | - | |
| 38 | -/// Wrapper over the `VAEncPictureParameterBufferJPEG` FFI type. | |
| 39 | -pub struct EncPictureParameterBufferJPEG(Box<bindings::VAEncPictureParameterBufferJPEG>); | |
| 40 | - | |
| 41 | -impl EncPictureParameterBufferJPEG { | |
| 42 | - /// Creates the wrapper. | |
| 43 | - pub fn new( | |
| 44 | - reconstructed_picture: bindings::VASurfaceID, | |
| 45 | - picture_width: u16, | |
| 46 | - picture_height: u16, | |
| 47 | - coded_buf: bindings::VABufferID, | |
| 48 | - pic_flags: PicFlags, | |
| 49 | - sample_bit_depth: u8, | |
| 50 | - num_scan: u8, | |
| 51 | - num_components: u16, | |
| 52 | - component_id: [u8; 4usize], | |
| 53 | - quantiser_table_selector: [u8; 4usize], | |
| 54 | - quality: u8, | |
| 55 | - ) -> Self { | |
| 56 | - Self(Box::new(bindings::VAEncPictureParameterBufferJPEG { | |
| 57 | - reconstructed_picture, | |
| 58 | - picture_width, | |
| 59 | - picture_height, | |
| 60 | - coded_buf, | |
| 61 | - pic_flags: pic_flags.0, | |
| 62 | - sample_bit_depth, | |
| 63 | - num_scan, | |
| 64 | - num_components, | |
| 65 | - component_id, | |
| 66 | - quantiser_table_selector, | |
| 67 | - quality, | |
| 68 | - va_reserved: Default::default(), | |
| 69 | - })) | |
| 70 | - } | |
| 71 | - | |
| 72 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferJPEG { | |
| 73 | - self.0.as_mut() | |
| 74 | - } | |
| 75 | - | |
| 76 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 77 | - pub fn inner(&self) -> &bindings::VAEncPictureParameterBufferJPEG { | |
| 78 | - self.0.as_ref() | |
| 79 | - } | |
| 80 | -} | |
| 81 | - | |
| 82 | -/// Wrapper over the `components` bindgen field in `VAEncSliceParameterBufferJPEG`. | |
| 83 | -pub struct EncSliceParameterBufferJPEGComponent( | |
| 84 | - bindings::_VAEncSliceParameterBufferJPEG__bindgen_ty_1, | |
| 85 | -); | |
| 86 | - | |
| 87 | -impl EncSliceParameterBufferJPEGComponent { | |
| 88 | - /// Creates the bindgen field. | |
| 89 | - pub fn new(component_selector: u8, dc_table_selector: u8, ac_table_selector: u8) -> Self { | |
| 90 | - Self(bindings::_VAEncSliceParameterBufferJPEG__bindgen_ty_1 { | |
| 91 | - component_selector, | |
| 92 | - dc_table_selector, | |
| 93 | - ac_table_selector, | |
| 94 | - }) | |
| 95 | - } | |
| 96 | - | |
| 97 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 98 | - pub fn inner(&self) -> &bindings::_VAEncSliceParameterBufferJPEG__bindgen_ty_1 { | |
| 99 | - &self.0 | |
| 100 | - } | |
| 101 | -} | |
| 102 | - | |
| 103 | -/// Wrapper over the `VAEncSliceParameterBufferJPEG` FFI type. | |
| 104 | -pub struct EncSliceParameterBufferJPEG(Box<bindings::VAEncSliceParameterBufferJPEG>); | |
| 105 | - | |
| 106 | -impl EncSliceParameterBufferJPEG { | |
| 107 | - /// Creates the wrapper. | |
| 108 | - pub fn new( | |
| 109 | - restart_interval: u16, | |
| 110 | - num_components: u16, | |
| 111 | - components: [EncSliceParameterBufferJPEGComponent; 4usize], | |
| 112 | - ) -> Self { | |
| 113 | - Self(Box::new(bindings::VAEncSliceParameterBufferJPEG { | |
| 114 | - restart_interval, | |
| 115 | - num_components, | |
| 116 | - components: components.map(|component| component.0), | |
| 117 | - va_reserved: Default::default(), | |
| 118 | - })) | |
| 119 | - } | |
| 120 | - | |
| 121 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSliceParameterBufferJPEG { | |
| 122 | - self.0.as_mut() | |
| 123 | - } | |
| 124 | - | |
| 125 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 126 | - pub fn inner(&self) -> &bindings::VAEncSliceParameterBufferJPEG { | |
| 127 | - self.0.as_ref() | |
| 128 | - } | |
| 129 | -} | |
| 130 | - | |
| 131 | -/// Wrapper over the `VAQMatrixBufferJPEG` FFI type. | |
| 132 | -pub struct QMatrixBufferJPEG(Box<bindings::VAQMatrixBufferJPEG>); | |
| 133 | - | |
| 134 | -impl QMatrixBufferJPEG { | |
| 135 | - /// Creates the wrapper. | |
| 136 | - pub fn new( | |
| 137 | - load_lum_quantiser_matrix: i32, | |
| 138 | - load_chroma_quantiser_matrix: i32, | |
| 139 | - lum_quantiser_matrix: [u8; 64usize], | |
| 140 | - chroma_quantiser_matrix: [u8; 64usize], | |
| 141 | - ) -> Self { | |
| 142 | - Self(Box::new(bindings::VAQMatrixBufferJPEG { | |
| 143 | - load_lum_quantiser_matrix, | |
| 144 | - load_chroma_quantiser_matrix, | |
| 145 | - lum_quantiser_matrix, | |
| 146 | - chroma_quantiser_matrix, | |
| 147 | - va_reserved: Default::default(), | |
| 148 | - })) | |
| 149 | - } | |
| 150 | - | |
| 151 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAQMatrixBufferJPEG { | |
| 152 | - self.0.as_mut() | |
| 153 | - } | |
| 154 | - | |
| 155 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 156 | - pub fn inner(&self) -> &bindings::VAQMatrixBufferJPEG { | |
| 157 | - self.0.as_ref() | |
| 158 | - } | |
| 159 | -} |
shims/cros-libva/src/buffer/jpeg_baseline.rsdeleted+0 -220
| @@ -1,220 +0,0 @@ | ||
| 1 | -// Copyright 2025 The ChromiumOS Authors | |
| 2 | -// Use of this source code is governed by a BSD-style license that can be | |
| 3 | -// found in the LICENSE file. | |
| 4 | - | |
| 5 | -//! Wrappers around JPEGBaseline `VABuffer` types. | |
| 6 | - | |
| 7 | -use crate::bindings; | |
| 8 | - | |
| 9 | -/// Wrapper over the `components` bindgen field in `VAPictureParameterBufferJPEGBaseline`. | |
| 10 | -pub struct PictureParameterBufferJPEGBaselineComponent( | |
| 11 | - bindings::_VAPictureParameterBufferJPEGBaseline__bindgen_ty_1, | |
| 12 | -); | |
| 13 | - | |
| 14 | -impl PictureParameterBufferJPEGBaselineComponent { | |
| 15 | - /// Creates the bindgen field. | |
| 16 | - #[allow(clippy::too_many_arguments)] | |
| 17 | - pub fn new( | |
| 18 | - component_id: u8, | |
| 19 | - h_sampling_factor: u8, | |
| 20 | - v_sampling_factor: u8, | |
| 21 | - quantiser_table_selector: u8, | |
| 22 | - ) -> Self { | |
| 23 | - Self( | |
| 24 | - bindings::_VAPictureParameterBufferJPEGBaseline__bindgen_ty_1 { | |
| 25 | - component_id, | |
| 26 | - h_sampling_factor, | |
| 27 | - v_sampling_factor, | |
| 28 | - quantiser_table_selector, | |
| 29 | - }, | |
| 30 | - ) | |
| 31 | - } | |
| 32 | - | |
| 33 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 34 | - pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferJPEGBaseline__bindgen_ty_1 { | |
| 35 | - &self.0 | |
| 36 | - } | |
| 37 | -} | |
| 38 | - | |
| 39 | -/// Wrapper over the `VAPictureParameterBufferJPEGBaseline` FFI type. | |
| 40 | -pub struct PictureParameterBufferJPEGBaseline(Box<bindings::VAPictureParameterBufferJPEGBaseline>); | |
| 41 | - | |
| 42 | -impl PictureParameterBufferJPEGBaseline { | |
| 43 | - /// Creates the wrapper. | |
| 44 | - pub fn new( | |
| 45 | - picture_width: u16, | |
| 46 | - picture_height: u16, | |
| 47 | - components: [PictureParameterBufferJPEGBaselineComponent; 255usize], | |
| 48 | - num_components: u8, | |
| 49 | - color_space: u8, | |
| 50 | - rotation: u32, | |
| 51 | - crop_rectangle: bindings::VARectangle, | |
| 52 | - ) -> Self { | |
| 53 | - Self(Box::new(bindings::VAPictureParameterBufferJPEGBaseline { | |
| 54 | - picture_width, | |
| 55 | - picture_height, | |
| 56 | - components: components.map(|component| component.0), | |
| 57 | - num_components, | |
| 58 | - color_space, | |
| 59 | - rotation, | |
| 60 | - crop_rectangle, | |
| 61 | - va_reserved: Default::default(), | |
| 62 | - })) | |
| 63 | - } | |
| 64 | - | |
| 65 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferJPEGBaseline { | |
| 66 | - self.0.as_mut() | |
| 67 | - } | |
| 68 | - | |
| 69 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 70 | - pub fn inner(&mut self) -> &bindings::VAPictureParameterBufferJPEGBaseline { | |
| 71 | - self.0.as_ref() | |
| 72 | - } | |
| 73 | -} | |
| 74 | - | |
| 75 | -/// Wrapper over the `components` bindgen field in `VASliceParameterBufferJPEGBaseline`. | |
| 76 | -pub struct VASliceParameterBufferJPEGBaselineComponent( | |
| 77 | - bindings::_VASliceParameterBufferJPEGBaseline__bindgen_ty_1, | |
| 78 | -); | |
| 79 | - | |
| 80 | -impl VASliceParameterBufferJPEGBaselineComponent { | |
| 81 | - /// Creates the bindgen field. | |
| 82 | - #[allow(clippy::too_many_arguments)] | |
| 83 | - pub fn new(component_selector: u8, dc_table_selector: u8, ac_table_selector: u8) -> Self { | |
| 84 | - Self( | |
| 85 | - bindings::_VASliceParameterBufferJPEGBaseline__bindgen_ty_1 { | |
| 86 | - component_selector, | |
| 87 | - dc_table_selector, | |
| 88 | - ac_table_selector, | |
| 89 | - }, | |
| 90 | - ) | |
| 91 | - } | |
| 92 | - | |
| 93 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 94 | - pub fn inner(&mut self) -> &bindings::_VASliceParameterBufferJPEGBaseline__bindgen_ty_1 { | |
| 95 | - &self.0 | |
| 96 | - } | |
| 97 | -} | |
| 98 | - | |
| 99 | -/// Wrapper over the `VASliceParameterBufferJPEGBaseline` FFI type. | |
| 100 | -pub struct SliceParameterBufferJPEGBaseline(Box<bindings::VASliceParameterBufferJPEGBaseline>); | |
| 101 | - | |
| 102 | -impl SliceParameterBufferJPEGBaseline { | |
| 103 | - /// Creates the wrapper. | |
| 104 | - pub fn new( | |
| 105 | - slice_data_size: u32, | |
| 106 | - slice_data_offset: u32, | |
| 107 | - slice_data_flag: u32, | |
| 108 | - slice_horizontal_position: u32, | |
| 109 | - slice_vertical_position: u32, | |
| 110 | - components: [VASliceParameterBufferJPEGBaselineComponent; 4usize], | |
| 111 | - num_components: u8, | |
| 112 | - restart_interval: u16, | |
| 113 | - num_mcus: u32, | |
| 114 | - ) -> Self { | |
| 115 | - Self(Box::new(bindings::VASliceParameterBufferJPEGBaseline { | |
| 116 | - slice_data_size, | |
| 117 | - slice_data_offset, | |
| 118 | - slice_data_flag, | |
| 119 | - slice_horizontal_position, | |
| 120 | - slice_vertical_position, | |
| 121 | - components: components.map(|component| component.0), | |
| 122 | - num_components, | |
| 123 | - restart_interval, | |
| 124 | - num_mcus, | |
| 125 | - va_reserved: Default::default(), | |
| 126 | - })) | |
| 127 | - } | |
| 128 | - | |
| 129 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferJPEGBaseline { | |
| 130 | - self.0.as_mut() | |
| 131 | - } | |
| 132 | - | |
| 133 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 134 | - pub fn inner(&mut self) -> &bindings::VASliceParameterBufferJPEGBaseline { | |
| 135 | - self.0.as_ref() | |
| 136 | - } | |
| 137 | -} | |
| 138 | - | |
| 139 | -/// Wrapper over the `VAIQMatrixBufferJPEGBaseline` FFI type. | |
| 140 | -pub struct IQMatrixBufferJPEGBaseline(Box<bindings::VAIQMatrixBufferJPEGBaseline>); | |
| 141 | - | |
| 142 | -impl IQMatrixBufferJPEGBaseline { | |
| 143 | - /// Creates the wrapper. | |
| 144 | - #[allow(clippy::too_many_arguments)] | |
| 145 | - pub fn new( | |
| 146 | - load_quantiser_table: [u8; 4usize], | |
| 147 | - quantiser_table: [[u8; 64usize]; 4usize], | |
| 148 | - ) -> Self { | |
| 149 | - Self(Box::new(bindings::VAIQMatrixBufferJPEGBaseline { | |
| 150 | - load_quantiser_table, | |
| 151 | - quantiser_table, | |
| 152 | - va_reserved: Default::default(), | |
| 153 | - })) | |
| 154 | - } | |
| 155 | - | |
| 156 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferJPEGBaseline { | |
| 157 | - self.0.as_mut() | |
| 158 | - } | |
| 159 | - | |
| 160 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 161 | - pub fn inner(&self) -> &bindings::VAIQMatrixBufferJPEGBaseline { | |
| 162 | - self.0.as_ref() | |
| 163 | - } | |
| 164 | -} | |
| 165 | - | |
| 166 | -/// Wrapper over the `huffman_table` bindgen field in `VAHuffmanTableBufferJPEGBaseline`. | |
| 167 | -pub struct HuffmanTableBufferJPEGBaselineHuffmanTable( | |
| 168 | - bindings::_VAHuffmanTableBufferJPEGBaseline__bindgen_ty_1, | |
| 169 | -); | |
| 170 | - | |
| 171 | -impl HuffmanTableBufferJPEGBaselineHuffmanTable { | |
| 172 | - /// Creates the bindgen field. | |
| 173 | - #[allow(clippy::too_many_arguments)] | |
| 174 | - pub fn new( | |
| 175 | - num_dc_codes: [u8; 16usize], | |
| 176 | - dc_values: [u8; 12usize], | |
| 177 | - num_ac_codes: [u8; 16usize], | |
| 178 | - ac_values: [u8; 162usize], | |
| 179 | - pad: [u8; 2usize], | |
| 180 | - ) -> Self { | |
| 181 | - Self(bindings::_VAHuffmanTableBufferJPEGBaseline__bindgen_ty_1 { | |
| 182 | - num_dc_codes, | |
| 183 | - dc_values, | |
| 184 | - num_ac_codes, | |
| 185 | - ac_values, | |
| 186 | - pad, | |
| 187 | - }) | |
| 188 | - } | |
| 189 | - | |
| 190 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 191 | - pub fn inner(&mut self) -> &bindings::_VAHuffmanTableBufferJPEGBaseline__bindgen_ty_1 { | |
| 192 | - &self.0 | |
| 193 | - } | |
| 194 | -} | |
| 195 | - | |
| 196 | -/// Wrapper over the `VAHuffmanTableBufferJPEGBaseline` FFI type. | |
| 197 | -pub struct HuffmanTableBufferJPEGBaseline(Box<bindings::VAHuffmanTableBufferJPEGBaseline>); | |
| 198 | - | |
| 199 | -impl HuffmanTableBufferJPEGBaseline { | |
| 200 | - /// Creates the wrapper. | |
| 201 | - pub fn new( | |
| 202 | - load_huffman_table: [u8; 2usize], | |
| 203 | - huffman_table: [HuffmanTableBufferJPEGBaselineHuffmanTable; 2usize], | |
| 204 | - ) -> Self { | |
| 205 | - Self(Box::new(bindings::VAHuffmanTableBufferJPEGBaseline { | |
| 206 | - load_huffman_table, | |
| 207 | - huffman_table: huffman_table.map(|component| component.0), | |
| 208 | - va_reserved: Default::default(), | |
| 209 | - })) | |
| 210 | - } | |
| 211 | - | |
| 212 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAHuffmanTableBufferJPEGBaseline { | |
| 213 | - self.0.as_mut() | |
| 214 | - } | |
| 215 | - | |
| 216 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 217 | - pub fn inner(&mut self) -> &bindings::VAHuffmanTableBufferJPEGBaseline { | |
| 218 | - self.0.as_ref() | |
| 219 | - } | |
| 220 | -} |
shims/cros-libva/src/buffer/mpeg2.rsdeleted+0 -172
| @@ -1,172 +0,0 @@ | ||
| 1 | -// Copyright 2023 The ChromiumOS Authors | |
| 2 | -// Use of this source code is governed by a BSD-style license that can be | |
| 3 | -// found in the LICENSE file. | |
| 4 | - | |
| 5 | -//! Wrappers around MPEG2 `VABuffer` types. | |
| 6 | - | |
| 7 | -use crate::bindings; | |
| 8 | - | |
| 9 | -/// Wrapper over the `picture_coding_extension` bindgen field in `VAPictureParameterBufferMPEG2`. | |
| 10 | -pub struct MPEG2PictureCodingExtension(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1); | |
| 11 | - | |
| 12 | -impl MPEG2PictureCodingExtension { | |
| 13 | - /// Creates the bindgen field. | |
| 14 | - #[allow(clippy::too_many_arguments)] | |
| 15 | - pub fn new( | |
| 16 | - intra_dc_precision: u32, | |
| 17 | - picture_structure: u32, | |
| 18 | - top_field_first: u32, | |
| 19 | - frame_pred_frame_dct: u32, | |
| 20 | - concealment_motion_vectors: u32, | |
| 21 | - q_scale_type: u32, | |
| 22 | - intra_vlc_format: u32, | |
| 23 | - alternate_scan: u32, | |
| 24 | - repeat_first_field: u32, | |
| 25 | - progressive_frame: u32, | |
| 26 | - is_first_field: u32, | |
| 27 | - ) -> Self { | |
| 28 | - let _bitfield_1 = | |
| 29 | - bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 30 | - intra_dc_precision, | |
| 31 | - picture_structure, | |
| 32 | - top_field_first, | |
| 33 | - frame_pred_frame_dct, | |
| 34 | - concealment_motion_vectors, | |
| 35 | - q_scale_type, | |
| 36 | - intra_vlc_format, | |
| 37 | - alternate_scan, | |
| 38 | - repeat_first_field, | |
| 39 | - progressive_frame, | |
| 40 | - is_first_field, | |
| 41 | - ); | |
| 42 | - | |
| 43 | - Self(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 { | |
| 44 | - bits: bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1__bindgen_ty_1 { | |
| 45 | - _bitfield_align_1: Default::default(), | |
| 46 | - _bitfield_1, | |
| 47 | - __bindgen_padding_0: Default::default(), | |
| 48 | - }, | |
| 49 | - }) | |
| 50 | - } | |
| 51 | - | |
| 52 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 53 | - pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 { | |
| 54 | - &self.0 | |
| 55 | - } | |
| 56 | -} | |
| 57 | - | |
| 58 | -/// Wrapper over the `PictureParameterBufferMPEG2` FFI type. | |
| 59 | -pub struct PictureParameterBufferMPEG2(Box<bindings::VAPictureParameterBufferMPEG2>); | |
| 60 | - | |
| 61 | -impl PictureParameterBufferMPEG2 { | |
| 62 | - /// Creates the wrapper. | |
| 63 | - pub fn new( | |
| 64 | - horizontal_size: u16, | |
| 65 | - vertical_size: u16, | |
| 66 | - forward_reference_picture: bindings::VASurfaceID, | |
| 67 | - backward_reference_picture: bindings::VASurfaceID, | |
| 68 | - picture_coding_type: i32, | |
| 69 | - f_code: i32, | |
| 70 | - picture_coding_extension: &MPEG2PictureCodingExtension, | |
| 71 | - ) -> Self { | |
| 72 | - let picture_coding_extension = picture_coding_extension.0; | |
| 73 | - | |
| 74 | - Self(Box::new(bindings::VAPictureParameterBufferMPEG2 { | |
| 75 | - horizontal_size, | |
| 76 | - vertical_size, | |
| 77 | - forward_reference_picture, | |
| 78 | - backward_reference_picture, | |
| 79 | - picture_coding_type, | |
| 80 | - f_code, | |
| 81 | - picture_coding_extension, | |
| 82 | - va_reserved: Default::default(), | |
| 83 | - })) | |
| 84 | - } | |
| 85 | - | |
| 86 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferMPEG2 { | |
| 87 | - self.0.as_mut() | |
| 88 | - } | |
| 89 | - | |
| 90 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 91 | - pub fn inner(&mut self) -> &bindings::VAPictureParameterBufferMPEG2 { | |
| 92 | - self.0.as_ref() | |
| 93 | - } | |
| 94 | -} | |
| 95 | - | |
| 96 | -/// Wrapper over the `VASliceParameterBufferMPEG2` FFI type. | |
| 97 | -pub struct SliceParameterBufferMPEG2(Box<bindings::VASliceParameterBufferMPEG2>); | |
| 98 | - | |
| 99 | -impl SliceParameterBufferMPEG2 { | |
| 100 | - /// Creates the wrapper. | |
| 101 | - #[allow(clippy::too_many_arguments)] | |
| 102 | - pub fn new( | |
| 103 | - slice_data_size: u32, | |
| 104 | - slice_data_offset: u32, | |
| 105 | - slice_data_flag: u32, | |
| 106 | - macroblock_offset: u32, | |
| 107 | - slice_horizontal_position: u32, | |
| 108 | - slice_vertical_position: u32, | |
| 109 | - quantiser_scale_code: i32, | |
| 110 | - intra_slice_flag: i32, | |
| 111 | - ) -> Self { | |
| 112 | - Self(Box::new(bindings::VASliceParameterBufferMPEG2 { | |
| 113 | - slice_data_size, | |
| 114 | - slice_data_offset, | |
| 115 | - slice_data_flag, | |
| 116 | - macroblock_offset, | |
| 117 | - slice_horizontal_position, | |
| 118 | - slice_vertical_position, | |
| 119 | - quantiser_scale_code, | |
| 120 | - intra_slice_flag, | |
| 121 | - va_reserved: Default::default(), | |
| 122 | - })) | |
| 123 | - } | |
| 124 | - | |
| 125 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferMPEG2 { | |
| 126 | - self.0.as_mut() | |
| 127 | - } | |
| 128 | - | |
| 129 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 130 | - pub fn inner(&self) -> &bindings::VASliceParameterBufferMPEG2 { | |
| 131 | - self.0.as_ref() | |
| 132 | - } | |
| 133 | -} | |
| 134 | - | |
| 135 | -/// Wrapper over the `VAIQMatrixBufferMPEG2` FFI type. | |
| 136 | -pub struct IQMatrixBufferMPEG2(Box<bindings::VAIQMatrixBufferMPEG2>); | |
| 137 | - | |
| 138 | -impl IQMatrixBufferMPEG2 { | |
| 139 | - /// Creates the wrapper. | |
| 140 | - #[allow(clippy::too_many_arguments)] | |
| 141 | - pub fn new( | |
| 142 | - load_intra_quantiser_matrix: i32, | |
| 143 | - load_non_intra_quantiser_matrix: i32, | |
| 144 | - load_chroma_intra_quantiser_matrix: i32, | |
| 145 | - load_chroma_non_intra_quantiser_matrix: i32, | |
| 146 | - intra_quantiser_matrix: [u8; 64usize], | |
| 147 | - non_intra_quantiser_matrix: [u8; 64usize], | |
| 148 | - chroma_intra_quantiser_matrix: [u8; 64usize], | |
| 149 | - chroma_non_intra_quantiser_matrix: [u8; 64usize], | |
| 150 | - ) -> Self { | |
| 151 | - Self(Box::new(bindings::VAIQMatrixBufferMPEG2 { | |
| 152 | - load_intra_quantiser_matrix, | |
| 153 | - load_non_intra_quantiser_matrix, | |
| 154 | - load_chroma_intra_quantiser_matrix, | |
| 155 | - load_chroma_non_intra_quantiser_matrix, | |
| 156 | - intra_quantiser_matrix, | |
| 157 | - non_intra_quantiser_matrix, | |
| 158 | - chroma_intra_quantiser_matrix, | |
| 159 | - chroma_non_intra_quantiser_matrix, | |
| 160 | - va_reserved: Default::default(), | |
| 161 | - })) | |
| 162 | - } | |
| 163 | - | |
| 164 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferMPEG2 { | |
| 165 | - self.0.as_mut() | |
| 166 | - } | |
| 167 | - | |
| 168 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 169 | - pub fn inner(&self) -> &bindings::VAIQMatrixBufferMPEG2 { | |
| 170 | - self.0.as_ref() | |
| 171 | - } | |
| 172 | -} |
shims/cros-libva/src/buffer/proc_pipeline.rsmodified+1 -1
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | //! Wrappers around `VAProcPipeline` types. |
| 6 | 6 | |
| 7 | 7 | use crate::bindings; |
| 8 | -use std::{marker::PhantomData, ptr}; | |
| 8 | +use std::ptr; | |
| 9 | 9 | |
| 10 | 10 | /// Wrapper over the `VABlendState` ffi type. |
| 11 | 11 | pub struct BlendState(bindings::VABlendState); |
shims/cros-libva/src/buffer/vp8.rsdeleted+0 -397
| @@ -1,397 +0,0 @@ | ||
| 1 | -// Copyright 2023 The ChromiumOS Authors | |
| 2 | -// Use of this source code is governed by a BSD-style license that can be | |
| 3 | -// found in the LICENSE file. | |
| 4 | - | |
| 5 | -//! Wrappers around VP8 `VABuffer` types. | |
| 6 | - | |
| 7 | -use crate::bindings; | |
| 8 | - | |
| 9 | -/// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferVP8`. | |
| 10 | -pub struct VP8PicFields(bindings::_VAPictureParameterBufferVP8__bindgen_ty_1); | |
| 11 | - | |
| 12 | -impl VP8PicFields { | |
| 13 | - /// Creates the bindgen field | |
| 14 | - #[allow(clippy::too_many_arguments)] | |
| 15 | - pub fn new( | |
| 16 | - key_frame: u32, | |
| 17 | - version: u32, | |
| 18 | - segmentation_enabled: u32, | |
| 19 | - update_mb_segmentation_map: u32, | |
| 20 | - update_segment_feature_data: u32, | |
| 21 | - filter_type: u32, | |
| 22 | - sharpness_level: u32, | |
| 23 | - loop_filter_adj_enable: u32, | |
| 24 | - mode_ref_lf_delta_update: u32, | |
| 25 | - sign_bias_golden: u32, | |
| 26 | - sign_bias_alternate: u32, | |
| 27 | - mb_no_coeff_skip: u32, | |
| 28 | - loop_filter_disable: u32, | |
| 29 | - ) -> Self { | |
| 30 | - let _bitfield_1 = | |
| 31 | - bindings::_VAPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 32 | - key_frame, | |
| 33 | - version, | |
| 34 | - segmentation_enabled, | |
| 35 | - update_mb_segmentation_map, | |
| 36 | - update_segment_feature_data, | |
| 37 | - filter_type, | |
| 38 | - sharpness_level, | |
| 39 | - loop_filter_adj_enable, | |
| 40 | - mode_ref_lf_delta_update, | |
| 41 | - sign_bias_golden, | |
| 42 | - sign_bias_alternate, | |
| 43 | - mb_no_coeff_skip, | |
| 44 | - loop_filter_disable, | |
| 45 | - ); | |
| 46 | - | |
| 47 | - Self(bindings::_VAPictureParameterBufferVP8__bindgen_ty_1 { | |
| 48 | - bits: bindings::_VAPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1 { | |
| 49 | - _bitfield_align_1: Default::default(), | |
| 50 | - _bitfield_1, | |
| 51 | - __bindgen_padding_0: Default::default(), | |
| 52 | - }, | |
| 53 | - }) | |
| 54 | - } | |
| 55 | - | |
| 56 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 57 | - pub fn inner(&self) -> &bindings::_VAPictureParameterBufferVP8__bindgen_ty_1 { | |
| 58 | - &self.0 | |
| 59 | - } | |
| 60 | -} | |
| 61 | - | |
| 62 | -/// Wrapper over the `VABoolCoderContextVPX` FFI type. | |
| 63 | -pub struct BoolCoderContextVPX(bindings::VABoolCoderContextVPX); | |
| 64 | - | |
| 65 | -impl BoolCoderContextVPX { | |
| 66 | - /// Creates the wrapper | |
| 67 | - pub fn new(range: u8, value: u8, count: u8) -> Self { | |
| 68 | - Self(bindings::VABoolCoderContextVPX { | |
| 69 | - range, | |
| 70 | - value, | |
| 71 | - count, | |
| 72 | - }) | |
| 73 | - } | |
| 74 | -} | |
| 75 | - | |
| 76 | -/// Wrapper over the `PictureParameterBufferVP8` FFI type. | |
| 77 | -pub struct PictureParameterBufferVP8(Box<bindings::VAPictureParameterBufferVP8>); | |
| 78 | - | |
| 79 | -impl PictureParameterBufferVP8 { | |
| 80 | - /// Creates the wrapper | |
| 81 | - #[allow(clippy::too_many_arguments)] | |
| 82 | - pub fn new( | |
| 83 | - frame_width: u32, | |
| 84 | - frame_height: u32, | |
| 85 | - last_ref_frame: bindings::VASurfaceID, | |
| 86 | - golden_ref_frame: bindings::VASurfaceID, | |
| 87 | - alt_ref_frame: bindings::VASurfaceID, | |
| 88 | - pic_fields: &VP8PicFields, | |
| 89 | - mb_segment_tree_probs: [u8; 3usize], | |
| 90 | - loop_filter_level: [u8; 4usize], | |
| 91 | - loop_filter_deltas_ref_frame: [i8; 4usize], | |
| 92 | - loop_filter_deltas_mode: [i8; 4usize], | |
| 93 | - prob_skip_false: u8, | |
| 94 | - prob_intra: u8, | |
| 95 | - prob_last: u8, | |
| 96 | - prob_gf: u8, | |
| 97 | - y_mode_probs: [u8; 4usize], | |
| 98 | - uv_mode_probs: [u8; 3usize], | |
| 99 | - mv_probs: [[u8; 19usize]; 2usize], | |
| 100 | - bool_coder_ctx: &BoolCoderContextVPX, | |
| 101 | - ) -> Self { | |
| 102 | - let pic_fields = pic_fields.0; | |
| 103 | - let bool_coder_ctx = bool_coder_ctx.0; | |
| 104 | - | |
| 105 | - Self(Box::new(bindings::VAPictureParameterBufferVP8 { | |
| 106 | - frame_width, | |
| 107 | - frame_height, | |
| 108 | - last_ref_frame, | |
| 109 | - golden_ref_frame, | |
| 110 | - alt_ref_frame, | |
| 111 | - out_of_loop_frame: bindings::VA_INVALID_SURFACE, | |
| 112 | - pic_fields, | |
| 113 | - mb_segment_tree_probs, | |
| 114 | - loop_filter_level, | |
| 115 | - loop_filter_deltas_ref_frame, | |
| 116 | - loop_filter_deltas_mode, | |
| 117 | - prob_skip_false, | |
| 118 | - prob_intra, | |
| 119 | - prob_last, | |
| 120 | - prob_gf, | |
| 121 | - y_mode_probs, | |
| 122 | - uv_mode_probs, | |
| 123 | - mv_probs, | |
| 124 | - bool_coder_ctx, | |
| 125 | - va_reserved: Default::default(), | |
| 126 | - })) | |
| 127 | - } | |
| 128 | - | |
| 129 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferVP8 { | |
| 130 | - self.0.as_mut() | |
| 131 | - } | |
| 132 | - | |
| 133 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 134 | - pub fn inner(&self) -> &bindings::VAPictureParameterBufferVP8 { | |
| 135 | - self.0.as_ref() | |
| 136 | - } | |
| 137 | -} | |
| 138 | - | |
| 139 | -/// Wrapper over the `VASliceParameterBufferVP8` FFI type. | |
| 140 | -pub struct SliceParameterBufferVP8(Box<bindings::VASliceParameterBufferVP8>); | |
| 141 | - | |
| 142 | -impl SliceParameterBufferVP8 { | |
| 143 | - /// Creates the wrapper. | |
| 144 | - pub fn new( | |
| 145 | - slice_data_size: u32, | |
| 146 | - slice_data_offset: u32, | |
| 147 | - slice_data_flag: u32, | |
| 148 | - macroblock_offset: u32, | |
| 149 | - num_of_partitions: u8, | |
| 150 | - partition_size: [u32; 9usize], | |
| 151 | - ) -> Self { | |
| 152 | - Self(Box::new(bindings::VASliceParameterBufferVP8 { | |
| 153 | - slice_data_size, | |
| 154 | - slice_data_offset, | |
| 155 | - slice_data_flag, | |
| 156 | - macroblock_offset, | |
| 157 | - num_of_partitions, | |
| 158 | - partition_size, | |
| 159 | - va_reserved: Default::default(), | |
| 160 | - })) | |
| 161 | - } | |
| 162 | - | |
| 163 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferVP8 { | |
| 164 | - self.0.as_mut() | |
| 165 | - } | |
| 166 | - | |
| 167 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 168 | - pub fn inner(&self) -> &bindings::VASliceParameterBufferVP8 { | |
| 169 | - self.0.as_ref() | |
| 170 | - } | |
| 171 | -} | |
| 172 | - | |
| 173 | -/// Wrapper over the `VAIQMatrixBufferVP8` FFI type. | |
| 174 | -pub struct IQMatrixBufferVP8(Box<bindings::VAIQMatrixBufferVP8>); | |
| 175 | - | |
| 176 | -impl IQMatrixBufferVP8 { | |
| 177 | - /// Creates the wrapper. | |
| 178 | - pub fn new(quantization_index: [[u16; 6usize]; 4usize]) -> Self { | |
| 179 | - Self(Box::new(bindings::VAIQMatrixBufferVP8 { | |
| 180 | - quantization_index, | |
| 181 | - va_reserved: Default::default(), | |
| 182 | - })) | |
| 183 | - } | |
| 184 | - | |
| 185 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferVP8 { | |
| 186 | - self.0.as_mut() | |
| 187 | - } | |
| 188 | - | |
| 189 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 190 | - pub fn inner(&self) -> &bindings::VAIQMatrixBufferVP8 { | |
| 191 | - self.0.as_ref() | |
| 192 | - } | |
| 193 | -} | |
| 194 | - | |
| 195 | -/// Wrapper over the VAProbabilityDataBufferVP8 FFI type. | |
| 196 | -pub struct ProbabilityDataBufferVP8(Box<bindings::VAProbabilityDataBufferVP8>); | |
| 197 | - | |
| 198 | -impl ProbabilityDataBufferVP8 { | |
| 199 | - /// Creates the wrapper. | |
| 200 | - pub fn new(dct_coeff_probs: [[[[u8; 11usize]; 3usize]; 8usize]; 4usize]) -> Self { | |
| 201 | - Self(Box::new(bindings::VAProbabilityDataBufferVP8 { | |
| 202 | - dct_coeff_probs, | |
| 203 | - va_reserved: Default::default(), | |
| 204 | - })) | |
| 205 | - } | |
| 206 | - | |
| 207 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAProbabilityDataBufferVP8 { | |
| 208 | - self.0.as_mut() | |
| 209 | - } | |
| 210 | - | |
| 211 | - /// Returns the inner FFI type. Useful for testing purposes. | |
| 212 | - pub fn inner(&self) -> &bindings::VAProbabilityDataBufferVP8 { | |
| 213 | - self.0.as_ref() | |
| 214 | - } | |
| 215 | -} | |
| 216 | - | |
| 217 | -pub struct EncSequenceParameterBufferVP8(Box<bindings::VAEncSequenceParameterBufferVP8>); | |
| 218 | - | |
| 219 | -impl EncSequenceParameterBufferVP8 { | |
| 220 | - #[allow(clippy::too_many_arguments)] | |
| 221 | - pub fn new( | |
| 222 | - frame_width: u32, | |
| 223 | - frame_height: u32, | |
| 224 | - frame_width_scale: u32, | |
| 225 | - frame_height_scale: u32, | |
| 226 | - error_resilient: u32, | |
| 227 | - kf_auto: u32, | |
| 228 | - kf_min_dist: u32, | |
| 229 | - kf_max_dist: u32, | |
| 230 | - bits_per_second: u32, | |
| 231 | - intra_period: u32, | |
| 232 | - reference_frames: [bindings::VASurfaceID; 4usize], | |
| 233 | - ) -> Self { | |
| 234 | - Self(Box::new(bindings::VAEncSequenceParameterBufferVP8 { | |
| 235 | - frame_width, | |
| 236 | - frame_height, | |
| 237 | - frame_width_scale, | |
| 238 | - frame_height_scale, | |
| 239 | - error_resilient, | |
| 240 | - kf_auto, | |
| 241 | - kf_min_dist, | |
| 242 | - kf_max_dist, | |
| 243 | - bits_per_second, | |
| 244 | - intra_period, | |
| 245 | - reference_frames, | |
| 246 | - va_reserved: Default::default(), | |
| 247 | - })) | |
| 248 | - } | |
| 249 | - | |
| 250 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSequenceParameterBufferVP8 { | |
| 251 | - &mut self.0 | |
| 252 | - } | |
| 253 | -} | |
| 254 | - | |
| 255 | -pub struct VP8EncRefFlags(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1); | |
| 256 | - | |
| 257 | -impl VP8EncRefFlags { | |
| 258 | - pub fn new( | |
| 259 | - force_kf: u32, | |
| 260 | - no_ref_last: u32, | |
| 261 | - no_ref_gf: u32, | |
| 262 | - no_ref_arf: u32, | |
| 263 | - temporal_id: u32, | |
| 264 | - first_ref: u32, | |
| 265 | - second_ref: u32, | |
| 266 | - ) -> Self { | |
| 267 | - let _bitfield_1 = | |
| 268 | - bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 269 | - force_kf, | |
| 270 | - no_ref_last, | |
| 271 | - no_ref_gf, | |
| 272 | - no_ref_arf, | |
| 273 | - temporal_id, | |
| 274 | - first_ref, | |
| 275 | - second_ref, | |
| 276 | - Default::default(), | |
| 277 | - ); | |
| 278 | - | |
| 279 | - Self(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1 { | |
| 280 | - bits: bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1 { | |
| 281 | - _bitfield_align_1: Default::default(), | |
| 282 | - _bitfield_1, | |
| 283 | - }, | |
| 284 | - }) | |
| 285 | - } | |
| 286 | -} | |
| 287 | - | |
| 288 | -pub struct VP8EncPicFlags(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2); | |
| 289 | - | |
| 290 | -impl VP8EncPicFlags { | |
| 291 | - #[allow(clippy::too_many_arguments)] | |
| 292 | - pub fn new( | |
| 293 | - frame_type: u32, | |
| 294 | - version: u32, | |
| 295 | - show_frame: u32, | |
| 296 | - color_space: u32, | |
| 297 | - recon_filter_type: u32, | |
| 298 | - loop_filter_type: u32, | |
| 299 | - auto_partitions: u32, | |
| 300 | - num_token_partitions: u32, | |
| 301 | - clamping_type: u32, | |
| 302 | - segmentation_enabled: u32, | |
| 303 | - update_mb_segmentation_map: u32, | |
| 304 | - update_segment_feature_data: u32, | |
| 305 | - loop_filter_adj_enable: u32, | |
| 306 | - refresh_entropy_probs: u32, | |
| 307 | - refresh_golden_frame: u32, | |
| 308 | - refresh_alternate_frame: u32, | |
| 309 | - refresh_last: u32, | |
| 310 | - copy_buffer_to_golden: u32, | |
| 311 | - copy_buffer_to_alternate: u32, | |
| 312 | - sign_bias_golden: u32, | |
| 313 | - sign_bias_alternate: u32, | |
| 314 | - mb_no_coeff_skip: u32, | |
| 315 | - forced_lf_adjustment: u32, | |
| 316 | - ) -> Self { | |
| 317 | - let _bitfield_1 = | |
| 318 | - bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
| 319 | - frame_type, | |
| 320 | - version, | |
| 321 | - show_frame, | |
| 322 | - color_space, | |
| 323 | - recon_filter_type, | |
| 324 | - loop_filter_type, | |
| 325 | - auto_partitions, | |
| 326 | - num_token_partitions, | |
| 327 | - clamping_type, | |
| 328 | - segmentation_enabled, | |
| 329 | - update_mb_segmentation_map, | |
| 330 | - update_segment_feature_data, | |
| 331 | - loop_filter_adj_enable, | |
| 332 | - refresh_entropy_probs, | |
| 333 | - refresh_golden_frame, | |
| 334 | - refresh_alternate_frame, | |
| 335 | - refresh_last, | |
| 336 | - copy_buffer_to_golden, | |
| 337 | - copy_buffer_to_alternate, | |
| 338 | - sign_bias_golden, | |
| 339 | - sign_bias_alternate, | |
| 340 | - mb_no_coeff_skip, | |
| 341 | - forced_lf_adjustment, | |
| 342 | - Default::default(), | |
| 343 | - ); | |
| 344 | - | |
| 345 | - Self(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2 { | |
| 346 | - bits: bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2__bindgen_ty_1 { | |
| 347 | - _bitfield_align_1: Default::default(), | |
| 348 | - _bitfield_1, | |
| 349 | - }, | |
| 350 | - }) | |
| 351 | - } | |
| 352 | -} | |
| 353 | - | |
| 354 | -pub struct EncPictureParameterBufferVP8(Box<bindings::VAEncPictureParameterBufferVP8>); | |
| 355 | - | |
| 356 | -impl EncPictureParameterBufferVP8 { | |
| 357 | - #[allow(clippy::too_many_arguments)] | |
| 358 | - pub fn new( | |
| 359 | - reconstructed_frame: bindings::VASurfaceID, | |
| 360 | - ref_last_frame: bindings::VASurfaceID, | |
| 361 | - ref_gf_frame: bindings::VASurfaceID, | |
| 362 | - ref_arf_frame: bindings::VASurfaceID, | |
| 363 | - coded_buf: bindings::VABufferID, | |
| 364 | - ref_flags: &VP8EncRefFlags, | |
| 365 | - pic_flags: &VP8EncPicFlags, | |
| 366 | - loop_filter_level: [i8; 4usize], | |
| 367 | - ref_lf_delta: [i8; 4usize], | |
| 368 | - mode_lf_delta: [i8; 4usize], | |
| 369 | - sharpness_level: u8, | |
| 370 | - clamp_qindex_high: u8, | |
| 371 | - clamp_qindex_low: u8, | |
| 372 | - ) -> Self { | |
| 373 | - let ref_flags = ref_flags.0; | |
| 374 | - let pic_flags = pic_flags.0; | |
| 375 | - | |
| 376 | - Self(Box::new(bindings::VAEncPictureParameterBufferVP8 { | |
| 377 | - reconstructed_frame, | |
| 378 | - ref_last_frame, | |
| 379 | - ref_gf_frame, | |
| 380 | - ref_arf_frame, | |
| 381 | - coded_buf, | |
| 382 | - ref_flags, | |
| 383 | - pic_flags, | |
| 384 | - loop_filter_level, | |
| 385 | - ref_lf_delta, | |
| 386 | - mode_lf_delta, | |
| 387 | - sharpness_level, | |
| 388 | - clamp_qindex_high, | |
| 389 | - clamp_qindex_low, | |
| 390 | - va_reserved: Default::default(), | |
| 391 | - })) | |
| 392 | - } | |
| 393 | - | |
| 394 | - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferVP8 { | |
| 395 | - &mut self.0 | |
| 396 | - } | |
| 397 | -} |
shims/cros-libva/src/lib.rsmodified+0 -465
| @@ -69,468 +69,3 @@ fn va_check(code: VAStatus) -> Result<(), VaError> { | ||
| 69 | 69 | _ => Err(VaError(unsafe { NonZeroI32::new_unchecked(code) })), |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | - | |
| 73 | -#[cfg(test)] | |
| 74 | -mod tests { | |
| 75 | - use std::io::Write; | |
| 76 | - use std::rc::Rc; | |
| 77 | - | |
| 78 | - use super::*; | |
| 79 | - | |
| 80 | - /// Returns a 32-bit CRC for the visible part of `image`, which must be in NV12 format. | |
| 81 | - fn crc_nv12_image(image: &Image) -> u32 { | |
| 82 | - let data = image.as_ref(); | |
| 83 | - let va_image = image.image(); | |
| 84 | - let offsets = &va_image.offsets; | |
| 85 | - let pitches = &va_image.pitches; | |
| 86 | - let width = va_image.width as usize; | |
| 87 | - let height = va_image.height as usize; | |
| 88 | - | |
| 89 | - // We only support NV12 images | |
| 90 | - assert_eq!(va_image.format.fourcc, u32::from_ne_bytes(*b"NV12")); | |
| 91 | - // Consistency check | |
| 92 | - assert_eq!(va_image.num_planes, 2); | |
| 93 | - | |
| 94 | - let mut hasher = crc32fast::Hasher::new(); | |
| 95 | - | |
| 96 | - let offset = offsets[0] as usize; | |
| 97 | - let pitch = pitches[0] as usize; | |
| 98 | - let y_plane = data[offset..(offset + pitch * height)] | |
| 99 | - .chunks(pitch) | |
| 100 | - .map(|line| &line[0..width]); | |
| 101 | - | |
| 102 | - let offset = offsets[1] as usize; | |
| 103 | - let pitch = pitches[1] as usize; | |
| 104 | - let uv_plane = data[offset..(offset + pitch * ((height + 1) / 2))] | |
| 105 | - .chunks(pitch) | |
| 106 | - .map(|line| &line[0..width]); | |
| 107 | - | |
| 108 | - for line in y_plane.chain(uv_plane) { | |
| 109 | - hasher.update(line); | |
| 110 | - } | |
| 111 | - | |
| 112 | - hasher.finalize() | |
| 113 | - } | |
| 114 | - | |
| 115 | - #[test] | |
| 116 | - // Ignore this test by default as it requires libva-compatible hardware. | |
| 117 | - #[ignore] | |
| 118 | - fn libva_utils_mpeg2vldemo() { | |
| 119 | - // Adapted from <https://github.com/intel/libva-utils/blob/master/decode/mpeg2vldemo.cpp> | |
| 120 | - let display = Display::open().unwrap(); | |
| 121 | - | |
| 122 | - assert!(!display.query_vendor_string().unwrap().is_empty()); | |
| 123 | - let profiles = display.query_config_profiles().unwrap(); | |
| 124 | - assert!(!profiles.is_empty()); | |
| 125 | - | |
| 126 | - let profile = bindings::VAProfile::VAProfileMPEG2Main; | |
| 127 | - let entrypoints = display.query_config_entrypoints(profile).unwrap(); | |
| 128 | - assert!(!entrypoints.is_empty()); | |
| 129 | - assert!(entrypoints | |
| 130 | - .iter() | |
| 131 | - .any(|e| *e == bindings::VAEntrypoint::VAEntrypointVLD)); | |
| 132 | - | |
| 133 | - let format = bindings::VA_RT_FORMAT_YUV420; | |
| 134 | - let width = 16u32; | |
| 135 | - let height = 16u32; | |
| 136 | - | |
| 137 | - let mut attrs = vec![bindings::VAConfigAttrib { | |
| 138 | - type_: bindings::VAConfigAttribType::VAConfigAttribRTFormat, | |
| 139 | - value: 0, | |
| 140 | - }]; | |
| 141 | - | |
| 142 | - let entrypoint = bindings::VAEntrypoint::VAEntrypointVLD; | |
| 143 | - display | |
| 144 | - .get_config_attributes(profile, entrypoint, &mut attrs) | |
| 145 | - .unwrap(); | |
| 146 | - assert!(attrs[0].value != bindings::VA_ATTRIB_NOT_SUPPORTED); | |
| 147 | - assert!(attrs[0].value & bindings::VA_RT_FORMAT_YUV420 != 0); | |
| 148 | - | |
| 149 | - let config = display.create_config(attrs, profile, entrypoint).unwrap(); | |
| 150 | - | |
| 151 | - let mut surfaces = display | |
| 152 | - .create_surfaces( | |
| 153 | - format, | |
| 154 | - None, | |
| 155 | - width, | |
| 156 | - height, | |
| 157 | - Some(UsageHint::USAGE_HINT_DECODER), | |
| 158 | - vec![()], | |
| 159 | - ) | |
| 160 | - .unwrap(); | |
| 161 | - let context = display | |
| 162 | - .create_context( | |
| 163 | - &config, | |
| 164 | - width, | |
| 165 | - ((height + 15) / 16) * 16, | |
| 166 | - Some(&surfaces), | |
| 167 | - true, | |
| 168 | - ) | |
| 169 | - .unwrap(); | |
| 170 | - | |
| 171 | - // The picture data is adapted from libva-utils at decode/mpeg2vldemo.cpp | |
| 172 | - // Data dump of a 16x16 MPEG2 video clip,it has one I frame | |
| 173 | - let mut mpeg2_clip: Vec<u8> = vec![ | |
| 174 | - 0x00, 0x00, 0x01, 0xb3, 0x01, 0x00, 0x10, 0x13, 0xff, 0xff, 0xe0, 0x18, 0x00, 0x00, | |
| 175 | - 0x01, 0xb5, 0x14, 0x8a, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb8, 0x00, 0x08, | |
| 176 | - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0f, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xb5, | |
| 177 | - 0x8f, 0xff, 0xf3, 0x41, 0x80, 0x00, 0x00, 0x01, 0x01, 0x13, 0xe1, 0x00, 0x15, 0x81, | |
| 178 | - 0x54, 0xe0, 0x2a, 0x05, 0x43, 0x00, 0x2d, 0x60, 0x18, 0x01, 0x4e, 0x82, 0xb9, 0x58, | |
| 179 | - 0xb1, 0x83, 0x49, 0xa4, 0xa0, 0x2e, 0x05, 0x80, 0x4b, 0x7a, 0x00, 0x01, 0x38, 0x20, | |
| 180 | - 0x80, 0xe8, 0x05, 0xff, 0x60, 0x18, 0xe0, 0x1d, 0x80, 0x98, 0x01, 0xf8, 0x06, 0x00, | |
| 181 | - 0x54, 0x02, 0xc0, 0x18, 0x14, 0x03, 0xb2, 0x92, 0x80, 0xc0, 0x18, 0x94, 0x42, 0x2c, | |
| 182 | - 0xb2, 0x11, 0x64, 0xa0, 0x12, 0x5e, 0x78, 0x03, 0x3c, 0x01, 0x80, 0x0e, 0x80, 0x18, | |
| 183 | - 0x80, 0x6b, 0xca, 0x4e, 0x01, 0x0f, 0xe4, 0x32, 0xc9, 0xbf, 0x01, 0x42, 0x69, 0x43, | |
| 184 | - 0x50, 0x4b, 0x01, 0xc9, 0x45, 0x80, 0x50, 0x01, 0x38, 0x65, 0xe8, 0x01, 0x03, 0xf3, | |
| 185 | - 0xc0, 0x76, 0x00, 0xe0, 0x03, 0x20, 0x28, 0x18, 0x01, 0xa9, 0x34, 0x04, 0xc5, 0xe0, | |
| 186 | - 0x0b, 0x0b, 0x04, 0x20, 0x06, 0xc0, 0x89, 0xff, 0x60, 0x12, 0x12, 0x8a, 0x2c, 0x34, | |
| 187 | - 0x11, 0xff, 0xf6, 0xe2, 0x40, 0xc0, 0x30, 0x1b, 0x7a, 0x01, 0xa9, 0x0d, 0x00, 0xac, | |
| 188 | - 0x64, | |
| 189 | - ]; | |
| 190 | - | |
| 191 | - let picture_coding_extension = | |
| 192 | - MPEG2PictureCodingExtension::new(0, 3, 0, 1, 0, 0, 0, 0, 0, 1, 1); | |
| 193 | - let pic_param = PictureParameterBufferMPEG2::new( | |
| 194 | - 16, | |
| 195 | - 16, | |
| 196 | - 0xffffffff, | |
| 197 | - 0xffffffff, | |
| 198 | - 1, | |
| 199 | - 0xffff, | |
| 200 | - &picture_coding_extension, | |
| 201 | - ); | |
| 202 | - | |
| 203 | - let pic_param = BufferType::PictureParameter(PictureParameter::MPEG2(pic_param)); | |
| 204 | - | |
| 205 | - let iq_matrix = IQMatrixBufferMPEG2::new( | |
| 206 | - 1, | |
| 207 | - 1, | |
| 208 | - 0, | |
| 209 | - 0, | |
| 210 | - [ | |
| 211 | - 8, 16, 16, 19, 16, 19, 22, 22, 22, 22, 22, 22, 26, 24, 26, 27, 27, 27, 26, 26, 26, | |
| 212 | - 26, 27, 27, 27, 29, 29, 29, 34, 34, 34, 29, 29, 29, 27, 27, 29, 29, 32, 32, 34, 34, | |
| 213 | - 37, 38, 37, 35, 35, 34, 35, 38, 38, 40, 40, 40, 48, 48, 46, 46, 56, 56, 58, 69, 69, | |
| 214 | - 83, | |
| 215 | - ], | |
| 216 | - [ | |
| 217 | - 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 218 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 219 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 220 | - ], | |
| 221 | - [0; 64], | |
| 222 | - [0; 64], | |
| 223 | - ); | |
| 224 | - | |
| 225 | - let iq_matrix = BufferType::IQMatrix(IQMatrix::MPEG2(iq_matrix)); | |
| 226 | - | |
| 227 | - let slice_param = SliceParameterBufferMPEG2::new(150, 0, 0, 38, 0, 0, 2, 0); | |
| 228 | - | |
| 229 | - let slice_param = BufferType::SliceParameter(SliceParameter::MPEG2(slice_param)); | |
| 230 | - | |
| 231 | - let test_data_offset = 47; | |
| 232 | - let slice_data = BufferType::SliceData(mpeg2_clip.drain(test_data_offset..).collect()); | |
| 233 | - | |
| 234 | - let buffers = vec![ | |
| 235 | - context.create_buffer(pic_param).unwrap(), | |
| 236 | - context.create_buffer(slice_param).unwrap(), | |
| 237 | - context.create_buffer(iq_matrix).unwrap(), | |
| 238 | - context.create_buffer(slice_data).unwrap(), | |
| 239 | - ]; | |
| 240 | - | |
| 241 | - let mut picture = Picture::new(0, Rc::clone(&context), surfaces.remove(0)); | |
| 242 | - for buffer in buffers { | |
| 243 | - picture.add_buffer(buffer); | |
| 244 | - } | |
| 245 | - | |
| 246 | - // Actual client code can just chain the calls. | |
| 247 | - let picture = picture.begin().unwrap(); | |
| 248 | - let picture = picture.render().unwrap(); | |
| 249 | - let picture = picture.end().unwrap(); | |
| 250 | - let picture = picture.sync().map_err(|(e, _)| e).unwrap(); | |
| 251 | - | |
| 252 | - // Test whether we can map the resulting surface to obtain the raw yuv | |
| 253 | - // data | |
| 254 | - let image_fmts = display.query_image_formats().unwrap(); | |
| 255 | - let image_fmt = image_fmts | |
| 256 | - .into_iter() | |
| 257 | - .find(|f| f.fourcc == bindings::VA_FOURCC_NV12) | |
| 258 | - .expect("No valid VAImageFormat found for NV12"); | |
| 259 | - | |
| 260 | - let resolution = (width, height); | |
| 261 | - let image = picture | |
| 262 | - .create_image(image_fmt, resolution, resolution) | |
| 263 | - .unwrap(); | |
| 264 | - | |
| 265 | - assert_eq!(crc_nv12_image(&image), 0xa5713e52); | |
| 266 | - } | |
| 267 | - | |
| 268 | - #[test] | |
| 269 | - // Ignore this test by default as it requires libva-compatible hardware. | |
| 270 | - #[ignore] | |
| 271 | - fn enc_h264_demo() { | |
| 272 | - // Based on `gst-launch-1.0 videotestsrc num-buffers=1 ! video/x-raw,width=64,height=64,format=NV12 ! vaapih264enc ! filesink location=frame.h264` | |
| 273 | - // Frame created using `gst-launch-1.0 videotestsrc num-buffers=1 ! video/x-raw,width=64,height=64,format=NV12 ! filesink location=src/test_frame.nv12` | |
| 274 | - let raw_frame_nv12 = include_bytes!("test_frame.nv12"); | |
| 275 | - | |
| 276 | - let display = Display::open().unwrap(); | |
| 277 | - | |
| 278 | - let format = bindings::VA_RT_FORMAT_YUV420; | |
| 279 | - let entrypoint = bindings::VAEntrypoint::VAEntrypointEncSliceLP; | |
| 280 | - let profile = bindings::VAProfile::VAProfileH264ConstrainedBaseline; | |
| 281 | - let width = 64u32; | |
| 282 | - let height = 64u32; | |
| 283 | - | |
| 284 | - let mut attrs = vec![bindings::VAConfigAttrib { | |
| 285 | - type_: bindings::VAConfigAttribType::VAConfigAttribRTFormat, | |
| 286 | - value: 0, | |
| 287 | - }]; | |
| 288 | - | |
| 289 | - display | |
| 290 | - .get_config_attributes(profile, entrypoint, &mut attrs) | |
| 291 | - .unwrap(); | |
| 292 | - | |
| 293 | - let config = display.create_config(attrs, profile, entrypoint).unwrap(); | |
| 294 | - | |
| 295 | - let mut surfaces = display | |
| 296 | - .create_surfaces( | |
| 297 | - format, | |
| 298 | - None, | |
| 299 | - width, | |
| 300 | - height, | |
| 301 | - Some(UsageHint::USAGE_HINT_ENCODER), | |
| 302 | - vec![()], | |
| 303 | - ) | |
| 304 | - .unwrap(); | |
| 305 | - | |
| 306 | - let context = display | |
| 307 | - .create_context(&config, width, height, Some(&surfaces), true) | |
| 308 | - .unwrap(); | |
| 309 | - | |
| 310 | - let seq_fields = H264EncSeqFields::new( | |
| 311 | - 1, // 4:2:0 | |
| 312 | - 1, // Only frames | |
| 313 | - 0, 0, 0, 1, 0, 2, 0, | |
| 314 | - ); | |
| 315 | - | |
| 316 | - let image_fmts = display.query_image_formats().unwrap(); | |
| 317 | - let image_fmt = image_fmts | |
| 318 | - .into_iter() | |
| 319 | - .find(|f| f.fourcc == bindings::VA_FOURCC_NV12) | |
| 320 | - .expect("No valid VAImageFormat found for NV12"); | |
| 321 | - | |
| 322 | - let surface = surfaces.pop().unwrap(); | |
| 323 | - let surface_id = surface.id(); | |
| 324 | - | |
| 325 | - let coded_buffer = context.create_enc_coded(raw_frame_nv12.len()).unwrap(); | |
| 326 | - | |
| 327 | - let mut image = | |
| 328 | - Image::create_from(&surface, image_fmt, (width, height), (width, height)).unwrap(); | |
| 329 | - | |
| 330 | - let va_image = *image.image(); | |
| 331 | - let dest = image.as_mut(); | |
| 332 | - let data = &raw_frame_nv12[..]; | |
| 333 | - let width = width as usize; | |
| 334 | - let height = height as usize; | |
| 335 | - | |
| 336 | - let mut src = data; | |
| 337 | - let mut dst = &mut dest[va_image.offsets[0] as usize..]; | |
| 338 | - | |
| 339 | - // Copy luma | |
| 340 | - for _ in 0..height { | |
| 341 | - dst[..width].copy_from_slice(&src[..width]); | |
| 342 | - dst = &mut dst[va_image.pitches[0] as usize..]; | |
| 343 | - src = &src[width..]; | |
| 344 | - } | |
| 345 | - | |
| 346 | - // Advance to the offset of the chroma plane | |
| 347 | - let mut src = &data[width * height..]; | |
| 348 | - let mut dst = &mut dest[va_image.offsets[1] as usize..]; | |
| 349 | - | |
| 350 | - let height = height / 2; | |
| 351 | - | |
| 352 | - // Copy chroma | |
| 353 | - for _ in 0..height { | |
| 354 | - dst[..width].copy_from_slice(&src[..width]); | |
| 355 | - dst = &mut dst[va_image.pitches[1] as usize..]; | |
| 356 | - src = &src[width..]; | |
| 357 | - } | |
| 358 | - drop(image); | |
| 359 | - | |
| 360 | - let sps = BufferType::EncSequenceParameter(EncSequenceParameter::H264( | |
| 361 | - EncSequenceParameterBufferH264::new( | |
| 362 | - 0, | |
| 363 | - 10, | |
| 364 | - 10, | |
| 365 | - 30, | |
| 366 | - 1, | |
| 367 | - 0, | |
| 368 | - 1, | |
| 369 | - (width / 16) as u16, // width / 16 | |
| 370 | - (height / 16) as u16, // height / 16 | |
| 371 | - &seq_fields, | |
| 372 | - 0, | |
| 373 | - 0, | |
| 374 | - 0, | |
| 375 | - 0, | |
| 376 | - 0, | |
| 377 | - [0; 256], | |
| 378 | - None, | |
| 379 | - Some(H264VuiFields::new(1, 1, 0, 0, 0, 1, 0, 0)), | |
| 380 | - 255, | |
| 381 | - 1, | |
| 382 | - 1, | |
| 383 | - 1, | |
| 384 | - 60, | |
| 385 | - ), | |
| 386 | - )); | |
| 387 | - | |
| 388 | - let sps = context.create_buffer(sps).unwrap(); | |
| 389 | - | |
| 390 | - let ref_frames: [PictureH264; 16] = (0..16) | |
| 391 | - .map(|_| { | |
| 392 | - PictureH264::new( | |
| 393 | - bindings::VA_INVALID_ID, | |
| 394 | - 0, | |
| 395 | - bindings::VA_INVALID_SURFACE, | |
| 396 | - 0, | |
| 397 | - 0, | |
| 398 | - ) | |
| 399 | - }) | |
| 400 | - .collect::<Vec<_>>() | |
| 401 | - .try_into() | |
| 402 | - .unwrap_or_else(|_| { | |
| 403 | - panic!(); | |
| 404 | - }); | |
| 405 | - | |
| 406 | - let pps = BufferType::EncPictureParameter(EncPictureParameter::H264( | |
| 407 | - EncPictureParameterBufferH264::new( | |
| 408 | - PictureH264::new(surface_id, 0, 0, 0, 0), | |
| 409 | - ref_frames, | |
| 410 | - coded_buffer.id(), | |
| 411 | - 0, | |
| 412 | - 0, | |
| 413 | - 0, | |
| 414 | - 0, | |
| 415 | - 26, | |
| 416 | - 0, | |
| 417 | - 0, | |
| 418 | - 0, | |
| 419 | - 0, | |
| 420 | - &H264EncPicFields::new(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0), | |
| 421 | - ), | |
| 422 | - )); | |
| 423 | - | |
| 424 | - let pps = context.create_buffer(pps).unwrap(); | |
| 425 | - | |
| 426 | - let ref_pic_list_0: [PictureH264; 32] = (0..32) | |
| 427 | - .map(|_| { | |
| 428 | - PictureH264::new( | |
| 429 | - bindings::VA_INVALID_ID, | |
| 430 | - 0, | |
| 431 | - bindings::VA_INVALID_SURFACE, | |
| 432 | - 0, | |
| 433 | - 0, | |
| 434 | - ) | |
| 435 | - }) | |
| 436 | - .collect::<Vec<_>>() | |
| 437 | - .try_into() | |
| 438 | - .unwrap_or_else(|_| { | |
| 439 | - panic!(); | |
| 440 | - }); | |
| 441 | - | |
| 442 | - let ref_pic_list_1: [PictureH264; 32] = (0..32) | |
| 443 | - .map(|_| { | |
| 444 | - PictureH264::new( | |
| 445 | - bindings::VA_INVALID_ID, | |
| 446 | - 0, | |
| 447 | - bindings::VA_INVALID_SURFACE, | |
| 448 | - 0, | |
| 449 | - 0, | |
| 450 | - ) | |
| 451 | - }) | |
| 452 | - .collect::<Vec<_>>() | |
| 453 | - .try_into() | |
| 454 | - .unwrap_or_else(|_| { | |
| 455 | - panic!(); | |
| 456 | - }); | |
| 457 | - | |
| 458 | - let slice = BufferType::EncSliceParameter(EncSliceParameter::H264( | |
| 459 | - EncSliceParameterBufferH264::new( | |
| 460 | - 0, | |
| 461 | - ((width / 16) * (height / 16)) as u32, | |
| 462 | - bindings::VA_INVALID_ID, | |
| 463 | - 2, // I | |
| 464 | - 0, | |
| 465 | - 1, | |
| 466 | - 0, | |
| 467 | - 0, | |
| 468 | - [0, 0], | |
| 469 | - 1, | |
| 470 | - 0, | |
| 471 | - 0, | |
| 472 | - 0, | |
| 473 | - ref_pic_list_0, | |
| 474 | - ref_pic_list_1, | |
| 475 | - 0, | |
| 476 | - 0, | |
| 477 | - 0, | |
| 478 | - [0; 32], | |
| 479 | - [0; 32], | |
| 480 | - 0, | |
| 481 | - [[0; 2]; 32], | |
| 482 | - [[0; 2]; 32], | |
| 483 | - 0, | |
| 484 | - [0; 32], | |
| 485 | - [0; 32], | |
| 486 | - 0, | |
| 487 | - [[0; 2]; 32], | |
| 488 | - [[0; 2]; 32], | |
| 489 | - 0, | |
| 490 | - 0, | |
| 491 | - 0, | |
| 492 | - 2, | |
| 493 | - 2, | |
| 494 | - ), | |
| 495 | - )); | |
| 496 | - | |
| 497 | - let slice = context.create_buffer(slice).unwrap(); | |
| 498 | - | |
| 499 | - let mut picture = Picture::new(0, Rc::clone(&context), surface); | |
| 500 | - picture.add_buffer(pps); | |
| 501 | - picture.add_buffer(sps); | |
| 502 | - picture.add_buffer(slice); | |
| 503 | - | |
| 504 | - let picture = picture.begin().unwrap(); | |
| 505 | - let picture = picture.render().unwrap(); | |
| 506 | - let picture = picture.end().unwrap(); | |
| 507 | - let _ = picture.sync().map_err(|(e, _)| e).unwrap(); | |
| 508 | - | |
| 509 | - let coded_buf = MappedCodedBuffer::new(&coded_buffer).unwrap(); | |
| 510 | - assert_ne!(coded_buf.segments().len(), 0); | |
| 511 | - | |
| 512 | - for segment in coded_buf.iter() { | |
| 513 | - assert_ne!(segment.buf.len(), 0); | |
| 514 | - } | |
| 515 | - | |
| 516 | - const WRITE_TO_FILE: bool = false; | |
| 517 | - if WRITE_TO_FILE { | |
| 518 | - let raw_sps_bitstream: Vec<u8> = vec![ | |
| 519 | - 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0xc0, 0x0a, 0xab, 0x42, 0x12, 0x7f, 0xe0, 0x00, | |
| 520 | - 0x20, 0x00, 0x22, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x79, 0x28, | |
| 521 | - ]; | |
| 522 | - | |
| 523 | - let raw_pps_bitstream: Vec<u8> = vec![0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x3c, 0x80]; | |
| 524 | - | |
| 525 | - let mut raw_file = std::fs::File::create("libva_utils_enc_h264_demo.h264").unwrap(); | |
| 526 | - raw_file.write_all(&raw_sps_bitstream).unwrap(); | |
| 527 | - raw_file.write_all(&raw_pps_bitstream).unwrap(); | |
| 528 | - | |
| 529 | - for segment in coded_buf.segments() { | |
| 530 | - raw_file.write_all(segment.buf).unwrap(); | |
| 531 | - } | |
| 532 | - | |
| 533 | - raw_file.flush().unwrap(); | |
| 534 | - } | |
| 535 | - } | |
| 536 | -} |
shims/cros-libva/src/test_frame.nv12deleted+0 -0
Binary file changed
shims/vk-video-ffi/Cargo.tomlmodified+0 -5
| @@ -17,10 +17,5 @@ windows = { version = "0.62.2", features = [ | ||
| 17 | 17 | "Win32_Graphics_Dxgi_Common", |
| 18 | 18 | ] } |
| 19 | 19 | |
| 20 | -[dev-dependencies] | |
| 21 | -ec-av1-syntax.workspace = true | |
| 22 | -ec-h264-syntax.workspace = true | |
| 23 | -ec-h265-syntax.workspace = true | |
| 24 | - | |
| 25 | 20 | [target.'cfg(windows)'.dev-dependencies] |
| 26 | 21 | windows = { version = "0.62.2", features = ["Win32_Graphics_Direct3D"] } |
shims/vk-video-ffi/examples/av1_decode_smoke.rsdeleted+0 -320
| @@ -1,320 +0,0 @@ | ||
| 1 | -use std::fs; | |
| 2 | -use std::path::PathBuf; | |
| 3 | -use std::process::Command; | |
| 4 | - | |
| 5 | -use ec_av1_syntax::{ | |
| 6 | - Av1Parser, ChromaSamplePosition, ColorConfig, FrameHeader, FrameType, InterpolationFilter, | |
| 7 | - ObuKind, RestorationType, SequenceHeader, TxMode, WarpModel, | |
| 8 | -}; | |
| 9 | -use vk_video_ffi::{ | |
| 10 | - Av1Cdef, Av1ColorConfig, Av1DecodeConfig, Av1DecodePicture, Av1DecodeSession, Av1DeltaParams, | |
| 11 | - Av1FrameHeader, Av1FrameType, Av1GlobalMotion, Av1InterpolationFilter, Av1LoopFilter, | |
| 12 | - Av1LoopRestoration, Av1Quantization, Av1Restoration, Av1Segmentation, Av1SequenceHeader, | |
| 13 | - Av1TileInfo, Av1TimingInfo, Av1TxMode, Av1WarpModel, Gpu, | |
| 14 | -}; | |
| 15 | - | |
| 16 | -fn color(c: &ColorConfig) -> Av1ColorConfig { | |
| 17 | - Av1ColorConfig { | |
| 18 | - bit_depth: c.bit_depth, | |
| 19 | - mono_chrome: c.mono_chrome, | |
| 20 | - color_range: c.color_range, | |
| 21 | - separate_uv_delta_q: c.separate_uv_delta_q, | |
| 22 | - subsampling_x: c.subsampling_x, | |
| 23 | - subsampling_y: c.subsampling_y, | |
| 24 | - color_primaries: c.color_primaries, | |
| 25 | - transfer_characteristics: c.transfer_characteristics, | |
| 26 | - matrix_coefficients: c.matrix_coefficients, | |
| 27 | - chroma_sample_position: match c.chroma_sample_position { | |
| 28 | - ChromaSamplePosition::Unknown => 0, | |
| 29 | - ChromaSamplePosition::Vertical => 1, | |
| 30 | - ChromaSamplePosition::Colocated => 2, | |
| 31 | - ChromaSamplePosition::Reserved => 3, | |
| 32 | - }, | |
| 33 | - } | |
| 34 | -} | |
| 35 | - | |
| 36 | -fn sequence(s: &SequenceHeader) -> Av1SequenceHeader { | |
| 37 | - Av1SequenceHeader { | |
| 38 | - seq_profile: s.seq_profile, | |
| 39 | - still_picture: s.still_picture, | |
| 40 | - reduced_still_picture_header: s.reduced_still_picture_header, | |
| 41 | - timing_info: s.timing_info.map(|t| Av1TimingInfo { | |
| 42 | - equal_picture_interval: t.equal_picture_interval, | |
| 43 | - num_units_in_display_tick: t.num_units_in_display_tick, | |
| 44 | - time_scale: t.time_scale, | |
| 45 | - num_ticks_per_picture_minus_1: t.num_ticks_per_picture.saturating_sub(1), | |
| 46 | - }), | |
| 47 | - initial_display_delay_present: s.initial_display_delay_present_flag, | |
| 48 | - frame_width_bits_minus_1: (s.frame_width_bits - 1) as u8, | |
| 49 | - frame_height_bits_minus_1: (s.frame_height_bits - 1) as u8, | |
| 50 | - max_frame_width_minus_1: (s.max_frame_width - 1) as u16, | |
| 51 | - max_frame_height_minus_1: (s.max_frame_height - 1) as u16, | |
| 52 | - frame_id_numbers_present: s.frame_id_numbers_present_flag, | |
| 53 | - delta_frame_id_length_minus_2: s.delta_frame_id_length.saturating_sub(2) as u8, | |
| 54 | - additional_frame_id_length_minus_1: s.additional_frame_id_length.saturating_sub(1) as u8, | |
| 55 | - order_hint_bits_minus_1: s.order_hint_bits.saturating_sub(1) as u8, | |
| 56 | - seq_force_integer_mv: s.seq_force_integer_mv, | |
| 57 | - seq_force_screen_content_tools: s.seq_force_screen_content_tools, | |
| 58 | - use_128x128_superblock: s.use_128x128_superblock, | |
| 59 | - enable_filter_intra: s.enable_filter_intra, | |
| 60 | - enable_intra_edge_filter: s.enable_intra_edge_filter, | |
| 61 | - enable_interintra_compound: s.enable_interintra_compound, | |
| 62 | - enable_masked_compound: s.enable_masked_compound, | |
| 63 | - enable_warped_motion: s.enable_warped_motion, | |
| 64 | - enable_dual_filter: s.enable_dual_filter, | |
| 65 | - enable_order_hint: s.enable_order_hint, | |
| 66 | - enable_jnt_comp: s.enable_jnt_comp, | |
| 67 | - enable_ref_frame_mvs: s.enable_ref_frame_mvs, | |
| 68 | - enable_superres: s.enable_superres, | |
| 69 | - enable_cdef: s.enable_cdef, | |
| 70 | - enable_restoration: s.enable_restoration, | |
| 71 | - color_config: color(&s.color_config), | |
| 72 | - film_grain_params_present: s.film_grain_params_present, | |
| 73 | - } | |
| 74 | -} | |
| 75 | - | |
| 76 | -fn restoration(r: RestorationType) -> Av1Restoration { | |
| 77 | - match r { | |
| 78 | - RestorationType::None => Av1Restoration::None, | |
| 79 | - RestorationType::Wiener => Av1Restoration::Wiener, | |
| 80 | - RestorationType::Sgrproj => Av1Restoration::Sgrproj, | |
| 81 | - RestorationType::Switchable => Av1Restoration::Switchable, | |
| 82 | - } | |
| 83 | -} | |
| 84 | - | |
| 85 | -fn frame(h: &FrameHeader, s: &SequenceHeader) -> Av1FrameHeader { | |
| 86 | - let sb_shift = s.sb_shift(); | |
| 87 | - let mut global_motion = [Av1GlobalMotion::default(); 8]; | |
| 88 | - let mut order_hints = [0u8; 8]; | |
| 89 | - for i in 0..7 { | |
| 90 | - global_motion[i + 1] = Av1GlobalMotion { | |
| 91 | - model: match h.global_motion[i].model { | |
| 92 | - WarpModel::Identity => Av1WarpModel::Identity, | |
| 93 | - WarpModel::Translation => Av1WarpModel::Translation, | |
| 94 | - WarpModel::Rotzoom => Av1WarpModel::Rotzoom, | |
| 95 | - WarpModel::Affine => Av1WarpModel::Affine, | |
| 96 | - }, | |
| 97 | - params: h.global_motion[i].params, | |
| 98 | - }; | |
| 99 | - order_hints[i + 1] = h.order_hints[i] as u8; | |
| 100 | - } | |
| 101 | - Av1FrameHeader { | |
| 102 | - frame_type: match h.frame_type { | |
| 103 | - FrameType::Key => Av1FrameType::Key, | |
| 104 | - FrameType::Inter => Av1FrameType::Inter, | |
| 105 | - FrameType::IntraOnly => Av1FrameType::IntraOnly, | |
| 106 | - FrameType::Switch => Av1FrameType::Switch, | |
| 107 | - }, | |
| 108 | - show_frame: h.show_frame, | |
| 109 | - showable_frame: h.showable_frame, | |
| 110 | - error_resilient_mode: h.error_resilient_mode, | |
| 111 | - disable_cdf_update: h.disable_cdf_update, | |
| 112 | - allow_screen_content_tools: h.allow_screen_content_tools, | |
| 113 | - force_integer_mv: h.force_integer_mv, | |
| 114 | - current_frame_id: h.current_frame_id, | |
| 115 | - frame_size_override_flag: h.frame_size_override_flag, | |
| 116 | - order_hint: h.order_hint as u8, | |
| 117 | - primary_ref_frame: h.primary_ref_frame, | |
| 118 | - refresh_frame_flags: h.refresh_frame_flags, | |
| 119 | - frame_width: h.frame_width, | |
| 120 | - frame_height: h.frame_height, | |
| 121 | - upscaled_width: h.upscaled_width, | |
| 122 | - render_width: h.render_width, | |
| 123 | - render_height: h.render_height, | |
| 124 | - use_superres: h.use_superres, | |
| 125 | - superres_denom: h.superres_denom, | |
| 126 | - allow_intrabc: h.allow_intrabc, | |
| 127 | - allow_high_precision_mv: h.allow_high_precision_mv, | |
| 128 | - is_motion_mode_switchable: h.is_motion_mode_switchable, | |
| 129 | - use_ref_frame_mvs: h.use_ref_frame_mvs, | |
| 130 | - frame_refs_short_signaling: h.frame_refs_short_signaling, | |
| 131 | - disable_frame_end_update_cdf: h.disable_frame_end_update_cdf, | |
| 132 | - reference_select: h.reference_select, | |
| 133 | - skip_mode_present: h.skip_mode_present, | |
| 134 | - allow_warped_motion: h.allow_warped_motion, | |
| 135 | - reduced_tx_set: h.reduced_tx_set, | |
| 136 | - interpolation_filter: match h.interpolation_filter { | |
| 137 | - InterpolationFilter::Eighttap => Av1InterpolationFilter::EightTap, | |
| 138 | - InterpolationFilter::EighttapSmooth => Av1InterpolationFilter::EightTapSmooth, | |
| 139 | - InterpolationFilter::EighttapSharp => Av1InterpolationFilter::EightTapSharp, | |
| 140 | - InterpolationFilter::Bilinear => Av1InterpolationFilter::Bilinear, | |
| 141 | - InterpolationFilter::Switchable => Av1InterpolationFilter::Switchable, | |
| 142 | - }, | |
| 143 | - tx_mode: match h.tx_mode { | |
| 144 | - TxMode::Only4x4 => Av1TxMode::Only4x4, | |
| 145 | - TxMode::Largest => Av1TxMode::Largest, | |
| 146 | - TxMode::Select => Av1TxMode::Select, | |
| 147 | - }, | |
| 148 | - tile_info: Av1TileInfo { | |
| 149 | - uniform_spacing: h.tile_info.uniform_spacing, | |
| 150 | - cols: h.tile_info.cols as u8, | |
| 151 | - rows: h.tile_info.rows as u8, | |
| 152 | - mi_col_starts: h | |
| 153 | - .tile_info | |
| 154 | - .mi_col_starts | |
| 155 | - .iter() | |
| 156 | - .map(|&v| v as u16) | |
| 157 | - .collect(), | |
| 158 | - mi_row_starts: h | |
| 159 | - .tile_info | |
| 160 | - .mi_row_starts | |
| 161 | - .iter() | |
| 162 | - .map(|&v| v as u16) | |
| 163 | - .collect(), | |
| 164 | - width_in_sbs_minus_1: h.tile_info.width_in_sbs_minus_1(sb_shift), | |
| 165 | - height_in_sbs_minus_1: h.tile_info.height_in_sbs_minus_1(sb_shift), | |
| 166 | - context_update_tile_id: h.tile_info.context_update_tile_id as u16, | |
| 167 | - tile_size_bytes_minus_1: h.tile_info.tile_size_bytes.saturating_sub(1) as u8, | |
| 168 | - }, | |
| 169 | - quantization: Av1Quantization { | |
| 170 | - base_q_idx: h.quantization.base_q_idx, | |
| 171 | - delta_q_y_dc: h.quantization.delta_q_y_dc, | |
| 172 | - delta_q_u_dc: h.quantization.delta_q_u_dc, | |
| 173 | - delta_q_u_ac: h.quantization.delta_q_u_ac, | |
| 174 | - delta_q_v_dc: h.quantization.delta_q_v_dc, | |
| 175 | - delta_q_v_ac: h.quantization.delta_q_v_ac, | |
| 176 | - using_qmatrix: h.quantization.using_qmatrix, | |
| 177 | - qm_y: h.quantization.qm_y, | |
| 178 | - qm_u: h.quantization.qm_u, | |
| 179 | - qm_v: h.quantization.qm_v, | |
| 180 | - }, | |
| 181 | - segmentation: Av1Segmentation { | |
| 182 | - enabled: h.segmentation.enabled, | |
| 183 | - update_map: h.segmentation.update_map, | |
| 184 | - temporal_update: h.segmentation.temporal_update, | |
| 185 | - update_data: h.segmentation.update_data, | |
| 186 | - feature_enabled: h.segmentation.feature_enabled, | |
| 187 | - feature_data: h.segmentation.feature_data, | |
| 188 | - }, | |
| 189 | - delta: Av1DeltaParams { | |
| 190 | - q_present: h.delta.q_present, | |
| 191 | - q_res: h.delta.q_res, | |
| 192 | - lf_present: h.delta.lf_present, | |
| 193 | - lf_res: h.delta.lf_res, | |
| 194 | - lf_multi: h.delta.lf_multi, | |
| 195 | - }, | |
| 196 | - loop_filter: Av1LoopFilter { | |
| 197 | - level: h.loop_filter.level, | |
| 198 | - sharpness: h.loop_filter.sharpness, | |
| 199 | - delta_enabled: h.loop_filter.delta_enabled, | |
| 200 | - delta_update: h.loop_filter.delta_update, | |
| 201 | - ref_deltas: h.loop_filter.ref_deltas, | |
| 202 | - mode_deltas: h.loop_filter.mode_deltas, | |
| 203 | - }, | |
| 204 | - cdef: Av1Cdef { | |
| 205 | - damping_minus_3: h.cdef.damping.saturating_sub(3), | |
| 206 | - bits: h.cdef.bits, | |
| 207 | - y_pri: h.cdef.y_pri_strength, | |
| 208 | - y_sec: h.cdef.y_sec_strength, | |
| 209 | - uv_pri: h.cdef.uv_pri_strength, | |
| 210 | - uv_sec: h.cdef.uv_sec_strength, | |
| 211 | - }, | |
| 212 | - loop_restoration: Av1LoopRestoration { | |
| 213 | - frame_restoration_type: h.loop_restoration.frame_restoration_type.map(restoration), | |
| 214 | - loop_restoration_size: h.loop_restoration.loop_restoration_size.map(|v| v as u16), | |
| 215 | - }, | |
| 216 | - global_motion, | |
| 217 | - order_hints, | |
| 218 | - skip_mode_frame: h.skip_mode_frame, | |
| 219 | - expected_frame_id: [0; 8], | |
| 220 | - apply_grain: h.film_grain.apply_grain, | |
| 221 | - } | |
| 222 | -} | |
| 223 | - | |
| 224 | -fn mean_abs_diff(a: &[u8], b: &[u8]) -> f64 { | |
| 225 | - a.iter() | |
| 226 | - .zip(b) | |
| 227 | - .map(|(&x, &y)| (f64::from(x) - f64::from(y)).abs()) | |
| 228 | - .sum::<f64>() | |
| 229 | - / a.len() as f64 | |
| 230 | -} | |
| 231 | - | |
| 232 | -fn main() { | |
| 233 | - let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument")); | |
| 234 | - let stream = dir.join("key.ivf"); | |
| 235 | - let reference = dir.join("av1_ref.yuv"); | |
| 236 | - let status = Command::new("ffmpeg") | |
| 237 | - .args(["-y", "-loglevel", "error", "-f", "lavfi", "-i"]) | |
| 238 | - .arg("testsrc2=size=320x240:rate=30") | |
| 239 | - .args(["-frames:v", "1", "-c:v", "libsvtav1", "-f", "ivf"]) | |
| 240 | - .arg(&stream) | |
| 241 | - .status() | |
| 242 | - .expect("run ffmpeg"); | |
| 243 | - assert!(status.success()); | |
| 244 | - let status = Command::new("ffmpeg") | |
| 245 | - .args(["-y", "-loglevel", "error", "-i"]) | |
| 246 | - .arg(&stream) | |
| 247 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) | |
| 248 | - .arg(&reference) | |
| 249 | - .status() | |
| 250 | - .expect("run ffmpeg"); | |
| 251 | - assert!(status.success()); | |
| 252 | - | |
| 253 | - let ivf = fs::read(&stream).expect("read ivf"); | |
| 254 | - let header_len = u16::from_le_bytes([ivf[6], ivf[7]]) as usize; | |
| 255 | - let frame_len = | |
| 256 | - u32::from_le_bytes(ivf[header_len..header_len + 4].try_into().unwrap()) as usize; | |
| 257 | - let data = &ivf[header_len + 12..header_len + 12 + frame_len]; | |
| 258 | - | |
| 259 | - let mut parser = Av1Parser::new(); | |
| 260 | - let obus = parser | |
| 261 | - .parse_temporal_unit(data) | |
| 262 | - .expect("parse temporal unit"); | |
| 263 | - let mut seq = None; | |
| 264 | - let mut frame_obu = None; | |
| 265 | - for obu in obus { | |
| 266 | - match obu.kind { | |
| 267 | - ObuKind::SequenceHeader(s) => seq = Some(*s), | |
| 268 | - ObuKind::Frame(h, tiles) => frame_obu = Some((*h, tiles)), | |
| 269 | - _ => {} | |
| 270 | - } | |
| 271 | - } | |
| 272 | - let seq = seq.expect("sequence header"); | |
| 273 | - let (header, tiles) = frame_obu.expect("frame OBU"); | |
| 274 | - assert_eq!(header.frame_type, FrameType::Key); | |
| 275 | - | |
| 276 | - let offsets: Vec<u32> = tiles.iter().map(|t| t.offset as u32).collect(); | |
| 277 | - let sizes: Vec<u32> = tiles.iter().map(|t| t.size as u32).collect(); | |
| 278 | - let plain_seq = sequence(&seq); | |
| 279 | - let plain_frame = frame(&header, &seq); | |
| 280 | - let (w, h) = (header.upscaled_width, header.frame_height); | |
| 281 | - | |
| 282 | - let gpu = Gpu::open().expect("open GPU"); | |
| 283 | - println!("device: {}", gpu.device_name()); | |
| 284 | - let cfg = Av1DecodeConfig { | |
| 285 | - max_width: w, | |
| 286 | - max_height: h, | |
| 287 | - max_dpb_slots: 9, | |
| 288 | - bit_depth: 8, | |
| 289 | - }; | |
| 290 | - let mut session = Av1DecodeSession::new(&gpu, &cfg).expect("decode session"); | |
| 291 | - session | |
| 292 | - .set_sequence_header(&plain_seq) | |
| 293 | - .expect("sequence header"); | |
| 294 | - let pic = Av1DecodePicture { | |
| 295 | - header: &plain_frame, | |
| 296 | - setup_slot: 0, | |
| 297 | - ref_frame_slot: [-1; 7], | |
| 298 | - refs: &[], | |
| 299 | - tile_data: data, | |
| 300 | - tile_offsets: &offsets, | |
| 301 | - tile_sizes: &sizes, | |
| 302 | - }; | |
| 303 | - session.decode(&pic).expect("decode"); | |
| 304 | - session.store_output(0, (0, 0, w, h)).expect("store"); | |
| 305 | - let (y, uv) = session.read_output(0, w, h).expect("read slot"); | |
| 306 | - | |
| 307 | - let reference = fs::read(&reference).expect("read reference"); | |
| 308 | - let luma = (w * h) as usize; | |
| 309 | - let chroma = luma / 4; | |
| 310 | - let ref_uv: Vec<u8> = reference[luma..luma + chroma] | |
| 311 | - .iter() | |
| 312 | - .zip(&reference[luma + chroma..luma + 2 * chroma]) | |
| 313 | - .flat_map(|(&u, &v)| [u, v]) | |
| 314 | - .collect(); | |
| 315 | - println!( | |
| 316 | - "mean abs diff Y: {:.6}", | |
| 317 | - mean_abs_diff(&y, &reference[..luma]) | |
| 318 | - ); | |
| 319 | - println!("mean abs diff UV: {:.6}", mean_abs_diff(&uv, &ref_uv)); | |
| 320 | -} |
shims/vk-video-ffi/examples/d3d11_pool.rsdeleted+0 -111
| @@ -1,111 +0,0 @@ | ||
| 1 | -#[cfg(windows)] | |
| 2 | -fn main() { | |
| 3 | - use std::os::windows::io::AsRawHandle; | |
| 4 | - | |
| 5 | - use vk_video_ffi::D3d11Pool; | |
| 6 | - use windows::Win32::Foundation::{HANDLE, HMODULE}; | |
| 7 | - use windows::Win32::Graphics::Direct3D::D3D_DRIVER_TYPE_WARP; | |
| 8 | - use windows::Win32::Graphics::Direct3D11::{ | |
| 9 | - D3D11_CPU_ACCESS_READ, D3D11_CREATE_DEVICE_BGRA_SUPPORT, D3D11_MAP_READ, | |
| 10 | - D3D11_MAPPED_SUBRESOURCE, D3D11_SDK_VERSION, D3D11_SUBRESOURCE_DATA, D3D11_TEXTURE2D_DESC, | |
| 11 | - D3D11_USAGE_DEFAULT, D3D11_USAGE_STAGING, D3D11CreateDevice, ID3D11Device, ID3D11Device1, | |
| 12 | - ID3D11Texture2D, | |
| 13 | - }; | |
| 14 | - use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_SAMPLE_DESC}; | |
| 15 | - use windows::core::Interface; | |
| 16 | - | |
| 17 | - let (w, h) = (256u32, 144u32); | |
| 18 | - let mut device: Option<ID3D11Device> = None; | |
| 19 | - unsafe { | |
| 20 | - D3D11CreateDevice( | |
| 21 | - None, | |
| 22 | - D3D_DRIVER_TYPE_WARP, | |
| 23 | - HMODULE::default(), | |
| 24 | - D3D11_CREATE_DEVICE_BGRA_SUPPORT, | |
| 25 | - None, | |
| 26 | - D3D11_SDK_VERSION, | |
| 27 | - Some(&mut device), | |
| 28 | - None, | |
| 29 | - None, | |
| 30 | - ) | |
| 31 | - .expect("WARP device"); | |
| 32 | - } | |
| 33 | - let device = device.expect("device"); | |
| 34 | - let context = unsafe { device.GetImmediateContext() }.expect("context"); | |
| 35 | - let desc = |usage, cpu: u32, bind: u32| D3D11_TEXTURE2D_DESC { | |
| 36 | - Width: w, | |
| 37 | - Height: h, | |
| 38 | - MipLevels: 1, | |
| 39 | - ArraySize: 1, | |
| 40 | - Format: DXGI_FORMAT_B8G8R8A8_UNORM, | |
| 41 | - SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, | |
| 42 | - Usage: usage, | |
| 43 | - BindFlags: bind, | |
| 44 | - CPUAccessFlags: cpu, | |
| 45 | - MiscFlags: 0, | |
| 46 | - }; | |
| 47 | - let mut pool = D3d11Pool::new(&device).expect("pool"); | |
| 48 | - let mut ids = Vec::new(); | |
| 49 | - for round in 0..6u32 { | |
| 50 | - let pixels: Vec<u8> = (0..w * h * 4).map(|i| (i * 7 + round * 13) as u8).collect(); | |
| 51 | - let init = D3D11_SUBRESOURCE_DATA { | |
| 52 | - pSysMem: pixels.as_ptr().cast(), | |
| 53 | - SysMemPitch: w * 4, | |
| 54 | - SysMemSlicePitch: 0, | |
| 55 | - }; | |
| 56 | - let mut src: Option<ID3D11Texture2D> = None; | |
| 57 | - unsafe { | |
| 58 | - device | |
| 59 | - .CreateTexture2D(&desc(D3D11_USAGE_DEFAULT, 0, 8), Some(&init), Some(&mut src)) | |
| 60 | - .expect("source texture"); | |
| 61 | - } | |
| 62 | - let src = src.expect("source"); | |
| 63 | - let frame = pool.submit(&src).expect("submit"); | |
| 64 | - ids.push(frame.id); | |
| 65 | - let dev1: ID3D11Device1 = device.cast().expect("ID3D11Device1"); | |
| 66 | - let opened: ID3D11Texture2D = | |
| 67 | - unsafe { dev1.OpenSharedResource1(HANDLE(frame.handle.as_raw_handle())) } | |
| 68 | - .expect("OpenSharedResource1"); | |
| 69 | - let mut staging: Option<ID3D11Texture2D> = None; | |
| 70 | - unsafe { | |
| 71 | - device | |
| 72 | - .CreateTexture2D( | |
| 73 | - &desc(D3D11_USAGE_STAGING, D3D11_CPU_ACCESS_READ.0 as u32, 0), | |
| 74 | - None, | |
| 75 | - Some(&mut staging), | |
| 76 | - ) | |
| 77 | - .expect("staging"); | |
| 78 | - } | |
| 79 | - let staging = staging.expect("staging"); | |
| 80 | - let mut got = vec![0u8; pixels.len()]; | |
| 81 | - unsafe { | |
| 82 | - context.CopyResource(&staging, &opened); | |
| 83 | - let mut map = D3D11_MAPPED_SUBRESOURCE::default(); | |
| 84 | - context.Map(&staging, 0, D3D11_MAP_READ, 0, Some(&mut map)).expect("map"); | |
| 85 | - for y in 0..h as usize { | |
| 86 | - let row = std::slice::from_raw_parts( | |
| 87 | - map.pData.cast::<u8>().add(y * map.RowPitch as usize), | |
| 88 | - w as usize * 4, | |
| 89 | - ); | |
| 90 | - got[y * w as usize * 4..][..w as usize * 4].copy_from_slice(row); | |
| 91 | - } | |
| 92 | - context.Unmap(&staging, 0); | |
| 93 | - } | |
| 94 | - println!( | |
| 95 | - "round {round} id {} {}x{} bgr {} {}", | |
| 96 | - frame.id, | |
| 97 | - frame.width, | |
| 98 | - frame.height, | |
| 99 | - frame.bgr, | |
| 100 | - if got == pixels { "identical" } else { "DIFFERS" } | |
| 101 | - ); | |
| 102 | - } | |
| 103 | - println!("ids {ids:?}"); | |
| 104 | - match vk_video_ffi::Gpu::open() { | |
| 105 | - Ok(gpu) => println!("vulkan: importable bgr {}", vk_video_ffi::d3d11_importable(&gpu, true)), | |
| 106 | - Err(e) => println!("vulkan: {e}"), | |
| 107 | - } | |
| 108 | -} | |
| 109 | - | |
| 110 | -#[cfg(not(windows))] | |
| 111 | -fn main() {} |
shims/vk-video-ffi/examples/dmabuf_smoke.rsdeleted+0 -767
| @@ -1,767 +0,0 @@ | ||
| 1 | -use std::os::fd::{AsFd, AsRawFd, FromRawFd, OwnedFd}; | |
| 2 | - | |
| 3 | -use vk_video_ffi::{ | |
| 4 | - Av1EncodeConfig, Av1EncodeSession, Av1Picture, Av1Ref, DmaBuf, DmaBufFormat, DmaBufPlane, | |
| 5 | - Error, Gpu, H264EncodeConfig, H264EncodeSession, H264Picture, H264Ref, H265EncodeConfig, | |
| 6 | - H265EncodeSession, H265Picture, H265Ref, H264Profile, RateControl, | |
| 7 | -}; | |
| 8 | -use vulkanalia::prelude::v1_3::*; | |
| 9 | -use vulkanalia::vk::KhrExternalMemoryFdExtensionDeviceCommands; | |
| 10 | - | |
| 11 | -const W: u32 = 1280; | |
| 12 | -const H: u32 = 720; | |
| 13 | -const FRAMES: usize = 10; | |
| 14 | -const FPS: (u32, u32) = (30, 1); | |
| 15 | -const RATE: RateControl = RateControl::ConstantQp { qp: 28 }; | |
| 16 | -const FORMAT: vk::Format = vk::Format::B8G8R8A8_UNORM; | |
| 17 | -const NV12: vk::Format = vk::Format::G8_B8R8_2PLANE_420_UNORM; | |
| 18 | -const P010: vk::Format = vk::Format::G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16; | |
| 19 | - | |
| 20 | -struct Export { | |
| 21 | - image: vk::Image, | |
| 22 | - memory: vk::DeviceMemory, | |
| 23 | - fd: OwnedFd, | |
| 24 | - modifier: u64, | |
| 25 | - planes: Vec<DmaBufPlane>, | |
| 26 | -} | |
| 27 | - | |
| 28 | -impl Export { | |
| 29 | - fn destroy(&self, d: &Device) { | |
| 30 | - unsafe { | |
| 31 | - d.destroy_image(self.image, None); | |
| 32 | - d.free_memory(self.memory, None); | |
| 33 | - } | |
| 34 | - } | |
| 35 | -} | |
| 36 | - | |
| 37 | -struct Pattern { | |
| 38 | - bits: u8, | |
| 39 | - y: Vec<u16>, | |
| 40 | - uv: Vec<u16>, | |
| 41 | -} | |
| 42 | - | |
| 43 | -impl Pattern { | |
| 44 | - fn new(bits: u8) -> Self { | |
| 45 | - let max = (1u32 << bits) - 1; | |
| 46 | - let y = (0..W * H) | |
| 47 | - .map(|i| { | |
| 48 | - let (x, row) = (i % W, i / W); | |
| 49 | - ((x * max / (W - 1) + row * max / (H - 1)) / 2) as u16 | |
| 50 | - }) | |
| 51 | - .collect(); | |
| 52 | - let uv = (0..W * H / 2) | |
| 53 | - .map(|i| ((i * 7) % (max + 1)) as u16) | |
| 54 | - .collect(); | |
| 55 | - Pattern { bits, y, uv } | |
| 56 | - } | |
| 57 | - | |
| 58 | - fn y8(&self) -> Vec<u8> { | |
| 59 | - self.y.iter().map(|&v| v as u8).collect() | |
| 60 | - } | |
| 61 | - | |
| 62 | - fn uv8(&self) -> Vec<u8> { | |
| 63 | - self.uv.iter().map(|&v| v as u8).collect() | |
| 64 | - } | |
| 65 | - | |
| 66 | - fn device(&self) -> Vec<u8> { | |
| 67 | - let samples = self.y.iter().chain(&self.uv); | |
| 68 | - if self.bits == 8 { | |
| 69 | - samples.map(|&v| v as u8).collect() | |
| 70 | - } else { | |
| 71 | - samples.flat_map(|&v| (v << 6).to_le_bytes()).collect() | |
| 72 | - } | |
| 73 | - } | |
| 74 | -} | |
| 75 | - | |
| 76 | -trait Encode: Sized { | |
| 77 | - fn open(gpu: &Gpu, size: (u32, u32), bits: u8) -> Result<Self, Error>; | |
| 78 | - fn rgb(&mut self, host: &[u8], frame: usize) -> Result<Vec<u8>, Error>; | |
| 79 | - fn planar(&mut self, pattern: &Pattern, frame: usize) -> Result<Vec<u8>, Error>; | |
| 80 | - fn dma(&mut self, src: &DmaBuf, frame: usize) -> Result<Vec<u8>, Error>; | |
| 81 | -} | |
| 82 | - | |
| 83 | -impl Encode for H264EncodeSession { | |
| 84 | - fn open(gpu: &Gpu, size: (u32, u32), _bits: u8) -> Result<Self, Error> { | |
| 85 | - let cfg = H264EncodeConfig { | |
| 86 | - width: size.0, | |
| 87 | - height: size.1, | |
| 88 | - fps: FPS, | |
| 89 | - rate: RATE, | |
| 90 | - profile: H264Profile::High, | |
| 91 | - level: 62, | |
| 92 | - colour: None, | |
| 93 | - quality: 0, | |
| 94 | - }; | |
| 95 | - H264EncodeSession::new(gpu, &cfg) | |
| 96 | - } | |
| 97 | - | |
| 98 | - fn rgb(&mut self, host: &[u8], i: usize) -> Result<Vec<u8>, Error> { | |
| 99 | - let pic = h264_picture(i); | |
| 100 | - self.encode_rgb(host, W, H, W * 4, true, &pic) | |
| 101 | - } | |
| 102 | - | |
| 103 | - fn planar(&mut self, pattern: &Pattern, i: usize) -> Result<Vec<u8>, Error> { | |
| 104 | - self.encode(&pattern.y8(), &pattern.uv8(), &h264_picture(i)) | |
| 105 | - } | |
| 106 | - | |
| 107 | - fn dma(&mut self, src: &DmaBuf, i: usize) -> Result<Vec<u8>, Error> { | |
| 108 | - self.encode_dmabuf(src, &h264_picture(i)) | |
| 109 | - } | |
| 110 | -} | |
| 111 | - | |
| 112 | -fn h264_picture(i: usize) -> H264Picture { | |
| 113 | - H264Picture { | |
| 114 | - idr: i == 0, | |
| 115 | - idr_pic_id: 0, | |
| 116 | - frame_num: i as u32, | |
| 117 | - poc: 2 * i as i32, | |
| 118 | - slot: (i % 2) as u32, | |
| 119 | - reference: (i > 0).then(|| H264Ref { | |
| 120 | - slot: ((i - 1) % 2) as u32, | |
| 121 | - frame_num: (i - 1) as u32, | |
| 122 | - poc: 2 * (i - 1) as i32, | |
| 123 | - }), | |
| 124 | - } | |
| 125 | -} | |
| 126 | - | |
| 127 | -impl Encode for H265EncodeSession { | |
| 128 | - fn open(gpu: &Gpu, size: (u32, u32), bits: u8) -> Result<Self, Error> { | |
| 129 | - let cfg = H265EncodeConfig { | |
| 130 | - width: size.0, | |
| 131 | - height: size.1, | |
| 132 | - fps: FPS, | |
| 133 | - rate: RATE, | |
| 134 | - bit_depth: bits, | |
| 135 | - level: 186, | |
| 136 | - colour: None, | |
| 137 | - quality: 0, | |
| 138 | - }; | |
| 139 | - H265EncodeSession::new(gpu, &cfg) | |
| 140 | - } | |
| 141 | - | |
| 142 | - fn rgb(&mut self, host: &[u8], i: usize) -> Result<Vec<u8>, Error> { | |
| 143 | - let pic = h265_picture(i); | |
| 144 | - self.encode_rgb(host, W, H, W * 4, true, &pic) | |
| 145 | - } | |
| 146 | - | |
| 147 | - fn planar(&mut self, p: &Pattern, i: usize) -> Result<Vec<u8>, Error> { | |
| 148 | - let pic = h265_picture(i); | |
| 149 | - if p.bits == 8 { | |
| 150 | - self.encode(&p.y8(), &p.uv8(), &pic) | |
| 151 | - } else { | |
| 152 | - self.encode_16(&p.y, &p.uv, &pic) | |
| 153 | - } | |
| 154 | - } | |
| 155 | - | |
| 156 | - fn dma(&mut self, src: &DmaBuf, i: usize) -> Result<Vec<u8>, Error> { | |
| 157 | - self.encode_dmabuf(src, &h265_picture(i)) | |
| 158 | - } | |
| 159 | -} | |
| 160 | - | |
| 161 | -fn h265_picture(i: usize) -> H265Picture { | |
| 162 | - H265Picture { | |
| 163 | - idr: i == 0, | |
| 164 | - poc: 2 * i as i32, | |
| 165 | - slot: (i % 2) as u32, | |
| 166 | - reference: (i > 0).then(|| H265Ref { | |
| 167 | - slot: ((i - 1) % 2) as u32, | |
| 168 | - poc: 2 * (i - 1) as i32, | |
| 169 | - }), | |
| 170 | - keep: [None; vk_video_ffi::DPB_SLOTS], | |
| 171 | - } | |
| 172 | -} | |
| 173 | - | |
| 174 | -impl Encode for Av1EncodeSession { | |
| 175 | - fn open(gpu: &Gpu, size: (u32, u32), bits: u8) -> Result<Self, Error> { | |
| 176 | - let cfg = Av1EncodeConfig { | |
| 177 | - width: size.0, | |
| 178 | - height: size.1, | |
| 179 | - fps: FPS, | |
| 180 | - rate: RATE, | |
| 181 | - bit_depth: bits, | |
| 182 | - level: 23, | |
| 183 | - colour: None, | |
| 184 | - quality: 0, | |
| 185 | - }; | |
| 186 | - Av1EncodeSession::new(gpu, &cfg) | |
| 187 | - } | |
| 188 | - | |
| 189 | - fn rgb(&mut self, host: &[u8], i: usize) -> Result<Vec<u8>, Error> { | |
| 190 | - let pic = av1_picture(i); | |
| 191 | - self.encode_rgb(host, W, H, W * 4, true, &pic) | |
| 192 | - } | |
| 193 | - | |
| 194 | - fn planar(&mut self, p: &Pattern, i: usize) -> Result<Vec<u8>, Error> { | |
| 195 | - let pic = av1_picture(i); | |
| 196 | - if p.bits == 8 { | |
| 197 | - self.encode(&p.y8(), &p.uv8(), &pic) | |
| 198 | - } else { | |
| 199 | - self.encode_16(&p.y, &p.uv, &pic) | |
| 200 | - } | |
| 201 | - } | |
| 202 | - | |
| 203 | - fn dma(&mut self, src: &DmaBuf, i: usize) -> Result<Vec<u8>, Error> { | |
| 204 | - self.encode_dmabuf(src, &av1_picture(i)) | |
| 205 | - } | |
| 206 | -} | |
| 207 | - | |
| 208 | -fn av1_picture(i: usize) -> Av1Picture { | |
| 209 | - Av1Picture { | |
| 210 | - key: i == 0, | |
| 211 | - order_hint: i as u8, | |
| 212 | - slot: (i % 2) as u32, | |
| 213 | - reference: (i > 0).then(|| Av1Ref { | |
| 214 | - slot: ((i - 1) % 2) as u32, | |
| 215 | - order_hint: (i - 1) as u8, | |
| 216 | - }), | |
| 217 | - } | |
| 218 | -} | |
| 219 | - | |
| 220 | -fn gradient() -> Vec<u8> { | |
| 221 | - let mut out = Vec::with_capacity((W * H * 4) as usize); | |
| 222 | - for y in 0..H { | |
| 223 | - for x in 0..W { | |
| 224 | - out.extend([ | |
| 225 | - (x * 255 / (W - 1)) as u8, | |
| 226 | - (y * 255 / (H - 1)) as u8, | |
| 227 | - (x ^ y) as u8, | |
| 228 | - 255, | |
| 229 | - ]); | |
| 230 | - } | |
| 231 | - } | |
| 232 | - out | |
| 233 | -} | |
| 234 | - | |
| 235 | -fn memory_index( | |
| 236 | - instance: &Instance, | |
| 237 | - physical: vk::PhysicalDevice, | |
| 238 | - bits: u32, | |
| 239 | - flags: vk::MemoryPropertyFlags, | |
| 240 | -) -> u32 { | |
| 241 | - let props = unsafe { instance.get_physical_device_memory_properties(physical) }; | |
| 242 | - (0..props.memory_type_count) | |
| 243 | - .find(|&i| { | |
| 244 | - bits & (1 << i) != 0 | |
| 245 | - && props.memory_types[i as usize] | |
| 246 | - .property_flags | |
| 247 | - .contains(flags) | |
| 248 | - }) | |
| 249 | - .expect("memory type") | |
| 250 | -} | |
| 251 | - | |
| 252 | -fn pick_modifier( | |
| 253 | - instance: &Instance, | |
| 254 | - physical: vk::PhysicalDevice, | |
| 255 | - format: vk::Format, | |
| 256 | - planes: u32, | |
| 257 | -) -> Option<u64> { | |
| 258 | - let mut list = vk::DrmFormatModifierPropertiesListEXT::builder().build(); | |
| 259 | - let mut props = vk::FormatProperties2::builder() | |
| 260 | - .push_next(&mut list) | |
| 261 | - .build(); | |
| 262 | - unsafe { instance.get_physical_device_format_properties2(physical, format, &mut props) }; | |
| 263 | - let count = list.drm_format_modifier_count as usize; | |
| 264 | - | |
| 265 | - let mut entries: Vec<vk::DrmFormatModifierPropertiesEXT> = (0..count) | |
| 266 | - .map(|_| vk::DrmFormatModifierPropertiesEXT::builder().build()) | |
| 267 | - .collect(); | |
| 268 | - let mut list = vk::DrmFormatModifierPropertiesListEXT::builder() | |
| 269 | - .drm_format_modifier_properties(&mut entries) | |
| 270 | - .build(); | |
| 271 | - let mut props = vk::FormatProperties2::builder() | |
| 272 | - .push_next(&mut list) | |
| 273 | - .build(); | |
| 274 | - unsafe { instance.get_physical_device_format_properties2(physical, format, &mut props) }; | |
| 275 | - | |
| 276 | - let want = vk::FormatFeatureFlags::TRANSFER_SRC | vk::FormatFeatureFlags::TRANSFER_DST; | |
| 277 | - entries | |
| 278 | - .iter() | |
| 279 | - .find(|e| { | |
| 280 | - e.drm_format_modifier != 0 | |
| 281 | - && e.drm_format_modifier_plane_count == planes | |
| 282 | - && e.drm_format_modifier_tiling_features.contains(want) | |
| 283 | - }) | |
| 284 | - .map(|e| e.drm_format_modifier) | |
| 285 | -} | |
| 286 | - | |
| 287 | -fn export( | |
| 288 | - instance: &Instance, | |
| 289 | - physical: vk::PhysicalDevice, | |
| 290 | - d: &Device, | |
| 291 | - queue: vk::Queue, | |
| 292 | - family: u32, | |
| 293 | - format: vk::Format, | |
| 294 | - modifier: u64, | |
| 295 | - host: &[u8], | |
| 296 | - regions: &[(vk::ImageAspectFlags, u64, u32, u32)], | |
| 297 | - memory_planes: usize, | |
| 298 | -) -> Export { | |
| 299 | - let modifiers = [modifier]; | |
| 300 | - let mut list = vk::ImageDrmFormatModifierListCreateInfoEXT::builder() | |
| 301 | - .drm_format_modifiers(&modifiers) | |
| 302 | - .build(); | |
| 303 | - let mut external = vk::ExternalMemoryImageCreateInfo::builder() | |
| 304 | - .handle_types(vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) | |
| 305 | - .build(); | |
| 306 | - let info = vk::ImageCreateInfo::builder() | |
| 307 | - .image_type(vk::ImageType::_2D) | |
| 308 | - .format(format) | |
| 309 | - .extent(vk::Extent3D { | |
| 310 | - width: W, | |
| 311 | - height: H, | |
| 312 | - depth: 1, | |
| 313 | - }) | |
| 314 | - .mip_levels(1) | |
| 315 | - .array_layers(1) | |
| 316 | - .samples(vk::SampleCountFlags::_1) | |
| 317 | - .tiling(vk::ImageTiling::DRM_FORMAT_MODIFIER_EXT) | |
| 318 | - .usage(vk::ImageUsageFlags::TRANSFER_SRC | vk::ImageUsageFlags::TRANSFER_DST) | |
| 319 | - .sharing_mode(vk::SharingMode::EXCLUSIVE) | |
| 320 | - .initial_layout(vk::ImageLayout::UNDEFINED) | |
| 321 | - .push_next(&mut external) | |
| 322 | - .push_next(&mut list) | |
| 323 | - .build(); | |
| 324 | - let image = unsafe { d.create_image(&info, None) }.expect("export image"); | |
| 325 | - | |
| 326 | - let req = unsafe { d.get_image_memory_requirements(image) }; | |
| 327 | - let index = memory_index( | |
| 328 | - instance, | |
| 329 | - physical, | |
| 330 | - req.memory_type_bits, | |
| 331 | - vk::MemoryPropertyFlags::DEVICE_LOCAL, | |
| 332 | - ); | |
| 333 | - let mut export_info = vk::ExportMemoryAllocateInfo::builder() | |
| 334 | - .handle_types(vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) | |
| 335 | - .build(); | |
| 336 | - let mut dedicated = vk::MemoryDedicatedAllocateInfo::builder() | |
| 337 | - .image(image) | |
| 338 | - .build(); | |
| 339 | - let alloc = vk::MemoryAllocateInfo::builder() | |
| 340 | - .allocation_size(req.size) | |
| 341 | - .memory_type_index(index) | |
| 342 | - .push_next(&mut dedicated) | |
| 343 | - .push_next(&mut export_info) | |
| 344 | - .build(); | |
| 345 | - let memory = unsafe { d.allocate_memory(&alloc, None) }.expect("export memory"); | |
| 346 | - unsafe { d.bind_image_memory(image, memory, 0) }.expect("bind export memory"); | |
| 347 | - | |
| 348 | - let fd_info = vk::MemoryGetFdInfoKHR::builder() | |
| 349 | - .memory(memory) | |
| 350 | - .handle_type(vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) | |
| 351 | - .build(); | |
| 352 | - let fd = unsafe { d.get_memory_fd_khr(&fd_info) }.expect("export fd"); | |
| 353 | - let fd = unsafe { OwnedFd::from_raw_fd(fd) }; | |
| 354 | - let memory_aspects = [ | |
| 355 | - vk::ImageAspectFlags::MEMORY_PLANE_0_EXT, | |
| 356 | - vk::ImageAspectFlags::MEMORY_PLANE_1_EXT, | |
| 357 | - ]; | |
| 358 | - let planes = memory_aspects[..memory_planes] | |
| 359 | - .iter() | |
| 360 | - .map(|&aspect_mask| { | |
| 361 | - let sub = vk::ImageSubresource { | |
| 362 | - aspect_mask, | |
| 363 | - mip_level: 0, | |
| 364 | - array_layer: 0, | |
| 365 | - }; | |
| 366 | - let layout = unsafe { d.get_image_subresource_layout(image, &sub) }; | |
| 367 | - DmaBufPlane { | |
| 368 | - fd: 0, | |
| 369 | - offset: layout.offset as u32, | |
| 370 | - pitch: layout.row_pitch as u32, | |
| 371 | - } | |
| 372 | - }) | |
| 373 | - .collect(); | |
| 374 | - | |
| 375 | - let bytes = host.len() as u64; | |
| 376 | - let buf_info = vk::BufferCreateInfo::builder() | |
| 377 | - .size(bytes) | |
| 378 | - .usage(vk::BufferUsageFlags::TRANSFER_SRC) | |
| 379 | - .sharing_mode(vk::SharingMode::EXCLUSIVE); | |
| 380 | - let staging = unsafe { d.create_buffer(&buf_info, None) }.expect("staging buffer"); | |
| 381 | - let breq = unsafe { d.get_buffer_memory_requirements(staging) }; | |
| 382 | - let bindex = memory_index( | |
| 383 | - instance, | |
| 384 | - physical, | |
| 385 | - breq.memory_type_bits, | |
| 386 | - vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT, | |
| 387 | - ); | |
| 388 | - let balloc = vk::MemoryAllocateInfo::builder() | |
| 389 | - .allocation_size(breq.size) | |
| 390 | - .memory_type_index(bindex) | |
| 391 | - .build(); | |
| 392 | - let bmem = unsafe { d.allocate_memory(&balloc, None) }.expect("staging memory"); | |
| 393 | - unsafe { | |
| 394 | - d.bind_buffer_memory(staging, bmem, 0) | |
| 395 | - .expect("bind staging"); | |
| 396 | - let ptr = d | |
| 397 | - .map_memory(bmem, 0, bytes, vk::MemoryMapFlags::empty()) | |
| 398 | - .expect("map staging") as *mut u8; | |
| 399 | - std::ptr::copy_nonoverlapping(host.as_ptr(), ptr, host.len()); | |
| 400 | - d.unmap_memory(bmem); | |
| 401 | - } | |
| 402 | - | |
| 403 | - let pool_info = vk::CommandPoolCreateInfo::builder().queue_family_index(family); | |
| 404 | - let pool = unsafe { d.create_command_pool(&pool_info, None) }.expect("pool"); | |
| 405 | - let alloc = vk::CommandBufferAllocateInfo::builder() | |
| 406 | - .command_pool(pool) | |
| 407 | - .level(vk::CommandBufferLevel::PRIMARY) | |
| 408 | - .command_buffer_count(1); | |
| 409 | - let cb = unsafe { d.allocate_command_buffers(&alloc) }.expect("command buffer")[0]; | |
| 410 | - let to_dst: Vec<vk::ImageMemoryBarrier> = regions | |
| 411 | - .iter() | |
| 412 | - .map(|&(aspect, ..)| { | |
| 413 | - vk::ImageMemoryBarrier::builder() | |
| 414 | - .old_layout(vk::ImageLayout::UNDEFINED) | |
| 415 | - .new_layout(vk::ImageLayout::TRANSFER_DST_OPTIMAL) | |
| 416 | - .src_access_mask(vk::AccessFlags::empty()) | |
| 417 | - .dst_access_mask(vk::AccessFlags::TRANSFER_WRITE) | |
| 418 | - .image(image) | |
| 419 | - .subresource_range(vk::ImageSubresourceRange { | |
| 420 | - aspect_mask: aspect, | |
| 421 | - base_mip_level: 0, | |
| 422 | - level_count: 1, | |
| 423 | - base_array_layer: 0, | |
| 424 | - layer_count: 1, | |
| 425 | - }) | |
| 426 | - .build() | |
| 427 | - }) | |
| 428 | - .collect(); | |
| 429 | - let copies: Vec<vk::BufferImageCopy> = regions | |
| 430 | - .iter() | |
| 431 | - .map(|&(aspect, offset, width, height)| { | |
| 432 | - vk::BufferImageCopy::builder() | |
| 433 | - .buffer_offset(offset) | |
| 434 | - .image_subresource(vk::ImageSubresourceLayers { | |
| 435 | - aspect_mask: aspect, | |
| 436 | - mip_level: 0, | |
| 437 | - base_array_layer: 0, | |
| 438 | - layer_count: 1, | |
| 439 | - }) | |
| 440 | - .image_extent(vk::Extent3D { | |
| 441 | - width, | |
| 442 | - height, | |
| 443 | - depth: 1, | |
| 444 | - }) | |
| 445 | - .build() | |
| 446 | - }) | |
| 447 | - .collect(); | |
| 448 | - let begin = | |
| 449 | - vk::CommandBufferBeginInfo::builder().flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT); | |
| 450 | - unsafe { | |
| 451 | - d.begin_command_buffer(cb, &begin).expect("begin"); | |
| 452 | - d.cmd_pipeline_barrier( | |
| 453 | - cb, | |
| 454 | - vk::PipelineStageFlags::TOP_OF_PIPE, | |
| 455 | - vk::PipelineStageFlags::TRANSFER, | |
| 456 | - vk::DependencyFlags::empty(), | |
| 457 | - &[] as &[vk::MemoryBarrier], | |
| 458 | - &[] as &[vk::BufferMemoryBarrier], | |
| 459 | - &to_dst, | |
| 460 | - ); | |
| 461 | - d.cmd_copy_buffer_to_image( | |
| 462 | - cb, | |
| 463 | - staging, | |
| 464 | - image, | |
| 465 | - vk::ImageLayout::TRANSFER_DST_OPTIMAL, | |
| 466 | - &copies, | |
| 467 | - ); | |
| 468 | - d.end_command_buffer(cb).expect("end"); | |
| 469 | - let cbs = [cb]; | |
| 470 | - let submit = vk::SubmitInfo::builder().command_buffers(&cbs).build(); | |
| 471 | - d.queue_submit(queue, &[submit], vk::Fence::null()) | |
| 472 | - .expect("submit"); | |
| 473 | - d.queue_wait_idle(queue).expect("wait"); | |
| 474 | - d.destroy_command_pool(pool, None); | |
| 475 | - d.destroy_buffer(staging, None); | |
| 476 | - d.free_memory(bmem, None); | |
| 477 | - } | |
| 478 | - | |
| 479 | - Export { | |
| 480 | - image, | |
| 481 | - memory, | |
| 482 | - fd, | |
| 483 | - modifier, | |
| 484 | - planes, | |
| 485 | - } | |
| 486 | -} | |
| 487 | - | |
| 488 | -fn export_planar( | |
| 489 | - instance: &Instance, | |
| 490 | - physical: vk::PhysicalDevice, | |
| 491 | - d: &Device, | |
| 492 | - queue: vk::Queue, | |
| 493 | - family: u32, | |
| 494 | - format: vk::Format, | |
| 495 | - modifier: u64, | |
| 496 | - pattern: &Pattern, | |
| 497 | -) -> Export { | |
| 498 | - let bps = if pattern.bits == 8 { 1 } else { 2 }; | |
| 499 | - let luma = (W * H * bps) as u64; | |
| 500 | - let regions = [ | |
| 501 | - (vk::ImageAspectFlags::PLANE_0, 0, W, H), | |
| 502 | - (vk::ImageAspectFlags::PLANE_1, luma, W / 2, H / 2), | |
| 503 | - ]; | |
| 504 | - export( | |
| 505 | - instance, | |
| 506 | - physical, | |
| 507 | - d, | |
| 508 | - queue, | |
| 509 | - family, | |
| 510 | - format, | |
| 511 | - modifier, | |
| 512 | - &pattern.device(), | |
| 513 | - ®ions, | |
| 514 | - 2, | |
| 515 | - ) | |
| 516 | -} | |
| 517 | - | |
| 518 | -fn run<S: Encode>(gpu: &Gpu, name: &str, host: &[u8], linear: &Export, tiled: &Export) { | |
| 519 | - let modifiers = vk_video_ffi::rgb_import_modifiers(gpu, true); | |
| 520 | - println!( | |
| 521 | - "{name} bgrx import modifiers {modifiers:x?}, linear {} tiled {}", | |
| 522 | - modifiers.contains(&linear.modifier), | |
| 523 | - modifiers.contains(&tiled.modifier) | |
| 524 | - ); | |
| 525 | - let cases = [(linear, (W, H)), (tiled, (W, H)), (linear, (W / 2, H / 2))]; | |
| 526 | - for (export, size) in cases { | |
| 527 | - let mut a = S::open(gpu, size, 8).expect("encoder"); | |
| 528 | - let mut b = S::open(gpu, size, 8).expect("encoder"); | |
| 529 | - let owned = vk_video_ffi::dup_raw_fd(export.fd.as_raw_fd()).expect("dup"); | |
| 530 | - let fds = [owned.as_fd()]; | |
| 531 | - let src = DmaBuf { | |
| 532 | - fds: &fds, | |
| 533 | - planes: &export.planes, | |
| 534 | - width: W, | |
| 535 | - height: H, | |
| 536 | - modifier: export.modifier, | |
| 537 | - format: DmaBufFormat::Bgrx, | |
| 538 | - }; | |
| 539 | - let mut left = Vec::new(); | |
| 540 | - let mut right = Vec::new(); | |
| 541 | - for i in 0..FRAMES { | |
| 542 | - left.extend(a.rgb(host, i).expect("encode_rgb")); | |
| 543 | - right.extend(b.dma(&src, i).expect("encode_dmabuf")); | |
| 544 | - } | |
| 545 | - let verdict = if left == right { | |
| 546 | - "identical" | |
| 547 | - } else { | |
| 548 | - "DIFFERENT" | |
| 549 | - }; | |
| 550 | - println!( | |
| 551 | - "{name} {:#x} {}x{} {verdict}", | |
| 552 | - export.modifier, size.0, size.1 | |
| 553 | - ); | |
| 554 | - } | |
| 555 | -} | |
| 556 | - | |
| 557 | -fn planar_format(pattern: &Pattern) -> DmaBufFormat { | |
| 558 | - if pattern.bits == 8 { | |
| 559 | - DmaBufFormat::Nv12 | |
| 560 | - } else { | |
| 561 | - DmaBufFormat::P010 | |
| 562 | - } | |
| 563 | -} | |
| 564 | - | |
| 565 | -fn split_planes(a: &Export, b: &Export) -> [DmaBufPlane; 2] { | |
| 566 | - [ | |
| 567 | - DmaBufPlane { fd: 0, ..a.planes[0] }, | |
| 568 | - DmaBufPlane { fd: 1, ..b.planes[1] }, | |
| 569 | - ] | |
| 570 | -} | |
| 571 | - | |
| 572 | -fn run_split<S: Encode>(gpu: &Gpu, name: &str, pattern: &Pattern, pairs: &[(Export, Export)]) { | |
| 573 | - let format = planar_format(pattern); | |
| 574 | - for (a_export, b_export) in pairs { | |
| 575 | - let mut a = S::open(gpu, (W, H), pattern.bits).expect("encoder"); | |
| 576 | - let mut b = S::open(gpu, (W, H), pattern.bits).expect("encoder"); | |
| 577 | - let fds = [a_export.fd.as_fd(), b_export.fd.as_fd()]; | |
| 578 | - let planes = split_planes(a_export, b_export); | |
| 579 | - let src = DmaBuf { | |
| 580 | - fds: &fds, | |
| 581 | - planes: &planes, | |
| 582 | - width: W, | |
| 583 | - height: H, | |
| 584 | - modifier: a_export.modifier, | |
| 585 | - format, | |
| 586 | - }; | |
| 587 | - let mut left = Vec::new(); | |
| 588 | - let mut right = Vec::new(); | |
| 589 | - for i in 0..FRAMES { | |
| 590 | - left.extend(a.planar(pattern, i).expect("encode")); | |
| 591 | - right.extend(b.dma(&src, i).expect("encode_dmabuf")); | |
| 592 | - } | |
| 593 | - let verdict = if left == right { | |
| 594 | - "identical" | |
| 595 | - } else { | |
| 596 | - "DIFFERENT" | |
| 597 | - }; | |
| 598 | - println!("{name} split {:#x} {W}x{H} {verdict}", a_export.modifier); | |
| 599 | - } | |
| 600 | -} | |
| 601 | - | |
| 602 | -fn run_planar<S: Encode>(gpu: &Gpu, name: &str, pattern: &Pattern, exports: &[&Export]) { | |
| 603 | - let format = planar_format(pattern); | |
| 604 | - for export in exports { | |
| 605 | - let mut a = S::open(gpu, (W, H), pattern.bits).expect("encoder"); | |
| 606 | - let mut b = S::open(gpu, (W, H), pattern.bits).expect("encoder"); | |
| 607 | - let fds = [export.fd.as_fd()]; | |
| 608 | - let src = DmaBuf { | |
| 609 | - fds: &fds, | |
| 610 | - planes: &export.planes, | |
| 611 | - width: W, | |
| 612 | - height: H, | |
| 613 | - modifier: export.modifier, | |
| 614 | - format, | |
| 615 | - }; | |
| 616 | - let mut left = Vec::new(); | |
| 617 | - let mut right = Vec::new(); | |
| 618 | - for i in 0..FRAMES { | |
| 619 | - left.extend(a.planar(pattern, i).expect("encode")); | |
| 620 | - right.extend(b.dma(&src, i).expect("encode_dmabuf")); | |
| 621 | - } | |
| 622 | - let verdict = if left == right { | |
| 623 | - "identical" | |
| 624 | - } else { | |
| 625 | - "DIFFERENT" | |
| 626 | - }; | |
| 627 | - println!("{name} {:#x} {W}x{H} {verdict}", export.modifier); | |
| 628 | - } | |
| 629 | -} | |
| 630 | - | |
| 631 | -fn main() { | |
| 632 | - let gpu = Gpu::open().expect("open GPU"); | |
| 633 | - let (instance, physical, d) = gpu.vulkan(); | |
| 634 | - let family = unsafe { instance.get_physical_device_queue_family_properties(physical) } | |
| 635 | - .iter() | |
| 636 | - .position(|f| f.queue_flags.contains(vk::QueueFlags::GRAPHICS)) | |
| 637 | - .expect("graphics family") as u32; | |
| 638 | - let queue = unsafe { d.get_device_queue(family, 0) }; | |
| 639 | - let host = gradient(); | |
| 640 | - let rgb_regions = [(vk::ImageAspectFlags::COLOR, 0, W, H)]; | |
| 641 | - let linear = export( | |
| 642 | - instance, | |
| 643 | - physical, | |
| 644 | - d, | |
| 645 | - queue, | |
| 646 | - family, | |
| 647 | - FORMAT, | |
| 648 | - 0, | |
| 649 | - &host, | |
| 650 | - &rgb_regions, | |
| 651 | - 1, | |
| 652 | - ); | |
| 653 | - let modifier = | |
| 654 | - pick_modifier(instance, physical, FORMAT, 1).expect("tiled single-plane modifier"); | |
| 655 | - let tiled = export( | |
| 656 | - instance, | |
| 657 | - physical, | |
| 658 | - d, | |
| 659 | - queue, | |
| 660 | - family, | |
| 661 | - FORMAT, | |
| 662 | - modifier, | |
| 663 | - &host, | |
| 664 | - &rgb_regions, | |
| 665 | - 1, | |
| 666 | - ); | |
| 667 | - run::<H264EncodeSession>(&gpu, "h264", &host, &linear, &tiled); | |
| 668 | - run::<H265EncodeSession>(&gpu, "h265", &host, &linear, &tiled); | |
| 669 | - run::<Av1EncodeSession>(&gpu, "av1", &host, &linear, &tiled); | |
| 670 | - | |
| 671 | - let nv12 = Pattern::new(8); | |
| 672 | - let p010 = Pattern::new(10); | |
| 673 | - let mut exports = vec![linear, tiled]; | |
| 674 | - let nv12_linear = export_planar(instance, physical, d, queue, family, NV12, 0, &nv12); | |
| 675 | - let nv12_tiled = pick_modifier(instance, physical, NV12, 2) | |
| 676 | - .map(|m| export_planar(instance, physical, d, queue, family, NV12, m, &nv12)); | |
| 677 | - let p010_linear = export_planar(instance, physical, d, queue, family, P010, 0, &p010); | |
| 678 | - let p010_tiled = pick_modifier(instance, physical, P010, 2) | |
| 679 | - .map(|m| export_planar(instance, physical, d, queue, family, P010, m, &p010)); | |
| 680 | - let nv12_set: Vec<&Export> = [Some(&nv12_linear), nv12_tiled.as_ref()] | |
| 681 | - .into_iter() | |
| 682 | - .flatten() | |
| 683 | - .collect(); | |
| 684 | - let p010_set: Vec<&Export> = [Some(&p010_linear), p010_tiled.as_ref()] | |
| 685 | - .into_iter() | |
| 686 | - .flatten() | |
| 687 | - .collect(); | |
| 688 | - run_planar::<H264EncodeSession>(&gpu, "h264 nv12", &nv12, &nv12_set); | |
| 689 | - run_planar::<H265EncodeSession>(&gpu, "h265 nv12", &nv12, &nv12_set); | |
| 690 | - run_planar::<H265EncodeSession>(&gpu, "h265 p010", &p010, &p010_set); | |
| 691 | - run_planar::<Av1EncodeSession>(&gpu, "av1 nv12", &nv12, &nv12_set); | |
| 692 | - run_planar::<Av1EncodeSession>(&gpu, "av1 p010", &p010, &p010_set); | |
| 693 | - | |
| 694 | - let pair = |format, pattern: &Pattern, modifier| { | |
| 695 | - ( | |
| 696 | - export_planar(instance, physical, d, queue, family, format, modifier, pattern), | |
| 697 | - export_planar(instance, physical, d, queue, family, format, modifier, pattern), | |
| 698 | - ) | |
| 699 | - }; | |
| 700 | - let nv12_pairs: Vec<(Export, Export)> = [Some(0), pick_modifier(instance, physical, NV12, 2)] | |
| 701 | - .into_iter() | |
| 702 | - .flatten() | |
| 703 | - .map(|m| pair(NV12, &nv12, m)) | |
| 704 | - .collect(); | |
| 705 | - let p010_pairs: Vec<(Export, Export)> = [Some(0), pick_modifier(instance, physical, P010, 2)] | |
| 706 | - .into_iter() | |
| 707 | - .flatten() | |
| 708 | - .map(|m| pair(P010, &p010, m)) | |
| 709 | - .collect(); | |
| 710 | - run_split::<H264EncodeSession>(&gpu, "h264 nv12", &nv12, &nv12_pairs); | |
| 711 | - run_split::<H265EncodeSession>(&gpu, "h265 nv12", &nv12, &nv12_pairs); | |
| 712 | - run_split::<H265EncodeSession>(&gpu, "h265 p010", &p010, &p010_pairs); | |
| 713 | - run_split::<Av1EncodeSession>(&gpu, "av1 nv12", &nv12, &nv12_pairs); | |
| 714 | - run_split::<Av1EncodeSession>(&gpu, "av1 p010", &p010, &p010_pairs); | |
| 715 | - | |
| 716 | - let mut split_cache = <H265EncodeSession as Encode>::open(&gpu, (W, H), 8).expect("encoder"); | |
| 717 | - let (sa, sb) = &nv12_pairs[0]; | |
| 718 | - let fds = [sa.fd.as_fd(), sb.fd.as_fd()]; | |
| 719 | - let planes = split_planes(sa, sb); | |
| 720 | - let src = DmaBuf { | |
| 721 | - fds: &fds, | |
| 722 | - planes: &planes, | |
| 723 | - width: W, | |
| 724 | - height: H, | |
| 725 | - modifier: sa.modifier, | |
| 726 | - format: DmaBufFormat::Nv12, | |
| 727 | - }; | |
| 728 | - for pass in 1..=2 { | |
| 729 | - for i in 0..FRAMES { | |
| 730 | - split_cache.dma(&src, i).expect("encode_dmabuf"); | |
| 731 | - } | |
| 732 | - println!( | |
| 733 | - "cache h265 nv12 split pass {pass} {FRAMES} frames same fds imports {}", | |
| 734 | - split_cache.dmabuf_imports() | |
| 735 | - ); | |
| 736 | - } | |
| 737 | - | |
| 738 | - let mut cache = <H265EncodeSession as Encode>::open(&gpu, (W, H), 8).expect("encoder"); | |
| 739 | - let fds = [nv12_linear.fd.as_fd()]; | |
| 740 | - let src = DmaBuf { | |
| 741 | - fds: &fds, | |
| 742 | - planes: &nv12_linear.planes, | |
| 743 | - width: W, | |
| 744 | - height: H, | |
| 745 | - modifier: nv12_linear.modifier, | |
| 746 | - format: DmaBufFormat::Nv12, | |
| 747 | - }; | |
| 748 | - for i in 0..FRAMES { | |
| 749 | - cache.dma(&src, i).expect("encode_dmabuf"); | |
| 750 | - } | |
| 751 | - println!( | |
| 752 | - "cache h265 nv12 {FRAMES} frames same fd imports {}", | |
| 753 | - cache.dmabuf_imports() | |
| 754 | - ); | |
| 755 | - | |
| 756 | - exports.extend(nv12_tiled); | |
| 757 | - exports.push(nv12_linear); | |
| 758 | - exports.extend(p010_tiled); | |
| 759 | - exports.push(p010_linear); | |
| 760 | - for e in &exports { | |
| 761 | - e.destroy(d); | |
| 762 | - } | |
| 763 | - for (a, b) in nv12_pairs.iter().chain(&p010_pairs) { | |
| 764 | - a.destroy(d); | |
| 765 | - b.destroy(d); | |
| 766 | - } | |
| 767 | -} |
shims/vk-video-ffi/examples/h264_decode_smoke.rsdeleted+0 -182
| @@ -1,182 +0,0 @@ | ||
| 1 | -use std::fs; | |
| 2 | -use std::path::PathBuf; | |
| 3 | -use std::process::Command; | |
| 4 | - | |
| 5 | -use ec_h264_syntax::sps::{ZIGZAG_4X4, ZIGZAG_8X8}; | |
| 6 | -use ec_h264_syntax::{ | |
| 7 | - AnnexBIter, NalHeader, NalUnitType, Pps, SliceHeader, Sps, unescape_rbsp, | |
| 8 | -}; | |
| 9 | -use vk_video_ffi::{ | |
| 10 | - Gpu, H264DecodeConfig, H264DecodePicture, H264DecodeSession, H264Pps, H264Sps, ScalingLists, | |
| 11 | -}; | |
| 12 | - | |
| 13 | -fn zigzag(raster: &[u8], scan: &[u8]) -> Vec<u8> { | |
| 14 | - scan.iter().map(|&r| raster[r as usize]).collect() | |
| 15 | -} | |
| 16 | - | |
| 17 | -fn lists(l: &ec_h264_syntax::ScalingLists) -> ScalingLists { | |
| 18 | - let mut out = ScalingLists { | |
| 19 | - l4x4: [[0; 16]; 6], | |
| 20 | - l8x8: [[0; 64]; 6], | |
| 21 | - }; | |
| 22 | - for i in 0..6 { | |
| 23 | - out.l4x4[i].copy_from_slice(&zigzag(&l.list_4x4[i], &ZIGZAG_4X4)); | |
| 24 | - out.l8x8[i].copy_from_slice(&zigzag(&l.list_8x8[i], &ZIGZAG_8X8)); | |
| 25 | - } | |
| 26 | - out | |
| 27 | -} | |
| 28 | - | |
| 29 | -fn main() { | |
| 30 | - let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument")); | |
| 31 | - let stream = dir.join("idr.h264"); | |
| 32 | - let reference = dir.join("ref.yuv"); | |
| 33 | - let status = Command::new("ffmpeg") | |
| 34 | - .args(["-y", "-loglevel", "error", "-f", "lavfi", "-i"]) | |
| 35 | - .arg("testsrc2=size=320x240:rate=30") | |
| 36 | - .args(["-frames:v", "1", "-c:v", "libx264", "-profile:v", "main"]) | |
| 37 | - .args(["-bsf:v", "h264_mp4toannexb", "-f", "h264"]) | |
| 38 | - .arg(&stream) | |
| 39 | - .status() | |
| 40 | - .expect("run ffmpeg"); | |
| 41 | - assert!(status.success()); | |
| 42 | - let status = Command::new("ffmpeg") | |
| 43 | - .args(["-y", "-loglevel", "error", "-i"]) | |
| 44 | - .arg(&stream) | |
| 45 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) | |
| 46 | - .arg(&reference) | |
| 47 | - .status() | |
| 48 | - .expect("run ffmpeg"); | |
| 49 | - assert!(status.success()); | |
| 50 | - | |
| 51 | - let data = fs::read(&stream).expect("read stream"); | |
| 52 | - let mut sps_list: Vec<Sps> = Vec::new(); | |
| 53 | - let mut pps_list: Vec<Pps> = Vec::new(); | |
| 54 | - let mut slices: Vec<&[u8]> = Vec::new(); | |
| 55 | - let mut slice_header = None; | |
| 56 | - let mut rbsp = Vec::new(); | |
| 57 | - for nal in AnnexBIter::new(&data) { | |
| 58 | - let header = NalHeader::parse(nal[0]).expect("NAL header"); | |
| 59 | - unescape_rbsp(&nal[1..], &mut rbsp); | |
| 60 | - match header.unit_type { | |
| 61 | - NalUnitType::Sps => sps_list.push(Sps::parse(&rbsp).expect("SPS")), | |
| 62 | - NalUnitType::Pps => { | |
| 63 | - let pps = Pps::parse(&rbsp, |id| sps_list.iter().find(|s| s.id == id)) | |
| 64 | - .expect("PPS"); | |
| 65 | - pps_list.push(pps); | |
| 66 | - } | |
| 67 | - NalUnitType::SliceIdr => { | |
| 68 | - let sps = &sps_list[0]; | |
| 69 | - let pps = &pps_list[0]; | |
| 70 | - let sh = SliceHeader::parse(&rbsp, header, sps, pps).expect("slice header"); | |
| 71 | - slice_header = Some(sh); | |
| 72 | - slices.push(nal); | |
| 73 | - } | |
| 74 | - _ => {} | |
| 75 | - } | |
| 76 | - } | |
| 77 | - let sps = &sps_list[0]; | |
| 78 | - let pps = &pps_list[0]; | |
| 79 | - let sh = slice_header.expect("IDR slice"); | |
| 80 | - | |
| 81 | - let unit_y = if sps.frame_mbs_only { 2 } else { 4 }; | |
| 82 | - let (left, right, top, bottom) = sps.crop; | |
| 83 | - let h264_sps = H264Sps { | |
| 84 | - id: sps.id, | |
| 85 | - profile_idc: sps.profile_idc, | |
| 86 | - level_idc: sps.level_idc, | |
| 87 | - chroma_format_idc: sps.chroma_format_idc, | |
| 88 | - bit_depth_luma_minus8: sps.bit_depth_luma - 8, | |
| 89 | - bit_depth_chroma_minus8: sps.bit_depth_chroma - 8, | |
| 90 | - log2_max_frame_num_minus4: sps.log2_max_frame_num - 4, | |
| 91 | - pic_order_cnt_type: sps.pic_order_cnt_type, | |
| 92 | - log2_max_pic_order_cnt_lsb_minus4: sps.log2_max_pic_order_cnt_lsb - 4, | |
| 93 | - offset_for_non_ref_pic: sps.offset_for_non_ref_pic, | |
| 94 | - offset_for_top_to_bottom_field: sps.offset_for_top_to_bottom_field, | |
| 95 | - offset_for_ref_frame: sps.offsets_for_ref_frame.clone(), | |
| 96 | - max_num_ref_frames: sps.max_num_ref_frames as u8, | |
| 97 | - pic_width_in_mbs_minus1: sps.mb_width - 1, | |
| 98 | - pic_height_in_map_units_minus1: (if sps.frame_mbs_only { | |
| 99 | - sps.mb_height | |
| 100 | - } else { | |
| 101 | - sps.mb_height / 2 | |
| 102 | - }) - 1, | |
| 103 | - frame_mbs_only: sps.frame_mbs_only, | |
| 104 | - mb_adaptive_frame_field: sps.mb_adaptive_frame_field, | |
| 105 | - direct_8x8_inference: sps.direct_8x8_inference, | |
| 106 | - delta_pic_order_always_zero: sps.delta_pic_order_always_zero, | |
| 107 | - frame_crop_offsets: [left / 2, right / 2, top / unit_y, bottom / unit_y], | |
| 108 | - qpprime_y_zero_transform_bypass: sps.transform_bypass, | |
| 109 | - seq_scaling_matrix: sps.scaling_lists.as_ref().map(lists), | |
| 110 | - }; | |
| 111 | - let h264_pps = H264Pps { | |
| 112 | - id: pps.id as u8, | |
| 113 | - sps_id: pps.sps_id, | |
| 114 | - entropy_coding_mode: pps.entropy_coding_mode, | |
| 115 | - bottom_field_pic_order_in_frame_present: pps.bottom_field_pic_order_in_frame_present, | |
| 116 | - num_ref_idx_l0_default_active_minus1: (pps.num_ref_idx_l0_default_active - 1) as u8, | |
| 117 | - num_ref_idx_l1_default_active_minus1: (pps.num_ref_idx_l1_default_active - 1) as u8, | |
| 118 | - weighted_pred: pps.weighted_pred, | |
| 119 | - weighted_bipred_idc: pps.weighted_bipred_idc, | |
| 120 | - pic_init_qp_minus26: (pps.pic_init_qp - 26) as i8, | |
| 121 | - pic_init_qs_minus26: (pps.pic_init_qs - 26) as i8, | |
| 122 | - chroma_qp_index_offset: pps.chroma_qp_index_offset as i8, | |
| 123 | - second_chroma_qp_index_offset: pps.second_chroma_qp_index_offset as i8, | |
| 124 | - deblocking_filter_control_present: pps.deblocking_filter_control_present, | |
| 125 | - constrained_intra_pred: pps.constrained_intra_pred, | |
| 126 | - redundant_pic_cnt_present: pps.redundant_pic_cnt_present, | |
| 127 | - transform_8x8_mode: pps.transform_8x8_mode, | |
| 128 | - pic_scaling_matrix: pps.scaling_lists.as_ref().map(lists), | |
| 129 | - }; | |
| 130 | - | |
| 131 | - let (w, h) = (sps.width, sps.height); | |
| 132 | - let gpu = Gpu::open().expect("open GPU"); | |
| 133 | - println!("device: {}", gpu.device_name()); | |
| 134 | - let cfg = H264DecodeConfig { | |
| 135 | - max_width: sps.coded_width, | |
| 136 | - max_height: sps.coded_height, | |
| 137 | - max_dpb_slots: 2, | |
| 138 | - profile_idc: sps.profile_idc, | |
| 139 | - chroma_format_idc: sps.chroma_format_idc, | |
| 140 | - }; | |
| 141 | - let mut session = H264DecodeSession::new(&gpu, &cfg).expect("decode session"); | |
| 142 | - session | |
| 143 | - .set_parameters(std::slice::from_ref(&h264_sps), std::slice::from_ref(&h264_pps)) | |
| 144 | - .expect("parameters"); | |
| 145 | - let poc = if sps.pic_order_cnt_type == 0 { | |
| 146 | - sh.pic_order_cnt_lsb as i32 | |
| 147 | - } else { | |
| 148 | - 0 | |
| 149 | - }; | |
| 150 | - let pic = H264DecodePicture { | |
| 151 | - sps_id: sps.id, | |
| 152 | - pps_id: pps.id as u8, | |
| 153 | - idr: true, | |
| 154 | - reference: true, | |
| 155 | - frame_num: sh.frame_num as u16, | |
| 156 | - idr_pic_id: sh.idr_pic_id.unwrap_or(0) as u16, | |
| 157 | - poc: [poc, poc + sh.delta_pic_order_cnt_bottom], | |
| 158 | - setup_slot: 0, | |
| 159 | - refs: &[], | |
| 160 | - slices: &slices, | |
| 161 | - }; | |
| 162 | - session.decode(&pic).expect("decode"); | |
| 163 | - session.store_output(0, (0, 0, w, h)).expect("store"); | |
| 164 | - let (y, uv) = session.read_output(0, w, h).expect("read slot"); | |
| 165 | - | |
| 166 | - let mut pgm = format!("P5\n{w} {h}\n255\n").into_bytes(); | |
| 167 | - pgm.extend_from_slice(&y); | |
| 168 | - fs::write(dir.join("out.pgm"), &pgm).expect("write pgm"); | |
| 169 | - | |
| 170 | - let ref_data = fs::read(&reference).expect("read reference"); | |
| 171 | - let luma = (w * h) as usize; | |
| 172 | - let chroma = luma / 4; | |
| 173 | - let ref_y = &ref_data[..luma]; | |
| 174 | - let ref_u = &ref_data[luma..luma + chroma]; | |
| 175 | - let ref_v = &ref_data[luma + chroma..luma + 2 * chroma]; | |
| 176 | - let mad = |a: &[u8], b: &[u8]| { | |
| 177 | - a.iter().zip(b).map(|(&x, &y)| (x as f64 - y as f64).abs()).sum::<f64>() / a.len() as f64 | |
| 178 | - }; | |
| 179 | - let ref_uv: Vec<u8> = ref_u.iter().zip(ref_v).flat_map(|(&u, &v)| [u, v]).collect(); | |
| 180 | - println!("mean abs diff Y: {:.6}", mad(&y, ref_y)); | |
| 181 | - println!("mean abs diff UV: {:.6}", mad(&uv, &ref_uv)); | |
| 182 | -} |
shims/vk-video-ffi/examples/h265_decode_smoke.rsdeleted+0 -284
| @@ -1,284 +0,0 @@ | ||
| 1 | -use std::fs; | |
| 2 | -use std::path::PathBuf; | |
| 3 | -use std::process::Command; | |
| 4 | - | |
| 5 | -use ec_h265_syntax::{ | |
| 6 | - NalUnitType, Pps, ProfileTierLevel, ScalingList, ShortTermRefPicSet, SliceHeader, Sps, Vps, | |
| 7 | - split_annex_b, | |
| 8 | -}; | |
| 9 | -use vk_video_ffi::{ | |
| 10 | - Gpu, H265DecPicBufMgr, H265DecodeConfig, H265DecodePicture, H265DecodeSession, | |
| 11 | - H265LongTermRefPicSps, H265Pcm, H265Pps, H265ProfileTierLevel, H265ScalingLists, | |
| 12 | - H265ShortTermRefPicSet, H265Sps, H265Vps, | |
| 13 | -}; | |
| 14 | - | |
| 15 | -fn ptl(p: &ProfileTierLevel) -> H265ProfileTierLevel { | |
| 16 | - H265ProfileTierLevel { | |
| 17 | - tier_flag: p.tier_flag, | |
| 18 | - progressive_source: p.progressive_source, | |
| 19 | - interlaced_source: p.interlaced_source, | |
| 20 | - non_packed_constraint: p.non_packed_constraint, | |
| 21 | - frame_only_constraint: p.frame_only_constraint, | |
| 22 | - profile_idc: p.profile_idc, | |
| 23 | - level_idc: p.level_idc, | |
| 24 | - } | |
| 25 | -} | |
| 26 | - | |
| 27 | -fn dpbm( | |
| 28 | - max_latency_increase_plus1: u32, | |
| 29 | - max_dec_pic_buffering_minus1: u32, | |
| 30 | - reorder: u32, | |
| 31 | -) -> H265DecPicBufMgr { | |
| 32 | - H265DecPicBufMgr { | |
| 33 | - max_latency_increase_plus1: [max_latency_increase_plus1; 7], | |
| 34 | - max_dec_pic_buffering_minus1: [max_dec_pic_buffering_minus1 as u8; 7], | |
| 35 | - max_num_reorder_pics: [reorder as u8; 7], | |
| 36 | - } | |
| 37 | -} | |
| 38 | - | |
| 39 | -fn lists(l: &ScalingList) -> H265ScalingLists { | |
| 40 | - let c = &l.coefficients; | |
| 41 | - H265ScalingLists { | |
| 42 | - list_4x4: std::array::from_fn(|i| c[0][i][..16].try_into().unwrap()), | |
| 43 | - list_8x8: std::array::from_fn(|i| c[1][i]), | |
| 44 | - list_16x16: std::array::from_fn(|i| c[2][i]), | |
| 45 | - list_32x32: std::array::from_fn(|i| c[3][3 * i]), | |
| 46 | - dc_16x16: std::array::from_fn(|i| l.dc[2][i]), | |
| 47 | - dc_32x32: std::array::from_fn(|i| l.dc[3][3 * i]), | |
| 48 | - } | |
| 49 | -} | |
| 50 | - | |
| 51 | -fn rps(r: &ShortTermRefPicSet) -> H265ShortTermRefPicSet { | |
| 52 | - let (n0, n1) = (r.num_negative as usize, r.num_positive as usize); | |
| 53 | - H265ShortTermRefPicSet { | |
| 54 | - delta_poc_s0: r.delta_poc_s0[..n0].to_vec(), | |
| 55 | - used_by_curr_pic_s0: r.used_s0[..n0].to_vec(), | |
| 56 | - delta_poc_s1: r.delta_poc_s1[..n1].to_vec(), | |
| 57 | - used_by_curr_pic_s1: r.used_s1[..n1].to_vec(), | |
| 58 | - } | |
| 59 | -} | |
| 60 | - | |
| 61 | -fn main() { | |
| 62 | - let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument")); | |
| 63 | - let stream = dir.join("idr.hevc"); | |
| 64 | - let reference = dir.join("ref.yuv"); | |
| 65 | - let status = Command::new("ffmpeg") | |
| 66 | - .args(["-y", "-loglevel", "error", "-f", "lavfi", "-i"]) | |
| 67 | - .arg("testsrc2=size=320x240:rate=30") | |
| 68 | - .args([ | |
| 69 | - "-frames:v", | |
| 70 | - "1", | |
| 71 | - "-c:v", | |
| 72 | - "libx265", | |
| 73 | - "-x265-params", | |
| 74 | - "log-level=error", | |
| 75 | - ]) | |
| 76 | - .args(["-f", "hevc"]) | |
| 77 | - .arg(&stream) | |
| 78 | - .status() | |
| 79 | - .expect("run ffmpeg"); | |
| 80 | - assert!(status.success()); | |
| 81 | - let status = Command::new("ffmpeg") | |
| 82 | - .args(["-y", "-loglevel", "error", "-i"]) | |
| 83 | - .arg(&stream) | |
| 84 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) | |
| 85 | - .arg(&reference) | |
| 86 | - .status() | |
| 87 | - .expect("run ffmpeg"); | |
| 88 | - assert!(status.success()); | |
| 89 | - | |
| 90 | - let data = fs::read(&stream).expect("read stream"); | |
| 91 | - let nals = split_annex_b(&data); | |
| 92 | - let mut vps_list: Vec<Vps> = Vec::new(); | |
| 93 | - let mut sps_list: Vec<Sps> = Vec::new(); | |
| 94 | - let mut pps_list: Vec<Pps> = Vec::new(); | |
| 95 | - let mut slice_nals: Vec<Vec<u8>> = Vec::new(); | |
| 96 | - for nal in &nals { | |
| 97 | - match nal.header.nal_type { | |
| 98 | - NalUnitType::Vps => vps_list.push(Vps::parse(&nal.rbsp()).expect("VPS")), | |
| 99 | - NalUnitType::Sps => sps_list.push(Sps::parse(&nal.rbsp()).expect("SPS")), | |
| 100 | - NalUnitType::Pps => pps_list.push(Pps::parse(&nal.rbsp()).expect("PPS")), | |
| 101 | - t if t.is_vcl() => { | |
| 102 | - let mut raw = nal.header.to_bytes().to_vec(); | |
| 103 | - raw.extend_from_slice(nal.payload); | |
| 104 | - slice_nals.push(raw); | |
| 105 | - } | |
| 106 | - _ => {} | |
| 107 | - } | |
| 108 | - } | |
| 109 | - let first = nals | |
| 110 | - .iter() | |
| 111 | - .find(|n| n.header.nal_type.is_vcl()) | |
| 112 | - .expect("slice"); | |
| 113 | - let vps = &vps_list[0]; | |
| 114 | - let pps = &pps_list[0]; | |
| 115 | - let sps = sps_list | |
| 116 | - .iter() | |
| 117 | - .find(|s| s.id == pps.sps_id) | |
| 118 | - .expect("SPS for PPS"); | |
| 119 | - let (sh, pos) = | |
| 120 | - SliceHeader::parse(&first.rbsp(), sps, pps, first.header.nal_type).expect("slice header"); | |
| 121 | - | |
| 122 | - let h265_vps = H265Vps { | |
| 123 | - id: vps.id, | |
| 124 | - max_sub_layers_minus1: 0, | |
| 125 | - profile_tier_level: ptl(&vps.ptl), | |
| 126 | - dec_pic_buf_mgr: dpbm( | |
| 127 | - 0, | |
| 128 | - vps.max_dec_pic_buffering_minus1, | |
| 129 | - vps.max_num_reorder_pics, | |
| 130 | - ), | |
| 131 | - }; | |
| 132 | - let c = &sps.conf_win; | |
| 133 | - let h265_sps = H265Sps { | |
| 134 | - id: sps.id as u8, | |
| 135 | - vps_id: sps.vps_id, | |
| 136 | - max_sub_layers_minus1: 0, | |
| 137 | - profile_tier_level: ptl(&sps.ptl), | |
| 138 | - chroma_format_idc: sps.chroma_format_idc as u8, | |
| 139 | - pic_width_in_luma_samples: sps.pic_width_in_luma_samples, | |
| 140 | - pic_height_in_luma_samples: sps.pic_height_in_luma_samples, | |
| 141 | - conformance_window: [c.left, c.right, c.top, c.bottom], | |
| 142 | - bit_depth_luma_minus8: sps.bit_depth_luma_minus8 as u8, | |
| 143 | - bit_depth_chroma_minus8: sps.bit_depth_chroma_minus8 as u8, | |
| 144 | - log2_max_pic_order_cnt_lsb_minus4: sps.log2_max_poc_lsb_minus4 as u8, | |
| 145 | - log2_min_luma_coding_block_size_minus3: sps.log2_min_cb_size_minus3 as u8, | |
| 146 | - log2_diff_max_min_luma_coding_block_size: sps.log2_diff_max_min_cb_size as u8, | |
| 147 | - log2_min_luma_transform_block_size_minus2: sps.log2_min_tb_size_minus2 as u8, | |
| 148 | - log2_diff_max_min_luma_transform_block_size: sps.log2_diff_max_min_tb_size as u8, | |
| 149 | - max_transform_hierarchy_depth_inter: sps.max_transform_hierarchy_depth_inter as u8, | |
| 150 | - max_transform_hierarchy_depth_intra: sps.max_transform_hierarchy_depth_intra as u8, | |
| 151 | - pcm: sps.pcm.map(|(a, b, c, d, e)| H265Pcm { | |
| 152 | - bit_depth_luma_minus1: a as u8, | |
| 153 | - bit_depth_chroma_minus1: b as u8, | |
| 154 | - log2_min_luma_coding_block_size_minus3: c as u8, | |
| 155 | - log2_diff_max_min_luma_coding_block_size: d as u8, | |
| 156 | - loop_filter_disabled: e, | |
| 157 | - }), | |
| 158 | - dec_pic_buf_mgr: dpbm( | |
| 159 | - sps.max_latency_increase_plus1, | |
| 160 | - sps.max_dec_pic_buffering_minus1, | |
| 161 | - sps.max_num_reorder_pics, | |
| 162 | - ), | |
| 163 | - scaling_list_enabled: sps.scaling_list_enabled, | |
| 164 | - scaling_lists: sps.scaling_list.as_ref().map(lists), | |
| 165 | - amp_enabled: sps.amp_enabled, | |
| 166 | - sample_adaptive_offset_enabled: sps.sao_enabled, | |
| 167 | - long_term_ref_pics_present: sps.long_term_ref_pics_present, | |
| 168 | - long_term_ref_pics_sps: sps | |
| 169 | - .long_term_ref_pics_sps | |
| 170 | - .iter() | |
| 171 | - .map(|&(poc_lsb, used_by_curr_pic)| H265LongTermRefPicSps { | |
| 172 | - poc_lsb, | |
| 173 | - used_by_curr_pic, | |
| 174 | - }) | |
| 175 | - .collect(), | |
| 176 | - temporal_mvp_enabled: sps.temporal_mvp_enabled, | |
| 177 | - strong_intra_smoothing_enabled: sps.strong_intra_smoothing, | |
| 178 | - short_term_ref_pic_sets: sps.short_term_ref_pic_sets.iter().map(rps).collect(), | |
| 179 | - }; | |
| 180 | - let h265_pps = H265Pps { | |
| 181 | - id: pps.id as u8, | |
| 182 | - sps_id: pps.sps_id as u8, | |
| 183 | - dependent_slice_segments_enabled: pps.dependent_slice_segments_enabled, | |
| 184 | - output_flag_present: pps.output_flag_present, | |
| 185 | - num_extra_slice_header_bits: pps.num_extra_slice_header_bits as u8, | |
| 186 | - sign_data_hiding_enabled: pps.sign_data_hiding_enabled, | |
| 187 | - cabac_init_present: pps.cabac_init_present, | |
| 188 | - num_ref_idx_l0_default_active_minus1: pps.num_ref_idx_l0_default_active_minus1 as u8, | |
| 189 | - num_ref_idx_l1_default_active_minus1: pps.num_ref_idx_l1_default_active_minus1 as u8, | |
| 190 | - init_qp_minus26: pps.init_qp_minus26 as i8, | |
| 191 | - constrained_intra_pred: pps.constrained_intra_pred, | |
| 192 | - transform_skip_enabled: pps.transform_skip_enabled, | |
| 193 | - cu_qp_delta_enabled: pps.cu_qp_delta_enabled, | |
| 194 | - diff_cu_qp_delta_depth: pps.diff_cu_qp_delta_depth as u8, | |
| 195 | - cb_qp_offset: pps.cb_qp_offset as i8, | |
| 196 | - cr_qp_offset: pps.cr_qp_offset as i8, | |
| 197 | - slice_chroma_qp_offsets_present: pps.slice_chroma_qp_offsets_present, | |
| 198 | - weighted_pred: pps.weighted_pred, | |
| 199 | - weighted_bipred: pps.weighted_bipred, | |
| 200 | - transquant_bypass_enabled: pps.transquant_bypass_enabled, | |
| 201 | - tiles_enabled: pps.tiles_enabled, | |
| 202 | - entropy_coding_sync_enabled: pps.entropy_coding_sync_enabled, | |
| 203 | - num_tile_columns_minus1: pps.num_tile_columns_minus1 as u8, | |
| 204 | - num_tile_rows_minus1: pps.num_tile_rows_minus1 as u8, | |
| 205 | - uniform_spacing: pps.uniform_spacing, | |
| 206 | - column_width_minus1: pps.column_width_minus1.iter().map(|&w| w as u16).collect(), | |
| 207 | - row_height_minus1: pps.row_height_minus1.iter().map(|&h| h as u16).collect(), | |
| 208 | - loop_filter_across_tiles_enabled: pps.loop_filter_across_tiles_enabled, | |
| 209 | - loop_filter_across_slices_enabled: pps.loop_filter_across_slices_enabled, | |
| 210 | - deblocking_filter_control_present: pps.deblocking_filter_control_present, | |
| 211 | - deblocking_filter_override_enabled: pps.deblocking_filter_override_enabled, | |
| 212 | - deblocking_filter_disabled: pps.deblocking_filter_disabled, | |
| 213 | - beta_offset_div2: pps.beta_offset_div2 as i8, | |
| 214 | - tc_offset_div2: pps.tc_offset_div2 as i8, | |
| 215 | - scaling_lists: pps.scaling_list.as_ref().map(lists), | |
| 216 | - lists_modification_present: pps.lists_modification_present, | |
| 217 | - log2_parallel_merge_level_minus2: pps.log2_parallel_merge_level_minus2 as u8, | |
| 218 | - slice_segment_header_extension_present: pps.slice_segment_header_extension_present, | |
| 219 | - }; | |
| 220 | - | |
| 221 | - let (w, h) = ( | |
| 222 | - h265_sps.pic_width_in_luma_samples, | |
| 223 | - h265_sps.pic_height_in_luma_samples, | |
| 224 | - ); | |
| 225 | - let gpu = Gpu::open().expect("open GPU"); | |
| 226 | - println!("device: {}", gpu.device_name()); | |
| 227 | - let cfg = H265DecodeConfig { | |
| 228 | - max_width: w, | |
| 229 | - max_height: h, | |
| 230 | - max_dpb_slots: 2, | |
| 231 | - bit_depth: 8, | |
| 232 | - }; | |
| 233 | - let mut session = H265DecodeSession::new(&gpu, &cfg).expect("decode session"); | |
| 234 | - session | |
| 235 | - .set_parameters( | |
| 236 | - std::slice::from_ref(&h265_vps), | |
| 237 | - std::slice::from_ref(&h265_sps), | |
| 238 | - std::slice::from_ref(&h265_pps), | |
| 239 | - ) | |
| 240 | - .expect("parameters"); | |
| 241 | - let slices: Vec<&[u8]> = slice_nals.iter().map(|v| v.as_slice()).collect(); | |
| 242 | - let pic = H265DecodePicture { | |
| 243 | - vps_id: sps.vps_id, | |
| 244 | - sps_id: sps.id as u8, | |
| 245 | - pps_id: pps.id as u8, | |
| 246 | - irap: first.header.nal_type.is_irap(), | |
| 247 | - idr: first.header.nal_type.is_idr(), | |
| 248 | - reference: true, | |
| 249 | - poc: 0, | |
| 250 | - setup_slot: 0, | |
| 251 | - short_term_ref_pic_set_sps: sh.short_term_ref_pic_set_sps_flag, | |
| 252 | - num_delta_pocs_of_ref_rps_idx: 0, | |
| 253 | - st_rps_bits: pos.st_rps_bits, | |
| 254 | - st_curr_before: &[], | |
| 255 | - st_curr_after: &[], | |
| 256 | - lt_curr: &[], | |
| 257 | - refs: &[], | |
| 258 | - slices: &slices, | |
| 259 | - }; | |
| 260 | - session.decode(&pic).expect("decode"); | |
| 261 | - session.store_output(0, (0, 0, w, h)).expect("store"); | |
| 262 | - let (y, uv) = session.read_output(0, w, h).expect("read slot"); | |
| 263 | - | |
| 264 | - let ref_data = fs::read(&reference).expect("read reference"); | |
| 265 | - let luma = (w * h) as usize; | |
| 266 | - let chroma = luma / 4; | |
| 267 | - let ref_y = &ref_data[..luma]; | |
| 268 | - let ref_u = &ref_data[luma..luma + chroma]; | |
| 269 | - let ref_v = &ref_data[luma + chroma..luma + 2 * chroma]; | |
| 270 | - let mad = |a: &[u8], b: &[u8]| { | |
| 271 | - a.iter() | |
| 272 | - .zip(b) | |
| 273 | - .map(|(&x, &y)| (x as f64 - y as f64).abs()) | |
| 274 | - .sum::<f64>() | |
| 275 | - / a.len() as f64 | |
| 276 | - }; | |
| 277 | - let ref_uv: Vec<u8> = ref_u | |
| 278 | - .iter() | |
| 279 | - .zip(ref_v) | |
| 280 | - .flat_map(|(&u, &v)| [u, v]) | |
| 281 | - .collect(); | |
| 282 | - println!("mean abs diff Y: {:.6}", mad(&y, ref_y)); | |
| 283 | - println!("mean abs diff UV: {:.6}", mad(&uv, &ref_uv)); | |
| 284 | -} |
shims/vk-video-ffi/src/av1_encode.rsmodified+0 -52
| @@ -302,25 +302,6 @@ impl Av1EncodeSession { | ||
| 302 | 302 | self.encode_uploaded(pic) |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - /// Encodes one picture from a shared D3D11 texture synchronously and returns its coded bytes. | |
| 306 | - #[cfg(windows)] | |
| 307 | - pub fn encode_d3d11(&mut self, src: &crate::D3d11Texture<'_>, pic: &Av1Picture) -> Result<Vec<u8>, Error> { | |
| 308 | - self.submit_d3d11(src, pic)?; | |
| 309 | - self.enc.flush_last() | |
| 310 | - } | |
| 311 | - | |
| 312 | - /// Number of D3D11 texture imports made so far; a texture re-used by id is imported once. | |
| 313 | - #[cfg(windows)] | |
| 314 | - pub fn d3d11_imports(&self) -> usize { | |
| 315 | - self.enc.import_count() | |
| 316 | - } | |
| 317 | - | |
| 318 | - /// Number of DMA-BUF imports made so far; a buffer re-used by fd is imported once. | |
| 319 | - #[cfg(target_os = "linux")] | |
| 320 | - pub fn dmabuf_imports(&self) -> usize { | |
| 321 | - self.enc.import_count() | |
| 322 | - } | |
| 323 | - | |
| 324 | 305 | fn encode_uploaded(&mut self, pic: &Av1Picture) -> Result<Option<Vec<u8>>, Error> { |
| 325 | 306 | let extent = self.enc.extent; |
| 326 | 307 | |
| @@ -460,39 +441,6 @@ impl Av1EncodeSession { | ||
| 460 | 441 | Ok(out) |
| 461 | 442 | } |
| 462 | 443 | |
| 463 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 464 | - pub fn encode(&mut self, y: &[u8], uv: &[u8], pic: &Av1Picture) -> Result<Vec<u8>, Error> { | |
| 465 | - self.submit(y, uv, pic)?; | |
| 466 | - self.enc.flush_last() | |
| 467 | - } | |
| 468 | - | |
| 469 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 470 | - pub fn encode_16(&mut self, y: &[u16], uv: &[u16], pic: &Av1Picture) -> Result<Vec<u8>, Error> { | |
| 471 | - self.submit_16(y, uv, pic)?; | |
| 472 | - self.enc.flush_last() | |
| 473 | - } | |
| 474 | - | |
| 475 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 476 | - pub fn encode_rgb( | |
| 477 | - &mut self, | |
| 478 | - rgb: &[u8], | |
| 479 | - src_width: u32, | |
| 480 | - src_height: u32, | |
| 481 | - stride_bytes: u32, | |
| 482 | - bgr: bool, | |
| 483 | - pic: &Av1Picture, | |
| 484 | - ) -> Result<Vec<u8>, Error> { | |
| 485 | - self.submit_rgb(rgb, src_width, src_height, stride_bytes, bgr, pic)?; | |
| 486 | - self.enc.flush_last() | |
| 487 | - } | |
| 488 | - | |
| 489 | - #[cfg(target_os = "linux")] | |
| 490 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 491 | - pub fn encode_dmabuf(&mut self, src: &DmaBuf<'_>, pic: &Av1Picture) -> Result<Vec<u8>, Error> { | |
| 492 | - self.submit_dmabuf(src, pic)?; | |
| 493 | - self.enc.flush_last() | |
| 494 | - } | |
| 495 | - | |
| 496 | 444 | /// Waits for queued pictures and returns their coded bytes in order. |
| 497 | 445 | pub fn flush(&mut self) -> Result<Vec<Vec<u8>>, Error> { |
| 498 | 446 | self.enc.flush() |
shims/vk-video-ffi/src/d3d11.rsmodified+0 -2
| @@ -194,7 +194,6 @@ fn import_memory( | ||
| 194 | 194 | pub(crate) struct ImportCache { |
| 195 | 195 | entries: Vec<(Key, Import)>, |
| 196 | 196 | next_id: u64, |
| 197 | - pub(crate) count: usize, | |
| 198 | 197 | } |
| 199 | 198 | |
| 200 | 199 | impl ImportCache { |
| @@ -224,7 +223,6 @@ impl ImportCache { | ||
| 224 | 223 | } |
| 225 | 224 | self.next_id += 1; |
| 226 | 225 | let import = Import::new(gpu, src, self.next_id)?; |
| 227 | - self.count += 1; | |
| 228 | 226 | self.entries.push((key, import)); |
| 229 | 227 | } |
| 230 | 228 | } |
shims/vk-video-ffi/src/dmabuf.rsmodified+0 -2
| @@ -388,7 +388,6 @@ fn device_memory(gpu: &Gpu, image: vk::Image) -> Result<vk::DeviceMemory, Error> | ||
| 388 | 388 | pub(crate) struct ImportCache { |
| 389 | 389 | entries: Vec<(Key, Import)>, |
| 390 | 390 | next_id: u64, |
| 391 | - pub(crate) count: usize, | |
| 392 | 391 | } |
| 393 | 392 | |
| 394 | 393 | impl ImportCache { |
| @@ -417,7 +416,6 @@ impl ImportCache { | ||
| 417 | 416 | } |
| 418 | 417 | self.next_id += 1; |
| 419 | 418 | let import = Import::new(gpu, src, self.next_id)?; |
| 420 | - self.count += 1; | |
| 421 | 419 | self.entries.push((key, import)); |
| 422 | 420 | } |
| 423 | 421 | } |
shims/vk-video-ffi/src/h264_encode.rsmodified+0 -46
| @@ -399,25 +399,6 @@ impl H264EncodeSession { | ||
| 399 | 399 | self.encode_uploaded(pic) |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - /// Encodes one picture from a shared D3D11 texture synchronously and returns its coded bytes. | |
| 403 | - #[cfg(windows)] | |
| 404 | - pub fn encode_d3d11(&mut self, src: &crate::D3d11Texture<'_>, pic: &H264Picture) -> Result<Vec<u8>, Error> { | |
| 405 | - self.submit_d3d11(src, pic)?; | |
| 406 | - self.enc.flush_last() | |
| 407 | - } | |
| 408 | - | |
| 409 | - /// Number of D3D11 texture imports made so far; a texture re-used by id is imported once. | |
| 410 | - #[cfg(windows)] | |
| 411 | - pub fn d3d11_imports(&self) -> usize { | |
| 412 | - self.enc.import_count() | |
| 413 | - } | |
| 414 | - | |
| 415 | - /// Number of DMA-BUF imports made so far; a buffer re-used by fd is imported once. | |
| 416 | - #[cfg(target_os = "linux")] | |
| 417 | - pub fn dmabuf_imports(&self) -> usize { | |
| 418 | - self.enc.import_count() | |
| 419 | - } | |
| 420 | - | |
| 421 | 402 | fn encode_uploaded(&mut self, pic: &H264Picture) -> Result<Option<Vec<u8>>, Error> { |
| 422 | 403 | let extent = self.enc.extent; |
| 423 | 404 | |
| @@ -550,33 +531,6 @@ impl H264EncodeSession { | ||
| 550 | 531 | .submit(&begin_slots, &mut applied.rc, &mut chain.rc, &encode) |
| 551 | 532 | } |
| 552 | 533 | |
| 553 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 554 | - pub fn encode(&mut self, y: &[u8], uv: &[u8], pic: &H264Picture) -> Result<Vec<u8>, Error> { | |
| 555 | - self.submit(y, uv, pic)?; | |
| 556 | - self.enc.flush_last() | |
| 557 | - } | |
| 558 | - | |
| 559 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 560 | - pub fn encode_rgb( | |
| 561 | - &mut self, | |
| 562 | - rgb: &[u8], | |
| 563 | - src_width: u32, | |
| 564 | - src_height: u32, | |
| 565 | - stride_bytes: u32, | |
| 566 | - bgr: bool, | |
| 567 | - pic: &H264Picture, | |
| 568 | - ) -> Result<Vec<u8>, Error> { | |
| 569 | - self.submit_rgb(rgb, src_width, src_height, stride_bytes, bgr, pic)?; | |
| 570 | - self.enc.flush_last() | |
| 571 | - } | |
| 572 | - | |
| 573 | - #[cfg(target_os = "linux")] | |
| 574 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 575 | - pub fn encode_dmabuf(&mut self, src: &DmaBuf<'_>, pic: &H264Picture) -> Result<Vec<u8>, Error> { | |
| 576 | - self.submit_dmabuf(src, pic)?; | |
| 577 | - self.enc.flush_last() | |
| 578 | - } | |
| 579 | - | |
| 580 | 534 | /// Waits for queued pictures and returns their coded bytes in order. |
| 581 | 535 | pub fn flush(&mut self) -> Result<Vec<Vec<u8>>, Error> { |
| 582 | 536 | self.enc.flush() |
shims/vk-video-ffi/src/h265_encode.rsmodified+0 -52
| @@ -344,25 +344,6 @@ impl H265EncodeSession { | ||
| 344 | 344 | self.encode_uploaded(pic) |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - /// Encodes one picture from a shared D3D11 texture synchronously and returns its coded bytes. | |
| 348 | - #[cfg(windows)] | |
| 349 | - pub fn encode_d3d11(&mut self, src: &crate::D3d11Texture<'_>, pic: &H265Picture) -> Result<Vec<u8>, Error> { | |
| 350 | - self.submit_d3d11(src, pic)?; | |
| 351 | - self.enc.flush_last() | |
| 352 | - } | |
| 353 | - | |
| 354 | - /// Number of D3D11 texture imports made so far; a texture re-used by id is imported once. | |
| 355 | - #[cfg(windows)] | |
| 356 | - pub fn d3d11_imports(&self) -> usize { | |
| 357 | - self.enc.import_count() | |
| 358 | - } | |
| 359 | - | |
| 360 | - /// Number of DMA-BUF imports made so far; a buffer re-used by fd is imported once. | |
| 361 | - #[cfg(target_os = "linux")] | |
| 362 | - pub fn dmabuf_imports(&self) -> usize { | |
| 363 | - self.enc.import_count() | |
| 364 | - } | |
| 365 | - | |
| 366 | 347 | fn encode_uploaded(&mut self, pic: &H265Picture) -> Result<Option<Vec<u8>>, Error> { |
| 367 | 348 | let extent = self.enc.extent; |
| 368 | 349 | |
| @@ -474,39 +455,6 @@ impl H265EncodeSession { | ||
| 474 | 455 | .submit(&begin_slots, &mut applied.rc, &mut chain.rc, &encode) |
| 475 | 456 | } |
| 476 | 457 | |
| 477 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 478 | - pub fn encode(&mut self, y: &[u8], uv: &[u8], pic: &H265Picture) -> Result<Vec<u8>, Error> { | |
| 479 | - self.submit(y, uv, pic)?; | |
| 480 | - self.enc.flush_last() | |
| 481 | - } | |
| 482 | - | |
| 483 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 484 | - pub fn encode_16(&mut self, y: &[u16], uv: &[u16], pic: &H265Picture) -> Result<Vec<u8>, Error> { | |
| 485 | - self.submit_16(y, uv, pic)?; | |
| 486 | - self.enc.flush_last() | |
| 487 | - } | |
| 488 | - | |
| 489 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 490 | - pub fn encode_rgb( | |
| 491 | - &mut self, | |
| 492 | - rgb: &[u8], | |
| 493 | - src_width: u32, | |
| 494 | - src_height: u32, | |
| 495 | - stride_bytes: u32, | |
| 496 | - bgr: bool, | |
| 497 | - pic: &H265Picture, | |
| 498 | - ) -> Result<Vec<u8>, Error> { | |
| 499 | - self.submit_rgb(rgb, src_width, src_height, stride_bytes, bgr, pic)?; | |
| 500 | - self.enc.flush_last() | |
| 501 | - } | |
| 502 | - | |
| 503 | - #[cfg(target_os = "linux")] | |
| 504 | - /// Encodes one picture synchronously and returns its coded bytes. | |
| 505 | - pub fn encode_dmabuf(&mut self, src: &DmaBuf<'_>, pic: &H265Picture) -> Result<Vec<u8>, Error> { | |
| 506 | - self.submit_dmabuf(src, pic)?; | |
| 507 | - self.enc.flush_last() | |
| 508 | - } | |
| 509 | - | |
| 510 | 458 | /// Waits for queued pictures and returns their coded bytes in order. |
| 511 | 459 | pub fn flush(&mut self) -> Result<Vec<Vec<u8>>, Error> { |
| 512 | 460 | self.enc.flush() |
shims/vk-video-ffi/src/session.rsmodified+0 -12
| @@ -1356,11 +1356,6 @@ impl Encoder { | ||
| 1356 | 1356 | slot.upload.submit_with(&[], &[slot.ready]) |
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | - #[cfg(any(target_os = "linux", windows))] | |
| 1360 | - pub(crate) fn import_count(&self) -> usize { | |
| 1361 | - self.imports.count | |
| 1362 | - } | |
| 1363 | - | |
| 1364 | 1359 | /// Records the encode of the uploaded slot and submits it without waiting. Returns the oldest picture once FLIGHT are queued. |
| 1365 | 1360 | pub(crate) fn submit( |
| 1366 | 1361 | &mut self, |
| @@ -1449,13 +1444,6 @@ impl Encoder { | ||
| 1449 | 1444 | Ok(out) |
| 1450 | 1445 | } |
| 1451 | 1446 | |
| 1452 | - /// Flushes and returns the last picture, for synchronous use where one picture is queued per call. | |
| 1453 | - pub(crate) fn flush_last(&mut self) -> Result<Vec<u8>, Error> { | |
| 1454 | - self.flush()? | |
| 1455 | - .pop() | |
| 1456 | - .ok_or_else(|| Error::Invalid("no picture encoded".into())) | |
| 1457 | - } | |
| 1458 | - | |
| 1459 | 1447 | fn finish(&mut self, k: usize) -> Result<Vec<u8>, Error> { |
| 1460 | 1448 | let slot = &self.slots[k]; |
| 1461 | 1449 | slot.main.wait()?; |