Skip to content

Commit

Permalink
Merge commit '059a934806d61f7af9ab3fd9f74994b838ea5eba'
Browse files Browse the repository at this point in the history
* commit '059a934806d61f7af9ab3fd9f74994b838ea5eba':
  lavc: Consistently prefix input buffer defines

Conflicts:
	doc/examples/decoding_encoding.c
	libavcodec/4xm.c
	libavcodec/aac_adtstoasc_bsf.c
	libavcodec/aacdec.c
	libavcodec/aacenc.c
	libavcodec/ac3dec.h
	libavcodec/asvenc.c
	libavcodec/avcodec.h
	libavcodec/avpacket.c
	libavcodec/dvdec.c
	libavcodec/ffv1enc.c
	libavcodec/g2meet.c
	libavcodec/gif.c
	libavcodec/h264.c
	libavcodec/h264_mp4toannexb_bsf.c
	libavcodec/huffyuvdec.c
	libavcodec/huffyuvenc.c
	libavcodec/jpeglsenc.c
	libavcodec/libxvid.c
	libavcodec/mdec.c
	libavcodec/motionpixels.c
	libavcodec/mpeg4videodec.c
	libavcodec/mpegvideo.c
	libavcodec/noise_bsf.c
	libavcodec/nuv.c
	libavcodec/nvenc.c
	libavcodec/options.c
	libavcodec/parser.c
	libavcodec/pngenc.c
	libavcodec/proresenc_kostya.c
	libavcodec/qsvdec.c
	libavcodec/svq1enc.c
	libavcodec/tiffenc.c
	libavcodec/truemotion2.c
	libavcodec/utils.c
	libavcodec/utvideoenc.c
	libavcodec/vc1dec.c
	libavcodec/wmalosslessdec.c
	libavformat/adxdec.c
	libavformat/aiffdec.c
	libavformat/apc.c
	libavformat/apetag.c
	libavformat/avidec.c
	libavformat/bink.c
	libavformat/cafdec.c
	libavformat/flvdec.c
	libavformat/id3v2.c
	libavformat/isom.c
	libavformat/matroskadec.c
	libavformat/mov.c
	libavformat/mpc.c
	libavformat/mpc8.c
	libavformat/mpegts.c
	libavformat/mvi.c
	libavformat/mxfdec.c
	libavformat/mxg.c
	libavformat/nutdec.c
	libavformat/oggdec.c
	libavformat/oggparsecelt.c
	libavformat/oggparseflac.c
	libavformat/oggparseopus.c
	libavformat/oggparsespeex.c
	libavformat/omadec.c
	libavformat/rawdec.c
	libavformat/riffdec.c
	libavformat/rl2.c
	libavformat/rmdec.c
	libavformat/rtpdec_latm.c
	libavformat/rtpdec_mpeg4.c
	libavformat/rtpdec_qdm2.c
	libavformat/rtpdec_svq3.c
	libavformat/sierravmd.c
	libavformat/smacker.c
	libavformat/smush.c
	libavformat/spdifenc.c
	libavformat/takdec.c
	libavformat/tta.c
	libavformat/utils.c
	libavformat/vqf.c
	libavformat/westwood_vqa.c
	libavformat/xmv.c
	libavformat/xwma.c
	libavformat/yop.c

Merged-by: Michael Niedermayer <[email protected]>
  • Loading branch information
