Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc()
@ 2023-06-17 15:18 James Almer
  2023-06-17 15:18 ` [FFmpeg-devel] [PATCH 2/3] avcodec/evc_frame_merge_bsf: use av_new_packet() James Almer
                   ` (16 more replies)
  0 siblings, 17 replies; 25+ messages in thread
From: James Almer @ 2023-06-17 15:18 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_frame_merge_bsf.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/libavcodec/evc_frame_merge_bsf.c b/libavcodec/evc_frame_merge_bsf.c
index 7cc701f5c5..827f114f0b 100644
--- a/libavcodec/evc_frame_merge_bsf.c
+++ b/libavcodec/evc_frame_merge_bsf.c
@@ -26,13 +26,11 @@
 #include "evc.h"
 #include "evc_parse.h"
 
-#define INIT_AU_BUF_CAPACITY 1024
-
 // Access unit data
 typedef struct AccessUnitBuffer {
     uint8_t *data;      // the data buffer
     size_t data_size;   // size of data in bytes
-    size_t capacity;    // buffer capacity
+    unsigned capacity;  // buffer capacity
 } AccessUnitBuffer;
 
 typedef struct EVCFMergeContext {
@@ -72,9 +70,8 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
 
     AVPacket *in = ctx->in;
 
-    int free_space = 0;
     size_t  nalu_size = 0;
-    uint8_t *nalu = NULL;
+    uint8_t *buffer, *nalu = NULL;
     int au_end_found = 0;
     int err;
 
@@ -102,15 +99,14 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
 
     au_end_found = end_of_access_unit_found(parser_ctx);
 
-    free_space = ctx->au_buffer.capacity - ctx->au_buffer.data_size;
-    while (free_space < in->size) {
-        ctx->au_buffer.capacity *= 2;
-        free_space = ctx->au_buffer.capacity - ctx->au_buffer.data_size;
-
-        if (free_space >= in->size)
-            ctx->au_buffer.data = av_realloc(ctx->au_buffer.data, ctx->au_buffer.capacity);
+    buffer = av_fast_realloc(ctx->au_buffer.data, &ctx->au_buffer.capacity,
+                             ctx->au_buffer.data_size + in->size);
+    if (!buffer) {
+        av_freep(&ctx->au_buffer.data);
+        return AVERROR(ENOMEM);
     }
 
+    ctx->au_buffer.data = buffer;
     memcpy(ctx->au_buffer.data + ctx->au_buffer.data_size, in->data, in->size);
 
     ctx->au_buffer.data_size += in->size;
@@ -143,10 +139,6 @@ static int evc_frame_merge_init(AVBSFContext *bsf)
     if (!ctx->in)
         return AVERROR(ENOMEM);
 
-    ctx->au_buffer.capacity = INIT_AU_BUF_CAPACITY;
-    ctx->au_buffer.data = av_malloc(INIT_AU_BUF_CAPACITY);
-    ctx->au_buffer.data_size = 0;
-
     return 0;
 }
 
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 2/3] avcodec/evc_frame_merge_bsf: use av_new_packet()
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
@ 2023-06-17 15:18 ` James Almer
  2023-06-17 15:18 ` [FFmpeg-devel] [PATCH 3/3] fate/lavf-container: add a test to remux raw evc into mp4 James Almer
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-17 15:18 UTC (permalink / raw)
  To: ffmpeg-devel

This ensures the buffer is padded as required by the AVPacket API.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_frame_merge_bsf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/evc_frame_merge_bsf.c b/libavcodec/evc_frame_merge_bsf.c
index 827f114f0b..540bb63631 100644
--- a/libavcodec/evc_frame_merge_bsf.c
+++ b/libavcodec/evc_frame_merge_bsf.c
@@ -114,14 +114,14 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
     av_packet_unref(in);
 
     if (au_end_found) {
-        uint8_t *data = av_memdup(ctx->au_buffer.data, ctx->au_buffer.data_size);
         size_t data_size = ctx->au_buffer.data_size;
 
         ctx->au_buffer.data_size = 0;
-        if (!data)
-            return AVERROR(ENOMEM);
+        err = av_new_packet(out, data_size);
+        if (err < 0)
+            return err;
 
-        err = av_packet_from_data(out, data, data_size);
+        memcpy(out->data, ctx->au_buffer.data, data_size);
     } else
         err = AVERROR(EAGAIN);
 
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 3/3] fate/lavf-container: add a test to remux raw evc into mp4
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
  2023-06-17 15:18 ` [FFmpeg-devel] [PATCH 2/3] avcodec/evc_frame_merge_bsf: use av_new_packet() James Almer
@ 2023-06-17 15:18 ` James Almer
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 04/10] avcodec/evc_parse: split off Parameter Set parsing into its own file James Almer
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-17 15:18 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 tests/fate/lavf-container.mak | 2 ++
 tests/ref/lavf-fate/evc.mp4   | 3 +++
 2 files changed, 5 insertions(+)
 create mode 100644 tests/ref/lavf-fate/evc.mp4

diff --git a/tests/fate/lavf-container.mak b/tests/fate/lavf-container.mak
index 93740475b4..0d4a224601 100644
--- a/tests/fate/lavf-container.mak
+++ b/tests/fate/lavf-container.mak
@@ -71,6 +71,7 @@ FATE_AVCONV += $(FATE_LAVF_CONTAINER)
 fate-lavf-container fate-lavf: $(FATE_LAVF_CONTAINER)
 
 FATE_LAVF_CONTAINER_FATE-$(call ALLYES, IVF_DEMUXER AV1_PARSER MOV_MUXER)      += av1.mp4
+FATE_LAVF_CONTAINER_FATE-$(call ALLYES, EVC_DEMUXER EVC_PARSER MOV_MUXER)      += evc.mp4
 FATE_LAVF_CONTAINER_FATE-$(call ALLYES, IVF_DEMUXER AV1_PARSER MATROSKA_MUXER) += av1.mkv
 FATE_LAVF_CONTAINER_FATE-$(call ALLYES, H264_DEMUXER H264_PARSER MOV_MUXER)    += h264.mp4
 FATE_LAVF_CONTAINER_FATE-$(call ALLYES, MATROSKA_DEMUXER   OGG_MUXER)          += vp3.ogg
@@ -87,6 +88,7 @@ $(FATE_LAVF_CONTAINER_FATE): $(AREF) $(VREF)
 
 fate-lavf-fate-av1.mp4: CMD = lavf_container_fate "av1-test-vectors/av1-1-b8-05-mv.ivf" "" "-c:v copy"
 fate-lavf-fate-av1.mkv: CMD = lavf_container_fate "av1-test-vectors/av1-1-b8-05-mv.ivf" "" "-c:v copy"
+fate-lavf-fate-evc.mp4: CMD = lavf_container_fate "evc/akiyo_cif.evc" "" "-c:v copy"
 fate-lavf-fate-h264.mp4: CMD = lavf_container_fate "h264/intra_refresh.h264" "" "-c:v copy"
 fate-lavf-fate-vp3.ogg: CMD = lavf_container_fate "vp3/coeff_level64.mkv" "-idct auto"
 fate-lavf-fate-vp8.ogg: CMD = lavf_container_fate "vp8/RRSF49-short.webm" "" "-acodec copy"
diff --git a/tests/ref/lavf-fate/evc.mp4 b/tests/ref/lavf-fate/evc.mp4
new file mode 100644
index 0000000000..b0afa350ac
--- /dev/null
+++ b/tests/ref/lavf-fate/evc.mp4
@@ -0,0 +1,3 @@
+55294f868fa3b31d34a48344c4f72630 *tests/data/lavf-fate/lavf.evc.mp4
+37386 tests/data/lavf-fate/lavf.evc.mp4
+tests/data/lavf-fate/lavf.evc.mp4 CRC=0x48063f85
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 04/10] avcodec/evc_parse: split off Parameter Set parsing into its own file
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
  2023-06-17 15:18 ` [FFmpeg-devel] [PATCH 2/3] avcodec/evc_frame_merge_bsf: use av_new_packet() James Almer
  2023-06-17 15:18 ` [FFmpeg-devel] [PATCH 3/3] fate/lavf-container: add a test to remux raw evc into mp4 James Almer
@ 2023-06-17 22:00 ` James Almer
  2023-06-20  7:37   ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 05/10] avcodec/evc_parser: stop exporting delay and gop_size James Almer
                   ` (13 subsequent siblings)
  16 siblings, 1 reply; 25+ messages in thread
From: James Almer @ 2023-06-17 22:00 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/Makefile              |   2 +-
 libavcodec/evc_frame_merge_bsf.c |   4 +-
 libavcodec/evc_parse.c           | 371 +-----------------------------
 libavcodec/evc_parse.h           | 198 +---------------
 libavcodec/evc_parser.c          |   2 +-
 libavcodec/evc_ps.c              | 381 +++++++++++++++++++++++++++++++
 libavcodec/evc_ps.h              | 228 ++++++++++++++++++
 7 files changed, 621 insertions(+), 565 deletions(-)
 create mode 100644 libavcodec/evc_ps.c
 create mode 100644 libavcodec/evc_ps.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 0ce8fe5b9c..723bfa25c7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -84,7 +84,7 @@ OBJS-$(CONFIG_DCT)                     += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_DEFLATE_WRAPPER)         += zlib_wrapper.o
 OBJS-$(CONFIG_DOVI_RPU)                += dovi_rpu.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)        += error_resilience.o
-OBJS-$(CONFIG_EVCPARSE)                += evc_parse.o
+OBJS-$(CONFIG_EVCPARSE)                += evc_parse.o evc_ps.o
 OBJS-$(CONFIG_EXIF)                    += exif.o tiff_common.o
 OBJS-$(CONFIG_FAANDCT)                 += faandct.o
 OBJS-$(CONFIG_FAANIDCT)                += faanidct.o
diff --git a/libavcodec/evc_frame_merge_bsf.c b/libavcodec/evc_frame_merge_bsf.c
index 540bb63631..f497780afb 100644
--- a/libavcodec/evc_frame_merge_bsf.c
+++ b/libavcodec/evc_frame_merge_bsf.c
@@ -58,7 +58,7 @@ static void evc_frame_merge_flush(AVBSFContext *bsf)
 {
     EVCFMergeContext *ctx = bsf->priv_data;
 
-    ff_evc_parse_free(&ctx->parser_ctx);
+    ff_evc_ps_free(&ctx->parser_ctx.ps);
     av_packet_unref(ctx->in);
     ctx->au_buffer.data_size = 0;
 }
@@ -147,7 +147,7 @@ static void evc_frame_merge_close(AVBSFContext *bsf)
     EVCFMergeContext *ctx = bsf->priv_data;
 
     av_packet_free(&ctx->in);
-    ff_evc_parse_free(&ctx->parser_ctx);
+    ff_evc_ps_free(&ctx->parser_ctx.ps);
 
     ctx->au_buffer.capacity = 0;
     av_freep(&ctx->au_buffer.data);
diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c
index 44be5c5291..a8e6356b96 100644
--- a/libavcodec/evc_parse.c
+++ b/libavcodec/evc_parse.c
@@ -21,8 +21,6 @@
 #include "evc.h"
 #include "evc_parse.h"
 
-#define EXTENDED_SAR            255
-
 #define NUM_CHROMA_FORMATS      4   // @see ISO_IEC_23094-1 section 6.2 table 2
 
 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)
     return temporal_id;
 }
 
-// @see ISO_IEC_23094-1 (7.3.7 Reference picture list structure syntax)
-static int ref_pic_list_struct(GetBitContext *gb, RefPicListStruct *rpl)
-{
-    uint32_t delta_poc_st, strp_entry_sign_flag = 0;
-    rpl->ref_pic_num = get_ue_golomb(gb);
-    if (rpl->ref_pic_num > 0) {
-        delta_poc_st = get_ue_golomb(gb);
-
-        rpl->ref_pics[0] = delta_poc_st;
-        if (rpl->ref_pics[0] != 0) {
-            strp_entry_sign_flag = get_bits(gb, 1);
-
-            rpl->ref_pics[0] *= 1 - (strp_entry_sign_flag << 1);
-        }
-    }
-
-    for (int i = 1; i < rpl->ref_pic_num; ++i) {
-        delta_poc_st = get_ue_golomb(gb);
-        if (delta_poc_st != 0)
-            strp_entry_sign_flag = get_bits(gb, 1);
-        rpl->ref_pics[i] = rpl->ref_pics[i - 1] + delta_poc_st * (1 - (strp_entry_sign_flag << 1));
-    }
-
-    return 0;
-}
-
-// @see  ISO_IEC_23094-1 (E.2.2 HRD parameters syntax)
-static int hrd_parameters(GetBitContext *gb, HRDParameters *hrd)
-{
-    hrd->cpb_cnt_minus1 = get_ue_golomb(gb);
-    hrd->bit_rate_scale = get_bits(gb, 4);
-    hrd->cpb_size_scale = get_bits(gb, 4);
-    for (int SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1; SchedSelIdx++) {
-        hrd->bit_rate_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
-        hrd->cpb_size_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
-        hrd->cbr_flag[SchedSelIdx] = get_bits(gb, 1);
-    }
-    hrd->initial_cpb_removal_delay_length_minus1 = get_bits(gb, 5);
-    hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
-    hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
-    hrd->time_offset_length = get_bits(gb, 5);
-
-    return 0;
-}
-
-// @see  ISO_IEC_23094-1 (E.2.1 VUI parameters syntax)
-static int vui_parameters(GetBitContext *gb, VUIParameters *vui)
-{
-    vui->aspect_ratio_info_present_flag = get_bits(gb, 1);
-    if (vui->aspect_ratio_info_present_flag) {
-        vui->aspect_ratio_idc = get_bits(gb, 8);
-        if (vui->aspect_ratio_idc == EXTENDED_SAR) {
-            vui->sar_width = get_bits(gb, 16);
-            vui->sar_height = get_bits(gb, 16);
-        }
-    }
-    vui->overscan_info_present_flag = get_bits(gb, 1);
-    if (vui->overscan_info_present_flag)
-        vui->overscan_appropriate_flag = get_bits(gb, 1);
-    vui->video_signal_type_present_flag = get_bits(gb, 1);
-    if (vui->video_signal_type_present_flag) {
-        vui->video_format = get_bits(gb, 3);
-        vui->video_full_range_flag = get_bits(gb, 1);
-        vui->colour_description_present_flag = get_bits(gb, 1);
-        if (vui->colour_description_present_flag) {
-            vui->colour_primaries = get_bits(gb, 8);
-            vui->transfer_characteristics = get_bits(gb, 8);
-            vui->matrix_coefficients = get_bits(gb, 8);
-        }
-    }
-    vui->chroma_loc_info_present_flag = get_bits(gb, 1);
-    if (vui->chroma_loc_info_present_flag) {
-        vui->chroma_sample_loc_type_top_field = get_ue_golomb(gb);
-        vui->chroma_sample_loc_type_bottom_field = get_ue_golomb(gb);
-    }
-    vui->neutral_chroma_indication_flag = get_bits(gb, 1);
-
-    vui->field_seq_flag = get_bits(gb, 1);
-
-    vui->timing_info_present_flag = get_bits(gb, 1);
-    if (vui->timing_info_present_flag) {
-        vui->num_units_in_tick = get_bits(gb, 32);
-        vui->time_scale = get_bits(gb, 32);
-        vui->fixed_pic_rate_flag = get_bits(gb, 1);
-    }
-    vui->nal_hrd_parameters_present_flag = get_bits(gb, 1);
-    if (vui->nal_hrd_parameters_present_flag)
-        hrd_parameters(gb, &vui->hrd_parameters);
-    vui->vcl_hrd_parameters_present_flag = get_bits(gb, 1);
-    if (vui->vcl_hrd_parameters_present_flag)
-        hrd_parameters(gb, &vui->hrd_parameters);
-    if (vui->nal_hrd_parameters_present_flag || vui->vcl_hrd_parameters_present_flag)
-        vui->low_delay_hrd_flag = get_bits(gb, 1);
-    vui->pic_struct_present_flag = get_bits(gb, 1);
-    vui->bitstream_restriction_flag = get_bits(gb, 1);
-    if (vui->bitstream_restriction_flag) {
-        vui->motion_vectors_over_pic_boundaries_flag = get_bits(gb, 1);
-        vui->max_bytes_per_pic_denom = get_ue_golomb(gb);
-        vui->max_bits_per_mb_denom = get_ue_golomb(gb);
-        vui->log2_max_mv_length_horizontal = get_ue_golomb(gb);
-        vui->log2_max_mv_length_vertical = get_ue_golomb(gb);
-        vui->num_reorder_pics = get_ue_golomb(gb);
-        vui->max_dec_pic_buffering = get_ue_golomb(gb);
-    }
-
-    return 0;
-}
-
-// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
-EVCParserSPS *ff_evc_parse_sps(EVCParserContext *ctx, const uint8_t *bs, int bs_size)
-{
-    GetBitContext gb;
-    EVCParserSPS *sps;
-    int sps_seq_parameter_set_id;
-
-    if (init_get_bits8(&gb, bs, bs_size) < 0)
-        return NULL;
-
-    sps_seq_parameter_set_id = get_ue_golomb(&gb);
-
-    if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT)
-        return NULL;
-
-    if(!ctx->sps[sps_seq_parameter_set_id]) {
-        if((ctx->sps[sps_seq_parameter_set_id] = av_malloc(sizeof(EVCParserSPS))) == NULL)
-            return NULL;
-    }
-
-    sps = ctx->sps[sps_seq_parameter_set_id];
-    memset(sps, 0, sizeof(*sps));
-
-    sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id;
-
-    // the Baseline profile is indicated by profile_idc eqal to 0
-    // the Main profile is indicated by profile_idc eqal to 1
-    sps->profile_idc = get_bits(&gb, 8);
-
-    sps->level_idc = get_bits(&gb, 8);
-
-    skip_bits_long(&gb, 32); /* skip toolset_idc_h */
-    skip_bits_long(&gb, 32); /* skip toolset_idc_l */
-
-    // 0 - monochrome
-    // 1 - 4:2:0
-    // 2 - 4:2:2
-    // 3 - 4:4:4
-    sps->chroma_format_idc = get_ue_golomb(&gb);
-
-    sps->pic_width_in_luma_samples = get_ue_golomb(&gb);
-    sps->pic_height_in_luma_samples = get_ue_golomb(&gb);
-
-    sps->bit_depth_luma_minus8 = get_ue_golomb(&gb);
-    sps->bit_depth_chroma_minus8 = get_ue_golomb(&gb);
-
-    sps->sps_btt_flag = get_bits(&gb, 1);
-    if (sps->sps_btt_flag) {
-        sps->log2_ctu_size_minus5 = get_ue_golomb(&gb);
-        sps->log2_min_cb_size_minus2 = get_ue_golomb(&gb);
-        sps->log2_diff_ctu_max_14_cb_size = get_ue_golomb(&gb);
-        sps->log2_diff_ctu_max_tt_cb_size = get_ue_golomb(&gb);
-        sps->log2_diff_min_cb_min_tt_cb_size_minus2 = get_ue_golomb(&gb);
-    }
-
-    sps->sps_suco_flag = get_bits(&gb, 1);
-    if (sps->sps_suco_flag) {
-        sps->log2_diff_ctu_size_max_suco_cb_size = get_ue_golomb(&gb);
-        sps->log2_diff_max_suco_min_suco_cb_size = get_ue_golomb(&gb);
-    }
-
-    sps->sps_admvp_flag = get_bits(&gb, 1);
-    if (sps->sps_admvp_flag) {
-        sps->sps_affine_flag = get_bits(&gb, 1);
-        sps->sps_amvr_flag = get_bits(&gb, 1);
-        sps->sps_dmvr_flag = get_bits(&gb, 1);
-        sps->sps_mmvd_flag = get_bits(&gb, 1);
-        sps->sps_hmvp_flag = get_bits(&gb, 1);
-    }
-
-    sps->sps_eipd_flag =  get_bits(&gb, 1);
-    if (sps->sps_eipd_flag) {
-        sps->sps_ibc_flag = get_bits(&gb, 1);
-        if (sps->sps_ibc_flag)
-            sps->log2_max_ibc_cand_size_minus2 = get_ue_golomb(&gb);
-    }
-
-    sps->sps_cm_init_flag = get_bits(&gb, 1);
-    if (sps->sps_cm_init_flag)
-        sps->sps_adcc_flag = get_bits(&gb, 1);
-
-    sps->sps_iqt_flag = get_bits(&gb, 1);
-    if (sps->sps_iqt_flag)
-        sps->sps_ats_flag = get_bits(&gb, 1);
-
-    sps->sps_addb_flag = get_bits(&gb, 1);
-    sps->sps_alf_flag = get_bits(&gb, 1);
-    sps->sps_htdf_flag = get_bits(&gb, 1);
-    sps->sps_rpl_flag = get_bits(&gb, 1);
-    sps->sps_pocs_flag = get_bits(&gb, 1);
-    sps->sps_dquant_flag = get_bits(&gb, 1);
-    sps->sps_dra_flag = get_bits(&gb, 1);
-
-    if (sps->sps_pocs_flag)
-        sps->log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb(&gb);
-
-    if (!sps->sps_pocs_flag || !sps->sps_rpl_flag) {
-        sps->log2_sub_gop_length = get_ue_golomb(&gb);
-        if (sps->log2_sub_gop_length == 0)
-            sps->log2_ref_pic_gap_length = get_ue_golomb(&gb);
-    }
-
-    if (!sps->sps_rpl_flag)
-        sps->max_num_tid0_ref_pics = get_ue_golomb(&gb);
-    else {
-        sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb(&gb);
-        sps->long_term_ref_pic_flag = get_bits(&gb, 1);
-        sps->rpl1_same_as_rpl0_flag = get_bits(&gb, 1);
-        sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(&gb);
-
-        for (int i = 0; i < sps->num_ref_pic_list_in_sps[0]; ++i)
-            ref_pic_list_struct(&gb, &sps->rpls[0][i]);
-
-        if (!sps->rpl1_same_as_rpl0_flag) {
-            sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(&gb);
-            for (int i = 0; i < sps->num_ref_pic_list_in_sps[1]; ++i)
-                ref_pic_list_struct(&gb, &sps->rpls[1][i]);
-        }
-    }
-
-    sps->picture_cropping_flag = get_bits(&gb, 1);
-
-    if (sps->picture_cropping_flag) {
-        sps->picture_crop_left_offset = get_ue_golomb(&gb);
-        sps->picture_crop_right_offset = get_ue_golomb(&gb);
-        sps->picture_crop_top_offset = get_ue_golomb(&gb);
-        sps->picture_crop_bottom_offset = get_ue_golomb(&gb);
-    }
-
-    if (sps->chroma_format_idc != 0) {
-        sps->chroma_qp_table_struct.chroma_qp_table_present_flag = get_bits(&gb, 1);
-
-        if (sps->chroma_qp_table_struct.chroma_qp_table_present_flag) {
-            sps->chroma_qp_table_struct.same_qp_table_for_chroma = get_bits(&gb, 1);
-            sps->chroma_qp_table_struct.global_offset_flag = get_bits(&gb, 1);
-            for (int i = 0; i < (sps->chroma_qp_table_struct.same_qp_table_for_chroma ? 1 : 2); i++) {
-                sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] = get_ue_golomb(&gb);;
-                for (int j = 0; j <= sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i]; j++) {
-                    sps->chroma_qp_table_struct.delta_qp_in_val_minus1[i][j] = get_bits(&gb, 6);
-                    sps->chroma_qp_table_struct.delta_qp_out_val[i][j] = get_se_golomb(&gb);
-                }
-            }
-        }
-    }
-
-    sps->vui_parameters_present_flag = get_bits(&gb, 1);
-    if (sps->vui_parameters_present_flag)
-        vui_parameters(&gb, &(sps->vui_parameters));
-
-    // @note
-    // If necessary, add the missing fields to the EVCParserSPS structure
-    // and then extend parser implementation
-
-    return sps;
-}
-
-// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
-//
-// @note
-// The current implementation of parse_sps function doesn't handle VUI parameters parsing.
-// If it will be needed, parse_sps function could be extended to handle VUI parameters parsing
-// to initialize fields of the AVCodecContex i.e. color_primaries, color_trc,color_range
-//
-EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs, int bs_size)
-{
-    GetBitContext gb;
-    EVCParserPPS *pps;
-
-    int pps_pic_parameter_set_id;
-
-    if (init_get_bits8(&gb, bs, bs_size) < 0)
-        return NULL;
-
-    pps_pic_parameter_set_id = get_ue_golomb(&gb);
-    if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT)
-        return NULL;
-
-    if(!ctx->pps[pps_pic_parameter_set_id]) {
-        if ((ctx->pps[pps_pic_parameter_set_id] = av_malloc(sizeof(EVCParserPPS))) == NULL)
-            return NULL;
-    }
-
-    pps = ctx->pps[pps_pic_parameter_set_id];
-    memset(pps, 0, sizeof(*pps));
-
-    pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id;
-
-    pps->pps_seq_parameter_set_id = get_ue_golomb(&gb);
-    if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) {
-        av_freep(&ctx->pps[pps_pic_parameter_set_id]);
-        return NULL;
-    }
-
-    pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
-    pps->num_ref_idx_default_active_minus1[1] = get_ue_golomb(&gb);
-    pps->additional_lt_poc_lsb_len = get_ue_golomb(&gb);
-    pps->rpl1_idx_present_flag = get_bits(&gb, 1);
-    pps->single_tile_in_pic_flag = get_bits(&gb, 1);
-
-    if (!pps->single_tile_in_pic_flag) {
-        pps->num_tile_columns_minus1 = get_ue_golomb(&gb);
-        pps->num_tile_rows_minus1 = get_ue_golomb(&gb);
-        pps->uniform_tile_spacing_flag = get_bits(&gb, 1);
-
-        if (!pps->uniform_tile_spacing_flag) {
-            for (int i = 0; i < pps->num_tile_columns_minus1; i++)
-                pps->tile_column_width_minus1[i] = get_ue_golomb(&gb);
-
-            for (int i = 0; i < pps->num_tile_rows_minus1; i++)
-                pps->tile_row_height_minus1[i] = get_ue_golomb(&gb);
-        }
-        pps->loop_filter_across_tiles_enabled_flag = get_bits(&gb, 1);
-        pps->tile_offset_len_minus1 = get_ue_golomb(&gb);
-    }
-
-    pps->tile_id_len_minus1 = get_ue_golomb(&gb);
-    pps->explicit_tile_id_flag = get_bits(&gb, 1);
-
-    if (pps->explicit_tile_id_flag) {
-        for (int i = 0; i <= pps->num_tile_rows_minus1; i++) {
-            for (int j = 0; j <= pps->num_tile_columns_minus1; j++)
-                pps->tile_id_val[i][j] = get_bits(&gb, pps->tile_id_len_minus1 + 1);
-        }
-    }
-
-    pps->pic_dra_enabled_flag = 0;
-    pps->pic_dra_enabled_flag = get_bits(&gb, 1);
-
-    if (pps->pic_dra_enabled_flag)
-        pps->pic_dra_aps_id = get_bits(&gb, 5);
-
-    pps->arbitrary_slice_present_flag = get_bits(&gb, 1);
-    pps->constrained_intra_pred_flag = get_bits(&gb, 1);
-    pps->cu_qp_delta_enabled_flag = get_bits(&gb, 1);
-
-    if (pps->cu_qp_delta_enabled_flag)
-        pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(&gb);
-
-    return pps;
-}
-
 // @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
 static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *sh, const uint8_t *bs, int bs_size)
 {
@@ -439,11 +88,11 @@ static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *s
     if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT)
         return AVERROR_INVALIDDATA;
 
