diff --git a/Cargo.lock b/Cargo.lock index 14b61940..3979e7cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -308,7 +308,6 @@ version = "0.0.13" dependencies = [ "bindgen", "bitflags 2.13.1", - "crc32fast", "log", "pkg-config", "regex", diff --git a/shims/cros-libva/Android.bp b/shims/cros-libva/Android.bp deleted file mode 100644 index e1ae101c..00000000 --- a/shims/cros-libva/Android.bp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2024 The ChromiumOS Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This file is generated by cargo_embargo. -// Do not modify this file because the changes will be overridden on upgrade. - -package { - default_applicable_licenses: ["external_rust_cros-libva_license"], -} - -soong_config_module_type_import { - from: "system/cros-codecs/Android.bp", - module_types: [ - "rust_defaults_cros_codecs_protected_content", - ], -} - -rust_defaults_cros_codecs_protected_content { - name: "cros_libva_protected_content_rust_library_defaults", - soong_config_variables: { - intel_protected_content: { - features: ["intel-protected-content-headers"], - }, - }, -} - -rust_library { - name: "libcros_libva", - crate_name: "cros_libva", - cargo_env_compat: true, - cargo_pkg_version: "0.0.8", - crate_root: "src/lib.rs", - edition: "2021", - defaults: ["cros_libva_protected_content_rust_library_defaults"], - rustlibs: [ - "libbitflags", - "liblog_rust", - "libthiserror", - ], - apex_available: [ - "//apex_available:platform", - "//apex_available:anyapex", - ], - - cfgs: [ - "libva_1_21_or_higher", - "libva_1_20_or_higher", - "libva_1_19_or_higher", - "libva_1_16_or_higher", - ], - - vendor: true, - enabled: false, - arch: { - x86_64: { - enabled: true, - // Bindgen-generated bindings of our local libva headers. - srcs: [":libcros_libva_bindgen"], - shared_libs: ["libva"], - }, - }, -} diff --git a/shims/cros-libva/Cargo.toml b/shims/cros-libva/Cargo.toml index c2d9e978..84d4fb65 100644 --- a/shims/cros-libva/Cargo.toml +++ b/shims/cros-libva/Cargo.toml @@ -21,6 +21,3 @@ log = { version = "0", features = ["release_max_level_debug"] } bindgen = "0.70.1" pkg-config = "0.3.31" regex = "1.11.1" - -[dev-dependencies] -crc32fast = "1.2.1" diff --git a/shims/cros-libva/src/buffer.rs b/shims/cros-libva/src/buffer.rs index c5f2686d..b6a62dc5 100644 --- a/shims/cros-libva/src/buffer.rs +++ b/shims/cros-libva/src/buffer.rs @@ -5,25 +5,17 @@ //! Wrappers and helpers around `VABuffer`s. mod av1; -mod enc_jpeg; mod enc_misc; mod h264; mod hevc; -mod jpeg_baseline; -mod mpeg2; mod proc_pipeline; -mod vp8; mod vp9; pub use av1::*; -pub use enc_jpeg::*; pub use enc_misc::*; pub use h264::*; pub use hevc::*; -pub use jpeg_baseline::*; -pub use mpeg2::*; pub use proc_pipeline::*; -pub use vp8::*; pub use vp9::*; use std::rc::Rc; @@ -61,14 +53,6 @@ impl Buffer { let (ptr, size) = match type_ { BufferType::PictureParameter(ref mut picture_param) => match picture_param { - PictureParameter::MPEG2(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), - PictureParameter::VP8(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), PictureParameter::VP9(ref mut wrapper) => ( wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), @@ -93,25 +77,9 @@ impl Buffer { wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), ), - PictureParameter::JPEGBaseline(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), - PictureParameter::EncJPEG(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), }, BufferType::SliceParameter(ref mut slice_param) => match slice_param { - SliceParameter::MPEG2(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), - SliceParameter::VP8(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), SliceParameter::VP9(ref mut wrapper) => ( wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), @@ -132,25 +100,9 @@ impl Buffer { wrapper.inner_mut().as_mut_ptr() as *mut std::ffi::c_void, std::mem::size_of::(), ), - SliceParameter::JPEGBaseline(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), - SliceParameter::EncJpeg(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), }, BufferType::IQMatrix(ref mut iq_matrix) => match iq_matrix { - IQMatrix::MPEG2(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), - IQMatrix::VP8(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), IQMatrix::H264(ref mut wrapper) => ( wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), @@ -159,23 +111,9 @@ impl Buffer { wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), ), - IQMatrix::JPEGBaseline(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), }, - BufferType::HuffmanTable(ref mut huffman_table) => match huffman_table { - HuffmanTable::JPEGBaseline(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), - }, - BufferType::Probability(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), BufferType::SliceData(ref mut data) => { (data.as_mut_ptr() as *mut std::ffi::c_void, data.len()) @@ -190,10 +128,6 @@ impl Buffer { wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), ), - EncSequenceParameter::VP8(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), EncSequenceParameter::VP9(ref mut wrapper) => ( wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), @@ -213,10 +147,6 @@ impl Buffer { wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), ), - EncPictureParameter::VP8(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), EncPictureParameter::VP9(ref mut wrapper) => ( wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), @@ -289,12 +219,6 @@ impl Buffer { proc_pipeline_param.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(proc_pipeline_param.inner_mut()), ), - BufferType::QMatrix(ref mut q_matrix) => match q_matrix { - QMatrix::JPEG(ref mut wrapper) => ( - wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, - std::mem::size_of_val(wrapper.inner_mut()), - ), - }, BufferType::EncPackedHeaderParameter(ref mut wrapper) => ( wrapper.inner_mut() as *mut _ as *mut std::ffi::c_void, std::mem::size_of_val(wrapper.inner_mut()), @@ -419,34 +343,28 @@ impl Drop for Buffer { /// Abstraction over `VABufferType`s. pub enum BufferType { - /// Abstraction over `VAPictureParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, JPEGBaseline. + /// Abstraction over `VAPictureParameterBufferType`. Needed for VP9, H264. PictureParameter(PictureParameter), - /// Abstraction over `VASliceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, JPEGBaseline. + /// Abstraction over `VASliceParameterBufferType`. Needed for VP9, H264. SliceParameter(SliceParameter), - /// Abstraction over `VAIQMatrixBufferType`. Needed for VP8, H264, JPEGBaseline. + /// Abstraction over `VAIQMatrixBufferType`. Needed for H264. IQMatrix(IQMatrix), - /// Abstraction over `HuffmanTableBufferType`. Needed for JPEGBaseline. - HuffmanTable(HuffmanTable), - /// Abstraction over `VAProbabilityDataBufferType`. Needed for VP8. - Probability(vp8::ProbabilityDataBufferVP8), /// Abstraction over `VASliceDataBufferType`. Needed for VP9, H264. SliceData(Vec), - /// Abstraction over `VAEncSequenceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. + /// Abstraction over `VAEncSequenceParameterBufferType`. Needed for VP9, H264, HEVC. EncSequenceParameter(EncSequenceParameter), - /// Abstraction over `VAEncPictureParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. + /// Abstraction over `VAEncPictureParameterBufferType`. Needed for VP9, H264, HEVC. EncPictureParameter(EncPictureParameter), - /// Abstraction over `VAEncSliceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. + /// Abstraction over `VAEncSliceParameterBufferType`. Needed for VP9, H264, HEVC. EncSliceParameter(EncSliceParameter), /// Abstraction over `VAEncMacroblockMapBufferType`. Needed for H264. EncMacroblockParameterBuffer(EncMacroblockParameterBuffer), - /// Abstraction over `VAEncCodedBufferType`. Needed for MPEG2, VP8, VP9, H264, HEVC. + /// Abstraction over `VAEncCodedBufferType`. Needed for VP9, H264, HEVC. EncCodedBuffer(usize), /// Abstraction over `VAEncMiscParameterBuffer`. EncMiscParameter(EncMiscParameter), /// Abstraction over `VAProcPipelineParameterBuffer`. ProcPipelineParameter(proc_pipeline::ProcPipelineParameterBuffer), - /// Abstraction over `VAQMatrixBufferType`. - QMatrix(QMatrix), /// Abstraction over `VAEncPackedHeaderParameterBufferType`. EncPackedHeaderParameter(EncPackedHeaderParameter), /// Abstraction over `VAEncPackedHeaderDataBufferType`. @@ -460,8 +378,6 @@ impl BufferType { BufferType::PictureParameter(_) => bindings::VABufferType::VAPictureParameterBufferType, BufferType::SliceParameter(_) => bindings::VABufferType::VASliceParameterBufferType, BufferType::IQMatrix(_) => bindings::VABufferType::VAIQMatrixBufferType, - BufferType::HuffmanTable(_) => bindings::VABufferType::VAHuffmanTableBufferType, - BufferType::Probability(_) => bindings::VABufferType::VAProbabilityBufferType, BufferType::SliceData { .. } => bindings::VABufferType::VASliceDataBufferType, BufferType::EncSequenceParameter(_) => { @@ -488,7 +404,6 @@ impl BufferType { bindings::VABufferType::VAProcPipelineParameterBufferType } - BufferType::QMatrix(_) => bindings::VABufferType::VAQMatrixBufferType, BufferType::EncPackedHeaderParameter(_) => { bindings::VABufferType::VAEncPackedHeaderParameterBufferType @@ -503,10 +418,6 @@ impl BufferType { /// Abstraction over the `PictureParameterBuffer` types we support. pub enum PictureParameter { - /// Wrapper over VAPictureParameterBufferMPEG2. - MPEG2(mpeg2::PictureParameterBufferMPEG2), - /// Wrapper over VAPictureParameterBufferVP8. - VP8(vp8::PictureParameterBufferVP8), /// Wrapper over VAPictureParameterBufferVP9. VP9(vp9::PictureParameterBufferVP9), /// Wrapper over VAPictureParameterBufferH264. @@ -519,18 +430,10 @@ pub enum PictureParameter { HEVCScc(hevc::PictureParameterBufferHEVCScc), /// Wrapper over VADecPictureParameterBufferAV1 AV1(av1::PictureParameterBufferAV1), - /// Wrapper over VAPictureParameterBufferJPEGBaseline - JPEGBaseline(jpeg_baseline::PictureParameterBufferJPEGBaseline), - /// Wrapper over VAEncPictureParameterBufferJPEG - EncJPEG(enc_jpeg::EncPictureParameterBufferJPEG), } /// Abstraction over the `SliceParameterBuffer` types we support pub enum SliceParameter { - /// Wrapper over VASliceParameterBufferMPEG2 - MPEG2(mpeg2::SliceParameterBufferMPEG2), - /// Wrapper over VASliceParameterBufferVP8 - VP8(vp8::SliceParameterBufferVP8), /// Wrapper over VASliceParameterBufferVP9 VP9(vp9::SliceParameterBufferVP9), /// Wrapper over VASliceParameterBufferH264 @@ -541,37 +444,16 @@ pub enum SliceParameter { HEVCRext(hevc::SliceParameterBufferHEVCRext), /// Wrapper over VASliceParameterBufferAV1 AV1(av1::SliceParameterBufferAV1), - /// Wrapper over VASliceParameterBufferJPEGBaseline - JPEGBaseline(jpeg_baseline::SliceParameterBufferJPEGBaseline), - /// Wrapper over VAEncSliceParameterBufferJPEG - EncJpeg(enc_jpeg::EncSliceParameterBufferJPEG), } /// Abstraction over the `IQMatrixBuffer` types we support. pub enum IQMatrix { - /// Abstraction over `VAIQMatrixBufferMPEG2` - MPEG2(mpeg2::IQMatrixBufferMPEG2), - /// Abstraction over `VAIQMatrixBufferVP8` - VP8(vp8::IQMatrixBufferVP8), /// Abstraction over `VAIQMatrixBufferH264` H264(h264::IQMatrixBufferH264), /// Abstraction over `VAIQMatrixBufferHEVC` HEVC(hevc::IQMatrixBufferHEVC), - /// Abstraction over `VAIQMatrixBufferJPEGBaseline`` - JPEGBaseline(jpeg_baseline::IQMatrixBufferJPEGBaseline), } -/// Abstraction over the `HuffmanTable` types we support. -pub enum HuffmanTable { - /// Abstraction over `VAHuffmanTableBufferJPEGBaseline` - JPEGBaseline(jpeg_baseline::HuffmanTableBufferJPEGBaseline), -} - -/// Abstraction over the `QMatrix` types we support. -pub enum QMatrix { - /// Abstraction over `VAQMatrixBufferJPEG` - JPEG(enc_jpeg::QMatrixBufferJPEG), -} /// Abstraction over the `EncSequenceParameter` types we support. pub enum EncSequenceParameter { @@ -579,8 +461,6 @@ pub enum EncSequenceParameter { H264(h264::EncSequenceParameterBufferH264), /// Abstraction over `VAEncSequenceParameterBufferHEVC` HEVC(hevc::EncSequenceParameterBufferHEVC), - /// Abstraction over `VAEncSequenceParameterBufferVP8` - VP8(vp8::EncSequenceParameterBufferVP8), /// Abstraction over `VAEncSequenceParameterBufferVP9` VP9(vp9::EncSequenceParameterBufferVP9), /// Abstraction over `VAEncSequenceParameterBufferAV1` @@ -593,8 +473,6 @@ pub enum EncPictureParameter { H264(h264::EncPictureParameterBufferH264), /// Abstraction over `VAEncPictureParameterBufferHEVC` HEVC(hevc::EncPictureParameterBufferHEVC), - /// Abstraction over `VAEncPictureParameterBufferVP8` - VP8(vp8::EncPictureParameterBufferVP8), /// Abstraction over `VAEncPictureParameterBufferVP9` VP9(vp9::EncPictureParameterBufferVP9), /// Abstraction over `VAEncPictureParameterBufferAV1` diff --git a/shims/cros-libva/src/buffer/enc_jpeg.rs b/shims/cros-libva/src/buffer/enc_jpeg.rs deleted file mode 100644 index 3b656ed4..00000000 --- a/shims/cros-libva/src/buffer/enc_jpeg.rs +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2025 The ChromiumOS Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -//! Wrappers around JPEG-Encoding `VABuffer` types. - -use crate::bindings; - -/// Wrapper over the `pic_flags` bindgen field in `VAEncPictureParameterBufferJPEG` -pub struct PicFlags(bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1); - -impl PicFlags { - pub fn new( - profile: u32, - progressive: u32, - huffman: u32, - interleaved: u32, - differential: u32, - ) -> Self { - let _bitfield_1 = - bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( - profile, - progressive, - huffman, - interleaved, - differential, - ); - Self(bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1 { - bits: bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1__bindgen_ty_1 { - _bitfield_align_1: Default::default(), - _bitfield_1, - __bindgen_padding_0: Default::default(), - }, - }) - } -} - -/// Wrapper over the `VAEncPictureParameterBufferJPEG` FFI type. -pub struct EncPictureParameterBufferJPEG(Box); - -impl EncPictureParameterBufferJPEG { - /// Creates the wrapper. - pub fn new( - reconstructed_picture: bindings::VASurfaceID, - picture_width: u16, - picture_height: u16, - coded_buf: bindings::VABufferID, - pic_flags: PicFlags, - sample_bit_depth: u8, - num_scan: u8, - num_components: u16, - component_id: [u8; 4usize], - quantiser_table_selector: [u8; 4usize], - quality: u8, - ) -> Self { - Self(Box::new(bindings::VAEncPictureParameterBufferJPEG { - reconstructed_picture, - picture_width, - picture_height, - coded_buf, - pic_flags: pic_flags.0, - sample_bit_depth, - num_scan, - num_components, - component_id, - quantiser_table_selector, - quality, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferJPEG { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VAEncPictureParameterBufferJPEG { - self.0.as_ref() - } -} - -/// Wrapper over the `components` bindgen field in `VAEncSliceParameterBufferJPEG`. -pub struct EncSliceParameterBufferJPEGComponent( - bindings::_VAEncSliceParameterBufferJPEG__bindgen_ty_1, -); - -impl EncSliceParameterBufferJPEGComponent { - /// Creates the bindgen field. - pub fn new(component_selector: u8, dc_table_selector: u8, ac_table_selector: u8) -> Self { - Self(bindings::_VAEncSliceParameterBufferJPEG__bindgen_ty_1 { - component_selector, - dc_table_selector, - ac_table_selector, - }) - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::_VAEncSliceParameterBufferJPEG__bindgen_ty_1 { - &self.0 - } -} - -/// Wrapper over the `VAEncSliceParameterBufferJPEG` FFI type. -pub struct EncSliceParameterBufferJPEG(Box); - -impl EncSliceParameterBufferJPEG { - /// Creates the wrapper. - pub fn new( - restart_interval: u16, - num_components: u16, - components: [EncSliceParameterBufferJPEGComponent; 4usize], - ) -> Self { - Self(Box::new(bindings::VAEncSliceParameterBufferJPEG { - restart_interval, - num_components, - components: components.map(|component| component.0), - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSliceParameterBufferJPEG { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VAEncSliceParameterBufferJPEG { - self.0.as_ref() - } -} - -/// Wrapper over the `VAQMatrixBufferJPEG` FFI type. -pub struct QMatrixBufferJPEG(Box); - -impl QMatrixBufferJPEG { - /// Creates the wrapper. - pub fn new( - load_lum_quantiser_matrix: i32, - load_chroma_quantiser_matrix: i32, - lum_quantiser_matrix: [u8; 64usize], - chroma_quantiser_matrix: [u8; 64usize], - ) -> Self { - Self(Box::new(bindings::VAQMatrixBufferJPEG { - load_lum_quantiser_matrix, - load_chroma_quantiser_matrix, - lum_quantiser_matrix, - chroma_quantiser_matrix, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAQMatrixBufferJPEG { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VAQMatrixBufferJPEG { - self.0.as_ref() - } -} diff --git a/shims/cros-libva/src/buffer/jpeg_baseline.rs b/shims/cros-libva/src/buffer/jpeg_baseline.rs deleted file mode 100644 index 92d962f4..00000000 --- a/shims/cros-libva/src/buffer/jpeg_baseline.rs +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright 2025 The ChromiumOS Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -//! Wrappers around JPEGBaseline `VABuffer` types. - -use crate::bindings; - -/// Wrapper over the `components` bindgen field in `VAPictureParameterBufferJPEGBaseline`. -pub struct PictureParameterBufferJPEGBaselineComponent( - bindings::_VAPictureParameterBufferJPEGBaseline__bindgen_ty_1, -); - -impl PictureParameterBufferJPEGBaselineComponent { - /// Creates the bindgen field. - #[allow(clippy::too_many_arguments)] - pub fn new( - component_id: u8, - h_sampling_factor: u8, - v_sampling_factor: u8, - quantiser_table_selector: u8, - ) -> Self { - Self( - bindings::_VAPictureParameterBufferJPEGBaseline__bindgen_ty_1 { - component_id, - h_sampling_factor, - v_sampling_factor, - quantiser_table_selector, - }, - ) - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferJPEGBaseline__bindgen_ty_1 { - &self.0 - } -} - -/// Wrapper over the `VAPictureParameterBufferJPEGBaseline` FFI type. -pub struct PictureParameterBufferJPEGBaseline(Box); - -impl PictureParameterBufferJPEGBaseline { - /// Creates the wrapper. - pub fn new( - picture_width: u16, - picture_height: u16, - components: [PictureParameterBufferJPEGBaselineComponent; 255usize], - num_components: u8, - color_space: u8, - rotation: u32, - crop_rectangle: bindings::VARectangle, - ) -> Self { - Self(Box::new(bindings::VAPictureParameterBufferJPEGBaseline { - picture_width, - picture_height, - components: components.map(|component| component.0), - num_components, - color_space, - rotation, - crop_rectangle, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferJPEGBaseline { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&mut self) -> &bindings::VAPictureParameterBufferJPEGBaseline { - self.0.as_ref() - } -} - -/// Wrapper over the `components` bindgen field in `VASliceParameterBufferJPEGBaseline`. -pub struct VASliceParameterBufferJPEGBaselineComponent( - bindings::_VASliceParameterBufferJPEGBaseline__bindgen_ty_1, -); - -impl VASliceParameterBufferJPEGBaselineComponent { - /// Creates the bindgen field. - #[allow(clippy::too_many_arguments)] - pub fn new(component_selector: u8, dc_table_selector: u8, ac_table_selector: u8) -> Self { - Self( - bindings::_VASliceParameterBufferJPEGBaseline__bindgen_ty_1 { - component_selector, - dc_table_selector, - ac_table_selector, - }, - ) - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&mut self) -> &bindings::_VASliceParameterBufferJPEGBaseline__bindgen_ty_1 { - &self.0 - } -} - -/// Wrapper over the `VASliceParameterBufferJPEGBaseline` FFI type. -pub struct SliceParameterBufferJPEGBaseline(Box); - -impl SliceParameterBufferJPEGBaseline { - /// Creates the wrapper. - pub fn new( - slice_data_size: u32, - slice_data_offset: u32, - slice_data_flag: u32, - slice_horizontal_position: u32, - slice_vertical_position: u32, - components: [VASliceParameterBufferJPEGBaselineComponent; 4usize], - num_components: u8, - restart_interval: u16, - num_mcus: u32, - ) -> Self { - Self(Box::new(bindings::VASliceParameterBufferJPEGBaseline { - slice_data_size, - slice_data_offset, - slice_data_flag, - slice_horizontal_position, - slice_vertical_position, - components: components.map(|component| component.0), - num_components, - restart_interval, - num_mcus, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferJPEGBaseline { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&mut self) -> &bindings::VASliceParameterBufferJPEGBaseline { - self.0.as_ref() - } -} - -/// Wrapper over the `VAIQMatrixBufferJPEGBaseline` FFI type. -pub struct IQMatrixBufferJPEGBaseline(Box); - -impl IQMatrixBufferJPEGBaseline { - /// Creates the wrapper. - #[allow(clippy::too_many_arguments)] - pub fn new( - load_quantiser_table: [u8; 4usize], - quantiser_table: [[u8; 64usize]; 4usize], - ) -> Self { - Self(Box::new(bindings::VAIQMatrixBufferJPEGBaseline { - load_quantiser_table, - quantiser_table, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferJPEGBaseline { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VAIQMatrixBufferJPEGBaseline { - self.0.as_ref() - } -} - -/// Wrapper over the `huffman_table` bindgen field in `VAHuffmanTableBufferJPEGBaseline`. -pub struct HuffmanTableBufferJPEGBaselineHuffmanTable( - bindings::_VAHuffmanTableBufferJPEGBaseline__bindgen_ty_1, -); - -impl HuffmanTableBufferJPEGBaselineHuffmanTable { - /// Creates the bindgen field. - #[allow(clippy::too_many_arguments)] - pub fn new( - num_dc_codes: [u8; 16usize], - dc_values: [u8; 12usize], - num_ac_codes: [u8; 16usize], - ac_values: [u8; 162usize], - pad: [u8; 2usize], - ) -> Self { - Self(bindings::_VAHuffmanTableBufferJPEGBaseline__bindgen_ty_1 { - num_dc_codes, - dc_values, - num_ac_codes, - ac_values, - pad, - }) - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&mut self) -> &bindings::_VAHuffmanTableBufferJPEGBaseline__bindgen_ty_1 { - &self.0 - } -} - -/// Wrapper over the `VAHuffmanTableBufferJPEGBaseline` FFI type. -pub struct HuffmanTableBufferJPEGBaseline(Box); - -impl HuffmanTableBufferJPEGBaseline { - /// Creates the wrapper. - pub fn new( - load_huffman_table: [u8; 2usize], - huffman_table: [HuffmanTableBufferJPEGBaselineHuffmanTable; 2usize], - ) -> Self { - Self(Box::new(bindings::VAHuffmanTableBufferJPEGBaseline { - load_huffman_table, - huffman_table: huffman_table.map(|component| component.0), - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAHuffmanTableBufferJPEGBaseline { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&mut self) -> &bindings::VAHuffmanTableBufferJPEGBaseline { - self.0.as_ref() - } -} diff --git a/shims/cros-libva/src/buffer/mpeg2.rs b/shims/cros-libva/src/buffer/mpeg2.rs deleted file mode 100644 index 22df3141..00000000 --- a/shims/cros-libva/src/buffer/mpeg2.rs +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2023 The ChromiumOS Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -//! Wrappers around MPEG2 `VABuffer` types. - -use crate::bindings; - -/// Wrapper over the `picture_coding_extension` bindgen field in `VAPictureParameterBufferMPEG2`. -pub struct MPEG2PictureCodingExtension(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1); - -impl MPEG2PictureCodingExtension { - /// Creates the bindgen field. - #[allow(clippy::too_many_arguments)] - pub fn new( - intra_dc_precision: u32, - picture_structure: u32, - top_field_first: u32, - frame_pred_frame_dct: u32, - concealment_motion_vectors: u32, - q_scale_type: u32, - intra_vlc_format: u32, - alternate_scan: u32, - repeat_first_field: u32, - progressive_frame: u32, - is_first_field: u32, - ) -> Self { - let _bitfield_1 = - bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( - intra_dc_precision, - picture_structure, - top_field_first, - frame_pred_frame_dct, - concealment_motion_vectors, - q_scale_type, - intra_vlc_format, - alternate_scan, - repeat_first_field, - progressive_frame, - is_first_field, - ); - - Self(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 { - bits: bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1__bindgen_ty_1 { - _bitfield_align_1: Default::default(), - _bitfield_1, - __bindgen_padding_0: Default::default(), - }, - }) - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 { - &self.0 - } -} - -/// Wrapper over the `PictureParameterBufferMPEG2` FFI type. -pub struct PictureParameterBufferMPEG2(Box); - -impl PictureParameterBufferMPEG2 { - /// Creates the wrapper. - pub fn new( - horizontal_size: u16, - vertical_size: u16, - forward_reference_picture: bindings::VASurfaceID, - backward_reference_picture: bindings::VASurfaceID, - picture_coding_type: i32, - f_code: i32, - picture_coding_extension: &MPEG2PictureCodingExtension, - ) -> Self { - let picture_coding_extension = picture_coding_extension.0; - - Self(Box::new(bindings::VAPictureParameterBufferMPEG2 { - horizontal_size, - vertical_size, - forward_reference_picture, - backward_reference_picture, - picture_coding_type, - f_code, - picture_coding_extension, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferMPEG2 { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&mut self) -> &bindings::VAPictureParameterBufferMPEG2 { - self.0.as_ref() - } -} - -/// Wrapper over the `VASliceParameterBufferMPEG2` FFI type. -pub struct SliceParameterBufferMPEG2(Box); - -impl SliceParameterBufferMPEG2 { - /// Creates the wrapper. - #[allow(clippy::too_many_arguments)] - pub fn new( - slice_data_size: u32, - slice_data_offset: u32, - slice_data_flag: u32, - macroblock_offset: u32, - slice_horizontal_position: u32, - slice_vertical_position: u32, - quantiser_scale_code: i32, - intra_slice_flag: i32, - ) -> Self { - Self(Box::new(bindings::VASliceParameterBufferMPEG2 { - slice_data_size, - slice_data_offset, - slice_data_flag, - macroblock_offset, - slice_horizontal_position, - slice_vertical_position, - quantiser_scale_code, - intra_slice_flag, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferMPEG2 { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VASliceParameterBufferMPEG2 { - self.0.as_ref() - } -} - -/// Wrapper over the `VAIQMatrixBufferMPEG2` FFI type. -pub struct IQMatrixBufferMPEG2(Box); - -impl IQMatrixBufferMPEG2 { - /// Creates the wrapper. - #[allow(clippy::too_many_arguments)] - pub fn new( - load_intra_quantiser_matrix: i32, - load_non_intra_quantiser_matrix: i32, - load_chroma_intra_quantiser_matrix: i32, - load_chroma_non_intra_quantiser_matrix: i32, - intra_quantiser_matrix: [u8; 64usize], - non_intra_quantiser_matrix: [u8; 64usize], - chroma_intra_quantiser_matrix: [u8; 64usize], - chroma_non_intra_quantiser_matrix: [u8; 64usize], - ) -> Self { - Self(Box::new(bindings::VAIQMatrixBufferMPEG2 { - load_intra_quantiser_matrix, - load_non_intra_quantiser_matrix, - load_chroma_intra_quantiser_matrix, - load_chroma_non_intra_quantiser_matrix, - intra_quantiser_matrix, - non_intra_quantiser_matrix, - chroma_intra_quantiser_matrix, - chroma_non_intra_quantiser_matrix, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferMPEG2 { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VAIQMatrixBufferMPEG2 { - self.0.as_ref() - } -} diff --git a/shims/cros-libva/src/buffer/vp8.rs b/shims/cros-libva/src/buffer/vp8.rs deleted file mode 100644 index 70989e1c..00000000 --- a/shims/cros-libva/src/buffer/vp8.rs +++ /dev/null @@ -1,397 +0,0 @@ -// Copyright 2023 The ChromiumOS Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -//! Wrappers around VP8 `VABuffer` types. - -use crate::bindings; - -/// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferVP8`. -pub struct VP8PicFields(bindings::_VAPictureParameterBufferVP8__bindgen_ty_1); - -impl VP8PicFields { - /// Creates the bindgen field - #[allow(clippy::too_many_arguments)] - pub fn new( - key_frame: u32, - version: u32, - segmentation_enabled: u32, - update_mb_segmentation_map: u32, - update_segment_feature_data: u32, - filter_type: u32, - sharpness_level: u32, - loop_filter_adj_enable: u32, - mode_ref_lf_delta_update: u32, - sign_bias_golden: u32, - sign_bias_alternate: u32, - mb_no_coeff_skip: u32, - loop_filter_disable: u32, - ) -> Self { - let _bitfield_1 = - bindings::_VAPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( - key_frame, - version, - segmentation_enabled, - update_mb_segmentation_map, - update_segment_feature_data, - filter_type, - sharpness_level, - loop_filter_adj_enable, - mode_ref_lf_delta_update, - sign_bias_golden, - sign_bias_alternate, - mb_no_coeff_skip, - loop_filter_disable, - ); - - Self(bindings::_VAPictureParameterBufferVP8__bindgen_ty_1 { - bits: bindings::_VAPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1 { - _bitfield_align_1: Default::default(), - _bitfield_1, - __bindgen_padding_0: Default::default(), - }, - }) - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::_VAPictureParameterBufferVP8__bindgen_ty_1 { - &self.0 - } -} - -/// Wrapper over the `VABoolCoderContextVPX` FFI type. -pub struct BoolCoderContextVPX(bindings::VABoolCoderContextVPX); - -impl BoolCoderContextVPX { - /// Creates the wrapper - pub fn new(range: u8, value: u8, count: u8) -> Self { - Self(bindings::VABoolCoderContextVPX { - range, - value, - count, - }) - } -} - -/// Wrapper over the `PictureParameterBufferVP8` FFI type. -pub struct PictureParameterBufferVP8(Box); - -impl PictureParameterBufferVP8 { - /// Creates the wrapper - #[allow(clippy::too_many_arguments)] - pub fn new( - frame_width: u32, - frame_height: u32, - last_ref_frame: bindings::VASurfaceID, - golden_ref_frame: bindings::VASurfaceID, - alt_ref_frame: bindings::VASurfaceID, - pic_fields: &VP8PicFields, - mb_segment_tree_probs: [u8; 3usize], - loop_filter_level: [u8; 4usize], - loop_filter_deltas_ref_frame: [i8; 4usize], - loop_filter_deltas_mode: [i8; 4usize], - prob_skip_false: u8, - prob_intra: u8, - prob_last: u8, - prob_gf: u8, - y_mode_probs: [u8; 4usize], - uv_mode_probs: [u8; 3usize], - mv_probs: [[u8; 19usize]; 2usize], - bool_coder_ctx: &BoolCoderContextVPX, - ) -> Self { - let pic_fields = pic_fields.0; - let bool_coder_ctx = bool_coder_ctx.0; - - Self(Box::new(bindings::VAPictureParameterBufferVP8 { - frame_width, - frame_height, - last_ref_frame, - golden_ref_frame, - alt_ref_frame, - out_of_loop_frame: bindings::VA_INVALID_SURFACE, - pic_fields, - mb_segment_tree_probs, - loop_filter_level, - loop_filter_deltas_ref_frame, - loop_filter_deltas_mode, - prob_skip_false, - prob_intra, - prob_last, - prob_gf, - y_mode_probs, - uv_mode_probs, - mv_probs, - bool_coder_ctx, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferVP8 { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VAPictureParameterBufferVP8 { - self.0.as_ref() - } -} - -/// Wrapper over the `VASliceParameterBufferVP8` FFI type. -pub struct SliceParameterBufferVP8(Box); - -impl SliceParameterBufferVP8 { - /// Creates the wrapper. - pub fn new( - slice_data_size: u32, - slice_data_offset: u32, - slice_data_flag: u32, - macroblock_offset: u32, - num_of_partitions: u8, - partition_size: [u32; 9usize], - ) -> Self { - Self(Box::new(bindings::VASliceParameterBufferVP8 { - slice_data_size, - slice_data_offset, - slice_data_flag, - macroblock_offset, - num_of_partitions, - partition_size, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferVP8 { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VASliceParameterBufferVP8 { - self.0.as_ref() - } -} - -/// Wrapper over the `VAIQMatrixBufferVP8` FFI type. -pub struct IQMatrixBufferVP8(Box); - -impl IQMatrixBufferVP8 { - /// Creates the wrapper. - pub fn new(quantization_index: [[u16; 6usize]; 4usize]) -> Self { - Self(Box::new(bindings::VAIQMatrixBufferVP8 { - quantization_index, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferVP8 { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VAIQMatrixBufferVP8 { - self.0.as_ref() - } -} - -/// Wrapper over the VAProbabilityDataBufferVP8 FFI type. -pub struct ProbabilityDataBufferVP8(Box); - -impl ProbabilityDataBufferVP8 { - /// Creates the wrapper. - pub fn new(dct_coeff_probs: [[[[u8; 11usize]; 3usize]; 8usize]; 4usize]) -> Self { - Self(Box::new(bindings::VAProbabilityDataBufferVP8 { - dct_coeff_probs, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAProbabilityDataBufferVP8 { - self.0.as_mut() - } - - /// Returns the inner FFI type. Useful for testing purposes. - pub fn inner(&self) -> &bindings::VAProbabilityDataBufferVP8 { - self.0.as_ref() - } -} - -pub struct EncSequenceParameterBufferVP8(Box); - -impl EncSequenceParameterBufferVP8 { - #[allow(clippy::too_many_arguments)] - pub fn new( - frame_width: u32, - frame_height: u32, - frame_width_scale: u32, - frame_height_scale: u32, - error_resilient: u32, - kf_auto: u32, - kf_min_dist: u32, - kf_max_dist: u32, - bits_per_second: u32, - intra_period: u32, - reference_frames: [bindings::VASurfaceID; 4usize], - ) -> Self { - Self(Box::new(bindings::VAEncSequenceParameterBufferVP8 { - frame_width, - frame_height, - frame_width_scale, - frame_height_scale, - error_resilient, - kf_auto, - kf_min_dist, - kf_max_dist, - bits_per_second, - intra_period, - reference_frames, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSequenceParameterBufferVP8 { - &mut self.0 - } -} - -pub struct VP8EncRefFlags(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1); - -impl VP8EncRefFlags { - pub fn new( - force_kf: u32, - no_ref_last: u32, - no_ref_gf: u32, - no_ref_arf: u32, - temporal_id: u32, - first_ref: u32, - second_ref: u32, - ) -> Self { - let _bitfield_1 = - bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( - force_kf, - no_ref_last, - no_ref_gf, - no_ref_arf, - temporal_id, - first_ref, - second_ref, - Default::default(), - ); - - Self(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1 { - bits: bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1 { - _bitfield_align_1: Default::default(), - _bitfield_1, - }, - }) - } -} - -pub struct VP8EncPicFlags(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2); - -impl VP8EncPicFlags { - #[allow(clippy::too_many_arguments)] - pub fn new( - frame_type: u32, - version: u32, - show_frame: u32, - color_space: u32, - recon_filter_type: u32, - loop_filter_type: u32, - auto_partitions: u32, - num_token_partitions: u32, - clamping_type: u32, - segmentation_enabled: u32, - update_mb_segmentation_map: u32, - update_segment_feature_data: u32, - loop_filter_adj_enable: u32, - refresh_entropy_probs: u32, - refresh_golden_frame: u32, - refresh_alternate_frame: u32, - refresh_last: u32, - copy_buffer_to_golden: u32, - copy_buffer_to_alternate: u32, - sign_bias_golden: u32, - sign_bias_alternate: u32, - mb_no_coeff_skip: u32, - forced_lf_adjustment: u32, - ) -> Self { - let _bitfield_1 = - bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( - frame_type, - version, - show_frame, - color_space, - recon_filter_type, - loop_filter_type, - auto_partitions, - num_token_partitions, - clamping_type, - segmentation_enabled, - update_mb_segmentation_map, - update_segment_feature_data, - loop_filter_adj_enable, - refresh_entropy_probs, - refresh_golden_frame, - refresh_alternate_frame, - refresh_last, - copy_buffer_to_golden, - copy_buffer_to_alternate, - sign_bias_golden, - sign_bias_alternate, - mb_no_coeff_skip, - forced_lf_adjustment, - Default::default(), - ); - - Self(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2 { - bits: bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2__bindgen_ty_1 { - _bitfield_align_1: Default::default(), - _bitfield_1, - }, - }) - } -} - -pub struct EncPictureParameterBufferVP8(Box); - -impl EncPictureParameterBufferVP8 { - #[allow(clippy::too_many_arguments)] - pub fn new( - reconstructed_frame: bindings::VASurfaceID, - ref_last_frame: bindings::VASurfaceID, - ref_gf_frame: bindings::VASurfaceID, - ref_arf_frame: bindings::VASurfaceID, - coded_buf: bindings::VABufferID, - ref_flags: &VP8EncRefFlags, - pic_flags: &VP8EncPicFlags, - loop_filter_level: [i8; 4usize], - ref_lf_delta: [i8; 4usize], - mode_lf_delta: [i8; 4usize], - sharpness_level: u8, - clamp_qindex_high: u8, - clamp_qindex_low: u8, - ) -> Self { - let ref_flags = ref_flags.0; - let pic_flags = pic_flags.0; - - Self(Box::new(bindings::VAEncPictureParameterBufferVP8 { - reconstructed_frame, - ref_last_frame, - ref_gf_frame, - ref_arf_frame, - coded_buf, - ref_flags, - pic_flags, - loop_filter_level, - ref_lf_delta, - mode_lf_delta, - sharpness_level, - clamp_qindex_high, - clamp_qindex_low, - va_reserved: Default::default(), - })) - } - - pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferVP8 { - &mut self.0 - } -} diff --git a/shims/cros-libva/src/lib.rs b/shims/cros-libva/src/lib.rs index c7111f34..70792843 100644 --- a/shims/cros-libva/src/lib.rs +++ b/shims/cros-libva/src/lib.rs @@ -69,468 +69,3 @@ fn va_check(code: VAStatus) -> Result<(), VaError> { _ => Err(VaError(unsafe { NonZeroI32::new_unchecked(code) })), } } - -#[cfg(test)] -mod tests { - use std::io::Write; - use std::rc::Rc; - - use super::*; - - /// Returns a 32-bit CRC for the visible part of `image`, which must be in NV12 format. - fn crc_nv12_image(image: &Image) -> u32 { - let data = image.as_ref(); - let va_image = image.image(); - let offsets = &va_image.offsets; - let pitches = &va_image.pitches; - let width = va_image.width as usize; - let height = va_image.height as usize; - - // We only support NV12 images - assert_eq!(va_image.format.fourcc, u32::from_ne_bytes(*b"NV12")); - // Consistency check - assert_eq!(va_image.num_planes, 2); - - let mut hasher = crc32fast::Hasher::new(); - - let offset = offsets[0] as usize; - let pitch = pitches[0] as usize; - let y_plane = data[offset..(offset + pitch * height)] - .chunks(pitch) - .map(|line| &line[0..width]); - - let offset = offsets[1] as usize; - let pitch = pitches[1] as usize; - let uv_plane = data[offset..(offset + pitch * ((height + 1) / 2))] - .chunks(pitch) - .map(|line| &line[0..width]); - - for line in y_plane.chain(uv_plane) { - hasher.update(line); - } - - hasher.finalize() - } - - #[test] - // Ignore this test by default as it requires libva-compatible hardware. - #[ignore] - fn libva_utils_mpeg2vldemo() { - // Adapted from - let display = Display::open().unwrap(); - - assert!(!display.query_vendor_string().unwrap().is_empty()); - let profiles = display.query_config_profiles().unwrap(); - assert!(!profiles.is_empty()); - - let profile = bindings::VAProfile::VAProfileMPEG2Main; - let entrypoints = display.query_config_entrypoints(profile).unwrap(); - assert!(!entrypoints.is_empty()); - assert!(entrypoints - .iter() - .any(|e| *e == bindings::VAEntrypoint::VAEntrypointVLD)); - - let format = bindings::VA_RT_FORMAT_YUV420; - let width = 16u32; - let height = 16u32; - - let mut attrs = vec![bindings::VAConfigAttrib { - type_: bindings::VAConfigAttribType::VAConfigAttribRTFormat, - value: 0, - }]; - - let entrypoint = bindings::VAEntrypoint::VAEntrypointVLD; - display - .get_config_attributes(profile, entrypoint, &mut attrs) - .unwrap(); - assert!(attrs[0].value != bindings::VA_ATTRIB_NOT_SUPPORTED); - assert!(attrs[0].value & bindings::VA_RT_FORMAT_YUV420 != 0); - - let config = display.create_config(attrs, profile, entrypoint).unwrap(); - - let mut surfaces = display - .create_surfaces( - format, - None, - width, - height, - Some(UsageHint::USAGE_HINT_DECODER), - vec![()], - ) - .unwrap(); - let context = display - .create_context( - &config, - width, - ((height + 15) / 16) * 16, - Some(&surfaces), - true, - ) - .unwrap(); - - // The picture data is adapted from libva-utils at decode/mpeg2vldemo.cpp - // Data dump of a 16x16 MPEG2 video clip,it has one I frame - let mut mpeg2_clip: Vec = vec![ - 0x00, 0x00, 0x01, 0xb3, 0x01, 0x00, 0x10, 0x13, 0xff, 0xff, 0xe0, 0x18, 0x00, 0x00, - 0x01, 0xb5, 0x14, 0x8a, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb8, 0x00, 0x08, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0f, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xb5, - 0x8f, 0xff, 0xf3, 0x41, 0x80, 0x00, 0x00, 0x01, 0x01, 0x13, 0xe1, 0x00, 0x15, 0x81, - 0x54, 0xe0, 0x2a, 0x05, 0x43, 0x00, 0x2d, 0x60, 0x18, 0x01, 0x4e, 0x82, 0xb9, 0x58, - 0xb1, 0x83, 0x49, 0xa4, 0xa0, 0x2e, 0x05, 0x80, 0x4b, 0x7a, 0x00, 0x01, 0x38, 0x20, - 0x80, 0xe8, 0x05, 0xff, 0x60, 0x18, 0xe0, 0x1d, 0x80, 0x98, 0x01, 0xf8, 0x06, 0x00, - 0x54, 0x02, 0xc0, 0x18, 0x14, 0x03, 0xb2, 0x92, 0x80, 0xc0, 0x18, 0x94, 0x42, 0x2c, - 0xb2, 0x11, 0x64, 0xa0, 0x12, 0x5e, 0x78, 0x03, 0x3c, 0x01, 0x80, 0x0e, 0x80, 0x18, - 0x80, 0x6b, 0xca, 0x4e, 0x01, 0x0f, 0xe4, 0x32, 0xc9, 0xbf, 0x01, 0x42, 0x69, 0x43, - 0x50, 0x4b, 0x01, 0xc9, 0x45, 0x80, 0x50, 0x01, 0x38, 0x65, 0xe8, 0x01, 0x03, 0xf3, - 0xc0, 0x76, 0x00, 0xe0, 0x03, 0x20, 0x28, 0x18, 0x01, 0xa9, 0x34, 0x04, 0xc5, 0xe0, - 0x0b, 0x0b, 0x04, 0x20, 0x06, 0xc0, 0x89, 0xff, 0x60, 0x12, 0x12, 0x8a, 0x2c, 0x34, - 0x11, 0xff, 0xf6, 0xe2, 0x40, 0xc0, 0x30, 0x1b, 0x7a, 0x01, 0xa9, 0x0d, 0x00, 0xac, - 0x64, - ]; - - let picture_coding_extension = - MPEG2PictureCodingExtension::new(0, 3, 0, 1, 0, 0, 0, 0, 0, 1, 1); - let pic_param = PictureParameterBufferMPEG2::new( - 16, - 16, - 0xffffffff, - 0xffffffff, - 1, - 0xffff, - &picture_coding_extension, - ); - - let pic_param = BufferType::PictureParameter(PictureParameter::MPEG2(pic_param)); - - let iq_matrix = IQMatrixBufferMPEG2::new( - 1, - 1, - 0, - 0, - [ - 8, 16, 16, 19, 16, 19, 22, 22, 22, 22, 22, 22, 26, 24, 26, 27, 27, 27, 26, 26, 26, - 26, 27, 27, 27, 29, 29, 29, 34, 34, 34, 29, 29, 29, 27, 27, 29, 29, 32, 32, 34, 34, - 37, 38, 37, 35, 35, 34, 35, 38, 38, 40, 40, 40, 48, 48, 46, 46, 56, 56, 58, 69, 69, - 83, - ], - [ - 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, - 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, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - [0; 64], - [0; 64], - ); - - let iq_matrix = BufferType::IQMatrix(IQMatrix::MPEG2(iq_matrix)); - - let slice_param = SliceParameterBufferMPEG2::new(150, 0, 0, 38, 0, 0, 2, 0); - - let slice_param = BufferType::SliceParameter(SliceParameter::MPEG2(slice_param)); - - let test_data_offset = 47; - let slice_data = BufferType::SliceData(mpeg2_clip.drain(test_data_offset..).collect()); - - let buffers = vec![ - context.create_buffer(pic_param).unwrap(), - context.create_buffer(slice_param).unwrap(), - context.create_buffer(iq_matrix).unwrap(), - context.create_buffer(slice_data).unwrap(), - ]; - - let mut picture = Picture::new(0, Rc::clone(&context), surfaces.remove(0)); - for buffer in buffers { - picture.add_buffer(buffer); - } - - // Actual client code can just chain the calls. - let picture = picture.begin().unwrap(); - let picture = picture.render().unwrap(); - let picture = picture.end().unwrap(); - let picture = picture.sync().map_err(|(e, _)| e).unwrap(); - - // Test whether we can map the resulting surface to obtain the raw yuv - // data - let image_fmts = display.query_image_formats().unwrap(); - let image_fmt = image_fmts - .into_iter() - .find(|f| f.fourcc == bindings::VA_FOURCC_NV12) - .expect("No valid VAImageFormat found for NV12"); - - let resolution = (width, height); - let image = picture - .create_image(image_fmt, resolution, resolution) - .unwrap(); - - assert_eq!(crc_nv12_image(&image), 0xa5713e52); - } - - #[test] - // Ignore this test by default as it requires libva-compatible hardware. - #[ignore] - fn enc_h264_demo() { - // Based on `gst-launch-1.0 videotestsrc num-buffers=1 ! video/x-raw,width=64,height=64,format=NV12 ! vaapih264enc ! filesink location=frame.h264` - // 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` - let raw_frame_nv12 = include_bytes!("test_frame.nv12"); - - let display = Display::open().unwrap(); - - let format = bindings::VA_RT_FORMAT_YUV420; - let entrypoint = bindings::VAEntrypoint::VAEntrypointEncSliceLP; - let profile = bindings::VAProfile::VAProfileH264ConstrainedBaseline; - let width = 64u32; - let height = 64u32; - - let mut attrs = vec![bindings::VAConfigAttrib { - type_: bindings::VAConfigAttribType::VAConfigAttribRTFormat, - value: 0, - }]; - - display - .get_config_attributes(profile, entrypoint, &mut attrs) - .unwrap(); - - let config = display.create_config(attrs, profile, entrypoint).unwrap(); - - let mut surfaces = display - .create_surfaces( - format, - None, - width, - height, - Some(UsageHint::USAGE_HINT_ENCODER), - vec![()], - ) - .unwrap(); - - let context = display - .create_context(&config, width, height, Some(&surfaces), true) - .unwrap(); - - let seq_fields = H264EncSeqFields::new( - 1, // 4:2:0 - 1, // Only frames - 0, 0, 0, 1, 0, 2, 0, - ); - - let image_fmts = display.query_image_formats().unwrap(); - let image_fmt = image_fmts - .into_iter() - .find(|f| f.fourcc == bindings::VA_FOURCC_NV12) - .expect("No valid VAImageFormat found for NV12"); - - let surface = surfaces.pop().unwrap(); - let surface_id = surface.id(); - - let coded_buffer = context.create_enc_coded(raw_frame_nv12.len()).unwrap(); - - let mut image = - Image::create_from(&surface, image_fmt, (width, height), (width, height)).unwrap(); - - let va_image = *image.image(); - let dest = image.as_mut(); - let data = &raw_frame_nv12[..]; - let width = width as usize; - let height = height as usize; - - let mut src = data; - let mut dst = &mut dest[va_image.offsets[0] as usize..]; - - // Copy luma - for _ in 0..height { - dst[..width].copy_from_slice(&src[..width]); - dst = &mut dst[va_image.pitches[0] as usize..]; - src = &src[width..]; - } - - // Advance to the offset of the chroma plane - let mut src = &data[width * height..]; - let mut dst = &mut dest[va_image.offsets[1] as usize..]; - - let height = height / 2; - - // Copy chroma - for _ in 0..height { - dst[..width].copy_from_slice(&src[..width]); - dst = &mut dst[va_image.pitches[1] as usize..]; - src = &src[width..]; - } - drop(image); - - let sps = BufferType::EncSequenceParameter(EncSequenceParameter::H264( - EncSequenceParameterBufferH264::new( - 0, - 10, - 10, - 30, - 1, - 0, - 1, - (width / 16) as u16, // width / 16 - (height / 16) as u16, // height / 16 - &seq_fields, - 0, - 0, - 0, - 0, - 0, - [0; 256], - None, - Some(H264VuiFields::new(1, 1, 0, 0, 0, 1, 0, 0)), - 255, - 1, - 1, - 1, - 60, - ), - )); - - let sps = context.create_buffer(sps).unwrap(); - - let ref_frames: [PictureH264; 16] = (0..16) - .map(|_| { - PictureH264::new( - bindings::VA_INVALID_ID, - 0, - bindings::VA_INVALID_SURFACE, - 0, - 0, - ) - }) - .collect::>() - .try_into() - .unwrap_or_else(|_| { - panic!(); - }); - - let pps = BufferType::EncPictureParameter(EncPictureParameter::H264( - EncPictureParameterBufferH264::new( - PictureH264::new(surface_id, 0, 0, 0, 0), - ref_frames, - coded_buffer.id(), - 0, - 0, - 0, - 0, - 26, - 0, - 0, - 0, - 0, - &H264EncPicFields::new(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0), - ), - )); - - let pps = context.create_buffer(pps).unwrap(); - - let ref_pic_list_0: [PictureH264; 32] = (0..32) - .map(|_| { - PictureH264::new( - bindings::VA_INVALID_ID, - 0, - bindings::VA_INVALID_SURFACE, - 0, - 0, - ) - }) - .collect::>() - .try_into() - .unwrap_or_else(|_| { - panic!(); - }); - - let ref_pic_list_1: [PictureH264; 32] = (0..32) - .map(|_| { - PictureH264::new( - bindings::VA_INVALID_ID, - 0, - bindings::VA_INVALID_SURFACE, - 0, - 0, - ) - }) - .collect::>() - .try_into() - .unwrap_or_else(|_| { - panic!(); - }); - - let slice = BufferType::EncSliceParameter(EncSliceParameter::H264( - EncSliceParameterBufferH264::new( - 0, - ((width / 16) * (height / 16)) as u32, - bindings::VA_INVALID_ID, - 2, // I - 0, - 1, - 0, - 0, - [0, 0], - 1, - 0, - 0, - 0, - ref_pic_list_0, - ref_pic_list_1, - 0, - 0, - 0, - [0; 32], - [0; 32], - 0, - [[0; 2]; 32], - [[0; 2]; 32], - 0, - [0; 32], - [0; 32], - 0, - [[0; 2]; 32], - [[0; 2]; 32], - 0, - 0, - 0, - 2, - 2, - ), - )); - - let slice = context.create_buffer(slice).unwrap(); - - let mut picture = Picture::new(0, Rc::clone(&context), surface); - picture.add_buffer(pps); - picture.add_buffer(sps); - picture.add_buffer(slice); - - let picture = picture.begin().unwrap(); - let picture = picture.render().unwrap(); - let picture = picture.end().unwrap(); - let _ = picture.sync().map_err(|(e, _)| e).unwrap(); - - let coded_buf = MappedCodedBuffer::new(&coded_buffer).unwrap(); - assert_ne!(coded_buf.segments().len(), 0); - - for segment in coded_buf.iter() { - assert_ne!(segment.buf.len(), 0); - } - - const WRITE_TO_FILE: bool = false; - if WRITE_TO_FILE { - let raw_sps_bitstream: Vec = vec![ - 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0xc0, 0x0a, 0xab, 0x42, 0x12, 0x7f, 0xe0, 0x00, - 0x20, 0x00, 0x22, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x79, 0x28, - ]; - - let raw_pps_bitstream: Vec = vec![0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x3c, 0x80]; - - let mut raw_file = std::fs::File::create("libva_utils_enc_h264_demo.h264").unwrap(); - raw_file.write_all(&raw_sps_bitstream).unwrap(); - raw_file.write_all(&raw_pps_bitstream).unwrap(); - - for segment in coded_buf.segments() { - raw_file.write_all(segment.buf).unwrap(); - } - - raw_file.flush().unwrap(); - } - } -} diff --git a/shims/cros-libva/src/test_frame.nv12 b/shims/cros-libva/src/test_frame.nv12 deleted file mode 100644 index c4e20156136e29109852b74653a43055505f6a57..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6144 zcmaF;8VWAKz$zG+2m@I#5C{XBZ~)Ujsvibm!8aOyFaS$Fqv;0*;Mr$1|G)q&`;6uv z7=UG;(fk7guQC8K2r7jO<29Z%~<}m=$aIZ3og&>NY(!`pxtK-h5Q?xOwKSKEo?1@}$~- zTzcQCGNtTnr_2pqXG+9v>bv zUF51r)&HdYMD3-#r}DkVHGLEI$?qgpfAqoF`^S`3PpWPdj;ooRexFqRv-=Bom@LU& z=&++?_fl&IAyV~gi#VH2R(o+v>HMM04Hv35lB)lN)+F^QlG8U&Nzr76!Rwf|>_bl)punS3U=jo_6M(=xNi!t~JarEOCq0k)0D&L!U~p7F1dN8? zX!;q=KcEm8S>*?;9NbY3D+ytx<