Skip to main content

moq_vaapi/buffer/
mpeg2.rs

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
7use crate::bindings;
8
9/// Wrapper over the `picture_coding_extension` bindgen field in `VAPictureParameterBufferMPEG2`.
10pub struct MPEG2PictureCodingExtension(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1);
11
12impl 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 = bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(
29			intra_dc_precision,
30			picture_structure,
31			top_field_first,
32			frame_pred_frame_dct,
33			concealment_motion_vectors,
34			q_scale_type,
35			intra_vlc_format,
36			alternate_scan,
37			repeat_first_field,
38			progressive_frame,
39			is_first_field,
40		);
41
42		Self(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 {
43			bits: bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1__bindgen_ty_1 {
44				_bitfield_align_1: Default::default(),
45				_bitfield_1,
46				__bindgen_padding_0: Default::default(),
47			},
48		})
49	}
50
51	/// Returns the inner FFI type. Useful for testing purposes.
52	pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 {
53		&self.0
54	}
55}
56
57/// Wrapper over the `PictureParameterBufferMPEG2` FFI type.
58pub struct PictureParameterBufferMPEG2(Box<bindings::VAPictureParameterBufferMPEG2>);
59
60impl PictureParameterBufferMPEG2 {
61	/// Creates the wrapper.
62	pub fn new(
63		horizontal_size: u16,
64		vertical_size: u16,
65		forward_reference_picture: bindings::VASurfaceID,
66		backward_reference_picture: bindings::VASurfaceID,
67		picture_coding_type: i32,
68		f_code: i32,
69		picture_coding_extension: &MPEG2PictureCodingExtension,
70	) -> Self {
71		let picture_coding_extension = picture_coding_extension.0;
72
73		Self(Box::new(bindings::VAPictureParameterBufferMPEG2 {
74			horizontal_size,
75			vertical_size,
76			forward_reference_picture,
77			backward_reference_picture,
78			picture_coding_type,
79			f_code,
80			picture_coding_extension,
81			va_reserved: Default::default(),
82		}))
83	}
84
85	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferMPEG2 {
86		self.0.as_mut()
87	}
88
89	/// Returns the inner FFI type. Useful for testing purposes.
90	pub fn inner(&mut self) -> &bindings::VAPictureParameterBufferMPEG2 {
91		self.0.as_ref()
92	}
93}
94
95/// Wrapper over the `VASliceParameterBufferMPEG2` FFI type.
96pub struct SliceParameterBufferMPEG2(Box<bindings::VASliceParameterBufferMPEG2>);
97
98impl SliceParameterBufferMPEG2 {
99	/// Creates the wrapper.
100	#[allow(clippy::too_many_arguments)]
101	pub fn new(
102		slice_data_size: u32,
103		slice_data_offset: u32,
104		slice_data_flag: u32,
105		macroblock_offset: u32,
106		slice_horizontal_position: u32,
107		slice_vertical_position: u32,
108		quantiser_scale_code: i32,
109		intra_slice_flag: i32,
110	) -> Self {
111		Self(Box::new(bindings::VASliceParameterBufferMPEG2 {
112			slice_data_size,
113			slice_data_offset,
114			slice_data_flag,
115			macroblock_offset,
116			slice_horizontal_position,
117			slice_vertical_position,
118			quantiser_scale_code,
119			intra_slice_flag,
120			va_reserved: Default::default(),
121		}))
122	}
123
124	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferMPEG2 {
125		self.0.as_mut()
126	}
127
128	/// Returns the inner FFI type. Useful for testing purposes.
129	pub fn inner(&self) -> &bindings::VASliceParameterBufferMPEG2 {
130		self.0.as_ref()
131	}
132}
133
134/// Wrapper over the `VAIQMatrixBufferMPEG2` FFI type.
135pub struct IQMatrixBufferMPEG2(Box<bindings::VAIQMatrixBufferMPEG2>);
136
137impl IQMatrixBufferMPEG2 {
138	/// Creates the wrapper.
139	#[allow(clippy::too_many_arguments)]
140	pub fn new(
141		load_intra_quantiser_matrix: i32,
142		load_non_intra_quantiser_matrix: i32,
143		load_chroma_intra_quantiser_matrix: i32,
144		load_chroma_non_intra_quantiser_matrix: i32,
145		intra_quantiser_matrix: [u8; 64usize],
146		non_intra_quantiser_matrix: [u8; 64usize],
147		chroma_intra_quantiser_matrix: [u8; 64usize],
148		chroma_non_intra_quantiser_matrix: [u8; 64usize],
149	) -> Self {
150		Self(Box::new(bindings::VAIQMatrixBufferMPEG2 {
151			load_intra_quantiser_matrix,
152			load_non_intra_quantiser_matrix,
153			load_chroma_intra_quantiser_matrix,
154			load_chroma_non_intra_quantiser_matrix,
155			intra_quantiser_matrix,
156			non_intra_quantiser_matrix,
157			chroma_intra_quantiser_matrix,
158			chroma_non_intra_quantiser_matrix,
159			va_reserved: Default::default(),
160		}))
161	}
162
163	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferMPEG2 {
164		self.0.as_mut()
165	}
166
167	/// Returns the inner FFI type. Useful for testing purposes.
168	pub fn inner(&self) -> &bindings::VAIQMatrixBufferMPEG2 {
169		self.0.as_ref()
170	}
171}