-    pps = ctx->pps[slice_pic_parameter_set_id];
+    pps = ctx->ps.pps[slice_pic_parameter_set_id];
     if(!pps)
         return AVERROR_INVALIDDATA;
 
-    sps = ctx->sps[pps->pps_seq_parameter_set_id];
+    sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
     if(!sps)
         return AVERROR_INVALIDDATA;
 
@@ -579,7 +228,7 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
         int SubGopLength;
         int bit_depth;
 
-        sps = ff_evc_parse_sps(ctx, data, nalu_size);
+        sps = ff_evc_parse_sps(&ctx->ps, data, nalu_size);
         if (!sps) {
             av_log(logctx, AV_LOG_ERROR, "SPS parsing error\n");
             return AVERROR_INVALIDDATA;
@@ -642,7 +291,7 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
     case EVC_PPS_NUT: {
         EVCParserPPS *pps;
 
-        pps = ff_evc_parse_pps(ctx, data, nalu_size);
+        pps = ff_evc_parse_pps(&ctx->ps, data, nalu_size);
         if (!pps) {
             av_log(logctx, AV_LOG_ERROR, "PPS parsing error\n");
             return AVERROR_INVALIDDATA;
@@ -688,8 +337,8 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
 
         // POC (picture order count of the current picture) derivation
         // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
-        pps = ctx->pps[sh.slice_pic_parameter_set_id];
-        sps = ctx->sps[pps->pps_seq_parameter_set_id];
+        pps = ctx->ps.pps[sh.slice_pic_parameter_set_id];
+        sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
         av_assert0(sps && pps);
 
         if (sps->sps_pocs_flag) {
@@ -764,11 +413,3 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
 
     return 0;
 }
-
-void ff_evc_parse_free(EVCParserContext *ctx) {
-    for (int i = 0; i < EVC_MAX_SPS_COUNT; i++)
-        av_freep(&ctx->sps[i]);
-
-    for (int i = 0; i < EVC_MAX_PPS_COUNT; i++)
-        av_freep(&ctx->pps[i]);
-}
diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index ee4b6c5708..b5462f5711 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -30,190 +30,7 @@
 #include "libavutil/log.h"
 #include "libavutil/rational.h"
 #include "evc.h"
-
-#define EVC_MAX_QP_TABLE_SIZE   58
-#define NUM_CPB                 32
-
-// rpl structure
-typedef struct RefPicListStruct {
-    int poc;
-    int tid;
-    int ref_pic_num;
-    int ref_pic_active_num;
-    int ref_pics[EVC_MAX_NUM_REF_PICS];
-    char pic_type;
-
-} RefPicListStruct;
-
-// chromaQP table structure to be signalled in SPS
-typedef struct ChromaQpTable {
-    int chroma_qp_table_present_flag;       // u(1)
-    int same_qp_table_for_chroma;           // u(1)
-    int global_offset_flag;                 // u(1)
-    int num_points_in_qp_table_minus1[2];   // ue(v)
-    int delta_qp_in_val_minus1[2][EVC_MAX_QP_TABLE_SIZE];   // u(6)
-    int delta_qp_out_val[2][EVC_MAX_QP_TABLE_SIZE];         // se(v)
-} ChromaQpTable;
-
-// Hypothetical Reference Decoder (HRD) parameters, part of VUI
-typedef struct HRDParameters {
-    int cpb_cnt_minus1;                             // ue(v)
-    int bit_rate_scale;                             // u(4)
-    int cpb_size_scale;                             // u(4)
-    int bit_rate_value_minus1[NUM_CPB];             // ue(v)
-    int cpb_size_value_minus1[NUM_CPB];             // ue(v)
-    int cbr_flag[NUM_CPB];                          // u(1)
-    int initial_cpb_removal_delay_length_minus1;    // u(5)
-    int cpb_removal_delay_length_minus1;            // u(5)
-    int dpb_output_delay_length_minus1;             // u(5)
-    int time_offset_length;                         // u(5)
-} HRDParameters;
-
-// video usability information (VUI) part of SPS
-typedef struct VUIParameters {
-    int aspect_ratio_info_present_flag;             // u(1)
-    int aspect_ratio_idc;                           // u(8)
-    int sar_width;                                  // u(16)
-    int sar_height;                                 // u(16)
-    int overscan_info_present_flag;                 // u(1)
-    int overscan_appropriate_flag;                  // u(1)
-    int video_signal_type_present_flag;             // u(1)
-    int video_format;                               // u(3)
-    int video_full_range_flag;                      // u(1)
-    int colour_description_present_flag;            // u(1)
-    int colour_primaries;                           // u(8)
-    int transfer_characteristics;                   // u(8)
-    int matrix_coefficients;                        // u(8)
-    int chroma_loc_info_present_flag;               // u(1)
-    int chroma_sample_loc_type_top_field;           // ue(v)
-    int chroma_sample_loc_type_bottom_field;        // ue(v)
-    int neutral_chroma_indication_flag;             // u(1)
-    int field_seq_flag;                             // u(1)
-    int timing_info_present_flag;                   // u(1)
-    int num_units_in_tick;                          // u(32)
-    int time_scale;                                 // u(32)
-    int fixed_pic_rate_flag;                        // u(1)
-    int nal_hrd_parameters_present_flag;            // u(1)
-    int vcl_hrd_parameters_present_flag;            // u(1)
-    int low_delay_hrd_flag;                         // u(1)
-    int pic_struct_present_flag;                    // u(1)
-    int bitstream_restriction_flag;                 // u(1)
-    int motion_vectors_over_pic_boundaries_flag;    // u(1)
-    int max_bytes_per_pic_denom;                    // ue(v)
-    int max_bits_per_mb_denom;                      // ue(v)
-    int log2_max_mv_length_horizontal;              // ue(v)
-    int log2_max_mv_length_vertical;                // ue(v)
-    int num_reorder_pics;                           // ue(v)
-    int max_dec_pic_buffering;                      // ue(v)
-
-    HRDParameters hrd_parameters;
-} VUIParameters;
-
-// The sturcture reflects SPS RBSP(raw byte sequence payload) layout
-// @see ISO_IEC_23094-1 section 7.3.2.1
-//
-// The following descriptors specify the parsing process of each element
-// u(n) - unsigned integer using n bits
-// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element with the left bit first
-typedef struct EVCParserSPS {
-    int sps_seq_parameter_set_id;   // ue(v)
-    int profile_idc;                // u(8)
-    int level_idc;                  // u(8)
-    int toolset_idc_h;              // u(32)
-    int toolset_idc_l;              // u(32)
-    int chroma_format_idc;          // ue(v)
-    int pic_width_in_luma_samples;  // ue(v)
-    int pic_height_in_luma_samples; // ue(v)
-    int bit_depth_luma_minus8;      // ue(v)
-    int bit_depth_chroma_minus8;    // ue(v)
-
-    int sps_btt_flag;                           // u(1)
-    int log2_ctu_size_minus5;                   // ue(v)
-    int log2_min_cb_size_minus2;                // ue(v)
-    int log2_diff_ctu_max_14_cb_size;           // ue(v)
-    int log2_diff_ctu_max_tt_cb_size;           // ue(v)
-    int log2_diff_min_cb_min_tt_cb_size_minus2; // ue(v)
-
-    int sps_suco_flag;                       // u(1)
-    int log2_diff_ctu_size_max_suco_cb_size; // ue(v)
-    int log2_diff_max_suco_min_suco_cb_size; // ue(v)
-
-    int sps_admvp_flag;     // u(1)
-    int sps_affine_flag;    // u(1)
-    int sps_amvr_flag;      // u(1)
-    int sps_dmvr_flag;      // u(1)
-    int sps_mmvd_flag;      // u(1)
-    int sps_hmvp_flag;      // u(1)
-
-    int sps_eipd_flag;                 // u(1)
-    int sps_ibc_flag;                  // u(1)
-    int log2_max_ibc_cand_size_minus2; // ue(v)
-
-    int sps_cm_init_flag; // u(1)
-    int sps_adcc_flag;    // u(1)
-
-    int sps_iqt_flag; // u(1)
-    int sps_ats_flag; // u(1)
-
-    int sps_addb_flag;   // u(1)
-    int sps_alf_flag;    // u(1)
-    int sps_htdf_flag;   // u(1)
-    int sps_rpl_flag;    // u(1)
-    int sps_pocs_flag;   // u(1)
-    int sps_dquant_flag; // u(1)
-    int sps_dra_flag;    // u(1)
-
-    int log2_max_pic_order_cnt_lsb_minus4; // ue(v)
-    int log2_sub_gop_length;               // ue(v)
-    int log2_ref_pic_gap_length;           // ue(v)
-
-    int max_num_tid0_ref_pics; // ue(v)
-
-    int sps_max_dec_pic_buffering_minus1; // ue(v)
-    int long_term_ref_pic_flag;           // u(1)
-    int rpl1_same_as_rpl0_flag;           // u(1)
-    int num_ref_pic_list_in_sps[2];       // ue(v)
-    struct RefPicListStruct rpls[2][EVC_MAX_NUM_RPLS];
-
-    int picture_cropping_flag;      // u(1)
-    int picture_crop_left_offset;   // ue(v)
-    int picture_crop_right_offset;  // ue(v)
-    int picture_crop_top_offset;    // ue(v)
-    int picture_crop_bottom_offset; // ue(v)
-
-    struct ChromaQpTable chroma_qp_table_struct;
-
-    int vui_parameters_present_flag;    // u(1)
-
-    struct VUIParameters vui_parameters;
-
-} EVCParserSPS;
-
-typedef struct EVCParserPPS {
-    int pps_pic_parameter_set_id;                           // ue(v)
-    int pps_seq_parameter_set_id;                           // ue(v)
-    int num_ref_idx_default_active_minus1[2];               // ue(v)
-    int additional_lt_poc_lsb_len;                          // ue(v)
-    int rpl1_idx_present_flag;                              // u(1)
-    int single_tile_in_pic_flag;                            // u(1)
-    int num_tile_columns_minus1;                            // ue(v)
-    int num_tile_rows_minus1;                               // ue(v)
-    int uniform_tile_spacing_flag;                          // u(1)
-    int tile_column_width_minus1[EVC_MAX_TILE_ROWS];        // ue(v)
-    int tile_row_height_minus1[EVC_MAX_TILE_COLUMNS];          // ue(v)
-    int loop_filter_across_tiles_enabled_flag;              // u(1)
-    int tile_offset_len_minus1;                             // ue(v)
-    int tile_id_len_minus1;                                 // ue(v)
-    int explicit_tile_id_flag;                              // u(1)
-    int tile_id_val[EVC_MAX_TILE_ROWS][EVC_MAX_TILE_COLUMNS];  // u(v)
-    int pic_dra_enabled_flag;                               // u(1)
-    int pic_dra_aps_id;                                     // u(5)
-    int arbitrary_slice_present_flag;                       // u(1)
-    int constrained_intra_pred_flag;                        // u(1)
-    int cu_qp_delta_enabled_flag;                           // u(1)
-    int log2_cu_qp_delta_area_minus6;                       // ue(v)
-
-} EVCParserPPS;
+#include "evc_ps.h"
 
 // The sturcture reflects Slice Header RBSP(raw byte sequence payload) layout
 // @see ISO_IEC_23094-1 section 7.3.2.6
@@ -265,10 +82,7 @@ typedef struct EVCParserPoc {
 } EVCParserPoc;
 
 typedef struct EVCParserContext {
-    //ParseContext pc;
-    EVCParserSPS *sps[EVC_MAX_SPS_COUNT];
-    EVCParserPPS *pps[EVC_MAX_PPS_COUNT];
-
+    EVCParamSets ps;
     EVCParserPoc poc;
 
     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
 // nuh_temporal_id specifies a temporal identifier for the NAL unit
 int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);
 
-// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
-EVCParserSPS *ff_evc_parse_sps(EVCParserContext *ctx, const uint8_t *bs, int bs_size);
-
-// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
-EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs, int bs_size);
-
 int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx);
 
-void ff_evc_parse_free(EVCParserContext *ctx);
-
 #endif /* AVCODEC_EVC_PARSE_H */
diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
index c85b8f89e7..1fd8aac1dc 100644
--- a/libavcodec/evc_parser.c
+++ b/libavcodec/evc_parser.c
@@ -202,7 +202,7 @@ static void evc_parser_close(AVCodecParserContext *s)
 {
     EVCParserContext *ctx = s->priv_data;
 
-    ff_evc_parse_free(ctx);
+    ff_evc_ps_free(&ctx->ps);
 }
 
 const AVCodecParser ff_evc_parser = {
diff --git a/libavcodec/evc_ps.c b/libavcodec/evc_ps.c
new file mode 100644
index 0000000000..af74ba46b0
--- /dev/null
+++ b/libavcodec/evc_ps.c
@@ -0,0 +1,381 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "golomb.h"
+#include "parser.h"
+#include "evc.h"
+#include "evc_ps.h"
+
+#define EXTENDED_SAR 255
+
+// @see ISO_IEC_23094-1 (7.3.7 Reference picture list structure syntax)
+static int ref_pic_list_struct(GetBitContext *gb, RefPicListStruct *rpl)
+{
+    uint32_t delta_poc_st, strp_entry_sign_flag = 0;
+    rpl->ref_pic_num = get_ue_golomb(gb);
+    if (rpl->ref_pic_num > 0) {
+        delta_poc_st = get_ue_golomb(gb);
+
+        rpl->ref_pics[0] = delta_poc_st;
+        if (rpl->ref_pics[0] != 0) {
+            strp_entry_sign_flag = get_bits(gb, 1);
+
+            rpl->ref_pics[0] *= 1 - (strp_entry_sign_flag << 1);
+        }
+    }
+
+    for (int i = 1; i < rpl->ref_pic_num; ++i) {
+        delta_poc_st = get_ue_golomb(gb);
+        if (delta_poc_st != 0)
+            strp_entry_sign_flag = get_bits(gb, 1);
+        rpl->ref_pics[i] = rpl->ref_pics[i - 1] + delta_poc_st * (1 - (strp_entry_sign_flag << 1));
+    }
+
+    return 0;
+}
+
+// @see  ISO_IEC_23094-1 (E.2.2 HRD parameters syntax)
+static int hrd_parameters(GetBitContext *gb, HRDParameters *hrd)
+{
+    hrd->cpb_cnt_minus1 = get_ue_golomb(gb);
+    hrd->bit_rate_scale = get_bits(gb, 4);
+    hrd->cpb_size_scale = get_bits(gb, 4);
+    for (int SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1; SchedSelIdx++) {
+        hrd->bit_rate_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
+        hrd->cpb_size_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
+        hrd->cbr_flag[SchedSelIdx] = get_bits(gb, 1);
+    }
+    hrd->initial_cpb_removal_delay_length_minus1 = get_bits(gb, 5);
+    hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
+    hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
+    hrd->time_offset_length = get_bits(gb, 5);
+
+    return 0;
+}
+
+// @see  ISO_IEC_23094-1 (E.2.1 VUI parameters syntax)
+static int vui_parameters(GetBitContext *gb, VUIParameters *vui)
+{
+    vui->aspect_ratio_info_present_flag = get_bits(gb, 1);
+    if (vui->aspect_ratio_info_present_flag) {
+        vui->aspect_ratio_idc = get_bits(gb, 8);
+        if (vui->aspect_ratio_idc == EXTENDED_SAR) {
+            vui->sar_width = get_bits(gb, 16);
+            vui->sar_height = get_bits(gb, 16);
+        }
+    }
+    vui->overscan_info_present_flag = get_bits(gb, 1);
+    if (vui->overscan_info_present_flag)
+        vui->overscan_appropriate_flag = get_bits(gb, 1);
+    vui->video_signal_type_present_flag = get_bits(gb, 1);
+    if (vui->video_signal_type_present_flag) {
+        vui->video_format = get_bits(gb, 3);
+        vui->video_full_range_flag = get_bits(gb, 1);
+        vui->colour_description_present_flag = get_bits(gb, 1);
+        if (vui->colour_description_present_flag) {
+            vui->colour_primaries = get_bits(gb, 8);
+            vui->transfer_characteristics = get_bits(gb, 8);
+            vui->matrix_coefficients = get_bits(gb, 8);
+        }
+    }
+    vui->chroma_loc_info_present_flag = get_bits(gb, 1);
+    if (vui->chroma_loc_info_present_flag) {
+        vui->chroma_sample_loc_type_top_field = get_ue_golomb(gb);
+        vui->chroma_sample_loc_type_bottom_field = get_ue_golomb(gb);
+    }
+    vui->neutral_chroma_indication_flag = get_bits(gb, 1);
+
+    vui->field_seq_flag = get_bits(gb, 1);
+
+    vui->timing_info_present_flag = get_bits(gb, 1);
+    if (vui->timing_info_present_flag) {
+        vui->num_units_in_tick = get_bits(gb, 32);
+        vui->time_scale = get_bits(gb, 32);
+        vui->fixed_pic_rate_flag = get_bits(gb, 1);
+    }
+    vui->nal_hrd_parameters_present_flag = get_bits(gb, 1);
+    if (vui->nal_hrd_parameters_present_flag)
+        hrd_parameters(gb, &vui->hrd_parameters);
+    vui->vcl_hrd_parameters_present_flag = get_bits(gb, 1);
+    if (vui->vcl_hrd_parameters_present_flag)
+        hrd_parameters(gb, &vui->hrd_parameters);
+    if (vui->nal_hrd_parameters_present_flag || vui->vcl_hrd_parameters_present_flag)
+        vui->low_delay_hrd_flag = get_bits(gb, 1);
+    vui->pic_struct_present_flag = get_bits(gb, 1);
+    vui->bitstream_restriction_flag = get_bits(gb, 1);
+    if (vui->bitstream_restriction_flag) {
+        vui->motion_vectors_over_pic_boundaries_flag = get_bits(gb, 1);
+        vui->max_bytes_per_pic_denom = get_ue_golomb(gb);
+        vui->max_bits_per_mb_denom = get_ue_golomb(gb);
+        vui->log2_max_mv_length_horizontal = get_ue_golomb(gb);
+        vui->log2_max_mv_length_vertical = get_ue_golomb(gb);
+        vui->num_reorder_pics = get_ue_golomb(gb);
+        vui->max_dec_pic_buffering = get_ue_golomb(gb);
+    }
+
+    return 0;
+}
+
+// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
+EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
+{
+    GetBitContext gb;
+    EVCParserSPS *sps;
+    int sps_seq_parameter_set_id;
+
+    if (init_get_bits8(&gb, bs, bs_size) < 0)
+        return NULL;
+
+    sps_seq_parameter_set_id = get_ue_golomb(&gb);
+
+    if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT)
+        return NULL;
+
+    if(!ps->sps[sps_seq_parameter_set_id]) {
+        if((ps->sps[sps_seq_parameter_set_id] = av_malloc(sizeof(EVCParserSPS))) == NULL)
+            return NULL;
+    }
+
+    sps = ps->sps[sps_seq_parameter_set_id];
+    memset(sps, 0, sizeof(*sps));
+
+    sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id;
+
+    // the Baseline profile is indicated by profile_idc eqal to 0
+    // the Main profile is indicated by profile_idc eqal to 1
+    sps->profile_idc = get_bits(&gb, 8);
+
+    sps->level_idc = get_bits(&gb, 8);
+
+    skip_bits_long(&gb, 32); /* skip toolset_idc_h */
+    skip_bits_long(&gb, 32); /* skip toolset_idc_l */
+
+    // 0 - monochrome
+    // 1 - 4:2:0
+    // 2 - 4:2:2
+    // 3 - 4:4:4
+    sps->chroma_format_idc = get_ue_golomb(&gb);
+
+    sps->pic_width_in_luma_samples = get_ue_golomb(&gb);
+    sps->pic_height_in_luma_samples = get_ue_golomb(&gb);
+
+    sps->bit_depth_luma_minus8 = get_ue_golomb(&gb);
+    sps->bit_depth_chroma_minus8 = get_ue_golomb(&gb);
+
+    sps->sps_btt_flag = get_bits(&gb, 1);
+    if (sps->sps_btt_flag) {
+        sps->log2_ctu_size_minus5 = get_ue_golomb(&gb);
+        sps->log2_min_cb_size_minus2 = get_ue_golomb(&gb);
+        sps->log2_diff_ctu_max_14_cb_size = get_ue_golomb(&gb);
+        sps->log2_diff_ctu_max_tt_cb_size = get_ue_golomb(&gb);
+        sps->log2_diff_min_cb_min_tt_cb_size_minus2 = get_ue_golomb(&gb);
+    }
+
+    sps->sps_suco_flag = get_bits(&gb, 1);
+    if (sps->sps_suco_flag) {
+        sps->log2_diff_ctu_size_max_suco_cb_size = get_ue_golomb(&gb);
+        sps->log2_diff_max_suco_min_suco_cb_size = get_ue_golomb(&gb);
+    }
+
+    sps->sps_admvp_flag = get_bits(&gb, 1);
+    if (sps->sps_admvp_flag) {
+        sps->sps_affine_flag = get_bits(&gb, 1);
+        sps->sps_amvr_flag = get_bits(&gb, 1);
+        sps->sps_dmvr_flag = get_bits(&gb, 1);
+        sps->sps_mmvd_flag = get_bits(&gb, 1);
+        sps->sps_hmvp_flag = get_bits(&gb, 1);
+    }
+
+    sps->sps_eipd_flag =  get_bits(&gb, 1);
+    if (sps->sps_eipd_flag) {
+        sps->sps_ibc_flag = get_bits(&gb, 1);
+        if (sps->sps_ibc_flag)
+            sps->log2_max_ibc_cand_size_minus2 = get_ue_golomb(&gb);
+    }
+
+    sps->sps_cm_init_flag = get_bits(&gb, 1);
+    if (sps->sps_cm_init_flag)
+        sps->sps_adcc_flag = get_bits(&gb, 1);
+
+    sps->sps_iqt_flag = get_bits(&gb, 1);
+    if (sps->sps_iqt_flag)
+        sps->sps_ats_flag = get_bits(&gb, 1);
+
+    sps->sps_addb_flag = get_bits(&gb, 1);
+    sps->sps_alf_flag = get_bits(&gb, 1);
+    sps->sps_htdf_flag = get_bits(&gb, 1);
+    sps->sps_rpl_flag = get_bits(&gb, 1);
+    sps->sps_pocs_flag = get_bits(&gb, 1);
+    sps->sps_dquant_flag = get_bits(&gb, 1);
+    sps->sps_dra_flag = get_bits(&gb, 1);
+
+    if (sps->sps_pocs_flag)
+        sps->log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb(&gb);
+
+    if (!sps->sps_pocs_flag || !sps->sps_rpl_flag) {
+        sps->log2_sub_gop_length = get_ue_golomb(&gb);
+        if (sps->log2_sub_gop_length == 0)
+            sps->log2_ref_pic_gap_length = get_ue_golomb(&gb);
+    }
+
+    if (!sps->sps_rpl_flag)
+        sps->max_num_tid0_ref_pics = get_ue_golomb(&gb);
+    else {
+        sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb(&gb);
+        sps->long_term_ref_pic_flag = get_bits(&gb, 1);
+        sps->rpl1_same_as_rpl0_flag = get_bits(&gb, 1);
+        sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(&gb);
+
+        for (int i = 0; i < sps->num_ref_pic_list_in_sps[0]; ++i)
+            ref_pic_list_struct(&gb, &sps->rpls[0][i]);
+
+        if (!sps->rpl1_same_as_rpl0_flag) {
+            sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(&gb);
+            for (int i = 0; i < sps->num_ref_pic_list_in_sps[1]; ++i)
+                ref_pic_list_struct(&gb, &sps->rpls[1][i]);
+        }
+    }
+
+    sps->picture_cropping_flag = get_bits(&gb, 1);
+
+    if (sps->picture_cropping_flag) {
+        sps->picture_crop_left_offset = get_ue_golomb(&gb);
+        sps->picture_crop_right_offset = get_ue_golomb(&gb);
+        sps->picture_crop_top_offset = get_ue_golomb(&gb);
+        sps->picture_crop_bottom_offset = get_ue_golomb(&gb);
+    }
+
+    if (sps->chroma_format_idc != 0) {
+        sps->chroma_qp_table_struct.chroma_qp_table_present_flag = get_bits(&gb, 1);
+
+        if (sps->chroma_qp_table_struct.chroma_qp_table_present_flag) {
+            sps->chroma_qp_table_struct.same_qp_table_for_chroma = get_bits(&gb, 1);
+            sps->chroma_qp_table_struct.global_offset_flag = get_bits(&gb, 1);
+            for (int i = 0; i < (sps->chroma_qp_table_struct.same_qp_table_for_chroma ? 1 : 2); i++) {
+                sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] = get_ue_golomb(&gb);;
+                for (int j = 0; j <= sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i]; j++) {
+                    sps->chroma_qp_table_struct.delta_qp_in_val_minus1[i][j] = get_bits(&gb, 6);
+                    sps->chroma_qp_table_struct.delta_qp_out_val[i][j] = get_se_golomb(&gb);
+                }
+            }
+        }
+    }
+
+    sps->vui_parameters_present_flag = get_bits(&gb, 1);
+    if (sps->vui_parameters_present_flag)
+        vui_parameters(&gb, &(sps->vui_parameters));
+
+    // @note
+    // If necessary, add the missing fields to the EVCParserSPS structure
+    // and then extend parser implementation
+
+    return sps;
+}
+
+// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
+//
+// @note
+// The current implementation of parse_sps function doesn't handle VUI parameters parsing.
+// If it will be needed, parse_sps function could be extended to handle VUI parameters parsing
+// to initialize fields of the AVCodecContex i.e. color_primaries, color_trc,color_range
+//
+EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
+{
+    GetBitContext gb;
+    EVCParserPPS *pps;
+
+    int pps_pic_parameter_set_id;
+
+    if (init_get_bits8(&gb, bs, bs_size) < 0)
+        return NULL;
+
+    pps_pic_parameter_set_id = get_ue_golomb(&gb);
+    if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT)
+        return NULL;
+
+    if(!ps->pps[pps_pic_parameter_set_id]) {
+        if ((ps->pps[pps_pic_parameter_set_id] = av_malloc(sizeof(EVCParserPPS))) == NULL)
+            return NULL;
+    }
+
+    pps = ps->pps[pps_pic_parameter_set_id];
+    memset(pps, 0, sizeof(*pps));
+
+    pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id;
+
+    pps->pps_seq_parameter_set_id = get_ue_golomb(&gb);
+    if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) {
+        av_freep(&ps->pps[pps_pic_parameter_set_id]);
+        return NULL;
+    }
+
+    pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
+    pps->num_ref_idx_default_active_minus1[1] = get_ue_golomb(&gb);
+    pps->additional_lt_poc_lsb_len = get_ue_golomb(&gb);
+    pps->rpl1_idx_present_flag = get_bits(&gb, 1);
+    pps->single_tile_in_pic_flag = get_bits(&gb, 1);
+
+    if (!pps->single_tile_in_pic_flag) {
+        pps->num_tile_columns_minus1 = get_ue_golomb(&gb);
+        pps->num_tile_rows_minus1 = get_ue_golomb(&gb);
+        pps->uniform_tile_spacing_flag = get_bits(&gb, 1);
+
+        if (!pps->uniform_tile_spacing_flag) {
+            for (int i = 0; i < pps->num_tile_columns_minus1; i++)
+                pps->tile_column_width_minus1[i] = get_ue_golomb(&gb);
+
+            for (int i = 0; i < pps->num_tile_rows_minus1; i++)
+                pps->tile_row_height_minus1[i] = get_ue_golomb(&gb);
+        }
+        pps->loop_filter_across_tiles_enabled_flag = get_bits(&gb, 1);
+        pps->tile_offset_len_minus1 = get_ue_golomb(&gb);
+    }
+
+    pps->tile_id_len_minus1 = get_ue_golomb(&gb);
+    pps->explicit_tile_id_flag = get_bits(&gb, 1);
+
+    if (pps->explicit_tile_id_flag) {
+        for (int i = 0; i <= pps->num_tile_rows_minus1; i++) {
+            for (int j = 0; j <= pps->num_tile_columns_minus1; j++)
+                pps->tile_id_val[i][j] = get_bits(&gb, pps->tile_id_len_minus1 + 1);
+        }
+    }
+
+    pps->pic_dra_enabled_flag = 0;
+    pps->pic_dra_enabled_flag = get_bits(&gb, 1);
+
+    if (pps->pic_dra_enabled_flag)
+        pps->pic_dra_aps_id = get_bits(&gb, 5);
+
+    pps->arbitrary_slice_present_flag = get_bits(&gb, 1);
+    pps->constrained_intra_pred_flag = get_bits(&gb, 1);
+    pps->cu_qp_delta_enabled_flag = get_bits(&gb, 1);
+
+    if (pps->cu_qp_delta_enabled_flag)
+        pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(&gb);
+
+    return pps;
+}
+
+void ff_evc_ps_free(EVCParamSets *ps) {
+    for (int i = 0; i < EVC_MAX_SPS_COUNT; i++)
+        av_freep(&ps->sps[i]);
+
+    for (int i = 0; i < EVC_MAX_PPS_COUNT; i++)
+        av_freep(&ps->pps[i]);
+}
diff --git a/libavcodec/evc_ps.h b/libavcodec/evc_ps.h
new file mode 100644
index 0000000000..989336079f
--- /dev/null
+++ b/libavcodec/evc_ps.h
@@ -0,0 +1,228 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * EVC decoder/parser shared code
+ */
+
+#ifndef AVCODEC_EVC_PS_H
+#define AVCODEC_EVC_PS_H
+
+#include <stdint.h>
+
+#include "evc.h"
+
+#define EVC_MAX_QP_TABLE_SIZE   58
+#define NUM_CPB                 32
+
+// rpl structure
+typedef struct RefPicListStruct {
+    int poc;
+    int tid;
+    int ref_pic_num;
+    int ref_pic_active_num;
+    int ref_pics[EVC_MAX_NUM_REF_PICS];
+    char pic_type;
+
+} RefPicListStruct;
+
+// chromaQP table structure to be signalled in SPS
+typedef struct ChromaQpTable {
+    int chroma_qp_table_present_flag;       // u(1)
+    int same_qp_table_for_chroma;           // u(1)
+    int global_offset_flag;                 // u(1)
+    int num_points_in_qp_table_minus1[2];   // ue(v)
+    int delta_qp_in_val_minus1[2][EVC_MAX_QP_TABLE_SIZE];   // u(6)
+    int delta_qp_out_val[2][EVC_MAX_QP_TABLE_SIZE];         // se(v)
+} ChromaQpTable;
+
+// Hypothetical Reference Decoder (HRD) parameters, part of VUI
+typedef struct HRDParameters {
+    int cpb_cnt_minus1;                             // ue(v)
+    int bit_rate_scale;                             // u(4)
+    int cpb_size_scale;                             // u(4)
+    int bit_rate_value_minus1[NUM_CPB];             // ue(v)
+    int cpb_size_value_minus1[NUM_CPB];             // ue(v)
+    int cbr_flag[NUM_CPB];                          // u(1)
+    int initial_cpb_removal_delay_length_minus1;    // u(5)
+    int cpb_removal_delay_length_minus1;            // u(5)
+    int dpb_output_delay_length_minus1;             // u(5)
+    int time_offset_length;                         // u(5)
+} HRDParameters;
+
+// video usability information (VUI) part of SPS
+typedef struct VUIParameters {
+    int aspect_ratio_info_present_flag;             // u(1)
+    int aspect_ratio_idc;                           // u(8)
+    int sar_width;                                  // u(16)
+    int sar_height;                                 // u(16)
+    int overscan_info_present_flag;                 // u(1)
+    int overscan_appropriate_flag;                  // u(1)
+    int video_signal_type_present_flag;             // u(1)
+    int video_format;                               // u(3)
+    int video_full_range_flag;                      // u(1)
+    int colour_description_present_flag;            // u(1)
+    int colour_primaries;                           // u(8)
+    int transfer_characteristics;                   // u(8)
+    int matrix_coefficients;                        // u(8)
+    int chroma_loc_info_present_flag;               // u(1)
+    int chroma_sample_loc_type_top_field;           // ue(v)
+    int chroma_sample_loc_type_bottom_field;        // ue(v)
+    int neutral_chroma_indication_flag;             // u(1)
+    int field_seq_flag;                             // u(1)
+    int timing_info_present_flag;                   // u(1)
+    int num_units_in_tick;                          // u(32)
+    int time_scale;                                 // u(32)
+    int fixed_pic_rate_flag;                        // u(1)
+    int nal_hrd_parameters_present_flag;            // u(1)
+    int vcl_hrd_parameters_present_flag;            // u(1)
+    int low_delay_hrd_flag;                         // u(1)
+    int pic_struct_present_flag;                    // u(1)
+    int bitstream_restriction_flag;                 // u(1)
+    int motion_vectors_over_pic_boundaries_flag;    // u(1)
+    int max_bytes_per_pic_denom;                    // ue(v)
+    int max_bits_per_mb_denom;                      // ue(v)
+    int log2_max_mv_length_horizontal;              // ue(v)
+    int log2_max_mv_length_vertical;                // ue(v)
+    int num_reorder_pics;                           // ue(v)
+    int max_dec_pic_buffering;                      // ue(v)
+
+    HRDParameters hrd_parameters;
+} VUIParameters;
+
+// The sturcture reflects SPS RBSP(raw byte sequence payload) layout
+// @see ISO_IEC_23094-1 section 7.3.2.1
+//
+// The following descriptors specify the parsing process of each element
+// u(n) - unsigned integer using n bits
+// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element with the left bit first
+typedef struct EVCParserSPS {
+    int sps_seq_parameter_set_id;   // ue(v)
+    int profile_idc;                // u(8)
+    int level_idc;                  // u(8)
+    int toolset_idc_h;              // u(32)
+    int toolset_idc_l;              // u(32)
+    int chroma_format_idc;          // ue(v)
+    int pic_width_in_luma_samples;  // ue(v)
+    int pic_height_in_luma_samples; // ue(v)
+    int bit_depth_luma_minus8;      // ue(v)
+    int bit_depth_chroma_minus8;    // ue(v)
+
+    int sps_btt_flag;                           // u(1)
+    int log2_ctu_size_minus5;                   // ue(v)
+    int log2_min_cb_size_minus2;                // ue(v)
+    int log2_diff_ctu_max_14_cb_size;           // ue(v)
+    int log2_diff_ctu_max_tt_cb_size;           // ue(v)
+    int log2_diff_min_cb_min_tt_cb_size_minus2; // ue(v)
+
+    int sps_suco_flag;                       // u(1)
+    int log2_diff_ctu_size_max_suco_cb_size; // ue(v)
+    int log2_diff_max_suco_min_suco_cb_size; // ue(v)
+
+    int sps_admvp_flag;     // u(1)
+    int sps_affine_flag;    // u(1)
+    int sps_amvr_flag;      // u(1)
+    int sps_dmvr_flag;      // u(1)
+    int sps_mmvd_flag;      // u(1)
+    int sps_hmvp_flag;      // u(1)
+
+    int sps_eipd_flag;                 // u(1)
+    int sps_ibc_flag;                  // u(1)
+    int log2_max_ibc_cand_size_minus2; // ue(v)
+
+    int sps_cm_init_flag; // u(1)
+    int sps_adcc_flag;    // u(1)
+
+    int sps_iqt_flag; // u(1)
+    int sps_ats_flag; // u(1)
+
+    int sps_addb_flag;   // u(1)
+    int sps_alf_flag;    // u(1)
+    int sps_htdf_flag;   // u(1)
+    int sps_rpl_flag;    // u(1)
+    int sps_pocs_flag;   // u(1)
+    int sps_dquant_flag; // u(1)
+    int sps_dra_flag;    // u(1)
+
+    int log2_max_pic_order_cnt_lsb_minus4; // ue(v)
+    int log2_sub_gop_length;               // ue(v)
+    int log2_ref_pic_gap_length;           // ue(v)
+
+    int max_num_tid0_ref_pics; // ue(v)
+
+    int sps_max_dec_pic_buffering_minus1; // ue(v)
+    int long_term_ref_pic_flag;           // u(1)
+    int rpl1_same_as_rpl0_flag;           // u(1)
+    int num_ref_pic_list_in_sps[2];       // ue(v)
+    struct RefPicListStruct rpls[2][EVC_MAX_NUM_RPLS];
+
+    int picture_cropping_flag;      // u(1)
+    int picture_crop_left_offset;   // ue(v)
+    int picture_crop_right_offset;  // ue(v)
+    int picture_crop_top_offset;    // ue(v)
+    int picture_crop_bottom_offset; // ue(v)
+
+    struct ChromaQpTable chroma_qp_table_struct;
+
+    int vui_parameters_present_flag;    // u(1)
+
+    struct VUIParameters vui_parameters;
+
+} EVCParserSPS;
+
+typedef struct EVCParserPPS {
+    int pps_pic_parameter_set_id;                           // ue(v)
+    int pps_seq_parameter_set_id;                           // ue(v)
+    int num_ref_idx_default_active_minus1[2];               // ue(v)
+    int additional_lt_poc_lsb_len;                          // ue(v)
+    int rpl1_idx_present_flag;                              // u(1)
+    int single_tile_in_pic_flag;                            // u(1)
+    int num_tile_columns_minus1;                            // ue(v)
+    int num_tile_rows_minus1;                               // ue(v)
+    int uniform_tile_spacing_flag;                          // u(1)
+    int tile_column_width_minus1[EVC_MAX_TILE_ROWS];        // ue(v)
+    int tile_row_height_minus1[EVC_MAX_TILE_COLUMNS];          // ue(v)
+    int loop_filter_across_tiles_enabled_flag;              // u(1)
+    int tile_offset_len_minus1;                             // ue(v)
+    int tile_id_len_minus1;                                 // ue(v)
+    int explicit_tile_id_flag;                              // u(1)
+    int tile_id_val[EVC_MAX_TILE_ROWS][EVC_MAX_TILE_COLUMNS];  // u(v)
+    int pic_dra_enabled_flag;                               // u(1)
+    int pic_dra_aps_id;                                     // u(5)
+    int arbitrary_slice_present_flag;                       // u(1)
+    int constrained_intra_pred_flag;                        // u(1)
+    int cu_qp_delta_enabled_flag;                           // u(1)
+    int log2_cu_qp_delta_area_minus6;                       // ue(v)
+
+} EVCParserPPS;
+
+typedef struct EVCParamSets {
+    EVCParserSPS *sps[EVC_MAX_SPS_COUNT];
+    EVCParserPPS *pps[EVC_MAX_PPS_COUNT];
+} EVCParamSets;
+
+// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
+EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
+
+// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
+EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
+
+void ff_evc_ps_free(EVCParamSets *ps);
+
+#endif /* AVCODEC_EVC_PS_H */
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 05/10] avcodec/evc_parser: stop exporting delay and gop_size
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (2 preceding siblings ...)
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 04/10] avcodec/evc_parse: split off Parameter Set parsing into its own file James Almer
@ 2023-06-17 22:00 ` James Almer
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 06/10] avcodec/evc_parse: split off deriving PoC James Almer
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-17 22:00 UTC (permalink / raw)
  To: ffmpeg-devel

The former is a property a decoder may export, and the latter is only
used in encoding scenarios.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_parse.c  | 6 ------
 libavcodec/evc_parse.h  | 6 ------
 libavcodec/evc_parser.c | 2 --
 3 files changed, 14 deletions(-)

diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c
index a8e6356b96..1fe58c8050 100644
--- a/libavcodec/evc_parse.c
+++ b/libavcodec/evc_parse.c
@@ -225,7 +225,6 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
     switch(nalu_type) {
     case EVC_SPS_NUT: {
         EVCParserSPS *sps;
-        int SubGopLength;
         int bit_depth;
 
         sps = ff_evc_parse_sps(&ctx->ps, data, nalu_size);
@@ -245,11 +244,6 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
             ctx->height          = sps->pic_height_in_luma_samples;
         }
 
-        SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length);
-        ctx->gop_size = SubGopLength;
-
-        ctx->delay = (sps->sps_max_dec_pic_buffering_minus1) ? sps->sps_max_dec_pic_buffering_minus1 - 1 : SubGopLength + sps->max_num_tid0_ref_pics - 1;
-
         if (sps->profile_idc == 1) ctx->profile = FF_PROFILE_EVC_MAIN;
         else ctx->profile = FF_PROFILE_EVC_BASELINE;
 
diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index b5462f5711..2748f8dfbf 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -117,12 +117,6 @@ typedef struct EVCParserContext {
     // Framerate value in the compressed bitstream
     AVRational framerate;
 
-    // Number of pictures in a group of pictures
-    int gop_size;
-
-    // Number of frames the decoded output will be delayed relative to the encoded input
-    int delay;
-
     int parsed_extradata;
 
 } EVCParserContext;
diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
index 1fd8aac1dc..4fd8c49fd4 100644
--- a/libavcodec/evc_parser.c
+++ b/libavcodec/evc_parser.c
@@ -72,8 +72,6 @@ static int parse_nal_units(AVCodecParserContext *s, AVCodecContext *avctx, const
             s->format              = ctx->format;
 
             avctx->framerate       = ctx->framerate;
-            avctx->gop_size        = ctx->gop_size;
-            avctx->delay           = ctx->delay;
             avctx->profile         = ctx->profile;
 
         } else if(ctx->nalu_type == EVC_NOIDR_NUT || ctx->nalu_type == EVC_IDR_NUT) {
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 06/10] avcodec/evc_parse: split off deriving PoC
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (3 preceding siblings ...)
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 05/10] avcodec/evc_parser: stop exporting delay and gop_size James Almer
@ 2023-06-17 22:00 ` James Almer
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 07/10] avcodec/evc_parser: make ff_evc_parse_nal_unit() local to the parser James Almer
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-17 22:00 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_parse.c | 142 +++++++++++++++++++++--------------------
 libavcodec/evc_parse.h |   5 ++
 2 files changed, 79 insertions(+), 68 deletions(-)

diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c
index 1fe58c8050..262ef5aa39 100644
--- a/libavcodec/evc_parse.c
+++ b/libavcodec/evc_parse.c
@@ -187,6 +187,77 @@ static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *s
     return 0;
 }
 
+int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
+                      EVCParserPoc *poc, enum EVCNALUnitType nalu_type, int tid)
+{
+    const EVCParserPPS *pps = ps->pps[sh->slice_pic_parameter_set_id];
+    const EVCParserSPS *sps;
+
+    if (!pps)
+        return AVERROR_INVALIDDATA;
+
+    sps = ps->sps[pps->pps_seq_parameter_set_id];
+    if (!sps)
+        return AVERROR_INVALIDDATA;
+
+    if (sps->sps_pocs_flag) {
+        int PicOrderCntMsb = 0;
+        poc->prevPicOrderCntVal = poc->PicOrderCntVal;
+
+        if (nalu_type == EVC_IDR_NUT)
+            PicOrderCntMsb = 0;
+        else {
+            int MaxPicOrderCntLsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
+            int prevPicOrderCntLsb = poc->PicOrderCntVal & (MaxPicOrderCntLsb - 1);
+            int prevPicOrderCntMsb = poc->PicOrderCntVal - prevPicOrderCntLsb;
+
+            if ((sh->slice_pic_order_cnt_lsb < prevPicOrderCntLsb) &&
+                ((prevPicOrderCntLsb - sh->slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2)))
+                PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb;
+            else if ((sh->slice_pic_order_cnt_lsb > prevPicOrderCntLsb) &&
+                     ((sh->slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2)))
+                PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb;
+            else
+                PicOrderCntMsb = prevPicOrderCntMsb;
+        }
+        poc->PicOrderCntVal = PicOrderCntMsb + sh->slice_pic_order_cnt_lsb;
+    } else {
+        if (nalu_type == EVC_IDR_NUT) {
+            poc->PicOrderCntVal = 0;
+            poc->DocOffset = -1;
+        } else {
+            int SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length);
+            if (tid == 0) {
+                poc->PicOrderCntVal = poc->prevPicOrderCntVal + SubGopLength;
+                poc->DocOffset = 0;
+                poc->prevPicOrderCntVal = poc->PicOrderCntVal;
+            } else {
+                int ExpectedTemporalId;
+                int PocOffset;
+                int prevDocOffset = poc->DocOffset;
+
+                poc->DocOffset = (prevDocOffset + 1) % SubGopLength;
+                if (poc->DocOffset == 0) {
+                    poc->prevPicOrderCntVal += SubGopLength;
+                    ExpectedTemporalId = 0;
+                } else
+                    ExpectedTemporalId = 1 + (int)log2(poc->DocOffset);
+                while (tid != ExpectedTemporalId) {
+                    poc->DocOffset = (poc->DocOffset + 1) % SubGopLength;
+                    if (poc->DocOffset == 0)
+                        ExpectedTemporalId = 0;
+                    else
+                        ExpectedTemporalId = 1 + (int)log2(poc->DocOffset);
+                }
+                PocOffset = (int)(SubGopLength * ((2.0 * poc->DocOffset + 1) / (int)pow(2.0, tid) - 2));
+                poc->PicOrderCntVal = poc->prevPicOrderCntVal + PocOffset;
+            }
+        }
+    }
+
+    return 0;
+}
+
 int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx)
 {
     int nalu_type, nalu_size;
@@ -299,8 +370,6 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
     case EVC_IDR_NUT:   // Coded slice of a IDR or non-IDR picture
     case EVC_NOIDR_NUT: {
         EVCParserSliceHeader sh;
-        const EVCParserSPS *sps;
-        const EVCParserPPS *pps;
         int ret;
 
         ret = evc_parse_slice_header(ctx, &sh, data, nalu_size);
@@ -331,72 +400,9 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
 
         // POC (picture order count of the current picture) derivation
         // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
-        pps = ctx->ps.pps[sh.slice_pic_parameter_set_id];
-        sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
-        av_assert0(sps && pps);
-
-        if (sps->sps_pocs_flag) {
-
-            int PicOrderCntMsb = 0;
-            ctx->poc.prevPicOrderCntVal = ctx->poc.PicOrderCntVal;
-
-            if (nalu_type == EVC_IDR_NUT)
-                PicOrderCntMsb = 0;
-            else {
-                int MaxPicOrderCntLsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
-
-                int prevPicOrderCntLsb = ctx->poc.PicOrderCntVal & (MaxPicOrderCntLsb - 1);
-                int prevPicOrderCntMsb = ctx->poc.PicOrderCntVal - prevPicOrderCntLsb;
-
-
-                if ((sh.slice_pic_order_cnt_lsb < prevPicOrderCntLsb) &&
-                    ((prevPicOrderCntLsb - sh.slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2)))
-
-                    PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb;
-
-                else if ((sh.slice_pic_order_cnt_lsb > prevPicOrderCntLsb) &&
-                         ((sh.slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2)))
-
-                    PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb;
-
-                else
-                    PicOrderCntMsb = prevPicOrderCntMsb;
-            }
-            ctx->poc.PicOrderCntVal = PicOrderCntMsb + sh.slice_pic_order_cnt_lsb;
-
-        } else {
-            if (nalu_type == EVC_IDR_NUT) {
-                ctx->poc.PicOrderCntVal = 0;
-                ctx->poc.DocOffset = -1;
-            } else {
-                int SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length);
-                if (tid == 0) {
-                    ctx->poc.PicOrderCntVal = ctx->poc.prevPicOrderCntVal + SubGopLength;
-                    ctx->poc.DocOffset = 0;
-                    ctx->poc.prevPicOrderCntVal = ctx->poc.PicOrderCntVal;
-                } else {
-                    int ExpectedTemporalId;
-                    int PocOffset;
-                    int prevDocOffset = ctx->poc.DocOffset;
-
-                    ctx->poc.DocOffset = (prevDocOffset + 1) % SubGopLength;
-                    if (ctx->poc.DocOffset == 0) {
-                        ctx->poc.prevPicOrderCntVal += SubGopLength;
-                        ExpectedTemporalId = 0;
-                    } else
-                        ExpectedTemporalId = 1 + (int)log2(ctx->poc.DocOffset);
-                    while (tid != ExpectedTemporalId) {
-                        ctx->poc.DocOffset = (ctx->poc.DocOffset + 1) % SubGopLength;
-                        if (ctx->poc.DocOffset == 0)
-                            ExpectedTemporalId = 0;
-                        else
-                            ExpectedTemporalId = 1 + (int)log2(ctx->poc.DocOffset);
-                    }
-                    PocOffset = (int)(SubGopLength * ((2.0 * ctx->poc.DocOffset + 1) / (int)pow(2.0, tid) - 2));
-                    ctx->poc.PicOrderCntVal = ctx->poc.prevPicOrderCntVal + PocOffset;
-                }
-            }
-        }
+        ret = ff_evc_derive_poc(&ctx->ps, &sh, &ctx->poc, nalu_type, tid);
+        if (ret < 0)
+            return ret;
 
         ctx->output_picture_number = ctx->poc.PicOrderCntVal;
         ctx->key_frame = (nalu_type == EVC_IDR_NUT) ? 1 : 0;
diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index 2748f8dfbf..97825efcd5 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -159,4 +159,9 @@ int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);
 
 int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx);
 
