ec-va: import_prime_raw / RawPrimeObject import DMA-BUFs by borrowed RawFd; cros-libva vendored in shims with Buffer owning its params, fixing a use-after-free of VAProcPipelineParameterBuffer regions that made every VPP region/scale convert render nothing (encode_surface/encode_frame of a size-mismatched source encoded black); ec-hw: submit_prime scales any source size to the encoder's size on the GPU
Browse files at this commitd27d6697416055f357d6770d0c565c7569ee2289Parent: 119065735 changed files +8487 -37
- Cargo.lock +1 -1
- Cargo.toml +3 -0
- crates/ec-hw/src/enc/mod.rs +19 -11
- crates/ec-hw/tests/gpu.rs +62 -4
- crates/ec-va/src/lib.rs +2 -2
- crates/ec-va/src/surface.rs +54 -14
- crates/ec-va/src/vpp.rs +3 -5
- shims/cros-libva/Android.bp +63 -0
- shims/cros-libva/Cargo.toml +26 -0
- shims/cros-libva/LICENSE +26 -0
- shims/cros-libva/bindgen_gen.rs +22 -0
- shims/cros-libva/build.rs +159 -0
- shims/cros-libva/libva-wrapper.h +11 -0
- shims/cros-libva/src/bindings.rs +15 -0
- shims/cros-libva/src/buffer.rs +755 -0
- shims/cros-libva/src/buffer/av1.rs +1156 -0
- shims/cros-libva/src/buffer/enc_jpeg.rs +159 -0
- shims/cros-libva/src/buffer/enc_misc.rs +337 -0
- shims/cros-libva/src/buffer/h264.rs +807 -0
- shims/cros-libva/src/buffer/hevc.rs +1154 -0
- shims/cros-libva/src/buffer/jpeg_baseline.rs +220 -0
- shims/cros-libva/src/buffer/mpeg2.rs +172 -0
- shims/cros-libva/src/buffer/proc_pipeline.rs +198 -0
- shims/cros-libva/src/buffer/vp8.rs +397 -0
- shims/cros-libva/src/buffer/vp9.rs +451 -0
- shims/cros-libva/src/config.rs +137 -0
- shims/cros-libva/src/context.rs +110 -0
- shims/cros-libva/src/display.rs +362 -0
- shims/cros-libva/src/generic_value.rs +50 -0
- shims/cros-libva/src/image.rs +235 -0
- shims/cros-libva/src/lib.rs +536 -0
- shims/cros-libva/src/picture.rs +307 -0
- shims/cros-libva/src/surface.rs +452 -0
- shims/cros-libva/src/test_frame.nv12 +0 -0
- shims/cros-libva/src/usage_hint.rs +26 -0
Cargo.lockmodified+1 -1
| @@ -275,10 +275,10 @@ dependencies = [ | ||
| 275 | 275 | [[package]] |
| 276 | 276 | name = "cros-libva" |
| 277 | 277 | version = "0.0.13" |
| 278 | -source = "git+https://github.com/chromeos/cros-libva?rev=59384456ac2ae78c0c3e5515f41ef1efd9b802cf#59384456ac2ae78c0c3e5515f41ef1efd9b802cf" | |
| 279 | 278 | dependencies = [ |
| 280 | 279 | "bindgen", |
| 281 | 280 | "bitflags", |
| 281 | + "crc32fast", | |
| 282 | 282 | "log", |
| 283 | 283 | "pkg-config", |
| 284 | 284 | "regex", |
Cargo.tomlmodified+3 -0
| @@ -57,3 +57,6 @@ opt-level = 3 | ||
| 57 | 57 | |
| 58 | 58 | [profile.dev] |
| 59 | 59 | debug = "line-tables-only" |
| 60 | + | |
| 61 | +[patch."https://github.com/chromeos/cros-libva"] | |
| 62 | +cros-libva = { path = "shims/cros-libva" } |
crates/ec-hw/src/enc/mod.rsmodified+19 -11
| @@ -156,7 +156,14 @@ struct RateFeedback { | ||
| 156 | 156 | |
| 157 | 157 | impl Default for RateFeedback { |
| 158 | 158 | fn default() -> Self { |
| 159 | - RateFeedback { scale: 1.0, spent: 0.0, frames: 0, window: 0.0, window_frames: 0, steered: false } | |
| 159 | + RateFeedback { | |
| 160 | + scale: 1.0, | |
| 161 | + spent: 0.0, | |
| 162 | + frames: 0, | |
| 163 | + window: 0.0, | |
| 164 | + window_frames: 0, | |
| 165 | + steered: false, | |
| 166 | + } | |
| 160 | 167 | } |
| 161 | 168 | } |
| 162 | 169 | |
| @@ -600,25 +607,26 @@ impl Encoder { | ||
| 600 | 607 | } |
| 601 | 608 | } |
| 602 | 609 | |
| 603 | - /// Pipelined encode of an imported surface of the encoder's coded size: a GPU copy | |
| 604 | - /// into a pool surface whose padding is then zeroed, matching the CPU upload path. | |
| 610 | + /// Pipelined encode of an imported surface: a GPU copy into a pool surface | |
| 611 | + /// whose padding is then zeroed, matching the CPU upload path. A surface of | |
| 612 | + /// the coded size is copied whole; any other size is scaled to the | |
| 613 | + /// configured width x height, so one capture can feed several layers. | |
| 605 | 614 | pub fn submit_prime( |
| 606 | 615 | &mut self, |
| 607 | 616 | surface: Rc<ec_va::va::Surface<ec_va::surface::PrimeImport>>, |
| 608 | 617 | meta: FrameMetadata, |
| 609 | 618 | ) -> Result<Option<CodedFrame>> { |
| 610 | - if surface.size() != self.coded_size { | |
| 611 | - return Err(Error::config(format!( | |
| 612 | - "submit_prime: a {:?} surface for a {:?} encoder", | |
| 613 | - surface.size(), | |
| 614 | - self.coded_size | |
| 615 | - ))); | |
| 616 | - } | |
| 617 | 619 | let input = self |
| 618 | 620 | .pool |
| 619 | 621 | .acquire() |
| 620 | 622 | .ok_or_else(|| Error::config("submit_prime: every surface is still in use"))?; |
| 621 | - self.vpp()?.convert(&surface, Rc::clone(input.surface()))?; | |
| 623 | + let dest = if surface.size() == self.coded_size { | |
| 624 | + (0, 0, 0, 0) | |
| 625 | + } else { | |
| 626 | + (0, 0, self.config.width, self.config.height) | |
| 627 | + }; | |
| 628 | + self.vpp()? | |
| 629 | + .convert_region(&surface, (0, 0, 0, 0), Rc::clone(input.surface()), dest)?; | |
| 622 | 630 | zero_padding( |
| 623 | 631 | self.context.display(), |
| 624 | 632 | input.surface(), |
crates/ec-hw/tests/gpu.rsmodified+62 -4
| @@ -3437,9 +3437,6 @@ fn cbr_lands_within_five_percent_of_the_request() { | ||
| 3437 | 3437 | assert!(failures.is_empty(), "outside +/-5%: {failures:?}"); |
| 3438 | 3438 | } |
| 3439 | 3439 | |
| 3440 | -/// An NV12 surface holding `frame`, imported from DMA-BUFs: the surface is made | |
| 3441 | -/// by the driver, exported, and imported back, as a foreign allocator's buffer | |
| 3442 | -/// would arrive. | |
| 3443 | 3440 | fn imported_nv12( |
| 3444 | 3441 | display: &Rc<Display>, |
| 3445 | 3442 | frame: &I420, |
| @@ -3472,7 +3469,25 @@ fn imported_nv12( | ||
| 3472 | 3469 | } |
| 3473 | 3470 | } |
| 3474 | 3471 | let prime = surface.export().expect("export"); |
| 3475 | - Rc::new(ec_va::surface::import_prime(display, &prime).expect("import")) | |
| 3472 | + let objects: Vec<ec_va::RawPrimeObject> = prime | |
| 3473 | + .objects | |
| 3474 | + .iter() | |
| 3475 | + .map(|o| ec_va::RawPrimeObject { | |
| 3476 | + fd: std::os::fd::AsRawFd::as_raw_fd(&o.fd), | |
| 3477 | + size: o.size, | |
| 3478 | + modifier: o.modifier, | |
| 3479 | + }) | |
| 3480 | + .collect(); | |
| 3481 | + let imported = ec_va::import_prime_raw( | |
| 3482 | + display, | |
| 3483 | + prime.fourcc, | |
| 3484 | + (prime.width, prime.height), | |
| 3485 | + &objects, | |
| 3486 | + &prime.layers, | |
| 3487 | + ) | |
| 3488 | + .expect("import"); | |
| 3489 | + drop(prime); | |
| 3490 | + Rc::new(imported) | |
| 3476 | 3491 | } |
| 3477 | 3492 | |
| 3478 | 3493 | /// Encoding an imported DMA-BUF must give the bytes the CPU path gives for the |
| @@ -3719,3 +3734,46 @@ fn h264_encode_decodes_with_no_reorder_delay() { | ||
| 3719 | 3734 | assert!(decoder.next_frame().is_some(), "frame {t} held back"); |
| 3720 | 3735 | } |
| 3721 | 3736 | } |
| 3737 | + | |
| 3738 | +#[test] | |
| 3739 | +fn imported_dma_buf_scales_and_crops_through_vpp() { | |
| 3740 | + let Some(display) = display() else { return }; | |
| 3741 | + let mean = |y: &[u8]| y.iter().map(|&v| f64::from(v)).sum::<f64>() / y.len() as f64; | |
| 3742 | + let meta = FrameMetadata { | |
| 3743 | + timestamp: 0, | |
| 3744 | + force_keyframe: false, | |
| 3745 | + }; | |
| 3746 | + for (source_w, source_h, scale) in [(1280, 720, true), (640, 360, false)] { | |
| 3747 | + let source = source_frame(source_w, source_h, 0); | |
| 3748 | + let mut config = EncoderConfig::new(EncCodec::H264, 640, 360); | |
| 3749 | + config.rate_control = RateControlMode::ConstantQp { qp: 22 }; | |
| 3750 | + let mut encoder = Encoder::new(&display, config).expect("encoder"); | |
| 3751 | + let surface = imported_nv12(&display, &source); | |
| 3752 | + let data = if scale { | |
| 3753 | + let mut data = Vec::new(); | |
| 3754 | + if let Some(c) = encoder.submit_prime(surface, meta).expect("submit_prime") { | |
| 3755 | + data.extend(c.data); | |
| 3756 | + } | |
| 3757 | + data.extend( | |
| 3758 | + encoder | |
| 3759 | + .flush() | |
| 3760 | + .expect("flush") | |
| 3761 | + .into_iter() | |
| 3762 | + .flat_map(|c| c.data), | |
| 3763 | + ); | |
| 3764 | + data | |
| 3765 | + } else { | |
| 3766 | + encoder | |
| 3767 | + .encode_surface(&surface, (640, 360), meta) | |
| 3768 | + .expect("encode_surface") | |
| 3769 | + .data | |
| 3770 | + }; | |
| 3771 | + let mut decoder = Decoder::new(&display, Codec::H264).expect("decoder"); | |
| 3772 | + decoder.decode(&data, 0).expect("decode"); | |
| 3773 | + decoder.flush().expect("flush"); | |
| 3774 | + let frame = decoder.next_frame().expect("a picture"); | |
| 3775 | + assert_eq!(frame.display_size, (640, 360)); | |
| 3776 | + let got = frame.to_i420().expect("readback"); | |
| 3777 | + assert!((mean(&got.y) - mean(&source.y)).abs() < 3.0); | |
| 3778 | + } | |
| 3779 | +} |
crates/ec-va/src/lib.rsmodified+2 -2
| @@ -51,7 +51,7 @@ pub use display::{Display, open, open_path}; | ||
| 51 | 51 | pub use error::{Error, Result}; |
| 52 | 52 | pub use picture::{Buffer, Context, Picture, create_context}; |
| 53 | 53 | pub use surface::{ |
| 54 | - Image, PrimeLayer, PrimeObject, PrimeSurface, Surface, SurfaceExt, SurfaceSpec, create_pool, | |
| 55 | - import_prime, | |
| 54 | + Image, PrimeLayer, PrimeObject, PrimeSurface, RawPrimeObject, Surface, SurfaceExt, SurfaceSpec, | |
| 55 | + create_pool, import_prime, import_prime_raw, | |
| 56 | 56 | }; |
| 57 | 57 | pub use vpp::Vpp; |
crates/ec-va/src/surface.rsmodified+54 -14
| @@ -212,27 +212,67 @@ pub fn import_prime( | ||
| 212 | 212 | display: &Rc<Display>, |
| 213 | 213 | prime: &PrimeSurface, |
| 214 | 214 | ) -> Result<cros_libva::Surface<PrimeImport>> { |
| 215 | - if prime.objects.len() > 4 || prime.layers.len() > 4 { | |
| 215 | + let objects: Vec<RawPrimeObject> = prime | |
| 216 | + .objects | |
| 217 | + .iter() | |
| 218 | + .map(|o| RawPrimeObject { | |
| 219 | + fd: o.fd.as_raw_fd(), | |
| 220 | + size: o.size, | |
| 221 | + modifier: o.modifier, | |
| 222 | + }) | |
| 223 | + .collect(); | |
| 224 | + import_prime_raw( | |
| 225 | + display, | |
| 226 | + prime.fourcc, | |
| 227 | + (prime.width, prime.height), | |
| 228 | + &objects, | |
| 229 | + &prime.layers, | |
| 230 | + ) | |
| 231 | +} | |
| 232 | + | |
| 233 | +/// A DMA-BUF object borrowed by raw fd, for buffers another owner keeps | |
| 234 | +/// (e.g. a PipeWire `spa_data` fd). | |
| 235 | +#[derive(Debug, Clone, Copy)] | |
| 236 | +pub struct RawPrimeObject { | |
| 237 | + /// The DMA-BUF, borrowed only for the duration of the import call. | |
| 238 | + pub fd: std::os::fd::RawFd, | |
| 239 | + /// Size of the object in bytes. | |
| 240 | + pub size: u32, | |
| 241 | + /// DRM format modifier of the object. | |
| 242 | + pub modifier: u64, | |
| 243 | +} | |
| 244 | + | |
| 245 | +/// [`import_prime`] with borrowed raw fds. The driver takes its own reference | |
| 246 | +/// to each DMA-BUF during `vaCreateSurfaces`, so the fds may be closed after | |
| 247 | +/// this returns; the buffer contents must stay valid while the surface is read. | |
| 248 | +pub fn import_prime_raw( | |
| 249 | + display: &Rc<Display>, | |
| 250 | + fourcc: u32, | |
| 251 | + size: (u32, u32), | |
| 252 | + objects: &[RawPrimeObject], | |
| 253 | + layers: &[PrimeLayer], | |
| 254 | +) -> Result<cros_libva::Surface<PrimeImport>> { | |
| 255 | + if objects.len() > 4 || layers.len() > 4 { | |
| 216 | 256 | return Err(Error::Protocol(format!( |
| 217 | 257 | "a PRIME surface has {} objects and {} layers, max 4 each", |
| 218 | - prime.objects.len(), | |
| 219 | - prime.layers.len() | |
| 258 | + objects.len(), | |
| 259 | + layers.len() | |
| 220 | 260 | ))); |
| 221 | 261 | } |
| 222 | 262 | let mut desc = VADRMPRIMESurfaceDescriptor { |
| 223 | - fourcc: prime.fourcc, | |
| 224 | - width: prime.width, | |
| 225 | - height: prime.height, | |
| 226 | - num_objects: prime.objects.len() as u32, | |
| 227 | - num_layers: prime.layers.len() as u32, | |
| 263 | + fourcc, | |
| 264 | + width: size.0, | |
| 265 | + height: size.1, | |
| 266 | + num_objects: objects.len() as u32, | |
| 267 | + num_layers: layers.len() as u32, | |
| 228 | 268 | ..Default::default() |
| 229 | 269 | }; |
| 230 | - for (i, o) in prime.objects.iter().enumerate() { | |
| 231 | - desc.objects[i].fd = o.fd.as_raw_fd(); | |
| 270 | + for (i, o) in objects.iter().enumerate() { | |
| 271 | + desc.objects[i].fd = o.fd; | |
| 232 | 272 | desc.objects[i].size = o.size; |
| 233 | 273 | desc.objects[i].drm_format_modifier = o.modifier; |
| 234 | 274 | } |
| 235 | - for (i, l) in prime.layers.iter().enumerate() { | |
| 275 | + for (i, l) in layers.iter().enumerate() { | |
| 236 | 276 | if l.planes.len() > 4 { |
| 237 | 277 | return Err(Error::Protocol(format!( |
| 238 | 278 | "a PRIME layer has {} planes, max 4", |
| @@ -251,9 +291,9 @@ pub fn import_prime( | ||
| 251 | 291 | "vaCreateSurfaces", |
| 252 | 292 | display.create_surfaces( |
| 253 | 293 | cros_libva::VA_RT_FORMAT_YUV420, |
| 254 | - Some(prime.fourcc), | |
| 255 | - prime.width, | |
| 256 | - prime.height, | |
| 294 | + Some(fourcc), | |
| 295 | + size.0, | |
| 296 | + size.1, | |
| 257 | 297 | None, |
| 258 | 298 | vec![PrimeImport(desc)], |
| 259 | 299 | ), |
crates/ec-va/src/vpp.rsmodified+3 -5
| @@ -68,11 +68,9 @@ impl Vpp { | ||
| 68 | 68 | self.convert_region(source, (0, 0, 0, 0), dest, (0, 0, 0, 0)) |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - /// Convert `source_region` of `source` into `dest_region` of `dest` with | |
| 72 | - /// no scaling (both regions are the same size in every caller), leaving | |
| 73 | - /// the rest of `dest` as it was. A zero-sized region means "the whole | |
| 74 | - /// surface". This is how a visible picture smaller than its block-aligned | |
| 75 | - /// coded surface lands inside a differently-padded destination. | |
| 71 | + /// Convert `source_region` of `source` into `dest_region` of `dest`, | |
| 72 | + /// scaling when the regions differ in size and leaving the rest of `dest` | |
| 73 | + /// as it was. A zero-sized region means "the whole surface". | |
| 76 | 74 | pub fn convert_region<D, E>( |
| 77 | 75 | &self, |
| 78 | 76 | source: &cros_libva::Surface<D>, |
shims/cros-libva/Android.bpadded+63 -0
| @@ -0,0 +1,63 @@ | ||
| 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.tomladded+26 -0
| @@ -0,0 +1,26 @@ | ||
| 1 | +[package] | |
| 2 | +name = "cros-libva" | |
| 3 | +version = "0.0.13" | |
| 4 | +license = "BSD-3-Clause" | |
| 5 | +description = "Safe bindings over libva" | |
| 6 | +repository = "https://github.com/chromeos/cros-libva" | |
| 7 | +authors = ["The Chromium OS Authors"] | |
| 8 | +edition = "2021" | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | +[features] | |
| 13 | +intel-protected-content-headers = [] | |
| 14 | + | |
| 15 | +[dependencies] | |
| 16 | +thiserror = "1" | |
| 17 | +bitflags = "2.5" | |
| 18 | +log = { version = "0", features = ["release_max_level_debug"] } | |
| 19 | + | |
| 20 | +[build-dependencies] | |
| 21 | +bindgen = "0.70.1" | |
| 22 | +pkg-config = "0.3.31" | |
| 23 | +regex = "1.11.1" | |
| 24 | + | |
| 25 | +[dev-dependencies] | |
| 26 | +crc32fast = "1.2.1" |
shims/cros-libva/LICENSEadded+26 -0
| @@ -0,0 +1,26 @@ | ||
| 1 | +Copyright 2022 The ChromiumOS Authors | |
| 2 | + | |
| 3 | +Redistribution and use in source and binary forms, with or without modification, | |
| 4 | +are permitted provided that the following conditions are met: | |
| 5 | + | |
| 6 | +1. Redistributions of source code must retain the above copyright notice, this | |
| 7 | + list of conditions and the following disclaimer. | |
| 8 | + | |
| 9 | +2. Redistributions in binary form must reproduce the above copyright notice, | |
| 10 | + this list of conditions and the following disclaimer in the documentation | |
| 11 | + and/or other materials provided with the distribution. | |
| 12 | + | |
| 13 | +3. Neither the name of the copyright holder nor the names of its contributors | |
| 14 | + may be used to endorse or promote products derived from this software without | |
| 15 | + specific prior written permission. | |
| 16 | + | |
| 17 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 18 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 19 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 20 | +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | |
| 21 | +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 22 | +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 23 | +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
| 24 | +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 | +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 26 | +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
shims/cros-libva/bindgen_gen.rsadded+22 -0
| @@ -0,0 +1,22 @@ | ||
| 1 | +// Copyright 2022 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 | +/// The allow list of VA structures and enum values. | |
| 6 | +const ALLOW_LIST_TYPE: &str = | |
| 7 | + ".*ExternalBuffers.*|.*PRIME.*|.*MPEG2.*|.*VP8.*|.*VP9.*|.*H264.*|.*HEVC.*|\ | |
| 8 | + .*JPEG.*|VACodedBufferSegment|.*AV1.*|VAEncMisc.*|VASurfaceDecodeMBErrors|\ | |
| 9 | + VADecodeErrorType|.*VAProc.*|VAEncPacked.*|\ | |
| 10 | + VACenc.*|VA_TEE_.*|VAEncryption.*|VA_PROTECTED_.*"; | |
| 11 | + | |
| 12 | +// The common bindgen builder for VA-API. | |
| 13 | +pub fn vaapi_gen_builder(builder: bindgen::Builder) -> bindgen::Builder { | |
| 14 | + builder | |
| 15 | + .derive_default(true) | |
| 16 | + .derive_eq(true) | |
| 17 | + .layout_tests(false) | |
| 18 | + .constified_enum_module("VA.*") | |
| 19 | + .allowlist_var("VA.*") | |
| 20 | + .allowlist_function("va.*") | |
| 21 | + .allowlist_type(ALLOW_LIST_TYPE) | |
| 22 | +} |
shims/cros-libva/build.rsadded+159 -0
| @@ -0,0 +1,159 @@ | ||
| 1 | +// Copyright 2022 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 | +use regex::Regex; | |
| 6 | +use std::env::VarError; | |
| 7 | +use std::env::{self}; | |
| 8 | +use std::fs::read_to_string; | |
| 9 | +use std::path::{Path, PathBuf}; | |
| 10 | + | |
| 11 | +mod bindgen_gen; | |
| 12 | +use bindgen_gen::vaapi_gen_builder; | |
| 13 | + | |
| 14 | +/// Environment variable that can be set to point to the directory containing the `va.h`, `va_drm.h` and `va_drmcommon.h` | |
| 15 | +/// files to use to generate the bindings. | |
| 16 | +const CROS_LIBVA_H_PATH_ENV: &str = "CROS_LIBVA_H_PATH"; | |
| 17 | +const CROS_LIBVA_LIB_PATH_ENV: &str = "CROS_LIBVA_LIB_PATH"; | |
| 18 | +const CROS_LIBVA_PROTECTED_CONTENT_H_PATH_ENV: &str = "CROS_LIBVA_PROTECTED_CONTENT_H_PATH"; | |
| 19 | + | |
| 20 | +/// Wrapper file to use as input of bindgen. | |
| 21 | +const WRAPPER_PATH: &str = "libva-wrapper.h"; | |
| 22 | + | |
| 23 | +// Return VA_MAJOR_VERSION and VA_MINOR_VERSION from va_version.h. | |
| 24 | +fn get_va_version(va_h_path: &str) -> (u32, u32) { | |
| 25 | + let va_version_h_path = Path::new(va_h_path).join("va/va_version.h"); | |
| 26 | + assert!( | |
| 27 | + va_version_h_path.exists(), | |
| 28 | + "{} doesn't exist", | |
| 29 | + va_version_h_path.display() | |
| 30 | + ); | |
| 31 | + let header_content = read_to_string(va_version_h_path).unwrap(); | |
| 32 | + let lines = header_content.lines(); | |
| 33 | + | |
| 34 | + const VERSION_REGEX_STRINGS: [&str; 2] = [ | |
| 35 | + r"#define VA_MAJOR_VERSION\s*[0-9]+", | |
| 36 | + r"#define VA_MINOR_VERSION\s*[0-9]+", | |
| 37 | + ]; | |
| 38 | + let mut numbers: [u32; 2] = [0; 2]; | |
| 39 | + for i in 0..2 { | |
| 40 | + let re = Regex::new(VERSION_REGEX_STRINGS[i]).unwrap(); | |
| 41 | + let match_line = lines | |
| 42 | + .clone() | |
| 43 | + .filter(|&s| re.is_match(s)) | |
| 44 | + .collect::<Vec<_>>(); | |
| 45 | + assert_eq!( | |
| 46 | + match_line.len(), | |
| 47 | + 1, | |
| 48 | + "unexpected match for {}: {:?}", | |
| 49 | + VERSION_REGEX_STRINGS[i], | |
| 50 | + match_line | |
| 51 | + ); | |
| 52 | + let number_str = Regex::new(r"[0-9]+") | |
| 53 | + .unwrap() | |
| 54 | + .find(match_line[0]) | |
| 55 | + .unwrap() | |
| 56 | + .as_str(); | |
| 57 | + numbers[i] = number_str.parse::<u32>().unwrap(); | |
| 58 | + } | |
| 59 | + | |
| 60 | + (numbers[0], numbers[1]) | |
| 61 | +} | |
| 62 | + | |
| 63 | +fn main() { | |
| 64 | + // Do not require dependencies when generating docs. | |
| 65 | + if std::env::var("CARGO_DOC").is_ok() || std::env::var("DOCS_RS").is_ok() { | |
| 66 | + return; | |
| 67 | + } | |
| 68 | + | |
| 69 | + let va_h_path = env::var(CROS_LIBVA_H_PATH_ENV) | |
| 70 | + .or_else(|e| { | |
| 71 | + if let VarError::NotPresent = e { | |
| 72 | + let libva_library = pkg_config::probe_library("libva"); | |
| 73 | + match libva_library { | |
| 74 | + Ok(_) => Ok(libva_library.unwrap().include_paths[0] | |
| 75 | + .clone() | |
| 76 | + .into_os_string() | |
| 77 | + .into_string() | |
| 78 | + .unwrap()), | |
| 79 | + Err(e) => panic!("libva is not found in system: {}", e), | |
| 80 | + } | |
| 81 | + } else { | |
| 82 | + Err(e) | |
| 83 | + } | |
| 84 | + }) | |
| 85 | + .expect("libva header location is unknown"); | |
| 86 | + | |
| 87 | + let va_lib_path = env::var(CROS_LIBVA_LIB_PATH_ENV).unwrap_or_default(); | |
| 88 | + // Check the path exists. | |
| 89 | + if !va_h_path.is_empty() { | |
| 90 | + assert!( | |
| 91 | + Path::new(&va_h_path).exists(), | |
| 92 | + "{} doesn't exist", | |
| 93 | + va_h_path | |
| 94 | + ); | |
| 95 | + } | |
| 96 | + | |
| 97 | + let (major, minor) = get_va_version(&va_h_path); | |
| 98 | + println!("libva {}.{} is used to generate bindings", major, minor); | |
| 99 | + let va_check_version = |desired_major: u32, desired_minor: u32| { | |
| 100 | + major > desired_major || (major == desired_major && minor >= desired_minor) | |
| 101 | + }; | |
| 102 | + | |
| 103 | + if va_check_version(1, 23) { | |
| 104 | + println!("cargo::rustc-cfg=libva_1_23_or_higher"); | |
| 105 | + } | |
| 106 | + if va_check_version(1, 22) { | |
| 107 | + println!("cargo::rustc-cfg=libva_1_22_or_higher"); | |
| 108 | + } | |
| 109 | + if va_check_version(1, 21) { | |
| 110 | + println!("cargo::rustc-cfg=libva_1_21_or_higher"); | |
| 111 | + } | |
| 112 | + if va_check_version(1, 20) { | |
| 113 | + println!("cargo::rustc-cfg=libva_1_20_or_higher") | |
| 114 | + } | |
| 115 | + if va_check_version(1, 19) { | |
| 116 | + println!("cargo::rustc-cfg=libva_1_19_or_higher") | |
| 117 | + } | |
| 118 | + if va_check_version(1, 16) { | |
| 119 | + println!("cargo::rustc-cfg=libva_1_16_or_higher") | |
| 120 | + } | |
| 121 | + | |
| 122 | + if !va_lib_path.is_empty() { | |
| 123 | + assert!( | |
| 124 | + Path::new(&va_lib_path).exists(), | |
| 125 | + "{} doesn't exist", | |
| 126 | + va_lib_path | |
| 127 | + ); | |
| 128 | + println!("cargo:rustc-link-arg=-Wl,-rpath={}", va_lib_path); | |
| 129 | + } | |
| 130 | + | |
| 131 | + // Tell cargo to link va and va-drm objects dynamically. | |
| 132 | + println!("cargo:rustc-link-lib=dylib=va"); | |
| 133 | + println!("cargo:rustc-link-lib=dylib=va-drm"); // for the vaGetDisplayDRM entrypoint | |
| 134 | + | |
| 135 | + let mut bindings_builder = vaapi_gen_builder(bindgen::builder()).header(WRAPPER_PATH); | |
| 136 | + if !va_h_path.is_empty() { | |
| 137 | + bindings_builder = bindings_builder.clang_arg(format!("-I{}", va_h_path)); | |
| 138 | + } | |
| 139 | + | |
| 140 | + if std::env::var("CARGO_FEATURE_INTEL_PROTECTED_CONTENT_HEADERS").is_ok() { | |
| 141 | + println!("cargo:warning=Building with intel protected content headers!"); | |
| 142 | + bindings_builder = bindings_builder.clang_arg("-DINTEL_PROTECTED_CONTENT_HEADERS"); | |
| 143 | + let va_p_h_path_env = env::var(CROS_LIBVA_PROTECTED_CONTENT_H_PATH_ENV); | |
| 144 | + if va_p_h_path_env.is_ok() { | |
| 145 | + let va_p_h_path = va_p_h_path_env.unwrap(); | |
| 146 | + bindings_builder = bindings_builder.clang_arg(format!("-I{}", va_p_h_path)); | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + let bindings = bindings_builder | |
| 151 | + .generate() | |
| 152 | + .expect("unable to generate bindings"); | |
| 153 | + | |
| 154 | + let out_path = PathBuf::from(env::var("OUT_DIR").expect("`OUT_DIR` is not set")); | |
| 155 | + | |
| 156 | + bindings | |
| 157 | + .write_to_file(out_path.join("bindings.rs")) | |
| 158 | + .expect("Couldn't write bindings!"); | |
| 159 | +} |
shims/cros-libva/libva-wrapper.hadded+11 -0
| @@ -0,0 +1,11 @@ | ||
| 1 | +// Copyright 2022 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 | +#include <va/va.h> | |
| 6 | +#include <va/va_drm.h> | |
| 7 | +#include <va/va_drmcommon.h> | |
| 8 | + | |
| 9 | +#if defined(INTEL_PROTECTED_CONTENT_HEADERS) | |
| 10 | +#include <va_protected_content.h> | |
| 11 | +#endif // defined(INTEL_PROTECTED_CONTENT_HEADERS) |
shims/cros-libva/src/bindings.rsadded+15 -0
| @@ -0,0 +1,15 @@ | ||
| 1 | +// Copyright 2022 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 module implements the bindgen C FFI bindings for use within this crate | |
| 6 | + | |
| 7 | +#![allow(missing_docs)] | |
| 8 | +#![allow(clippy::useless_transmute)] | |
| 9 | +#![allow(clippy::too_many_arguments)] | |
| 10 | +#![allow(non_upper_case_globals)] | |
| 11 | +#![allow(non_snake_case)] | |
| 12 | +#![allow(non_camel_case_types)] | |
| 13 | +#![allow(dead_code)] | |
| 14 | + | |
| 15 | +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); |
shims/cros-libva/src/buffer.rsadded+755 -0
| @@ -0,0 +1,755 @@ | ||
| 1 | +// Copyright 2022 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 and helpers around `VABuffer`s. | |
| 6 | + | |
| 7 | +mod av1; | |
| 8 | +mod enc_jpeg; | |
| 9 | +mod enc_misc; | |
| 10 | +mod h264; | |
| 11 | +mod hevc; | |
| 12 | +mod jpeg_baseline; | |
| 13 | +mod mpeg2; | |
| 14 | +mod proc_pipeline; | |
| 15 | +mod vp8; | |
| 16 | +mod vp9; | |
| 17 | + | |
| 18 | +pub use av1::*; | |
| 19 | +pub use enc_jpeg::*; | |
| 20 | +pub use enc_misc::*; | |
| 21 | +pub use h264::*; | |
| 22 | +pub use hevc::*; | |
| 23 | +pub use jpeg_baseline::*; | |
| 24 | +pub use mpeg2::*; | |
| 25 | +pub use proc_pipeline::*; | |
| 26 | +pub use vp8::*; | |
| 27 | +pub use vp9::*; | |
| 28 | + | |
| 29 | +use std::rc::Rc; | |
| 30 | + | |
| 31 | +use log::error; | |
| 32 | + | |
| 33 | +use crate::bindings; | |
| 34 | +use crate::va_check; | |
| 35 | +use crate::Context; | |
| 36 | +use crate::VaError; | |
| 37 | + | |
| 38 | +/// Wrapper type representing a buffer created with `vaCreateBuffer`. | |
| 39 | +pub struct Buffer { | |
| 40 | + context: Rc<Context>, | |
| 41 | + id: bindings::VABufferID, | |
| 42 | + _params: Option<BufferType>, | |
| 43 | +} | |
| 44 | + | |
| 45 | +impl Buffer { | |
| 46 | + /// Creates a new buffer by wrapping a `vaCreateBuffer` call. This is just a helper for | |
| 47 | + /// [`Context::create_buffer`]. | |
| 48 | + pub(crate) fn new(context: Rc<Context>, mut type_: BufferType) -> Result<Self, VaError> { | |
| 49 | + let mut buffer_id = 0; | |
| 50 | + | |
| 51 | + /* we send all slices parameters as a single array in H264, AV1 */ | |
| 52 | + let nb_elements = match type_ { | |
| 53 | + BufferType::SliceParameter(SliceParameter::H264(ref mut params)) => { | |
| 54 | + params.inner_mut().len() | |
| 55 | + } | |
| 56 | + BufferType::SliceParameter(SliceParameter::AV1(ref mut params)) => { | |
| 57 | + params.inner_mut().len() | |
| 58 | + } | |
| 59 | + _ => 1, | |
| 60 | + }; | |
| 61 | + | |
| 62 | + let (ptr, size) = match type_ { | |
| 63 | + 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 | + PictureParameter::VP9(ref mut wrapper) => ( | |
| 73 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 74 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 75 | + ), | |
| 76 | + PictureParameter::H264(ref mut wrapper) => ( | |
| 77 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 78 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 79 | + ), | |
| 80 | + PictureParameter::HEVC(ref mut wrapper) => ( | |
| 81 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 82 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 83 | + ), | |
| 84 | + PictureParameter::HEVCRext(ref mut wrapper) => ( | |
| 85 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 86 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 87 | + ), | |
| 88 | + PictureParameter::HEVCScc(ref mut wrapper) => ( | |
| 89 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 90 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 91 | + ), | |
| 92 | + PictureParameter::AV1(ref mut wrapper) => ( | |
| 93 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 94 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 95 | + ), | |
| 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 | + }, | |
| 105 | + | |
| 106 | + 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 | + SliceParameter::VP9(ref mut wrapper) => ( | |
| 116 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 117 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 118 | + ), | |
| 119 | + SliceParameter::H264(ref mut wrapper) => ( | |
| 120 | + wrapper.inner_mut().as_mut_ptr() as *mut std::ffi::c_void, | |
| 121 | + std::mem::size_of::<bindings::VASliceParameterBufferH264>(), | |
| 122 | + ), | |
| 123 | + SliceParameter::HEVC(ref mut wrapper) => ( | |
| 124 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 125 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 126 | + ), | |
| 127 | + SliceParameter::HEVCRext(ref mut wrapper) => ( | |
| 128 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 129 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 130 | + ), | |
| 131 | + SliceParameter::AV1(ref mut wrapper) => ( | |
| 132 | + wrapper.inner_mut().as_mut_ptr() as *mut std::ffi::c_void, | |
| 133 | + std::mem::size_of::<bindings::VASliceParameterBufferAV1>(), | |
| 134 | + ), | |
| 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 | + }, | |
| 144 | + | |
| 145 | + 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 | + IQMatrix::H264(ref mut wrapper) => ( | |
| 155 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 156 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 157 | + ), | |
| 158 | + IQMatrix::HEVC(ref mut wrapper) => ( | |
| 159 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 160 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 161 | + ), | |
| 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 | + }, | |
| 167 | + | |
| 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 | + | |
| 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 | + | |
| 180 | + BufferType::SliceData(ref mut data) => { | |
| 181 | + (data.as_mut_ptr() as *mut std::ffi::c_void, data.len()) | |
| 182 | + } | |
| 183 | + | |
| 184 | + BufferType::EncSequenceParameter(ref mut seq_param) => match seq_param { | |
| 185 | + EncSequenceParameter::H264(ref mut wrapper) => ( | |
| 186 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 187 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 188 | + ), | |
| 189 | + EncSequenceParameter::HEVC(ref mut wrapper) => ( | |
| 190 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 191 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 192 | + ), | |
| 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 | + EncSequenceParameter::VP9(ref mut wrapper) => ( | |
| 198 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 199 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 200 | + ), | |
| 201 | + EncSequenceParameter::AV1(ref mut wrapper) => ( | |
| 202 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 203 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 204 | + ), | |
| 205 | + }, | |
| 206 | + | |
| 207 | + BufferType::EncPictureParameter(ref mut picture_param) => match picture_param { | |
| 208 | + EncPictureParameter::H264(ref mut wrapper) => ( | |
| 209 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 210 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 211 | + ), | |
| 212 | + EncPictureParameter::HEVC(ref mut wrapper) => ( | |
| 213 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 214 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 215 | + ), | |
| 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 | + EncPictureParameter::VP9(ref mut wrapper) => ( | |
| 221 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 222 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 223 | + ), | |
| 224 | + EncPictureParameter::AV1(ref mut wrapper) => ( | |
| 225 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 226 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 227 | + ), | |
| 228 | + }, | |
| 229 | + | |
| 230 | + BufferType::EncSliceParameter(ref mut slice_param) => match slice_param { | |
| 231 | + EncSliceParameter::H264(ref mut wrapper) => ( | |
| 232 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 233 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 234 | + ), | |
| 235 | + EncSliceParameter::HEVC(ref mut wrapper) => ( | |
| 236 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 237 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 238 | + ), | |
| 239 | + EncSliceParameter::AV1(ref mut wrapper) => ( | |
| 240 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 241 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 242 | + ), | |
| 243 | + }, | |
| 244 | + | |
| 245 | + BufferType::EncMacroblockParameterBuffer(ref mut mb_param) => match mb_param { | |
| 246 | + EncMacroblockParameterBuffer::H264(ref mut wrapper) => ( | |
| 247 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 248 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 249 | + ), | |
| 250 | + }, | |
| 251 | + | |
| 252 | + BufferType::EncCodedBuffer(size) => (std::ptr::null_mut(), size), | |
| 253 | + | |
| 254 | + BufferType::EncMiscParameter(ref mut enc_misc_param) => match enc_misc_param { | |
| 255 | + EncMiscParameter::FrameRate(ref mut wrapper) => ( | |
| 256 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 257 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 258 | + ), | |
| 259 | + EncMiscParameter::RateControl(ref mut wrapper) => ( | |
| 260 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 261 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 262 | + ), | |
| 263 | + EncMiscParameter::MaxSliceSize(ref mut wrapper) => ( | |
| 264 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 265 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 266 | + ), | |
| 267 | + EncMiscParameter::MaxFrameSize(ref mut wrapper) => ( | |
| 268 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 269 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 270 | + ), | |
| 271 | + EncMiscParameter::SkipFrame(ref mut wrapper) => ( | |
| 272 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 273 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 274 | + ), | |
| 275 | + EncMiscParameter::HRD(ref mut wrapper) => ( | |
| 276 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 277 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 278 | + ), | |
| 279 | + EncMiscParameter::QualityLevel(ref mut wrapper) => ( | |
| 280 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 281 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 282 | + ), | |
| 283 | + EncMiscParameter::Quantization(ref mut wrapper) => ( | |
| 284 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 285 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 286 | + ), | |
| 287 | + }, | |
| 288 | + BufferType::ProcPipelineParameter(ref mut proc_pipeline_param) => ( | |
| 289 | + proc_pipeline_param.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 290 | + std::mem::size_of_val(proc_pipeline_param.inner_mut()), | |
| 291 | + ), | |
| 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 | + BufferType::EncPackedHeaderParameter(ref mut wrapper) => ( | |
| 299 | + wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, | |
| 300 | + std::mem::size_of_val(wrapper.inner_mut()), | |
| 301 | + ), | |
| 302 | + | |
| 303 | + BufferType::EncPackedHeaderData(ref data) => { | |
| 304 | + (data.as_ptr() as *mut std::ffi::c_void, data.len()) | |
| 305 | + } | |
| 306 | + }; | |
| 307 | + | |
| 308 | + // Safe because `self` represents a valid `VAContext`. `ptr` and `size` are also ensured to | |
| 309 | + // be correct, as `ptr` is just a cast to `*c_void` from a Rust struct, and `size` is | |
| 310 | + // computed from `std::mem::size_of_val`. | |
| 311 | + va_check(unsafe { | |
| 312 | + bindings::vaCreateBuffer( | |
| 313 | + context.display().handle(), | |
| 314 | + context.id(), | |
| 315 | + type_.inner(), | |
| 316 | + size as u32, | |
| 317 | + nb_elements as u32, | |
| 318 | + ptr, | |
| 319 | + &mut buffer_id, | |
| 320 | + ) | |
| 321 | + })?; | |
| 322 | + | |
| 323 | + Ok(Self { | |
| 324 | + context, | |
| 325 | + id: buffer_id, | |
| 326 | + _params: Some(type_), | |
| 327 | + }) | |
| 328 | + } | |
| 329 | + | |
| 330 | + /// Convenience function to return a `VABufferID` vector from a slice of `Buffer`s in order to | |
| 331 | + /// easily interface with the C API where a buffer array might be needed. | |
| 332 | + pub fn as_id_vec(buffers: &[Self]) -> Vec<bindings::VABufferID> { | |
| 333 | + buffers.iter().map(|buffer| buffer.id).collect() | |
| 334 | + } | |
| 335 | +} | |
| 336 | + | |
| 337 | +/// A borrowed version of `BufferType` that avoids copying data. | |
| 338 | +pub enum BorrowedBufferType<'a> { | |
| 339 | + /// Abstraction over `VASliceDataBufferType` that uses borrowed data. | |
| 340 | + SliceData(&'a [u8]), | |
| 341 | + /// Abstraction over `VAEncPackedHeaderDataBufferType` that uses borrowed data. | |
| 342 | + EncPackedHeaderData(&'a [u8]), | |
| 343 | + /// Abstraction over `VAProtectedSliceDataBufferType` that uses borrowed data. | |
| 344 | + ProtectedSliceDataBuffer(&'a [u8]), | |
| 345 | +} | |
| 346 | + | |
| 347 | +impl<'a> BorrowedBufferType<'a> { | |
| 348 | + /// Returns the inner FFI buffer type. | |
| 349 | + pub(crate) fn inner(&self) -> bindings::VABufferType::Type { | |
| 350 | + match self { | |
| 351 | + BorrowedBufferType::SliceData(_) => bindings::VABufferType::VASliceDataBufferType, | |
| 352 | + BorrowedBufferType::EncPackedHeaderData(_) => { | |
| 353 | + bindings::VABufferType::VAEncPackedHeaderDataBufferType | |
| 354 | + } | |
| 355 | + BorrowedBufferType::ProtectedSliceDataBuffer(_) => { | |
| 356 | + bindings::VABufferType::VAProtectedSliceDataBufferType | |
| 357 | + } | |
| 358 | + } | |
| 359 | + } | |
| 360 | +} | |
| 361 | + | |
| 362 | +impl Buffer { | |
| 363 | + /// Creates a new buffer from a `BorrowedBufferType`. | |
| 364 | + pub(crate) fn new_borrowed( | |
| 365 | + context: Rc<Context>, | |
| 366 | + type_: BorrowedBufferType, | |
| 367 | + ) -> Result<Self, VaError> { | |
| 368 | + let mut buffer_id = 0; | |
| 369 | + | |
| 370 | + let nb_elements = 1; | |
| 371 | + | |
| 372 | + let (ptr, size) = match type_ { | |
| 373 | + BorrowedBufferType::SliceData(data) => { | |
| 374 | + (data.as_ptr() as *mut std::ffi::c_void, data.len()) | |
| 375 | + } | |
| 376 | + BorrowedBufferType::EncPackedHeaderData(data) => { | |
| 377 | + (data.as_ptr() as *mut std::ffi::c_void, data.len()) | |
| 378 | + } | |
| 379 | + BorrowedBufferType::ProtectedSliceDataBuffer(data) => { | |
| 380 | + (data.as_ptr() as *mut std::ffi::c_void, data.len()) | |
| 381 | + } | |
| 382 | + }; | |
| 383 | + | |
| 384 | + // Safe because `self` represents a valid `VAContext`. `ptr` and `size` are also ensured to | |
| 385 | + // be correct. | |
| 386 | + va_check(unsafe { | |
| 387 | + bindings::vaCreateBuffer( | |
| 388 | + context.display().handle(), | |
| 389 | + context.id(), | |
| 390 | + type_.inner(), | |
| 391 | + size as u32, | |
| 392 | + nb_elements as u32, | |
| 393 | + ptr, | |
| 394 | + &mut buffer_id, | |
| 395 | + ) | |
| 396 | + })?; | |
| 397 | + | |
| 398 | + Ok(Self { | |
| 399 | + context, | |
| 400 | + id: buffer_id, | |
| 401 | + _params: None, | |
| 402 | + }) | |
| 403 | + } | |
| 404 | +} | |
| 405 | + | |
| 406 | +impl Drop for Buffer { | |
| 407 | + fn drop(&mut self) { | |
| 408 | + // Safe because `self` represents a valid buffer, created with | |
| 409 | + // vaCreateBuffers. | |
| 410 | + let status = va_check(unsafe { | |
| 411 | + bindings::vaDestroyBuffer(self.context.display().handle(), self.id) | |
| 412 | + }); | |
| 413 | + | |
| 414 | + if status.is_err() { | |
| 415 | + error!("vaDestroyBuffer failed: {}", status.unwrap_err()); | |
| 416 | + } | |
| 417 | + } | |
| 418 | +} | |
| 419 | + | |
| 420 | +/// Abstraction over `VABufferType`s. | |
| 421 | +pub enum BufferType { | |
| 422 | + /// Abstraction over `VAPictureParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, JPEGBaseline. | |
| 423 | + PictureParameter(PictureParameter), | |
| 424 | + /// Abstraction over `VASliceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, JPEGBaseline. | |
| 425 | + SliceParameter(SliceParameter), | |
| 426 | + /// Abstraction over `VAIQMatrixBufferType`. Needed for VP8, H264, JPEGBaseline. | |
| 427 | + IQMatrix(IQMatrix), | |
| 428 | + /// Abstraction over `HuffmanTableBufferType`. Needed for JPEGBaseline. | |
| 429 | + HuffmanTable(HuffmanTable), | |
| 430 | + /// Abstraction over `VAProbabilityDataBufferType`. Needed for VP8. | |
| 431 | + Probability(vp8::ProbabilityDataBufferVP8), | |
| 432 | + /// Abstraction over `VASliceDataBufferType`. Needed for VP9, H264. | |
| 433 | + SliceData(Vec<u8>), | |
| 434 | + /// Abstraction over `VAEncSequenceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. | |
| 435 | + EncSequenceParameter(EncSequenceParameter), | |
| 436 | + /// Abstraction over `VAEncPictureParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. | |
| 437 | + EncPictureParameter(EncPictureParameter), | |
| 438 | + /// Abstraction over `VAEncSliceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. | |
| 439 | + EncSliceParameter(EncSliceParameter), | |
| 440 | + /// Abstraction over `VAEncMacroblockMapBufferType`. Needed for H264. | |
| 441 | + EncMacroblockParameterBuffer(EncMacroblockParameterBuffer), | |
| 442 | + /// Abstraction over `VAEncCodedBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. | |
| 443 | + EncCodedBuffer(usize), | |
| 444 | + /// Abstraction over `VAEncMiscParameterBuffer`. | |
| 445 | + EncMiscParameter(EncMiscParameter), | |
| 446 | + /// Abstraction over `VAProcPipelineParameterBuffer`. | |
| 447 | + ProcPipelineParameter(proc_pipeline::ProcPipelineParameterBuffer), | |
| 448 | + /// Abstraction over `VAQMatrixBufferType`. | |
| 449 | + QMatrix(QMatrix), | |
| 450 | + /// Abstraction over `VAEncPackedHeaderParameterBufferType`. | |
| 451 | + EncPackedHeaderParameter(EncPackedHeaderParameter), | |
| 452 | + /// Abstraction over `VAEncPackedHeaderDataBufferType`. | |
| 453 | + EncPackedHeaderData(Vec<u8>), | |
| 454 | +} | |
| 455 | + | |
| 456 | +impl BufferType { | |
| 457 | + /// Returns the inner FFI buffer type. | |
| 458 | + pub(crate) fn inner(&self) -> bindings::VABufferType::Type { | |
| 459 | + match self { | |
| 460 | + BufferType::PictureParameter(_) => bindings::VABufferType::VAPictureParameterBufferType, | |
| 461 | + BufferType::SliceParameter(_) => bindings::VABufferType::VASliceParameterBufferType, | |
| 462 | + BufferType::IQMatrix(_) => bindings::VABufferType::VAIQMatrixBufferType, | |
| 463 | + BufferType::HuffmanTable(_) => bindings::VABufferType::VAHuffmanTableBufferType, | |
| 464 | + BufferType::Probability(_) => bindings::VABufferType::VAProbabilityBufferType, | |
| 465 | + BufferType::SliceData { .. } => bindings::VABufferType::VASliceDataBufferType, | |
| 466 | + | |
| 467 | + BufferType::EncSequenceParameter(_) => { | |
| 468 | + bindings::VABufferType::VAEncSequenceParameterBufferType | |
| 469 | + } | |
| 470 | + | |
| 471 | + BufferType::EncPictureParameter(_) => { | |
| 472 | + bindings::VABufferType::VAEncPictureParameterBufferType | |
| 473 | + } | |
| 474 | + | |
| 475 | + BufferType::EncSliceParameter(_) => { | |
| 476 | + bindings::VABufferType::VAEncSliceParameterBufferType | |
| 477 | + } | |
| 478 | + | |
| 479 | + BufferType::EncMacroblockParameterBuffer(_) => { | |
| 480 | + bindings::VABufferType::VAEncMacroblockMapBufferType | |
| 481 | + } | |
| 482 | + | |
| 483 | + BufferType::EncCodedBuffer(_) => bindings::VABufferType::VAEncCodedBufferType, | |
| 484 | + | |
| 485 | + BufferType::EncMiscParameter(_) => bindings::VABufferType::VAEncMiscParameterBufferType, | |
| 486 | + | |
| 487 | + BufferType::ProcPipelineParameter(_) => { | |
| 488 | + bindings::VABufferType::VAProcPipelineParameterBufferType | |
| 489 | + } | |
| 490 | + | |
| 491 | + BufferType::QMatrix(_) => bindings::VABufferType::VAQMatrixBufferType, | |
| 492 | + | |
| 493 | + BufferType::EncPackedHeaderParameter(_) => { | |
| 494 | + bindings::VABufferType::VAEncPackedHeaderParameterBufferType | |
| 495 | + } | |
| 496 | + | |
| 497 | + BufferType::EncPackedHeaderData(_) => { | |
| 498 | + bindings::VABufferType::VAEncPackedHeaderDataBufferType | |
| 499 | + } | |
| 500 | + } | |
| 501 | + } | |
| 502 | +} | |
| 503 | + | |
| 504 | +/// Abstraction over the `PictureParameterBuffer` types we support. | |
| 505 | +pub enum PictureParameter { | |
| 506 | + /// Wrapper over VAPictureParameterBufferMPEG2. | |
| 507 | + MPEG2(mpeg2::PictureParameterBufferMPEG2), | |
| 508 | + /// Wrapper over VAPictureParameterBufferVP8. | |
| 509 | + VP8(vp8::PictureParameterBufferVP8), | |
| 510 | + /// Wrapper over VAPictureParameterBufferVP9. | |
| 511 | + VP9(vp9::PictureParameterBufferVP9), | |
| 512 | + /// Wrapper over VAPictureParameterBufferH264. | |
| 513 | + H264(h264::PictureParameterBufferH264), | |
| 514 | + /// Wrapper over VAPictureParameterBufferHEVC | |
| 515 | + HEVC(hevc::PictureParameterBufferHEVC), | |
| 516 | + /// Wrapper over VAPictureParameterBufferHEVCRext | |
| 517 | + HEVCRext(hevc::PictureParameterBufferHEVCRext), | |
| 518 | + /// Wrapper over VAPictureParameterBufferHEVCScc | |
| 519 | + HEVCScc(hevc::PictureParameterBufferHEVCScc), | |
| 520 | + /// Wrapper over VADecPictureParameterBufferAV1 | |
| 521 | + AV1(av1::PictureParameterBufferAV1), | |
| 522 | + /// Wrapper over VAPictureParameterBufferJPEGBaseline | |
| 523 | + JPEGBaseline(jpeg_baseline::PictureParameterBufferJPEGBaseline), | |
| 524 | + /// Wrapper over VAEncPictureParameterBufferJPEG | |
| 525 | + EncJPEG(enc_jpeg::EncPictureParameterBufferJPEG), | |
| 526 | +} | |
| 527 | + | |
| 528 | +/// Abstraction over the `SliceParameterBuffer` types we support | |
| 529 | +pub enum SliceParameter { | |
| 530 | + /// Wrapper over VASliceParameterBufferMPEG2 | |
| 531 | + MPEG2(mpeg2::SliceParameterBufferMPEG2), | |
| 532 | + /// Wrapper over VASliceParameterBufferVP8 | |
| 533 | + VP8(vp8::SliceParameterBufferVP8), | |
| 534 | + /// Wrapper over VASliceParameterBufferVP9 | |
| 535 | + VP9(vp9::SliceParameterBufferVP9), | |
| 536 | + /// Wrapper over VASliceParameterBufferH264 | |
| 537 | + H264(h264::SliceParameterBufferH264), | |
| 538 | + /// Wrapper over VASliceParameterBufferHEVC | |
| 539 | + HEVC(hevc::SliceParameterBufferHEVC), | |
| 540 | + /// Wrapper over VASliceParameterBufferHEVCRext | |
| 541 | + HEVCRext(hevc::SliceParameterBufferHEVCRext), | |
| 542 | + /// Wrapper over VASliceParameterBufferAV1 | |
| 543 | + AV1(av1::SliceParameterBufferAV1), | |
| 544 | + /// Wrapper over VASliceParameterBufferJPEGBaseline | |
| 545 | + JPEGBaseline(jpeg_baseline::SliceParameterBufferJPEGBaseline), | |
| 546 | + /// Wrapper over VAEncSliceParameterBufferJPEG | |
| 547 | + EncJpeg(enc_jpeg::EncSliceParameterBufferJPEG), | |
| 548 | +} | |
| 549 | + | |
| 550 | +/// Abstraction over the `IQMatrixBuffer` types we support. | |
| 551 | +pub enum IQMatrix { | |
| 552 | + /// Abstraction over `VAIQMatrixBufferMPEG2` | |
| 553 | + MPEG2(mpeg2::IQMatrixBufferMPEG2), | |
| 554 | + /// Abstraction over `VAIQMatrixBufferVP8` | |
| 555 | + VP8(vp8::IQMatrixBufferVP8), | |
| 556 | + /// Abstraction over `VAIQMatrixBufferH264` | |
| 557 | + H264(h264::IQMatrixBufferH264), | |
| 558 | + /// Abstraction over `VAIQMatrixBufferHEVC` | |
| 559 | + HEVC(hevc::IQMatrixBufferHEVC), | |
| 560 | + /// Abstraction over `VAIQMatrixBufferJPEGBaseline`` | |
| 561 | + JPEGBaseline(jpeg_baseline::IQMatrixBufferJPEGBaseline), | |
| 562 | +} | |
| 563 | + | |
| 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 | + | |
| 576 | +/// Abstraction over the `EncSequenceParameter` types we support. | |
| 577 | +pub enum EncSequenceParameter { | |
| 578 | + /// Abstraction over `VAEncSequenceParameterBufferH264` | |
| 579 | + H264(h264::EncSequenceParameterBufferH264), | |
| 580 | + /// Abstraction over `VAEncSequenceParameterBufferHEVC` | |
| 581 | + HEVC(hevc::EncSequenceParameterBufferHEVC), | |
| 582 | + /// Abstraction over `VAEncSequenceParameterBufferVP8` | |
| 583 | + VP8(vp8::EncSequenceParameterBufferVP8), | |
| 584 | + /// Abstraction over `VAEncSequenceParameterBufferVP9` | |
| 585 | + VP9(vp9::EncSequenceParameterBufferVP9), | |
| 586 | + /// Abstraction over `VAEncSequenceParameterBufferAV1` | |
| 587 | + AV1(av1::EncSequenceParameterBufferAV1), | |
| 588 | +} | |
| 589 | + | |
| 590 | +/// Abstraction over the `EncPictureParameter` types we support. | |
| 591 | +pub enum EncPictureParameter { | |
| 592 | + /// Abstraction over `VAEncPictureParameterBufferH264` | |
| 593 | + H264(h264::EncPictureParameterBufferH264), | |
| 594 | + /// Abstraction over `VAEncPictureParameterBufferHEVC` | |
| 595 | + HEVC(hevc::EncPictureParameterBufferHEVC), | |
| 596 | + /// Abstraction over `VAEncPictureParameterBufferVP8` | |
| 597 | + VP8(vp8::EncPictureParameterBufferVP8), | |
| 598 | + /// Abstraction over `VAEncPictureParameterBufferVP9` | |
| 599 | + VP9(vp9::EncPictureParameterBufferVP9), | |
| 600 | + /// Abstraction over `VAEncPictureParameterBufferAV1` | |
| 601 | + AV1(av1::EncPictureParameterBufferAV1), | |
| 602 | +} | |
| 603 | + | |
| 604 | +/// Abstraction over the `EncSliceParameter` types we support. | |
| 605 | +pub enum EncSliceParameter { | |
| 606 | + /// Abstraction over `VAEncSliceParameterBufferH264` | |
| 607 | + H264(h264::EncSliceParameterBufferH264), | |
| 608 | + /// Abstraction over `VAEncSliceParameterBufferHEVC` | |
| 609 | + HEVC(hevc::EncSliceParameterBufferHEVC), | |
| 610 | + /// Abstraction over `VAEncTileGroupBufferAV1` | |
| 611 | + AV1(av1::EncTileGroupBufferAV1), | |
| 612 | +} | |
| 613 | + | |
| 614 | +/// Abstraction over the `EncMacroblockParameterBuffer` types we support. | |
| 615 | +pub enum EncMacroblockParameterBuffer { | |
| 616 | + /// Abstraction over `VAEncMacroblockParameterBufferH264` | |
| 617 | + H264(h264::EncMacroblockParameterBufferH264), | |
| 618 | +} | |
| 619 | + | |
| 620 | +/// Wrapper type representing a buffer created with `vaCreateBuffer` with VAEncCodedBufferType. | |
| 621 | +pub struct EncCodedBuffer(Buffer); | |
| 622 | + | |
| 623 | +impl EncCodedBuffer { | |
| 624 | + pub(crate) fn new(context: Rc<Context>, size: usize) -> Result<Self, VaError> { | |
| 625 | + Ok(Self(Buffer::new( | |
| 626 | + context, | |
| 627 | + BufferType::EncCodedBuffer(size), | |
| 628 | + )?)) | |
| 629 | + } | |
| 630 | + | |
| 631 | + /// Convenience function to return buffer's `VABufferID`. | |
| 632 | + pub fn id(&self) -> bindings::VABufferID { | |
| 633 | + self.0.id | |
| 634 | + } | |
| 635 | +} | |
| 636 | + | |
| 637 | +/// Helper to access a single segment of mapped coded buffer | |
| 638 | +pub struct MappedCodedSegment<'s> { | |
| 639 | + pub bit_offset: u32, | |
| 640 | + pub status: u32, | |
| 641 | + pub buf: &'s [u8], | |
| 642 | +} | |
| 643 | + | |
| 644 | +/// Helper to access segments of mapped coded buffer | |
| 645 | +pub struct MappedCodedBuffer<'p> { | |
| 646 | + segments: Vec<MappedCodedSegment<'p>>, | |
| 647 | + buffer: &'p EncCodedBuffer, | |
| 648 | +} | |
| 649 | + | |
| 650 | +impl<'p> MappedCodedBuffer<'p> { | |
| 651 | + /// Map a 'VAEncCodedBufferType' buffer. | |
| 652 | + pub fn new(buffer: &'p EncCodedBuffer) -> Result<Self, VaError> { | |
| 653 | + let mut addr = std::ptr::null_mut(); | |
| 654 | + let mut segments = Vec::new(); | |
| 655 | + | |
| 656 | + va_check(unsafe { | |
| 657 | + bindings::vaMapBuffer(buffer.0.context.display().handle(), buffer.id(), &mut addr) | |
| 658 | + })?; | |
| 659 | + | |
| 660 | + while !addr.is_null() { | |
| 661 | + let segment: &bindings::VACodedBufferSegment = | |
| 662 | + unsafe { &*(addr as *const bindings::VACodedBufferSegment) }; | |
| 663 | + | |
| 664 | + let size = segment.size; | |
| 665 | + let buf = segment.buf; | |
| 666 | + | |
| 667 | + let buf = unsafe { std::slice::from_raw_parts(buf as *mut u8, size as usize) }; | |
| 668 | + | |
| 669 | + segments.push(MappedCodedSegment { | |
| 670 | + bit_offset: segment.bit_offset, | |
| 671 | + status: segment.status, | |
| 672 | + buf, | |
| 673 | + }); | |
| 674 | + | |
| 675 | + addr = segment.next; | |
| 676 | + } | |
| 677 | + | |
| 678 | + Ok(Self { segments, buffer }) | |
| 679 | + } | |
| 680 | + | |
| 681 | + /// Returns the iterator over segments | |
| 682 | + pub fn iter(&self) -> impl Iterator<Item = &MappedCodedSegment<'p>> { | |
| 683 | + self.segments.iter() | |
| 684 | + } | |
| 685 | + | |
| 686 | + /// Returns the segments of mapped coded buffers. | |
| 687 | + pub fn segments(&self) -> &Vec<MappedCodedSegment<'p>> { | |
| 688 | + &self.segments | |
| 689 | + } | |
| 690 | +} | |
| 691 | + | |
| 692 | +impl<'p> Drop for MappedCodedBuffer<'p> { | |
| 693 | + fn drop(&mut self) { | |
| 694 | + let status = va_check(unsafe { | |
| 695 | + bindings::vaUnmapBuffer(self.buffer.0.context.display().handle(), self.buffer.id()) | |
| 696 | + }); | |
| 697 | + | |
| 698 | + if status.is_err() { | |
| 699 | + error!("vaUnmapBuffer failed: {}", status.unwrap_err()); | |
| 700 | + } | |
| 701 | + } | |
| 702 | +} | |
| 703 | + | |
| 704 | +/// Abstraction over the `EncMiscParameterBuffer` types we support. | |
| 705 | +pub enum EncMiscParameter { | |
| 706 | + /// Wrapper over `VAEncMiscParameterBuffer` with `VAEncMiscParameterFrameRate`. | |
| 707 | + FrameRate(EncMiscParameterFrameRate), | |
| 708 | + /// Wrapper over `VAEncMiscParameterBuffer` with `VAEncMiscParameterRateControl`. | |
| 709 | + RateControl(EncMiscParameterRateControl), | |
| 710 | + /// Wrapper over `VAEncMiscParameterBuffer` with `VAEncMiscParameterMaxSliceSize`. | |
| 711 | + MaxSliceSize(EncMiscParameterMaxSliceSize), | |
| 712 | + /// Wrapper over `VAEncMiscParameterBuffer` with `VAEncMiscParameterBufferMaxFrameSize`. | |
| 713 | + MaxFrameSize(EncMiscParameterBufferMaxFrameSize), | |
| 714 | + /// Wrapper over `VAEncMiscParameterBuffer` with `VAEncMiscParameterSkipFrame`. | |
| 715 | + SkipFrame(EncMiscParameterSkipFrame), | |
| 716 | + /// Wrapper over `VAEncMiscParameterBuffer` with `VAEncMiscParameterHRD`. | |
| 717 | + HRD(EncMiscParameterHRD), | |
| 718 | + /// Wrapper over `VAEncMiscParameterBuffer` with `VAEncMiscParameterBufferQualityLevel`. | |
| 719 | + QualityLevel(EncMiscParameterBufferQualityLevel), | |
| 720 | + /// Wrapper over `VAEncMiscParameterBuffer` with `VAEncMiscParameterQuantization`. | |
| 721 | + Quantization(EncMiscParameterQuantization), | |
| 722 | +} | |
| 723 | + | |
| 724 | +/// Abstraction over the `VAEncPackedHeaderType` enum values we support. | |
| 725 | +#[repr(u32)] | |
| 726 | +pub enum EncPackedHeaderType { | |
| 727 | + /// Sequence header | |
| 728 | + Sequence = bindings::VAEncPackedHeaderType::VAEncPackedHeaderSequence, | |
| 729 | + /// Picture header | |
| 730 | + Picture = bindings::VAEncPackedHeaderType::VAEncPackedHeaderPicture, | |
| 731 | + /// Slice header | |
| 732 | + Slice = bindings::VAEncPackedHeaderType::VAEncPackedHeaderSlice, | |
| 733 | + /// Raw data | |
| 734 | + RawData = bindings::VAEncPackedHeaderType::VAEncPackedHeaderRawData, | |
| 735 | +} | |
| 736 | + | |
| 737 | +/// Abstraction over `EncPackedHeaderParameterBuffer` types we support | |
| 738 | +pub struct EncPackedHeaderParameter(Box<bindings::VAEncPackedHeaderParameterBuffer>); | |
| 739 | + | |
| 740 | +impl EncPackedHeaderParameter { | |
| 741 | + /// Creates a new `EncPackedHeaderParameter` from the given `VAEncPackedHeaderParameterBuffer`. | |
| 742 | + pub fn new(type_: EncPackedHeaderType, length_in_bits: u32, has_emulation: bool) -> Self { | |
| 743 | + Self(Box::new(bindings::VAEncPackedHeaderParameterBuffer { | |
| 744 | + type_: type_ as _, | |
| 745 | + bit_length: length_in_bits, | |
| 746 | + has_emulation_bytes: has_emulation as u8, | |
| 747 | + ..Default::default() | |
| 748 | + })) | |
| 749 | + } | |
| 750 | + | |
| 751 | + /// Returns a mutable reference to the inner `VAEncPackedHeaderParameterBuffer`. | |
| 752 | + pub fn inner_mut(&mut self) -> &mut bindings::VAEncPackedHeaderParameterBuffer { | |
| 753 | + &mut self.0 | |
| 754 | + } | |
| 755 | +} |
shims/cros-libva/src/buffer/av1.rsadded+1156 -0
| @@ -0,0 +1,1156 @@ | ||
| 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 AV1 `VABuffer` types. | |
| 6 | + | |
| 7 | +use crate::bindings; | |
| 8 | + | |
| 9 | +/// Wrapper over the `seq_fields` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 10 | +pub struct AV1SeqFields(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_1); | |
| 11 | + | |
| 12 | +impl AV1SeqFields { | |
| 13 | + /// Creates the bindgen field | |
| 14 | + #[allow(clippy::too_many_arguments)] | |
| 15 | + pub fn new( | |
| 16 | + still_picture: u32, | |
| 17 | + use_128x128_superblock: u32, | |
| 18 | + enable_filter_intra: u32, | |
| 19 | + enable_intra_edge_filter: u32, | |
| 20 | + enable_interintra_compound: u32, | |
| 21 | + enable_masked_compound: u32, | |
| 22 | + enable_dual_filter: u32, | |
| 23 | + enable_order_hint: u32, | |
| 24 | + enable_jnt_comp: u32, | |
| 25 | + enable_cdef: u32, | |
| 26 | + mono_chrome: u32, | |
| 27 | + color_range: u32, | |
| 28 | + subsampling_x: u32, | |
| 29 | + subsampling_y: u32, | |
| 30 | + chroma_sample_position: u32, | |
| 31 | + film_grain_params_present: u32, | |
| 32 | + ) -> Self { | |
| 33 | + let _bitfield_1 = | |
| 34 | + bindings::_VADecPictureParameterBufferAV1__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 35 | + still_picture, | |
| 36 | + use_128x128_superblock, | |
| 37 | + enable_filter_intra, | |
| 38 | + enable_intra_edge_filter, | |
| 39 | + enable_interintra_compound, | |
| 40 | + enable_masked_compound, | |
| 41 | + enable_dual_filter, | |
| 42 | + enable_order_hint, | |
| 43 | + enable_jnt_comp, | |
| 44 | + enable_cdef, | |
| 45 | + mono_chrome, | |
| 46 | + color_range, | |
| 47 | + subsampling_x, | |
| 48 | + subsampling_y, | |
| 49 | + chroma_sample_position, | |
| 50 | + film_grain_params_present, | |
| 51 | + 0, | |
| 52 | + ); | |
| 53 | + | |
| 54 | + Self(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_1 { | |
| 55 | + fields: bindings::_VADecPictureParameterBufferAV1__bindgen_ty_1__bindgen_ty_1 { | |
| 56 | + _bitfield_align_1: Default::default(), | |
| 57 | + _bitfield_1, | |
| 58 | + }, | |
| 59 | + }) | |
| 60 | + } | |
| 61 | +} | |
| 62 | + | |
| 63 | +/// Wrapper over the `segment_info_fields` bindgen field in `VASegmentationStructAV1`. | |
| 64 | +pub struct AV1SegmentInfoFields(bindings::_VASegmentationStructAV1__bindgen_ty_1); | |
| 65 | + | |
| 66 | +impl AV1SegmentInfoFields { | |
| 67 | + /// Creates the bindgen field | |
| 68 | + pub fn new(enabled: u32, update_map: u32, temporal_update: u32, update_data: u32) -> Self { | |
| 69 | + let _bitfield_1 = | |
| 70 | + bindings::_VASegmentationStructAV1__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 71 | + enabled, | |
| 72 | + update_map, | |
| 73 | + temporal_update, | |
| 74 | + update_data, | |
| 75 | + 0, | |
| 76 | + ); | |
| 77 | + | |
| 78 | + Self(bindings::_VASegmentationStructAV1__bindgen_ty_1 { | |
| 79 | + bits: bindings::_VASegmentationStructAV1__bindgen_ty_1__bindgen_ty_1 { | |
| 80 | + _bitfield_align_1: Default::default(), | |
| 81 | + _bitfield_1, | |
| 82 | + }, | |
| 83 | + }) | |
| 84 | + } | |
| 85 | +} | |
| 86 | + | |
| 87 | +/// Wrapper over the `seg_info` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 88 | +pub struct AV1Segmentation(bindings::VASegmentationStructAV1); | |
| 89 | + | |
| 90 | +impl AV1Segmentation { | |
| 91 | + /// Creates the bindgen field | |
| 92 | + pub fn new( | |
| 93 | + segment_info_fields: &AV1SegmentInfoFields, | |
| 94 | + feature_data: [[i16; 8usize]; 8usize], | |
| 95 | + feature_mask: [u8; 8usize], | |
| 96 | + ) -> Self { | |
| 97 | + let segment_info_fields = segment_info_fields.0; | |
| 98 | + Self(bindings::VASegmentationStructAV1 { | |
| 99 | + segment_info_fields, | |
| 100 | + feature_data, | |
| 101 | + feature_mask, | |
| 102 | + va_reserved: Default::default(), | |
| 103 | + }) | |
| 104 | + } | |
| 105 | +} | |
| 106 | + | |
| 107 | +/// Wrapper over the `film_grain_fields` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 108 | +pub struct AV1FilmGrainFields(bindings::_VAFilmGrainStructAV1__bindgen_ty_1); | |
| 109 | + | |
| 110 | +impl AV1FilmGrainFields { | |
| 111 | + /// Creates the bindgen field | |
| 112 | + #[allow(clippy::too_many_arguments)] | |
| 113 | + pub fn new( | |
| 114 | + apply_grain: u32, | |
| 115 | + chroma_scaling_from_luma: u32, | |
| 116 | + grain_scaling_minus_8: u32, | |
| 117 | + ar_coeff_lag: u32, | |
| 118 | + ar_coeff_shift_minus_6: u32, | |
| 119 | + grain_scale_shift: u32, | |
| 120 | + overlap_flag: u32, | |
| 121 | + clip_to_restricted_range: u32, | |
| 122 | + ) -> Self { | |
| 123 | + let _bitfield_1 = | |
| 124 | + bindings::_VAFilmGrainStructAV1__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 125 | + apply_grain, | |
| 126 | + chroma_scaling_from_luma, | |
| 127 | + grain_scaling_minus_8, | |
| 128 | + ar_coeff_lag, | |
| 129 | + ar_coeff_shift_minus_6, | |
| 130 | + grain_scale_shift, | |
| 131 | + overlap_flag, | |
| 132 | + clip_to_restricted_range, | |
| 133 | + 0, | |
| 134 | + ); | |
| 135 | + Self(bindings::_VAFilmGrainStructAV1__bindgen_ty_1 { | |
| 136 | + bits: bindings::_VAFilmGrainStructAV1__bindgen_ty_1__bindgen_ty_1 { | |
| 137 | + _bitfield_align_1: Default::default(), | |
| 138 | + _bitfield_1, | |
| 139 | + }, | |
| 140 | + }) | |
| 141 | + } | |
| 142 | +} | |
| 143 | + | |
| 144 | +/// Wrapper over the `film_grain_info` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 145 | +pub struct AV1FilmGrain(bindings::VAFilmGrainStructAV1); | |
| 146 | + | |
| 147 | +impl AV1FilmGrain { | |
| 148 | + /// Creates the wrapper | |
| 149 | + #[allow(clippy::too_many_arguments)] | |
| 150 | + pub fn new( | |
| 151 | + film_grain_info_fields: &AV1FilmGrainFields, | |
| 152 | + grain_seed: u16, | |
| 153 | + num_y_points: u8, | |
| 154 | + point_y_value: [u8; 14usize], | |
| 155 | + point_y_scaling: [u8; 14usize], | |
| 156 | + num_cb_points: u8, | |
| 157 | + point_cb_value: [u8; 10usize], | |
| 158 | + point_cb_scaling: [u8; 10usize], | |
| 159 | + num_cr_points: u8, | |
| 160 | + point_cr_value: [u8; 10usize], | |
| 161 | + point_cr_scaling: [u8; 10usize], | |
| 162 | + ar_coeffs_y: [i8; 24usize], | |
| 163 | + ar_coeffs_cb: [i8; 25usize], | |
| 164 | + ar_coeffs_cr: [i8; 25usize], | |
| 165 | + cb_mult: u8, | |
| 166 | + cb_luma_mult: u8, | |
| 167 | + cb_offset: u16, | |
| 168 | + cr_mult: u8, | |
| 169 | + cr_luma_mult: u8, | |
| 170 | + cr_offset: u16, | |
| 171 | + ) -> Self { | |
| 172 | + let film_grain_info_fields = film_grain_info_fields.0; | |
| 173 | + Self(bindings::VAFilmGrainStructAV1 { | |
| 174 | + film_grain_info_fields, | |
| 175 | + grain_seed, | |
| 176 | + num_y_points, | |
| 177 | + point_y_value, | |
| 178 | + point_y_scaling, | |
| 179 | + num_cb_points, | |
| 180 | + point_cb_value, | |
| 181 | + point_cb_scaling, | |
| 182 | + num_cr_points, | |
| 183 | + point_cr_value, | |
| 184 | + point_cr_scaling, | |
| 185 | + ar_coeffs_y, | |
| 186 | + ar_coeffs_cb, | |
| 187 | + ar_coeffs_cr, | |
| 188 | + cb_mult, | |
| 189 | + cb_luma_mult, | |
| 190 | + cb_offset, | |
| 191 | + cr_mult, | |
| 192 | + cr_luma_mult, | |
| 193 | + cr_offset, | |
| 194 | + va_reserved: Default::default(), | |
| 195 | + }) | |
| 196 | + } | |
| 197 | +} | |
| 198 | + | |
| 199 | +/// Wrapper over the `pic_info_fields` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 200 | +pub struct AV1PicInfoFields(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_2); | |
| 201 | + | |
| 202 | +impl AV1PicInfoFields { | |
| 203 | + /// Creates the wrapper | |
| 204 | + #[allow(clippy::too_many_arguments)] | |
| 205 | + pub fn new( | |
| 206 | + frame_type: u32, | |
| 207 | + show_frame: u32, | |
| 208 | + showable_frame: u32, | |
| 209 | + error_resilient_mode: u32, | |
| 210 | + disable_cdf_update: u32, | |
| 211 | + allow_screen_content_tools: u32, | |
| 212 | + force_integer_mv: u32, | |
| 213 | + allow_intrabc: u32, | |
| 214 | + use_superres: u32, | |
| 215 | + allow_high_precision_mv: u32, | |
| 216 | + is_motion_mode_switchable: u32, | |
| 217 | + use_ref_frame_mvs: u32, | |
| 218 | + disable_frame_end_update_cdf: u32, | |
| 219 | + uniform_tile_spacing_flag: u32, | |
| 220 | + allow_warped_motion: u32, | |
| 221 | + large_scale_tile: u32, | |
| 222 | + ) -> Self { | |
| 223 | + let _bitfield_1 = | |
| 224 | + bindings::_VADecPictureParameterBufferAV1__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
| 225 | + frame_type, | |
| 226 | + show_frame, | |
| 227 | + showable_frame, | |
| 228 | + error_resilient_mode, | |
| 229 | + disable_cdf_update, | |
| 230 | + allow_screen_content_tools, | |
| 231 | + force_integer_mv, | |
| 232 | + allow_intrabc, | |
| 233 | + use_superres, | |
| 234 | + allow_high_precision_mv, | |
| 235 | + is_motion_mode_switchable, | |
| 236 | + use_ref_frame_mvs, | |
| 237 | + disable_frame_end_update_cdf, | |
| 238 | + uniform_tile_spacing_flag, | |
| 239 | + allow_warped_motion, | |
| 240 | + large_scale_tile, | |
| 241 | + 0, | |
| 242 | + ); | |
| 243 | + Self(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_2 { | |
| 244 | + bits: bindings::_VADecPictureParameterBufferAV1__bindgen_ty_2__bindgen_ty_1 { | |
| 245 | + _bitfield_align_1: Default::default(), | |
| 246 | + _bitfield_1, | |
| 247 | + }, | |
| 248 | + }) | |
| 249 | + } | |
| 250 | +} | |
| 251 | + | |
| 252 | +/// Wrapper over the `loop_filter_fields` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 253 | +pub struct AV1LoopFilterFields(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_3); | |
| 254 | + | |
| 255 | +impl AV1LoopFilterFields { | |
| 256 | + /// Creates the wrapper | |
| 257 | + pub fn new(sharpness_level: u8, mode_ref_delta_enabled: u8, mode_ref_delta_update: u8) -> Self { | |
| 258 | + let _bitfield_1 = | |
| 259 | + bindings::_VADecPictureParameterBufferAV1__bindgen_ty_3__bindgen_ty_1::new_bitfield_1( | |
| 260 | + sharpness_level, | |
| 261 | + mode_ref_delta_enabled, | |
| 262 | + mode_ref_delta_update, | |
| 263 | + 0, | |
| 264 | + ); | |
| 265 | + Self(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_3 { | |
| 266 | + bits: bindings::_VADecPictureParameterBufferAV1__bindgen_ty_3__bindgen_ty_1 { | |
| 267 | + _bitfield_align_1: Default::default(), | |
| 268 | + _bitfield_1, | |
| 269 | + }, | |
| 270 | + }) | |
| 271 | + } | |
| 272 | +} | |
| 273 | + | |
| 274 | +/// Wrapper over the `wm` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 275 | +pub struct AV1WarpedMotionParams(bindings::VAWarpedMotionParamsAV1); | |
| 276 | + | |
| 277 | +impl AV1WarpedMotionParams { | |
| 278 | + /// Creates the wrapper | |
| 279 | + pub fn new( | |
| 280 | + wmtype: bindings::VAAV1TransformationType::Type, | |
| 281 | + wmmat: [i32; 8], | |
| 282 | + invalid: u8, | |
| 283 | + ) -> Self { | |
| 284 | + Self(bindings::VAWarpedMotionParamsAV1 { | |
| 285 | + wmtype, | |
| 286 | + wmmat, | |
| 287 | + invalid, | |
| 288 | + va_reserved: Default::default(), | |
| 289 | + }) | |
| 290 | + } | |
| 291 | +} | |
| 292 | + | |
| 293 | +/// Wrapper over the `loop_restoration_fields` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 294 | +pub struct AV1LoopRestorationFields(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_6); | |
| 295 | + | |
| 296 | +impl AV1LoopRestorationFields { | |
| 297 | + /// Creates the wrapper | |
| 298 | + pub fn new( | |
| 299 | + yframe_restoration_type: u16, | |
| 300 | + cbframe_restoration_type: u16, | |
| 301 | + crframe_restoration_type: u16, | |
| 302 | + lr_unit_shift: u16, | |
| 303 | + lr_uv_shift: u16, | |
| 304 | + ) -> Self { | |
| 305 | + let _bitfield_1 = | |
| 306 | + bindings::_VADecPictureParameterBufferAV1__bindgen_ty_6__bindgen_ty_1::new_bitfield_1( | |
| 307 | + yframe_restoration_type, | |
| 308 | + cbframe_restoration_type, | |
| 309 | + crframe_restoration_type, | |
| 310 | + lr_unit_shift, | |
| 311 | + lr_uv_shift, | |
| 312 | + 0, | |
| 313 | + ); | |
| 314 | + Self(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_6 { | |
| 315 | + bits: bindings::_VADecPictureParameterBufferAV1__bindgen_ty_6__bindgen_ty_1 { | |
| 316 | + _bitfield_align_1: Default::default(), | |
| 317 | + _bitfield_1, | |
| 318 | + }, | |
| 319 | + }) | |
| 320 | + } | |
| 321 | +} | |
| 322 | + | |
| 323 | +/// Wrapper over the `mode_control_fields` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 324 | +pub struct AV1ModeControlFields(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_5); | |
| 325 | + | |
| 326 | +impl AV1ModeControlFields { | |
| 327 | + /// Creates the wrapper | |
| 328 | + #[allow(clippy::too_many_arguments)] | |
| 329 | + pub fn new( | |
| 330 | + delta_q_present_flag: u32, | |
| 331 | + log2_delta_q_res: u32, | |
| 332 | + delta_lf_present_flag: u32, | |
| 333 | + log2_delta_lf_res: u32, | |
| 334 | + delta_lf_multi: u32, | |
| 335 | + tx_mode: u32, | |
| 336 | + reference_select: u32, | |
| 337 | + reduced_tx_set_used: u32, | |
| 338 | + skip_mode_present: u32, | |
| 339 | + ) -> Self { | |
| 340 | + let _bitfield_1 = | |
| 341 | + bindings::_VADecPictureParameterBufferAV1__bindgen_ty_5__bindgen_ty_1::new_bitfield_1( | |
| 342 | + delta_q_present_flag, | |
| 343 | + log2_delta_q_res, | |
| 344 | + delta_lf_present_flag, | |
| 345 | + log2_delta_lf_res, | |
| 346 | + delta_lf_multi, | |
| 347 | + tx_mode, | |
| 348 | + reference_select, | |
| 349 | + reduced_tx_set_used, | |
| 350 | + skip_mode_present, | |
| 351 | + 0, | |
| 352 | + ); | |
| 353 | + Self(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_5 { | |
| 354 | + bits: bindings::_VADecPictureParameterBufferAV1__bindgen_ty_5__bindgen_ty_1 { | |
| 355 | + _bitfield_align_1: Default::default(), | |
| 356 | + _bitfield_1, | |
| 357 | + }, | |
| 358 | + }) | |
| 359 | + } | |
| 360 | +} | |
| 361 | + | |
| 362 | +/// Wrapper over the `qmatrix_fields` bindgen field in `VADecPictureParameterBufferAV1`. | |
| 363 | +pub struct AV1QMatrixFields(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_4); | |
| 364 | + | |
| 365 | +impl AV1QMatrixFields { | |
| 366 | + /// Creates the wrapper | |
| 367 | + pub fn new(using_qmatrix: u16, qm_y: u16, qm_u: u16, qm_v: u16) -> Self { | |
| 368 | + let _bitfield_1 = | |
| 369 | + bindings::_VADecPictureParameterBufferAV1__bindgen_ty_4__bindgen_ty_1::new_bitfield_1( | |
| 370 | + using_qmatrix, | |
| 371 | + qm_y, | |
| 372 | + qm_u, | |
| 373 | + qm_v, | |
| 374 | + 0, | |
| 375 | + ); | |
| 376 | + Self(bindings::_VADecPictureParameterBufferAV1__bindgen_ty_4 { | |
| 377 | + bits: bindings::_VADecPictureParameterBufferAV1__bindgen_ty_4__bindgen_ty_1 { | |
| 378 | + _bitfield_align_1: Default::default(), | |
| 379 | + _bitfield_1, | |
| 380 | + }, | |
| 381 | + }) | |
| 382 | + } | |
| 383 | +} | |
| 384 | + | |
| 385 | +/// A wrapper over `VADecPictureParameterBufferAV1` FFI type | |
| 386 | +pub struct PictureParameterBufferAV1(Box<bindings::VADecPictureParameterBufferAV1>); | |
| 387 | + | |
| 388 | +impl PictureParameterBufferAV1 { | |
| 389 | + /// Creates the wrapper | |
| 390 | + #[allow(clippy::too_many_arguments)] | |
| 391 | + pub fn new( | |
| 392 | + profile: u8, | |
| 393 | + order_hint_bits_minus_1: u8, | |
| 394 | + bit_depth_idx: u8, | |
| 395 | + matrix_coefficients: u8, | |
| 396 | + seq_info_fields: &AV1SeqFields, | |
| 397 | + current_frame: bindings::VASurfaceID, | |
| 398 | + current_display_picture: bindings::VASurfaceID, | |
| 399 | + mut anchor_frames_list: Vec<bindings::VASurfaceID>, | |
| 400 | + frame_width_minus1: u16, | |
| 401 | + frame_height_minus1: u16, | |
| 402 | + output_frame_width_in_tiles_minus_1: u16, | |
| 403 | + output_frame_height_in_tiles_minus_1: u16, | |
| 404 | + ref_frame_map: [bindings::VASurfaceID; 8usize], | |
| 405 | + ref_frame_idx: [u8; 7usize], | |
| 406 | + primary_ref_frame: u8, | |
| 407 | + order_hint: u8, | |
| 408 | + seg_info: &AV1Segmentation, | |
| 409 | + film_grain_info: &AV1FilmGrain, | |
| 410 | + tile_cols: u8, | |
| 411 | + tile_rows: u8, | |
| 412 | + width_in_sbs_minus_1: [u16; 63usize], | |
| 413 | + height_in_sbs_minus_1: [u16; 63usize], | |
| 414 | + tile_count_minus_1: u16, | |
| 415 | + context_update_tile_id: u16, | |
| 416 | + pic_info_fields: &AV1PicInfoFields, | |
| 417 | + superres_scale_denominator: u8, | |
| 418 | + interp_filter: u8, | |
| 419 | + filter_level: [u8; 2usize], | |
| 420 | + filter_level_u: u8, | |
| 421 | + filter_level_v: u8, | |
| 422 | + loop_filter_info_fields: &AV1LoopFilterFields, | |
| 423 | + ref_deltas: [i8; 8usize], | |
| 424 | + mode_deltas: [i8; 2usize], | |
| 425 | + base_qindex: u8, | |
| 426 | + y_dc_delta_q: i8, | |
| 427 | + u_dc_delta_q: i8, | |
| 428 | + u_ac_delta_q: i8, | |
| 429 | + v_dc_delta_q: i8, | |
| 430 | + v_ac_delta_q: i8, | |
| 431 | + qmatrix_fields: &AV1QMatrixFields, | |
| 432 | + mode_control_fields: &AV1ModeControlFields, | |
| 433 | + cdef_damping_minus_3: u8, | |
| 434 | + cdef_bits: u8, | |
| 435 | + cdef_y_strengths: [u8; 8usize], | |
| 436 | + cdef_uv_strengths: [u8; 8usize], | |
| 437 | + loop_restoration_fields: &AV1LoopRestorationFields, | |
| 438 | + wm: &[AV1WarpedMotionParams; 7usize], | |
| 439 | + ) -> Self { | |
| 440 | + let seq_info_fields = seq_info_fields.0; | |
| 441 | + let seg_info = seg_info.0; | |
| 442 | + let pic_info_fields = pic_info_fields.0; | |
| 443 | + let loop_filter_info_fields = loop_filter_info_fields.0; | |
| 444 | + let qmatrix_fields = qmatrix_fields.0; | |
| 445 | + let mode_control_fields = mode_control_fields.0; | |
| 446 | + | |
| 447 | + let anchor_frames_num = anchor_frames_list.len() as u8; | |
| 448 | + let anchor_frames_list = anchor_frames_list.as_mut_ptr(); | |
| 449 | + | |
| 450 | + let film_grain_info = film_grain_info.0; | |
| 451 | + let loop_restoration_fields = loop_restoration_fields.0; | |
| 452 | + | |
| 453 | + // Will not panic, as the arrays are the same size. | |
| 454 | + let wm = wm | |
| 455 | + .iter() | |
| 456 | + .map(|wm| wm.0) | |
| 457 | + .collect::<Vec<_>>() | |
| 458 | + .try_into() | |
| 459 | + .unwrap(); | |
| 460 | + | |
| 461 | + Self(Box::new(bindings::VADecPictureParameterBufferAV1 { | |
| 462 | + profile, | |
| 463 | + order_hint_bits_minus_1, | |
| 464 | + bit_depth_idx, | |
| 465 | + matrix_coefficients, | |
| 466 | + seq_info_fields, | |
| 467 | + current_frame, | |
| 468 | + current_display_picture, | |
| 469 | + anchor_frames_num, | |
| 470 | + anchor_frames_list, | |
| 471 | + frame_width_minus1, | |
| 472 | + frame_height_minus1, | |
| 473 | + output_frame_width_in_tiles_minus_1, | |
| 474 | + output_frame_height_in_tiles_minus_1, | |
| 475 | + ref_frame_map, | |
| 476 | + ref_frame_idx, | |
| 477 | + primary_ref_frame, | |
| 478 | + order_hint, | |
| 479 | + seg_info, | |
| 480 | + film_grain_info, | |
| 481 | + tile_cols, | |
| 482 | + tile_rows, | |
| 483 | + width_in_sbs_minus_1, | |
| 484 | + height_in_sbs_minus_1, | |
| 485 | + tile_count_minus_1, | |
| 486 | + context_update_tile_id, | |
| 487 | + pic_info_fields, | |
| 488 | + superres_scale_denominator, | |
| 489 | + interp_filter, | |
| 490 | + filter_level, | |
| 491 | + filter_level_u, | |
| 492 | + filter_level_v, | |
| 493 | + loop_filter_info_fields, | |
| 494 | + ref_deltas, | |
| 495 | + mode_deltas, | |
| 496 | + base_qindex, | |
| 497 | + y_dc_delta_q, | |
| 498 | + u_dc_delta_q, | |
| 499 | + u_ac_delta_q, | |
| 500 | + v_dc_delta_q, | |
| 501 | + v_ac_delta_q, | |
| 502 | + qmatrix_fields, | |
| 503 | + mode_control_fields, | |
| 504 | + cdef_damping_minus_3, | |
| 505 | + cdef_bits, | |
| 506 | + cdef_y_strengths, | |
| 507 | + cdef_uv_strengths, | |
| 508 | + loop_restoration_fields, | |
| 509 | + wm, | |
| 510 | + va_reserved: Default::default(), | |
| 511 | + })) | |
| 512 | + } | |
| 513 | + | |
| 514 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VADecPictureParameterBufferAV1 { | |
| 515 | + self.0.as_mut() | |
| 516 | + } | |
| 517 | +} | |
| 518 | + | |
| 519 | +/// A wrapper over an array of the `VASliceParameterBufferAV1` FFI type. This | |
| 520 | +/// allows for passing all tile parameters in a single call if multiple tiles | |
| 521 | +/// are present in the tile group. | |
| 522 | +#[derive(Default)] | |
| 523 | +pub struct SliceParameterBufferAV1(Vec<bindings::VASliceParameterBufferAV1>); | |
| 524 | + | |
| 525 | +impl SliceParameterBufferAV1 { | |
| 526 | + /// Creates the wrapper | |
| 527 | + pub fn new() -> Self { | |
| 528 | + Default::default() | |
| 529 | + } | |
| 530 | + | |
| 531 | + /// Adds a slice parameter to the wrapper | |
| 532 | + #[allow(clippy::too_many_arguments)] | |
| 533 | + pub fn add_slice_parameter( | |
| 534 | + &mut self, | |
| 535 | + slice_data_size: u32, | |
| 536 | + slice_data_offset: u32, | |
| 537 | + slice_data_flag: u32, | |
| 538 | + tile_row: u16, | |
| 539 | + tile_column: u16, | |
| 540 | + tg_start: u16, | |
| 541 | + tg_end: u16, | |
| 542 | + anchor_frame_idx: u8, | |
| 543 | + tile_idx_in_tile_list: u16, | |
| 544 | + ) { | |
| 545 | + self.0.push(bindings::VASliceParameterBufferAV1 { | |
| 546 | + slice_data_size, | |
| 547 | + slice_data_offset, | |
| 548 | + slice_data_flag, | |
| 549 | + tile_row, | |
| 550 | + tile_column, | |
| 551 | + tg_start, | |
| 552 | + tg_end, | |
| 553 | + anchor_frame_idx, | |
| 554 | + tile_idx_in_tile_list, | |
| 555 | + va_reserved: Default::default(), | |
| 556 | + }); | |
| 557 | + } | |
| 558 | + | |
| 559 | + pub(crate) fn inner_mut(&mut self) -> &mut Vec<bindings::VASliceParameterBufferAV1> { | |
| 560 | + self.0.as_mut() | |
| 561 | + } | |
| 562 | +} | |
| 563 | + | |
| 564 | +pub struct AV1EncSeqFields(bindings::_VAEncSequenceParameterBufferAV1__bindgen_ty_1); | |
| 565 | + | |
| 566 | +impl AV1EncSeqFields { | |
| 567 | + pub fn new( | |
| 568 | + still_picture: bool, | |
| 569 | + use_128x128_superblock: bool, | |
| 570 | + enable_filter_intra: bool, | |
| 571 | + enable_intra_edge_filter: bool, | |
| 572 | + enable_interintra_compound: bool, | |
| 573 | + enable_masked_compound: bool, | |
| 574 | + enable_warped_motion: bool, | |
| 575 | + enable_dual_filter: bool, | |
| 576 | + enable_order_hint: bool, | |
| 577 | + enable_jnt_comp: bool, | |
| 578 | + enable_ref_frame_mvs: bool, | |
| 579 | + enable_superres: bool, | |
| 580 | + enable_cdef: bool, | |
| 581 | + enable_restoration: bool, | |
| 582 | + bit_depth_minus8: u32, | |
| 583 | + subsampling_x: bool, | |
| 584 | + subsampling_y: bool, | |
| 585 | + mono_chrome: bool, | |
| 586 | + ) -> Self { | |
| 587 | + let still_picture = still_picture as u32; | |
| 588 | + let use_128x128_superblock = use_128x128_superblock as u32; | |
| 589 | + let enable_filter_intra = enable_filter_intra as u32; | |
| 590 | + let enable_intra_edge_filter = enable_intra_edge_filter as u32; | |
| 591 | + let enable_interintra_compound = enable_interintra_compound as u32; | |
| 592 | + let enable_masked_compound = enable_masked_compound as u32; | |
| 593 | + let enable_warped_motion = enable_warped_motion as u32; | |
| 594 | + let enable_dual_filter = enable_dual_filter as u32; | |
| 595 | + let enable_order_hint = enable_order_hint as u32; | |
| 596 | + let enable_jnt_comp = enable_jnt_comp as u32; | |
| 597 | + let enable_ref_frame_mvs = enable_ref_frame_mvs as u32; | |
| 598 | + let enable_superres = enable_superres as u32; | |
| 599 | + let enable_cdef = enable_cdef as u32; | |
| 600 | + let enable_restoration = enable_restoration as u32; | |
| 601 | + let subsampling_x = subsampling_x as u32; | |
| 602 | + let subsampling_y = subsampling_y as u32; | |
| 603 | + let mono_chrome = mono_chrome as u32; | |
| 604 | + | |
| 605 | + let _bitfield_1 = | |
| 606 | + bindings::_VAEncSequenceParameterBufferAV1__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 607 | + still_picture, | |
| 608 | + use_128x128_superblock, | |
| 609 | + enable_filter_intra, | |
| 610 | + enable_intra_edge_filter, | |
| 611 | + enable_interintra_compound, | |
| 612 | + enable_masked_compound, | |
| 613 | + enable_warped_motion, | |
| 614 | + enable_dual_filter, | |
| 615 | + enable_order_hint, | |
| 616 | + enable_jnt_comp, | |
| 617 | + enable_ref_frame_mvs, | |
| 618 | + enable_superres, | |
| 619 | + enable_cdef, | |
| 620 | + enable_restoration, | |
| 621 | + bit_depth_minus8, | |
| 622 | + subsampling_x, | |
| 623 | + subsampling_y, | |
| 624 | + #[cfg(libva_1_19_or_higher)] | |
| 625 | + mono_chrome, | |
| 626 | + Default::default(), | |
| 627 | + ); | |
| 628 | + | |
| 629 | + Self(bindings::_VAEncSequenceParameterBufferAV1__bindgen_ty_1 { | |
| 630 | + bits: bindings::_VAEncSequenceParameterBufferAV1__bindgen_ty_1__bindgen_ty_1 { | |
| 631 | + _bitfield_align_1: Default::default(), | |
| 632 | + _bitfield_1, | |
| 633 | + }, | |
| 634 | + }) | |
| 635 | + } | |
| 636 | +} | |
| 637 | + | |
| 638 | +#[derive(Default)] | |
| 639 | +pub struct EncSequenceParameterBufferAV1(Box<bindings::VAEncSequenceParameterBufferAV1>); | |
| 640 | + | |
| 641 | +impl EncSequenceParameterBufferAV1 { | |
| 642 | + pub fn new( | |
| 643 | + seq_profile: u8, | |
| 644 | + seq_level_idx: u8, | |
| 645 | + seq_tier: u8, | |
| 646 | + hierarchical_flag: u8, | |
| 647 | + intra_period: u32, | |
| 648 | + ip_period: u32, | |
| 649 | + bits_per_second: u32, | |
| 650 | + seq_fields: &AV1EncSeqFields, | |
| 651 | + order_hint_bits_minus_1: u8, | |
| 652 | + ) -> Self { | |
| 653 | + let seq_fields = seq_fields.0; | |
| 654 | + | |
| 655 | + Self(Box::new(bindings::_VAEncSequenceParameterBufferAV1 { | |
| 656 | + seq_profile, | |
| 657 | + seq_level_idx, | |
| 658 | + seq_tier, | |
| 659 | + #[cfg(libva_1_16_or_higher)] | |
| 660 | + hierarchical_flag, | |
| 661 | + intra_period, | |
| 662 | + ip_period, | |
| 663 | + bits_per_second, | |
| 664 | + seq_fields, | |
| 665 | + order_hint_bits_minus_1, | |
| 666 | + ..Default::default() | |
| 667 | + })) | |
| 668 | + } | |
| 669 | + | |
| 670 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSequenceParameterBufferAV1 { | |
| 671 | + &mut self.0 | |
| 672 | + } | |
| 673 | +} | |
| 674 | + | |
| 675 | +#[derive(Default)] | |
| 676 | +pub struct RefFrameCtrlAV1(bindings::VARefFrameCtrlAV1); | |
| 677 | + | |
| 678 | +impl RefFrameCtrlAV1 { | |
| 679 | + pub fn new( | |
| 680 | + search_idx0: u32, | |
| 681 | + search_idx1: u32, | |
| 682 | + search_idx2: u32, | |
| 683 | + search_idx3: u32, | |
| 684 | + search_idx4: u32, | |
| 685 | + search_idx5: u32, | |
| 686 | + search_idx6: u32, | |
| 687 | + ) -> Self { | |
| 688 | + let _bitfield_1 = bindings::VARefFrameCtrlAV1__bindgen_ty_1::new_bitfield_1( | |
| 689 | + search_idx0, | |
| 690 | + search_idx1, | |
| 691 | + search_idx2, | |
| 692 | + search_idx3, | |
| 693 | + search_idx4, | |
| 694 | + search_idx5, | |
| 695 | + search_idx6, | |
| 696 | + Default::default(), | |
| 697 | + ); | |
| 698 | + | |
| 699 | + Self(bindings::VARefFrameCtrlAV1 { | |
| 700 | + fields: bindings::VARefFrameCtrlAV1__bindgen_ty_1 { | |
| 701 | + _bitfield_align_1: Default::default(), | |
| 702 | + _bitfield_1, | |
| 703 | + }, | |
| 704 | + }) | |
| 705 | + } | |
| 706 | +} | |
| 707 | + | |
| 708 | +#[derive(Default)] | |
| 709 | +pub struct AV1EncPictureFlags(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_1); | |
| 710 | + | |
| 711 | +impl AV1EncPictureFlags { | |
| 712 | + pub fn new( | |
| 713 | + frame_type: u32, | |
| 714 | + error_resilient_mode: bool, | |
| 715 | + disable_cdf_update: bool, | |
| 716 | + use_superres: bool, | |
| 717 | + allow_high_precision_mv: bool, | |
| 718 | + use_ref_frame_mvs: bool, | |
| 719 | + disable_frame_end_update_cdf: bool, | |
| 720 | + reduced_tx_set: bool, | |
| 721 | + enable_frame_obu: bool, | |
| 722 | + long_term_reference: bool, | |
| 723 | + disable_frame_recon: bool, | |
| 724 | + allow_intrabc: bool, | |
| 725 | + palette_mode_enable: bool, | |
| 726 | + allow_screen_content_tools: bool, | |
| 727 | + force_integer_mv: bool, | |
| 728 | + ) -> Self { | |
| 729 | + let error_resilient_mode = error_resilient_mode as u32; | |
| 730 | + let disable_cdf_update = disable_cdf_update as u32; | |
| 731 | + let use_superres = use_superres as u32; | |
| 732 | + let allow_high_precision_mv = allow_high_precision_mv as u32; | |
| 733 | + let use_ref_frame_mvs = use_ref_frame_mvs as u32; | |
| 734 | + let disable_frame_end_update_cdf = disable_frame_end_update_cdf as u32; | |
| 735 | + let reduced_tx_set = reduced_tx_set as u32; | |
| 736 | + let enable_frame_obu = enable_frame_obu as u32; | |
| 737 | + let long_term_reference = long_term_reference as u32; | |
| 738 | + let disable_frame_recon = disable_frame_recon as u32; | |
| 739 | + let allow_intrabc = allow_intrabc as u32; | |
| 740 | + let palette_mode_enable = palette_mode_enable as u32; | |
| 741 | + #[cfg(libva_1_21_or_higher)] | |
| 742 | + let allow_screen_content_tools = allow_screen_content_tools as u32; | |
| 743 | + #[cfg(libva_1_21_or_higher)] | |
| 744 | + let force_integer_mv = force_integer_mv as u32; | |
| 745 | + | |
| 746 | + let _bitfield_1 = { | |
| 747 | + bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 748 | + frame_type, | |
| 749 | + error_resilient_mode, | |
| 750 | + disable_cdf_update, | |
| 751 | + use_superres, | |
| 752 | + allow_high_precision_mv, | |
| 753 | + use_ref_frame_mvs, | |
| 754 | + disable_frame_end_update_cdf, | |
| 755 | + reduced_tx_set, | |
| 756 | + enable_frame_obu, | |
| 757 | + long_term_reference, | |
| 758 | + disable_frame_recon, | |
| 759 | + allow_intrabc, | |
| 760 | + palette_mode_enable, | |
| 761 | + #[cfg(libva_1_21_or_higher)] | |
| 762 | + allow_screen_content_tools, | |
| 763 | + #[cfg(libva_1_21_or_higher)] | |
| 764 | + force_integer_mv, | |
| 765 | + Default::default(), | |
| 766 | + ) | |
| 767 | + }; | |
| 768 | + Self(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_1 { | |
| 769 | + bits: bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_1__bindgen_ty_1 { | |
| 770 | + _bitfield_align_1: Default::default(), | |
| 771 | + _bitfield_1, | |
| 772 | + }, | |
| 773 | + }) | |
| 774 | + } | |
| 775 | +} | |
| 776 | + | |
| 777 | +#[derive(Default)] | |
| 778 | +pub struct AV1EncLoopFilterFlags(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_2); | |
| 779 | + | |
| 780 | +impl AV1EncLoopFilterFlags { | |
| 781 | + pub fn new( | |
| 782 | + sharpness_level: u8, | |
| 783 | + mode_ref_delta_enabled: bool, | |
| 784 | + mode_ref_delta_update: bool, | |
| 785 | + ) -> Self { | |
| 786 | + let mode_ref_delta_enabled = mode_ref_delta_enabled as u8; | |
| 787 | + let mode_ref_delta_update = mode_ref_delta_update as u8; | |
| 788 | + | |
| 789 | + let _bitfield_1 = | |
| 790 | + bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
| 791 | + sharpness_level, | |
| 792 | + mode_ref_delta_enabled, | |
| 793 | + mode_ref_delta_update, | |
| 794 | + Default::default(), | |
| 795 | + ); | |
| 796 | + | |
| 797 | + Self(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_2 { | |
| 798 | + bits: bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_2__bindgen_ty_1 { | |
| 799 | + _bitfield_align_1: Default::default(), | |
| 800 | + _bitfield_1, | |
| 801 | + }, | |
| 802 | + }) | |
| 803 | + } | |
| 804 | +} | |
| 805 | + | |
| 806 | +#[derive(Default)] | |
| 807 | +pub struct AV1EncQMatrixFlags(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_3); | |
| 808 | + | |
| 809 | +impl AV1EncQMatrixFlags { | |
| 810 | + pub fn new(using_qmatrix: bool, qm_y: u16, qm_u: u16, qm_v: u16) -> Self { | |
| 811 | + let using_qmatrix = using_qmatrix as u16; | |
| 812 | + | |
| 813 | + let _bitfield_1 = | |
| 814 | + bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_3__bindgen_ty_1::new_bitfield_1( | |
| 815 | + using_qmatrix, | |
| 816 | + qm_y, | |
| 817 | + qm_u, | |
| 818 | + qm_v, | |
| 819 | + Default::default(), | |
| 820 | + ); | |
| 821 | + | |
| 822 | + Self(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_3 { | |
| 823 | + bits: bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_3__bindgen_ty_1 { | |
| 824 | + _bitfield_1, | |
| 825 | + _bitfield_align_1: Default::default(), | |
| 826 | + }, | |
| 827 | + }) | |
| 828 | + } | |
| 829 | +} | |
| 830 | + | |
| 831 | +#[derive(Default)] | |
| 832 | +pub struct AV1EncModeControlFlags(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_4); | |
| 833 | + | |
| 834 | +impl AV1EncModeControlFlags { | |
| 835 | + pub fn new( | |
| 836 | + delta_q_present: bool, | |
| 837 | + delta_q_res: u32, | |
| 838 | + delta_lf_present: bool, | |
| 839 | + delta_lf_res: u32, | |
| 840 | + delta_lf_multi: bool, | |
| 841 | + tx_mode: u32, | |
| 842 | + reference_mode: u32, | |
| 843 | + skip_mode_present: bool, | |
| 844 | + ) -> Self { | |
| 845 | + let delta_q_present = delta_q_present as u32; | |
| 846 | + let delta_lf_present = delta_lf_present as u32; | |
| 847 | + let delta_lf_multi = delta_lf_multi as u32; | |
| 848 | + let skip_mode_present = skip_mode_present as u32; | |
| 849 | + | |
| 850 | + let _bitfield_1 = | |
| 851 | + bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_4__bindgen_ty_1::new_bitfield_1( | |
| 852 | + delta_q_present, | |
| 853 | + delta_q_res, | |
| 854 | + delta_lf_present, | |
| 855 | + delta_lf_res, | |
| 856 | + delta_lf_multi, | |
| 857 | + tx_mode, | |
| 858 | + reference_mode, | |
| 859 | + skip_mode_present, | |
| 860 | + Default::default(), | |
| 861 | + ); | |
| 862 | + | |
| 863 | + Self(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_4 { | |
| 864 | + bits: bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_4__bindgen_ty_1 { | |
| 865 | + _bitfield_align_1: Default::default(), | |
| 866 | + _bitfield_1, | |
| 867 | + }, | |
| 868 | + }) | |
| 869 | + } | |
| 870 | +} | |
| 871 | + | |
| 872 | +#[derive(Default)] | |
| 873 | +pub struct EncSegParamFlagsAV1(bindings::_VAEncSegParamAV1__bindgen_ty_1); | |
| 874 | + | |
| 875 | +impl EncSegParamFlagsAV1 { | |
| 876 | + pub fn new( | |
| 877 | + segmentation_enabled: bool, | |
| 878 | + segmentation_update_map: bool, | |
| 879 | + segmentation_temporal_update: bool, | |
| 880 | + ) -> Self { | |
| 881 | + let segmentation_enabled = segmentation_enabled as u8; | |
| 882 | + let segmentation_update_map = segmentation_update_map as u8; | |
| 883 | + let segmentation_temporal_update = segmentation_temporal_update as u8; | |
| 884 | + | |
| 885 | + let _bitfield_1 = bindings::_VAEncSegParamAV1__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 886 | + segmentation_enabled, | |
| 887 | + segmentation_update_map, | |
| 888 | + segmentation_temporal_update, | |
| 889 | + Default::default(), | |
| 890 | + ); | |
| 891 | + | |
| 892 | + Self(bindings::_VAEncSegParamAV1__bindgen_ty_1 { | |
| 893 | + bits: bindings::_VAEncSegParamAV1__bindgen_ty_1__bindgen_ty_1 { | |
| 894 | + _bitfield_align_1: Default::default(), | |
| 895 | + _bitfield_1, | |
| 896 | + }, | |
| 897 | + }) | |
| 898 | + } | |
| 899 | +} | |
| 900 | + | |
| 901 | +#[derive(Default)] | |
| 902 | +pub struct EncSegParamAV1(bindings::VAEncSegParamAV1); | |
| 903 | + | |
| 904 | +impl EncSegParamAV1 { | |
| 905 | + pub fn new( | |
| 906 | + seg_flags: &EncSegParamFlagsAV1, | |
| 907 | + segment_number: u8, | |
| 908 | + feature_data: [[i16; 8usize]; 8usize], | |
| 909 | + feature_mask: [u8; 8usize], | |
| 910 | + ) -> Self { | |
| 911 | + let seg_flags = seg_flags.0; | |
| 912 | + | |
| 913 | + Self(bindings::_VAEncSegParamAV1 { | |
| 914 | + seg_flags, | |
| 915 | + segment_number, | |
| 916 | + feature_data, | |
| 917 | + feature_mask, | |
| 918 | + va_reserved: Default::default(), | |
| 919 | + }) | |
| 920 | + } | |
| 921 | +} | |
| 922 | + | |
| 923 | +pub struct AV1EncLoopRestorationFlags(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_5); | |
| 924 | + | |
| 925 | +impl AV1EncLoopRestorationFlags { | |
| 926 | + pub fn new( | |
| 927 | + yframe_restoration_type: u16, | |
| 928 | + cbframe_restoration_type: u16, | |
| 929 | + crframe_restoration_type: u16, | |
| 930 | + lr_unit_shift: u16, | |
| 931 | + lr_uv_shift: bool, | |
| 932 | + ) -> Self { | |
| 933 | + let lr_uv_shift = lr_uv_shift as u16; | |
| 934 | + | |
| 935 | + let _bitfield_1 = | |
| 936 | + bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_5__bindgen_ty_1::new_bitfield_1( | |
| 937 | + yframe_restoration_type, | |
| 938 | + cbframe_restoration_type, | |
| 939 | + crframe_restoration_type, | |
| 940 | + lr_unit_shift, | |
| 941 | + lr_uv_shift, | |
| 942 | + Default::default(), | |
| 943 | + ); | |
| 944 | + | |
| 945 | + Self(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_5 { | |
| 946 | + bits: bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_5__bindgen_ty_1 { | |
| 947 | + _bitfield_align_1: Default::default(), | |
| 948 | + _bitfield_1, | |
| 949 | + }, | |
| 950 | + }) | |
| 951 | + } | |
| 952 | +} | |
| 953 | + | |
| 954 | +#[derive(Default, Copy, Clone)] | |
| 955 | +pub struct EncWarpedMotionParamsAV1(bindings::VAEncWarpedMotionParamsAV1); | |
| 956 | + | |
| 957 | +impl EncWarpedMotionParamsAV1 { | |
| 958 | + pub fn new( | |
| 959 | + wmtype: bindings::VAEncTransformationTypeAV1::Type, | |
| 960 | + wmmat: [i32; 8usize], | |
| 961 | + invalid: u8, | |
| 962 | + ) -> Self { | |
| 963 | + Self(bindings::_VAEncWarpedMotionParamsAV1 { | |
| 964 | + wmtype, | |
| 965 | + wmmat, | |
| 966 | + invalid, | |
| 967 | + va_reserved: Default::default(), | |
| 968 | + }) | |
| 969 | + } | |
| 970 | +} | |
| 971 | + | |
| 972 | +pub struct AV1EncTileGroupObuHdrInfo(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_6); | |
| 973 | + | |
| 974 | +impl AV1EncTileGroupObuHdrInfo { | |
| 975 | + pub fn new( | |
| 976 | + obu_extension_flag: bool, | |
| 977 | + obu_has_size_field: bool, | |
| 978 | + temporal_id: u8, | |
| 979 | + spatial_id: u8, | |
| 980 | + ) -> Self { | |
| 981 | + let obu_extension_flag = obu_extension_flag as u8; | |
| 982 | + let obu_has_size_field = obu_has_size_field as u8; | |
| 983 | + | |
| 984 | + let _bitfield_1 = | |
| 985 | + bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_6__bindgen_ty_1::new_bitfield_1( | |
| 986 | + obu_extension_flag, | |
| 987 | + obu_has_size_field, | |
| 988 | + temporal_id, | |
| 989 | + spatial_id, | |
| 990 | + Default::default(), | |
| 991 | + ); | |
| 992 | + | |
| 993 | + Self(bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_6 { | |
| 994 | + bits: bindings::_VAEncPictureParameterBufferAV1__bindgen_ty_6__bindgen_ty_1 { | |
| 995 | + _bitfield_align_1: Default::default(), | |
| 996 | + _bitfield_1, | |
| 997 | + }, | |
| 998 | + }) | |
| 999 | + } | |
| 1000 | +} | |
| 1001 | + | |
| 1002 | +#[derive(Default)] | |
| 1003 | +pub struct EncPictureParameterBufferAV1(Box<bindings::VAEncPictureParameterBufferAV1>); | |
| 1004 | + | |
| 1005 | +impl EncPictureParameterBufferAV1 { | |
| 1006 | + pub fn new( | |
| 1007 | + frame_width_minus_1: u16, | |
| 1008 | + frame_height_minus_1: u16, | |
| 1009 | + reconstructed_frame: bindings::VASurfaceID, | |
| 1010 | + coded_buf: bindings::VABufferID, | |
| 1011 | + reference_frames: [bindings::VASurfaceID; 8usize], | |
| 1012 | + ref_frame_idx: [u8; 7usize], | |
| 1013 | + hierarchical_level_plus1: u8, | |
| 1014 | + primary_ref_frame: u8, | |
| 1015 | + order_hint: u8, | |
| 1016 | + refresh_frame_flags: u8, | |
| 1017 | + ref_frame_ctrl_l0: &RefFrameCtrlAV1, | |
| 1018 | + ref_frame_ctrl_l1: &RefFrameCtrlAV1, | |
| 1019 | + picture_flags: &AV1EncPictureFlags, | |
| 1020 | + seg_id_block_size: u8, | |
| 1021 | + num_tile_groups_minus1: u8, | |
| 1022 | + temporal_id: u8, | |
| 1023 | + filter_level: [u8; 2usize], | |
| 1024 | + filter_level_u: u8, | |
| 1025 | + filter_level_v: u8, | |
| 1026 | + loop_filter_flags: &AV1EncLoopFilterFlags, | |
| 1027 | + superres_scale_denominator: u8, | |
| 1028 | + interpolation_filter: u8, | |
| 1029 | + ref_deltas: [i8; 8usize], | |
| 1030 | + mode_deltas: [i8; 2usize], | |
| 1031 | + base_qindex: u8, | |
| 1032 | + y_dc_delta_q: i8, | |
| 1033 | + u_dc_delta_q: i8, | |
| 1034 | + u_ac_delta_q: i8, | |
| 1035 | + v_dc_delta_q: i8, | |
| 1036 | + v_ac_delta_q: i8, | |
| 1037 | + min_base_qindex: u8, | |
| 1038 | + max_base_qindex: u8, | |
| 1039 | + qmatrix_flags: &AV1EncQMatrixFlags, | |
| 1040 | + mode_control_flags: &AV1EncModeControlFlags, | |
| 1041 | + segments: &EncSegParamAV1, | |
| 1042 | + tile_cols: u8, | |
| 1043 | + tile_rows: u8, | |
| 1044 | + width_in_sbs_minus_1: [u16; 63usize], | |
| 1045 | + height_in_sbs_minus_1: [u16; 63usize], | |
| 1046 | + context_update_tile_id: u16, | |
| 1047 | + cdef_damping_minus_3: u8, | |
| 1048 | + cdef_bits: u8, | |
| 1049 | + cdef_y_strengths: [u8; 8usize], | |
| 1050 | + cdef_uv_strengths: [u8; 8usize], | |
| 1051 | + loop_restoration_flags: &AV1EncLoopRestorationFlags, | |
| 1052 | + wm: [EncWarpedMotionParamsAV1; 7usize], | |
| 1053 | + bit_offset_qindex: u32, | |
| 1054 | + bit_offset_segmentation: u32, | |
| 1055 | + bit_offset_loopfilter_params: u32, | |
| 1056 | + bit_offset_cdef_params: u32, | |
| 1057 | + size_in_bits_cdef_params: u32, | |
| 1058 | + byte_offset_frame_hdr_obu_size: u32, | |
| 1059 | + size_in_bits_frame_hdr_obu: u32, | |
| 1060 | + tile_group_obu_hdr_info: &AV1EncTileGroupObuHdrInfo, | |
| 1061 | + number_skip_frames: u8, | |
| 1062 | + skip_frames_reduced_size: i32, | |
| 1063 | + ) -> Self { | |
| 1064 | + let ref_frame_ctrl_l0 = ref_frame_ctrl_l0.0; | |
| 1065 | + let ref_frame_ctrl_l1 = ref_frame_ctrl_l1.0; | |
| 1066 | + let picture_flags = picture_flags.0; | |
| 1067 | + let loop_filter_flags = loop_filter_flags.0; | |
| 1068 | + let qmatrix_flags = qmatrix_flags.0; | |
| 1069 | + let mode_control_flags = mode_control_flags.0; | |
| 1070 | + let segments = segments.0; | |
| 1071 | + let loop_restoration_flags = loop_restoration_flags.0; | |
| 1072 | + let wm = wm.map(|e| e.0); | |
| 1073 | + let tile_group_obu_hdr_info = tile_group_obu_hdr_info.0; | |
| 1074 | + | |
| 1075 | + Self(Box::new(bindings::_VAEncPictureParameterBufferAV1 { | |
| 1076 | + frame_width_minus_1, | |
| 1077 | + frame_height_minus_1, | |
| 1078 | + reconstructed_frame, | |
| 1079 | + coded_buf, | |
| 1080 | + reference_frames, | |
| 1081 | + ref_frame_idx, | |
| 1082 | + #[cfg(libva_1_19_or_higher)] | |
| 1083 | + hierarchical_level_plus1, | |
| 1084 | + primary_ref_frame, | |
| 1085 | + order_hint, | |
| 1086 | + refresh_frame_flags, | |
| 1087 | + ref_frame_ctrl_l0, | |
| 1088 | + ref_frame_ctrl_l1, | |
| 1089 | + picture_flags, | |
| 1090 | + seg_id_block_size, | |
| 1091 | + num_tile_groups_minus1, | |
| 1092 | + temporal_id, | |
| 1093 | + filter_level, | |
| 1094 | + filter_level_u, | |
| 1095 | + filter_level_v, | |
| 1096 | + loop_filter_flags, | |
| 1097 | + superres_scale_denominator, | |
| 1098 | + interpolation_filter, | |
| 1099 | + ref_deltas, | |
| 1100 | + mode_deltas, | |
| 1101 | + base_qindex, | |
| 1102 | + y_dc_delta_q, | |
| 1103 | + u_dc_delta_q, | |
| 1104 | + u_ac_delta_q, | |
| 1105 | + v_dc_delta_q, | |
| 1106 | + v_ac_delta_q, | |
| 1107 | + min_base_qindex, | |
| 1108 | + max_base_qindex, | |
| 1109 | + qmatrix_flags, | |
| 1110 | + mode_control_flags, | |
| 1111 | + segments, | |
| 1112 | + tile_cols, | |
| 1113 | + tile_rows, | |
| 1114 | + width_in_sbs_minus_1, | |
| 1115 | + height_in_sbs_minus_1, | |
| 1116 | + context_update_tile_id, | |
| 1117 | + cdef_damping_minus_3, | |
| 1118 | + cdef_bits, | |
| 1119 | + cdef_y_strengths, | |
| 1120 | + cdef_uv_strengths, | |
| 1121 | + loop_restoration_flags, | |
| 1122 | + wm, | |
| 1123 | + bit_offset_qindex, | |
| 1124 | + bit_offset_segmentation, | |
| 1125 | + bit_offset_loopfilter_params, | |
| 1126 | + bit_offset_cdef_params, | |
| 1127 | + size_in_bits_cdef_params, | |
| 1128 | + byte_offset_frame_hdr_obu_size, | |
| 1129 | + size_in_bits_frame_hdr_obu, | |
| 1130 | + tile_group_obu_hdr_info, | |
| 1131 | + number_skip_frames, | |
| 1132 | + skip_frames_reduced_size, | |
| 1133 | + ..Default::default() | |
| 1134 | + })) | |
| 1135 | + } | |
| 1136 | + | |
| 1137 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferAV1 { | |
| 1138 | + &mut self.0 | |
| 1139 | + } | |
| 1140 | +} | |
| 1141 | + | |
| 1142 | +pub struct EncTileGroupBufferAV1(Box<bindings::VAEncTileGroupBufferAV1>); | |
| 1143 | + | |
| 1144 | +impl EncTileGroupBufferAV1 { | |
| 1145 | + pub fn new(tg_start: u8, tg_end: u8) -> Self { | |
| 1146 | + Self(Box::new(bindings::VAEncTileGroupBufferAV1 { | |
| 1147 | + tg_start, | |
| 1148 | + tg_end, | |
| 1149 | + va_reserved: Default::default(), | |
| 1150 | + })) | |
| 1151 | + } | |
| 1152 | + | |
| 1153 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncTileGroupBufferAV1 { | |
| 1154 | + &mut self.0 | |
| 1155 | + } | |
| 1156 | +} |
shims/cros-libva/src/buffer/enc_jpeg.rsadded+159 -0
| @@ -0,0 +1,159 @@ | ||
| 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/enc_misc.rsadded+337 -0
| @@ -0,0 +1,337 @@ | ||
| 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 | +//! Wrappers around `VAEncMisc*` types. | |
| 6 | + | |
| 7 | +use crate::bindings; | |
| 8 | + | |
| 9 | +#[repr(C)] | |
| 10 | +#[derive(Default)] | |
| 11 | +pub struct MiscEncParamBuffer<T> { | |
| 12 | + hdr: bindings::VAEncMiscParameterBuffer, | |
| 13 | + value: T, | |
| 14 | +} | |
| 15 | + | |
| 16 | +impl<T> MiscEncParamBuffer<T> { | |
| 17 | + fn new(type_: bindings::VAEncMiscParameterType::Type, value: T) -> Self { | |
| 18 | + Self { | |
| 19 | + hdr: bindings::_VAEncMiscParameterBuffer { | |
| 20 | + type_, | |
| 21 | + data: Default::default(), | |
| 22 | + }, | |
| 23 | + value, | |
| 24 | + } | |
| 25 | + } | |
| 26 | + | |
| 27 | + fn new_boxed(type_: bindings::VAEncMiscParameterType::Type, value: T) -> Box<Self> { | |
| 28 | + Box::new(Self::new(type_, value)) | |
| 29 | + } | |
| 30 | +} | |
| 31 | + | |
| 32 | +#[derive(Default)] | |
| 33 | +pub struct EncMiscParameterFrameRate( | |
| 34 | + Box<MiscEncParamBuffer<bindings::VAEncMiscParameterFrameRate>>, | |
| 35 | +); | |
| 36 | + | |
| 37 | +impl EncMiscParameterFrameRate { | |
| 38 | + pub fn new(framerate: u32, temporal_id: u32) -> Self { | |
| 39 | + let _bitfield_1 = | |
| 40 | + bindings::_VAEncMiscParameterFrameRate__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 41 | + temporal_id, | |
| 42 | + Default::default(), | |
| 43 | + ); | |
| 44 | + | |
| 45 | + Self(MiscEncParamBuffer::new_boxed( | |
| 46 | + bindings::VAEncMiscParameterType::VAEncMiscParameterTypeFrameRate, | |
| 47 | + bindings::_VAEncMiscParameterFrameRate { | |
| 48 | + framerate, | |
| 49 | + framerate_flags: bindings::_VAEncMiscParameterFrameRate__bindgen_ty_1 { | |
| 50 | + bits: bindings::_VAEncMiscParameterFrameRate__bindgen_ty_1__bindgen_ty_1 { | |
| 51 | + _bitfield_align_1: Default::default(), | |
| 52 | + _bitfield_1, | |
| 53 | + }, | |
| 54 | + }, | |
| 55 | + ..Default::default() | |
| 56 | + }, | |
| 57 | + )) | |
| 58 | + } | |
| 59 | + | |
| 60 | + pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterFrameRate> { | |
| 61 | + &self.0 | |
| 62 | + } | |
| 63 | + | |
| 64 | + pub(crate) fn inner_mut( | |
| 65 | + &mut self, | |
| 66 | + ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterFrameRate> { | |
| 67 | + &mut self.0 | |
| 68 | + } | |
| 69 | +} | |
| 70 | + | |
| 71 | +#[derive(Default)] | |
| 72 | +pub struct RcFlags(bindings::_VAEncMiscParameterRateControl__bindgen_ty_1); | |
| 73 | + | |
| 74 | +impl RcFlags { | |
| 75 | + pub fn new( | |
| 76 | + reset: u32, | |
| 77 | + disable_frame_skip: u32, | |
| 78 | + disable_bit_stuffing: u32, | |
| 79 | + mb_rate_control: u32, | |
| 80 | + temporal_id: u32, | |
| 81 | + cfs_i_frames: u32, | |
| 82 | + enable_parallel_brc: u32, | |
| 83 | + enable_dynamic_scaling: u32, | |
| 84 | + frame_tolerance_mode: u32, | |
| 85 | + ) -> Self { | |
| 86 | + let _bitfield_1 = | |
| 87 | + bindings::_VAEncMiscParameterRateControl__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 88 | + reset, | |
| 89 | + disable_frame_skip, | |
| 90 | + disable_bit_stuffing, | |
| 91 | + mb_rate_control, | |
| 92 | + temporal_id, | |
| 93 | + cfs_i_frames, | |
| 94 | + enable_parallel_brc, | |
| 95 | + enable_dynamic_scaling, | |
| 96 | + frame_tolerance_mode, | |
| 97 | + Default::default(), | |
| 98 | + ); | |
| 99 | + | |
| 100 | + Self(bindings::_VAEncMiscParameterRateControl__bindgen_ty_1 { | |
| 101 | + bits: bindings::_VAEncMiscParameterRateControl__bindgen_ty_1__bindgen_ty_1 { | |
| 102 | + _bitfield_align_1: Default::default(), | |
| 103 | + _bitfield_1, | |
| 104 | + }, | |
| 105 | + }) | |
| 106 | + } | |
| 107 | +} | |
| 108 | + | |
| 109 | +#[derive(Default)] | |
| 110 | +pub struct EncMiscParameterRateControl( | |
| 111 | + Box<MiscEncParamBuffer<bindings::VAEncMiscParameterRateControl>>, | |
| 112 | +); | |
| 113 | + | |
| 114 | +impl EncMiscParameterRateControl { | |
| 115 | + pub fn new( | |
| 116 | + bits_per_second: u32, | |
| 117 | + target_percentage: u32, | |
| 118 | + window_size: u32, | |
| 119 | + initial_qp: u32, | |
| 120 | + min_qp: u32, | |
| 121 | + basic_unit_size: u32, | |
| 122 | + rc_flags: RcFlags, | |
| 123 | + icq_quality_factor: u32, | |
| 124 | + max_qp: u32, | |
| 125 | + quality_factor: u32, | |
| 126 | + target_frame_size: u32, | |
| 127 | + ) -> Self { | |
| 128 | + Self(MiscEncParamBuffer::new_boxed( | |
| 129 | + bindings::VAEncMiscParameterType::VAEncMiscParameterTypeRateControl, | |
| 130 | + bindings::VAEncMiscParameterRateControl { | |
| 131 | + bits_per_second, | |
| 132 | + target_percentage, | |
| 133 | + window_size, | |
| 134 | + initial_qp, | |
| 135 | + min_qp, | |
| 136 | + basic_unit_size, | |
| 137 | + rc_flags: rc_flags.0, | |
| 138 | + ICQ_quality_factor: icq_quality_factor, | |
| 139 | + max_qp, | |
| 140 | + quality_factor, | |
| 141 | + target_frame_size, | |
| 142 | + ..Default::default() | |
| 143 | + }, | |
| 144 | + )) | |
| 145 | + } | |
| 146 | + | |
| 147 | + pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterRateControl> { | |
| 148 | + &self.0 | |
| 149 | + } | |
| 150 | + | |
| 151 | + pub(crate) fn inner_mut( | |
| 152 | + &mut self, | |
| 153 | + ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterRateControl> { | |
| 154 | + &mut self.0 | |
| 155 | + } | |
| 156 | +} | |
| 157 | + | |
| 158 | +#[derive(Default)] | |
| 159 | +pub struct EncMiscParameterMaxSliceSize( | |
| 160 | + Box<MiscEncParamBuffer<bindings::VAEncMiscParameterMaxSliceSize>>, | |
| 161 | +); | |
| 162 | + | |
| 163 | +impl EncMiscParameterMaxSliceSize { | |
| 164 | + pub fn new(max_slice_size: u32) -> Self { | |
| 165 | + Self(MiscEncParamBuffer::new_boxed( | |
| 166 | + bindings::VAEncMiscParameterType::VAEncMiscParameterTypeMaxFrameSize, | |
| 167 | + bindings::VAEncMiscParameterMaxSliceSize { | |
| 168 | + max_slice_size, | |
| 169 | + ..Default::default() | |
| 170 | + }, | |
| 171 | + )) | |
| 172 | + } | |
| 173 | + | |
| 174 | + pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterMaxSliceSize> { | |
| 175 | + &self.0 | |
| 176 | + } | |
| 177 | + | |
| 178 | + pub(crate) fn inner_mut( | |
| 179 | + &mut self, | |
| 180 | + ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterMaxSliceSize> { | |
| 181 | + &mut self.0 | |
| 182 | + } | |
| 183 | +} | |
| 184 | + | |
| 185 | +#[derive(Default)] | |
| 186 | +pub struct EncMiscParameterBufferMaxFrameSize( | |
| 187 | + Box<MiscEncParamBuffer<bindings::VAEncMiscParameterBufferMaxFrameSize>>, | |
| 188 | +); | |
| 189 | + | |
| 190 | +impl EncMiscParameterBufferMaxFrameSize { | |
| 191 | + pub fn new(max_frame_size: u32) -> Self { | |
| 192 | + Self(MiscEncParamBuffer::new_boxed( | |
| 193 | + bindings::VAEncMiscParameterType::VAEncMiscParameterTypeMaxFrameSize, | |
| 194 | + bindings::VAEncMiscParameterBufferMaxFrameSize { | |
| 195 | + type_: bindings::VAEncMiscParameterType::VAEncMiscParameterTypeMaxFrameSize, | |
| 196 | + max_frame_size, | |
| 197 | + ..Default::default() | |
| 198 | + }, | |
| 199 | + )) | |
| 200 | + } | |
| 201 | + | |
| 202 | + pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterBufferMaxFrameSize> { | |
| 203 | + &self.0 | |
| 204 | + } | |
| 205 | + | |
| 206 | + pub(crate) fn inner_mut( | |
| 207 | + &mut self, | |
| 208 | + ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterBufferMaxFrameSize> { | |
| 209 | + &mut self.0 | |
| 210 | + } | |
| 211 | +} | |
| 212 | + | |
| 213 | +#[derive(Default)] | |
| 214 | +pub struct EncMiscParameterSkipFrame( | |
| 215 | + Box<MiscEncParamBuffer<bindings::VAEncMiscParameterSkipFrame>>, | |
| 216 | +); | |
| 217 | + | |
| 218 | +impl EncMiscParameterSkipFrame { | |
| 219 | + pub fn new(skip_frame_flag: u8, num_skip_frames: u8, size_skip_frames: u32) -> Self { | |
| 220 | + Self(MiscEncParamBuffer::new_boxed( | |
| 221 | + bindings::VAEncMiscParameterType::VAEncMiscParameterTypeSkipFrame, | |
| 222 | + bindings::VAEncMiscParameterSkipFrame { | |
| 223 | + skip_frame_flag, | |
| 224 | + num_skip_frames, | |
| 225 | + size_skip_frames, | |
| 226 | + ..Default::default() | |
| 227 | + }, | |
| 228 | + )) | |
| 229 | + } | |
| 230 | + | |
| 231 | + pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterSkipFrame> { | |
| 232 | + &self.0 | |
| 233 | + } | |
| 234 | + | |
| 235 | + pub(crate) fn inner_mut( | |
| 236 | + &mut self, | |
| 237 | + ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterSkipFrame> { | |
| 238 | + &mut self.0 | |
| 239 | + } | |
| 240 | +} | |
| 241 | + | |
| 242 | +#[derive(Default)] | |
| 243 | +pub struct EncMiscParameterHRD(Box<MiscEncParamBuffer<bindings::VAEncMiscParameterHRD>>); | |
| 244 | + | |
| 245 | +impl EncMiscParameterHRD { | |
| 246 | + pub fn new(initial_buffer_fullness: u32, buffer_size: u32) -> Self { | |
| 247 | + Self(MiscEncParamBuffer::new_boxed( | |
| 248 | + bindings::VAEncMiscParameterType::VAEncMiscParameterTypeHRD, | |
| 249 | + bindings::VAEncMiscParameterHRD { | |
| 250 | + initial_buffer_fullness, | |
| 251 | + buffer_size, | |
| 252 | + ..Default::default() | |
| 253 | + }, | |
| 254 | + )) | |
| 255 | + } | |
| 256 | + | |
| 257 | + pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterHRD> { | |
| 258 | + &self.0 | |
| 259 | + } | |
| 260 | + | |
| 261 | + pub(crate) fn inner_mut(&mut self) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterHRD> { | |
| 262 | + &mut self.0 | |
| 263 | + } | |
| 264 | +} | |
| 265 | + | |
| 266 | +#[derive(Default)] | |
| 267 | +pub struct EncMiscParameterBufferQualityLevel( | |
| 268 | + Box<MiscEncParamBuffer<bindings::VAEncMiscParameterBufferQualityLevel>>, | |
| 269 | +); | |
| 270 | + | |
| 271 | +impl EncMiscParameterBufferQualityLevel { | |
| 272 | + pub fn new(quality_level: u32) -> Self { | |
| 273 | + Self(MiscEncParamBuffer::new_boxed( | |
| 274 | + bindings::VAEncMiscParameterType::VAEncMiscParameterTypeQualityLevel, | |
| 275 | + bindings::VAEncMiscParameterBufferQualityLevel { | |
| 276 | + quality_level, | |
| 277 | + ..Default::default() | |
| 278 | + }, | |
| 279 | + )) | |
| 280 | + } | |
| 281 | + | |
| 282 | + pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterBufferQualityLevel> { | |
| 283 | + &self.0 | |
| 284 | + } | |
| 285 | + | |
| 286 | + pub(crate) fn inner_mut( | |
| 287 | + &mut self, | |
| 288 | + ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterBufferQualityLevel> { | |
| 289 | + &mut self.0 | |
| 290 | + } | |
| 291 | +} | |
| 292 | + | |
| 293 | +#[derive(Default)] | |
| 294 | +pub struct EncMiscParameterQuantization( | |
| 295 | + Box<MiscEncParamBuffer<bindings::VAEncMiscParameterQuantization>>, | |
| 296 | +); | |
| 297 | + | |
| 298 | +impl EncMiscParameterQuantization { | |
| 299 | + pub fn new( | |
| 300 | + disable_trellis: bool, | |
| 301 | + enable_trellis_i: bool, | |
| 302 | + enable_trellis_p: bool, | |
| 303 | + enable_trellis_b: bool, | |
| 304 | + ) -> Self { | |
| 305 | + let _bitfield_1 = | |
| 306 | + bindings::_VAEncMiscParameterQuantization__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 307 | + disable_trellis as u32, | |
| 308 | + enable_trellis_i as u32, | |
| 309 | + enable_trellis_p as u32, | |
| 310 | + enable_trellis_b as u32, | |
| 311 | + Default::default(), | |
| 312 | + ); | |
| 313 | + | |
| 314 | + Self(MiscEncParamBuffer::new_boxed( | |
| 315 | + bindings::VAEncMiscParameterType::VAEncMiscParameterTypeQuantization, | |
| 316 | + bindings::VAEncMiscParameterQuantization { | |
| 317 | + quantization_flags: bindings::_VAEncMiscParameterQuantization__bindgen_ty_1 { | |
| 318 | + bits: bindings::_VAEncMiscParameterQuantization__bindgen_ty_1__bindgen_ty_1 { | |
| 319 | + _bitfield_align_1: Default::default(), | |
| 320 | + _bitfield_1, | |
| 321 | + }, | |
| 322 | + }, | |
| 323 | + ..Default::default() | |
| 324 | + }, | |
| 325 | + )) | |
| 326 | + } | |
| 327 | + | |
| 328 | + pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterQuantization> { | |
| 329 | + &self.0 | |
| 330 | + } | |
| 331 | + | |
| 332 | + pub(crate) fn inner_mut( | |
| 333 | + &mut self, | |
| 334 | + ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterQuantization> { | |
| 335 | + &mut self.0 | |
| 336 | + } | |
| 337 | +} |
shims/cros-libva/src/buffer/h264.rsadded+807 -0
| @@ -0,0 +1,807 @@ | ||
| 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 H264 `VABuffer` types. | |
| 6 | + | |
| 7 | +use crate::bindings; | |
| 8 | + | |
| 9 | +/// Wrapper over the `VAPictureH264` FFI type. | |
| 10 | +pub struct PictureH264(bindings::VAPictureH264); | |
| 11 | + | |
| 12 | +impl PictureH264 { | |
| 13 | + /// Creates the wrapper | |
| 14 | + pub fn new( | |
| 15 | + picture_id: bindings::VASurfaceID, | |
| 16 | + frame_idx: u32, | |
| 17 | + flags: u32, | |
| 18 | + top_field_order_cnt: i32, | |
| 19 | + bottom_field_order_cnt: i32, | |
| 20 | + ) -> Self { | |
| 21 | + Self(bindings::VAPictureH264 { | |
| 22 | + picture_id, | |
| 23 | + frame_idx, | |
| 24 | + flags, | |
| 25 | + TopFieldOrderCnt: top_field_order_cnt, | |
| 26 | + BottomFieldOrderCnt: bottom_field_order_cnt, | |
| 27 | + va_reserved: Default::default(), | |
| 28 | + }) | |
| 29 | + } | |
| 30 | +} | |
| 31 | + | |
| 32 | +/// Wrapper over the `seq_fields` bindgen field in `VAPictureParameterBufferH264`. | |
| 33 | +pub struct H264SeqFields(bindings::_VAPictureParameterBufferH264__bindgen_ty_1); | |
| 34 | + | |
| 35 | +impl H264SeqFields { | |
| 36 | + /// Creates the bindgen field | |
| 37 | + #[allow(clippy::too_many_arguments)] | |
| 38 | + pub fn new( | |
| 39 | + chroma_format_idc: u32, | |
| 40 | + residual_colour_transform_flag: u32, | |
| 41 | + gaps_in_frame_num_value_allowed_flag: u32, | |
| 42 | + frame_mbs_only_flag: u32, | |
| 43 | + mb_adaptive_frame_field_flag: u32, | |
| 44 | + direct_8x8_inference_flag: u32, | |
| 45 | + min_luma_bi_pred_size8x8: u32, | |
| 46 | + log2_max_frame_num_minus4: u32, | |
| 47 | + pic_order_cnt_type: u32, | |
| 48 | + log2_max_pic_order_cnt_lsb_minus4: u32, | |
| 49 | + delta_pic_order_always_zero_flag: u32, | |
| 50 | + ) -> Self { | |
| 51 | + let _bitfield_1 = | |
| 52 | + bindings::_VAPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 53 | + chroma_format_idc, | |
| 54 | + residual_colour_transform_flag, | |
| 55 | + gaps_in_frame_num_value_allowed_flag, | |
| 56 | + frame_mbs_only_flag, | |
| 57 | + mb_adaptive_frame_field_flag, | |
| 58 | + direct_8x8_inference_flag, | |
| 59 | + min_luma_bi_pred_size8x8, | |
| 60 | + log2_max_frame_num_minus4, | |
| 61 | + pic_order_cnt_type, | |
| 62 | + log2_max_pic_order_cnt_lsb_minus4, | |
| 63 | + delta_pic_order_always_zero_flag, | |
| 64 | + ); | |
| 65 | + | |
| 66 | + Self(bindings::_VAPictureParameterBufferH264__bindgen_ty_1 { | |
| 67 | + bits: bindings::_VAPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1 { | |
| 68 | + _bitfield_align_1: Default::default(), | |
| 69 | + _bitfield_1, | |
| 70 | + __bindgen_padding_0: Default::default(), | |
| 71 | + }, | |
| 72 | + }) | |
| 73 | + } | |
| 74 | + | |
| 75 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 76 | + pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_1 { | |
| 77 | + &self.0 | |
| 78 | + } | |
| 79 | +} | |
| 80 | + | |
| 81 | +/// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferH264`. | |
| 82 | +pub struct H264PicFields(bindings::_VAPictureParameterBufferH264__bindgen_ty_2); | |
| 83 | + | |
| 84 | +impl H264PicFields { | |
| 85 | + /// Creates the bindgen field | |
| 86 | + #[allow(clippy::too_many_arguments)] | |
| 87 | + pub fn new( | |
| 88 | + entropy_coding_mode_flag: u32, | |
| 89 | + weighted_pred_flag: u32, | |
| 90 | + weighted_bipred_idc: u32, | |
| 91 | + transform_8x8_mode_flag: u32, | |
| 92 | + field_pic_flag: u32, | |
| 93 | + constrained_intra_pred_flag: u32, | |
| 94 | + pic_order_present_flag: u32, | |
| 95 | + deblocking_filter_control_present_flag: u32, | |
| 96 | + redundant_pic_cnt_present_flag: u32, | |
| 97 | + reference_pic_flag: u32, | |
| 98 | + ) -> Self { | |
| 99 | + let _bitfield_1 = | |
| 100 | + bindings::_VAPictureParameterBufferH264__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
| 101 | + entropy_coding_mode_flag, | |
| 102 | + weighted_pred_flag, | |
| 103 | + weighted_bipred_idc, | |
| 104 | + transform_8x8_mode_flag, | |
| 105 | + field_pic_flag, | |
| 106 | + constrained_intra_pred_flag, | |
| 107 | + pic_order_present_flag, | |
| 108 | + deblocking_filter_control_present_flag, | |
| 109 | + redundant_pic_cnt_present_flag, | |
| 110 | + reference_pic_flag, | |
| 111 | + ); | |
| 112 | + | |
| 113 | + Self(bindings::_VAPictureParameterBufferH264__bindgen_ty_2 { | |
| 114 | + bits: bindings::_VAPictureParameterBufferH264__bindgen_ty_2__bindgen_ty_1 { | |
| 115 | + _bitfield_align_1: Default::default(), | |
| 116 | + _bitfield_1, | |
| 117 | + __bindgen_padding_0: Default::default(), | |
| 118 | + }, | |
| 119 | + }) | |
| 120 | + } | |
| 121 | + | |
| 122 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 123 | + pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_2 { | |
| 124 | + &self.0 | |
| 125 | + } | |
| 126 | +} | |
| 127 | + | |
| 128 | +/// A wrapper over `VAPictureParameterBufferH264` FFI type | |
| 129 | +pub struct PictureParameterBufferH264(Box<bindings::VAPictureParameterBufferH264>); | |
| 130 | + | |
| 131 | +impl PictureParameterBufferH264 { | |
| 132 | + /// Creates the wrapper | |
| 133 | + #[allow(clippy::too_many_arguments)] | |
| 134 | + pub fn new( | |
| 135 | + curr_pic: PictureH264, | |
| 136 | + reference_frames: [PictureH264; 16], | |
| 137 | + picture_width_in_mbs_minus1: u16, | |
| 138 | + picture_height_in_mbs_minus1: u16, | |
| 139 | + bit_depth_luma_minus8: u8, | |
| 140 | + bit_depth_chroma_minus8: u8, | |
| 141 | + num_ref_frames: u8, | |
| 142 | + seq_fields: &H264SeqFields, | |
| 143 | + num_slice_groups_minus1: u8, | |
| 144 | + slice_group_map_type: u8, | |
| 145 | + slice_group_change_rate_minus1: u16, | |
| 146 | + pic_init_qp_minus26: i8, | |
| 147 | + pic_init_qs_minus26: i8, | |
| 148 | + chroma_qp_index_offset: i8, | |
| 149 | + second_chroma_qp_index_offset: i8, | |
| 150 | + pic_fields: &H264PicFields, | |
| 151 | + frame_num: u16, | |
| 152 | + ) -> Self { | |
| 153 | + let reference_frames = (0..16usize) | |
| 154 | + .map(|i| reference_frames[i].0) | |
| 155 | + .collect::<Vec<_>>() | |
| 156 | + .try_into() | |
| 157 | + // try_into is guaranteed to work because the iterator and target array have the same | |
| 158 | + // size. | |
| 159 | + .unwrap(); | |
| 160 | + | |
| 161 | + let seq_fields = seq_fields.0; | |
| 162 | + let pic_fields = pic_fields.0; | |
| 163 | + | |
| 164 | + Self(Box::new(bindings::VAPictureParameterBufferH264 { | |
| 165 | + CurrPic: curr_pic.0, | |
| 166 | + ReferenceFrames: reference_frames, | |
| 167 | + picture_width_in_mbs_minus1, | |
| 168 | + picture_height_in_mbs_minus1, | |
| 169 | + bit_depth_luma_minus8, | |
| 170 | + bit_depth_chroma_minus8, | |
| 171 | + num_ref_frames, | |
| 172 | + seq_fields, | |
| 173 | + num_slice_groups_minus1, | |
| 174 | + slice_group_map_type, | |
| 175 | + slice_group_change_rate_minus1, | |
| 176 | + pic_init_qp_minus26, | |
| 177 | + pic_init_qs_minus26, | |
| 178 | + chroma_qp_index_offset, | |
| 179 | + second_chroma_qp_index_offset, | |
| 180 | + pic_fields, | |
| 181 | + frame_num, | |
| 182 | + va_reserved: Default::default(), | |
| 183 | + })) | |
| 184 | + } | |
| 185 | + | |
| 186 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferH264 { | |
| 187 | + self.0.as_mut() | |
| 188 | + } | |
| 189 | + | |
| 190 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 191 | + pub fn inner(&self) -> &bindings::VAPictureParameterBufferH264 { | |
| 192 | + self.0.as_ref() | |
| 193 | + } | |
| 194 | +} | |
| 195 | + | |
| 196 | +/// Wrapper over the `VASliceParameterBufferH264` FFI type. | |
| 197 | +pub struct SliceParameterBufferH264(Vec<bindings::VASliceParameterBufferH264>); | |
| 198 | + | |
| 199 | +impl SliceParameterBufferH264 { | |
| 200 | + pub fn new_array() -> Self { | |
| 201 | + Self(Vec::new()) | |
| 202 | + } | |
| 203 | + | |
| 204 | + /// Creates the wrapper | |
| 205 | + #[allow(clippy::too_many_arguments)] | |
| 206 | + pub fn new( | |
| 207 | + slice_data_size: u32, | |
| 208 | + slice_data_offset: u32, | |
| 209 | + slice_data_flag: u32, | |
| 210 | + slice_data_bit_offset: u16, | |
| 211 | + first_mb_in_slice: u16, | |
| 212 | + slice_type: u8, | |
| 213 | + direct_spatial_mv_pred_flag: u8, | |
| 214 | + num_ref_idx_l0_active_minus1: u8, | |
| 215 | + num_ref_idx_l1_active_minus1: u8, | |
| 216 | + cabac_init_idc: u8, | |
| 217 | + slice_qp_delta: i8, | |
| 218 | + disable_deblocking_filter_idc: u8, | |
| 219 | + slice_alpha_c0_offset_div2: i8, | |
| 220 | + slice_beta_offset_div2: i8, | |
| 221 | + ref_pic_list_0: [PictureH264; 32usize], | |
| 222 | + ref_pic_list_1: [PictureH264; 32usize], | |
| 223 | + luma_log2_weight_denom: u8, | |
| 224 | + chroma_log2_weight_denom: u8, | |
| 225 | + luma_weight_l0_flag: u8, | |
| 226 | + luma_weight_l0: [i16; 32usize], | |
| 227 | + luma_offset_l0: [i16; 32usize], | |
| 228 | + chroma_weight_l0_flag: u8, | |
| 229 | + chroma_weight_l0: [[i16; 2usize]; 32usize], | |
| 230 | + chroma_offset_l0: [[i16; 2usize]; 32usize], | |
| 231 | + luma_weight_l1_flag: u8, | |
| 232 | + luma_weight_l1: [i16; 32usize], | |
| 233 | + luma_offset_l1: [i16; 32usize], | |
| 234 | + chroma_weight_l1_flag: u8, | |
| 235 | + chroma_weight_l1: [[i16; 2usize]; 32usize], | |
| 236 | + chroma_offset_l1: [[i16; 2usize]; 32usize], | |
| 237 | + ) -> Self { | |
| 238 | + let mut array = Self::new_array(); | |
| 239 | + | |
| 240 | + array.add_slice_parameter( | |
| 241 | + slice_data_size, | |
| 242 | + slice_data_offset, | |
| 243 | + slice_data_flag, | |
| 244 | + slice_data_bit_offset, | |
| 245 | + first_mb_in_slice, | |
| 246 | + slice_type, | |
| 247 | + direct_spatial_mv_pred_flag, | |
| 248 | + num_ref_idx_l0_active_minus1, | |
| 249 | + num_ref_idx_l1_active_minus1, | |
| 250 | + cabac_init_idc, | |
| 251 | + slice_qp_delta, | |
| 252 | + disable_deblocking_filter_idc, | |
| 253 | + slice_alpha_c0_offset_div2, | |
| 254 | + slice_beta_offset_div2, | |
| 255 | + ref_pic_list_0, | |
| 256 | + ref_pic_list_1, | |
| 257 | + luma_log2_weight_denom, | |
| 258 | + chroma_log2_weight_denom, | |
| 259 | + luma_weight_l0_flag, | |
| 260 | + luma_weight_l0, | |
| 261 | + luma_offset_l0, | |
| 262 | + chroma_weight_l0_flag, | |
| 263 | + chroma_weight_l0, | |
| 264 | + chroma_offset_l0, | |
| 265 | + luma_weight_l1_flag, | |
| 266 | + luma_weight_l1, | |
| 267 | + luma_offset_l1, | |
| 268 | + chroma_weight_l1_flag, | |
| 269 | + chroma_weight_l1, | |
| 270 | + chroma_offset_l1, | |
| 271 | + ); | |
| 272 | + | |
| 273 | + array | |
| 274 | + } | |
| 275 | + | |
| 276 | + /// Creates the wrapper | |
| 277 | + #[allow(clippy::too_many_arguments)] | |
| 278 | + pub fn add_slice_parameter( | |
| 279 | + &mut self, | |
| 280 | + slice_data_size: u32, | |
| 281 | + slice_data_offset: u32, | |
| 282 | + slice_data_flag: u32, | |
| 283 | + slice_data_bit_offset: u16, | |
| 284 | + first_mb_in_slice: u16, | |
| 285 | + slice_type: u8, | |
| 286 | + direct_spatial_mv_pred_flag: u8, | |
| 287 | + num_ref_idx_l0_active_minus1: u8, | |
| 288 | + num_ref_idx_l1_active_minus1: u8, | |
| 289 | + cabac_init_idc: u8, | |
| 290 | + slice_qp_delta: i8, | |
| 291 | + disable_deblocking_filter_idc: u8, | |
| 292 | + slice_alpha_c0_offset_div2: i8, | |
| 293 | + slice_beta_offset_div2: i8, | |
| 294 | + ref_pic_list_0: [PictureH264; 32usize], | |
| 295 | + ref_pic_list_1: [PictureH264; 32usize], | |
| 296 | + luma_log2_weight_denom: u8, | |
| 297 | + chroma_log2_weight_denom: u8, | |
| 298 | + luma_weight_l0_flag: u8, | |
| 299 | + luma_weight_l0: [i16; 32usize], | |
| 300 | + luma_offset_l0: [i16; 32usize], | |
| 301 | + chroma_weight_l0_flag: u8, | |
| 302 | + chroma_weight_l0: [[i16; 2usize]; 32usize], | |
| 303 | + chroma_offset_l0: [[i16; 2usize]; 32usize], | |
| 304 | + luma_weight_l1_flag: u8, | |
| 305 | + luma_weight_l1: [i16; 32usize], | |
| 306 | + luma_offset_l1: [i16; 32usize], | |
| 307 | + chroma_weight_l1_flag: u8, | |
| 308 | + chroma_weight_l1: [[i16; 2usize]; 32usize], | |
| 309 | + chroma_offset_l1: [[i16; 2usize]; 32usize], | |
| 310 | + ) { | |
| 311 | + let ref_pic_list_0 = ref_pic_list_0.map(|pic| pic.0); | |
| 312 | + let ref_pic_list_1 = ref_pic_list_1.map(|pic| pic.0); | |
| 313 | + | |
| 314 | + let buf = bindings::VASliceParameterBufferH264 { | |
| 315 | + slice_data_size, | |
| 316 | + slice_data_offset, | |
| 317 | + slice_data_flag, | |
| 318 | + slice_data_bit_offset, | |
| 319 | + first_mb_in_slice, | |
| 320 | + slice_type, | |
| 321 | + direct_spatial_mv_pred_flag, | |
| 322 | + num_ref_idx_l0_active_minus1, | |
| 323 | + num_ref_idx_l1_active_minus1, | |
| 324 | + cabac_init_idc, | |
| 325 | + slice_qp_delta, | |
| 326 | + disable_deblocking_filter_idc, | |
| 327 | + slice_alpha_c0_offset_div2, | |
| 328 | + slice_beta_offset_div2, | |
| 329 | + RefPicList0: ref_pic_list_0, | |
| 330 | + RefPicList1: ref_pic_list_1, | |
| 331 | + luma_log2_weight_denom, | |
| 332 | + chroma_log2_weight_denom, | |
| 333 | + luma_weight_l0_flag, | |
| 334 | + luma_weight_l0, | |
| 335 | + luma_offset_l0, | |
| 336 | + chroma_weight_l0_flag, | |
| 337 | + chroma_weight_l0, | |
| 338 | + chroma_offset_l0, | |
| 339 | + luma_weight_l1_flag, | |
| 340 | + luma_weight_l1, | |
| 341 | + luma_offset_l1, | |
| 342 | + chroma_weight_l1_flag, | |
| 343 | + chroma_weight_l1, | |
| 344 | + chroma_offset_l1, | |
| 345 | + va_reserved: Default::default(), | |
| 346 | + }; | |
| 347 | + | |
| 348 | + self.0.push(buf); | |
| 349 | + } | |
| 350 | + | |
| 351 | + pub(crate) fn inner_mut(&mut self) -> &mut Vec<bindings::VASliceParameterBufferH264> { | |
| 352 | + &mut self.0 | |
| 353 | + } | |
| 354 | + | |
| 355 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 356 | + pub fn inner(&self) -> &Vec<bindings::VASliceParameterBufferH264> { | |
| 357 | + &self.0 | |
| 358 | + } | |
| 359 | +} | |
| 360 | + | |
| 361 | +/// Wrapper over the `VAIQMatrixBufferH264` FFI type | |
| 362 | +pub struct IQMatrixBufferH264(Box<bindings::VAIQMatrixBufferH264>); | |
| 363 | + | |
| 364 | +impl IQMatrixBufferH264 { | |
| 365 | + /// Creates the wrapper. | |
| 366 | + pub fn new( | |
| 367 | + scaling_list4x4: [[u8; 16usize]; 6usize], | |
| 368 | + scaling_list8x8: [[u8; 64usize]; 2usize], | |
| 369 | + ) -> Self { | |
| 370 | + Self(Box::new(bindings::VAIQMatrixBufferH264 { | |
| 371 | + ScalingList4x4: scaling_list4x4, | |
| 372 | + ScalingList8x8: scaling_list8x8, | |
| 373 | + va_reserved: Default::default(), | |
| 374 | + })) | |
| 375 | + } | |
| 376 | + | |
| 377 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferH264 { | |
| 378 | + self.0.as_mut() | |
| 379 | + } | |
| 380 | + | |
| 381 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 382 | + pub fn inner(&self) -> &bindings::VAIQMatrixBufferH264 { | |
| 383 | + self.0.as_ref() | |
| 384 | + } | |
| 385 | +} | |
| 386 | + | |
| 387 | +/// Wrapper over the `seq_fields` bindgen field in `VAEncSequenceParameterBufferH264` | |
| 388 | +pub struct H264EncSeqFields(bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1); | |
| 389 | + | |
| 390 | +impl H264EncSeqFields { | |
| 391 | + #[allow(clippy::too_many_arguments)] | |
| 392 | + pub fn new( | |
| 393 | + chroma_format_idc: u32, | |
| 394 | + frame_mbs_only_flag: u32, | |
| 395 | + mb_adaptive_frame_field_flag: u32, | |
| 396 | + seq_scaling_matrix_present_flag: u32, | |
| 397 | + direct_8x8_inference_flag: u32, | |
| 398 | + log2_max_frame_num_minus4: u32, | |
| 399 | + pic_order_cnt_type: u32, | |
| 400 | + log2_max_pic_order_cnt_lsb_minus4: u32, | |
| 401 | + delta_pic_order_always_zero_flag: u32, | |
| 402 | + ) -> Self { | |
| 403 | + let _bitfield_1 = | |
| 404 | + bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 405 | + chroma_format_idc, | |
| 406 | + frame_mbs_only_flag, | |
| 407 | + mb_adaptive_frame_field_flag, | |
| 408 | + seq_scaling_matrix_present_flag, | |
| 409 | + direct_8x8_inference_flag, | |
| 410 | + log2_max_frame_num_minus4, | |
| 411 | + pic_order_cnt_type, | |
| 412 | + log2_max_pic_order_cnt_lsb_minus4, | |
| 413 | + delta_pic_order_always_zero_flag, | |
| 414 | + ); | |
| 415 | + | |
| 416 | + Self(bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1 { | |
| 417 | + bits: bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1__bindgen_ty_1 { | |
| 418 | + _bitfield_align_1: Default::default(), | |
| 419 | + _bitfield_1, | |
| 420 | + __bindgen_padding_0: Default::default(), | |
| 421 | + }, | |
| 422 | + }) | |
| 423 | + } | |
| 424 | + | |
| 425 | + pub fn inner(&self) -> &bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1 { | |
| 426 | + &self.0 | |
| 427 | + } | |
| 428 | +} | |
| 429 | + | |
| 430 | +#[derive(Default)] | |
| 431 | +pub struct H264VuiFields(bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_2); | |
| 432 | + | |
| 433 | +impl H264VuiFields { | |
| 434 | + #[allow(clippy::too_many_arguments)] | |
| 435 | + pub fn new( | |
| 436 | + aspect_ratio_info_present_flag: u32, | |
| 437 | + timing_info_present_flag: u32, | |
| 438 | + bitstream_restriction_flag: u32, | |
| 439 | + log2_max_mv_length_horizontal: u32, | |
| 440 | + log2_max_mv_length_vertical: u32, | |
| 441 | + fixed_frame_rate_flag: u32, | |
| 442 | + low_delay_hrd_flag: u32, | |
| 443 | + motion_vectors_over_pic_boundaries_flag: u32, | |
| 444 | + ) -> Self { | |
| 445 | + let _bitfield_1 = | |
| 446 | + bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
| 447 | + aspect_ratio_info_present_flag, | |
| 448 | + timing_info_present_flag, | |
| 449 | + bitstream_restriction_flag, | |
| 450 | + log2_max_mv_length_horizontal, | |
| 451 | + log2_max_mv_length_vertical, | |
| 452 | + fixed_frame_rate_flag, | |
| 453 | + low_delay_hrd_flag, | |
| 454 | + motion_vectors_over_pic_boundaries_flag, | |
| 455 | + Default::default(), | |
| 456 | + ); | |
| 457 | + | |
| 458 | + Self(bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_2 { | |
| 459 | + bits: bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_2__bindgen_ty_1 { | |
| 460 | + _bitfield_align_1: Default::default(), | |
| 461 | + _bitfield_1, | |
| 462 | + }, | |
| 463 | + }) | |
| 464 | + } | |
| 465 | +} | |
| 466 | + | |
| 467 | +#[derive(Default)] | |
| 468 | +pub struct H264EncFrameCropOffsets { | |
| 469 | + pub left: u32, | |
| 470 | + pub right: u32, | |
| 471 | + pub top: u32, | |
| 472 | + pub bottom: u32, | |
| 473 | +} | |
| 474 | + | |
| 475 | +impl H264EncFrameCropOffsets { | |
| 476 | + pub fn new( | |
| 477 | + frame_crop_left_offset: u32, | |
| 478 | + frame_crop_right_offset: u32, | |
| 479 | + frame_crop_top_offset: u32, | |
| 480 | + frame_crop_bottom_offset: u32, | |
| 481 | + ) -> Self { | |
| 482 | + Self { | |
| 483 | + left: frame_crop_left_offset, | |
| 484 | + right: frame_crop_right_offset, | |
| 485 | + top: frame_crop_top_offset, | |
| 486 | + bottom: frame_crop_bottom_offset, | |
| 487 | + } | |
| 488 | + } | |
| 489 | +} | |
| 490 | + | |
| 491 | +pub struct EncSequenceParameterBufferH264(Box<bindings::VAEncSequenceParameterBufferH264>); | |
| 492 | + | |
| 493 | +impl EncSequenceParameterBufferH264 { | |
| 494 | + #[allow(clippy::too_many_arguments)] | |
| 495 | + pub fn new( | |
| 496 | + seq_parameter_set_id: u8, | |
| 497 | + level_idc: u8, | |
| 498 | + intra_period: u32, | |
| 499 | + intra_idr_period: u32, | |
| 500 | + ip_period: u32, | |
| 501 | + bits_per_second: u32, | |
| 502 | + max_num_ref_frames: u32, | |
| 503 | + picture_width_in_mbs: u16, | |
| 504 | + picture_height_in_mbs: u16, | |
| 505 | + seq_fields: &H264EncSeqFields, | |
| 506 | + bit_depth_luma_minus8: u8, | |
| 507 | + bit_depth_chroma_minus8: u8, | |
| 508 | + num_ref_frames_in_pic_order_cnt_cycle: u8, | |
| 509 | + offset_for_non_ref_pic: i32, | |
| 510 | + offset_for_top_to_bottom_field: i32, | |
| 511 | + offset_for_ref_frame: [i32; 256usize], | |
| 512 | + frame_crop: Option<H264EncFrameCropOffsets>, | |
| 513 | + vui_fields: Option<H264VuiFields>, | |
| 514 | + aspect_ratio_idc: u8, | |
| 515 | + sar_width: u32, | |
| 516 | + sar_height: u32, | |
| 517 | + num_units_in_tick: u32, | |
| 518 | + time_scale: u32, | |
| 519 | + ) -> Self { | |
| 520 | + let seq_fields = seq_fields.0; | |
| 521 | + | |
| 522 | + let frame_cropping_flag = if frame_crop.is_some() { 1 } else { 0 }; | |
| 523 | + let frame_crop = frame_crop.unwrap_or_default(); | |
| 524 | + | |
| 525 | + let frame_crop_left_offset = frame_crop.left; | |
| 526 | + let frame_crop_right_offset = frame_crop.right; | |
| 527 | + let frame_crop_top_offset = frame_crop.top; | |
| 528 | + let frame_crop_bottom_offset = frame_crop.bottom; | |
| 529 | + | |
| 530 | + let vui_parameters_present_flag = if vui_fields.is_some() { 1 } else { 0 }; | |
| 531 | + let vui_fields = vui_fields.unwrap_or_default().0; | |
| 532 | + | |
| 533 | + Self(Box::new(bindings::VAEncSequenceParameterBufferH264 { | |
| 534 | + seq_parameter_set_id, | |
| 535 | + level_idc, | |
| 536 | + intra_period, | |
| 537 | + intra_idr_period, | |
| 538 | + ip_period, | |
| 539 | + bits_per_second, | |
| 540 | + max_num_ref_frames, | |
| 541 | + picture_width_in_mbs, | |
| 542 | + picture_height_in_mbs, | |
| 543 | + seq_fields, | |
| 544 | + bit_depth_luma_minus8, | |
| 545 | + bit_depth_chroma_minus8, | |
| 546 | + num_ref_frames_in_pic_order_cnt_cycle, | |
| 547 | + offset_for_non_ref_pic, | |
| 548 | + offset_for_top_to_bottom_field, | |
| 549 | + offset_for_ref_frame, | |
| 550 | + frame_cropping_flag, | |
| 551 | + frame_crop_left_offset, | |
| 552 | + frame_crop_right_offset, | |
| 553 | + frame_crop_top_offset, | |
| 554 | + frame_crop_bottom_offset, | |
| 555 | + vui_parameters_present_flag, | |
| 556 | + vui_fields, | |
| 557 | + aspect_ratio_idc, | |
| 558 | + sar_width, | |
| 559 | + sar_height, | |
| 560 | + num_units_in_tick, | |
| 561 | + time_scale, | |
| 562 | + ..Default::default() | |
| 563 | + })) | |
| 564 | + } | |
| 565 | + | |
| 566 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSequenceParameterBufferH264 { | |
| 567 | + self.0.as_mut() | |
| 568 | + } | |
| 569 | +} | |
| 570 | + | |
| 571 | +pub struct H264EncPicFields(bindings::_VAEncPictureParameterBufferH264__bindgen_ty_1); | |
| 572 | + | |
| 573 | +impl H264EncPicFields { | |
| 574 | + #[allow(clippy::too_many_arguments)] | |
| 575 | + pub fn new( | |
| 576 | + idr_pic_flag: u32, | |
| 577 | + reference_pic_flag: u32, | |
| 578 | + entropy_coding_mode_flag: u32, | |
| 579 | + weighted_pred_flag: u32, | |
| 580 | + weighted_bipred_idc: u32, | |
| 581 | + constrained_intra_pred_flag: u32, | |
| 582 | + transform_8x8_mode_flag: u32, | |
| 583 | + deblocking_filter_control_present_flag: u32, | |
| 584 | + redundant_pic_cnt_present_flag: u32, | |
| 585 | + pic_order_present_flag: u32, | |
| 586 | + pic_scaling_matrix_present_flag: u32, | |
| 587 | + ) -> Self { | |
| 588 | + let _bitfield_1 = | |
| 589 | + bindings::_VAEncPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 590 | + idr_pic_flag, | |
| 591 | + reference_pic_flag, | |
| 592 | + entropy_coding_mode_flag, | |
| 593 | + weighted_pred_flag, | |
| 594 | + weighted_bipred_idc, | |
| 595 | + constrained_intra_pred_flag, | |
| 596 | + transform_8x8_mode_flag, | |
| 597 | + deblocking_filter_control_present_flag, | |
| 598 | + redundant_pic_cnt_present_flag, | |
| 599 | + pic_order_present_flag, | |
| 600 | + pic_scaling_matrix_present_flag, | |
| 601 | + ); | |
| 602 | + | |
| 603 | + Self(bindings::_VAEncPictureParameterBufferH264__bindgen_ty_1 { | |
| 604 | + bits: bindings::_VAEncPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1 { | |
| 605 | + _bitfield_align_1: Default::default(), | |
| 606 | + _bitfield_1, | |
| 607 | + __bindgen_padding_0: Default::default(), | |
| 608 | + }, | |
| 609 | + }) | |
| 610 | + } | |
| 611 | +} | |
| 612 | + | |
| 613 | +pub struct EncPictureParameterBufferH264(Box<bindings::VAEncPictureParameterBufferH264>); | |
| 614 | + | |
| 615 | +impl EncPictureParameterBufferH264 { | |
| 616 | + #[allow(clippy::too_many_arguments)] | |
| 617 | + pub fn new( | |
| 618 | + curr_pic: PictureH264, | |
| 619 | + reference_frames: [PictureH264; 16usize], | |
| 620 | + coded_buf: bindings::VABufferID, | |
| 621 | + pic_parameter_set_id: u8, | |
| 622 | + seq_parameter_set_id: u8, | |
| 623 | + last_picture: u8, | |
| 624 | + frame_num: u16, | |
| 625 | + pic_init_qp: u8, | |
| 626 | + num_ref_idx_l0_active_minus1: u8, | |
| 627 | + num_ref_idx_l1_active_minus1: u8, | |
| 628 | + chroma_qp_index_offset: i8, | |
| 629 | + second_chroma_qp_index_offset: i8, | |
| 630 | + pic_fields: &H264EncPicFields, | |
| 631 | + ) -> Self { | |
| 632 | + let reference_frames = (0..16usize) | |
| 633 | + .map(|i| reference_frames[i].0) | |
| 634 | + .collect::<Vec<_>>() | |
| 635 | + .try_into() | |
| 636 | + // try_into is guaranteed to work because the iterator and target array have the same | |
| 637 | + // size. | |
| 638 | + .unwrap(); | |
| 639 | + | |
| 640 | + let pic_fields = pic_fields.0; | |
| 641 | + | |
| 642 | + Self(Box::new(bindings::_VAEncPictureParameterBufferH264 { | |
| 643 | + CurrPic: curr_pic.0, | |
| 644 | + ReferenceFrames: reference_frames, | |
| 645 | + coded_buf, | |
| 646 | + pic_parameter_set_id, | |
| 647 | + seq_parameter_set_id, | |
| 648 | + last_picture, | |
| 649 | + frame_num, | |
| 650 | + pic_init_qp, | |
| 651 | + num_ref_idx_l0_active_minus1, | |
| 652 | + num_ref_idx_l1_active_minus1, | |
| 653 | + chroma_qp_index_offset, | |
| 654 | + second_chroma_qp_index_offset, | |
| 655 | + pic_fields, | |
| 656 | + ..Default::default() | |
| 657 | + })) | |
| 658 | + } | |
| 659 | + | |
| 660 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferH264 { | |
| 661 | + self.0.as_mut() | |
| 662 | + } | |
| 663 | +} | |
| 664 | + | |
| 665 | +pub struct EncSliceParameterBufferH264(Box<bindings::VAEncSliceParameterBufferH264>); | |
| 666 | + | |
| 667 | +impl EncSliceParameterBufferH264 { | |
| 668 | + #[allow(clippy::too_many_arguments)] | |
| 669 | + pub fn new( | |
| 670 | + macroblock_address: u32, | |
| 671 | + num_macroblocks: u32, | |
| 672 | + macroblock_info: bindings::VABufferID, | |
| 673 | + slice_type: u8, | |
| 674 | + pic_parameter_set_id: u8, | |
| 675 | + idr_pic_id: u16, | |
| 676 | + pic_order_cnt_lsb: u16, | |
| 677 | + delta_pic_order_cnt_bottom: i32, | |
| 678 | + delta_pic_order_cnt: [i32; 2usize], | |
| 679 | + direct_spatial_mv_pred_flag: u8, | |
| 680 | + num_ref_idx_active_override_flag: u8, | |
| 681 | + num_ref_idx_l0_active_minus1: u8, | |
| 682 | + num_ref_idx_l1_active_minus1: u8, | |
| 683 | + ref_pic_list_0: [PictureH264; 32usize], | |
| 684 | + ref_pic_list_1: [PictureH264; 32usize], | |
| 685 | + luma_log2_weight_denom: u8, | |
| 686 | + chroma_log2_weight_denom: u8, | |
| 687 | + luma_weight_l0_flag: u8, | |
| 688 | + luma_weight_l0: [i16; 32usize], | |
| 689 | + luma_offset_l0: [i16; 32usize], | |
| 690 | + chroma_weight_l0_flag: u8, | |
| 691 | + chroma_weight_l0: [[i16; 2usize]; 32usize], | |
| 692 | + chroma_offset_l0: [[i16; 2usize]; 32usize], | |
| 693 | + luma_weight_l1_flag: u8, | |
| 694 | + luma_weight_l1: [i16; 32usize], | |
| 695 | + luma_offset_l1: [i16; 32usize], | |
| 696 | + chroma_weight_l1_flag: u8, | |
| 697 | + chroma_weight_l1: [[i16; 2usize]; 32usize], | |
| 698 | + chroma_offset_l1: [[i16; 2usize]; 32usize], | |
| 699 | + cabac_init_idc: u8, | |
| 700 | + slice_qp_delta: i8, | |
| 701 | + disable_deblocking_filter_idc: u8, | |
| 702 | + slice_alpha_c0_offset_div2: i8, | |
| 703 | + slice_beta_offset_div2: i8, | |
| 704 | + ) -> Self { | |
| 705 | + let ref_pic_list_0 = ref_pic_list_0.map(|pic| pic.0); | |
| 706 | + let ref_pic_list_1 = ref_pic_list_1.map(|pic| pic.0); | |
| 707 | + | |
| 708 | + Self(Box::new(bindings::VAEncSliceParameterBufferH264 { | |
| 709 | + macroblock_address, | |
| 710 | + num_macroblocks, | |
| 711 | + macroblock_info, | |
| 712 | + slice_type, | |
| 713 | + pic_parameter_set_id, | |
| 714 | + idr_pic_id, | |
| 715 | + pic_order_cnt_lsb, | |
| 716 | + delta_pic_order_cnt_bottom, | |
| 717 | + delta_pic_order_cnt, | |
| 718 | + direct_spatial_mv_pred_flag, | |
| 719 | + num_ref_idx_active_override_flag, | |
| 720 | + num_ref_idx_l0_active_minus1, | |
| 721 | + num_ref_idx_l1_active_minus1, | |
| 722 | + RefPicList0: ref_pic_list_0, | |
| 723 | + RefPicList1: ref_pic_list_1, | |
| 724 | + luma_log2_weight_denom, | |
| 725 | + chroma_log2_weight_denom, | |
| 726 | + luma_weight_l0_flag, | |
| 727 | + luma_weight_l0, | |
| 728 | + luma_offset_l0, | |
| 729 | + chroma_weight_l0_flag, | |
| 730 | + chroma_weight_l0, | |
| 731 | + chroma_offset_l0, | |
| 732 | + luma_weight_l1_flag, | |
| 733 | + luma_weight_l1, | |
| 734 | + luma_offset_l1, | |
| 735 | + chroma_weight_l1_flag, | |
| 736 | + chroma_weight_l1, | |
| 737 | + chroma_offset_l1, | |
| 738 | + cabac_init_idc, | |
| 739 | + slice_qp_delta, | |
| 740 | + disable_deblocking_filter_idc, | |
| 741 | + slice_alpha_c0_offset_div2, | |
| 742 | + slice_beta_offset_div2, | |
| 743 | + ..Default::default() | |
| 744 | + })) | |
| 745 | + } | |
| 746 | + | |
| 747 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSliceParameterBufferH264 { | |
| 748 | + self.0.as_mut() | |
| 749 | + } | |
| 750 | + | |
| 751 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 752 | + pub fn inner(&self) -> &bindings::VAEncSliceParameterBufferH264 { | |
| 753 | + self.0.as_ref() | |
| 754 | + } | |
| 755 | +} | |
| 756 | + | |
| 757 | +pub struct H264EncMacroblockInfo(bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1); | |
| 758 | + | |
| 759 | +impl H264EncMacroblockInfo { | |
| 760 | + pub fn new_intra(pred_avail_override_flag: u32, pred_avail_flags: u32) -> Self { | |
| 761 | + let _bitfield_1 = | |
| 762 | + bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(pred_avail_override_flag, pred_avail_flags); | |
| 763 | + | |
| 764 | + Self(bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1 { | |
| 765 | + intra_fields: bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_1 { | |
| 766 | + bits: bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { | |
| 767 | + _bitfield_align_1: Default::default(), | |
| 768 | + _bitfield_1, | |
| 769 | + __bindgen_padding_0: Default::default(), | |
| 770 | + } | |
| 771 | + } | |
| 772 | + }) | |
| 773 | + } | |
| 774 | + | |
| 775 | + pub fn new_inter() -> Self { | |
| 776 | + Self(bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1 { | |
| 777 | + inter_fields: bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_2 { | |
| 778 | + bits: bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1 { | |
| 779 | + reserved: Default::default() | |
| 780 | + } | |
| 781 | + } | |
| 782 | + }) | |
| 783 | + } | |
| 784 | +} | |
| 785 | + | |
| 786 | +pub struct EncMacroblockParameterBufferH264(Box<bindings::VAEncMacroblockParameterBufferH264>); | |
| 787 | + | |
| 788 | +impl EncMacroblockParameterBufferH264 { | |
| 789 | + pub fn new(qp: u8, info: &H264EncMacroblockInfo) -> Self { | |
| 790 | + let info = info.0; | |
| 791 | + | |
| 792 | + Self(Box::new(bindings::VAEncMacroblockParameterBufferH264 { | |
| 793 | + qp, | |
| 794 | + info, | |
| 795 | + ..Default::default() | |
| 796 | + })) | |
| 797 | + } | |
| 798 | + | |
| 799 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncMacroblockParameterBufferH264 { | |
| 800 | + self.0.as_mut() | |
| 801 | + } | |
| 802 | + | |
| 803 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 804 | + pub fn inner(&self) -> &bindings::VAEncMacroblockParameterBufferH264 { | |
| 805 | + self.0.as_ref() | |
| 806 | + } | |
| 807 | +} |
shims/cros-libva/src/buffer/hevc.rsadded+1154 -0
| @@ -0,0 +1,1154 @@ | ||
| 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 HEVC `VABuffer` types. | |
| 6 | + | |
| 7 | +use crate::bindings; | |
| 8 | + | |
| 9 | +/// Wrapper over the `VAPictureH264` FFI type. | |
| 10 | +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] | |
| 11 | +pub struct PictureHEVC(bindings::VAPictureHEVC); | |
| 12 | + | |
| 13 | +impl PictureHEVC { | |
| 14 | + /// Creates the wrapper | |
| 15 | + pub fn new(picture_id: bindings::VASurfaceID, pic_order_cnt: i32, flags: u32) -> Self { | |
| 16 | + Self(bindings::VAPictureHEVC { | |
| 17 | + picture_id, | |
| 18 | + pic_order_cnt, | |
| 19 | + flags, | |
| 20 | + va_reserved: Default::default(), | |
| 21 | + }) | |
| 22 | + } | |
| 23 | + | |
| 24 | + /// Returns the `picture_id` field. | |
| 25 | + pub fn picture_id(&self) -> u32 { | |
| 26 | + self.0.picture_id | |
| 27 | + } | |
| 28 | + | |
| 29 | + /// Returns the `pic_order_cnt` field. | |
| 30 | + pub fn pic_order_cnt(&self) -> i32 { | |
| 31 | + self.0.pic_order_cnt | |
| 32 | + } | |
| 33 | + | |
| 34 | + /// Returns the `flags` field. | |
| 35 | + pub fn flags(&self) -> u32 { | |
| 36 | + self.0.flags | |
| 37 | + } | |
| 38 | +} | |
| 39 | + | |
| 40 | +/// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferHEVC`. | |
| 41 | +pub struct HevcPicFields(bindings::_VAPictureParameterBufferHEVC__bindgen_ty_1); | |
| 42 | + | |
| 43 | +impl HevcPicFields { | |
| 44 | + /// Creates the bindgen field | |
| 45 | + #[allow(clippy::too_many_arguments)] | |
| 46 | + pub fn new( | |
| 47 | + chroma_format_idc: u32, | |
| 48 | + separate_colour_plane_flag: u32, | |
| 49 | + pcm_enabled_flag: u32, | |
| 50 | + scaling_list_enabled_flag: u32, | |
| 51 | + transform_skip_enabled_flag: u32, | |
| 52 | + amp_enabled_flag: u32, | |
| 53 | + strong_intra_smoothing_enabled_flag: u32, | |
| 54 | + sign_data_hiding_enabled_flag: u32, | |
| 55 | + constrained_intra_pred_flag: u32, | |
| 56 | + cu_qp_delta_enabled_flag: u32, | |
| 57 | + weighted_pred_flag: u32, | |
| 58 | + weighted_bipred_flag: u32, | |
| 59 | + transquant_bypass_enabled_flag: u32, | |
| 60 | + tiles_enabled_flag: u32, | |
| 61 | + entropy_coding_sync_enabled_flag: u32, | |
| 62 | + pps_loop_filter_across_slices_enabled_flag: u32, | |
| 63 | + loop_filter_across_tiles_enabled_flag: u32, | |
| 64 | + pcm_loop_filter_disabled_flag: u32, | |
| 65 | + no_pic_reordering_flag: u32, | |
| 66 | + no_bi_pred_flag: u32, | |
| 67 | + ) -> Self { | |
| 68 | + let _bitfield_1 = | |
| 69 | + bindings::_VAPictureParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 70 | + chroma_format_idc, | |
| 71 | + separate_colour_plane_flag, | |
| 72 | + pcm_enabled_flag, | |
| 73 | + scaling_list_enabled_flag, | |
| 74 | + transform_skip_enabled_flag, | |
| 75 | + amp_enabled_flag, | |
| 76 | + strong_intra_smoothing_enabled_flag, | |
| 77 | + sign_data_hiding_enabled_flag, | |
| 78 | + constrained_intra_pred_flag, | |
| 79 | + cu_qp_delta_enabled_flag, | |
| 80 | + weighted_pred_flag, | |
| 81 | + weighted_bipred_flag, | |
| 82 | + transquant_bypass_enabled_flag, | |
| 83 | + tiles_enabled_flag, | |
| 84 | + entropy_coding_sync_enabled_flag, | |
| 85 | + pps_loop_filter_across_slices_enabled_flag, | |
| 86 | + loop_filter_across_tiles_enabled_flag, | |
| 87 | + pcm_loop_filter_disabled_flag, | |
| 88 | + no_pic_reordering_flag, | |
| 89 | + no_bi_pred_flag, | |
| 90 | + 0, | |
| 91 | + ); | |
| 92 | + | |
| 93 | + Self(bindings::_VAPictureParameterBufferHEVC__bindgen_ty_1 { | |
| 94 | + bits: bindings::_VAPictureParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1 { | |
| 95 | + _bitfield_align_1: Default::default(), | |
| 96 | + _bitfield_1, | |
| 97 | + }, | |
| 98 | + }) | |
| 99 | + } | |
| 100 | + | |
| 101 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 102 | + pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferHEVC__bindgen_ty_1 { | |
| 103 | + &self.0 | |
| 104 | + } | |
| 105 | +} | |
| 106 | + | |
| 107 | +/// Wrapper over the `slice_parsing_fields` bindgen field in `VAPictureParameterBufferHEVC`. | |
| 108 | +pub struct HevcSliceParsingFields(bindings::_VAPictureParameterBufferHEVC__bindgen_ty_2); | |
| 109 | + | |
| 110 | +impl HevcSliceParsingFields { | |
| 111 | + /// Creates the bindgen field | |
| 112 | + #[allow(clippy::too_many_arguments)] | |
| 113 | + pub fn new( | |
| 114 | + lists_modification_present_flag: u32, | |
| 115 | + long_term_ref_pics_present_flag: u32, | |
| 116 | + sps_temporal_mvp_enabled_flag: u32, | |
| 117 | + cabac_init_present_flag: u32, | |
| 118 | + output_flag_present_flag: u32, | |
| 119 | + dependent_slice_segments_enabled_flag: u32, | |
| 120 | + pps_slice_chroma_qp_offsets_present_flag: u32, | |
| 121 | + sample_adaptive_offset_enabled_flag: u32, | |
| 122 | + deblocking_filter_override_enabled_flag: u32, | |
| 123 | + pps_disable_deblocking_filter_flag: u32, | |
| 124 | + slice_segment_header_extension_present_flag: u32, | |
| 125 | + rap_pic_flag: u32, | |
| 126 | + idr_pic_flag: u32, | |
| 127 | + intra_pic_flag: u32, | |
| 128 | + ) -> Self { | |
| 129 | + let _bitfield_1 = | |
| 130 | + bindings::_VAPictureParameterBufferHEVC__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
| 131 | + lists_modification_present_flag, | |
| 132 | + long_term_ref_pics_present_flag, | |
| 133 | + sps_temporal_mvp_enabled_flag, | |
| 134 | + cabac_init_present_flag, | |
| 135 | + output_flag_present_flag, | |
| 136 | + dependent_slice_segments_enabled_flag, | |
| 137 | + pps_slice_chroma_qp_offsets_present_flag, | |
| 138 | + sample_adaptive_offset_enabled_flag, | |
| 139 | + deblocking_filter_override_enabled_flag, | |
| 140 | + pps_disable_deblocking_filter_flag, | |
| 141 | + slice_segment_header_extension_present_flag, | |
| 142 | + rap_pic_flag, | |
| 143 | + idr_pic_flag, | |
| 144 | + intra_pic_flag, | |
| 145 | + 0, | |
| 146 | + ); | |
| 147 | + | |
| 148 | + Self(bindings::_VAPictureParameterBufferHEVC__bindgen_ty_2 { | |
| 149 | + bits: bindings::_VAPictureParameterBufferHEVC__bindgen_ty_2__bindgen_ty_1 { | |
| 150 | + _bitfield_align_1: Default::default(), | |
| 151 | + _bitfield_1, | |
| 152 | + }, | |
| 153 | + }) | |
| 154 | + } | |
| 155 | + | |
| 156 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 157 | + pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferHEVC__bindgen_ty_2 { | |
| 158 | + &self.0 | |
| 159 | + } | |
| 160 | +} | |
| 161 | + | |
| 162 | +/// A wrapper over `VAPictureParameterBufferHEVC` FFI type | |
| 163 | +pub struct PictureParameterBufferHEVC(Box<bindings::VAPictureParameterBufferHEVC>); | |
| 164 | + | |
| 165 | +impl PictureParameterBufferHEVC { | |
| 166 | + /// Creates the wrapper | |
| 167 | + #[allow(clippy::too_many_arguments)] | |
| 168 | + pub fn new( | |
| 169 | + curr_pic: PictureHEVC, | |
| 170 | + reference_frames: [PictureHEVC; 15], | |
| 171 | + pic_width_in_luma_samples: u16, | |
| 172 | + pic_height_in_luma_samples: u16, | |
| 173 | + pic_fields: &HevcPicFields, | |
| 174 | + sps_max_dec_pic_buffering_minus1: u8, | |
| 175 | + bit_depth_luma_minus8: u8, | |
| 176 | + bit_depth_chroma_minus8: u8, | |
| 177 | + pcm_sample_bit_depth_luma_minus1: u8, | |
| 178 | + pcm_sample_bit_depth_chroma_minus1: u8, | |
| 179 | + log2_min_luma_coding_block_size_minus3: u8, | |
| 180 | + log2_diff_max_min_luma_coding_block_size: u8, | |
| 181 | + log2_min_transform_block_size_minus2: u8, | |
| 182 | + log2_diff_max_min_transform_block_size: u8, | |
| 183 | + log2_min_pcm_luma_coding_block_size_minus3: u8, | |
| 184 | + log2_diff_max_min_pcm_luma_coding_block_size: u8, | |
| 185 | + max_transform_hierarchy_depth_intra: u8, | |
| 186 | + max_transform_hierarchy_depth_inter: u8, | |
| 187 | + init_qp_minus26: i8, | |
| 188 | + diff_cu_qp_delta_depth: u8, | |
| 189 | + pps_cb_qp_offset: i8, | |
| 190 | + pps_cr_qp_offset: i8, | |
| 191 | + log2_parallel_merge_level_minus2: u8, | |
| 192 | + num_tile_columns_minus1: u8, | |
| 193 | + num_tile_rows_minus1: u8, | |
| 194 | + column_width_minus1: [u16; 19], | |
| 195 | + row_height_minus1: [u16; 21], | |
| 196 | + slice_parsing_fields: &HevcSliceParsingFields, | |
| 197 | + log2_max_pic_order_cnt_lsb_minus4: u8, | |
| 198 | + num_short_term_ref_pic_sets: u8, | |
| 199 | + num_long_term_ref_pic_sps: u8, | |
| 200 | + num_ref_idx_l0_default_active_minus1: u8, | |
| 201 | + num_ref_idx_l1_default_active_minus1: u8, | |
| 202 | + pps_beta_offset_div2: i8, | |
| 203 | + pps_tc_offset_div2: i8, | |
| 204 | + num_extra_slice_header_bits: u8, | |
| 205 | + st_rps_bits: u32, | |
| 206 | + ) -> Self { | |
| 207 | + let reference_frames = (0..15usize) | |
| 208 | + .map(|i| reference_frames[i].0) | |
| 209 | + .collect::<Vec<_>>() | |
| 210 | + .try_into() | |
| 211 | + // try_into is guaranteed to work because the iterator and target array have the same | |
| 212 | + // size. | |
| 213 | + .unwrap(); | |
| 214 | + | |
| 215 | + let pic_fields = pic_fields.0; | |
| 216 | + let slice_parsing_fields = slice_parsing_fields.0; | |
| 217 | + | |
| 218 | + Self(Box::new(bindings::VAPictureParameterBufferHEVC { | |
| 219 | + CurrPic: curr_pic.0, | |
| 220 | + ReferenceFrames: reference_frames, | |
| 221 | + pic_width_in_luma_samples, | |
| 222 | + pic_height_in_luma_samples, | |
| 223 | + pic_fields, | |
| 224 | + sps_max_dec_pic_buffering_minus1, | |
| 225 | + bit_depth_luma_minus8, | |
| 226 | + bit_depth_chroma_minus8, | |
| 227 | + pcm_sample_bit_depth_luma_minus1, | |
| 228 | + pcm_sample_bit_depth_chroma_minus1, | |
| 229 | + log2_min_luma_coding_block_size_minus3, | |
| 230 | + log2_diff_max_min_luma_coding_block_size, | |
| 231 | + log2_min_transform_block_size_minus2, | |
| 232 | + log2_diff_max_min_transform_block_size, | |
| 233 | + log2_min_pcm_luma_coding_block_size_minus3, | |
| 234 | + log2_diff_max_min_pcm_luma_coding_block_size, | |
| 235 | + max_transform_hierarchy_depth_intra, | |
| 236 | + max_transform_hierarchy_depth_inter, | |
| 237 | + init_qp_minus26, | |
| 238 | + diff_cu_qp_delta_depth, | |
| 239 | + pps_cb_qp_offset, | |
| 240 | + pps_cr_qp_offset, | |
| 241 | + log2_parallel_merge_level_minus2, | |
| 242 | + num_tile_columns_minus1, | |
| 243 | + num_tile_rows_minus1, | |
| 244 | + column_width_minus1, | |
| 245 | + row_height_minus1, | |
| 246 | + slice_parsing_fields, | |
| 247 | + log2_max_pic_order_cnt_lsb_minus4, | |
| 248 | + num_short_term_ref_pic_sets, | |
| 249 | + num_long_term_ref_pic_sps, | |
| 250 | + num_ref_idx_l0_default_active_minus1, | |
| 251 | + num_ref_idx_l1_default_active_minus1, | |
| 252 | + pps_beta_offset_div2, | |
| 253 | + pps_tc_offset_div2, | |
| 254 | + num_extra_slice_header_bits, | |
| 255 | + st_rps_bits, | |
| 256 | + va_reserved: Default::default(), | |
| 257 | + })) | |
| 258 | + } | |
| 259 | + | |
| 260 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferHEVC { | |
| 261 | + self.0.as_mut() | |
| 262 | + } | |
| 263 | + | |
| 264 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 265 | + pub fn inner(&self) -> &bindings::VAPictureParameterBufferHEVC { | |
| 266 | + self.0.as_ref() | |
| 267 | + } | |
| 268 | +} | |
| 269 | + | |
| 270 | +/// Wrapper over the `range_extension_pic_fields` bindgen field in `VAPictureParameterBufferHEVCRext`. | |
| 271 | +pub struct HevcRangeExtensionPicFields(bindings::_VAPictureParameterBufferHEVCRext__bindgen_ty_1); | |
| 272 | + | |
| 273 | +impl HevcRangeExtensionPicFields { | |
| 274 | + /// Creates the bindgen field | |
| 275 | + #[allow(clippy::too_many_arguments)] | |
| 276 | + pub fn new( | |
| 277 | + transform_skip_rotation_enabled_flag: u32, | |
| 278 | + transform_skip_context_enabled_flag: u32, | |
| 279 | + implicit_rdpcm_enabled_flag: u32, | |
| 280 | + explicit_rdpcm_enabled_flag: u32, | |
| 281 | + extended_precision_processing_flag: u32, | |
| 282 | + intra_smoothing_disabled_flag: u32, | |
| 283 | + high_precision_offsets_enabled_flag: u32, | |
| 284 | + persistent_rice_adaptation_enabled_flag: u32, | |
| 285 | + cabac_bypass_alignment_enabled_flag: u32, | |
| 286 | + cross_component_prediction_enabled_flag: u32, | |
| 287 | + chroma_qp_offset_list_enabled_flag: u32, | |
| 288 | + ) -> Self { | |
| 289 | + let _bitfield_1 = | |
| 290 | + bindings::_VAPictureParameterBufferHEVCRext__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 291 | + transform_skip_rotation_enabled_flag, | |
| 292 | + transform_skip_context_enabled_flag, | |
| 293 | + implicit_rdpcm_enabled_flag, | |
| 294 | + explicit_rdpcm_enabled_flag, | |
| 295 | + extended_precision_processing_flag, | |
| 296 | + intra_smoothing_disabled_flag, | |
| 297 | + high_precision_offsets_enabled_flag, | |
| 298 | + persistent_rice_adaptation_enabled_flag, | |
| 299 | + cabac_bypass_alignment_enabled_flag, | |
| 300 | + cross_component_prediction_enabled_flag, | |
| 301 | + chroma_qp_offset_list_enabled_flag, | |
| 302 | + 0, | |
| 303 | + ); | |
| 304 | + | |
| 305 | + Self(bindings::_VAPictureParameterBufferHEVCRext__bindgen_ty_1 { | |
| 306 | + bits: bindings::_VAPictureParameterBufferHEVCRext__bindgen_ty_1__bindgen_ty_1 { | |
| 307 | + _bitfield_align_1: Default::default(), | |
| 308 | + _bitfield_1, | |
| 309 | + }, | |
| 310 | + }) | |
| 311 | + } | |
| 312 | + | |
| 313 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 314 | + pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferHEVCRext__bindgen_ty_1 { | |
| 315 | + &self.0 | |
| 316 | + } | |
| 317 | +} | |
| 318 | + | |
| 319 | +/// A wrapper over `VAPictureParameterBufferHEVCRext` FFI type | |
| 320 | +pub struct PictureParameterBufferHEVCRext(Box<bindings::VAPictureParameterBufferHEVCRext>); | |
| 321 | + | |
| 322 | +impl PictureParameterBufferHEVCRext { | |
| 323 | + /// Creates the wrapper | |
| 324 | + #[allow(clippy::too_many_arguments)] | |
| 325 | + pub fn new( | |
| 326 | + range_extension_pic_fields: &HevcRangeExtensionPicFields, | |
| 327 | + diff_cu_chroma_qp_offset_depth: u8, | |
| 328 | + chroma_qp_offset_list_len_minus1: u8, | |
| 329 | + log2_sao_offset_scale_luma: u8, | |
| 330 | + log2_sao_offset_scale_chroma: u8, | |
| 331 | + log2_max_transform_skip_block_size_minus2: u8, | |
| 332 | + cb_qp_offset_list: [i8; 6usize], | |
| 333 | + cr_qp_offset_list: [i8; 6usize], | |
| 334 | + ) -> Self { | |
| 335 | + let range_extension_pic_fields = range_extension_pic_fields.0; | |
| 336 | + | |
| 337 | + Self(Box::new(bindings::VAPictureParameterBufferHEVCRext { | |
| 338 | + range_extension_pic_fields, | |
| 339 | + diff_cu_chroma_qp_offset_depth, | |
| 340 | + chroma_qp_offset_list_len_minus1, | |
| 341 | + log2_sao_offset_scale_luma, | |
| 342 | + log2_sao_offset_scale_chroma, | |
| 343 | + log2_max_transform_skip_block_size_minus2, | |
| 344 | + cb_qp_offset_list, | |
| 345 | + cr_qp_offset_list, | |
| 346 | + })) | |
| 347 | + } | |
| 348 | + | |
| 349 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferHEVCRext { | |
| 350 | + self.0.as_mut() | |
| 351 | + } | |
| 352 | + | |
| 353 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 354 | + pub fn inner(&self) -> &bindings::VAPictureParameterBufferHEVCRext { | |
| 355 | + self.0.as_ref() | |
| 356 | + } | |
| 357 | +} | |
| 358 | + | |
| 359 | +/// Wrapper over the `screen_content_pic_fields` bindgen field in `VAPictureParameterBufferHEVCScc`. | |
| 360 | +pub struct HevcScreenContentPicFields(bindings::_VAPictureParameterBufferHEVCScc__bindgen_ty_1); | |
| 361 | + | |
| 362 | +impl HevcScreenContentPicFields { | |
| 363 | + /// Creates the bindgen field | |
| 364 | + #[allow(clippy::too_many_arguments)] | |
| 365 | + pub fn new( | |
| 366 | + pps_curr_pic_ref_enabled_flag: u32, | |
| 367 | + palette_mode_enabled_flag: u32, | |
| 368 | + motion_vector_resolution_control_idc: u32, | |
| 369 | + intra_boundary_filtering_disabled_flag: u32, | |
| 370 | + residual_adaptive_colour_transform_enabled_flag: u32, | |
| 371 | + pps_slice_act_qp_offsets_present_flag: u32, | |
| 372 | + ) -> Self { | |
| 373 | + let _bitfield_1 = | |
| 374 | + bindings::_VAPictureParameterBufferHEVCScc__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 375 | + pps_curr_pic_ref_enabled_flag, | |
| 376 | + palette_mode_enabled_flag, | |
| 377 | + motion_vector_resolution_control_idc, | |
| 378 | + intra_boundary_filtering_disabled_flag, | |
| 379 | + residual_adaptive_colour_transform_enabled_flag, | |
| 380 | + pps_slice_act_qp_offsets_present_flag, | |
| 381 | + 0, | |
| 382 | + ); | |
| 383 | + | |
| 384 | + Self(bindings::_VAPictureParameterBufferHEVCScc__bindgen_ty_1 { | |
| 385 | + bits: bindings::_VAPictureParameterBufferHEVCScc__bindgen_ty_1__bindgen_ty_1 { | |
| 386 | + _bitfield_align_1: Default::default(), | |
| 387 | + _bitfield_1, | |
| 388 | + }, | |
| 389 | + }) | |
| 390 | + } | |
| 391 | + | |
| 392 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 393 | + pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferHEVCScc__bindgen_ty_1 { | |
| 394 | + &self.0 | |
| 395 | + } | |
| 396 | +} | |
| 397 | + | |
| 398 | +/// A wrapper over `VAPictureParameterBufferScc` FFI type | |
| 399 | +pub struct PictureParameterBufferHEVCScc(Box<bindings::VAPictureParameterBufferHEVCScc>); | |
| 400 | + | |
| 401 | +impl PictureParameterBufferHEVCScc { | |
| 402 | + /// Creates the wrapper | |
| 403 | + #[allow(clippy::too_many_arguments)] | |
| 404 | + pub fn new( | |
| 405 | + screen_content_pic_fields: &HevcScreenContentPicFields, | |
| 406 | + palette_max_size: u8, | |
| 407 | + delta_palette_max_predictor_size: u8, | |
| 408 | + predictor_palette_size: u8, | |
| 409 | + predictor_palette_entries: [[u16; 128usize]; 3usize], | |
| 410 | + pps_act_y_qp_offset_plus5: i8, | |
| 411 | + pps_act_cb_qp_offset_plus5: i8, | |
| 412 | + pps_act_cr_qp_offset_plus3: i8, | |
| 413 | + ) -> Self { | |
| 414 | + let screen_content_pic_fields = screen_content_pic_fields.0; | |
| 415 | + | |
| 416 | + Self(Box::new(bindings::VAPictureParameterBufferHEVCScc { | |
| 417 | + screen_content_pic_fields, | |
| 418 | + palette_max_size, | |
| 419 | + delta_palette_max_predictor_size, | |
| 420 | + predictor_palette_size, | |
| 421 | + predictor_palette_entries, | |
| 422 | + pps_act_y_qp_offset_plus5, | |
| 423 | + pps_act_cb_qp_offset_plus5, | |
| 424 | + pps_act_cr_qp_offset_plus3, | |
| 425 | + })) | |
| 426 | + } | |
| 427 | + | |
| 428 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferHEVCScc { | |
| 429 | + self.0.as_mut() | |
| 430 | + } | |
| 431 | + | |
| 432 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 433 | + pub fn inner(&self) -> &bindings::VAPictureParameterBufferHEVCScc { | |
| 434 | + self.0.as_ref() | |
| 435 | + } | |
| 436 | +} | |
| 437 | + | |
| 438 | +/// Wrapper over the `long_slice_flags` bindgen field in `VASliceParameterBufferHEVC`. | |
| 439 | +pub struct HevcLongSliceFlags(bindings::_VASliceParameterBufferHEVC__bindgen_ty_1); | |
| 440 | + | |
| 441 | +impl HevcLongSliceFlags { | |
| 442 | + /// Creates the bindgen field | |
| 443 | + #[allow(clippy::too_many_arguments)] | |
| 444 | + pub fn new( | |
| 445 | + last_slice_of_pic: u32, | |
| 446 | + dependent_slice_segment_flag: u32, | |
| 447 | + slice_type: u32, | |
| 448 | + color_plane_id: u32, | |
| 449 | + slice_sao_luma_flag: u32, | |
| 450 | + slice_sao_chroma_flag: u32, | |
| 451 | + mvd_l1_zero_flag: u32, | |
| 452 | + cabac_init_flag: u32, | |
| 453 | + slice_temporal_mvp_enabled_flag: u32, | |
| 454 | + slice_deblocking_filter_disabled_flag: u32, | |
| 455 | + collocated_from_l0_flag: u32, | |
| 456 | + slice_loop_filter_across_slices_enabled_flag: u32, | |
| 457 | + ) -> Self { | |
| 458 | + let _bitfield_1 = | |
| 459 | + bindings::_VASliceParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 460 | + last_slice_of_pic, | |
| 461 | + dependent_slice_segment_flag, | |
| 462 | + slice_type, | |
| 463 | + color_plane_id, | |
| 464 | + slice_sao_luma_flag, | |
| 465 | + slice_sao_chroma_flag, | |
| 466 | + mvd_l1_zero_flag, | |
| 467 | + cabac_init_flag, | |
| 468 | + slice_temporal_mvp_enabled_flag, | |
| 469 | + slice_deblocking_filter_disabled_flag, | |
| 470 | + collocated_from_l0_flag, | |
| 471 | + slice_loop_filter_across_slices_enabled_flag, | |
| 472 | + 0, | |
| 473 | + ); | |
| 474 | + | |
| 475 | + Self(bindings::_VASliceParameterBufferHEVC__bindgen_ty_1 { | |
| 476 | + fields: bindings::_VASliceParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1 { | |
| 477 | + _bitfield_align_1: Default::default(), | |
| 478 | + _bitfield_1, | |
| 479 | + }, | |
| 480 | + }) | |
| 481 | + } | |
| 482 | + | |
| 483 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 484 | + pub fn inner(&mut self) -> &bindings::_VASliceParameterBufferHEVC__bindgen_ty_1 { | |
| 485 | + &self.0 | |
| 486 | + } | |
| 487 | +} | |
| 488 | + | |
| 489 | +/// A wrapper over `VASliceParameterBufferHEVC` FFI type | |
| 490 | +pub struct SliceParameterBufferHEVC(Box<bindings::VASliceParameterBufferHEVC>); | |
| 491 | + | |
| 492 | +impl SliceParameterBufferHEVC { | |
| 493 | + /// Creates the wrapper | |
| 494 | + #[allow(clippy::too_many_arguments)] | |
| 495 | + pub fn new( | |
| 496 | + slice_data_size: u32, | |
| 497 | + slice_data_offset: u32, | |
| 498 | + slice_data_flag: u32, | |
| 499 | + slice_data_byte_offset: u32, | |
| 500 | + slice_segment_address: u32, | |
| 501 | + ref_pic_list: [[u8; 15usize]; 2usize], | |
| 502 | + long_slice_flags: &HevcLongSliceFlags, | |
| 503 | + collocated_ref_idx: u8, | |
| 504 | + num_ref_idx_l0_active_minus1: u8, | |
| 505 | + num_ref_idx_l1_active_minus1: u8, | |
| 506 | + slice_qp_delta: i8, | |
| 507 | + slice_cb_qp_offset: i8, | |
| 508 | + slice_cr_qp_offset: i8, | |
| 509 | + slice_beta_offset_div2: i8, | |
| 510 | + slice_tc_offset_div2: i8, | |
| 511 | + luma_log2_weight_denom: u8, | |
| 512 | + delta_chroma_log2_weight_denom: i8, | |
| 513 | + delta_luma_weight_l0: [i8; 15usize], | |
| 514 | + luma_offset_l0: [i8; 15usize], | |
| 515 | + delta_chroma_weight_l0: [[i8; 2usize]; 15usize], | |
| 516 | + chroma_offset_l0: [[i8; 2usize]; 15usize], | |
| 517 | + delta_luma_weight_l1: [i8; 15usize], | |
| 518 | + luma_offset_l1: [i8; 15usize], | |
| 519 | + delta_chroma_weight_l1: [[i8; 2usize]; 15usize], | |
| 520 | + chroma_offset_l1: [[i8; 2usize]; 15usize], | |
| 521 | + five_minus_max_num_merge_cand: u8, | |
| 522 | + num_entry_point_offsets: u16, | |
| 523 | + entry_offset_to_subset_array: u16, | |
| 524 | + slice_data_num_emu_prevn_bytes: u16, | |
| 525 | + ) -> Self { | |
| 526 | + let long_slice_flags = long_slice_flags.0; | |
| 527 | + | |
| 528 | + Self(Box::new(bindings::VASliceParameterBufferHEVC { | |
| 529 | + slice_data_size, | |
| 530 | + slice_data_offset, | |
| 531 | + slice_data_flag, | |
| 532 | + slice_data_byte_offset, | |
| 533 | + slice_segment_address, | |
| 534 | + RefPicList: ref_pic_list, | |
| 535 | + LongSliceFlags: long_slice_flags, | |
| 536 | + collocated_ref_idx, | |
| 537 | + num_ref_idx_l0_active_minus1, | |
| 538 | + num_ref_idx_l1_active_minus1, | |
| 539 | + slice_qp_delta, | |
| 540 | + slice_cb_qp_offset, | |
| 541 | + slice_cr_qp_offset, | |
| 542 | + slice_beta_offset_div2, | |
| 543 | + slice_tc_offset_div2, | |
| 544 | + luma_log2_weight_denom, | |
| 545 | + delta_chroma_log2_weight_denom, | |
| 546 | + delta_luma_weight_l0, | |
| 547 | + luma_offset_l0, | |
| 548 | + delta_chroma_weight_l0, | |
| 549 | + ChromaOffsetL0: chroma_offset_l0, | |
| 550 | + delta_luma_weight_l1, | |
| 551 | + luma_offset_l1, | |
| 552 | + delta_chroma_weight_l1, | |
| 553 | + ChromaOffsetL1: chroma_offset_l1, | |
| 554 | + five_minus_max_num_merge_cand, | |
| 555 | + num_entry_point_offsets, | |
| 556 | + entry_offset_to_subset_array, | |
| 557 | + slice_data_num_emu_prevn_bytes, | |
| 558 | + va_reserved: Default::default(), | |
| 559 | + })) | |
| 560 | + } | |
| 561 | + | |
| 562 | + /// Set this slice as the last one after creation. Implementations may only | |
| 563 | + /// be able to conveniently see if this is the last slice after it has been | |
| 564 | + /// created. | |
| 565 | + pub fn set_as_last(&mut self) { | |
| 566 | + // Safe because we know that both fields are valid at all times (just a | |
| 567 | + // different view on the data), and we are mutating through the bindgen | |
| 568 | + // function, respecting the padding in place. | |
| 569 | + unsafe { self.inner_mut().LongSliceFlags.fields.set_LastSliceOfPic(1) }; | |
| 570 | + } | |
| 571 | + | |
| 572 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferHEVC { | |
| 573 | + self.0.as_mut() | |
| 574 | + } | |
| 575 | + | |
| 576 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 577 | + pub fn inner(&self) -> &bindings::VASliceParameterBufferHEVC { | |
| 578 | + self.0.as_ref() | |
| 579 | + } | |
| 580 | +} | |
| 581 | + | |
| 582 | +/// Wrapper over the `slice_ext_flags` bindgen field in `VASliceParameterBufferHEVCRext`. | |
| 583 | +pub struct HevcSliceExtFlags(bindings::_VASliceParameterBufferHEVCRext__bindgen_ty_1); | |
| 584 | + | |
| 585 | +impl HevcSliceExtFlags { | |
| 586 | + /// Creates the bindgen field | |
| 587 | + #[allow(clippy::too_many_arguments)] | |
| 588 | + pub fn new(cu_chroma_qp_offset_enabled_flag: u32, use_integer_mv_flag: u32) -> Self { | |
| 589 | + let _bitfield_1 = | |
| 590 | + bindings::_VASliceParameterBufferHEVCRext__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 591 | + cu_chroma_qp_offset_enabled_flag, | |
| 592 | + use_integer_mv_flag, | |
| 593 | + 0, | |
| 594 | + ); | |
| 595 | + | |
| 596 | + Self(bindings::_VASliceParameterBufferHEVCRext__bindgen_ty_1 { | |
| 597 | + bits: bindings::_VASliceParameterBufferHEVCRext__bindgen_ty_1__bindgen_ty_1 { | |
| 598 | + _bitfield_align_1: Default::default(), | |
| 599 | + _bitfield_1, | |
| 600 | + }, | |
| 601 | + }) | |
| 602 | + } | |
| 603 | + | |
| 604 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 605 | + pub fn inner(&mut self) -> &bindings::_VASliceParameterBufferHEVCRext__bindgen_ty_1 { | |
| 606 | + &self.0 | |
| 607 | + } | |
| 608 | +} | |
| 609 | + | |
| 610 | +/// A wrapper over `VASliceParameterBufferHEVCRext` FFI type | |
| 611 | +pub struct SliceParameterBufferHEVCRext(Box<bindings::VASliceParameterBufferHEVCRext>); | |
| 612 | + | |
| 613 | +impl SliceParameterBufferHEVCRext { | |
| 614 | + /// Creates the wrapper | |
| 615 | + #[allow(clippy::too_many_arguments)] | |
| 616 | + pub fn new( | |
| 617 | + luma_offset_l0: [i16; 15usize], | |
| 618 | + chroma_offset_l0: [[i16; 2usize]; 15usize], | |
| 619 | + luma_offset_l1: [i16; 15usize], | |
| 620 | + chroma_offset_l1: [[i16; 2usize]; 15usize], | |
| 621 | + slice_ext_flags: &HevcSliceExtFlags, | |
| 622 | + slice_act_y_qp_offset: i8, | |
| 623 | + slice_act_cb_qp_offset: i8, | |
| 624 | + slice_act_cr_qp_offset: i8, | |
| 625 | + ) -> Self { | |
| 626 | + let slice_ext_flags = slice_ext_flags.0; | |
| 627 | + | |
| 628 | + Self(Box::new(bindings::VASliceParameterBufferHEVCRext { | |
| 629 | + luma_offset_l0, | |
| 630 | + ChromaOffsetL0: chroma_offset_l0, | |
| 631 | + luma_offset_l1, | |
| 632 | + ChromaOffsetL1: chroma_offset_l1, | |
| 633 | + slice_ext_flags, | |
| 634 | + slice_act_y_qp_offset, | |
| 635 | + slice_act_cb_qp_offset, | |
| 636 | + slice_act_cr_qp_offset, | |
| 637 | + })) | |
| 638 | + } | |
| 639 | + | |
| 640 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferHEVCRext { | |
| 641 | + self.0.as_mut() | |
| 642 | + } | |
| 643 | + | |
| 644 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 645 | + pub fn inner(&self) -> &bindings::VASliceParameterBufferHEVCRext { | |
| 646 | + self.0.as_ref() | |
| 647 | + } | |
| 648 | +} | |
| 649 | + | |
| 650 | +/// A wrapper over `VAIQMatrixBufferHEVC` FFI type | |
| 651 | +pub struct IQMatrixBufferHEVC(Box<bindings::VAIQMatrixBufferHEVC>); | |
| 652 | + | |
| 653 | +impl IQMatrixBufferHEVC { | |
| 654 | + /// Creates the wrapper | |
| 655 | + #[allow(clippy::too_many_arguments)] | |
| 656 | + pub fn new( | |
| 657 | + scaling_list4x4: [[u8; 16usize]; 6usize], | |
| 658 | + scaling_list8x8: [[u8; 64usize]; 6usize], | |
| 659 | + scaling_list16x16: [[u8; 64usize]; 6usize], | |
| 660 | + scaling_list32x32: [[u8; 64usize]; 2usize], | |
| 661 | + scaling_list_dc16x16: [u8; 6usize], | |
| 662 | + scaling_list_dc32x32: [u8; 2usize], | |
| 663 | + ) -> Self { | |
| 664 | + Self(Box::new(bindings::VAIQMatrixBufferHEVC { | |
| 665 | + ScalingList4x4: scaling_list4x4, | |
| 666 | + ScalingList8x8: scaling_list8x8, | |
| 667 | + ScalingList16x16: scaling_list16x16, | |
| 668 | + ScalingList32x32: scaling_list32x32, | |
| 669 | + ScalingListDC16x16: scaling_list_dc16x16, | |
| 670 | + ScalingListDC32x32: scaling_list_dc32x32, | |
| 671 | + va_reserved: Default::default(), | |
| 672 | + })) | |
| 673 | + } | |
| 674 | + | |
| 675 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferHEVC { | |
| 676 | + self.0.as_mut() | |
| 677 | + } | |
| 678 | + | |
| 679 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 680 | + pub fn inner(&self) -> &bindings::VAIQMatrixBufferHEVC { | |
| 681 | + self.0.as_ref() | |
| 682 | + } | |
| 683 | +} | |
| 684 | + | |
| 685 | +pub struct HEVCEncSeqFields(bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_1); | |
| 686 | + | |
| 687 | +impl HEVCEncSeqFields { | |
| 688 | + #[allow(clippy::too_many_arguments)] | |
| 689 | + pub fn new( | |
| 690 | + chroma_format_idc: u32, | |
| 691 | + separate_colour_plane_flag: u32, | |
| 692 | + bit_depth_luma_minus8: u32, | |
| 693 | + bit_depth_chroma_minus8: u32, | |
| 694 | + scaling_list_enabled_flag: u32, | |
| 695 | + strong_intra_smoothing_enabled_flag: u32, | |
| 696 | + amp_enabled_flag: u32, | |
| 697 | + sample_adaptive_offset_enabled_flag: u32, | |
| 698 | + pcm_enabled_flag: u32, | |
| 699 | + pcm_loop_filter_disabled_flag: u32, | |
| 700 | + sps_temporal_mvp_enabled_flag: u32, | |
| 701 | + low_delay_seq: u32, | |
| 702 | + hierachical_flag: u32, | |
| 703 | + ) -> Self { | |
| 704 | + let _bitfield_1 = | |
| 705 | + bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 706 | + chroma_format_idc, | |
| 707 | + separate_colour_plane_flag, | |
| 708 | + bit_depth_luma_minus8, | |
| 709 | + bit_depth_chroma_minus8, | |
| 710 | + scaling_list_enabled_flag, | |
| 711 | + strong_intra_smoothing_enabled_flag, | |
| 712 | + amp_enabled_flag, | |
| 713 | + sample_adaptive_offset_enabled_flag, | |
| 714 | + pcm_enabled_flag, | |
| 715 | + pcm_loop_filter_disabled_flag, | |
| 716 | + sps_temporal_mvp_enabled_flag, | |
| 717 | + low_delay_seq, | |
| 718 | + hierachical_flag, | |
| 719 | + Default::default(), | |
| 720 | + ); | |
| 721 | + | |
| 722 | + Self(bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_1 { | |
| 723 | + bits: bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1 { | |
| 724 | + _bitfield_align_1: Default::default(), | |
| 725 | + _bitfield_1, | |
| 726 | + }, | |
| 727 | + }) | |
| 728 | + } | |
| 729 | +} | |
| 730 | + | |
| 731 | +#[derive(Default)] | |
| 732 | +pub struct HevcEncVuiFields(bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_2); | |
| 733 | + | |
| 734 | +impl HevcEncVuiFields { | |
| 735 | + #[allow(clippy::too_many_arguments)] | |
| 736 | + pub fn new( | |
| 737 | + aspect_ratio_info_present_flag: u32, | |
| 738 | + neutral_chroma_indication_flag: u32, | |
| 739 | + field_seq_flag: u32, | |
| 740 | + vui_timing_info_present_flag: u32, | |
| 741 | + bitstream_restriction_flag: u32, | |
| 742 | + tiles_fixed_structure_flag: u32, | |
| 743 | + motion_vectors_over_pic_boundaries_flag: u32, | |
| 744 | + restricted_ref_pic_lists_flag: u32, | |
| 745 | + log2_max_mv_length_horizontal: u32, | |
| 746 | + log2_max_mv_length_vertical: u32, | |
| 747 | + ) -> Self { | |
| 748 | + let _bitfield_1 = | |
| 749 | + bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
| 750 | + aspect_ratio_info_present_flag, | |
| 751 | + neutral_chroma_indication_flag, | |
| 752 | + field_seq_flag, | |
| 753 | + vui_timing_info_present_flag, | |
| 754 | + bitstream_restriction_flag, | |
| 755 | + tiles_fixed_structure_flag, | |
| 756 | + motion_vectors_over_pic_boundaries_flag, | |
| 757 | + restricted_ref_pic_lists_flag, | |
| 758 | + log2_max_mv_length_horizontal, | |
| 759 | + log2_max_mv_length_vertical, | |
| 760 | + ); | |
| 761 | + | |
| 762 | + Self(bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_2 { | |
| 763 | + bits: bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_2__bindgen_ty_1 { | |
| 764 | + _bitfield_align_1: Default::default(), | |
| 765 | + _bitfield_1, | |
| 766 | + __bindgen_padding_0: Default::default(), | |
| 767 | + }, | |
| 768 | + }) | |
| 769 | + } | |
| 770 | +} | |
| 771 | + | |
| 772 | +pub struct HevcEncSeqSccFields(bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_3); | |
| 773 | + | |
| 774 | +impl HevcEncSeqSccFields { | |
| 775 | + pub fn new(palette_mode_enabled_flag: u32) -> Self { | |
| 776 | + let _bitfield_1 = | |
| 777 | + bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_3__bindgen_ty_1::new_bitfield_1( | |
| 778 | + palette_mode_enabled_flag, | |
| 779 | + Default::default(), | |
| 780 | + ); | |
| 781 | + | |
| 782 | + Self(bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_3 { | |
| 783 | + bits: bindings::_VAEncSequenceParameterBufferHEVC__bindgen_ty_3__bindgen_ty_1 { | |
| 784 | + _bitfield_align_1: Default::default(), | |
| 785 | + _bitfield_1, | |
| 786 | + }, | |
| 787 | + }) | |
| 788 | + } | |
| 789 | +} | |
| 790 | + | |
| 791 | +pub struct EncSequenceParameterBufferHEVC(Box<bindings::VAEncSequenceParameterBufferHEVC>); | |
| 792 | + | |
| 793 | +impl EncSequenceParameterBufferHEVC { | |
| 794 | + #[allow(clippy::too_many_arguments)] | |
| 795 | + pub fn new( | |
| 796 | + general_profile_idc: u8, | |
| 797 | + general_level_idc: u8, | |
| 798 | + general_tier_flag: u8, | |
| 799 | + intra_period: u32, | |
| 800 | + intra_idr_period: u32, | |
| 801 | + ip_period: u32, | |
| 802 | + bits_per_second: u32, | |
| 803 | + pic_width_in_luma_samples: u16, | |
| 804 | + pic_height_in_luma_samples: u16, | |
| 805 | + seq_fields: &HEVCEncSeqFields, | |
| 806 | + log2_min_luma_coding_block_size_minus3: u8, | |
| 807 | + log2_diff_max_min_luma_coding_block_size: u8, | |
| 808 | + log2_min_transform_block_size_minus2: u8, | |
| 809 | + log2_diff_max_min_transform_block_size: u8, | |
| 810 | + max_transform_hierarchy_depth_inter: u8, | |
| 811 | + max_transform_hierarchy_depth_intra: u8, | |
| 812 | + pcm_sample_bit_depth_luma_minus1: u32, | |
| 813 | + pcm_sample_bit_depth_chroma_minus1: u32, | |
| 814 | + log2_min_pcm_luma_coding_block_size_minus3: u32, | |
| 815 | + log2_max_pcm_luma_coding_block_size_minus3: u32, | |
| 816 | + vui_fields: Option<HevcEncVuiFields>, | |
| 817 | + aspect_ratio_idc: u8, | |
| 818 | + sar_width: u32, | |
| 819 | + sar_height: u32, | |
| 820 | + vui_num_units_in_tick: u32, | |
| 821 | + vui_time_scale: u32, | |
| 822 | + min_spatial_segmentation_idc: u16, | |
| 823 | + max_bytes_per_pic_denom: u8, | |
| 824 | + max_bits_per_min_cu_denom: u8, | |
| 825 | + scc_fields: &HevcEncSeqSccFields, | |
| 826 | + ) -> Self { | |
| 827 | + let seq_fields = seq_fields.0; | |
| 828 | + let vui_parameters_present_flag = vui_fields.is_some() as u8; | |
| 829 | + let vui_fields = vui_fields.unwrap_or_default().0; | |
| 830 | + let scc_fields = scc_fields.0; | |
| 831 | + | |
| 832 | + Self(Box::new(bindings::VAEncSequenceParameterBufferHEVC { | |
| 833 | + general_profile_idc, | |
| 834 | + general_level_idc, | |
| 835 | + general_tier_flag, | |
| 836 | + intra_period, | |
| 837 | + intra_idr_period, | |
| 838 | + ip_period, | |
| 839 | + bits_per_second, | |
| 840 | + pic_width_in_luma_samples, | |
| 841 | + pic_height_in_luma_samples, | |
| 842 | + seq_fields, | |
| 843 | + log2_min_luma_coding_block_size_minus3, | |
| 844 | + log2_diff_max_min_luma_coding_block_size, | |
| 845 | + log2_min_transform_block_size_minus2, | |
| 846 | + log2_diff_max_min_transform_block_size, | |
| 847 | + max_transform_hierarchy_depth_inter, | |
| 848 | + max_transform_hierarchy_depth_intra, | |
| 849 | + pcm_sample_bit_depth_luma_minus1, | |
| 850 | + pcm_sample_bit_depth_chroma_minus1, | |
| 851 | + log2_min_pcm_luma_coding_block_size_minus3, | |
| 852 | + log2_max_pcm_luma_coding_block_size_minus3, | |
| 853 | + vui_parameters_present_flag, | |
| 854 | + vui_fields, | |
| 855 | + aspect_ratio_idc, | |
| 856 | + sar_width, | |
| 857 | + sar_height, | |
| 858 | + vui_num_units_in_tick, | |
| 859 | + vui_time_scale, | |
| 860 | + min_spatial_segmentation_idc, | |
| 861 | + max_bytes_per_pic_denom, | |
| 862 | + max_bits_per_min_cu_denom, | |
| 863 | + scc_fields, | |
| 864 | + va_reserved: Default::default(), | |
| 865 | + })) | |
| 866 | + } | |
| 867 | + | |
| 868 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSequenceParameterBufferHEVC { | |
| 869 | + &mut self.0 | |
| 870 | + } | |
| 871 | +} | |
| 872 | + | |
| 873 | +pub struct HEVCEncPicFields(bindings::_VAEncPictureParameterBufferHEVC__bindgen_ty_1); | |
| 874 | + | |
| 875 | +impl HEVCEncPicFields { | |
| 876 | + #[allow(clippy::too_many_arguments)] | |
| 877 | + pub fn new( | |
| 878 | + idr_pic_flag: u32, | |
| 879 | + coding_type: u32, | |
| 880 | + reference_pic_flag: u32, | |
| 881 | + dependent_slice_segments_enabled_flag: u32, | |
| 882 | + sign_data_hiding_enabled_flag: u32, | |
| 883 | + constrained_intra_pred_flag: u32, | |
| 884 | + transform_skip_enabled_flag: u32, | |
| 885 | + cu_qp_delta_enabled_flag: u32, | |
| 886 | + weighted_pred_flag: u32, | |
| 887 | + weighted_bipred_flag: u32, | |
| 888 | + transquant_bypass_enabled_flag: u32, | |
| 889 | + tiles_enabled_flag: u32, | |
| 890 | + entropy_coding_sync_enabled_flag: u32, | |
| 891 | + loop_filter_across_tiles_enabled_flag: u32, | |
| 892 | + pps_loop_filter_across_slices_enabled_flag: u32, | |
| 893 | + scaling_list_data_present_flag: u32, | |
| 894 | + screen_content_flag: u32, | |
| 895 | + enable_gpu_weighted_prediction: u32, | |
| 896 | + no_output_of_prior_pics_flag: u32, | |
| 897 | + ) -> Self { | |
| 898 | + let _bitfield_1 = | |
| 899 | + bindings::_VAEncPictureParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 900 | + idr_pic_flag, | |
| 901 | + coding_type, | |
| 902 | + reference_pic_flag, | |
| 903 | + dependent_slice_segments_enabled_flag, | |
| 904 | + sign_data_hiding_enabled_flag, | |
| 905 | + constrained_intra_pred_flag, | |
| 906 | + transform_skip_enabled_flag, | |
| 907 | + cu_qp_delta_enabled_flag, | |
| 908 | + weighted_pred_flag, | |
| 909 | + weighted_bipred_flag, | |
| 910 | + transquant_bypass_enabled_flag, | |
| 911 | + tiles_enabled_flag, | |
| 912 | + entropy_coding_sync_enabled_flag, | |
| 913 | + loop_filter_across_tiles_enabled_flag, | |
| 914 | + pps_loop_filter_across_slices_enabled_flag, | |
| 915 | + scaling_list_data_present_flag, | |
| 916 | + screen_content_flag, | |
| 917 | + enable_gpu_weighted_prediction, | |
| 918 | + no_output_of_prior_pics_flag, | |
| 919 | + Default::default(), | |
| 920 | + ); | |
| 921 | + | |
| 922 | + Self(bindings::_VAEncPictureParameterBufferHEVC__bindgen_ty_1 { | |
| 923 | + bits: bindings::_VAEncPictureParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1 { | |
| 924 | + _bitfield_align_1: Default::default(), | |
| 925 | + _bitfield_1, | |
| 926 | + }, | |
| 927 | + }) | |
| 928 | + } | |
| 929 | +} | |
| 930 | + | |
| 931 | +pub struct HevcEncPicSccFields(bindings::_VAEncPictureParameterBufferHEVC__bindgen_ty_2); | |
| 932 | + | |
| 933 | +impl HevcEncPicSccFields { | |
| 934 | + pub fn new(pps_curr_pic_ref_enabled_flag: u16) -> Self { | |
| 935 | + let _bitfield_1 = | |
| 936 | + bindings::_VAEncPictureParameterBufferHEVC__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
| 937 | + pps_curr_pic_ref_enabled_flag, | |
| 938 | + Default::default(), | |
| 939 | + ); | |
| 940 | + | |
| 941 | + Self(bindings::_VAEncPictureParameterBufferHEVC__bindgen_ty_2 { | |
| 942 | + bits: bindings::_VAEncPictureParameterBufferHEVC__bindgen_ty_2__bindgen_ty_1 { | |
| 943 | + _bitfield_align_1: Default::default(), | |
| 944 | + _bitfield_1, | |
| 945 | + }, | |
| 946 | + }) | |
| 947 | + } | |
| 948 | +} | |
| 949 | + | |
| 950 | +pub struct EncPictureParameterBufferHEVC(Box<bindings::VAEncPictureParameterBufferHEVC>); | |
| 951 | + | |
| 952 | +impl EncPictureParameterBufferHEVC { | |
| 953 | + #[allow(clippy::too_many_arguments)] | |
| 954 | + pub fn new( | |
| 955 | + decoded_curr_pic: PictureHEVC, | |
| 956 | + reference_frames: [PictureHEVC; 15usize], | |
| 957 | + coded_buf: bindings::VABufferID, | |
| 958 | + collocated_ref_pic_index: u8, | |
| 959 | + last_picture: u8, | |
| 960 | + pic_init_qp: u8, | |
| 961 | + diff_cu_qp_delta_depth: u8, | |
| 962 | + pps_cb_qp_offset: i8, | |
| 963 | + pps_cr_qp_offset: i8, | |
| 964 | + num_tile_columns_minus1: u8, | |
| 965 | + num_tile_rows_minus1: u8, | |
| 966 | + column_width_minus1: [u8; 19usize], | |
| 967 | + row_height_minus1: [u8; 21usize], | |
| 968 | + log2_parallel_merge_level_minus2: u8, | |
| 969 | + ctu_max_bitsize_allowed: u8, | |
| 970 | + num_ref_idx_l0_default_active_minus1: u8, | |
| 971 | + num_ref_idx_l1_default_active_minus1: u8, | |
| 972 | + slice_pic_parameter_set_id: u8, | |
| 973 | + nal_unit_type: u8, | |
| 974 | + pic_fields: &HEVCEncPicFields, | |
| 975 | + hierarchical_level_plus1: u8, | |
| 976 | + va_byte_reserved: u8, | |
| 977 | + scc_fields: &HevcEncPicSccFields, | |
| 978 | + ) -> Self { | |
| 979 | + let decoded_curr_pic = decoded_curr_pic.0; | |
| 980 | + let reference_frames = (0..15usize) | |
| 981 | + .map(|i| reference_frames[i].0) | |
| 982 | + .collect::<Vec<_>>() | |
| 983 | + .try_into() | |
| 984 | + // try_into is guaranteed to work because the iterator and target array have the same | |
| 985 | + // size. | |
| 986 | + .unwrap(); | |
| 987 | + | |
| 988 | + let pic_fields = pic_fields.0; | |
| 989 | + let scc_fields = scc_fields.0; | |
| 990 | + | |
| 991 | + Self(Box::new(bindings::VAEncPictureParameterBufferHEVC { | |
| 992 | + decoded_curr_pic, | |
| 993 | + reference_frames, | |
| 994 | + coded_buf, | |
| 995 | + collocated_ref_pic_index, | |
| 996 | + last_picture, | |
| 997 | + pic_init_qp, | |
| 998 | + diff_cu_qp_delta_depth, | |
| 999 | + pps_cb_qp_offset, | |
| 1000 | + pps_cr_qp_offset, | |
| 1001 | + num_tile_columns_minus1, | |
| 1002 | + num_tile_rows_minus1, | |
| 1003 | + column_width_minus1, | |
| 1004 | + row_height_minus1, | |
| 1005 | + log2_parallel_merge_level_minus2, | |
| 1006 | + ctu_max_bitsize_allowed, | |
| 1007 | + num_ref_idx_l0_default_active_minus1, | |
| 1008 | + num_ref_idx_l1_default_active_minus1, | |
| 1009 | + slice_pic_parameter_set_id, | |
| 1010 | + nal_unit_type, | |
| 1011 | + pic_fields, | |
| 1012 | + hierarchical_level_plus1, | |
| 1013 | + va_byte_reserved, | |
| 1014 | + scc_fields, | |
| 1015 | + va_reserved: Default::default(), | |
| 1016 | + })) | |
| 1017 | + } | |
| 1018 | + | |
| 1019 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferHEVC { | |
| 1020 | + &mut self.0 | |
| 1021 | + } | |
| 1022 | +} | |
| 1023 | + | |
| 1024 | +pub struct HevcEncSliceFields(bindings::_VAEncSliceParameterBufferHEVC__bindgen_ty_1); | |
| 1025 | + | |
| 1026 | +impl HevcEncSliceFields { | |
| 1027 | + #[allow(clippy::too_many_arguments)] | |
| 1028 | + pub fn new( | |
| 1029 | + last_slice_of_pic_flag: u32, | |
| 1030 | + dependent_slice_segment_flag: u32, | |
| 1031 | + colour_plane_id: u32, | |
| 1032 | + slice_temporal_mvp_enabled_flag: u32, | |
| 1033 | + slice_sao_luma_flag: u32, | |
| 1034 | + slice_sao_chroma_flag: u32, | |
| 1035 | + num_ref_idx_active_override_flag: u32, | |
| 1036 | + mvd_l1_zero_flag: u32, | |
| 1037 | + cabac_init_flag: u32, | |
| 1038 | + slice_deblocking_filter_disabled_flag: u32, | |
| 1039 | + slice_loop_filter_across_slices_enabled_flag: u32, | |
| 1040 | + collocated_from_l0_flag: u32, | |
| 1041 | + ) -> Self { | |
| 1042 | + let _bitfield_1 = | |
| 1043 | + bindings::_VAEncSliceParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 1044 | + last_slice_of_pic_flag, | |
| 1045 | + dependent_slice_segment_flag, | |
| 1046 | + colour_plane_id, | |
| 1047 | + slice_temporal_mvp_enabled_flag, | |
| 1048 | + slice_sao_luma_flag, | |
| 1049 | + slice_sao_chroma_flag, | |
| 1050 | + num_ref_idx_active_override_flag, | |
| 1051 | + mvd_l1_zero_flag, | |
| 1052 | + cabac_init_flag, | |
| 1053 | + slice_deblocking_filter_disabled_flag, | |
| 1054 | + slice_loop_filter_across_slices_enabled_flag, | |
| 1055 | + collocated_from_l0_flag, | |
| 1056 | + ); | |
| 1057 | + | |
| 1058 | + Self(bindings::_VAEncSliceParameterBufferHEVC__bindgen_ty_1 { | |
| 1059 | + bits: bindings::_VAEncSliceParameterBufferHEVC__bindgen_ty_1__bindgen_ty_1 { | |
| 1060 | + _bitfield_align_1: Default::default(), | |
| 1061 | + _bitfield_1, | |
| 1062 | + __bindgen_padding_0: Default::default(), | |
| 1063 | + }, | |
| 1064 | + }) | |
| 1065 | + } | |
| 1066 | +} | |
| 1067 | + | |
| 1068 | +pub struct EncSliceParameterBufferHEVC(Box<bindings::VAEncSliceParameterBufferHEVC>); | |
| 1069 | + | |
| 1070 | +impl EncSliceParameterBufferHEVC { | |
| 1071 | + #[allow(clippy::too_many_arguments)] | |
| 1072 | + pub fn new( | |
| 1073 | + slice_segment_address: u32, | |
| 1074 | + num_ctu_in_slice: u32, | |
| 1075 | + slice_type: u8, | |
| 1076 | + slice_pic_parameter_set_id: u8, | |
| 1077 | + num_ref_idx_l0_active_minus1: u8, | |
| 1078 | + num_ref_idx_l1_active_minus1: u8, | |
| 1079 | + ref_pic_list0: [PictureHEVC; 15usize], | |
| 1080 | + ref_pic_list1: [PictureHEVC; 15usize], | |
| 1081 | + luma_log2_weight_denom: u8, | |
| 1082 | + delta_chroma_log2_weight_denom: i8, | |
| 1083 | + delta_luma_weight_l0: [i8; 15usize], | |
| 1084 | + luma_offset_l0: [i8; 15usize], | |
| 1085 | + delta_chroma_weight_l0: [[i8; 2usize]; 15usize], | |
| 1086 | + chroma_offset_l0: [[i8; 2usize]; 15usize], | |
| 1087 | + delta_luma_weight_l1: [i8; 15usize], | |
| 1088 | + luma_offset_l1: [i8; 15usize], | |
| 1089 | + delta_chroma_weight_l1: [[i8; 2usize]; 15usize], | |
| 1090 | + chroma_offset_l1: [[i8; 2usize]; 15usize], | |
| 1091 | + max_num_merge_cand: u8, | |
| 1092 | + slice_qp_delta: i8, | |
| 1093 | + slice_cb_qp_offset: i8, | |
| 1094 | + slice_cr_qp_offset: i8, | |
| 1095 | + slice_beta_offset_div2: i8, | |
| 1096 | + slice_tc_offset_div2: i8, | |
| 1097 | + slice_fields: &HevcEncSliceFields, | |
| 1098 | + pred_weight_table_bit_offset: u32, | |
| 1099 | + pred_weight_table_bit_length: u32, | |
| 1100 | + ) -> Self { | |
| 1101 | + let ref_pic_list0 = (0..15usize) | |
| 1102 | + .map(|i| ref_pic_list0[i].0) | |
| 1103 | + .collect::<Vec<_>>() | |
| 1104 | + .try_into() | |
| 1105 | + // try_into is guaranteed to work because the iterator and target array have the same | |
| 1106 | + // size. | |
| 1107 | + .unwrap(); | |
| 1108 | + | |
| 1109 | + let ref_pic_list1 = (0..15usize) | |
| 1110 | + .map(|i| ref_pic_list1[i].0) | |
| 1111 | + .collect::<Vec<_>>() | |
| 1112 | + .try_into() | |
| 1113 | + // try_into is guaranteed to work because the iterator and target array have the same | |
| 1114 | + // size. | |
| 1115 | + .unwrap(); | |
| 1116 | + | |
| 1117 | + let slice_fields = slice_fields.0; | |
| 1118 | + | |
| 1119 | + Self(Box::new(bindings::VAEncSliceParameterBufferHEVC { | |
| 1120 | + slice_segment_address, | |
| 1121 | + num_ctu_in_slice, | |
| 1122 | + slice_type, | |
| 1123 | + slice_pic_parameter_set_id, | |
| 1124 | + num_ref_idx_l0_active_minus1, | |
| 1125 | + num_ref_idx_l1_active_minus1, | |
| 1126 | + ref_pic_list0, | |
| 1127 | + ref_pic_list1, | |
| 1128 | + luma_log2_weight_denom, | |
| 1129 | + delta_chroma_log2_weight_denom, | |
| 1130 | + delta_luma_weight_l0, | |
| 1131 | + luma_offset_l0, | |
| 1132 | + delta_chroma_weight_l0, | |
| 1133 | + chroma_offset_l0, | |
| 1134 | + delta_luma_weight_l1, | |
| 1135 | + luma_offset_l1, | |
| 1136 | + delta_chroma_weight_l1, | |
| 1137 | + chroma_offset_l1, | |
| 1138 | + max_num_merge_cand, | |
| 1139 | + slice_qp_delta, | |
| 1140 | + slice_cb_qp_offset, | |
| 1141 | + slice_cr_qp_offset, | |
| 1142 | + slice_beta_offset_div2, | |
| 1143 | + slice_tc_offset_div2, | |
| 1144 | + slice_fields, | |
| 1145 | + pred_weight_table_bit_offset, | |
| 1146 | + pred_weight_table_bit_length, | |
| 1147 | + va_reserved: Default::default(), | |
| 1148 | + })) | |
| 1149 | + } | |
| 1150 | + | |
| 1151 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSliceParameterBufferHEVC { | |
| 1152 | + &mut self.0 | |
| 1153 | + } | |
| 1154 | +} |
shims/cros-libva/src/buffer/jpeg_baseline.rsadded+220 -0
| @@ -0,0 +1,220 @@ | ||
| 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.rsadded+172 -0
| @@ -0,0 +1,172 @@ | ||
| 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.rsadded+198 -0
| @@ -0,0 +1,198 @@ | ||
| 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 `VAProcPipeline` types. | |
| 6 | + | |
| 7 | +use crate::bindings; | |
| 8 | +use std::{marker::PhantomData, ptr}; | |
| 9 | + | |
| 10 | +/// Wrapper over the `VABlendState` ffi type. | |
| 11 | +pub struct BlendState(bindings::VABlendState); | |
| 12 | + | |
| 13 | +impl BlendState { | |
| 14 | + /// Creates the bindgen field | |
| 15 | + pub fn new(flags: u32, global_alpha: f32, min_luma: f32, max_luma: f32) -> Self { | |
| 16 | + Self(bindings::VABlendState { | |
| 17 | + flags, | |
| 18 | + global_alpha, | |
| 19 | + min_luma, | |
| 20 | + max_luma, | |
| 21 | + }) | |
| 22 | + } | |
| 23 | +} | |
| 24 | + | |
| 25 | +/// Wrapper over the `VAProcColorProperties` ffi type. | |
| 26 | +pub struct ProcColorProperties(bindings::VAProcColorProperties); | |
| 27 | + | |
| 28 | +impl ProcColorProperties { | |
| 29 | + /// Creates the bindgen field | |
| 30 | + pub fn new( | |
| 31 | + chroma_sample_location: u8, | |
| 32 | + color_range: u8, | |
| 33 | + colour_primaries: u8, | |
| 34 | + transfer_characteristics: u8, | |
| 35 | + matrix_coefficients: u8, | |
| 36 | + ) -> Self { | |
| 37 | + Self(bindings::VAProcColorProperties { | |
| 38 | + chroma_sample_location, | |
| 39 | + color_range, | |
| 40 | + colour_primaries, | |
| 41 | + transfer_characteristics, | |
| 42 | + matrix_coefficients, | |
| 43 | + reserved: Default::default(), | |
| 44 | + }) | |
| 45 | + } | |
| 46 | +} | |
| 47 | + | |
| 48 | +impl Default for ProcColorProperties { | |
| 49 | + fn default() -> Self { | |
| 50 | + Self::new(0, 0, 0, 0, 0) | |
| 51 | + } | |
| 52 | +} | |
| 53 | + | |
| 54 | +/// Wrapper over the `VAHdrMetaData` ffi type. | |
| 55 | +pub struct HdrMetaData(bindings::VAHdrMetaData); | |
| 56 | + | |
| 57 | +impl<'a> HdrMetaData { | |
| 58 | + /// Creates the bindgen field | |
| 59 | + pub fn new(metadata_type: u32, metadata: Option<&'a [u8]>, metadata_size: u32) -> Self { | |
| 60 | + Self(bindings::VAHdrMetaData { | |
| 61 | + metadata_type: metadata_type as _, | |
| 62 | + metadata: metadata.map_or(ptr::null_mut(), |f| f.as_ptr() as *mut _), | |
| 63 | + metadata_size, | |
| 64 | + reserved: Default::default(), | |
| 65 | + }) | |
| 66 | + } | |
| 67 | +} | |
| 68 | + | |
| 69 | +/// Wrapper over the `VAProcPipelineParameterBuffer` FFI type. | |
| 70 | +pub struct ProcPipelineParameterBuffer { | |
| 71 | + c_params: Box<bindings::VAProcPipelineParameterBuffer>, | |
| 72 | + | |
| 73 | + // Fields that own the data for the pointers in `c_params`. | |
| 74 | + surface_region: Option<Box<bindings::VARectangle>>, | |
| 75 | + output_region: Option<Box<bindings::VARectangle>>, | |
| 76 | + filters: Option<Vec<bindings::VABufferID>>, | |
| 77 | + forward_references: Option<Vec<bindings::VASurfaceID>>, | |
| 78 | + backward_references: Option<Vec<bindings::VASurfaceID>>, | |
| 79 | + blend_state: Option<Vec<BlendState>>, | |
| 80 | + additional_outputs: Option<Vec<bindings::VASurfaceID>>, | |
| 81 | + output_hdr_metadata: Option<Vec<HdrMetaData>>, | |
| 82 | +} | |
| 83 | + | |
| 84 | +impl ProcPipelineParameterBuffer { | |
| 85 | + /// Creates the wrapper. | |
| 86 | + #[allow(clippy::too_many_arguments)] | |
| 87 | + pub fn new( | |
| 88 | + surface: bindings::VASurfaceID, | |
| 89 | + surface_region: Option<bindings::VARectangle>, | |
| 90 | + surface_color_standard: u8, | |
| 91 | + output_region: Option<bindings::VARectangle>, | |
| 92 | + output_background_color: u32, | |
| 93 | + output_color_standard: u8, | |
| 94 | + pipeline_flags: u32, | |
| 95 | + filter_flags: u32, | |
| 96 | + filters: Option<Vec<bindings::VABufferID>>, | |
| 97 | + forward_references: Option<Vec<bindings::VASurfaceID>>, | |
| 98 | + backward_references: Option<Vec<bindings::VASurfaceID>>, | |
| 99 | + rotation_state: u32, | |
| 100 | + blend_state: Option<Vec<BlendState>>, | |
| 101 | + mirror_state: u32, | |
| 102 | + additional_outputs: Option<Vec<bindings::VASurfaceID>>, | |
| 103 | + input_surface_flag: u32, | |
| 104 | + output_surface_flag: u32, | |
| 105 | + input_color_properties: ProcColorProperties, | |
| 106 | + output_color_properties: ProcColorProperties, | |
| 107 | + processing_mode: u32, | |
| 108 | + output_hdr_metadata: Option<Vec<HdrMetaData>>, | |
| 109 | + ) -> Self { | |
| 110 | + let mut slf = Self { | |
| 111 | + // SAFETY: The VA-API structures are C-compatible so zeroing is safe. | |
| 112 | + c_params: Box::new(unsafe { std::mem::zeroed() }), | |
| 113 | + surface_region: surface_region.map(Box::new), | |
| 114 | + output_region: output_region.map(Box::new), | |
| 115 | + filters, | |
| 116 | + forward_references, | |
| 117 | + backward_references, | |
| 118 | + blend_state, | |
| 119 | + additional_outputs, | |
| 120 | + output_hdr_metadata, | |
| 121 | + }; | |
| 122 | + | |
| 123 | + slf.c_params = Box::new(bindings::VAProcPipelineParameterBuffer { | |
| 124 | + surface, | |
| 125 | + surface_region: slf | |
| 126 | + .surface_region | |
| 127 | + .as_deref() | |
| 128 | + .map_or(ptr::null_mut(), |r| r as *const _ as *mut _), | |
| 129 | + surface_color_standard: surface_color_standard as _, | |
| 130 | + output_region: slf | |
| 131 | + .output_region | |
| 132 | + .as_deref() | |
| 133 | + .map_or(ptr::null_mut(), |r| r as *const _ as *mut _), | |
| 134 | + output_background_color, | |
| 135 | + output_color_standard: output_color_standard as _, | |
| 136 | + pipeline_flags, | |
| 137 | + filter_flags, | |
| 138 | + filters: slf | |
| 139 | + .filters | |
| 140 | + .as_deref() | |
| 141 | + .map_or(ptr::null_mut(), |f| f.as_ptr() as *mut _), | |
| 142 | + num_filters: slf.filters.as_ref().map_or(0, |f| f.len() as u32), | |
| 143 | + forward_references: slf | |
| 144 | + .forward_references | |
| 145 | + .as_deref() | |
| 146 | + .map_or(ptr::null_mut(), |r| r.as_ptr() as *mut _), | |
| 147 | + num_forward_references: slf | |
| 148 | + .forward_references | |
| 149 | + .as_ref() | |
| 150 | + .map_or(0, |f| f.len() as u32), | |
| 151 | + backward_references: slf | |
| 152 | + .backward_references | |
| 153 | + .as_deref() | |
| 154 | + .map_or(ptr::null_mut(), |r| r.as_ptr() as *mut _), | |
| 155 | + num_backward_references: slf | |
| 156 | + .backward_references | |
| 157 | + .as_ref() | |
| 158 | + .map_or(0, |b| b.len() as u32), | |
| 159 | + rotation_state, | |
| 160 | + blend_state: slf | |
| 161 | + .blend_state | |
| 162 | + .as_deref() | |
| 163 | + .map_or(ptr::null(), |b| b.as_ptr() as *const bindings::VABlendState), | |
| 164 | + mirror_state, | |
| 165 | + additional_outputs: slf | |
| 166 | + .additional_outputs | |
| 167 | + .as_deref() | |
| 168 | + .map_or(ptr::null_mut(), |a| a.as_ptr() as *mut _), | |
| 169 | + num_additional_outputs: slf | |
| 170 | + .additional_outputs | |
| 171 | + .as_ref() | |
| 172 | + .map_or(0, |a| a.len() as u32), | |
| 173 | + input_surface_flag, | |
| 174 | + output_surface_flag, | |
| 175 | + input_color_properties: input_color_properties.0, | |
| 176 | + output_color_properties: output_color_properties.0, | |
| 177 | + processing_mode, | |
| 178 | + output_hdr_metadata: slf | |
| 179 | + .output_hdr_metadata | |
| 180 | + .as_deref() | |
| 181 | + .map_or(ptr::null_mut(), |o| { | |
| 182 | + o.as_ptr() as *mut bindings::VAHdrMetaData | |
| 183 | + }), | |
| 184 | + va_reserved: Default::default(), | |
| 185 | + }); | |
| 186 | + | |
| 187 | + slf | |
| 188 | + } | |
| 189 | + | |
| 190 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAProcPipelineParameterBuffer { | |
| 191 | + self.c_params.as_mut() | |
| 192 | + } | |
| 193 | + | |
| 194 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 195 | + pub fn inner(&self) -> &bindings::VAProcPipelineParameterBuffer { | |
| 196 | + self.c_params.as_ref() | |
| 197 | + } | |
| 198 | +} |
shims/cros-libva/src/buffer/vp8.rsadded+397 -0
| @@ -0,0 +1,397 @@ | ||
| 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/buffer/vp9.rsadded+451 -0
| @@ -0,0 +1,451 @@ | ||
| 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 VP9 `VABuffer` types. | |
| 6 | + | |
| 7 | +use crate::bindings; | |
| 8 | + | |
| 9 | +/// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferVP9`. | |
| 10 | +pub struct VP9PicFields(bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1); | |
| 11 | + | |
| 12 | +impl VP9PicFields { | |
| 13 | + /// Creates the bindgen field | |
| 14 | + #[allow(clippy::too_many_arguments)] | |
| 15 | + pub fn new( | |
| 16 | + subsampling_x: u32, | |
| 17 | + subsampling_y: u32, | |
| 18 | + frame_type: u32, | |
| 19 | + show_frame: u32, | |
| 20 | + error_resilient_mode: u32, | |
| 21 | + intra_only: u32, | |
| 22 | + allow_high_precision_mv: u32, | |
| 23 | + mcomp_filter_type: u32, | |
| 24 | + frame_parallel_decoding_mode: u32, | |
| 25 | + reset_frame_context: u32, | |
| 26 | + refresh_frame_context: u32, | |
| 27 | + frame_context_idx: u32, | |
| 28 | + segmentation_enabled: u32, | |
| 29 | + segmentation_temporal_update: u32, | |
| 30 | + segmentation_update_map: u32, | |
| 31 | + last_ref_frame: u32, | |
| 32 | + last_ref_frame_sign_bias: u32, | |
| 33 | + golden_ref_frame: u32, | |
| 34 | + golden_ref_frame_sign_bias: u32, | |
| 35 | + alt_ref_frame: u32, | |
| 36 | + alt_ref_frame_sign_bias: u32, | |
| 37 | + lossless_flag: u32, | |
| 38 | + ) -> Self { | |
| 39 | + let _bitfield_1 = | |
| 40 | + bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 41 | + subsampling_x, | |
| 42 | + subsampling_y, | |
| 43 | + frame_type, | |
| 44 | + show_frame, | |
| 45 | + error_resilient_mode, | |
| 46 | + intra_only, | |
| 47 | + allow_high_precision_mv, | |
| 48 | + mcomp_filter_type, | |
| 49 | + frame_parallel_decoding_mode, | |
| 50 | + reset_frame_context, | |
| 51 | + refresh_frame_context, | |
| 52 | + frame_context_idx, | |
| 53 | + segmentation_enabled, | |
| 54 | + segmentation_temporal_update, | |
| 55 | + segmentation_update_map, | |
| 56 | + last_ref_frame, | |
| 57 | + last_ref_frame_sign_bias, | |
| 58 | + golden_ref_frame, | |
| 59 | + golden_ref_frame_sign_bias, | |
| 60 | + alt_ref_frame, | |
| 61 | + alt_ref_frame_sign_bias, | |
| 62 | + lossless_flag, | |
| 63 | + ); | |
| 64 | + | |
| 65 | + Self(bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1 { | |
| 66 | + bits: bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1 { | |
| 67 | + _bitfield_align_1: Default::default(), | |
| 68 | + _bitfield_1, | |
| 69 | + }, | |
| 70 | + }) | |
| 71 | + } | |
| 72 | + | |
| 73 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 74 | + pub fn inner(&mut self) -> &bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1 { | |
| 75 | + &self.0 | |
| 76 | + } | |
| 77 | +} | |
| 78 | + | |
| 79 | +/// Wrapper over the `PictureParameterBufferVP9` FFI type. | |
| 80 | +pub struct PictureParameterBufferVP9(Box<bindings::VADecPictureParameterBufferVP9>); | |
| 81 | + | |
| 82 | +impl PictureParameterBufferVP9 { | |
| 83 | + /// Creates the wrapper | |
| 84 | + #[allow(clippy::too_many_arguments)] | |
| 85 | + pub fn new( | |
| 86 | + frame_width: u16, | |
| 87 | + frame_height: u16, | |
| 88 | + reference_frames: [bindings::VASurfaceID; 8], | |
| 89 | + pic_fields: &VP9PicFields, | |
| 90 | + filter_level: u8, | |
| 91 | + sharpness_level: u8, | |
| 92 | + log2_tile_rows: u8, | |
| 93 | + log2_tile_columns: u8, | |
| 94 | + frame_header_length_in_bytes: u8, | |
| 95 | + first_partition_size: u16, | |
| 96 | + mb_segment_tree_probs: [u8; 7usize], | |
| 97 | + segment_pred_probs: [u8; 3usize], | |
| 98 | + profile: u8, | |
| 99 | + bit_depth: u8, | |
| 100 | + ) -> Self { | |
| 101 | + let pic_fields = pic_fields.0; | |
| 102 | + | |
| 103 | + Self(Box::new(bindings::VADecPictureParameterBufferVP9 { | |
| 104 | + frame_width, | |
| 105 | + frame_height, | |
| 106 | + reference_frames, | |
| 107 | + pic_fields, | |
| 108 | + filter_level, | |
| 109 | + sharpness_level, | |
| 110 | + log2_tile_rows, | |
| 111 | + log2_tile_columns, | |
| 112 | + frame_header_length_in_bytes, | |
| 113 | + first_partition_size, | |
| 114 | + mb_segment_tree_probs, | |
| 115 | + segment_pred_probs, | |
| 116 | + profile, | |
| 117 | + bit_depth, | |
| 118 | + va_reserved: Default::default(), | |
| 119 | + })) | |
| 120 | + } | |
| 121 | + | |
| 122 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VADecPictureParameterBufferVP9 { | |
| 123 | + self.0.as_mut() | |
| 124 | + } | |
| 125 | + | |
| 126 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 127 | + pub fn inner(&self) -> &bindings::VADecPictureParameterBufferVP9 { | |
| 128 | + self.0.as_ref() | |
| 129 | + } | |
| 130 | +} | |
| 131 | + | |
| 132 | +/// Wrapper over the `segment_flags` bindgen field in `VASegmentParameterVP9`. | |
| 133 | +pub struct VP9SegmentFlags(bindings::_VASegmentParameterVP9__bindgen_ty_1); | |
| 134 | + | |
| 135 | +impl VP9SegmentFlags { | |
| 136 | + /// Creates the wrapper. | |
| 137 | + pub fn new( | |
| 138 | + segment_reference_enabled: u16, | |
| 139 | + segment_reference: u16, | |
| 140 | + segment_reference_skipped: u16, | |
| 141 | + ) -> Self { | |
| 142 | + let _bitfield_1 = | |
| 143 | + bindings::_VASegmentParameterVP9__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 144 | + segment_reference_enabled, | |
| 145 | + segment_reference, | |
| 146 | + segment_reference_skipped, | |
| 147 | + ); | |
| 148 | + | |
| 149 | + Self(bindings::_VASegmentParameterVP9__bindgen_ty_1 { | |
| 150 | + fields: bindings::_VASegmentParameterVP9__bindgen_ty_1__bindgen_ty_1 { | |
| 151 | + _bitfield_align_1: Default::default(), | |
| 152 | + _bitfield_1, | |
| 153 | + __bindgen_padding_0: Default::default(), | |
| 154 | + }, | |
| 155 | + }) | |
| 156 | + } | |
| 157 | + | |
| 158 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 159 | + pub fn inner(&mut self) -> &bindings::_VASegmentParameterVP9__bindgen_ty_1 { | |
| 160 | + &self.0 | |
| 161 | + } | |
| 162 | +} | |
| 163 | + | |
| 164 | +/// Wrapper over the `VASegmentParameterVP9` FFI type. | |
| 165 | +pub struct SegmentParameterVP9(bindings::VASegmentParameterVP9); | |
| 166 | + | |
| 167 | +impl SegmentParameterVP9 { | |
| 168 | + /// Creates the wrapper. | |
| 169 | + pub fn new( | |
| 170 | + segment_flags: &VP9SegmentFlags, | |
| 171 | + filter_level: [[u8; 2usize]; 4usize], | |
| 172 | + luma_ac_quant_scale: i16, | |
| 173 | + luma_dc_quant_scale: i16, | |
| 174 | + chroma_ac_quant_scale: i16, | |
| 175 | + chroma_dc_quant_scale: i16, | |
| 176 | + ) -> Self { | |
| 177 | + let segment_flags = segment_flags.0; | |
| 178 | + | |
| 179 | + Self(bindings::VASegmentParameterVP9 { | |
| 180 | + segment_flags, | |
| 181 | + filter_level, | |
| 182 | + luma_ac_quant_scale, | |
| 183 | + luma_dc_quant_scale, | |
| 184 | + chroma_ac_quant_scale, | |
| 185 | + chroma_dc_quant_scale, | |
| 186 | + va_reserved: Default::default(), | |
| 187 | + }) | |
| 188 | + } | |
| 189 | +} | |
| 190 | + | |
| 191 | +/// Wrapper over the `VASliceParameterBufferVP9` FFI type. | |
| 192 | +pub struct SliceParameterBufferVP9(Box<bindings::VASliceParameterBufferVP9>); | |
| 193 | + | |
| 194 | +impl SliceParameterBufferVP9 { | |
| 195 | + /// Creates the wrapper. | |
| 196 | + pub fn new( | |
| 197 | + slice_data_size: u32, | |
| 198 | + slice_data_offset: u32, | |
| 199 | + slice_data_flag: u32, | |
| 200 | + seg_param: [SegmentParameterVP9; 8usize], | |
| 201 | + ) -> Self { | |
| 202 | + let seg_param = seg_param.map(|param| param.0); | |
| 203 | + | |
| 204 | + Self(Box::new(bindings::VASliceParameterBufferVP9 { | |
| 205 | + slice_data_size, | |
| 206 | + slice_data_offset, | |
| 207 | + slice_data_flag, | |
| 208 | + seg_param, | |
| 209 | + va_reserved: Default::default(), | |
| 210 | + })) | |
| 211 | + } | |
| 212 | + | |
| 213 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferVP9 { | |
| 214 | + self.0.as_mut() | |
| 215 | + } | |
| 216 | + | |
| 217 | + /// Returns the inner FFI type. Useful for testing purposes. | |
| 218 | + pub fn inner(&self) -> &bindings::VASliceParameterBufferVP9 { | |
| 219 | + self.0.as_ref() | |
| 220 | + } | |
| 221 | +} | |
| 222 | + | |
| 223 | +pub struct CodedBufferVP9Status(Box<bindings::VACodedBufferVP9Status>); | |
| 224 | + | |
| 225 | +impl CodedBufferVP9Status { | |
| 226 | + pub fn new( | |
| 227 | + base_qp_index: u16, | |
| 228 | + loop_filter_level: u8, | |
| 229 | + long_term_indication: u8, | |
| 230 | + next_frame_width: u16, | |
| 231 | + next_frame_height: u16, | |
| 232 | + ) -> Self { | |
| 233 | + Self(Box::new(bindings::VACodedBufferVP9Status { | |
| 234 | + base_qp_index, | |
| 235 | + loop_filter_level, | |
| 236 | + long_term_indication, | |
| 237 | + next_frame_width, | |
| 238 | + next_frame_height, | |
| 239 | + va_reserved: Default::default(), | |
| 240 | + })) | |
| 241 | + } | |
| 242 | +} | |
| 243 | + | |
| 244 | +pub struct EncSequenceParameterBufferVP9(Box<bindings::VAEncSequenceParameterBufferVP9>); | |
| 245 | + | |
| 246 | +impl EncSequenceParameterBufferVP9 { | |
| 247 | + pub fn new( | |
| 248 | + max_frame_width: u32, | |
| 249 | + max_frame_height: u32, | |
| 250 | + kf_auto: u32, | |
| 251 | + kf_min_dist: u32, | |
| 252 | + kf_max_dist: u32, | |
| 253 | + bits_per_second: u32, | |
| 254 | + intra_period: u32, | |
| 255 | + ) -> Self { | |
| 256 | + Self(Box::new(bindings::VAEncSequenceParameterBufferVP9 { | |
| 257 | + max_frame_width, | |
| 258 | + max_frame_height, | |
| 259 | + kf_auto, | |
| 260 | + kf_min_dist, | |
| 261 | + kf_max_dist, | |
| 262 | + bits_per_second, | |
| 263 | + intra_period, | |
| 264 | + va_reserved: Default::default(), | |
| 265 | + })) | |
| 266 | + } | |
| 267 | + | |
| 268 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSequenceParameterBufferVP9 { | |
| 269 | + &mut self.0 | |
| 270 | + } | |
| 271 | +} | |
| 272 | + | |
| 273 | +pub struct VP9EncRefFlags(bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_1); | |
| 274 | + | |
| 275 | +impl VP9EncRefFlags { | |
| 276 | + #[allow(clippy::too_many_arguments)] | |
| 277 | + pub fn new( | |
| 278 | + force_kf: u32, | |
| 279 | + ref_frame_ctrl_l0: u32, | |
| 280 | + ref_frame_ctrl_l1: u32, | |
| 281 | + ref_last_idx: u32, | |
| 282 | + ref_last_sign_bias: u32, | |
| 283 | + ref_gf_idx: u32, | |
| 284 | + ref_gf_sign_bias: u32, | |
| 285 | + ref_arf_idx: u32, | |
| 286 | + ref_arf_sign_bias: u32, | |
| 287 | + temporal_id: u32, | |
| 288 | + ) -> Self { | |
| 289 | + let _bitfield_1 = | |
| 290 | + bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
| 291 | + force_kf, | |
| 292 | + ref_frame_ctrl_l0, | |
| 293 | + ref_frame_ctrl_l1, | |
| 294 | + ref_last_idx, | |
| 295 | + ref_last_sign_bias, | |
| 296 | + ref_gf_idx, | |
| 297 | + ref_gf_sign_bias, | |
| 298 | + ref_arf_idx, | |
| 299 | + ref_arf_sign_bias, | |
| 300 | + temporal_id, | |
| 301 | + Default::default(), | |
| 302 | + ); | |
| 303 | + | |
| 304 | + Self(bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_1 { | |
| 305 | + bits: bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1 { | |
| 306 | + _bitfield_align_1: Default::default(), | |
| 307 | + _bitfield_1, | |
| 308 | + }, | |
| 309 | + }) | |
| 310 | + } | |
| 311 | +} | |
| 312 | + | |
| 313 | +pub struct VP9EncPicFlags(bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_2); | |
| 314 | + | |
| 315 | +impl VP9EncPicFlags { | |
| 316 | + #[allow(clippy::too_many_arguments)] | |
| 317 | + pub fn new( | |
| 318 | + frame_type: u32, | |
| 319 | + show_frame: u32, | |
| 320 | + error_resilient_mode: u32, | |
| 321 | + intra_only: u32, | |
| 322 | + allow_high_precision_mv: u32, | |
| 323 | + mcomp_filter_type: u32, | |
| 324 | + frame_parallel_decoding_mode: u32, | |
| 325 | + reset_frame_context: u32, | |
| 326 | + refresh_frame_context: u32, | |
| 327 | + frame_context_idx: u32, | |
| 328 | + segmentation_enabled: u32, | |
| 329 | + segmentation_temporal_update: u32, | |
| 330 | + segmentation_update_map: u32, | |
| 331 | + lossless_mode: u32, | |
| 332 | + comp_prediction_mode: u32, | |
| 333 | + auto_segmentation: u32, | |
| 334 | + super_frame_flag: u32, | |
| 335 | + ) -> Self { | |
| 336 | + let _bitfield_1 = | |
| 337 | + bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
| 338 | + frame_type, | |
| 339 | + show_frame, | |
| 340 | + error_resilient_mode, | |
| 341 | + intra_only, | |
| 342 | + allow_high_precision_mv, | |
| 343 | + mcomp_filter_type, | |
| 344 | + frame_parallel_decoding_mode, | |
| 345 | + reset_frame_context, | |
| 346 | + refresh_frame_context, | |
| 347 | + frame_context_idx, | |
| 348 | + segmentation_enabled, | |
| 349 | + segmentation_temporal_update, | |
| 350 | + segmentation_update_map, | |
| 351 | + lossless_mode, | |
| 352 | + comp_prediction_mode, | |
| 353 | + auto_segmentation, | |
| 354 | + super_frame_flag, | |
| 355 | + Default::default(), | |
| 356 | + ); | |
| 357 | + | |
| 358 | + Self(bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_2 { | |
| 359 | + bits: bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_2__bindgen_ty_1 { | |
| 360 | + _bitfield_align_1: Default::default(), | |
| 361 | + _bitfield_1, | |
| 362 | + }, | |
| 363 | + }) | |
| 364 | + } | |
| 365 | +} | |
| 366 | + | |
| 367 | +pub struct EncPictureParameterBufferVP9(Box<bindings::VAEncPictureParameterBufferVP9>); | |
| 368 | + | |
| 369 | +impl EncPictureParameterBufferVP9 { | |
| 370 | + #[allow(clippy::too_many_arguments)] | |
| 371 | + pub fn new( | |
| 372 | + frame_width_src: u32, | |
| 373 | + frame_height_src: u32, | |
| 374 | + frame_width_dst: u32, | |
| 375 | + frame_height_dst: u32, | |
| 376 | + reconstructed_frame: bindings::VASurfaceID, | |
| 377 | + reference_frames: [bindings::VASurfaceID; 8usize], | |
| 378 | + coded_buf: bindings::VABufferID, | |
| 379 | + ref_flags: &VP9EncRefFlags, | |
| 380 | + pic_flags: &VP9EncPicFlags, | |
| 381 | + refresh_frame_flags: u8, | |
| 382 | + luma_ac_qindex: u8, | |
| 383 | + luma_dc_qindex_delta: i8, | |
| 384 | + chroma_ac_qindex_delta: i8, | |
| 385 | + chroma_dc_qindex_delta: i8, | |
| 386 | + filter_level: u8, | |
| 387 | + sharpness_level: u8, | |
| 388 | + ref_lf_delta: [i8; 4usize], | |
| 389 | + mode_lf_delta: [i8; 2usize], | |
| 390 | + bit_offset_ref_lf_delta: u16, | |
| 391 | + bit_offset_mode_lf_delta: u16, | |
| 392 | + bit_offset_lf_level: u16, | |
| 393 | + bit_offset_qindex: u16, | |
| 394 | + bit_offset_first_partition_size: u16, | |
| 395 | + bit_offset_segmentation: u16, | |
| 396 | + bit_size_segmentation: u16, | |
| 397 | + log2_tile_rows: u8, | |
| 398 | + log2_tile_columns: u8, | |
| 399 | + skip_frame_flag: u8, | |
| 400 | + number_skip_frames: u8, | |
| 401 | + skip_frames_size: u32, | |
| 402 | + seg_id_block_size: u8, | |
| 403 | + ) -> Self { | |
| 404 | + let ref_flags = ref_flags.0; | |
| 405 | + let pic_flags = pic_flags.0; | |
| 406 | + #[cfg(not(libva_1_23_or_higher))] | |
| 407 | + let _ = seg_id_block_size; | |
| 408 | + | |
| 409 | + Self(Box::new(bindings::VAEncPictureParameterBufferVP9 { | |
| 410 | + frame_width_src, | |
| 411 | + frame_height_src, | |
| 412 | + frame_width_dst, | |
| 413 | + frame_height_dst, | |
| 414 | + reconstructed_frame, | |
| 415 | + reference_frames, | |
| 416 | + coded_buf, | |
| 417 | + ref_flags, | |
| 418 | + pic_flags, | |
| 419 | + refresh_frame_flags, | |
| 420 | + luma_ac_qindex, | |
| 421 | + luma_dc_qindex_delta, | |
| 422 | + chroma_ac_qindex_delta, | |
| 423 | + chroma_dc_qindex_delta, | |
| 424 | + filter_level, | |
| 425 | + sharpness_level, | |
| 426 | + ref_lf_delta, | |
| 427 | + mode_lf_delta, | |
| 428 | + bit_offset_ref_lf_delta, | |
| 429 | + bit_offset_mode_lf_delta, | |
| 430 | + bit_offset_lf_level, | |
| 431 | + bit_offset_qindex, | |
| 432 | + bit_offset_first_partition_size, | |
| 433 | + bit_offset_segmentation, | |
| 434 | + bit_size_segmentation, | |
| 435 | + log2_tile_rows, | |
| 436 | + log2_tile_columns, | |
| 437 | + skip_frame_flag, | |
| 438 | + number_skip_frames, | |
| 439 | + skip_frames_size, | |
| 440 | + #[cfg(libva_1_23_or_higher)] | |
| 441 | + seg_id_block_size, | |
| 442 | + #[cfg(libva_1_23_or_higher)] | |
| 443 | + va_reserved8: Default::default(), | |
| 444 | + va_reserved: Default::default(), | |
| 445 | + })) | |
| 446 | + } | |
| 447 | + | |
| 448 | + pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferVP9 { | |
| 449 | + &mut self.0 | |
| 450 | + } | |
| 451 | +} |
shims/cros-libva/src/config.rsadded+137 -0
| @@ -0,0 +1,137 @@ | ||
| 1 | +// Copyright 2022 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 | +use std::rc::Rc; | |
| 6 | + | |
| 7 | +use log::error; | |
| 8 | +use thiserror::Error; | |
| 9 | + | |
| 10 | +use crate::bindings; | |
| 11 | +use crate::display::Display; | |
| 12 | +use crate::generic_value::GenericValue; | |
| 13 | +use crate::va_check; | |
| 14 | +use crate::GenericValueError; | |
| 15 | +use crate::VaError; | |
| 16 | + | |
| 17 | +/// A configuration for a given [`Display`]. | |
| 18 | +pub struct Config { | |
| 19 | + display: Rc<Display>, | |
| 20 | + id: bindings::VAConfigID, | |
| 21 | +} | |
| 22 | + | |
| 23 | +#[derive(Debug, Error)] | |
| 24 | +pub enum QuerySurfaceAttributesError { | |
| 25 | + #[error("error while calling vaQuerySurfaceAttributes: {0}")] | |
| 26 | + VaError(#[from] VaError), | |
| 27 | + #[error("error while converting attribute: {0}")] | |
| 28 | + GenericValueError(#[from] GenericValueError), | |
| 29 | +} | |
| 30 | + | |
| 31 | +impl Config { | |
| 32 | + /// Creates a Config by wrapping around the `vaCreateConfig` call. This is just a helper for | |
| 33 | + /// [`Display::create_config`]. | |
| 34 | + pub(crate) fn new( | |
| 35 | + display: Rc<Display>, | |
| 36 | + mut attrs: Vec<bindings::VAConfigAttrib>, | |
| 37 | + profile: bindings::VAProfile::Type, | |
| 38 | + entrypoint: bindings::VAEntrypoint::Type, | |
| 39 | + ) -> Result<Self, VaError> { | |
| 40 | + let mut config_id = 0u32; | |
| 41 | + | |
| 42 | + // Safe because `self` represents a valid `VADisplay`. | |
| 43 | + // | |
| 44 | + // The `attrs` vector is also properly initialized and its actual size is passed to | |
| 45 | + // `vaCreateConfig`, so it is impossible to write past the end of its storage by mistake. | |
| 46 | + va_check(unsafe { | |
| 47 | + bindings::vaCreateConfig( | |
| 48 | + display.handle(), | |
| 49 | + profile, | |
| 50 | + entrypoint, | |
| 51 | + attrs.as_mut_ptr(), | |
| 52 | + attrs.len() as i32, | |
| 53 | + &mut config_id, | |
| 54 | + ) | |
| 55 | + })?; | |
| 56 | + | |
| 57 | + Ok(Self { | |
| 58 | + display, | |
| 59 | + id: config_id, | |
| 60 | + }) | |
| 61 | + } | |
| 62 | + | |
| 63 | + /// Returns the ID of this config. | |
| 64 | + pub(crate) fn id(&self) -> bindings::VAConfigID { | |
| 65 | + self.id | |
| 66 | + } | |
| 67 | + | |
| 68 | + // Queries surface attributes for this config. | |
| 69 | + // | |
| 70 | + // This function queries for all supported attributes for this configuration. In particular, if | |
| 71 | + // the underlying hardware supports the creation of VA surfaces in various formats, then this | |
| 72 | + // function will enumerate all pixel formats that are supported. | |
| 73 | + fn query_surface_attributes(&mut self) -> Result<Vec<bindings::VASurfaceAttrib>, VaError> { | |
| 74 | + // Safe because `self` represents a valid VAConfig. We first query how | |
| 75 | + // much space is needed by the C API by passing in NULL in the first | |
| 76 | + // call to `vaQuerySurfaceAttributes`. | |
| 77 | + let attrs_len: std::os::raw::c_uint = 0; | |
| 78 | + va_check(unsafe { | |
| 79 | + bindings::vaQuerySurfaceAttributes( | |
| 80 | + self.display.handle(), | |
| 81 | + self.id, | |
| 82 | + std::ptr::null_mut(), | |
| 83 | + &attrs_len as *const _ as *mut std::os::raw::c_uint, | |
| 84 | + ) | |
| 85 | + })?; | |
| 86 | + | |
| 87 | + let mut attrs = Vec::with_capacity(attrs_len as usize); | |
| 88 | + // Safe because we allocate a vector with the required capacity as | |
| 89 | + // returned by the initial call to vaQuerySurfaceAttributes. We then | |
| 90 | + // pass a valid pointer to it. | |
| 91 | + va_check(unsafe { | |
| 92 | + bindings::vaQuerySurfaceAttributes( | |
| 93 | + self.display.handle(), | |
| 94 | + self.id, | |
| 95 | + attrs.as_mut_ptr(), | |
| 96 | + &attrs_len as *const _ as *mut std::os::raw::c_uint, | |
| 97 | + ) | |
| 98 | + })?; | |
| 99 | + | |
| 100 | + // Safe because vaQuerySurfaceAttributes will have written to | |
| 101 | + // exactly attrs_len entries in the vector. | |
| 102 | + unsafe { | |
| 103 | + attrs.set_len(attrs_len as usize); | |
| 104 | + } | |
| 105 | + | |
| 106 | + Ok(attrs) | |
| 107 | + } | |
| 108 | + | |
| 109 | + /// Query the surface attributes of type `attr_type`. The attribute may or may not be defined by | |
| 110 | + /// the driver. | |
| 111 | + pub fn query_surface_attributes_by_type( | |
| 112 | + &mut self, | |
| 113 | + attr_type: bindings::VASurfaceAttribType::Type, | |
| 114 | + ) -> Result<Vec<GenericValue>, QuerySurfaceAttributesError> { | |
| 115 | + let surface_attributes = self.query_surface_attributes()?; | |
| 116 | + | |
| 117 | + surface_attributes | |
| 118 | + .into_iter() | |
| 119 | + .filter(|attr| attr.type_ == attr_type) | |
| 120 | + .map(|attr| { | |
| 121 | + GenericValue::try_from(attr.value) | |
| 122 | + .map_err(QuerySurfaceAttributesError::GenericValueError) | |
| 123 | + }) | |
| 124 | + .collect() | |
| 125 | + } | |
| 126 | +} | |
| 127 | + | |
| 128 | +impl Drop for Config { | |
| 129 | + fn drop(&mut self) { | |
| 130 | + // Safe because `self` represents a valid Config. | |
| 131 | + let status = va_check(unsafe { bindings::vaDestroyConfig(self.display.handle(), self.id) }); | |
| 132 | + | |
| 133 | + if status.is_err() { | |
| 134 | + error!("vaDestroyConfig failed: {}", status.unwrap_err()); | |
| 135 | + } | |
| 136 | + } | |
| 137 | +} |
shims/cros-libva/src/context.rsadded+110 -0
| @@ -0,0 +1,110 @@ | ||
| 1 | +// Copyright 2022 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 | +use std::rc::Rc; | |
| 6 | + | |
| 7 | +use log::error; | |
| 8 | + | |
| 9 | +use crate::bindings; | |
| 10 | +use crate::buffer::Buffer; | |
| 11 | +use crate::buffer::BufferType; | |
| 12 | +use crate::display::Display; | |
| 13 | +use crate::va_check; | |
| 14 | +use crate::Config; | |
| 15 | +use crate::EncCodedBuffer; | |
| 16 | +use crate::Surface; | |
| 17 | +use crate::SurfaceMemoryDescriptor; | |
| 18 | +use crate::VaError; | |
| 19 | + | |
| 20 | +/// A VA context for a particular [`Display`]. | |
| 21 | +pub struct Context { | |
| 22 | + display: Rc<Display>, | |
| 23 | + id: bindings::VAContextID, | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl Context { | |
| 27 | + /// Creates a Context by wrapping around a `vaCreateContext` call. This is just a helper for | |
| 28 | + /// [`Display::create_context`]. | |
| 29 | + pub(crate) fn new<D: SurfaceMemoryDescriptor>( | |
| 30 | + display: Rc<Display>, | |
| 31 | + config: &Config, | |
| 32 | + coded_width: u32, | |
| 33 | + coded_height: u32, | |
| 34 | + surfaces: Option<&Vec<Surface<D>>>, | |
| 35 | + progressive: bool, | |
| 36 | + ) -> Result<Rc<Self>, VaError> { | |
| 37 | + let mut context_id = 0; | |
| 38 | + let flags = if progressive { | |
| 39 | + bindings::VA_PROGRESSIVE as i32 | |
| 40 | + } else { | |
| 41 | + 0 | |
| 42 | + }; | |
| 43 | + | |
| 44 | + let mut render_targets = match surfaces { | |
| 45 | + Some(surfaces) => Surface::as_id_vec(surfaces), | |
| 46 | + None => Default::default(), | |
| 47 | + }; | |
| 48 | + | |
| 49 | + // Safe because `self` represents a valid VADisplay and render_targets | |
| 50 | + // and ntargets are properly initialized. Note that render_targets==NULL | |
| 51 | + // is valid so long as ntargets==0. | |
| 52 | + va_check(unsafe { | |
| 53 | + bindings::vaCreateContext( | |
| 54 | + display.handle(), | |
| 55 | + config.id(), | |
| 56 | + coded_width as i32, | |
| 57 | + coded_height as i32, | |
| 58 | + flags, | |
| 59 | + render_targets.as_mut_ptr(), | |
| 60 | + render_targets.len() as i32, | |
| 61 | + &mut context_id, | |
| 62 | + ) | |
| 63 | + })?; | |
| 64 | + | |
| 65 | + Ok(Rc::new(Self { | |
| 66 | + display, | |
| 67 | + id: context_id, | |
| 68 | + })) | |
| 69 | + } | |
| 70 | + | |
| 71 | + /// Returns a shared reference to the [`Display`] used by this context. | |
| 72 | + pub fn display(&self) -> &Rc<Display> { | |
| 73 | + &self.display | |
| 74 | + } | |
| 75 | + | |
| 76 | + /// Returns the ID of this context. | |
| 77 | + pub(crate) fn id(&self) -> bindings::VAContextID { | |
| 78 | + self.id | |
| 79 | + } | |
| 80 | + | |
| 81 | + /// Create a new buffer of type `type_`. | |
| 82 | + pub fn create_buffer(self: &Rc<Self>, type_: BufferType) -> Result<Buffer, VaError> { | |
| 83 | + Buffer::new(Rc::clone(self), type_) | |
| 84 | + } | |
| 85 | + | |
| 86 | + /// Create a new buffer from a `BorrowedBufferType`. | |
| 87 | + pub fn create_buffer_borrowed( | |
| 88 | + self: &Rc<Self>, | |
| 89 | + type_: crate::buffer::BorrowedBufferType<'_>, | |
| 90 | + ) -> Result<Buffer, VaError> { | |
| 91 | + Buffer::new_borrowed(Rc::clone(self), type_) | |
| 92 | + } | |
| 93 | + | |
| 94 | + /// Create a new buffer of type `type_`. | |
| 95 | + pub fn create_enc_coded(self: &Rc<Self>, size: usize) -> Result<EncCodedBuffer, VaError> { | |
| 96 | + EncCodedBuffer::new(Rc::clone(self), size) | |
| 97 | + } | |
| 98 | +} | |
| 99 | + | |
| 100 | +impl Drop for Context { | |
| 101 | + fn drop(&mut self) { | |
| 102 | + // Safe because `self` represents a valid VAContext. | |
| 103 | + let status = | |
| 104 | + va_check(unsafe { bindings::vaDestroyContext(self.display.handle(), self.id) }); | |
| 105 | + | |
| 106 | + if status.is_err() { | |
| 107 | + error!("vaDestroyContext failed: {}", status.unwrap_err()); | |
| 108 | + } | |
| 109 | + } | |
| 110 | +} |
shims/cros-libva/src/display.rsadded+362 -0
| @@ -0,0 +1,362 @@ | ||
| 1 | +// Copyright 2022 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 | +use std::ffi::CStr; | |
| 6 | +use std::fs::File; | |
| 7 | +use std::io; | |
| 8 | +use std::os::unix::io::AsRawFd; | |
| 9 | +use std::path::Path; | |
| 10 | +use std::path::PathBuf; | |
| 11 | +use std::rc::Rc; | |
| 12 | + | |
| 13 | +use thiserror::Error; | |
| 14 | + | |
| 15 | +use crate::bindings; | |
| 16 | +use crate::config::Config; | |
| 17 | +use crate::context::Context; | |
| 18 | +use crate::surface::Surface; | |
| 19 | +use crate::va_check; | |
| 20 | +use crate::SurfaceMemoryDescriptor; | |
| 21 | +use crate::UsageHint; | |
| 22 | +use crate::VaError; | |
| 23 | + | |
| 24 | +/// Iterates over existing DRM devices. | |
| 25 | +/// | |
| 26 | +/// DRM devices can be passed to [`Display::open_drm_display`] in order to create a `Display` on | |
| 27 | +/// that device. | |
| 28 | +pub struct DrmDeviceIterator { | |
| 29 | + cur_idx: usize, | |
| 30 | +} | |
| 31 | + | |
| 32 | +const DRM_NODE_DEFAULT_PREFIX: &str = "/dev/dri/renderD"; | |
| 33 | +const DRM_NUM_NODES: usize = 64; | |
| 34 | +const DRM_RENDER_NODE_START: usize = 128; | |
| 35 | + | |
| 36 | +impl Default for DrmDeviceIterator { | |
| 37 | + fn default() -> Self { | |
| 38 | + Self { | |
| 39 | + cur_idx: DRM_RENDER_NODE_START, | |
| 40 | + } | |
| 41 | + } | |
| 42 | +} | |
| 43 | + | |
| 44 | +impl Iterator for DrmDeviceIterator { | |
| 45 | + type Item = PathBuf; | |
| 46 | + | |
| 47 | + fn next(&mut self) -> Option<Self::Item> { | |
| 48 | + match self.cur_idx { | |
| 49 | + idx if idx >= DRM_RENDER_NODE_START + DRM_NUM_NODES => None, | |
| 50 | + idx => { | |
| 51 | + let path = PathBuf::from(format!("{}{}", DRM_NODE_DEFAULT_PREFIX, idx)); | |
| 52 | + if !path.exists() { | |
| 53 | + None | |
| 54 | + } else { | |
| 55 | + self.cur_idx += 1; | |
| 56 | + Some(path) | |
| 57 | + } | |
| 58 | + } | |
| 59 | + } | |
| 60 | + } | |
| 61 | +} | |
| 62 | + | |
| 63 | +/// A VADisplay opened over DRM. | |
| 64 | +/// | |
| 65 | +/// A Display is the starting point to using libva. This struct is essentially a safe wrapper over | |
| 66 | +/// `VADisplay`, from which [`Surface`]s and [`Context`]s can be allocated in order to perform | |
| 67 | +/// actual work using [`Display::create_surfaces`] and [`Display::create_context`], respectively. | |
| 68 | +/// | |
| 69 | +/// Although libva offers several ways to create a display, this struct currently only supports | |
| 70 | +/// opening through DRM. It may be extended to support other display types (X11, Wayland) in the | |
| 71 | +/// future. | |
| 72 | +pub struct Display { | |
| 73 | + /// Handle to interact with the underlying `VADisplay`. | |
| 74 | + handle: bindings::VADisplay, | |
| 75 | + /// DRM file that must be kept open while the display is in use. | |
| 76 | + #[allow(dead_code)] | |
| 77 | + drm_file: File, | |
| 78 | +} | |
| 79 | + | |
| 80 | +/// Error type for `Display::open_drm_display`. | |
| 81 | +#[derive(Debug, Error)] | |
| 82 | +pub enum OpenDrmDisplayError { | |
| 83 | + #[error("cannot open DRM device: {0}")] | |
| 84 | + DeviceOpen(io::Error), | |
| 85 | + #[error("vaGetDisplayDRM returned NULL")] | |
| 86 | + VaGetDisplayDrm, | |
| 87 | + #[error("call to vaInitialize failed: {0}")] | |
| 88 | + VaInitialize(VaError), | |
| 89 | +} | |
| 90 | + | |
| 91 | +impl Display { | |
| 92 | + /// Opens and initializes a specific DRM `Display`. | |
| 93 | + /// | |
| 94 | + /// `path` is the path to a DRM device that supports VAAPI, e.g. `/dev/dri/renderD128`. | |
| 95 | + pub fn open_drm_display<P: AsRef<Path>>(path: P) -> Result<Rc<Self>, OpenDrmDisplayError> { | |
| 96 | + let file = std::fs::File::options() | |
| 97 | + .read(true) | |
| 98 | + .write(true) | |
| 99 | + .open(path.as_ref()) | |
| 100 | + .map_err(OpenDrmDisplayError::DeviceOpen)?; | |
| 101 | + | |
| 102 | + // Safe because fd represents a valid file descriptor and the pointer is checked for | |
| 103 | + // NULL afterwards. | |
| 104 | + let display = unsafe { bindings::vaGetDisplayDRM(file.as_raw_fd()) }; | |
| 105 | + if display.is_null() { | |
| 106 | + return Err(OpenDrmDisplayError::VaGetDisplayDrm); | |
| 107 | + } | |
| 108 | + | |
| 109 | + let mut major = 0i32; | |
| 110 | + let mut minor = 0i32; | |
| 111 | + // Safe because we ensure that the display is valid (i.e not NULL) before calling | |
| 112 | + // vaInitialize. The File will close the DRM fd on drop. | |
| 113 | + va_check(unsafe { bindings::vaInitialize(display, &mut major, &mut minor) }) | |
| 114 | + .map(|()| { | |
| 115 | + Rc::new(Self { | |
| 116 | + handle: display, | |
| 117 | + drm_file: file, | |
| 118 | + }) | |
| 119 | + }) | |
| 120 | + .map_err(OpenDrmDisplayError::VaInitialize) | |
| 121 | + } | |
| 122 | + | |
| 123 | + /// Opens the first device that succeeds and returns its `Display`. | |
| 124 | + /// | |
| 125 | + /// If an error occurs on a given device, it is ignored and the next one is tried until one | |
| 126 | + /// succeeds or we reach the end of the iterator. | |
| 127 | + pub fn open() -> Option<Rc<Self>> { | |
| 128 | + let devices = DrmDeviceIterator::default(); | |
| 129 | + | |
| 130 | + // Try all the DRM devices until one succeeds. | |
| 131 | + for device in devices { | |
| 132 | + if let Ok(display) = Self::open_drm_display(device) { | |
| 133 | + return Some(display); | |
| 134 | + } | |
| 135 | + } | |
| 136 | + | |
| 137 | + None | |
| 138 | + } | |
| 139 | + | |
| 140 | + /// Returns the handle of this display. | |
| 141 | + pub(crate) fn handle(&self) -> bindings::VADisplay { | |
| 142 | + self.handle | |
| 143 | + } | |
| 144 | + | |
| 145 | + /// Queries supported profiles by this display by wrapping `vaQueryConfigProfiles`. | |
| 146 | + pub fn query_config_profiles(&self) -> Result<Vec<bindings::VAProfile::Type>, VaError> { | |
| 147 | + // Safe because `self` represents a valid VADisplay. | |
| 148 | + let mut max_num_profiles = unsafe { bindings::vaMaxNumProfiles(self.handle) }; | |
| 149 | + let mut profiles = Vec::with_capacity(max_num_profiles as usize); | |
| 150 | + | |
| 151 | + // Safe because `self` represents a valid `VADisplay` and the vector has `max_num_profiles` | |
| 152 | + // as capacity. | |
| 153 | + va_check(unsafe { | |
| 154 | + bindings::vaQueryConfigProfiles( | |
| 155 | + self.handle, | |
| 156 | + profiles.as_mut_ptr(), | |
| 157 | + &mut max_num_profiles, | |
| 158 | + ) | |
| 159 | + })?; | |
| 160 | + | |
| 161 | + // Safe because `profiles` is allocated with a `max_num_profiles` capacity and | |
| 162 | + // `vaQueryConfigProfiles` wrote the actual number of profiles to `max_num_entrypoints`. | |
| 163 | + unsafe { | |
| 164 | + profiles.set_len(max_num_profiles as usize); | |
| 165 | + }; | |
| 166 | + | |
| 167 | + Ok(profiles) | |
| 168 | + } | |
| 169 | + | |
| 170 | + /// Returns a string describing some aspects of the VA implemenation on the specific hardware | |
| 171 | + /// accelerator used by this display. Wrapper over `vaQueryVendorString`. | |
| 172 | + /// | |
| 173 | + /// The format of the returned string is vendor specific and at the discretion of the | |
| 174 | + /// implementer. e.g. for the Intel GMA500 implementation, an example would be: `Intel GMA500 - | |
| 175 | + /// 2.0.0.32L.0005`. | |
| 176 | + pub fn query_vendor_string(&self) -> std::result::Result<String, &'static str> { | |
| 177 | + // Safe because `self` represents a valid VADisplay. | |
| 178 | + let vendor_string = unsafe { bindings::vaQueryVendorString(self.handle) }; | |
| 179 | + | |
| 180 | + if vendor_string.is_null() { | |
| 181 | + return Err("vaQueryVendorString() returned NULL"); | |
| 182 | + } | |
| 183 | + | |
| 184 | + // Safe because we check the whether the vendor_String pointer is NULL | |
| 185 | + Ok(unsafe { CStr::from_ptr(vendor_string) } | |
| 186 | + .to_string_lossy() | |
| 187 | + .to_string()) | |
| 188 | + } | |
| 189 | + | |
| 190 | + /// Query supported entrypoints for a given profile by wrapping `vaQueryConfigEntrypoints`. | |
| 191 | + pub fn query_config_entrypoints( | |
| 192 | + &self, | |
| 193 | + profile: bindings::VAProfile::Type, | |
| 194 | + ) -> Result<Vec<bindings::VAEntrypoint::Type>, VaError> { | |
| 195 | + // Safe because `self` represents a valid VADisplay. | |
| 196 | + let mut max_num_entrypoints = unsafe { bindings::vaMaxNumEntrypoints(self.handle) }; | |
| 197 | + let mut entrypoints = Vec::with_capacity(max_num_entrypoints as usize); | |
| 198 | + | |
| 199 | + // Safe because `self` represents a valid VADisplay and the vector has `max_num_entrypoints` | |
| 200 | + // as capacity. | |
| 201 | + va_check(unsafe { | |
| 202 | + bindings::vaQueryConfigEntrypoints( | |
| 203 | + self.handle, | |
| 204 | + profile, | |
| 205 | + entrypoints.as_mut_ptr(), | |
| 206 | + &mut max_num_entrypoints, | |
| 207 | + ) | |
| 208 | + })?; | |
| 209 | + | |
| 210 | + // Safe because `entrypoints` is allocated with a `max_num_entrypoints` capacity, and | |
| 211 | + // `vaQueryConfigEntrypoints` wrote the actual number of entrypoints to | |
| 212 | + // `max_num_entrypoints` | |
| 213 | + unsafe { | |
| 214 | + entrypoints.set_len(max_num_entrypoints as usize); | |
| 215 | + } | |
| 216 | + | |
| 217 | + Ok(entrypoints) | |
| 218 | + } | |
| 219 | + | |
| 220 | + /// Writes attributes for a given `profile`/`entrypoint` pair into `attributes`. Wrapper over | |
| 221 | + /// `vaGetConfigAttributes`. | |
| 222 | + /// | |
| 223 | + /// Entries of `attributes` must have their `type_` member initialized to the desired attribute | |
| 224 | + /// to retrieve. | |
| 225 | + pub fn get_config_attributes( | |
| 226 | + &self, | |
| 227 | + profile: bindings::VAProfile::Type, | |
| 228 | + entrypoint: bindings::VAEntrypoint::Type, | |
| 229 | + attributes: &mut [bindings::VAConfigAttrib], | |
| 230 | + ) -> Result<(), VaError> { | |
| 231 | + // Safe because `self` represents a valid VADisplay. The slice length is passed to the C | |
| 232 | + // function, so it is impossible to write past the end of the slice's storage by mistake. | |
| 233 | + va_check(unsafe { | |
| 234 | + bindings::vaGetConfigAttributes( | |
| 235 | + self.handle, | |
| 236 | + profile, | |
| 237 | + entrypoint, | |
| 238 | + attributes.as_mut_ptr(), | |
| 239 | + attributes.len() as i32, | |
| 240 | + ) | |
| 241 | + }) | |
| 242 | + } | |
| 243 | + | |
| 244 | + /// Creates `Surface`s by wrapping around a `vaCreateSurfaces` call. | |
| 245 | + /// | |
| 246 | + /// The number of surfaces created will be equal to the length of `descriptors`. | |
| 247 | + /// | |
| 248 | + /// # Arguments | |
| 249 | + /// | |
| 250 | + /// * `rt_format` - The desired surface format. See `VA_RT_FORMAT_*` | |
| 251 | + /// * `va_fourcc` - The desired pixel format (optional). See `VA_FOURCC_*` | |
| 252 | + /// * `width` - Width for the create surfaces | |
| 253 | + /// * `height` - Height for the created surfaces | |
| 254 | + /// * `usage_hint` - Optional hint of intended usage to optimize allocation (e.g. tiling) | |
| 255 | + /// * `num_surfaces` - Number of surfaces to create | |
| 256 | + /// * `descriptors` - Memory descriptors used as surface memory backing. | |
| 257 | + /// | |
| 258 | + /// # Return value | |
| 259 | + /// | |
| 260 | + /// Returns as many surfaces as the length of `descriptors`. | |
| 261 | + /// | |
| 262 | + /// Note that the `descriptors`'s ownership is irrevocably given to the surfaces, and that in | |
| 263 | + /// case of error the `descriptors` will be destroyed. Make sure to duplicate the descriptors | |
| 264 | + /// if you need something outside of libva to access them. | |
| 265 | + pub fn create_surfaces<D: SurfaceMemoryDescriptor>( | |
| 266 | + self: &Rc<Self>, | |
| 267 | + rt_format: u32, | |
| 268 | + va_fourcc: Option<u32>, | |
| 269 | + width: u32, | |
| 270 | + height: u32, | |
| 271 | + usage_hint: Option<UsageHint>, | |
| 272 | + descriptors: Vec<D>, | |
| 273 | + ) -> Result<Vec<Surface<D>>, VaError> { | |
| 274 | + Surface::new( | |
| 275 | + Rc::clone(self), | |
| 276 | + rt_format, | |
| 277 | + va_fourcc, | |
| 278 | + width, | |
| 279 | + height, | |
| 280 | + usage_hint, | |
| 281 | + descriptors, | |
| 282 | + ) | |
| 283 | + } | |
| 284 | + | |
| 285 | + /// Creates a `Context` by wrapping around a `vaCreateContext` call. | |
| 286 | + /// | |
| 287 | + /// # Arguments | |
| 288 | + /// | |
| 289 | + /// * `config` - The configuration for the context | |
| 290 | + /// * `coded_width` - The coded picture width | |
| 291 | + /// * `coded_height` - The coded picture height | |
| 292 | + /// * `surfaces` - Optional hint for the amount of surfaces tied to the context | |
| 293 | + /// * `progressive` - Whether only progressive frame pictures are present in the sequence | |
| 294 | + pub fn create_context<D: SurfaceMemoryDescriptor>( | |
| 295 | + self: &Rc<Self>, | |
| 296 | + config: &Config, | |
| 297 | + coded_width: u32, | |
| 298 | + coded_height: u32, | |
| 299 | + surfaces: Option<&Vec<Surface<D>>>, | |
| 300 | + progressive: bool, | |
| 301 | + ) -> Result<Rc<Context>, VaError> { | |
| 302 | + Context::new( | |
| 303 | + Rc::clone(self), | |
| 304 | + config, | |
| 305 | + coded_width, | |
| 306 | + coded_height, | |
| 307 | + surfaces, | |
| 308 | + progressive, | |
| 309 | + ) | |
| 310 | + } | |
| 311 | + | |
| 312 | + /// Creates a `Config` by wrapping around the `vaCreateConfig` call. | |
| 313 | + /// | |
| 314 | + /// `attrs` describe the attributes to set for this config. A list of the supported attributes | |
| 315 | + /// for a given profile/entrypoint pair can be retrieved using | |
| 316 | + /// [`Display::get_config_attributes`]. Other attributes will take their default values, and | |
| 317 | + /// `attrs` can be empty in order to obtain a default configuration. | |
| 318 | + pub fn create_config( | |
| 319 | + self: &Rc<Self>, | |
| 320 | + attrs: Vec<bindings::VAConfigAttrib>, | |
| 321 | + profile: bindings::VAProfile::Type, | |
| 322 | + entrypoint: bindings::VAEntrypoint::Type, | |
| 323 | + ) -> Result<Config, VaError> { | |
| 324 | + Config::new(Rc::clone(self), attrs, profile, entrypoint) | |
| 325 | + } | |
| 326 | + | |
| 327 | + /// Returns available image formats for this display by wrapping around `vaQueryImageFormats`. | |
| 328 | + pub fn query_image_formats(&self) -> Result<Vec<bindings::VAImageFormat>, VaError> { | |
| 329 | + // Safe because `self` represents a valid VADisplay. | |
| 330 | + let mut num_image_formats = unsafe { bindings::vaMaxNumImageFormats(self.handle) }; | |
| 331 | + let mut image_formats = Vec::with_capacity(num_image_formats as usize); | |
| 332 | + | |
| 333 | + // Safe because `self` represents a valid VADisplay. The `image_formats` vector is properly | |
| 334 | + // initialized and a valid size is passed to the C function, so it is impossible to write | |
| 335 | + // past the end of their storage by mistake. | |
| 336 | + va_check(unsafe { | |
| 337 | + bindings::vaQueryImageFormats( | |
| 338 | + self.handle, | |
| 339 | + image_formats.as_mut_ptr(), | |
| 340 | + &mut num_image_formats, | |
| 341 | + ) | |
| 342 | + })?; | |
| 343 | + | |
| 344 | + // Safe because the C function will have written exactly `num_image_format` entries, which | |
| 345 | + // is known to be within the vector's capacity. | |
| 346 | + unsafe { | |
| 347 | + image_formats.set_len(num_image_formats as usize); | |
| 348 | + } | |
| 349 | + | |
| 350 | + Ok(image_formats) | |
| 351 | + } | |
| 352 | +} | |
| 353 | + | |
| 354 | +impl Drop for Display { | |
| 355 | + fn drop(&mut self) { | |
| 356 | + // Safe because `self` represents a valid VADisplay. | |
| 357 | + unsafe { | |
| 358 | + bindings::vaTerminate(self.handle); | |
| 359 | + // The File will close the DRM fd on drop. | |
| 360 | + } | |
| 361 | + } | |
| 362 | +} |
shims/cros-libva/src/generic_value.rsadded+50 -0
| @@ -0,0 +1,50 @@ | ||
| 1 | +// Copyright 2022 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 | +use thiserror::Error; | |
| 6 | + | |
| 7 | +use crate::bindings; | |
| 8 | + | |
| 9 | +/// A wrapper over `VAGenericValue` giving us safe access to the underlying union members. | |
| 10 | +#[derive(Debug)] | |
| 11 | +pub enum GenericValue { | |
| 12 | + /// A wrapper over VAGenericValueTypeInteger | |
| 13 | + Integer(i32), | |
| 14 | + /// A wrapper over VAGenericValueTypeFloat | |
| 15 | + Float(f32), | |
| 16 | + /// A wrapper over VAGenericValueTypePointer | |
| 17 | + Pointer(*mut std::os::raw::c_void), | |
| 18 | + /// A wrapper over VAGenericValueTypeFunc | |
| 19 | + Func(bindings::VAGenericFunc), | |
| 20 | +} | |
| 21 | + | |
| 22 | +#[derive(Debug, Error)] | |
| 23 | +pub enum GenericValueError { | |
| 24 | + #[error("unexpected VAGenericValueType {0}")] | |
| 25 | + UnexpectedType(u32), | |
| 26 | +} | |
| 27 | + | |
| 28 | +impl TryFrom<bindings::VAGenericValue> for GenericValue { | |
| 29 | + type Error = GenericValueError; | |
| 30 | + | |
| 31 | + fn try_from(value: bindings::VAGenericValue) -> Result<Self, Self::Error> { | |
| 32 | + // Safe because we check the type before accessing the union. | |
| 33 | + match value.type_ { | |
| 34 | + // Safe because we check the type before accessing the union. | |
| 35 | + bindings::VAGenericValueType::VAGenericValueTypeInteger => { | |
| 36 | + Ok(Self::Integer(unsafe { value.value.i })) | |
| 37 | + } | |
| 38 | + bindings::VAGenericValueType::VAGenericValueTypeFloat => { | |
| 39 | + Ok(Self::Float(unsafe { value.value.f })) | |
| 40 | + } | |
| 41 | + bindings::VAGenericValueType::VAGenericValueTypePointer => { | |
| 42 | + Ok(Self::Pointer(unsafe { value.value.p })) | |
| 43 | + } | |
| 44 | + bindings::VAGenericValueType::VAGenericValueTypeFunc => { | |
| 45 | + Ok(Self::Func(unsafe { value.value.fn_ })) | |
| 46 | + } | |
| 47 | + _ => Err(GenericValueError::UnexpectedType(value.type_)), | |
| 48 | + } | |
| 49 | + } | |
| 50 | +} |
shims/cros-libva/src/image.rsadded+235 -0
| @@ -0,0 +1,235 @@ | ||
| 1 | +// Copyright 2022 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 | +use std::rc::Rc; | |
| 6 | + | |
| 7 | +use crate::bindings; | |
| 8 | +use crate::va_check; | |
| 9 | +use crate::Display; | |
| 10 | +use crate::Surface; | |
| 11 | +use crate::SurfaceMemoryDescriptor; | |
| 12 | +use crate::VaError; | |
| 13 | + | |
| 14 | +/// Wrapper around `VAImage` that is tied to the lifetime of a given `Picture`. | |
| 15 | +/// | |
| 16 | +/// An image is used to either get the surface data to client memory, or to copy image data in | |
| 17 | +/// client memory to a surface. | |
| 18 | +pub struct Image<'a> { | |
| 19 | + /// The display from which the image was created, so we can unmap it upon destruction. | |
| 20 | + display: Rc<Display>, | |
| 21 | + /// The `VAImage` returned by libva. | |
| 22 | + image: bindings::VAImage, | |
| 23 | + /// The mapped surface data. | |
| 24 | + /// | |
| 25 | + /// The lifetime also allows us to ensure that the `Surface` we have been created from | |
| 26 | + /// does not drop or get changed while we exist. | |
| 27 | + data: &'a mut [u8], | |
| 28 | + /// Whether the image was derived using the `vaDeriveImage` API or created using the | |
| 29 | + /// `vaCreateImage` API. | |
| 30 | + derived: bool, | |
| 31 | + /// The display resolution requested by the client. The implementation is | |
| 32 | + /// free to enlarge this value as needed. In any case, we guarantee that an | |
| 33 | + /// image at least as large is returned. | |
| 34 | + display_resolution: (u32, u32), | |
| 35 | + /// Tracks whether the underlying data has possibly been written to, i.e. an encoder will create | |
| 36 | + /// an image and map its buffer in order to write to it, so we must writeback later. | |
| 37 | + dirty: bool, | |
| 38 | + /// The ID of the `Surface` we have been created from. | |
| 39 | + surface_id: u32, | |
| 40 | +} | |
| 41 | + | |
| 42 | +impl<'a> Image<'a> { | |
| 43 | + /// Helper method to map a `VAImage` using `vaMapBuffer` and return an `Image`. | |
| 44 | + /// | |
| 45 | + /// Returns an error if the mapping failed. | |
| 46 | + fn new<D: SurfaceMemoryDescriptor>( | |
| 47 | + surface: &'a Surface<D>, | |
| 48 | + image: bindings::VAImage, | |
| 49 | + derived: bool, | |
| 50 | + display_resolution: (u32, u32), | |
| 51 | + ) -> Result<Self, VaError> { | |
| 52 | + let mut addr = std::ptr::null_mut(); | |
| 53 | + | |
| 54 | + // Safe since `picture.inner.context` represents a valid `VAContext` and `image` has been | |
| 55 | + // successfully created at this point. | |
| 56 | + match va_check(unsafe { | |
| 57 | + bindings::vaMapBuffer(surface.display().handle(), image.buf, &mut addr) | |
| 58 | + }) { | |
| 59 | + Ok(_) => { | |
| 60 | + // Assert that libva provided us with a coded resolution that is | |
| 61 | + // at least as large as `display_resolution`. | |
| 62 | + assert!(u32::from(image.width) >= display_resolution.0); | |
| 63 | + assert!(u32::from(image.height) >= display_resolution.1); | |
| 64 | + | |
| 65 | + // Safe since `addr` points to data mapped onto our address space since we called | |
| 66 | + // `vaMapBuffer` above, which also guarantees that the data is valid for | |
| 67 | + // `image.data_size`. | |
| 68 | + let data = | |
| 69 | + unsafe { std::slice::from_raw_parts_mut(addr as _, image.data_size as usize) }; | |
| 70 | + Ok(Image { | |
| 71 | + display: Rc::clone(surface.display()), | |
| 72 | + image, | |
| 73 | + data, | |
| 74 | + derived, | |
| 75 | + display_resolution, | |
| 76 | + dirty: false, | |
| 77 | + surface_id: surface.id(), | |
| 78 | + }) | |
| 79 | + } | |
| 80 | + Err(e) => { | |
| 81 | + // Safe because `picture.inner.context` represents a valid `VAContext` and `image` | |
| 82 | + // represents a valid `VAImage`. | |
| 83 | + unsafe { | |
| 84 | + bindings::vaDestroyImage(surface.display().handle(), image.image_id); | |
| 85 | + } | |
| 86 | + | |
| 87 | + Err(e) | |
| 88 | + } | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 92 | + /// Create a new derived image from this `surface` using `vaDeriveImage`. | |
| 93 | + /// | |
| 94 | + /// Derived images are a direct view (i.e. without any copy) on the buffer content of | |
| 95 | + /// `surface`. On the other hand, not all `Surface`s can be derived. | |
| 96 | + /// | |
| 97 | + /// `visible_rect` is the visible rectangle inside `surface` that we want to access. | |
| 98 | + pub fn derive_from<D: SurfaceMemoryDescriptor>( | |
| 99 | + surface: &'a Surface<D>, | |
| 100 | + visible_rect: (u32, u32), | |
| 101 | + ) -> Result<Self, VaError> { | |
| 102 | + // An all-zero byte-pattern is a valid initial value for `VAImage`. | |
| 103 | + let mut image: bindings::VAImage = Default::default(); | |
| 104 | + | |
| 105 | + // Safe because `self` has a valid display handle and ID. | |
| 106 | + va_check(unsafe { | |
| 107 | + bindings::vaDeriveImage(surface.display().handle(), surface.id(), &mut image) | |
| 108 | + })?; | |
| 109 | + | |
| 110 | + Self::new(surface, image, true, visible_rect) | |
| 111 | + } | |
| 112 | + | |
| 113 | + /// Create new image from `surface` using `vaCreateImage` and `vaGetImage`. | |
| 114 | + /// | |
| 115 | + /// `visible_rect` is the visible rectangle inside `surface` that we want to access. | |
| 116 | + /// | |
| 117 | + /// The image will contain a copy of `surface`'s data' in the desired `format` and | |
| 118 | + /// `coded_resolution`, meaning the data can be scaled if `coded_resolution` and `visible_rect` | |
| 119 | + /// differ. | |
| 120 | + pub fn create_from<D: SurfaceMemoryDescriptor>( | |
| 121 | + surface: &'a Surface<D>, | |
| 122 | + mut format: bindings::VAImageFormat, | |
| 123 | + coded_resolution: (u32, u32), | |
| 124 | + visible_rect: (u32, u32), | |
| 125 | + ) -> Result<Image<'a>, VaError> { | |
| 126 | + // An all-zero byte-pattern is a valid initial value for `VAImage`. | |
| 127 | + let mut image: bindings::VAImage = Default::default(); | |
| 128 | + let dpy = surface.display().handle(); | |
| 129 | + | |
| 130 | + // Safe because `dpy` is a valid display handle. | |
| 131 | + va_check(unsafe { | |
| 132 | + bindings::vaCreateImage( | |
| 133 | + dpy, | |
| 134 | + &mut format, | |
| 135 | + coded_resolution.0 as i32, | |
| 136 | + coded_resolution.1 as i32, | |
| 137 | + &mut image, | |
| 138 | + ) | |
| 139 | + })?; | |
| 140 | + | |
| 141 | + // Safe because `dpy` is a valid display handle, `picture.surface` is a valid VASurface and | |
| 142 | + // `image` is a valid `VAImage`. | |
| 143 | + match va_check(unsafe { | |
| 144 | + bindings::vaGetImage( | |
| 145 | + dpy, | |
| 146 | + surface.id(), | |
| 147 | + 0, | |
| 148 | + 0, | |
| 149 | + coded_resolution.0, | |
| 150 | + coded_resolution.1, | |
| 151 | + image.image_id, | |
| 152 | + ) | |
| 153 | + }) { | |
| 154 | + Ok(()) => Self::new(surface, image, false, visible_rect), | |
| 155 | + | |
| 156 | + Err(e) => { | |
| 157 | + // Safe because `image` is a valid `VAImage`. | |
| 158 | + unsafe { | |
| 159 | + bindings::vaDestroyImage(dpy, image.image_id); | |
| 160 | + } | |
| 161 | + | |
| 162 | + Err(e) | |
| 163 | + } | |
| 164 | + } | |
| 165 | + } | |
| 166 | + | |
| 167 | + /// Get a reference to the underlying `VAImage` that describes this image. | |
| 168 | + pub fn image(&self) -> &bindings::VAImage { | |
| 169 | + &self.image | |
| 170 | + } | |
| 171 | + | |
| 172 | + /// Returns whether this image is directly derived from its underlying `Picture`, as opposed to | |
| 173 | + /// being a view/copy of said `Picture` in a guaranteed pixel format. | |
| 174 | + pub fn is_derived(&self) -> bool { | |
| 175 | + self.derived | |
| 176 | + } | |
| 177 | + | |
| 178 | + /// Returns the display resolution as passed in by the client. This is a | |
| 179 | + /// value that is less than or equal to the coded resolution. | |
| 180 | + pub fn display_resolution(&self) -> (u32, u32) { | |
| 181 | + self.display_resolution | |
| 182 | + } | |
| 183 | + | |
| 184 | + /// Returns the coded resolution. This value can be larger than the value | |
| 185 | + /// passed in when the image was created if the driver needs to. | |
| 186 | + pub fn coded_resolution(&self) -> (u32, u32) { | |
| 187 | + (self.image.width.into(), self.image.height.into()) | |
| 188 | + } | |
| 189 | +} | |
| 190 | + | |
| 191 | +impl<'a> AsRef<[u8]> for Image<'a> { | |
| 192 | + fn as_ref(&self) -> &[u8] { | |
| 193 | + self.data | |
| 194 | + } | |
| 195 | +} | |
| 196 | + | |
| 197 | +impl<'a> AsMut<[u8]> for Image<'a> { | |
| 198 | + fn as_mut(&mut self) -> &mut [u8] { | |
| 199 | + self.dirty = true; | |
| 200 | + self.data | |
| 201 | + } | |
| 202 | +} | |
| 203 | + | |
| 204 | +impl<'a> Drop for Image<'a> { | |
| 205 | + fn drop(&mut self) { | |
| 206 | + if !self.derived && self.dirty { | |
| 207 | + // Safe because `picture.inner.context` represents a valid `VAContext`, | |
| 208 | + // `picture.surface` represents a valid `VASurface` and `image` represents a valid | |
| 209 | + // `VAImage`. | |
| 210 | + unsafe { | |
| 211 | + bindings::vaPutImage( | |
| 212 | + self.display.handle(), | |
| 213 | + self.surface_id, | |
| 214 | + self.image.image_id, | |
| 215 | + 0, | |
| 216 | + 0, | |
| 217 | + self.image.width as u32, | |
| 218 | + self.image.height as u32, | |
| 219 | + 0, | |
| 220 | + 0, | |
| 221 | + self.image.width as u32, | |
| 222 | + self.image.height as u32, | |
| 223 | + ); | |
| 224 | + } | |
| 225 | + } | |
| 226 | + | |
| 227 | + unsafe { | |
| 228 | + // Safe since the buffer is mapped in `Image::new`, so `self.image.buf` points to a | |
| 229 | + // valid `VABufferID`. | |
| 230 | + bindings::vaUnmapBuffer(self.display.handle(), self.image.buf); | |
| 231 | + // Safe since `self.image` represents a valid `VAImage`. | |
| 232 | + bindings::vaDestroyImage(self.display.handle(), self.image.image_id); | |
| 233 | + } | |
| 234 | + } | |
| 235 | +} |
shims/cros-libva/src/lib.rsadded+536 -0
| @@ -0,0 +1,536 @@ | ||
| 1 | +// Copyright 2022 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 | +//! Implements a lightweight and safe interface over `libva`. | |
| 6 | +//! | |
| 7 | +//! The starting point to using this crate is to open a [`Display`], from which a [`Context`] and | |
| 8 | +//! [`Surface`]s can be allocated and used for doing actual work. | |
| 9 | + | |
| 10 | +mod bindings; | |
| 11 | +pub mod buffer; | |
| 12 | +mod config; | |
| 13 | +mod context; | |
| 14 | +mod display; | |
| 15 | +mod generic_value; | |
| 16 | +mod image; | |
| 17 | +mod picture; | |
| 18 | +mod surface; | |
| 19 | +mod usage_hint; | |
| 20 | + | |
| 21 | +pub use bindings::_VADRMPRIMESurfaceDescriptor__bindgen_ty_1 as VADRMPRIMESurfaceDescriptorObject; | |
| 22 | +pub use bindings::_VADRMPRIMESurfaceDescriptor__bindgen_ty_2 as VADRMPRIMESurfaceDescriptorLayer; | |
| 23 | +pub use bindings::*; | |
| 24 | +pub use buffer::*; | |
| 25 | +pub use config::*; | |
| 26 | +pub use context::*; | |
| 27 | +pub use display::*; | |
| 28 | +pub use generic_value::*; | |
| 29 | +pub use image::*; | |
| 30 | +pub use picture::*; | |
| 31 | +pub use surface::*; | |
| 32 | +pub use usage_hint::*; | |
| 33 | + | |
| 34 | +use std::num::NonZeroI32; | |
| 35 | + | |
| 36 | +/// A `VAStatus` that is guaranteed to not be `VA_STATUS_SUCCESS`. | |
| 37 | +#[derive(Debug)] | |
| 38 | +pub struct VaError(NonZeroI32); | |
| 39 | + | |
| 40 | +impl VaError { | |
| 41 | + /// Returns the `VAStatus` of this error. | |
| 42 | + pub fn va_status(&self) -> VAStatus { | |
| 43 | + self.0.get() as VAStatus | |
| 44 | + } | |
| 45 | +} | |
| 46 | + | |
| 47 | +impl std::fmt::Display for VaError { | |
| 48 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
| 49 | + use std::ffi::CStr; | |
| 50 | + | |
| 51 | + // Safe because `vaErrorStr` will return a pointer to a statically allocated, null | |
| 52 | + // terminated C string. The pointer is guaranteed to never be null. | |
| 53 | + let err_str = unsafe { CStr::from_ptr(bindings::vaErrorStr(self.0.get())) } | |
| 54 | + .to_str() | |
| 55 | + .unwrap(); | |
| 56 | + f.write_str(err_str) | |
| 57 | + } | |
| 58 | +} | |
| 59 | + | |
| 60 | +impl std::error::Error for VaError {} | |
| 61 | + | |
| 62 | +/// Checks a VA return value and returns a `VaError` if it is not `VA_STATUS_SUCCESS`. | |
| 63 | +/// | |
| 64 | +/// This can be used on the return value of any VA function returning `VAStatus` in order to | |
| 65 | +/// convert it to a proper Rust `Result`. | |
| 66 | +fn va_check(code: VAStatus) -> Result<(), VaError> { | |
| 67 | + match code as u32 { | |
| 68 | + bindings::VA_STATUS_SUCCESS => Ok(()), | |
| 69 | + _ => Err(VaError(unsafe { NonZeroI32::new_unchecked(code) })), | |
| 70 | + } | |
| 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/picture.rsadded+307 -0
| @@ -0,0 +1,307 @@ | ||
| 1 | +// Copyright 2022 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 | +use std::borrow::Borrow; | |
| 6 | +use std::marker::PhantomData; | |
| 7 | +use std::rc::Rc; | |
| 8 | + | |
| 9 | +use crate::bindings; | |
| 10 | +use crate::buffer::Buffer; | |
| 11 | +use crate::context::Context; | |
| 12 | +use crate::surface::Surface; | |
| 13 | +use crate::va_check; | |
| 14 | +use crate::Image; | |
| 15 | +use crate::SurfaceMemoryDescriptor; | |
| 16 | +use crate::VaError; | |
| 17 | + | |
| 18 | +// Use the sealed trait pattern to make sure that new states are not created in caller code. More | |
| 19 | +// information about the sealed trait pattern can be found at | |
| 20 | +// <https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed> | |
| 21 | +mod private { | |
| 22 | + pub trait Sealed {} | |
| 23 | +} | |
| 24 | + | |
| 25 | +/// A `Picture` will only have valid YUV data after a sequence of operations are performed in a | |
| 26 | +/// particular order. This order correspond to the following VA-API calls: `vaBeginPicture`, | |
| 27 | +/// `vaRenderPicture`, `vaEndPicture` and `vaSyncSurface`. This trait enforces this ordering by | |
| 28 | +/// implementing the Typestate pattern to constrain what operations are available in what particular | |
| 29 | +/// states. | |
| 30 | +/// | |
| 31 | +/// The states for the state machine are: | |
| 32 | +/// | |
| 33 | +/// * PictureNew -> PictureBegin | |
| 34 | +/// * PictureBegin -> PictureRender | |
| 35 | +/// * PictureRender ->PictureEnd | |
| 36 | +/// * PictureEnd -> PictureSync | |
| 37 | +/// | |
| 38 | +/// Where the surface can be reclaimed in both `PictureNew` and `PictureSync`, as either no | |
| 39 | +/// operation took place (as in `PictureNew`), or it is guaranteed that the operation has already | |
| 40 | +/// completed (as in `PictureSync`). | |
| 41 | +/// | |
| 42 | +/// More information about the Typestate pattern can be found at | |
| 43 | +/// <http://cliffle.com/blog/rust-typestate/> | |
| 44 | +pub trait PictureState: private::Sealed {} | |
| 45 | + | |
| 46 | +/// Represents a `Picture` that has just been created. | |
| 47 | +pub enum PictureNew {} | |
| 48 | +impl PictureState for PictureNew {} | |
| 49 | +impl private::Sealed for PictureNew {} | |
| 50 | + | |
| 51 | +/// Represents a `Picture` after `vaBeginPicture` has been called. | |
| 52 | +pub enum PictureBegin {} | |
| 53 | +impl PictureState for PictureBegin {} | |
| 54 | +impl private::Sealed for PictureBegin {} | |
| 55 | + | |
| 56 | +/// Represents a `Picture` after `vaRenderPicture` has been called. | |
| 57 | +pub enum PictureRender {} | |
| 58 | +impl PictureState for PictureRender {} | |
| 59 | +impl private::Sealed for PictureRender {} | |
| 60 | + | |
| 61 | +/// Represents a `Picture` after `vaEndPicture` has been called. | |
| 62 | +pub enum PictureEnd {} | |
| 63 | +impl PictureState for PictureEnd {} | |
| 64 | +impl private::Sealed for PictureEnd {} | |
| 65 | + | |
| 66 | +/// Represents a `Picture` after `vaSyncSurface` has been called on the underlying surface. | |
| 67 | +pub enum PictureSync {} | |
| 68 | +impl PictureState for PictureSync {} | |
| 69 | +impl private::Sealed for PictureSync {} | |
| 70 | + | |
| 71 | +/// Represents a state where one can reclaim the underlying `Surface` for this `Picture`. This is | |
| 72 | +/// true when either no decoding has been initiated or, alternatively, when the decoding operation | |
| 73 | +/// has completed for the underlying `vaSurface` | |
| 74 | +pub trait PictureReclaimableSurface: PictureState + private::Sealed {} | |
| 75 | +impl PictureReclaimableSurface for PictureNew {} | |
| 76 | +impl PictureReclaimableSurface for PictureSync {} | |
| 77 | + | |
| 78 | +/// Inner type for [`Picture`], that is, the part that exists in all states. | |
| 79 | +struct PictureInner<T> { | |
| 80 | + /// Timestamp of the picture. | |
| 81 | + timestamp: u64, | |
| 82 | + /// A context associated with this picture. | |
| 83 | + context: Rc<Context>, | |
| 84 | + /// Contains the buffers used to decode the data. | |
| 85 | + buffers: Vec<Buffer>, | |
| 86 | + /// Contains the actual decoded data. Note that the surface may be shared in | |
| 87 | + /// interlaced decoding. | |
| 88 | + surface: Rc<T>, | |
| 89 | +} | |
| 90 | + | |
| 91 | +/// A `Surface` that is being rendered into. | |
| 92 | +/// | |
| 93 | +/// This struct abstracts the decoding flow using `vaBeginPicture`, `vaRenderPicture`, | |
| 94 | +/// `vaEndPicture` and `vaSyncSurface` in a type-safe way. | |
| 95 | +/// | |
| 96 | +/// The surface will have valid picture data after all the stages of decoding are called. | |
| 97 | +/// | |
| 98 | +/// The `T` generic parameter must be `Borrow<Surface<_>>`, i.e. it can be [`Surface`] directly or | |
| 99 | +/// some other type that contains one. | |
| 100 | +/// | |
| 101 | +/// No constraint on `T` is specified in this declaration because specifying it here would force us | |
| 102 | +/// to add the generic argument of [`Surface`] to this type as well, turning it into a type with 3 | |
| 103 | +/// generics, one of which is redundant. To avoid that we leave `T` unconstrained and instead | |
| 104 | +/// constrain the methods that require to act on it as a [`Surface`]. | |
| 105 | +pub struct Picture<S: PictureState, T> { | |
| 106 | + inner: Box<PictureInner<T>>, | |
| 107 | + phantom: std::marker::PhantomData<S>, | |
| 108 | +} | |
| 109 | + | |
| 110 | +impl<T> Picture<PictureNew, T> { | |
| 111 | + /// Creates a new Picture with a given `timestamp`. `surface` is the underlying surface that | |
| 112 | + /// libva will render to. | |
| 113 | + pub fn new<D: SurfaceMemoryDescriptor>(timestamp: u64, context: Rc<Context>, surface: T) -> Self | |
| 114 | + where | |
| 115 | + T: Borrow<Surface<D>>, | |
| 116 | + { | |
| 117 | + Self { | |
| 118 | + inner: Box::new(PictureInner { | |
| 119 | + timestamp, | |
| 120 | + context, | |
| 121 | + buffers: Default::default(), | |
| 122 | + surface: Rc::new(surface), | |
| 123 | + }), | |
| 124 | + | |
| 125 | + phantom: PhantomData, | |
| 126 | + } | |
| 127 | + } | |
| 128 | + | |
| 129 | + /// Creates a new Picture with a given `timestamp` to identify it, | |
| 130 | + /// reusing the Surface from `picture`. This is useful for interlaced | |
| 131 | + /// decoding as one can render both fields to the same underlying surface. | |
| 132 | + pub fn new_from_same_surface<S: PictureState>(timestamp: u64, picture: &Picture<S, T>) -> Self { | |
| 133 | + let context = Rc::clone(&picture.inner.context); | |
| 134 | + Picture { | |
| 135 | + inner: Box::new(PictureInner { | |
| 136 | + timestamp, | |
| 137 | + context, | |
| 138 | + buffers: Default::default(), | |
| 139 | + surface: Rc::clone(&picture.inner.surface), | |
| 140 | + }), | |
| 141 | + | |
| 142 | + phantom: PhantomData, | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + /// Add `buffer` to the picture. | |
| 147 | + pub fn add_buffer(&mut self, buffer: Buffer) { | |
| 148 | + self.inner.buffers.push(buffer); | |
| 149 | + } | |
| 150 | + | |
| 151 | + /// Wrapper around `vaBeginPicture`. | |
| 152 | + pub fn begin<D: SurfaceMemoryDescriptor>(self) -> Result<Picture<PictureBegin, T>, VaError> | |
| 153 | + where | |
| 154 | + T: Borrow<Surface<D>>, | |
| 155 | + { | |
| 156 | + // Safe because `self.inner.context` represents a valid VAContext and | |
| 157 | + // `self.inner.surface` represents a valid VASurface. | |
| 158 | + let res = va_check(unsafe { | |
| 159 | + bindings::vaBeginPicture( | |
| 160 | + self.inner.context.display().handle(), | |
| 161 | + self.inner.context.id(), | |
| 162 | + self.surface().id(), | |
| 163 | + ) | |
| 164 | + }); | |
| 165 | + | |
| 166 | + res.map(|()| Picture { | |
| 167 | + inner: self.inner, | |
| 168 | + phantom: PhantomData, | |
| 169 | + }) | |
| 170 | + } | |
| 171 | +} | |
| 172 | + | |
| 173 | +impl<T> Picture<PictureBegin, T> { | |
| 174 | + /// Wrapper around `vaRenderPicture`. | |
| 175 | + pub fn render(self) -> Result<Picture<PictureRender, T>, VaError> { | |
| 176 | + // Safe because `self.inner.context` represents a valid `VAContext` and `self.inner.surface` | |
| 177 | + // represents a valid `VASurface`. `buffers` point to a Rust struct and the vector length is | |
| 178 | + // passed to the C function, so it is impossible to write past the end of the vector's | |
| 179 | + // storage by mistake. | |
| 180 | + va_check(unsafe { | |
| 181 | + bindings::vaRenderPicture( | |
| 182 | + self.inner.context.display().handle(), | |
| 183 | + self.inner.context.id(), | |
| 184 | + Buffer::as_id_vec(&self.inner.buffers).as_mut_ptr(), | |
| 185 | + self.inner.buffers.len() as i32, | |
| 186 | + ) | |
| 187 | + }) | |
| 188 | + .map(|()| Picture { | |
| 189 | + inner: self.inner, | |
| 190 | + phantom: PhantomData, | |
| 191 | + }) | |
| 192 | + } | |
| 193 | +} | |
| 194 | + | |
| 195 | +impl<T> Picture<PictureRender, T> { | |
| 196 | + /// Wrapper around `vaEndPicture`. | |
| 197 | + pub fn end(self) -> Result<Picture<PictureEnd, T>, VaError> { | |
| 198 | + // Safe because `self.inner.context` represents a valid `VAContext`. | |
| 199 | + va_check(unsafe { | |
| 200 | + bindings::vaEndPicture( | |
| 201 | + self.inner.context.display().handle(), | |
| 202 | + self.inner.context.id(), | |
| 203 | + ) | |
| 204 | + }) | |
| 205 | + .map(|()| Picture { | |
| 206 | + inner: self.inner, | |
| 207 | + phantom: PhantomData, | |
| 208 | + }) | |
| 209 | + } | |
| 210 | +} | |
| 211 | + | |
| 212 | +impl<T> Picture<PictureEnd, T> { | |
| 213 | + /// Syncs the picture, ensuring that all pending operations are complete when this call returns. | |
| 214 | + pub fn sync<D: SurfaceMemoryDescriptor>( | |
| 215 | + self, | |
| 216 | + ) -> Result<Picture<PictureSync, T>, (VaError, Self)> | |
| 217 | + where | |
| 218 | + T: Borrow<Surface<D>>, | |
| 219 | + { | |
| 220 | + let res = self.surface().sync(); | |
| 221 | + | |
| 222 | + match res { | |
| 223 | + Ok(()) => Ok(Picture { | |
| 224 | + inner: self.inner, | |
| 225 | + phantom: PhantomData, | |
| 226 | + }), | |
| 227 | + Err(e) => Err((e, self)), | |
| 228 | + } | |
| 229 | + } | |
| 230 | +} | |
| 231 | + | |
| 232 | +impl<S: PictureState, T> Picture<S, T> { | |
| 233 | + /// Returns the timestamp of this picture. | |
| 234 | + pub fn timestamp(&self) -> u64 { | |
| 235 | + self.inner.timestamp | |
| 236 | + } | |
| 237 | + | |
| 238 | + /// Returns a reference to the underlying `Surface`. | |
| 239 | + /// | |
| 240 | + /// If you are interested in obtaining the container of the `Surface`, use `as_ref()` instead. | |
| 241 | + /// This is a convenience method to avoid having to call `borrow()` every time the surface is | |
| 242 | + /// needed. | |
| 243 | + pub fn surface<D: SurfaceMemoryDescriptor>(&self) -> &Surface<D> | |
| 244 | + where | |
| 245 | + T: Borrow<Surface<D>>, | |
| 246 | + { | |
| 247 | + self.as_ref().borrow() | |
| 248 | + } | |
| 249 | +} | |
| 250 | + | |
| 251 | +impl<S: PictureReclaimableSurface, T> Picture<S, T> { | |
| 252 | + /// Reclaim ownership of the Surface this picture has been created from, consuming the picture | |
| 253 | + /// in the process. Useful if the Surface is part of a pool. | |
| 254 | + /// | |
| 255 | + /// This will fail and return the passed object if there are more than one reference to the | |
| 256 | + /// underlying surface. | |
| 257 | + pub fn take_surface(self) -> Result<T, Self> { | |
| 258 | + let inner = self.inner; | |
| 259 | + match Rc::try_unwrap(inner.surface) { | |
| 260 | + Ok(surface) => Ok(surface), | |
| 261 | + Err(surface) => Err(Self { | |
| 262 | + inner: Box::new(PictureInner { | |
| 263 | + surface, | |
| 264 | + context: inner.context, | |
| 265 | + buffers: inner.buffers, | |
| 266 | + timestamp: inner.timestamp, | |
| 267 | + }), | |
| 268 | + phantom: PhantomData, | |
| 269 | + }), | |
| 270 | + } | |
| 271 | + } | |
| 272 | + | |
| 273 | + /// Create a new derived image from this `Picture` using `vaDeriveImage`. | |
| 274 | + /// | |
| 275 | + /// Derived images are a direct view (i.e. without any copy) on the buffer content of the | |
| 276 | + /// `Picture`. On the other hand, not all `Pictures` can be derived. | |
| 277 | + pub fn derive_image<'a, D: SurfaceMemoryDescriptor + 'a>( | |
| 278 | + &'a self, | |
| 279 | + visible_rect: (u32, u32), | |
| 280 | + ) -> Result<Image<'a>, VaError> | |
| 281 | + where | |
| 282 | + T: Borrow<Surface<D>>, | |
| 283 | + { | |
| 284 | + Image::derive_from(self.surface(), visible_rect) | |
| 285 | + } | |
| 286 | + | |
| 287 | + /// Create new image from the `Picture` using `vaCreateImage` and `vaGetImage`. | |
| 288 | + /// | |
| 289 | + /// The image will contain a copy of the `Picture` in the desired `format` and `coded_resolution`. | |
| 290 | + pub fn create_image<'a, D: SurfaceMemoryDescriptor + 'a>( | |
| 291 | + &'a self, | |
| 292 | + format: bindings::VAImageFormat, | |
| 293 | + coded_resolution: (u32, u32), | |
| 294 | + visible_rect: (u32, u32), | |
| 295 | + ) -> Result<Image<'a>, VaError> | |
| 296 | + where | |
| 297 | + T: Borrow<Surface<D>>, | |
| 298 | + { | |
| 299 | + Image::create_from(self.surface(), format, coded_resolution, visible_rect) | |
| 300 | + } | |
| 301 | +} | |
| 302 | + | |
| 303 | +impl<S: PictureState, T> AsRef<T> for Picture<S, T> { | |
| 304 | + fn as_ref(&self) -> &T { | |
| 305 | + (*self.inner.surface).borrow() | |
| 306 | + } | |
| 307 | +} |
shims/cros-libva/src/surface.rsadded+452 -0
| @@ -0,0 +1,452 @@ | ||
| 1 | +// Copyright 2022 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 | +use std::any::Any; | |
| 6 | +use std::os::fd::FromRawFd; | |
| 7 | +use std::os::fd::OwnedFd; | |
| 8 | +use std::os::raw::c_void; | |
| 9 | +use std::rc::Rc; | |
| 10 | + | |
| 11 | +use crate::bindings; | |
| 12 | +use crate::display::Display; | |
| 13 | +use crate::va_check; | |
| 14 | +use crate::UsageHint; | |
| 15 | +use crate::VASurfaceID; | |
| 16 | +use crate::VaError; | |
| 17 | + | |
| 18 | +/// Trait describing a memory backing for surfaces. | |
| 19 | +/// | |
| 20 | +/// Using external memory for backing a VA surface is done in two steps: | |
| 21 | +/// | |
| 22 | +/// 1. Build the descriptor specific to the memory type we want to use, | |
| 23 | +/// 2. Mention this descriptor as an attribute to be passed to `vaDeriveImage`. | |
| 24 | +/// | |
| 25 | +/// This trait allows to do that in a as-safe-as-possible way, by adding the required attributes | |
| 26 | +/// and returning a heap-allocated object containing the data pointed to by the attributes. That | |
| 27 | +/// way, the caller can keep that object alive until `vaCreateSurfaces` has returned. | |
| 28 | +pub trait SurfaceMemoryDescriptor { | |
| 29 | + /// Add the required attributes to `attr` in order to attach the memory of this descriptor to | |
| 30 | + /// the surface when it is created. | |
| 31 | + /// | |
| 32 | + /// The returned object, if any, is the descriptor pointed to by the attributes. The caller | |
| 33 | + /// must keep it around and unmoved until `vaCreateSurfaces` has returned. | |
| 34 | + fn add_attrs(&mut self, attrs: &mut Vec<bindings::VASurfaceAttrib>) -> Option<Box<dyn Any>>; | |
| 35 | +} | |
| 36 | + | |
| 37 | +/// VA memory types, aka `VA_SURFACE_ATTRIB_MEM_TYPE_*`. | |
| 38 | +#[repr(u32)] | |
| 39 | +pub enum MemoryType { | |
| 40 | + Va = bindings::VA_SURFACE_ATTRIB_MEM_TYPE_VA, | |
| 41 | + V4L2 = bindings::VA_SURFACE_ATTRIB_MEM_TYPE_V4L2, | |
| 42 | + UserPtr = bindings::VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR, | |
| 43 | + DrmPrime2 = bindings::VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2, | |
| 44 | +} | |
| 45 | + | |
| 46 | +/// Used when we want the VA driver to allocate surface memory for us. In this case we don't need | |
| 47 | +/// to add any specific attribute for surface creation. | |
| 48 | +impl SurfaceMemoryDescriptor for () { | |
| 49 | + fn add_attrs(&mut self, _: &mut Vec<bindings::VASurfaceAttrib>) -> Option<Box<dyn Any>> { | |
| 50 | + None | |
| 51 | + } | |
| 52 | +} | |
| 53 | + | |
| 54 | +/// Sealed trait pattern to avoid reimplementation of our local traits. | |
| 55 | +mod private { | |
| 56 | + pub trait Sealed {} | |
| 57 | +} | |
| 58 | + | |
| 59 | +/// Trait for types that can be used as a `VASurfaceAttribExternalBufferDescriptor`. | |
| 60 | +pub trait SurfaceExternalDescriptor: private::Sealed {} | |
| 61 | +impl private::Sealed for bindings::VASurfaceAttribExternalBuffers {} | |
| 62 | +impl SurfaceExternalDescriptor for bindings::VASurfaceAttribExternalBuffers {} | |
| 63 | +impl private::Sealed for bindings::VADRMPRIMESurfaceDescriptor {} | |
| 64 | +impl SurfaceExternalDescriptor for bindings::VADRMPRIMESurfaceDescriptor {} | |
| 65 | + | |
| 66 | +/// Trait allowing to import an external memory source to use with a surface by setting the | |
| 67 | +/// `VASurfaceAttribMemoryType` and `VASurfaceAttribExternalBuffers` attributes. | |
| 68 | +pub trait ExternalBufferDescriptor { | |
| 69 | + /// Memory type to set for `VASurfaceAttribMemoryType`. | |
| 70 | + const MEMORY_TYPE: MemoryType; | |
| 71 | + /// Type of the descriptor to be set with `VASurfaceAttribExternalBuffers`. | |
| 72 | + type DescriptorAttribute: SurfaceExternalDescriptor; | |
| 73 | + | |
| 74 | + /// Returns the `Self::DescriptorAttribute` instance allowing this memory to be imported | |
| 75 | + /// into VAAPI. | |
| 76 | + fn va_surface_attribute(&mut self) -> Self::DescriptorAttribute; | |
| 77 | +} | |
| 78 | + | |
| 79 | +impl<T> SurfaceMemoryDescriptor for T | |
| 80 | +where | |
| 81 | + T: ExternalBufferDescriptor, | |
| 82 | + <T as ExternalBufferDescriptor>::DescriptorAttribute: 'static, | |
| 83 | +{ | |
| 84 | + fn add_attrs(&mut self, attrs: &mut Vec<bindings::VASurfaceAttrib>) -> Option<Box<dyn Any>> { | |
| 85 | + let mut desc = Box::new(self.va_surface_attribute()); | |
| 86 | + | |
| 87 | + attrs.push(bindings::VASurfaceAttrib::new_memory_type( | |
| 88 | + Self::MEMORY_TYPE, | |
| 89 | + )); | |
| 90 | + attrs.push(bindings::VASurfaceAttrib::new_buffer_descriptor( | |
| 91 | + desc.as_mut(), | |
| 92 | + )); | |
| 93 | + | |
| 94 | + Some(desc) | |
| 95 | + } | |
| 96 | +} | |
| 97 | + | |
| 98 | +/// Decode error type aka `VADecodeErrorType` | |
| 99 | +#[repr(u32)] | |
| 100 | +#[derive(Debug)] | |
| 101 | +pub enum DecodeErrorType { | |
| 102 | + SliceMissing = bindings::VADecodeErrorType::VADecodeSliceMissing, | |
| 103 | + MBError = bindings::VADecodeErrorType::VADecodeMBError, | |
| 104 | + #[cfg(libva_1_20_or_higher)] | |
| 105 | + Reset = bindings::VADecodeErrorType::VADecodeReset, | |
| 106 | +} | |
| 107 | + | |
| 108 | +/// Decode error details extracted from `VASurfaceDecodeMBErrors`, result of vaQuerySurfaceError. | |
| 109 | +#[derive(Debug)] | |
| 110 | +pub struct SurfaceDecodeMBError { | |
| 111 | + /// Start mb address with errors | |
| 112 | + pub start_mb: u32, | |
| 113 | + | |
| 114 | + /// End mb address with errors | |
| 115 | + pub end_mb: u32, | |
| 116 | + | |
| 117 | + pub decode_error_type: DecodeErrorType, | |
| 118 | + | |
| 119 | + /// Number of mbs with errors | |
| 120 | + pub num_mb: u32, | |
| 121 | +} | |
| 122 | + | |
| 123 | +/// An owned VA surface that is tied to a particular `Display`. | |
| 124 | +pub struct Surface<D: SurfaceMemoryDescriptor> { | |
| 125 | + display: Rc<Display>, | |
| 126 | + id: bindings::VASurfaceID, | |
| 127 | + descriptor: D, | |
| 128 | + width: u32, | |
| 129 | + height: u32, | |
| 130 | +} | |
| 131 | + | |
| 132 | +impl From<i32> for bindings::VAGenericValue { | |
| 133 | + fn from(i: i32) -> Self { | |
| 134 | + Self { | |
| 135 | + type_: bindings::VAGenericValueType::VAGenericValueTypeInteger, | |
| 136 | + value: bindings::_VAGenericValue__bindgen_ty_1 { i }, | |
| 137 | + } | |
| 138 | + } | |
| 139 | +} | |
| 140 | + | |
| 141 | +impl From<f32> for bindings::VAGenericValue { | |
| 142 | + fn from(f: f32) -> Self { | |
| 143 | + Self { | |
| 144 | + type_: bindings::VAGenericValueType::VAGenericValueTypeFloat, | |
| 145 | + value: bindings::_VAGenericValue__bindgen_ty_1 { f }, | |
| 146 | + } | |
| 147 | + } | |
| 148 | +} | |
| 149 | + | |
| 150 | +impl From<*mut c_void> for bindings::VAGenericValue { | |
| 151 | + fn from(p: *mut c_void) -> Self { | |
| 152 | + Self { | |
| 153 | + type_: bindings::VAGenericValueType::VAGenericValueTypePointer, | |
| 154 | + value: bindings::_VAGenericValue__bindgen_ty_1 { p }, | |
| 155 | + } | |
| 156 | + } | |
| 157 | +} | |
| 158 | + | |
| 159 | +/// Helpers to build valid `VASurfaceAttrib`s. | |
| 160 | +impl bindings::VASurfaceAttrib { | |
| 161 | + pub fn new_pixel_format(fourcc: u32) -> Self { | |
| 162 | + Self { | |
| 163 | + type_: bindings::VASurfaceAttribType::VASurfaceAttribPixelFormat, | |
| 164 | + flags: bindings::VA_SURFACE_ATTRIB_SETTABLE, | |
| 165 | + value: bindings::VAGenericValue::from(fourcc as i32), | |
| 166 | + } | |
| 167 | + } | |
| 168 | + | |
| 169 | + pub fn new_usage_hint(usage_hint: UsageHint) -> Self { | |
| 170 | + Self { | |
| 171 | + type_: bindings::VASurfaceAttribType::VASurfaceAttribUsageHint, | |
| 172 | + flags: bindings::VA_SURFACE_ATTRIB_SETTABLE, | |
| 173 | + value: bindings::VAGenericValue::from(usage_hint.bits() as i32), | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + pub fn new_memory_type(mem_type: MemoryType) -> Self { | |
| 178 | + Self { | |
| 179 | + type_: bindings::VASurfaceAttribType::VASurfaceAttribMemoryType, | |
| 180 | + flags: bindings::VA_SURFACE_ATTRIB_SETTABLE, | |
| 181 | + value: bindings::VAGenericValue::from(mem_type as i32), | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + pub fn new_buffer_descriptor<T: SurfaceExternalDescriptor>(desc: &mut T) -> Self { | |
| 186 | + Self { | |
| 187 | + type_: bindings::VASurfaceAttribType::VASurfaceAttribExternalBufferDescriptor, | |
| 188 | + flags: bindings::VA_SURFACE_ATTRIB_SETTABLE, | |
| 189 | + value: bindings::VAGenericValue::from(desc as *mut _ as *mut c_void), | |
| 190 | + } | |
| 191 | + } | |
| 192 | +} | |
| 193 | + | |
| 194 | +impl<D: SurfaceMemoryDescriptor> Surface<D> { | |
| 195 | + /// Create `Surfaces` by wrapping around a `vaCreateSurfaces` call. This is just a helper for | |
| 196 | + /// [`Display::create_surfaces`]. | |
| 197 | + pub(crate) fn new( | |
| 198 | + display: Rc<Display>, | |
| 199 | + rt_format: u32, | |
| 200 | + va_fourcc: Option<u32>, | |
| 201 | + width: u32, | |
| 202 | + height: u32, | |
| 203 | + usage_hint: Option<UsageHint>, | |
| 204 | + descriptors: Vec<D>, | |
| 205 | + ) -> Result<Vec<Self>, VaError> { | |
| 206 | + let mut surfaces = vec![]; | |
| 207 | + | |
| 208 | + for mut descriptor in descriptors { | |
| 209 | + let mut attrs = vec![]; | |
| 210 | + | |
| 211 | + if let Some(usage_hint) = usage_hint { | |
| 212 | + attrs.push(bindings::VASurfaceAttrib::new_usage_hint(usage_hint)); | |
| 213 | + } | |
| 214 | + | |
| 215 | + if let Some(fourcc) = va_fourcc { | |
| 216 | + attrs.push(bindings::VASurfaceAttrib::new_pixel_format(fourcc)); | |
| 217 | + } | |
| 218 | + | |
| 219 | + // Just to be kept alive until we call `vaCreateSurfaces`... | |
| 220 | + let mut _va_desc = descriptor.add_attrs(&mut attrs); | |
| 221 | + let mut surface_id: VASurfaceID = 0; | |
| 222 | + | |
| 223 | + // Safe because `self` represents a valid VADisplay. The `surface` and `attrs` vectors are | |
| 224 | + // properly initialized and valid sizes are passed to the C function, so it is impossible to | |
| 225 | + // write past the end of their storage by mistake. | |
| 226 | + // | |
| 227 | + // Also all the pointers in `attrs` are pointing to valid objects that haven't been | |
| 228 | + // moved or destroyed. | |
| 229 | + match va_check(unsafe { | |
| 230 | + bindings::vaCreateSurfaces( | |
| 231 | + display.handle(), | |
| 232 | + rt_format, | |
| 233 | + width, | |
| 234 | + height, | |
| 235 | + &mut surface_id, | |
| 236 | + 1, | |
| 237 | + attrs.as_mut_ptr(), | |
| 238 | + attrs.len() as u32, | |
| 239 | + ) | |
| 240 | + }) { | |
| 241 | + Ok(()) => surfaces.push(Self { | |
| 242 | + display: Rc::clone(&display), | |
| 243 | + id: surface_id, | |
| 244 | + descriptor, | |
| 245 | + width, | |
| 246 | + height, | |
| 247 | + }), | |
| 248 | + Err(e) => return Err(e), | |
| 249 | + } | |
| 250 | + } | |
| 251 | + | |
| 252 | + Ok(surfaces) | |
| 253 | + } | |
| 254 | + | |
| 255 | + pub(crate) fn display(&self) -> &Rc<Display> { | |
| 256 | + &self.display | |
| 257 | + } | |
| 258 | + | |
| 259 | + /// Wrapper around `vaSyncSurface` that blocks until all pending operations on the render | |
| 260 | + /// target have been completed. | |
| 261 | + /// | |
| 262 | + /// Upon return it | |
| 263 | + /// is safe to use the render target for a different picture. | |
| 264 | + pub fn sync(&self) -> Result<(), VaError> { | |
| 265 | + // Safe because `self` represents a valid VASurface. | |
| 266 | + va_check(unsafe { bindings::vaSyncSurface(self.display.handle(), self.id) }) | |
| 267 | + } | |
| 268 | + | |
| 269 | + /// Convenience function to return a VASurfaceID vector. Useful to interface with the C API | |
| 270 | + /// where a surface array might be needed. | |
| 271 | + pub fn as_id_vec(surfaces: &[Self]) -> Vec<bindings::VASurfaceID> { | |
| 272 | + surfaces.iter().map(|surface| surface.id).collect() | |
| 273 | + } | |
| 274 | + | |
| 275 | + /// Wrapper over `vaQuerySurfaceStatus` to find out any pending ops on the render target. | |
| 276 | + pub fn query_status(&self) -> Result<bindings::VASurfaceStatus::Type, VaError> { | |
| 277 | + let mut status: bindings::VASurfaceStatus::Type = 0; | |
| 278 | + // Safe because `self` represents a valid VASurface. | |
| 279 | + va_check(unsafe { | |
| 280 | + bindings::vaQuerySurfaceStatus(self.display.handle(), self.id, &mut status) | |
| 281 | + })?; | |
| 282 | + | |
| 283 | + Ok(status) | |
| 284 | + } | |
| 285 | + | |
| 286 | + pub fn query_error(&self) -> Result<Vec<SurfaceDecodeMBError>, VaError> { | |
| 287 | + let mut raw: *const bindings::VASurfaceDecodeMBErrors = std::ptr::null(); | |
| 288 | + | |
| 289 | + // Safe because `self` represents a valid VASurface. | |
| 290 | + va_check(unsafe { | |
| 291 | + bindings::vaQuerySurfaceError( | |
| 292 | + self.display.handle(), | |
| 293 | + self.id, | |
| 294 | + bindings::VA_STATUS_ERROR_DECODING_ERROR as i32, | |
| 295 | + (&mut raw) as *mut _ as *mut _, | |
| 296 | + ) | |
| 297 | + })?; | |
| 298 | + | |
| 299 | + let mut errors = vec![]; | |
| 300 | + | |
| 301 | + while !raw.is_null() { | |
| 302 | + // Safe because raw is a valid pointer | |
| 303 | + let error = unsafe { *raw }; | |
| 304 | + if error.status == -1 { | |
| 305 | + break; | |
| 306 | + } | |
| 307 | + | |
| 308 | + let type_ = match error.decode_error_type { | |
| 309 | + bindings::VADecodeErrorType::VADecodeSliceMissing => DecodeErrorType::SliceMissing, | |
| 310 | + bindings::VADecodeErrorType::VADecodeMBError => DecodeErrorType::MBError, | |
| 311 | + #[cfg(libva_1_20_or_higher)] | |
| 312 | + bindings::VADecodeErrorType::VADecodeReset => DecodeErrorType::Reset, | |
| 313 | + _ => { | |
| 314 | + log::warn!( | |
| 315 | + "Unrecognized `decode_error_type` value ({})", | |
| 316 | + error.decode_error_type | |
| 317 | + ); | |
| 318 | + | |
| 319 | + // Safe because status != -1 | |
| 320 | + raw = unsafe { raw.offset(1) }; | |
| 321 | + continue; | |
| 322 | + } | |
| 323 | + }; | |
| 324 | + | |
| 325 | + errors.push(SurfaceDecodeMBError { | |
| 326 | + start_mb: error.start_mb, | |
| 327 | + end_mb: error.end_mb, | |
| 328 | + decode_error_type: type_, | |
| 329 | + num_mb: error.num_mb, | |
| 330 | + }); | |
| 331 | + | |
| 332 | + // Safe because status != -1 | |
| 333 | + raw = unsafe { raw.offset(1) }; | |
| 334 | + } | |
| 335 | + | |
| 336 | + Ok(errors) | |
| 337 | + } | |
| 338 | + | |
| 339 | + /// Returns the ID of this surface. | |
| 340 | + pub fn id(&self) -> bindings::VASurfaceID { | |
| 341 | + self.id | |
| 342 | + } | |
| 343 | + | |
| 344 | + /// Returns the dimensions of this surface. | |
| 345 | + pub fn size(&self) -> (u32, u32) { | |
| 346 | + (self.width, self.height) | |
| 347 | + } | |
| 348 | + | |
| 349 | + /// Returns a PRIME descriptor for this surface. | |
| 350 | + pub fn export_prime(&self) -> Result<DrmPrimeSurfaceDescriptor, VaError> { | |
| 351 | + let mut desc: bindings::VADRMPRIMESurfaceDescriptor = Default::default(); | |
| 352 | + | |
| 353 | + va_check(unsafe { | |
| 354 | + bindings::vaExportSurfaceHandle( | |
| 355 | + self.display.handle(), | |
| 356 | + self.id(), | |
| 357 | + bindings::VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2, | |
| 358 | + bindings::VA_EXPORT_SURFACE_READ_ONLY | bindings::VA_EXPORT_SURFACE_COMPOSED_LAYERS, | |
| 359 | + &mut desc as *mut _ as *mut c_void, | |
| 360 | + ) | |
| 361 | + })?; | |
| 362 | + | |
| 363 | + // We do not use a `From<VADRMPRIMESurfaceDescriptor>` implementation as this would allow | |
| 364 | + // to create "safe" descriptors outside of this method and thus from made up values, | |
| 365 | + // violating the safety guarantee that our FDs are legit. | |
| 366 | + | |
| 367 | + let objects = (0..desc.num_objects as usize) | |
| 368 | + // Make sure we don't go out of bounds. | |
| 369 | + .take(4) | |
| 370 | + .map(|i| desc.objects[i]) | |
| 371 | + .map(|o| { | |
| 372 | + DrmPrimeSurfaceDescriptorObject { | |
| 373 | + // Safe because `o.fd` is a valid file descriptor returned by | |
| 374 | + // `vaExportSurfaceHandle`. | |
| 375 | + fd: unsafe { OwnedFd::from_raw_fd(o.fd) }, | |
| 376 | + size: o.size, | |
| 377 | + drm_format_modifier: o.drm_format_modifier, | |
| 378 | + } | |
| 379 | + }) | |
| 380 | + .collect(); | |
| 381 | + | |
| 382 | + let layers = (0..desc.num_layers as usize) | |
| 383 | + // Make sure we don't go out of bounds. | |
| 384 | + .take(4) | |
| 385 | + .map(|i| desc.layers[i]) | |
| 386 | + .map(|l| DrmPrimeSurfaceDescriptorLayer { | |
| 387 | + drm_format: l.drm_format, | |
| 388 | + num_planes: l.num_planes, | |
| 389 | + object_index: [ | |
| 390 | + l.object_index[0] as u8, | |
| 391 | + l.object_index[1] as u8, | |
| 392 | + l.object_index[2] as u8, | |
| 393 | + l.object_index[3] as u8, | |
| 394 | + ], | |
| 395 | + offset: l.offset, | |
| 396 | + pitch: l.pitch, | |
| 397 | + }) | |
| 398 | + .collect(); | |
| 399 | + | |
| 400 | + Ok(DrmPrimeSurfaceDescriptor { | |
| 401 | + fourcc: desc.fourcc, | |
| 402 | + width: desc.width, | |
| 403 | + height: desc.height, | |
| 404 | + objects, | |
| 405 | + layers, | |
| 406 | + }) | |
| 407 | + } | |
| 408 | +} | |
| 409 | + | |
| 410 | +impl<D: SurfaceMemoryDescriptor> AsRef<D> for Surface<D> { | |
| 411 | + fn as_ref(&self) -> &D { | |
| 412 | + &self.descriptor | |
| 413 | + } | |
| 414 | +} | |
| 415 | + | |
| 416 | +impl<D: SurfaceMemoryDescriptor> AsMut<D> for Surface<D> { | |
| 417 | + fn as_mut(&mut self) -> &mut D { | |
| 418 | + &mut self.descriptor | |
| 419 | + } | |
| 420 | +} | |
| 421 | + | |
| 422 | +impl<D: SurfaceMemoryDescriptor> Drop for Surface<D> { | |
| 423 | + fn drop(&mut self) { | |
| 424 | + // Safe because `self` represents a valid VASurface. | |
| 425 | + unsafe { bindings::vaDestroySurfaces(self.display.handle(), &mut self.id, 1) }; | |
| 426 | + } | |
| 427 | +} | |
| 428 | + | |
| 429 | +/// Safe wrapper for the `object` member of `VADRMPRIMESurfaceDescriptor`. | |
| 430 | +pub struct DrmPrimeSurfaceDescriptorObject { | |
| 431 | + pub fd: OwnedFd, | |
| 432 | + pub size: u32, | |
| 433 | + pub drm_format_modifier: u64, | |
| 434 | +} | |
| 435 | + | |
| 436 | +/// Safe wrapper for the `layers` member of `VADRMPRIMESurfaceDescriptor`. | |
| 437 | +pub struct DrmPrimeSurfaceDescriptorLayer { | |
| 438 | + pub drm_format: u32, | |
| 439 | + pub num_planes: u32, | |
| 440 | + pub object_index: [u8; 4], | |
| 441 | + pub offset: [u32; 4], | |
| 442 | + pub pitch: [u32; 4], | |
| 443 | +} | |
| 444 | + | |
| 445 | +/// Safe wrapper around `VADRMPRIMESurfaceDescriptor`. | |
| 446 | +pub struct DrmPrimeSurfaceDescriptor { | |
| 447 | + pub fourcc: u32, | |
| 448 | + pub width: u32, | |
| 449 | + pub height: u32, | |
| 450 | + pub objects: Vec<DrmPrimeSurfaceDescriptorObject>, | |
| 451 | + pub layers: Vec<DrmPrimeSurfaceDescriptorLayer>, | |
| 452 | +} |
shims/cros-libva/src/test_frame.nv12added+0 -0
Binary file changed
shims/cros-libva/src/usage_hint.rsadded+26 -0
| @@ -0,0 +1,26 @@ | ||
| 1 | +// Copyright 2022 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 | +use bitflags::bitflags; | |
| 6 | + | |
| 7 | +use crate::bindings; | |
| 8 | + | |
| 9 | +bitflags! { | |
| 10 | + /// Gives the driver a hint of intended usage to optimize allocation (e.g. tiling). | |
| 11 | + #[derive(Debug, Clone, Copy)] | |
| 12 | + pub struct UsageHint: u32 { | |
| 13 | + /// Surface used by video decoder. | |
| 14 | + const USAGE_HINT_DECODER = bindings::VA_SURFACE_ATTRIB_USAGE_HINT_DECODER; | |
| 15 | + /// Surface used by video encoder. | |
| 16 | + const USAGE_HINT_ENCODER = bindings::VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER; | |
| 17 | + /// Surface read by video post-processing. | |
| 18 | + const USAGE_HINT_VPP_READ = bindings::VA_SURFACE_ATTRIB_USAGE_HINT_VPP_READ; | |
| 19 | + /// Surface written by video post-processing. | |
| 20 | + const USAGE_HINT_VPP_WRITE = bindings::VA_SURFACE_ATTRIB_USAGE_HINT_VPP_WRITE; | |
| 21 | + /// Surface used for display. | |
| 22 | + const USAGE_HINT_DISPLAY = bindings::VA_SURFACE_ATTRIB_USAGE_HINT_DISPLAY; | |
| 23 | + /// Surface used for export to third-party APIs, e.g. via `vaExportSurfaceHandle()`. | |
| 24 | + const USAGE_HINT_EXPORT = bindings::VA_SURFACE_ATTRIB_USAGE_HINT_EXPORT; | |
| 25 | + } | |
| 26 | +} |