edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 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(Vec<bindings::VASliceParameterBufferH264>); |
| 198 | |
| 199 | impl SliceParameterBufferH264 { |
| 200 | pub fn new_array() -> Self { |
| 201 | Self(Vec::new()) |
| 202 | } |
| 203 | |
| 204 | /// Creates the wrapper |
| 205 | #[allow(clippy::too_many_arguments)] |
| 206 | pub fn new( |
| 207 | slice_data_size: u32, |
| 208 | slice_data_offset: u32, |
| 209 | slice_data_flag: u32, |
| 210 | slice_data_bit_offset: u16, |
| 211 | first_mb_in_slice: u16, |
| 212 | slice_type: u8, |
| 213 | direct_spatial_mv_pred_flag: u8, |
| 214 | num_ref_idx_l0_active_minus1: u8, |
| 215 | num_ref_idx_l1_active_minus1: u8, |
| 216 | cabac_init_idc: u8, |
| 217 | slice_qp_delta: i8, |
| 218 | disable_deblocking_filter_idc: u8, |
| 219 | slice_alpha_c0_offset_div2: i8, |
| 220 | slice_beta_offset_div2: i8, |
| 221 | ref_pic_list_0: [PictureH264; 32usize], |
| 222 | ref_pic_list_1: [PictureH264; 32usize], |
| 223 | luma_log2_weight_denom: u8, |
| 224 | chroma_log2_weight_denom: u8, |
| 225 | luma_weight_l0_flag: u8, |
| 226 | luma_weight_l0: [i16; 32usize], |
| 227 | luma_offset_l0: [i16; 32usize], |
| 228 | chroma_weight_l0_flag: u8, |
| 229 | chroma_weight_l0: [[i16; 2usize]; 32usize], |
| 230 | chroma_offset_l0: [[i16; 2usize]; 32usize], |
| 231 | luma_weight_l1_flag: u8, |
| 232 | luma_weight_l1: [i16; 32usize], |
| 233 | luma_offset_l1: [i16; 32usize], |
| 234 | chroma_weight_l1_flag: u8, |
| 235 | chroma_weight_l1: [[i16; 2usize]; 32usize], |
| 236 | chroma_offset_l1: [[i16; 2usize]; 32usize], |
| 237 | ) -> Self { |
| 238 | let mut array = Self::new_array(); |
| 239 | |
| 240 | array.add_slice_parameter( |
| 241 | slice_data_size, |
| 242 | slice_data_offset, |
| 243 | slice_data_flag, |
| 244 | slice_data_bit_offset, |
| 245 | first_mb_in_slice, |
| 246 | slice_type, |
| 247 | direct_spatial_mv_pred_flag, |
| 248 | num_ref_idx_l0_active_minus1, |
| 249 | num_ref_idx_l1_active_minus1, |
| 250 | cabac_init_idc, |
| 251 | slice_qp_delta, |
| 252 | disable_deblocking_filter_idc, |
| 253 | slice_alpha_c0_offset_div2, |
| 254 | slice_beta_offset_div2, |
| 255 | ref_pic_list_0, |
| 256 | ref_pic_list_1, |
| 257 | luma_log2_weight_denom, |
| 258 | chroma_log2_weight_denom, |
| 259 | luma_weight_l0_flag, |
| 260 | luma_weight_l0, |
| 261 | luma_offset_l0, |
| 262 | chroma_weight_l0_flag, |
| 263 | chroma_weight_l0, |
| 264 | chroma_offset_l0, |
| 265 | luma_weight_l1_flag, |
| 266 | luma_weight_l1, |
| 267 | luma_offset_l1, |
| 268 | chroma_weight_l1_flag, |
| 269 | chroma_weight_l1, |
| 270 | chroma_offset_l1, |
| 271 | ); |
| 272 | |
| 273 | array |
| 274 | } |
| 275 | |
| 276 | /// Creates the wrapper |
| 277 | #[allow(clippy::too_many_arguments)] |
| 278 | pub fn add_slice_parameter( |
| 279 | &mut self, |
| 280 | slice_data_size: u32, |
| 281 | slice_data_offset: u32, |
| 282 | slice_data_flag: u32, |
| 283 | slice_data_bit_offset: u16, |
| 284 | first_mb_in_slice: u16, |
| 285 | slice_type: u8, |
| 286 | direct_spatial_mv_pred_flag: u8, |
| 287 | num_ref_idx_l0_active_minus1: u8, |
| 288 | num_ref_idx_l1_active_minus1: u8, |
| 289 | cabac_init_idc: u8, |
| 290 | slice_qp_delta: i8, |
| 291 | disable_deblocking_filter_idc: u8, |
| 292 | slice_alpha_c0_offset_div2: i8, |
| 293 | slice_beta_offset_div2: i8, |
| 294 | ref_pic_list_0: [PictureH264; 32usize], |
| 295 | ref_pic_list_1: [PictureH264; 32usize], |
| 296 | luma_log2_weight_denom: u8, |
| 297 | chroma_log2_weight_denom: u8, |
| 298 | luma_weight_l0_flag: u8, |
| 299 | luma_weight_l0: [i16; 32usize], |
| 300 | luma_offset_l0: [i16; 32usize], |
| 301 | chroma_weight_l0_flag: u8, |
| 302 | chroma_weight_l0: [[i16; 2usize]; 32usize], |
| 303 | chroma_offset_l0: [[i16; 2usize]; 32usize], |
| 304 | luma_weight_l1_flag: u8, |
| 305 | luma_weight_l1: [i16; 32usize], |
| 306 | luma_offset_l1: [i16; 32usize], |
| 307 | chroma_weight_l1_flag: u8, |
| 308 | chroma_weight_l1: [[i16; 2usize]; 32usize], |
| 309 | chroma_offset_l1: [[i16; 2usize]; 32usize], |
| 310 | ) { |
| 311 | let ref_pic_list_0 = ref_pic_list_0.map(|pic| pic.0); |
| 312 | let ref_pic_list_1 = ref_pic_list_1.map(|pic| pic.0); |
| 313 | |
| 314 | let buf = bindings::VASliceParameterBufferH264 { |
| 315 | slice_data_size, |
| 316 | slice_data_offset, |
| 317 | slice_data_flag, |
| 318 | slice_data_bit_offset, |
| 319 | first_mb_in_slice, |
| 320 | slice_type, |
| 321 | direct_spatial_mv_pred_flag, |
| 322 | num_ref_idx_l0_active_minus1, |
| 323 | num_ref_idx_l1_active_minus1, |
| 324 | cabac_init_idc, |
| 325 | slice_qp_delta, |
| 326 | disable_deblocking_filter_idc, |
| 327 | slice_alpha_c0_offset_div2, |
| 328 | slice_beta_offset_div2, |
| 329 | RefPicList0: ref_pic_list_0, |
| 330 | RefPicList1: ref_pic_list_1, |
| 331 | luma_log2_weight_denom, |
| 332 | chroma_log2_weight_denom, |
| 333 | luma_weight_l0_flag, |
| 334 | luma_weight_l0, |
| 335 | luma_offset_l0, |
| 336 | chroma_weight_l0_flag, |
| 337 | chroma_weight_l0, |
| 338 | chroma_offset_l0, |
| 339 | luma_weight_l1_flag, |
| 340 | luma_weight_l1, |
| 341 | luma_offset_l1, |
| 342 | chroma_weight_l1_flag, |
| 343 | chroma_weight_l1, |
| 344 | chroma_offset_l1, |
| 345 | va_reserved: Default::default(), |
| 346 | }; |
| 347 | |
| 348 | self.0.push(buf); |
| 349 | } |
| 350 | |
| 351 | pub(crate) fn inner_mut(&mut self) -> &mut Vec<bindings::VASliceParameterBufferH264> { |
| 352 | &mut self.0 |
| 353 | } |
| 354 | |
| 355 | /// Returns the inner FFI type. Useful for testing purposes. |
| 356 | pub fn inner(&self) -> &Vec<bindings::VASliceParameterBufferH264> { |
| 357 | &self.0 |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | /// Wrapper over the `VAIQMatrixBufferH264` FFI type |
| 362 | pub struct IQMatrixBufferH264(Box<bindings::VAIQMatrixBufferH264>); |
| 363 | |
| 364 | impl IQMatrixBufferH264 { |
| 365 | /// Creates the wrapper. |
| 366 | pub fn new( |
| 367 | scaling_list4x4: [[u8; 16usize]; 6usize], |
| 368 | scaling_list8x8: [[u8; 64usize]; 2usize], |
| 369 | ) -> Self { |
| 370 | Self(Box::new(bindings::VAIQMatrixBufferH264 { |
| 371 | ScalingList4x4: scaling_list4x4, |
| 372 | ScalingList8x8: scaling_list8x8, |
| 373 | va_reserved: Default::default(), |
| 374 | })) |
| 375 | } |
| 376 | |
| 377 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferH264 { |
| 378 | self.0.as_mut() |
| 379 | } |
| 380 | |
| 381 | /// Returns the inner FFI type. Useful for testing purposes. |
| 382 | pub fn inner(&self) -> &bindings::VAIQMatrixBufferH264 { |
| 383 | self.0.as_ref() |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | /// Wrapper over the `seq_fields` bindgen field in `VAEncSequenceParameterBufferH264` |
| 388 | pub struct H264EncSeqFields(bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1); |
| 389 | |
| 390 | impl H264EncSeqFields { |
| 391 | #[allow(clippy::too_many_arguments)] |
| 392 | pub fn new( |
| 393 | chroma_format_idc: u32, |
| 394 | frame_mbs_only_flag: u32, |
| 395 | mb_adaptive_frame_field_flag: u32, |
| 396 | seq_scaling_matrix_present_flag: u32, |
| 397 | direct_8x8_inference_flag: u32, |
| 398 | log2_max_frame_num_minus4: u32, |
| 399 | pic_order_cnt_type: u32, |
| 400 | log2_max_pic_order_cnt_lsb_minus4: u32, |
| 401 | delta_pic_order_always_zero_flag: u32, |
| 402 | ) -> Self { |
| 403 | let _bitfield_1 = |
| 404 | bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( |
| 405 | chroma_format_idc, |
| 406 | frame_mbs_only_flag, |
| 407 | mb_adaptive_frame_field_flag, |
| 408 | seq_scaling_matrix_present_flag, |
| 409 | direct_8x8_inference_flag, |
| 410 | log2_max_frame_num_minus4, |
| 411 | pic_order_cnt_type, |
| 412 | log2_max_pic_order_cnt_lsb_minus4, |
| 413 | delta_pic_order_always_zero_flag, |
| 414 | ); |
| 415 | |
| 416 | Self(bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1 { |
| 417 | bits: bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1__bindgen_ty_1 { |
| 418 | _bitfield_align_1: Default::default(), |
| 419 | _bitfield_1, |
| 420 | __bindgen_padding_0: Default::default(), |
| 421 | }, |
| 422 | }) |
| 423 | } |
| 424 | |
| 425 | pub fn inner(&self) -> &bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_1 { |
| 426 | &self.0 |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | #[derive(Default)] |
| 431 | pub struct H264VuiFields(bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_2); |
| 432 | |
| 433 | impl H264VuiFields { |
| 434 | #[allow(clippy::too_many_arguments)] |
| 435 | pub fn new( |
| 436 | aspect_ratio_info_present_flag: u32, |
| 437 | timing_info_present_flag: u32, |
| 438 | bitstream_restriction_flag: u32, |
| 439 | log2_max_mv_length_horizontal: u32, |
| 440 | log2_max_mv_length_vertical: u32, |
| 441 | fixed_frame_rate_flag: u32, |
| 442 | low_delay_hrd_flag: u32, |
| 443 | motion_vectors_over_pic_boundaries_flag: u32, |
| 444 | ) -> Self { |
| 445 | let _bitfield_1 = |
| 446 | bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( |
| 447 | aspect_ratio_info_present_flag, |
| 448 | timing_info_present_flag, |
| 449 | bitstream_restriction_flag, |
| 450 | log2_max_mv_length_horizontal, |
| 451 | log2_max_mv_length_vertical, |
| 452 | fixed_frame_rate_flag, |
| 453 | low_delay_hrd_flag, |
| 454 | motion_vectors_over_pic_boundaries_flag, |
| 455 | Default::default(), |
| 456 | ); |
| 457 | |
| 458 | Self(bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_2 { |
| 459 | bits: bindings::_VAEncSequenceParameterBufferH264__bindgen_ty_2__bindgen_ty_1 { |
| 460 | _bitfield_align_1: Default::default(), |
| 461 | _bitfield_1, |
| 462 | }, |
| 463 | }) |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | #[derive(Default)] |
| 468 | pub struct H264EncFrameCropOffsets { |
| 469 | pub left: u32, |
| 470 | pub right: u32, |
| 471 | pub top: u32, |
| 472 | pub bottom: u32, |
| 473 | } |
| 474 | |
| 475 | impl H264EncFrameCropOffsets { |
| 476 | pub fn new( |
| 477 | frame_crop_left_offset: u32, |
| 478 | frame_crop_right_offset: u32, |
| 479 | frame_crop_top_offset: u32, |
| 480 | frame_crop_bottom_offset: u32, |
| 481 | ) -> Self { |
| 482 | Self { |
| 483 | left: frame_crop_left_offset, |
| 484 | right: frame_crop_right_offset, |
| 485 | top: frame_crop_top_offset, |
| 486 | bottom: frame_crop_bottom_offset, |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | pub struct EncSequenceParameterBufferH264(Box<bindings::VAEncSequenceParameterBufferH264>); |
| 492 | |
| 493 | impl EncSequenceParameterBufferH264 { |
| 494 | #[allow(clippy::too_many_arguments)] |
| 495 | pub fn new( |
| 496 | seq_parameter_set_id: u8, |
| 497 | level_idc: u8, |
| 498 | intra_period: u32, |
| 499 | intra_idr_period: u32, |
| 500 | ip_period: u32, |
| 501 | bits_per_second: u32, |
| 502 | max_num_ref_frames: u32, |
| 503 | picture_width_in_mbs: u16, |
| 504 | picture_height_in_mbs: u16, |
| 505 | seq_fields: &H264EncSeqFields, |
| 506 | bit_depth_luma_minus8: u8, |
| 507 | bit_depth_chroma_minus8: u8, |
| 508 | num_ref_frames_in_pic_order_cnt_cycle: u8, |
| 509 | offset_for_non_ref_pic: i32, |
| 510 | offset_for_top_to_bottom_field: i32, |
| 511 | offset_for_ref_frame: [i32; 256usize], |
| 512 | frame_crop: Option<H264EncFrameCropOffsets>, |
| 513 | vui_fields: Option<H264VuiFields>, |
| 514 | aspect_ratio_idc: u8, |
| 515 | sar_width: u32, |
| 516 | sar_height: u32, |
| 517 | num_units_in_tick: u32, |
| 518 | time_scale: u32, |
| 519 | ) -> Self { |
| 520 | let seq_fields = seq_fields.0; |
| 521 | |
| 522 | let frame_cropping_flag = if frame_crop.is_some() { 1 } else { 0 }; |
| 523 | let frame_crop = frame_crop.unwrap_or_default(); |
| 524 | |
| 525 | let frame_crop_left_offset = frame_crop.left; |
| 526 | let frame_crop_right_offset = frame_crop.right; |
| 527 | let frame_crop_top_offset = frame_crop.top; |
| 528 | let frame_crop_bottom_offset = frame_crop.bottom; |
| 529 | |
| 530 | let vui_parameters_present_flag = if vui_fields.is_some() { 1 } else { 0 }; |
| 531 | let vui_fields = vui_fields.unwrap_or_default().0; |
| 532 | |
| 533 | Self(Box::new(bindings::VAEncSequenceParameterBufferH264 { |
| 534 | seq_parameter_set_id, |
| 535 | level_idc, |
| 536 | intra_period, |
| 537 | intra_idr_period, |
| 538 | ip_period, |
| 539 | bits_per_second, |
| 540 | max_num_ref_frames, |
| 541 | picture_width_in_mbs, |
| 542 | picture_height_in_mbs, |
| 543 | seq_fields, |
| 544 | bit_depth_luma_minus8, |
| 545 | bit_depth_chroma_minus8, |
| 546 | num_ref_frames_in_pic_order_cnt_cycle, |
| 547 | offset_for_non_ref_pic, |
| 548 | offset_for_top_to_bottom_field, |
| 549 | offset_for_ref_frame, |
| 550 | frame_cropping_flag, |
| 551 | frame_crop_left_offset, |
| 552 | frame_crop_right_offset, |
| 553 | frame_crop_top_offset, |
| 554 | frame_crop_bottom_offset, |
| 555 | vui_parameters_present_flag, |
| 556 | vui_fields, |
| 557 | aspect_ratio_idc, |
| 558 | sar_width, |
| 559 | sar_height, |
| 560 | num_units_in_tick, |
| 561 | time_scale, |
| 562 | ..Default::default() |
| 563 | })) |
| 564 | } |
| 565 | |
| 566 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSequenceParameterBufferH264 { |
| 567 | self.0.as_mut() |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | pub struct H264EncPicFields(bindings::_VAEncPictureParameterBufferH264__bindgen_ty_1); |
| 572 | |
| 573 | impl H264EncPicFields { |
| 574 | #[allow(clippy::too_many_arguments)] |
| 575 | pub fn new( |
| 576 | idr_pic_flag: u32, |
| 577 | reference_pic_flag: u32, |
| 578 | entropy_coding_mode_flag: u32, |
| 579 | weighted_pred_flag: u32, |
| 580 | weighted_bipred_idc: u32, |
| 581 | constrained_intra_pred_flag: u32, |
| 582 | transform_8x8_mode_flag: u32, |
| 583 | deblocking_filter_control_present_flag: u32, |
| 584 | redundant_pic_cnt_present_flag: u32, |
| 585 | pic_order_present_flag: u32, |
| 586 | pic_scaling_matrix_present_flag: u32, |
| 587 | ) -> Self { |
| 588 | let _bitfield_1 = |
| 589 | bindings::_VAEncPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( |
| 590 | idr_pic_flag, |
| 591 | reference_pic_flag, |
| 592 | entropy_coding_mode_flag, |
| 593 | weighted_pred_flag, |
| 594 | weighted_bipred_idc, |
| 595 | constrained_intra_pred_flag, |
| 596 | transform_8x8_mode_flag, |
| 597 | deblocking_filter_control_present_flag, |
| 598 | redundant_pic_cnt_present_flag, |
| 599 | pic_order_present_flag, |
| 600 | pic_scaling_matrix_present_flag, |
| 601 | ); |
| 602 | |
| 603 | Self(bindings::_VAEncPictureParameterBufferH264__bindgen_ty_1 { |
| 604 | bits: bindings::_VAEncPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1 { |
| 605 | _bitfield_align_1: Default::default(), |
| 606 | _bitfield_1, |
| 607 | __bindgen_padding_0: Default::default(), |
| 608 | }, |
| 609 | }) |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | pub struct EncPictureParameterBufferH264(Box<bindings::VAEncPictureParameterBufferH264>); |
| 614 | |
| 615 | impl EncPictureParameterBufferH264 { |
| 616 | #[allow(clippy::too_many_arguments)] |
| 617 | pub fn new( |
| 618 | curr_pic: PictureH264, |
| 619 | reference_frames: [PictureH264; 16usize], |
| 620 | coded_buf: bindings::VABufferID, |
| 621 | pic_parameter_set_id: u8, |
| 622 | seq_parameter_set_id: u8, |
| 623 | last_picture: u8, |
| 624 | frame_num: u16, |
| 625 | pic_init_qp: u8, |
| 626 | num_ref_idx_l0_active_minus1: u8, |
| 627 | num_ref_idx_l1_active_minus1: u8, |
| 628 | chroma_qp_index_offset: i8, |
| 629 | second_chroma_qp_index_offset: i8, |
| 630 | pic_fields: &H264EncPicFields, |
| 631 | ) -> Self { |
| 632 | let reference_frames = (0..16usize) |
| 633 | .map(|i| reference_frames[i].0) |
| 634 | .collect::<Vec<_>>() |
| 635 | .try_into() |
| 636 | // try_into is guaranteed to work because the iterator and target array have the same |
| 637 | // size. |
| 638 | .unwrap(); |
| 639 | |
| 640 | let pic_fields = pic_fields.0; |
| 641 | |
| 642 | Self(Box::new(bindings::_VAEncPictureParameterBufferH264 { |
| 643 | CurrPic: curr_pic.0, |
| 644 | ReferenceFrames: reference_frames, |
| 645 | coded_buf, |
| 646 | pic_parameter_set_id, |
| 647 | seq_parameter_set_id, |
| 648 | last_picture, |
| 649 | frame_num, |
| 650 | pic_init_qp, |
| 651 | num_ref_idx_l0_active_minus1, |
| 652 | num_ref_idx_l1_active_minus1, |
| 653 | chroma_qp_index_offset, |
| 654 | second_chroma_qp_index_offset, |
| 655 | pic_fields, |
| 656 | ..Default::default() |
| 657 | })) |
| 658 | } |
| 659 | |
| 660 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferH264 { |
| 661 | self.0.as_mut() |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | pub struct EncSliceParameterBufferH264(Box<bindings::VAEncSliceParameterBufferH264>); |
| 666 | |
| 667 | impl EncSliceParameterBufferH264 { |
| 668 | #[allow(clippy::too_many_arguments)] |
| 669 | pub fn new( |
| 670 | macroblock_address: u32, |
| 671 | num_macroblocks: u32, |
| 672 | macroblock_info: bindings::VABufferID, |
| 673 | slice_type: u8, |
| 674 | pic_parameter_set_id: u8, |
| 675 | idr_pic_id: u16, |
| 676 | pic_order_cnt_lsb: u16, |
| 677 | delta_pic_order_cnt_bottom: i32, |
| 678 | delta_pic_order_cnt: [i32; 2usize], |
| 679 | direct_spatial_mv_pred_flag: u8, |
| 680 | num_ref_idx_active_override_flag: u8, |
| 681 | num_ref_idx_l0_active_minus1: u8, |
| 682 | num_ref_idx_l1_active_minus1: u8, |
| 683 | ref_pic_list_0: [PictureH264; 32usize], |
| 684 | ref_pic_list_1: [PictureH264; 32usize], |
| 685 | luma_log2_weight_denom: u8, |
| 686 | chroma_log2_weight_denom: u8, |
| 687 | luma_weight_l0_flag: u8, |
| 688 | luma_weight_l0: [i16; 32usize], |
| 689 | luma_offset_l0: [i16; 32usize], |
| 690 | chroma_weight_l0_flag: u8, |
| 691 | chroma_weight_l0: [[i16; 2usize]; 32usize], |
| 692 | chroma_offset_l0: [[i16; 2usize]; 32usize], |
| 693 | luma_weight_l1_flag: u8, |
| 694 | luma_weight_l1: [i16; 32usize], |
| 695 | luma_offset_l1: [i16; 32usize], |
| 696 | chroma_weight_l1_flag: u8, |
| 697 | chroma_weight_l1: [[i16; 2usize]; 32usize], |
| 698 | chroma_offset_l1: [[i16; 2usize]; 32usize], |
| 699 | cabac_init_idc: u8, |
| 700 | slice_qp_delta: i8, |
| 701 | disable_deblocking_filter_idc: u8, |
| 702 | slice_alpha_c0_offset_div2: i8, |
| 703 | slice_beta_offset_div2: i8, |
| 704 | ) -> Self { |
| 705 | let ref_pic_list_0 = ref_pic_list_0.map(|pic| pic.0); |
| 706 | let ref_pic_list_1 = ref_pic_list_1.map(|pic| pic.0); |
| 707 | |
| 708 | Self(Box::new(bindings::VAEncSliceParameterBufferH264 { |
| 709 | macroblock_address, |
| 710 | num_macroblocks, |
| 711 | macroblock_info, |
| 712 | slice_type, |
| 713 | pic_parameter_set_id, |
| 714 | idr_pic_id, |
| 715 | pic_order_cnt_lsb, |
| 716 | delta_pic_order_cnt_bottom, |
| 717 | delta_pic_order_cnt, |
| 718 | direct_spatial_mv_pred_flag, |
| 719 | num_ref_idx_active_override_flag, |
| 720 | num_ref_idx_l0_active_minus1, |
| 721 | num_ref_idx_l1_active_minus1, |
| 722 | RefPicList0: ref_pic_list_0, |
| 723 | RefPicList1: ref_pic_list_1, |
| 724 | luma_log2_weight_denom, |
| 725 | chroma_log2_weight_denom, |
| 726 | luma_weight_l0_flag, |
| 727 | luma_weight_l0, |
| 728 | luma_offset_l0, |
| 729 | chroma_weight_l0_flag, |
| 730 | chroma_weight_l0, |
| 731 | chroma_offset_l0, |
| 732 | luma_weight_l1_flag, |
| 733 | luma_weight_l1, |
| 734 | luma_offset_l1, |
| 735 | chroma_weight_l1_flag, |
| 736 | chroma_weight_l1, |
| 737 | chroma_offset_l1, |
| 738 | cabac_init_idc, |
| 739 | slice_qp_delta, |
| 740 | disable_deblocking_filter_idc, |
| 741 | slice_alpha_c0_offset_div2, |
| 742 | slice_beta_offset_div2, |
| 743 | ..Default::default() |
| 744 | })) |
| 745 | } |
| 746 | |
| 747 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSliceParameterBufferH264 { |
| 748 | self.0.as_mut() |
| 749 | } |
| 750 | |
| 751 | /// Returns the inner FFI type. Useful for testing purposes. |
| 752 | pub fn inner(&self) -> &bindings::VAEncSliceParameterBufferH264 { |
| 753 | self.0.as_ref() |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | pub struct H264EncMacroblockInfo(bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1); |
| 758 | |
| 759 | impl H264EncMacroblockInfo { |
| 760 | pub fn new_intra(pred_avail_override_flag: u32, pred_avail_flags: u32) -> Self { |
| 761 | let _bitfield_1 = |
| 762 | bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(pred_avail_override_flag, pred_avail_flags); |
| 763 | |
| 764 | Self(bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1 { |
| 765 | intra_fields: bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_1 { |
| 766 | bits: bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { |
| 767 | _bitfield_align_1: Default::default(), |
| 768 | _bitfield_1, |
| 769 | __bindgen_padding_0: Default::default(), |
| 770 | } |
| 771 | } |
| 772 | }) |
| 773 | } |
| 774 | |
| 775 | pub fn new_inter() -> Self { |
| 776 | Self(bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1 { |
| 777 | inter_fields: bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_2 { |
| 778 | bits: bindings::_VAEncMacroblockParameterBufferH264__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1 { |
| 779 | reserved: Default::default() |
| 780 | } |
| 781 | } |
| 782 | }) |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | pub struct EncMacroblockParameterBufferH264(Box<bindings::VAEncMacroblockParameterBufferH264>); |
| 787 | |
| 788 | impl EncMacroblockParameterBufferH264 { |
| 789 | pub fn new(qp: u8, info: &H264EncMacroblockInfo) -> Self { |
| 790 | let info = info.0; |
| 791 | |
| 792 | Self(Box::new(bindings::VAEncMacroblockParameterBufferH264 { |
| 793 | qp, |
| 794 | info, |
| 795 | ..Default::default() |
| 796 | })) |
| 797 | } |
| 798 | |
| 799 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncMacroblockParameterBufferH264 { |
| 800 | self.0.as_mut() |
| 801 | } |
| 802 | |
| 803 | /// Returns the inner FFI type. Useful for testing purposes. |
| 804 | pub fn inner(&self) -> &bindings::VAEncMacroblockParameterBufferH264 { |
| 805 | self.0.as_ref() |
| 806 | } |
| 807 | } |