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.
5 //! Wrappers around H264 `VABuffer` types.
9 /// Wrapper over the `VAPictureH264` FFI type.
10 pub struct PictureH264(bindings::VAPictureH264);
13 /// Creates the wrapper
15 picture_id: bindings::VASurfaceID,
18 top_field_order_cnt: i32,
19 bottom_field_order_cnt: i32,
21 Self(bindings::VAPictureH264 {
25 TopFieldOrderCnt: top_field_order_cnt,
26 BottomFieldOrderCnt: bottom_field_order_cnt,
27 va_reserved: Default::default(),
32 /// Wrapper over the `seq_fields` bindgen field in `VAPictureParameterBufferH264`.
33 pub struct H264SeqFields(bindings::_VAPictureParameterBufferH264__bindgen_ty_1);
36 /// Creates the bindgen field
37 #[allow(clippy::too_many_arguments)]
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,
52 bindings::_VAPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(
54 residual_colour_transform_flag,
55 gaps_in_frame_num_value_allowed_flag,
57 mb_adaptive_frame_field_flag,
58 direct_8x8_inference_flag,
59 min_luma_bi_pred_size8x8,
60 log2_max_frame_num_minus4,
62 log2_max_pic_order_cnt_lsb_minus4,
63 delta_pic_order_always_zero_flag,
66 Self(bindings::_VAPictureParameterBufferH264__bindgen_ty_1 {
67 bits: bindings::_VAPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1 {
68 _bitfield_align_1: Default::default(),
70 __bindgen_padding_0: Default::default(),
75 /// Returns the inner FFI type. Useful for testing purposes.
76 pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_1 {
81 /// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferH264`.
82 pub struct H264PicFields(bindings::_VAPictureParameterBufferH264__bindgen_ty_2);
85 /// Creates the bindgen field
86 #[allow(clippy::too_many_arguments)]
88 entropy_coding_mode_flag: u32,
89 weighted_pred_flag: u32,
90 weighted_bipred_idc: u32,
91 transform_8x8_mode_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,
100 bindings::_VAPictureParameterBufferH264__bindgen_ty_2__bindgen_ty_1::new_bitfield_1(
101 entropy_coding_mode_flag,
104 transform_8x8_mode_flag,
106 constrained_intra_pred_flag,
107 pic_order_present_flag,
108 deblocking_filter_control_present_flag,
109 redundant_pic_cnt_present_flag,
113 Self(bindings::_VAPictureParameterBufferH264__bindgen_ty_2 {
114 bits: bindings::_VAPictureParameterBufferH264__bindgen_ty_2__bindgen_ty_1 {
115 _bitfield_align_1: Default::default(),
117 __bindgen_padding_0: Default::default(),
122 /// Returns the inner FFI type. Useful for testing purposes.
123 pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_2 {
128 /// A wrapper over `VAPictureParameterBufferH264` FFI type
129 pub struct PictureParameterBufferH264(Box<bindings::VAPictureParameterBufferH264>);
131 impl PictureParameterBufferH264 {
132 /// Creates the wrapper
133 #[allow(clippy::too_many_arguments)]
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,
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,
153 let reference_frames = (0..16usize)
154 .map(|i| reference_frames[i].0)
157 // try_into is guaranteed to work because the iterator and target array have the same
161 let seq_fields = seq_fields.0;
162 let pic_fields = pic_fields.0;
164 Self(Box::new(bindings::VAPictureParameterBufferH264 {
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,
173 num_slice_groups_minus1,
174 slice_group_map_type,
175 slice_group_change_rate_minus1,
178 chroma_qp_index_offset,
179 second_chroma_qp_index_offset,
182 va_reserved: Default::default(),
186 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferH264 {
190 /// Returns the inner FFI type. Useful for testing purposes.
191 pub fn inner(&self) -> &bindings::VAPictureParameterBufferH264 {
196 /// Wrapper over the `VASliceParameterBufferH264` FFI type.
197 pub struct SliceParameterBufferH264(Box<bindings::VASliceParameterBufferH264>);
199 impl SliceParameterBufferH264 {
200 /// Creates the wrapper
201 #[allow(clippy::too_many_arguments)]
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,
209 direct_spatial_mv_pred_flag: u8,
210 num_ref_idx_l0_active_minus1: u8,
211 num_ref_idx_l1_active_minus1: u8,
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],
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);
237 Self(Box::new(bindings::VASliceParameterBufferH264 {
241 slice_data_bit_offset,
244 direct_spatial_mv_pred_flag,
245 num_ref_idx_l0_active_minus1,
246 num_ref_idx_l1_active_minus1,
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,
259 chroma_weight_l0_flag,
265 chroma_weight_l1_flag,
268 va_reserved: Default::default(),
272 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferH264 {
276 /// Returns the inner FFI type. Useful for testing purposes.
277 pub fn inner(&self) -> &bindings::VASliceParameterBufferH264 {
282 /// Wrapper over the `VAIQMatrixBufferH264` FFI type
283 pub struct IQMatrixBufferH264(Box<bindings::VAIQMatrixBufferH264>);
285 impl IQMatrixBufferH264 {
286 /// Creates the wrapper.
288 scaling_list4x4: [[u8; 16usize]; 6usize],
289 scaling_list8x8: [[u8; 64usize]; 2usize],
291 Self(Box::new(bindings::VAIQMatrixBufferH264 {
292 ScalingList4x4: scaling_list4x4,
293 ScalingList8x8: scaling_list8x8,
294 va_reserved: Default::default(),
298 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferH264 {
302 /// Returns the inner FFI type. Useful for testing purposes.
303 pub fn inner(&self) -> &bindings::VAIQMatrixBufferH264 {