From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 109B1467E3 for ; Sun, 18 Jun 2023 23:44:39 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 43F3368BF89; Mon, 19 Jun 2023 02:44:00 +0300 (EEST) Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6F69768BF4D for ; Mon, 19 Jun 2023 02:43:53 +0300 (EEST) Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-39e8a7701f0so1880733b6e.3 for ; Sun, 18 Jun 2023 16:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687131832; x=1689723832; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=WGa0gO1KccuQGzI2YmoFFmwKG5mcyXy6/7e7K+q6t8s=; b=EVIilB44Ig9aubHWZja4alGCiFR1kxMG5iOQmBNj45g/2ZXf5CW0EdaO2mzgdnioF/ j7d6gJgrhdGstL3B6o7M0Ptbim5J1PpD6X4MMSwtl8tfRQvYnNOAwYd7b0uQX+j7qq6A 2TR7yiglj6ycFrgfX7LSad4nhciaj0ldTKHn26urxU0K29rMmNpP5HMMfpfUB6vVnXwT 545/IMh6LNA67FaaTnnduqPBonPCfp6pVJ/JhzuCz5cJJwfEfzaoNr+//suh6KwwH79j A/oeWscFephoO6kEp3t6XBh3Z7GWUadf7c7eG06mWu0EC8aaJPE3ojgGS81xsUzPZiPY NpUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687131832; x=1689723832; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WGa0gO1KccuQGzI2YmoFFmwKG5mcyXy6/7e7K+q6t8s=; b=lGgRMHta7A4+tjL7v1P8mKssZI1qd+XYVupIZefGuhk3pspyo/oMiuUpQ5t6j4pKGm BV/c+lbYlVoy/xy+K60f/5Ls6wvvNEuG5diRReD7W1pDyxOluNHISm/y5CxfZo8Oj97G mmtO5ncn/ThQmiyIxGZgV46qbVQdc1nYYfSXKSAzP9pXVVvEtzaeYRldLvlLf3by67oJ xqT44AZbfEizT28XYjVe65GXPTMovCTGKBaNY98pKxOTwuycbn/wAtnwmU99A4Wn0E6v 1r3Q2MbNpCreiF0Ok/i52FOwPKj7VO60+RHIaoWDjGDiw2Rvc/xw0NttYNg9OrGPhZyy HZzQ== X-Gm-Message-State: AC+VfDzrDJ/kkcqIpGvBAaYUC4GV1cCRKPoa73fWeuc5U3d/WL1Osn3b 9c6TOKkYkS3+mrUM9cJ6UP3tZkAlEK8= X-Google-Smtp-Source: ACHHUZ4u6qMTauvMjuq6SpA5MDwMU4+z2C7J/MiI4d+YBLQGEcF3QeDVdZsU3s7qDqx75yWdEqS22w== X-Received: by 2002:a05:6808:1a28:b0:39e:ce3a:70df with SMTP id bk40-20020a0568081a2800b0039ece3a70dfmr1911616oib.8.1687131831714; Sun, 18 Jun 2023 16:43:51 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id bk36-20020a0568081a2400b0039eb5f4543csm2069664oib.34.2023.06.18.16.43.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jun 2023 16:43:51 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Jun 2023 20:43:31 -0300 Message-ID: <20230618234332.1370-6-jamrial@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230617151848.1378-1-jamrial@gmail.com> References: <20230617151848.1378-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/17] avcodec/evc_ps: make ff_evc_parse_{sps, pps} return an error code X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: James Almer --- 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".