1 // Copyright 2022 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 use crate::bindings; 6 7 /// Abstraction over `VABufferType`s. 8 pub enum BufferType { 9 /// Abstraction over `VAPictureParameterBufferType`. Needed for MPEG2, VP8, VP9, H264. 10 PictureParameter(PictureParameter), 11 /// Abstraction over `VASliceParameterBufferType`. Needed for MPEG2, VP8, VP9, H264. 12 SliceParameter(SliceParameter), 13 /// Abstraction over `VAIQMatrixBufferType`. Needed for VP8, H264. 14 IQMatrix(IQMatrix), 15 /// Abstraction over `VAProbabilityDataBufferType`. Needed for VP8. 16 Probability(ProbabilityDataBufferVP8), 17 /// Abstraction over `VASliceDataBufferType`. Needed for VP9, H264. 18 SliceData(Vec<u8>), 19 } 20 21 impl BufferType { 22 /// Returns the inner FFI buffer type. inner(&self) -> bindings::VABufferType::Type23 pub(crate) fn inner(&self) -> bindings::VABufferType::Type { 24 match self { 25 BufferType::PictureParameter(_) => bindings::VABufferType::VAPictureParameterBufferType, 26 BufferType::SliceParameter(_) => bindings::VABufferType::VASliceParameterBufferType, 27 BufferType::IQMatrix(_) => bindings::VABufferType::VAIQMatrixBufferType, 28 BufferType::Probability(_) => bindings::VABufferType::VAProbabilityBufferType, 29 BufferType::SliceData { .. } => bindings::VABufferType::VASliceDataBufferType, 30 } 31 } 32 } 33 34 /// Wrapper over the `picture_coding_extension` bindgen field in `VAPictureParameterBufferMPEG2`. 35 pub struct MPEG2PictureCodingExtension(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1); 36 37 impl MPEG2PictureCodingExtension { 38 /// Creates the bindgen field. new( intra_dc_precision: u32, picture_structure: u32, top_field_first: u32, frame_pred_frame_dct: u32, concealment_motion_vectors: u32, q_scale_type: u32, intra_vlc_format: u32, alternate_scan: u32, repeat_first_field: u32, progressive_frame: u32, is_first_field: u32, ) -> Self39 pub fn new( 40 intra_dc_precision: u32, 41 picture_structure: u32, 42 top_field_first: u32, 43 frame_pred_frame_dct: u32, 44 concealment_motion_vectors: u32, 45 q_scale_type: u32, 46 intra_vlc_format: u32, 47 alternate_scan: u32, 48 repeat_first_field: u32, 49 progressive_frame: u32, 50 is_first_field: u32, 51 ) -> Self { 52 let _bitfield_1 = 53 bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( 54 intra_dc_precision, 55 picture_structure, 56 top_field_first, 57 frame_pred_frame_dct, 58 concealment_motion_vectors, 59 q_scale_type, 60 intra_vlc_format, 61 alternate_scan, 62 repeat_first_field, 63 progressive_frame, 64 is_first_field, 65 ); 66 67 Self(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 { 68 bits: bindings::_VAPictureParameterBufferMPEG2__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. inner(&mut self) -> &bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_177 pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 { 78 &self.0 79 } 80 } 81 82 /// Wrapper over the `PictureParameterBufferMPEG2` FFI type. 83 pub struct PictureParameterBufferMPEG2(Box<bindings::VAPictureParameterBufferMPEG2>); 84 85 impl PictureParameterBufferMPEG2 { 86 /// Creates the wrapper. new( horizontal_size: u16, vertical_size: u16, forward_reference_picture: bindings::VASurfaceID, backward_reference_picture: bindings::VASurfaceID, picture_coding_type: i32, f_code: i32, picture_coding_extension: &MPEG2PictureCodingExtension, ) -> Self87 pub fn new( 88 horizontal_size: u16, 89 vertical_size: u16, 90 forward_reference_picture: bindings::VASurfaceID, 91 backward_reference_picture: bindings::VASurfaceID, 92 picture_coding_type: i32, 93 f_code: i32, 94 picture_coding_extension: &MPEG2PictureCodingExtension, 95 ) -> Self { 96 let picture_coding_extension = picture_coding_extension.0; 97 98 Self(Box::new(bindings::VAPictureParameterBufferMPEG2 { 99 horizontal_size, 100 vertical_size, 101 forward_reference_picture, 102 backward_reference_picture, 103 picture_coding_type, 104 f_code, 105 picture_coding_extension, 106 va_reserved: Default::default(), 107 })) 108 } 109 inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferMPEG2110 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferMPEG2 { 111 self.0.as_mut() 112 } 113 114 /// Returns the inner FFI type. Useful for testing purposes. inner(&mut self) -> &bindings::VAPictureParameterBufferMPEG2115 pub fn inner(&mut self) -> &bindings::VAPictureParameterBufferMPEG2 { 116 self.0.as_ref() 117 } 118 } 119 120 /// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferVP8`. 121 pub struct VP8PicFields(bindings::_VAPictureParameterBufferVP8__bindgen_ty_1); 122 123 impl VP8PicFields { 124 /// Creates the bindgen field new( key_frame: u32, version: u32, segmentation_enabled: u32, update_mb_segmentation_map: u32, update_segment_feature_data: u32, filter_type: u32, sharpness_level: u32, loop_filter_adj_enable: u32, mode_ref_lf_delta_update: u32, sign_bias_golden: u32, sign_bias_alternate: u32, mb_no_coeff_skip: u32, loop_filter_disable: u32, ) -> Self125 pub fn new( 126 key_frame: u32, 127 version: u32, 128 segmentation_enabled: u32, 129 update_mb_segmentation_map: u32, 130 update_segment_feature_data: u32, 131 filter_type: u32, 132 sharpness_level: u32, 133 loop_filter_adj_enable: u32, 134 mode_ref_lf_delta_update: u32, 135 sign_bias_golden: u32, 136 sign_bias_alternate: u32, 137 mb_no_coeff_skip: u32, 138 loop_filter_disable: u32, 139 ) -> Self { 140 let _bitfield_1 = 141 bindings::_VAPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( 142 key_frame, 143 version, 144 segmentation_enabled, 145 update_mb_segmentation_map, 146 update_segment_feature_data, 147 filter_type, 148 sharpness_level, 149 loop_filter_adj_enable, 150 mode_ref_lf_delta_update, 151 sign_bias_golden, 152 sign_bias_alternate, 153 mb_no_coeff_skip, 154 loop_filter_disable, 155 ); 156 157 Self(bindings::_VAPictureParameterBufferVP8__bindgen_ty_1 { 158 bits: bindings::_VAPictureParameterBufferVP8__bindgen_ty_1__bindgen_ty_1 { 159 _bitfield_align_1: Default::default(), 160 _bitfield_1, 161 __bindgen_padding_0: Default::default(), 162 }, 163 }) 164 } 165 166 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::_VAPictureParameterBufferVP8__bindgen_ty_1167 pub fn inner(&self) -> &bindings::_VAPictureParameterBufferVP8__bindgen_ty_1 { 168 &self.0 169 } 170 } 171 172 /// Wrapper over the `VABoolCoderContextVPX` FFI type. 173 pub struct BoolCoderContextVPX(bindings::VABoolCoderContextVPX); 174 175 impl BoolCoderContextVPX { 176 /// Creates the wrapper new(range: u8, value: u8, count: u8) -> Self177 pub fn new(range: u8, value: u8, count: u8) -> Self { 178 Self(bindings::VABoolCoderContextVPX { 179 range, 180 value, 181 count, 182 }) 183 } 184 } 185 186 /// Wrapper over the `PictureParameterBufferVP8` FFI type. 187 pub struct PictureParameterBufferVP8(Box<bindings::VAPictureParameterBufferVP8>); 188 189 impl PictureParameterBufferVP8 { 190 /// Creates the wrapper new( frame_width: u32, frame_height: u32, last_ref_frame: bindings::VASurfaceID, golden_ref_frame: bindings::VASurfaceID, alt_ref_frame: bindings::VASurfaceID, pic_fields: &VP8PicFields, mb_segment_tree_probs: [u8; 3usize], loop_filter_level: [u8; 4usize], loop_filter_deltas_ref_frame: [i8; 4usize], loop_filter_deltas_mode: [i8; 4usize], prob_skip_false: u8, prob_intra: u8, prob_last: u8, prob_gf: u8, y_mode_probs: [u8; 4usize], uv_mode_probs: [u8; 3usize], mv_probs: [[u8; 19usize]; 2usize], bool_coder_ctx: &BoolCoderContextVPX, ) -> Self191 pub fn new( 192 frame_width: u32, 193 frame_height: u32, 194 last_ref_frame: bindings::VASurfaceID, 195 golden_ref_frame: bindings::VASurfaceID, 196 alt_ref_frame: bindings::VASurfaceID, 197 pic_fields: &VP8PicFields, 198 mb_segment_tree_probs: [u8; 3usize], 199 loop_filter_level: [u8; 4usize], 200 loop_filter_deltas_ref_frame: [i8; 4usize], 201 loop_filter_deltas_mode: [i8; 4usize], 202 prob_skip_false: u8, 203 prob_intra: u8, 204 prob_last: u8, 205 prob_gf: u8, 206 y_mode_probs: [u8; 4usize], 207 uv_mode_probs: [u8; 3usize], 208 mv_probs: [[u8; 19usize]; 2usize], 209 bool_coder_ctx: &BoolCoderContextVPX, 210 ) -> Self { 211 let pic_fields = pic_fields.0; 212 let bool_coder_ctx = bool_coder_ctx.0; 213 214 Self(Box::new(bindings::VAPictureParameterBufferVP8 { 215 frame_width, 216 frame_height, 217 last_ref_frame, 218 golden_ref_frame, 219 alt_ref_frame, 220 out_of_loop_frame: bindings::constants::VA_INVALID_SURFACE, 221 pic_fields, 222 mb_segment_tree_probs, 223 loop_filter_level, 224 loop_filter_deltas_ref_frame, 225 loop_filter_deltas_mode, 226 prob_skip_false, 227 prob_intra, 228 prob_last, 229 prob_gf, 230 y_mode_probs, 231 uv_mode_probs, 232 mv_probs, 233 bool_coder_ctx, 234 va_reserved: Default::default(), 235 })) 236 } 237 inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferVP8238 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferVP8 { 239 self.0.as_mut() 240 } 241 242 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VAPictureParameterBufferVP8243 pub fn inner(&self) -> &bindings::VAPictureParameterBufferVP8 { 244 self.0.as_ref() 245 } 246 } 247 248 /// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferVP9`. 249 pub struct VP9PicFields(bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1); 250 251 impl VP9PicFields { 252 /// Creates the bindgen field new( subsampling_x: u32, subsampling_y: u32, frame_type: u32, show_frame: u32, error_resilient_mode: u32, intra_only: u32, allow_high_precision_mv: u32, mcomp_filter_type: u32, frame_parallel_decoding_mode: u32, reset_frame_context: u32, refresh_frame_context: u32, frame_context_idx: u32, segmentation_enabled: u32, segmentation_temporal_update: u32, segmentation_update_map: u32, last_ref_frame: u32, last_ref_frame_sign_bias: u32, golden_ref_frame: u32, golden_ref_frame_sign_bias: u32, alt_ref_frame: u32, alt_ref_frame_sign_bias: u32, lossless_flag: u32, ) -> Self253 pub fn new( 254 subsampling_x: u32, 255 subsampling_y: u32, 256 frame_type: u32, 257 show_frame: u32, 258 error_resilient_mode: u32, 259 intra_only: u32, 260 allow_high_precision_mv: u32, 261 mcomp_filter_type: u32, 262 frame_parallel_decoding_mode: u32, 263 reset_frame_context: u32, 264 refresh_frame_context: u32, 265 frame_context_idx: u32, 266 segmentation_enabled: u32, 267 segmentation_temporal_update: u32, 268 segmentation_update_map: u32, 269 last_ref_frame: u32, 270 last_ref_frame_sign_bias: u32, 271 golden_ref_frame: u32, 272 golden_ref_frame_sign_bias: u32, 273 alt_ref_frame: u32, 274 alt_ref_frame_sign_bias: u32, 275 lossless_flag: u32, 276 ) -> Self { 277 let _bitfield_1 = 278 bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( 279 subsampling_x, 280 subsampling_y, 281 frame_type, 282 show_frame, 283 error_resilient_mode, 284 intra_only, 285 allow_high_precision_mv, 286 mcomp_filter_type, 287 frame_parallel_decoding_mode, 288 reset_frame_context, 289 refresh_frame_context, 290 frame_context_idx, 291 segmentation_enabled, 292 segmentation_temporal_update, 293 segmentation_update_map, 294 last_ref_frame, 295 last_ref_frame_sign_bias, 296 golden_ref_frame, 297 golden_ref_frame_sign_bias, 298 alt_ref_frame, 299 alt_ref_frame_sign_bias, 300 lossless_flag, 301 ); 302 303 Self(bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1 { 304 bits: bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1 { 305 _bitfield_align_1: Default::default(), 306 _bitfield_1, 307 }, 308 }) 309 } 310 311 /// Returns the inner FFI type. Useful for testing purposes. inner(&mut self) -> &bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1312 pub fn inner(&mut self) -> &bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1 { 313 &self.0 314 } 315 } 316 317 /// Wrapper over the `PictureParameterBufferVP9` FFI type. 318 pub struct PictureParameterBufferVP9(Box<bindings::VADecPictureParameterBufferVP9>); 319 320 impl PictureParameterBufferVP9 { 321 /// Creates the wrapper new( frame_width: u16, frame_height: u16, reference_frames: [bindings::VASurfaceID; 8], pic_fields: &VP9PicFields, filter_level: u8, sharpness_level: u8, log2_tile_rows: u8, log2_tile_columns: u8, frame_header_length_in_bytes: u8, first_partition_size: u16, mb_segment_tree_probs: [u8; 7usize], segment_pred_probs: [u8; 3usize], profile: u8, bit_depth: u8, ) -> Self322 pub fn new( 323 frame_width: u16, 324 frame_height: u16, 325 reference_frames: [bindings::VASurfaceID; 8], 326 pic_fields: &VP9PicFields, 327 filter_level: u8, 328 sharpness_level: u8, 329 log2_tile_rows: u8, 330 log2_tile_columns: u8, 331 frame_header_length_in_bytes: u8, 332 first_partition_size: u16, 333 mb_segment_tree_probs: [u8; 7usize], 334 segment_pred_probs: [u8; 3usize], 335 profile: u8, 336 bit_depth: u8, 337 ) -> Self { 338 let pic_fields = pic_fields.0; 339 340 Self(Box::new(bindings::VADecPictureParameterBufferVP9 { 341 frame_width, 342 frame_height, 343 reference_frames, 344 pic_fields, 345 filter_level, 346 sharpness_level, 347 log2_tile_rows, 348 log2_tile_columns, 349 frame_header_length_in_bytes, 350 first_partition_size, 351 mb_segment_tree_probs, 352 segment_pred_probs, 353 profile, 354 bit_depth, 355 va_reserved: Default::default(), 356 })) 357 } 358 inner_mut(&mut self) -> &mut bindings::VADecPictureParameterBufferVP9359 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VADecPictureParameterBufferVP9 { 360 self.0.as_mut() 361 } 362 363 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VADecPictureParameterBufferVP9364 pub fn inner(&self) -> &bindings::VADecPictureParameterBufferVP9 { 365 self.0.as_ref() 366 } 367 } 368 369 /// Wrapper over the `VAPictureH264` FFI type. 370 pub struct PictureH264(bindings::VAPictureH264); 371 372 impl PictureH264 { 373 /// Creates the wrapper new( picture_id: bindings::VASurfaceID, frame_idx: u32, flags: u32, top_field_order_cnt: i32, bottom_field_order_cnt: i32, ) -> Self374 pub fn new( 375 picture_id: bindings::VASurfaceID, 376 frame_idx: u32, 377 flags: u32, 378 top_field_order_cnt: i32, 379 bottom_field_order_cnt: i32, 380 ) -> Self { 381 Self(bindings::VAPictureH264 { 382 picture_id, 383 frame_idx, 384 flags, 385 TopFieldOrderCnt: top_field_order_cnt, 386 BottomFieldOrderCnt: bottom_field_order_cnt, 387 va_reserved: Default::default(), 388 }) 389 } 390 } 391 392 /// Wrapper over the `seq_fields` bindgen field in `VAPictureParameterBufferH264`. 393 pub struct H264SeqFields(bindings::_VAPictureParameterBufferH264__bindgen_ty_1); 394 395 impl H264SeqFields { 396 /// Creates the bindgen field new( chroma_format_idc: u32, residual_colour_transform_flag: u32, gaps_in_frame_num_value_allowed_flag: u32, frame_mbs_only_flag: u32, mb_adaptive_frame_field_flag: u32, direct_8x8_inference_flag: u32, min_luma_bi_pred_size8x8: u32, log2_max_frame_num_minus4: u32, pic_order_cnt_type: u32, log2_max_pic_order_cnt_lsb_minus4: u32, delta_pic_order_always_zero_flag: u32, ) -> Self397 pub fn new( 398 chroma_format_idc: u32, 399 residual_colour_transform_flag: u32, 400 gaps_in_frame_num_value_allowed_flag: u32, 401 frame_mbs_only_flag: u32, 402 mb_adaptive_frame_field_flag: u32, 403 direct_8x8_inference_flag: u32, 404 min_luma_bi_pred_size8x8: u32, 405 log2_max_frame_num_minus4: u32, 406 pic_order_cnt_type: u32, 407 log2_max_pic_order_cnt_lsb_minus4: u32, 408 delta_pic_order_always_zero_flag: u32, 409 ) -> Self { 410 let _bitfield_1 = 411 bindings::_VAPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( 412 chroma_format_idc, 413 residual_colour_transform_flag, 414 gaps_in_frame_num_value_allowed_flag, 415 frame_mbs_only_flag, 416 mb_adaptive_frame_field_flag, 417 direct_8x8_inference_flag, 418 min_luma_bi_pred_size8x8, 419 log2_max_frame_num_minus4, 420 pic_order_cnt_type, 421 log2_max_pic_order_cnt_lsb_minus4, 422 delta_pic_order_always_zero_flag, 423 ); 424 425 Self(bindings::_VAPictureParameterBufferH264__bindgen_ty_1 { 426 bits: bindings::_VAPictureParameterBufferH264__bindgen_ty_1__bindgen_ty_1 { 427 _bitfield_align_1: Default::default(), 428 _bitfield_1, 429 __bindgen_padding_0: Default::default(), 430 }, 431 }) 432 } 433 434 /// Returns the inner FFI type. Useful for testing purposes. inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_1435 pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_1 { 436 &self.0 437 } 438 } 439 440 /// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferH264`. 441 pub struct H264PicFields(bindings::_VAPictureParameterBufferH264__bindgen_ty_2); 442 443 impl H264PicFields { 444 /// Creates the bindgen field new( entropy_coding_mode_flag: u32, weighted_pred_flag: u32, weighted_bipred_idc: u32, transform_8x8_mode_flag: u32, field_pic_flag: u32, constrained_intra_pred_flag: u32, pic_order_present_flag: u32, deblocking_filter_control_present_flag: u32, redundant_pic_cnt_present_flag: u32, reference_pic_flag: u32, ) -> Self445 pub fn new( 446 entropy_coding_mode_flag: u32, 447 weighted_pred_flag: u32, 448 weighted_bipred_idc: u32, 449 transform_8x8_mode_flag: u32, 450 field_pic_flag: u32, 451 constrained_intra_pred_flag: u32, 452 pic_order_present_flag: u32, 453 deblocking_filter_control_present_flag: u32, 454 redundant_pic_cnt_present_flag: u32, 455 reference_pic_flag: u32, 456 ) -> Self { 457 let _bitfield_1 = 458 bindings::_VAPictureParameterBufferH264__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( 459 entropy_coding_mode_flag, 460 weighted_pred_flag, 461 weighted_bipred_idc, 462 transform_8x8_mode_flag, 463 field_pic_flag, 464 constrained_intra_pred_flag, 465 pic_order_present_flag, 466 deblocking_filter_control_present_flag, 467 redundant_pic_cnt_present_flag, 468 reference_pic_flag, 469 ); 470 471 Self(bindings::_VAPictureParameterBufferH264__bindgen_ty_2 { 472 bits: bindings::_VAPictureParameterBufferH264__bindgen_ty_2__bindgen_ty_1 { 473 _bitfield_align_1: Default::default(), 474 _bitfield_1, 475 __bindgen_padding_0: Default::default(), 476 }, 477 }) 478 } 479 480 /// Returns the inner FFI type. Useful for testing purposes. inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_2481 pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferH264__bindgen_ty_2 { 482 &self.0 483 } 484 } 485 486 /// A wrapper over `VAPictureParameterBufferH264` FFI type 487 pub struct PictureParameterBufferH264(Box<bindings::VAPictureParameterBufferH264>); 488 489 impl PictureParameterBufferH264 { 490 /// Creates the wrapper new( curr_pic: PictureH264, reference_frames: [PictureH264; 16], picture_width_in_mbs_minus1: u16, picture_height_in_mbs_minus1: u16, bit_depth_luma_minus8: u8, bit_depth_chroma_minus8: u8, num_ref_frames: u8, seq_fields: &H264SeqFields, num_slice_groups_minus1: u8, slice_group_map_type: u8, slice_group_change_rate_minus1: u16, pic_init_qp_minus26: i8, pic_init_qs_minus26: i8, chroma_qp_index_offset: i8, second_chroma_qp_index_offset: i8, pic_fields: &H264PicFields, frame_num: u16, ) -> Self491 pub fn new( 492 curr_pic: PictureH264, 493 reference_frames: [PictureH264; 16], 494 picture_width_in_mbs_minus1: u16, 495 picture_height_in_mbs_minus1: u16, 496 bit_depth_luma_minus8: u8, 497 bit_depth_chroma_minus8: u8, 498 num_ref_frames: u8, 499 seq_fields: &H264SeqFields, 500 num_slice_groups_minus1: u8, 501 slice_group_map_type: u8, 502 slice_group_change_rate_minus1: u16, 503 pic_init_qp_minus26: i8, 504 pic_init_qs_minus26: i8, 505 chroma_qp_index_offset: i8, 506 second_chroma_qp_index_offset: i8, 507 pic_fields: &H264PicFields, 508 frame_num: u16, 509 ) -> Self { 510 let reference_frames = (0..16usize) 511 .map(|i| reference_frames[i].0) 512 .collect::<Vec<_>>() 513 .try_into() 514 // try_into is guaranteed to work because the iterator and target array have the same 515 // size. 516 .unwrap(); 517 518 let seq_fields = seq_fields.0; 519 let pic_fields = pic_fields.0; 520 521 Self(Box::new(bindings::VAPictureParameterBufferH264 { 522 CurrPic: curr_pic.0, 523 ReferenceFrames: reference_frames, 524 picture_width_in_mbs_minus1, 525 picture_height_in_mbs_minus1, 526 bit_depth_luma_minus8, 527 bit_depth_chroma_minus8, 528 num_ref_frames, 529 seq_fields, 530 num_slice_groups_minus1, 531 slice_group_map_type, 532 slice_group_change_rate_minus1, 533 pic_init_qp_minus26, 534 pic_init_qs_minus26, 535 chroma_qp_index_offset, 536 second_chroma_qp_index_offset, 537 pic_fields, 538 frame_num, 539 va_reserved: Default::default(), 540 })) 541 } 542 inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferH264543 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferH264 { 544 self.0.as_mut() 545 } 546 547 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VAPictureParameterBufferH264548 pub fn inner(&self) -> &bindings::VAPictureParameterBufferH264 { 549 self.0.as_ref() 550 } 551 } 552 553 /// Abstraction over the `PictureParameterBuffer` types we support. 554 pub enum PictureParameter { 555 /// Wrapper over VAPictureParameterBufferMPEG2. 556 MPEG2(PictureParameterBufferMPEG2), 557 /// Wrapper over VAPictureParameterBufferVP8. 558 VP8(PictureParameterBufferVP8), 559 /// Wrapper over VAPictureParameterBufferVP9. 560 VP9(PictureParameterBufferVP9), 561 /// Wrapper over VAPictureParameterBufferH264. 562 H264(PictureParameterBufferH264), 563 } 564 565 /// Wrapper over the `VASliceParameterBufferMPEG2` FFI type. 566 pub struct SliceParameterBufferMPEG2(Box<bindings::VASliceParameterBufferMPEG2>); 567 568 impl SliceParameterBufferMPEG2 { 569 /// Creates the wrapper. new( slice_data_size: u32, slice_data_offset: u32, slice_data_flag: u32, macroblock_offset: u32, slice_horizontal_position: u32, slice_vertical_position: u32, quantiser_scale_code: i32, intra_slice_flag: i32, ) -> Self570 pub fn new( 571 slice_data_size: u32, 572 slice_data_offset: u32, 573 slice_data_flag: u32, 574 macroblock_offset: u32, 575 slice_horizontal_position: u32, 576 slice_vertical_position: u32, 577 quantiser_scale_code: i32, 578 intra_slice_flag: i32, 579 ) -> Self { 580 Self(Box::new(bindings::VASliceParameterBufferMPEG2 { 581 slice_data_size, 582 slice_data_offset, 583 slice_data_flag, 584 macroblock_offset, 585 slice_horizontal_position, 586 slice_vertical_position, 587 quantiser_scale_code, 588 intra_slice_flag, 589 va_reserved: Default::default(), 590 })) 591 } 592 inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferMPEG2593 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferMPEG2 { 594 self.0.as_mut() 595 } 596 597 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VASliceParameterBufferMPEG2598 pub fn inner(&self) -> &bindings::VASliceParameterBufferMPEG2 { 599 self.0.as_ref() 600 } 601 } 602 603 /// Abstraction over the `SliceParameterBuffer` types we support 604 pub enum SliceParameter { 605 /// Wrapper over VASliceParameterBufferMPEG2 606 MPEG2(SliceParameterBufferMPEG2), 607 /// Wrapper over VASliceParameterBufferVP8 608 VP8(SliceParameterBufferVP8), 609 /// Wrapper over VASliceParameterBufferVP9 610 VP9(SliceParameterBufferVP9), 611 /// Wrapper over VASliceParameterBufferH264 612 H264(SliceParameterBufferH264), 613 } 614 615 /// Wrapper over the `VASliceParameterBufferVP8` FFI type. 616 pub struct SliceParameterBufferVP8(Box<bindings::VASliceParameterBufferVP8>); 617 618 impl SliceParameterBufferVP8 { 619 /// Creates the wrapper. new( slice_data_size: u32, slice_data_offset: u32, slice_data_flag: u32, macroblock_offset: u32, num_of_partitions: u8, partition_size: [u32; 9usize], ) -> Self620 pub fn new( 621 slice_data_size: u32, 622 slice_data_offset: u32, 623 slice_data_flag: u32, 624 macroblock_offset: u32, 625 num_of_partitions: u8, 626 partition_size: [u32; 9usize], 627 ) -> Self { 628 Self(Box::new(bindings::VASliceParameterBufferVP8 { 629 slice_data_size, 630 slice_data_offset, 631 slice_data_flag, 632 macroblock_offset, 633 num_of_partitions, 634 partition_size, 635 va_reserved: Default::default(), 636 })) 637 } 638 inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferVP8639 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferVP8 { 640 self.0.as_mut() 641 } 642 643 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VASliceParameterBufferVP8644 pub fn inner(&self) -> &bindings::VASliceParameterBufferVP8 { 645 self.0.as_ref() 646 } 647 } 648 649 /// Wrapper over the `segment_flags` bindgen field in `VASegmentParameterVP9`. 650 pub struct VP9SegmentFlags(bindings::_VASegmentParameterVP9__bindgen_ty_1); 651 652 impl VP9SegmentFlags { 653 /// Creates the wrapper. new( segment_reference_enabled: u16, segment_reference: u16, segment_reference_skipped: u16, ) -> Self654 pub fn new( 655 segment_reference_enabled: u16, 656 segment_reference: u16, 657 segment_reference_skipped: u16, 658 ) -> Self { 659 let _bitfield_1 = 660 bindings::_VASegmentParameterVP9__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( 661 segment_reference_enabled, 662 segment_reference, 663 segment_reference_skipped, 664 ); 665 666 Self(bindings::_VASegmentParameterVP9__bindgen_ty_1 { 667 fields: bindings::_VASegmentParameterVP9__bindgen_ty_1__bindgen_ty_1 { 668 _bitfield_align_1: Default::default(), 669 _bitfield_1, 670 __bindgen_padding_0: Default::default(), 671 }, 672 }) 673 } 674 675 /// Returns the inner FFI type. Useful for testing purposes. inner(&mut self) -> &bindings::_VASegmentParameterVP9__bindgen_ty_1676 pub fn inner(&mut self) -> &bindings::_VASegmentParameterVP9__bindgen_ty_1 { 677 &self.0 678 } 679 } 680 681 /// Wrapper over the `VASegmentParameterVP9` FFI type. 682 pub struct SegmentParameterVP9(bindings::VASegmentParameterVP9); 683 684 impl SegmentParameterVP9 { 685 /// Creates the wrapper. new( segment_flags: &VP9SegmentFlags, filter_level: [[u8; 2usize]; 4usize], luma_ac_quant_scale: i16, luma_dc_quant_scale: i16, chroma_ac_quant_scale: i16, chroma_dc_quant_scale: i16, ) -> Self686 pub fn new( 687 segment_flags: &VP9SegmentFlags, 688 filter_level: [[u8; 2usize]; 4usize], 689 luma_ac_quant_scale: i16, 690 luma_dc_quant_scale: i16, 691 chroma_ac_quant_scale: i16, 692 chroma_dc_quant_scale: i16, 693 ) -> Self { 694 let segment_flags = segment_flags.0; 695 696 Self(bindings::VASegmentParameterVP9 { 697 segment_flags, 698 filter_level, 699 luma_ac_quant_scale, 700 luma_dc_quant_scale, 701 chroma_ac_quant_scale, 702 chroma_dc_quant_scale, 703 va_reserved: Default::default(), 704 }) 705 } 706 } 707 708 /// Wrapper over the `VASliceParameterBufferVP9` FFI type. 709 pub struct SliceParameterBufferVP9(Box<bindings::VASliceParameterBufferVP9>); 710 711 impl SliceParameterBufferVP9 { 712 /// Creates the wrapper. new( slice_data_size: u32, slice_data_offset: u32, slice_data_flag: u32, seg_param: [SegmentParameterVP9; 8usize], ) -> Self713 pub fn new( 714 slice_data_size: u32, 715 slice_data_offset: u32, 716 slice_data_flag: u32, 717 seg_param: [SegmentParameterVP9; 8usize], 718 ) -> Self { 719 let seg_param = seg_param.map(|param| param.0); 720 721 Self(Box::new(bindings::VASliceParameterBufferVP9 { 722 slice_data_size, 723 slice_data_offset, 724 slice_data_flag, 725 seg_param, 726 va_reserved: Default::default(), 727 })) 728 } 729 inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferVP9730 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferVP9 { 731 self.0.as_mut() 732 } 733 734 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VASliceParameterBufferVP9735 pub fn inner(&self) -> &bindings::VASliceParameterBufferVP9 { 736 self.0.as_ref() 737 } 738 } 739 740 /// Wrapper over the `VASliceParameterBufferH264` FFI type. 741 pub struct SliceParameterBufferH264(Box<bindings::VASliceParameterBufferH264>); 742 743 impl SliceParameterBufferH264 { 744 /// Creates the wrapper new( slice_data_size: u32, slice_data_offset: u32, slice_data_flag: u32, slice_data_bit_offset: u16, first_mb_in_slice: u16, slice_type: u8, direct_spatial_mv_pred_flag: u8, num_ref_idx_l0_active_minus1: u8, num_ref_idx_l1_active_minus1: u8, cabac_init_idc: u8, slice_qp_delta: i8, disable_deblocking_filter_idc: u8, slice_alpha_c0_offset_div2: i8, slice_beta_offset_div2: i8, ref_pic_list_0: [PictureH264; 32usize], ref_pic_list_1: [PictureH264; 32usize], luma_log2_weight_denom: u8, chroma_log2_weight_denom: u8, luma_weight_l0_flag: u8, luma_weight_l0: [i16; 32usize], luma_offset_l0: [i16; 32usize], chroma_weight_l0_flag: u8, chroma_weight_l0: [[i16; 2usize]; 32usize], chroma_offset_l0: [[i16; 2usize]; 32usize], luma_weight_l1_flag: u8, luma_weight_l1: [i16; 32usize], luma_offset_l1: [i16; 32usize], chroma_weight_l1_flag: u8, chroma_weight_l1: [[i16; 2usize]; 32usize], chroma_offset_l1: [[i16; 2usize]; 32usize], ) -> Self745 pub fn new( 746 slice_data_size: u32, 747 slice_data_offset: u32, 748 slice_data_flag: u32, 749 slice_data_bit_offset: u16, 750 first_mb_in_slice: u16, 751 slice_type: u8, 752 direct_spatial_mv_pred_flag: u8, 753 num_ref_idx_l0_active_minus1: u8, 754 num_ref_idx_l1_active_minus1: u8, 755 cabac_init_idc: u8, 756 slice_qp_delta: i8, 757 disable_deblocking_filter_idc: u8, 758 slice_alpha_c0_offset_div2: i8, 759 slice_beta_offset_div2: i8, 760 ref_pic_list_0: [PictureH264; 32usize], 761 ref_pic_list_1: [PictureH264; 32usize], 762 luma_log2_weight_denom: u8, 763 chroma_log2_weight_denom: u8, 764 luma_weight_l0_flag: u8, 765 luma_weight_l0: [i16; 32usize], 766 luma_offset_l0: [i16; 32usize], 767 chroma_weight_l0_flag: u8, 768 chroma_weight_l0: [[i16; 2usize]; 32usize], 769 chroma_offset_l0: [[i16; 2usize]; 32usize], 770 luma_weight_l1_flag: u8, 771 luma_weight_l1: [i16; 32usize], 772 luma_offset_l1: [i16; 32usize], 773 chroma_weight_l1_flag: u8, 774 chroma_weight_l1: [[i16; 2usize]; 32usize], 775 chroma_offset_l1: [[i16; 2usize]; 32usize], 776 ) -> Self { 777 let ref_pic_list_0 = ref_pic_list_0.map(|pic| pic.0); 778 let ref_pic_list_1 = ref_pic_list_1.map(|pic| pic.0); 779 780 Self(Box::new(bindings::VASliceParameterBufferH264 { 781 slice_data_size, 782 slice_data_offset, 783 slice_data_flag, 784 slice_data_bit_offset, 785 first_mb_in_slice, 786 slice_type, 787 direct_spatial_mv_pred_flag, 788 num_ref_idx_l0_active_minus1, 789 num_ref_idx_l1_active_minus1, 790 cabac_init_idc, 791 slice_qp_delta, 792 disable_deblocking_filter_idc, 793 slice_alpha_c0_offset_div2, 794 slice_beta_offset_div2, 795 RefPicList0: ref_pic_list_0, 796 RefPicList1: ref_pic_list_1, 797 luma_log2_weight_denom, 798 chroma_log2_weight_denom, 799 luma_weight_l0_flag, 800 luma_weight_l0, 801 luma_offset_l0, 802 chroma_weight_l0_flag, 803 chroma_weight_l0, 804 chroma_offset_l0, 805 luma_weight_l1_flag, 806 luma_weight_l1, 807 luma_offset_l1, 808 chroma_weight_l1_flag, 809 chroma_weight_l1, 810 chroma_offset_l1, 811 va_reserved: Default::default(), 812 })) 813 } 814 inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferH264815 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferH264 { 816 self.0.as_mut() 817 } 818 819 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VASliceParameterBufferH264820 pub fn inner(&self) -> &bindings::VASliceParameterBufferH264 { 821 self.0.as_ref() 822 } 823 } 824 825 /// Wrapper over the `VAIQMatrixBufferMPEG2` FFI type. 826 pub struct IQMatrixBufferMPEG2(Box<bindings::VAIQMatrixBufferMPEG2>); 827 828 impl IQMatrixBufferMPEG2 { 829 /// Creates the wrapper. new( load_intra_quantiser_matrix: i32, load_non_intra_quantiser_matrix: i32, load_chroma_intra_quantiser_matrix: i32, load_chroma_non_intra_quantiser_matrix: i32, intra_quantiser_matrix: [u8; 64usize], non_intra_quantiser_matrix: [u8; 64usize], chroma_intra_quantiser_matrix: [u8; 64usize], chroma_non_intra_quantiser_matrix: [u8; 64usize], ) -> Self830 pub fn new( 831 load_intra_quantiser_matrix: i32, 832 load_non_intra_quantiser_matrix: i32, 833 load_chroma_intra_quantiser_matrix: i32, 834 load_chroma_non_intra_quantiser_matrix: i32, 835 intra_quantiser_matrix: [u8; 64usize], 836 non_intra_quantiser_matrix: [u8; 64usize], 837 chroma_intra_quantiser_matrix: [u8; 64usize], 838 chroma_non_intra_quantiser_matrix: [u8; 64usize], 839 ) -> Self { 840 Self(Box::new(bindings::VAIQMatrixBufferMPEG2 { 841 load_intra_quantiser_matrix, 842 load_non_intra_quantiser_matrix, 843 load_chroma_intra_quantiser_matrix, 844 load_chroma_non_intra_quantiser_matrix, 845 intra_quantiser_matrix, 846 non_intra_quantiser_matrix, 847 chroma_intra_quantiser_matrix, 848 chroma_non_intra_quantiser_matrix, 849 va_reserved: Default::default(), 850 })) 851 } 852 inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferMPEG2853 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferMPEG2 { 854 self.0.as_mut() 855 } 856 857 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VAIQMatrixBufferMPEG2858 pub fn inner(&self) -> &bindings::VAIQMatrixBufferMPEG2 { 859 self.0.as_ref() 860 } 861 } 862 863 /// Wrapper over the `VAIQMatrixBufferVP8` FFI type. 864 pub struct IQMatrixBufferVP8(Box<bindings::VAIQMatrixBufferVP8>); 865 866 impl IQMatrixBufferVP8 { 867 /// Creates the wrapper. new(quantization_index: [[u16; 6usize]; 4usize]) -> Self868 pub fn new(quantization_index: [[u16; 6usize]; 4usize]) -> Self { 869 Self(Box::new(bindings::VAIQMatrixBufferVP8 { 870 quantization_index, 871 va_reserved: Default::default(), 872 })) 873 } 874 inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferVP8875 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferVP8 { 876 self.0.as_mut() 877 } 878 879 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VAIQMatrixBufferVP8880 pub fn inner(&self) -> &bindings::VAIQMatrixBufferVP8 { 881 self.0.as_ref() 882 } 883 } 884 885 /// Wrapper over the `VAIQMatrixBufferH264` FFI type 886 pub struct IQMatrixBufferH264(Box<bindings::VAIQMatrixBufferH264>); 887 888 impl IQMatrixBufferH264 { 889 /// Creates the wrapper. new( scaling_list4x4: [[u8; 16usize]; 6usize], scaling_list8x8: [[u8; 64usize]; 2usize], ) -> Self890 pub fn new( 891 scaling_list4x4: [[u8; 16usize]; 6usize], 892 scaling_list8x8: [[u8; 64usize]; 2usize], 893 ) -> Self { 894 Self(Box::new(bindings::VAIQMatrixBufferH264 { 895 ScalingList4x4: scaling_list4x4, 896 ScalingList8x8: scaling_list8x8, 897 va_reserved: Default::default(), 898 })) 899 } 900 inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferH264901 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferH264 { 902 self.0.as_mut() 903 } 904 905 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VAIQMatrixBufferH264906 pub fn inner(&self) -> &bindings::VAIQMatrixBufferH264 { 907 self.0.as_ref() 908 } 909 } 910 911 /// Abstraction over the `IQMatrixBuffer` types we support. 912 pub enum IQMatrix { 913 /// Abstraction over `VAIQMatrixBufferMPEG2` 914 MPEG2(IQMatrixBufferMPEG2), 915 /// Abstraction over `VAIQMatrixBufferVP8` 916 VP8(IQMatrixBufferVP8), 917 /// Abstraction over `VAIQMatrixBufferH264` 918 H264(IQMatrixBufferH264), 919 } 920 921 /// Wrapper over the VAProbabilityDataBufferVP8 FFI type. 922 pub struct ProbabilityDataBufferVP8(Box<bindings::VAProbabilityDataBufferVP8>); 923 924 impl ProbabilityDataBufferVP8 { 925 /// Creates the wrapper. new(dct_coeff_probs: [[[[u8; 11usize]; 3usize]; 8usize]; 4usize]) -> Self926 pub fn new(dct_coeff_probs: [[[[u8; 11usize]; 3usize]; 8usize]; 4usize]) -> Self { 927 Self(Box::new(bindings::VAProbabilityDataBufferVP8 { 928 dct_coeff_probs, 929 va_reserved: Default::default(), 930 })) 931 } 932 inner_mut(&mut self) -> &mut bindings::VAProbabilityDataBufferVP8933 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAProbabilityDataBufferVP8 { 934 self.0.as_mut() 935 } 936 937 /// Returns the inner FFI type. Useful for testing purposes. inner(&self) -> &bindings::VAProbabilityDataBufferVP8938 pub fn inner(&self) -> &bindings::VAProbabilityDataBufferVP8 { 939 self.0.as_ref() 940 } 941 } 942