summaryrefslogtreecommitdiff
path: root/libavformat/omadec.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/omadec.c
parenta8068346e48e123f8d3bdf4d64464d81e53e5fc7 (diff)
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/omadec.c')
-rw-r--r--libavformat/omadec.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/libavformat/omadec.c b/libavformat/omadec.c
index c7625a8c20..e29b93eeb9 100644
--- a/libavformat/omadec.c
+++ b/libavformat/omadec.c
@@ -346,10 +346,10 @@ static int oma_read_header(AVFormatContext *s)
return AVERROR(ENOMEM);
st->start_time = 0;
- st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
- st->codec->codec_tag = buf[32];
- st->codec->codec_id = ff_codec_get_id(ff_oma_codec_tags,
- st->codec->codec_tag);
+ st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codecpar->codec_tag = buf[32];
+ st->codecpar->codec_id = ff_codec_get_id(ff_oma_codec_tags,
+ st->codecpar->codec_tag);
switch (buf[32]) {
case OMA_CODECID_ATRAC3:
@@ -366,19 +366,19 @@ static int oma_read_header(AVFormatContext *s)
/* get stereo coding mode, 1 for joint-stereo */
jsflag = (codec_params >> 17) & 1;
- st->codec->channels = 2;
- st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
- st->codec->sample_rate = samplerate;
- st->codec->bit_rate = st->codec->sample_rate * framesize * 8 / 1024;
+ st->codecpar->channels = 2;
+ st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+ st->codecpar->sample_rate = samplerate;
+ st->codecpar->bit_rate = st->codecpar->sample_rate * framesize * 8 / 1024;
/* fake the ATRAC3 extradata
* (wav format, makes stream copy to wav work) */
- st->codec->extradata_size = 14;
+ st->codecpar->extradata_size = 14;
edata = av_mallocz(14 + AV_INPUT_BUFFER_PADDING_SIZE);
if (!edata)
return AVERROR(ENOMEM);
- st->codec->extradata = edata;
+ st->codecpar->extradata = edata;
AV_WL16(&edata[0], 1); // always 1
AV_WL32(&edata[2], samplerate); // samples rate
AV_WL16(&edata[6], jsflag); // coding mode
@@ -386,7 +386,7 @@ static int oma_read_header(AVFormatContext *s)
AV_WL16(&edata[10], 1); // always 1
// AV_WL16(&edata[12], 0); // always 0
- avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
break;
case OMA_CODECID_ATRAC3P:
channel_id = (codec_params >> 10) & 7;
@@ -395,16 +395,16 @@ static int oma_read_header(AVFormatContext *s)
"Invalid ATRAC-X channel id: %"PRIu32"\n", channel_id);
return AVERROR_INVALIDDATA;
}
- st->codec->channel_layout = ff_oma_chid_to_native_layout[channel_id - 1];
- st->codec->channels = ff_oma_chid_to_num_channels[channel_id - 1];
+ st->codecpar->channel_layout = ff_oma_chid_to_native_layout[channel_id - 1];
+ st->codecpar->channels = ff_oma_chid_to_num_channels[channel_id - 1];
framesize = ((codec_params & 0x3FF) * 8) + 8;
samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100;
if (!samplerate) {
av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n");
return AVERROR_INVALIDDATA;
}
- st->codec->sample_rate = samplerate;
- st->codec->bit_rate = samplerate * framesize * 8 / 2048;
+ st->codecpar->sample_rate = samplerate;
+ st->codecpar->bit_rate = samplerate * framesize * 8 / 2048;
avpriv_set_pts_info(st, 64, 1, samplerate);
break;
case OMA_CODECID_MP3:
@@ -413,22 +413,22 @@ static int oma_read_header(AVFormatContext *s)
break;
case OMA_CODECID_LPCM:
/* PCM 44.1 kHz 16 bit stereo big-endian */
- st->codec->channels = 2;
- st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
- st->codec->sample_rate = 44100;
+ st->codecpar->channels = 2;
+ st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+ st->codecpar->sample_rate = 44100;
framesize = 1024;
/* bit rate = sample rate x PCM block align (= 4) x 8 */
- st->codec->bit_rate = st->codec->sample_rate * 32;
- st->codec->bits_per_coded_sample =
- av_get_bits_per_sample(st->codec->codec_id);
- avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ st->codecpar->bit_rate = st->codecpar->sample_rate * 32;
+ st->codecpar->bits_per_coded_sample =
+ av_get_bits_per_sample(st->codecpar->codec_id);
+ avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
break;
default:
av_log(s, AV_LOG_ERROR, "Unsupported codec %d!\n", buf[32]);
return AVERROR(ENOSYS);
}
- st->codec->block_align = framesize;
+ st->codecpar->block_align = framesize;
return 0;
}
@@ -438,8 +438,8 @@ static int oma_read_packet(AVFormatContext *s, AVPacket *pkt)
{
OMAContext *oc = s->priv_data;
AVStream *st = s->streams[0];
- int packet_size = st->codec->block_align;
- int byte_rate = st->codec->bit_rate >> 3;
+ int packet_size = st->codecpar->block_align;
+ int byte_rate = st->codecpar->bit_rate >> 3;
int64_t pos = avio_tell(s->pb);
int ret = av_get_packet(s->pb, pkt, packet_size);