forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB00c1b3fTahinli2 months ago1999 commits

hevc.rs473 lines, 18.4 KiBHistoryRawDownload
1//! HEVC decode parameter buffers (`va.h:5287`, `va_dec_hevc.h`).
2
3use ec_va::sys::{
4 VAIQMatrixBufferType, VAPictureParameterBufferType, VASliceParameterBufferType, VASurfaceID,
5};
6
7use super::{INVALID_SURFACE, VaParam};
8use crate::va_bits;
9
10/// `VA_PICTURE_HEVC_INVALID`.
11pub const PICTURE_INVALID: u32 = 0x0000_0001;
12/// `VA_PICTURE_HEVC_FIELD_PIC`.
13pub const PICTURE_FIELD_PIC: u32 = 0x0000_0002;
14/// `VA_PICTURE_HEVC_BOTTOM_FIELD`.
15pub const PICTURE_BOTTOM_FIELD: u32 = 0x0000_0004;
16/// `VA_PICTURE_HEVC_LONG_TERM_REFERENCE`.
17pub const PICTURE_LONG_TERM_REFERENCE: u32 = 0x0000_0008;
18/// `VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE`.
19pub const PICTURE_RPS_ST_CURR_BEFORE: u32 = 0x0000_0010;
20/// `VA_PICTURE_HEVC_RPS_ST_CURR_AFTER`.
21pub const PICTURE_RPS_ST_CURR_AFTER: u32 = 0x0000_0020;
22/// `VA_PICTURE_HEVC_RPS_LT_CURR`.
23pub const PICTURE_RPS_LT_CURR: u32 = 0x0000_0040;
24
25/// `VAPictureHEVC`, `va.h:5287`.
26#[repr(C)]
27#[derive(Debug, Clone, Copy, PartialEq, Eq)]
28pub struct VAPictureHEVC {
29 /// Surface holding the picture, or [`INVALID_SURFACE`].
30 pub picture_id: VASurfaceID,
31 /// `PicOrderCntVal`.
32 pub pic_order_cnt: i32,
33 /// `VA_PICTURE_HEVC_*` bitmask.
34 pub flags: u32,
35 pub(crate) va_reserved: [u32; 4],
36}
37
38impl VAPictureHEVC {
39 /// The "no picture here" entry for unused reference slots.
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 /// A reference or current picture.
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
58impl Default for VAPictureHEVC {
59 fn default() -> Self {
60 VAPictureHEVC::INVALID
61 }
62}
63
64va_bits! {
65 /// `VAPictureParameterBufferHEVC::pic_fields`.
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
90va_bits! {
91 /// `VAPictureParameterBufferHEVC::slice_parsing_fields`.
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/// `VAPictureParameterBufferHEVC`, `va_dec_hevc.h:57`.
111#[repr(C)]
112#[derive(Debug, Clone, Copy)]
113pub struct PictureParameterBufferHEVC {
114 /// The picture being decoded.
115 pub curr_pic: VAPictureHEVC,
116 /// The DPB; unused slots are [`VAPictureHEVC::INVALID`].
117 pub reference_frames: [VAPictureHEVC; 15],
118 /// `pic_width_in_luma_samples`.
119 pub pic_width_in_luma_samples: u16,
120 /// `pic_height_in_luma_samples`.
121 pub pic_height_in_luma_samples: u16,
122 /// Picture flags.
123 pub pic_fields: PicFields,
124 /// `sps_max_dec_pic_buffering_minus1`.
125 pub sps_max_dec_pic_buffering_minus1: u8,
126 /// `bit_depth_luma_minus8`.
127 pub bit_depth_luma_minus8: u8,
128 /// `bit_depth_chroma_minus8`.
129 pub bit_depth_chroma_minus8: u8,
130 /// `pcm_sample_bit_depth_luma_minus1`.
131 pub pcm_sample_bit_depth_luma_minus1: u8,
132 /// `pcm_sample_bit_depth_chroma_minus1`.
133 pub pcm_sample_bit_depth_chroma_minus1: u8,
134 /// `log2_min_luma_coding_block_size_minus3`.
135 pub log2_min_luma_coding_block_size_minus3: u8,
136 /// `log2_diff_max_min_luma_coding_block_size`.
137 pub log2_diff_max_min_luma_coding_block_size: u8,
138 /// `log2_min_transform_block_size_minus2`.
139 pub log2_min_transform_block_size_minus2: u8,
140 /// `log2_diff_max_min_transform_block_size`.
141 pub log2_diff_max_min_transform_block_size: u8,
142 /// `log2_min_pcm_luma_coding_block_size_minus3`.
143 pub log2_min_pcm_luma_coding_block_size_minus3: u8,
144 /// `log2_diff_max_min_pcm_luma_coding_block_size`.
145 pub log2_diff_max_min_pcm_luma_coding_block_size: u8,
146 /// `max_transform_hierarchy_depth_intra`.
147 pub max_transform_hierarchy_depth_intra: u8,
148 /// `max_transform_hierarchy_depth_inter`.
149 pub max_transform_hierarchy_depth_inter: u8,
150 /// `init_qp_minus26`.
151 pub init_qp_minus26: i8,
152 /// `diff_cu_qp_delta_depth`.
153 pub diff_cu_qp_delta_depth: u8,
154 /// `pps_cb_qp_offset`.
155 pub pps_cb_qp_offset: i8,
156 /// `pps_cr_qp_offset`.
157 pub pps_cr_qp_offset: i8,
158 /// `log2_parallel_merge_level_minus2`.
159 pub log2_parallel_merge_level_minus2: u8,
160 /// `num_tile_columns_minus1`.
161 pub num_tile_columns_minus1: u8,
162 /// `num_tile_rows_minus1`.
163 pub num_tile_rows_minus1: u8,
164 /// `column_width_minus1`, filled even for uniform spacing.
165 pub column_width_minus1: [u16; 19],
166 /// `row_height_minus1`, filled even for uniform spacing.
167 pub row_height_minus1: [u16; 21],
168 /// Flags a driver needs to parse slice segment headers.
169 pub slice_parsing_fields: SliceParsingFields,
170 /// `log2_max_pic_order_cnt_lsb_minus4`.
171 pub log2_max_pic_order_cnt_lsb_minus4: u8,
172 /// `num_short_term_ref_pic_sets`.
173 pub num_short_term_ref_pic_sets: u8,
174 /// `num_long_term_ref_pics_sps`.
175 pub num_long_term_ref_pic_sps: u8,
176 /// `num_ref_idx_l0_default_active_minus1`.
177 pub num_ref_idx_l0_default_active_minus1: u8,
178 /// `num_ref_idx_l1_default_active_minus1`.
179 pub num_ref_idx_l1_default_active_minus1: u8,
180 /// `pps_beta_offset_div2`.
181 pub pps_beta_offset_div2: i8,
182 /// `pps_tc_offset_div2`.
183 pub pps_tc_offset_div2: i8,
184 /// `num_extra_slice_header_bits`.
185 pub num_extra_slice_header_bits: u8,
186 /// Size in bits of the `st_ref_pic_set()` written in the slice header, so
187 /// the driver can skip it; zero when the slice referenced an SPS set.
188 pub st_rps_bits: u32,
189 pub(crate) va_reserved: [u32; 8],
190}
191
192impl 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// SAFETY: `#[repr(C)]` transcription of `VAPictureParameterBufferHEVC`, checked
238// by the assertion block below; all fields are integers or integer arrays.
239unsafe impl VaParam for PictureParameterBufferHEVC {
240 const TYPE: i32 = VAPictureParameterBufferType;
241}
242
243va_bits! {
244 /// `VASliceParameterBufferHEVC::LongSliceFlags`.
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/// `VASliceParameterBufferHEVC`, `va_dec_hevc.h:352`.
262#[repr(C)]
263#[derive(Debug, Clone, Copy)]
264pub struct SliceParameterBufferHEVC {
265 /// Bytes of slice data, NAL unit header included.
266 pub slice_data_size: u32,
267 /// Offset of this slice's NAL unit within the data buffer.
268 pub slice_data_offset: u32,
269 /// `VA_SLICE_DATA_FLAG_*`.
270 pub slice_data_flag: u32,
271 /// Bytes from the NAL unit header to `slice_data()`, in escaped bytes.
272 pub slice_data_byte_offset: u32,
273 /// `slice_segment_address`.
274 pub slice_segment_address: u32,
275 /// Indices into `reference_frames`, `0xff` for unused entries.
276 pub ref_pic_list: [[u8; 15]; 2],
277 /// Slice flags.
278 pub long_slice_flags: LongSliceFlags,
279 /// Index into `ref_pic_list`, `0xff` when there is no collocated picture.
280 pub collocated_ref_idx: u8,
281 /// `num_ref_idx_l0_active_minus1`, override applied.
282 pub num_ref_idx_l0_active_minus1: u8,
283 /// `num_ref_idx_l1_active_minus1`, override applied.
284 pub num_ref_idx_l1_active_minus1: u8,
285 /// `slice_qp_delta`.
286 pub slice_qp_delta: i8,
287 /// `slice_cb_qp_offset`.
288 pub slice_cb_qp_offset: i8,
289 /// `slice_cr_qp_offset`.
290 pub slice_cr_qp_offset: i8,
291 /// `slice_beta_offset_div2`.
292 pub slice_beta_offset_div2: i8,
293 /// `slice_tc_offset_div2`.
294 pub slice_tc_offset_div2: i8,
295 /// `luma_log2_weight_denom`.
296 pub luma_log2_weight_denom: u8,
297 /// `delta_chroma_log2_weight_denom`.
298 pub delta_chroma_log2_weight_denom: i8,
299 /// `delta_luma_weight_l0`.
300 pub delta_luma_weight_l0: [i8; 15],
301 /// `luma_offset_l0`.
302 pub luma_offset_l0: [i8; 15],
303 /// `delta_chroma_weight_l0`.
304 pub delta_chroma_weight_l0: [[i8; 2]; 15],
305 /// `ChromaOffsetL0`.
306 pub chroma_offset_l0: [[i8; 2]; 15],
307 /// `delta_luma_weight_l1`.
308 pub delta_luma_weight_l1: [i8; 15],
309 /// `luma_offset_l1`.
310 pub luma_offset_l1: [i8; 15],
311 /// `delta_chroma_weight_l1`.
312 pub delta_chroma_weight_l1: [[i8; 2]; 15],
313 /// `ChromaOffsetL1`.
314 pub chroma_offset_l1: [[i8; 2]; 15],
315 /// `five_minus_max_num_merge_cand`.
316 pub five_minus_max_num_merge_cand: u8,
317 /// `num_entry_point_offsets`.
318 pub num_entry_point_offsets: u16,
319 /// `entry_offset_to_subset_array`.
320 pub entry_offset_to_subset_array: u16,
321 /// Emulation prevention bytes inside the slice header.
322 pub slice_data_num_emu_prevn_bytes: u16,
323 pub(crate) va_reserved: [u32; 2],
324}
325
326impl 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// SAFETY: as `PictureParameterBufferHEVC`.
364unsafe impl VaParam for SliceParameterBufferHEVC {
365 const TYPE: i32 = VASliceParameterBufferType;
366}
367
368/// `VAIQMatrixBufferHEVC`, `va_dec_hevc.h:561`.
369#[repr(C)]
370#[derive(Debug, Clone, Copy)]
371pub struct IQMatrixBufferHEVC {
372 /// `ScalingList[0]`.
373 pub scaling_list_4x4: [[u8; 16]; 6],
374 /// `ScalingList[1]`.
375 pub scaling_list_8x8: [[u8; 64]; 6],
376 /// `ScalingList[2]`.
377 pub scaling_list_16x16: [[u8; 64]; 6],
378 /// `ScalingList[3]`.
379 pub scaling_list_32x32: [[u8; 64]; 2],
380 /// DC coefficients of the 16x16 lists.
381 pub scaling_list_dc_16x16: [u8; 6],
382 /// DC coefficients of the 32x32 lists.
383 pub scaling_list_dc_32x32: [u8; 2],
384 pub(crate) va_reserved: [u32; 4],
385}
386
387impl 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// SAFETY: as `PictureParameterBufferHEVC`.
402unsafe impl VaParam for IQMatrixBufferHEVC {
403 const TYPE: i32 = VAIQMatrixBufferType;
404}
405
406// ---------------------------------------------------------------------------
407// ABI transcription check — `crates/ec-hw/abi-probe.c`, libva 1.23.0, x86_64:
408//
409// VAPictureHEVC size=28 align=4 pic_order_cnt=4 flags=8
410// VAPictureParameterBufferHEVC size=604 align=4 ReferenceFrames=28
411// pic_width_in_luma_samples=448
412// pic_fields=452
413// sps_max_dec_pic_buffering_minus1=456
414// column_width_minus1=476
415// row_height_minus1=514
416// slice_parsing_fields=556
417// log2_max_pic_order_cnt_lsb_minus4=560
418// st_rps_bits=568
419// VASliceParameterBufferHEVC size=264 align=4 slice_segment_address=16
420// RefPicList=20 LongSliceFlags=52
421// collocated_ref_idx=56
422// luma_log2_weight_denom=64
423// delta_luma_weight_l0=66
424// delta_luma_weight_l1=156
425// five_minus_max_num_merge_cand=246
426// num_entry_point_offsets=248
427// slice_data_num_emu_prevn_bytes=252
428// VAIQMatrixBufferHEVC size=1016 align=4 ScalingList32x32=864
429// ScalingListDC16x16=992
430const _: () = {
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};