mirror of
https://github.com/librempeg/librempeg
synced 2024-11-22 09:02:20 +00:00
avcodec/avcodec: Deprecate AV_INPUT_BUFFER_MIN_SIZE
It used to be used with preallocated packet buffers with the old encode API, but said API is no more and therefore there is no reason for this to be public any more. So deprecate it and use an internal replacement for the encoders using it as an upper bound for the size of their headers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
2613ac13bf
commit
6b1cf924ed
@ -272,7 +272,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
}
|
||||
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, c->mb_height * c->mb_width * MAX_MB_SIZE +
|
||||
AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return ret;
|
||||
|
||||
init_put_bits(&a->pb, pkt->data, pkt->size);
|
||||
|
@ -187,12 +187,16 @@ struct AVCodecParameters;
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if FF_API_BUFFER_MIN_SIZE
|
||||
/**
|
||||
* @ingroup lavc_encoding
|
||||
* minimum encoding buffer size
|
||||
* Used to avoid some checks during header writing.
|
||||
* @deprecated Unused: avcodec_receive_packet() does not work
|
||||
* with preallocated packet buffers.
|
||||
*/
|
||||
#define AV_INPUT_BUFFER_MIN_SIZE 16384
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup lavc_encoding
|
||||
|
@ -26,6 +26,12 @@
|
||||
#include "avcodec.h"
|
||||
#include "packet.h"
|
||||
|
||||
/**
|
||||
* Used by some encoders as upper bound for the length of headers.
|
||||
* TODO: Use proper codec-specific upper bounds.
|
||||
*/
|
||||
#define FF_INPUT_BUFFER_MIN_SIZE 16384
|
||||
|
||||
/**
|
||||
* Called by encoders to get the next frame for encoding.
|
||||
*
|
||||
|
@ -1104,7 +1104,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
uint8_t keystate = 128;
|
||||
uint8_t *buf_p;
|
||||
int i, ret;
|
||||
int64_t maxsize = AV_INPUT_BUFFER_MIN_SIZE
|
||||
int64_t maxsize = FF_INPUT_BUFFER_MIN_SIZE
|
||||
+ avctx->width*avctx->height*37LL*4;
|
||||
|
||||
if(!pict) {
|
||||
@ -1154,7 +1154,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
}
|
||||
|
||||
if (f->version > 3)
|
||||
maxsize = AV_INPUT_BUFFER_MIN_SIZE + avctx->width*avctx->height*3LL*4;
|
||||
maxsize = FF_INPUT_BUFFER_MIN_SIZE + avctx->width*avctx->height*3LL*4;
|
||||
|
||||
if (maxsize > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32) {
|
||||
av_log(avctx, AV_LOG_WARNING, "Cannot allocate worst case packet size, the encoding could fail\n");
|
||||
|
@ -857,7 +857,7 @@ static int flashsv2_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
int res;
|
||||
int keyframe = 0;
|
||||
|
||||
if ((res = ff_alloc_packet(avctx, pkt, s->frame_size + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
if ((res = ff_alloc_packet(avctx, pkt, s->frame_size + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return res;
|
||||
|
||||
/* First frame needs to be a keyframe */
|
||||
|
@ -477,7 +477,7 @@ static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
const uint32_t *palette = NULL;
|
||||
int ret;
|
||||
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*7/5 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*7/5 + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return ret;
|
||||
outbuf_ptr = pkt->data;
|
||||
end = pkt->data + pkt->size;
|
||||
|
@ -762,7 +762,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
const AVFrame * const p = pict;
|
||||
int i, j, size = 0, ret;
|
||||
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, width * height * 3 * 4 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, width * height * 3 * 4 + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return ret;
|
||||
|
||||
if (s->context) {
|
||||
|
@ -1534,7 +1534,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
uint8_t *chunkstart, *jp2cstart, *jp2hstart;
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
|
||||
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*9 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*9 + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return ret;
|
||||
|
||||
// init:
|
||||
|
@ -432,7 +432,7 @@ static av_cold int encode_jpegls_init(AVCodecContext *avctx)
|
||||
ctx->comps = 1;
|
||||
else
|
||||
ctx->comps = 3;
|
||||
size = AV_INPUT_BUFFER_MIN_SIZE;
|
||||
size = FF_INPUT_BUFFER_MIN_SIZE;
|
||||
/* INT_MAX due to PutBit-API. */
|
||||
if (avctx->width * (unsigned)avctx->height > (INT_MAX - size) / 4 / ctx->comps)
|
||||
return AVERROR(ERANGE);
|
||||
|
@ -739,7 +739,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_packet(avctx, pkt, mb_width*(int64_t)mb_height*MAX_MB_BYTES + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, mb_width*(int64_t)mb_height*MAX_MB_BYTES + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return ret;
|
||||
|
||||
/* Start setting up the frame */
|
||||
|
@ -214,7 +214,7 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
const int height = avctx->height;
|
||||
const int mb_width = (width + s->hsample[0] - 1) / s->hsample[0];
|
||||
const int mb_height = (height + s->vsample[0] - 1) / s->vsample[0];
|
||||
size_t max_pkt_size = AV_INPUT_BUFFER_MIN_SIZE;
|
||||
size_t max_pkt_size = FF_INPUT_BUFFER_MIN_SIZE;
|
||||
int ret, header_bits;
|
||||
|
||||
if( avctx->pix_fmt == AV_PIX_FMT_BGR0
|
||||
|
@ -252,7 +252,7 @@ static int msrle_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, (
|
||||
avctx->width*2 /* worst case = rle every pixel */ + 2 /*end of line */
|
||||
) * avctx->height + 2 /* end of bitmap */ + AV_INPUT_BUFFER_MIN_SIZE)))
|
||||
) * avctx->height + 2 /* end of bitmap */ + FF_INPUT_BUFFER_MIN_SIZE)))
|
||||
return ret;
|
||||
|
||||
if (pict->data[1]) {
|
||||
|
@ -78,7 +78,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
int skips = 0;
|
||||
int quality = 24;
|
||||
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*9 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*9 + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return ret;
|
||||
dst= buf= pkt->data;
|
||||
|
||||
|
@ -637,7 +637,7 @@ static int encode_png(AVCodecContext *avctx, AVPacket *pkt,
|
||||
enc_row_size = deflateBound(&s->zstream.zstream,
|
||||
(avctx->width * s->bits_per_pixel + 7) >> 3);
|
||||
max_packet_size =
|
||||
AV_INPUT_BUFFER_MIN_SIZE + // headers
|
||||
FF_INPUT_BUFFER_MIN_SIZE + // headers
|
||||
avctx->height * (
|
||||
enc_row_size +
|
||||
12 * (((int64_t)enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) // IDAT * ceil(enc_row_size / IOBUF_SIZE)
|
||||
@ -968,7 +968,7 @@ static int encode_apng(AVCodecContext *avctx, AVPacket *pkt,
|
||||
enc_row_size = deflateBound(&s->zstream.zstream,
|
||||
(avctx->width * s->bits_per_pixel + 7) >> 3);
|
||||
max_packet_size =
|
||||
AV_INPUT_BUFFER_MIN_SIZE + // headers
|
||||
FF_INPUT_BUFFER_MIN_SIZE + // headers
|
||||
avctx->height * (
|
||||
enc_row_size +
|
||||
(4 + 12) * (((int64_t)enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) // fdAT * ceil(enc_row_size / IOBUF_SIZE)
|
||||
@ -982,7 +982,7 @@ static int encode_apng(AVCodecContext *avctx, AVPacket *pkt,
|
||||
if (!pict)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
s->bytestream = s->extra_data = av_malloc(AV_INPUT_BUFFER_MIN_SIZE);
|
||||
s->bytestream = s->extra_data = av_malloc(FF_INPUT_BUFFER_MIN_SIZE);
|
||||
if (!s->extra_data)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
|
@ -733,10 +733,10 @@ static int prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
uint8_t *buf;
|
||||
int compress_frame_size, pic_size, ret, is_top_field_first = 0;
|
||||
uint8_t frame_flags;
|
||||
int frame_size = FFALIGN(avctx->width, 16) * FFALIGN(avctx->height, 16)*16 + 500 + AV_INPUT_BUFFER_MIN_SIZE; //FIXME choose tighter limit
|
||||
int frame_size = FFALIGN(avctx->width, 16) * FFALIGN(avctx->height, 16)*16 + 500 + FF_INPUT_BUFFER_MIN_SIZE; //FIXME choose tighter limit
|
||||
|
||||
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, frame_size + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, frame_size + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return ret;
|
||||
|
||||
buf = pkt->data;
|
||||
|
@ -981,7 +981,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
ctx->pic = pic;
|
||||
pkt_size = ctx->frame_size_upper_bound;
|
||||
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, pkt_size + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, pkt_size + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return ret;
|
||||
|
||||
orig_buf = pkt->data;
|
||||
|
@ -1761,7 +1761,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_packet(avctx, pkt, s->b_width*s->b_height*MB_SIZE*MB_SIZE*3 + AV_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, s->b_width*s->b_height*MB_SIZE*MB_SIZE*3 + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
|
||||
return ret;
|
||||
|
||||
ff_init_range_encoder(c, pkt->data, pkt->size);
|
||||
|
@ -655,7 +655,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
int i, ret;
|
||||
|
||||
ret = ff_alloc_packet(avctx, pkt, s->y_block_width * s->y_block_height *
|
||||
MAX_MB_BYTES * 3 + AV_INPUT_BUFFER_MIN_SIZE);
|
||||
MAX_MB_BYTES * 3 + FF_INPUT_BUFFER_MIN_SIZE);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
|
@ -334,7 +334,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
bytes_per_row = (((s->width - 1) / s->subsampling[0] + 1) * s->bpp *
|
||||
s->subsampling[0] * s->subsampling[1] + 7) >> 3;
|
||||
packet_size = avctx->height * bytes_per_row * 2 +
|
||||
avctx->height * 4 + AV_INPUT_BUFFER_MIN_SIZE;
|
||||
avctx->height * 4 + FF_INPUT_BUFFER_MIN_SIZE;
|
||||
|
||||
if ((ret = ff_alloc_packet(avctx, pkt, packet_size)) < 0)
|
||||
return ret;
|
||||
|
@ -29,8 +29,8 @@
|
||||
|
||||
#include "version_major.h"
|
||||
|
||||
#define LIBAVCODEC_VERSION_MINOR 39
|
||||
#define LIBAVCODEC_VERSION_MICRO 101
|
||||
#define LIBAVCODEC_VERSION_MINOR 40
|
||||
#define LIBAVCODEC_VERSION_MICRO 100
|
||||
|
||||
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
|
||||
LIBAVCODEC_VERSION_MINOR, \
|
||||
|
@ -53,6 +53,7 @@
|
||||
#define FF_API_AVFFT (LIBAVCODEC_VERSION_MAJOR < 62)
|
||||
#define FF_API_FF_PROFILE_LEVEL (LIBAVCODEC_VERSION_MAJOR < 62)
|
||||
#define FF_API_AVCODEC_CLOSE (LIBAVCODEC_VERSION_MAJOR < 62)
|
||||
#define FF_API_BUFFER_MIN_SIZE (LIBAVCODEC_VERSION_MAJOR < 62)
|
||||
|
||||
// reminder to remove CrystalHD decoders on next major bump
|
||||
#define FF_CODEC_CRYSTAL_HD (LIBAVCODEC_VERSION_MAJOR < 61)
|
||||
|
Loading…
Reference in New Issue
Block a user