[FFmpeg-cvslog] avcodec/encode: Always use intermediate buffer in ff_alloc_packet2()
Andreas Rheinhardt
git at videolan.org
Tue Jun 8 16:04:46 EEST 2021
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue May 11 15:17:13 2021 +0200| [56e9e0273a79fb4ff4276503e69981f8e383f22b] | committer: Andreas Rheinhardt
avcodec/encode: Always use intermediate buffer in ff_alloc_packet2()
Up until now, ff_alloc_packet2() has a min_size parameter:
It is supposed to be a lower bound on the final size of the packet
to allocate. If it is not too far from the upper bound (namely,
if it is at least half the upper bound), then ff_alloc_packet2()
already allocates the final, already refcounted packet; if it is
not, then the packet is not refcounted and its data only points to
a buffer owned by the AVCodecContext (in this case, the packet will
be made refcounted in encode_simple_internal() in libavcodec/encode.c).
The goal of this was to avoid data copies and intermediate buffers
if one has a precise lower bound.
Yet those encoders for which precise lower bounds exist have recently
been switched to ff_get_encode_buffer() (which automatically allocates
final buffers), leaving only two encoders to actually set the min_size
to something else than zero (namely aliaspixenc and hapenc). Both of
these encoders use a very low lower bound that is not helpful in any
nontrivial case.
This commit therefore removes the min_size parameter as well as the
codepath in ff_alloc_packet2() for the allocation of final buffers.
Furthermore, the function has been renamed to ff_alloc_packet() and
moved to encode.h alongside ff_get_encode_buffer().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=56e9e0273a79fb4ff4276503e69981f8e383f22b
---
libavcodec/aacenc.c | 3 ++-
libavcodec/alacenc.c | 3 ++-
libavcodec/aliaspixenc.c | 5 ++---
libavcodec/asvenc.c | 5 +++--
libavcodec/audiotoolboxenc.c | 3 ++-
libavcodec/cfhdenc.c | 3 ++-
libavcodec/cinepakenc.c | 3 ++-
libavcodec/encode.c | 18 +++++++-----------
libavcodec/encode.h | 15 +++++++++++++++
libavcodec/ffv1enc.c | 3 ++-
libavcodec/flashsv2enc.c | 3 ++-
libavcodec/flashsvenc.c | 3 ++-
libavcodec/gif.c | 3 ++-
libavcodec/hapenc.c | 3 ++-
libavcodec/huffyuvenc.c | 3 ++-
libavcodec/internal.h | 24 ------------------------
libavcodec/j2kenc.c | 3 ++-
libavcodec/lclenc.c | 3 ++-
libavcodec/libfdk-aacenc.c | 4 +++-
libavcodec/libilbc.c | 3 ++-
libavcodec/libopencore-amr.c | 3 ++-
libavcodec/libopenjpegenc.c | 4 ++--
libavcodec/libopusenc.c | 3 ++-
libavcodec/libspeexenc.c | 3 ++-
libavcodec/libtwolame.c | 3 ++-
libavcodec/libvo-amrwbenc.c | 3 ++-
libavcodec/libxvid.c | 3 ++-
libavcodec/ljpegenc.c | 3 ++-
libavcodec/magicyuvenc.c | 5 +++--
libavcodec/mlpenc.c | 3 ++-
libavcodec/mpegaudioenc_template.c | 3 ++-
libavcodec/mpegvideo_enc.c | 3 ++-
libavcodec/msvideo1enc.c | 3 ++-
libavcodec/opusenc.c | 3 ++-
libavcodec/pcxenc.c | 3 ++-
libavcodec/pngenc.c | 2 +-
libavcodec/proresenc_anatoliy.c | 3 ++-
libavcodec/proresenc_kostya.c | 3 ++-
libavcodec/qtrleenc.c | 3 ++-
libavcodec/roqvideoenc.c | 3 ++-
libavcodec/rpzaenc.c | 5 +++--
libavcodec/sgienc.c | 3 ++-
libavcodec/snowenc.c | 3 ++-
libavcodec/sonic.c | 3 ++-
libavcodec/sunrastenc.c | 3 ++-
libavcodec/svq1enc.c | 6 ++++--
libavcodec/targaenc.c | 3 ++-
libavcodec/tiffenc.c | 3 ++-
libavcodec/ttaenc.c | 3 ++-
libavcodec/utvideoenc.c | 5 +++--
libavcodec/vorbisenc.c | 3 ++-
libavcodec/wavpackenc.c | 3 ++-
libavcodec/wmaenc.c | 3 ++-
libavcodec/xbmenc.c | 3 ++-
54 files changed, 130 insertions(+), 94 deletions(-)
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 605b804b27..23bfa20eaf 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -34,6 +34,7 @@
#include "libavutil/float_dsp.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "put_bits.h"
#include "internal.h"
#include "mpeg4audio.h"
@@ -676,7 +677,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
}
start_ch += chans;
}
- if ((ret = ff_alloc_packet2(avctx, avpkt, 8192 * s->channels, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, 8192 * s->channels)) < 0)
return ret;
frame_bits = its = 0;
do {
diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c
index eddd9c97c3..a38aa6e7d7 100644
--- a/libavcodec/alacenc.c
+++ b/libavcodec/alacenc.c
@@ -22,6 +22,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "put_bits.h"
#include "internal.h"
#include "lpc.h"
@@ -589,7 +590,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, 4 * max_frame_size, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, 4 * max_frame_size)) < 0)
return ret;
/* use verbatim mode for compression_level 0 */
diff --git a/libavcodec/aliaspixenc.c b/libavcodec/aliaspixenc.c
index 01e9b3ab96..22234c091e 100644
--- a/libavcodec/aliaspixenc.c
+++ b/libavcodec/aliaspixenc.c
@@ -23,6 +23,7 @@
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "internal.h"
#define ALIAS_HEADER_SIZE 10
@@ -54,10 +55,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
length = ALIAS_HEADER_SIZE + 4 * width * height; // max possible
- if ((ret = ff_alloc_packet2(avctx, pkt, length, ALIAS_HEADER_SIZE + height*2)) < 0) {
- av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", length);
+ if ((ret = ff_alloc_packet(avctx, pkt, length)) < 0)
return ret;
- }
buf = pkt->data;
diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c
index bf11701d17..6be7f5282a 100644
--- a/libavcodec/asvenc.c
+++ b/libavcodec/asvenc.c
@@ -30,6 +30,7 @@
#include "asv.h"
#include "avcodec.h"
#include "dct.h"
+#include "encode.h"
#include "fdctdsp.h"
#include "internal.h"
#include "mpeg12data.h"
@@ -255,8 +256,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
return ret;
}
- if ((ret = ff_alloc_packet2(avctx, pkt, a->mb_height * a->mb_width * MAX_MB_SIZE +
- AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, a->mb_height * a->mb_width * MAX_MB_SIZE +
+ AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return ret;
init_put_bits(&a->pb, pkt->data, pkt->size);
diff --git a/libavcodec/audiotoolboxenc.c b/libavcodec/audiotoolboxenc.c
index e0e00ba2b0..f599802b7b 100644
--- a/libavcodec/audiotoolboxenc.c
+++ b/libavcodec/audiotoolboxenc.c
@@ -29,6 +29,7 @@
#include "audio_frame_queue.h"
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "internal.h"
#include "libavformat/isom.h"
#include "libavutil/avassert.h"
@@ -536,7 +537,7 @@ static int ffat_encode(AVCodecContext *avctx, AVPacket *avpkt,
at->eof = 1;
}
- if ((ret = ff_alloc_packet2(avctx, avpkt, at->pkt_size, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, at->pkt_size)) < 0)
return ret;
diff --git a/libavcodec/cfhdenc.c b/libavcodec/cfhdenc.c
index 3445295796..968962102f 100644
--- a/libavcodec/cfhdenc.c
+++ b/libavcodec/cfhdenc.c
@@ -34,6 +34,7 @@
#include "bytestream.h"
#include "cfhd.h"
#include "cfhdencdsp.h"
+#include "encode.h"
#include "put_bits.h"
#include "internal.h"
#include "thread.h"
@@ -547,7 +548,7 @@ static int cfhd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
width, height * 2);
}
- ret = ff_alloc_packet2(avctx, pkt, 64LL + s->planes * (2LL * avctx->width * avctx->height + 1000LL), 0);
+ ret = ff_alloc_packet(avctx, pkt, 64LL + s->planes * (2LL * avctx->width * avctx->height + 1000LL));
if (ret < 0)
return ret;
diff --git a/libavcodec/cinepakenc.c b/libavcodec/cinepakenc.c
index 422cb3f8e9..41da231dfb 100644
--- a/libavcodec/cinepakenc.c
+++ b/libavcodec/cinepakenc.c
@@ -45,6 +45,7 @@
#include "avcodec.h"
#include "elbg.h"
+#include "encode.h"
#include "internal.h"
#define CVID_HEADER_SIZE 10
@@ -1140,7 +1141,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, s->frame_buf_size)) < 0)
return ret;
ret = rd_frame(s, frame, (s->curframe == 0), pkt->data, s->frame_buf_size);
pkt->size = ret;
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 62c47afb24..a569904f2c 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -30,7 +30,7 @@
#include "frame_thread_encoder.h"
#include "internal.h"
-int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
+int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
{
if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
@@ -40,18 +40,14 @@ int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64
av_assert0(!avpkt->data);
- if (avctx && 2*min_size < size) { // FIXME The factor needs to be finetuned
- av_fast_padded_malloc(&avctx->internal->byte_buffer, &avctx->internal->byte_buffer_size, size);
- avpkt->data = avctx->internal->byte_buffer;
- avpkt->size = size;
- }
-
+ av_fast_padded_malloc(&avctx->internal->byte_buffer,
+ &avctx->internal->byte_buffer_size, size);
+ avpkt->data = avctx->internal->byte_buffer;
if (!avpkt->data) {
- int ret = av_new_packet(avpkt, size);
- if (ret < 0)
- av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
- return ret;
+ av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
+ return AVERROR(ENOMEM);
}
+ avpkt->size = size;
return 0;
}
diff --git a/libavcodec/encode.h b/libavcodec/encode.h
index 9af2f42483..c9cec0cc80 100644
--- a/libavcodec/encode.h
+++ b/libavcodec/encode.h
@@ -44,6 +44,21 @@ int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame);
*/
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags);
+/**
+ * Check AVPacket size and allocate data.
+ *
+ * Encoders supporting AVCodec.encode2() can use this as a convenience to
+ * obtain a big enough buffer for the encoded bitstream.
+ *
+ * @param avctx the AVCodecContext of the encoder
+ * @param avpkt The AVPacket: on success, avpkt->data will point to a buffer
+ * of size at least `size`; the packet will not be refcounted.
+ * This packet must be initially blank.
+ * @param size an upper bound of the size of the packet to encode
+ * @return non negative on success, negative error code on failure
+ */
+int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size);
+
/*
* Perform encoder initialization and validation.
* Called when opening the encoder, before the AVCodec.init() call.
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 4df10d3e75..69b9065343 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -33,6 +33,7 @@
#include "libavutil/pixdesc.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "put_bits.h"
#include "rangecoder.h"
@@ -1159,7 +1160,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
maxsize = INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32;
}
- if ((ret = ff_alloc_packet2(avctx, pkt, maxsize, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, maxsize)) < 0)
return ret;
ff_init_range_encoder(c, pkt->data, pkt->size);
diff --git a/libavcodec/flashsv2enc.c b/libavcodec/flashsv2enc.c
index c4debe174c..56ea0ed0a4 100644
--- a/libavcodec/flashsv2enc.c
+++ b/libavcodec/flashsv2enc.c
@@ -48,6 +48,7 @@
#include "libavutil/imgutils.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "put_bits.h"
#include "bytestream.h"
@@ -844,7 +845,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 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((res = ff_alloc_packet(avctx, pkt, s->frame_size + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return res;
/* First frame needs to be a keyframe */
diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
index 87119c15ea..171a66ee15 100644
--- a/libavcodec/flashsvenc.c
+++ b/libavcodec/flashsvenc.c
@@ -49,6 +49,7 @@
#include <zlib.h>
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "put_bits.h"
#include "bytestream.h"
@@ -229,7 +230,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)) < 0)
+ if ((res = ff_alloc_packet(avctx, pkt, s->image_width * s->image_height * 3)) < 0)
return res;
pkt->size = encode_bitstream(s, p, pkt->data, pkt->size, opt_w * 16, opt_h * 16,
diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index 8f0a3d79c1..5e7cc47206 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -35,6 +35,7 @@
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "internal.h"
#include "lzw.h"
#include "gif.h"
@@ -480,7 +481,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 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*7/5 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return ret;
outbuf_ptr = pkt->data;
end = pkt->data + pkt->size;
diff --git a/libavcodec/hapenc.c b/libavcodec/hapenc.c
index 7801111e15..f4313ecf6d 100644
--- a/libavcodec/hapenc.c
+++ b/libavcodec/hapenc.c
@@ -39,6 +39,7 @@
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "hap.h"
#include "internal.h"
#include "texturedsp.h"
@@ -200,7 +201,7 @@ static int hap_encode(AVCodecContext *avctx, AVPacket *pkt,
int pktsize = FFMAX(ctx->tex_size, ctx->max_snappy * ctx->chunk_count) + header_length;
/* Allocate maximum size packet, shrink later. */
- ret = ff_alloc_packet2(avctx, pkt, pktsize, header_length);
+ ret = ff_alloc_packet(avctx, pkt, pktsize);
if (ret < 0)
return ret;
diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c
index a67b89b49b..b35f5c3342 100644
--- a/libavcodec/huffyuvenc.c
+++ b/libavcodec/huffyuvenc.c
@@ -29,6 +29,7 @@
*/
#include "avcodec.h"
+#include "encode.h"
#include "huffyuv.h"
#include "huffman.h"
#include "huffyuvencdsp.h"
@@ -728,7 +729,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 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, width * height * 3 * 4 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return ret;
if (s->context) {
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index ac3d50df9c..975ec0ba30 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -228,30 +228,6 @@ void ff_color_frame(AVFrame *frame, const int color[4]);
*/
#define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
-/**
- * Check AVPacket size and allocate data.
- *
- * Encoders supporting AVCodec.encode2() can use this as a convenience to
- * obtain a big enough buffer for the encoded bitstream.
- *
- * @param avctx the AVCodecContext of the encoder
- * @param avpkt The AVPacket: on success, avpkt->data will point to a buffer
- * of size at least `size`; the packet will not be refcounted.
- * This packet must be initially blank.
- * @param size an upper bound of the size of the packet to encode
- * @param min_size This is a hint to the allocation algorithm, which indicates
- * to what minimal size the caller might later shrink the packet
- * to. Encoders often allocate packets which are larger than the
- * amount of data that is written into them as the exact amount is
- * not known at the time of allocation. min_size represents the
- * size a packet might be shrunk to by the caller. Can be set to
- * 0. setting this roughly correctly allows the allocation code
- * to choose between several allocation strategies 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, int64_t min_size);
-
/**
* Rescale from sample rate to AVCodecContext.time_base.
*/
diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 82ad3284b5..c53c34f412 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -66,6 +66,7 @@
#include <float.h>
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "bytestream.h"
#include "jpeg2000.h"
@@ -1534,7 +1535,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 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*9 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return ret;
// init:
diff --git a/libavcodec/lclenc.c b/libavcodec/lclenc.c
index 3eee95fa04..1e15b09624 100644
--- a/libavcodec/lclenc.c
+++ b/libavcodec/lclenc.c
@@ -42,6 +42,7 @@
#include "libavutil/avassert.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "lcl.h"
#include "libavutil/internal.h"
@@ -70,7 +71,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, max_size)) < 0)
return ret;
if(avctx->pix_fmt != AV_PIX_FMT_BGR24){
diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index a7144e95dd..7ee2f13ac7 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -24,6 +24,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
#include "audio_frame_queue.h"
+#include "encode.h"
#include "internal.h"
#include "profiles.h"
@@ -391,7 +392,8 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
in_buf.bufElSizes = &in_buffer_element_size;
/* 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)) < 0)
+ ret = ff_alloc_packet(avctx, avpkt, FFMAX(8192, 768 * avctx->channels));
+ if (ret < 0)
return ret;
out_ptr = avpkt->data;
diff --git a/libavcodec/libilbc.c b/libavcodec/libilbc.c
index 20a2951850..04192e3045 100644
--- a/libavcodec/libilbc.c
+++ b/libavcodec/libilbc.c
@@ -25,6 +25,7 @@
#include "libavutil/common.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#ifndef LIBILBC_VERSION_MAJOR
@@ -183,7 +184,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, 50)) < 0)
return ret;
WebRtcIlbcfix_EncodeImpl((uint16_t *) avpkt->data, (const int16_t *) frame->data[0], &s->encoder);
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index e88431ba9f..f2cbc6eeb1 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -27,6 +27,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
#include "audio_frame_queue.h"
+#include "encode.h"
#include "internal.h"
#if CONFIG_LIBOPENCORE_AMRNB_DECODER || CONFIG_LIBOPENCORE_AMRWB_DECODER
@@ -243,7 +244,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, 32)) < 0)
return ret;
if (frame) {
diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
index 14808a7591..051d644c0d 100644
--- a/libavcodec/libopenjpegenc.c
+++ b/libavcodec/libopenjpegenc.c
@@ -30,6 +30,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include <openjpeg.h>
@@ -661,9 +662,8 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
goto done;
}
- if ((ret = ff_alloc_packet2(avctx, pkt, 1024, 0)) < 0) {
+ if ((ret = ff_alloc_packet(avctx, pkt, 1024)) < 0)
goto done;
- }
compress = opj_create_compress(ctx->format);
if (!compress) {
diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index c642037aac..6602500f26 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -25,6 +25,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "internal.h"
#include "libopus.h"
#include "vorbis.h"
@@ -483,7 +484,7 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt,
/* Maximum packet size taken from opusenc in opus-tools. 120ms packets
* consist of 6 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 * 6 + 7) * opus->stream_count, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, (1275 * 6 + 7) * opus->stream_count)) < 0)
return ret;
if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT)
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index a7891b367c..d095b41bee 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -89,6 +89,7 @@
#include "libavutil/common.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "audio_frame_queue.h"
@@ -294,7 +295,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, speex_bits_nbytes(&s->bits))) < 0)
return ret;
ret = speex_bits_write(&s->bits, avpkt->data, avpkt->size);
speex_bits_reset(&s->bits);
diff --git a/libavcodec/libtwolame.c b/libavcodec/libtwolame.c
index e28141022d..1f6808b6f5 100644
--- a/libavcodec/libtwolame.c
+++ b/libavcodec/libtwolame.c
@@ -30,6 +30,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "mpegaudio.h"
@@ -110,7 +111,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)) < 0)
return ret;
if (frame) {
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index e48dc8a5b7..dcc0071a36 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -28,6 +28,7 @@
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#define MAX_PACKET_SIZE (1 + (477 + 7) / 8)
@@ -118,7 +119,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, MAX_PACKET_SIZE)) < 0)
return ret;
if (s->last_bitrate != avctx->bit_rate) {
diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c
index 4c635ae86f..e1a1c01f57 100644
--- a/libavcodec/libxvid.c
+++ b/libavcodec/libxvid.c
@@ -39,6 +39,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "mpegutils.h"
#include "packet_internal.h"
@@ -740,7 +741,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 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, mb_width*(int64_t)mb_height*MAX_MB_BYTES + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return ret;
/* Start setting up the frame */
diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c
index d820b9a0f5..ce5409da34 100644
--- a/libavcodec/ljpegenc.c
+++ b/libavcodec/ljpegenc.c
@@ -36,6 +36,7 @@
#include "libavutil/pixdesc.h"
#include "avcodec.h"
+#include "encode.h"
#include "idctdsp.h"
#include "internal.h"
#include "jpegtables.h"
@@ -232,7 +233,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, max_pkt_size)) < 0)
return ret;
init_put_bits(&pb, pkt->data, pkt->size);
diff --git a/libavcodec/magicyuvenc.c b/libavcodec/magicyuvenc.c
index a61d8555d9..8a80441cf6 100644
--- a/libavcodec/magicyuvenc.c
+++ b/libavcodec/magicyuvenc.c
@@ -28,6 +28,7 @@
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "put_bits.h"
#include "internal.h"
#include "thread.h"
@@ -413,8 +414,8 @@ static int magy_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const int width = avctx->width, height = avctx->height;
int pos, slice, i, j, ret = 0;
- ret = ff_alloc_packet2(avctx, pkt, (256 + 4 * s->nb_slices + width * height) *
- s->planes + 256, 0);
+ ret = ff_alloc_packet(avctx, pkt, (256 + 4 * s->nb_slices + width * height) *
+ s->planes + 256);
if (ret < 0)
return ret;
diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index f200f45e86..7693feb127 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -21,6 +21,7 @@
*/
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "put_bits.h"
#include "audio_frame_queue.h"
@@ -2214,7 +2215,7 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
int restart_frame, ret;
uint8_t *data;
- if ((ret = ff_alloc_packet2(avctx, avpkt, 87500 * avctx->channels, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, 87500 * avctx->channels)) < 0)
return ret;
/* add current frame to queue */
diff --git a/libavcodec/mpegaudioenc_template.c b/libavcodec/mpegaudioenc_template.c
index 8e6e20c358..1df3cc704a 100644
--- a/libavcodec/mpegaudioenc_template.c
+++ b/libavcodec/mpegaudioenc_template.c
@@ -27,6 +27,7 @@
#include "libavutil/channel_layout.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "put_bits.h"
@@ -760,7 +761,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)) < 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 7849cdce85..794ca017a4 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -42,6 +42,7 @@
#include "libavutil/thread.h"
#include "avcodec.h"
#include "dct.h"
+#include "encode.h"
#include "idctdsp.h"
#include "mpeg12.h"
#include "mpegvideo.h"
@@ -1721,7 +1722,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) - AV_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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, pkt_size)) < 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 3680c32b11..df621a6f48 100644
--- a/libavcodec/msvideo1enc.c
+++ b/libavcodec/msvideo1enc.c
@@ -25,6 +25,7 @@
*/
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "bytestream.h"
#include "libavutil/lfg.h"
@@ -76,7 +77,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 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*9 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return ret;
dst= buf= pkt->data;
diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
index ac8a5d651c..7b22b929f7 100644
--- a/libavcodec/opusenc.c
+++ b/libavcodec/opusenc.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "encode.h"
#include "opusenc.h"
#include "opus_pvq.h"
#include "opusenc_psy.h"
@@ -577,7 +578,7 @@ static int opus_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
/* Worst case toc + the frame lengths if needed */
alloc_size += 2 + s->packet.frames*2;
- if ((ret = ff_alloc_packet2(avctx, avpkt, alloc_size, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, alloc_size)) < 0)
return ret;
/* Assemble packet */
diff --git a/libavcodec/pcxenc.c b/libavcodec/pcxenc.c
index 96132105f1..4c43c9e344 100644
--- a/libavcodec/pcxenc.c
+++ b/libavcodec/pcxenc.c
@@ -29,6 +29,7 @@
#include "avcodec.h"
#include "bytestream.h"
#include "libavutil/imgutils.h"
+#include "encode.h"
#include "internal.h"
static const uint32_t monoblack_pal[16] = { 0x000000, 0xFFFFFF };
@@ -133,7 +134,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, max_pkt_size)) < 0)
return ret;
buf = pkt->data;
buf_end = pkt->data + pkt->size;
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 894b44197e..9a9aee06f9 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -539,7 +539,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, 0);
+ ret = ff_alloc_packet(avctx, pkt, max_packet_size);
if (ret < 0)
return ret;
diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c
index 280197c9c6..3098b9db05 100644
--- a/libavcodec/proresenc_anatoliy.c
+++ b/libavcodec/proresenc_anatoliy.c
@@ -31,6 +31,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
#include "dct.h"
+#include "encode.h"
#include "internal.h"
#include "profiles.h"
#include "proresdata.h"
@@ -727,7 +728,7 @@ static int prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
int frame_size = FFALIGN(avctx->width, 16) * FFALIGN(avctx->height, 16)*16 + 500 + AV_INPUT_BUFFER_MIN_SIZE; //FIXME choose tighter limit
- if ((ret = ff_alloc_packet2(avctx, pkt, frame_size + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, frame_size + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return ret;
buf = pkt->data;
diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
index 2e39ed41da..4f303593ce 100644
--- a/libavcodec/proresenc_kostya.c
+++ b/libavcodec/proresenc_kostya.c
@@ -27,6 +27,7 @@
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avcodec.h"
+#include "encode.h"
#include "fdctdsp.h"
#include "put_bits.h"
#include "profiles.h"
@@ -998,7 +999,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 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, pkt_size + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return ret;
orig_buf = pkt->data;
diff --git a/libavcodec/qtrleenc.c b/libavcodec/qtrleenc.c
index fc92f5cb06..4089157d47 100644
--- a/libavcodec/qtrleenc.c
+++ b/libavcodec/qtrleenc.c
@@ -25,6 +25,7 @@
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "internal.h"
/** Maximum RLE code for bulk copy */
@@ -369,7 +370,7 @@ static int qtrle_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
QtrleEncContext * const s = avctx->priv_data;
int ret;
- if ((ret = ff_alloc_packet2(avctx, pkt, s->max_buf_size, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, s->max_buf_size)) < 0)
return ret;
if (avctx->gop_size == 0 || !s->previous_frame->data[0] ||
diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c
index aa4f376431..f8e363ada7 100644
--- a/libavcodec/roqvideoenc.c
+++ b/libavcodec/roqvideoenc.c
@@ -62,6 +62,7 @@
#include "roqvideo.h"
#include "bytestream.h"
#include "elbg.h"
+#include "encode.h"
#include "internal.h"
#include "mathops.h"
@@ -1071,7 +1072,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 = ((roq->width * roq->height / 64) * 138 + 7) / 8 + 256 * (6 + 4) + 8;
- if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, size)) < 0)
return ret;
enc->out_buf = pkt->data;
diff --git a/libavcodec/rpzaenc.c b/libavcodec/rpzaenc.c
index e4651d9d9c..337b1faf5b 100644
--- a/libavcodec/rpzaenc.c
+++ b/libavcodec/rpzaenc.c
@@ -28,6 +28,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "put_bits.h"
@@ -776,9 +777,9 @@ static int rpza_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
RpzaContext *s = avctx->priv_data;
const AVFrame *pict = frame;
uint8_t *buf;
- int ret;
+ int ret = ff_alloc_packet(avctx, pkt, 6LL * avctx->height * avctx->width);
- if ((ret = ff_alloc_packet2(avctx, pkt, 6LL * avctx->height * avctx->width, 0)) < 0)
+ if (ret < 0)
return ret;
init_put_bits(&s->pb, pkt->data, pkt->size);
diff --git a/libavcodec/sgienc.c b/libavcodec/sgienc.c
index 962dac0f8a..d323e41172 100644
--- a/libavcodec/sgienc.c
+++ b/libavcodec/sgienc.c
@@ -23,6 +23,7 @@
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "internal.h"
#include "sgi.h"
#include "rle.h"
@@ -154,7 +155,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
else // assume sgi_rle_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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, bytes_per_channel * length)) < 0)
return ret;
bytestream2_init_writer(&pbc, pkt->data, pkt->size);
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 5d384e8d91..d2c0beb1aa 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -24,6 +24,7 @@
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "packet_internal.h"
#include "snow_dwt.h"
@@ -1569,7 +1570,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 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, s->b_width*s->b_height*MB_SIZE*MB_SIZE*3 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
return ret;
ff_init_range_encoder(c, pkt->data, pkt->size);
diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
index 74b388c64f..63a613f77d 100644
--- a/libavcodec/sonic.c
+++ b/libavcodec/sonic.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
+#include "encode.h"
#include "get_bits.h"
#include "golomb.h"
#include "internal.h"
@@ -721,7 +722,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, s->frame_size * 5 + 1000)) < 0)
return ret;
ff_init_range_encoder(&c, avpkt->data, avpkt->size);
diff --git a/libavcodec/sunrastenc.c b/libavcodec/sunrastenc.c
index e4c7c6b090..b77bed01a5 100644
--- a/libavcodec/sunrastenc.c
+++ b/libavcodec/sunrastenc.c
@@ -23,6 +23,7 @@
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "internal.h"
#include "sunrast.h"
@@ -175,7 +176,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)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, s->size)) < 0)
return ret;
bytestream2_init_writer(&s->p, avpkt->data, avpkt->size);
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 91a208180b..11cbd97185 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -27,6 +27,7 @@
*/
#include "avcodec.h"
+#include "encode.h"
#include "hpeldsp.h"
#include "me_cmp.h"
#include "mpegvideo.h"
@@ -581,8 +582,9 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
SVQ1EncContext *const s = avctx->priv_data;
int i, ret;
- if ((ret = ff_alloc_packet2(avctx, pkt, s->y_block_width * s->y_block_height *
- MAX_MB_BYTES*3 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ ret = ff_alloc_packet(avctx, pkt, s->y_block_width * s->y_block_height *
+ MAX_MB_BYTES * 3 + AV_INPUT_BUFFER_MIN_SIZE);
+ if (ret < 0)
return ret;
if (avctx->pix_fmt != AV_PIX_FMT_YUV410P) {
diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c
index b955a4616e..82870c089b 100644
--- a/libavcodec/targaenc.c
+++ b/libavcodec/targaenc.c
@@ -27,6 +27,7 @@
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "rle.h"
#include "targa.h"
@@ -91,7 +92,7 @@ static int targa_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
picsize = av_image_get_buffer_size(avctx->pix_fmt,
avctx->width, avctx->height, 1);
- if ((ret = ff_alloc_packet2(avctx, pkt, picsize + 45, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, picsize + 45)) < 0)
return ret;
/* zero out the header and only set applicable fields */
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index 0abedc4ae4..f8623be3e9 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -36,6 +36,7 @@
#include "libavutil/pixdesc.h"
#include "avcodec.h"
#include "bytestream.h"
+#include "encode.h"
#include "internal.h"
#include "lzw.h"
#include "put_bits.h"
@@ -334,7 +335,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
packet_size = avctx->height * bytes_per_row * 2 +
avctx->height * 4 + AV_INPUT_BUFFER_MIN_SIZE;
- if ((ret = ff_alloc_packet2(avctx, pkt, packet_size, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, packet_size)) < 0)
return ret;
ptr = pkt->data;
s->buf_start = pkt->data;
diff --git a/libavcodec/ttaenc.c b/libavcodec/ttaenc.c
index 8f8afdd338..addaf30bb5 100644
--- a/libavcodec/ttaenc.c
+++ b/libavcodec/ttaenc.c
@@ -22,6 +22,7 @@
#include "ttadata.h"
#include "ttaencdsp.h"
#include "avcodec.h"
+#include "encode.h"
#include "put_bits.h"
#include "internal.h"
#include "libavutil/crc.h"
@@ -92,7 +93,7 @@ static int tta_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
pkt_alloc:
cur_chan = 0, res = 0, samples = 0;
- if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, pkt_size)) < 0)
return ret;
init_put_bits(&pb, avpkt->data, avpkt->size);
diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c
index 30d3e33ee7..1402825fa7 100644
--- a/libavcodec/utvideoenc.c
+++ b/libavcodec/utvideoenc.c
@@ -29,6 +29,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "bswapdsp.h"
#include "bytestream.h"
@@ -530,8 +531,8 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
int i, ret = 0;
/* 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, 0);
+ ret = ff_alloc_packet(avctx, pkt, (256 + 4 * c->slices + width * height)
+ * c->planes + 4);
if (ret < 0)
return ret;
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index d8d7d4d4eb..332c09f9a1 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -28,6 +28,7 @@
#include "libavutil/float_dsp.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "fft.h"
#include "mathops.h"
@@ -1134,7 +1135,7 @@ static int vorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
if (!apply_window_and_mdct(venc))
return 0;
- if ((ret = ff_alloc_packet2(avctx, avpkt, 8192, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, 8192)) < 0)
return ret;
init_put_bits(&pb, avpkt->data, avpkt->size);
diff --git a/libavcodec/wavpackenc.c b/libavcodec/wavpackenc.c
index ba7ea2e45f..bd548a5c30 100644
--- a/libavcodec/wavpackenc.c
+++ b/libavcodec/wavpackenc.c
@@ -23,6 +23,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "put_bits.h"
#include "bytestream.h"
@@ -2869,7 +2870,7 @@ static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
buf_size = s->block_samples * avctx->channels * 8
+ 200 * avctx->channels /* for headers */;
- if ((ret = ff_alloc_packet2(avctx, avpkt, buf_size, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, buf_size)) < 0)
return ret;
buf = avpkt->data;
diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c
index cf42aeaca0..66e3537cb0 100644
--- a/libavcodec/wmaenc.c
+++ b/libavcodec/wmaenc.c
@@ -23,6 +23,7 @@
#include "libavutil/ffmath.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "wma.h"
#include "libavutil/avassert.h"
@@ -392,7 +393,7 @@ static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt,
}
}
- if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE)) < 0)
return ret;
total_gain = 128;
diff --git a/libavcodec/xbmenc.c b/libavcodec/xbmenc.c
index 3451ecc88c..37773bc382 100644
--- a/libavcodec/xbmenc.c
+++ b/libavcodec/xbmenc.c
@@ -21,6 +21,7 @@
*/
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "mathops.h"
@@ -43,7 +44,7 @@ static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
size = rowsout * (lineout * 6 + 1) + 106;
- if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0)
+ if ((ret = ff_alloc_packet(avctx, pkt, size)) < 0)
return ret;
buf = pkt->data;
More information about the ffmpeg-cvslog
mailing list