7 #ifndef PACKAGER_MEDIA_CODECS_AV1_PARSER_H_
8 #define PACKAGER_MEDIA_CODECS_AV1_PARSER_H_
24 size_t start_offset_in_bytes;
39 virtual bool Parse(
const uint8_t* data,
41 std::vector<Tile>* tiles);
52 struct ObuExtensionHeader {
59 bool obu_has_size_field =
false;
60 ObuExtensionHeader extension_header;
65 bool mono_chrome =
false;
67 int color_primaries = 0;
68 int transfer_chracteristics = 0;
69 int matrix_coefficients = 0;
70 bool color_range =
false;
71 bool subsampling_x =
false;
72 bool subsampling_y =
false;
73 int chroma_sampling_position = 0;
74 bool separate_uv_delta_q =
false;
78 bool equal_picture_interval =
false;
81 struct DecoderModelInfo {
82 int buffer_delay_length_minus_1 = 0;
83 int buffer_removal_time_length_minus_1 = 0;
84 int frame_presentation_time_length_minus_1 = 0;
87 struct SequenceHeaderObu {
89 bool reduced_still_picture_header =
false;
91 TimingInfo timing_info;
92 bool decoder_model_info_present_flag =
false;
93 DecoderModelInfo decoder_model_info;
95 int operating_points_cnt_minus_1 = 0;
96 static constexpr
int kMaxOperatingPointsCount = 1 << 5;
97 int operating_point_idc[kMaxOperatingPointsCount] = {};
98 bool decoder_model_present_for_this_op[kMaxOperatingPointsCount] = {};
100 int frame_width_bits_minus_1 = 0;
101 int frame_height_bits_minus_1 = 0;
102 int max_frame_width_minus_1 = 0;
103 int max_frame_height_minus_1 = 0;
105 bool frame_id_numbers_present_flag =
false;
106 int delta_frame_id_length_minus_2 = 0;
107 int additional_frame_id_length_minus_1 = 0;
109 bool use_128x128_superblock =
false;
111 bool enable_warped_motion =
false;
112 bool enable_order_hint =
false;
113 bool enable_ref_frame_mvs =
false;
114 int order_hint_bits = 0;
116 int seq_force_screen_content_tools = 0;
117 int seq_force_integer_mv = 0;
119 bool enable_superres =
false;
120 bool enable_cdef =
false;
121 bool enable_restoration =
false;
122 ColorConfig color_config;
123 bool film_grain_params_present =
false;
129 int tile_cols_log2 = 0;
130 int tile_rows_log2 = 0;
131 int tile_size_bytes = 0;
134 struct QuantizationParams {
143 static constexpr
int kMaxSegments = 8;
144 static constexpr
int kSegLvlMax = 8;
145 struct SegmentationParams {
146 bool segmentation_enabled =
false;
147 bool feature_enabled[kMaxSegments][kSegLvlMax] = {};
148 int feature_data[kMaxSegments][kSegLvlMax] = {};
151 static constexpr
int kRefsPerFrame = 7;
152 struct FrameHeaderObu {
153 bool seen_frame_header =
false;
155 bool show_existing_frame =
false;
156 int frame_to_show_map_idx = 0;
159 int refresh_frame_flags = 0;
161 int ref_frame_idx[kRefsPerFrame] = {};
166 int frame_height = 0;
167 int upscaled_width = 0;
168 int render_width = 0;
169 int render_height = 0;
175 QuantizationParams quantization_params;
176 SegmentationParams segmentation_params;
179 struct ReferenceFrame {
184 int frame_height = 0;
185 int upscaled_width = 0;
186 int render_width = 0;
187 int render_height = 0;
193 bool subsampling_x =
false;
194 bool subsampling_y =
false;
197 bool ParseOpenBitstreamUnit(BitReader* reader, std::vector<Tile>* tiles);
198 bool ParseObuHeader(BitReader* reader, ObuHeader* obu_header);
199 bool ParseObuExtensionHeader(BitReader* reader,
200 ObuExtensionHeader* obu_extension_header);
201 bool ParseTrailingBits(
size_t nb_bits, BitReader* reader);
202 bool ByteAlignment(BitReader* reader);
205 bool ParseSequenceHeaderObu(BitReader* reader);
206 bool ParseColorConfig(BitReader* reader);
207 bool ParseTimingInfo(BitReader* reader);
208 bool ParseDecoderModelInfo(BitReader* reader);
209 bool SkipOperatingParametersInfo(BitReader* reader);
212 bool ParseFrameHeaderObu(
const ObuHeader& obu_header, BitReader* reader);
213 bool ParseUncompressedHeader(
const ObuHeader& obu_header, BitReader* reader);
214 int GetRelativeDist(
int a,
int b);
215 bool ParseFrameSize(
bool frame_size_override_flag, BitReader* reader);
216 bool ParseRenderSize(BitReader* reader);
217 bool ParseFrameSizeWithRefs(
bool frame_size_override_flag, BitReader* reader);
218 bool ParseSuperresParams(BitReader* reader);
219 void ComputeImageSize();
220 bool SkipInterpolationFilter(BitReader* reader);
221 bool ParseLoopFilterParams(
bool coded_lossless,
224 bool ParseTileInfo(BitReader* reader);
225 bool ParseQuantizationParams(BitReader* reader);
226 bool ReadDeltaQ(BitReader* reader,
int* delta_q);
227 bool ParseSegmentationParams(
int primary_ref_frame, BitReader* reader);
228 bool SkipDeltaQParams(BitReader* reader,
bool* delta_q_present);
229 bool SkipDeltaLfParams(
bool delta_q_present,
232 bool ParseCdefParams(
bool coded_lossless,
235 bool ParseLrParams(
bool all_lossless,
bool allow_intrabc, BitReader* reader);
236 bool SkipTxMode(
bool coded_lossless, BitReader* reader);
237 bool SkipSkipModeParams(
bool frame_is_intra,
238 bool reference_select,
240 bool ParseFrameReferenceMode(
bool frame_is_intra,
242 bool* reference_select);
243 bool SkipGlobalMotionParams(
bool frame_is_intra,
244 bool allow_high_precision_mv,
246 bool SkipGlobalParam(
int type,
249 bool allow_high_precision_mv,
251 bool SkipDecodeSignedSubexpWithRef(
int low,
int high, BitReader* reader);
252 bool SkipDecodeUnsignedSubexpWithRef(
int mx, BitReader* reader);
253 bool SkipDecodeSubexp(
int num_syms, BitReader* reader);
254 bool SkipFilmGrainParams(
bool show_frame,
257 bool SkipTemporalPointInfo(BitReader* reader);
260 bool ParseFrameObu(
const ObuHeader& obu_header,
263 std::vector<Tile>* tiles);
266 bool ParseTileGroupObu(
size_t size,
268 std::vector<Tile>* tiles);
269 bool SegFeatureActiveIdx(
int idx,
int feature);
274 void DecodeFrameWrapup();
275 bool SetFrameRefs(
int last_frame_idx,
int gold_frame_idx);
276 int GetQIndex(
bool ignore_delta_q,
int segment_id);
278 SequenceHeaderObu sequence_header_;
279 FrameHeaderObu frame_header_;
280 static constexpr
int kNumRefFrames = 8;
281 ReferenceFrame reference_frames_[kNumRefFrames];
All the methods that are virtual are virtual for mocking.