You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avcodec/libvpxenc: use av_fast_realloc() to resize the stats buffer
Reviewed-by: James Zern <jzern@google.com> Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@@ -80,6 +80,7 @@ typedef struct VPxEncoderContext {
|
|||||||
struct vpx_image rawimg_alpha;
|
struct vpx_image rawimg_alpha;
|
||||||
uint8_t is_alpha;
|
uint8_t is_alpha;
|
||||||
struct vpx_fixed_buf twopass_stats;
|
struct vpx_fixed_buf twopass_stats;
|
||||||
|
unsigned twopass_stats_size;
|
||||||
int deadline; //i.e., RT/GOOD/BEST
|
int deadline; //i.e., RT/GOOD/BEST
|
||||||
uint64_t sse[4];
|
uint64_t sse[4];
|
||||||
int have_sse; /**< true if we have pending sse[] */
|
int have_sse; /**< true if we have pending sse[] */
|
||||||
@@ -1356,16 +1357,20 @@ static int queue_frames(AVCodecContext *avctx, struct vpx_codec_ctx *encoder,
|
|||||||
break;
|
break;
|
||||||
case VPX_CODEC_STATS_PKT: {
|
case VPX_CODEC_STATS_PKT: {
|
||||||
struct vpx_fixed_buf *stats = &ctx->twopass_stats;
|
struct vpx_fixed_buf *stats = &ctx->twopass_stats;
|
||||||
int err;
|
uint8_t *tmp;
|
||||||
if (!pkt_out)
|
if (!pkt_out)
|
||||||
break;
|
break;
|
||||||
if ((err = av_reallocp(&stats->buf,
|
tmp = av_fast_realloc(stats->buf,
|
||||||
|
&ctx->twopass_stats_size,
|
||||||
stats->sz +
|
stats->sz +
|
||||||
pkt->data.twopass_stats.sz)) < 0) {
|
pkt->data.twopass_stats.sz);
|
||||||
|
if (!tmp) {
|
||||||
|
av_freep(&stats->buf);
|
||||||
stats->sz = 0;
|
stats->sz = 0;
|
||||||
av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
|
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,
|
memcpy((uint8_t*)stats->buf + stats->sz,
|
||||||
pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
|
pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
|
||||||
stats->sz += pkt->data.twopass_stats.sz;
|
stats->sz += pkt->data.twopass_stats.sz;
|
||||||
|
Reference in New Issue
Block a user