From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 05/11] avcodec/evc_parse: use a local EVCParserSliceHeader when parsing slices Date: Thu, 15 Jun 2023 12:18:29 -0300 Message-ID: <20230615151836.50535-5-jamrial@gmail.com> (raw) In-Reply-To: <20230615151836.50535-1-jamrial@gmail.com> There's no need to store EVC_MAX_PPS_COUNT amount of slice headers in EVCParserContext. Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/evc_parse.c | 50 +++++++++++++++++------------------------ libavcodec/evc_parse.h | 4 ---- libavcodec/evc_parser.c | 2 -- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c index f8a4ca3e07..71e2605281 100644 --- a/libavcodec/evc_parse.c +++ b/libavcodec/evc_parse.c @@ -419,40 +419,33 @@ EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs, int bs_ } // @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax) -EVCParserSliceHeader *ff_evc_parse_slice_header(EVCParserContext *ctx, const uint8_t *bs, int bs_size) +static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *sh, const uint8_t *bs, int bs_size) { GetBitContext gb; - EVCParserSliceHeader *sh; EVCParserPPS *pps; EVCParserSPS *sps; int num_tiles_in_slice = 0; int slice_pic_parameter_set_id; + int ret; - if (init_get_bits8(&gb, bs, bs_size) < 0) - return NULL; + if ((ret = init_get_bits8(&gb, bs, bs_size)) < 0) + return ret; slice_pic_parameter_set_id = get_ue_golomb(&gb); if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT) - return NULL; - - if(!ctx->slice_header[slice_pic_parameter_set_id]) { - if((ctx->slice_header[slice_pic_parameter_set_id] = av_malloc(sizeof(EVCParserSliceHeader))) == NULL) - return NULL; - } - - sh = ctx->slice_header[slice_pic_parameter_set_id]; - memset(sh, 0, sizeof(*sh)); + return AVERROR_INVALIDDATA; pps = ctx->pps[slice_pic_parameter_set_id]; if(!pps) - return NULL; + return AVERROR_INVALIDDATA; sps = ctx->sps[slice_pic_parameter_set_id]; if(!sps) - return NULL; + return AVERROR_INVALIDDATA; + memset(sh, 0, sizeof(*sh)); sh->slice_pic_parameter_set_id = slice_pic_parameter_set_id; if (!pps->single_tile_in_pic_flag) { @@ -540,7 +533,7 @@ EVCParserSliceHeader *ff_evc_parse_slice_header(EVCParserContext *ctx, const uin // If necessary, add the missing fields to the EVCParserSliceHeader structure // and then extend parser implementation - return sh; + return 0; } int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx) @@ -660,17 +653,17 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz break; case EVC_IDR_NUT: // Coded slice of a IDR or non-IDR picture case EVC_NOIDR_NUT: { - EVCParserSliceHeader *sh; + EVCParserSliceHeader sh; EVCParserSPS *sps; - int slice_pic_parameter_set_id; + int ret; - sh = ff_evc_parse_slice_header(ctx, data, nalu_size); - if (!sh) { + ret = evc_parse_slice_header(ctx, &sh, data, nalu_size); + if (ret < 0) { av_log(logctx, AV_LOG_ERROR, "Slice header parsing error\n"); - return AVERROR_INVALIDDATA; + return ret; } - switch (sh->slice_type) { + switch (sh.slice_type) { case EVC_SLICE_TYPE_B: { ctx->pict_type = AV_PICTURE_TYPE_B; break; @@ -692,8 +685,7 @@ 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 - slice_pic_parameter_set_id = sh->slice_pic_parameter_set_id; - sps = ctx->sps[slice_pic_parameter_set_id]; + sps = ctx->sps[sh.slice_pic_parameter_set_id]; if (sps && sps->sps_pocs_flag) { @@ -709,20 +701,20 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz int prevPicOrderCntMsb = ctx->poc.PicOrderCntVal - prevPicOrderCntLsb; - if ((sh->slice_pic_order_cnt_lsb < prevPicOrderCntLsb) && - ((prevPicOrderCntLsb - sh->slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2))) + 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))) + 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; + ctx->poc.PicOrderCntVal = PicOrderCntMsb + sh.slice_pic_order_cnt_lsb; } else { if (nalu_type == EVC_IDR_NUT) { diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h index d74a3b5159..1c1b8ec093 100644 --- a/libavcodec/evc_parse.h +++ b/libavcodec/evc_parse.h @@ -261,7 +261,6 @@ typedef struct EVCParserContext { //ParseContext pc; EVCParserSPS *sps[EVC_MAX_SPS_COUNT]; EVCParserPPS *pps[EVC_MAX_PPS_COUNT]; - EVCParserSliceHeader *slice_header[EVC_MAX_PPS_COUNT]; EVCParserPoc poc; @@ -349,9 +348,6 @@ EVCParserSPS *ff_evc_parse_sps(EVCParserContext *ctx, const uint8_t *bs, int bs_ // @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); -// @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax) -EVCParserSliceHeader *ff_evc_parse_slice_header(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); #endif /* AVCODEC_EVC_PARSE_H */ diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c index 5feb673b04..072fe41bf1 100644 --- a/libavcodec/evc_parser.c +++ b/libavcodec/evc_parser.c @@ -209,10 +209,8 @@ static void evc_parser_close(AVCodecParserContext *s) for(int i = 0; i < EVC_MAX_PPS_COUNT; i++) { EVCParserPPS *pps = ctx->pps[i]; - EVCParserSliceHeader *sh = ctx->slice_header[i]; av_freep(&pps); - av_freep(&sh); } } -- 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".
next prev parent reply other threads:[~2023-06-15 15:19 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-06-15 15:18 [FFmpeg-devel] [PATCH 01/11] avformat/evcdec: set the demuxer as AVFMT_NOTIMESTAMPS James Almer 2023-06-15 15:18 ` [FFmpeg-devel] [PATCH 02/11] avcodec/evc_parser: remove superfluous memset calls James Almer 2023-06-15 15:19 ` Paul B Mahol 2023-06-15 15:18 ` [FFmpeg-devel] [PATCH 03/11] avcodec/evc_parser: export framerate to the AVCodecContext James Almer 2023-06-15 15:18 ` [FFmpeg-devel] [PATCH 04/11] avcodec/evc_parse: zero sps, pps and sh structs James Almer 2023-06-15 15:18 ` James Almer [this message] 2023-06-15 15:18 ` [FFmpeg-devel] [PATCH 06/11] avcodec/evc_parse: use the correct struct size when allocating pps James Almer 2023-06-15 15:20 ` Paul B Mahol 2023-06-15 15:18 ` [FFmpeg-devel] [PATCH 07/11] avcodec/evc_parse: use the correct sps when parsing slice headers James Almer 2023-06-15 15:18 ` [FFmpeg-devel] [PATCH 08/11] avcodec/evc_parse: free pps struct on parsing failure James Almer 2023-06-15 15:18 ` [FFmpeg-devel] [PATCH 09/11] avcodec/evc_parse: make freeing EVCParserContext buffers a shared function James Almer 2023-06-15 15:18 ` [FFmpeg-devel] [PATCH 10/11] avcodec/evc_frame_merge_bsf: ceck for av_memdup() failure James Almer 2023-06-15 15:18 ` [FFmpeg-devel] [PATCH 11/11] avcodec/evc_frame_merge_bsf: free EVCFMergeContext on flush and close James Almer 2023-06-16 18:07 ` [FFmpeg-devel] [PATCH 01/11] avformat/evcdec: set the demuxer as AVFMT_NOTIMESTAMPS 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=20230615151836.50535-5-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