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