+// POC (picture order count of the current picture) derivation
+// @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
+int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
+                      EVCParserPoc *poc, enum EVCNALUnitType nalu_type, int tid);
+
 #endif /* AVCODEC_EVC_PARSE_H */
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 07/10] avcodec/evc_parser: make ff_evc_parse_nal_unit() local to the parser
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (4 preceding siblings ...)
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 06/10] avcodec/evc_parse: split off deriving PoC James Almer
@ 2023-06-17 22:00 ` James Almer
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 08/10] avcodec/evc_parser: remove write only variable James Almer
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-17 22:00 UTC (permalink / raw)
  To: ffmpeg-devel

This is in preparation for the following commits.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_parse.c  |  17 +--
 libavcodec/evc_parse.h  |   3 +
 libavcodec/evc_parser.c | 222 ++++++++++++++++++++++++++++++++++------
 3 files changed, 202 insertions(+), 40 deletions(-)

diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c
index 262ef5aa39..0ad0d82137 100644
--- a/libavcodec/evc_parse.c
+++ b/libavcodec/evc_parse.c
@@ -70,11 +70,12 @@ int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx)
 }
 
 // @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
-static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *sh, const uint8_t *bs, int bs_size)
+int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,
+                              enum EVCNALUnitType nalu_type, const uint8_t *bs, int bs_size)
 {
     GetBitContext gb;
-    EVCParserPPS *pps;
-    EVCParserSPS *sps;
+    const EVCParserPPS *pps;
+    const EVCParserSPS *sps;
 
     int num_tiles_in_slice = 0;
     int slice_pic_parameter_set_id;
@@ -88,11 +89,11 @@ static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *s
     if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT)
         return AVERROR_INVALIDDATA;
 
-    pps = ctx->ps.pps[slice_pic_parameter_set_id];
+    pps = ps->pps[slice_pic_parameter_set_id];
     if(!pps)
         return AVERROR_INVALIDDATA;
 
-    sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
+    sps = ps->sps[pps->pps_seq_parameter_set_id];
     if(!sps)
         return AVERROR_INVALIDDATA;
 
@@ -121,7 +122,7 @@ static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *s
 
     sh->slice_type = get_ue_golomb(&gb);
 
-    if (ctx->nalu_type == EVC_IDR_NUT)
+    if (nalu_type == EVC_IDR_NUT)
         sh->no_output_of_prior_pics_flag = get_bits(&gb, 1);
 
     if (sps->sps_mmvd_flag && ((sh->slice_type == EVC_SLICE_TYPE_B) || (sh->slice_type == EVC_SLICE_TYPE_P)))
@@ -175,7 +176,7 @@ static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *s
         }
     }
 
-    if (ctx->nalu_type != EVC_IDR_NUT) {
+    if (nalu_type != EVC_IDR_NUT) {
         if (sps->sps_pocs_flag)
             sh->slice_pic_order_cnt_lsb = get_bits(&gb, sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
     }
@@ -372,7 +373,7 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
         EVCParserSliceHeader sh;
         int ret;
 
-        ret = evc_parse_slice_header(ctx, &sh, data, nalu_size);
+        ret = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, data, nalu_size);
         if (ret < 0) {
             av_log(logctx, AV_LOG_ERROR, "Slice header parsing error\n");
             return ret;
diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index 97825efcd5..f31075ff9c 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -159,6 +159,9 @@ int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);
 
 int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx);
 
+int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,
+                              enum EVCNALUnitType nalu_type, const uint8_t *buf, int buf_size);
+
 // POC (picture order count of the current picture) derivation
 // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
 int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
index 4fd8c49fd4..d22922d1c9 100644
--- a/libavcodec/evc_parser.c
+++ b/libavcodec/evc_parser.c
@@ -25,6 +25,180 @@
 #include "evc.h"
 #include "evc_parse.h"
 
+#define NUM_CHROMA_FORMATS      4   // @see ISO_IEC_23094-1 section 6.2 table 2
+
+static const enum AVPixelFormat pix_fmts_8bit[NUM_CHROMA_FORMATS] = {
+    AV_PIX_FMT_GRAY8, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P
+};
+
+static const enum AVPixelFormat pix_fmts_9bit[NUM_CHROMA_FORMATS] = {
+    AV_PIX_FMT_GRAY9, AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9
+};
+
+static const enum AVPixelFormat pix_fmts_10bit[NUM_CHROMA_FORMATS] = {
+    AV_PIX_FMT_GRAY10, AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10
+};
+
+static const enum AVPixelFormat pix_fmts_12bit[NUM_CHROMA_FORMATS] = {
+    AV_PIX_FMT_GRAY12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12
+};
+
+static const enum AVPixelFormat pix_fmts_14bit[NUM_CHROMA_FORMATS] = {
+    AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14
+};
+
+static const enum AVPixelFormat pix_fmts_16bit[NUM_CHROMA_FORMATS] = {
+    AV_PIX_FMT_GRAY16, AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16
+};
+
+static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
+                          const uint8_t *buf, int buf_size)
+{
+    EVCParserContext *ctx = s->priv_data;
+    int nalu_type, tid;
+
+    if (buf_size <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit size: (%d)\n", buf_size);
+        return AVERROR_INVALIDDATA;
+    }
+
+    // @see ISO_IEC_23094-1_2020, 7.4.2.2 NAL unit header semantic (Table 4 - NAL unit type codes and NAL unit type classes)
+    // @see enum EVCNALUnitType in evc.h
+    nalu_type = evc_get_nalu_type(buf, buf_size, avctx);
+    if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit type: (%d)\n", nalu_type);
+        return AVERROR_INVALIDDATA;
+    }
+
+    tid = ff_evc_get_temporal_id(buf, buf_size, avctx);
+    if (tid < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid temporial id: (%d)\n", tid);
+        return AVERROR_INVALIDDATA;
+    }
+
+    buf += EVC_NALU_HEADER_SIZE;
+    buf_size -= EVC_NALU_HEADER_SIZE;
+
+    switch (nalu_type) {
+    case EVC_SPS_NUT: {
+        EVCParserSPS *sps = ff_evc_parse_sps(&ctx->ps, buf, buf_size);
+        if (!sps) {
+            av_log(avctx, AV_LOG_ERROR, "SPS parsing error\n");
+            return AVERROR_INVALIDDATA;
+        }
+        break;
+    }
+    case EVC_PPS_NUT: {
+        EVCParserPPS *pps = ff_evc_parse_pps(&ctx->ps, buf, buf_size);
+        if (!pps) {
+            av_log(avctx, AV_LOG_ERROR, "PPS parsing error\n");
+            return AVERROR_INVALIDDATA;
+        }
+        break;
+    }
+    case EVC_IDR_NUT:   // Coded slice of a IDR or non-IDR picture
+    case EVC_NOIDR_NUT: {
+        const EVCParserPPS *pps;
+        const EVCParserSPS *sps;
+        EVCParserSliceHeader sh;
+        int bit_depth;
+        int ret;
+
+        ret = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, buf, buf_size);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Slice header parsing error\n");
+            return ret;
+        }
+
+        pps = ctx->ps.pps[sh.slice_pic_parameter_set_id];
+        sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
+        av_assert0(sps && pps);
+
+        s->coded_width  = sps->pic_width_in_luma_samples;
+        s->coded_height = sps->pic_height_in_luma_samples;
+
+        if (sps->picture_cropping_flag) {
+            s->width    = sps->pic_width_in_luma_samples  - sps->picture_crop_left_offset - sps->picture_crop_right_offset;
+            s->height   = sps->pic_height_in_luma_samples - sps->picture_crop_top_offset  - sps->picture_crop_bottom_offset;
+        } else {
+            s->width    = sps->pic_width_in_luma_samples;
+            s->height   = sps->pic_height_in_luma_samples;
+        }
+
+        switch (sh.slice_type) {
+        case EVC_SLICE_TYPE_B: {
+            s->pict_type =  AV_PICTURE_TYPE_B;
+            break;
+        }
+        case EVC_SLICE_TYPE_P: {
+            s->pict_type =  AV_PICTURE_TYPE_P;
+            break;
+        }
+        case EVC_SLICE_TYPE_I: {
+            s->pict_type =  AV_PICTURE_TYPE_I;
+            break;
+        }
+        default: {
+            s->pict_type =  AV_PICTURE_TYPE_NONE;
+        }
+        }
+
+        avctx->profile = sps->profile_idc;
+
+        if (sps->vui_parameters_present_flag && sps->vui_parameters.timing_info_present_flag) {
+            int64_t num = sps->vui_parameters.num_units_in_tick;
+            int64_t den = sps->vui_parameters.time_scale;
+            if (num != 0 && den != 0)
+                av_reduce(&avctx->framerate.den, &avctx->framerate.num, num, den, 1 << 30);
+        } else
+            avctx->framerate = (AVRational) { 0, 1 };
+
+        bit_depth = sps->bit_depth_chroma_minus8 + 8;
+        s->format = AV_PIX_FMT_NONE;
+
+        switch (bit_depth) {
+        case 8:
+            s->format = pix_fmts_8bit[sps->chroma_format_idc];
+            break;
+        case 9:
+            s->format = pix_fmts_9bit[sps->chroma_format_idc];
+            break;
+        case 10:
+            s->format = pix_fmts_10bit[sps->chroma_format_idc];
+            break;
+        case 12:
+            s->format = pix_fmts_12bit[sps->chroma_format_idc];
+            break;
+        case 14:
+            s->format = pix_fmts_14bit[sps->chroma_format_idc];
+            break;
+        case 16:
+            s->format = pix_fmts_16bit[sps->chroma_format_idc];
+            break;
+        }
+
+        s->key_frame = (nalu_type == EVC_IDR_NUT) ? 1 : 0;
+
+        // POC (picture order count of the current picture) derivation
+        // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
+        ret = ff_evc_derive_poc(&ctx->ps, &sh, &ctx->poc, nalu_type, tid);
+        if (ret < 0)
+            return ret;
+
+        s->output_picture_number = ctx->poc.PicOrderCntVal;
+
+        break;
+    }
+    case EVC_SEI_NUT:   // Supplemental Enhancement Information
+    case EVC_APS_NUT:   // Adaptation parameter set
+    case EVC_FD_NUT:    // Filler data
+    default:
+        break;
+    }
+
+    return 0;
+}
+
 /**
  * Parse NAL units of found picture and decode some basic information.
  *
@@ -35,13 +209,13 @@
  */
 static int parse_nal_units(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t *buf, int buf_size)
 {
-    EVCParserContext *ctx = s->priv_data;
     const uint8_t *data = buf;
     int data_size = buf_size;
     int bytes_read = 0;
-    int nalu_size = 0;
 
     while (data_size > 0) {
+        int nalu_size = 0;
+        int ret;
 
         // Buffer size is not enough for buffer to store NAL unit 4-bytes prefix (length)
         if (data_size < EVC_NALU_LENGTH_PREFIX_SIZE)
@@ -57,31 +231,12 @@ static int parse_nal_units(AVCodecParserContext *s, AVCodecContext *avctx, const
         if (data_size < nalu_size)
             return AVERROR_INVALIDDATA;
 
-        if (ff_evc_parse_nal_unit(ctx, data, nalu_size, avctx) != 0) {
+        ret = parse_nal_unit(s, avctx, data, nalu_size);
+        if (ret < 0) {
             av_log(avctx, AV_LOG_ERROR, "Parsing of NAL unit failed\n");
             return AVERROR_INVALIDDATA;
         }
 
-        if(ctx->nalu_type == EVC_SPS_NUT) {
-
-            s->coded_width         = ctx->coded_width;
-            s->coded_height        = ctx->coded_height;
-            s->width               = ctx->width;
-            s->height              = ctx->height;
-
-            s->format              = ctx->format;
-
-            avctx->framerate       = ctx->framerate;
-            avctx->profile         = ctx->profile;
-
-        } else if(ctx->nalu_type == EVC_NOIDR_NUT || ctx->nalu_type == EVC_IDR_NUT) {
-
-            s->pict_type = ctx->pict_type;
-            s->key_frame = ctx->key_frame;
-            s->output_picture_number = ctx->output_picture_number;
-
-        }
-
         data += nalu_size;
         data_size -= nalu_size;
     }
@@ -90,8 +245,10 @@ static int parse_nal_units(AVCodecParserContext *s, AVCodecContext *avctx, const
 
 // Decoding nal units from evcC (EVCDecoderConfigurationRecord)
 // @see @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.2
-static int decode_extradata(EVCParserContext *ctx, const uint8_t *data, int size, void *logctx)
+static int decode_extradata(AVCodecParserContext *s, AVCodecContext *avctx)
 {
+    const uint8_t *data = avctx->extradata;
+    int size = avctx->extradata_size;
     int ret = 0;
     GetByteContext gb;
 
@@ -108,7 +265,7 @@ static int decode_extradata(EVCParserContext *ctx, const uint8_t *data, int size
         // The value of this field shall be one of 0, 1, or 3 corresponding to a length encoded with 1, 2, or 4 bytes, respectively.
 
         if (bytestream2_get_bytes_left(&gb) < 18) {
-            av_log(logctx, AV_LOG_ERROR, "evcC %d too short\n", size);
+            av_log(avctx, AV_LOG_ERROR, "evcC %d too short\n", size);
             return AVERROR_INVALIDDATA;
         }
 
@@ -121,7 +278,7 @@ static int decode_extradata(EVCParserContext *ctx, const uint8_t *data, int size
         if( nalu_length_field_size != 1 &&
             nalu_length_field_size != 2 &&
             nalu_length_field_size != 4 ) {
-            av_log(logctx, AV_LOG_ERROR, "The length in bytes of the NALUnitLenght field in a EVC video stream has unsupported value of %d\n", nalu_length_field_size);
+            av_log(avctx, AV_LOG_ERROR, "The length in bytes of the NALUnitLenght field in a EVC video stream has unsupported value of %d\n", nalu_length_field_size);
             return AVERROR_INVALIDDATA;
         }
 
@@ -142,7 +299,7 @@ static int decode_extradata(EVCParserContext *ctx, const uint8_t *data, int size
                 int nal_unit_length = bytestream2_get_be16(&gb);
 
                 if (bytestream2_get_bytes_left(&gb) < nal_unit_length) {
-                    av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit size in extradata.\n");
+                    av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit size in extradata.\n");
                     return AVERROR_INVALIDDATA;
                 }
 
@@ -150,8 +307,8 @@ static int decode_extradata(EVCParserContext *ctx, const uint8_t *data, int size
                     nal_unit_type == EVC_PPS_NUT ||
                     nal_unit_type == EVC_APS_NUT ||
                     nal_unit_type == EVC_SEI_NUT ) {
-                    if (ff_evc_parse_nal_unit(ctx, gb.buffer, nal_unit_length, logctx) != 0) {
-                        av_log(logctx, AV_LOG_ERROR, "Parsing of NAL unit failed\n");
+                    if (parse_nal_unit(s, avctx, gb.buffer, nal_unit_length) != 0) {
+                        av_log(avctx, AV_LOG_ERROR, "Parsing of NAL unit failed\n");
                         return AVERROR_INVALIDDATA;
                     }
                 }
@@ -173,8 +330,11 @@ static int evc_parse(AVCodecParserContext *s, AVCodecContext *avctx,
     int ret;
     EVCParserContext *ctx = s->priv_data;
 
+    s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
+    s->key_frame = 0;
+
     if (avctx->extradata && !ctx->parsed_extradata) {
-        decode_extradata(ctx, avctx->extradata, avctx->extradata_size, avctx);
+        decode_extradata(s, avctx);
         ctx->parsed_extradata = 1;
     }
 
@@ -187,8 +347,6 @@ static int evc_parse(AVCodecParserContext *s, AVCodecContext *avctx,
         return buf_size;
     }
 
-    s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
-
     // poutbuf contains just one Access Unit
     *poutbuf      = buf;
     *poutbuf_size = buf_size;
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 08/10] avcodec/evc_parser: remove write only variable
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (5 preceding siblings ...)
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 07/10] avcodec/evc_parser: make ff_evc_parse_nal_unit() local to the parser James Almer
@ 2023-06-17 22:00 ` James Almer
  2023-06-18 12:04   ` Paul B Mahol
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 09/10] avcodec/evc_frame_merge_bsf: make ff_evc_parse_nal_unit() local to the filter James Almer
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 25+ messages in thread
From: James Almer @ 2023-06-17 22:00 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_parser.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
index d22922d1c9..c30da6846e 100644
--- a/libavcodec/evc_parser.c
+++ b/libavcodec/evc_parser.c
@@ -211,7 +211,6 @@ static int parse_nal_units(AVCodecParserContext *s, AVCodecContext *avctx, const
 {
     const uint8_t *data = buf;
     int data_size = buf_size;
-    int bytes_read = 0;
 
     while (data_size > 0) {
         int nalu_size = 0;
@@ -223,7 +222,6 @@ static int parse_nal_units(AVCodecParserContext *s, AVCodecContext *avctx, const
 
         nalu_size = evc_read_nal_unit_length(data, data_size, avctx);
 
-        bytes_read += EVC_NALU_LENGTH_PREFIX_SIZE;
 
         data += EVC_NALU_LENGTH_PREFIX_SIZE;
         data_size -= EVC_NALU_LENGTH_PREFIX_SIZE;
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 09/10] avcodec/evc_frame_merge_bsf: make ff_evc_parse_nal_unit() local to the filter
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (6 preceding siblings ...)
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 08/10] avcodec/evc_parser: remove write only variable James Almer
@ 2023-06-17 22:00 ` James Almer
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 10/10] avcodec/evc_parse: remove ff_evc_parse_nal_unit() James Almer
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-17 22:00 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_frame_merge_bsf.c | 114 +++++++++++++++++++++++++------
 1 file changed, 92 insertions(+), 22 deletions(-)

