From 9200514ad8717c63f82101dc394f4378854325bf Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 18 Jun 2014 20:42:52 +0200 Subject: 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. --- libavformat/voc_packet.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'libavformat/voc_packet.c') diff --git a/libavformat/voc_packet.c b/libavformat/voc_packet.c index 9e1c746..ff48d50 100644 --- a/libavformat/voc_packet.c +++ b/libavformat/voc_packet.c @@ -24,7 +24,7 @@ int ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size) { VocDecContext *voc = s->priv_data; - AVCodecContext *dec = st->codec; + AVCodecParameters *par = st->codecpar; AVIOContext *pb = s->pb; VocType type; int size, tmp_codec=-1; @@ -45,13 +45,13 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size) switch (type) { case VOC_TYPE_VOICE_DATA: - if (!dec->sample_rate) { - dec->sample_rate = 1000000 / (256 - avio_r8(pb)); + if (!par->sample_rate) { + par->sample_rate = 1000000 / (256 - avio_r8(pb)); if (sample_rate) - dec->sample_rate = sample_rate; - avpriv_set_pts_info(st, 64, 1, dec->sample_rate); - dec->channels = channels; - dec->bits_per_coded_sample = av_get_bits_per_sample(dec->codec_id); + par->sample_rate = sample_rate; + avpriv_set_pts_info(st, 64, 1, par->sample_rate); + par->channels = channels; + par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id); } else avio_skip(pb, 1); tmp_codec = avio_r8(pb); @@ -73,11 +73,11 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size) break; case VOC_TYPE_NEW_VOICE_DATA: - if (!dec->sample_rate) { - dec->sample_rate = avio_rl32(pb); - avpriv_set_pts_info(st, 64, 1, dec->sample_rate); - dec->bits_per_coded_sample = avio_r8(pb); - dec->channels = avio_r8(pb); + if (!par->sample_rate) { + par->sample_rate = avio_rl32(pb); + avpriv_set_pts_info(st, 64, 1, par->sample_rate); + par->bits_per_coded_sample = avio_r8(pb); + par->channels = avio_r8(pb); } else avio_skip(pb, 6); tmp_codec = avio_rl16(pb); @@ -96,11 +96,11 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size) if (tmp_codec >= 0) { tmp_codec = ff_codec_get_id(ff_voc_codec_tags, tmp_codec); - if (dec->codec_id == AV_CODEC_ID_NONE) - dec->codec_id = tmp_codec; - else if (dec->codec_id != tmp_codec) + if (par->codec_id == AV_CODEC_ID_NONE) + par->codec_id = tmp_codec; + else if (par->codec_id != tmp_codec) av_log(s, AV_LOG_WARNING, "Ignoring mid-stream change in audio codec\n"); - if (dec->codec_id == AV_CODEC_ID_NONE) { + if (par->codec_id == AV_CODEC_ID_NONE) { if (s->audio_codec_id == AV_CODEC_ID_NONE) { av_log(s, AV_LOG_ERROR, "unknown codec tag\n"); return AVERROR(EINVAL); @@ -109,7 +109,7 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size) } } - dec->bit_rate = dec->sample_rate * dec->bits_per_coded_sample; + par->bit_rate = par->sample_rate * par->bits_per_coded_sample; if (max_size <= 0) max_size = 2048; -- cgit v1.1