Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 16/17] avcodec/evc_ps: make ff_evc_parse_{sps, pps} return an error code
Date: Sun, 18 Jun 2023 20:43:31 -0300
Message-ID: <20230618234332.1370-6-jamrial@gmail.com> (raw)
In-Reply-To: <20230617151848.1378-1-jamrial@gmail.com>

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".

  parent reply	other threads:[~2023-06-18 23:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` James Almer [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230618234332.1370-6-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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