diff --git a/libavcodec/evc_frame_merge_bsf.c b/libavcodec/evc_frame_merge_bsf.c
index f497780afb..817136a551 100644
--- a/libavcodec/evc_frame_merge_bsf.c
+++ b/libavcodec/evc_frame_merge_bsf.c
@@ -35,20 +35,27 @@ typedef struct AccessUnitBuffer {
 
 typedef struct EVCFMergeContext {
     AVPacket *in;
-    EVCParserContext parser_ctx;
+    EVCParamSets ps;
+    EVCParserPoc poc;
     AccessUnitBuffer au_buffer;
 } EVCFMergeContext;
 
-static int end_of_access_unit_found(EVCParserContext *parser_ctx)
+static int end_of_access_unit_found(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
+                                    const EVCParserPoc *poc, enum EVCNALUnitType nalu_type)
 {
-    if (parser_ctx->profile == 0) { // BASELINE profile
-        if (parser_ctx->nalu_type == EVC_NOIDR_NUT || parser_ctx->nalu_type == EVC_IDR_NUT)
+    EVCParserPPS *pps = ps->pps[sh->slice_pic_parameter_set_id];
+    EVCParserSPS *sps = ps->sps[pps->pps_seq_parameter_set_id];
+
+    av_assert0(sps && pps);
+
+    if (sps->profile_idc == 0) { // BASELINE profile
+        if (nalu_type == EVC_NOIDR_NUT || nalu_type == EVC_IDR_NUT)
             return 1;
     } else { // MAIN profile
-        if (parser_ctx->nalu_type == EVC_NOIDR_NUT) {
-            if (parser_ctx->poc.PicOrderCntVal != parser_ctx->poc.prevPicOrderCntVal)
+        if (nalu_type == EVC_NOIDR_NUT) {
+            if (poc->PicOrderCntVal != poc->prevPicOrderCntVal)
                 return 1;
-        } else if (parser_ctx->nalu_type == EVC_IDR_NUT)
+        } else if (nalu_type == EVC_IDR_NUT)
             return 1;
     }
     return 0;
@@ -58,7 +65,7 @@ static void evc_frame_merge_flush(AVBSFContext *bsf)
 {
     EVCFMergeContext *ctx = bsf->priv_data;
 
-    ff_evc_ps_free(&ctx->parser_ctx.ps);
+    ff_evc_ps_free(&ctx->ps);
     av_packet_unref(ctx->in);
     ctx->au_buffer.data_size = 0;
 }
@@ -66,12 +73,10 @@ static void evc_frame_merge_flush(AVBSFContext *bsf)
 static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
 {
     EVCFMergeContext *ctx = bsf->priv_data;
-    EVCParserContext *parser_ctx = &ctx->parser_ctx;
-
     AVPacket *in = ctx->in;
-
-    size_t  nalu_size = 0;
     uint8_t *buffer, *nalu = NULL;
+    enum EVCNALUnitType nalu_type;
+    int tid, nalu_size = 0;
     int au_end_found = 0;
     int err;
 
@@ -81,29 +86,91 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
 
     nalu_size = evc_read_nal_unit_length(in->data, EVC_NALU_LENGTH_PREFIX_SIZE, bsf);
     if (nalu_size <= 0) {
-        av_packet_unref(in);
-        return AVERROR_INVALIDDATA;
+        err = AVERROR_INVALIDDATA;
+        goto end;
     }
 
     nalu = in->data + EVC_NALU_LENGTH_PREFIX_SIZE;
     nalu_size = in->size - EVC_NALU_LENGTH_PREFIX_SIZE;
 
     // NAL unit parsing needed to determine if end of AU was found
-    err = ff_evc_parse_nal_unit(parser_ctx, nalu, nalu_size, bsf);
-    if (err < 0) {
-        av_log(bsf, AV_LOG_ERROR, "NAL Unit parsing error\n");
-        av_packet_unref(in);
+    if (nalu_size <= 0) {
+        av_log(bsf, AV_LOG_ERROR, "Invalid NAL unit size: (%d)\n", nalu_size);
+        err = AVERROR_INVALIDDATA;
+        goto end;
+    }
 
-        return err;
+    // @see ISO_IEC_23094-1_2020, 7.4.2.2 NAL unit header semantic (Table 4 - NAL unit type codes and NAL unit type classes)
+    // @see enum EVCNALUnitType in evc.h
+    nalu_type = evc_get_nalu_type(nalu, nalu_size, bsf);
+    if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) {
+        av_log(bsf, AV_LOG_ERROR, "Invalid NAL unit type: (%d)\n", nalu_type);
+        err = AVERROR_INVALIDDATA;
+        goto end;
     }
 
-    au_end_found = end_of_access_unit_found(parser_ctx);
+    tid = ff_evc_get_temporal_id(nalu, nalu_size, bsf);
+    if (tid < 0) {
+        av_log(bsf, AV_LOG_ERROR, "Invalid temporial id: (%d)\n", tid);
+        err = AVERROR_INVALIDDATA;
+        goto end;
+    }
+
+    nalu += EVC_NALU_HEADER_SIZE;
+    nalu_size -= EVC_NALU_HEADER_SIZE;
+
+    switch (nalu_type) {
+    case EVC_SPS_NUT: {
+        EVCParserSPS *sps = ff_evc_parse_sps(&ctx->ps, nalu, nalu_size);
+        if (!sps) {
+            av_log(bsf, AV_LOG_ERROR, "SPS parsing error\n");
+            err = AVERROR_INVALIDDATA;
+            goto end;
+        }
+        break;
+    }
+    case EVC_PPS_NUT: {
+        EVCParserPPS *pps = ff_evc_parse_pps(&ctx->ps, nalu, nalu_size);
+        if (!pps) {
+            av_log(bsf, AV_LOG_ERROR, "PPS parsing error\n");
+            err = AVERROR_INVALIDDATA;
+            goto end;
+        }
+        break;
+    }
+    case EVC_IDR_NUT:   // Coded slice of a IDR or non-IDR picture
+    case EVC_NOIDR_NUT: {
+        EVCParserSliceHeader sh;
+
+        err = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, nalu, nalu_size);
+        if (err < 0) {
+            av_log(bsf, AV_LOG_ERROR, "Slice header parsing error\n");
+            goto end;
+        }
+
+        // POC (picture order count of the current picture) derivation
+        // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
+        err = ff_evc_derive_poc(&ctx->ps, &sh, &ctx->poc, nalu_type, tid);
+        if (err < 0)
+            goto end;
+
+        au_end_found = end_of_access_unit_found(&ctx->ps, &sh, &ctx->poc, nalu_type);
+
+        break;
+    }
+    case EVC_SEI_NUT:   // Supplemental Enhancement Information
+    case EVC_APS_NUT:   // Adaptation parameter set
+    case EVC_FD_NUT:    // Filler data
+    default:
+        break;
+    }
 
     buffer = av_fast_realloc(ctx->au_buffer.data, &ctx->au_buffer.capacity,
                              ctx->au_buffer.data_size + in->size);
     if (!buffer) {
         av_freep(&ctx->au_buffer.data);
-        return AVERROR(ENOMEM);
+        err = AVERROR_INVALIDDATA;
+        goto end;
     }
 
     ctx->au_buffer.data = buffer;
@@ -128,6 +195,9 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
     if (err < 0 && err != AVERROR(EAGAIN))
         ctx->au_buffer.data_size = 0;
 
+end:
+    if (err < 0)
+        av_packet_unref(in);
     return err;
 }
 
@@ -147,7 +217,7 @@ static void evc_frame_merge_close(AVBSFContext *bsf)
     EVCFMergeContext *ctx = bsf->priv_data;
 
     av_packet_free(&ctx->in);
-    ff_evc_ps_free(&ctx->parser_ctx.ps);
+    ff_evc_ps_free(&ctx->ps);
 
     ctx->au_buffer.capacity = 0;
     av_freep(&ctx->au_buffer.data);
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 10/10] avcodec/evc_parse: remove ff_evc_parse_nal_unit()
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (7 preceding siblings ...)
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 09/10] avcodec/evc_frame_merge_bsf: make ff_evc_parse_nal_unit() local to the filter James Almer
@ 2023-06-17 22:00 ` James Almer
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 11/17] avformat/evc: don't use an AVIOContext as log context James Almer
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-17 22:00 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_parse.c  | 156 ----------------------------------------
 libavcodec/evc_parse.h  |  42 -----------
 libavcodec/evc_parser.c |   7 ++
 3 files changed, 7 insertions(+), 198 deletions(-)

diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c
index 0ad0d82137..48bd3ce5e9 100644
--- a/libavcodec/evc_parse.c
+++ b/libavcodec/evc_parse.c
@@ -258,159 +258,3 @@ int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
 
     return 0;
 }
-
-int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx)
-{
-    int nalu_type, nalu_size;
-    int tid;
-    const uint8_t *data = buf;
-    int data_size = buf_size;
-
-    // ctx->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
-    ctx->key_frame = -1;
-
-    nalu_size = buf_size;
-    if (nalu_size <= 0) {
-        av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit size: (%d)\n", nalu_size);
-        return AVERROR_INVALIDDATA;
-    }
-
-    // @see ISO_IEC_23094-1_2020, 7.4.2.2 NAL unit header semantic (Table 4 - NAL unit type codes and NAL unit type classes)
-    // @see enum EVCNALUnitType in evc.h
-    nalu_type = evc_get_nalu_type(data, data_size, logctx);
-    if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) {
-        av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit type: (%d)\n", nalu_type);
-        return AVERROR_INVALIDDATA;
-    }
-    ctx->nalu_type = nalu_type;
-
-    tid = ff_evc_get_temporal_id(data, data_size, logctx);
-    if (tid < 0) {
-        av_log(logctx, AV_LOG_ERROR, "Invalid temporial id: (%d)\n", tid);
-        return AVERROR_INVALIDDATA;
-    }
-    ctx->nuh_temporal_id = tid;
-
-    data += EVC_NALU_HEADER_SIZE;
-    data_size -= EVC_NALU_HEADER_SIZE;
-
-    switch(nalu_type) {
-    case EVC_SPS_NUT: {
-        EVCParserSPS *sps;
-        int bit_depth;
-
-        sps = ff_evc_parse_sps(&ctx->ps, data, nalu_size);
-        if (!sps) {
-            av_log(logctx, AV_LOG_ERROR, "SPS parsing error\n");
-            return AVERROR_INVALIDDATA;
-        }
-
-        ctx->coded_width         = sps->pic_width_in_luma_samples;
-        ctx->coded_height        = sps->pic_height_in_luma_samples;
-
-        if(sps->picture_cropping_flag) {
-            ctx->width           = sps->pic_width_in_luma_samples  - sps->picture_crop_left_offset - sps->picture_crop_right_offset;
-            ctx->height          = sps->pic_height_in_luma_samples - sps->picture_crop_top_offset  - sps->picture_crop_bottom_offset;
-        } else {
-            ctx->width           = sps->pic_width_in_luma_samples;
-            ctx->height          = sps->pic_height_in_luma_samples;
-        }
-
-        if (sps->profile_idc == 1) ctx->profile = FF_PROFILE_EVC_MAIN;
-        else ctx->profile = FF_PROFILE_EVC_BASELINE;
-
-        if (sps->vui_parameters_present_flag && sps->vui_parameters.timing_info_present_flag) {
-            int64_t num = sps->vui_parameters.num_units_in_tick;
-            int64_t den = sps->vui_parameters.time_scale;
-            if (num != 0 && den != 0)
-                av_reduce(&ctx->framerate.den, &ctx->framerate.num, num, den, 1 << 30);
-        } else
-            ctx->framerate = (AVRational) { 0, 1 };
-
-        bit_depth = sps->bit_depth_chroma_minus8 + 8;
-        ctx->format = AV_PIX_FMT_NONE;
-
-        switch (bit_depth) {
-        case 8:
-            ctx->format = pix_fmts_8bit[sps->chroma_format_idc];
-            break;
-        case 9:
-            ctx->format = pix_fmts_9bit[sps->chroma_format_idc];
-            break;
-        case 10:
-            ctx->format = pix_fmts_10bit[sps->chroma_format_idc];
-            break;
-        case 12:
-            ctx->format = pix_fmts_12bit[sps->chroma_format_idc];
-            break;
-        case 14:
-            ctx->format = pix_fmts_14bit[sps->chroma_format_idc];
-            break;
-        case 16:
-            ctx->format = pix_fmts_16bit[sps->chroma_format_idc];
-            break;
-        }
-        av_assert0(ctx->format != AV_PIX_FMT_NONE);
-
-        break;
-    }
-    case EVC_PPS_NUT: {
-        EVCParserPPS *pps;
-
-        pps = ff_evc_parse_pps(&ctx->ps, data, nalu_size);
-        if (!pps) {
-            av_log(logctx, AV_LOG_ERROR, "PPS parsing error\n");
-            return AVERROR_INVALIDDATA;
-        }
-        break;
-    }
-    case EVC_SEI_NUT:   // Supplemental Enhancement Information
-    case EVC_APS_NUT:   // Adaptation parameter set
-    case EVC_FD_NUT:    // Filler data
-        break;
-    case EVC_IDR_NUT:   // Coded slice of a IDR or non-IDR picture
-    case EVC_NOIDR_NUT: {
-        EVCParserSliceHeader sh;
-        int ret;
-
-        ret = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, data, nalu_size);
-        if (ret < 0) {
-            av_log(logctx, AV_LOG_ERROR, "Slice header parsing error\n");
-            return ret;
-        }
-
-        switch (sh.slice_type) {
-        case EVC_SLICE_TYPE_B: {
-            ctx->pict_type =  AV_PICTURE_TYPE_B;
-            break;
-        }
-        case EVC_SLICE_TYPE_P: {
-            ctx->pict_type =  AV_PICTURE_TYPE_P;
-            break;
-        }
-        case EVC_SLICE_TYPE_I: {
-            ctx->pict_type =  AV_PICTURE_TYPE_I;
-            break;
-        }
-        default: {
-            ctx->pict_type =  AV_PICTURE_TYPE_NONE;
-        }
-        }
-
-        ctx->key_frame = (nalu_type == EVC_IDR_NUT) ? 1 : 0;
-
-        // POC (picture order count of the current picture) derivation
-        // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
-        ret = ff_evc_derive_poc(&ctx->ps, &sh, &ctx->poc, nalu_type, tid);
-        if (ret < 0)
-            return ret;
-
-        ctx->output_picture_number = ctx->poc.PicOrderCntVal;
-        ctx->key_frame = (nalu_type == EVC_IDR_NUT) ? 1 : 0;
-
-        break;
-    }
-    }
-
-    return 0;
-}
diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index f31075ff9c..a1fbbc643d 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -81,46 +81,6 @@ typedef struct EVCParserPoc {
     int DocOffset;          // the decoding order count of the previous picture
 } EVCParserPoc;
 
-typedef struct EVCParserContext {
-    EVCParamSets ps;
-    EVCParserPoc poc;
-
-    int nuh_temporal_id;            // the value of TemporalId (shall be the same for all VCL NAL units of an Access Unit)
-    int nalu_type;                  // the current NALU type
-
-    // Dimensions of the decoded video intended for presentation.
-    int width;
-    int height;
-
-    // Dimensions of the coded video.
-    int coded_width;
-    int coded_height;
-
-    // The format of the coded data, corresponds to enum AVPixelFormat
-    int format;
-
-    // AV_PICTURE_TYPE_I, EVC_SLICE_TYPE_P, AV_PICTURE_TYPE_B
-    int pict_type;
-
-    // Set by parser to 1 for key frames and 0 for non-key frames
-    int key_frame;
-
-    // Picture number incremented in presentation or output order.
-    // This corresponds to EVCEVCParserPoc::PicOrderCntVal
-    int output_picture_number;
-
-    // profile
-    // 0: FF_PROFILE_EVC_BASELINE
-    // 1: FF_PROFILE_EVC_MAIN
-    int profile;
-
-    // Framerate value in the compressed bitstream
-    AVRational framerate;
-
-    int parsed_extradata;
-
-} EVCParserContext;
-
 static inline int evc_get_nalu_type(const uint8_t *bits, int bits_size, void *logctx)
 {
     int unit_type_plus1 = 0;
@@ -157,8 +117,6 @@ static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_si
 // nuh_temporal_id specifies a temporal identifier for the NAL unit
 int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);
 
-int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx);
-
 int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,
                               enum EVCNALUnitType nalu_type, const uint8_t *buf, int buf_size);
 
diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
index c30da6846e..710fabccb2 100644
--- a/libavcodec/evc_parser.c
+++ b/libavcodec/evc_parser.c
@@ -25,6 +25,13 @@
 #include "evc.h"
 #include "evc_parse.h"
 
+typedef struct EVCParserContext {
+    EVCParamSets ps;
+    EVCParserPoc poc;
+
+    int parsed_extradata;
+} EVCParserContext;
+
 #define NUM_CHROMA_FORMATS      4   // @see ISO_IEC_23094-1 section 6.2 table 2
 
 static const enum AVPixelFormat pix_fmts_8bit[NUM_CHROMA_FORMATS] = {
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [FFmpeg-devel] [PATCH 08/10] avcodec/evc_parser: remove write only variable
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 08/10] avcodec/evc_parser: remove write only variable James Almer
@ 2023-06-18 12:04   ` Paul B Mahol
  0 siblings, 0 replies; 25+ messages in thread
From: Paul B Mahol @ 2023-06-18 12:04 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

lgtm
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 11/17] avformat/evc: don't use an AVIOContext as log context
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (8 preceding siblings ...)
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 10/10] avcodec/evc_parse: remove ff_evc_parse_nal_unit() James Almer
@ 2023-06-18 23:43 ` James Almer
  2023-06-19 21:11   ` [FFmpeg-devel] [PATCH 11/17 v2] " James Almer
  2023-06-20 14:38   ` [FFmpeg-devel] [PATCH 11/17] " James Almer
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 12/17] avformat/evcdec: deduplicate nalu length and type parsing functions James Almer
                   ` (6 subsequent siblings)
  16 siblings, 2 replies; 25+ messages in thread
From: James Almer @ 2023-06-18 23:43 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_parse.h | 3 ++-
 libavformat/evc.c      | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index a1fbbc643d..677e01a64a 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -105,7 +105,8 @@ static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_si
     uint32_t nalu_len = 0;
 
     if (bits_size < EVC_NALU_LENGTH_PREFIX_SIZE) {
-        av_log(logctx, AV_LOG_ERROR, "Can't read NAL unit length\n");
+        if (logctx) // Don't log without a context
+            av_log(logctx, AV_LOG_ERROR, "Can't read NAL unit length\n");
         return 0;
     }
 
diff --git a/libavformat/evc.c b/libavformat/evc.c
index dc75ccb56d..a7cc6167e8 100644
--- a/libavformat/evc.c
+++ b/libavformat/evc.c
@@ -359,7 +359,7 @@ int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data,
     evcc_init(&evcc);
 
     while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) {
-        nalu_size = evc_read_nal_unit_length(data, EVC_NALU_LENGTH_PREFIX_SIZE, pb);
+        nalu_size = evc_read_nal_unit_length(data, EVC_NALU_LENGTH_PREFIX_SIZE, NULL);
         if (nalu_size == 0) break;
 
         data += EVC_NALU_LENGTH_PREFIX_SIZE;
@@ -367,7 +367,7 @@ int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data,
 
         if (bytes_to_read < nalu_size) break;
 
-        nalu_type = evc_get_nalu_type(data, bytes_to_read, pb);
+        nalu_type = evc_get_nalu_type(data, bytes_to_read, NULL);
 
         // @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.3
         // NAL_unit_type indicates the type of the NAL units in the following array (which shall be all of that type);
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 12/17] avformat/evcdec: deduplicate nalu length and type parsing functions
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (9 preceding siblings ...)
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 11/17] avformat/evc: don't use an AVIOContext as log context James Almer
@ 2023-06-18 23:43 ` James Almer
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 13/17] avformat/evcdec: simplify probe function James Almer
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-18 23:43 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/evcdec.c | 46 ++++----------------------------------------
 1 file changed, 4 insertions(+), 42 deletions(-)

diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 807406885a..0f17edd371 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -20,10 +20,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavcodec/get_bits.h"
-#include "libavcodec/golomb.h"
 #include "libavcodec/internal.h"
 #include "libavcodec/evc.h"
+#include "libavcodec/evc_parse.h"
 #include "libavcodec/bsf.h"
 
 #include "libavutil/opt.h"
@@ -66,43 +65,6 @@ static const AVClass evc_demuxer_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-static int get_nalu_type(const uint8_t *bits, int bits_size)
-{
-    int unit_type_plus1 = 0;
-
-    if (bits_size >= EVC_NALU_HEADER_SIZE) {
-        unsigned char *p = (unsigned char *)bits;
-        // forbidden_zero_bit
-        if ((p[0] & 0x80) != 0)   // Cannot get bitstream information. Malformed bitstream.
-            return -1;
-
-        // nal_unit_type
-        unit_type_plus1 = (p[0] >> 1) & 0x3F;
-    }
-
-    return unit_type_plus1 - 1;
-}
-
-static uint32_t read_nal_unit_length(const uint8_t *bits, int bits_size)
-{
-    uint32_t nalu_len = 0;
-
-    if (bits_size >= EVC_NALU_LENGTH_PREFIX_SIZE) {
-
-        int t = 0;
-        unsigned char *p = (unsigned char *)bits;
-
-        for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++)
-            t = (t << 8) | p[i];
-
-        nalu_len = t;
-        if (nalu_len == 0)   // Invalid bitstream size
-            return 0;
-    }
-
-    return nalu_len;
-}
-
 static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
 {
     int nalu_type;
@@ -112,7 +74,7 @@ static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
 
     while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) {
 
-        nalu_size = read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE);
+        nalu_size = evc_read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE, NULL);
         if (nalu_size == 0) break;
 
         bits += EVC_NALU_LENGTH_PREFIX_SIZE;
@@ -120,7 +82,7 @@ static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
 
         if(bytes_to_read < nalu_size) break;
 
-        nalu_type = get_nalu_type(bits, bytes_to_read);
+        nalu_type = evc_get_nalu_type(bits, bytes_to_read, NULL);
 
         if (nalu_type == EVC_SPS_NUT)
             ev->got_sps++;
@@ -218,7 +180,7 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
             return ret;
         }
 
-        nalu_size = read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
+        nalu_size = evc_read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE, s);
         if(nalu_size <= 0) {
             av_packet_unref(pkt);
             return -1;
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 13/17] avformat/evcdec: simplify probe function
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (10 preceding siblings ...)
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 12/17] avformat/evcdec: deduplicate nalu length and type parsing functions James Almer
@ 2023-06-18 23:43 ` James Almer
  2023-06-19 20:29   ` Michael Niedermayer
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 14/17] avformat/evcdec: simplify au_end_found check James Almer
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 25+ messages in thread
From: James Almer @ 2023-06-18 23:43 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/evcdec.c | 29 +++++++----------------------
 1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 0f17edd371..7a783e9809 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -34,14 +34,6 @@
 
 #define RAW_PACKET_SIZE 1024
 
-typedef struct EVCParserContext {
-    int got_sps;
-    int got_pps;
-    int got_idr;
-    int got_nonidr;
-
-} EVCParserContext;
-
 typedef struct EVCDemuxContext {
     const AVClass *class;
     AVRational framerate;
@@ -65,10 +57,11 @@ static const AVClass evc_demuxer_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
+static int annexb_probe(const AVProbeData *p)
 {
     int nalu_type;
     size_t nalu_size;
+    int got_sps = 0, got_pps = 0, got_idr = 0, got_nonidr = 0;
     unsigned char *bits = (unsigned char *)p->buf;
     int bytes_to_read = p->buf_size;
 
@@ -85,27 +78,19 @@ static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
         nalu_type = evc_get_nalu_type(bits, bytes_to_read, NULL);
 
         if (nalu_type == EVC_SPS_NUT)
-            ev->got_sps++;
+            got_sps++;
         else if (nalu_type == EVC_PPS_NUT)
-            ev->got_pps++;
+            got_pps++;
         else if (nalu_type == EVC_IDR_NUT )
-            ev->got_idr++;
+            got_idr++;
         else if (nalu_type == EVC_NOIDR_NUT)
-            ev->got_nonidr++;
+            got_nonidr++;
 
         bits += nalu_size;
         bytes_to_read -= nalu_size;
     }
 
-    return 0;
-}
-
-static int annexb_probe(const AVProbeData *p)
-{
-    EVCParserContext ev = {0};
-    int ret = parse_nal_units(p, &ev);
-
-    if (ret == 0 && ev.got_sps && ev.got_pps && (ev.got_idr || ev.got_nonidr > 3))
+    if (got_sps && got_pps && (got_idr || got_nonidr > 3))
         return AVPROBE_SCORE_EXTENSION + 1;  // 1 more than .mpg
 
     return 0;
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 14/17] avformat/evcdec: simplify au_end_found check
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (11 preceding siblings ...)
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 13/17] avformat/evcdec: simplify probe function James Almer
@ 2023-06-18 23:43 ` James Almer
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 15/17] avformat/evcdec: don't set AVCodecParameters.framerate James Almer
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-18 23:43 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/evcdec.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 7a783e9809..a3a41cb4a5 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -144,7 +144,7 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int ret;
     int32_t nalu_size;
-    int au_end_found;
+    int au_end_found = 0;
 
     EVCDemuxContext *const c = s->priv_data;
 
@@ -154,8 +154,6 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
         return AVERROR_EOF;
     }
 
-    au_end_found = 0;
-
     while(!au_end_found) {
 
         uint8_t buf[EVC_NALU_LENGTH_PREFIX_SIZE];
@@ -191,9 +189,8 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
             av_log(s, AV_LOG_ERROR, "evc_frame_merge filter failed to "
                    "send output packet\n");
 
-        au_end_found = 1;
-        if (ret == AVERROR(EAGAIN))
-            au_end_found = 0;
+        if (ret != AVERROR(EAGAIN))
+            au_end_found = 1;
     }
 
     return ret;
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 15/17] avformat/evcdec: don't set AVCodecParameters.framerate
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (12 preceding siblings ...)
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 14/17] avformat/evcdec: simplify au_end_found check James Almer
@ 2023-06-18 23:43 ` James Almer
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 16/17] avcodec/evc_ps: make ff_evc_parse_{sps, pps} return an error code James Almer
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-18 23:43 UTC (permalink / raw)
  To: ffmpeg-devel

It's not necessary. Setting AVStream.avg_frame_rate is enough.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/evcdec.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index a3a41cb4a5..3cadbc1530 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -119,7 +119,6 @@ static int evc_read_header(AVFormatContext *s)
     sti->need_parsing = AVSTREAM_PARSE_HEADERS;
 
     st->avg_frame_rate = c->framerate;
-    st->codecpar->framerate = c->framerate;
 
     // taken from rawvideo demuxers
     avpriv_set_pts_info(st, 64, 1, 1200000);
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 16/17] avcodec/evc_ps: make ff_evc_parse_{sps, pps} return an error code
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (13 preceding siblings ...)
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 15/17] avformat/evcdec: don't set AVCodecParameters.framerate James Almer
@ 2023-06-18 23:43 ` James Almer
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 17/17] avcodec/evc_ps: Check log2_sub_gop_length James Almer
  2023-06-19 18:28 ` [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-18 23:43 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_frame_merge_bsf.c | 17 +++++-----
 libavcodec/evc_parser.c          | 18 +++++------
 libavcodec/evc_ps.c              | 54 ++++++++++++++++++--------------
 libavcodec/evc_ps.h              |  4 +--
 4 files changed, 48 insertions(+), 45 deletions(-)

diff --git a/libavcodec/evc_frame_merge_bsf.c b/libavcodec/evc_frame_merge_bsf.c
index 817136a551..e9f549eb71 100644
--- a/libavcodec/evc_frame_merge_bsf.c
+++ b/libavcodec/evc_frame_merge_bsf.c
@@ -120,24 +120,21 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
     nalu_size -= EVC_NALU_HEADER_SIZE;
 
     switch (nalu_type) {
-    case EVC_SPS_NUT: {
-        EVCParserSPS *sps = ff_evc_parse_sps(&ctx->ps, nalu, nalu_size);
-        if (!sps) {
+    case EVC_SPS_NUT:
+        err = ff_evc_parse_sps(&ctx->ps, nalu, nalu_size);
+        if (err < 0) {
             av_log(bsf, AV_LOG_ERROR, "SPS parsing error\n");
-            err = AVERROR_INVALIDDATA;
             goto end;
         }
         break;
-    }
-    case EVC_PPS_NUT: {
-        EVCParserPPS *pps = ff_evc_parse_pps(&ctx->ps, nalu, nalu_size);
-        if (!pps) {
+    case EVC_PPS_NUT:
+        err = ff_evc_parse_pps(&ctx->ps, nalu, nalu_size);
+        if (err < 0) {
             av_log(bsf, AV_LOG_ERROR, "PPS parsing error\n");
-            err = AVERROR_INVALIDDATA;
+
             goto end;
         }
         break;
-    }
     case EVC_IDR_NUT:   // Coded slice of a IDR or non-IDR picture
     case EVC_NOIDR_NUT: {
         EVCParserSliceHeader sh;
diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
index 710fabccb2..0f6abf8b0f 100644
--- a/libavcodec/evc_parser.c
+++ b/libavcodec/evc_parser.c
@@ -63,6 +63,7 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
 {
     EVCParserContext *ctx = s->priv_data;
     int nalu_type, tid;
+    int ret;
 
     if (buf_size <= 0) {
         av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit size: (%d)\n", buf_size);
@@ -87,29 +88,26 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
     buf_size -= EVC_NALU_HEADER_SIZE;
 
     switch (nalu_type) {
-    case EVC_SPS_NUT: {
-        EVCParserSPS *sps = ff_evc_parse_sps(&ctx->ps, buf, buf_size);
-        if (!sps) {
+    case EVC_SPS_NUT:
+        ret = ff_evc_parse_sps(&ctx->ps, buf, buf_size);
+        if (ret < 0) {
             av_log(avctx, AV_LOG_ERROR, "SPS parsing error\n");
-            return AVERROR_INVALIDDATA;
+            return ret;
         }
         break;
-    }
-    case EVC_PPS_NUT: {
-        EVCParserPPS *pps = ff_evc_parse_pps(&ctx->ps, buf, buf_size);
-        if (!pps) {
+    case EVC_PPS_NUT:
+        ret = ff_evc_parse_pps(&ctx->ps, buf, buf_size);
+        if (ret < 0) {
             av_log(avctx, AV_LOG_ERROR, "PPS parsing error\n");
             return AVERROR_INVALIDDATA;
         }
         break;
-    }
     case EVC_IDR_NUT:   // Coded slice of a IDR or non-IDR picture
     case EVC_NOIDR_NUT: {
         const EVCParserPPS *pps;
         const EVCParserSPS *sps;
         EVCParserSliceHeader sh;
         int bit_depth;
-        int ret;
 
         ret = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, buf, buf_size);
         if (ret < 0) {
diff --git a/libavcodec/evc_ps.c b/libavcodec/evc_ps.c
index af74ba46b0..b8d7329b94 100644
--- a/libavcodec/evc_ps.c
+++ b/libavcodec/evc_ps.c
@@ -132,26 +132,26 @@ static int vui_parameters(GetBitContext *gb, VUIParameters *vui)
 }
 
 // @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
-EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
+int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
 {
     GetBitContext gb;
     EVCParserSPS *sps;
     int sps_seq_parameter_set_id;
+    int ret;
 
-    if (init_get_bits8(&gb, bs, bs_size) < 0)
-        return NULL;
+    ret = init_get_bits8(&gb, bs, bs_size);
+    if (ret < 0)
+        return ret;
 
     sps_seq_parameter_set_id = get_ue_golomb(&gb);
 
     if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT)
-        return NULL;
+        return AVERROR_INVALIDDATA;
 
-    if(!ps->sps[sps_seq_parameter_set_id]) {
-        if((ps->sps[sps_seq_parameter_set_id] = av_malloc(sizeof(EVCParserSPS))) == NULL)
-            return NULL;
-    }
+    sps = av_malloc(sizeof(*sps));
+    if (!sps)
+        return AVERROR(ENOMEM);
 
-    sps = ps->sps[sps_seq_parameter_set_id];
     memset(sps, 0, sizeof(*sps));
 
     sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id;
@@ -284,7 +284,10 @@ EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
     // If necessary, add the missing fields to the EVCParserSPS structure
     // and then extend parser implementation
 
-    return sps;
+    av_freep(&ps->sps[sps_seq_parameter_set_id]);
+    ps->sps[sps_seq_parameter_set_id] = sps;
+
+    return 0;
 }
 
 // @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
@@ -294,34 +297,33 @@ EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
 // If it will be needed, parse_sps function could be extended to handle VUI parameters parsing
 // to initialize fields of the AVCodecContex i.e. color_primaries, color_trc,color_range
 //
-EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
+int ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
 {
     GetBitContext gb;
     EVCParserPPS *pps;
-
     int pps_pic_parameter_set_id;
+    int ret;
 
-    if (init_get_bits8(&gb, bs, bs_size) < 0)
-        return NULL;
+    ret = init_get_bits8(&gb, bs, bs_size);
+    if (ret < 0)
+        return ret;
 
     pps_pic_parameter_set_id = get_ue_golomb(&gb);
     if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT)
-        return NULL;
+        return AVERROR_INVALIDDATA;
 
-    if(!ps->pps[pps_pic_parameter_set_id]) {
-        if ((ps->pps[pps_pic_parameter_set_id] = av_malloc(sizeof(EVCParserPPS))) == NULL)
-            return NULL;
-    }
+    pps = av_malloc(sizeof(*pps));
+    if (!pps)
+        return AVERROR(ENOMEM);
 
-    pps = ps->pps[pps_pic_parameter_set_id];
     memset(pps, 0, sizeof(*pps));
 
     pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id;
 
     pps->pps_seq_parameter_set_id = get_ue_golomb(&gb);
     if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) {
-        av_freep(&ps->pps[pps_pic_parameter_set_id]);
-        return NULL;
+        ret = AVERROR_INVALIDDATA;
+        goto fail;
     }
 
     pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
@@ -369,7 +371,13 @@ EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
     if (pps->cu_qp_delta_enabled_flag)
         pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(&gb);
 
-    return pps;
+    av_freep(&ps->pps[pps_pic_parameter_set_id]);
+    ps->pps[pps_pic_parameter_set_id] = pps;
+
+    return 0;
+fail:
+    av_free(pps);
+    return ret;
 }
 
 void ff_evc_ps_free(EVCParamSets *ps) {
diff --git a/libavcodec/evc_ps.h b/libavcodec/evc_ps.h
index 989336079f..c7ed2af37b 100644
--- a/libavcodec/evc_ps.h
+++ b/libavcodec/evc_ps.h
@@ -218,10 +218,10 @@ typedef struct EVCParamSets {
 } EVCParamSets;
 
 // @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
-EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
+int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
 
 // @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
-EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
+int ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
 
 void ff_evc_ps_free(EVCParamSets *ps);
 
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 17/17] avcodec/evc_ps: Check log2_sub_gop_length
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (14 preceding siblings ...)
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 16/17] avcodec/evc_ps: make ff_evc_parse_{sps, pps} return an error code James Almer
@ 2023-06-18 23:43 ` James Almer
  2023-06-19 18:28 ` [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-18 23:43 UTC (permalink / raw)
  To: ffmpeg-devel

From: Michael Niedermayer <michael@niedermayer.cc>

Fixes: 1.70141e+38 is outside the range of representable values of type 'int'
Fixes: 59883/clusterfuzz-testcase-minimized-ffmpeg_BSF_EVC_FRAME_MERGE_fuzzer-5557887217565696

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_ps.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libavcodec/evc_ps.c b/libavcodec/evc_ps.c
index b8d7329b94..0b8cc81d49 100644
--- a/libavcodec/evc_ps.c
+++ b/libavcodec/evc_ps.c
@@ -229,6 +229,10 @@ int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
 
     if (!sps->sps_pocs_flag || !sps->sps_rpl_flag) {
         sps->log2_sub_gop_length = get_ue_golomb(&gb);
+        if (sps->log2_sub_gop_length > 5U) {
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
+        }
         if (sps->log2_sub_gop_length == 0)
             sps->log2_ref_pic_gap_length = get_ue_golomb(&gb);
     }
@@ -288,6 +292,9 @@ int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
     ps->sps[sps_seq_parameter_set_id] = sps;
 
     return 0;
+fail:
+    av_free(sps);
+    return ret;
 }
 
 // @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc()
  2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
                   ` (15 preceding siblings ...)
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 17/17] avcodec/evc_ps: Check log2_sub_gop_length James Almer
@ 2023-06-19 18:28 ` James Almer
  16 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-19 18:28 UTC (permalink / raw)
  To: ffmpeg-devel

On 6/17/2023 12:18 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   libavcodec/evc_frame_merge_bsf.c | 24 ++++++++----------------
>   1 file changed, 8 insertions(+), 16 deletions(-)

Will apply the first ten patches.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [FFmpeg-devel] [PATCH 13/17] avformat/evcdec: simplify probe function
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 13/17] avformat/evcdec: simplify probe function James Almer
@ 2023-06-19 20:29   ` Michael Niedermayer
  2023-06-19 20:42     ` James Almer
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Niedermayer @ 2023-06-19 20:29 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 669 bytes --]

On Sun, Jun 18, 2023 at 08:43:28PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/evcdec.c | 29 +++++++----------------------
>  1 file changed, 7 insertions(+), 22 deletions(-)

This or the previous might cause "Invalid NAL unit header" noise
from tools/probetest 256 4096
(not 100% sure as some patches didnt apply so maybe my tree was
broken) just reporting (please ignore if it doesnt reproduce)

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [FFmpeg-devel] [PATCH 13/17] avformat/evcdec: simplify probe function
  2023-06-19 20:29   ` Michael Niedermayer
