Skip to content

Commit

Permalink
lavc: Consistently prefix input buffer defines
Browse files Browse the repository at this point in the history
Signed-off-by: Vittorio Giovara <[email protected]>
  • Loading branch information
kodawah committed Jul 27, 2015
1 parent def9785 commit 059a934
Show file tree
Hide file tree
Showing 150 changed files with 273 additions and 264 deletions.
2 changes: 1 addition & 1 deletion avconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ static int transcode_init(void)

av_assert0(ist && !ost->filter);

extra_size = (uint64_t)dec_ctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE;
extra_size = (uint64_t)dec_ctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE;

if (extra_size > INT_MAX) {
return AVERROR(EINVAL);
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/avcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static void audio_decode_example(const char *outfilename, const char *filename)
AVCodecContext *c= NULL;
int len;
FILE *f, *outfile;
uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
uint8_t inbuf[AUDIO_INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
AVPacket avpkt;
AVFrame *decoded_frame = NULL;

Expand Down Expand Up @@ -459,14 +459,14 @@ static void video_decode_example(const char *outfilename, const char *filename)
int frame, got_picture, len;
FILE *f;
AVFrame *picture;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
uint8_t inbuf[INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
char buf[1024];
AVPacket avpkt;

av_init_packet(&avpkt);

/* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
memset(inbuf + INBUF_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE);

printf("Video decoding\n");

Expand Down
2 changes: 1 addition & 1 deletion doc/examples/qsvdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ int main(int argc, char **argv)
decoder_ctx->codec_id = AV_CODEC_ID_H264;
if (video_st->codec->extradata_size) {
decoder_ctx->extradata = av_mallocz(video_st->codec->extradata_size +
FF_INPUT_BUFFER_PADDING_SIZE);
AV_INPUT_BUFFER_PADDING_SIZE);
if (!decoder_ctx->extradata) {
ret = AVERROR(ENOMEM);
goto finish;
Expand Down
10 changes: 5 additions & 5 deletions libavcodec/4xm.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,13 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length)
}

av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,
bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);
bitstream_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!f->bitstream_buffer)
return AVERROR(ENOMEM);
f->bbdsp.bswap_buf(f->bitstream_buffer, (const uint32_t *) (buf + extra),
bitstream_size / 4);
memset((uint8_t*)f->bitstream_buffer + bitstream_size,
0, FF_INPUT_BUFFER_PADDING_SIZE);
0, AV_INPUT_BUFFER_PADDING_SIZE);
init_get_bits(&f->gb, f->bitstream_buffer, 8 * bitstream_size);

wordstream_offset = extra + bitstream_size;
Expand Down Expand Up @@ -769,13 +769,13 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length)
prestream_size = length + buf - prestream;

av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,
prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);
prestream_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!f->bitstream_buffer)
return AVERROR(ENOMEM);
f->bbdsp.bswap_buf(f->bitstream_buffer, (const uint32_t *) prestream,
prestream_size / 4);
memset((uint8_t*)f->bitstream_buffer + prestream_size,
0, FF_INPUT_BUFFER_PADDING_SIZE);
0, AV_INPUT_BUFFER_PADDING_SIZE);
init_get_bits(&f->pre_gb, f->bitstream_buffer, 8 * prestream_size);

f->last_dc = 0 * 128 * 8 * 8;
Expand Down Expand Up @@ -849,7 +849,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
cfrm = &f->cfrm[i];

cfrm->data = av_fast_realloc(cfrm->data, &cfrm->allocated_size,
cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);
cfrm->size + data_size + AV_INPUT_BUFFER_PADDING_SIZE);
// explicit check needed as memcpy below might not catch a NULL
if (!cfrm->data) {
av_log(f->avctx, AV_LOG_ERROR, "realloc failure");
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/a64multienc.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static av_cold int a64multi_encode_init(AVCodecContext *avctx)
}

/* set up extradata */
if (!(avctx->extradata = av_mallocz(8 * 4 + FF_INPUT_BUFFER_PADDING_SIZE))) {
if (!(avctx->extradata = av_mallocz(8 * 4 + AV_INPUT_BUFFER_PADDING_SIZE))) {
av_log(avctx, AV_LOG_ERROR, "Failed to allocate memory for extradata.\n");
return AVERROR(ENOMEM);
}
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/aac_adtstoasc_bsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
buf += get_bits_count(&gb)/8;
}
avctx->extradata_size = 2 + pce_size;
avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
avctx->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata)
return AVERROR(ENOMEM);

Expand Down
2 changes: 1 addition & 1 deletion libavcodec/aac_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
int size;
union {
uint64_t u64;
uint8_t u8[8 + FF_INPUT_BUFFER_PADDING_SIZE];
uint8_t u8[8 + AV_INPUT_BUFFER_PADDING_SIZE];
} tmp;

tmp.u64 = av_be2ne64(state);
Expand Down
6 changes: 3 additions & 3 deletions libavcodec/aacdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2969,7 +2969,7 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
if (new_extradata) {
av_free(avctx->extradata);
avctx->extradata = av_mallocz(new_extradata_size +
FF_INPUT_BUFFER_PADDING_SIZE);
AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata)
return AVERROR(ENOMEM);
avctx->extradata_size = new_extradata_size;
Expand Down Expand Up @@ -3089,14 +3089,14 @@ static int latm_decode_audio_specific_config(struct LATMContext *latmctx,

if (avctx->extradata_size < esize) {
av_free(avctx->extradata);
avctx->extradata = av_malloc(esize + FF_INPUT_BUFFER_PADDING_SIZE);
avctx->extradata = av_malloc(esize + AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata)
return AVERROR(ENOMEM);
}

avctx->extradata_size = esize;
memcpy(avctx->extradata, gb->buffer + (config_start_bit/8), esize);
memset(avctx->extradata+esize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
memset(avctx->extradata+esize, 0, AV_INPUT_BUFFER_PADDING_SIZE);
}
skip_bits_long(gb, bits_consumed);

Expand Down
2 changes: 1 addition & 1 deletion libavcodec/aacenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ static av_cold int alloc_buffers(AVCodecContext *avctx, AACEncContext *s)
int ch;
FF_ALLOCZ_OR_GOTO(avctx, s->buffer.samples, 3 * 1024 * s->channels * sizeof(s->buffer.samples[0]), alloc_fail);
FF_ALLOCZ_OR_GOTO(avctx, s->cpe, sizeof(ChannelElement) * s->chan_map[0], alloc_fail);
FF_ALLOCZ_OR_GOTO(avctx, avctx->extradata, 5 + FF_INPUT_BUFFER_PADDING_SIZE, alloc_fail);
FF_ALLOCZ_OR_GOTO(avctx, avctx->extradata, 5 + AV_INPUT_BUFFER_PADDING_SIZE, alloc_fail);

for(ch = 0; ch < s->channels; ch++)
s->planar_samples[ch] = s->buffer.samples + 3 * 1024 * ch;
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/ac3_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info,
int err;
union {
uint64_t u64;
uint8_t u8[8 + FF_INPUT_BUFFER_PADDING_SIZE];
uint8_t u8[8 + AV_INPUT_BUFFER_PADDING_SIZE];
} tmp = { av_be2ne64(state) };
AC3HeaderInfo hdr;
GetBitContext gbc;
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/ac3dec.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ typedef struct AC3DecodeContext {
DECLARE_ALIGNED(32, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients
DECLARE_ALIGNED(32, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing
DECLARE_ALIGNED(32, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing
DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread
DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread
///@}
} AC3DecodeContext;

Expand Down
2 changes: 1 addition & 1 deletion libavcodec/adpcmenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 /
avctx->channels + 2;
avctx->block_align = BLKSIZE;
if (!(avctx->extradata = av_malloc(32 + FF_INPUT_BUFFER_PADDING_SIZE)))
if (!(avctx->extradata = av_malloc(32 + AV_INPUT_BUFFER_PADDING_SIZE)))
goto error;
avctx->extradata_size = 32;
extradata = avctx->extradata;
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/alacenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
avctx->channels,
avctx->bits_per_raw_sample);

avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata) {
ret = AVERROR(ENOMEM);
goto error;
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/asvenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,

if (!pkt->data &&
(ret = av_new_packet(pkt, a->mb_height * a->mb_width * MAX_MB_SIZE +
FF_MIN_BUFFER_SIZE)) < 0) {
AV_INPUT_BUFFER_MIN_SIZE)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/atrac3.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);

q->decoded_bytes_buffer = av_mallocz(FFALIGN(avctx->block_align, 4) +
FF_INPUT_BUFFER_PADDING_SIZE);
AV_INPUT_BUFFER_PADDING_SIZE);
if (!q->decoded_bytes_buffer)
return AVERROR(ENOMEM);

Expand Down
23 changes: 16 additions & 7 deletions libavcodec/avcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,24 @@ typedef struct AVCodecDescriptor {
* Note: If the first 23 bits of the additional bytes are not 0, then damaged
* MPEG bitstreams could cause overread and segfault.
*/
#define FF_INPUT_BUFFER_PADDING_SIZE 8
#define AV_INPUT_BUFFER_PADDING_SIZE 8

/**
* @ingroup lavc_encoding
* minimum encoding buffer size
* Used to avoid some checks during header writing.
*/
#define FF_MIN_BUFFER_SIZE 16384
#define AV_INPUT_BUFFER_MIN_SIZE 16384

/**
* @deprecated use AV_INPUT_BUFFER_PADDING_SIZE instead
*/
#define FF_INPUT_BUFFER_PADDING_SIZE 8

/**
* @deprecated use AV_INPUT_BUFFER_MIN_SIZE instead
*/
#define FF_MIN_BUFFER_SIZE 16384

/**
* @ingroup lavc_encoding
Expand Down Expand Up @@ -1362,7 +1371,7 @@ typedef struct AVCodecContext {
* mjpeg: Huffman tables
* rv10: additional flags
* mpeg4: global headers (they can be in the bitstream or here)
* The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
* The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
* than extradata_size to avoid prolems if it is read with the bitstream reader.
* The bytewise contents of extradata must not depend on the architecture or CPU endianness.
* - encoding: Set/allocated/freed by libavcodec.
Expand Down Expand Up @@ -3627,7 +3636,7 @@ int av_grow_packet(AVPacket *pkt, int grow_by);
* function returns successfully, the data is owned by the underlying AVBuffer.
* The caller may not access the data through other means.
* @param size size of data in bytes, without the padding. I.e. the full buffer
* size is assumed to be size + FF_INPUT_BUFFER_PADDING_SIZE.
* size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.
*
* @return 0 on success, a negative AVERROR on error
*/
Expand Down Expand Up @@ -3843,7 +3852,7 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
* returning samples. It is safe to flush even those decoders that are not
* marked with AV_CODEC_CAP_DELAY, then no samples will be returned.
*
* @warning The input buffer, avpkt->data must be FF_INPUT_BUFFER_PADDING_SIZE
* @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
* larger than the actual read bytes because some optimized bitstream
* readers read 32 or 64 bits at once and could read over the end.
*
Expand Down Expand Up @@ -3883,7 +3892,7 @@ int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
* Some decoders may support multiple frames in a single AVPacket, such
* decoders would then just decode the first frame.
*
* @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
* @warning The input buffer must be AV_INPUT_BUFFER_PADDING_SIZE larger than
* the actual read bytes because some optimized bitstream readers read 32 or 64
* bits at once and could read over the end.
*
Expand Down Expand Up @@ -4612,7 +4621,7 @@ AVBitStreamFilter *av_bitstream_filter_next(const AVBitStreamFilter *f);
* Allocate a buffer with padding, reusing the given one if large enough.
*
* Same behaviour av_fast_malloc but the buffer has additional
* FF_INPUT_PADDING_SIZE at the end which will always memset to 0.
* AV_INPUT_PADDING_SIZE at the end which will always memset to 0.
*
*/
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
Expand Down
30 changes: 15 additions & 15 deletions libavcodec/avpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
static int packet_alloc(AVBufferRef **buf, int size)
{
int ret;
if ((unsigned)size >= (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
if ((unsigned)size >= (unsigned)size + AV_INPUT_BUFFER_PADDING_SIZE)
return AVERROR(EINVAL);

ret = av_buffer_realloc(buf, size + FF_INPUT_BUFFER_PADDING_SIZE);
ret = av_buffer_realloc(buf, size + AV_INPUT_BUFFER_PADDING_SIZE);
if (ret < 0)
return ret;

memset((*buf)->data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
memset((*buf)->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);

return 0;
}
Expand Down Expand Up @@ -103,20 +103,20 @@ void av_shrink_packet(AVPacket *pkt, int size)
if (pkt->size <= size)
return;
pkt->size = size;
memset(pkt->data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
memset(pkt->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
}

int av_grow_packet(AVPacket *pkt, int grow_by)
{
int new_size;
av_assert0((unsigned)pkt->size <= INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE);
av_assert0((unsigned)pkt->size <= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
if (!pkt->size)
return av_new_packet(pkt, grow_by);
if ((unsigned)grow_by >
INT_MAX - (pkt->size + FF_INPUT_BUFFER_PADDING_SIZE))
INT_MAX - (pkt->size + AV_INPUT_BUFFER_PADDING_SIZE))
return -1;

new_size = pkt->size + grow_by + FF_INPUT_BUFFER_PADDING_SIZE;
new_size = pkt->size + grow_by + AV_INPUT_BUFFER_PADDING_SIZE;
if (pkt->buf) {
int ret = av_buffer_realloc(&pkt->buf, new_size);
if (ret < 0)
Expand All @@ -134,17 +134,17 @@ FF_ENABLE_DEPRECATION_WARNINGS
}
pkt->data = pkt->buf->data;
pkt->size += grow_by;
memset(pkt->data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);

return 0;
}

int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
{
if (size >= INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
if (size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
return AVERROR(EINVAL);

pkt->buf = av_buffer_create(data, size + FF_INPUT_BUFFER_PADDING_SIZE,
pkt->buf = av_buffer_create(data, size + AV_INPUT_BUFFER_PADDING_SIZE,
av_buffer_default_free, NULL, 0);
if (!pkt->buf)
return AVERROR(ENOMEM);
Expand Down Expand Up @@ -172,9 +172,9 @@ do { \
void *data; \
if (padding) { \
if ((unsigned)(size) > \
(unsigned)(size) + FF_INPUT_BUFFER_PADDING_SIZE) \
(unsigned)(size) + AV_INPUT_BUFFER_PADDING_SIZE) \
goto failed_alloc; \
ALLOC(data, size + FF_INPUT_BUFFER_PADDING_SIZE); \
ALLOC(data, size + AV_INPUT_BUFFER_PADDING_SIZE); \
} else { \
ALLOC(data, size); \
} \
Expand All @@ -183,7 +183,7 @@ do { \
memcpy(data, src, size); \
if (padding) \
memset((uint8_t *)data + size, 0, \
FF_INPUT_BUFFER_PADDING_SIZE); \
AV_INPUT_BUFFER_PADDING_SIZE); \
dst = data; \
} while (0)

Expand Down Expand Up @@ -266,15 +266,15 @@ uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,

if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data))
return NULL;
if ((unsigned)size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
return NULL;

pkt->side_data = av_realloc(pkt->side_data,
(elems + 1) * sizeof(*pkt->side_data));
if (!pkt->side_data)
return NULL;

pkt->side_data[elems].data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
pkt->side_data[elems].data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!pkt->side_data[elems].data)
return NULL;
pkt->side_data[elems].size = size;
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/binkaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
return AVERROR_INVALIDDATA;
}
buf = av_realloc(s->packet_buffer, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
buf = av_realloc(s->packet_buffer, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!buf)
return AVERROR(ENOMEM);
s->packet_buffer = buf;
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/cdxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static int cdxl_decode_frame(AVCodecContext *avctx, void *data,

if (encoding) {
av_fast_padded_malloc(&c->new_video, &c->new_video_size,
h * w + FF_INPUT_BUFFER_PADDING_SIZE);
h * w + AV_INPUT_BUFFER_PADDING_SIZE);
if (!c->new_video)
return AVERROR(ENOMEM);
if (c->bpp == 8)
Expand Down
Loading

0 comments on commit 059a934

Please sign in to comment.