michaelni committed Jul 27, 2015
2 parents 444e987 + 059a934 commit 29d147c
Show file tree
Hide file tree
Showing 153 changed files with 296 additions and 287 deletions.
6 changes: 3 additions & 3 deletions doc/examples/decoding_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,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 @@ -538,13 +538,13 @@ static void video_decode_example(const char *outfilename, const char *filename)
int frame_count;
FILE *f;
AVFrame *frame;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
uint8_t inbuf[INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
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("Decode video file %s to %s\n", filename, outfilename);

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
8 changes: 4 additions & 4 deletions ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
int ret;

if (!ost->st->codec->extradata_size && ost->enc_ctx->extradata_size) {
ost->st->codec->extradata = av_mallocz(ost->enc_ctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
ost->st->codec->extradata = av_mallocz(ost->enc_ctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (ost->st->codec->extradata) {
memcpy(ost->st->codec->extradata, ost->enc_ctx->extradata, ost->enc_ctx->extradata_size);
ost->st->codec->extradata_size = ost->enc_ctx->extradata_size;
Expand Down Expand Up @@ -688,10 +688,10 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
pkt->data, pkt->size,
pkt->flags & AV_PKT_FLAG_KEY);
if(a == 0 && new_pkt.data != pkt->data && new_pkt.destruct) {
uint8_t *t = av_malloc(new_pkt.size + FF_INPUT_BUFFER_PADDING_SIZE); //the new should be a subset of the old so cannot overflow
uint8_t *t = av_malloc(new_pkt.size + AV_INPUT_BUFFER_PADDING_SIZE); //the new should be a subset of the old so cannot overflow
if(t) {
memcpy(t, new_pkt.data, new_pkt.size);
memset(t + new_pkt.size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
memset(t + new_pkt.size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
new_pkt.data = t;
new_pkt.buf = NULL;
a = 1;
Expand Down Expand Up @@ -2811,7 +2811,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
2 changes: 1 addition & 1 deletion ffserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3510,7 +3510,7 @@ static void extract_mpeg4_header(AVFormatContext *infile)
if (p[0] == 0x00 && p[1] == 0x00 &&
p[2] == 0x01 && p[3] == 0xb6) {
size = p - pkt.data;
st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
st->codec->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
st->codec->extradata_size = size;
memcpy(st->codec->extradata, pkt.data, size);
break;
Expand Down
4 changes: 2 additions & 2 deletions libavcodec/4xm.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,11 @@ static int decode_frame(AVCodecContext *avctx, void *data,
}
cfrm = &f->cfrm[i];

if (data_size > UINT_MAX - cfrm->size - FF_INPUT_BUFFER_PADDING_SIZE)
if (data_size > UINT_MAX - cfrm->size - AV_INPUT_BUFFER_PADDING_SIZE)
return AVERROR_INVALIDDATA;

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\n");
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/a64multienc.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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 @@ -89,7 +89,7 @@ static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
}
av_free(avctx->extradata);
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) {
avctx->extradata_size = 0;
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
4 changes: 2 additions & 2 deletions libavcodec/aacdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,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/aacdec_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -3098,7 +3098,7 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
if (new_extradata && 0) {
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
2 changes: 1 addition & 1 deletion libavcodec/aacenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ static av_cold int alloc_buffers(AVCodecContext *avctx, AACEncContext *s)
int ch;
FF_ALLOCZ_ARRAY_OR_GOTO(avctx, s->buffer.samples, s->channels, 3 * 1024 * sizeof(s->buffer.samples[0]), alloc_fail);
FF_ALLOCZ_ARRAY_OR_GOTO(avctx, s->cpe, s->chan_map[0], sizeof(ChannelElement), 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 @@ -166,7 +166,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, *phdr = &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 @@ -235,7 +235,7 @@ typedef struct AC3DecodeContext {
DECLARE_ALIGNED(32, INTFLOAT, window)[AC3_BLOCK_SIZE]; ///< window coefficients
DECLARE_ALIGNED(32, INTFLOAT, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing
DECLARE_ALIGNED(32, SHORTFLOAT, 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 @@ -113,7 +113,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2;
avctx->bits_per_coded_sample = 4;
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 @@ -531,7 +531,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 @@ -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)) < 0)
AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
return ret;

init_put_bits(&a->pb, pkt->data, pkt->size);
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/atrac3.c
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,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 @@ -632,15 +632,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 32
#define AV_INPUT_BUFFER_PADDING_SIZE 32

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

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

/**
* @ingroup lavc_encoding
Expand Down Expand Up @@ -1595,7 +1604,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 problems 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 @@ -4062,7 +4071,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 @@ -4399,7 +4408,7 @@ attribute_deprecated int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *s
* 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 @@ -4439,7 +4448,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 @@ -5447,7 +5456,7 @@ AVBitStreamFilter *av_bitstream_filter_next(const AVBitStreamFilter *f);

/**
* Same behaviour av_fast_malloc but the buffer has additional
* FF_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0.
* AV_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0.
*
* In addition the whole buffer will initially and after resizes
* be 0-initialized so that no uninitialized data will ever appear.
Expand Down
Loading

0 comments on commit 29d147c

Please sign in to comment.