History

avcodec/evc_parse: split off Parameter Set parsing into its own file

James Almer committed 3 years ago

Commit 1e189fe1 parent 4afee837 files · +621 −565Browse files

Unified · Split

7 files
  1. libavcodec/Makefile +1 −1
  2. libavcodec/evc_frame_merge_bsf.c +2 −2
  3. libavcodec/evc_parse.c +6 −365
  4. libavcodec/evc_parse.h +2 −196
  5. libavcodec/evc_parser.c +1 −1
  6. libavcodec/evc_ps.c +381 −0
  7. libavcodec/evc_ps.h +228 −0
libavcodec/Makefile+1−1
@@ -84,7 +84,7 @@ OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o · 83 unmodified lines
8484 OBJS-$(CONFIG_DEFLATE_WRAPPER) += zlib_wrapper.o
8585 OBJS-$(CONFIG_DOVI_RPU) += dovi_rpu.o
8686 OBJS-$(CONFIG_ERROR_RESILIENCE) += error_resilience.o
87−OBJS-$(CONFIG_EVCPARSE) += evc_parse.o
87+OBJS-$(CONFIG_EVCPARSE) += evc_parse.o evc_ps.o
8888 OBJS-$(CONFIG_EXIF) += exif.o tiff_common.o
8989 OBJS-$(CONFIG_FAANDCT) += faandct.o
9090 OBJS-$(CONFIG_FAANIDCT) += faanidct.o
libavcodec/evc_frame_merge_bsf.c+2−2
@@ -58,7 +58,7 @@ static void evc_frame_merge_flush(AVBSFContext *bsf) · 57 unmodified lines
5858 {
5959 EVCFMergeContext *ctx = bsf->priv_data;
6060
61− ff_evc_parse_free(&ctx->parser_ctx);
61+ ff_evc_ps_free(&ctx->parser_ctx.ps);
6262 av_packet_unref(ctx->in);
6363 ctx->au_buffer.data_size = 0;
6464 }
@@ -147,7 +147,7 @@ static void evc_frame_merge_close(AVBSFContext *bsf) · 82 unmodified lines
147147 EVCFMergeContext *ctx = bsf->priv_data;
148148
149149 av_packet_free(&ctx->in);
150− ff_evc_parse_free(&ctx->parser_ctx);
150+ ff_evc_ps_free(&ctx->parser_ctx.ps);
151151
152152 ctx->au_buffer.capacity = 0;
153153 av_freep(&ctx->au_buffer.data);
libavcodec/evc_parse.c+6−365
@@ -21,8 +21,6 @@ · 20 unmodified lines
2121 #include "evc.h"
2222 #include "evc_parse.h"
2323
24−#define EXTENDED_SAR 255
25−
2624 #define NUM_CHROMA_FORMATS 4 // @see ISO_IEC_23094-1 section 6.2 table 2
2725
2826 static const enum AVPixelFormat pix_fmts_8bit[NUM_CHROMA_FORMATS] = {
@@ -71,355 +69,6 @@ int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx) · 42 unmodified lines
7169 return temporal_id;
7270 }
7371
74−// @see ISO_IEC_23094-1 (7.3.7 Reference picture list structure syntax)
75−static int ref_pic_list_struct(GetBitContext *gb, RefPicListStruct *rpl)
76−{
77− uint32_t delta_poc_st, strp_entry_sign_flag = 0;
78− rpl->ref_pic_num = get_ue_golomb(gb);
79− if (rpl->ref_pic_num > 0) {
80− delta_poc_st = get_ue_golomb(gb);
81−
82− rpl->ref_pics[0] = delta_poc_st;
83− if (rpl->ref_pics[0] != 0) {
84− strp_entry_sign_flag = get_bits(gb, 1);
85−
86− rpl->ref_pics[0] *= 1 - (strp_entry_sign_flag << 1);
87− }
88− }
89−
90− for (int i = 1; i < rpl->ref_pic_num; ++i) {
91− delta_poc_st = get_ue_golomb(gb);
92− if (delta_poc_st != 0)
93− strp_entry_sign_flag = get_bits(gb, 1);
94− rpl->ref_pics[i] = rpl->ref_pics[i - 1] + delta_poc_st * (1 - (strp_entry_sign_flag << 1));
95− }
96−
97− return 0;
98−}
99−
100−// @see ISO_IEC_23094-1 (E.2.2 HRD parameters syntax)
101−static int hrd_parameters(GetBitContext *gb, HRDParameters *hrd)
102−{
103− hrd->cpb_cnt_minus1 = get_ue_golomb(gb);
104− hrd->bit_rate_scale = get_bits(gb, 4);
105− hrd->cpb_size_scale = get_bits(gb, 4);
106− for (int SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1; SchedSelIdx++) {
107− hrd->bit_rate_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
108− hrd->cpb_size_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
109− hrd->cbr_flag[SchedSelIdx] = get_bits(gb, 1);
110− }
111− hrd->initial_cpb_removal_delay_length_minus1 = get_bits(gb, 5);
112− hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
113− hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
114− hrd->time_offset_length = get_bits(gb, 5);
115−
116− return 0;
117−}
118−
119−// @see ISO_IEC_23094-1 (E.2.1 VUI parameters syntax)
120−static int vui_parameters(GetBitContext *gb, VUIParameters *vui)
121−{
122− vui->aspect_ratio_info_present_flag = get_bits(gb, 1);
123− if (vui->aspect_ratio_info_present_flag) {
124− vui->aspect_ratio_idc = get_bits(gb, 8);
125− if (vui->aspect_ratio_idc == EXTENDED_SAR) {
126− vui->sar_width = get_bits(gb, 16);
127− vui->sar_height = get_bits(gb, 16);
128− }
129− }
130− vui->overscan_info_present_flag = get_bits(gb, 1);
131− if (vui->overscan_info_present_flag)
132− vui->overscan_appropriate_flag = get_bits(gb, 1);
133− vui->video_signal_type_present_flag = get_bits(gb, 1);
134− if (vui->video_signal_type_present_flag) {
135− vui->video_format = get_bits(gb, 3);
136− vui->video_full_range_flag = get_bits(gb, 1);
137− vui->colour_description_present_flag = get_bits(gb, 1);
138− if (vui->colour_description_present_flag) {
139− vui->colour_primaries = get_bits(gb, 8);
140− vui->transfer_characteristics = get_bits(gb, 8);
141− vui->matrix_coefficients = get_bits(gb, 8);
142− }
143− }
144− vui->chroma_loc_info_present_flag = get_bits(gb, 1);
145− if (vui->chroma_loc_info_present_flag) {
146− vui->chroma_sample_loc_type_top_field = get_ue_golomb(gb);
147− vui->chroma_sample_loc_type_bottom_field = get_ue_golomb(gb);
148− }
149− vui->neutral_chroma_indication_flag = get_bits(gb, 1);
150−
151− vui->field_seq_flag = get_bits(gb, 1);
152−
153− vui->timing_info_present_flag = get_bits(gb, 1);
154− if (vui->timing_info_present_flag) {
155− vui->num_units_in_tick = get_bits(gb, 32);
156− vui->time_scale = get_bits(gb, 32);
157− vui->fixed_pic_rate_flag = get_bits(gb, 1);
158− }
159− vui->nal_hrd_parameters_present_flag = get_bits(gb, 1);
160− if (vui->nal_hrd_parameters_present_flag)
161− hrd_parameters(gb, &vui->hrd_parameters);
162− vui->vcl_hrd_parameters_present_flag = get_bits(gb, 1);
163− if (vui->vcl_hrd_parameters_present_flag)
164− hrd_parameters(gb, &vui->hrd_parameters);
165− if (vui->nal_hrd_parameters_present_flag || vui->vcl_hrd_parameters_present_flag)
166− vui->low_delay_hrd_flag = get_bits(gb, 1);
167− vui->pic_struct_present_flag = get_bits(gb, 1);
168− vui->bitstream_restriction_flag = get_bits(gb, 1);
169− if (vui->bitstream_restriction_flag) {
170− vui->motion_vectors_over_pic_boundaries_flag = get_bits(gb, 1);
171− vui->max_bytes_per_pic_denom = get_ue_golomb(gb);
172− vui->max_bits_per_mb_denom = get_ue_golomb(gb);
173− vui->log2_max_mv_length_horizontal = get_ue_golomb(gb);
174− vui->log2_max_mv_length_vertical = get_ue_golomb(gb);
175− vui->num_reorder_pics = get_ue_golomb(gb);
176− vui->max_dec_pic_buffering = get_ue_golomb(gb);
177− }
178−
179− return 0;
180−}
181−
182−// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
183−EVCParserSPS *ff_evc_parse_sps(EVCParserContext *ctx, const uint8_t *bs, int bs_size)
184−{
185− GetBitContext gb;
186− EVCParserSPS *sps;
187− int sps_seq_parameter_set_id;
188−
189− if (init_get_bits8(&gb, bs, bs_size) < 0)
190− return NULL;
191−
192− sps_seq_parameter_set_id = get_ue_golomb(&gb);
193−
194− if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT)
195− return NULL;
196−
197− if(!ctx->sps[sps_seq_parameter_set_id]) {
198− if((ctx->sps[sps_seq_parameter_set_id] = av_malloc(sizeof(EVCParserSPS))) == NULL)
199− return NULL;
200− }
201−
202− sps = ctx->sps[sps_seq_parameter_set_id];
203− memset(sps, 0, sizeof(*sps));
204−
205− sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id;
206−
207− // the Baseline profile is indicated by profile_idc eqal to 0
208− // the Main profile is indicated by profile_idc eqal to 1
209− sps->profile_idc = get_bits(&gb, 8);
210−
211− sps->level_idc = get_bits(&gb, 8);
212−
213− skip_bits_long(&gb, 32); /* skip toolset_idc_h */
214− skip_bits_long(&gb, 32); /* skip toolset_idc_l */
215−
216− // 0 - monochrome
217− // 1 - 4:2:0
218− // 2 - 4:2:2
219− // 3 - 4:4:4
220− sps->chroma_format_idc = get_ue_golomb(&gb);
221−
222− sps->pic_width_in_luma_samples = get_ue_golomb(&gb);
223− sps->pic_height_in_luma_samples = get_ue_golomb(&gb);
224−
225− sps->bit_depth_luma_minus8 = get_ue_golomb(&gb);
226− sps->bit_depth_chroma_minus8 = get_ue_golomb(&gb);
227−
228− sps->sps_btt_flag = get_bits(&gb, 1);
229− if (sps->sps_btt_flag) {
230− sps->log2_ctu_size_minus5 = get_ue_golomb(&gb);
231− sps->log2_min_cb_size_minus2 = get_ue_golomb(&gb);
232− sps->log2_diff_ctu_max_14_cb_size = get_ue_golomb(&gb);
233− sps->log2_diff_ctu_max_tt_cb_size = get_ue_golomb(&gb);
234− sps->log2_diff_min_cb_min_tt_cb_size_minus2 = get_ue_golomb(&gb);
235− }
236−
237− sps->sps_suco_flag = get_bits(&gb, 1);
238− if (sps->sps_suco_flag) {
239− sps->log2_diff_ctu_size_max_suco_cb_size = get_ue_golomb(&gb);
240− sps->log2_diff_max_suco_min_suco_cb_size = get_ue_golomb(&gb);
241− }
242−
243− sps->sps_admvp_flag = get_bits(&gb, 1);
244− if (sps->sps_admvp_flag) {
245− sps->sps_affine_flag = get_bits(&gb, 1);
246− sps->sps_amvr_flag = get_bits(&gb, 1);
247− sps->sps_dmvr_flag = get_bits(&gb, 1);
248− sps->sps_mmvd_flag = get_bits(&gb, 1);
249− sps->sps_hmvp_flag = get_bits(&gb, 1);
250− }
251−
252− sps->sps_eipd_flag = get_bits(&gb, 1);
253− if (sps->sps_eipd_flag) {
254− sps->sps_ibc_flag = get_bits(&gb, 1);
255− if (sps->sps_ibc_flag)
256− sps->log2_max_ibc_cand_size_minus2 = get_ue_golomb(&gb);
257− }
258−
259− sps->sps_cm_init_flag = get_bits(&gb, 1);
260− if (sps->sps_cm_init_flag)
261− sps->sps_adcc_flag = get_bits(&gb, 1);
262−
263− sps->sps_iqt_flag = get_bits(&gb, 1);
264− if (sps->sps_iqt_flag)
265− sps->sps_ats_flag = get_bits(&gb, 1);
266−
267− sps->sps_addb_flag = get_bits(&gb, 1);
268− sps->sps_alf_flag = get_bits(&gb, 1);
269− sps->sps_htdf_flag = get_bits(&gb, 1);
270− sps->sps_rpl_flag = get_bits(&gb, 1);
271− sps->sps_pocs_flag = get_bits(&gb, 1);
272− sps->sps_dquant_flag = get_bits(&gb, 1);
273− sps->sps_dra_flag = get_bits(&gb, 1);
274−
275− if (sps->sps_pocs_flag)
276− sps->log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb(&gb);
277−
278− if (!sps->sps_pocs_flag || !sps->sps_rpl_flag) {
279− sps->log2_sub_gop_length = get_ue_golomb(&gb);
280− if (sps->log2_sub_gop_length == 0)
281− sps->log2_ref_pic_gap_length = get_ue_golomb(&gb);
282− }
283−
284− if (!sps->sps_rpl_flag)
285− sps->max_num_tid0_ref_pics = get_ue_golomb(&gb);
286− else {
287− sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb(&gb);
288− sps->long_term_ref_pic_flag = get_bits(&gb, 1);
289− sps->rpl1_same_as_rpl0_flag = get_bits(&gb, 1);
290− sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(&gb);
291−
292− for (int i = 0; i < sps->num_ref_pic_list_in_sps[0]; ++i)
293− ref_pic_list_struct(&gb, &sps->rpls[0][i]);
294−
295− if (!sps->rpl1_same_as_rpl0_flag) {
296− sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(&gb);
297− for (int i = 0; i < sps->num_ref_pic_list_in_sps[1]; ++i)
298− ref_pic_list_struct(&gb, &sps->rpls[1][i]);
299− }
300− }
301−
302− sps->picture_cropping_flag = get_bits(&gb, 1);
303−
304− if (sps->picture_cropping_flag) {
305− sps->picture_crop_left_offset = get_ue_golomb(&gb);
306− sps->picture_crop_right_offset = get_ue_golomb(&gb);
307− sps->picture_crop_top_offset = get_ue_golomb(&gb);
308− sps->picture_crop_bottom_offset = get_ue_golomb(&gb);
309− }
310−
311− if (sps->chroma_format_idc != 0) {
312− sps->chroma_qp_table_struct.chroma_qp_table_present_flag = get_bits(&gb, 1);
313−
314− if (sps->chroma_qp_table_struct.chroma_qp_table_present_flag) {
315− sps->chroma_qp_table_struct.same_qp_table_for_chroma = get_bits(&gb, 1);
316− sps->chroma_qp_table_struct.global_offset_flag = get_bits(&gb, 1);
317− for (int i = 0; i < (sps->chroma_qp_table_struct.same_qp_table_for_chroma ? 1 : 2); i++) {
318− sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] = get_ue_golomb(&gb);;
319− for (int j = 0; j <= sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i]; j++) {
320− sps->chroma_qp_table_struct.delta_qp_in_val_minus1[i][j] = get_bits(&gb, 6);
321− sps->chroma_qp_table_struct.delta_qp_out_val[i][j] = get_se_golomb(&gb);
322− }
323− }
324− }
325− }
326−
327− sps->vui_parameters_present_flag = get_bits(&gb, 1);
328− if (sps->vui_parameters_present_flag)
329− vui_parameters(&gb, &(sps->vui_parameters));
330−
331− // @note
332− // If necessary, add the missing fields to the EVCParserSPS structure
333− // and then extend parser implementation
334−
335− return sps;
336−}
337−
338−// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
339−//
340−// @note
341−// The current implementation of parse_sps function doesn't handle VUI parameters parsing.
342−// If it will be needed, parse_sps function could be extended to handle VUI parameters parsing
343−// to initialize fields of the AVCodecContex i.e. color_primaries, color_trc,color_range
344−//
345−EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs, int bs_size)
346−{
347− GetBitContext gb;
348− EVCParserPPS *pps;
349−
350− int pps_pic_parameter_set_id;
351−
352− if (init_get_bits8(&gb, bs, bs_size) < 0)
353− return NULL;
354−
355− pps_pic_parameter_set_id = get_ue_golomb(&gb);
356− if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT)
357− return NULL;
358−
359− if(!ctx->pps[pps_pic_parameter_set_id]) {
360− if ((ctx->pps[pps_pic_parameter_set_id] = av_malloc(sizeof(EVCParserPPS))) == NULL)
361− return NULL;
362− }
363−
364− pps = ctx->pps[pps_pic_parameter_set_id];
365− memset(pps, 0, sizeof(*pps));
366−
367− pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id;
368−
369− pps->pps_seq_parameter_set_id = get_ue_golomb(&gb);
370− if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) {
371− av_freep(&ctx->pps[pps_pic_parameter_set_id]);
372− return NULL;
373− }
374−
375− pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
376− pps->num_ref_idx_default_active_minus1[1] = get_ue_golomb(&gb);
377− pps->additional_lt_poc_lsb_len = get_ue_golomb(&gb);
378− pps->rpl1_idx_present_flag = get_bits(&gb, 1);
379− pps->single_tile_in_pic_flag = get_bits(&gb, 1);
380−
381− if (!pps->single_tile_in_pic_flag) {
382− pps->num_tile_columns_minus1 = get_ue_golomb(&gb);
383− pps->num_tile_rows_minus1 = get_ue_golomb(&gb);
384− pps->uniform_tile_spacing_flag = get_bits(&gb, 1);
385−
386− if (!pps->uniform_tile_spacing_flag) {
387− for (int i = 0; i < pps->num_tile_columns_minus1; i++)
388− pps->tile_column_width_minus1[i] = get_ue_golomb(&gb);
389−
390− for (int i = 0; i < pps->num_tile_rows_minus1; i++)
391− pps->tile_row_height_minus1[i] = get_ue_golomb(&gb);
392− }
393− pps->loop_filter_across_tiles_enabled_flag = get_bits(&gb, 1);
394− pps->tile_offset_len_minus1 = get_ue_golomb(&gb);
395− }
396−
397− pps->tile_id_len_minus1 = get_ue_golomb(&gb);
398− pps->explicit_tile_id_flag = get_bits(&gb, 1);
399−
400− if (pps->explicit_tile_id_flag) {
401− for (int i = 0; i <= pps->num_tile_rows_minus1; i++) {
402− for (int j = 0; j <= pps->num_tile_columns_minus1; j++)
403− pps->tile_id_val[i][j] = get_bits(&gb, pps->tile_id_len_minus1 + 1);
404− }
405− }
406−
407− pps->pic_dra_enabled_flag = 0;
408− pps->pic_dra_enabled_flag = get_bits(&gb, 1);
409−
410− if (pps->pic_dra_enabled_flag)
411− pps->pic_dra_aps_id = get_bits(&gb, 5);
412−
413− pps->arbitrary_slice_present_flag = get_bits(&gb, 1);
414− pps->constrained_intra_pred_flag = get_bits(&gb, 1);
415− pps->cu_qp_delta_enabled_flag = get_bits(&gb, 1);
416−
417− if (pps->cu_qp_delta_enabled_flag)
418− pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(&gb);
419−
420− return pps;
421−}
422−
42372 // @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
42473 static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *sh, const uint8_t *bs, int bs_size)
42574 {
@@ -439,11 +88,11 @@ static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *s · 13 unmodified lines
43988 if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT)
44089 return AVERROR_INVALIDDATA;
44190
442− pps = ctx->pps[slice_pic_parameter_set_id];
91+ pps = ctx->ps.pps[slice_pic_parameter_set_id];
44392 if(!pps)
44493 return AVERROR_INVALIDDATA;
44594
446− sps = ctx->sps[pps->pps_seq_parameter_set_id];
95+ sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
44796 if(!sps)
44897 return AVERROR_INVALIDDATA;
44998
@@ -579,7 +228,7 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz · 129 unmodified lines
579228 int SubGopLength;
580229 int bit_depth;
581230
582− sps = ff_evc_parse_sps(ctx, data, nalu_size);
231+ sps = ff_evc_parse_sps(&ctx->ps, data, nalu_size);
583232 if (!sps) {
584233 av_log(logctx, AV_LOG_ERROR, "SPS parsing error\n");
585234 return AVERROR_INVALIDDATA;
@@ -642,7 +291,7 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz · 56 unmodified lines
642291 case EVC_PPS_NUT: {
643292 EVCParserPPS *pps;
644293
645− pps = ff_evc_parse_pps(ctx, data, nalu_size);
294+ pps = ff_evc_parse_pps(&ctx->ps, data, nalu_size);
646295 if (!pps) {
647296 av_log(logctx, AV_LOG_ERROR, "PPS parsing error\n");
648297 return AVERROR_INVALIDDATA;
@@ -688,8 +337,8 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz · 39 unmodified lines
688337
689338 // POC (picture order count of the current picture) derivation
690339 // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
691− pps = ctx->pps[sh.slice_pic_parameter_set_id];
692− sps = ctx->sps[pps->pps_seq_parameter_set_id];
340+ pps = ctx->ps.pps[sh.slice_pic_parameter_set_id];
341+ sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
693342 av_assert0(sps && pps);
694343
695344 if (sps->sps_pocs_flag) {
@@ -764,11 +413,3 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz · 68 unmodified lines
764413
765414 return 0;
766415 }
767−
768−void ff_evc_parse_free(EVCParserContext *ctx) {
769− for (int i = 0; i < EVC_MAX_SPS_COUNT; i++)
770− av_freep(&ctx->sps[i]);
771−
772− for (int i = 0; i < EVC_MAX_PPS_COUNT; i++)
773− av_freep(&ctx->pps[i]);
774−}
libavcodec/evc_parse.h+2−196
@@ -30,190 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/log.h"
3131 #include "libavutil/rational.h"
3232 #include "evc.h"
33−
34−#define EVC_MAX_QP_TABLE_SIZE 58
35−#define NUM_CPB 32
36−
37−// rpl structure
38−typedef struct RefPicListStruct {
39− int poc;
40− int tid;
41− int ref_pic_num;
42− int ref_pic_active_num;
43− int ref_pics[EVC_MAX_NUM_REF_PICS];
44− char pic_type;
45−
46−} RefPicListStruct;
47−
48−// chromaQP table structure to be signalled in SPS
49−typedef struct ChromaQpTable {
50− int chroma_qp_table_present_flag; // u(1)
51− int same_qp_table_for_chroma; // u(1)
52− int global_offset_flag; // u(1)
53− int num_points_in_qp_table_minus1[2]; // ue(v)
54− int delta_qp_in_val_minus1[2][EVC_MAX_QP_TABLE_SIZE]; // u(6)
55− int delta_qp_out_val[2][EVC_MAX_QP_TABLE_SIZE]; // se(v)
56−} ChromaQpTable;
57−
58−// Hypothetical Reference Decoder (HRD) parameters, part of VUI
59−typedef struct HRDParameters {
60− int cpb_cnt_minus1; // ue(v)
61− int bit_rate_scale; // u(4)
62− int cpb_size_scale; // u(4)
63− int bit_rate_value_minus1[NUM_CPB]; // ue(v)
64− int cpb_size_value_minus1[NUM_CPB]; // ue(v)
65− int cbr_flag[NUM_CPB]; // u(1)
66− int initial_cpb_removal_delay_length_minus1; // u(5)
67− int cpb_removal_delay_length_minus1; // u(5)
68− int dpb_output_delay_length_minus1; // u(5)
69− int time_offset_length; // u(5)
70−} HRDParameters;
71−
72−// video usability information (VUI) part of SPS
73−typedef struct VUIParameters {
74− int aspect_ratio_info_present_flag; // u(1)
75− int aspect_ratio_idc; // u(8)
76− int sar_width; // u(16)
77− int sar_height; // u(16)
78− int overscan_info_present_flag; // u(1)
79− int overscan_appropriate_flag; // u(1)
80− int video_signal_type_present_flag; // u(1)
81− int video_format; // u(3)
82− int video_full_range_flag; // u(1)
83− int colour_description_present_flag; // u(1)
84− int colour_primaries; // u(8)
85− int transfer_characteristics; // u(8)
86− int matrix_coefficients; // u(8)
87− int chroma_loc_info_present_flag; // u(1)
88− int chroma_sample_loc_type_top_field; // ue(v)
89− int chroma_sample_loc_type_bottom_field; // ue(v)
90− int neutral_chroma_indication_flag; // u(1)
91− int field_seq_flag; // u(1)
92− int timing_info_present_flag; // u(1)
93− int num_units_in_tick; // u(32)
94− int time_scale; // u(32)
95− int fixed_pic_rate_flag; // u(1)
96− int nal_hrd_parameters_present_flag; // u(1)
97− int vcl_hrd_parameters_present_flag; // u(1)
98− int low_delay_hrd_flag; // u(1)
99− int pic_struct_present_flag; // u(1)
100− int bitstream_restriction_flag; // u(1)
101− int motion_vectors_over_pic_boundaries_flag; // u(1)
102− int max_bytes_per_pic_denom; // ue(v)
103− int max_bits_per_mb_denom; // ue(v)
104− int log2_max_mv_length_horizontal; // ue(v)
105− int log2_max_mv_length_vertical; // ue(v)
106− int num_reorder_pics; // ue(v)
107− int max_dec_pic_buffering; // ue(v)
108−
109− HRDParameters hrd_parameters;
110−} VUIParameters;
111−
112−// The sturcture reflects SPS RBSP(raw byte sequence payload) layout
113−// @see ISO_IEC_23094-1 section 7.3.2.1
114−//
115−// The following descriptors specify the parsing process of each element
116−// u(n) - unsigned integer using n bits
117−// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element with the left bit first
118−typedef struct EVCParserSPS {
119− int sps_seq_parameter_set_id; // ue(v)
120− int profile_idc; // u(8)
121− int level_idc; // u(8)
122− int toolset_idc_h; // u(32)
123− int toolset_idc_l; // u(32)
124− int chroma_format_idc; // ue(v)
125− int pic_width_in_luma_samples; // ue(v)
126− int pic_height_in_luma_samples; // ue(v)
127− int bit_depth_luma_minus8; // ue(v)
128− int bit_depth_chroma_minus8; // ue(v)
129−
130− int sps_btt_flag; // u(1)
131− int log2_ctu_size_minus5; // ue(v)
132− int log2_min_cb_size_minus2; // ue(v)
133− int log2_diff_ctu_max_14_cb_size; // ue(v)
134− int log2_diff_ctu_max_tt_cb_size; // ue(v)
135− int log2_diff_min_cb_min_tt_cb_size_minus2; // ue(v)
136−
137− int sps_suco_flag; // u(1)
138− int log2_diff_ctu_size_max_suco_cb_size; // ue(v)
139− int log2_diff_max_suco_min_suco_cb_size; // ue(v)
140−
141− int sps_admvp_flag; // u(1)
142− int sps_affine_flag; // u(1)
143− int sps_amvr_flag; // u(1)
144− int sps_dmvr_flag; // u(1)
145− int sps_mmvd_flag; // u(1)
146− int sps_hmvp_flag; // u(1)
147−
148− int sps_eipd_flag; // u(1)
149− int sps_ibc_flag; // u(1)
150− int log2_max_ibc_cand_size_minus2; // ue(v)
151−
152− int sps_cm_init_flag; // u(1)
153− int sps_adcc_flag; // u(1)
154−
155− int sps_iqt_flag; // u(1)
156− int sps_ats_flag; // u(1)
157−
158− int sps_addb_flag; // u(1)
159− int sps_alf_flag; // u(1)
160− int sps_htdf_flag; // u(1)
161− int sps_rpl_flag; // u(1)
162− int sps_pocs_flag; // u(1)
163− int sps_dquant_flag; // u(1)
164− int sps_dra_flag; // u(1)
165−
166− int log2_max_pic_order_cnt_lsb_minus4; // ue(v)
167− int log2_sub_gop_length; // ue(v)
168− int log2_ref_pic_gap_length; // ue(v)
169−
170− int max_num_tid0_ref_pics; // ue(v)
171−
172− int sps_max_dec_pic_buffering_minus1; // ue(v)
173− int long_term_ref_pic_flag; // u(1)
174− int rpl1_same_as_rpl0_flag; // u(1)
175− int num_ref_pic_list_in_sps[2]; // ue(v)
176− struct RefPicListStruct rpls[2][EVC_MAX_NUM_RPLS];
177−
178− int picture_cropping_flag; // u(1)
179− int picture_crop_left_offset; // ue(v)
180− int picture_crop_right_offset; // ue(v)
181− int picture_crop_top_offset; // ue(v)
182− int picture_crop_bottom_offset; // ue(v)
183−
184− struct ChromaQpTable chroma_qp_table_struct;
185−
186− int vui_parameters_present_flag; // u(1)
187−
188− struct VUIParameters vui_parameters;
189−
190−} EVCParserSPS;
191−
192−typedef struct EVCParserPPS {
193− int pps_pic_parameter_set_id; // ue(v)
194− int pps_seq_parameter_set_id; // ue(v)
195− int num_ref_idx_default_active_minus1[2]; // ue(v)
196− int additional_lt_poc_lsb_len; // ue(v)
197− int rpl1_idx_present_flag; // u(1)
198− int single_tile_in_pic_flag; // u(1)
199− int num_tile_columns_minus1; // ue(v)
200− int num_tile_rows_minus1; // ue(v)
201− int uniform_tile_spacing_flag; // u(1)
202− int tile_column_width_minus1[EVC_MAX_TILE_ROWS]; // ue(v)
203− int tile_row_height_minus1[EVC_MAX_TILE_COLUMNS]; // ue(v)
204− int loop_filter_across_tiles_enabled_flag; // u(1)
205− int tile_offset_len_minus1; // ue(v)
206− int tile_id_len_minus1; // ue(v)
207− int explicit_tile_id_flag; // u(1)
208− int tile_id_val[EVC_MAX_TILE_ROWS][EVC_MAX_TILE_COLUMNS]; // u(v)
209− int pic_dra_enabled_flag; // u(1)
210− int pic_dra_aps_id; // u(5)
211− int arbitrary_slice_present_flag; // u(1)
212− int constrained_intra_pred_flag; // u(1)
213− int cu_qp_delta_enabled_flag; // u(1)
214− int log2_cu_qp_delta_area_minus6; // ue(v)
215−
216−} EVCParserPPS;
33+#include "evc_ps.h"
21734
21835 // The sturcture reflects Slice Header RBSP(raw byte sequence payload) layout
21936 // @see ISO_IEC_23094-1 section 7.3.2.6
@@ -265,10 +82,7 @@ typedef struct EVCParserPoc { · 45 unmodified lines
26582 } EVCParserPoc;
26683
26784 typedef struct EVCParserContext {
268− //ParseContext pc;
269− EVCParserSPS *sps[EVC_MAX_SPS_COUNT];
270− EVCParserPPS *pps[EVC_MAX_PPS_COUNT];
271−
85+ EVCParamSets ps;
27286 EVCParserPoc poc;
27387
27488 int nuh_temporal_id; // the value of TemporalId (shall be the same for all VCL NAL units of an Access Unit)
@@ -349,14 +163,6 @@ static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_si · 74 unmodified lines
349163 // nuh_temporal_id specifies a temporal identifier for the NAL unit
350164 int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);
351165
352−// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
353−EVCParserSPS *ff_evc_parse_sps(EVCParserContext *ctx, const uint8_t *bs, int bs_size);
354−
355−// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
356−EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs, int bs_size);
357−
358166 int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx);
359167
360−void ff_evc_parse_free(EVCParserContext *ctx);
361−
362168 #endif /* AVCODEC_EVC_PARSE_H */
libavcodec/evc_parser.c+1−1
@@ -202,7 +202,7 @@ static void evc_parser_close(AVCodecParserContext *s) · 201 unmodified lines
202202 {
203203 EVCParserContext *ctx = s->priv_data;
204204
205− ff_evc_parse_free(ctx);
205+ ff_evc_ps_free(&ctx->ps);
206206 }
207207
208208 const AVCodecParser ff_evc_parser = {
libavcodec/evc_ps.c+381−0
@@ -0,0 +1,381 @@
1+/*
2+ * This file is part of FFmpeg.
3+ *
4+ * FFmpeg is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * FFmpeg is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with FFmpeg; if not, write to the Free Software
16+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+ */
18+
19+#include "golomb.h"
20+#include "parser.h"
21+#include "evc.h"
22+#include "evc_ps.h"
23+
24+#define EXTENDED_SAR 255
25+
26+// @see ISO_IEC_23094-1 (7.3.7 Reference picture list structure syntax)
27+static int ref_pic_list_struct(GetBitContext *gb, RefPicListStruct *rpl)
28+{
29+ uint32_t delta_poc_st, strp_entry_sign_flag = 0;
30+ rpl->ref_pic_num = get_ue_golomb(gb);
31+ if (rpl->ref_pic_num > 0) {
32+ delta_poc_st = get_ue_golomb(gb);
33+
34+ rpl->ref_pics[0] = delta_poc_st;
35+ if (rpl->ref_pics[0] != 0) {
36+ strp_entry_sign_flag = get_bits(gb, 1);
37+
38+ rpl->ref_pics[0] *= 1 - (strp_entry_sign_flag << 1);
39+ }
40+ }
41+
42+ for (int i = 1; i < rpl->ref_pic_num; ++i) {
43+ delta_poc_st = get_ue_golomb(gb);
44+ if (delta_poc_st != 0)
45+ strp_entry_sign_flag = get_bits(gb, 1);
46+ rpl->ref_pics[i] = rpl->ref_pics[i - 1] + delta_poc_st * (1 - (strp_entry_sign_flag << 1));
47+ }
48+
49+ return 0;
50+}
51+
52+// @see ISO_IEC_23094-1 (E.2.2 HRD parameters syntax)
53+static int hrd_parameters(GetBitContext *gb, HRDParameters *hrd)
54+{
55+ hrd->cpb_cnt_minus1 = get_ue_golomb(gb);
56+ hrd->bit_rate_scale = get_bits(gb, 4);
57+ hrd->cpb_size_scale = get_bits(gb, 4);
58+ for (int SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1; SchedSelIdx++) {
59+ hrd->bit_rate_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
60+ hrd->cpb_size_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
61+ hrd->cbr_flag[SchedSelIdx] = get_bits(gb, 1);
62+ }
63+ hrd->initial_cpb_removal_delay_length_minus1 = get_bits(gb, 5);
64+ hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
65+ hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
66+ hrd->time_offset_length = get_bits(gb, 5);
67+
68+ return 0;
69+}
70+
71+// @see ISO_IEC_23094-1 (E.2.1 VUI parameters syntax)
72+static int vui_parameters(GetBitContext *gb, VUIParameters *vui)
73+{
74+ vui->aspect_ratio_info_present_flag = get_bits(gb, 1);
75+ if (vui->aspect_ratio_info_present_flag) {
76+ vui->aspect_ratio_idc = get_bits(gb, 8);
77+ if (vui->aspect_ratio_idc == EXTENDED_SAR) {
78+ vui->sar_width = get_bits(gb, 16);
79+ vui->sar_height = get_bits(gb, 16);
80+ }
81+ }
82+ vui->overscan_info_present_flag = get_bits(gb, 1);
83+ if (vui->overscan_info_present_flag)
84+ vui->overscan_appropriate_flag = get_bits(gb, 1);
85+ vui->video_signal_type_present_flag = get_bits(gb, 1);
86+ if (vui->video_signal_type_present_flag) {
87+ vui->video_format = get_bits(gb, 3);
88+ vui->video_full_range_flag = get_bits(gb, 1);
89+ vui->colour_description_present_flag = get_bits(gb, 1);
90+ if (vui->colour_description_present_flag) {
91+ vui->colour_primaries = get_bits(gb, 8);
92+ vui->transfer_characteristics = get_bits(gb, 8);
93+ vui->matrix_coefficients = get_bits(gb, 8);
94+ }
95+ }
96+ vui->chroma_loc_info_present_flag = get_bits(gb, 1);
97+ if (vui->chroma_loc_info_present_flag) {
98+ vui->chroma_sample_loc_type_top_field = get_ue_golomb(gb);
99+ vui->chroma_sample_loc_type_bottom_field = get_ue_golomb(gb);
100+ }
101+ vui->neutral_chroma_indication_flag = get_bits(gb, 1);
102+
103+ vui->field_seq_flag = get_bits(gb, 1);
104+
105+ vui->timing_info_present_flag = get_bits(gb, 1);
106+ if (vui->timing_info_present_flag) {
107+ vui->num_units_in_tick = get_bits(gb, 32);
108+ vui->time_scale = get_bits(gb, 32);
109+ vui->fixed_pic_rate_flag = get_bits(gb, 1);
110+ }
111+ vui->nal_hrd_parameters_present_flag = get_bits(gb, 1);
112+ if (vui->nal_hrd_parameters_present_flag)
113+ hrd_parameters(gb, &vui->hrd_parameters);
114+ vui->vcl_hrd_parameters_present_flag = get_bits(gb, 1);
115+ if (vui->vcl_hrd_parameters_present_flag)
116+ hrd_parameters(gb, &vui->hrd_parameters);
117+ if (vui->nal_hrd_parameters_present_flag || vui->vcl_hrd_parameters_present_flag)
118+ vui->low_delay_hrd_flag = get_bits(gb, 1);
119+ vui->pic_struct_present_flag = get_bits(gb, 1);
120+ vui->bitstream_restriction_flag = get_bits(gb, 1);
121+ if (vui->bitstream_restriction_flag) {
122+ vui->motion_vectors_over_pic_boundaries_flag = get_bits(gb, 1);
123+ vui->max_bytes_per_pic_denom = get_ue_golomb(gb);
124+ vui->max_bits_per_mb_denom = get_ue_golomb(gb);
125+ vui->log2_max_mv_length_horizontal = get_ue_golomb(gb);
126+ vui->log2_max_mv_length_vertical = get_ue_golomb(gb);
127+ vui->num_reorder_pics = get_ue_golomb(gb);
128+ vui->max_dec_pic_buffering = get_ue_golomb(gb);
129+ }
130+
131+ return 0;
132+}
133+
134+// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
135+EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
136+{
137+ GetBitContext gb;
138+ EVCParserSPS *sps;
139+ int sps_seq_parameter_set_id;
140+
141+ if (init_get_bits8(&gb, bs, bs_size) < 0)
142+ return NULL;
143+
144+ sps_seq_parameter_set_id = get_ue_golomb(&gb);
145+
146+ if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT)
147+ return NULL;
148+
149+ if(!ps->sps[sps_seq_parameter_set_id]) {
150+ if((ps->sps[sps_seq_parameter_set_id] = av_malloc(sizeof(EVCParserSPS))) == NULL)
151+ return NULL;
152+ }
153+
154+ sps = ps->sps[sps_seq_parameter_set_id];
155+ memset(sps, 0, sizeof(*sps));
156+
157+ sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id;
158+
159+ // the Baseline profile is indicated by profile_idc eqal to 0
160+ // the Main profile is indicated by profile_idc eqal to 1
161+ sps->profile_idc = get_bits(&gb, 8);
162+
163+ sps->level_idc = get_bits(&gb, 8);
164+
165+ skip_bits_long(&gb, 32); /* skip toolset_idc_h */
166+ skip_bits_long(&gb, 32); /* skip toolset_idc_l */
167+
168+ // 0 - monochrome
169+ // 1 - 4:2:0
170+ // 2 - 4:2:2
171+ // 3 - 4:4:4
172+ sps->chroma_format_idc = get_ue_golomb(&gb);
173+
174+ sps->pic_width_in_luma_samples = get_ue_golomb(&gb);
175+ sps->pic_height_in_luma_samples = get_ue_golomb(&gb);
176+
177+ sps->bit_depth_luma_minus8 = get_ue_golomb(&gb);
178+ sps->bit_depth_chroma_minus8 = get_ue_golomb(&gb);
179+
180+ sps->sps_btt_flag = get_bits(&gb, 1);
181+ if (sps->sps_btt_flag) {
182+ sps->log2_ctu_size_minus5 = get_ue_golomb(&gb);
183+ sps->log2_min_cb_size_minus2 = get_ue_golomb(&gb);
184+ sps->log2_diff_ctu_max_14_cb_size = get_ue_golomb(&gb);
185+ sps->log2_diff_ctu_max_tt_cb_size = get_ue_golomb(&gb);
186+ sps->log2_diff_min_cb_min_tt_cb_size_minus2 = get_ue_golomb(&gb);
187+ }
188+
189+ sps->sps_suco_flag = get_bits(&gb, 1);
190+ if (sps->sps_suco_flag) {
191+ sps->log2_diff_ctu_size_max_suco_cb_size = get_ue_golomb(&gb);
192+ sps->log2_diff_max_suco_min_suco_cb_size = get_ue_golomb(&gb);
193+ }
194+
195+ sps->sps_admvp_flag = get_bits(&gb, 1);
196+ if (sps->sps_admvp_flag) {
197+ sps->sps_affine_flag = get_bits(&gb, 1);
198+ sps->sps_amvr_flag = get_bits(&gb, 1);
199+ sps->sps_dmvr_flag = get_bits(&gb, 1);
200+ sps->sps_mmvd_flag = get_bits(&gb, 1);
201+ sps->sps_hmvp_flag = get_bits(&gb, 1);
202+ }
203+
204+ sps->sps_eipd_flag = get_bits(&gb, 1);
205+ if (sps->sps_eipd_flag) {
206+ sps->sps_ibc_flag = get_bits(&gb, 1);
207+ if (sps->sps_ibc_flag)
208+ sps->log2_max_ibc_cand_size_minus2 = get_ue_golomb(&gb);
209+ }
210+
211+ sps->sps_cm_init_flag = get_bits(&gb, 1);
212+ if (sps->sps_cm_init_flag)
213+ sps->sps_adcc_flag = get_bits(&gb, 1);
214+
215+ sps->sps_iqt_flag = get_bits(&gb, 1);
216+ if (sps->sps_iqt_flag)
217+ sps->sps_ats_flag = get_bits(&gb, 1);
218+
219+ sps->sps_addb_flag = get_bits(&gb, 1);
220+ sps->sps_alf_flag = get_bits(&gb, 1);
221+ sps->sps_htdf_flag = get_bits(&gb, 1);
222+ sps->sps_rpl_flag = get_bits(&gb, 1);
223+ sps->sps_pocs_flag = get_bits(&gb, 1);
224+ sps->sps_dquant_flag = get_bits(&gb, 1);
225+ sps->sps_dra_flag = get_bits(&gb, 1);
226+
227+ if (sps->sps_pocs_flag)
228+ sps->log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb(&gb);
229+
230+ if (!sps->sps_pocs_flag || !sps->sps_rpl_flag) {
231+ sps->log2_sub_gop_length = get_ue_golomb(&gb);
232+ if (sps->log2_sub_gop_length == 0)
233+ sps->log2_ref_pic_gap_length = get_ue_golomb(&gb);
234+ }
235+
236+ if (!sps->sps_rpl_flag)
237+ sps->max_num_tid0_ref_pics = get_ue_golomb(&gb);
238+ else {
239+ sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb(&gb);
240+ sps->long_term_ref_pic_flag = get_bits(&gb, 1);
241+ sps->rpl1_same_as_rpl0_flag = get_bits(&gb, 1);
242+ sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(&gb);
243+
244+ for (int i = 0; i < sps->num_ref_pic_list_in_sps[0]; ++i)
245+ ref_pic_list_struct(&gb, &sps->rpls[0][i]);
246+
247+ if (!sps->rpl1_same_as_rpl0_flag) {
248+ sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(&gb);
249+ for (int i = 0; i < sps->num_ref_pic_list_in_sps[1]; ++i)
250+ ref_pic_list_struct(&gb, &sps->rpls[1][i]);
251+ }
252+ }
253+
254+ sps->picture_cropping_flag = get_bits(&gb, 1);
255+
256+ if (sps->picture_cropping_flag) {
257+ sps->picture_crop_left_offset = get_ue_golomb(&gb);
258+ sps->picture_crop_right_offset = get_ue_golomb(&gb);
259+ sps->picture_crop_top_offset = get_ue_golomb(&gb);
260+ sps->picture_crop_bottom_offset = get_ue_golomb(&gb);
261+ }
262+
263+ if (sps->chroma_format_idc != 0) {
264+ sps->chroma_qp_table_struct.chroma_qp_table_present_flag = get_bits(&gb, 1);
265+
266+ if (sps->chroma_qp_table_struct.chroma_qp_table_present_flag) {
267+ sps->chroma_qp_table_struct.same_qp_table_for_chroma = get_bits(&gb, 1);
268+ sps->chroma_qp_table_struct.global_offset_flag = get_bits(&gb, 1);
269+ for (int i = 0; i < (sps->chroma_qp_table_struct.same_qp_table_for_chroma ? 1 : 2); i++) {
270+ sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] = get_ue_golomb(&gb);;
271+ for (int j = 0; j <= sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i]; j++) {
272+ sps->chroma_qp_table_struct.delta_qp_in_val_minus1[i][j] = get_bits(&gb, 6);
273+ sps->chroma_qp_table_struct.delta_qp_out_val[i][j] = get_se_golomb(&gb);
274+ }
275+ }
276+ }
277+ }
278+
279+ sps->vui_parameters_present_flag = get_bits(&gb, 1);
280+ if (sps->vui_parameters_present_flag)
281+ vui_parameters(&gb, &(sps->vui_parameters));
282+
283+ // @note
284+ // If necessary, add the missing fields to the EVCParserSPS structure
285+ // and then extend parser implementation
286+
287+ return sps;
288+}
289+
290+// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
291+//
292+// @note
293+// The current implementation of parse_sps function doesn't handle VUI parameters parsing.
294+// If it will be needed, parse_sps function could be extended to handle VUI parameters parsing
295+// to initialize fields of the AVCodecContex i.e. color_primaries, color_trc,color_range
296+//
297+EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
298+{
299+ GetBitContext gb;
300+ EVCParserPPS *pps;
301+
302+ int pps_pic_parameter_set_id;
303+
304+ if (init_get_bits8(&gb, bs, bs_size) < 0)
305+ return NULL;
306+
307+ pps_pic_parameter_set_id = get_ue_golomb(&gb);
308+ if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT)
309+ return NULL;
310+
311+ if(!ps->pps[pps_pic_parameter_set_id]) {
312+ if ((ps->pps[pps_pic_parameter_set_id] = av_malloc(sizeof(EVCParserPPS))) == NULL)
313+ return NULL;
314+ }
315+
316+ pps = ps->pps[pps_pic_parameter_set_id];
317+ memset(pps, 0, sizeof(*pps));
318+
319+ pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id;
320+
321+ pps->pps_seq_parameter_set_id = get_ue_golomb(&gb);
322+ if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) {
323+ av_freep(&ps->pps[pps_pic_parameter_set_id]);
324+ return NULL;
325+ }
326+
327+ pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
328+ pps->num_ref_idx_default_active_minus1[1] = get_ue_golomb(&gb);
329+ pps->additional_lt_poc_lsb_len = get_ue_golomb(&gb);
330+ pps->rpl1_idx_present_flag = get_bits(&gb, 1);
331+ pps->single_tile_in_pic_flag = get_bits(&gb, 1);
332+
333+ if (!pps->single_tile_in_pic_flag) {
334+ pps->num_tile_columns_minus1 = get_ue_golomb(&gb);
335+ pps->num_tile_rows_minus1 = get_ue_golomb(&gb);
336+ pps->uniform_tile_spacing_flag = get_bits(&gb, 1);
337+
338+ if (!pps->uniform_tile_spacing_flag) {
339+ for (int i = 0; i < pps->num_tile_columns_minus1; i++)
340+ pps->tile_column_width_minus1[i] = get_ue_golomb(&gb);
341+
342+ for (int i = 0; i < pps->num_tile_rows_minus1; i++)
343+ pps->tile_row_height_minus1[i] = get_ue_golomb(&gb);
344+ }
345+ pps->loop_filter_across_tiles_enabled_flag = get_bits(&gb, 1);
346+ pps->tile_offset_len_minus1 = get_ue_golomb(&gb);
347+ }
348+
349+ pps->tile_id_len_minus1 = get_ue_golomb(&gb);
350+ pps->explicit_tile_id_flag = get_bits(&gb, 1);
351+
352+ if (pps->explicit_tile_id_flag) {
353+ for (int i = 0; i <= pps->num_tile_rows_minus1; i++) {
354+ for (int j = 0; j <= pps->num_tile_columns_minus1; j++)
355+ pps->tile_id_val[i][j] = get_bits(&gb, pps->tile_id_len_minus1 + 1);
356+ }
357+ }
358+
359+ pps->pic_dra_enabled_flag = 0;
360+ pps->pic_dra_enabled_flag = get_bits(&gb, 1);
361+
362+ if (pps->pic_dra_enabled_flag)
363+ pps->pic_dra_aps_id = get_bits(&gb, 5);
364+
365+ pps->arbitrary_slice_present_flag = get_bits(&gb, 1);
366+ pps->constrained_intra_pred_flag = get_bits(&gb, 1);
367+ pps->cu_qp_delta_enabled_flag = get_bits(&gb, 1);
368+
369+ if (pps->cu_qp_delta_enabled_flag)
370+ pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(&gb);
371+
372+ return pps;
373+}
374+
375+void ff_evc_ps_free(EVCParamSets *ps) {
376+ for (int i = 0; i < EVC_MAX_SPS_COUNT; i++)
377+ av_freep(&ps->sps[i]);
378+
379+ for (int i = 0; i < EVC_MAX_PPS_COUNT; i++)
380+ av_freep(&ps->pps[i]);
381+}
libavcodec/evc_ps.h+228−0
@@ -0,0 +1,228 @@
1+/*
2+ * This file is part of FFmpeg.
3+ *
4+ * FFmpeg is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * FFmpeg is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with FFmpeg; if not, write to the Free Software
16+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+ */
18+
19+/**
20+ * @file
21+ * EVC decoder/parser shared code
22+ */
23+
24+#ifndef AVCODEC_EVC_PS_H
25+#define AVCODEC_EVC_PS_H
26+
27+#include <stdint.h>
28+
29+#include "evc.h"
30+
31+#define EVC_MAX_QP_TABLE_SIZE 58
32+#define NUM_CPB 32
33+
34+// rpl structure
35+typedef struct RefPicListStruct {
36+ int poc;
37+ int tid;
38+ int ref_pic_num;
39+ int ref_pic_active_num;
40+ int ref_pics[EVC_MAX_NUM_REF_PICS];
41+ char pic_type;
42+
43+} RefPicListStruct;
44+
45+// chromaQP table structure to be signalled in SPS
46+typedef struct ChromaQpTable {
47+ int chroma_qp_table_present_flag; // u(1)
48+ int same_qp_table_for_chroma; // u(1)
49+ int global_offset_flag; // u(1)
50+ int num_points_in_qp_table_minus1[2]; // ue(v)
51+ int delta_qp_in_val_minus1[2][EVC_MAX_QP_TABLE_SIZE]; // u(6)
52+ int delta_qp_out_val[2][EVC_MAX_QP_TABLE_SIZE]; // se(v)
53+} ChromaQpTable;
54+
55+// Hypothetical Reference Decoder (HRD) parameters, part of VUI
56+typedef struct HRDParameters {
57+ int cpb_cnt_minus1; // ue(v)
58+ int bit_rate_scale; // u(4)
59+ int cpb_size_scale; // u(4)
60+ int bit_rate_value_minus1[NUM_CPB]; // ue(v)
61+ int cpb_size_value_minus1[NUM_CPB]; // ue(v)
62+ int cbr_flag[NUM_CPB]; // u(1)
63+ int initial_cpb_removal_delay_length_minus1; // u(5)
64+ int cpb_removal_delay_length_minus1; // u(5)
65+ int dpb_output_delay_length_minus1; // u(5)
66+ int time_offset_length; // u(5)
67+} HRDParameters;
68+
69+// video usability information (VUI) part of SPS
70+typedef struct VUIParameters {
71+ int aspect_ratio_info_present_flag; // u(1)
72+ int aspect_ratio_idc; // u(8)
73+ int sar_width; // u(16)
74+ int sar_height; // u(16)
75+ int overscan_info_present_flag; // u(1)
76+ int overscan_appropriate_flag; // u(1)
77+ int video_signal_type_present_flag; // u(1)
78+ int video_format; // u(3)
79+ int video_full_range_flag; // u(1)
80+ int colour_description_present_flag; // u(1)
81+ int colour_primaries; // u(8)
82+ int transfer_characteristics; // u(8)
83+ int matrix_coefficients; // u(8)
84+ int chroma_loc_info_present_flag; // u(1)
85+ int chroma_sample_loc_type_top_field; // ue(v)
86+ int chroma_sample_loc_type_bottom_field; // ue(v)
87+ int neutral_chroma_indication_flag; // u(1)
88+ int field_seq_flag; // u(1)
89+ int timing_info_present_flag; // u(1)
90+ int num_units_in_tick; // u(32)
91+ int time_scale; // u(32)
92+ int fixed_pic_rate_flag; // u(1)
93+ int nal_hrd_parameters_present_flag; // u(1)
94+ int vcl_hrd_parameters_present_flag; // u(1)
95+ int low_delay_hrd_flag; // u(1)
96+ int pic_struct_present_flag; // u(1)
97+ int bitstream_restriction_flag; // u(1)
98+ int motion_vectors_over_pic_boundaries_flag; // u(1)
99+ int max_bytes_per_pic_denom; // ue(v)
100+ int max_bits_per_mb_denom; // ue(v)
101+ int log2_max_mv_length_horizontal; // ue(v)
102+ int log2_max_mv_length_vertical; // ue(v)
103+ int num_reorder_pics; // ue(v)
104+ int max_dec_pic_buffering; // ue(v)
105+
106+ HRDParameters hrd_parameters;
107+} VUIParameters;
108+
109+// The sturcture reflects SPS RBSP(raw byte sequence payload) layout
110+// @see ISO_IEC_23094-1 section 7.3.2.1
111+//
112+// The following descriptors specify the parsing process of each element
113+// u(n) - unsigned integer using n bits
114+// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element with the left bit first
115+typedef struct EVCParserSPS {
116+ int sps_seq_parameter_set_id; // ue(v)
117+ int profile_idc; // u(8)
118+ int level_idc; // u(8)
119+ int toolset_idc_h; // u(32)
120+ int toolset_idc_l; // u(32)
121+ int chroma_format_idc; // ue(v)
122+ int pic_width_in_luma_samples; // ue(v)
123+ int pic_height_in_luma_samples; // ue(v)
124+ int bit_depth_luma_minus8; // ue(v)
125+ int bit_depth_chroma_minus8; // ue(v)
126+
127+ int sps_btt_flag; // u(1)
128+ int log2_ctu_size_minus5; // ue(v)
129+ int log2_min_cb_size_minus2; // ue(v)
130+ int log2_diff_ctu_max_14_cb_size; // ue(v)
131+ int log2_diff_ctu_max_tt_cb_size; // ue(v)
132+ int log2_diff_min_cb_min_tt_cb_size_minus2; // ue(v)
133+
134+ int sps_suco_flag; // u(1)
135+ int log2_diff_ctu_size_max_suco_cb_size; // ue(v)
136+ int log2_diff_max_suco_min_suco_cb_size; // ue(v)
137+
138+ int sps_admvp_flag; // u(1)
139+ int sps_affine_flag; // u(1)
140+ int sps_amvr_flag; // u(1)
141+ int sps_dmvr_flag; // u(1)
142+ int sps_mmvd_flag; // u(1)
143+ int sps_hmvp_flag; // u(1)
144+
145+ int sps_eipd_flag; // u(1)
146+ int sps_ibc_flag; // u(1)
147+ int log2_max_ibc_cand_size_minus2; // ue(v)
148+
149+ int sps_cm_init_flag; // u(1)
150+ int sps_adcc_flag; // u(1)
151+
152+ int sps_iqt_flag; // u(1)
153+ int sps_ats_flag; // u(1)
154+
155+ int sps_addb_flag; // u(1)
156+ int sps_alf_flag; // u(1)
157+ int sps_htdf_flag; // u(1)
158+ int sps_rpl_flag; // u(1)
159+ int sps_pocs_flag; // u(1)
160+ int sps_dquant_flag; // u(1)
161+ int sps_dra_flag; // u(1)
162+
163+ int log2_max_pic_order_cnt_lsb_minus4; // ue(v)
164+ int log2_sub_gop_length; // ue(v)
165+ int log2_ref_pic_gap_length; // ue(v)
166+
167+ int max_num_tid0_ref_pics; // ue(v)
168+
169+ int sps_max_dec_pic_buffering_minus1; // ue(v)
170+ int long_term_ref_pic_flag; // u(1)
171+ int rpl1_same_as_rpl0_flag; // u(1)
172+ int num_ref_pic_list_in_sps[2]; // ue(v)
173+ struct RefPicListStruct rpls[2][EVC_MAX_NUM_RPLS];
174+
175+ int picture_cropping_flag; // u(1)
176+ int picture_crop_left_offset; // ue(v)
177+ int picture_crop_right_offset; // ue(v)
178+ int picture_crop_top_offset; // ue(v)
179+ int picture_crop_bottom_offset; // ue(v)
180+
181+ struct ChromaQpTable chroma_qp_table_struct;
182+
183+ int vui_parameters_present_flag; // u(1)
184+
185+ struct VUIParameters vui_parameters;
186+
187+} EVCParserSPS;
188+
189+typedef struct EVCParserPPS {
190+ int pps_pic_parameter_set_id; // ue(v)
191+ int pps_seq_parameter_set_id; // ue(v)
192+ int num_ref_idx_default_active_minus1[2]; // ue(v)
193+ int additional_lt_poc_lsb_len; // ue(v)
194+ int rpl1_idx_present_flag; // u(1)
195+ int single_tile_in_pic_flag; // u(1)
196+ int num_tile_columns_minus1; // ue(v)
197+ int num_tile_rows_minus1; // ue(v)
198+ int uniform_tile_spacing_flag; // u(1)
199+ int tile_column_width_minus1[EVC_MAX_TILE_ROWS]; // ue(v)
200+ int tile_row_height_minus1[EVC_MAX_TILE_COLUMNS]; // ue(v)
201+ int loop_filter_across_tiles_enabled_flag; // u(1)
202+ int tile_offset_len_minus1; // ue(v)
203+ int tile_id_len_minus1; // ue(v)
204+ int explicit_tile_id_flag; // u(1)
205+ int tile_id_val[EVC_MAX_TILE_ROWS][EVC_MAX_TILE_COLUMNS]; // u(v)
206+ int pic_dra_enabled_flag; // u(1)
207+ int pic_dra_aps_id; // u(5)
208+ int arbitrary_slice_present_flag; // u(1)
209+ int constrained_intra_pred_flag; // u(1)
210+ int cu_qp_delta_enabled_flag; // u(1)
211+ int log2_cu_qp_delta_area_minus6; // ue(v)
212+
213+} EVCParserPPS;
214+
215+typedef struct EVCParamSets {
216+ EVCParserSPS *sps[EVC_MAX_SPS_COUNT];
217+ EVCParserPPS *pps[EVC_MAX_PPS_COUNT];
218+} EVCParamSets;
219+
220+// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
221+EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
222+
223+// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
224+EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
225+
226+void ff_evc_ps_free(EVCParamSets *ps);
227+
228+#endif /* AVCODEC_EVC_PS_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t