aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/aiffdec.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/aiffdec.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/aiffdec.c')
-rw-r--r--libavformat/aiffdec.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index fc0b7ebf81..e56390937e 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -90,7 +90,7 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size,
unsigned version)
{
AVIOContext *pb = s->pb;
- AVCodecContext *codec = s->streams[0]->codec;
+ AVCodecParameters *par = s->streams[0]->codecpar;
AIFFInputContext *aiff = s->priv_data;
int exp;
uint64_t val;
@@ -99,30 +99,30 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size,
if (size & 1)
size++;
- codec->codec_type = AVMEDIA_TYPE_AUDIO;
- codec->channels = avio_rb16(pb);
+ par->codec_type = AVMEDIA_TYPE_AUDIO;
+ par->channels = avio_rb16(pb);
num_frames = avio_rb32(pb);
- codec->bits_per_coded_sample = avio_rb16(pb);
+ par->bits_per_coded_sample = avio_rb16(pb);
exp = avio_rb16(pb);
val = avio_rb64(pb);
sample_rate = ldexp(val, exp - 16383 - 63);
- codec->sample_rate = sample_rate;
+ par->sample_rate = sample_rate;
size -= 18;
/* get codec id for AIFF-C */
if (version == AIFF_C_VERSION1) {
- codec->codec_tag = avio_rl32(pb);
- codec->codec_id = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag);
+ par->codec_tag = avio_rl32(pb);
+ par->codec_id = ff_codec_get_id(ff_codec_aiff_tags, par->codec_tag);
size -= 4;
}
- if (version != AIFF_C_VERSION1 || codec->codec_id == AV_CODEC_ID_PCM_S16BE) {
- codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample);
- codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id);
+ if (version != AIFF_C_VERSION1 || par->codec_id == AV_CODEC_ID_PCM_S16BE) {
+ par->codec_id = aiff_codec_get_id(par->bits_per_coded_sample);
+ par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id);
aiff->block_duration = 1;
} else {
- switch (codec->codec_id) {
+ switch (par->codec_id) {
case AV_CODEC_ID_PCM_F32BE:
case AV_CODEC_ID_PCM_F64BE:
case AV_CODEC_ID_PCM_S16LE:
@@ -131,37 +131,37 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size,
aiff->block_duration = 1;
break;
case AV_CODEC_ID_ADPCM_IMA_QT:
- codec->block_align = 34*codec->channels;
+ par->block_align = 34 * par->channels;
break;
case AV_CODEC_ID_MACE3:
- codec->block_align = 2*codec->channels;
+ par->block_align = 2 * par->channels;
break;
case AV_CODEC_ID_ADPCM_G722:
case AV_CODEC_ID_MACE6:
- codec->block_align = 1*codec->channels;
+ par->block_align = 1 * par->channels;
break;
case AV_CODEC_ID_GSM:
- codec->block_align = 33;
+ par->block_align = 33;
break;
case AV_CODEC_ID_QCELP:
- codec->block_align = 35;
+ par->block_align = 35;
break;
default:
break;
}
- if (codec->block_align > 0)
- aiff->block_duration = av_get_audio_frame_duration(codec,
- codec->block_align);
+ if (par->block_align > 0)
+ aiff->block_duration = av_get_audio_frame_duration2(par,
+ par->block_align);
}
/* Block align needs to be computed in all cases, as the definition
* is specific to applications -> here we use the WAVE format definition */
- if (!codec->block_align)
- codec->block_align = (codec->bits_per_coded_sample * codec->channels) >> 3;
+ if (!par->block_align)
+ par->block_align = (par->bits_per_coded_sample * par->channels) >> 3;
if (aiff->block_duration) {
- codec->bit_rate = codec->sample_rate * (codec->block_align << 3) /
- aiff->block_duration;
+ par->bit_rate = par->sample_rate * (par->block_align << 3) /
+ aiff->block_duration;
}
/* Chunk is over */
@@ -249,7 +249,7 @@ static int aiff_read_header(AVFormatContext *s)
offset = avio_rb32(pb); /* Offset of sound data */
avio_rb32(pb); /* BlockSize... don't care */
offset += avio_tell(pb); /* Compute absolute data offset */
- if (st->codec->block_align) /* Assume COMM already parsed */
+ if (st->codecpar->block_align) /* Assume COMM already parsed */
goto got_sound;
if (!pb->seekable) {
av_log(s, AV_LOG_ERROR, "file is not seekable\n");
@@ -260,11 +260,11 @@ 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 + 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);
- st->codec->extradata_size = size;
- avio_read(pb, st->codec->extradata, size);
+ st->codecpar->extradata_size = size;
+ avio_read(pb, st->codecpar->extradata, size);
break;
default: /* Jump */
if (size & 1) /* Always even aligned */
@@ -274,13 +274,13 @@ static int aiff_read_header(AVFormatContext *s)
}
got_sound:
- if (!st->codec->block_align) {
+ if (!st->codecpar->block_align) {
av_log(s, AV_LOG_ERROR, "could not find COMM tag or invalid block_align value\n");
return -1;
}
/* Now positioned, get the sound data start and end */
- 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;
st->duration = st->nb_frames * aiff->block_duration;
@@ -306,10 +306,10 @@ static int aiff_read_packet(AVFormatContext *s,
return AVERROR_EOF;
/* Now for that packet */
- if (st->codec->block_align >= 33) // GSM, QCLP, IMA4
- size = st->codec->block_align;
+ if (st->codecpar->block_align >= 33) // GSM, QCLP, IMA4
+ size = st->codecpar->block_align;
else
- size = (MAX_SIZE / st->codec->block_align) * st->codec->block_align;
+ size = (MAX_SIZE / st->codecpar->block_align) * st->codecpar->block_align;
size = FFMIN(max_size, size);
res = av_get_packet(s->pb, pkt, size);
if (res < 0)
@@ -317,7 +317,7 @@ static int aiff_read_packet(AVFormatContext *s,
/* Only one stream in an AIFF file */
pkt->stream_index = 0;
- pkt->duration = (res / st->codec->block_align) * aiff->block_duration;
+ pkt->duration = (res / st->codecpar->block_align) * aiff->block_duration;
return 0;
}