From a807c68253b02cce8b9fbc87d7857c31d531a1ee Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 13 Oct 2013 10:30:59 +0000 Subject: avformat: use ff_alloc_extradata() Signed-off-by: Paul B Mahol --- libavformat/adxdec.c | 3 +-- libavformat/afc.c | 4 +--- libavformat/aiffdec.c | 4 +--- libavformat/apc.c | 6 ++---- libavformat/ape.c | 4 ++-- libavformat/apetag.c | 5 ++--- libavformat/avidec.c | 12 ++---------- libavformat/bink.c | 8 ++------ libavformat/bintext.c | 15 ++++----------- libavformat/cafdec.c | 8 ++------ libavformat/dfa.c | 4 ++-- libavformat/ffmdec.c | 8 ++------ libavformat/flic.c | 8 ++------ libavformat/flvdec.c | 8 ++------ libavformat/idcin.c | 4 +--- libavformat/isom.c | 4 +--- libavformat/libnut.c | 3 +-- libavformat/matroskadec.c | 9 ++------- libavformat/mov.c | 24 +++++------------------- libavformat/mpc.c | 4 ++-- libavformat/mpc8.c | 4 ++-- libavformat/mpegts.c | 4 +--- libavformat/mvi.c | 4 +--- libavformat/mxfdec.c | 4 +--- libavformat/nutdec.c | 4 +--- libavformat/nuv.c | 4 +--- libavformat/oggparseflac.c | 6 ++---- libavformat/oggparseogm.c | 5 ++--- libavformat/oggparsespeex.c | 4 +--- libavformat/omadec.c | 6 ++---- libavformat/redspark.c | 4 +--- libavformat/riffdec.c | 5 +---- libavformat/rl2.c | 4 +--- libavformat/rmdec.c | 4 +--- libavformat/rsd.c | 4 +--- libavformat/rtpdec_latm.c | 5 +---- libavformat/rtpdec_mpeg4.c | 4 +--- libavformat/rtpdec_qdm2.c | 5 ++--- libavformat/rtpdec_svq3.c | 5 ++--- libavformat/rtpdec_xiph.c | 5 +++-- libavformat/sbgdec.c | 6 ++---- libavformat/sierravmd.c | 4 +--- libavformat/smacker.c | 5 +---- libavformat/smush.c | 4 +--- libavformat/tta.c | 6 +----- libavformat/utils.c | 10 ++-------- libavformat/vc1test.c | 4 ++-- libavformat/vqf.c | 3 +-- libavformat/wavdec.c | 5 +---- libavformat/westwood_vqa.c | 8 ++------ libavformat/xmv.c | 4 +--- libavformat/yop.c | 7 +------ 52 files changed, 83 insertions(+), 218 deletions(-) diff --git a/libavformat/adxdec.c b/libavformat/adxdec.c index 38f09f4ca7..0a0436f184 100644 --- a/libavformat/adxdec.c +++ b/libavformat/adxdec.c @@ -78,8 +78,7 @@ static int adx_read_header(AVFormatContext *s) c->header_size = avio_rb16(s->pb) + 4; avio_seek(s->pb, -4, SEEK_CUR); - avctx->extradata = av_mallocz(c->header_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!avctx->extradata) + if (ff_alloc_extradata(avctx, c->header_size)) return AVERROR(ENOMEM); if (avio_read(s->pb, avctx->extradata, c->header_size) < c->header_size) { av_freep(&avctx->extradata); diff --git a/libavformat/afc.c b/libavformat/afc.c index 183a8e0030..8dbd232fc1 100644 --- a/libavformat/afc.c +++ b/libavformat/afc.c @@ -39,10 +39,8 @@ static int afc_read_header(AVFormatContext *s) st->codec->codec_id = AV_CODEC_ID_ADPCM_AFC; st->codec->channels = 2; st->codec->channel_layout = AV_CH_LAYOUT_STEREO; - st->codec->extradata_size = 1; - st->codec->extradata = av_mallocz(1 + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, 1)) return AVERROR(ENOMEM); st->codec->extradata[0] = 8 * st->codec->channels; diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index 851091e5cb..2883713253 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -276,10 +276,8 @@ static int aiff_read_header(AVFormatContext *s) case MKTAG('w', 'a', 'v', 'e'): if ((uint64_t)size > (1<<30)) return -1; - st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, size)) return AVERROR(ENOMEM); - st->codec->extradata_size = size; avio_read(pb, st->codec->extradata, size); if (st->codec->codec_id == AV_CODEC_ID_QDM2 && size>=12*4 && !st->codec->block_align) { st->codec->block_align = AV_RB32(st->codec->extradata+11*4); diff --git a/libavformat/apc.c b/libavformat/apc.c index bb28a628f7..08ae9351dc 100644 --- a/libavformat/apc.c +++ b/libavformat/apc.c @@ -23,6 +23,7 @@ #include "libavutil/channel_layout.h" #include "avformat.h" +#include "internal.h" static int apc_probe(AVProbeData *p) { @@ -51,10 +52,7 @@ static int apc_read_header(AVFormatContext *s) avio_rl32(pb); /* number of samples */ st->codec->sample_rate = avio_rl32(pb); - st->codec->extradata_size = 2 * 4; - st->codec->extradata = av_malloc(st->codec->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, 2 * 4)) return AVERROR(ENOMEM); /* initial predictor values for adpcm decoder */ diff --git a/libavformat/ape.c b/libavformat/ape.c index 7ed9dd813b..613a59d5f8 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -354,8 +354,8 @@ static int ape_read_header(AVFormatContext * s) st->duration = total_blocks; avpriv_set_pts_info(st, 64, 1, ape->samplerate); - st->codec->extradata = av_malloc(APE_EXTRADATA_SIZE); - st->codec->extradata_size = APE_EXTRADATA_SIZE; + if (ff_alloc_extradata(st->codec, APE_EXTRADATA_SIZE)) + return AVERROR(ENOMEM); AV_WL16(st->codec->extradata + 0, ape->fileversion); AV_WL16(st->codec->extradata + 2, ape->compressiontype); AV_WL16(st->codec->extradata + 4, ape->formatflags); diff --git a/libavformat/apetag.c b/libavformat/apetag.c index ab93736718..a376a0bc4a 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -88,14 +88,13 @@ static int ape_tag_read_field(AVFormatContext *s) st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; } else { - st->codec->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, size)) return AVERROR(ENOMEM); if (avio_read(pb, st->codec->extradata, size) != size) { av_freep(&st->codec->extradata); + st->codec->extradata_size = 0; return AVERROR(EIO); } - st->codec->extradata_size = size; st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; } } else { diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 44ab9d9a3f..1a40e94c82 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -648,12 +648,8 @@ static int avi_read_header(AVFormatContext *s) st->codec->extradata_size = esize - 10 * 4; } else st->codec->extradata_size = size - 10 * 4; - st->codec->extradata = av_malloc(st->codec->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) { - st->codec->extradata_size = 0; + if (ff_alloc_extradata(st->codec, st->codec->extradata_size)) return AVERROR(ENOMEM); - } avio_read(pb, st->codec->extradata, st->codec->extradata_size); @@ -781,12 +777,8 @@ static int avi_read_header(AVFormatContext *s) st = s->streams[stream_index]; if (size<(1<<30)) { - st->codec->extradata_size= size; - st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) { - st->codec->extradata_size= 0; + if (ff_alloc_extradata(st->codec, size)) return AVERROR(ENOMEM); - } avio_read(pb, st->codec->extradata, st->codec->extradata_size); } diff --git a/libavformat/bink.c b/libavformat/bink.c index 887f70a512..6db73cce3a 100644 --- a/libavformat/bink.c +++ b/libavformat/bink.c @@ -116,10 +116,8 @@ static int read_header(AVFormatContext *s) vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = AV_CODEC_ID_BINKVIDEO; - vst->codec->extradata = av_mallocz(4 + FF_INPUT_BUFFER_PADDING_SIZE); - if (!vst->codec->extradata) + if (ff_alloc_extradata(vst->codec, 4)) return AVERROR(ENOMEM); - vst->codec->extradata_size = 4; avio_read(pb, vst->codec->extradata, 4); bink->num_audio_tracks = avio_rl32(pb); @@ -152,10 +150,8 @@ static int read_header(AVFormatContext *s) ast->codec->channels = 1; ast->codec->channel_layout = AV_CH_LAYOUT_MONO; } - ast->codec->extradata = av_mallocz(4 + FF_INPUT_BUFFER_PADDING_SIZE); - if (!ast->codec->extradata) + if (ff_alloc_extradata(ast->codec, 4)) return AVERROR(ENOMEM); - ast->codec->extradata_size = 4; AV_WL32(ast->codec->extradata, vst->codec->codec_tag); } diff --git a/libavformat/bintext.c b/libavformat/bintext.c index c1c6c0064a..d5046075a1 100644 --- a/libavformat/bintext.c +++ b/libavformat/bintext.c @@ -136,9 +136,7 @@ static int bintext_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codec->codec_id = AV_CODEC_ID_BINTEXT; - st->codec->extradata_size = 2; - st->codec->extradata = av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, 2)) return AVERROR(ENOMEM); st->codec->extradata[0] = 16; st->codec->extradata[1] = 0; @@ -194,8 +192,7 @@ static int xbin_read_header(AVFormatContext *s) st->codec->extradata_size += fontheight * (flags & 0x10 ? 512 : 256); st->codec->codec_id = flags & 4 ? AV_CODEC_ID_XBIN : AV_CODEC_ID_BINTEXT; - st->codec->extradata = av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, st->codec->extradata_size)) return AVERROR(ENOMEM); st->codec->extradata[0] = fontheight; st->codec->extradata[1] = flags; @@ -227,9 +224,7 @@ static int adf_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codec->codec_id = AV_CODEC_ID_BINTEXT; - st->codec->extradata_size = 2 + 48 + 4096; - st->codec->extradata = av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, 2 + 48 + 4096)) return AVERROR(ENOMEM); st->codec->extradata[0] = 16; st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; @@ -284,9 +279,7 @@ static int idf_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codec->codec_id = AV_CODEC_ID_IDF; - st->codec->extradata_size = 2 + 48 + 4096; - st->codec->extradata = av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, 2 + 48 + 4096)) return AVERROR(ENOMEM); st->codec->extradata[0] = 16; st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index 337758ee12..e954c65683 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -130,8 +130,7 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) } avio_read(pb, preamble, ALAC_PREAMBLE); - st->codec->extradata = av_mallocz(ALAC_HEADER + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, ALAC_HEADER)) return AVERROR(ENOMEM); /* For the old style cookie, we skip 12 bytes, then read 36 bytes. @@ -154,13 +153,10 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) avio_read(pb, &st->codec->extradata[24], ALAC_NEW_KUKI - 12); avio_skip(pb, size - ALAC_NEW_KUKI); } - st->codec->extradata_size = ALAC_HEADER; } else { - st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, size)) return AVERROR(ENOMEM); avio_read(pb, st->codec->extradata, size); - st->codec->extradata_size = size; } return 0; diff --git a/libavformat/dfa.c b/libavformat/dfa.c index 5799d983cf..12516afdc5 100644 --- a/libavformat/dfa.c +++ b/libavformat/dfa.c @@ -64,8 +64,8 @@ static int dfa_read_header(AVFormatContext *s) avio_skip(pb, 128 - 16); // padding st->duration = frames; - st->codec->extradata = av_malloc(2); - st->codec->extradata_size = 2; + if (ff_alloc_extradata(st->codec, 2)) + return AVERROR(ENOMEM); AV_WL16(st->codec->extradata, version); if (version == 0x100) st->sample_aspect_ratio = (AVRational){2, 1}; diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c index 02cf790f87..b20ee131b6 100644 --- a/libavformat/ffmdec.c +++ b/libavformat/ffmdec.c @@ -278,9 +278,7 @@ static int ffm2_read_header(AVFormatContext *s) codec->flags2 = avio_rb32(pb); codec->debug = avio_rb32(pb); if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) { - codec->extradata_size = avio_rb32(pb); - codec->extradata = av_malloc(codec->extradata_size); - if (!codec->extradata) + if (ff_alloc_extradata(codec, avio_rb32(pb))) return AVERROR(ENOMEM); avio_read(pb, codec->extradata, codec->extradata_size); } @@ -468,9 +466,7 @@ static int ffm_read_header(AVFormatContext *s) goto fail; } if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) { - codec->extradata_size = avio_rb32(pb); - codec->extradata = av_malloc(codec->extradata_size); - if (!codec->extradata) + if (ff_alloc_extradata(codec, avio_rb32(pb))) return AVERROR(ENOMEM); avio_read(pb, codec->extradata, codec->extradata_size); } diff --git a/libavformat/flic.c b/libavformat/flic.c index e04e2778c9..7235f2e188 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -125,10 +125,8 @@ static int flic_read_header(AVFormatContext *s) } /* send over the whole 128-byte FLIC header */ - st->codec->extradata = av_malloc(FLIC_HEADER_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, FLIC_HEADER_SIZE)) return AVERROR(ENOMEM); - st->codec->extradata_size = FLIC_HEADER_SIZE; memcpy(st->codec->extradata, header, FLIC_HEADER_SIZE); /* peek at the preamble to detect TFTD videos - they seem to always start with an audio chunk */ @@ -178,10 +176,8 @@ static int flic_read_header(AVFormatContext *s) /* send over abbreviated FLIC header chunk */ av_free(st->codec->extradata); - st->codec->extradata = av_malloc(12); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, 12)) return AVERROR(ENOMEM); - st->codec->extradata_size = 12; memcpy(st->codec->extradata, header, 12); } else if (magic_number == FLIC_FILE_MAGIC_1) { diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index d81a70b93b..d259927a84 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -246,9 +246,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, vcodec->codec_id = AV_CODEC_ID_VP6A; if (read) { if (vcodec->extradata_size != 1) { - vcodec->extradata = av_malloc(1 + FF_INPUT_BUFFER_PADDING_SIZE); - if (vcodec->extradata) - vcodec->extradata_size = 1; + ff_alloc_extradata(vcodec, 1); } if (vcodec->extradata) vcodec->extradata[0] = avio_r8(s->pb); @@ -616,10 +614,8 @@ static int flv_read_close(AVFormatContext *s) static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) { av_free(st->codec->extradata); - st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, size)) return AVERROR(ENOMEM); - st->codec->extradata_size = size; avio_read(s->pb, st->codec->extradata, st->codec->extradata_size); return 0; } diff --git a/libavformat/idcin.c b/libavformat/idcin.c index 85d538c4f3..9671fca6f8 100644 --- a/libavformat/idcin.c +++ b/libavformat/idcin.c @@ -196,10 +196,8 @@ static int idcin_read_header(AVFormatContext *s) st->codec->height = height; /* load up the Huffman tables into extradata */ - st->codec->extradata = av_malloc(HUFFMAN_TABLE_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, HUFFMAN_TABLE_SIZE)) return AVERROR(ENOMEM); - st->codec->extradata_size = HUFFMAN_TABLE_SIZE; ret = avio_read(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE); if (ret < 0) { return ret; diff --git a/libavformat/isom.c b/libavformat/isom.c index ec372288ca..8cbf70b56e 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -452,11 +452,9 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext if (!len || (uint64_t)len > (1<<30)) return -1; av_free(st->codec->extradata); - st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, len)) return AVERROR(ENOMEM); avio_read(pb, st->codec->extradata, len); - st->codec->extradata_size = len; if (st->codec->codec_id == AV_CODEC_ID_AAC) { MPEG4AudioConfig cfg; avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, diff --git a/libavformat/libnut.c b/libavformat/libnut.c index 71479982c3..be8f3cb283 100644 --- a/libavformat/libnut.c +++ b/libavformat/libnut.c @@ -232,8 +232,7 @@ static int nut_read_header(AVFormatContext * avf) { st->codec->extradata_size = s[i].codec_specific_len; if (st->codec->extradata_size) { - st->codec->extradata = av_mallocz(st->codec->extradata_size); - if(!st->codec->extradata){ + if(ff_alloc_extradata(st->codec, st->codec->extradata_size)){ nut_demuxer_uninit(nut); priv->nut = NULL; return AVERROR(ENOMEM); diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 1879328ece..de798e5b79 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1819,11 +1819,8 @@ static int matroska_read_header(AVFormatContext *s) st->codec->extradata = extradata; st->codec->extradata_size = extradata_size; } else if(track->codec_priv.data && track->codec_priv.size > 0){ - st->codec->extradata = av_mallocz(track->codec_priv.size + - FF_INPUT_BUFFER_PADDING_SIZE); - if(st->codec->extradata == NULL) + if (ff_alloc_extradata(st->codec, track->codec_priv.size)) return AVERROR(ENOMEM); - st->codec->extradata_size = track->codec_priv.size; memcpy(st->codec->extradata, track->codec_priv.data + extradata_offset, track->codec_priv.size); @@ -1916,10 +1913,8 @@ static int matroska_read_header(AVFormatContext *s) av_dict_set(&st->metadata, "mimetype", attachements[j].mime, 0); st->codec->codec_id = AV_CODEC_ID_NONE; st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; - st->codec->extradata = av_malloc(attachements[j].bin.size + FF_INPUT_BUFFER_PADDING_SIZE); - if(st->codec->extradata == NULL) + if (ff_alloc_extradata(st->codec, attachements[j].bin.size)) break; - st->codec->extradata_size = attachements[j].bin.size; memcpy(st->codec->extradata, attachements[j].bin.data, attachements[j].bin.size); for (i=0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) { diff --git a/libavformat/mov.c b/libavformat/mov.c index f222cf8452..f8535f0413 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1077,11 +1077,8 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->codec->codec_id == AV_CODEC_ID_SPEEX) { // pass all frma atom to codec, needed at least for QDMC and QDM2 av_free(st->codec->extradata); - st->codec->extradata_size = 0; - st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, atom.size)) return AVERROR(ENOMEM); - st->codec->extradata_size = atom.size; avio_read(pb, st->codec->extradata, atom.size); } else if (atom.size > 8) { /* to read frma, esds atoms */ int ret; @@ -1117,11 +1114,8 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom) return mov_read_default(c, pb, atom); } av_free(st->codec->extradata); - st->codec->extradata_size = 0; - st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, atom.size)) return AVERROR(ENOMEM); - st->codec->extradata_size = atom.size; avio_read(pb, st->codec->extradata, atom.size); return 0; } @@ -1143,11 +1137,8 @@ static int mov_read_dvc1(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; av_free(st->codec->extradata); - st->codec->extradata_size = 0; - st->codec->extradata = av_mallocz(atom.size - 7 + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, atom.size - 7)) return AVERROR(ENOMEM); - st->codec->extradata_size = atom.size - 7; avio_seek(pb, 6, SEEK_CUR); avio_read(pb, st->codec->extradata, st->codec->extradata_size); return 0; @@ -1172,11 +1163,8 @@ static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom) return AVERROR_INVALIDDATA; av_free(st->codec->extradata); - st->codec->extradata_size = 0; - st->codec->extradata = av_mallocz(atom.size - 40 + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, atom.size - 40)) return AVERROR(ENOMEM); - st->codec->extradata_size = atom.size - 40; avio_skip(pb, 40); avio_read(pb, st->codec->extradata, atom.size - 40); return 0; @@ -1491,9 +1479,7 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb, int size) { if (st->codec->codec_tag == MKTAG('t','m','c','d')) { - st->codec->extradata_size = size; - st->codec->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, size)) return AVERROR(ENOMEM); avio_read(pb, st->codec->extradata, size); if (size > 16) { diff --git a/libavformat/mpc.c b/libavformat/mpc.c index b0f6f533e1..8abc488553 100644 --- a/libavformat/mpc.c +++ b/libavformat/mpc.c @@ -95,8 +95,8 @@ static int mpc_read_header(AVFormatContext *s) st->codec->channel_layout = AV_CH_LAYOUT_STEREO; st->codec->bits_per_coded_sample = 16; - st->codec->extradata_size = 16; - st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); + if (ff_alloc_extradata(st->codec, 16)) + return AVERROR(ENOMEM); avio_read(s->pb, st->codec->extradata, 16); st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3]; avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate); diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c index 5ee4e00a5d..7017c187f7 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -241,8 +241,8 @@ static int mpc8_read_header(AVFormatContext *s) st->codec->codec_id = AV_CODEC_ID_MUSEPACK8; st->codec->bits_per_coded_sample = 16; - st->codec->extradata_size = 2; - st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + if (ff_alloc_extradata(st->codec, 2)) + return AVERROR(ENOMEM); avio_read(pb, st->codec->extradata, st->codec->extradata_size); st->codec->channels = (st->codec->extradata[1] >> 4) + 1; diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 67e94fb39e..cd881d8130 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1454,9 +1454,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type if (st->codec->extradata_size == 4 && memcmp(st->codec->extradata, *pp, 4)) avpriv_request_sample(fc, "DVB sub with multiple IDs"); } else { - st->codec->extradata = av_malloc(4 + FF_INPUT_BUFFER_PADDING_SIZE); - if (st->codec->extradata) { - st->codec->extradata_size = 4; + if (!ff_alloc_extradata(st->codec, 4)) { memcpy(st->codec->extradata, *pp, 4); } } diff --git a/libavformat/mvi.c b/libavformat/mvi.c index bd1f3c66f9..5efc443152 100644 --- a/libavformat/mvi.c +++ b/libavformat/mvi.c @@ -52,9 +52,7 @@ static int read_header(AVFormatContext *s) if (!vst) return AVERROR(ENOMEM); - vst->codec->extradata_size = 2; - vst->codec->extradata = av_mallocz(2 + FF_INPUT_BUFFER_PADDING_SIZE); - if (!vst->codec->extradata) + if (ff_alloc_extradata(vst->codec, 2)) return AVERROR(ENOMEM); version = avio_r8(pb); diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index dac98acaf3..72faf4cce2 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1599,10 +1599,8 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } } if (descriptor->extradata) { - st->codec->extradata = av_mallocz(descriptor->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (st->codec->extradata) { + if (!ff_alloc_extradata(st->codec, descriptor->extradata_size)) { memcpy(st->codec->extradata, descriptor->extradata, descriptor->extradata_size); - st->codec->extradata_size = descriptor->extradata_size; } } else if(st->codec->codec_id == AV_CODEC_ID_H264) { ff_generate_avci_extradata(st); diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index e6b10c7e1f..f380279343 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -415,9 +415,7 @@ static int decode_stream_header(NUTContext *nut) GET_V(st->codec->extradata_size, tmp < (1 << 30)); if (st->codec->extradata_size) { - st->codec->extradata = av_mallocz(st->codec->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, st->codec->extradata_size)) return AVERROR(ENOMEM); avio_read(bc, st->codec->extradata, st->codec->extradata_size); } diff --git a/libavformat/nuv.c b/libavformat/nuv.c index fc9e916013..32d0e02f68 100644 --- a/libavformat/nuv.c +++ b/libavformat/nuv.c @@ -86,10 +86,8 @@ static int get_codec_data(AVIOContext *pb, AVStream *vst, av_freep(&vst->codec->extradata); vst->codec->extradata_size = 0; } - vst->codec->extradata = av_malloc(size); - if (!vst->codec->extradata) + if (ff_alloc_extradata(vst->codec, size)) return AVERROR(ENOMEM); - vst->codec->extradata_size = size; avio_read(pb, vst->codec->extradata, size); size = 0; if (!myth) diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c index 08fd77e9ed..894b43850c 100644 --- a/libavformat/oggparseflac.c +++ b/libavformat/oggparseflac.c @@ -62,10 +62,8 @@ flac_header (AVFormatContext * s, int idx) st->codec->codec_id = AV_CODEC_ID_FLAC; st->need_parsing = AVSTREAM_PARSE_HEADERS; - st->codec->extradata = - av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(st->codec->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE); - st->codec->extradata_size = FLAC_STREAMINFO_SIZE; + ff_alloc_extradata(st->codec, FLAC_STREAMINFO_SIZE); + memcpy(st->codec->extradata, streaminfo_start, st->codec->extradata_size); avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) { diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c index a9091e43a1..b8c502a5ff 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -99,9 +99,8 @@ ogm_header(AVFormatContext *s, int idx) if (size > 52) { av_assert0(FF_INPUT_BUFFER_PADDING_SIZE <= 52); size -= 52; - st->codec->extradata_size = size; - st->codec->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); - bytestream2_get_buffer(&p, st->codec->extradata, size); + ff_alloc_extradata(st->codec, size); + bytestream2_get_buffer(&p, st->codec->extradata, st->codec->extradata_size); } } } else if (bytestream2_peek_byte(&p) == 3) { diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c index 63e6370482..7cbc7e0673 100644 --- a/libavformat/oggparsespeex.c +++ b/libavformat/oggparsespeex.c @@ -77,9 +77,7 @@ static int speex_header(AVFormatContext *s, int idx) { if (frames_per_packet) spxp->packet_size *= frames_per_packet; - st->codec->extradata_size = os->psize; - st->codec->extradata = av_malloc(st->codec->extradata_size - + FF_INPUT_BUFFER_PADDING_SIZE); + ff_alloc_extradata(st->codec, os->psize); memcpy(st->codec->extradata, p, st->codec->extradata_size); avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); diff --git a/libavformat/omadec.c b/libavformat/omadec.c index e4291d9b55..4017db3f2b 100644 --- a/libavformat/omadec.c +++ b/libavformat/omadec.c @@ -349,12 +349,10 @@ static int oma_read_header(AVFormatContext *s) /* fake the ATRAC3 extradata * (wav format, makes stream copy to wav work) */ - st->codec->extradata_size = 14; - edata = av_mallocz(14 + FF_INPUT_BUFFER_PADDING_SIZE); - if (!edata) + if (ff_alloc_extradata(st->codec, 14)) return AVERROR(ENOMEM); - st->codec->extradata = edata; + edata = st->codec->extradata; AV_WL16(&edata[0], 1); // always 1 AV_WL32(&edata[2], samplerate); // samples rate AV_WL16(&edata[6], jsflag); // coding mode diff --git a/libavformat/redspark.c b/libavformat/redspark.c index 3963261b9a..6d4c8c5c1a 100644 --- a/libavformat/redspark.c +++ b/libavformat/redspark.c @@ -113,9 +113,7 @@ static int redspark_read_header(AVFormatContext *s) goto fail; } - codec->extradata_size = 32 * codec->channels; - codec->extradata = av_malloc(codec->extradata_size); - if (!codec->extradata) { + if (ff_alloc_extradata(codec, 32 * codec->channels)) { ret = AVERROR(ENOMEM); goto fail; } diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c index e7c52e09c3..de8eb5f588 100644 --- a/libavformat/riffdec.c +++ b/libavformat/riffdec.c @@ -115,12 +115,9 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size) cbSize -= 22; size -= 22; } - codec->extradata_size = cbSize; if (cbSize > 0) { av_free(codec->extradata); - codec->extradata = av_mallocz(codec->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - if (!codec->extradata) + if (ff_alloc_extradata(codec, cbSize)) return AVERROR(ENOMEM); avio_read(pb, codec->extradata, codec->extradata_size); size -= cbSize; diff --git a/libavformat/rl2.c b/libavformat/rl2.c index fb7409eaa6..ff4006497f 100644 --- a/libavformat/rl2.c +++ b/libavformat/rl2.c @@ -125,9 +125,7 @@ static av_cold int rl2_read_header(AVFormatContext *s) if(signature == RLV3_TAG && back_size > 0) st->codec->extradata_size += back_size; - st->codec->extradata = av_mallocz(st->codec->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - if(!st->codec->extradata) + if(ff_alloc_extradata(st->codec, st->codec->extradata_size)) return AVERROR(ENOMEM); if(avio_read(pb,st->codec->extradata,st->codec->extradata_size) != diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 278fc37b45..a79fbaf4db 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -86,11 +86,9 @@ static int rm_read_extradata(AVIOContext *pb, AVCodecContext *avctx, unsigned si { if (size >= 1<<24) return -1; - avctx->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!avctx->extradata) + if (ff_alloc_extradata(avctx, size)) return AVERROR(ENOMEM); avctx->extradata_size = avio_read(pb, avctx->extradata, size); - memset(avctx->extradata + avctx->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); if (avctx->extradata_size != size) return AVERROR(EIO); return 0; diff --git a/libavformat/rsd.c b/libavformat/rsd.c index 5b53cef9c0..37e544acb1 100644 --- a/libavformat/rsd.c +++ b/libavformat/rsd.c @@ -101,9 +101,7 @@ static int rsd_read_header(AVFormatContext *s) /* RSD3GADP is mono, so only alloc enough memory to store the coeff table for a single channel. */ - codec->extradata_size = 32; - codec->extradata = av_malloc(codec->extradata_size); - if (!codec->extradata) + if (ff_alloc_extradata(codec, 32)) return AVERROR(ENOMEM); start = avio_rl32(pb); diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c index a2ad07104a..fdeff3a151 100644 --- a/libavformat/rtpdec_latm.c +++ b/libavformat/rtpdec_latm.c @@ -130,10 +130,7 @@ static int parse_fmtp_config(AVStream *st, char *value) goto end; } av_freep(&st->codec->extradata); - st->codec->extradata_size = (get_bits_left(&gb) + 7)/8; - st->codec->extradata = av_mallocz(st->codec->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) { + if (ff_alloc_extradata(st->codec, (get_bits_left(&gb) + 7)/8)) { ret = AVERROR(ENOMEM); goto end; } diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index 571b7392e0..0ea5594c06 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -105,10 +105,8 @@ static int parse_fmtp_config(AVCodecContext *codec, char *value) /* decode the hexa encoded parameter */ int len = ff_hex_to_data(NULL, value); av_free(codec->extradata); - codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); - if (!codec->extradata) + if (ff_alloc_extradata(codec, len)) return AVERROR(ENOMEM); - codec->extradata_size = len; ff_hex_to_data(codec->extradata, value); return 0; } diff --git a/libavformat/rtpdec_qdm2.c b/libavformat/rtpdec_qdm2.c index 6ce776db44..e1dd62fb8e 100644 --- a/libavformat/rtpdec_qdm2.c +++ b/libavformat/rtpdec_qdm2.c @@ -29,6 +29,7 @@ #include "libavutil/avassert.h" #include "libavutil/intreadwrite.h" #include "libavcodec/avcodec.h" +#include "internal.h" #include "rtp.h" #include "rtpdec.h" #include "rtpdec_formats.h" @@ -104,9 +105,7 @@ static int qdm2_parse_config(PayloadContext *qdm, AVStream *st, if (item_len < 30) return AVERROR_INVALIDDATA; av_freep(&st->codec->extradata); - st->codec->extradata_size = 26 + item_len; - if (!(st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE))) { - st->codec->extradata_size = 0; + if (ff_alloc_extradata(st->codec, 26 + item_len)) { return AVERROR(ENOMEM); } AV_WB32(st->codec->extradata, 12); diff --git a/libavformat/rtpdec_svq3.c b/libavformat/rtpdec_svq3.c index 106b7857cb..98e8b58673 100644 --- a/libavformat/rtpdec_svq3.c +++ b/libavformat/rtpdec_svq3.c @@ -28,6 +28,7 @@ #include #include "libavutil/intreadwrite.h" +#include "internal.h" #include "rtp.h" #include "rtpdec.h" #include "rtpdec_formats.h" @@ -60,11 +61,9 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv, av_freep(&st->codec->extradata); st->codec->extradata_size = 0; - if (len < 2 || !(st->codec->extradata = - av_malloc(len + 8 + FF_INPUT_BUFFER_PADDING_SIZE))) + if (len < 2 || ff_alloc_extradata(st->codec, len + 8)) return AVERROR_INVALIDDATA; - st->codec->extradata_size = len + 8; memcpy(st->codec->extradata, "SEQH", 4); AV_WB32(st->codec->extradata + 4, len); memcpy(st->codec->extradata + 8, buf, len); diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c index 52a94b3159..887a65ed65 100644 --- a/libavformat/rtpdec_xiph.c +++ b/libavformat/rtpdec_xiph.c @@ -33,6 +33,7 @@ #include "libavutil/base64.h" #include "libavcodec/bytestream.h" +#include "internal.h" #include "rtpdec.h" #include "rtpdec_formats.h" @@ -288,11 +289,11 @@ parse_packed_headers(const uint8_t * packed_headers, * -- FF_INPUT_BUFFER_PADDING_SIZE required */ extradata_alloc = length + length/255 + 3 + FF_INPUT_BUFFER_PADDING_SIZE; - ptr = codec->extradata = av_malloc(extradata_alloc); - if (!ptr) { + if (ff_alloc_extradata(codec, extradata_alloc)) { av_log(codec, AV_LOG_ERROR, "Out of memory\n"); return AVERROR(ENOMEM); } + ptr = codec->extradata; *ptr++ = 2; ptr += av_xiphlacing(ptr, length1); ptr += av_xiphlacing(ptr, length2); diff --git a/libavformat/sbgdec.c b/libavformat/sbgdec.c index 30c3b49cd7..36cd8a3ce2 100644 --- a/libavformat/sbgdec.c +++ b/libavformat/sbgdec.c @@ -1333,11 +1333,9 @@ static int encode_intervals(struct sbg_script *s, AVCodecContext *avc, if (edata_size < 0) return AVERROR(ENOMEM); } - edata = av_malloc(edata_size); - if (!edata) + if (ff_alloc_extradata(avc, edata_size)) return AVERROR(ENOMEM); - avc->extradata = edata; - avc->extradata_size = edata_size; + edata = avc->extradata; #define ADD_EDATA32(v) do { AV_WL32(edata, (v)); edata += 4; } while(0) #define ADD_EDATA64(v) do { AV_WL64(edata, (v)); edata += 8; } while(0) diff --git a/libavformat/sierravmd.c b/libavformat/sierravmd.c index fad3dd3d8a..8749ec1640 100644 --- a/libavformat/sierravmd.c +++ b/libavformat/sierravmd.c @@ -127,10 +127,8 @@ static int vmd_read_header(AVFormatContext *s) vst->codec->width >>= 1; vst->codec->height >>= 1; } - vst->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); - if (!vst->codec->extradata) + if (ff_alloc_extradata(vst->codec, VMD_HEADER_SIZE)) return AVERROR(ENOMEM); - vst->codec->extradata_size = VMD_HEADER_SIZE; memcpy(vst->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE); } diff --git a/libavformat/smacker.c b/libavformat/smacker.c index c5bc5e0e29..527faf7dd8 100644 --- a/libavformat/smacker.c +++ b/libavformat/smacker.c @@ -217,10 +217,7 @@ static int smacker_read_header(AVFormatContext *s) /* load trees to extradata, they will be unpacked by decoder */ - st->codec->extradata = av_mallocz(smk->treesize + 16 + - FF_INPUT_BUFFER_PADDING_SIZE); - st->codec->extradata_size = smk->treesize + 16; - if(!st->codec->extradata){ + if(ff_alloc_extradata(st->codec, smk->treesize + 16)){ av_log(s, AV_LOG_ERROR, "Cannot allocate %i bytes of extradata\n", smk->treesize + 16); av_freep(&smk->frm_size); av_freep(&smk->frm_flags); diff --git a/libavformat/smush.c b/libavformat/smush.c index 9c8997cc00..e9c1937398 100644 --- a/libavformat/smush.c +++ b/libavformat/smush.c @@ -145,11 +145,9 @@ static int smush_read_header(AVFormatContext *ctx) avpriv_set_pts_info(vst, 64, 66667, 1000000); if (!smush->version) { - vst->codec->extradata = av_malloc(1024 + 2 + FF_INPUT_BUFFER_PADDING_SIZE); - if (!vst->codec->extradata) + if (ff_alloc_extradata(vst->codec, 1024 + 2)) return AVERROR(ENOMEM); - vst->codec->extradata_size = 1024 + 2; AV_WL16(vst->codec->extradata, subversion); for (i = 0; i < 256; i++) AV_WL32(vst->codec->extradata + 2 + i * 4, palette[i]); diff --git a/libavformat/tta.c b/libavformat/tta.c index bbb6a2292c..7174fd5438 100644 --- a/libavformat/tta.c +++ b/libavformat/tta.c @@ -109,12 +109,8 @@ static int tta_read_header(AVFormatContext *s) framepos = avio_tell(s->pb) + 4*c->totalframes + 4; - st->codec->extradata_size = avio_tell(s->pb) - start_offset; - st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) { - st->codec->extradata_size = 0; + if (ff_alloc_extradata(st->codec, avio_tell(s->pb) - start_offset)) return AVERROR(ENOMEM); - } avio_seek(s->pb, start_offset, SEEK_SET); avio_read(s->pb, st->codec->extradata, st->codec->extradata_size); diff --git a/libavformat/utils.c b/libavformat/utils.c index 6a7f58027c..50f7d8732e 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2950,12 +2950,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) if(st->parser && st->parser->parser->split && !st->codec->extradata){ int i= st->parser->parser->split(st->codec, pkt->data, pkt->size); if (i > 0 && i < FF_MAX_EXTRADATA_SIZE) { - st->codec->extradata_size= i; - st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, i)) return AVERROR(ENOMEM); memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size); - memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE); } } @@ -4271,10 +4268,7 @@ void ff_generate_avci_extradata(AVStream *st) if (!size) return; av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; - st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, size)) return; memcpy(st->codec->extradata, data, size); - st->codec->extradata_size = size; } diff --git a/libavformat/vc1test.c b/libavformat/vc1test.c index 7c6bcde089..bf1bfe0318 100644 --- a/libavformat/vc1test.c +++ b/libavformat/vc1test.c @@ -61,8 +61,8 @@ static int vc1t_read_header(AVFormatContext *s) st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = AV_CODEC_ID_WMV3; - st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE); - st->codec->extradata_size = VC1_EXTRADATA_SIZE; + if (ff_alloc_extradata(st->codec, VC1_EXTRADATA_SIZE)) + return AVERROR(ENOMEM); avio_read(pb, st->codec->extradata, VC1_EXTRADATA_SIZE); st->codec->height = avio_rl32(pb); st->codec->width = avio_rl32(pb); diff --git a/libavformat/vqf.c b/libavformat/vqf.c index be7d8a0a80..4cd0a6deec 100644 --- a/libavformat/vqf.c +++ b/libavformat/vqf.c @@ -220,9 +220,8 @@ static int vqf_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 64, size, st->codec->sample_rate); /* put first 12 bytes of COMM chunk in extradata */ - if (!(st->codec->extradata = av_malloc(12 + FF_INPUT_BUFFER_PADDING_SIZE))) + if (ff_alloc_extradata(st->codec, 12)) return AVERROR(ENOMEM); - st->codec->extradata_size = 12; memcpy(st->codec->extradata, comm_chunk, 12); ff_metadata_conv_ctx(s, NULL, vqf_metadata_conv); diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index ef28349fec..8ae7b4557b 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -353,10 +353,7 @@ static int wav_read_header(AVFormatContext *s) vst->codec->codec_id = AV_CODEC_ID_SMVJPEG; vst->codec->width = avio_rl24(pb); vst->codec->height = avio_rl24(pb); - vst->codec->extradata_size = 4; - vst->codec->extradata = av_malloc(vst->codec->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - if (!vst->codec->extradata) { + if (ff_alloc_extradata(vst->codec, 4)) { av_log(s, AV_LOG_ERROR, "Could not allocate extradata.\n"); return AVERROR(ENOMEM); } diff --git a/libavformat/westwood_vqa.c b/libavformat/westwood_vqa.c index d8791da131..2e72928a4c 100644 --- a/libavformat/westwood_vqa.c +++ b/libavformat/westwood_vqa.c @@ -101,10 +101,8 @@ static int wsvqa_read_header(AVFormatContext *s) avio_seek(pb, 20, SEEK_SET); /* the VQA header needs to go to the decoder */ - st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, VQA_HEADER_SIZE)) return AVERROR(ENOMEM); - st->codec->extradata_size = VQA_HEADER_SIZE; header = (unsigned char *)st->codec->extradata; if (avio_read(pb, st->codec->extradata, VQA_HEADER_SIZE) != VQA_HEADER_SIZE) { @@ -221,9 +219,7 @@ static int wsvqa_read_packet(AVFormatContext *s, break; case SND2_TAG: st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_WS; - st->codec->extradata_size = 2; - st->codec->extradata = av_mallocz(2 + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (ff_alloc_extradata(st->codec, 2)) return AVERROR(ENOMEM); AV_WL16(st->codec->extradata, wsvqa->version); break; diff --git a/libavformat/xmv.c b/libavformat/xmv.c index b42b0b1968..20f9bea55b 100644 --- a/libavformat/xmv.c +++ b/libavformat/xmv.c @@ -383,9 +383,7 @@ static int xmv_process_packet_header(AVFormatContext *s) if (vst->codec->extradata_size < 4) { av_free(vst->codec->extradata); - vst->codec->extradata = - av_malloc(4 + FF_INPUT_BUFFER_PADDING_SIZE); - vst->codec->extradata_size = 4; + ff_alloc_extradata(vst->codec, 4); } memcpy(vst->codec->extradata, xmv->video.extradata, 4); diff --git a/libavformat/yop.c b/libavformat/yop.c index e962b093e8..07086d53b8 100644 --- a/libavformat/yop.c +++ b/libavformat/yop.c @@ -69,12 +69,7 @@ static int yop_read_header(AVFormatContext *s) return AVERROR(ENOMEM); // Extra data that will be passed to the decoder - video_stream->codec->extradata_size = 8; - - video_stream->codec->extradata = av_mallocz(video_stream->codec->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - - if (!video_stream->codec->extradata) + if (ff_alloc_extradata(video_stream->codec, 8)) return AVERROR(ENOMEM); // Audio -- cgit v1.2.3