aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/cafdec.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2014-06-18 20:42:52 +0200
committerAnton Khirnov <anton@khirnov.net>2016-02-23 17:01:58 +0100
commit9200514ad8717c63f82101dc394f4378854325bf (patch)
tree566b8d48565a88303363198acc81de06363daa7a /libavformat/cafdec.c
parenta8068346e48e123f8d3bdf4d64464d81e53e5fc7 (diff)
downloadffmpeg-9200514ad8717c63f82101dc394f4378854325bf.tar.gz
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which is used by demuxers to export stream parameters to the caller and by muxers to receive stream parameters from the caller. It is also used internally as the codec context that is passed to parsers. In addition, it is also widely used by the callers as the decoding (when demuxer) or encoding (when muxing) context, though this has been officially discouraged since Libav 11. There are multiple important problems with this approach: - the fields in AVCodecContext are in general one of * stream parameters * codec options * codec state However, it's not clear which ones are which. It is consequently unclear which fields are a demuxer allowed to set or a muxer allowed to read. This leads to erratic behaviour depending on whether decoding or encoding is being performed or not (and whether it uses the AVStream embedded codec context). - various synchronization issues arising from the fact that the same context is used by several different APIs (muxers/demuxers, parsers, bitstream filters and encoders/decoders) simultaneously, with there being no clear rules for who can modify what and the different processes being typically delayed with respect to each other. - avformat_find_stream_info() making it necessary to support opening and closing a single codec context multiple times, thus complicating the semantics of freeing various allocated objects in the codec context. Those problems are resolved by replacing the AVStream embedded codec context with a newly added AVCodecParameters instance, which stores only the stream parameters exported by the demuxers or read by the muxers.
Diffstat (limited to 'libavformat/cafdec.c')
-rw-r--r--libavformat/cafdec.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 36c39678d1..65bdcfc1ef 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -69,29 +69,29 @@ static int read_desc_chunk(AVFormatContext *s)
return AVERROR(ENOMEM);
/* parse format description */
- st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
- st->codec->sample_rate = av_int2double(avio_rb64(pb));
- st->codec->codec_tag = avio_rb32(pb);
+ st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codecpar->sample_rate = av_int2double(avio_rb64(pb));
+ st->codecpar->codec_tag = avio_rb32(pb);
flags = avio_rb32(pb);
caf->bytes_per_packet = avio_rb32(pb);
- st->codec->block_align = caf->bytes_per_packet;
+ st->codecpar->block_align = caf->bytes_per_packet;
caf->frames_per_packet = avio_rb32(pb);
- st->codec->channels = avio_rb32(pb);
- st->codec->bits_per_coded_sample = avio_rb32(pb);
+ st->codecpar->channels = avio_rb32(pb);
+ st->codecpar->bits_per_coded_sample = avio_rb32(pb);
/* calculate bit rate for constant size packets */
if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) {
- st->codec->bit_rate = (uint64_t)st->codec->sample_rate * (uint64_t)caf->bytes_per_packet * 8
- / (uint64_t)caf->frames_per_packet;
+ st->codecpar->bit_rate = (uint64_t)st->codecpar->sample_rate * (uint64_t)caf->bytes_per_packet * 8
+ / (uint64_t)caf->frames_per_packet;
} else {
- st->codec->bit_rate = 0;
+ st->codecpar->bit_rate = 0;
}
/* determine codec */
- if (st->codec->codec_tag == MKBETAG('l','p','c','m'))
- st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, (flags ^ 0x2) | 0x4);
+ if (st->codecpar->codec_tag == MKBETAG('l','p','c','m'))
+ st->codecpar->codec_id = ff_mov_get_lpcm_codec_id(st->codecpar->bits_per_coded_sample, (flags ^ 0x2) | 0x4);
else
- st->codec->codec_id = ff_codec_get_id(ff_codec_caf_tags, st->codec->codec_tag);
+ st->codecpar->codec_id = ff_codec_get_id(ff_codec_caf_tags, st->codecpar->codec_tag);
return 0;
}
@@ -104,7 +104,7 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size)
if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
return -1;
- if (st->codec->codec_id == AV_CODEC_ID_AAC) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
/* The magic cookie format for AAC is an mp4 esds atom.
The lavc AAC decoder requires the data from the codec specific
description as extradata input. */
@@ -113,13 +113,13 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size)
strt = avio_tell(pb);
ff_mov_read_esds(s, pb);
skip = size - (avio_tell(pb) - strt);
- if (skip < 0 || !st->codec->extradata ||
- st->codec->codec_id != AV_CODEC_ID_AAC) {
+ if (skip < 0 || !st->codecpar->extradata ||
+ st->codecpar->codec_id != AV_CODEC_ID_AAC) {
av_log(s, AV_LOG_ERROR, "invalid AAC magic cookie\n");
return AVERROR_INVALIDDATA;
}
avio_skip(pb, skip);
- } else if (st->codec->codec_id == AV_CODEC_ID_ALAC) {
+ } else if (st->codecpar->codec_id == AV_CODEC_ID_ALAC) {
#define ALAC_PREAMBLE 12
#define ALAC_HEADER 36
#define ALAC_NEW_KUKI 24
@@ -131,8 +131,8 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size)
}
avio_read(pb, preamble, ALAC_PREAMBLE);
- st->codec->extradata = av_mallocz(ALAC_HEADER + AV_INPUT_BUFFER_PADDING_SIZE);
- if (!st->codec->extradata)
+ st->codecpar->extradata = av_mallocz(ALAC_HEADER + AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!st->codecpar->extradata)
return AVERROR(ENOMEM);
/* For the old style cookie, we skip 12 bytes, then read 36 bytes.
@@ -142,26 +142,26 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size)
if (!memcmp(&preamble[4], "frmaalac", 8)) {
if (size < ALAC_PREAMBLE + ALAC_HEADER) {
av_log(s, AV_LOG_ERROR, "invalid ALAC magic cookie\n");
- av_freep(&st->codec->extradata);
+ av_freep(&st->codecpar->extradata);
return AVERROR_INVALIDDATA;
}
- avio_read(pb, st->codec->extradata, ALAC_HEADER);
+ avio_read(pb, st->codecpar->extradata, ALAC_HEADER);
avio_skip(pb, size - ALAC_PREAMBLE - ALAC_HEADER);
} else {
- AV_WB32(st->codec->extradata, 36);
- memcpy(&st->codec->extradata[4], "alac", 4);
- AV_WB32(&st->codec->extradata[8], 0);
- memcpy(&st->codec->extradata[12], preamble, 12);
- avio_read(pb, &st->codec->extradata[24], ALAC_NEW_KUKI - 12);
+ AV_WB32(st->codecpar->extradata, 36);
+ memcpy(&st->codecpar->extradata[4], "alac", 4);
+ AV_WB32(&st->codecpar->extradata[8], 0);
+ memcpy(&st->codecpar->extradata[12], preamble, 12);
+ avio_read(pb, &st->codecpar->extradata[24], ALAC_NEW_KUKI - 12);
avio_skip(pb, size - ALAC_NEW_KUKI);
}
- st->codec->extradata_size = ALAC_HEADER;
+ st->codecpar->extradata_size = ALAC_HEADER;
} else {
- st->codec->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
- if (!st->codec->extradata)
+ st->codecpar->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!st->codecpar->extradata)
return AVERROR(ENOMEM);
- avio_read(pb, st->codec->extradata, size);
- st->codec->extradata_size = size;
+ avio_read(pb, st->codecpar->extradata, size);
+ st->codecpar->extradata_size = size;
}
return 0;
@@ -309,7 +309,7 @@ static int read_header(AVFormatContext *s)
if (caf->data_size > 0)
st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet;
} else if (st->nb_index_entries) {
- st->codec->bit_rate = st->codec->sample_rate * caf->data_size * 8 /
+ st->codecpar->bit_rate = st->codecpar->sample_rate * caf->data_size * 8 /
st->duration;
} else {
av_log(s, AV_LOG_ERROR, "Missing packet table. It is required when "
@@ -317,7 +317,7 @@ static int read_header(AVFormatContext *s)
return AVERROR_INVALIDDATA;
}
- avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
st->start_time = 0;
/* position the stream at the start of data */