diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c index 50da46738c..6179b50583 100644 --- a/libavcodec/asvenc.c +++ b/libavcodec/asvenc.c @@ -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); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 0018ccbb0c..43859251cc 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -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 diff --git a/libavcodec/encode.h b/libavcodec/encode.h index e019cd7702..85331e04b7 100644 --- a/libavcodec/encode.h +++ b/libavcodec/encode.h @@ -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. * diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 8203844d6b..ed738dee64 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -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"); diff --git a/libavcodec/flashsv2enc.c b/libavcodec/flashsv2enc.c index 75b48eb1fd..6dcb9102a8 100644 --- a/libavcodec/flashsv2enc.c +++ b/libavcodec/flashsv2enc.c @@ -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 */ diff --git a/libavcodec/gif.c b/libavcodec/gif.c index a4b1538f0c..12c343cd27 100644 --- a/libavcodec/gif.c +++ b/libavcodec/gif.c @@ -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; diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index b3c03b6a5f..b220949939 100644 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@ -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) { diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c index 60b6cf85ba..ed58deded6 100644 --- a/libavcodec/j2kenc.c +++ b/libavcodec/j2kenc.c @@ -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: diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c index 478df832ae..9ba1bb7bf6 100644 --- a/libavcodec/jpeglsenc.c +++ b/libavcodec/jpeglsenc.c @@ -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); diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c index aa813b6a61..8694deeb16 100644 --- a/libavcodec/libxvid.c +++ b/libavcodec/libxvid.c @@ -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 */ diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c index d655d064f3..767f876e94 100644 --- a/libavcodec/ljpegenc.c +++ b/libavcodec/ljpegenc.c @@ -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 diff --git a/libavcodec/msrleenc.c b/libavcodec/msrleenc.c index 931e7af053..cc39aa308f 100644 --- a/libavcodec/msrleenc.c +++ b/libavcodec/msrleenc.c @@ -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]) { diff --git a/libavcodec/msvideo1enc.c b/libavcodec/msvideo1enc.c index 1fb8be8883..3bea3ed297 100644 --- a/libavcodec/msvideo1enc.c +++ b/libavcodec/msvideo1enc.c @@ -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; diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index d4825ee0c2..8691808f3c 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -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); diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c index a348b7622a..80cb4bb444 100644 --- a/libavcodec/proresenc_anatoliy.c +++ b/libavcodec/proresenc_anatoliy.c @@ -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; diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index 11cfea36bf..aafc081928 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -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; diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 8578286ec6..658d3cd39f 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -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); diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c index d8a34a8fdb..324544c7ad 100644 --- a/libavcodec/svq1enc.c +++ b/libavcodec/svq1enc.c @@ -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; diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c index 935b83f33c..14ad655540 100644 --- a/libavcodec/tiffenc.c +++ b/libavcodec/tiffenc.c @@ -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; diff --git a/libavcodec/version.h b/libavcodec/version.h index ecdbc51c74..19f3f4a272 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -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, \ diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h index 45209c0a4f..161442df95 100644 --- a/libavcodec/version_major.h +++ b/libavcodec/version_major.h @@ -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)