From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/libaomenc: use av_fast_realloc() to resize the stats buffer Date: Tue, 23 Aug 2022 20:34:18 -0300 Message-ID: <20220823233418.2367-2-jamrial@gmail.com> (raw) In-Reply-To: <20220823233418.2367-1-jamrial@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/libaomenc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index 1fd69d59a7..485f554165 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -70,6 +70,7 @@ typedef struct AOMEncoderContext { struct aom_codec_ctx encoder; struct aom_image rawimg; struct aom_fixed_buf twopass_stats; + unsigned twopass_stats_size; struct FrameListData *coded_frame_list; int cpu_used; int auto_alt_ref; @@ -1200,14 +1201,17 @@ static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out) case AOM_CODEC_STATS_PKT: { struct aom_fixed_buf *stats = &ctx->twopass_stats; - int err; - if ((err = av_reallocp(&stats->buf, - stats->sz + - pkt->data.twopass_stats.sz)) < 0) { + uint8_t *tmp = av_fast_realloc(stats->buf, + &ctx->twopass_stats_size, + stats->sz + + pkt->data.twopass_stats.sz); + if (!tmp) { + av_freep(&stats->buf); stats->sz = 0; av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n"); - return err; + return AVERROR(ENOMEM); } + stats->buf = tmp; memcpy((uint8_t *)stats->buf + stats->sz, pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz); stats->sz += pkt->data.twopass_stats.sz; -- 2.37.2 _______________________________________________ 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:[~2022-08-23 23:34 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-08-23 23:34 [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: " James Almer 2022-08-23 23:34 ` James Almer [this message] 2022-08-24 18:00 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libaomenc: " James Zern 2022-08-24 17:59 ` [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: " James Zern
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=20220823233418.2367-2-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