@ 2023-06-19 20:42     ` James Almer
  0 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-19 20:42 UTC (permalink / raw)
  To: ffmpeg-devel

On 6/19/2023 5:29 PM, Michael Niedermayer wrote:
> On Sun, Jun 18, 2023 at 08:43:28PM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavformat/evcdec.c | 29 +++++++----------------------
>>   1 file changed, 7 insertions(+), 22 deletions(-)
> 
> This or the previous might cause "Invalid NAL unit header" noise
> from tools/probetest 256 4096
> (not 100% sure as some patches didnt apply so maybe my tree was
> broken) just reporting (please ignore if it doesnt reproduce)
> 
> thx

It was patch 11/17. Forgot to add a logctx in evc_get_nalu_type().
Fixed locally.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [FFmpeg-devel] [PATCH 11/17 v2] avformat/evc: don't use an AVIOContext as log context
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 11/17] avformat/evc: don't use an AVIOContext as log context James Almer
@ 2023-06-19 21:11   ` James Almer
  2023-06-20 14:38   ` [FFmpeg-devel] [PATCH 11/17] " James Almer
  1 sibling, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-19 21:11 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_parse.h | 6 ++++--
 libavformat/evc.c      | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index a1fbbc643d..6fc19d0868 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -89,7 +89,8 @@ static inline int evc_get_nalu_type(const uint8_t *bits, int bits_size, void *lo
         unsigned char *p = (unsigned char *)bits;
         // forbidden_zero_bit
         if ((p[0] & 0x80) != 0) {
-            av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit header\n");
+            if (logctx) // Don't log without a context
+                av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit header\n");
             return -1;
         }
 
@@ -105,7 +106,8 @@ static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_si
     uint32_t nalu_len = 0;
 
     if (bits_size < EVC_NALU_LENGTH_PREFIX_SIZE) {
-        av_log(logctx, AV_LOG_ERROR, "Can't read NAL unit length\n");
+        if (logctx) // Don't log without a context
+            av_log(logctx, AV_LOG_ERROR, "Can't read NAL unit length\n");
         return 0;
     }
 
diff --git a/libavformat/evc.c b/libavformat/evc.c
index 421ff84cb7..caead88bba 100644
--- a/libavformat/evc.c
+++ b/libavformat/evc.c
@@ -361,7 +361,7 @@ int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data,
     evcc_init(&evcc);
 
     while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) {
-        nalu_size = evc_read_nal_unit_length(data, EVC_NALU_LENGTH_PREFIX_SIZE, pb);
+        nalu_size = evc_read_nal_unit_length(data, EVC_NALU_LENGTH_PREFIX_SIZE, NULL);
         if (nalu_size == 0) break;
 
         data += EVC_NALU_LENGTH_PREFIX_SIZE;
@@ -369,7 +369,7 @@ int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data,
 
         if (bytes_to_read < nalu_size) break;
 
-        nalu_type = evc_get_nalu_type(data, bytes_to_read, pb);
+        nalu_type = evc_get_nalu_type(data, bytes_to_read, NULL);
         if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) {
             ret = AVERROR_INVALIDDATA;
             goto end;
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [FFmpeg-devel] [PATCH 04/10] avcodec/evc_parse: split off Parameter Set parsing into its own file
  2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 04/10] avcodec/evc_parse: split off Parameter Set parsing into its own file James Almer
@ 2023-06-20  7:37   ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics
  2023-06-20 11:37     ` James Almer
  0 siblings, 1 reply; 25+ messages in thread
From: Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics @ 2023-06-20  7:37 UTC (permalink / raw)
  To: 'FFmpeg development discussions and patches'

