Skip to content

Commit

Permalink
avformat: use ff_alloc_extradata()
Browse files Browse the repository at this point in the history
Signed-off-by: Paul B Mahol <[email protected]>
  • Loading branch information
richardpl committed Oct 13, 2013
1 parent 3fd7983 commit a807c68
Show file tree
Hide file tree
Showing 52 changed files with 83 additions and 218 deletions.
3 changes: 1 addition & 2 deletions libavformat/adxdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions libavformat/afc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions libavformat/aiffdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions libavformat/apc.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "libavutil/channel_layout.h"
#include "avformat.h"
#include "internal.h"

static int apc_probe(AVProbeData *p)
{
Expand Down Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions libavformat/ape.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions libavformat/apetag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 2 additions & 10 deletions libavformat/avidec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 2 additions & 6 deletions libavformat/bink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
15 changes: 4 additions & 11 deletions libavformat/bintext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions libavformat/cafdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions libavformat/dfa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
8 changes: 2 additions & 6 deletions libavformat/ffmdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 2 additions & 6 deletions libavformat/flic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 2 additions & 6 deletions libavformat/flvdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions libavformat/idcin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions libavformat/isom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions libavformat/libnut.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions libavformat/matroskadec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand Down
Loading

0 comments on commit a807c68

Please sign in to comment.