[FFmpeg-cvslog] avcodec/libaomenc: use av_fast_realloc() to resize the stats buffer
James Almer
git at videolan.org
Wed Aug 24 21:24:37 EEST 2022
ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Tue Aug 23 20:32:33 2022 -0300| [22514527d316f3ed184301d4694d4d028e2a362e] | committer: James Almer
avcodec/libaomenc: use av_fast_realloc() to resize the stats buffer
Reviewed-by: James Zern <jzern at google.com>
Signed-off-by: James Almer <jamrial at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=22514527d316f3ed184301d4694d4d028e2a362e
---
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;
More information about the ffmpeg-cvslog
mailing list