rav2d 0.3.0

AV2 video decoder in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
pub const MAX_CDEF_STRENGTHS: usize = 8;
pub const MAX_OPERATING_POINTS: usize = 64;
pub const MAX_TILE_COLS: usize = 64;
pub const MAX_TILE_ROWS: usize = 64;
pub const MAX_SEGMENTS: usize = 16;
pub const NUM_REF_FRAMES: usize = 8;
pub const PRIMARY_REF_NONE: u8 = 7;
pub const REFS_PER_FRAME: usize = 7;
pub const TOTAL_REFS_PER_FRAME: usize = REFS_PER_FRAME + 1;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum ObuType {
    SeqHdr = 1,
    Td = 2,
    MultiFrameHdr = 3,
    ClosedLoopKf = 4,
    OpenLoopKf = 5,
    LeadingTileGrp = 6,
    TileGrp = 7,
    Metadata = 8,
    MetadataGrp = 9,
    Switch = 10,
    LeadingSef = 11,
    Sef = 12,
    LeadingTip = 13,
    Tip = 14,
    BufRmTiming = 15,
    LayerCfgRec = 16,
    AtlasSeg = 17,
    OpPtSet = 18,
    Bridge = 19,
    Msdo = 20,
    Ras = 21,
    Qm = 22,
    Fgm = 23,
    ContentInterp = 24,
    Padding = 25,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum TxfmMode {
    #[default]
    Only4x4 = 0,
    Largest = 1,
    Switchable = 2,
}
pub const N_TX_MODES: usize = 3;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum FilterMode {
    #[default]
    Regular8Tap = 0,
    Smooth8Tap = 1,
    Sharp8Tap = 2,
    Bilinear = 3,
    Switchable = 4,
}
pub const N_SWITCHABLE_FILTERS: usize = 3;
pub const N_FILTERS: usize = 4;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum AdaptiveBoolean {
    #[default]
    Off = 0,
    On = 1,
    Adaptive = 2,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum RestorationType {
    #[default]
    None = 0,
    PcWiener = 1,
    NsWiener = 2,
    Switchable = 3,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(i8)]
#[derive(Default)]
pub enum WarpedMotionType {
    Invalid = -1,
    #[default]
    Identity = 0,
    Translation = 1,
    RotZoom = 2,
    Affine = 3,
}

impl WarpedMotionType {
    /// # Safety
    /// `val` must be in range -1..=3 (Invalid..Affine).
    pub unsafe fn from_raw(val: i8) -> Self {
        debug_assert!((-1..=3).contains(&val), "invalid WarpedMotionType: {val}");
        unsafe { std::mem::transmute(val) }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum PixelLayout {
    #[default]
    I400 = 0,
    I420 = 1,
    I422 = 2,
    I444 = 3,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum FrameType {
    #[default]
    Key = 0,
    Inter = 1,
    Intra = 2,
    Switch = 3,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum ColorDescription {
    #[default]
    Explicit = 0,
    Bt709Sdr = 1,
    Bt2100Pq = 2,
    Bt2100Hlg = 3,
    Srgb = 4,
    SrgbSycc = 5,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum ColorPrimaries {
    Bt709 = 1,
    #[default]
    Unknown = 2,
    Bt470M = 4,
    Bt470Bg = 5,
    Bt601 = 6,
    Smpte240 = 7,
    Film = 8,
    Bt2020 = 9,
    Xyz = 10,
    Smpte431 = 11,
    Smpte432 = 12,
    Ebu3213 = 22,
    Reserved = 255,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum TransferCharacteristics {
    Bt709 = 1,
    #[default]
    Unknown = 2,
    Bt470M = 4,
    Bt470Bg = 5,
    Bt601 = 6,
    Smpte240 = 7,
    Linear = 8,
    Log100 = 9,
    Log100Sqrt10 = 10,
    Iec61966 = 11,
    Bt1361 = 12,
    Srgb = 13,
    Bt2020_10Bit = 14,
    Bt2020_12Bit = 15,
    Smpte2084 = 16,
    Smpte428 = 17,
    Hlg = 18,
    Reserved = 255,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum MatrixCoefficients {
    Identity = 0,
    Bt709 = 1,
    #[default]
    Unknown = 2,
    Fcc = 4,
    Bt470Bg = 5,
    Bt601 = 6,
    Smpte240 = 7,
    SmpteYcgco = 8,
    Bt2020Ncl = 9,
    Bt2020Cl = 10,
    Smpte2085 = 11,
    ChromatNcl = 12,
    ChromatCl = 13,
    Ictcp = 14,
    IptC2 = 15,
    YcgcoRe = 16,
    YcgcoRo = 17,
    Reserved = 255,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum ChromaSamplePosition {
    Left = 0,
    Center = 1,
    TopLeft = 2,
    Top = 3,
    BottomLeft = 4,
    Bottom = 5,
    #[default]
    Unknown = 6,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum ScanType {
    #[default]
    Unknown = 0,
    Progressive = 1,
    Interlace = 2,
    InterlaceComplementary = 3,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum AspectRatio {
    #[default]
    Unknown = 0,
    Sar1_1 = 1,
    Sar12_11 = 2,
    Sar10_11 = 3,
    Sar16_11 = 4,
    Sar40_33 = 5,
    Sar24_11 = 6,
    Sar20_11 = 7,
    Sar32_11 = 8,
    Sar80_33 = 9,
    Sar18_11 = 10,
    Sar15_11 = 11,
    Sar64_33 = 12,
    Sar160_99 = 13,
    Sar4_3 = 14,
    Sar3_2 = 15,
    Sar2_1 = 16,
    Explicit = 255,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct CiColor {
    pub desc_type: ColorDescription,
    pub pri: ColorPrimaries,
    pub trc: TransferCharacteristics,
    pub mtrx: MatrixCoefficients,
    pub range: u8,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct CiSar {
    pub sar_type: AspectRatio,
    pub w: u32,
    pub h: u32,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct CiTiming {
    pub num_units_in_display_tick: u32,
    pub time_scale: u32,
    pub equal_elemental_interval: u8,
    pub num_ticks_per_elemental_duration: u32,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct ContentInterpretation {
    pub scan_type: ScanType,
    pub color_description_present: bool,
    pub chroma_sample_position_present: bool,
    pub aspect_ratio_info_present: bool,
    pub timing_info_present: bool,
    pub extension_present: bool,
    pub chr: [ChromaSamplePosition; 2],
    pub color: CiColor,
    pub sar: CiSar,
    pub timing: CiTiming,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct WarpedMotionParams {
    pub wm_type: WarpedMotionType,
    pub matrix: [i32; 6],
    pub abcd: [i16; 4],
    pub affine: i32,
}

#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct SegmentationDataSet {
    pub delta_q: [i16; MAX_SEGMENTS],
    pub delta_q_mask: u16,
    pub skip_mask: u16,
    pub globalmv_mask: u16,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct ContentLightLevel {
    pub max_content_light_level: u16,
    pub max_frame_average_light_level: u16,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct MasteringDisplay {
    pub primaries: [[u16; 2]; 3],
    pub white_point: [u16; 2],
    pub max_luminance: u32,
    pub min_luminance: u32,
}

#[derive(Debug, Clone, PartialEq)]
pub struct TileInfo {
    pub uniform: bool,
    pub min_log2_cols: u8,
    pub max_log2_cols: u8,
    pub log2_cols: u8,
    pub cols: u8,
    pub min_log2_rows: u8,
    pub max_log2_rows: u8,
    pub log2_rows: u8,
    pub rows: u8,
    pub col_start_sb: Box<[u16; MAX_TILE_COLS + 1]>,
    pub row_start_sb: Box<[u16; MAX_TILE_ROWS + 1]>,
}

impl Default for TileInfo {
    fn default() -> Self {
        Self {
            uniform: false,
            min_log2_cols: 0,
            max_log2_cols: 0,
            log2_cols: 0,
            cols: 0,
            min_log2_rows: 0,
            max_log2_rows: 0,
            log2_rows: 0,
            rows: 0,
            col_start_sb: Box::new([0u16; MAX_TILE_COLS + 1]),
            row_start_sb: Box::new([0u16; MAX_TILE_ROWS + 1]),
        }
    }
}

#[derive(Debug, Clone, Default, PartialEq)]
pub struct SequenceHeader {
    pub id: u8,
    pub profile: u8,
    pub reduced_still_picture_header: bool,
    pub level: u8,
    pub tier: u8,
    pub layout: PixelLayout,
    pub ss_hor: u8,
    pub ss_ver: u8,
    pub hbd: u8,
    pub lcr_id: u8,
    pub still_picture: bool,
    pub max_tlayer_id: u8,
    pub max_mlayer_id: u8,
    pub tlayer_dependency_present: bool,
    pub mlayer_dependency_present: bool,
    pub tlayer_dependencies: [u8; 8],
    pub mlayer_dependencies: [u8; 8],
    pub monotonic: bool,
    pub max_width: i32,
    pub max_height: i32,
    pub width_n_bits: u8,
    pub height_n_bits: u8,

    pub crop: CropInfo,
    pub sb128: u8,

    pub sdp: bool,
    pub ext_sdp: bool,
    pub ext_partitions: bool,
    pub uneven_4way_partitions: bool,
    pub max_pb_aspect_ratio_log2: u8,

    pub segmentation: SeqSegmentation,

    pub intra_dip: bool,
    pub intra_edge_filter: bool,
    pub mrls: bool,
    pub cfl: bool,
    pub cfl_ds_filter_index: u8,
    pub mhccp: bool,
    pub ibp: bool,

    pub motion_modes: u8,
    pub frame_motion_modes_present: bool,
    pub six_param_warp_delta: bool,
    pub masked_compound: bool,
    pub ref_frame_mvs: bool,
    pub reduced_ref_frame_mvs_mode: u8,
    pub order_hint_n_bits: u8,

    pub refmv_bank: bool,
    /// DRL candidate reorder mode (dav2d `drl_reorder`): 0 = off, 1 =
    /// constraint (reorder only when `nearest_refmv_count >= 4`), 2 = always
    /// (reorder when `nearest_refmv_count >= 2`).
    pub drl_reorder: u8,
    pub explicit_ref_frame_map: bool,
    pub ref_frames: u8,
    pub ref_frames_log2: u8,
    pub number_of_bits_for_lt_frame_id: u8,
    pub def_max_drl_bits: u8,
    pub allow_frame_max_drl_bits: bool,
    pub def_max_bvp_drl_bits: u8,
    pub allow_max_bvp_drl_bits: bool,
    pub num_same_ref_comp: u8,

    pub tip: bool,
    pub tip_hole_fill: bool,
    pub mv_traj: bool,
    pub bawp: bool,
    pub cwp: bool,
    pub imp_msk_bld: bool,

    pub db_sub_pu: bool,
    pub tip_explicit_qp: bool,

    pub opfl_refine: bool,
    pub refine_mv: bool,
    pub tip_refine_mv: bool,
    pub bru: bool,
    pub adaptive_mvd: bool,
    pub mvd_sign_derive: bool,
    pub flex_mvres: bool,
    pub global_motion: bool,
    pub short_refresh_frame_flags: bool,

    pub screen_content_tools: AdaptiveBoolean,
    pub force_integer_mv: AdaptiveBoolean,

    pub fsc: bool,
    pub idtx_intra: bool,
    pub ist: [bool; 2],
    pub chroma_dctonly: bool,
    pub inter_ddt: bool,
    pub reduced_tx_part_set: bool,
    pub cctx: bool,

    pub tcq: AdaptiveBoolean,
    pub parity_hiding: bool,

    pub avg_cdf: bool,
    pub avg_cdf_type: u8,

    pub disable_loopfilters_across_tiles: bool,
    pub cdef: bool,
    pub gdf: bool,
    pub gdf_unit_matches_sbsz: bool,
    pub restoration: bool,
    pub rst_disable_mask: [u8; 2],
    pub ccso: bool,
    pub ccso_unit_matches_sbsz: bool,
    pub cdef_on_skiptx: AdaptiveBoolean,
    pub df_par_bits: u8,

    pub separate_uv_delta_q: bool,
    pub equal_ac_dc_q: bool,
    pub base_ydc_dq: i8,
    pub ydc_dq_enabled: bool,
    pub base_uvdc_dq: u8,
    pub uvdc_dq_enabled: bool,
    pub base_uvac_dq: u8,
    pub uvac_dq_enabled: bool,

    pub tiling: SeqTiling,
    pub film_grain_present: bool,
}

#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct CropInfo {
    pub enabled: bool,
    pub left: u32,
    pub right: u32,
    pub top: u32,
    pub bottom: u32,
}

#[derive(Debug, Clone, Default, PartialEq)]
pub struct SeqSegmentation {
    pub ext: bool,
    pub info_present: bool,
    pub adaptive: bool,
    pub d: SegmentationDataSet,
}

#[derive(Debug, Clone, Default, PartialEq)]
pub struct SeqTiling {
    pub present: AdaptiveBoolean,
    pub t: TileInfo,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FilmGrainData {
    pub chroma_scaling_from_luma: bool,
    pub num_points: [i32; 3],
    pub points: [[[u8; 2]; 14]; 3],
    pub scaling_shift: i32,
    pub ar_coeff_lag: i32,
    pub ar_coeffs: [[i8; 28]; 3],
    pub ar_coeff_shift: u64,
    pub grain_scale_shift: i32,
    pub uv_mult: [i32; 2],
    pub uv_luma_mult: [i32; 2],
    pub uv_offset: [i32; 2],
    pub overlap_flag: bool,
    pub clip_to_restricted_range: bool,
    pub mc_identity: bool,
    pub block_size: i32,
}

#[derive(Debug, Clone, Default)]
pub struct FhTip {
    pub frame_mode: u8,
    pub hole_fill: u8,
    pub global_wtd_idx: u8,
    pub apply_filter: u8,
    pub gmv_y: i8,
    pub gmv_x: i8,
    pub subpel_filter: u8,
    pub r#ref: [i8; 2],
}

#[derive(Debug, Clone, Default)]
pub struct FhTiling {
    pub t: TileInfo,
    pub n_bytes: u8,
    pub update: u16,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhQuantQm {
    pub enabled: u8,
    pub num: u8,
    pub y: [u8; 4],
    pub u: [u8; 4],
    pub v: [u8; 4],
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhQuant {
    pub yac: u16,
    pub ydc_delta: i8,
    pub udc_delta: i8,
    pub uac_delta: i8,
    pub vdc_delta: i8,
    pub vac_delta: i8,
    pub qm: FhQuantQm,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhSegmentation {
    pub enabled: u8,
    pub update_map: u8,
    pub temporal: u8,
    pub d: SegmentationDataSet,
    pub preskip: u8,
    pub last_active_segid: i8,
    pub lossless: [u8; MAX_SEGMENTS],
    pub qidx: [u8; MAX_SEGMENTS],
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhDeltaQ {
    pub present: u8,
    pub res_log2: u8,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhDelta {
    pub q: FhDeltaQ,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhDeblock {
    pub sub_pu: u8,
    pub level_y: [u8; 2],
    pub level_u: u8,
    pub level_v: u8,
    pub delta_q_y: [i8; 2],
    pub delta_q_u: i8,
    pub delta_q_v: i8,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhGdf {
    pub enabled: AdaptiveBoolean,
    pub qp_idx: u8,
    pub scale: u8,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhCdef {
    pub enabled: u8,
    pub damping: u8,
    pub n_strengths: u8,
    pub on_skiptx: u8,
    pub y_strength: [u8; MAX_CDEF_STRENGTHS],
    pub uv_strength: [u8; MAX_CDEF_STRENGTHS],
}

#[derive(Debug, Clone, Copy, Default)]
pub struct NSWienerPlane {
    pub frame_filters_on: u8,
    pub num_classes_idx: u8,
    pub num_classes: u8,
    pub temporal: u8,
    pub refidx: u8,
    pub filter: [[i8; 18]; 16],
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhRestorationPlane {
    pub restoration_type: u8,
    pub ns: NSWienerPlane,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhRestoration {
    pub p: [FhRestorationPlane; 3],
    pub unit_size: [u8; 2],
}

#[derive(Debug, Clone, Copy)]
pub struct FhCcsoPlane {
    pub enabled: u8,
    pub reuse: u8,
    pub sb_reuse: u8,
    pub refidx: u8,
    pub bo_only: u8,
    pub scale_idx: u8,
    pub quant_idx: u8,
    pub ext_filter_support: u8,
    pub edge_clf: u8,
    pub max_band_log2: u8,
    pub filter_off: [u8; 64],
}

impl Default for FhCcsoPlane {
    fn default() -> Self {
        Self {
            enabled: 0,
            reuse: 0,
            sb_reuse: 0,
            refidx: 0,
            bo_only: 0,
            scale_idx: 0,
            quant_idx: 0,
            ext_filter_support: 0,
            edge_clf: 0,
            max_band_log2: 0,
            filter_off: [0; 64],
        }
    }
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhCcso {
    pub enabled: u8,
    pub p: [FhCcsoPlane; 3],
}

#[derive(Debug, Clone, Default)]
pub struct FhGmv {
    pub r#ref: u8,
    pub refref: u8,
    pub m: [WarpedMotionParams; REFS_PER_FRAME],
}

#[derive(Debug, Clone, Copy, Default)]
pub struct FhFilmGrain {
    pub present: u8,
    pub id: u8,
    pub seed: u32,
}

#[derive(Debug, Clone, Default)]
pub struct FrameHeader {
    pub id: u8,
    pub frame_type: FrameType,
    pub width: i32,
    pub height: i32,
    pub frame_offset: u8,
    pub tlayer_id: u8,
    pub mlayer_id: u8,
    pub xlayer_id: u8,
    pub show_existing_frame: u8,
    pub existing_frame_idx: i8,
    pub ltr_id: i8,
    pub frame_presentation_delay: u32,
    pub show_immediate: u8,
    pub show_implicit: u8,
    pub cross_frame_context: u8,
    pub disable_cdf_update: u8,
    pub allow_screen_content_tools: u8,
    pub force_integer_mv: u8,
    pub frame_size_override: u8,
    pub primary_ref_signaled: u8,
    pub primary_ref_frame: u8,
    pub secondary_ref_frame: u8,
    pub n_ref_frames: u8,
    pub refresh_frame_flags: u8,
    pub allow_intrabc: u8,
    pub allow_global_intrabc: u8,
    pub allow_local_intrabc: u8,
    pub max_bvp_drl_bits: u8,
    pub max_drl_bits: u8,
    pub refidx: [i8; REFS_PER_FRAME],
    pub has_future_refs: u8,
    pub has_past_refs: u8,
    pub has_bothside_refs: u8,
    pub mv_precision: u8,
    pub subpel_filter_mode: FilterMode,
    pub motion_modes: u8,
    pub use_ref_frame_mvs: u8,
    pub tmvp_sample_step: u8,
    pub opfl_refine_type: u8,
    pub tip: FhTip,
    pub sb128: u8,
    pub tiling: FhTiling,
    pub quant: FhQuant,
    pub segmentation: FhSegmentation,
    pub delta: FhDelta,
    pub all_lossless: u8,
    pub any_lossless: u8,
    pub tcq: u8,
    pub parity_hiding: u8,
    pub deblock: FhDeblock,
    pub gdf: FhGdf,
    pub cdef: FhCdef,
    pub restoration: FhRestoration,
    pub ccso: FhCcso,
    pub txfm_mode: TxfmMode,
    pub switchable_comp_refs: u8,
    pub skip_mode_enabled: u8,
    pub bawp: u8,
    pub warp_motion: u8,
    pub reduced_txtp_set: u8,
    pub gmv: FhGmv,
    pub film_grain: FhFilmGrain,
}

impl FrameHeader {
    pub fn is_inter_or_switch(&self) -> bool {
        (self.frame_type as u8) & 1 != 0
    }

    pub fn is_key_or_intra(&self) -> bool {
        !self.is_inter_or_switch()
    }
}