Why have you split off the parameter set parsing into its own file? Just
asking what's the reason.



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of James
> Almer
> Sent: niedziela, 18 czerwca 2023 00:00
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH 04/10] avcodec/evc_parse: split off
Parameter
> Set parsing into its own file
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/Makefile              |   2 +-
>  libavcodec/evc_frame_merge_bsf.c |   4 +-
>  libavcodec/evc_parse.c           | 371 +-----------------------------
>  libavcodec/evc_parse.h           | 198 +---------------
>  libavcodec/evc_parser.c          |   2 +-
>  libavcodec/evc_ps.c              | 381 +++++++++++++++++++++++++++++++
>  libavcodec/evc_ps.h              | 228 ++++++++++++++++++
>  7 files changed, 621 insertions(+), 565 deletions(-)
>  create mode 100644 libavcodec/evc_ps.c
>  create mode 100644 libavcodec/evc_ps.h
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 0ce8fe5b9c..723bfa25c7 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -84,7 +84,7 @@ OBJS-$(CONFIG_DCT)                     += dct.o
dct32_fixed.o
> dct32_float.o
>  OBJS-$(CONFIG_DEFLATE_WRAPPER)         += zlib_wrapper.o
>  OBJS-$(CONFIG_DOVI_RPU)                += dovi_rpu.o
>  OBJS-$(CONFIG_ERROR_RESILIENCE)        += error_resilience.o
> -OBJS-$(CONFIG_EVCPARSE)                += evc_parse.o
> +OBJS-$(CONFIG_EVCPARSE)                += evc_parse.o evc_ps.o
>  OBJS-$(CONFIG_EXIF)                    += exif.o tiff_common.o
>  OBJS-$(CONFIG_FAANDCT)                 += faandct.o
>  OBJS-$(CONFIG_FAANIDCT)                += faanidct.o
> diff --git a/libavcodec/evc_frame_merge_bsf.c
> b/libavcodec/evc_frame_merge_bsf.c
> index 540bb63631..f497780afb 100644
> --- a/libavcodec/evc_frame_merge_bsf.c
> +++ b/libavcodec/evc_frame_merge_bsf.c
> @@ -58,7 +58,7 @@ static void evc_frame_merge_flush(AVBSFContext *bsf)
>  {
>      EVCFMergeContext *ctx = bsf->priv_data;
> 
> -    ff_evc_parse_free(&ctx->parser_ctx);
> +    ff_evc_ps_free(&ctx->parser_ctx.ps);
>      av_packet_unref(ctx->in);
>      ctx->au_buffer.data_size = 0;
>  }
> @@ -147,7 +147,7 @@ static void evc_frame_merge_close(AVBSFContext *bsf)
>      EVCFMergeContext *ctx = bsf->priv_data;
> 
>      av_packet_free(&ctx->in);
> -    ff_evc_parse_free(&ctx->parser_ctx);
> +    ff_evc_ps_free(&ctx->parser_ctx.ps);
> 
>      ctx->au_buffer.capacity = 0;
>      av_freep(&ctx->au_buffer.data);
> diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c
> index 44be5c5291..a8e6356b96 100644
> --- a/libavcodec/evc_parse.c
> +++ b/libavcodec/evc_parse.c
> @@ -21,8 +21,6 @@
>  #include "evc.h"
>  #include "evc_parse.h"
> 
> -#define EXTENDED_SAR            255
> -
>  #define NUM_CHROMA_FORMATS      4   // @see ISO_IEC_23094-1 section 6.2
> table 2
> 
>  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)
>      return temporal_id;
>  }
> 
> -// @see ISO_IEC_23094-1 (7.3.7 Reference picture list structure syntax)
> -static int ref_pic_list_struct(GetBitContext *gb, RefPicListStruct *rpl)
> -{
> -    uint32_t delta_poc_st, strp_entry_sign_flag = 0;
> -    rpl->ref_pic_num = get_ue_golomb(gb);
> -    if (rpl->ref_pic_num > 0) {
> -        delta_poc_st = get_ue_golomb(gb);
> -
> -        rpl->ref_pics[0] = delta_poc_st;
> -        if (rpl->ref_pics[0] != 0) {
> -            strp_entry_sign_flag = get_bits(gb, 1);
> -
> -            rpl->ref_pics[0] *= 1 - (strp_entry_sign_flag << 1);
> -        }
> -    }
> -
> -    for (int i = 1; i < rpl->ref_pic_num; ++i) {
> -        delta_poc_st = get_ue_golomb(gb);
> -        if (delta_poc_st != 0)
> -            strp_entry_sign_flag = get_bits(gb, 1);
> -        rpl->ref_pics[i] = rpl->ref_pics[i - 1] + delta_poc_st * (1 -
> (strp_entry_sign_flag << 1));
> -    }
> -
> -    return 0;
> -}
> -
> -// @see  ISO_IEC_23094-1 (E.2.2 HRD parameters syntax)
> -static int hrd_parameters(GetBitContext *gb, HRDParameters *hrd)
> -{
> -    hrd->cpb_cnt_minus1 = get_ue_golomb(gb);
> -    hrd->bit_rate_scale = get_bits(gb, 4);
> -    hrd->cpb_size_scale = get_bits(gb, 4);
> -    for (int SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1;
SchedSelIdx++)
> {
> -        hrd->bit_rate_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
> -        hrd->cpb_size_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
> -        hrd->cbr_flag[SchedSelIdx] = get_bits(gb, 1);
> -    }
> -    hrd->initial_cpb_removal_delay_length_minus1 = get_bits(gb, 5);
> -    hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
> -    hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
> -    hrd->time_offset_length = get_bits(gb, 5);
> -
> -    return 0;
> -}
> -
> -// @see  ISO_IEC_23094-1 (E.2.1 VUI parameters syntax)
> -static int vui_parameters(GetBitContext *gb, VUIParameters *vui)
> -{
> -    vui->aspect_ratio_info_present_flag = get_bits(gb, 1);
> -    if (vui->aspect_ratio_info_present_flag) {
> -        vui->aspect_ratio_idc = get_bits(gb, 8);
> -        if (vui->aspect_ratio_idc == EXTENDED_SAR) {
> -            vui->sar_width = get_bits(gb, 16);
> -            vui->sar_height = get_bits(gb, 16);
> -        }
> -    }
> -    vui->overscan_info_present_flag = get_bits(gb, 1);
> -    if (vui->overscan_info_present_flag)
> -        vui->overscan_appropriate_flag = get_bits(gb, 1);
> -    vui->video_signal_type_present_flag = get_bits(gb, 1);
> -    if (vui->video_signal_type_present_flag) {
> -        vui->video_format = get_bits(gb, 3);
> -        vui->video_full_range_flag = get_bits(gb, 1);
> -        vui->colour_description_present_flag = get_bits(gb, 1);
> -        if (vui->colour_description_present_flag) {
> -            vui->colour_primaries = get_bits(gb, 8);
> -            vui->transfer_characteristics = get_bits(gb, 8);
> -            vui->matrix_coefficients = get_bits(gb, 8);
> -        }
> -    }
> -    vui->chroma_loc_info_present_flag = get_bits(gb, 1);
> -    if (vui->chroma_loc_info_present_flag) {
> -        vui->chroma_sample_loc_type_top_field = get_ue_golomb(gb);
> -        vui->chroma_sample_loc_type_bottom_field = get_ue_golomb(gb);
> -    }
> -    vui->neutral_chroma_indication_flag = get_bits(gb, 1);
> -
> -    vui->field_seq_flag = get_bits(gb, 1);
> -
> -    vui->timing_info_present_flag = get_bits(gb, 1);
> -    if (vui->timing_info_present_flag) {
> -        vui->num_units_in_tick = get_bits(gb, 32);
> -        vui->time_scale = get_bits(gb, 32);
> -        vui->fixed_pic_rate_flag = get_bits(gb, 1);
> -    }
> -    vui->nal_hrd_parameters_present_flag = get_bits(gb, 1);
> -    if (vui->nal_hrd_parameters_present_flag)
> -        hrd_parameters(gb, &vui->hrd_parameters);
> -    vui->vcl_hrd_parameters_present_flag = get_bits(gb, 1);
> -    if (vui->vcl_hrd_parameters_present_flag)
> -        hrd_parameters(gb, &vui->hrd_parameters);
> -    if (vui->nal_hrd_parameters_present_flag || vui-
> >vcl_hrd_parameters_present_flag)
> -        vui->low_delay_hrd_flag = get_bits(gb, 1);
> -    vui->pic_struct_present_flag = get_bits(gb, 1);
> -    vui->bitstream_restriction_flag = get_bits(gb, 1);
> -    if (vui->bitstream_restriction_flag) {
> -        vui->motion_vectors_over_pic_boundaries_flag = get_bits(gb, 1);
> -        vui->max_bytes_per_pic_denom = get_ue_golomb(gb);
> -        vui->max_bits_per_mb_denom = get_ue_golomb(gb);
> -        vui->log2_max_mv_length_horizontal = get_ue_golomb(gb);
> -        vui->log2_max_mv_length_vertical = get_ue_golomb(gb);
> -        vui->num_reorder_pics = get_ue_golomb(gb);
> -        vui->max_dec_pic_buffering = get_ue_golomb(gb);
> -    }
> -
> -    return 0;
> -}
> -
> -// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
> -EVCParserSPS *ff_evc_parse_sps(EVCParserContext *ctx, const uint8_t *bs,
int
> bs_size)
> -{
> -    GetBitContext gb;
> -    EVCParserSPS *sps;
> -    int sps_seq_parameter_set_id;
> -
> -    if (init_get_bits8(&gb, bs, bs_size) < 0)
> -        return NULL;
> -
> -    sps_seq_parameter_set_id = get_ue_golomb(&gb);
> -
> -    if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT)
> -        return NULL;
> -
> -    if(!ctx->sps[sps_seq_parameter_set_id]) {
> -        if((ctx->sps[sps_seq_parameter_set_id] =
av_malloc(sizeof(EVCParserSPS)))
> == NULL)
> -            return NULL;
> -    }
> -
> -    sps = ctx->sps[sps_seq_parameter_set_id];
> -    memset(sps, 0, sizeof(*sps));
> -
> -    sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id;
> -
> -    // the Baseline profile is indicated by profile_idc eqal to 0
> -    // the Main profile is indicated by profile_idc eqal to 1
> -    sps->profile_idc = get_bits(&gb, 8);
> -
> -    sps->level_idc = get_bits(&gb, 8);
> -
> -    skip_bits_long(&gb, 32); /* skip toolset_idc_h */
> -    skip_bits_long(&gb, 32); /* skip toolset_idc_l */
> -
> -    // 0 - monochrome
> -    // 1 - 4:2:0
> -    // 2 - 4:2:2
> -    // 3 - 4:4:4
> -    sps->chroma_format_idc = get_ue_golomb(&gb);
> -
> -    sps->pic_width_in_luma_samples = get_ue_golomb(&gb);
> -    sps->pic_height_in_luma_samples = get_ue_golomb(&gb);
> -
> -    sps->bit_depth_luma_minus8 = get_ue_golomb(&gb);
> -    sps->bit_depth_chroma_minus8 = get_ue_golomb(&gb);
> -
> -    sps->sps_btt_flag = get_bits(&gb, 1);
> -    if (sps->sps_btt_flag) {
> -        sps->log2_ctu_size_minus5 = get_ue_golomb(&gb);
> -        sps->log2_min_cb_size_minus2 = get_ue_golomb(&gb);
> -        sps->log2_diff_ctu_max_14_cb_size = get_ue_golomb(&gb);
> -        sps->log2_diff_ctu_max_tt_cb_size = get_ue_golomb(&gb);
> -        sps->log2_diff_min_cb_min_tt_cb_size_minus2 = get_ue_golomb(&gb);
> -    }
> -
> -    sps->sps_suco_flag = get_bits(&gb, 1);
> -    if (sps->sps_suco_flag) {
> -        sps->log2_diff_ctu_size_max_suco_cb_size = get_ue_golomb(&gb);
> -        sps->log2_diff_max_suco_min_suco_cb_size = get_ue_golomb(&gb);
> -    }
> -
> -    sps->sps_admvp_flag = get_bits(&gb, 1);
> -    if (sps->sps_admvp_flag) {
> -        sps->sps_affine_flag = get_bits(&gb, 1);
> -        sps->sps_amvr_flag = get_bits(&gb, 1);
> -        sps->sps_dmvr_flag = get_bits(&gb, 1);
> -        sps->sps_mmvd_flag = get_bits(&gb, 1);
> -        sps->sps_hmvp_flag = get_bits(&gb, 1);
> -    }
> -
> -    sps->sps_eipd_flag =  get_bits(&gb, 1);
> -    if (sps->sps_eipd_flag) {
> -        sps->sps_ibc_flag = get_bits(&gb, 1);
> -        if (sps->sps_ibc_flag)
> -            sps->log2_max_ibc_cand_size_minus2 = get_ue_golomb(&gb);
> -    }
> -
> -    sps->sps_cm_init_flag = get_bits(&gb, 1);
> -    if (sps->sps_cm_init_flag)
> -        sps->sps_adcc_flag = get_bits(&gb, 1);
> -
> -    sps->sps_iqt_flag = get_bits(&gb, 1);
> -    if (sps->sps_iqt_flag)
> -        sps->sps_ats_flag = get_bits(&gb, 1);
> -
> -    sps->sps_addb_flag = get_bits(&gb, 1);
> -    sps->sps_alf_flag = get_bits(&gb, 1);
> -    sps->sps_htdf_flag = get_bits(&gb, 1);
> -    sps->sps_rpl_flag = get_bits(&gb, 1);
> -    sps->sps_pocs_flag = get_bits(&gb, 1);
> -    sps->sps_dquant_flag = get_bits(&gb, 1);
> -    sps->sps_dra_flag = get_bits(&gb, 1);
> -
> -    if (sps->sps_pocs_flag)
> -        sps->log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb(&gb);
> -
> -    if (!sps->sps_pocs_flag || !sps->sps_rpl_flag) {
> -        sps->log2_sub_gop_length = get_ue_golomb(&gb);
> -        if (sps->log2_sub_gop_length == 0)
> -            sps->log2_ref_pic_gap_length = get_ue_golomb(&gb);
> -    }
> -
> -    if (!sps->sps_rpl_flag)
> -        sps->max_num_tid0_ref_pics = get_ue_golomb(&gb);
> -    else {
> -        sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb(&gb);
> -        sps->long_term_ref_pic_flag = get_bits(&gb, 1);
> -        sps->rpl1_same_as_rpl0_flag = get_bits(&gb, 1);
> -        sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(&gb);
> -
> -        for (int i = 0; i < sps->num_ref_pic_list_in_sps[0]; ++i)
> -            ref_pic_list_struct(&gb, &sps->rpls[0][i]);
> -
> -        if (!sps->rpl1_same_as_rpl0_flag) {
> -            sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(&gb);
> -            for (int i = 0; i < sps->num_ref_pic_list_in_sps[1]; ++i)
> -                ref_pic_list_struct(&gb, &sps->rpls[1][i]);
> -        }
> -    }
> -
> -    sps->picture_cropping_flag = get_bits(&gb, 1);
> -
> -    if (sps->picture_cropping_flag) {
> -        sps->picture_crop_left_offset = get_ue_golomb(&gb);
> -        sps->picture_crop_right_offset = get_ue_golomb(&gb);
> -        sps->picture_crop_top_offset = get_ue_golomb(&gb);
> -        sps->picture_crop_bottom_offset = get_ue_golomb(&gb);
> -    }
> -
> -    if (sps->chroma_format_idc != 0) {
> -        sps->chroma_qp_table_struct.chroma_qp_table_present_flag =
> get_bits(&gb, 1);
> -
> -        if (sps->chroma_qp_table_struct.chroma_qp_table_present_flag) {
> -            sps->chroma_qp_table_struct.same_qp_table_for_chroma =
> get_bits(&gb, 1);
> -            sps->chroma_qp_table_struct.global_offset_flag =
get_bits(&gb, 1);
> -            for (int i = 0; i < (sps-
> >chroma_qp_table_struct.same_qp_table_for_chroma ? 1 : 2); i++) {
> -
sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] =
> get_ue_golomb(&gb);;
> -                for (int j = 0; j <= sps-
> >chroma_qp_table_struct.num_points_in_qp_table_minus1[i]; j++) {
> -
sps->chroma_qp_table_struct.delta_qp_in_val_minus1[i][j] =
> get_bits(&gb, 6);
> -                    sps->chroma_qp_table_struct.delta_qp_out_val[i][j] =
> get_se_golomb(&gb);
> -                }
> -            }
> -        }
> -    }
> -
> -    sps->vui_parameters_present_flag = get_bits(&gb, 1);
> -    if (sps->vui_parameters_present_flag)
> -        vui_parameters(&gb, &(sps->vui_parameters));
> -
> -    // @note
> -    // If necessary, add the missing fields to the EVCParserSPS structure
> -    // and then extend parser implementation
> -
> -    return sps;
> -}
> -
> -// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
> -//
> -// @note
> -// The current implementation of parse_sps function doesn't handle VUI
> parameters parsing.
> -// If it will be needed, parse_sps function could be extended to handle
VUI
> parameters parsing
> -// to initialize fields of the AVCodecContex i.e. color_primaries,
> color_trc,color_range
> -//
> -EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs,
int
> bs_size)
> -{
> -    GetBitContext gb;
> -    EVCParserPPS *pps;
> -
> -    int pps_pic_parameter_set_id;
> -
> -    if (init_get_bits8(&gb, bs, bs_size) < 0)
> -        return NULL;
> -
> -    pps_pic_parameter_set_id = get_ue_golomb(&gb);
> -    if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT)
> -        return NULL;
> -
> -    if(!ctx->pps[pps_pic_parameter_set_id]) {
> -        if ((ctx->pps[pps_pic_parameter_set_id] =
> av_malloc(sizeof(EVCParserPPS))) == NULL)
> -            return NULL;
> -    }
> -
> -    pps = ctx->pps[pps_pic_parameter_set_id];
> -    memset(pps, 0, sizeof(*pps));
> -
> -    pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id;
> -
> -    pps->pps_seq_parameter_set_id = get_ue_golomb(&gb);
> -    if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) {
> -        av_freep(&ctx->pps[pps_pic_parameter_set_id]);
> -        return NULL;
> -    }
> -
> -    pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
> -    pps->num_ref_idx_default_active_minus1[1] = get_ue_golomb(&gb);
> -    pps->additional_lt_poc_lsb_len = get_ue_golomb(&gb);
> -    pps->rpl1_idx_present_flag = get_bits(&gb, 1);
> -    pps->single_tile_in_pic_flag = get_bits(&gb, 1);
> -
> -    if (!pps->single_tile_in_pic_flag) {
> -        pps->num_tile_columns_minus1 = get_ue_golomb(&gb);
> -        pps->num_tile_rows_minus1 = get_ue_golomb(&gb);
> -        pps->uniform_tile_spacing_flag = get_bits(&gb, 1);
> -
> -        if (!pps->uniform_tile_spacing_flag) {
> -            for (int i = 0; i < pps->num_tile_columns_minus1; i++)
> -                pps->tile_column_width_minus1[i] = get_ue_golomb(&gb);
> -
> -            for (int i = 0; i < pps->num_tile_rows_minus1; i++)
> -                pps->tile_row_height_minus1[i] = get_ue_golomb(&gb);
> -        }
> -        pps->loop_filter_across_tiles_enabled_flag = get_bits(&gb, 1);
> -        pps->tile_offset_len_minus1 = get_ue_golomb(&gb);
> -    }
> -
> -    pps->tile_id_len_minus1 = get_ue_golomb(&gb);
> -    pps->explicit_tile_id_flag = get_bits(&gb, 1);
> -
> -    if (pps->explicit_tile_id_flag) {
> -        for (int i = 0; i <= pps->num_tile_rows_minus1; i++) {
> -            for (int j = 0; j <= pps->num_tile_columns_minus1; j++)
> -                pps->tile_id_val[i][j] = get_bits(&gb,
pps->tile_id_len_minus1 + 1);
> -        }
> -    }
> -
> -    pps->pic_dra_enabled_flag = 0;
> -    pps->pic_dra_enabled_flag = get_bits(&gb, 1);
> -
> -    if (pps->pic_dra_enabled_flag)
> -        pps->pic_dra_aps_id = get_bits(&gb, 5);
> -
> -    pps->arbitrary_slice_present_flag = get_bits(&gb, 1);
> -    pps->constrained_intra_pred_flag = get_bits(&gb, 1);
> -    pps->cu_qp_delta_enabled_flag = get_bits(&gb, 1);
> -
> -    if (pps->cu_qp_delta_enabled_flag)
> -        pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(&gb);
> -
> -    return pps;
> -}
> -
>  // @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
>  static int evc_parse_slice_header(EVCParserContext *ctx,
> EVCParserSliceHeader *sh, const uint8_t *bs, int bs_size)
>  {
> @@ -439,11 +88,11 @@ static int evc_parse_slice_header(EVCParserContext
> *ctx, EVCParserSliceHeader *s
>      if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >=
> EVC_MAX_PPS_COUNT)
>          return AVERROR_INVALIDDATA;
> 
> -    pps = ctx->pps[slice_pic_parameter_set_id];
> +    pps = ctx->ps.pps[slice_pic_parameter_set_id];
>      if(!pps)
>          return AVERROR_INVALIDDATA;
> 
> -    sps = ctx->sps[pps->pps_seq_parameter_set_id];
> +    sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
>      if(!sps)
>          return AVERROR_INVALIDDATA;
> 
> @@ -579,7 +228,7 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const
> uint8_t *buf, int buf_siz
>          int SubGopLength;
>          int bit_depth;
> 
> -        sps = ff_evc_parse_sps(ctx, data, nalu_size);
> +        sps = ff_evc_parse_sps(&ctx->ps, data, nalu_size);
>          if (!sps) {
>              av_log(logctx, AV_LOG_ERROR, "SPS parsing error\n");
>              return AVERROR_INVALIDDATA;
> @@ -642,7 +291,7 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const
> uint8_t *buf, int buf_siz
>      case EVC_PPS_NUT: {
>          EVCParserPPS *pps;
> 
> -        pps = ff_evc_parse_pps(ctx, data, nalu_size);
> +        pps = ff_evc_parse_pps(&ctx->ps, data, nalu_size);
>          if (!pps) {
>              av_log(logctx, AV_LOG_ERROR, "PPS parsing error\n");
>              return AVERROR_INVALIDDATA;
> @@ -688,8 +337,8 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const
> uint8_t *buf, int buf_siz
> 
>          // POC (picture order count of the current picture) derivation
>          // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for
picture order
> count
> -        pps = ctx->pps[sh.slice_pic_parameter_set_id];
> -        sps = ctx->sps[pps->pps_seq_parameter_set_id];
> +        pps = ctx->ps.pps[sh.slice_pic_parameter_set_id];
> +        sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
>          av_assert0(sps && pps);
> 
>          if (sps->sps_pocs_flag) {
> @@ -764,11 +413,3 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx,
> const uint8_t *buf, int buf_siz
> 
>      return 0;
>  }
> -
> -void ff_evc_parse_free(EVCParserContext *ctx) {
> -    for (int i = 0; i < EVC_MAX_SPS_COUNT; i++)
> -        av_freep(&ctx->sps[i]);
> -
> -    for (int i = 0; i < EVC_MAX_PPS_COUNT; i++)
> -        av_freep(&ctx->pps[i]);
> -}
> diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
> index ee4b6c5708..b5462f5711 100644
> --- a/libavcodec/evc_parse.h
> +++ b/libavcodec/evc_parse.h
> @@ -30,190 +30,7 @@
>  #include "libavutil/log.h"
>  #include "libavutil/rational.h"
>  #include "evc.h"
> -
> -#define EVC_MAX_QP_TABLE_SIZE   58
> -#define NUM_CPB                 32
> -
> -// rpl structure
> -typedef struct RefPicListStruct {
> -    int poc;
> -    int tid;
> -    int ref_pic_num;
> -    int ref_pic_active_num;
> -    int ref_pics[EVC_MAX_NUM_REF_PICS];
> -    char pic_type;
> -
> -} RefPicListStruct;
> -
> -// chromaQP table structure to be signalled in SPS
> -typedef struct ChromaQpTable {
> -    int chroma_qp_table_present_flag;       // u(1)
> -    int same_qp_table_for_chroma;           // u(1)
> -    int global_offset_flag;                 // u(1)
> -    int num_points_in_qp_table_minus1[2];   // ue(v)
> -    int delta_qp_in_val_minus1[2][EVC_MAX_QP_TABLE_SIZE];   // u(6)
> -    int delta_qp_out_val[2][EVC_MAX_QP_TABLE_SIZE];         // se(v)
> -} ChromaQpTable;
> -
> -// Hypothetical Reference Decoder (HRD) parameters, part of VUI
> -typedef struct HRDParameters {
> -    int cpb_cnt_minus1;                             // ue(v)
> -    int bit_rate_scale;                             // u(4)
> -    int cpb_size_scale;                             // u(4)
> -    int bit_rate_value_minus1[NUM_CPB];             // ue(v)
> -    int cpb_size_value_minus1[NUM_CPB];             // ue(v)
> -    int cbr_flag[NUM_CPB];                          // u(1)
> -    int initial_cpb_removal_delay_length_minus1;    // u(5)
> -    int cpb_removal_delay_length_minus1;            // u(5)
> -    int dpb_output_delay_length_minus1;             // u(5)
> -    int time_offset_length;                         // u(5)
> -} HRDParameters;
> -
> -// video usability information (VUI) part of SPS
> -typedef struct VUIParameters {
> -    int aspect_ratio_info_present_flag;             // u(1)
> -    int aspect_ratio_idc;                           // u(8)
> -    int sar_width;                                  // u(16)
> -    int sar_height;                                 // u(16)
> -    int overscan_info_present_flag;                 // u(1)
> -    int overscan_appropriate_flag;                  // u(1)
> -    int video_signal_type_present_flag;             // u(1)
> -    int video_format;                               // u(3)
> -    int video_full_range_flag;                      // u(1)
> -    int colour_description_present_flag;            // u(1)
> -    int colour_primaries;                           // u(8)
> -    int transfer_characteristics;                   // u(8)
> -    int matrix_coefficients;                        // u(8)
> -    int chroma_loc_info_present_flag;               // u(1)
> -    int chroma_sample_loc_type_top_field;           // ue(v)
> -    int chroma_sample_loc_type_bottom_field;        // ue(v)
> -    int neutral_chroma_indication_flag;             // u(1)
> -    int field_seq_flag;                             // u(1)
> -    int timing_info_present_flag;                   // u(1)
> -    int num_units_in_tick;                          // u(32)
> -    int time_scale;                                 // u(32)
> -    int fixed_pic_rate_flag;                        // u(1)
> -    int nal_hrd_parameters_present_flag;            // u(1)
> -    int vcl_hrd_parameters_present_flag;            // u(1)
> -    int low_delay_hrd_flag;                         // u(1)
> -    int pic_struct_present_flag;                    // u(1)
> -    int bitstream_restriction_flag;                 // u(1)
> -    int motion_vectors_over_pic_boundaries_flag;    // u(1)
> -    int max_bytes_per_pic_denom;                    // ue(v)
> -    int max_bits_per_mb_denom;                      // ue(v)
> -    int log2_max_mv_length_horizontal;              // ue(v)
> -    int log2_max_mv_length_vertical;                // ue(v)
> -    int num_reorder_pics;                           // ue(v)
> -    int max_dec_pic_buffering;                      // ue(v)
> -
> -    HRDParameters hrd_parameters;
> -} VUIParameters;
> -
> -// The sturcture reflects SPS RBSP(raw byte sequence payload) layout
> -// @see ISO_IEC_23094-1 section 7.3.2.1
> -//
> -// The following descriptors specify the parsing process of each element
> -// u(n) - unsigned integer using n bits
> -// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element
with
> the left bit first
> -typedef struct EVCParserSPS {
> -    int sps_seq_parameter_set_id;   // ue(v)
> -    int profile_idc;                // u(8)
> -    int level_idc;                  // u(8)
> -    int toolset_idc_h;              // u(32)
> -    int toolset_idc_l;              // u(32)
> -    int chroma_format_idc;          // ue(v)
> -    int pic_width_in_luma_samples;  // ue(v)
> -    int pic_height_in_luma_samples; // ue(v)
> -    int bit_depth_luma_minus8;      // ue(v)
> -    int bit_depth_chroma_minus8;    // ue(v)
> -
> -    int sps_btt_flag;                           // u(1)
> -    int log2_ctu_size_minus5;                   // ue(v)
> -    int log2_min_cb_size_minus2;                // ue(v)
> -    int log2_diff_ctu_max_14_cb_size;           // ue(v)
> -    int log2_diff_ctu_max_tt_cb_size;           // ue(v)
> -    int log2_diff_min_cb_min_tt_cb_size_minus2; // ue(v)
> -
> -    int sps_suco_flag;                       // u(1)
> -    int log2_diff_ctu_size_max_suco_cb_size; // ue(v)
> -    int log2_diff_max_suco_min_suco_cb_size; // ue(v)
> -
> -    int sps_admvp_flag;     // u(1)
> -    int sps_affine_flag;    // u(1)
> -    int sps_amvr_flag;      // u(1)
> -    int sps_dmvr_flag;      // u(1)
> -    int sps_mmvd_flag;      // u(1)
> -    int sps_hmvp_flag;      // u(1)
> -
> -    int sps_eipd_flag;                 // u(1)
> -    int sps_ibc_flag;                  // u(1)
> -    int log2_max_ibc_cand_size_minus2; // ue(v)
> -
> -    int sps_cm_init_flag; // u(1)
> -    int sps_adcc_flag;    // u(1)
> -
> -    int sps_iqt_flag; // u(1)
> -    int sps_ats_flag; // u(1)
> -
> -    int sps_addb_flag;   // u(1)
> -    int sps_alf_flag;    // u(1)
> -    int sps_htdf_flag;   // u(1)
> -    int sps_rpl_flag;    // u(1)
> -    int sps_pocs_flag;   // u(1)
> -    int sps_dquant_flag; // u(1)
> -    int sps_dra_flag;    // u(1)
> -
> -    int log2_max_pic_order_cnt_lsb_minus4; // ue(v)
> -    int log2_sub_gop_length;               // ue(v)
> -    int log2_ref_pic_gap_length;           // ue(v)
> -
> -    int max_num_tid0_ref_pics; // ue(v)
> -
> -    int sps_max_dec_pic_buffering_minus1; // ue(v)
> -    int long_term_ref_pic_flag;           // u(1)
> -    int rpl1_same_as_rpl0_flag;           // u(1)
> -    int num_ref_pic_list_in_sps[2];       // ue(v)
> -    struct RefPicListStruct rpls[2][EVC_MAX_NUM_RPLS];
> -
> -    int picture_cropping_flag;      // u(1)
> -    int picture_crop_left_offset;   // ue(v)
> -    int picture_crop_right_offset;  // ue(v)
> -    int picture_crop_top_offset;    // ue(v)
> -    int picture_crop_bottom_offset; // ue(v)
> -
> -    struct ChromaQpTable chroma_qp_table_struct;
> -
> -    int vui_parameters_present_flag;    // u(1)
> -
> -    struct VUIParameters vui_parameters;
> -
> -} EVCParserSPS;
> -
> -typedef struct EVCParserPPS {
> -    int pps_pic_parameter_set_id;                           // ue(v)
> -    int pps_seq_parameter_set_id;                           // ue(v)
> -    int num_ref_idx_default_active_minus1[2];               // ue(v)
> -    int additional_lt_poc_lsb_len;                          // ue(v)
> -    int rpl1_idx_present_flag;                              // u(1)
> -    int single_tile_in_pic_flag;                            // u(1)
> -    int num_tile_columns_minus1;                            // ue(v)
> -    int num_tile_rows_minus1;                               // ue(v)
> -    int uniform_tile_spacing_flag;                          // u(1)
> -    int tile_column_width_minus1[EVC_MAX_TILE_ROWS];        // ue(v)
> -    int tile_row_height_minus1[EVC_MAX_TILE_COLUMNS];          // ue(v)
> -    int loop_filter_across_tiles_enabled_flag;              // u(1)
> -    int tile_offset_len_minus1;                             // ue(v)
> -    int tile_id_len_minus1;                                 // ue(v)
> -    int explicit_tile_id_flag;                              // u(1)
> -    int tile_id_val[EVC_MAX_TILE_ROWS][EVC_MAX_TILE_COLUMNS];  // u(v)
> -    int pic_dra_enabled_flag;                               // u(1)
> -    int pic_dra_aps_id;                                     // u(5)
> -    int arbitrary_slice_present_flag;                       // u(1)
> -    int constrained_intra_pred_flag;                        // u(1)
> -    int cu_qp_delta_enabled_flag;                           // u(1)
> -    int log2_cu_qp_delta_area_minus6;                       // ue(v)
> -
> -} EVCParserPPS;
> +#include "evc_ps.h"
> 
>  // The sturcture reflects Slice Header RBSP(raw byte sequence payload)
layout
>  // @see ISO_IEC_23094-1 section 7.3.2.6
> @@ -265,10 +82,7 @@ typedef struct EVCParserPoc {
>  } EVCParserPoc;
> 
>  typedef struct EVCParserContext {
> -    //ParseContext pc;
> -    EVCParserSPS *sps[EVC_MAX_SPS_COUNT];
> -    EVCParserPPS *pps[EVC_MAX_PPS_COUNT];
> -
> +    EVCParamSets ps;
>      EVCParserPoc poc;
> 
>      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
>  // nuh_temporal_id specifies a temporal identifier for the NAL unit
>  int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void
*logctx);
> 
> -// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
> -EVCParserSPS *ff_evc_parse_sps(EVCParserContext *ctx, const uint8_t *bs,
int
> bs_size);
> -
> -// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
> -EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs,
int
> bs_size);
> -
>  int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int
> buf_size, void *logctx);
> 
> -void ff_evc_parse_free(EVCParserContext *ctx);
> -
>  #endif /* AVCODEC_EVC_PARSE_H */
> diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
> index c85b8f89e7..1fd8aac1dc 100644
> --- a/libavcodec/evc_parser.c
> +++ b/libavcodec/evc_parser.c
> @@ -202,7 +202,7 @@ static void evc_parser_close(AVCodecParserContext *s)
>  {
>      EVCParserContext *ctx = s->priv_data;
> 
> -    ff_evc_parse_free(ctx);
> +    ff_evc_ps_free(&ctx->ps);
>  }
> 
>  const AVCodecParser ff_evc_parser = {
> diff --git a/libavcodec/evc_ps.c b/libavcodec/evc_ps.c
> new file mode 100644
> index 0000000000..af74ba46b0
> --- /dev/null
> +++ b/libavcodec/evc_ps.c
> @@ -0,0 +1,381 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
> + */
> +
> +#include "golomb.h"
> +#include "parser.h"
> +#include "evc.h"
> +#include "evc_ps.h"
> +
> +#define EXTENDED_SAR 255
> +
> +// @see ISO_IEC_23094-1 (7.3.7 Reference picture list structure syntax)
> +static int ref_pic_list_struct(GetBitContext *gb, RefPicListStruct *rpl)
> +{
> +    uint32_t delta_poc_st, strp_entry_sign_flag = 0;
> +    rpl->ref_pic_num = get_ue_golomb(gb);
> +    if (rpl->ref_pic_num > 0) {
> +        delta_poc_st = get_ue_golomb(gb);
> +
> +        rpl->ref_pics[0] = delta_poc_st;
> +        if (rpl->ref_pics[0] != 0) {
> +            strp_entry_sign_flag = get_bits(gb, 1);
> +
> +            rpl->ref_pics[0] *= 1 - (strp_entry_sign_flag << 1);
> +        }
> +    }
> +
> +    for (int i = 1; i < rpl->ref_pic_num; ++i) {
> +        delta_poc_st = get_ue_golomb(gb);
> +        if (delta_poc_st != 0)
> +            strp_entry_sign_flag = get_bits(gb, 1);
> +        rpl->ref_pics[i] = rpl->ref_pics[i - 1] + delta_poc_st * (1 -
> (strp_entry_sign_flag << 1));
> +    }
> +
> +    return 0;
> +}
> +
> +// @see  ISO_IEC_23094-1 (E.2.2 HRD parameters syntax)
> +static int hrd_parameters(GetBitContext *gb, HRDParameters *hrd)
> +{
> +    hrd->cpb_cnt_minus1 = get_ue_golomb(gb);
> +    hrd->bit_rate_scale = get_bits(gb, 4);
> +    hrd->cpb_size_scale = get_bits(gb, 4);
> +    for (int SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1;
SchedSelIdx++)
> {
> +        hrd->bit_rate_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
> +        hrd->cpb_size_value_minus1[SchedSelIdx] = get_ue_golomb(gb);
> +        hrd->cbr_flag[SchedSelIdx] = get_bits(gb, 1);
> +    }
> +    hrd->initial_cpb_removal_delay_length_minus1 = get_bits(gb, 5);
> +    hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
> +    hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5);
> +    hrd->time_offset_length = get_bits(gb, 5);
> +
> +    return 0;
> +}
> +
> +// @see  ISO_IEC_23094-1 (E.2.1 VUI parameters syntax)
> +static int vui_parameters(GetBitContext *gb, VUIParameters *vui)
> +{
> +    vui->aspect_ratio_info_present_flag = get_bits(gb, 1);
> +    if (vui->aspect_ratio_info_present_flag) {
> +        vui->aspect_ratio_idc = get_bits(gb, 8);
> +        if (vui->aspect_ratio_idc == EXTENDED_SAR) {
> +            vui->sar_width = get_bits(gb, 16);
> +            vui->sar_height = get_bits(gb, 16);
> +        }
> +    }
> +    vui->overscan_info_present_flag = get_bits(gb, 1);
> +    if (vui->overscan_info_present_flag)
> +        vui->overscan_appropriate_flag = get_bits(gb, 1);
> +    vui->video_signal_type_present_flag = get_bits(gb, 1);
> +    if (vui->video_signal_type_present_flag) {
> +        vui->video_format = get_bits(gb, 3);
> +        vui->video_full_range_flag = get_bits(gb, 1);
> +        vui->colour_description_present_flag = get_bits(gb, 1);
> +        if (vui->colour_description_present_flag) {
> +            vui->colour_primaries = get_bits(gb, 8);
> +            vui->transfer_characteristics = get_bits(gb, 8);
> +            vui->matrix_coefficients = get_bits(gb, 8);
> +        }
> +    }
> +    vui->chroma_loc_info_present_flag = get_bits(gb, 1);
> +    if (vui->chroma_loc_info_present_flag) {
> +        vui->chroma_sample_loc_type_top_field = get_ue_golomb(gb);
> +        vui->chroma_sample_loc_type_bottom_field = get_ue_golomb(gb);
> +    }
> +    vui->neutral_chroma_indication_flag = get_bits(gb, 1);
> +
> +    vui->field_seq_flag = get_bits(gb, 1);
> +
> +    vui->timing_info_present_flag = get_bits(gb, 1);
> +    if (vui->timing_info_present_flag) {
> +        vui->num_units_in_tick = get_bits(gb, 32);
> +        vui->time_scale = get_bits(gb, 32);
> +        vui->fixed_pic_rate_flag = get_bits(gb, 1);
> +    }
> +    vui->nal_hrd_parameters_present_flag = get_bits(gb, 1);
> +    if (vui->nal_hrd_parameters_present_flag)
> +        hrd_parameters(gb, &vui->hrd_parameters);
> +    vui->vcl_hrd_parameters_present_flag = get_bits(gb, 1);
> +    if (vui->vcl_hrd_parameters_present_flag)
> +        hrd_parameters(gb, &vui->hrd_parameters);
> +    if (vui->nal_hrd_parameters_present_flag || vui-
> >vcl_hrd_parameters_present_flag)
> +        vui->low_delay_hrd_flag = get_bits(gb, 1);
> +    vui->pic_struct_present_flag = get_bits(gb, 1);
> +    vui->bitstream_restriction_flag = get_bits(gb, 1);
> +    if (vui->bitstream_restriction_flag) {
> +        vui->motion_vectors_over_pic_boundaries_flag = get_bits(gb, 1);
> +        vui->max_bytes_per_pic_denom = get_ue_golomb(gb);
> +        vui->max_bits_per_mb_denom = get_ue_golomb(gb);
> +        vui->log2_max_mv_length_horizontal = get_ue_golomb(gb);
> +        vui->log2_max_mv_length_vertical = get_ue_golomb(gb);
> +        vui->num_reorder_pics = get_ue_golomb(gb);
> +        vui->max_dec_pic_buffering = get_ue_golomb(gb);
> +    }
> +
> +    return 0;
> +}
> +
> +// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
> +EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int
> bs_size)
> +{
> +    GetBitContext gb;
> +    EVCParserSPS *sps;
> +    int sps_seq_parameter_set_id;
> +
> +    if (init_get_bits8(&gb, bs, bs_size) < 0)
> +        return NULL;
> +
> +    sps_seq_parameter_set_id = get_ue_golomb(&gb);
> +
> +    if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT)
> +        return NULL;
> +
> +    if(!ps->sps[sps_seq_parameter_set_id]) {
> +        if((ps->sps[sps_seq_parameter_set_id] =
av_malloc(sizeof(EVCParserSPS)))
> == NULL)
> +            return NULL;
> +    }
> +
> +    sps = ps->sps[sps_seq_parameter_set_id];
> +    memset(sps, 0, sizeof(*sps));
> +
> +    sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id;
> +
> +    // the Baseline profile is indicated by profile_idc eqal to 0
> +    // the Main profile is indicated by profile_idc eqal to 1
> +    sps->profile_idc = get_bits(&gb, 8);
> +
> +    sps->level_idc = get_bits(&gb, 8);
> +
> +    skip_bits_long(&gb, 32); /* skip toolset_idc_h */
> +    skip_bits_long(&gb, 32); /* skip toolset_idc_l */
> +
> +    // 0 - monochrome
> +    // 1 - 4:2:0
> +    // 2 - 4:2:2
> +    // 3 - 4:4:4
> +    sps->chroma_format_idc = get_ue_golomb(&gb);
> +
> +    sps->pic_width_in_luma_samples = get_ue_golomb(&gb);
> +    sps->pic_height_in_luma_samples = get_ue_golomb(&gb);
> +
> +    sps->bit_depth_luma_minus8 = get_ue_golomb(&gb);
> +    sps->bit_depth_chroma_minus8 = get_ue_golomb(&gb);
> +
> +    sps->sps_btt_flag = get_bits(&gb, 1);
> +    if (sps->sps_btt_flag) {
> +        sps->log2_ctu_size_minus5 = get_ue_golomb(&gb);
> +        sps->log2_min_cb_size_minus2 = get_ue_golomb(&gb);
> +        sps->log2_diff_ctu_max_14_cb_size = get_ue_golomb(&gb);
> +        sps->log2_diff_ctu_max_tt_cb_size = get_ue_golomb(&gb);
> +        sps->log2_diff_min_cb_min_tt_cb_size_minus2 = get_ue_golomb(&gb);
> +    }
> +
> +    sps->sps_suco_flag = get_bits(&gb, 1);
> +    if (sps->sps_suco_flag) {
> +        sps->log2_diff_ctu_size_max_suco_cb_size = get_ue_golomb(&gb);
> +        sps->log2_diff_max_suco_min_suco_cb_size = get_ue_golomb(&gb);
> +    }
> +
> +    sps->sps_admvp_flag = get_bits(&gb, 1);
> +    if (sps->sps_admvp_flag) {
> +        sps->sps_affine_flag = get_bits(&gb, 1);
> +        sps->sps_amvr_flag = get_bits(&gb, 1);
> +        sps->sps_dmvr_flag = get_bits(&gb, 1);
> +        sps->sps_mmvd_flag = get_bits(&gb, 1);
> +        sps->sps_hmvp_flag = get_bits(&gb, 1);
> +    }
> +
> +    sps->sps_eipd_flag =  get_bits(&gb, 1);
> +    if (sps->sps_eipd_flag) {
> +        sps->sps_ibc_flag = get_bits(&gb, 1);
> +        if (sps->sps_ibc_flag)
> +            sps->log2_max_ibc_cand_size_minus2 = get_ue_golomb(&gb);
> +    }
> +
> +    sps->sps_cm_init_flag = get_bits(&gb, 1);
> +    if (sps->sps_cm_init_flag)
> +        sps->sps_adcc_flag = get_bits(&gb, 1);
> +
> +    sps->sps_iqt_flag = get_bits(&gb, 1);
> +    if (sps->sps_iqt_flag)
> +        sps->sps_ats_flag = get_bits(&gb, 1);
> +
> +    sps->sps_addb_flag = get_bits(&gb, 1);
> +    sps->sps_alf_flag = get_bits(&gb, 1);
> +    sps->sps_htdf_flag = get_bits(&gb, 1);
> +    sps->sps_rpl_flag = get_bits(&gb, 1);
> +    sps->sps_pocs_flag = get_bits(&gb, 1);
> +    sps->sps_dquant_flag = get_bits(&gb, 1);
> +    sps->sps_dra_flag = get_bits(&gb, 1);
> +
> +    if (sps->sps_pocs_flag)
> +        sps->log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb(&gb);
> +
> +    if (!sps->sps_pocs_flag || !sps->sps_rpl_flag) {
> +        sps->log2_sub_gop_length = get_ue_golomb(&gb);
> +        if (sps->log2_sub_gop_length == 0)
> +            sps->log2_ref_pic_gap_length = get_ue_golomb(&gb);
> +    }
> +
> +    if (!sps->sps_rpl_flag)
> +        sps->max_num_tid0_ref_pics = get_ue_golomb(&gb);
> +    else {
> +        sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb(&gb);
> +        sps->long_term_ref_pic_flag = get_bits(&gb, 1);
> +        sps->rpl1_same_as_rpl0_flag = get_bits(&gb, 1);
> +        sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(&gb);
> +
> +        for (int i = 0; i < sps->num_ref_pic_list_in_sps[0]; ++i)
> +            ref_pic_list_struct(&gb, &sps->rpls[0][i]);
> +
> +        if (!sps->rpl1_same_as_rpl0_flag) {
> +            sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(&gb);
> +            for (int i = 0; i < sps->num_ref_pic_list_in_sps[1]; ++i)
> +                ref_pic_list_struct(&gb, &sps->rpls[1][i]);
> +        }
> +    }
> +
> +    sps->picture_cropping_flag = get_bits(&gb, 1);
> +
> +    if (sps->picture_cropping_flag) {
> +        sps->picture_crop_left_offset = get_ue_golomb(&gb);
> +        sps->picture_crop_right_offset = get_ue_golomb(&gb);
> +        sps->picture_crop_top_offset = get_ue_golomb(&gb);
> +        sps->picture_crop_bottom_offset = get_ue_golomb(&gb);
> +    }
> +
> +    if (sps->chroma_format_idc != 0) {
> +        sps->chroma_qp_table_struct.chroma_qp_table_present_flag =
> get_bits(&gb, 1);
> +
> +        if (sps->chroma_qp_table_struct.chroma_qp_table_present_flag) {
> +            sps->chroma_qp_table_struct.same_qp_table_for_chroma =
> get_bits(&gb, 1);
> +            sps->chroma_qp_table_struct.global_offset_flag =
get_bits(&gb, 1);
> +            for (int i = 0; i < (sps-
> >chroma_qp_table_struct.same_qp_table_for_chroma ? 1 : 2); i++) {
> +
sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] =
> get_ue_golomb(&gb);;
> +                for (int j = 0; j <= sps-
> >chroma_qp_table_struct.num_points_in_qp_table_minus1[i]; j++) {
> +
sps->chroma_qp_table_struct.delta_qp_in_val_minus1[i][j] =
> get_bits(&gb, 6);
> +                    sps->chroma_qp_table_struct.delta_qp_out_val[i][j] =
> get_se_golomb(&gb);
> +                }
> +            }
> +        }
> +    }
> +
> +    sps->vui_parameters_present_flag = get_bits(&gb, 1);
> +    if (sps->vui_parameters_present_flag)
> +        vui_parameters(&gb, &(sps->vui_parameters));
> +
> +    // @note
> +    // If necessary, add the missing fields to the EVCParserSPS structure
> +    // and then extend parser implementation
> +
> +    return sps;
> +}
> +
> +// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
> +//
> +// @note
> +// The current implementation of parse_sps function doesn't handle VUI
> parameters parsing.
> +// If it will be needed, parse_sps function could be extended to handle
VUI
> parameters parsing
> +// to initialize fields of the AVCodecContex i.e. color_primaries,
> color_trc,color_range
> +//
> +EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int
> bs_size)
> +{
> +    GetBitContext gb;
> +    EVCParserPPS *pps;
> +
> +    int pps_pic_parameter_set_id;
> +
> +    if (init_get_bits8(&gb, bs, bs_size) < 0)
> +        return NULL;
> +
> +    pps_pic_parameter_set_id = get_ue_golomb(&gb);
> +    if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT)
> +        return NULL;
> +
> +    if(!ps->pps[pps_pic_parameter_set_id]) {
> +        if ((ps->pps[pps_pic_parameter_set_id] =
av_malloc(sizeof(EVCParserPPS)))
> == NULL)
> +            return NULL;
> +    }
> +
> +    pps = ps->pps[pps_pic_parameter_set_id];
> +    memset(pps, 0, sizeof(*pps));
> +
> +    pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id;
> +
> +    pps->pps_seq_parameter_set_id = get_ue_golomb(&gb);
> +    if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) {
> +        av_freep(&ps->pps[pps_pic_parameter_set_id]);
> +        return NULL;
> +    }
> +
> +    pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
> +    pps->num_ref_idx_default_active_minus1[1] = get_ue_golomb(&gb);
> +    pps->additional_lt_poc_lsb_len = get_ue_golomb(&gb);
> +    pps->rpl1_idx_present_flag = get_bits(&gb, 1);
> +    pps->single_tile_in_pic_flag = get_bits(&gb, 1);
> +
> +    if (!pps->single_tile_in_pic_flag) {
> +        pps->num_tile_columns_minus1 = get_ue_golomb(&gb);
> +        pps->num_tile_rows_minus1 = get_ue_golomb(&gb);
> +        pps->uniform_tile_spacing_flag = get_bits(&gb, 1);
> +
> +        if (!pps->uniform_tile_spacing_flag) {
> +            for (int i = 0; i < pps->num_tile_columns_minus1; i++)
> +                pps->tile_column_width_minus1[i] = get_ue_golomb(&gb);
> +
> +            for (int i = 0; i < pps->num_tile_rows_minus1; i++)
> +                pps->tile_row_height_minus1[i] = get_ue_golomb(&gb);
> +        }
> +        pps->loop_filter_across_tiles_enabled_flag = get_bits(&gb, 1);
> +        pps->tile_offset_len_minus1 = get_ue_golomb(&gb);
> +    }
> +
> +    pps->tile_id_len_minus1 = get_ue_golomb(&gb);
> +    pps->explicit_tile_id_flag = get_bits(&gb, 1);
> +
> +    if (pps->explicit_tile_id_flag) {
> +        for (int i = 0; i <= pps->num_tile_rows_minus1; i++) {
> +            for (int j = 0; j <= pps->num_tile_columns_minus1; j++)
> +                pps->tile_id_val[i][j] = get_bits(&gb,
pps->tile_id_len_minus1 + 1);
> +        }
> +    }
> +
> +    pps->pic_dra_enabled_flag = 0;
> +    pps->pic_dra_enabled_flag = get_bits(&gb, 1);
> +
> +    if (pps->pic_dra_enabled_flag)
> +        pps->pic_dra_aps_id = get_bits(&gb, 5);
> +
> +    pps->arbitrary_slice_present_flag = get_bits(&gb, 1);
> +    pps->constrained_intra_pred_flag = get_bits(&gb, 1);
> +    pps->cu_qp_delta_enabled_flag = get_bits(&gb, 1);
> +
> +    if (pps->cu_qp_delta_enabled_flag)
> +        pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(&gb);
> +
> +    return pps;
> +}
> +
> +void ff_evc_ps_free(EVCParamSets *ps) {
> +    for (int i = 0; i < EVC_MAX_SPS_COUNT; i++)
> +        av_freep(&ps->sps[i]);
> +
> +    for (int i = 0; i < EVC_MAX_PPS_COUNT; i++)
> +        av_freep(&ps->pps[i]);
> +}
> diff --git a/libavcodec/evc_ps.h b/libavcodec/evc_ps.h
> new file mode 100644
> index 0000000000..989336079f
> --- /dev/null
> +++ b/libavcodec/evc_ps.h
> @@ -0,0 +1,228 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
> + */
> +
> +/**
> + * @file
> + * EVC decoder/parser shared code
> + */
> +
> +#ifndef AVCODEC_EVC_PS_H
> +#define AVCODEC_EVC_PS_H
> +
> +#include <stdint.h>
> +
> +#include "evc.h"
> +
> +#define EVC_MAX_QP_TABLE_SIZE   58
> +#define NUM_CPB                 32
> +
> +// rpl structure
> +typedef struct RefPicListStruct {
> +    int poc;
> +    int tid;
> +    int ref_pic_num;
> +    int ref_pic_active_num;
> +    int ref_pics[EVC_MAX_NUM_REF_PICS];
> +    char pic_type;
> +
> +} RefPicListStruct;
> +
> +// chromaQP table structure to be signalled in SPS
> +typedef struct ChromaQpTable {
> +    int chroma_qp_table_present_flag;       // u(1)
> +    int same_qp_table_for_chroma;           // u(1)
> +    int global_offset_flag;                 // u(1)
> +    int num_points_in_qp_table_minus1[2];   // ue(v)
> +    int delta_qp_in_val_minus1[2][EVC_MAX_QP_TABLE_SIZE];   // u(6)
> +    int delta_qp_out_val[2][EVC_MAX_QP_TABLE_SIZE];         // se(v)
> +} ChromaQpTable;
> +
> +// Hypothetical Reference Decoder (HRD) parameters, part of VUI
> +typedef struct HRDParameters {
> +    int cpb_cnt_minus1;                             // ue(v)
> +    int bit_rate_scale;                             // u(4)
> +    int cpb_size_scale;                             // u(4)
> +    int bit_rate_value_minus1[NUM_CPB];             // ue(v)
> +    int cpb_size_value_minus1[NUM_CPB];             // ue(v)
> +    int cbr_flag[NUM_CPB];                          // u(1)
> +    int initial_cpb_removal_delay_length_minus1;    // u(5)
> +    int cpb_removal_delay_length_minus1;            // u(5)
> +    int dpb_output_delay_length_minus1;             // u(5)
> +    int time_offset_length;                         // u(5)
> +} HRDParameters;
> +
> +// video usability information (VUI) part of SPS
> +typedef struct VUIParameters {
> +    int aspect_ratio_info_present_flag;             // u(1)
> +    int aspect_ratio_idc;                           // u(8)
> +    int sar_width;                                  // u(16)
> +    int sar_height;                                 // u(16)
> +    int overscan_info_present_flag;                 // u(1)
> +    int overscan_appropriate_flag;                  // u(1)
> +    int video_signal_type_present_flag;             // u(1)
> +    int video_format;                               // u(3)
> +    int video_full_range_flag;                      // u(1)
> +    int colour_description_present_flag;            // u(1)
> +    int colour_primaries;                           // u(8)
> +    int transfer_characteristics;                   // u(8)
> +    int matrix_coefficients;                        // u(8)
> +    int chroma_loc_info_present_flag;               // u(1)
> +    int chroma_sample_loc_type_top_field;           // ue(v)
> +    int chroma_sample_loc_type_bottom_field;        // ue(v)
> +    int neutral_chroma_indication_flag;             // u(1)
> +    int field_seq_flag;                             // u(1)
> +    int timing_info_present_flag;                   // u(1)
> +    int num_units_in_tick;                          // u(32)
> +    int time_scale;                                 // u(32)
> +    int fixed_pic_rate_flag;                        // u(1)
> +    int nal_hrd_parameters_present_flag;            // u(1)
> +    int vcl_hrd_parameters_present_flag;            // u(1)
> +    int low_delay_hrd_flag;                         // u(1)
> +    int pic_struct_present_flag;                    // u(1)
> +    int bitstream_restriction_flag;                 // u(1)
> +    int motion_vectors_over_pic_boundaries_flag;    // u(1)
> +    int max_bytes_per_pic_denom;                    // ue(v)
> +    int max_bits_per_mb_denom;                      // ue(v)
> +    int log2_max_mv_length_horizontal;              // ue(v)
> +    int log2_max_mv_length_vertical;                // ue(v)
> +    int num_reorder_pics;                           // ue(v)
> +    int max_dec_pic_buffering;                      // ue(v)
> +
> +    HRDParameters hrd_parameters;
> +} VUIParameters;
> +
> +// The sturcture reflects SPS RBSP(raw byte sequence payload) layout
> +// @see ISO_IEC_23094-1 section 7.3.2.1
> +//
> +// The following descriptors specify the parsing process of each element
> +// u(n) - unsigned integer using n bits
> +// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element
with
> the left bit first
> +typedef struct EVCParserSPS {
> +    int sps_seq_parameter_set_id;   // ue(v)
> +    int profile_idc;                // u(8)
> +    int level_idc;                  // u(8)
> +    int toolset_idc_h;              // u(32)
> +    int toolset_idc_l;              // u(32)
> +    int chroma_format_idc;          // ue(v)
> +    int pic_width_in_luma_samples;  // ue(v)
> +    int pic_height_in_luma_samples; // ue(v)
> +    int bit_depth_luma_minus8;      // ue(v)
> +    int bit_depth_chroma_minus8;    // ue(v)
> +
> +    int sps_btt_flag;                           // u(1)
> +    int log2_ctu_size_minus5;                   // ue(v)
> +    int log2_min_cb_size_minus2;                // ue(v)
> +    int log2_diff_ctu_max_14_cb_size;           // ue(v)
> +    int log2_diff_ctu_max_tt_cb_size;           // ue(v)
> +    int log2_diff_min_cb_min_tt_cb_size_minus2; // ue(v)
> +
> +    int sps_suco_flag;                       // u(1)
> +    int log2_diff_ctu_size_max_suco_cb_size; // ue(v)
> +    int log2_diff_max_suco_min_suco_cb_size; // ue(v)
> +
> +    int sps_admvp_flag;     // u(1)
> +    int sps_affine_flag;    // u(1)
> +    int sps_amvr_flag;      // u(1)
> +    int sps_dmvr_flag;      // u(1)
> +    int sps_mmvd_flag;      // u(1)
> +    int sps_hmvp_flag;      // u(1)
> +
> +    int sps_eipd_flag;                 // u(1)
> +    int sps_ibc_flag;                  // u(1)
> +    int log2_max_ibc_cand_size_minus2; // ue(v)
> +
> +    int sps_cm_init_flag; // u(1)
> +    int sps_adcc_flag;    // u(1)
> +
> +    int sps_iqt_flag; // u(1)
> +    int sps_ats_flag; // u(1)
> +
> +    int sps_addb_flag;   // u(1)
> +    int sps_alf_flag;    // u(1)
> +    int sps_htdf_flag;   // u(1)
> +    int sps_rpl_flag;    // u(1)
> +    int sps_pocs_flag;   // u(1)
> +    int sps_dquant_flag; // u(1)
> +    int sps_dra_flag;    // u(1)
> +
> +    int log2_max_pic_order_cnt_lsb_minus4; // ue(v)
> +    int log2_sub_gop_length;               // ue(v)
> +    int log2_ref_pic_gap_length;           // ue(v)
> +
> +    int max_num_tid0_ref_pics; // ue(v)
> +
> +    int sps_max_dec_pic_buffering_minus1; // ue(v)
> +    int long_term_ref_pic_flag;           // u(1)
> +    int rpl1_same_as_rpl0_flag;           // u(1)
> +    int num_ref_pic_list_in_sps[2];       // ue(v)
> +    struct RefPicListStruct rpls[2][EVC_MAX_NUM_RPLS];
> +
> +    int picture_cropping_flag;      // u(1)
> +    int picture_crop_left_offset;   // ue(v)
> +    int picture_crop_right_offset;  // ue(v)
> +    int picture_crop_top_offset;    // ue(v)
> +    int picture_crop_bottom_offset; // ue(v)
> +
> +    struct ChromaQpTable chroma_qp_table_struct;
> +
> +    int vui_parameters_present_flag;    // u(1)
> +
> +    struct VUIParameters vui_parameters;
> +
> +} EVCParserSPS;
> +
> +typedef struct EVCParserPPS {
> +    int pps_pic_parameter_set_id;                           // ue(v)
> +    int pps_seq_parameter_set_id;                           // ue(v)
> +    int num_ref_idx_default_active_minus1[2];               // ue(v)
> +    int additional_lt_poc_lsb_len;                          // ue(v)
> +    int rpl1_idx_present_flag;                              // u(1)
> +    int single_tile_in_pic_flag;                            // u(1)
> +    int num_tile_columns_minus1;                            // ue(v)
> +    int num_tile_rows_minus1;                               // ue(v)
> +    int uniform_tile_spacing_flag;                          // u(1)
> +    int tile_column_width_minus1[EVC_MAX_TILE_ROWS];        // ue(v)
> +    int tile_row_height_minus1[EVC_MAX_TILE_COLUMNS];          // ue(v)
> +    int loop_filter_across_tiles_enabled_flag;              // u(1)
> +    int tile_offset_len_minus1;                             // ue(v)
> +    int tile_id_len_minus1;                                 // ue(v)
> +    int explicit_tile_id_flag;                              // u(1)
> +    int tile_id_val[EVC_MAX_TILE_ROWS][EVC_MAX_TILE_COLUMNS];  // u(v)
> +    int pic_dra_enabled_flag;                               // u(1)
> +    int pic_dra_aps_id;                                     // u(5)
> +    int arbitrary_slice_present_flag;                       // u(1)
> +    int constrained_intra_pred_flag;                        // u(1)
> +    int cu_qp_delta_enabled_flag;                           // u(1)
> +    int log2_cu_qp_delta_area_minus6;                       // ue(v)
> +
> +} EVCParserPPS;
> +
> +typedef struct EVCParamSets {
> +    EVCParserSPS *sps[EVC_MAX_SPS_COUNT];
> +    EVCParserPPS *pps[EVC_MAX_PPS_COUNT];
> +} EVCParamSets;
> +
> +// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
> +EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int
> bs_size);
> +
> +// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
> +EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int
> bs_size);
> +
> +void ff_evc_ps_free(EVCParamSets *ps);
> +
> +#endif /* AVCODEC_EVC_PS_H */
> --
> 2.41.0
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://protect2.fireeye.com/v1/url?k=8708fc5b-d894d571-87097714-
> 000babe598f7-a29b47b5c273342b&q=1&e=f39a2fa5-9fa0-43a4-8767-
> 4e4532bab712&u=https%3A%2F%2Fffmpeg.org%2Fmailman%2Flistinfo%2Fffmp
> eg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [FFmpeg-devel] [PATCH 04/10] avcodec/evc_parse: split off Parameter Set parsing into its own file
  2023-06-20  7:37   ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics
