forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

vp8.rs397 lines, 12.1 KiBHistoryRawDownload
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 =
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.
63pub struct BoolCoderContextVPX(bindings::VABoolCoderContextVPX);
64
65impl 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.
77pub struct PictureParameterBufferVP8(Box<bindings::VAPictureParameterBufferVP8>);
78
79impl 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.
140pub struct SliceParameterBufferVP8(Box<bindings::VASliceParameterBufferVP8>);
141
142impl 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.
174pub struct IQMatrixBufferVP8(Box<bindings::VAIQMatrixBufferVP8>);
175
176impl 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.
196pub struct ProbabilityDataBufferVP8(Box<bindings::VAProbabilityDataBufferVP8>);
197
198impl 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
217pub struct EncSequenceParameterBufferVP8(Box<bindings::VAEncSequenceParameterBufferVP8>);
218
219impl 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
255pub struct VP8EncRefFlags(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_1);
256
257impl 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
288pub struct VP8EncPicFlags(bindings::_VAEncPictureParameterBufferVP8__bindgen_ty_2);
289
290impl 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
354pub struct EncPictureParameterBufferVP8(Box<bindings::VAEncPictureParameterBufferVP8>);
355
356impl 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}