summaryrefslogtreecommitdiff
path: root/libavformat/avidec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavformat/avidec.c')
-rw-r--r--libavformat/avidec.c179
1 files changed, 89 insertions, 90 deletions
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 8ce07ab310..87c9bd4951 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -385,11 +385,11 @@ static void avi_read_nikon(AVFormatContext *s, uint64_t end)
}
}
-static int avi_extract_stream_metadata(AVStream *st)
+static int avi_extract_stream_metadata(AVFormatContext *s, AVStream *st)
{
GetByteContext gb;
- uint8_t *data = st->codec->extradata;
- int data_size = st->codec->extradata_size;
+ uint8_t *data = st->codecpar->extradata;
+ int data_size = st->codecpar->extradata_size;
int tag, offset;
if (!data || data_size < 8) {
@@ -408,13 +408,13 @@ static int avi_extract_stream_metadata(AVStream *st)
bytestream2_init(&gb, data + offset, data_size - offset);
// decode EXIF tags from IFD, AVI is always little-endian
- return avpriv_exif_decode_ifd(st->codec, &gb, 1, 0, &st->metadata);
+ return avpriv_exif_decode_ifd(s, &gb, 1, 0, &st->metadata);
break;
case MKTAG('C', 'A', 'S', 'I'):
- avpriv_request_sample(st->codec, "RIFF stream data tag type CASI (%u)", tag);
+ avpriv_request_sample(s, "RIFF stream data tag type CASI (%u)", tag);
break;
case MKTAG('Z', 'o', 'r', 'a'):
- avpriv_request_sample(st->codec, "RIFF stream data tag type Zora (%u)", tag);
+ avpriv_request_sample(s, "RIFF stream data tag type Zora (%u)", tag);
break;
default:
break;
@@ -456,12 +456,12 @@ static int calculate_bitrate(AVFormatContext *s)
for (j = 0; j < st->nb_index_entries; j++)
len += st->index_entries[j].size;
- if (st->nb_index_entries < 2 || st->codec->bit_rate > 0)
+ if (st->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
continue;
duration = st->index_entries[j-1].timestamp - st->index_entries[0].timestamp;
bitrate = av_rescale(8*len, st->time_base.den, duration * st->time_base.num);
if (bitrate <= INT_MAX && bitrate > 0) {
- st->codec->bit_rate = bitrate;
+ st->codecpar->bit_rate = bitrate;
}
}
return 1;
@@ -603,8 +603,8 @@ static int avi_read_header(AVFormatContext *s)
goto fail;
ast = s->streams[0]->priv_data;
- av_freep(&s->streams[0]->codec->extradata);
- av_freep(&s->streams[0]->codec);
+ av_freep(&s->streams[0]->codecpar->extradata);
+ av_freep(&s->streams[0]->codecpar);
if (s->streams[0]->info)
av_freep(&s->streams[0]->info->duration_error);
av_freep(&s->streams[0]->info);
@@ -733,17 +733,17 @@ static int avi_read_header(AVFormatContext *s)
if (cur_pos < list_end)
size = FFMIN(size, list_end - cur_pos);
st = s->streams[stream_index];
- if (st->codec->codec_type != AVMEDIA_TYPE_UNKNOWN) {
+ if (st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) {
avio_skip(pb, size);
break;
}
switch (codec_type) {
case AVMEDIA_TYPE_VIDEO:
if (amv_file_format) {
- st->codec->width = avih_width;
- st->codec->height = avih_height;
- st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- st->codec->codec_id = AV_CODEC_ID_AMV;
+ st->codecpar->width = avih_width;
+ st->codecpar->height = avih_height;
+ st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+ st->codecpar->codec_id = AV_CODEC_ID_AMV;
avio_skip(pb, size);
break;
}
@@ -751,40 +751,40 @@ static int avi_read_header(AVFormatContext *s)
if (tag1 == MKTAG('D', 'X', 'S', 'B') ||
tag1 == MKTAG('D', 'X', 'S', 'A')) {
- st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
- st->codec->codec_tag = tag1;
- st->codec->codec_id = AV_CODEC_ID_XSUB;
+ st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ st->codecpar->codec_tag = tag1;
+ st->codecpar->codec_id = AV_CODEC_ID_XSUB;
break;
}
if (size > 10 * 4 && size < (1 << 30) && size < avi->fsize) {
if (esize == size-1 && (esize&1)) {
- st->codec->extradata_size = esize - 10 * 4;
+ st->codecpar->extradata_size = esize - 10 * 4;
} else
- st->codec->extradata_size = size - 10 * 4;
- if (ff_get_extradata(st->codec, pb, st->codec->extradata_size) < 0)
+ st->codecpar->extradata_size = size - 10 * 4;
+ if (ff_get_extradata(st->codecpar, pb, st->codecpar->extradata_size) < 0)
return AVERROR(ENOMEM);
}
// FIXME: check if the encoder really did this correctly
- if (st->codec->extradata_size & 1)
+ if (st->codecpar->extradata_size & 1)
avio_r8(pb);
/* Extract palette from extradata if bpp <= 8.
* This code assumes that extradata contains only palette.
* This is true for all paletted codecs implemented in
* FFmpeg. */
- if (st->codec->extradata_size &&
- (st->codec->bits_per_coded_sample <= 8)) {
- int pal_size = (1 << st->codec->bits_per_coded_sample) << 2;
+ if (st->codecpar->extradata_size &&
+ (st->codecpar->bits_per_coded_sample <= 8)) {
+ int pal_size = (1 << st->codecpar->bits_per_coded_sample) << 2;
const uint8_t *pal_src;
- pal_size = FFMIN(pal_size, st->codec->extradata_size);
- pal_src = st->codec->extradata +
- st->codec->extradata_size - pal_size;
+ pal_size = FFMIN(pal_size, st->codecpar->extradata_size);
+ pal_src = st->codecpar->extradata +
+ st->codecpar->extradata_size - pal_size;
/* Exclude the "BottomUp" field from the palette */
- if (pal_src - st->codec->extradata >= 9 &&
- !memcmp(st->codec->extradata + st->codec->extradata_size - 9, "BottomUp", 9))
+ if (pal_src - st->codecpar->extradata >= 9 &&
+ !memcmp(st->codecpar->extradata + st->codecpar->extradata_size - 9, "BottomUp", 9))
pal_src -= 9;
for (i = 0; i < pal_size / 4; i++)
ast->pal[i] = 0xFFU<<24 | AV_RL32(pal_src+4*i);
@@ -793,17 +793,17 @@ static int avi_read_header(AVFormatContext *s)
print_tag("video", tag1, 0);
- st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- st->codec->codec_tag = tag1;
- st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
+ st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+ st->codecpar->codec_tag = tag1;
+ st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
tag1);
/* If codec is not found yet, try with the mov tags. */
- if (!st->codec->codec_id) {
+ if (!st->codecpar->codec_id) {
char tag_buf[32];
av_get_codec_tag_string(tag_buf, sizeof(tag_buf), tag1);
- st->codec->codec_id =
+ st->codecpar->codec_id =
ff_codec_get_id(ff_codec_movvideo_tags, tag1);
- if (st->codec->codec_id)
+ if (st->codecpar->codec_id)
av_log(s, AV_LOG_WARNING,
"mov tag found in avi (fourcc %s)\n",
tag_buf);
@@ -812,44 +812,44 @@ static int avi_read_header(AVFormatContext *s)
* for generating correct pts. */
st->need_parsing = AVSTREAM_PARSE_HEADERS;
- if (st->codec->codec_id == AV_CODEC_ID_MPEG4 &&
+ if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 &&
ast->handler == MKTAG('X', 'V', 'I', 'D'))
- st->codec->codec_tag = MKTAG('X', 'V', 'I', 'D');
+ st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D');
- if (st->codec->codec_tag == MKTAG('V', 'S', 'S', 'H'))
+ if (st->codecpar->codec_tag == MKTAG('V', 'S', 'S', 'H'))
st->need_parsing = AVSTREAM_PARSE_FULL;
- if (st->codec->codec_id == AV_CODEC_ID_RV40)
+ if (st->codecpar->codec_id == AV_CODEC_ID_RV40)
st->need_parsing = AVSTREAM_PARSE_NONE;
- if (st->codec->codec_tag == 0 && st->codec->height > 0 &&
- st->codec->extradata_size < 1U << 30) {
- st->codec->extradata_size += 9;
- if ((ret = av_reallocp(&st->codec->extradata,
- st->codec->extradata_size +
+ if (st->codecpar->codec_tag == 0 && st->codecpar->height > 0 &&
+ st->codecpar->extradata_size < 1U << 30) {
+ st->codecpar->extradata_size += 9;
+ if ((ret = av_reallocp(&st->codecpar->extradata,
+ st->codecpar->extradata_size +
AV_INPUT_BUFFER_PADDING_SIZE)) < 0) {
- st->codec->extradata_size = 0;
+ st->codecpar->extradata_size = 0;
return ret;
} else
- memcpy(st->codec->extradata + st->codec->extradata_size - 9,
+ memcpy(st->codecpar->extradata + st->codecpar->extradata_size - 9,
"BottomUp", 9);
}
- st->codec->height = FFABS(st->codec->height);
+ st->codecpar->height = FFABS(st->codecpar->height);
// avio_skip(pb, size - 5 * 4);
break;
case AVMEDIA_TYPE_AUDIO:
- ret = ff_get_wav_header(s, pb, st->codec, size, 0);
+ ret = ff_get_wav_header(s, pb, st->codecpar, size, 0);
if (ret < 0)
return ret;
- ast->dshow_block_align = st->codec->block_align;
- if (ast->sample_size && st->codec->block_align &&
- ast->sample_size != st->codec->block_align) {
+ ast->dshow_block_align = st->codecpar->block_align;
+ if (ast->sample_size && st->codecpar->block_align &&
+ ast->sample_size != st->codecpar->block_align) {
av_log(s,
AV_LOG_WARNING,
"sample size (%d) != block align (%d)\n",
ast->sample_size,
- st->codec->block_align);
- ast->sample_size = st->codec->block_align;
+ st->codecpar->block_align);
+ ast->sample_size = st->codecpar->block_align;
}
/* 2-aligned
* (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
@@ -861,45 +861,45 @@ static int avi_read_header(AVFormatContext *s)
/* ADTS header is in extradata, AAC without header must be
* stored as exact frames. Parser not needed and it will
* fail. */
- if (st->codec->codec_id == AV_CODEC_ID_AAC &&
- st->codec->extradata_size)
+ if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
+ st->codecpar->extradata_size)
st->need_parsing = AVSTREAM_PARSE_NONE;
// The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS
- if (st->codec->codec_id == AV_CODEC_ID_FLAC)
+ if (st->codecpar->codec_id == AV_CODEC_ID_FLAC)
st->need_parsing = AVSTREAM_PARSE_NONE;
/* AVI files with Xan DPCM audio (wrongly) declare PCM
* audio in the header but have Axan as stream_code_tag. */
if (ast->handler == AV_RL32("Axan")) {
- st->codec->codec_id = AV_CODEC_ID_XAN_DPCM;
- st->codec->codec_tag = 0;
+ st->codecpar->codec_id = AV_CODEC_ID_XAN_DPCM;
+ st->codecpar->codec_tag = 0;
ast->dshow_block_align = 0;
}
if (amv_file_format) {
- st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_AMV;
+ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_AMV;
ast->dshow_block_align = 0;
}
- if ((st->codec->codec_id == AV_CODEC_ID_AAC ||
- st->codec->codec_id == AV_CODEC_ID_FLAC ||
- st->codec->codec_id == AV_CODEC_ID_MP2 ) && ast->dshow_block_align <= 4 && ast->dshow_block_align) {
+ if ((st->codecpar->codec_id == AV_CODEC_ID_AAC ||
+ st->codecpar->codec_id == AV_CODEC_ID_FLAC ||
+ st->codecpar->codec_id == AV_CODEC_ID_MP2 ) && ast->dshow_block_align <= 4 && ast->dshow_block_align) {
av_log(s, AV_LOG_DEBUG, "overriding invalid dshow_block_align of %d\n", ast->dshow_block_align);
ast->dshow_block_align = 0;
}
- if (st->codec->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 1024 && ast->sample_size == 1024 ||
- st->codec->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 4096 && ast->sample_size == 4096 ||
- st->codec->codec_id == AV_CODEC_ID_MP3 && ast->dshow_block_align == 1152 && ast->sample_size == 1152) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 1024 && ast->sample_size == 1024 ||
+ st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 4096 && ast->sample_size == 4096 ||
+ st->codecpar->codec_id == AV_CODEC_ID_MP3 && ast->dshow_block_align == 1152 && ast->sample_size == 1152) {
av_log(s, AV_LOG_DEBUG, "overriding sample_size\n");
ast->sample_size = 0;
}
break;
case AVMEDIA_TYPE_SUBTITLE:
- st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
st->request_probe= 1;
avio_skip(pb, size);
break;
default:
- st->codec->codec_type = AVMEDIA_TYPE_DATA;
- st->codec->codec_id = AV_CODEC_ID_NONE;
- st->codec->codec_tag = 0;
+ st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
+ st->codecpar->codec_id = AV_CODEC_ID_NONE;
+ st->codecpar->codec_tag = 0;
avio_skip(pb, size);
break;
}
@@ -907,8 +907,8 @@ static int avi_read_header(AVFormatContext *s)
break;
case MKTAG('s', 't', 'r', 'd'):
if (stream_index >= (unsigned)s->nb_streams
- || s->streams[stream_index]->codec->extradata_size
- || s->streams[stream_index]->codec->codec_tag == MKTAG('H','2','6','4')) {
+ || s->streams[stream_index]->codecpar->extradata_size
+ || s->streams[stream_index]->codecpar->codec_tag == MKTAG('H','2','6','4')) {
avio_skip(pb, size);
} else {
uint64_t cur_pos = avio_tell(pb);
@@ -917,14 +917,14 @@ static int avi_read_header(AVFormatContext *s)
st = s->streams[stream_index];
if (size<(1<<30)) {
- if (ff_get_extradata(st->codec, pb, size) < 0)
+ if (ff_get_extradata(st->codecpar, pb, size) < 0)
return AVERROR(ENOMEM);
}
- if (st->codec->extradata_size & 1) //FIXME check if the encoder really did this correctly
+ if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly
avio_r8(pb);
- ret = avi_extract_stream_metadata(st);
+ ret = avi_extract_stream_metadata(s, st);
if (ret < 0) {
av_log(s, AV_LOG_WARNING, "could not decoding EXIF data in stream header.\n");
}
@@ -1014,8 +1014,8 @@ fail:
if (dict_entry && !strcmp(dict_entry->value, "PotEncoder"))
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
- if ( st->codec->codec_id == AV_CODEC_ID_MPEG1VIDEO
- || st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO)
+ if ( st->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO
+ || st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO)
st->need_parsing = AVSTREAM_PARSE_FULL;
}
@@ -1094,8 +1094,7 @@ static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt)
if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) {
ff_read_packet(ast->sub_ctx, &ast->sub_pkt);
- *st->codec = *ast->sub_ctx->streams[0]->codec;
- ast->sub_ctx->streams[0]->codec->extradata = NULL;
+ avcodec_parameters_copy(st->codecpar, ast->sub_ctx->streams[0]->codecpar);
time_base = ast->sub_ctx->streams[0]->time_base;
avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
}
@@ -1232,8 +1231,8 @@ start_sync:
// workaround for broken small-file-bug402.avi
if ( d[2] == 'w' && d[3] == 'b'
&& n == 0
- && st ->codec->codec_type == AVMEDIA_TYPE_VIDEO
- && st1->codec->codec_type == AVMEDIA_TYPE_AUDIO
+ && st ->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
+ && st1->codecpar->codec_type == AVMEDIA_TYPE_AUDIO
&& ast->prefix == 'd'*256+'c'
&& (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count)
) {
@@ -1443,8 +1442,8 @@ resync:
pkt->flags |= AV_PKT_FLAG_KEY;
if (size < 0)
av_packet_unref(pkt);
- } else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE &&
- !st->codec->codec_tag && read_gab2_sub(s, st, pkt)) {
+ } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
+ !st->codecpar->codec_tag && read_gab2_sub(s, st, pkt)) {
ast->frame_offset++;
avi->stream_index = -1;
ast->remaining = 0;
@@ -1468,7 +1467,7 @@ resync:
size);
pkt->stream_index = avi->stream_index;
- if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) {
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) {
AVIndexEntry *e;
int index;
@@ -1479,7 +1478,7 @@ resync:
if (index == st->nb_index_entries-1) {
int key=1;
uint32_t state=-1;
- if (st->codec->codec_id == AV_CODEC_ID_MPEG4) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
const uint8_t *ptr = pkt->data, *end = ptr + FFMIN(size, 256);
while (ptr < end) {
ptr = avpriv_find_start_code(ptr, end, &state);
@@ -1557,7 +1556,7 @@ static int avi_read_idx1(AVFormatContext *s, int size)
avi->stream_index = -1;
avio_seek(pb, idx1_pos, SEEK_SET);
- if (s->nb_streams == 1 && s->streams[0]->codec->codec_tag == AV_RL32("MMES")) {
+ if (s->nb_streams == 1 && s->streams[0]->codecpar->codec_tag == AV_RL32("MMES")) {
first_packet_pos = 0;
data_offset = avi->movi_list;
}
@@ -1661,7 +1660,7 @@ static int check_stream_max_drift(AVFormatContext *s)
max_dts = FFMAX(max_dts, dts);
max_buffer = FFMAX(max_buffer,
av_rescale(dts - min_dts,
- st->codec->bit_rate,
+ st->codecpar->bit_rate,
AV_TIME_BASE));
}
}
@@ -1847,7 +1846,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
if (st2->nb_index_entries <= 0)
continue;
-// av_assert1(st2->codec->block_align);
+// av_assert1(st2->codecpar->block_align);
av_assert0(fabs(av_q2d(st2->time_base) - ast2->scale / (double)ast2->rate) < av_q2d(st2->time_base) * 0.00000001);
index = av_index_search_timestamp(st2,
av_rescale_q(timestamp,
@@ -1856,7 +1855,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
FFMAX(ast2->sample_size, 1),
flags |
AVSEEK_FLAG_BACKWARD |
- (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
+ (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
if (index < 0)
index = 0;
ast2->seek_pos = st2->index_entries[index].pos;
@@ -1872,7 +1871,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
index = av_index_search_timestamp(
st2,
av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
- flags | AVSEEK_FLAG_BACKWARD | (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
+ flags | AVSEEK_FLAG_BACKWARD | (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
if (index < 0)
index = 0;
while (!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min)