summaryrefslogtreecommitdiff
path: root/libavformat/mp3enc.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/mp3enc.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/mp3enc.c')
-rw-r--r--libavformat/mp3enc.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index 42b3296512..24949cba65 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -128,7 +128,7 @@ static const uint8_t xing_offtbl[2][2] = {{32, 17}, {17, 9}};
static void mp3_write_xing(AVFormatContext *s)
{
MP3Context *mp3 = s->priv_data;
- AVCodecContext *codec = s->streams[mp3->audio_stream_idx]->codec;
+ AVCodecParameters *par = s->streams[mp3->audio_stream_idx]->codecpar;
AVDictionaryEntry *enc = av_dict_get(s->streams[mp3->audio_stream_idx]->metadata, "encoder", NULL, 0);
AVIOContext *dyn_ctx;
int32_t header;
@@ -147,9 +147,9 @@ static void mp3_write_xing(AVFormatContext *s)
for (i = 0; i < FF_ARRAY_ELEMS(avpriv_mpa_freq_tab); i++) {
const uint16_t base_freq = avpriv_mpa_freq_tab[i];
- if (codec->sample_rate == base_freq) ver = 0x3; // MPEG 1
- else if (codec->sample_rate == base_freq / 2) ver = 0x2; // MPEG 2
- else if (codec->sample_rate == base_freq / 4) ver = 0x0; // MPEG 2.5
+ if (par->sample_rate == base_freq) ver = 0x3; // MPEG 1
+ else if (par->sample_rate == base_freq / 2) ver = 0x2; // MPEG 2
+ else if (par->sample_rate == base_freq / 4) ver = 0x0; // MPEG 2.5
else continue;
srate_idx = i;
@@ -161,7 +161,7 @@ static void mp3_write_xing(AVFormatContext *s)
return;
}
- switch (codec->channels) {
+ switch (par->channels) {
case 1: channels = MPA_MONO; break;
case 2: channels = MPA_STEREO; break;
default: av_log(s, AV_LOG_WARNING, "Unsupported number of channels, "
@@ -182,7 +182,7 @@ static void mp3_write_xing(AVFormatContext *s)
for (bitrate_idx = 1; bitrate_idx < 15; bitrate_idx++) {
int bit_rate = 1000 * avpriv_mpa_bitrate_tab[lsf][3 - 1][bitrate_idx];
- int error = FFABS(bit_rate - codec->bit_rate);
+ int error = FFABS(bit_rate - par->bit_rate);
if (error < best_bitrate_error){
best_bitrate_error = error;
@@ -245,11 +245,11 @@ static void mp3_write_xing(AVFormatContext *s)
avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate
// encoder delay
- if (codec->initial_padding >= 1 << 12) {
+ if (par->initial_padding >= 1 << 12) {
av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n");
avio_wb24(dyn_ctx, 0);
} else {
- avio_wb24(dyn_ctx, codec->initial_padding << 12);
+ avio_wb24(dyn_ctx, par->initial_padding << 12);
}
avio_w8(dyn_ctx, 0); // misc
@@ -535,14 +535,14 @@ static int mp3_write_header(struct AVFormatContext *s)
mp3->audio_stream_idx = -1;
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
- if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
- if (mp3->audio_stream_idx >= 0 || st->codec->codec_id != AV_CODEC_ID_MP3) {
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+ if (mp3->audio_stream_idx >= 0 || st->codecpar->codec_id != AV_CODEC_ID_MP3) {
av_log(s, AV_LOG_ERROR, "Invalid audio stream. Exactly one MP3 "
"audio stream is required.\n");
return AVERROR(EINVAL);
}
mp3->audio_stream_idx = i;
- } else if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) {
+ } else if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) {
av_log(s, AV_LOG_ERROR, "Only audio streams and pictures are allowed in MP3.\n");
return AVERROR(EINVAL);
}