]>
Commit | Line | Data |
---|---|---|
68362724 KS |
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(Box<bindings::VASliceParameterBufferH264>); | |
198 | ||
199 | impl SliceParameterBufferH264 { | |
200 | /// Creates the wrapper | |
201 | #[allow(clippy::too_many_arguments)] | |
202 | pub fn new( | |
203 | slice_data_size: u32, | |
204 | slice_data_offset: u32, | |
205 | slice_data_flag: u32, | |
206 | slice_data_bit_offset: u16, | |
207 | first_mb_in_slice: u16, | |
208 | slice_type: u8, | |
209 | direct_spatial_mv_pred_flag: u8, | |
210 | num_ref_idx_l0_active_minus1: u8, | |
211 | num_ref_idx_l1_active_minus1: u8, | |
212 | cabac_init_idc: u8, | |
213 | slice_qp_delta: i8, | |
214 | disable_deblocking_filter_idc: u8, | |
215 | slice_alpha_c0_offset_div2: i8, | |
216 | slice_beta_offset_div2: i8, | |
217 | ref_pic_list_0: [PictureH264; 32usize], | |
218 | ref_pic_list_1: [PictureH264; 32usize], | |
219 | luma_log2_weight_denom: u8, | |
220 | chroma_log2_weight_denom: u8, | |
221 | luma_weight_l0_flag: u8, | |
222 | luma_weight_l0: [i16; 32usize], | |
223 | luma_offset_l0: [i16; 32usize], | |
224 | chroma_weight_l0_flag: u8, | |
225 | chroma_weight_l0: [[i16; 2usize]; 32usize], | |
226 | chroma_offset_l0: [[i16; 2usize]; 32usize], | |
227 | luma_weight_l1_flag: u8, | |
228 | luma_weight_l1: [i16; 32usize], | |
229 | luma_offset_l1: [i16; 32usize], | |
230 | chroma_weight_l1_flag: u8, | |
231 | chroma_weight_l1: [[i16; 2usize]; 32usize], | |
232 | chroma_offset_l1: [[i16; 2usize]; 32usize], | |
233 | ) -> Self { | |
234 | let ref_pic_list_0 = ref_pic_list_0.map(|pic| pic.0); | |
235 | let ref_pic_list_1 = ref_pic_list_1.map(|pic| pic.0); | |
236 | ||
237 | Self(Box::new(bindings::VASliceParameterBufferH264 { | |
238 | slice_data_size, | |
239 | slice_data_offset, | |
240 | slice_data_flag, | |
241 | slice_data_bit_offset, | |
242 | first_mb_in_slice, | |
243 | slice_type, | |
244 | direct_spatial_mv_pred_flag, | |
245 | num_ref_idx_l0_active_minus1, | |
246 | num_ref_idx_l1_active_minus1, | |
247 | cabac_init_idc, | |
248 | slice_qp_delta, | |
249 | disable_deblocking_filter_idc, | |
250 | slice_alpha_c0_offset_div2, | |
251 | slice_beta_offset_div2, | |
252 | RefPicList0: ref_pic_list_0, | |
253 | RefPicList1: ref_pic_list_1, | |
254 | luma_log2_weight_denom, | |
255 | chroma_log2_weight_denom, | |
256 | luma_weight_l0_flag, | |
257 | luma_weight_l0, | |
258 | luma_offset_l0, | |
259 | chroma_weight_l0_flag, | |
260 | chroma_weight_l0, | |
261 | chroma_offset_l0, | |
262 | luma_weight_l1_flag, | |
263 | luma_weight_l1, | |
264 | luma_offset_l1, | |
265 | chroma_weight_l1_flag, | |
266 | chroma_weight_l1, | |
267 | chroma_offset_l1, | |
268 | va_reserved: Default::default(), | |
269 | })) | |
270 | } | |
271 | ||
272 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferH264 { | |
273 | self.0.as_mut() | |
274 | } | |
275 | ||
276 | /// Returns the inner FFI type. Useful for testing purposes. | |
277 | pub fn inner(&self) -> &bindings::VASliceParameterBufferH264 { | |
278 | self.0.as_ref() | |
279 | } | |
280 | } | |
281 | ||
282 | /// Wrapper over the `VAIQMatrixBufferH264` FFI type | |
283 | pub struct IQMatrixBufferH264(Box<bindings::VAIQMatrixBufferH264>); | |
284 | ||
285 | impl IQMatrixBufferH264 { | |
286 | /// Creates the wrapper. | |
287 | pub fn new( | |
288 | scaling_list4x4: [[u8; 16usize]; 6usize], | |
289 | scaling_list8x8: [[u8; 64usize]; 2usize], | |
290 | ) -> Self { | |
291 | Self(Box::new(bindings::VAIQMatrixBufferH264 { | |
292 | ScalingList4x4: scaling_list4x4, | |
293 | ScalingList8x8: scaling_list8x8, | |
294 | va_reserved: Default::default(), | |
295 | })) | |
296 | } | |
297 | ||
298 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferH264 { | |
299 | self.0.as_mut() | |
300 | } | |
301 | ||
302 | /// Returns the inner FFI type. Useful for testing purposes. | |
303 | pub fn inner(&self) -> &bindings::VAIQMatrixBufferH264 { | |
304 | self.0.as_ref() | |
305 | } | |
306 | } |