@ 2023-06-20 11:37     ` James Almer
  0 siblings, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-20 11:37 UTC (permalink / raw)
  To: ffmpeg-devel

On 6/20/2023 4:37 AM, Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff 
Engineer/Samsung Electronics wrote:
> Why have you split off the parameter set parsing into its own file? Just
> asking what's the reason.
I copied the design from h264. Smaller source files are better than 
monolith ones. And an eventual native decoder will benefit from this 
being already in place.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [FFmpeg-devel] [PATCH 11/17] avformat/evc: don't use an AVIOContext as log context
  2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 11/17] avformat/evc: don't use an AVIOContext as log context James Almer
  2023-06-19 21:11   ` [FFmpeg-devel] [PATCH 11/17 v2] " James Almer
@ 2023-06-20 14:38   ` James Almer
  1 sibling, 0 replies; 25+ messages in thread
From: James Almer @ 2023-06-20 14:38 UTC (permalink / raw)
  To: ffmpeg-devel

On 6/18/2023 8:43 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   libavcodec/evc_parse.h | 3 ++-
>   libavformat/evc.c      | 4 ++--
>   2 files changed, 4 insertions(+), 3 deletions(-)

Dropped patches 11 and 12, pushed patches 13 to 17.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2023-06-20 14:38 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
2023-06-17 15:18 ` [FFmpeg-devel] [PATCH 2/3] avcodec/evc_frame_merge_bsf: use av_new_packet() James Almer
2023-06-17 15:18 ` [FFmpeg-devel] [PATCH 3/3] fate/lavf-container: add a test to remux raw evc into mp4 James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 04/10] avcodec/evc_parse: split off Parameter Set parsing into its own file James Almer
2023-06-20  7:37   ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics
2023-06-20 11:37     ` James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 05/10] avcodec/evc_parser: stop exporting delay and gop_size James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 06/10] avcodec/evc_parse: split off deriving PoC James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 07/10] avcodec/evc_parser: make ff_evc_parse_nal_unit() local to the parser James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 08/10] avcodec/evc_parser: remove write only variable James Almer
2023-06-18 12:04   ` Paul B Mahol
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 09/10] avcodec/evc_frame_merge_bsf: make ff_evc_parse_nal_unit() local to the filter James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 10/10] avcodec/evc_parse: remove ff_evc_parse_nal_unit() James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 11/17] avformat/evc: don't use an AVIOContext as log context James Almer
2023-06-19 21:11   ` [FFmpeg-devel] [PATCH 11/17 v2] " James Almer
2023-06-20 14:38   ` [FFmpeg-devel] [PATCH 11/17] " James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 12/17] avformat/evcdec: deduplicate nalu length and type parsing functions James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 13/17] avformat/evcdec: simplify probe function James Almer
2023-06-19 20:29   ` Michael Niedermayer
2023-06-19 20:42     ` James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 14/17] avformat/evcdec: simplify au_end_found check James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 15/17] avformat/evcdec: don't set AVCodecParameters.framerate James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 16/17] avcodec/evc_ps: make ff_evc_parse_{sps, pps} return an error code James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 17/17] avcodec/evc_ps: Check log2_sub_gop_length James Almer
2023-06-19 18:28 ` [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git