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 | //! AV1 decode parameter buffers (`va_dec_av1.h`), as plain Rust values. |
| 2 | //! |
| 3 | //! Every struct here carries the fields of the libva buffer it becomes, under |
| 4 | //! the same names. The `to_buffer` methods hand them to cros-libva's typed |
| 5 | //! constructors, which lay them out for the driver. |
| 6 | |
| 7 | use ec_va::va::{ |
| 8 | AV1FilmGrain, AV1FilmGrainFields, AV1LoopFilterFields, AV1LoopRestorationFields, |
| 9 | AV1ModeControlFields, AV1PicInfoFields, AV1QMatrixFields, AV1SegmentInfoFields, |
| 10 | AV1Segmentation, AV1SeqFields, AV1WarpedMotionParams, BufferType, PictureParameter, |
| 11 | PictureParameterBufferAV1 as CrosPicture, SliceParameter, SliceParameterBufferAV1 as CrosSlice, |
| 12 | }; |
| 13 | |
| 14 | use super::INVALID_SURFACE; |
| 15 | |
| 16 | /// `VASegmentationStructAV1::segment_info_fields`. |
| 17 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 18 | pub struct SegmentInfoFields { |
| 19 | /// `enabled`. |
| 20 | pub enabled: u32, |
| 21 | /// `update_map`. |
| 22 | pub update_map: u32, |
| 23 | /// `temporal_update`. |
| 24 | pub temporal_update: u32, |
| 25 | /// `update_data`. |
| 26 | pub update_data: u32, |
| 27 | } |
| 28 | |
| 29 | /// `VASegmentationStructAV1`. |
| 30 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 31 | pub struct SegmentationStructAV1 { |
| 32 | /// Segmentation flags. |
| 33 | pub segment_info_fields: SegmentInfoFields, |
| 34 | /// `FeatureData[segment][feature]`. |
| 35 | pub feature_data: [[i16; 8]; 8], |
| 36 | /// `FeatureEnabled` as one bit per feature, per segment. |
| 37 | pub feature_mask: [u8; 8], |
| 38 | } |
| 39 | |
| 40 | impl SegmentationStructAV1 { |
| 41 | fn to_cros(self) -> AV1Segmentation { |
| 42 | let f = self.segment_info_fields; |
| 43 | let fields = |
| 44 | AV1SegmentInfoFields::new(f.enabled, f.update_map, f.temporal_update, f.update_data); |
| 45 | AV1Segmentation::new(&fields, self.feature_data, self.feature_mask) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /// `VAFilmGrainStructAV1::film_grain_info_fields`. |
| 50 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 51 | pub struct FilmGrainInfoFields { |
| 52 | /// `apply_grain`. |
| 53 | pub apply_grain: u32, |
| 54 | /// `chroma_scaling_from_luma`. |
| 55 | pub chroma_scaling_from_luma: u32, |
| 56 | /// `grain_scaling_minus_8`. |
| 57 | pub grain_scaling_minus_8: u32, |
| 58 | /// `ar_coeff_lag`. |
| 59 | pub ar_coeff_lag: u32, |
| 60 | /// `ar_coeff_shift_minus_6`. |
| 61 | pub ar_coeff_shift_minus_6: u32, |
| 62 | /// `grain_scale_shift`. |
| 63 | pub grain_scale_shift: u32, |
| 64 | /// `overlap_flag`. |
| 65 | pub overlap_flag: u32, |
| 66 | /// `clip_to_restricted_range`. |
| 67 | pub clip_to_restricted_range: u32, |
| 68 | } |
| 69 | |
| 70 | /// `VAFilmGrainStructAV1`. |
| 71 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 72 | pub struct FilmGrainStructAV1 { |
| 73 | /// Grain flags. |
| 74 | pub film_grain_info_fields: FilmGrainInfoFields, |
| 75 | /// `grain_seed`. |
| 76 | pub grain_seed: u16, |
| 77 | /// `num_y_points`. |
| 78 | pub num_y_points: u8, |
| 79 | /// `point_y_value`. |
| 80 | pub point_y_value: [u8; 14], |
| 81 | /// `point_y_scaling`. |
| 82 | pub point_y_scaling: [u8; 14], |
| 83 | /// `num_cb_points`. |
| 84 | pub num_cb_points: u8, |
| 85 | /// `point_cb_value`. |
| 86 | pub point_cb_value: [u8; 10], |
| 87 | /// `point_cb_scaling`. |
| 88 | pub point_cb_scaling: [u8; 10], |
| 89 | /// `num_cr_points`. |
| 90 | pub num_cr_points: u8, |
| 91 | /// `point_cr_value`. |
| 92 | pub point_cr_value: [u8; 10], |
| 93 | /// `point_cr_scaling`. |
| 94 | pub point_cr_scaling: [u8; 10], |
| 95 | /// `ar_coeffs_y_plus_128` as signed coefficients. |
| 96 | pub ar_coeffs_y: [i8; 24], |
| 97 | /// `ar_coeffs_cb`. |
| 98 | pub ar_coeffs_cb: [i8; 25], |
| 99 | /// `ar_coeffs_cr`. |
| 100 | pub ar_coeffs_cr: [i8; 25], |
| 101 | /// `cb_mult`. |
| 102 | pub cb_mult: u8, |
| 103 | /// `cb_luma_mult`. |
| 104 | pub cb_luma_mult: u8, |
| 105 | /// `cb_offset`. |
| 106 | pub cb_offset: u16, |
| 107 | /// `cr_mult`. |
| 108 | pub cr_mult: u8, |
| 109 | /// `cr_luma_mult`. |
| 110 | pub cr_luma_mult: u8, |
| 111 | /// `cr_offset`. |
| 112 | pub cr_offset: u16, |
| 113 | } |
| 114 | |
| 115 | impl FilmGrainStructAV1 { |
| 116 | fn to_cros(self) -> AV1FilmGrain { |
| 117 | let f = self.film_grain_info_fields; |
| 118 | let fields = AV1FilmGrainFields::new( |
| 119 | f.apply_grain, |
| 120 | f.chroma_scaling_from_luma, |
| 121 | f.grain_scaling_minus_8, |
| 122 | f.ar_coeff_lag, |
| 123 | f.ar_coeff_shift_minus_6, |
| 124 | f.grain_scale_shift, |
| 125 | f.overlap_flag, |
| 126 | f.clip_to_restricted_range, |
| 127 | ); |
| 128 | AV1FilmGrain::new( |
| 129 | &fields, |
| 130 | self.grain_seed, |
| 131 | self.num_y_points, |
| 132 | self.point_y_value, |
| 133 | self.point_y_scaling, |
| 134 | self.num_cb_points, |
| 135 | self.point_cb_value, |
| 136 | self.point_cb_scaling, |
| 137 | self.num_cr_points, |
| 138 | self.point_cr_value, |
| 139 | self.point_cr_scaling, |
| 140 | self.ar_coeffs_y, |
| 141 | self.ar_coeffs_cb, |
| 142 | self.ar_coeffs_cr, |
| 143 | self.cb_mult, |
| 144 | self.cb_luma_mult, |
| 145 | self.cb_offset, |
| 146 | self.cr_mult, |
| 147 | self.cr_luma_mult, |
| 148 | self.cr_offset, |
| 149 | ) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /// `VAWarpedMotionParamsAV1`. |
| 154 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 155 | pub struct WarpedMotionParamsAV1 { |
| 156 | /// `wmtype`: the transformation type (`VAAV1TransformationType`). |
| 157 | pub wmtype: u32, |
| 158 | /// `wmmat`. |
| 159 | pub wmmat: [i32; 8], |
| 160 | /// `invalid`. |
| 161 | pub invalid: u8, |
| 162 | } |
| 163 | |
| 164 | /// `VADecPictureParameterBufferAV1::seq_info_fields`. |
| 165 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 166 | pub struct SeqInfoFields { |
| 167 | /// `still_picture`. |
| 168 | pub still_picture: u32, |
| 169 | /// `use_128x128_superblock`. |
| 170 | pub use_128x128_superblock: u32, |
| 171 | /// `enable_filter_intra`. |
| 172 | pub enable_filter_intra: u32, |
| 173 | /// `enable_intra_edge_filter`. |
| 174 | pub enable_intra_edge_filter: u32, |
| 175 | /// `enable_interintra_compound`. |
| 176 | pub enable_interintra_compound: u32, |
| 177 | /// `enable_masked_compound`. |
| 178 | pub enable_masked_compound: u32, |
| 179 | /// `enable_dual_filter`. |
| 180 | pub enable_dual_filter: u32, |
| 181 | /// `enable_order_hint`. |
| 182 | pub enable_order_hint: u32, |
| 183 | /// `enable_jnt_comp`. |
| 184 | pub enable_jnt_comp: u32, |
| 185 | /// `enable_cdef`. |
| 186 | pub enable_cdef: u32, |
| 187 | /// `mono_chrome`. |
| 188 | pub mono_chrome: u32, |
| 189 | /// `color_range`. |
| 190 | pub color_range: u32, |
| 191 | /// `subsampling_x`. |
| 192 | pub subsampling_x: u32, |
| 193 | /// `subsampling_y`. |
| 194 | pub subsampling_y: u32, |
| 195 | /// `chroma_sample_position`. |
| 196 | pub chroma_sample_position: u32, |
| 197 | /// `film_grain_params_present`. |
| 198 | pub film_grain_params_present: u32, |
| 199 | } |
| 200 | |
| 201 | /// `VADecPictureParameterBufferAV1::pic_info_fields`. |
| 202 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 203 | pub struct PicInfoFields { |
| 204 | /// `frame_type`. |
| 205 | pub frame_type: u32, |
| 206 | /// `show_frame`. |
| 207 | pub show_frame: u32, |
| 208 | /// `showable_frame`. |
| 209 | pub showable_frame: u32, |
| 210 | /// `error_resilient_mode`. |
| 211 | pub error_resilient_mode: u32, |
| 212 | /// `disable_cdf_update`. |
| 213 | pub disable_cdf_update: u32, |
| 214 | /// `allow_screen_content_tools`. |
| 215 | pub allow_screen_content_tools: u32, |
| 216 | /// `force_integer_mv`. |
| 217 | pub force_integer_mv: u32, |
| 218 | /// `allow_intrabc`. |
| 219 | pub allow_intrabc: u32, |
| 220 | /// `use_superres`. |
| 221 | pub use_superres: u32, |
| 222 | /// `allow_high_precision_mv`. |
| 223 | pub allow_high_precision_mv: u32, |
| 224 | /// `is_motion_mode_switchable`. |
| 225 | pub is_motion_mode_switchable: u32, |
| 226 | /// `use_ref_frame_mvs`. |
| 227 | pub use_ref_frame_mvs: u32, |
| 228 | /// `disable_frame_end_update_cdf`. |
| 229 | pub disable_frame_end_update_cdf: u32, |
| 230 | /// `uniform_tile_spacing_flag`. |
| 231 | pub uniform_tile_spacing_flag: u32, |
| 232 | /// `allow_warped_motion`. |
| 233 | pub allow_warped_motion: u32, |
| 234 | /// `large_scale_tile`. |
| 235 | pub large_scale_tile: u32, |
| 236 | } |
| 237 | |
| 238 | /// `VADecPictureParameterBufferAV1::loop_filter_info_fields`. |
| 239 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 240 | pub struct LoopFilterInfoFields { |
| 241 | /// `sharpness_level`. |
| 242 | pub sharpness_level: u8, |
| 243 | /// `mode_ref_delta_enabled`. |
| 244 | pub mode_ref_delta_enabled: u8, |
| 245 | /// `mode_ref_delta_update`. |
| 246 | pub mode_ref_delta_update: u8, |
| 247 | } |
| 248 | |
| 249 | /// `VADecPictureParameterBufferAV1::qmatrix_fields`. |
| 250 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 251 | pub struct QMatrixFields { |
| 252 | /// `using_qmatrix`. |
| 253 | pub using_qmatrix: u16, |
| 254 | /// `qm_y`. |
| 255 | pub qm_y: u16, |
| 256 | /// `qm_u`. |
| 257 | pub qm_u: u16, |
| 258 | /// `qm_v`. |
| 259 | pub qm_v: u16, |
| 260 | } |
| 261 | |
| 262 | /// `VADecPictureParameterBufferAV1::mode_control_fields`. |
| 263 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 264 | pub struct ModeControlFields { |
| 265 | /// `delta_q_present_flag`. |
| 266 | pub delta_q_present_flag: u32, |
| 267 | /// `log2_delta_q_res`. |
| 268 | pub log2_delta_q_res: u32, |
| 269 | /// `delta_lf_present_flag`. |
| 270 | pub delta_lf_present_flag: u32, |
| 271 | /// `log2_delta_lf_res`. |
| 272 | pub log2_delta_lf_res: u32, |
| 273 | /// `delta_lf_multi`. |
| 274 | pub delta_lf_multi: u32, |
| 275 | /// `tx_mode`. |
| 276 | pub tx_mode: u32, |
| 277 | /// `reference_select`. |
| 278 | pub reference_select: u32, |
| 279 | /// `reduced_tx_set_used`. |
| 280 | pub reduced_tx_set_used: u32, |
| 281 | /// `skip_mode_present`. |
| 282 | pub skip_mode_present: u32, |
| 283 | } |
| 284 | |
| 285 | /// `VADecPictureParameterBufferAV1::loop_restoration_fields`. |
| 286 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 287 | pub struct LoopRestorationFields { |
| 288 | /// `yframe_restoration_type`. |
| 289 | pub yframe_restoration_type: u16, |
| 290 | /// `cbframe_restoration_type`. |
| 291 | pub cbframe_restoration_type: u16, |
| 292 | /// `crframe_restoration_type`. |
| 293 | pub crframe_restoration_type: u16, |
| 294 | /// `lr_unit_shift`. |
| 295 | pub lr_unit_shift: u16, |
| 296 | /// `lr_uv_shift`. |
| 297 | pub lr_uv_shift: u16, |
| 298 | } |
| 299 | |
| 300 | /// `VADecPictureParameterBufferAV1`, `va_dec_av1.h`. |
| 301 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 302 | pub struct PictureParameterBufferAV1 { |
| 303 | /// `profile`. |
| 304 | pub profile: u8, |
| 305 | /// `order_hint_bits_minus_1`. |
| 306 | pub order_hint_bits_minus_1: u8, |
| 307 | /// `bit_depth_idx`: 0 for 8-bit, 1 for 10-bit. |
| 308 | pub bit_depth_idx: u8, |
| 309 | /// `matrix_coefficients`. |
| 310 | pub matrix_coefficients: u8, |
| 311 | /// Sequence flags. |
| 312 | pub seq_info_fields: SeqInfoFields, |
| 313 | /// `current_frame`: the surface being decoded into. |
| 314 | pub current_frame: u32, |
| 315 | /// `current_display_picture`: the surface the grained output lands in, or |
| 316 | /// the current frame when the frame carries no grain. |
| 317 | pub current_display_picture: u32, |
| 318 | /// `frame_width_minus1`. |
| 319 | pub frame_width_minus1: u16, |
| 320 | /// `frame_height_minus1`. |
| 321 | pub frame_height_minus1: u16, |
| 322 | /// `output_frame_width_in_tiles_minus_1` (large scale tile only). |
| 323 | pub output_frame_width_in_tiles_minus_1: u16, |
| 324 | /// `output_frame_height_in_tiles_minus_1` (large scale tile only). |
| 325 | pub output_frame_height_in_tiles_minus_1: u16, |
| 326 | /// `ref_frame_map`, `VA_INVALID_SURFACE` where empty. |
| 327 | pub ref_frame_map: [u32; 8], |
| 328 | /// `ref_frame_idx`. |
| 329 | pub ref_frame_idx: [u8; 7], |
| 330 | /// `primary_ref_frame`. |
| 331 | pub primary_ref_frame: u8, |
| 332 | /// `order_hint`. |
| 333 | pub order_hint: u8, |
| 334 | /// Segmentation state. |
| 335 | pub seg_info: SegmentationStructAV1, |
| 336 | /// Film grain state. |
| 337 | pub film_grain_info: FilmGrainStructAV1, |
| 338 | /// `tile_cols`. |
| 339 | pub tile_cols: u8, |
| 340 | /// `tile_rows`. |
| 341 | pub tile_rows: u8, |
| 342 | /// `width_in_sbs_minus_1`. |
| 343 | pub width_in_sbs_minus_1: [u16; 63], |
| 344 | /// `height_in_sbs_minus_1`. |
| 345 | pub height_in_sbs_minus_1: [u16; 63], |
| 346 | /// `tile_count_minus_1`. |
| 347 | pub tile_count_minus_1: u16, |
| 348 | /// `context_update_tile_id`. |
| 349 | pub context_update_tile_id: u16, |
| 350 | /// Picture flags. |
| 351 | pub pic_info_fields: PicInfoFields, |
| 352 | /// `superres_scale_denominator`. |
| 353 | pub superres_scale_denominator: u8, |
| 354 | /// `interp_filter`. |
| 355 | pub interp_filter: u8, |
| 356 | /// `filter_level`: luma vertical and horizontal. |
| 357 | pub filter_level: [u8; 2], |
| 358 | /// `filter_level_u`. |
| 359 | pub filter_level_u: u8, |
| 360 | /// `filter_level_v`. |
| 361 | pub filter_level_v: u8, |
| 362 | /// Loop filter flags. |
| 363 | pub loop_filter_info_fields: LoopFilterInfoFields, |
| 364 | /// `ref_deltas`. |
| 365 | pub ref_deltas: [i8; 8], |
| 366 | /// `mode_deltas`. |
| 367 | pub mode_deltas: [i8; 2], |
| 368 | /// `base_qindex`. |
| 369 | pub base_qindex: u8, |
| 370 | /// `y_dc_delta_q`. |
| 371 | pub y_dc_delta_q: i8, |
| 372 | /// `u_dc_delta_q`. |
| 373 | pub u_dc_delta_q: i8, |
| 374 | /// `u_ac_delta_q`. |
| 375 | pub u_ac_delta_q: i8, |
| 376 | /// `v_dc_delta_q`. |
| 377 | pub v_dc_delta_q: i8, |
| 378 | /// `v_ac_delta_q`. |
| 379 | pub v_ac_delta_q: i8, |
| 380 | /// Quantiser matrix flags. |
| 381 | pub qmatrix_fields: QMatrixFields, |
| 382 | /// Delta-q/lf and transform mode flags. |
| 383 | pub mode_control_fields: ModeControlFields, |
| 384 | /// `cdef_damping_minus_3`. |
| 385 | pub cdef_damping_minus_3: u8, |
| 386 | /// `cdef_bits`. |
| 387 | pub cdef_bits: u8, |
| 388 | /// `cdef_y_strengths`. |
| 389 | pub cdef_y_strengths: [u8; 8], |
| 390 | /// `cdef_uv_strengths`. |
| 391 | pub cdef_uv_strengths: [u8; 8], |
| 392 | /// Loop restoration flags. |
| 393 | pub loop_restoration_fields: LoopRestorationFields, |
| 394 | /// `wm`: global motion per reference frame. |
| 395 | pub wm: [WarpedMotionParamsAV1; 7], |
| 396 | } |
| 397 | |
| 398 | impl Default for PictureParameterBufferAV1 { |
| 399 | fn default() -> Self { |
| 400 | PictureParameterBufferAV1 { |
| 401 | profile: 0, |
| 402 | order_hint_bits_minus_1: 0, |
| 403 | bit_depth_idx: 0, |
| 404 | matrix_coefficients: 2, // MC_UNSPECIFIED |
| 405 | seq_info_fields: SeqInfoFields::default(), |
| 406 | current_frame: INVALID_SURFACE, |
| 407 | current_display_picture: INVALID_SURFACE, |
| 408 | frame_width_minus1: 0, |
| 409 | frame_height_minus1: 0, |
| 410 | output_frame_width_in_tiles_minus_1: 0, |
| 411 | output_frame_height_in_tiles_minus_1: 0, |
| 412 | ref_frame_map: [INVALID_SURFACE; 8], |
| 413 | ref_frame_idx: [0; 7], |
| 414 | primary_ref_frame: 0, |
| 415 | order_hint: 0, |
| 416 | seg_info: SegmentationStructAV1::default(), |
| 417 | film_grain_info: FilmGrainStructAV1::default(), |
| 418 | tile_cols: 1, |
| 419 | tile_rows: 1, |
| 420 | width_in_sbs_minus_1: [0; 63], |
| 421 | height_in_sbs_minus_1: [0; 63], |
| 422 | tile_count_minus_1: 0, |
| 423 | context_update_tile_id: 0, |
| 424 | pic_info_fields: PicInfoFields::default(), |
| 425 | superres_scale_denominator: 8, |
| 426 | interp_filter: 0, |
| 427 | filter_level: [0; 2], |
| 428 | filter_level_u: 0, |
| 429 | filter_level_v: 0, |
| 430 | loop_filter_info_fields: LoopFilterInfoFields::default(), |
| 431 | ref_deltas: [0; 8], |
| 432 | mode_deltas: [0; 2], |
| 433 | base_qindex: 0, |
| 434 | y_dc_delta_q: 0, |
| 435 | u_dc_delta_q: 0, |
| 436 | u_ac_delta_q: 0, |
| 437 | v_dc_delta_q: 0, |
| 438 | v_ac_delta_q: 0, |
| 439 | qmatrix_fields: QMatrixFields::default(), |
| 440 | mode_control_fields: ModeControlFields::default(), |
| 441 | cdef_damping_minus_3: 0, |
| 442 | cdef_bits: 0, |
| 443 | cdef_y_strengths: [0; 8], |
| 444 | cdef_uv_strengths: [0; 8], |
| 445 | loop_restoration_fields: LoopRestorationFields::default(), |
| 446 | wm: [WarpedMotionParamsAV1::default(); 7], |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | impl PictureParameterBufferAV1 { |
| 452 | /// The typed cros-libva buffer for these picture parameters. No scale |
| 453 | /// tile anchor list is sent: this crate does not decode large scale tile |
| 454 | /// streams, so the anchor count is zero. |
| 455 | pub fn to_buffer(&self) -> BufferType { |
| 456 | let s = self.seq_info_fields; |
| 457 | let seq = AV1SeqFields::new( |
| 458 | s.still_picture, |
| 459 | s.use_128x128_superblock, |
| 460 | s.enable_filter_intra, |
| 461 | s.enable_intra_edge_filter, |
| 462 | s.enable_interintra_compound, |
| 463 | s.enable_masked_compound, |
| 464 | s.enable_dual_filter, |
| 465 | s.enable_order_hint, |
| 466 | s.enable_jnt_comp, |
| 467 | s.enable_cdef, |
| 468 | s.mono_chrome, |
| 469 | s.color_range, |
| 470 | s.subsampling_x, |
| 471 | s.subsampling_y, |
| 472 | s.chroma_sample_position, |
| 473 | s.film_grain_params_present, |
| 474 | ); |
| 475 | let p = self.pic_info_fields; |
| 476 | let pic = AV1PicInfoFields::new( |
| 477 | p.frame_type, |
| 478 | p.show_frame, |
| 479 | p.showable_frame, |
| 480 | p.error_resilient_mode, |
| 481 | p.disable_cdf_update, |
| 482 | p.allow_screen_content_tools, |
| 483 | p.force_integer_mv, |
| 484 | p.allow_intrabc, |
| 485 | p.use_superres, |
| 486 | p.allow_high_precision_mv, |
| 487 | p.is_motion_mode_switchable, |
| 488 | p.use_ref_frame_mvs, |
| 489 | p.disable_frame_end_update_cdf, |
| 490 | p.uniform_tile_spacing_flag, |
| 491 | p.allow_warped_motion, |
| 492 | p.large_scale_tile, |
| 493 | ); |
| 494 | let lf = self.loop_filter_info_fields; |
| 495 | let loop_filter = AV1LoopFilterFields::new( |
| 496 | lf.sharpness_level, |
| 497 | lf.mode_ref_delta_enabled, |
| 498 | lf.mode_ref_delta_update, |
| 499 | ); |
| 500 | let q = self.qmatrix_fields; |
| 501 | let qmatrix = AV1QMatrixFields::new(q.using_qmatrix, q.qm_y, q.qm_u, q.qm_v); |
| 502 | let m = self.mode_control_fields; |
| 503 | let mode = AV1ModeControlFields::new( |
| 504 | m.delta_q_present_flag, |
| 505 | m.log2_delta_q_res, |
| 506 | m.delta_lf_present_flag, |
| 507 | m.log2_delta_lf_res, |
| 508 | m.delta_lf_multi, |
| 509 | m.tx_mode, |
| 510 | m.reference_select, |
| 511 | m.reduced_tx_set_used, |
| 512 | m.skip_mode_present, |
| 513 | ); |
| 514 | let r = self.loop_restoration_fields; |
| 515 | let restoration = AV1LoopRestorationFields::new( |
| 516 | r.yframe_restoration_type, |
| 517 | r.cbframe_restoration_type, |
| 518 | r.crframe_restoration_type, |
| 519 | r.lr_unit_shift, |
| 520 | r.lr_uv_shift, |
| 521 | ); |
| 522 | let wm: [AV1WarpedMotionParams; 7] = self |
| 523 | .wm |
| 524 | .map(|w| AV1WarpedMotionParams::new(w.wmtype, w.wmmat, w.invalid)); |
| 525 | BufferType::PictureParameter(PictureParameter::AV1(CrosPicture::new( |
| 526 | self.profile, |
| 527 | self.order_hint_bits_minus_1, |
| 528 | self.bit_depth_idx, |
| 529 | self.matrix_coefficients, |
| 530 | &seq, |
| 531 | self.current_frame, |
| 532 | self.current_display_picture, |
| 533 | Vec::new(), |
| 534 | self.frame_width_minus1, |
| 535 | self.frame_height_minus1, |
| 536 | self.output_frame_width_in_tiles_minus_1, |
| 537 | self.output_frame_height_in_tiles_minus_1, |
| 538 | self.ref_frame_map, |
| 539 | self.ref_frame_idx, |
| 540 | self.primary_ref_frame, |
| 541 | self.order_hint, |
| 542 | &self.seg_info.to_cros(), |
| 543 | &self.film_grain_info.to_cros(), |
| 544 | self.tile_cols, |
| 545 | self.tile_rows, |
| 546 | self.width_in_sbs_minus_1, |
| 547 | self.height_in_sbs_minus_1, |
| 548 | self.tile_count_minus_1, |
| 549 | self.context_update_tile_id, |
| 550 | &pic, |
| 551 | self.superres_scale_denominator, |
| 552 | self.interp_filter, |
| 553 | self.filter_level, |
| 554 | self.filter_level_u, |
| 555 | self.filter_level_v, |
| 556 | &loop_filter, |
| 557 | self.ref_deltas, |
| 558 | self.mode_deltas, |
| 559 | self.base_qindex, |
| 560 | self.y_dc_delta_q, |
| 561 | self.u_dc_delta_q, |
| 562 | self.u_ac_delta_q, |
| 563 | self.v_dc_delta_q, |
| 564 | self.v_ac_delta_q, |
| 565 | &qmatrix, |
| 566 | &mode, |
| 567 | self.cdef_damping_minus_3, |
| 568 | self.cdef_bits, |
| 569 | self.cdef_y_strengths, |
| 570 | self.cdef_uv_strengths, |
| 571 | &restoration, |
| 572 | &wm, |
| 573 | ))) |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | /// `VASliceParameterBufferAV1`, one per tile. |
| 578 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 579 | pub struct SliceParameterBufferAV1 { |
| 580 | /// `slice_data_size`. |
| 581 | pub slice_data_size: u32, |
| 582 | /// `slice_data_offset`. |
| 583 | pub slice_data_offset: u32, |
| 584 | /// `slice_data_flag`. |
| 585 | pub slice_data_flag: u32, |
| 586 | /// `tile_row`. |
| 587 | pub tile_row: u16, |
| 588 | /// `tile_column`. |
| 589 | pub tile_column: u16, |
| 590 | /// `tg_start`. |
| 591 | pub tg_start: u16, |
| 592 | /// `tg_end`. |
| 593 | pub tg_end: u16, |
| 594 | /// `anchor_frame_idx`. |
| 595 | pub anchor_frame_idx: u8, |
| 596 | /// `tile_idx_in_tile_list`. |
| 597 | pub tile_idx_in_tile_list: u16, |
| 598 | } |
| 599 | |
| 600 | /// The one slice-parameter buffer carrying every tile of a frame. cros-libva |
| 601 | /// sends the tiles as a single array, which is how the driver takes AV1 slices. |
| 602 | pub fn slice_buffer(tiles: &[SliceParameterBufferAV1]) -> BufferType { |
| 603 | let mut buffer = CrosSlice::new(); |
| 604 | for t in tiles { |
| 605 | buffer.add_slice_parameter( |
| 606 | t.slice_data_size, |
| 607 | t.slice_data_offset, |
| 608 | t.slice_data_flag, |
| 609 | t.tile_row, |
| 610 | t.tile_column, |
| 611 | t.tg_start, |
| 612 | t.tg_end, |
| 613 | t.anchor_frame_idx, |
| 614 | t.tile_idx_in_tile_list, |
| 615 | ); |
| 616 | } |
| 617 | BufferType::SliceParameter(SliceParameter::AV1(buffer)) |
| 618 | } |