Skip to main content

moq_vaapi/buffer/
vp8.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 VP8 `VABuffer` types.
6
7use crate::bindings;
8
9/// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferVP8`.
10pub struct VP8PicFields(bindings::_VAPictureParameterBufferVP8__bindgen_ty_1);
11
12impl 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 = bindings::_VAPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(
31			key_frame,
32			version,
33			segmentation_enabled,
34			update_mb_segmentation_map,
35			update_segment_feature_data,
36			filter_type,
37			sharpness_level,
38			loop_filter_adj_enable,
39			mode_ref_lf_delta_update,
40			sign_bias_golden,
41			sign_bias_alternate,
42			mb_no_coeff_skip,
43			loop_filter_disable,
44		);
45
46		Self(bindings::_VAPictureParameterBufferVP8__bindgen_ty_1 {
47			bits: bindings::_VAPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1 {
48				_bitfield_align_1: Default::default(),
49				_bitfield_1,
50				__bindgen_padding_0: Default::default(),
51			},
52		})
53	}
54
55	/// Returns the inner FFI type. Useful for testing purposes.
56	pub fn inner(&self) -> &bindings::_VAPictureParameterBufferVP8__bindgen_ty_1 {
57		&self.0
58	}
59}
60
61/// Wrapper over the `VABoolCoderContextVPX` FFI type.
62pub struct BoolCoderContextVPX(bindings::VABoolCoderContextVPX);
63
64impl BoolCoderContextVPX {
65	/// Creates the wrapper
66	pub fn new(range: u8, value: u8, count: u8) -> Self {
67		Self(bindings::VABoolCoderContextVPX { range, value, count })
68	}
69}
70
71/// Wrapper over the `PictureParameterBufferVP8` FFI type.
72pub struct PictureParameterBufferVP8(Box<bindings::VAPictureParameterBufferVP8>);
73
74impl PictureParameterBufferVP8 {
75	/// Creates the wrapper
76	#[allow(clippy::too_many_arguments)]
77	pub fn new(
78		frame_width: u32,
79		frame_height: u32,
80		last_ref_frame: bindings::VASurfaceID,
81		golden_ref_frame: bindings::VASurfaceID,
82		alt_ref_frame: bindings::VASurfaceID,
83		pic_fields: &VP8PicFields,
84		mb_segment_tree_probs: [u8; 3usize],
85		loop_filter_level: [u8; 4usize],
86		loop_filter_deltas_ref_frame: [i8; 4usize],
87		loop_filter_deltas_mode: [i8; 4usize],
88		prob_skip_false: u8,
89		prob_intra: u8,
90		prob_last: u8,
91		prob_gf: u8,
92		y_mode_probs: [u8; 4usize],
93		uv_mode_probs: [u8; 3usize],
94		mv_probs: [[u8; 19usize]; 2usize],
95		bool_coder_ctx: &BoolCoderContextVPX,
96	) -> Self {
97		let pic_fields = pic_fields.0;
98		let bool_coder_ctx = bool_coder_ctx.0;
99
100		Self(Box::new(bindings::VAPictureParameterBufferVP8 {
101			frame_width,
102			frame_height,
103			last_ref_frame,
104			golden_ref_frame,
105			alt_ref_frame,
106			out_of_loop_frame: bindings::VA_INVALID_SURFACE,
107			pic_fields,
108			mb_segment_tree_probs,
109			loop_filter_level,
110			loop_filter_deltas_ref_frame,
111			loop_filter_deltas_mode,
112			prob_skip_false,
113			prob_intra,
114			prob_last,
115			prob_gf,
116			y_mode_probs,
117			uv_mode_probs,
118			mv_probs,
119			bool_coder_ctx,
120			va_reserved: Default::default(),
121		}))
122	}
123
124	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferVP8 {
125		self.0.as_mut()
126	}
127
128	/// Returns the inner FFI type. Useful for testing purposes.
129	pub fn inner(&self) -> &bindings::VAPictureParameterBufferVP8 {
130		self.0.as_ref()
131	}
132}
133
134/// Wrapper over the `VASliceParameterBufferVP8` FFI type.
135pub struct SliceParameterBufferVP8(Box<bindings::VASliceParameterBufferVP8>);
136
137impl SliceParameterBufferVP8 {
138	/// Creates the wrapper.
139	pub fn new(
140		slice_data_size: u32,
141		slice_data_offset: u32,
142		slice_data_flag: u32,
143		macroblock_offset: u32,
144		num_of_partitions: u8,
145		partition_size: [u32; 9usize],
146	) -> Self {
147		Self(Box::new(bindings::VASliceParameterBufferVP8 {
148			slice_data_size,
149			slice_data_offset,
150			slice_data_flag,
151			macroblock_offset,
152			num_of_partitions,
153			partition_size,
154			va_reserved: Default::default(),
155		}))
156	}
157
158	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferVP8 {
159		self.0.as_mut()
160	}
161
162	/// Returns the inner FFI type. Useful for testing purposes.
163	pub fn inner(&self) -> &bindings::VASliceParameterBufferVP8 {
164		self.0.as_ref()
165	}
166}
167
168/// Wrapper over the `VAIQMatrixBufferVP8` FFI type.
169pub struct IQMatrixBufferVP8(Box<bindings::VAIQMatrixBufferVP8>);
170
171impl IQMatrixBufferVP8 {
172	/// Creates the wrapper.
173	pub fn new(quantization_index: [[u16; 6usize]; 4usize]) -> Self {
174		Self(Box::new(bindings::VAIQMatrixBufferVP8 {
175			quantization_index,
176			va_reserved: Default::default(),
177		}))
178	}
179
180	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferVP8 {
181		self.0.as_mut()
182	}
183
184	/// Returns the inner FFI type. Useful for testing purposes.
185	pub fn inner(&self) -> &bindings::VAIQMatrixBufferVP8 {
186		self.0.as_ref()
187	}
188}
189
190/// Wrapper over the VAProbabilityDataBufferVP8 FFI type.
191pub struct ProbabilityDataBufferVP8(Box<bindings::VAProbabilityDataBufferVP8>);
192
193impl ProbabilityDataBufferVP8 {
194	/// Creates the wrapper.
195	pub fn new(dct_coeff_probs: [[[[u8; 11usize]; 3usize]; 8usize]; 4usize]) -> Self {
196		Self(Box::new(bindings::VAProbabilityDataBufferVP8 {
197			dct_coeff_probs,
198			va_reserved: Default::default(),
199		}))
200	}
201
202	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAProbabilityDataBufferVP8 {
203		self.0.as_mut()
204	}
205
206	/// Returns the inner FFI type. Useful for testing purposes.
207	pub fn inner(&self) -> &bindings::VAProbabilityDataBufferVP8 {
208		self.0.as_ref()
209	}
210}
211
212pub struct EncSequenceParameterBufferVP8(Box<bindings::VAEncSequenceParameterBufferVP8>);
213
214impl EncSequenceParameterBufferVP8 {
215	#[allow(clippy::too_many_arguments)]
216	pub fn new(
217		frame_width: u32,
218		frame_height: u32,
219		frame_width_scale: u32,
220		frame_height_scale: u32,
221		error_resilient: u32,
222		kf_auto: u32,
223		kf_min_dist: u32,
224		kf_max_dist: u32,
225		bits_per_second: u32,
226		intra_period: u32,
227		reference_frames: [bindings::VASurfaceID; 4usize],
228	) -> Self {
229		Self(Box::new(bindings::VAEncSequenceParameterBufferVP8 {
230			frame_width,
231			frame_height,
232			frame_width_scale,
233			frame_height_scale,
234			error_resilient,
235			kf_auto,
236			kf_min_dist,
237			kf_max_dist,
238			bits_per_second,
239			intra_period,
240			reference_frames,
241			va_reserved: Default::default(),
242		}))
243	}
244
245	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSequenceParameterBufferVP8 {
246		&mut self.0
247	}
248}
249
250pub struct VP8EncRefFlags(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1);
251
252impl VP8EncRefFlags {
253	pub fn new(
254		force_kf: u32,
255		no_ref_last: u32,
256		no_ref_gf: u32,
257		no_ref_arf: u32,
258		temporal_id: u32,
259		first_ref: u32,
260		second_ref: u32,
261	) -> Self {
262		let _bitfield_1 = bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(
263			force_kf,
264			no_ref_last,
265			no_ref_gf,
266			no_ref_arf,
267			temporal_id,
268			first_ref,
269			second_ref,
270			Default::default(),
271		);
272
273		Self(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1 {
274			bits: bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1 {
275				_bitfield_align_1: Default::default(),
276				_bitfield_1,
277			},
278		})
279	}
280}
281
282pub struct VP8EncPicFlags(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2);
283
284impl VP8EncPicFlags {
285	#[allow(clippy::too_many_arguments)]
286	pub fn new(
287		frame_type: u32,
288		version: u32,
289		show_frame: u32,
290		color_space: u32,
291		recon_filter_type: u32,
292		loop_filter_type: u32,
293		auto_partitions: u32,
294		num_token_partitions: u32,
295		clamping_type: u32,
296		segmentation_enabled: u32,
297		update_mb_segmentation_map: u32,
298		update_segment_feature_data: u32,
299		loop_filter_adj_enable: u32,
300		refresh_entropy_probs: u32,
301		refresh_golden_frame: u32,
302		refresh_alternate_frame: u32,
303		refresh_last: u32,
304		copy_buffer_to_golden: u32,
305		copy_buffer_to_alternate: u32,
306		sign_bias_golden: u32,
307		sign_bias_alternate: u32,
308		mb_no_coeff_skip: u32,
309		forced_lf_adjustment: u32,
310	) -> Self {
311		let _bitfield_1 = bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2__bindgen_ty_1::new_bitfield_1(
312			frame_type,
313			version,
314			show_frame,
315			color_space,
316			recon_filter_type,
317			loop_filter_type,
318			auto_partitions,
319			num_token_partitions,
320			clamping_type,
321			segmentation_enabled,
322			update_mb_segmentation_map,
323			update_segment_feature_data,
324			loop_filter_adj_enable,
325			refresh_entropy_probs,
326			refresh_golden_frame,
327			refresh_alternate_frame,
328			refresh_last,
329			copy_buffer_to_golden,
330			copy_buffer_to_alternate,
331			sign_bias_golden,
332			sign_bias_alternate,
333			mb_no_coeff_skip,
334			forced_lf_adjustment,
335			Default::default(),
336		);
337
338		Self(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2 {
339			bits: bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2__bindgen_ty_1 {
340				_bitfield_align_1: Default::default(),
341				_bitfield_1,
342			},
343		})
344	}
345}
346
347pub struct EncPictureParameterBufferVP8(Box<bindings::VAEncPictureParameterBufferVP8>);
348
349impl EncPictureParameterBufferVP8 {
350	#[allow(clippy::too_many_arguments)]
351	pub fn new(
352		reconstructed_frame: bindings::VASurfaceID,
353		ref_last_frame: bindings::VASurfaceID,
354		ref_gf_frame: bindings::VASurfaceID,
355		ref_arf_frame: bindings::VASurfaceID,
356		coded_buf: bindings::VABufferID,
357		ref_flags: &VP8EncRefFlags,
358		pic_flags: &VP8EncPicFlags,
359		loop_filter_level: [i8; 4usize],
360		ref_lf_delta: [i8; 4usize],
361		mode_lf_delta: [i8; 4usize],
362		sharpness_level: u8,
363		clamp_qindex_high: u8,
364		clamp_qindex_low: u8,
365	) -> Self {
366		let ref_flags = ref_flags.0;
367		let pic_flags = pic_flags.0;
368
369		Self(Box::new(bindings::VAEncPictureParameterBufferVP8 {
370			reconstructed_frame,
371			ref_last_frame,
372			ref_gf_frame,
373			ref_arf_frame,
374			coded_buf,
375			ref_flags,
376			pic_flags,
377			loop_filter_level,
378			ref_lf_delta,
379			mode_lf_delta,
380			sharpness_level,
381			clamp_qindex_high,
382			clamp_qindex_low,
383			va_reserved: Default::default(),
384		}))
385	}
386
387	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferVP8 {
388		&mut self.0
389	}
390}