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
pub enum Rav1dCodecErr {
    Rav1dCodecOk,
    Rav1dCodecError,
    Rav1dCodecMemError,
    Rav1dCodecAbiMismatch,
    Rav1dCodecIncapable,
    Rav1dCodecUnsupBitstream,
    Rav1dCodecUnsupFeature,
    Rav1dCodecCorruptFrame,
    Rav1dCodecInvalidParam,
}

// Constants from Section 3. "Symbols and abbreviated terms"
const RAV1D_MAX_CDEF_STRENGTHS: usize = 8;
const RAV1D_MAX_OPERATING_POINTS: usize = 32;
const RAV1D_MAX_TILE_COLS: usize = 64;
const RAV1D_MAX_TILE_ROWS: usize = 64;
const RAV1D_MAX_SEGMENTS: usize = 8;
const RAV1D_NUM_REF_FRAMES: usize = 8;
const RAV1D_PRIMARY_REF_NONE: usize = 7;
const RAV1D_REFS_PER_FRAME: usize = 7;
const RAV1D_TOTAL_REFS_PER_FRAME: usize = (RAV1D_REFS_PER_FRAME + 1);

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum MatrixCoefficients {
    Identity = 0,
    BT709,
    Unspecified,
    BT470M = 4,
    BT470BG,
    ST170M,
    ST240M,
    YCgCo,
    BT2020NonConstantLuminance,
    BT2020ConstantLuminance,
    ST2085,
    ChromaticityDerivedNonConstantLuminance,
    ChromaticityDerivedConstantLuminance,
    ICtCp,
}
impl Default for MatrixCoefficients {
    fn default() -> Self {
        MatrixCoefficients::Unspecified
    }
}

#[derive(Debug,Clone,Copy,PartialEq)]
pub enum ColorPrimaries {
    BT709 = 1,
    Unspecified,
    BT470M = 4,
    BT470BG,
    ST170M,
    ST240M,
    Film,
    BT2020,
    ST428,
    P3DCI,
    P3Display,
    Tech3213 = 22,
}
impl Default for ColorPrimaries {
    fn default() -> Self {
        ColorPrimaries::Unspecified
    }
}

#[derive(Debug,Clone,Copy,PartialEq)]
pub enum TransferCharacteristics {
    BT1886 = 1,
    Unspecified,
    BT470M = 4,
    BT470BG,
    ST170M,
    ST240M,
    Linear,
    Logarithmic100,
    Logarithmic316,
    XVYCC,
    BT1361E,
    SRGB,
    BT2020Ten,
    BT2020Twelve,
    PerceptualQuantizer,
    ST428,
    HybridLogGamma,
}
impl Default for TransferCharacteristics {
    fn default() -> Self {
        TransferCharacteristics::Unspecified
    }
}

#[derive(Default)]
pub struct SequenceHeader {
    pub seq_profile: u8,
    pub still_picture: bool,
    pub reduced_still_picture_header: bool,

    pub timing_info_present_flag: bool,
    pub timing_info: TimingInfo,

    pub decoder_model_info_present_flag: bool,
    pub decoder_model_info: DecoderModelInfo,

    pub initial_display_delay_present_flag: bool,

    pub operating_points_cnt_minus_1: u8,
    pub operating_points: [OperatingPoint; RAV1D_MAX_OPERATING_POINTS],

    pub frame_width_bits_minus_1: u8,
    pub frame_height_bits_minus_1: u8,

    pub max_frame_width_minus_1: u16,
    pub max_frame_height_minus_1: u16,

    pub frame_id_numbers_present_flag: bool,
    pub delta_frame_id_length_minus_2: u8,
    pub additional_frame_id_length_minus_1: u8,
    pub frame_id_length: u8,

    pub use_128x128_superblock: bool,
    pub enable_filter_intra: bool,
    pub enable_intra_edge_filter: bool,

    pub enable_interintra_compound: bool,
    pub enable_masked_compound: bool,
    pub enable_warped_motion: bool,
    pub enable_dual_filter: bool,
    pub enable_order_hint: bool,
    pub enable_jnt_comp: bool,
    pub enable_ref_frame_mvs: bool,
    pub seq_choose_screen_content_tools: bool,
    pub seq_force_screen_content_tools: u8,
    pub seq_choose_integer_mv: bool,
    pub seq_force_integer_mv: u8,
    pub order_hint_bits: u8,

    pub enable_superres: bool,
    pub enable_cdef: bool,
    pub enable_restoration: bool,

    pub color_config: ColorConfig,

    pub film_grain_params_present: bool,
}

#[derive(Default)]
pub struct TimingInfo {
    pub num_units_in_display_tick: u32,
    pub time_scale: u32,
    pub equal_picture_interval: bool,
    pub num_ticks_per_picture_minus_1: u32,
}

#[derive(Default)]
pub struct DecoderModelInfo {
    pub buffer_delay_length_minus_1: u8,
    pub num_units_in_decoding_tick: u32,
    pub buffer_removal_time_length_minus_1: u8,
    pub frame_presentation_time_length: u8,
}

#[derive(Default)]
pub struct OperatingParametersInfo {
    pub decoder_buffer_delay: u32,
    pub encoder_buffer_dealy: u32,
    pub low_delay_mode_flag: bool,
}

#[derive(Default)]
pub struct OperatingPoint {
    pub operating_point_idc: u16,
    pub seq_level_idx: u8,
    pub seq_tier: bool,
    pub decoder_model_present_for_this_op: bool,
    pub operating_parameters_info: OperatingParametersInfo,
    pub initial_display_delay_present_for_this_op: bool,
    pub initial_display_delay_minus_1: u8,
}

#[derive(Default)]
pub struct ColorConfig {
    pub high_bitdepth: bool,
    pub twelve_bit: bool,
    pub mono_chrome: bool,
    pub color_description_present_flag: bool,
    pub color_primaries: u8,
    pub transfer_characteristics: u8,
    pub matrix_coefficients: u8,
    pub color_range: bool,
    pub subsampling_x: u8,
    pub subsampling_y: u8,
    pub chroma_sample_position: u8,
    pub separate_uv_delta_q: bool,

    pub bit_depth: u8,
}