| 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_TOP_FIELD: u32 = 0x0000_0002; |
| 14 | |
| 15 | pub const PICTURE_BOTTOM_FIELD: u32 = 0x0000_0004; |
| 16 | |
| 17 | pub const PICTURE_SHORT_TERM_REFERENCE: u32 = 0x0000_0008; |
| 18 | |
| 19 | pub const PICTURE_LONG_TERM_REFERENCE: u32 = 0x0000_0010; |
| 20 | |
| 21 | |
| 22 | #[repr(C)] |
| 23 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 24 | pub struct VAPictureH264 { |
| 25 | |
| 26 | pub picture_id: VASurfaceID, |
| 27 | |
| 28 | pub frame_idx: u32, |
| 29 | |
| 30 | pub flags: u32, |
| 31 | |
| 32 | pub top_field_order_cnt: i32, |
| 33 | |
| 34 | pub bottom_field_order_cnt: i32, |
| 35 | pub(crate) va_reserved: [u32; 4], |
| 36 | } |
| 37 | |
| 38 | impl VAPictureH264 { |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | pub const INVALID: VAPictureH264 = VAPictureH264 { |
| 44 | picture_id: INVALID_SURFACE, |
| 45 | frame_idx: 0, |
| 46 | flags: PICTURE_INVALID, |
| 47 | top_field_order_cnt: 0, |
| 48 | bottom_field_order_cnt: 0, |
| 49 | va_reserved: [0; 4], |
| 50 | }; |
| 51 | |
| 52 | |
| 53 | pub fn frame(picture_id: VASurfaceID, frame_idx: u32, poc: i32, flags: u32) -> VAPictureH264 { |
| 54 | VAPictureH264 { |
| 55 | picture_id, |
| 56 | frame_idx, |
| 57 | flags, |
| 58 | top_field_order_cnt: poc, |
| 59 | bottom_field_order_cnt: poc, |
| 60 | va_reserved: [0; 4], |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | impl Default for VAPictureH264 { |
| 66 | fn default() -> Self { |
| 67 | VAPictureH264::INVALID |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | va_bits! { |
| 72 | |
| 73 | SeqFields: u32 { |
| 74 | chroma_format_idc: 2, |
| 75 | residual_colour_transform_flag: 1, |
| 76 | gaps_in_frame_num_value_allowed_flag: 1, |
| 77 | frame_mbs_only_flag: 1, |
| 78 | mb_adaptive_frame_field_flag: 1, |
| 79 | direct_8x8_inference_flag: 1, |
| 80 | min_luma_bipred_size8x8: 1, |
| 81 | log2_max_frame_num_minus4: 4, |
| 82 | pic_order_cnt_type: 2, |
| 83 | log2_max_pic_order_cnt_lsb_minus4: 4, |
| 84 | delta_pic_order_always_zero_flag: 1, |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | va_bits! { |
| 89 | |
| 90 | PicFields: u32 { |
| 91 | entropy_coding_mode_flag: 1, |
| 92 | weighted_pred_flag: 1, |
| 93 | weighted_bipred_idc: 2, |
| 94 | transform_8x8_mode_flag: 1, |
| 95 | field_pic_flag: 1, |
| 96 | constrained_intra_pred_flag: 1, |
| 97 | pic_order_present_flag: 1, |
| 98 | deblocking_filter_control_present_flag: 1, |
| 99 | redundant_pic_cnt_present_flag: 1, |
| 100 | reference_pic_flag: 1, |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | |
| 105 | #[repr(C)] |
| 106 | #[derive(Debug, Clone, Copy)] |
| 107 | pub struct PictureParameterBufferH264 { |
| 108 | |
| 109 | pub curr_pic: VAPictureH264, |
| 110 | |
| 111 | pub reference_frames: [VAPictureH264; 16], |
| 112 | |
| 113 | pub picture_width_in_mbs_minus1: u16, |
| 114 | |
| 115 | pub picture_height_in_mbs_minus1: u16, |
| 116 | |
| 117 | pub bit_depth_luma_minus8: u8, |
| 118 | |
| 119 | pub bit_depth_chroma_minus8: u8, |
| 120 | |
| 121 | pub num_ref_frames: u8, |
| 122 | |
| 123 | pub seq_fields: SeqFields, |
| 124 | |
| 125 | pub(crate) num_slice_groups_minus1: u8, |
| 126 | pub(crate) slice_group_map_type: u8, |
| 127 | pub(crate) slice_group_change_rate_minus1: u16, |
| 128 | |
| 129 | pub pic_init_qp_minus26: i8, |
| 130 | |
| 131 | pub pic_init_qs_minus26: i8, |
| 132 | |
| 133 | pub chroma_qp_index_offset: i8, |
| 134 | |
| 135 | pub second_chroma_qp_index_offset: i8, |
| 136 | |
| 137 | pub pic_fields: PicFields, |
| 138 | |
| 139 | pub frame_num: u16, |
| 140 | pub(crate) va_reserved: [u32; 8], |
| 141 | } |
| 142 | |
| 143 | impl Default for PictureParameterBufferH264 { |
| 144 | fn default() -> Self { |
| 145 | PictureParameterBufferH264 { |
| 146 | curr_pic: VAPictureH264::INVALID, |
| 147 | reference_frames: [VAPictureH264::INVALID; 16], |
| 148 | picture_width_in_mbs_minus1: 0, |
| 149 | picture_height_in_mbs_minus1: 0, |
| 150 | bit_depth_luma_minus8: 0, |
| 151 | bit_depth_chroma_minus8: 0, |
| 152 | num_ref_frames: 0, |
| 153 | seq_fields: SeqFields::default(), |
| 154 | num_slice_groups_minus1: 0, |
| 155 | slice_group_map_type: 0, |
| 156 | slice_group_change_rate_minus1: 0, |
| 157 | pic_init_qp_minus26: 0, |
| 158 | pic_init_qs_minus26: 0, |
| 159 | chroma_qp_index_offset: 0, |
| 160 | second_chroma_qp_index_offset: 0, |
| 161 | pic_fields: PicFields::default(), |
| 162 | frame_num: 0, |
| 163 | va_reserved: [0; 8], |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | unsafe impl VaParam for PictureParameterBufferH264 { |
| 172 | const TYPE: i32 = VAPictureParameterBufferType; |
| 173 | } |
| 174 | |
| 175 | |
| 176 | #[repr(C)] |
| 177 | #[derive(Debug, Clone, Copy)] |
| 178 | pub struct IQMatrixBufferH264 { |
| 179 | |
| 180 | pub scaling_list_4x4: [[u8; 16]; 6], |
| 181 | |
| 182 | pub scaling_list_8x8: [[u8; 64]; 2], |
| 183 | pub(crate) va_reserved: [u32; 4], |
| 184 | } |
| 185 | |
| 186 | impl Default for IQMatrixBufferH264 { |
| 187 | fn default() -> Self { |
| 188 | IQMatrixBufferH264 { |
| 189 | scaling_list_4x4: [[16; 16]; 6], |
| 190 | scaling_list_8x8: [[16; 64]; 2], |
| 191 | va_reserved: [0; 4], |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | |
| 197 | unsafe impl VaParam for IQMatrixBufferH264 { |
| 198 | const TYPE: i32 = VAIQMatrixBufferType; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | #[repr(C)] |
| 207 | #[derive(Debug, Clone, Copy)] |
| 208 | pub struct SliceParameterBufferH264 { |
| 209 | |
| 210 | pub slice_data_size: u32, |
| 211 | |
| 212 | pub slice_data_offset: u32, |
| 213 | |
| 214 | pub slice_data_flag: u32, |
| 215 | |
| 216 | |
| 217 | pub slice_data_bit_offset: u16, |
| 218 | |
| 219 | pub first_mb_in_slice: u16, |
| 220 | |
| 221 | pub slice_type: u8, |
| 222 | |
| 223 | pub direct_spatial_mv_pred_flag: u8, |
| 224 | |
| 225 | pub num_ref_idx_l0_active_minus1: u8, |
| 226 | |
| 227 | pub num_ref_idx_l1_active_minus1: u8, |
| 228 | |
| 229 | pub cabac_init_idc: u8, |
| 230 | |
| 231 | pub slice_qp_delta: i8, |
| 232 | |
| 233 | pub disable_deblocking_filter_idc: u8, |
| 234 | |
| 235 | pub slice_alpha_c0_offset_div2: i8, |
| 236 | |
| 237 | pub slice_beta_offset_div2: i8, |
| 238 | |
| 239 | pub ref_pic_list0: [VAPictureH264; 32], |
| 240 | |
| 241 | pub ref_pic_list1: [VAPictureH264; 32], |
| 242 | |
| 243 | pub luma_log2_weight_denom: u8, |
| 244 | |
| 245 | pub chroma_log2_weight_denom: u8, |
| 246 | |
| 247 | pub luma_weight_l0_flag: u8, |
| 248 | |
| 249 | pub luma_weight_l0: [i16; 32], |
| 250 | |
| 251 | pub luma_offset_l0: [i16; 32], |
| 252 | |
| 253 | pub chroma_weight_l0_flag: u8, |
| 254 | |
| 255 | pub chroma_weight_l0: [[i16; 2]; 32], |
| 256 | |
| 257 | pub chroma_offset_l0: [[i16; 2]; 32], |
| 258 | |
| 259 | pub luma_weight_l1_flag: u8, |
| 260 | |
| 261 | pub luma_weight_l1: [i16; 32], |
| 262 | |
| 263 | pub luma_offset_l1: [i16; 32], |
| 264 | |
| 265 | pub chroma_weight_l1_flag: u8, |
| 266 | |
| 267 | pub chroma_weight_l1: [[i16; 2]; 32], |
| 268 | |
| 269 | pub chroma_offset_l1: [[i16; 2]; 32], |
| 270 | pub(crate) va_reserved: [u32; 4], |
| 271 | } |
| 272 | |
| 273 | impl Default for SliceParameterBufferH264 { |
| 274 | fn default() -> Self { |
| 275 | SliceParameterBufferH264 { |
| 276 | slice_data_size: 0, |
| 277 | slice_data_offset: 0, |
| 278 | slice_data_flag: 0, |
| 279 | slice_data_bit_offset: 0, |
| 280 | first_mb_in_slice: 0, |
| 281 | slice_type: 0, |
| 282 | direct_spatial_mv_pred_flag: 0, |
| 283 | num_ref_idx_l0_active_minus1: 0, |
| 284 | num_ref_idx_l1_active_minus1: 0, |
| 285 | cabac_init_idc: 0, |
| 286 | slice_qp_delta: 0, |
| 287 | disable_deblocking_filter_idc: 0, |
| 288 | slice_alpha_c0_offset_div2: 0, |
| 289 | slice_beta_offset_div2: 0, |
| 290 | ref_pic_list0: [VAPictureH264::INVALID; 32], |
| 291 | ref_pic_list1: [VAPictureH264::INVALID; 32], |
| 292 | luma_log2_weight_denom: 0, |
| 293 | chroma_log2_weight_denom: 0, |
| 294 | luma_weight_l0_flag: 0, |
| 295 | luma_weight_l0: [0; 32], |
| 296 | luma_offset_l0: [0; 32], |
| 297 | chroma_weight_l0_flag: 0, |
| 298 | chroma_weight_l0: [[0; 2]; 32], |
| 299 | chroma_offset_l0: [[0; 2]; 32], |
| 300 | luma_weight_l1_flag: 0, |
| 301 | luma_weight_l1: [0; 32], |
| 302 | luma_offset_l1: [0; 32], |
| 303 | chroma_weight_l1_flag: 0, |
| 304 | chroma_weight_l1: [[0; 2]; 32], |
| 305 | chroma_offset_l1: [[0; 2]; 32], |
| 306 | va_reserved: [0; 4], |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | |
| 312 | unsafe impl VaParam for SliceParameterBufferH264 { |
| 313 | const TYPE: i32 = VASliceParameterBufferType; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | const _: () = { |
| 338 | use std::mem::{align_of, offset_of, size_of}; |
| 339 | |
| 340 | assert!(size_of::<VAPictureH264>() == 36 && align_of::<VAPictureH264>() == 4); |
| 341 | assert!(offset_of!(VAPictureH264, frame_idx) == 4); |
| 342 | assert!(offset_of!(VAPictureH264, flags) == 8); |
| 343 | assert!(offset_of!(VAPictureH264, top_field_order_cnt) == 12); |
| 344 | assert!(offset_of!(VAPictureH264, bottom_field_order_cnt) == 16); |
| 345 | |
| 346 | assert!( |
| 347 | size_of::<PictureParameterBufferH264>() == 672 |
| 348 | && align_of::<PictureParameterBufferH264>() == 4 |
| 349 | ); |
| 350 | assert!(offset_of!(PictureParameterBufferH264, reference_frames) == 36); |
| 351 | assert!(offset_of!(PictureParameterBufferH264, picture_width_in_mbs_minus1) == 612); |
| 352 | assert!(offset_of!(PictureParameterBufferH264, bit_depth_luma_minus8) == 616); |
| 353 | assert!(offset_of!(PictureParameterBufferH264, num_ref_frames) == 618); |
| 354 | assert!(offset_of!(PictureParameterBufferH264, seq_fields) == 620); |
| 355 | assert!(offset_of!(PictureParameterBufferH264, pic_init_qp_minus26) == 628); |
| 356 | assert!(offset_of!(PictureParameterBufferH264, pic_fields) == 632); |
| 357 | assert!(offset_of!(PictureParameterBufferH264, frame_num) == 636); |
| 358 | |
| 359 | assert!(size_of::<IQMatrixBufferH264>() == 240 && align_of::<IQMatrixBufferH264>() == 4); |
| 360 | assert!(offset_of!(IQMatrixBufferH264, scaling_list_8x8) == 96); |
| 361 | |
| 362 | assert!( |
| 363 | size_of::<SliceParameterBufferH264>() == 3128 |
| 364 | && align_of::<SliceParameterBufferH264>() == 4 |
| 365 | ); |
| 366 | assert!(offset_of!(SliceParameterBufferH264, slice_data_bit_offset) == 12); |
| 367 | assert!(offset_of!(SliceParameterBufferH264, slice_type) == 16); |
| 368 | assert!(offset_of!(SliceParameterBufferH264, cabac_init_idc) == 20); |
| 369 | assert!(offset_of!(SliceParameterBufferH264, ref_pic_list0) == 28); |
| 370 | assert!(offset_of!(SliceParameterBufferH264, ref_pic_list1) == 1180); |
| 371 | assert!(offset_of!(SliceParameterBufferH264, luma_log2_weight_denom) == 2332); |
| 372 | assert!(offset_of!(SliceParameterBufferH264, luma_weight_l0) == 2336); |
| 373 | assert!(offset_of!(SliceParameterBufferH264, chroma_weight_l0) == 2466); |
| 374 | assert!(offset_of!(SliceParameterBufferH264, luma_weight_l1_flag) == 2722); |
| 375 | assert!(offset_of!(SliceParameterBufferH264, chroma_offset_l1) == 2982); |
| 376 | }; |