diff options
author | Michael Niedermayer | 2015-07-27 19:36:16 +0200 |
---|---|---|
committer | Michael Niedermayer | 2015-07-27 19:57:52 +0200 |
commit | e36db49b7b31cb17912895cb4d95b7b45d6f0882 (patch) | |
tree | e8cb205407627584f9d9eb6563a02dac3c4cfbd8 | |
parent | 59216e0525a58714be4207be6ae8744750e62867 (diff) |
avcodec: Add a min size parameter to ff_alloc_packet2()
This parameter can be used to inform the allocation code about how much
downsizing might occur, and can be used to optimize how to allocate the
packet
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
89 files changed, 96 insertions, 92 deletions
diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c index 4cd7e8b599..ceb7dcaff7 100644 --- a/libavcodec/a64multienc.c +++ b/libavcodec/a64multienc.c @@ -328,7 +328,7 @@ static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt, /* any frames to encode? */ if (c->mc_lifetime) { int alloc_size = charset_size + c->mc_lifetime*(screen_size + colram_size); - if ((ret = ff_alloc_packet2(avctx, pkt, alloc_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, alloc_size, 0)) < 0) return ret; buf = pkt->data; diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index c3c72aff31..e82f7b5bfa 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -652,7 +652,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } start_ch += chans; } - if ((ret = ff_alloc_packet2(avctx, avpkt, 8192 * s->channels)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, 8192 * s->channels, 0)) < 0) return ret; do { int frame_bits; diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c index c3ad76f429..9dec9ae9cf 100644 --- a/libavcodec/ac3enc_template.c +++ b/libavcodec/ac3enc_template.c @@ -438,7 +438,7 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt, ff_ac3_quantize_mantissas(s); - if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size, 0)) < 0) return ret; ff_ac3_output_frame(s, avpkt->data); diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 50872c3e46..e671358331 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -486,7 +486,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, pkt_size = (2 + avctx->channels * (22 + 4 * (frame->nb_samples - 1)) + 7) / 8; else pkt_size = avctx->block_align; - if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size, 0)) < 0) return ret; dst = avpkt->data; diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c index 7736d09b56..f1ba5911b3 100644 --- a/libavcodec/adxenc.c +++ b/libavcodec/adxenc.c @@ -146,7 +146,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int ch, out_size, ret; out_size = BLOCK_SIZE * avctx->channels + !c->header_parsed * HEADER_SIZE; - if ((ret = ff_alloc_packet2(avctx, avpkt, out_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, out_size, 0)) < 0) return ret; dst = avpkt->data; diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c index ce63da6637..43932400b2 100644 --- a/libavcodec/alacenc.c +++ b/libavcodec/alacenc.c @@ -618,7 +618,7 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, else max_frame_size = s->max_coded_frame_size; - if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * max_frame_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * max_frame_size, 0)) < 0) return ret; /* use verbatim mode for compression_level 0 */ diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c index 5decde34ee..8473823807 100644 --- a/libavcodec/asvenc.c +++ b/libavcodec/asvenc.c @@ -265,7 +265,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, } if ((ret = ff_alloc_packet2(avctx, pkt, a->mb_height * a->mb_width * MAX_MB_SIZE + - FF_MIN_BUFFER_SIZE)) < 0) + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; init_put_bits(&a->pb, pkt->data, pkt->size); diff --git a/libavcodec/bmpenc.c b/libavcodec/bmpenc.c index fc72e5dedd..e829d68475 100644 --- a/libavcodec/bmpenc.c +++ b/libavcodec/bmpenc.c @@ -118,7 +118,7 @@ FF_ENABLE_DEPRECATION_WARNINGS #define SIZE_BITMAPINFOHEADER 40 hsize = SIZE_BITMAPFILEHEADER + SIZE_BITMAPINFOHEADER + (pal_entries << 2); n_bytes = n_bytes_image + hsize; - if ((ret = ff_alloc_packet2(avctx, pkt, n_bytes)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, n_bytes, 0)) < 0) return ret; buf = pkt->data; bytestream_put_byte(&buf, 'B'); // BITMAPFILEHEADER.bfType diff --git a/libavcodec/cinepakenc.c b/libavcodec/cinepakenc.c index 2931fa3bc8..0f0b8cde7a 100644 --- a/libavcodec/cinepakenc.c +++ b/libavcodec/cinepakenc.c @@ -1275,7 +1275,7 @@ static int cinepak_encode_frame(AVCodecContext *avctx, AVPacket *pkt, s->lambda = frame->quality ? frame->quality - 1 : 2 * FF_LAMBDA_SCALE; - if ((ret = ff_alloc_packet2(avctx, pkt, s->frame_buf_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, s->frame_buf_size, 0)) < 0) return ret; ret = rd_frame(s, frame, (s->curframe == 0), pkt->data, s->frame_buf_size); pkt->size = ret; diff --git a/libavcodec/cljrenc.c b/libavcodec/cljrenc.c index c672f800f6..a3718259d1 100644 --- a/libavcodec/cljrenc.c +++ b/libavcodec/cljrenc.c @@ -56,7 +56,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, return AVERROR_EXPERIMENTAL; } - if ((ret = ff_alloc_packet2(avctx, pkt, 32*avctx->height*avctx->width/4)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, 32*avctx->height*avctx->width/4, 0)) < 0) return ret; init_put_bits(&pb, pkt->data, pkt->size); diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c index c8a215c200..92b8b1ff25 100644 --- a/libavcodec/dcaenc.c +++ b/libavcodec/dcaenc.c @@ -916,7 +916,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const int32_t *samples; int ret, i; - if ((ret = ff_alloc_packet2(avctx, avpkt, c->frame_size )) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, c->frame_size , 0)) < 0) return ret; samples = (const int32_t *)frame->data[0]; diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index c099f649e4..5a6a566ca2 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -1060,7 +1060,7 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt, int offset, i, ret; uint8_t *buf; - if ((ret = ff_alloc_packet2(avctx, pkt, ctx->cid_table->frame_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, ctx->cid_table->frame_size, 0)) < 0) return ret; buf = pkt->data; diff --git a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c index 76aa0cc473..d797489213 100644 --- a/libavcodec/dpxenc.c +++ b/libavcodec/dpxenc.c @@ -195,7 +195,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, need_align = size - len; size *= avctx->height; } - if ((ret = ff_alloc_packet2(avctx, pkt, size + HEADER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, size + HEADER_SIZE, 0)) < 0) return ret; buf = pkt->data; diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c index 81cee0d372..3f9c5254f8 100644 --- a/libavcodec/dvenc.c +++ b/libavcodec/dvenc.c @@ -717,7 +717,7 @@ static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt, DVVideoContext *s = c->priv_data; int ret; - if ((ret = ff_alloc_packet2(c, pkt, s->sys->frame_size)) < 0) + if ((ret = ff_alloc_packet2(c, pkt, s->sys->frame_size, 0)) < 0) return ret; c->pix_fmt = s->sys->pix_fmt; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index af42a18608..4aab82fdfc 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -1247,7 +1247,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, if (f->version > 3) maxsize = FF_MIN_BUFFER_SIZE + avctx->width*avctx->height*3LL*4; - if ((ret = ff_alloc_packet2(avctx, pkt, maxsize)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, maxsize, 0)) < 0) return ret; ff_init_range_encoder(c, pkt->data, pkt->size); diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 29bd9999b5..d3ac1b2cf8 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -1390,7 +1390,7 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } } - if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes, 0)) < 0) return ret; out_bytes = write_frame(s, avpkt); diff --git a/libavcodec/flashsv2enc.c b/libavcodec/flashsv2enc.c index a8bcaa2467..9f048f91ef 100644 --- a/libavcodec/flashsv2enc.c +++ b/libavcodec/flashsv2enc.c @@ -854,7 +854,7 @@ static int flashsv2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, int res; int keyframe = 0; - if ((res = ff_alloc_packet2(avctx, pkt, s->frame_size + FF_MIN_BUFFER_SIZE)) < 0) + if ((res = ff_alloc_packet2(avctx, pkt, s->frame_size + FF_MIN_BUFFER_SIZE, 0)) < 0) return res; /* First frame needs to be a keyframe */ diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c index b679e289d3..69e36a36e5 100644 --- a/libavcodec/flashsvenc.c +++ b/libavcodec/flashsvenc.c @@ -238,7 +238,7 @@ static int flashsv_encode_frame(AVCodecContext *avctx, AVPacket *pkt, I_frame = 1; } - if ((res = ff_alloc_packet2(avctx, pkt, s->image_width * s->image_height * 3)) < 0) + if ((res = ff_alloc_packet2(avctx, pkt, s->image_width * s->image_height * 3, 0)) < 0) return res; pkt->size = encode_bitstream(s, p, pkt->data, pkt->size, opt_w * 16, opt_h * 16, diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c index 38432f5006..cd27fa0d74 100644 --- a/libavcodec/g722enc.c +++ b/libavcodec/g722enc.c @@ -358,7 +358,7 @@ static int g722_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int nb_samples, out_size, ret; out_size = (frame->nb_samples + 1) / 2; - if ((ret = ff_alloc_packet2(avctx, avpkt, out_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, out_size, 0)) < 0) return ret; nb_samples = frame->nb_samples - (frame->nb_samples & 1); diff --git a/libavcodec/g723_1.c b/libavcodec/g723_1.c index 66afd6af6a..1b7bdd3d10 100644 --- a/libavcodec/g723_1.c +++ b/libavcodec/g723_1.c @@ -2462,7 +2462,7 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_freep(&in_orig); in = NULL; - if ((ret = ff_alloc_packet2(avctx, avpkt, 24)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, 24, 0)) < 0) return ret; *got_packet_ptr = 1; diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 6544e32d94..ee065f4b17 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -351,7 +351,7 @@ static int g726_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int i, ret, out_size; out_size = (frame->nb_samples * c->code_size + 7) / 8; - if ((ret = ff_alloc_packet2(avctx, avpkt, out_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, out_size, 0)) < 0) return ret; init_put_bits(&pb, avpkt->data, avpkt->size); diff --git a/libavcodec/gif.c b/libavcodec/gif.c index 7ac95d26c8..1b17377037 100644 --- a/libavcodec/gif.c +++ b/libavcodec/gif.c @@ -269,7 +269,7 @@ static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const uint32_t *palette = NULL; int ret; - if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*7/5 + FF_MIN_BUFFER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*7/5 + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; outbuf_ptr = pkt->data; end = pkt->data + pkt->size; diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index ad8870936a..994b21fc1e 100644 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@ -760,7 +760,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame * const p = pict; int i, j, size = 0, ret; - if ((ret = ff_alloc_packet2(avctx, pkt, width * height * 3 * 4 + FF_MIN_BUFFER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, width * height * 3 * 4 + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; if (s->context) { diff --git a/libavcodec/internal.h b/libavcodec/internal.h index e0b40f1cc4..1a15e6b443 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -217,9 +217,13 @@ int avpriv_unlock_avformat(void); * avpkt->size is set to the specified size. * All other AVPacket fields will be reset with av_init_packet(). * @param size the minimum required packet size + * @param min_size the smallest the packet might be down sized to, can be set to + * 0, setting this roughly correctly allows the allocation code + * to choose between several allocation stragies to improve + * speed slightly. * @return non negative on success, negative error code on failure */ -int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size); +int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size); int ff_alloc_packet(AVPacket *avpkt, int size); diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c index 948255ec64..acf8e1e175 100644 --- a/libavcodec/j2kenc.c +++ b/libavcodec/j2kenc.c @@ -955,7 +955,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, Jpeg2000EncoderContext *s = avctx->priv_data; uint8_t *chunkstart, *jp2cstart, *jp2hstart; - if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + FF_MIN_BUFFER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; // init: diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c index f6ed4be364..0edad14c72 100644 --- a/libavcodec/jpeglsenc.c +++ b/libavcodec/jpeglsenc.c @@ -269,7 +269,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, comps = 3; if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width *avctx->height * comps * 4 + - FF_MIN_BUFFER_SIZE)) < 0) + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; buf2 = av_malloc(pkt->size); diff --git a/libavcodec/lclenc.c b/libavcodec/lclenc.c index 7387da4a65..7a9fa35eac 100644 --- a/libavcodec/lclenc.c +++ b/libavcodec/lclenc.c @@ -79,7 +79,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, int zret; // Zlib return code int max_size = deflateBound(&c->zstream, avctx->width * avctx->height * 3); - if ((ret = ff_alloc_packet2(avctx, pkt, max_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, max_size, 0)) < 0) return ret; if(avctx->pix_fmt != AV_PIX_FMT_BGR24){ diff --git a/libavcodec/libaacplus.c b/libavcodec/libaacplus.c index 9087d00635..64bdb5e5dd 100644 --- a/libavcodec/libaacplus.c +++ b/libavcodec/libaacplus.c @@ -101,7 +101,7 @@ static int aacPlus_encode_frame(AVCodecContext *avctx, AVPacket *pkt, int32_t *input_buffer = (int32_t *)frame->data[0]; int ret; - if ((ret = ff_alloc_packet2(avctx, pkt, s->max_output_bytes)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, s->max_output_bytes, 0)) < 0) return ret; pkt->size = aacplusEncEncode(s->aacplus_handle, input_buffer, diff --git a/libavcodec/libfaac.c b/libavcodec/libfaac.c index 69c186b11a..504629d2f5 100644 --- a/libavcodec/libfaac.c +++ b/libavcodec/libfaac.c @@ -184,7 +184,7 @@ static int Faac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int num_samples = frame ? frame->nb_samples : 0; void *samples = frame ? frame->data[0] : NULL; - if ((ret = ff_alloc_packet2(avctx, avpkt, (7 + 768) * avctx->channels)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, (7 + 768) * avctx->channels, 0)) < 0) return ret; bytes_written = faacEncEncode(s->faac_handle, samples, diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c index 3eadb36b83..f886fa9dde 100644 --- a/libavcodec/libfdk-aacenc.c +++ b/libavcodec/libfdk-aacenc.c @@ -342,7 +342,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } /* The maximum packet size is 6144 bits aka 768 bytes per channel. */ - if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels))) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels), 0)) < 0) return ret; out_ptr = avpkt->data; diff --git a/libavcodec/libgsmenc.c b/libavcodec/libgsmenc.c index b06ec6498b..45fdb8edd6 100644 --- a/libavcodec/libgsmenc.c +++ b/libavcodec/libgsmenc.c @@ -98,7 +98,7 @@ static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, gsm_signal *samples = (gsm_signal *)frame->data[0]; struct gsm_state *state = avctx->priv_data; - if ((ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align, 0)) < 0) return ret; switch(avctx->codec_id) { diff --git a/libavcodec/libilbc.c b/libavcodec/libilbc.c index 9fdd3c83f5..c1e01e14f1 100644 --- a/libavcodec/libilbc.c +++ b/libavcodec/libilbc.c @@ -166,7 +166,7 @@ static int ilbc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ILBCEncContext *s = avctx->priv_data; int ret; - if ((ret = ff_alloc_packet2(avctx, avpkt, 50)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, 50, 0)) < 0) return ret; WebRtcIlbcfix_EncodeImpl((uint16_t *) avpkt->data, (const int16_t *) frame->data[0], &s->encoder); diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index b5d50048aa..78af178f45 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -258,7 +258,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_dlog(avctx, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len, s->buffer_index); if (len <= s->buffer_index) { - if ((ret = ff_alloc_packet2(avctx, avpkt, len)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, len, 0)) < 0) return ret; memcpy(avpkt->data, s->buffer, len); s->buffer_index -= len; diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c index 556792ad77..7f0c958f60 100644 --- a/libavcodec/libopencore-amr.c +++ b/libavcodec/libopencore-amr.c @@ -236,7 +236,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, s->enc_bitrate = avctx->bit_rate; } - if ((ret = ff_alloc_packet2(avctx, avpkt, 32)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, 32, 0)) < 0) return ret; if (frame) { diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c index f48e55e164..49125157e1 100644 --- a/libavcodec/libopenjpegenc.c +++ b/libavcodec/libopenjpegenc.c @@ -579,7 +579,7 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, } len = cio_tell(stream); - if ((ret = ff_alloc_packet2(avctx, pkt, len)) < 0) { + if ((ret = ff_alloc_packet2(avctx, pkt, len, 0)) < 0) { return ret; } diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c index 785460972d..da59988516 100644 --- a/libavcodec/libopusenc.c +++ b/libavcodec/libopusenc.c @@ -335,7 +335,7 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt, /* Maximum packet size taken from opusenc in opus-tools. 60ms packets * consist of 3 frames in one packet. The maximum frame size is 1275 * bytes along with the largest possible packet header of 7 bytes. */ - if ((ret = ff_alloc_packet2(avctx, avpkt, (1275 * 3 + 7) * opus->stream_count)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, (1275 * 3 + 7) * opus->stream_count, 0)) < 0) return ret; if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) diff --git a/libavcodec/libschroedingerenc.c b/libavcodec/libschroedingerenc.c index 2d69318ee2..406022bdad 100644 --- a/libavcodec/libschroedingerenc.c +++ b/libavcodec/libschroedingerenc.c @@ -379,7 +379,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avctx, AVPacket *pkt, pkt_size = p_frame_output->size; if (last_frame_in_sequence && p_schro_params->enc_buf_size > 0) pkt_size += p_schro_params->enc_buf_size; - if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size, 0)) < 0) goto error; memcpy(pkt->data, p_frame_output->p_encbuf, p_frame_output->size); diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c index 3e4e2e9877..9554a3d9da 100644 --- a/libavcodec/libspeexenc.c +++ b/libavcodec/libspeexenc.c @@ -294,7 +294,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, /* write output if all frames for the packet have been encoded */ if (s->pkt_frame_count == s->frames_per_packet) { s->pkt_frame_count = 0; - if ((ret = ff_alloc_packet2(avctx, avpkt, speex_bits_nbytes(&s->bits))) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, speex_bits_nbytes(&s->bits), 0)) < 0) return ret; ret = speex_bits_write(&s->bits, avpkt->data, avpkt->size); speex_bits_reset(&s->bits); diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c index 43880072ca..8e13af6933 100644 --- a/libavcodec/libtheoraenc.c +++ b/libavcodec/libtheoraenc.c @@ -337,7 +337,7 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt, } /* Copy ogg_packet content out to buffer */ - if ((ret = ff_alloc_packet2(avc_context, pkt, o_packet.bytes)) < 0) + if ((ret = ff_alloc_packet2(avc_context, pkt, o_packet.bytes, 0)) < 0) return ret; memcpy(pkt->data, o_packet.packet, o_packet.bytes); diff --git a/libavcodec/libtwolame.c b/libavcodec/libtwolame.c index dc188575b5..5408a970ef 100644 --- a/libavcodec/libtwolame.c +++ b/libavcodec/libtwolame.c @@ -106,7 +106,7 @@ static int twolame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, TWOLAMEContext *s = avctx->priv_data; int ret; - if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE, 0)) < 0) return ret; if (frame) { diff --git a/libavcodec/libutvideoenc.cpp b/libavcodec/libutvideoenc.cpp index 38d019b18b..d574ab00d3 100644 --- a/libavcodec/libutvideoenc.cpp +++ b/libavcodec/libutvideoenc.cpp @@ -143,7 +143,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t *dst; /* Alloc buffer */ - if ((ret = ff_alloc_packet2(avctx, pkt, utv->buf_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, utv->buf_size, 0)) < 0) return ret; dst = pkt->data; diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c index 2c4a424252..facc817cd9 100644 --- a/libavcodec/libvo-aacenc.c +++ b/libavcodec/libvo-aacenc.c @@ -153,7 +153,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, return ret; } - if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels))) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels), 0)) < 0) return ret; input.Buffer = samples; diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c index fe19e71156..92fa185081 100644 --- a/libavcodec/libvo-amrwbenc.c +++ b/libavcodec/libvo-amrwbenc.c @@ -115,7 +115,7 @@ static int amr_wb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const int16_t *samples = (const int16_t *)frame->data[0]; int size, ret; - if ((ret = ff_alloc_packet2(avctx, avpkt, MAX_PACKET_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, MAX_PACKET_SIZE, 0)) < 0) return ret; if (s->last_bitrate != avctx->bit_rate) { diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c index 231d1be252..8a466911d4 100644 --- a/libavcodec/libvorbisenc.c +++ b/libavcodec/libvorbisenc.c @@ -338,7 +338,7 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL); - if ((ret = ff_alloc_packet2(avctx, avpkt, op.bytes)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, op.bytes, 0)) < 0) return ret; av_fifo_generic_read(s->pkt_fifo, avpkt->data, op.bytes, NULL); diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 7d301803b1..127b8384db 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -687,7 +687,7 @@ static inline void cx_pktcpy(struct FrameListData *dst, static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, AVPacket *pkt) { - int ret = ff_alloc_packet2(avctx, pkt, cx_frame->sz); + int ret = ff_alloc_packet2(avctx, pkt, cx_frame->sz, 0); uint8_t *side_data; if (ret >= 0) { memcpy(pkt->data, cx_frame->buf, pkt->size); diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 44c6a70827..7b17a8863c 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -113,7 +113,7 @@ static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, for (i = 0; i < nnal; i++) size += nals[i].i_payload; - if ((ret = ff_alloc_packet2(ctx, pkt, size)) < 0) + if ((ret = ff_alloc_packet2(ctx, pkt, size, 0)) < 0) return ret; p = pkt->data; diff --git a/libavcodec/libxavs.c b/libavcodec/libxavs.c index b8140ab672..41473028f7 100644 --- a/libavcodec/libxavs.c +++ b/libavcodec/libxavs.c @@ -88,7 +88,7 @@ static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, for (i = 0; i < nnal; i++) size += nals[i].i_payload; - if ((ret = ff_alloc_packet2(ctx, pkt, size)) < 0) + if ((ret = ff_alloc_packet2(ctx, pkt, size, 0)) < 0) return ret; p = pkt->data; @@ -144,7 +144,7 @@ static int XAVS_frame(AVCodecContext *avctx, AVPacket *pkt, if (!ret) { if (!frame && !(x4->end_of_stream)) { - if ((ret = ff_alloc_packet2(avctx, pkt, 4)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, 4, 0)) < 0) return ret; pkt->data[0] = 0x0; diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c index 6979346f62..5c86bcd1dd 100644 --- a/libavcodec/libxvid.c +++ b/libavcodec/libxvid.c @@ -696,7 +696,7 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, xvid_enc_frame_t xvid_enc_frame = { 0 }; xvid_enc_stats_t xvid_enc_stats = { 0 }; - if ((ret = ff_alloc_packet2(avctx, pkt, mb_width*(int64_t)mb_height*MAX_MB_BYTES + FF_MIN_BUFFER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, mb_width*(int64_t)mb_height*MAX_MB_BYTES + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; /* Start setting up the frame */ diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c index c8d5a45a0e..e0a149ac13 100644 --- a/libavcodec/ljpegenc.c +++ b/libavcodec/ljpegenc.c @@ -229,7 +229,7 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, * s->hsample[0] * s->vsample[0]; } - if ((ret = ff_alloc_packet2(avctx, pkt, max_pkt_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, max_pkt_size, 0)) < 0) return ret; init_put_bits(&pb, pkt->data, pkt->size); diff --git a/libavcodec/mpegaudioenc_template.c b/libavcodec/mpegaudioenc_template.c index 5a0897f036..ce93cc7c6d 100644 --- a/libavcodec/mpegaudioenc_template.c +++ b/libavcodec/mpegaudioenc_template.c @@ -763,7 +763,7 @@ static int MPA_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } compute_bit_allocation(s, smr, bit_alloc, &padding); - if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE, 0)) < 0) return ret; init_put_bits(&s->pb, avpkt->data, avpkt->size); diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index f837b3f29d..5e9d6e8d51 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1739,7 +1739,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, int pkt_size = growing_buffer ? FFMAX(s->mb_width*s->mb_height*64+10000, avctx->internal->byte_buffer_size) - FF_INPUT_BUFFER_PADDING_SIZE : s->mb_width*s->mb_height*(MAX_MB_BYTES+100)+10000; - if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size, 0)) < 0) return ret; if (s->mb_info) { s->mb_info_ptr = av_packet_new_side_data(pkt, diff --git a/libavcodec/msvideo1enc.c b/libavcodec/msvideo1enc.c index 5e6cdfa3f8..ac32cae1bc 100644 --- a/libavcodec/msvideo1enc.c +++ b/libavcodec/msvideo1enc.c @@ -76,7 +76,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, int skips = 0; int quality = 24; - if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + FF_MIN_BUFFER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; dst= buf= pkt->data; diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c index 7c77ff74e0..de3c978af3 100644 --- a/libavcodec/nellymoserenc.c +++ b/libavcodec/nellymoserenc.c @@ -397,7 +397,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, s->last_frame = 1; } - if ((ret = ff_alloc_packet2(avctx, avpkt, NELLY_BLOCK_LEN)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, NELLY_BLOCK_LEN, 0)) < 0) return ret; encode_block(s, avpkt->data, avpkt->size); diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 9c97f356aa..b5e6862f0e 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1124,7 +1124,7 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencOut goto error; } - if (res = ff_alloc_packet2(avctx, pkt, lock_params.bitstreamSizeInBytes)) { + if (res = ff_alloc_packet2(avctx, pkt, lock_params.bitstreamSizeInBytes, 0)) { p_nvenc->nvEncUnlockBitstream(ctx->nvencoder, tmpoutsurf->output_surface); goto error; } diff --git a/libavcodec/pamenc.c b/libavcodec/pamenc.c index 03f6454fbc..50c9fcb404 100644 --- a/libavcodec/pamenc.c +++ b/libavcodec/pamenc.c @@ -91,7 +91,7 @@ static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt, return -1; } - if ((ret = ff_alloc_packet2(avctx, pkt, n*h + 200)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, n*h + 200, 0)) < 0) return ret; bytestream_start = diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c index 0a4ad0b9d9..941d94f0df 100644 --- a/libavcodec/pcm.c +++ b/libavcodec/pcm.c @@ -97,7 +97,7 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, n = frame->nb_samples * avctx->channels; samples = (const short *)frame->data[0]; - if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size, 0)) < 0) return ret; dst = avpkt->data; diff --git a/libavcodec/pcxenc.c b/libavcodec/pcxenc.c index fef34bed9b..f0ffedfa56 100644 --- a/libavcodec/pcxenc.c +++ b/libavcodec/pcxenc.c @@ -145,7 +145,7 @@ static int pcx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, line_bytes = (line_bytes + 1) & ~1; max_pkt_size = 128 + avctx->height * 2 * line_bytes * nplanes + (pal ? 256*3 + 1 : 0); - if ((ret = ff_alloc_packet2(avctx, pkt, max_pkt_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, max_pkt_size, 0)) < 0) return ret; buf = pkt->data; buf_end = pkt->data + pkt->size; diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index ad05311aab..6a5e0f8860 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -502,7 +502,7 @@ static int encode_png(AVCodecContext *avctx, AVPacket *pkt, ); if (max_packet_size > INT_MAX) return AVERROR(ENOMEM); - ret = ff_alloc_packet2(avctx, pkt, max_packet_size); + ret = ff_alloc_packet2(avctx, pkt, max_packet_size, 0); if (ret < 0) return ret; @@ -560,7 +560,7 @@ static int encode_apng(AVCodecContext *avctx, AVPacket *pkt, ); if (max_packet_size > INT_MAX) return AVERROR(ENOMEM); - ret = ff_alloc_packet2(avctx, pkt, max_packet_size); + ret = ff_alloc_packet2(avctx, pkt, max_packet_size, 0); if (ret < 0) return ret; diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c index 05460ea855..9c63dcb54b 100644 --- a/libavcodec/pnmenc.c +++ b/libavcodec/pnmenc.c @@ -32,7 +32,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, if ((ret = ff_alloc_packet2(avctx, pkt, avpicture_get_size(avctx->pix_fmt, avctx->width, - avctx->height) + 200)) < 0) + avctx->height) + 200, 0)) < 0) return ret; bytestream_start = diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c index 607053412c..094320af08 100644 --- a/libavcodec/proresenc_anatoliy.c +++ b/libavcodec/proresenc_anatoliy.c @@ -494,7 +494,7 @@ static int prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt, int frame_size = FFALIGN(avctx->width, 16) * FFALIGN(avctx->height, 16)*16 + 500 + FF_MIN_BUFFER_SIZE; //FIXME choose tighter limit - if ((ret = ff_alloc_packet2(avctx, pkt, frame_size + FF_MIN_BUFFER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, frame_size + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; buf = pkt->data; diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index 8e873cd33e..de18298a8b 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -944,7 +944,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, ctx->pic = pic; pkt_size = ctx->frame_size_upper_bound; - if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size + FF_MIN_BUFFER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; orig_buf = pkt->data; diff --git a/libavcodec/qtrleenc.c b/libavcodec/qtrleenc.c index 9440f8f556..590c39dcea 100644 --- a/libavcodec/qtrleenc.c +++ b/libavcodec/qtrleenc.c @@ -366,7 +366,7 @@ static int qtrle_encode_frame(AVCodecContext *avctx, AVPacket *pkt, enum AVPictureType pict_type; int ret; - if ((ret = ff_alloc_packet2(avctx, pkt, s->max_buf_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, s->max_buf_size, 0)) < 0) return ret; if (avctx->gop_size == 0 || (s->avctx->frame_number % avctx->gop_size) == 0) { diff --git a/libavcodec/r210enc.c b/libavcodec/r210enc.c index 0aae40977f..64aa33f557 100644 --- a/libavcodec/r210enc.c +++ b/libavcodec/r210enc.c @@ -34,7 +34,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t *src_line; uint8_t *dst; - if ((ret = ff_alloc_packet2(avctx, pkt, 4 * aligned_width * avctx->height)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, 4 * aligned_width * avctx->height, 0)) < 0) return ret; avctx->coded_frame->key_frame = 1; diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c index 3ad3f4ea96..d6cd8d55de 100644 --- a/libavcodec/ra144enc.c +++ b/libavcodec/ra144enc.c @@ -447,7 +447,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (ractx->last_frame) return 0; - if ((ret = ff_alloc_packet2(avctx, avpkt, FRAME_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, FRAME_SIZE, 0)) < 0) return ret; /** diff --git a/libavcodec/roqaudioenc.c b/libavcodec/roqaudioenc.c index c373ccca47..3760514d33 100644 --- a/libavcodec/roqaudioenc.c +++ b/libavcodec/roqaudioenc.c @@ -160,7 +160,7 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, else data_size = avctx->channels * avctx->frame_size; - if ((ret = ff_alloc_packet2(avctx, avpkt, ROQ_HEADER_SIZE + data_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, ROQ_HEADER_SIZE + data_size, 0)) < 0) return ret; out = avpkt->data; diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c index bb5be77211..72fc2d75ae 100644 --- a/libavcodec/roqvideoenc.c +++ b/libavcodec/roqvideoenc.c @@ -1090,7 +1090,7 @@ static int roq_encode_frame(AVCodecContext *avctx, AVPacket *pkt, /* 138 bits max per 8x8 block + * 256 codebooks*(6 bytes 2x2 + 4 bytes 4x4) + 8 bytes frame header */ size = ((enc->width * enc->height / 64) * 138 + 7) / 8 + 256 * (6 + 4) + 8; - if ((ret = ff_alloc_packet2(avctx, pkt, size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0) return ret; enc->out_buf = pkt->data; diff --git a/libavcodec/s302menc.c b/libavcodec/s302menc.c index e738f09d19..7ced674c8a 100644 --- a/libavcodec/s302menc.c +++ b/libavcodec/s302menc.c @@ -78,7 +78,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, uint8_t *o; PutBitContext pb; - if ((ret = ff_alloc_packet2(avctx, avpkt, buf_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, buf_size, 0)) < 0) return ret; o = avpkt->data; diff --git a/libavcodec/sgienc.c b/libavcodec/sgienc.c index a16d079562..28cec8625f 100644 --- a/libavcodec/sgienc.c +++ b/libavcodec/sgienc.c @@ -114,7 +114,7 @@ FF_ENABLE_DEPRECATION_WARNINGS else // assume ff_rl_encode() produces at most 2x size of input length += tablesize * 2 + depth * height * (2 * width + 1); - if ((ret = ff_alloc_packet2(avctx, pkt, bytes_per_channel * length)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, bytes_per_channel * length, 0)) < 0) return ret; buf = pkt->data; end_buf = pkt->data + pkt->size; diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 9c804acbd4..33aef933a4 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -1555,7 +1555,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t rc_header_bak[sizeof(s->header_state)]; uint8_t rc_block_bak[sizeof(s->block_state)]; - if ((ret = ff_alloc_packet2(avctx, pkt, s->b_width*s->b_height*MB_SIZE*MB_SIZE*3 + FF_MIN_BUFFER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, s->b_width*s->b_height*MB_SIZE*MB_SIZE*3 + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; ff_init_range_encoder(c, pkt->data, pkt->size); diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c index c5076f9d8e..c6937435d7 100644 --- a/libavcodec/sonic.c +++ b/libavcodec/sonic.c @@ -727,7 +727,7 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const short *samples = (const int16_t*)frame->data[0]; uint8_t state[32]; - if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size * 5 + 1000)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size * 5 + 1000, 0)) < 0) return ret; ff_init_range_encoder(&c, avpkt->data, avpkt->size); diff --git a/libavcodec/sunrastenc.c b/libavcodec/sunrastenc.c index b6eb38f8b9..d83a42dd0f 100644 --- a/libavcodec/sunrastenc.c +++ b/libavcodec/sunrastenc.c @@ -181,7 +181,7 @@ static int sunrast_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, SUNRASTContext *s = avctx->priv_data; int ret; - if ((ret = ff_alloc_packet2(avctx, avpkt, s->size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, s->size, 0)) < 0) return ret; bytestream2_init_writer(&s->p, avpkt->data, avpkt->size); diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c index e49dee6268..0cba19d390 100644 --- a/libavcodec/svq1enc.c +++ b/libavcodec/svq1enc.c @@ -576,7 +576,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, int i, ret; if ((ret = ff_alloc_packet2(avctx, pkt, s->y_block_width * s->y_block_height * - MAX_MB_BYTES*3 + FF_MIN_BUFFER_SIZE)) < 0) + MAX_MB_BYTES*3 + FF_MIN_BUFFER_SIZE, 0)) < 0) return ret; if (avctx->pix_fmt != AV_PIX_FMT_YUV410P) { diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c index e8a3dee4b2..de8163a5f0 100644 --- a/libavcodec/targaenc.c +++ b/libavcodec/targaenc.c @@ -85,7 +85,7 @@ static int targa_encode_frame(AVCodecContext *avctx, AVPacket *pkt, return AVERROR(EINVAL); } picsize = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); - if ((ret = ff_alloc_packet2(avctx, pkt, picsize + 45)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, picsize + 45, 0)) < 0) return ret; /* zero out the header and only set applicable fields */ diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c index 543dcaf151..3cfc77eb4e 100644 --- a/libavcodec/tiffenc.c +++ b/libavcodec/tiffenc.c @@ -331,7 +331,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, packet_size = avctx->height * bytes_per_row * 2 + avctx->height * 4 + FF_MIN_BUFFER_SIZE; - if ((ret = ff_alloc_packet2(avctx, pkt, packet_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, packet_size, 0)) < 0) return ret; ptr = pkt->data; s->buf_start = pkt->data; diff --git a/libavcodec/ttaenc.c b/libavcodec/ttaenc.c index ccd41a90c9..da1cc4fbb3 100644 --- a/libavcodec/ttaenc.c +++ b/libavcodec/ttaenc.c @@ -116,7 +116,7 @@ static int tta_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, PutBitContext pb; int ret, i, out_bytes, cur_chan = 0, res = 0, samples = 0; - if ((ret = ff_alloc_packet2(avctx, avpkt, frame->nb_samples * 2 * avctx->channels * s->bps)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, frame->nb_samples * 2 * avctx->channels * s->bps, 0)) < 0) return ret; init_put_bits(&pb, avpkt->data, avpkt->size); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index d926a2631a..b147559aba 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1777,7 +1777,7 @@ FF_ENABLE_DEPRECATION_WARNINGS goto end; } -int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size) +int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size) { if (avpkt->size < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", avpkt->size); @@ -1835,7 +1835,7 @@ FF_ENABLE_DEPRECATION_WARNINGS int ff_alloc_packet(AVPacket *avpkt, int size) { - return ff_alloc_packet2(NULL, avpkt, size); + return ff_alloc_packet2(NULL, avpkt, size, 0); } /** diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c index 8a3ec5d129..5745971b50 100644 --- a/libavcodec/utvideoenc.c +++ b/libavcodec/utvideoenc.c @@ -536,7 +536,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt, /* Allocate a new packet if needed, and set it to the pointer dst */ ret = ff_alloc_packet2(avctx, pkt, (256 + 4 * c->slices + width * height) * - c->planes + 4); + c->planes + 4, 0); if (ret < 0) return ret; diff --git a/libavcodec/v308enc.c b/libavcodec/v308enc.c index 0e5ab822c0..4331ec129f 100644 --- a/libavcodec/v308enc.c +++ b/libavcodec/v308enc.c @@ -41,7 +41,7 @@ static int v308_encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t *y, *u, *v; int i, j, ret; - if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 3)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 3, 0)) < 0) return ret; dst = pkt->data; diff --git a/libavcodec/v408enc.c b/libavcodec/v408enc.c index b09da89eaa..14ca619dc1 100644 --- a/libavcodec/v408enc.c +++ b/libavcodec/v408enc.c @@ -37,7 +37,7 @@ static int v408_encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t *y, *u, *v, *a; int i, j, ret; - if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4, 0)) < 0) return ret; dst = pkt->data; diff --git a/libavcodec/v410enc.c b/libavcodec/v410enc.c index 19487dc219..9a914bdcbb 100644 --- a/libavcodec/v410enc.c +++ b/libavcodec/v410enc.c @@ -43,7 +43,7 @@ static int v410_encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint32_t val; int i, j, ret; - if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4, 0)) < 0) return ret; dst = pkt->data; diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c index dcb2a6e557..40d907e199 100644 --- a/libavcodec/vorbisenc.c +++ b/libavcodec/vorbisenc.c @@ -1033,7 +1033,7 @@ static int vorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, return 0; samples = 1 << (venc->log2_blocksize[0] - 1); - if ((ret = ff_alloc_packet2(avctx, avpkt, 8192)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, 8192, 0)) < 0) return ret; init_put_bits(&pb, avpkt->data, avpkt->size); diff --git a/libavcodec/wavpackenc.c b/libavcodec/wavpackenc.c index 87f1445738..05881672c5 100644 --- a/libavcodec/wavpackenc.c +++ b/libavcodec/wavpackenc.c @@ -2879,7 +2879,7 @@ static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, buf_size = s->block_samples * avctx->channels * 8 + 200 /* for headers */; - if ((ret = ff_alloc_packet2(avctx, avpkt, buf_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, buf_size, 0)) < 0) return ret; buf = avpkt->data; diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c index b922acdee8..fc23d4e33d 100644 --- a/libavcodec/wmaenc.c +++ b/libavcodec/wmaenc.c @@ -377,7 +377,7 @@ static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt, } } - if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE, 0)) < 0) return ret; total_gain = 128; diff --git a/libavcodec/xbmenc.c b/libavcodec/xbmenc.c index a752bdf2a7..b25615f2a4 100644 --- a/libavcodec/xbmenc.c +++ b/libavcodec/xbmenc.c @@ -32,7 +32,7 @@ static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, linesize = (avctx->width + 7) / 8; size = avctx->height * (linesize * 7 + 2) + 110; - if ((ret = ff_alloc_packet2(avctx, pkt, size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0) return ret; buf = pkt->data; diff --git a/libavcodec/xfaceenc.c b/libavcodec/xfaceenc.c index ca0f72bc9e..38f63e622a 100644 --- a/libavcodec/xfaceenc.c +++ b/libavcodec/xfaceenc.c @@ -202,7 +202,7 @@ static int xface_encode_frame(AVCodecContext *avctx, AVPacket *pkt, intbuf[i++] = r + XFACE_FIRST_PRINT; } - if ((ret = ff_alloc_packet2(avctx, pkt, i+2)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, i+2, 0)) < 0) return ret; /* revert the number, and close the buffer */ diff --git a/libavcodec/xwdenc.c b/libavcodec/xwdenc.c index 06fa4a0a97..43bca89033 100644 --- a/libavcodec/xwdenc.c +++ b/libavcodec/xwdenc.c @@ -146,7 +146,7 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, header_size = XWD_HEADER_SIZE + WINDOW_NAME_SIZE; out_size = header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize; - if ((ret = ff_alloc_packet2(avctx, pkt, out_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, out_size, 0)) < 0) return ret; buf = pkt->data; diff --git a/libavcodec/y41penc.c b/libavcodec/y41penc.c index b30cbfaf26..0645d276b4 100644 --- a/libavcodec/y41penc.c +++ b/libavcodec/y41penc.c @@ -42,7 +42,7 @@ static int y41p_encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t *y, *u, *v; int i, j, ret; - if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 1.5)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 1.5, 0)) < 0) return ret; avctx->coded_frame->key_frame = 1; diff --git a/libavcodec/yuv4enc.c b/libavcodec/yuv4enc.c index cc9ecbbf87..17c670f406 100644 --- a/libavcodec/yuv4enc.c +++ b/libavcodec/yuv4enc.c @@ -35,7 +35,7 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t *y, *u, *v; int i, j, ret; - if ((ret = ff_alloc_packet2(avctx, pkt, 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1))) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1), 0)) < 0) return ret; dst = pkt->data; diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c index 02adfa725e..df06e37cb2 100644 --- a/libavcodec/zmbvenc.c +++ b/libavcodec/zmbvenc.c @@ -231,7 +231,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } pkt_size = c->zstream.total_out + 1 + 6*keyframe; - if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size, 0)) < 0) return ret; buf = pkt->data; |