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 | // Copyright 2023 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 | //! Wrappers around VP9 `VABuffer` types. |
| 6 | |
| 7 | use crate::bindings; |
| 8 | |
| 9 | /// Wrapper over the `pic_fields` bindgen field in `VAPictureParameterBufferVP9`. |
| 10 | pub struct VP9PicFields(bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1); |
| 11 | |
| 12 | impl VP9PicFields { |
| 13 | /// Creates the bindgen field |
| 14 | #[allow(clippy::too_many_arguments)] |
| 15 | pub fn new( |
| 16 | subsampling_x: u32, |
| 17 | subsampling_y: u32, |
| 18 | frame_type: u32, |
| 19 | show_frame: u32, |
| 20 | error_resilient_mode: u32, |
| 21 | intra_only: u32, |
| 22 | allow_high_precision_mv: u32, |
| 23 | mcomp_filter_type: u32, |
| 24 | frame_parallel_decoding_mode: u32, |
| 25 | reset_frame_context: u32, |
| 26 | refresh_frame_context: u32, |
| 27 | frame_context_idx: u32, |
| 28 | segmentation_enabled: u32, |
| 29 | segmentation_temporal_update: u32, |
| 30 | segmentation_update_map: u32, |
| 31 | last_ref_frame: u32, |
| 32 | last_ref_frame_sign_bias: u32, |
| 33 | golden_ref_frame: u32, |
| 34 | golden_ref_frame_sign_bias: u32, |
| 35 | alt_ref_frame: u32, |
| 36 | alt_ref_frame_sign_bias: u32, |
| 37 | lossless_flag: u32, |
| 38 | ) -> Self { |
| 39 | let _bitfield_1 = |
| 40 | bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( |
| 41 | subsampling_x, |
| 42 | subsampling_y, |
| 43 | frame_type, |
| 44 | show_frame, |
| 45 | error_resilient_mode, |
| 46 | intra_only, |
| 47 | allow_high_precision_mv, |
| 48 | mcomp_filter_type, |
| 49 | frame_parallel_decoding_mode, |
| 50 | reset_frame_context, |
| 51 | refresh_frame_context, |
| 52 | frame_context_idx, |
| 53 | segmentation_enabled, |
| 54 | segmentation_temporal_update, |
| 55 | segmentation_update_map, |
| 56 | last_ref_frame, |
| 57 | last_ref_frame_sign_bias, |
| 58 | golden_ref_frame, |
| 59 | golden_ref_frame_sign_bias, |
| 60 | alt_ref_frame, |
| 61 | alt_ref_frame_sign_bias, |
| 62 | lossless_flag, |
| 63 | ); |
| 64 | |
| 65 | Self(bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1 { |
| 66 | bits: bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1 { |
| 67 | _bitfield_align_1: Default::default(), |
| 68 | _bitfield_1, |
| 69 | }, |
| 70 | }) |
| 71 | } |
| 72 | |
| 73 | /// Returns the inner FFI type. Useful for testing purposes. |
| 74 | pub fn inner(&mut self) -> &bindings::_VADecPictureParameterBufferVP9__bindgen_ty_1 { |
| 75 | &self.0 |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /// Wrapper over the `PictureParameterBufferVP9` FFI type. |
| 80 | pub struct PictureParameterBufferVP9(Box<bindings::VADecPictureParameterBufferVP9>); |
| 81 | |
| 82 | impl PictureParameterBufferVP9 { |
| 83 | /// Creates the wrapper |
| 84 | #[allow(clippy::too_many_arguments)] |
| 85 | pub fn new( |
| 86 | frame_width: u16, |
| 87 | frame_height: u16, |
| 88 | reference_frames: [bindings::VASurfaceID; 8], |
| 89 | pic_fields: &VP9PicFields, |
| 90 | filter_level: u8, |
| 91 | sharpness_level: u8, |
| 92 | log2_tile_rows: u8, |
| 93 | log2_tile_columns: u8, |
| 94 | frame_header_length_in_bytes: u8, |
| 95 | first_partition_size: u16, |
| 96 | mb_segment_tree_probs: [u8; 7usize], |
| 97 | segment_pred_probs: [u8; 3usize], |
| 98 | profile: u8, |
| 99 | bit_depth: u8, |
| 100 | ) -> Self { |
| 101 | let pic_fields = pic_fields.0; |
| 102 | |
| 103 | Self(Box::new(bindings::VADecPictureParameterBufferVP9 { |
| 104 | frame_width, |
| 105 | frame_height, |
| 106 | reference_frames, |
| 107 | pic_fields, |
| 108 | filter_level, |
| 109 | sharpness_level, |
| 110 | log2_tile_rows, |
| 111 | log2_tile_columns, |
| 112 | frame_header_length_in_bytes, |
| 113 | first_partition_size, |
| 114 | mb_segment_tree_probs, |
| 115 | segment_pred_probs, |
| 116 | profile, |
| 117 | bit_depth, |
| 118 | va_reserved: Default::default(), |
| 119 | })) |
| 120 | } |
| 121 | |
| 122 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VADecPictureParameterBufferVP9 { |
| 123 | self.0.as_mut() |
| 124 | } |
| 125 | |
| 126 | /// Returns the inner FFI type. Useful for testing purposes. |
| 127 | pub fn inner(&self) -> &bindings::VADecPictureParameterBufferVP9 { |
| 128 | self.0.as_ref() |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /// Wrapper over the `segment_flags` bindgen field in `VASegmentParameterVP9`. |
| 133 | pub struct VP9SegmentFlags(bindings::_VASegmentParameterVP9__bindgen_ty_1); |
| 134 | |
| 135 | impl VP9SegmentFlags { |
| 136 | /// Creates the wrapper. |
| 137 | pub fn new( |
| 138 | segment_reference_enabled: u16, |
| 139 | segment_reference: u16, |
| 140 | segment_reference_skipped: u16, |
| 141 | ) -> Self { |
| 142 | let _bitfield_1 = |
| 143 | bindings::_VASegmentParameterVP9__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( |
| 144 | segment_reference_enabled, |
| 145 | segment_reference, |
| 146 | segment_reference_skipped, |
| 147 | ); |
| 148 | |
| 149 | Self(bindings::_VASegmentParameterVP9__bindgen_ty_1 { |
| 150 | fields: bindings::_VASegmentParameterVP9__bindgen_ty_1__bindgen_ty_1 { |
| 151 | _bitfield_align_1: Default::default(), |
| 152 | _bitfield_1, |
| 153 | __bindgen_padding_0: Default::default(), |
| 154 | }, |
| 155 | }) |
| 156 | } |
| 157 | |
| 158 | /// Returns the inner FFI type. Useful for testing purposes. |
| 159 | pub fn inner(&mut self) -> &bindings::_VASegmentParameterVP9__bindgen_ty_1 { |
| 160 | &self.0 |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | /// Wrapper over the `VASegmentParameterVP9` FFI type. |
| 165 | pub struct SegmentParameterVP9(bindings::VASegmentParameterVP9); |
| 166 | |
| 167 | impl SegmentParameterVP9 { |
| 168 | /// Creates the wrapper. |
| 169 | pub fn new( |
| 170 | segment_flags: &VP9SegmentFlags, |
| 171 | filter_level: [[u8; 2usize]; 4usize], |
| 172 | luma_ac_quant_scale: i16, |
| 173 | luma_dc_quant_scale: i16, |
| 174 | chroma_ac_quant_scale: i16, |
| 175 | chroma_dc_quant_scale: i16, |
| 176 | ) -> Self { |
| 177 | let segment_flags = segment_flags.0; |
| 178 | |
| 179 | Self(bindings::VASegmentParameterVP9 { |
| 180 | segment_flags, |
| 181 | filter_level, |
| 182 | luma_ac_quant_scale, |
| 183 | luma_dc_quant_scale, |
| 184 | chroma_ac_quant_scale, |
| 185 | chroma_dc_quant_scale, |
| 186 | va_reserved: Default::default(), |
| 187 | }) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /// Wrapper over the `VASliceParameterBufferVP9` FFI type. |
| 192 | pub struct SliceParameterBufferVP9(Box<bindings::VASliceParameterBufferVP9>); |
| 193 | |
| 194 | impl SliceParameterBufferVP9 { |
| 195 | /// Creates the wrapper. |
| 196 | pub fn new( |
| 197 | slice_data_size: u32, |
| 198 | slice_data_offset: u32, |
| 199 | slice_data_flag: u32, |
| 200 | seg_param: [SegmentParameterVP9; 8usize], |
| 201 | ) -> Self { |
| 202 | let seg_param = seg_param.map(|param| param.0); |
| 203 | |
| 204 | Self(Box::new(bindings::VASliceParameterBufferVP9 { |
| 205 | slice_data_size, |
| 206 | slice_data_offset, |
| 207 | slice_data_flag, |
| 208 | seg_param, |
| 209 | va_reserved: Default::default(), |
| 210 | })) |
| 211 | } |
| 212 | |
| 213 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferVP9 { |
| 214 | self.0.as_mut() |
| 215 | } |
| 216 | |
| 217 | /// Returns the inner FFI type. Useful for testing purposes. |
| 218 | pub fn inner(&self) -> &bindings::VASliceParameterBufferVP9 { |
| 219 | self.0.as_ref() |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | pub struct CodedBufferVP9Status(Box<bindings::VACodedBufferVP9Status>); |
| 224 | |
| 225 | impl CodedBufferVP9Status { |
| 226 | pub fn new( |
| 227 | base_qp_index: u16, |
| 228 | loop_filter_level: u8, |
| 229 | long_term_indication: u8, |
| 230 | next_frame_width: u16, |
| 231 | next_frame_height: u16, |
| 232 | ) -> Self { |
| 233 | Self(Box::new(bindings::VACodedBufferVP9Status { |
| 234 | base_qp_index, |
| 235 | loop_filter_level, |
| 236 | long_term_indication, |
| 237 | next_frame_width, |
| 238 | next_frame_height, |
| 239 | va_reserved: Default::default(), |
| 240 | })) |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | pub struct EncSequenceParameterBufferVP9(Box<bindings::VAEncSequenceParameterBufferVP9>); |
| 245 | |
| 246 | impl EncSequenceParameterBufferVP9 { |
| 247 | pub fn new( |
| 248 | max_frame_width: u32, |
| 249 | max_frame_height: u32, |
| 250 | kf_auto: u32, |
| 251 | kf_min_dist: u32, |
| 252 | kf_max_dist: u32, |
| 253 | bits_per_second: u32, |
| 254 | intra_period: u32, |
| 255 | ) -> Self { |
| 256 | Self(Box::new(bindings::VAEncSequenceParameterBufferVP9 { |
| 257 | max_frame_width, |
| 258 | max_frame_height, |
| 259 | kf_auto, |
| 260 | kf_min_dist, |
| 261 | kf_max_dist, |
| 262 | bits_per_second, |
| 263 | intra_period, |
| 264 | va_reserved: Default::default(), |
| 265 | })) |
| 266 | } |
| 267 | |
| 268 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSequenceParameterBufferVP9 { |
| 269 | &mut self.0 |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | pub struct VP9EncRefFlags(bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_1); |
| 274 | |
| 275 | impl VP9EncRefFlags { |
| 276 | #[allow(clippy::too_many_arguments)] |
| 277 | pub fn new( |
| 278 | force_kf: u32, |
| 279 | ref_frame_ctrl_l0: u32, |
| 280 | ref_frame_ctrl_l1: u32, |
| 281 | ref_last_idx: u32, |
| 282 | ref_last_sign_bias: u32, |
| 283 | ref_gf_idx: u32, |
| 284 | ref_gf_sign_bias: u32, |
| 285 | ref_arf_idx: u32, |
| 286 | ref_arf_sign_bias: u32, |
| 287 | temporal_id: u32, |
| 288 | ) -> Self { |
| 289 | let _bitfield_1 = |
| 290 | bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1::new_bitfield_1( |
| 291 | force_kf, |
| 292 | ref_frame_ctrl_l0, |
| 293 | ref_frame_ctrl_l1, |
| 294 | ref_last_idx, |
| 295 | ref_last_sign_bias, |
| 296 | ref_gf_idx, |
| 297 | ref_gf_sign_bias, |
| 298 | ref_arf_idx, |
| 299 | ref_arf_sign_bias, |
| 300 | temporal_id, |
| 301 | Default::default(), |
| 302 | ); |
| 303 | |
| 304 | Self(bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_1 { |
| 305 | bits: bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_1__bindgen_ty_1 { |
| 306 | _bitfield_align_1: Default::default(), |
| 307 | _bitfield_1, |
| 308 | }, |
| 309 | }) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | pub struct VP9EncPicFlags(bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_2); |
| 314 | |
| 315 | impl VP9EncPicFlags { |
| 316 | #[allow(clippy::too_many_arguments)] |
| 317 | pub fn new( |
| 318 | frame_type: u32, |
| 319 | show_frame: u32, |
| 320 | error_resilient_mode: u32, |
| 321 | intra_only: u32, |
| 322 | allow_high_precision_mv: u32, |
| 323 | mcomp_filter_type: u32, |
| 324 | frame_parallel_decoding_mode: u32, |
| 325 | reset_frame_context: u32, |
| 326 | refresh_frame_context: u32, |
| 327 | frame_context_idx: u32, |
| 328 | segmentation_enabled: u32, |
| 329 | segmentation_temporal_update: u32, |
| 330 | segmentation_update_map: u32, |
| 331 | lossless_mode: u32, |
| 332 | comp_prediction_mode: u32, |
| 333 | auto_segmentation: u32, |
| 334 | super_frame_flag: u32, |
| 335 | ) -> Self { |
| 336 | let _bitfield_1 = |
| 337 | bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_2__bindgen_ty_1::new_bitfield_1( |
| 338 | frame_type, |
| 339 | show_frame, |
| 340 | error_resilient_mode, |
| 341 | intra_only, |
| 342 | allow_high_precision_mv, |
| 343 | mcomp_filter_type, |
| 344 | frame_parallel_decoding_mode, |
| 345 | reset_frame_context, |
| 346 | refresh_frame_context, |
| 347 | frame_context_idx, |
| 348 | segmentation_enabled, |
| 349 | segmentation_temporal_update, |
| 350 | segmentation_update_map, |
| 351 | lossless_mode, |
| 352 | comp_prediction_mode, |
| 353 | auto_segmentation, |
| 354 | super_frame_flag, |
| 355 | Default::default(), |
| 356 | ); |
| 357 | |
| 358 | Self(bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_2 { |
| 359 | bits: bindings::_VAEncPictureParameterBufferVP9__bindgen_ty_2__bindgen_ty_1 { |
| 360 | _bitfield_align_1: Default::default(), |
| 361 | _bitfield_1, |
| 362 | }, |
| 363 | }) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | pub struct EncPictureParameterBufferVP9(Box<bindings::VAEncPictureParameterBufferVP9>); |
| 368 | |
| 369 | impl EncPictureParameterBufferVP9 { |
| 370 | #[allow(clippy::too_many_arguments)] |
| 371 | pub fn new( |
| 372 | frame_width_src: u32, |
| 373 | frame_height_src: u32, |
| 374 | frame_width_dst: u32, |
| 375 | frame_height_dst: u32, |
| 376 | reconstructed_frame: bindings::VASurfaceID, |
| 377 | reference_frames: [bindings::VASurfaceID; 8usize], |
| 378 | coded_buf: bindings::VABufferID, |
| 379 | ref_flags: &VP9EncRefFlags, |
| 380 | pic_flags: &VP9EncPicFlags, |
| 381 | refresh_frame_flags: u8, |
| 382 | luma_ac_qindex: u8, |
| 383 | luma_dc_qindex_delta: i8, |
| 384 | chroma_ac_qindex_delta: i8, |
| 385 | chroma_dc_qindex_delta: i8, |
| 386 | filter_level: u8, |
| 387 | sharpness_level: u8, |
| 388 | ref_lf_delta: [i8; 4usize], |
| 389 | mode_lf_delta: [i8; 2usize], |
| 390 | bit_offset_ref_lf_delta: u16, |
| 391 | bit_offset_mode_lf_delta: u16, |
| 392 | bit_offset_lf_level: u16, |
| 393 | bit_offset_qindex: u16, |
| 394 | bit_offset_first_partition_size: u16, |
| 395 | bit_offset_segmentation: u16, |
| 396 | bit_size_segmentation: u16, |
| 397 | log2_tile_rows: u8, |
| 398 | log2_tile_columns: u8, |
| 399 | skip_frame_flag: u8, |
| 400 | number_skip_frames: u8, |
| 401 | skip_frames_size: u32, |
| 402 | seg_id_block_size: u8, |
| 403 | ) -> Self { |
| 404 | let ref_flags = ref_flags.0; |
| 405 | let pic_flags = pic_flags.0; |
| 406 | #[cfg(not(libva_1_23_or_higher))] |
| 407 | let _ = seg_id_block_size; |
| 408 | |
| 409 | Self(Box::new(bindings::VAEncPictureParameterBufferVP9 { |
| 410 | frame_width_src, |
| 411 | frame_height_src, |
| 412 | frame_width_dst, |
| 413 | frame_height_dst, |
| 414 | reconstructed_frame, |
| 415 | reference_frames, |
| 416 | coded_buf, |
| 417 | ref_flags, |
| 418 | pic_flags, |
| 419 | refresh_frame_flags, |
| 420 | luma_ac_qindex, |
| 421 | luma_dc_qindex_delta, |
| 422 | chroma_ac_qindex_delta, |
| 423 | chroma_dc_qindex_delta, |
| 424 | filter_level, |
| 425 | sharpness_level, |
| 426 | ref_lf_delta, |
| 427 | mode_lf_delta, |
| 428 | bit_offset_ref_lf_delta, |
| 429 | bit_offset_mode_lf_delta, |
| 430 | bit_offset_lf_level, |
| 431 | bit_offset_qindex, |
| 432 | bit_offset_first_partition_size, |
| 433 | bit_offset_segmentation, |
| 434 | bit_size_segmentation, |
| 435 | log2_tile_rows, |
| 436 | log2_tile_columns, |
| 437 | skip_frame_flag, |
| 438 | number_skip_frames, |
| 439 | skip_frames_size, |
| 440 | #[cfg(libva_1_23_or_higher)] |
| 441 | seg_id_block_size, |
| 442 | #[cfg(libva_1_23_or_higher)] |
| 443 | va_reserved8: Default::default(), |
| 444 | va_reserved: Default::default(), |
| 445 | })) |
| 446 | } |
| 447 | |
| 448 | pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferVP9 { |
| 449 | &mut self.0 |
| 450 | } |
| 451 | } |