| 1 | |
| 2 | |
| 3 | use ec_va::sys::{ |
| 4 | VAIQMatrixBufferType, VAPictureParameterBufferType, VASliceParameterBufferType, VASurfaceID, |
| 5 | }; |
| 6 | |
| 7 | use super::{INVALID_SURFACE, VaParam}; |
| 8 | use crate::va_bits; |
| 9 | |
| 10 | |
| 11 | pub const PICTURE_INVALID: u32 = 0x0000_0001; |
| 12 | |
| 13 | pub const PICTURE_FIELD_PIC: u32 = 0x0000_0002; |
| 14 | |
| 15 | pub const PICTURE_BOTTOM_FIELD: u32 = 0x0000_0004; |
| 16 | |
| 17 | pub const PICTURE_LONG_TERM_REFERENCE: u32 = 0x0000_0008; |
| 18 | |
| 19 | pub const PICTURE_RPS_ST_CURR_BEFORE: u32 = 0x0000_0010; |
| 20 | |
| 21 | pub const PICTURE_RPS_ST_CURR_AFTER: u32 = 0x0000_0020; |
| 22 | |
| 23 | pub const PICTURE_RPS_LT_CURR: u32 = 0x0000_0040; |
| 24 | |
| 25 | |
| 26 | #[repr(C)] |
| 27 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 28 | pub struct VAPictureHEVC { |
| 29 | |
| 30 | pub picture_id: VASurfaceID, |
| 31 | |
| 32 | pub pic_order_cnt: i32, |
| 33 | |
| 34 | pub flags: u32, |
| 35 | pub(crate) va_reserved: [u32; 4], |
| 36 | } |
| 37 | |
| 38 | impl VAPictureHEVC { |
| 39 | |
| 40 | pub const INVALID: VAPictureHEVC = VAPictureHEVC { |
| 41 | picture_id: INVALID_SURFACE, |
| 42 | pic_order_cnt: 0, |
| 43 | flags: PICTURE_INVALID, |
| 44 | va_reserved: [0; 4], |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | pub fn new(picture_id: VASurfaceID, pic_order_cnt: i32, flags: u32) -> VAPictureHEVC { |
| 49 | VAPictureHEVC { |
| 50 | picture_id, |
| 51 | pic_order_cnt, |
| 52 | flags, |
| 53 | va_reserved: [0; 4], |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | impl Default for VAPictureHEVC { |
| 59 | fn default() -> Self { |
| 60 | VAPictureHEVC::INVALID |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | va_bits! { |
| 65 | |
| 66 | PicFields: u32 { |
| 67 | chroma_format_idc: 2, |
| 68 | separate_colour_plane_flag: 1, |
| 69 | pcm_enabled_flag: 1, |
| 70 | scaling_list_enabled_flag: 1, |
| 71 | transform_skip_enabled_flag: 1, |
| 72 | amp_enabled_flag: 1, |
| 73 | strong_intra_smoothing_enabled_flag: 1, |
| 74 | sign_data_hiding_enabled_flag: 1, |
| 75 | constrained_intra_pred_flag: 1, |
| 76 | cu_qp_delta_enabled_flag: 1, |
| 77 | weighted_pred_flag: 1, |
| 78 | weighted_bipred_flag: 1, |
| 79 | transquant_bypass_enabled_flag: 1, |
| 80 | tiles_enabled_flag: 1, |
| 81 | entropy_coding_sync_enabled_flag: 1, |
| 82 | pps_loop_filter_across_slices_enabled_flag: 1, |
| 83 | loop_filter_across_tiles_enabled_flag: 1, |
| 84 | pcm_loop_filter_disabled_flag: 1, |
| 85 | no_pic_reordering_flag: 1, |
| 86 | no_bi_pred_flag: 1, |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | va_bits! { |
| 91 | |
| 92 | SliceParsingFields: u32 { |
| 93 | lists_modification_present_flag: 1, |
| 94 | long_term_ref_pics_present_flag: 1, |
| 95 | sps_temporal_mvp_enabled_flag: 1, |
| 96 | cabac_init_present_flag: 1, |
| 97 | output_flag_present_flag: 1, |
| 98 | dependent_slice_segments_enabled_flag: 1, |
| 99 | pps_slice_chroma_qp_offsets_present_flag: 1, |
| 100 | sample_adaptive_offset_enabled_flag: 1, |
| 101 | deblocking_filter_override_enabled_flag: 1, |
| 102 | pps_disable_deblocking_filter_flag: 1, |
| 103 | slice_segment_header_extension_present_flag: 1, |
| 104 | rap_pic_flag: 1, |
| 105 | idr_pic_flag: 1, |
| 106 | intra_pic_flag: 1, |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | |
| 111 | #[repr(C)] |
| 112 | #[derive(Debug, Clone, Copy)] |
| 113 | pub struct PictureParameterBufferHEVC { |
| 114 | |
| 115 | pub curr_pic: VAPictureHEVC, |
| 116 | |
| 117 | pub reference_frames: [VAPictureHEVC; 15], |
| 118 | |
| 119 | pub pic_width_in_luma_samples: u16, |
| 120 | |
| 121 | pub pic_height_in_luma_samples: u16, |
| 122 | |
| 123 | pub pic_fields: PicFields, |
| 124 | |
| 125 | pub sps_max_dec_pic_buffering_minus1: u8, |
| 126 | |
| 127 | pub bit_depth_luma_minus8: u8, |
| 128 | |
| 129 | pub bit_depth_chroma_minus8: u8, |
| 130 | |
| 131 | pub pcm_sample_bit_depth_luma_minus1: u8, |
| 132 | |
| 133 | pub pcm_sample_bit_depth_chroma_minus1: u8, |
| 134 | |
| 135 | pub log2_min_luma_coding_block_size_minus3: u8, |
| 136 | |
| 137 | pub log2_diff_max_min_luma_coding_block_size: u8, |
| 138 | |
| 139 | pub log2_min_transform_block_size_minus2: u8, |
| 140 | |
| 141 | pub log2_diff_max_min_transform_block_size: u8, |
| 142 | |
| 143 | pub log2_min_pcm_luma_coding_block_size_minus3: u8, |
| 144 | |
| 145 | pub log2_diff_max_min_pcm_luma_coding_block_size: u8, |
| 146 | |
| 147 | pub max_transform_hierarchy_depth_intra: u8, |
| 148 | |
| 149 | pub max_transform_hierarchy_depth_inter: u8, |
| 150 | |
| 151 | pub init_qp_minus26: i8, |
| 152 | |
| 153 | pub diff_cu_qp_delta_depth: u8, |
| 154 | |
| 155 | pub pps_cb_qp_offset: i8, |
| 156 | |
| 157 | pub pps_cr_qp_offset: i8, |
| 158 | |
| 159 | pub log2_parallel_merge_level_minus2: u8, |
| 160 | |
| 161 | pub num_tile_columns_minus1: u8, |
| 162 | |
| 163 | pub num_tile_rows_minus1: u8, |
| 164 | |
| 165 | pub column_width_minus1: [u16; 19], |
| 166 | |
| 167 | pub row_height_minus1: [u16; 21], |
| 168 | |
| 169 | pub slice_parsing_fields: SliceParsingFields, |
| 170 | |
| 171 | pub log2_max_pic_order_cnt_lsb_minus4: u8, |
| 172 | |
| 173 | pub num_short_term_ref_pic_sets: u8, |
| 174 | |
| 175 | pub num_long_term_ref_pic_sps: u8, |
| 176 | |
| 177 | pub num_ref_idx_l0_default_active_minus1: u8, |
| 178 | |
| 179 | pub num_ref_idx_l1_default_active_minus1: u8, |
| 180 | |
| 181 | pub pps_beta_offset_div2: i8, |
| 182 | |
| 183 | pub pps_tc_offset_div2: i8, |
| 184 | |
| 185 | pub num_extra_slice_header_bits: u8, |
| 186 | |
| 187 | |
| 188 | pub st_rps_bits: u32, |
| 189 | pub(crate) va_reserved: [u32; 8], |
| 190 | } |
| 191 | |
| 192 | impl Default for PictureParameterBufferHEVC { |
| 193 | fn default() -> Self { |
| 194 | PictureParameterBufferHEVC { |
| 195 | curr_pic: VAPictureHEVC::INVALID, |
| 196 | reference_frames: [VAPictureHEVC::INVALID; 15], |
| 197 | pic_width_in_luma_samples: 0, |
| 198 | pic_height_in_luma_samples: 0, |
| 199 | pic_fields: PicFields::default(), |
| 200 | sps_max_dec_pic_buffering_minus1: 0, |
| 201 | bit_depth_luma_minus8: 0, |
| 202 | bit_depth_chroma_minus8: 0, |
| 203 | pcm_sample_bit_depth_luma_minus1: 0, |
| 204 | pcm_sample_bit_depth_chroma_minus1: 0, |
| 205 | log2_min_luma_coding_block_size_minus3: 0, |
| 206 | log2_diff_max_min_luma_coding_block_size: 0, |
| 207 | log2_min_transform_block_size_minus2: 0, |
| 208 | log2_diff_max_min_transform_block_size: 0, |
| 209 | log2_min_pcm_luma_coding_block_size_minus3: 0, |
| 210 | log2_diff_max_min_pcm_luma_coding_block_size: 0, |
| 211 | max_transform_hierarchy_depth_intra: 0, |
| 212 | max_transform_hierarchy_depth_inter: 0, |
| 213 | init_qp_minus26: 0, |
| 214 | diff_cu_qp_delta_depth: 0, |
| 215 | pps_cb_qp_offset: 0, |
| 216 | pps_cr_qp_offset: 0, |
| 217 | log2_parallel_merge_level_minus2: 0, |
| 218 | num_tile_columns_minus1: 0, |
| 219 | num_tile_rows_minus1: 0, |
| 220 | column_width_minus1: [0; 19], |
| 221 | row_height_minus1: [0; 21], |
| 222 | slice_parsing_fields: SliceParsingFields::default(), |
| 223 | log2_max_pic_order_cnt_lsb_minus4: 0, |
| 224 | num_short_term_ref_pic_sets: 0, |
| 225 | num_long_term_ref_pic_sps: 0, |
| 226 | num_ref_idx_l0_default_active_minus1: 0, |
| 227 | num_ref_idx_l1_default_active_minus1: 0, |
| 228 | pps_beta_offset_div2: 0, |
| 229 | pps_tc_offset_div2: 0, |
| 230 | num_extra_slice_header_bits: 0, |
| 231 | st_rps_bits: 0, |
| 232 | va_reserved: [0; 8], |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | |
| 238 | |
| 239 | unsafe impl VaParam for PictureParameterBufferHEVC { |
| 240 | const TYPE: i32 = VAPictureParameterBufferType; |
| 241 | } |
| 242 | |
| 243 | va_bits! { |
| 244 | |
| 245 | LongSliceFlags: u32 { |
| 246 | last_slice_of_pic: 1, |
| 247 | dependent_slice_segment_flag: 1, |
| 248 | slice_type: 2, |
| 249 | color_plane_id: 2, |
| 250 | slice_sao_luma_flag: 1, |
| 251 | slice_sao_chroma_flag: 1, |
| 252 | mvd_l1_zero_flag: 1, |
| 253 | cabac_init_flag: 1, |
| 254 | slice_temporal_mvp_enabled_flag: 1, |
| 255 | slice_deblocking_filter_disabled_flag: 1, |
| 256 | collocated_from_l0_flag: 1, |
| 257 | slice_loop_filter_across_slices_enabled_flag: 1, |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | |
| 262 | #[repr(C)] |
| 263 | #[derive(Debug, Clone, Copy)] |
| 264 | pub struct SliceParameterBufferHEVC { |
| 265 | |
| 266 | pub slice_data_size: u32, |
| 267 | |
| 268 | pub slice_data_offset: u32, |
| 269 | |
| 270 | pub slice_data_flag: u32, |
| 271 | |
| 272 | pub slice_data_byte_offset: u32, |
| 273 | |
| 274 | pub slice_segment_address: u32, |
| 275 | |
| 276 | pub ref_pic_list: [[u8; 15]; 2], |
| 277 | |
| 278 | pub long_slice_flags: LongSliceFlags, |
| 279 | |
| 280 | pub collocated_ref_idx: u8, |
| 281 | |
| 282 | pub num_ref_idx_l0_active_minus1: u8, |
| 283 | |
| 284 | pub num_ref_idx_l1_active_minus1: u8, |
| 285 | |
| 286 | pub slice_qp_delta: i8, |
| 287 | |
| 288 | pub slice_cb_qp_offset: i8, |
| 289 | |
| 290 | pub slice_cr_qp_offset: i8, |
| 291 | |
| 292 | pub slice_beta_offset_div2: i8, |
| 293 | |
| 294 | pub slice_tc_offset_div2: i8, |
| 295 | |
| 296 | pub luma_log2_weight_denom: u8, |
| 297 | |
| 298 | pub delta_chroma_log2_weight_denom: i8, |
| 299 | |
| 300 | pub delta_luma_weight_l0: [i8; 15], |
| 301 | |
| 302 | pub luma_offset_l0: [i8; 15], |
| 303 | |
| 304 | pub delta_chroma_weight_l0: [[i8; 2]; 15], |
| 305 | |
| 306 | pub chroma_offset_l0: [[i8; 2]; 15], |
| 307 | |
| 308 | pub delta_luma_weight_l1: [i8; 15], |
| 309 | |
| 310 | pub luma_offset_l1: [i8; 15], |
| 311 | |
| 312 | pub delta_chroma_weight_l1: [[i8; 2]; 15], |
| 313 | |
| 314 | pub chroma_offset_l1: [[i8; 2]; 15], |
| 315 | |
| 316 | pub five_minus_max_num_merge_cand: u8, |
| 317 | |
| 318 | pub num_entry_point_offsets: u16, |
| 319 | |
| 320 | pub entry_offset_to_subset_array: u16, |
| 321 | |
| 322 | pub slice_data_num_emu_prevn_bytes: u16, |
| 323 | pub(crate) va_reserved: [u32; 2], |
| 324 | } |
| 325 | |
| 326 | impl Default for SliceParameterBufferHEVC { |
| 327 | fn default() -> Self { |
| 328 | SliceParameterBufferHEVC { |
| 329 | slice_data_size: 0, |
| 330 | slice_data_offset: 0, |
| 331 | slice_data_flag: 0, |
| 332 | slice_data_byte_offset: 0, |
| 333 | slice_segment_address: 0, |
| 334 | ref_pic_list: [[0xff; 15]; 2], |
| 335 | long_slice_flags: LongSliceFlags::default(), |
| 336 | collocated_ref_idx: 0xff, |
| 337 | num_ref_idx_l0_active_minus1: 0, |
| 338 | num_ref_idx_l1_active_minus1: 0, |
| 339 | slice_qp_delta: 0, |
| 340 | slice_cb_qp_offset: 0, |
| 341 | slice_cr_qp_offset: 0, |
| 342 | slice_beta_offset_div2: 0, |
| 343 | slice_tc_offset_div2: 0, |
| 344 | luma_log2_weight_denom: 0, |
| 345 | delta_chroma_log2_weight_denom: 0, |
| 346 | delta_luma_weight_l0: [0; 15], |
| 347 | luma_offset_l0: [0; 15], |
| 348 | delta_chroma_weight_l0: [[0; 2]; 15], |
| 349 | chroma_offset_l0: [[0; 2]; 15], |
| 350 | delta_luma_weight_l1: [0; 15], |
| 351 | luma_offset_l1: [0; 15], |
| 352 | delta_chroma_weight_l1: [[0; 2]; 15], |
| 353 | chroma_offset_l1: [[0; 2]; 15], |
| 354 | five_minus_max_num_merge_cand: 0, |
| 355 | num_entry_point_offsets: 0, |
| 356 | entry_offset_to_subset_array: 0, |
| 357 | slice_data_num_emu_prevn_bytes: 0, |
| 358 | va_reserved: [0; 2], |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | |
| 364 | unsafe impl VaParam for SliceParameterBufferHEVC { |
| 365 | const TYPE: i32 = VASliceParameterBufferType; |
| 366 | } |
| 367 | |
| 368 | |
| 369 | #[repr(C)] |
| 370 | #[derive(Debug, Clone, Copy)] |
| 371 | pub struct IQMatrixBufferHEVC { |
| 372 | |
| 373 | pub scaling_list_4x4: [[u8; 16]; 6], |
| 374 | |
| 375 | pub scaling_list_8x8: [[u8; 64]; 6], |
| 376 | |
| 377 | pub scaling_list_16x16: [[u8; 64]; 6], |
| 378 | |
| 379 | pub scaling_list_32x32: [[u8; 64]; 2], |
| 380 | |
| 381 | pub scaling_list_dc_16x16: [u8; 6], |
| 382 | |
| 383 | pub scaling_list_dc_32x32: [u8; 2], |
| 384 | pub(crate) va_reserved: [u32; 4], |
| 385 | } |
| 386 | |
| 387 | impl Default for IQMatrixBufferHEVC { |
| 388 | fn default() -> Self { |
| 389 | IQMatrixBufferHEVC { |
| 390 | scaling_list_4x4: [[16; 16]; 6], |
| 391 | scaling_list_8x8: [[16; 64]; 6], |
| 392 | scaling_list_16x16: [[16; 64]; 6], |
| 393 | scaling_list_32x32: [[16; 64]; 2], |
| 394 | scaling_list_dc_16x16: [16; 6], |
| 395 | scaling_list_dc_32x32: [16; 2], |
| 396 | va_reserved: [0; 4], |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | |
| 402 | unsafe impl VaParam for IQMatrixBufferHEVC { |
| 403 | const TYPE: i32 = VAIQMatrixBufferType; |
| 404 | } |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | const _: () = { |
| 431 | use std::mem::{align_of, offset_of, size_of}; |
| 432 | |
| 433 | assert!(size_of::<VAPictureHEVC>() == 28 && align_of::<VAPictureHEVC>() == 4); |
| 434 | assert!(offset_of!(VAPictureHEVC, pic_order_cnt) == 4); |
| 435 | assert!(offset_of!(VAPictureHEVC, flags) == 8); |
| 436 | |
| 437 | assert!( |
| 438 | size_of::<PictureParameterBufferHEVC>() == 604 |
| 439 | && align_of::<PictureParameterBufferHEVC>() == 4 |
| 440 | ); |
| 441 | assert!(offset_of!(PictureParameterBufferHEVC, reference_frames) == 28); |
| 442 | assert!(offset_of!(PictureParameterBufferHEVC, pic_width_in_luma_samples) == 448); |
| 443 | assert!(offset_of!(PictureParameterBufferHEVC, pic_fields) == 452); |
| 444 | assert!(offset_of!(PictureParameterBufferHEVC, sps_max_dec_pic_buffering_minus1) == 456); |
| 445 | assert!(offset_of!(PictureParameterBufferHEVC, column_width_minus1) == 476); |
| 446 | assert!(offset_of!(PictureParameterBufferHEVC, row_height_minus1) == 514); |
| 447 | assert!(offset_of!(PictureParameterBufferHEVC, slice_parsing_fields) == 556); |
| 448 | assert!( |
| 449 | offset_of!( |
| 450 | PictureParameterBufferHEVC, |
| 451 | log2_max_pic_order_cnt_lsb_minus4 |
| 452 | ) == 560 |
| 453 | ); |
| 454 | assert!(offset_of!(PictureParameterBufferHEVC, st_rps_bits) == 568); |
| 455 | |
| 456 | assert!( |
| 457 | size_of::<SliceParameterBufferHEVC>() == 264 && align_of::<SliceParameterBufferHEVC>() == 4 |
| 458 | ); |
| 459 | assert!(offset_of!(SliceParameterBufferHEVC, slice_segment_address) == 16); |
| 460 | assert!(offset_of!(SliceParameterBufferHEVC, ref_pic_list) == 20); |
| 461 | assert!(offset_of!(SliceParameterBufferHEVC, long_slice_flags) == 52); |
| 462 | assert!(offset_of!(SliceParameterBufferHEVC, collocated_ref_idx) == 56); |
| 463 | assert!(offset_of!(SliceParameterBufferHEVC, luma_log2_weight_denom) == 64); |
| 464 | assert!(offset_of!(SliceParameterBufferHEVC, delta_luma_weight_l0) == 66); |
| 465 | assert!(offset_of!(SliceParameterBufferHEVC, delta_luma_weight_l1) == 156); |
| 466 | assert!(offset_of!(SliceParameterBufferHEVC, five_minus_max_num_merge_cand) == 246); |
| 467 | assert!(offset_of!(SliceParameterBufferHEVC, num_entry_point_offsets) == 248); |
| 468 | assert!(offset_of!(SliceParameterBufferHEVC, slice_data_num_emu_prevn_bytes) == 252); |
| 469 | |
| 470 | assert!(size_of::<IQMatrixBufferHEVC>() == 1016 && align_of::<IQMatrixBufferHEVC>() == 4); |
| 471 | assert!(offset_of!(IQMatrixBufferHEVC, scaling_list_32x32) == 864); |
| 472 | assert!(offset_of!(IQMatrixBufferHEVC, scaling_list_dc_16x16) == 992); |
| 473 | }; |