]>
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; | |
0f2fb233 | 8 | use crate::formats::H264PictureFlags; |
68362724 KS |
9 | |
10 | /// Wrapper over the `VAPictureH264` FFI type. | |
11 | pub struct PictureH264(bindings::VAPictureH264); | |
12 | ||
13 | impl PictureH264 { | |
14 | /// Creates the wrapper | |
15 | pub fn new( | |
16 | picture_id: bindings::VASurfaceID, | |
17 | frame_idx: u32, | |
0f2fb233 | 18 | flags: H264PictureFlags, |
68362724 KS |
19 | top_field_order_cnt: i32, |
20 | bottom_field_order_cnt: i32, | |
21 | ) -> Self { | |
22 | Self(bindings::VAPictureH264 { | |
23 | picture_id, | |
24 | frame_idx, | |
0f2fb233 | 25 | flags: flags.into(), |
68362724 KS |
26 | TopFieldOrderCnt: top_field_order_cnt, |
27 | BottomFieldOrderCnt: bottom_field_order_cnt, | |
28 | va_reserved: Default::default(), | |
29 | }) | |
30 | } | |
31 | } | |
32 | ||
33 | /// Wrapper over the `seq_fields` bindgen field in `VAPictureParameterBufferH264`. | |
34 | pub struct H264SeqFields(bindings::_VAPictureParameterBufferH264__bindgen_ty_1); | |
35 | ||
36 | impl H264SeqFields { | |
37 | /// Creates the bindgen field | |
38 | #[allow(clippy::too_many_arguments)] | |
39 | pub fn new( | |
40 | chroma_format_idc: u32, | |
41 | residual_colour_transform_flag: u32, | |
42 | gaps_in_frame_num_value_allowed_flag: u32, | |
43 | frame_mbs_only_flag: u32, | |
44 | mb_adaptive_frame_field_flag: u32, | |
45 | direct_8x8_inference_flag: u32, | |
46 | min_luma_bi_pred_size8x8: u32, | |
47 | log2_max_frame_num_minus4: u32, | |
48 | pic_order_cnt_type: u32, | |
49 | log2_max_pic_order_cnt_lsb_minus4: u32, | |
50 | delta_pic_order_always_zero_flag: u32, | |
51 | ) -> Self { | |
52 | let _bitfield_1 = | |
53 | bindings::_VAPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( | |
54 | chroma_format_idc, | |
55 | residual_colour_transform_flag, | |
56 | gaps_in_frame_num_value_allowed_flag, | |
57 | frame_mbs_only_flag, | |
58 | mb_adaptive_frame_field_flag, | |
59 | direct_8x8_inference_flag, | |
60 | min_luma_bi_pred_size8x8, | |
61 | log2_max_frame_num_minus4, | |
62 | pic_order_cnt_type, | |
63 | log2_max_pic_order_cnt_lsb_minus4, | |
64 | delta_pic_order_always_zero_flag, | |
65 | ); | |
66 | ||
67 | Self(bindings::_VAPictureParameterBufferH264__bindgen_ty_1 { | |
68 | bits: bindings::_VAPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1 { | |
69 | _bitfield_align_1: Default::default(), | |
70 | _bitfield_1, | |
71 | __bindgen_padding_0: Default::default(), | |
72 | }, | |
73 | }) | |
74 | } | |
75 | ||
76 | /// Returns the inner FFI type. Useful for testing purposes. | |
77 | pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_1 { | |
78 | &self.0 | |
79 | } | |
80 | } | |
81 | ||
82 | /// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferH264`. | |
83 | pub struct H264PicFields(bindings::_VAPictureParameterBufferH264__bindgen_ty_2); | |
84 | ||
85 | impl H264PicFields { | |
86 | /// Creates the bindgen field | |
87 | #[allow(clippy::too_many_arguments)] | |
88 | pub fn new( | |
89 | entropy_coding_mode_flag: u32, | |
90 | weighted_pred_flag: u32, | |
91 | weighted_bipred_idc: u32, | |
92 | transform_8x8_mode_flag: u32, | |
93 | field_pic_flag: u32, | |
94 | constrained_intra_pred_flag: u32, | |
95 | pic_order_present_flag: u32, | |
96 | deblocking_filter_control_present_flag: u32, | |
97 | redundant_pic_cnt_present_flag: u32, | |
98 | reference_pic_flag: u32, | |
99 | ) -> Self { | |
100 | let _bitfield_1 = | |
101 | bindings::_VAPictureParameterBufferH264__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( | |
102 | entropy_coding_mode_flag, | |
103 | weighted_pred_flag, | |
104 | weighted_bipred_idc, | |
105 | transform_8x8_mode_flag, | |
106 | field_pic_flag, | |
107 | constrained_intra_pred_flag, | |
108 | pic_order_present_flag, | |
109 | deblocking_filter_control_present_flag, | |
110 | redundant_pic_cnt_present_flag, | |
111 | reference_pic_flag, | |
112 | ); | |
113 | ||
114 | Self(bindings::_VAPictureParameterBufferH264__bindgen_ty_2 { | |
115 | bits: bindings::_VAPictureParameterBufferH264__bindgen_ty_2__bindgen_ty_1 { | |
116 | _bitfield_align_1: Default::default(), | |
117 | _bitfield_1, | |
118 | __bindgen_padding_0: Default::default(), | |
119 | }, | |
120 | }) | |
121 | } | |
122 | ||
123 | /// Returns the inner FFI type. Useful for testing purposes. | |
124 | pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_2 { | |
125 | &self.0 | |
126 | } | |
127 | } | |
128 | ||
129 | /// A wrapper over `VAPictureParameterBufferH264` FFI type | |
130 | pub struct PictureParameterBufferH264(Box<bindings::VAPictureParameterBufferH264>); | |
131 | ||
132 | impl PictureParameterBufferH264 { | |
133 | /// Creates the wrapper | |
134 | #[allow(clippy::too_many_arguments)] | |
135 | pub fn new( | |
136 | curr_pic: PictureH264, | |
137 | reference_frames: [PictureH264; 16], | |
138 | picture_width_in_mbs_minus1: u16, | |
139 | picture_height_in_mbs_minus1: u16, | |
140 | bit_depth_luma_minus8: u8, | |
141 | bit_depth_chroma_minus8: u8, | |
142 | num_ref_frames: u8, | |
143 | seq_fields: &H264SeqFields, | |
144 | num_slice_groups_minus1: u8, | |
145 | slice_group_map_type: u8, | |
146 | slice_group_change_rate_minus1: u16, | |
147 | pic_init_qp_minus26: i8, | |
148 | pic_init_qs_minus26: i8, | |
149 | chroma_qp_index_offset: i8, | |
150 | second_chroma_qp_index_offset: i8, | |
151 | pic_fields: &H264PicFields, | |
152 | frame_num: u16, | |
153 | ) -> Self { | |
154 | let reference_frames = (0..16usize) | |
155 | .map(|i| reference_frames[i].0) | |
156 | .collect::<Vec<_>>() | |
157 | .try_into() | |
158 | // try_into is guaranteed to work because the iterator and target array have the same | |
159 | // size. | |
160 | .unwrap(); | |
161 | ||
162 | let seq_fields = seq_fields.0; | |
163 | let pic_fields = pic_fields.0; | |
164 | ||
165 | Self(Box::new(bindings::VAPictureParameterBufferH264 { | |
166 | CurrPic: curr_pic.0, | |
167 | ReferenceFrames: reference_frames, | |
168 | picture_width_in_mbs_minus1, | |
169 | picture_height_in_mbs_minus1, | |
170 | bit_depth_luma_minus8, | |
171 | bit_depth_chroma_minus8, | |
172 | num_ref_frames, | |
173 | seq_fields, | |
174 | num_slice_groups_minus1, | |
175 | slice_group_map_type, | |
176 | slice_group_change_rate_minus1, | |
177 | pic_init_qp_minus26, | |
178 | pic_init_qs_minus26, | |
179 | chroma_qp_index_offset, | |
180 | second_chroma_qp_index_offset, | |
181 | pic_fields, | |
182 | frame_num, | |
183 | va_reserved: Default::default(), | |
184 | })) | |
185 | } | |
186 | ||
187 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferH264 { | |
188 | self.0.as_mut() | |
189 | } | |
190 | ||
191 | /// Returns the inner FFI type. Useful for testing purposes. | |
192 | pub fn inner(&self) -> &bindings::VAPictureParameterBufferH264 { | |
193 | self.0.as_ref() | |
194 | } | |
195 | } | |
196 | ||
197 | /// Wrapper over the `VASliceParameterBufferH264` FFI type. | |
198 | pub struct SliceParameterBufferH264(Box<bindings::VASliceParameterBufferH264>); | |
199 | ||
200 | impl SliceParameterBufferH264 { | |
201 | /// Creates the wrapper | |
202 | #[allow(clippy::too_many_arguments)] | |
203 | pub fn new( | |
204 | slice_data_size: u32, | |
205 | slice_data_offset: u32, | |
0f2fb233 | 206 | slice_data_flag: crate::formats::VASliceDataFlag, |
68362724 KS |
207 | slice_data_bit_offset: u16, |
208 | first_mb_in_slice: u16, | |
209 | slice_type: u8, | |
210 | direct_spatial_mv_pred_flag: u8, | |
211 | num_ref_idx_l0_active_minus1: u8, | |
212 | num_ref_idx_l1_active_minus1: u8, | |
213 | cabac_init_idc: u8, | |
214 | slice_qp_delta: i8, | |
215 | disable_deblocking_filter_idc: u8, | |
216 | slice_alpha_c0_offset_div2: i8, | |
217 | slice_beta_offset_div2: i8, | |
218 | ref_pic_list_0: [PictureH264; 32usize], | |
219 | ref_pic_list_1: [PictureH264; 32usize], | |
220 | luma_log2_weight_denom: u8, | |
221 | chroma_log2_weight_denom: u8, | |
222 | luma_weight_l0_flag: u8, | |
223 | luma_weight_l0: [i16; 32usize], | |
224 | luma_offset_l0: [i16; 32usize], | |
225 | chroma_weight_l0_flag: u8, | |
226 | chroma_weight_l0: [[i16; 2usize]; 32usize], | |
227 | chroma_offset_l0: [[i16; 2usize]; 32usize], | |
228 | luma_weight_l1_flag: u8, | |
229 | luma_weight_l1: [i16; 32usize], | |
230 | luma_offset_l1: [i16; 32usize], | |
231 | chroma_weight_l1_flag: u8, | |
232 | chroma_weight_l1: [[i16; 2usize]; 32usize], | |
233 | chroma_offset_l1: [[i16; 2usize]; 32usize], | |
234 | ) -> Self { | |
235 | let ref_pic_list_0 = ref_pic_list_0.map(|pic| pic.0); | |
236 | let ref_pic_list_1 = ref_pic_list_1.map(|pic| pic.0); | |
237 | ||
238 | Self(Box::new(bindings::VASliceParameterBufferH264 { | |
239 | slice_data_size, | |
240 | slice_data_offset, | |
0f2fb233 | 241 | slice_data_flag: slice_data_flag as u32, |
68362724 KS |
242 | slice_data_bit_offset, |
243 | first_mb_in_slice, | |
244 | slice_type, | |
245 | direct_spatial_mv_pred_flag, | |
246 | num_ref_idx_l0_active_minus1, | |
247 | num_ref_idx_l1_active_minus1, | |
248 | cabac_init_idc, | |
249 | slice_qp_delta, | |
250 | disable_deblocking_filter_idc, | |
251 | slice_alpha_c0_offset_div2, | |
252 | slice_beta_offset_div2, | |
253 | RefPicList0: ref_pic_list_0, | |
254 | RefPicList1: ref_pic_list_1, | |
255 | luma_log2_weight_denom, | |
256 | chroma_log2_weight_denom, | |
257 | luma_weight_l0_flag, | |
258 | luma_weight_l0, | |
259 | luma_offset_l0, | |
260 | chroma_weight_l0_flag, | |
261 | chroma_weight_l0, | |
262 | chroma_offset_l0, | |
263 | luma_weight_l1_flag, | |
264 | luma_weight_l1, | |
265 | luma_offset_l1, | |
266 | chroma_weight_l1_flag, | |
267 | chroma_weight_l1, | |
268 | chroma_offset_l1, | |
269 | va_reserved: Default::default(), | |
270 | })) | |
271 | } | |
272 | ||
273 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferH264 { | |
274 | self.0.as_mut() | |
275 | } | |
276 | ||
277 | /// Returns the inner FFI type. Useful for testing purposes. | |
278 | pub fn inner(&self) -> &bindings::VASliceParameterBufferH264 { | |
279 | self.0.as_ref() | |
280 | } | |
281 | } | |
282 | ||
283 | /// Wrapper over the `VAIQMatrixBufferH264` FFI type | |
284 | pub struct IQMatrixBufferH264(Box<bindings::VAIQMatrixBufferH264>); | |
285 | ||
286 | impl IQMatrixBufferH264 { | |
287 | /// Creates the wrapper. | |
288 | pub fn new( | |
289 | scaling_list4x4: [[u8; 16usize]; 6usize], | |
290 | scaling_list8x8: [[u8; 64usize]; 2usize], | |
291 | ) -> Self { | |
292 | Self(Box::new(bindings::VAIQMatrixBufferH264 { | |
293 | ScalingList4x4: scaling_list4x4, | |
294 | ScalingList8x8: scaling_list8x8, | |
295 | va_reserved: Default::default(), | |
296 | })) | |
297 | } | |
298 | ||
299 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferH264 { | |
300 | self.0.as_mut() | |
301 | } | |
302 | ||
303 | /// Returns the inner FFI type. Useful for testing purposes. | |
304 | pub fn inner(&self) -> &bindings::VAIQMatrixBufferH264 { | |
305 | self.0.as_ref() | |
306 | } | |
307 | } |