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>
This commit is contained in:
Michael Niedermayer 2015-07-27 19:36:16 +02:00
parent 59216e0525
commit e36db49b7b
89 changed files with 96 additions and 92 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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];

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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 */

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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:

View File

@ -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);

View File

@ -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){

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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) {

View File

@ -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;
}

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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);

View File

@ -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);

View File

@ -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,

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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 =

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 =

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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;
/**

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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 */

View File

@ -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;

View File

@ -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);

View File

@ -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);
}
/**

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;