diff options
author | Anton Khirnov <anton@khirnov.net> | 2014-06-18 20:42:52 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2016-02-23 17:01:58 +0100 |
commit | 9200514ad8717c63f82101dc394f4378854325bf (patch) | |
tree | 566b8d48565a88303363198acc81de06363daa7a /libavformat | |
parent | a8068346e48e123f8d3bdf4d64464d81e53e5fc7 (diff) | |
download | ffmpeg-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')
223 files changed, 4075 insertions, 3863 deletions
diff --git a/libavformat/4xm.c b/libavformat/4xm.c index 5eaf9851b7..6889ca4c37 100644 --- a/libavformat/4xm.c +++ b/libavformat/4xm.c @@ -108,16 +108,16 @@ static int parse_vtrk(AVFormatContext *s, fourxm->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_4XM; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_4XM; - st->codec->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = 4; - AV_WL32(st->codec->extradata, AV_RL32(buf + 16)); - st->codec->width = AV_RL32(buf + 36); - st->codec->height = AV_RL32(buf + 40); + st->codecpar->extradata_size = 4; + AV_WL32(st->codecpar->extradata, AV_RL32(buf + 16)); + st->codecpar->width = AV_RL32(buf + 36); + st->codecpar->height = AV_RL32(buf + 40); return 0; } @@ -165,23 +165,23 @@ static int parse_strk(AVFormatContext *s, fourxm->tracks[track].stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 0; - st->codec->channels = fourxm->tracks[track].channels; - st->codec->sample_rate = fourxm->tracks[track].sample_rate; - st->codec->bits_per_coded_sample = fourxm->tracks[track].bits; - st->codec->bit_rate = st->codec->channels * - st->codec->sample_rate * - st->codec->bits_per_coded_sample; - st->codec->block_align = st->codec->channels * - st->codec->bits_per_coded_sample; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 0; + st->codecpar->channels = fourxm->tracks[track].channels; + st->codecpar->sample_rate = fourxm->tracks[track].sample_rate; + st->codecpar->bits_per_coded_sample = fourxm->tracks[track].bits; + st->codecpar->bit_rate = st->codecpar->channels * + st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = st->codecpar->channels * + st->codecpar->bits_per_coded_sample; if (fourxm->tracks[track].adpcm){ - st->codec->codec_id = AV_CODEC_ID_ADPCM_4XM; - } else if (st->codec->bits_per_coded_sample == 8) { - st->codec->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_4XM; + } else if (st->codecpar->bits_per_coded_sample == 8) { + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; } else - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; return 0; } diff --git a/libavformat/a64.c b/libavformat/a64.c index c8e8e646b5..fdd6f62750 100644 --- a/libavformat/a64.c +++ b/libavformat/a64.c @@ -27,7 +27,7 @@ static int a64_write_header(AVFormatContext *s) { - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; uint8_t header[5] = { 0x00, //load 0x40, //address @@ -36,20 +36,20 @@ static int a64_write_header(AVFormatContext *s) 0x00 //fps in 50/fps; }; - if (avctx->extradata_size < 4) { + if (par->extradata_size < 4) { av_log(s, AV_LOG_ERROR, "Missing extradata\n"); return AVERROR_INVALIDDATA; } - switch (avctx->codec->id) { + switch (par->codec_id) { case AV_CODEC_ID_A64_MULTI: header[2] = 0x00; - header[3] = AV_RB32(avctx->extradata+0); + header[3] = AV_RB32(par->extradata+0); header[4] = 2; break; case AV_CODEC_ID_A64_MULTI5: header[2] = 0x01; - header[3] = AV_RB32(avctx->extradata+0); + header[3] = AV_RB32(par->extradata+0); header[4] = 3; break; default: diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c index 566c3e78b9..2f207928db 100644 --- a/libavformat/aacdec.c +++ b/libavformat/aacdec.c @@ -82,8 +82,8 @@ static int adts_aac_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->iformat->raw_codec_id; st->need_parsing = AVSTREAM_PARSE_FULL; ff_id3v1_read(s); diff --git a/libavformat/adtsenc.c b/libavformat/adtsenc.c index 55d7510557..e7c72d8c02 100644 --- a/libavformat/adtsenc.c +++ b/libavformat/adtsenc.c @@ -91,11 +91,11 @@ static int adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t static int adts_write_header(AVFormatContext *s) { ADTSContext *adts = s->priv_data; - AVCodecContext *avc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - if (avc->extradata_size > 0) - return adts_decode_extradata(s, adts, avc->extradata, - avc->extradata_size); + if (par->extradata_size > 0) + return adts_decode_extradata(s, adts, par->extradata, + par->extradata_size); return 0; } diff --git a/libavformat/adxdec.c b/libavformat/adxdec.c index c7bd33ab8b..8162c69a9a 100644 --- a/libavformat/adxdec.c +++ b/libavformat/adxdec.c @@ -37,10 +37,10 @@ typedef struct ADXDemuxerContext { static int adx_read_packet(AVFormatContext *s, AVPacket *pkt) { ADXDemuxerContext *c = s->priv_data; - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int ret, size; - size = BLOCK_SIZE * avctx->channels; + size = BLOCK_SIZE * par->channels; pkt->pos = avio_tell(s->pb); pkt->stream_index = 0; @@ -64,43 +64,43 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt) static int adx_read_header(AVFormatContext *s) { ADXDemuxerContext *c = s->priv_data; - AVCodecContext *avctx; + AVCodecParameters *par; AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - avctx = s->streams[0]->codec; + par = s->streams[0]->codecpar; if (avio_rb16(s->pb) != 0x8000) return AVERROR_INVALIDDATA; c->header_size = avio_rb16(s->pb) + 4; avio_seek(s->pb, -4, SEEK_CUR); - avctx->extradata = av_mallocz(c->header_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!avctx->extradata) + par->extradata = av_mallocz(c->header_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!par->extradata) return AVERROR(ENOMEM); - if (avio_read(s->pb, avctx->extradata, c->header_size) < c->header_size) { - av_freep(&avctx->extradata); + if (avio_read(s->pb, par->extradata, c->header_size) < c->header_size) { + av_freep(&par->extradata); return AVERROR(EIO); } - avctx->extradata_size = c->header_size; + par->extradata_size = c->header_size; - if (avctx->extradata_size < 12) { + if (par->extradata_size < 12) { av_log(s, AV_LOG_ERROR, "Invalid extradata size.\n"); return AVERROR_INVALIDDATA; } - avctx->channels = AV_RB8(avctx->extradata + 7); - avctx->sample_rate = AV_RB32(avctx->extradata + 8); + par->channels = AV_RB8 (par->extradata + 7); + par->sample_rate = AV_RB32(par->extradata + 8); - if (avctx->channels <= 0) { - av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", avctx->channels); + if (par->channels <= 0) { + av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", par->channels); return AVERROR_INVALIDDATA; } - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->codec_id = s->iformat->raw_codec_id; - avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate); + avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, par->sample_rate); return 0; } diff --git a/libavformat/aea.c b/libavformat/aea.c index c107109cfa..a20bf7ca67 100644 --- a/libavformat/aea.c +++ b/libavformat/aea.c @@ -62,29 +62,29 @@ static int aea_read_header(AVFormatContext *s) /* Parse the amount of channels and skip to pos 2048(0x800) */ avio_skip(s->pb, 264); - st->codec->channels = avio_r8(s->pb); + st->codecpar->channels = avio_r8(s->pb); avio_skip(s->pb, 1783); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ATRAC1; - st->codec->sample_rate = 44100; - st->codec->bit_rate = 292000; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ATRAC1; + st->codecpar->sample_rate = 44100; + st->codecpar->bit_rate = 292000; - if (st->codec->channels != 1 && st->codec->channels != 2) { - av_log(s,AV_LOG_ERROR,"Channels %d not supported!\n",st->codec->channels); + if (st->codecpar->channels != 1 && st->codecpar->channels != 2) { + av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", st->codecpar->channels); return AVERROR_INVALIDDATA; } - st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; + st->codecpar->channel_layout = (st->codecpar->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; - st->codec->block_align = AT1_SU_SIZE * st->codec->channels; + st->codecpar->block_align = AT1_SU_SIZE * st->codecpar->channels; return 0; } static int aea_read_packet(AVFormatContext *s, AVPacket *pkt) { - int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align); + int ret = av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align); pkt->stream_index = 0; if (ret <= 0) 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; } diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c index aa68108368..6449c00cad 100644 --- a/libavformat/aiffenc.c +++ b/libavformat/aiffenc.c @@ -37,14 +37,14 @@ static int aiff_write_header(AVFormatContext *s) { AIFFOutputContext *aiff = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; uint64_t sample_rate; int aifc = 0; /* First verify if format is ok */ - if (!enc->codec_tag) + if (!par->codec_tag) return -1; - if (enc->codec_tag != MKTAG('N','O','N','E')) + if (par->codec_tag != MKTAG('N','O','N','E')) aifc = 1; /* FORM AIFF header */ @@ -54,8 +54,8 @@ static int aiff_write_header(AVFormatContext *s) ffio_wfourcc(pb, aifc ? "AIFC" : "AIFF"); if (aifc) { // compressed audio - enc->bits_per_coded_sample = 16; - if (!enc->block_align) { + par->bits_per_coded_sample = 16; + if (!par->block_align) { av_log(s, AV_LOG_ERROR, "block align not set\n"); return -1; } @@ -68,28 +68,28 @@ static int aiff_write_header(AVFormatContext *s) /* Common chunk */ ffio_wfourcc(pb, "COMM"); avio_wb32(pb, aifc ? 24 : 18); /* size */ - avio_wb16(pb, enc->channels); /* Number of channels */ + avio_wb16(pb, par->channels); /* Number of channels */ aiff->frames = avio_tell(pb); avio_wb32(pb, 0); /* Number of frames */ - if (!enc->bits_per_coded_sample) - enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id); - if (!enc->bits_per_coded_sample) { + if (!par->bits_per_coded_sample) + par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id); + if (!par->bits_per_coded_sample) { av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n"); return -1; } - if (!enc->block_align) - enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3; + if (!par->block_align) + par->block_align = (par->bits_per_coded_sample * par->channels) >> 3; - avio_wb16(pb, enc->bits_per_coded_sample); /* Sample size */ + avio_wb16(pb, par->bits_per_coded_sample); /* Sample size */ - sample_rate = av_double2int(enc->sample_rate); + sample_rate = av_double2int(par->sample_rate); avio_wb16(pb, (sample_rate >> 52) + (16383 - 1023)); avio_wb64(pb, UINT64_C(1) << 63 | sample_rate << 11); if (aifc) { - avio_wl32(pb, enc->codec_tag); + avio_wl32(pb, par->codec_tag); avio_wb16(pb, 0); } @@ -100,7 +100,7 @@ static int aiff_write_header(AVFormatContext *s) avio_wb32(pb, 0); /* Data offset */ avio_wb32(pb, 0); /* Block-size (block align) */ - avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); + avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codecpar->sample_rate); /* Data is starting here */ avio_flush(pb); @@ -119,7 +119,7 @@ static int aiff_write_trailer(AVFormatContext *s) { AVIOContext *pb = s->pb; AIFFOutputContext *aiff = s->priv_data; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; /* Chunks sizes must be even */ int64_t file_size, end_size; @@ -136,7 +136,7 @@ static int aiff_write_trailer(AVFormatContext *s) /* Number of sample frames */ avio_seek(pb, aiff->frames, SEEK_SET); - avio_wb32(pb, (file_size-aiff->ssnd-12)/enc->block_align); + avio_wb32(pb, (file_size - aiff->ssnd - 12) / par->block_align); /* Sound Data chunk size */ avio_seek(pb, aiff->ssnd, SEEK_SET); diff --git a/libavformat/amr.c b/libavformat/amr.c index b57a568525..580e9339a3 100644 --- a/libavformat/amr.c +++ b/libavformat/amr.c @@ -37,13 +37,13 @@ static const char AMRWB_header[] = "#!AMR-WB\n"; static int amr_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; s->priv_data = NULL; - if (enc->codec_id == AV_CODEC_ID_AMR_NB) { + if (par->codec_id == AV_CODEC_ID_AMR_NB) { avio_write(pb, AMR_header, sizeof(AMR_header) - 1); /* magic number */ - } else if (enc->codec_id == AV_CODEC_ID_AMR_WB) { + } else if (par->codec_id == AV_CODEC_ID_AMR_WB) { avio_write(pb, AMRWB_header, sizeof(AMRWB_header) - 1); /* magic number */ } else { return -1; @@ -89,25 +89,25 @@ static int amr_read_header(AVFormatContext *s) return -1; } - st->codec->codec_tag = MKTAG('s', 'a', 'w', 'b'); - st->codec->codec_id = AV_CODEC_ID_AMR_WB; - st->codec->sample_rate = 16000; + st->codecpar->codec_tag = MKTAG('s', 'a', 'w', 'b'); + st->codecpar->codec_id = AV_CODEC_ID_AMR_WB; + st->codecpar->sample_rate = 16000; } else { - st->codec->codec_tag = MKTAG('s', 'a', 'm', 'r'); - st->codec->codec_id = AV_CODEC_ID_AMR_NB; - st->codec->sample_rate = 8000; + st->codecpar->codec_tag = MKTAG('s', 'a', 'm', 'r'); + st->codecpar->codec_id = AV_CODEC_ID_AMR_NB; + st->codecpar->sample_rate = 8000; } - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int read, size = 0, toc, mode; int64_t pos = avio_tell(s->pb); @@ -119,13 +119,13 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) toc = avio_r8(s->pb); mode = (toc >> 3) & 0x0F; - if (enc->codec_id == AV_CODEC_ID_AMR_NB) { + if (par->codec_id == AV_CODEC_ID_AMR_NB) { static const uint8_t packed_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; size = packed_size[mode] + 1; - } else if (enc->codec_id == AV_CODEC_ID_AMR_WB) { + } else if (par->codec_id == AV_CODEC_ID_AMR_WB) { static const uint8_t packed_size[16] = { 18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1 }; @@ -139,12 +139,12 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EIO); /* Both AMR formats have 50 frames per second */ - s->streams[0]->codec->bit_rate = size*8*50; + s->streams[0]->codecpar->bit_rate = size*8*50; pkt->stream_index = 0; pkt->pos = pos; pkt->data[0] = toc; - pkt->duration = enc->codec_id == AV_CODEC_ID_AMR_NB ? 160 : 320; + pkt->duration = par->codec_id == AV_CODEC_ID_AMR_NB ? 160 : 320; read = avio_read(s->pb, pkt->data + 1, size - 1); if (read != size - 1) { diff --git a/libavformat/anm.c b/libavformat/anm.c index 69a13744f1..2ab6712f26 100644 --- a/libavformat/anm.c +++ b/libavformat/anm.c @@ -100,11 +100,11 @@ static int read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_ANM; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = avio_rl16(pb); - st->codec->height = avio_rl16(pb); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_ANM; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = avio_rl16(pb); + st->codecpar->height = avio_rl16(pb); if (avio_r8(pb) != 0) goto invalid; avio_skip(pb, 1); /* frame rate multiplier info */ @@ -132,12 +132,12 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 58); /* color cycling and palette data */ - st->codec->extradata_size = 16*8 + 4*256; - st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) { + st->codecpar->extradata_size = 16*8 + 4*256; + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) { return AVERROR(ENOMEM); } - ret = avio_read(pb, st->codec->extradata, st->codec->extradata_size); + ret = avio_read(pb, st->codecpar->extradata, st->codecpar->extradata_size); if (ret < 0) return ret; diff --git a/libavformat/apc.c b/libavformat/apc.c index 58fd9f8771..40ecdf2c5d 100644 --- a/libavformat/apc.c +++ b/libavformat/apc.c @@ -45,33 +45,33 @@ static int apc_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_APC; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_APC; avio_rl32(pb); /* number of samples */ - st->codec->sample_rate = avio_rl32(pb); + st->codecpar->sample_rate = avio_rl32(pb); - st->codec->extradata_size = 2 * 4; - st->codec->extradata = av_malloc(st->codec->extradata_size + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata_size = 2 * 4; + st->codecpar->extradata = av_malloc(st->codecpar->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); /* initial predictor values for adpcm decoder */ - avio_read(pb, st->codec->extradata, 2 * 4); + avio_read(pb, st->codecpar->extradata, 2 * 4); if (avio_rl32(pb)) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - st->codec->bits_per_coded_sample = 4; - st->codec->bit_rate = st->codec->bits_per_coded_sample * st->codec->channels - * st->codec->sample_rate; - st->codec->block_align = 1; + st->codecpar->bits_per_coded_sample = 4; + st->codecpar->bit_rate = st->codecpar->bits_per_coded_sample * st->codecpar->channels + * st->codecpar->sample_rate; + st->codecpar->block_align = 1; return 0; } diff --git a/libavformat/ape.c b/libavformat/ape.c index 09a756da60..bcc1f7aa07 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -344,23 +344,23 @@ static int ape_read_header(AVFormatContext * s) total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_APE; - st->codec->codec_tag = MKTAG('A', 'P', 'E', ' '); - st->codec->channels = ape->channels; - st->codec->sample_rate = ape->samplerate; - st->codec->bits_per_coded_sample = ape->bps; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_APE; + st->codecpar->codec_tag = MKTAG('A', 'P', 'E', ' '); + st->codecpar->channels = ape->channels; + st->codecpar->sample_rate = ape->samplerate; + st->codecpar->bits_per_coded_sample = ape->bps; st->nb_frames = ape->totalframes; st->start_time = 0; st->duration = total_blocks / MAC_SUBFRAME_SIZE; avpriv_set_pts_info(st, 64, MAC_SUBFRAME_SIZE, ape->samplerate); - st->codec->extradata = av_malloc(APE_EXTRADATA_SIZE); - st->codec->extradata_size = APE_EXTRADATA_SIZE; - AV_WL16(st->codec->extradata + 0, ape->fileversion); - AV_WL16(st->codec->extradata + 2, ape->compressiontype); - AV_WL16(st->codec->extradata + 4, ape->formatflags); + st->codecpar->extradata = av_malloc(APE_EXTRADATA_SIZE); + st->codecpar->extradata_size = APE_EXTRADATA_SIZE; + AV_WL16(st->codecpar->extradata + 0, ape->fileversion); + AV_WL16(st->codecpar->extradata + 2, ape->compressiontype); + AV_WL16(st->codecpar->extradata + 4, ape->formatflags); pts = 0; for (i = 0; i < ape->totalframes; i++) { diff --git a/libavformat/apetag.c b/libavformat/apetag.c index 5591555377..044bfd8022 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -87,22 +87,22 @@ static int ape_tag_read_field(AVFormatContext *s) } st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; st->attached_pic = pkt; st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; } else { - st->codec->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - if (avio_read(pb, st->codec->extradata, size) != size) { - av_freep(&st->codec->extradata); + if (avio_read(pb, st->codecpar->extradata, size) != size) { + av_freep(&st->codecpar->extradata); return AVERROR(EIO); } - st->codec->extradata_size = size; - st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; + st->codecpar->extradata_size = size; + st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT; } } else { value = av_malloc(size+1); diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c index 85d32668f8..e3320e9b69 100644 --- a/libavformat/asfdec.c +++ b/libavformat/asfdec.c @@ -431,8 +431,8 @@ static int asf_read_picture(AVFormatContext *s, int len) } st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = asf_st->type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = id; + st->codecpar->codec_type = asf_st->type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; st->attached_pic = pkt; st->attached_pic.stream_index = asf_st->index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; @@ -695,26 +695,26 @@ static int parse_video_info(AVIOContext *pb, AVStream *st) uint16_t size; unsigned int tag; - st->codec->width = avio_rl32(pb); - st->codec->height = avio_rl32(pb); + st->codecpar->width = avio_rl32(pb); + st->codecpar->height = avio_rl32(pb); avio_skip(pb, 1); // skip reserved flags size = avio_rl16(pb); // size of the Format Data tag = ff_get_bmp_header(pb, st); - st->codec->codec_tag = tag; - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); + st->codecpar->codec_tag = tag; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); if (size > BMP_HEADER_SIZE) { int ret; - st->codec->extradata_size = size - BMP_HEADER_SIZE; - if (!(st->codec->extradata = av_malloc(st->codec->extradata_size + + st->codecpar->extradata_size = size - BMP_HEADER_SIZE; + if (!(st->codecpar->extradata = av_malloc(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE))) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = 0; return AVERROR(ENOMEM); } - memset(st->codec->extradata + st->codec->extradata_size , 0, + memset(st->codecpar->extradata + st->codecpar->extradata_size , 0, AV_INPUT_BUFFER_PADDING_SIZE); - if ((ret = avio_read(pb, st->codec->extradata, - st->codec->extradata_size)) < 0) + if ((ret = avio_read(pb, st->codecpar->extradata, + st->codecpar->extradata_size)) < 0) return ret; } return 0; @@ -773,7 +773,7 @@ static int asf_read_stream_properties(AVFormatContext *s, const GUIDParseTable * if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 32, 1, 1000); // pts should be dword, in milliseconds - st->codec->codec_type = type; + st->codecpar->codec_type = type; asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st)); if (!asf->asf_st[asf->nb_streams]) return AVERROR(ENOMEM); @@ -790,7 +790,7 @@ static int asf_read_stream_properties(AVFormatContext *s, const GUIDParseTable * switch (type) { case AVMEDIA_TYPE_AUDIO: asf_st->type = AVMEDIA_TYPE_AUDIO; - if ((ret = ff_get_wav_header(s, pb, st->codec, ts_data_len)) < 0) + if ((ret = ff_get_wav_header(s, pb, st->codecpar, ts_data_len)) < 0) return ret; break; case AVMEDIA_TYPE_VIDEO: @@ -867,7 +867,7 @@ static int asf_read_ext_stream_properties(AVFormatContext *s, const GUIDParseTab if (st) { st->start_time = start_time; st->duration = end_time - start_time; - st->codec->bit_rate = bitrate; + st->codecpar->bit_rate = bitrate; st->avg_frame_rate.num = 10000000; st->avg_frame_rate.den = time_per_frame; } diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c index f6608d5292..79eb08310b 100644 --- a/libavformat/asfenc.c +++ b/libavformat/asfenc.c @@ -377,7 +377,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int header_size, n, extra_size, extra_size2, wav_extra_size, file_time; int has_title; int metadata_count; - AVCodecContext *enc; + AVCodecParameters *par; int64_t header_offset, cur_pos, hpos; int bit_rate; int64_t duration; @@ -396,11 +396,11 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, bit_rate = 0; for (n = 0; n < s->nb_streams; n++) { - enc = s->streams[n]->codec; + par = s->streams[n]->codecpar; avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */ - bit_rate += enc->bit_rate; + bit_rate += par->bit_rate; } if (asf->is_streamed) { @@ -479,11 +479,11 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t es_pos; // ASFStream *stream = &asf->streams[n]; - enc = s->streams[n]->codec; + par = s->streams[n]->codecpar; asf->streams[n].num = n + 1; asf->streams[n].seq = 0; - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: wav_extra_size = 0; extra_size = 18 + wav_extra_size; @@ -491,14 +491,14 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, break; default: case AVMEDIA_TYPE_VIDEO: - wav_extra_size = enc->extradata_size; + wav_extra_size = par->extradata_size; extra_size = 0x33 + wav_extra_size; extra_size2 = 0; break; } hpos = put_header(pb, &ff_asf_stream_header); - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + if (par->codec_type == AVMEDIA_TYPE_AUDIO) { put_guid(pb, &ff_asf_audio_stream); put_guid(pb, &ff_asf_audio_conceal_spread); } else { @@ -512,9 +512,9 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, avio_wl16(pb, n + 1); /* stream number */ avio_wl32(pb, 0); /* ??? */ - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + if (par->codec_type == AVMEDIA_TYPE_AUDIO) { /* WAVEFORMATEX header */ - int wavsize = ff_put_wav_header(pb, enc); + int wavsize = ff_put_wav_header(s, pb, par); if (wavsize < 0) return -1; @@ -526,23 +526,23 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, } /* ERROR Correction */ avio_w8(pb, 0x01); - if (enc->codec_id == AV_CODEC_ID_ADPCM_G726 || !enc->block_align) { + if (par->codec_id == AV_CODEC_ID_ADPCM_G726 || !par->block_align) { avio_wl16(pb, 0x0190); avio_wl16(pb, 0x0190); } else { - avio_wl16(pb, enc->block_align); - avio_wl16(pb, enc->block_align); + avio_wl16(pb, par->block_align); + avio_wl16(pb, par->block_align); } avio_wl16(pb, 0x01); avio_w8(pb, 0x00); } else { - avio_wl32(pb, enc->width); - avio_wl32(pb, enc->height); + avio_wl32(pb, par->width); + avio_wl32(pb, par->height); avio_w8(pb, 2); /* ??? */ - avio_wl16(pb, 40 + enc->extradata_size); /* size */ + avio_wl16(pb, 40 + par->extradata_size); /* size */ /* BITMAPINFOHEADER header */ - ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 1); + ff_put_bmp_header(pb, par, ff_codec_bmp_tags, 1); } end_header(pb, hpos); } @@ -556,17 +556,17 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, const AVCodecDescriptor *codec_desc; const char *desc; - enc = s->streams[n]->codec; - codec_desc = avcodec_descriptor_get(enc->codec_id); + par = s->streams[n]->codecpar; + codec_desc = avcodec_descriptor_get(par->codec_id); - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + if (par->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl16(pb, 2); - else if (enc->codec_type == AVMEDIA_TYPE_VIDEO) + else if (par->codec_type == AVMEDIA_TYPE_VIDEO) avio_wl16(pb, 1); else avio_wl16(pb, -1); - if (enc->codec_id == AV_CODEC_ID_WMAV2) + if (par->codec_id == AV_CODEC_ID_WMAV2) desc = "Windows Media Audio V8"; else desc = codec_desc ? codec_desc->name : NULL; @@ -591,14 +591,14 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, avio_wl16(pb, 0); /* no parameters */ /* id */ - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + if (par->codec_type == AVMEDIA_TYPE_AUDIO) { avio_wl16(pb, 2); - avio_wl16(pb, enc->codec_tag); + avio_wl16(pb, par->codec_tag); } else { avio_wl16(pb, 4); - avio_wl32(pb, enc->codec_tag); + avio_wl32(pb, par->codec_tag); } - if (!enc->codec_tag) + if (!par->codec_tag) return -1; } end_header(pb, hpos); @@ -813,7 +813,7 @@ static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst, PACKET_HEADER_MIN_SIZE - 1; if (frag_len1 < payload_len && - avst->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + avst->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { flush_packet(s); continue; } @@ -855,16 +855,16 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt) AVIOContext *pb = s->pb; ASFStream *stream; int64_t duration; - AVCodecContext *codec; + AVCodecParameters *par; int64_t packet_st, pts; int start_sec, i; int flags = pkt->flags; uint64_t offset = avio_tell(pb); - codec = s->streams[pkt->stream_index]->codec; + par = s->streams[pkt->stream_index]->codecpar; stream = &asf->streams[pkt->stream_index]; - if (codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (par->codec_type == AVMEDIA_TYPE_AUDIO) flags &= ~AV_PKT_FLAG_KEY; pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts; diff --git a/libavformat/assdec.c b/libavformat/assdec.c index f9f1bdfb9a..059cefe081 100644 --- a/libavformat/assdec.c +++ b/libavformat/assdec.c @@ -91,11 +91,11 @@ static int read_header(AVFormatContext *s) if (!st) return -1; avpriv_set_pts_info(st, 64, 1, 100); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_SSA; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_SSA; header_remaining = INT_MAX; - dst[0] = &st->codec->extradata; + dst[0] = &st->codecpar->extradata; dst[1] = &ass->event_buffer; while (!pb->eof_reached) { uint8_t line[MAX_LINESIZE]; @@ -123,7 +123,7 @@ static int read_header(AVFormatContext *s) else header_remaining--; } - st->codec->extradata_size = pos[0]; + st->codecpar->extradata_size = pos[0]; if (ass->event_count >= UINT_MAX / sizeof(*ass->event)) goto fail; @@ -163,7 +163,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) return ret; pkt->flags |= AV_PKT_FLAG_KEY; - pkt->pos = p - ass->event_buffer + s->streams[0]->codec->extradata_size; + pkt->pos = p - ass->event_buffer + s->streams[0]->codecpar->extradata_size; pkt->pts = pkt->dts = get_pts(p); memcpy(pkt->data, p, pkt->size); diff --git a/libavformat/assenc.c b/libavformat/assenc.c index 751485dfb5..c6f9851c3b 100644 --- a/libavformat/assenc.c +++ b/libavformat/assenc.c @@ -28,18 +28,18 @@ typedef struct ASSContext{ static int write_header(AVFormatContext *s) { ASSContext *ass = s->priv_data; - AVCodecContext *avctx= s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; uint8_t *last= NULL; - if(s->nb_streams != 1 || avctx->codec_id != AV_CODEC_ID_SSA){ + if(s->nb_streams != 1 || par->codec_id != AV_CODEC_ID_SSA){ av_log(s, AV_LOG_ERROR, "Exactly one ASS/SSA stream is needed.\n"); return -1; } - while(ass->extra_index < avctx->extradata_size){ - uint8_t *p = avctx->extradata + ass->extra_index; + while(ass->extra_index < par->extradata_size){ + uint8_t *p = par->extradata + ass->extra_index; uint8_t *end= strchr(p, '\n'); - if(!end) end= avctx->extradata + avctx->extradata_size; + if(!end) end= par->extradata + par->extradata_size; else end++; avio_write(s->pb, p, end-p); @@ -64,10 +64,10 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) static int write_trailer(AVFormatContext *s) { ASSContext *ass = s->priv_data; - AVCodecContext *avctx= s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - avio_write(s->pb, avctx->extradata + ass->extra_index, - avctx->extradata_size - ass->extra_index); + avio_write(s->pb, par->extradata + ass->extra_index, + par->extradata_size - ass->extra_index); return 0; } diff --git a/libavformat/au.c b/libavformat/au.c index e682cbf305..e30314239f 100644 --- a/libavformat/au.c +++ b/libavformat/au.c @@ -108,13 +108,13 @@ static int au_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = id; - st->codec->codec_id = codec; - st->codec->channels = channels; - st->codec->sample_rate = rate; - st->codec->bit_rate = channels * rate * bps; - st->codec->block_align = channels * bps >> 3; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = id; + st->codecpar->codec_id = codec; + st->codecpar->channels = channels; + st->codecpar->sample_rate = rate; + st->codecpar->bit_rate = channels * rate * bps; + st->codecpar->block_align = channels * bps >> 3; st->start_time = 0; avpriv_set_pts_info(st, 64, 1, rate); @@ -127,12 +127,12 @@ static int au_read_packet(AVFormatContext *s, AVPacket *pkt) int ret; ret = av_get_packet(s->pb, pkt, BLOCK_SIZE * - s->streams[0]->codec->block_align); + s->streams[0]->codecpar->block_align); if (ret < 0) return ret; pkt->stream_index = 0; - pkt->duration = ret / s->streams[0]->codec->block_align; + pkt->duration = ret / s->streams[0]->codecpar->block_align; return 0; } @@ -157,17 +157,17 @@ AVInputFormat ff_au_demuxer = { #define AU_UNKNOWN_SIZE ((uint32_t)(~0)) /* AUDIO_FILE header */ -static int put_au_header(AVIOContext *pb, AVCodecContext *enc) +static int put_au_header(AVIOContext *pb, AVCodecParameters *par) { - if (!enc->codec_tag) + if (!par->codec_tag) return AVERROR(EINVAL); ffio_wfourcc(pb, ".snd"); /* magic number */ avio_wb32(pb, 24); /* header size */ avio_wb32(pb, AU_UNKNOWN_SIZE); /* data size */ - avio_wb32(pb, enc->codec_tag); /* codec ID */ - avio_wb32(pb, enc->sample_rate); - avio_wb32(pb, enc->channels); + avio_wb32(pb, par->codec_tag); /* codec ID */ + avio_wb32(pb, par->sample_rate); + avio_wb32(pb, par->channels); return 0; } @@ -179,7 +179,7 @@ static int au_write_header(AVFormatContext *s) s->priv_data = NULL; - if ((ret = put_au_header(pb, s->streams[0]->codec)) < 0) + if ((ret = put_au_header(pb, s->streams[0]->codecpar)) < 0) return ret; avio_flush(pb); diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c index fd07893b5c..aa379f675e 100644 --- a/libavformat/audiointerleave.c +++ b/libavformat/audiointerleave.c @@ -33,7 +33,7 @@ void ff_audio_interleave_close(AVFormatContext *s) AVStream *st = s->streams[i]; AudioInterleaveContext *aic = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) av_fifo_free(aic->fifo); } } @@ -51,9 +51,9 @@ int ff_audio_interleave_init(AVFormatContext *s, AVStream *st = s->streams[i]; AudioInterleaveContext *aic = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - aic->sample_size = (st->codec->channels * - av_get_bits_per_sample(st->codec->codec_id)) / 8; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + aic->sample_size = (st->codecpar->channels * + av_get_bits_per_sample(st->codecpar->codec_id)) / 8; if (!aic->sample_size) { av_log(s, AV_LOG_ERROR, "could not compute sample size\n"); return -1; @@ -106,7 +106,7 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt if (pkt) { AVStream *st = s->streams[pkt->stream_index]; AudioInterleaveContext *aic = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { unsigned new_size = av_fifo_size(aic->fifo) + pkt->size; if (new_size > aic->fifo_size) { if (av_fifo_realloc2(aic->fifo, new_size) < 0) @@ -126,7 +126,7 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { AVPacket new_pkt = { 0 }; while (interleave_new_audio_packet(s, &new_pkt, i, flush)) if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index b63541d411..6db17f70cf 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -704,18 +704,13 @@ typedef struct AVStream { * encoding: set by the user, replaced by libavformat if left unset */ int id; +#if FF_API_LAVF_AVCTX /** - * Codec context associated with this stream. Allocated and freed by - * libavformat. - * - * - decoding: The demuxer exports codec information stored in the headers - * here. - * - encoding: The user sets codec information, the muxer writes it to the - * output. Mandatory fields as specified in AVCodecContext - * documentation must be set even if this AVCodecContext is - * not actually used for encoding. + * @deprecated use the codecpar struct instead */ + attribute_deprecated AVCodecContext *codec; +#endif void *priv_data; #if FF_API_LAVF_FRAC @@ -818,6 +813,17 @@ typedef struct AVStream { int event_flags; #define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001 ///< The call resulted in updated metadata. + /* + * Codec parameters associated with this stream. Allocated and freed by + * libavformat in avformat_new_stream() and avformat_free_context() + * respectively. + * + * - demuxing: filled by libavformat on stream creation or in + * avformat_find_stream_info() + * - muxing: filled by the caller before avformat_write_header() + */ + AVCodecParameters *codecpar; + /***************************************************************** * All fields below this line are not part of the public API. They * may not be used outside of libavformat and can be changed and diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 4cebd17919..f5705e5436 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -487,8 +487,8 @@ static int avi_read_header(AVFormatContext *s) goto fail; ast = s->streams[0]->priv_data; - av_freep(&s->streams[0]->codec->extradata); - av_freep(&s->streams[0]->codec); + av_freep(&s->streams[0]->codecpar->extradata); + av_freep(&s->streams[0]->codecpar); av_freep(&s->streams[0]->info); av_freep(&s->streams[0]); s->nb_streams = 0; @@ -606,10 +606,10 @@ static int avi_read_header(AVFormatContext *s) switch (codec_type) { case AVMEDIA_TYPE_VIDEO: if (amv_file_format) { - st->codec->width = avih_width; - st->codec->height = avih_height; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_AMV; + st->codecpar->width = avih_width; + st->codecpar->height = avih_height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_AMV; avio_skip(pb, size); break; } @@ -617,41 +617,41 @@ static int avi_read_header(AVFormatContext *s) if (tag1 == MKTAG('D', 'X', 'S', 'B') || tag1 == MKTAG('D', 'X', 'S', 'A')) { - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_tag = tag1; - st->codec->codec_id = AV_CODEC_ID_XSUB; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_tag = tag1; + st->codecpar->codec_id = AV_CODEC_ID_XSUB; break; } if (size > 10 * 4 && size < (1 << 30)) { - st->codec->extradata_size = size - 10 * 4; - st->codec->extradata = av_malloc(st->codec->extradata_size + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = size - 10 * 4; + st->codecpar->extradata = av_malloc(st->codecpar->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) { + st->codecpar->extradata_size = 0; return AVERROR(ENOMEM); } avio_read(pb, - st->codec->extradata, - st->codec->extradata_size); + st->codecpar->extradata, + st->codecpar->extradata_size); } // FIXME: check if the encoder really did this correctly - if (st->codec->extradata_size & 1) + if (st->codecpar->extradata_size & 1) avio_r8(pb); /* Extract palette from extradata if bpp <= 8. * This code assumes that extradata contains only palette. * This is true for all paletted codecs implemented in * Libav. */ - if (st->codec->extradata_size && - (st->codec->bits_per_coded_sample <= 8)) { - int pal_size = (1 << st->codec->bits_per_coded_sample) << 2; + if (st->codecpar->extradata_size && + (st->codecpar->bits_per_coded_sample <= 8)) { + int pal_size = (1 << st->codecpar->bits_per_coded_sample) << 2; const uint8_t *pal_src; - pal_size = FFMIN(pal_size, st->codec->extradata_size); - pal_src = st->codec->extradata + - st->codec->extradata_size - pal_size; + pal_size = FFMIN(pal_size, st->codecpar->extradata_size); + pal_src = st->codecpar->extradata + + st->codecpar->extradata_size - pal_size; #if HAVE_BIGENDIAN for (i = 0; i < pal_size / 4; i++) ast->pal[i] = av_bswap32(((uint32_t *)pal_src)[i]); @@ -663,17 +663,17 @@ static int avi_read_header(AVFormatContext *s) print_tag("video", tag1, 0); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = tag1; - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = tag1; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); /* If codec is not found yet, try with the mov tags. */ - if (!st->codec->codec_id) { + if (!st->codecpar->codec_id) { char tag_buf[32]; av_get_codec_tag_string(tag_buf, sizeof(tag_buf), tag1); - st->codec->codec_id = + st->codecpar->codec_id = ff_codec_get_id(ff_codec_movvideo_tags, tag1); - if (st->codec->codec_id) + if (st->codecpar->codec_id) av_log(s, AV_LOG_WARNING, "mov tag found in avi (fourcc %s)\n", tag_buf); @@ -682,45 +682,45 @@ static int avi_read_header(AVFormatContext *s) * for generating correct pts. */ st->need_parsing = AVSTREAM_PARSE_HEADERS; - if (st->codec->codec_id == AV_CODEC_ID_MPEG4 && + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 && ast->handler == MKTAG('X', 'V', 'I', 'D')) - st->codec->codec_tag = MKTAG('X', 'V', 'I', 'D'); + st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D'); // Support "Resolution 1:1" for Avid AVI Codec if (tag1 == MKTAG('A', 'V', 'R', 'n') && - st->codec->extradata_size >= 31 && - !memcmp(&st->codec->extradata[28], "1:1", 3)) - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - - if (st->codec->codec_tag == 0 && st->codec->height > 0 && - st->codec->extradata_size < 1U << 30) { - st->codec->extradata_size += 9; - if ((ret = av_reallocp(&st->codec->extradata, - st->codec->extradata_size + + st->codecpar->extradata_size >= 31 && + !memcmp(&st->codecpar->extradata[28], "1:1", 3)) + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + + if (st->codecpar->codec_tag == 0 && st->codecpar->height > 0 && + st->codecpar->extradata_size < 1U << 30) { + st->codecpar->extradata_size += 9; + if ((ret = av_reallocp(&st->codecpar->extradata, + st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = 0; return ret; } else - memcpy(st->codec->extradata + st->codec->extradata_size - 9, + memcpy(st->codecpar->extradata + st->codecpar->extradata_size - 9, "BottomUp", 9); } - st->codec->height = FFABS(st->codec->height); + st->codecpar->height = FFABS(st->codecpar->height); // avio_skip(pb, size - 5 * 4); break; case AVMEDIA_TYPE_AUDIO: - ret = ff_get_wav_header(s, pb, st->codec, size); + ret = ff_get_wav_header(s, pb, st->codecpar, size); if (ret < 0) return ret; - ast->dshow_block_align = st->codec->block_align; - if (ast->sample_size && st->codec->block_align && - ast->sample_size != st->codec->block_align) { + ast->dshow_block_align = st->codecpar->block_align; + if (ast->sample_size && st->codecpar->block_align && + ast->sample_size != st->codecpar->block_align) { av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, - st->codec->block_align); - ast->sample_size = st->codec->block_align; + st->codecpar->block_align); + ast->sample_size = st->codecpar->block_align; } /* 2-aligned * (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ @@ -732,28 +732,28 @@ static int avi_read_header(AVFormatContext *s) /* ADTS header is in extradata, AAC without header must be * stored as exact frames. Parser not needed and it will * fail. */ - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size) + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size) st->need_parsing = AVSTREAM_PARSE_NONE; /* AVI files with Xan DPCM audio (wrongly) declare PCM * audio in the header but have Axan as stream_code_tag. */ if (ast->handler == AV_RL32("Axan")) { - st->codec->codec_id = AV_CODEC_ID_XAN_DPCM; - st->codec->codec_tag = 0; + st->codecpar->codec_id = AV_CODEC_ID_XAN_DPCM; + st->codecpar->codec_tag = 0; } if (amv_file_format) { - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_AMV; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_AMV; ast->dshow_block_align = 0; } break; case AVMEDIA_TYPE_SUBTITLE: - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_PROBE; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_PROBE; break; default: - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_NONE; - st->codec->codec_tag = 0; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_tag = 0; avio_skip(pb, size); break; } @@ -895,8 +895,7 @@ static int read_gab2_sub(AVStream *st, AVPacket *pkt) ast->sub_ctx->pb = pb; if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) { ff_read_packet(ast->sub_ctx, &ast->sub_pkt); - *st->codec = *ast->sub_ctx->streams[0]->codec; - ast->sub_ctx->streams[0]->codec->extradata = NULL; + avcodec_parameters_copy(st->codecpar, ast->sub_ctx->streams[0]->codecpar); time_base = ast->sub_ctx->streams[0]->time_base; avpriv_set_pts_info(st, 64, time_base.num, time_base.den); } @@ -1022,8 +1021,8 @@ start_sync: AVIStream *ast1 = st1->priv_data; // workaround for broken small-file-bug402.avi if (d[2] == 'w' && d[3] == 'b' && n == 0 && - st->codec->codec_type == AVMEDIA_TYPE_VIDEO && - st1->codec->codec_type == AVMEDIA_TYPE_AUDIO && + st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + st1->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && ast->prefix == 'd' * 256 + 'c' && (d[2] * 256 + d[3] == ast1->prefix || !ast1->prefix_count)) { @@ -1230,8 +1229,8 @@ resync: pkt->flags |= AV_PKT_FLAG_KEY; if (size < 0) av_packet_unref(pkt); - } else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE && - !st->codec->codec_tag && read_gab2_sub(st, pkt)) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE && + !st->codecpar->codec_tag && read_gab2_sub(st, pkt)) { ast->frame_offset++; avi->stream_index = -1; ast->remaining = 0; @@ -1255,7 +1254,7 @@ resync: size); pkt->stream_index = avi->stream_index; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { AVIndexEntry *e; int index; assert(st->index_entries); @@ -1391,7 +1390,7 @@ static int check_stream_max_drift(AVFormatContext *s) max_dts = FFMAX(max_dts, dts); max_buffer = FFMAX(max_buffer, av_rescale(dts - min_dts, - st->codec->bit_rate, + st->codecpar->bit_rate, AV_TIME_BASE)); } } @@ -1555,7 +1554,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, if (st2->nb_index_entries <= 0) continue; -// assert(st2->codec->block_align); +// assert(st2->codecpar->block_align); assert((int64_t)st2->time_base.num * ast2->rate == (int64_t)st2->time_base.den * ast2->scale); index = av_index_search_timestamp(st2, diff --git a/libavformat/avienc.c b/libavformat/avienc.c index 9c2936af60..d89fab17e8 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -111,21 +111,21 @@ static int avi_write_counters(AVFormatContext *s, int riff_id) AVIContext *avi = s->priv_data; int n, au_byterate, au_ssize, au_scale, nb_frames = 0; int64_t file_size; - AVCodecContext *stream; + AVCodecParameters *par; file_size = avio_tell(pb); for (n = 0; n < s->nb_streams; n++) { AVIStream *avist = s->streams[n]->priv_data; assert(avist->frames_hdr_strm); - stream = s->streams[n]->codec; + par = s->streams[n]->codecpar; avio_seek(pb, avist->frames_hdr_strm, SEEK_SET); ff_parse_specific_params(s->streams[n], &au_byterate, &au_ssize, &au_scale); if (au_ssize == 0) avio_wl32(pb, avist->packet_count); else avio_wl32(pb, avist->audio_strm_length / au_ssize); - if (stream->codec_type == AVMEDIA_TYPE_VIDEO) + if (par->codec_type == AVMEDIA_TYPE_VIDEO) nb_frames = FFMAX(nb_frames, avist->packet_count); } if (riff_id == 1) { @@ -143,7 +143,7 @@ static int avi_write_header(AVFormatContext *s) AVIContext *avi = s->priv_data; AVIOContext *pb = s->pb; int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; - AVCodecContext *video_enc; + AVCodecParameters *video_par; AVStream *video_st = NULL; int64_t list1, list2, strh, strf; AVDictionaryEntry *t = NULL; @@ -169,12 +169,12 @@ static int avi_write_header(AVFormatContext *s) avio_wl32(pb, 14 * 4); bitrate = 0; - video_enc = NULL; + video_par = NULL; for (n = 0; n < s->nb_streams; n++) { - AVCodecContext *codec = s->streams[n]->codec; - bitrate += codec->bit_rate; - if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { - video_enc = codec; + AVCodecParameters *par = s->streams[n]->codecpar; + bitrate += par->bit_rate; + if (par->codec_type == AVMEDIA_TYPE_VIDEO) { + video_par = par; video_st = s->streams[n]; } } @@ -198,9 +198,9 @@ static int avi_write_header(AVFormatContext *s) avio_wl32(pb, 0); /* initial frame */ avio_wl32(pb, s->nb_streams); /* nb streams */ avio_wl32(pb, 1024 * 1024); /* suggested buffer size */ - if (video_enc) { - avio_wl32(pb, video_enc->width); - avio_wl32(pb, video_enc->height); + if (video_par) { + avio_wl32(pb, video_par->width); + avio_wl32(pb, video_par->height); } else { avio_wl32(pb, 0); avio_wl32(pb, 0); @@ -213,18 +213,18 @@ static int avi_write_header(AVFormatContext *s) /* stream list */ for (i = 0; i < n; i++) { AVStream *st = s->streams[i]; - AVCodecContext *enc = st->codec; + AVCodecParameters *par = st->codecpar; AVIStream *avist = st->priv_data; list2 = ff_start_tag(pb, "LIST"); ffio_wfourcc(pb, "strl"); /* stream generic header */ strh = ff_start_tag(pb, "strh"); - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_SUBTITLE: // XSUB subtitles behave like video tracks, other subtitles // are not (yet) supported. - if (enc->codec_id != AV_CODEC_ID_XSUB) { + if (par->codec_id != AV_CODEC_ID_XSUB) { av_log(s, AV_LOG_ERROR, "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n"); return AVERROR_PATCHWELCOME; @@ -242,9 +242,9 @@ static int avi_write_header(AVFormatContext *s) ffio_wfourcc(pb, "dats"); break; } - if (enc->codec_type == AVMEDIA_TYPE_VIDEO || - enc->codec_id == AV_CODEC_ID_XSUB) - avio_wl32(pb, enc->codec_tag); + if (par->codec_type == AVMEDIA_TYPE_VIDEO || + par->codec_id == AV_CODEC_ID_XSUB) + avio_wl32(pb, par->codec_tag); else avio_wl32(pb, 1); avio_wl32(pb, 0); /* flags */ @@ -268,32 +268,32 @@ static int avi_write_header(AVFormatContext *s) avio_wl32(pb, 0); /* length, XXX: filled later */ /* suggested buffer size */ //FIXME set at the end to largest chunk - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) + if (par->codec_type == AVMEDIA_TYPE_VIDEO) avio_wl32(pb, 1024 * 1024); - else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + else if (par->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl32(pb, 12 * 1024); else avio_wl32(pb, 0); avio_wl32(pb, -1); /* quality */ avio_wl32(pb, au_ssize); /* sample size */ avio_wl32(pb, 0); - avio_wl16(pb, enc->width); - avio_wl16(pb, enc->height); + avio_wl16(pb, par->width); + avio_wl16(pb, par->height); ff_end_tag(pb, strh); - if (enc->codec_type != AVMEDIA_TYPE_DATA) { + if (par->codec_type != AVMEDIA_TYPE_DATA) { strf = ff_start_tag(pb, "strf"); - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_SUBTITLE: /* XSUB subtitles behave like video tracks, other subtitles * are not (yet) supported. */ - if (enc->codec_id != AV_CODEC_ID_XSUB) + if (par->codec_id != AV_CODEC_ID_XSUB) break; case AVMEDIA_TYPE_VIDEO: - ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 0); + ff_put_bmp_header(pb, par, ff_codec_bmp_tags, 0); break; case AVMEDIA_TYPE_AUDIO: - if (ff_put_wav_header(pb, enc) < 0) + if (ff_put_wav_header(s, pb, par) < 0) return -1; break; default: @@ -320,7 +320,7 @@ static int avi_write_header(AVFormatContext *s) avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */ avio_w8(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ avio_wl32(pb, 0); /* nEntriesInUse (will fill out later on) */ - ffio_wfourcc(pb, avi_stream2fourcc(tag, i, enc->codec_type)); + ffio_wfourcc(pb, avi_stream2fourcc(tag, i, par->codec_type)); /* dwChunkId */ avio_wl64(pb, 0); /* dwReserved[3] */ // avio_wl32(pb, 0); /* Must be 0. */ @@ -329,13 +329,13 @@ static int avi_write_header(AVFormatContext *s) ff_end_tag(pb, avist->indexes.indx_start); } - if (enc->codec_type == AVMEDIA_TYPE_VIDEO && + if (par->codec_type == AVMEDIA_TYPE_VIDEO && st->sample_aspect_ratio.num > 0 && st->sample_aspect_ratio.den > 0) { int vprp = ff_start_tag(pb, "vprp"); AVRational dar = av_mul_q(st->sample_aspect_ratio, - (AVRational) { enc->width, - enc->height }); + (AVRational) { par->width, + par->height }); int num, den; av_reduce(&num, &den, dar.num, dar.den, 0xFFFF); @@ -343,18 +343,18 @@ static int avi_write_header(AVFormatContext *s) avio_wl32(pb, 0); // video standard = unknown // TODO: should be avg_frame_rate avio_wl32(pb, lrintf(1.0 / av_q2d(st->time_base))); - avio_wl32(pb, enc->width); - avio_wl32(pb, enc->height); + avio_wl32(pb, par->width); + avio_wl32(pb, par->height); avio_wl16(pb, den); avio_wl16(pb, num); - avio_wl32(pb, enc->width); - avio_wl32(pb, enc->height); + avio_wl32(pb, par->width); + avio_wl32(pb, par->height); avio_wl32(pb, 1); // progressive FIXME - avio_wl32(pb, enc->height); - avio_wl32(pb, enc->width); - avio_wl32(pb, enc->height); - avio_wl32(pb, enc->width); + avio_wl32(pb, par->height); + avio_wl32(pb, par->width); + avio_wl32(pb, par->height); + avio_wl32(pb, par->width); avio_wl32(pb, 0); avio_wl32(pb, 0); @@ -412,7 +412,7 @@ static int avi_write_ix(AVFormatContext *s) AVIStream *avist = s->streams[i]->priv_data; int64_t ix, pos; - avi_stream2fourcc(tag, i, s->streams[i]->codec->codec_type); + avi_stream2fourcc(tag, i, s->streams[i]->codecpar->codec_type); ix_tag[3] = '0' + i; /* Writing AVI OpenDML leaf index chunk */ @@ -489,7 +489,7 @@ static int avi_write_idx1(AVFormatContext *s) if (!empty) { avist = s->streams[stream_id]->priv_data; avi_stream2fourcc(tag, stream_id, - s->streams[stream_id]->codec->codec_type); + s->streams[stream_id]->codecpar->codec_type); ffio_wfourcc(pb, tag); avio_wl32(pb, ie->flags); avio_wl32(pb, ie->pos); @@ -513,9 +513,9 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) AVIContext *avi = s->priv_data; AVIOContext *pb = s->pb; AVIStream *avist = s->streams[stream_index]->priv_data; - AVCodecContext *enc = s->streams[stream_index]->codec; + AVCodecParameters *par = s->streams[stream_index]->codecpar; - while (enc->block_align == 0 && pkt->dts != AV_NOPTS_VALUE && + while (par->block_align == 0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avist->packet_count) { AVPacket empty_packet; @@ -540,10 +540,10 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi"); } - avi_stream2fourcc(tag, stream_index, enc->codec_type); + avi_stream2fourcc(tag, stream_index, par->codec_type); if (pkt->flags & AV_PKT_FLAG_KEY) flags = 0x10; - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + if (par->codec_type == AVMEDIA_TYPE_AUDIO) avist->audio_strm_length += size; if (s->pb->seekable) { @@ -604,15 +604,15 @@ static int avi_write_trailer(AVFormatContext *s) avio_skip(pb, 16); for (n = nb_frames = 0; n < s->nb_streams; n++) { - AVCodecContext *stream = s->streams[n]->codec; + AVCodecParameters *par = s->streams[n]->codecpar; AVIStream *avist = s->streams[n]->priv_data; - if (stream->codec_type == AVMEDIA_TYPE_VIDEO) { + if (par->codec_type == AVMEDIA_TYPE_VIDEO) { if (nb_frames < avist->packet_count) nb_frames = avist->packet_count; } else { - if (stream->codec_id == AV_CODEC_ID_MP2 || - stream->codec_id == AV_CODEC_ID_MP3) + if (par->codec_id == AV_CODEC_ID_MP2 || + par->codec_id == AV_CODEC_ID_MP3) nb_frames += avist->packet_count; } } diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 1a6a73f53e..b00f9bc42e 100644 --- a/libavformat/avisynth.c +++ b/libavformat/avisynth.c @@ -233,10 +233,10 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) AviSynthContext *avs = s->priv_data; int planar = 0; // 0: packed, 1: YUV, 2: Y8 - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->width = avs->vi->width; - st->codec->height = avs->vi->height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->width = avs->vi->width; + st->codecpar->height = avs->vi->height; st->time_base = (AVRational) { avs->vi->fps_denominator, avs->vi->fps_numerator }; @@ -249,38 +249,38 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) switch (avs->vi->pixel_type) { #ifdef USING_AVISYNTH case AVS_CS_YV24: - st->codec->pix_fmt = AV_PIX_FMT_YUV444P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV444P; + planar = 1; break; case AVS_CS_YV16: - st->codec->pix_fmt = AV_PIX_FMT_YUV422P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV422P; + planar = 1; break; case AVS_CS_YV411: - st->codec->pix_fmt = AV_PIX_FMT_YUV411P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV411P; + planar = 1; break; case AVS_CS_Y8: - st->codec->pix_fmt = AV_PIX_FMT_GRAY8; - planar = 2; + st->codecpar->format = AV_PIX_FMT_GRAY8; + planar = 2; break; #endif case AVS_CS_BGR24: - st->codec->pix_fmt = AV_PIX_FMT_BGR24; + st->codecpar->format = AV_PIX_FMT_BGR24; break; case AVS_CS_BGR32: - st->codec->pix_fmt = AV_PIX_FMT_RGB32; + st->codecpar->format = AV_PIX_FMT_RGB32; break; case AVS_CS_YUY2: - st->codec->pix_fmt = AV_PIX_FMT_YUYV422; + st->codecpar->format = AV_PIX_FMT_YUYV422; break; case AVS_CS_YV12: - st->codec->pix_fmt = AV_PIX_FMT_YUV420P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV420P; + planar = 1; break; case AVS_CS_I420: // Is this even used anywhere? - st->codec->pix_fmt = AV_PIX_FMT_YUV420P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV420P; + planar = 1; break; default: av_log(s, AV_LOG_ERROR, @@ -309,28 +309,28 @@ static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st) { AviSynthContext *avs = s->priv_data; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->sample_rate = avs->vi->audio_samples_per_second; - st->codec->channels = avs->vi->nchannels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->sample_rate = avs->vi->audio_samples_per_second; + st->codecpar->channels = avs->vi->nchannels; st->time_base = (AVRational) { 1, avs->vi->audio_samples_per_second }; st->duration = avs->vi->num_audio_samples; switch (avs->vi->sample_type) { case AVS_SAMPLE_INT8: - st->codec->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; break; case AVS_SAMPLE_INT16: - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; break; case AVS_SAMPLE_INT24: - st->codec->codec_id = AV_CODEC_ID_PCM_S24LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE; break; case AVS_SAMPLE_INT32: - st->codec->codec_id = AV_CODEC_ID_PCM_S32LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE; break; case AVS_SAMPLE_FLOAT: - st->codec->codec_id = AV_CODEC_ID_PCM_F32LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE; break; default: av_log(s, AV_LOG_ERROR, @@ -639,7 +639,7 @@ static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt) /* If either stream reaches EOF, try to read the other one before * giving up. */ avisynth_next_stream(s, &st, pkt, &discard); - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { ret = avisynth_read_packet_video(s, pkt, discard); if (ret == AVERROR_EOF && avs_has_audio(avs->vi)) { avisynth_next_stream(s, &st, pkt, &discard); @@ -681,7 +681,7 @@ static int avisynth_read_seek(AVFormatContext *s, int stream_index, samplerate = (AVRational) { avs->vi->audio_samples_per_second, 1 }; st = s->streams[stream_index]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { /* AviSynth frame counts are signed int. */ if ((timestamp >= avs->vi->num_frames) || (timestamp > INT_MAX) || diff --git a/libavformat/avs.c b/libavformat/avs.c index 74721b63c4..c825a3abc4 100644 --- a/libavformat/avs.c +++ b/libavformat/avs.c @@ -184,11 +184,11 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) avs->st_video = avformat_new_stream(s, NULL); if (!avs->st_video) return AVERROR(ENOMEM); - avs->st_video->codec->codec_type = AVMEDIA_TYPE_VIDEO; - avs->st_video->codec->codec_id = AV_CODEC_ID_AVS; - avs->st_video->codec->width = avs->width; - avs->st_video->codec->height = avs->height; - avs->st_video->codec->bits_per_coded_sample=avs->bits_per_sample; + avs->st_video->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + avs->st_video->codecpar->codec_id = AV_CODEC_ID_AVS; + avs->st_video->codecpar->width = avs->width; + avs->st_video->codecpar->height = avs->height; + avs->st_video->codecpar->bits_per_coded_sample=avs->bits_per_sample; avs->st_video->nb_frames = avs->nb_frames; avs->st_video->avg_frame_rate = (AVRational){avs->fps, 1}; } @@ -200,7 +200,7 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) avs->st_audio = avformat_new_stream(s, NULL); if (!avs->st_audio) return AVERROR(ENOMEM); - avs->st_audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; + avs->st_audio->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; } avs->remaining_audio_size = size - 4; size = avs_read_audio_packet(s, pkt); diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c index 135a3c491a..8ed9d4f290 100644 --- a/libavformat/bethsoftvid.c +++ b/libavformat/bethsoftvid.c @@ -113,13 +113,13 @@ static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt, "video packet"); } avpriv_set_pts_info(st, 64, 185, vid->sample_rate); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_BETHSOFTVID; - st->codec->width = vid->width; - st->codec->height = vid->height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_BETHSOFTVID; + st->codecpar->width = vid->width; + st->codecpar->height = vid->height; } st = s->streams[vid->video_index]; - npixels = st->codec->width * st->codec->height; + npixels = st->codecpar->width * st->codecpar->height; vidbuf_start = av_malloc(vidbuf_capacity = BUFFER_PADDING_SIZE); if(!vidbuf_start) @@ -240,13 +240,13 @@ static int vid_read_packet(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); vid->audio_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_U8; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->bits_per_coded_sample = 8; - st->codec->sample_rate = vid->sample_rate; - st->codec->bit_rate = 8 * st->codec->sample_rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->bits_per_coded_sample = 8; + st->codecpar->sample_rate = vid->sample_rate; + st->codecpar->bit_rate = 8 * st->codecpar->sample_rate; st->start_time = 0; avpriv_set_pts_info(st, 64, 1, vid->sample_rate); } diff --git a/libavformat/bfi.c b/libavformat/bfi.c index 19060e760f..99371bd4c0 100644 --- a/libavformat/bfi.c +++ b/libavformat/bfi.c @@ -75,34 +75,34 @@ static int bfi_read_header(AVFormatContext * s) avio_rl32(pb); fps = avio_rl32(pb); avio_skip(pb, 12); - vstream->codec->width = avio_rl32(pb); - vstream->codec->height = avio_rl32(pb); + vstream->codecpar->width = avio_rl32(pb); + vstream->codecpar->height = avio_rl32(pb); /*Load the palette to extradata */ avio_skip(pb, 8); - vstream->codec->extradata = av_malloc(768); - vstream->codec->extradata_size = 768; - avio_read(pb, vstream->codec->extradata, - vstream->codec->extradata_size); + vstream->codecpar->extradata = av_malloc(768); + vstream->codecpar->extradata_size = 768; + avio_read(pb, vstream->codecpar->extradata, + vstream->codecpar->extradata_size); - astream->codec->sample_rate = avio_rl32(pb); + astream->codecpar->sample_rate = avio_rl32(pb); /* Set up the video codec... */ avpriv_set_pts_info(vstream, 32, 1, fps); - vstream->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vstream->codec->codec_id = AV_CODEC_ID_BFI; - vstream->codec->pix_fmt = AV_PIX_FMT_PAL8; + vstream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vstream->codecpar->codec_id = AV_CODEC_ID_BFI; + vstream->codecpar->format = AV_PIX_FMT_PAL8; /* Set up the audio codec now... */ - astream->codec->codec_type = AVMEDIA_TYPE_AUDIO; - astream->codec->codec_id = AV_CODEC_ID_PCM_U8; - astream->codec->channels = 1; - astream->codec->channel_layout = AV_CH_LAYOUT_MONO; - astream->codec->bits_per_coded_sample = 8; - astream->codec->bit_rate = - astream->codec->sample_rate * astream->codec->bits_per_coded_sample; + astream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + astream->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + astream->codecpar->channels = 1; + astream->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + astream->codecpar->bits_per_coded_sample = 8; + astream->codecpar->bit_rate = + astream->codecpar->sample_rate * astream->codecpar->bits_per_coded_sample; avio_seek(pb, chunk_header - 3, SEEK_SET); - avpriv_set_pts_info(astream, 64, 1, astream->codec->sample_rate); + avpriv_set_pts_info(astream, 64, 1, astream->codecpar->sample_rate); return 0; } diff --git a/libavformat/bink.c b/libavformat/bink.c index 608de245d3..807e51b3d9 100644 --- a/libavformat/bink.c +++ b/libavformat/bink.c @@ -86,7 +86,7 @@ static int read_header(AVFormatContext *s) if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_tag = avio_rl32(pb); + vst->codecpar->codec_tag = avio_rl32(pb); bink->file_size = avio_rl32(pb) + 8; vst->duration = avio_rl32(pb); @@ -104,8 +104,8 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 4); - vst->codec->width = avio_rl32(pb); - vst->codec->height = avio_rl32(pb); + vst->codecpar->width = avio_rl32(pb); + vst->codecpar->height = avio_rl32(pb); fps_num = avio_rl32(pb); fps_den = avio_rl32(pb); @@ -118,13 +118,13 @@ static int read_header(AVFormatContext *s) avpriv_set_pts_info(vst, 64, fps_den, fps_num); vst->avg_frame_rate = av_inv_q(vst->time_base); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_BINKVIDEO; - vst->codec->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!vst->codec->extradata) + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_BINKVIDEO; + vst->codecpar->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!vst->codecpar->extradata) return AVERROR(ENOMEM); - vst->codec->extradata_size = 4; - avio_read(pb, vst->codec->extradata, 4); + vst->codecpar->extradata_size = 4; + avio_read(pb, vst->codecpar->extradata, 4); bink->num_audio_tracks = avio_rl32(pb); @@ -142,25 +142,25 @@ static int read_header(AVFormatContext *s) ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_tag = 0; - ast->codec->sample_rate = avio_rl16(pb); - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_tag = 0; + ast->codecpar->sample_rate = avio_rl16(pb); + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); flags = avio_rl16(pb); - ast->codec->codec_id = flags & BINK_AUD_USEDCT ? + ast->codecpar->codec_id = flags & BINK_AUD_USEDCT ? AV_CODEC_ID_BINKAUDIO_DCT : AV_CODEC_ID_BINKAUDIO_RDFT; if (flags & BINK_AUD_STEREO) { - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - ast->codec->channels = 1; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; + ast->codecpar->channels = 1; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - ast->codec->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!ast->codec->extradata) + ast->codecpar->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!ast->codecpar->extradata) return AVERROR(ENOMEM); - ast->codec->extradata_size = 4; - AV_WL32(ast->codec->extradata, vst->codec->codec_tag); + ast->codecpar->extradata_size = 4; + AV_WL32(ast->codecpar->extradata, vst->codecpar->codec_tag); } for (i = 0; i < bink->num_audio_tracks; i++) @@ -242,7 +242,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) (in bytes). We use this value to calcuate the audio PTS */ if (pkt->size >= 4) bink->audio_pts[bink->current_track -1] += - AV_RL32(pkt->data) / (2 * s->streams[bink->current_track]->codec->channels); + AV_RL32(pkt->data) / (2 * s->streams[bink->current_track]->codecpar->channels); return 0; } else { avio_skip(pb, audio_size); diff --git a/libavformat/bmv.c b/libavformat/bmv.c index b5572aff37..cfb4439edc 100644 --- a/libavformat/bmv.c +++ b/libavformat/bmv.c @@ -47,20 +47,20 @@ static int bmv_read_header(AVFormatContext *s) st = avformat_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_BMV_VIDEO; - st->codec->width = 640; - st->codec->height = 429; - st->codec->pix_fmt = AV_PIX_FMT_PAL8; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_BMV_VIDEO; + st->codecpar->width = 640; + st->codecpar->height = 429; + st->codecpar->format = AV_PIX_FMT_PAL8; avpriv_set_pts_info(st, 16, 1, 12); ast = avformat_new_stream(s, 0); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_BMV_AUDIO; - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; - ast->codec->sample_rate = 22050; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_BMV_AUDIO; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->sample_rate = 22050; avpriv_set_pts_info(ast, 16, 1, 22050); c->get_next = 1; diff --git a/libavformat/c93.c b/libavformat/c93.c index 3ae99fcfc9..c213b06255 100644 --- a/libavformat/c93.c +++ b/libavformat/c93.c @@ -83,10 +83,10 @@ static int read_header(AVFormatContext *s) if (!video) return AVERROR(ENOMEM); - video->codec->codec_type = AVMEDIA_TYPE_VIDEO; - video->codec->codec_id = AV_CODEC_ID_C93; - video->codec->width = 320; - video->codec->height = 192; + video->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + video->codecpar->codec_id = AV_CODEC_ID_C93; + video->codecpar->width = 320; + video->codecpar->height = 192; /* 4:3 320x200 with 8 empty lines */ video->sample_aspect_ratio = (AVRational) { 5, 6 }; avpriv_set_pts_info(video, 64, 2, 25); @@ -120,7 +120,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) c93->audio = avformat_new_stream(s, NULL); if (!c93->audio) return AVERROR(ENOMEM); - c93->audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; + c93->audio->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; } avio_skip(pb, 26); /* VOC header */ ret = ff_voc_get_packet(s, pkt, c93->audio, datasize - 26); 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 */ diff --git a/libavformat/cdg.c b/libavformat/cdg.c index 285bfaf35b..3f11286c30 100644 --- a/libavformat/cdg.c +++ b/libavformat/cdg.c @@ -39,8 +39,8 @@ static int read_header(AVFormatContext *s) if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_CDGRAPHICS; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_CDGRAPHICS; /// 75 sectors/sec * 4 packets/sector = 300 packets/sec avpriv_set_pts_info(vst, 32, 1, 300); diff --git a/libavformat/cdxl.c b/libavformat/cdxl.c index 366da4bf7c..26a5f8161c 100644 --- a/libavformat/cdxl.c +++ b/libavformat/cdxl.c @@ -99,17 +99,17 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 0; - st->codec->codec_id = AV_CODEC_ID_PCM_S8; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 0; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S8; if (cdxl->header[1] & 0x10) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - st->codec->sample_rate = cdxl->sample_rate; + st->codecpar->sample_rate = cdxl->sample_rate; st->start_time = 0; cdxl->audio_stream_index = st->index; avpriv_set_pts_info(st, 64, 1, cdxl->sample_rate); @@ -128,11 +128,11 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = 0; - st->codec->codec_id = AV_CODEC_ID_CDXL; - st->codec->width = width; - st->codec->height = height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = 0; + st->codecpar->codec_id = AV_CODEC_ID_CDXL; + st->codecpar->width = width; + st->codecpar->height = height; st->start_time = 0; cdxl->video_stream_index = st->index; if (cdxl->framerate) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 8c75d189b0..9c7e23aa8e 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -105,19 +105,19 @@ static int dash_write(void *opaque, uint8_t *buf, int buf_size) } // RFC 6381 -static void set_codec_str(AVFormatContext *s, AVCodecContext *codec, +static void set_codec_str(AVFormatContext *s, AVCodecParameters *par, char *str, int size) { const AVCodecTag *tags[2] = { NULL, NULL }; uint32_t tag; - if (codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (par->codec_type == AVMEDIA_TYPE_VIDEO) tags[0] = ff_codec_movvideo_tags; - else if (codec->codec_type == AVMEDIA_TYPE_AUDIO) + else if (par->codec_type == AVMEDIA_TYPE_AUDIO) tags[0] = ff_codec_movaudio_tags; else return; - tag = av_codec_get_tag(tags, codec->codec_id); + tag = av_codec_get_tag(tags, par->codec_id); if (!tag) return; if (size < 5) @@ -128,17 +128,17 @@ static void set_codec_str(AVFormatContext *s, AVCodecContext *codec, if (!strcmp(str, "mp4a") || !strcmp(str, "mp4v")) { uint32_t oti; tags[0] = ff_mp4_obj_type; - oti = av_codec_get_tag(tags, codec->codec_id); + oti = av_codec_get_tag(tags, par->codec_id); if (oti) av_strlcatf(str, size, ".%02x", oti); else return; if (tag == MKTAG('m', 'p', '4', 'a')) { - if (codec->extradata_size >= 2) { - int aot = codec->extradata[0] >> 3; + if (par->extradata_size >= 2) { + int aot = par->extradata[0] >> 3; if (aot == 31) - aot = ((AV_RB16(codec->extradata) >> 5) & 0x3f) + 32; + aot = ((AV_RB16(par->extradata) >> 5) & 0x3f) + 32; av_strlcatf(str, size, ".%d", aot); } } else if (tag == MKTAG('m', 'p', '4', 'v')) { @@ -147,8 +147,8 @@ static void set_codec_str(AVFormatContext *s, AVCodecContext *codec, } } else if (!strcmp(str, "avc1")) { uint8_t *tmpbuf = NULL; - uint8_t *extradata = codec->extradata; - int extradata_size = codec->extradata_size; + uint8_t *extradata = par->extradata; + int extradata_size = par->extradata_size; if (!extradata_size) return; if (extradata[0] != 1) { @@ -506,9 +506,9 @@ static int write_manifest(AVFormatContext *s, int final) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; OutputStream *os = &c->streams[i]; - if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) continue; - avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"video/mp4\" codecs=\"%s\"%s width=\"%d\" height=\"%d\">\n", i, os->codec_str, os->bandwidth_str, st->codec->width, st->codec->height); + avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"video/mp4\" codecs=\"%s\"%s width=\"%d\" height=\"%d\">\n", i, os->codec_str, os->bandwidth_str, st->codecpar->width, st->codecpar->height); output_segment_list(&c->streams[i], out, c); avio_printf(out, "\t\t\t</Representation>\n"); } @@ -519,10 +519,10 @@ static int write_manifest(AVFormatContext *s, int final) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; OutputStream *os = &c->streams[i]; - if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) continue; - avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"audio/mp4\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n", i, os->codec_str, os->bandwidth_str, st->codec->sample_rate); - avio_printf(out, "\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n", st->codec->channels); + avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"audio/mp4\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n", i, os->codec_str, os->bandwidth_str, st->codecpar->sample_rate); + avio_printf(out, "\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n", st->codecpar->channels); output_segment_list(&c->streams[i], out, c); avio_printf(out, "\t\t\t</Representation>\n"); } @@ -581,7 +581,7 @@ static int dash_write_header(AVFormatContext *s) AVDictionary *opts = NULL; char filename[1024]; - os->bit_rate = s->streams[i]->codec->bit_rate; + os->bit_rate = s->streams[i]->codecpar->bit_rate; if (os->bit_rate) { snprintf(os->bandwidth_str, sizeof(os->bandwidth_str), " bandwidth=\"%d\"", os->bit_rate); @@ -611,7 +611,7 @@ static int dash_write_header(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } - avcodec_copy_context(st->codec, s->streams[i]->codec); + avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; ctx->avoid_negative_ts = s->avoid_negative_ts; @@ -651,12 +651,12 @@ static int dash_write_header(AVFormatContext *s) // already before being handed to this muxer, so we don't have mismatches // between the MPD and the actual segments. s->avoid_negative_ts = ctx->avoid_negative_ts; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) c->has_video = 1; - else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) c->has_audio = 1; - set_codec_str(s, st->codec, os->codec_str, sizeof(os->codec_str)); + set_codec_str(s, st->codecpar, os->codec_str, sizeof(os->codec_str)); os->first_pts = AV_NOPTS_VALUE; os->max_pts = AV_NOPTS_VALUE; os->last_dts = AV_NOPTS_VALUE; @@ -745,24 +745,24 @@ static void find_index_range(AVFormatContext *s, const char *full_path, } static int update_stream_extradata(AVFormatContext *s, OutputStream *os, - AVCodecContext *codec) + AVCodecParameters *par) { uint8_t *extradata; - if (os->ctx->streams[0]->codec->extradata_size || !codec->extradata_size) + if (os->ctx->streams[0]->codecpar->extradata_size || !par->extradata_size) return 0; - extradata = av_malloc(codec->extradata_size); + extradata = av_malloc(par->extradata_size); if (!extradata) return AVERROR(ENOMEM); - memcpy(extradata, codec->extradata, codec->extradata_size); + memcpy(extradata, par->extradata, par->extradata_size); - os->ctx->streams[0]->codec->extradata = extradata; - os->ctx->streams[0]->codec->extradata_size = codec->extradata_size; + os->ctx->streams[0]->codecpar->extradata = extradata; + os->ctx->streams[0]->codecpar->extradata_size = par->extradata_size; - set_codec_str(s, codec, os->codec_str, sizeof(os->codec_str)); + set_codec_str(s, par, os->codec_str, sizeof(os->codec_str)); return 0; } @@ -788,7 +788,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream) // Flush all audio streams as well, in sync with video keyframes, // but not the other video streams. if (stream >= 0 && i != stream) { - if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_AUDIO) + if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) continue; // Make sure we don't flush audio streams multiple times, when // all video streams are flushed one at a time. @@ -867,7 +867,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) int64_t seg_end_duration = (os->segment_index) * (int64_t) c->min_seg_duration; int ret; - ret = update_stream_extradata(s, os, st->codec); + ret = update_stream_extradata(s, os, st->codecpar); if (ret < 0) return ret; @@ -892,7 +892,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) if (os->first_pts == AV_NOPTS_VALUE) os->first_pts = pkt->pts; - if ((!c->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && + if ((!c->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && pkt->flags & AV_PKT_FLAG_KEY && os->packets_written && av_compare_ts(pkt->pts - os->first_pts, st->time_base, seg_end_duration, AV_TIME_BASE_Q) >= 0) { diff --git a/libavformat/dauddec.c b/libavformat/dauddec.c index 1855e84aae..98f8a5749d 100644 --- a/libavformat/dauddec.c +++ b/libavformat/dauddec.c @@ -26,15 +26,15 @@ static int daud_header(AVFormatContext *s) { AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S24DAUD; - st->codec->codec_tag = MKTAG('d', 'a', 'u', 'd'); - st->codec->channels = 6; - st->codec->channel_layout = AV_CH_LAYOUT_5POINT1; - st->codec->sample_rate = 96000; - st->codec->bit_rate = 3 * 6 * 96000 * 8; - st->codec->block_align = 3 * 6; - st->codec->bits_per_coded_sample = 24; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24DAUD; + st->codecpar->codec_tag = MKTAG('d', 'a', 'u', 'd'); + st->codecpar->channels = 6; + st->codecpar->channel_layout = AV_CH_LAYOUT_5POINT1; + st->codecpar->sample_rate = 96000; + st->codecpar->bit_rate = 3 * 6 * 96000 * 8; + st->codecpar->block_align = 3 * 6; + st->codecpar->bits_per_coded_sample = 24; return 0; } diff --git a/libavformat/daudenc.c b/libavformat/daudenc.c index 416e895395..93608e3319 100644 --- a/libavformat/daudenc.c +++ b/libavformat/daudenc.c @@ -23,8 +23,8 @@ static int daud_write_header(struct AVFormatContext *s) { - AVCodecContext *codec = s->streams[0]->codec; - if (codec->channels!=6 || codec->sample_rate!=96000) + AVCodecParameters *par = s->streams[0]->codecpar; + if (par->channels!=6 || par->sample_rate!=96000) return -1; return 0; } diff --git a/libavformat/dfa.c b/libavformat/dfa.c index 03dca4f5c3..cecf6b69c2 100644 --- a/libavformat/dfa.c +++ b/libavformat/dfa.c @@ -51,10 +51,10 @@ static int dfa_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DFA; - st->codec->width = avio_rl16(pb); - st->codec->height = avio_rl16(pb); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DFA; + st->codecpar->width = avio_rl16(pb); + st->codecpar->height = avio_rl16(pb); mspf = avio_rl32(pb); if (!mspf) { av_log(s, AV_LOG_WARNING, "Zero FPS reported, defaulting to 10\n"); diff --git a/libavformat/dsicin.c b/libavformat/dsicin.c index 612289fd4f..fa5943dfe2 100644 --- a/libavformat/dsicin.c +++ b/libavformat/dsicin.c @@ -115,11 +115,11 @@ static int cin_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 32, 1, 12); cin->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DSICINVIDEO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = hdr->video_frame_width; - st->codec->height = hdr->video_frame_height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DSICINVIDEO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = hdr->video_frame_width; + st->codecpar->height = hdr->video_frame_height; /* initialize the audio decoder stream */ st = avformat_new_stream(s, NULL); @@ -128,14 +128,14 @@ static int cin_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 32, 1, 22050); cin->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_DSICINAUDIO; - st->codec->codec_tag = 0; /* no tag */ - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = 22050; - st->codec->bits_per_coded_sample = 8; - st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_coded_sample * st->codec->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_DSICINAUDIO; + st->codecpar->codec_tag = 0; /* no tag */ + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = 22050; + st->codecpar->bits_per_coded_sample = 8; + st->codecpar->bit_rate = st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample * st->codecpar->channels; return 0; } diff --git a/libavformat/dss.c b/libavformat/dss.c index e9610dd1a1..a9b2ebf2d8 100644 --- a/libavformat/dss.c +++ b/libavformat/dss.c @@ -141,22 +141,22 @@ static int dss_read_header(AVFormatContext *s) ctx->audio_codec = avio_r8(pb); if (ctx->audio_codec == DSS_ACODEC_DSS_SP) { - st->codec->codec_id = AV_CODEC_ID_DSS_SP; - st->codec->sample_rate = 12000; + st->codecpar->codec_id = AV_CODEC_ID_DSS_SP; + st->codecpar->sample_rate = 12000; } else if (ctx->audio_codec == DSS_ACODEC_G723_1) { - st->codec->codec_id = AV_CODEC_ID_G723_1; - st->codec->sample_rate = 8000; + st->codecpar->codec_id = AV_CODEC_ID_G723_1; + st->codecpar->sample_rate = 8000; } else { avpriv_request_sample(s, "Support for codec %x in DSS", ctx->audio_codec); return AVERROR_PATCHWELCOME; } - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->channels = 1; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; - 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; /* Jump over header */ diff --git a/libavformat/dump.c b/libavformat/dump.c index 345d2a95fc..d7dee9d570 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -400,8 +400,22 @@ static void dump_stream_format(AVFormatContext *ic, int i, int flags = (is_output ? ic->oformat->flags : ic->iformat->flags); AVStream *st = ic->streams[i]; AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); + AVCodecContext *avctx; + int ret; + + avctx = avcodec_alloc_context3(NULL); + if (!avctx) + return; + + ret = avcodec_parameters_to_context(avctx, st->codecpar); + if (ret < 0) { + avcodec_free_context(&avctx); + return; + } + + avcodec_string(buf, sizeof(buf), avctx, is_output); + avcodec_free_context(&avctx); - avcodec_string(buf, sizeof(buf), st->codec, is_output); av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i); /* the pid is an important information, so we display it */ @@ -414,31 +428,27 @@ static void dump_stream_format(AVFormatContext *ic, int i, st->time_base.num, st->time_base.den); av_log(NULL, AV_LOG_INFO, ": %s", buf); - if (st->sample_aspect_ratio.num && // default - av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) { + if (st->sample_aspect_ratio.num) { AVRational display_aspect_ratio; av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, - st->codec->width * st->sample_aspect_ratio.num, - st->codec->height * st->sample_aspect_ratio.den, + st->codecpar->width * st->sample_aspect_ratio.num, + st->codecpar->height * st->sample_aspect_ratio.den, 1024 * 1024); av_log(NULL, AV_LOG_INFO, ", PAR %d:%d DAR %d:%d", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den); } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { int fps = st->avg_frame_rate.den && st->avg_frame_rate.num; int tbn = st->time_base.den && st->time_base.num; - int tbc = st->codec->time_base.den && st->codec->time_base.num; - if (fps || tbn || tbc) + if (fps || tbn) av_log(NULL, AV_LOG_INFO, "\n "); if (fps) - print_fps(av_q2d(st->avg_frame_rate), tbn || tbc ? "fps, " : "fps"); + print_fps(av_q2d(st->avg_frame_rate), tbn ? "fps, " : "fps"); if (tbn) - print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn"); - if (tbc) - print_fps(1 / av_q2d(st->codec->time_base), "tbc"); + print_fps(1 / av_q2d(st->time_base), "tbn"); } if (st->disposition & AV_DISPOSITION_DEFAULT) diff --git a/libavformat/dv.c b/libavformat/dv.c index 1ba8698d20..f7df279bdc 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -245,8 +245,8 @@ static int dv_extract_audio_info(DVDemuxContext *c, uint8_t *frame) if (!c->ast[i]) break; avpriv_set_pts_info(c->ast[i], 64, 1, 30000); - c->ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO; - c->ast[i]->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + c->ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; av_init_packet(&c->audio_pkt[i]); c->audio_pkt[i].size = 0; @@ -254,10 +254,10 @@ static int dv_extract_audio_info(DVDemuxContext *c, uint8_t *frame) c->audio_pkt[i].stream_index = c->ast[i]->index; c->audio_pkt[i].flags |= AV_PKT_FLAG_KEY; } - c->ast[i]->codec->sample_rate = dv_audio_frequency[freq]; - c->ast[i]->codec->channels = 2; - c->ast[i]->codec->channel_layout = AV_CH_LAYOUT_STEREO; - c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16; + c->ast[i]->codecpar->sample_rate = dv_audio_frequency[freq]; + c->ast[i]->codecpar->channels = 2; + c->ast[i]->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + c->ast[i]->codecpar->bit_rate = 2 * dv_audio_frequency[freq] * 16; c->ast[i]->start_time = 0; } c->ach = i; @@ -268,21 +268,20 @@ static int dv_extract_audio_info(DVDemuxContext *c, uint8_t *frame) static int dv_extract_video_info(DVDemuxContext *c, uint8_t *frame) { const uint8_t *vsc_pack; - AVCodecContext *avctx; int apt, is16_9; int size = 0; if (c->sys) { - avctx = c->vst->codec; + AVCodecParameters *par = c->vst->codecpar; avpriv_set_pts_info(c->vst, 64, c->sys->time_base.num, c->sys->time_base.den); c->vst->avg_frame_rate = av_inv_q(c->vst->time_base); - if (!avctx->width) { - avctx->width = c->sys->width; - avctx->height = c->sys->height; + if (!par->width) { + par->width = c->sys->width; + par->height = c->sys->height; } - avctx->pix_fmt = c->sys->pix_fmt; + par->format = c->sys->pix_fmt; /* finding out SAR is a little bit messy */ vsc_pack = dv_extract_pack(frame, dv_video_control); @@ -290,9 +289,9 @@ static int dv_extract_video_info(DVDemuxContext *c, uint8_t *frame) is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07))); c->vst->sample_aspect_ratio = c->sys->sar[is16_9]; - avctx->bit_rate = av_rescale_q(c->sys->frame_size, - (AVRational) { 8, 1 }, - c->sys->time_base); + par->bit_rate = av_rescale_q(c->sys->frame_size, + (AVRational) { 8, 1 }, + c->sys->time_base); size = c->sys->frame_size; } return size; @@ -315,9 +314,9 @@ DVDemuxContext *avpriv_dv_init_demux(AVFormatContext *s) } c->fctx = s; - c->vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - c->vst->codec->codec_id = AV_CODEC_ID_DVVIDEO; - c->vst->codec->bit_rate = 25000000; + c->vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + c->vst->codecpar->codec_id = AV_CODEC_ID_DVVIDEO; + c->vst->codecpar->bit_rate = 25000000; c->vst->start_time = 0; return c; @@ -358,7 +357,7 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, for (i = 0; i < c->ach; i++) { c->audio_pkt[i].size = size; c->audio_pkt[i].pts = c->abytes * 30000 * 8 / - c->ast[i]->codec->bit_rate; + c->ast[i]->codecpar->bit_rate; ppcm[i] = c->audio_buf[i]; } if (c->ach) @@ -395,8 +394,8 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c, int64_t timestamp, int flags) { // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk) - const AVDVProfile *sys = av_dv_codec_profile(c->vst->codec->width, c->vst->codec->height, - c->vst->codec->pix_fmt); + const AVDVProfile *sys = av_dv_codec_profile(c->vst->codecpar->width, c->vst->codecpar->height, + c->vst->codecpar->format); int64_t offset; int64_t size = avio_size(s->pb) - s->internal->data_offset; int64_t max_offset = ((size - 1) / sys->frame_size) * sys->frame_size; @@ -416,7 +415,7 @@ void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset) c->frames = frame_offset; if (c->ach) c->abytes = av_rescale_q(c->frames, c->sys->time_base, - (AVRational) { 8, c->ast[0]->codec->bit_rate }); + (AVRational) { 8, c->ast[0]->codecpar->bit_rate }); c->audio_pkt[0].size = c->audio_pkt[1].size = 0; c->audio_pkt[2].size = c->audio_pkt[3].size = 0; diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c index 106cba4c34..094ddc90a9 100644 --- a/libavformat/dvenc.c +++ b/libavformat/dvenc.c @@ -236,7 +236,8 @@ static void dv_inject_metadata(DVMuxContext *c, uint8_t* frame) * The following 3 functions constitute our interface to the world */ -static int dv_assemble_frame(DVMuxContext *c, AVStream* st, +static int dv_assemble_frame(AVFormatContext *s, + DVMuxContext *c, AVStream* st, uint8_t* data, int data_size, uint8_t** frame) { int i, reqasize; @@ -244,13 +245,13 @@ static int dv_assemble_frame(DVMuxContext *c, AVStream* st, *frame = &c->frame_buf[0]; reqasize = 4 * dv_audio_frame_size(c->sys, c->frames); - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: /* FIXME: we have to have more sensible approach than this one */ if (c->has_video) - av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames); + av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames); if (data_size != c->sys->frame_size) { - av_log(st->codec, AV_LOG_ERROR, "Unexpected frame size, %d != %d\n", + av_log(s, AV_LOG_ERROR, "Unexpected frame size, %d != %d\n", data_size, c->sys->frame_size); return AVERROR(ENOSYS); } @@ -263,7 +264,7 @@ static int dv_assemble_frame(DVMuxContext *c, AVStream* st, /* FIXME: we have to have more sensible approach than this one */ if (av_fifo_size(c->audio_data[i]) + data_size >= 100*MAX_AUDIO_FRAME_SIZE) - av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames); + av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames); av_fifo_generic_write(c->audio_data[i], data, data_size, NULL); /* Let us see if we've got enough audio for one DV frame. */ @@ -310,7 +311,7 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s) /* We have to sort out where audio and where video stream is */ for (i=0; i<s->nb_streams; i++) { - switch (s->streams[i]->codec->codec_type) { + switch (s->streams[i]->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: if (vst) return NULL; vst = s->streams[i]; @@ -325,15 +326,15 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s) } /* Some checks -- DV format is very picky about its incoming streams */ - if (!vst || vst->codec->codec_id != AV_CODEC_ID_DVVIDEO) + if (!vst || vst->codecpar->codec_id != AV_CODEC_ID_DVVIDEO) goto bail_out; for (i=0; i<c->n_ast; i++) { - if (c->ast[i] && (c->ast[i]->codec->codec_id != AV_CODEC_ID_PCM_S16LE || - c->ast[i]->codec->sample_rate != 48000 || - c->ast[i]->codec->channels != 2)) + if (c->ast[i] && (c->ast[i]->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE || + c->ast[i]->codecpar->sample_rate != 48000 || + c->ast[i]->codecpar->channels != 2)) goto bail_out; } - c->sys = av_dv_codec_profile(vst->codec->width, vst->codec->height, vst->codec->pix_fmt); + c->sys = av_dv_codec_profile(vst->codecpar->width, vst->codecpar->height, vst->codecpar->format); if (!c->sys) goto bail_out; @@ -389,7 +390,7 @@ static int dv_write_packet(struct AVFormatContext *s, AVPacket *pkt) uint8_t* frame; int fsize; - fsize = dv_assemble_frame(s->priv_data, s->streams[pkt->stream_index], + fsize = dv_assemble_frame(s, s->priv_data, s->streams[pkt->stream_index], pkt->data, pkt->size, &frame); if (fsize > 0) { avio_write(s->pb, frame, fsize); diff --git a/libavformat/dxa.c b/libavformat/dxa.c index 7d04e7bfaa..a86b90e7d5 100644 --- a/libavformat/dxa.c +++ b/libavformat/dxa.c @@ -106,11 +106,11 @@ static int dxa_read_header(AVFormatContext *s) ast = avformat_new_stream(s, NULL); if (!ast) return -1; - ret = ff_get_wav_header(s, pb, ast->codec, fsize); + ret = ff_get_wav_header(s, pb, ast->codecpar, fsize); if (ret < 0) return ret; - if (ast->codec->sample_rate > 0) - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + if (ast->codecpar->sample_rate > 0) + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); // find 'data' chunk while(avio_tell(pb) < c->vidpos && !pb->eof_reached){ tag = avio_rl32(pb); @@ -119,18 +119,18 @@ static int dxa_read_header(AVFormatContext *s) avio_skip(pb, fsize); } c->bpc = (fsize + c->frames - 1) / c->frames; - if(ast->codec->block_align) - c->bpc = ((c->bpc + ast->codec->block_align - 1) / ast->codec->block_align) * ast->codec->block_align; + if(ast->codecpar->block_align) + c->bpc = ((c->bpc + ast->codecpar->block_align - 1) / ast->codecpar->block_align) * ast->codecpar->block_align; c->bytes_left = fsize; c->wavpos = avio_tell(pb); avio_seek(pb, c->vidpos, SEEK_SET); } /* now we are ready: build format streams */ - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DXA; - st->codec->width = w; - st->codec->height = h; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DXA; + st->codecpar->width = w; + st->codecpar->height = h; av_reduce(&den, &num, den, num, (1UL<<31)-1); avpriv_set_pts_info(st, 33, num, den); /* flags & 0x80 means that image is interlaced, @@ -138,7 +138,7 @@ static int dxa_read_header(AVFormatContext *s) * either way set true height */ if(flags & 0xC0){ - st->codec->height >>= 1; + st->codecpar->height >>= 1; } c->readvid = !c->has_sound; c->vidpos = avio_tell(pb); diff --git a/libavformat/eacdata.c b/libavformat/eacdata.c index c81dec847d..d3f27a44c2 100644 --- a/libavformat/eacdata.c +++ b/libavformat/eacdata.c @@ -68,11 +68,11 @@ static int cdata_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->codec_id = AV_CODEC_ID_ADPCM_EA_XAS; - st->codec->channels = cdata->channels; - st->codec->sample_rate = sample_rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_EA_XAS; + st->codecpar->channels = cdata->channels; + st->codecpar->sample_rate = sample_rate; avpriv_set_pts_info(st, 64, 1, sample_rate); cdata->audio_pts = 0; diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c index b3855b69a5..07d1efceac 100644 --- a/libavformat/electronicarts.c +++ b/libavformat/electronicarts.c @@ -462,11 +462,11 @@ static int ea_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); ea->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = ea->video_codec; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = ea->width; - st->codec->height = ea->height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = ea->video_codec; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = ea->width; + st->codecpar->height = ea->height; avpriv_set_pts_info(st, 33, ea->time_base.num, ea->time_base.den); st->avg_frame_rate = (AVRational) { ea->time_base.den, ea->time_base.num }; @@ -497,17 +497,17 @@ static int ea_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 33, 1, ea->sample_rate); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = ea->audio_codec; - st->codec->codec_tag = 0; /* no tag */ - st->codec->channels = ea->num_channels; - st->codec->sample_rate = ea->sample_rate; - st->codec->bits_per_coded_sample = ea->bytes * 8; - st->codec->bit_rate = st->codec->channels * - st->codec->sample_rate * - st->codec->bits_per_coded_sample / 4; - st->codec->block_align = st->codec->channels * - st->codec->bits_per_coded_sample; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = ea->audio_codec; + st->codecpar->codec_tag = 0; /* no tag */ + st->codecpar->channels = ea->num_channels; + st->codecpar->sample_rate = ea->sample_rate; + st->codecpar->bits_per_coded_sample = ea->bytes * 8; + st->codecpar->bit_rate = st->codecpar->channels * + st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample / 4; + st->codecpar->block_align = st->codecpar->channels * + st->codecpar->bits_per_coded_sample; ea->audio_stream_index = st->index; st->start_time = 0; } diff --git a/libavformat/ffmetadec.c b/libavformat/ffmetadec.c index 7dbf7ed35d..42fc98f4bd 100644 --- a/libavformat/ffmetadec.c +++ b/libavformat/ffmetadec.c @@ -137,8 +137,8 @@ static int read_header(AVFormatContext *s) if (!st) return -1; - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_FFMETADATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_FFMETADATA; m = &st->metadata; } else if (!memcmp(line, ID_CHAPTER, strlen(ID_CHAPTER))) { diff --git a/libavformat/filmstripdec.c b/libavformat/filmstripdec.c index c82656e72f..b029d8023e 100644 --- a/libavformat/filmstripdec.c +++ b/libavformat/filmstripdec.c @@ -60,12 +60,12 @@ static int read_header(AVFormatContext *s) } avio_skip(pb, 2); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->pix_fmt = AV_PIX_FMT_RGBA; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = avio_rb16(pb); - st->codec->height = avio_rb16(pb); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->format = AV_PIX_FMT_RGBA; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = avio_rb16(pb); + st->codecpar->height = avio_rb16(pb); film->leading = avio_rb16(pb); avpriv_set_pts_info(st, 64, 1, avio_rb16(pb)); @@ -82,9 +82,9 @@ static int read_packet(AVFormatContext *s, if (s->pb->eof_reached) return AVERROR(EIO); - pkt->dts = avio_tell(s->pb) / (st->codec->width * (st->codec->height + film->leading) * 4); - pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4); - avio_skip(s->pb, st->codec->width * (int64_t) film->leading * 4); + pkt->dts = avio_tell(s->pb) / (st->codecpar->width * (st->codecpar->height + film->leading) * 4); + pkt->size = av_get_packet(s->pb, pkt, st->codecpar->width * st->codecpar->height * 4); + avio_skip(s->pb, st->codecpar->width * (int64_t) film->leading * 4); if (pkt->size < 0) return pkt->size; pkt->flags |= AV_PKT_FLAG_KEY; @@ -94,7 +94,7 @@ static int read_packet(AVFormatContext *s, static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { AVStream *st = s->streams[stream_index]; - if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET) < 0) + if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codecpar->width * st->codecpar->height * 4, SEEK_SET) < 0) return -1; return 0; } diff --git a/libavformat/filmstripenc.c b/libavformat/filmstripenc.c index 0794b18c50..5a09691a70 100644 --- a/libavformat/filmstripenc.c +++ b/libavformat/filmstripenc.c @@ -35,7 +35,7 @@ typedef struct FilmstripMuxContext { static int write_header(AVFormatContext *s) { - if (s->streams[0]->codec->pix_fmt != AV_PIX_FMT_RGBA) { + if (s->streams[0]->codecpar->format != AV_PIX_FMT_RGBA) { av_log(s, AV_LOG_ERROR, "only AV_PIX_FMT_RGBA is supported\n"); return AVERROR_INVALIDDATA; } @@ -61,8 +61,8 @@ static int write_trailer(AVFormatContext *s) avio_wb32(pb, film->nb_frames); avio_wb16(pb, 0); // packing method avio_wb16(pb, 0); // reserved - avio_wb16(pb, st->codec->width); - avio_wb16(pb, st->codec->height); + avio_wb16(pb, st->codecpar->width); + avio_wb16(pb, st->codecpar->height); avio_wb16(pb, 0); // leading // TODO: should be avg_frame_rate avio_wb16(pb, 1/av_q2d(st->time_base)); diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c index a6b55379f8..1381a28b80 100644 --- a/libavformat/flac_picture.c +++ b/libavformat/flac_picture.c @@ -131,10 +131,10 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size) st->attached_pic.flags |= AV_PKT_FLAG_KEY; st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = id; - st->codec->width = width; - st->codec->height = height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; + st->codecpar->width = width; + st->codecpar->height = height; av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0); if (desc) av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL); diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 494bb095cc..7a75527333 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -36,8 +36,8 @@ static int flac_read_header(AVFormatContext *s) AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_FLAC; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_FLAC; st->need_parsing = AVSTREAM_PARSE_FULL; /* the parameters will be extracted from the compressed bitstream */ @@ -88,14 +88,14 @@ static int flac_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } found_streaminfo = 1; - st->codec->extradata = buffer; - st->codec->extradata_size = metadata_size; + st->codecpar->extradata = buffer; + st->codecpar->extradata_size = metadata_size; buffer = NULL; /* get sample rate and sample count from STREAMINFO header; * other parameters will be extracted by the parser */ - samplerate = AV_RB24(st->codec->extradata + 10) >> 4; - samples = (AV_RB64(st->codec->extradata + 13) >> 24) & ((1ULL << 36) - 1); + samplerate = AV_RB24(st->codecpar->extradata + 10) >> 4; + samples = (AV_RB64(st->codecpar->extradata + 13) >> 24) & ((1ULL << 36) - 1); /* set time base and duration */ if (samplerate > 0) { @@ -159,7 +159,7 @@ static int flac_read_header(AVFormatContext *s) av_log(s, AV_LOG_WARNING, "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n"); } else { - st->codec->channel_layout = mask; + st->codecpar->channel_layout = mask; av_dict_set(&s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", NULL, 0); } } diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index a686826543..3cee668afc 100644 --- a/libavformat/flacenc.c +++ b/libavformat/flacenc.c @@ -77,21 +77,21 @@ static int flac_write_block_comment(AVIOContext *pb, AVDictionary **m, static int flac_write_header(struct AVFormatContext *s) { int ret; - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; FlacMuxerContext *c = s->priv_data; if (!c->write_header) return 0; - ret = ff_flac_write_header(s->pb, codec->extradata, - codec->extradata_size, 0); + ret = ff_flac_write_header(s->pb, par->extradata, + par->extradata_size, 0); if (ret) return ret; /* add the channel layout tag */ - if (codec->channel_layout && - !(codec->channel_layout & ~0x3ffffULL) && - !ff_flac_is_native_layout(codec->channel_layout)) { + if (par->channel_layout && + !(par->channel_layout & ~0x3ffffULL) && + !ff_flac_is_native_layout(par->channel_layout)) { AVDictionaryEntry *chmask = av_dict_get(s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", NULL, 0); @@ -100,7 +100,7 @@ static int flac_write_header(struct AVFormatContext *s) "already present, this muxer will not overwrite it.\n"); } else { uint8_t buf[32]; - snprintf(buf, sizeof(buf), "0x%"PRIx64, codec->channel_layout); + snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout); av_dict_set(&s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0); } } @@ -125,7 +125,7 @@ static int flac_write_trailer(struct AVFormatContext *s) int64_t file_size; FlacMuxerContext *c = s->priv_data; uint8_t *streaminfo = c->streaminfo ? c->streaminfo : - s->streams[0]->codec->extradata; + s->streams[0]->codecpar->extradata; if (!c->write_header || !streaminfo) return 0; diff --git a/libavformat/flic.c b/libavformat/flic.c index 277e12b20c..cb88b67521 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -109,25 +109,25 @@ static int flic_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); flic->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_FLIC; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = AV_RL16(&header[0x08]); - st->codec->height = AV_RL16(&header[0x0A]); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_FLIC; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = AV_RL16(&header[0x08]); + st->codecpar->height = AV_RL16(&header[0x0A]); - if (!st->codec->width || !st->codec->height) { + if (!st->codecpar->width || !st->codecpar->height) { /* Ugly hack needed for the following sample: */ /* http://samples.libav.org/fli-flc/fli-bugs/specular.flc */ av_log(s, AV_LOG_WARNING, "File with no specified width/height. Trying 640x480.\n"); - st->codec->width = 640; - st->codec->height = 480; + st->codecpar->width = 640; + st->codecpar->height = 480; } /* send over the whole 128-byte FLIC header */ - st->codec->extradata_size = FLIC_HEADER_SIZE; - st->codec->extradata = av_malloc(FLIC_HEADER_SIZE); - memcpy(st->codec->extradata, header, FLIC_HEADER_SIZE); + st->codecpar->extradata_size = FLIC_HEADER_SIZE; + st->codecpar->extradata = av_malloc(FLIC_HEADER_SIZE); + memcpy(st->codecpar->extradata, header, FLIC_HEADER_SIZE); /* peek at the preamble to detect TFTD videos - they seem to always start with an audio chunk */ if (avio_read(pb, preamble, FLIC_PREAMBLE_SIZE) != FLIC_PREAMBLE_SIZE) { @@ -152,22 +152,22 @@ static int flic_read_header(AVFormatContext *s) flic->audio_stream_index = ast->index; /* all audio frames are the same size, so use the size of the first chunk for block_align */ - ast->codec->block_align = AV_RL32(&preamble[0]); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_U8; - ast->codec->codec_tag = 0; - ast->codec->sample_rate = FLIC_TFTD_SAMPLE_RATE; - ast->codec->channels = 1; - ast->codec->sample_fmt = AV_SAMPLE_FMT_U8; - ast->codec->bit_rate = st->codec->sample_rate * 8; - ast->codec->bits_per_coded_sample = 8; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; - ast->codec->extradata_size = 0; + ast->codecpar->block_align = AV_RL32(&preamble[0]); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + ast->codecpar->codec_tag = 0; + ast->codecpar->sample_rate = FLIC_TFTD_SAMPLE_RATE; + ast->codecpar->channels = 1; + ast->codecpar->format = AV_SAMPLE_FMT_U8; + ast->codecpar->bit_rate = st->codecpar->sample_rate * 8; + ast->codecpar->bits_per_coded_sample = 8; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + ast->codecpar->extradata_size = 0; /* Since the header information is incorrect we have to figure out the * framerate using block_align and the fact that the audio is 22050 Hz. * We usually have two cases: 2205 -> 10 fps and 1470 -> 15 fps */ - avpriv_set_pts_info(st, 64, ast->codec->block_align, FLIC_TFTD_SAMPLE_RATE); + avpriv_set_pts_info(st, 64, ast->codecpar->block_align, FLIC_TFTD_SAMPLE_RATE); avpriv_set_pts_info(ast, 64, 1, FLIC_TFTD_SAMPLE_RATE); } else if (AV_RL16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) { avpriv_set_pts_info(st, 64, FLIC_MC_SPEED, 70); @@ -176,10 +176,10 @@ static int flic_read_header(AVFormatContext *s) avio_seek(pb, 12, SEEK_SET); /* send over abbreviated FLIC header chunk */ - av_free(st->codec->extradata); - st->codec->extradata_size = 12; - st->codec->extradata = av_malloc(12); - memcpy(st->codec->extradata, header, 12); + av_free(st->codecpar->extradata); + st->codecpar->extradata_size = 12; + st->codecpar->extradata = av_malloc(12); + memcpy(st->codecpar->extradata, header, 12); } else if (magic_number == FLIC_FILE_MAGIC_1) { avpriv_set_pts_info(st, 64, speed, 70); diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 8b0d201f80..a9bead5fda 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -80,21 +80,21 @@ static AVStream *create_stream(AVFormatContext *s, int codec_type) AVStream *st = avformat_new_stream(s, NULL); if (!st) return NULL; - st->codec->codec_type = codec_type; + st->codecpar->codec_type = codec_type; avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ return st; } -static int flv_same_audio_codec(AVCodecContext *acodec, int flags) +static int flv_same_audio_codec(AVCodecParameters *apar, int flags) { int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; int flv_codecid = flags & FLV_AUDIO_CODECID_MASK; int codec_id; - if (!acodec->codec_id && !acodec->codec_tag) + if (!apar->codec_id && !apar->codec_tag) return 1; - if (acodec->bits_per_coded_sample != bits_per_coded_sample) + if (apar->bits_per_coded_sample != bits_per_coded_sample) return 0; switch (flv_codecid) { @@ -107,42 +107,42 @@ static int flv_same_audio_codec(AVCodecContext *acodec, int flags) #else : AV_CODEC_ID_PCM_S16LE; #endif - return codec_id == acodec->codec_id; + return codec_id == apar->codec_id; case FLV_CODECID_PCM_LE: codec_id = bits_per_coded_sample == 8 ? AV_CODEC_ID_PCM_U8 : AV_CODEC_ID_PCM_S16LE; - return codec_id == acodec->codec_id; + return codec_id == apar->codec_id; case FLV_CODECID_AAC: - return acodec->codec_id == AV_CODEC_ID_AAC; + return apar->codec_id == AV_CODEC_ID_AAC; case FLV_CODECID_ADPCM: - return acodec->codec_id == AV_CODEC_ID_ADPCM_SWF; + return apar->codec_id == AV_CODEC_ID_ADPCM_SWF; case FLV_CODECID_SPEEX: - return acodec->codec_id == AV_CODEC_ID_SPEEX; + return apar->codec_id == AV_CODEC_ID_SPEEX; case FLV_CODECID_MP3: - return acodec->codec_id == AV_CODEC_ID_MP3; + return apar->codec_id == AV_CODEC_ID_MP3; case FLV_CODECID_NELLYMOSER_8KHZ_MONO: case FLV_CODECID_NELLYMOSER_16KHZ_MONO: case FLV_CODECID_NELLYMOSER: - return acodec->codec_id == AV_CODEC_ID_NELLYMOSER; + return apar->codec_id == AV_CODEC_ID_NELLYMOSER; case FLV_CODECID_PCM_MULAW: - return acodec->sample_rate == 8000 && - acodec->codec_id == AV_CODEC_ID_PCM_MULAW; + return apar->sample_rate == 8000 && + apar->codec_id == AV_CODEC_ID_PCM_MULAW; case FLV_CODECID_PCM_ALAW: - return acodec->sample_rate == 8000 && - acodec->codec_id == AV_CODEC_ID_PCM_ALAW; + return apar->sample_rate == 8000 && + apar->codec_id == AV_CODEC_ID_PCM_ALAW; default: - return acodec->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET); + return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET); } } static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, - AVCodecContext *acodec, int flv_codecid) + AVCodecParameters *apar, int flv_codecid) { switch (flv_codecid) { // no distinction between S16 and S8 PCM codec flags case FLV_CODECID_PCM: - acodec->codec_id = acodec->bits_per_coded_sample == 8 + apar->codec_id = apar->bits_per_coded_sample == 8 ? AV_CODEC_ID_PCM_U8 #if HAVE_BIGENDIAN : AV_CODEC_ID_PCM_S16BE; @@ -151,113 +151,113 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, #endif break; case FLV_CODECID_PCM_LE: - acodec->codec_id = acodec->bits_per_coded_sample == 8 + apar->codec_id = apar->bits_per_coded_sample == 8 ? AV_CODEC_ID_PCM_U8 : AV_CODEC_ID_PCM_S16LE; break; case FLV_CODECID_AAC: - acodec->codec_id = AV_CODEC_ID_AAC; + apar->codec_id = AV_CODEC_ID_AAC; break; case FLV_CODECID_ADPCM: - acodec->codec_id = AV_CODEC_ID_ADPCM_SWF; + apar->codec_id = AV_CODEC_ID_ADPCM_SWF; break; case FLV_CODECID_SPEEX: - acodec->codec_id = AV_CODEC_ID_SPEEX; - acodec->sample_rate = 16000; + apar->codec_id = AV_CODEC_ID_SPEEX; + apar->sample_rate = 16000; break; case FLV_CODECID_MP3: - acodec->codec_id = AV_CODEC_ID_MP3; + apar->codec_id = AV_CODEC_ID_MP3; astream->need_parsing = AVSTREAM_PARSE_FULL; break; case FLV_CODECID_NELLYMOSER_8KHZ_MONO: // in case metadata does not otherwise declare samplerate - acodec->sample_rate = 8000; - acodec->codec_id = AV_CODEC_ID_NELLYMOSER; + apar->sample_rate = 8000; + apar->codec_id = AV_CODEC_ID_NELLYMOSER; break; case FLV_CODECID_NELLYMOSER_16KHZ_MONO: - acodec->sample_rate = 16000; - acodec->codec_id = AV_CODEC_ID_NELLYMOSER; + apar->sample_rate = 16000; + apar->codec_id = AV_CODEC_ID_NELLYMOSER; break; case FLV_CODECID_NELLYMOSER: - acodec->codec_id = AV_CODEC_ID_NELLYMOSER; + apar->codec_id = AV_CODEC_ID_NELLYMOSER; break; case FLV_CODECID_PCM_MULAW: - acodec->sample_rate = 8000; - acodec->codec_id = AV_CODEC_ID_PCM_MULAW; + apar->sample_rate = 8000; + apar->codec_id = AV_CODEC_ID_PCM_MULAW; break; case FLV_CODECID_PCM_ALAW: - acodec->sample_rate = 8000; - acodec->codec_id = AV_CODEC_ID_PCM_ALAW; + apar->sample_rate = 8000; + apar->codec_id = AV_CODEC_ID_PCM_ALAW; break; default: av_log(s, AV_LOG_INFO, "Unsupported audio codec (%x)\n", flv_codecid >> FLV_AUDIO_CODECID_OFFSET); - acodec->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET; + apar->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET; } } -static int flv_same_video_codec(AVCodecContext *vcodec, int flags) +static int flv_same_video_codec(AVCodecParameters *vpar, int flags) { int flv_codecid = flags & FLV_VIDEO_CODECID_MASK; - if (!vcodec->codec_id && !vcodec->codec_tag) + if (!vpar->codec_id && !vpar->codec_tag) return 1; switch (flv_codecid) { case FLV_CODECID_H263: - return vcodec->codec_id == AV_CODEC_ID_FLV1; + return vpar->codec_id == AV_CODEC_ID_FLV1; case FLV_CODECID_SCREEN: - return vcodec->codec_id == AV_CODEC_ID_FLASHSV; + return vpar->codec_id == AV_CODEC_ID_FLASHSV; case FLV_CODECID_SCREEN2: - return vcodec->codec_id == AV_CODEC_ID_FLASHSV2; + return vpar->codec_id == AV_CODEC_ID_FLASHSV2; case FLV_CODECID_VP6: - return vcodec->codec_id == AV_CODEC_ID_VP6F; + return vpar->codec_id == AV_CODEC_ID_VP6F; case FLV_CODECID_VP6A: - return vcodec->codec_id == AV_CODEC_ID_VP6A; + return vpar->codec_id == AV_CODEC_ID_VP6A; case FLV_CODECID_H264: - return vcodec->codec_id == AV_CODEC_ID_H264; + return vpar->codec_id == AV_CODEC_ID_H264; default: - return vcodec->codec_tag == flv_codecid; + return vpar->codec_tag == flv_codecid; } } static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid, int read) { - AVCodecContext *vcodec = vstream->codec; + AVCodecParameters *par = vstream->codecpar; switch (flv_codecid) { case FLV_CODECID_H263: - vcodec->codec_id = AV_CODEC_ID_FLV1; + par->codec_id = AV_CODEC_ID_FLV1; break; case FLV_CODECID_SCREEN: - vcodec->codec_id = AV_CODEC_ID_FLASHSV; + par->codec_id = AV_CODEC_ID_FLASHSV; break; case FLV_CODECID_SCREEN2: - vcodec->codec_id = AV_CODEC_ID_FLASHSV2; + par->codec_id = AV_CODEC_ID_FLASHSV2; break; case FLV_CODECID_VP6: - vcodec->codec_id = AV_CODEC_ID_VP6F; + par->codec_id = AV_CODEC_ID_VP6F; case FLV_CODECID_VP6A: if (flv_codecid == FLV_CODECID_VP6A) - vcodec->codec_id = AV_CODEC_ID_VP6A; + par->codec_id = AV_CODEC_ID_VP6A; if (read) { - if (vcodec->extradata_size != 1) { - vcodec->extradata = av_malloc(1); - if (vcodec->extradata) - vcodec->extradata_size = 1; + if (par->extradata_size != 1) { + par->extradata = av_malloc(1); + if (par->extradata) + par->extradata_size = 1; } - if (vcodec->extradata) - vcodec->extradata[0] = avio_r8(s->pb); + if (par->extradata) + par->extradata[0] = avio_r8(s->pb); else avio_skip(s->pb, 1); } return 1; // 1 byte body size adjustment for flv_read_packet() case FLV_CODECID_H264: - vcodec->codec_id = AV_CODEC_ID_H264; + par->codec_id = AV_CODEC_ID_H264; return 3; // not 4, reading packet type will consume one byte default: av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid); - vcodec->codec_tag = flv_codecid; + par->codec_tag = flv_codecid; } return 0; @@ -368,7 +368,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, int64_t max_pos, int depth) { - AVCodecContext *acodec, *vcodec; + AVCodecParameters *apar, *vpar; FLVContext *flv = s->priv_data; AVIOContext *ioc; AMFDataType amf_type; @@ -442,43 +442,43 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, if (key) { // stream info doesn't live any deeper than the first object if (depth == 1) { - acodec = astream ? astream->codec : NULL; - vcodec = vstream ? vstream->codec : NULL; + apar = astream ? astream->codecpar : NULL; + vpar = vstream ? vstream->codecpar : NULL; if (amf_type == AMF_DATA_TYPE_NUMBER || amf_type == AMF_DATA_TYPE_BOOL) { if (!strcmp(key, "duration")) s->duration = num_val * AV_TIME_BASE; - else if (!strcmp(key, "videodatarate") && vcodec && + else if (!strcmp(key, "videodatarate") && vpar && 0 <= (int)(num_val * 1024.0)) - vcodec->bit_rate = num_val * 1024.0; - else if (!strcmp(key, "audiodatarate") && acodec && + vpar->bit_rate = num_val * 1024.0; + else if (!strcmp(key, "audiodatarate") && apar && 0 <= (int)(num_val * 1024.0)) - acodec->bit_rate = num_val * 1024.0; + apar->bit_rate = num_val * 1024.0; else if (!strcmp(key, "datastream")) { AVStream *st = create_stream(s, AVMEDIA_TYPE_DATA); if (!st) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; } else if (flv->trust_metadata) { - if (!strcmp(key, "videocodecid") && vcodec) { + if (!strcmp(key, "videocodecid") && vpar) { flv_set_video_codec(s, vstream, num_val, 0); - } else if (!strcmp(key, "audiocodecid") && acodec) { + } else if (!strcmp(key, "audiocodecid") && apar) { int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET; - flv_set_audio_codec(s, astream, acodec, id); - } else if (!strcmp(key, "audiosamplerate") && acodec) { - acodec->sample_rate = num_val; - } else if (!strcmp(key, "audiosamplesize") && acodec) { - acodec->bits_per_coded_sample = num_val; - } else if (!strcmp(key, "stereo") && acodec) { - acodec->channels = num_val + 1; - acodec->channel_layout = acodec->channels == 2 ? - AV_CH_LAYOUT_STEREO : - AV_CH_LAYOUT_MONO; - } else if (!strcmp(key, "width") && vcodec) { - vcodec->width = num_val; - } else if (!strcmp(key, "height") && vcodec) { - vcodec->height = num_val; + flv_set_audio_codec(s, astream, apar, id); + } else if (!strcmp(key, "audiosamplerate") && apar) { + apar->sample_rate = num_val; + } else if (!strcmp(key, "audiosamplesize") && apar) { + apar->bits_per_coded_sample = num_val; + } else if (!strcmp(key, "stereo") && apar) { + apar->channels = num_val + 1; + apar->channel_layout = apar->channels == 2 ? + AV_CH_LAYOUT_STEREO : + AV_CH_LAYOUT_MONO; + } else if (!strcmp(key, "width") && vpar) { + vpar->width = num_val; + } else if (!strcmp(key, "height") && vpar) { + vpar->height = num_val; } } } @@ -544,9 +544,9 @@ static int flv_read_metabody(AVFormatContext *s, int64_t next_pos) // the lookup every time it is called. for (i = 0; i < s->nb_streams; i++) { stream = s->streams[i]; - if (stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) astream = stream; - else if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) + else if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) vstream = stream; } @@ -585,12 +585,12 @@ static int flv_read_close(AVFormatContext *s) static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) { - av_free(st->codec->extradata); - st->codec->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_free(st->codecpar->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(s->pb, st->codec->extradata, st->codec->extradata_size); + st->codecpar->extradata_size = size; + avio_read(s->pb, st->codecpar->extradata, st->codecpar->extradata_size); return 0; } @@ -704,7 +704,7 @@ static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_DATA) + if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) break; } @@ -712,7 +712,7 @@ static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, st = create_stream(s, AVMEDIA_TYPE_DATA); if (!st) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; } pkt->dts = dts; @@ -803,12 +803,12 @@ skip: /* now find stream */ for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (is_audio && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (flv_same_audio_codec(st->codec, flags)) + if (is_audio && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (flv_same_audio_codec(st->codecpar, flags)) break; } else if (!is_audio && - st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - if (flv_same_video_codec(st->codec, flags)) + st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (flv_same_video_codec(st->codecpar, flags)) break; } } @@ -866,38 +866,43 @@ skip: sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3; bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; - if (!st->codec->channels || !st->codec->sample_rate || - !st->codec->bits_per_coded_sample) { - st->codec->channels = channels; - st->codec->channel_layout = channels == 1 + if (!st->codecpar->channels || !st->codecpar->sample_rate || + !st->codecpar->bits_per_coded_sample) { + st->codecpar->channels = channels; + st->codecpar->channel_layout = channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = sample_rate; - st->codec->bits_per_coded_sample = bits_per_coded_sample; + st->codecpar->sample_rate = sample_rate; + st->codecpar->bits_per_coded_sample = bits_per_coded_sample; } - if (!st->codec->codec_id) { - flv_set_audio_codec(s, st, st->codec, + if (!st->codecpar->codec_id) { + flv_set_audio_codec(s, st, st->codecpar, flags & FLV_AUDIO_CODECID_MASK); flv->last_sample_rate = - sample_rate = st->codec->sample_rate; + sample_rate = st->codecpar->sample_rate; flv->last_channels = - channels = st->codec->channels; + channels = st->codecpar->channels; } else { - AVCodecContext ctx; - ctx.sample_rate = sample_rate; - ctx.bits_per_coded_sample = bits_per_coded_sample; - flv_set_audio_codec(s, st, &ctx, flags & FLV_AUDIO_CODECID_MASK); - sample_rate = ctx.sample_rate; + AVCodecParameters *par = avcodec_parameters_alloc(); + if (!par) { + ret = AVERROR(ENOMEM); + goto leave; + } + par->sample_rate = sample_rate; + par->bits_per_coded_sample = bits_per_coded_sample; + flv_set_audio_codec(s, st, par, flags & FLV_AUDIO_CODECID_MASK); + sample_rate = par->sample_rate; + avcodec_parameters_free(&par); } } else { size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK, 1); } - if (st->codec->codec_id == AV_CODEC_ID_AAC || - st->codec->codec_id == AV_CODEC_ID_H264) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC || + st->codecpar->codec_id == AV_CODEC_ID_H264) { int type = avio_r8(s->pb); size--; - if (st->codec->codec_id == AV_CODEC_ID_H264) { + if (st->codecpar->codec_id == AV_CODEC_ID_H264) { // sign extension int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000; pts = dts + cts; @@ -908,7 +913,7 @@ skip: } } if (type == 0) { - if (st->codec->extradata) { + if (st->codecpar->extradata) { if ((ret = flv_queue_extradata(flv, s->pb, is_audio, size)) < 0) return ret; ret = AVERROR(EAGAIN); @@ -916,24 +921,24 @@ skip: } if ((ret = flv_get_extradata(s, st, size)) < 0) return ret; - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { MPEG4AudioConfig cfg; /* Workaround for buggy Omnia A/XE encoder */ AVDictionaryEntry *t = av_dict_get(s->metadata, "Encoder", NULL, 0); if (t && !strcmp(t->value, "Omnia A/XE")) - st->codec->extradata_size = 2; + st->codecpar->extradata_size = 2; - avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, - st->codec->extradata_size * 8, 1); - st->codec->channels = cfg.channels; - st->codec->channel_layout = 0; + avpriv_mpeg4audio_get_config(&cfg, st->codecpar->extradata, + st->codecpar->extradata_size * 8, 1); + st->codecpar->channels = cfg.channels; + st->codecpar->channel_layout = 0; if (cfg.ext_sample_rate) - st->codec->sample_rate = cfg.ext_sample_rate; + st->codecpar->sample_rate = cfg.ext_sample_rate; else - st->codec->sample_rate = cfg.sample_rate; + st->codecpar->sample_rate = cfg.sample_rate; av_log(s, AV_LOG_TRACE, "mp4a config channels %d sample rate %d\n", - st->codec->channels, st->codec->sample_rate); + st->codecpar->channels, st->codecpar->sample_rate); } ret = AVERROR(EAGAIN); diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 49c52357e2..2dfe3ae867 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -61,37 +61,37 @@ typedef struct FLVContext { int64_t duration; int64_t delay; ///< first dts delay (needed for AVC & Speex) - AVCodecContext *audio_enc; - AVCodecContext *video_enc; + AVCodecParameters *audio_par; + AVCodecParameters *video_par; double framerate; - AVCodecContext *data_enc; + AVCodecParameters *data_par; } FLVContext; typedef struct FLVStreamContext { int64_t last_ts; ///< last timestamp for each stream } FLVStreamContext; -static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc) +static int get_audio_flags(AVFormatContext *s, AVCodecParameters *par) { - int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT + int flags = (par->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT; - if (enc->codec_id == AV_CODEC_ID_AAC) // specs force these parameters + if (par->codec_id == AV_CODEC_ID_AAC) // specs force these parameters return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ | FLV_SAMPLESSIZE_16BIT | FLV_STEREO; - else if (enc->codec_id == AV_CODEC_ID_SPEEX) { - if (enc->sample_rate != 16000) { + else if (par->codec_id == AV_CODEC_ID_SPEEX) { + if (par->sample_rate != 16000) { av_log(s, AV_LOG_ERROR, "flv only supports wideband (16kHz) Speex audio\n"); return -1; } - if (enc->channels != 1) { + if (par->channels != 1) { av_log(s, AV_LOG_ERROR, "flv only supports mono Speex audio\n"); return -1; } return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT; } else { - switch (enc->sample_rate) { + switch (par->sample_rate) { case 44100: flags |= FLV_SAMPLERATE_44100HZ; break; @@ -104,7 +104,7 @@ static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc) case 16000: // nellymoser only case 8000: // nellymoser only case 5512: // not MP3 - if (enc->codec_id != AV_CODEC_ID_MP3) { + if (par->codec_id != AV_CODEC_ID_MP3) { flags |= FLV_SAMPLERATE_SPECIAL; break; } @@ -116,10 +116,10 @@ static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc) } } - if (enc->channels > 1) + if (par->channels > 1) flags |= FLV_STEREO; - switch (enc->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_MP3: flags |= FLV_CODECID_MP3 | FLV_SAMPLESSIZE_16BIT; break; @@ -136,9 +136,9 @@ static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc) flags |= FLV_CODECID_ADPCM | FLV_SAMPLESSIZE_16BIT; break; case AV_CODEC_ID_NELLYMOSER: - if (enc->sample_rate == 8000) + if (par->sample_rate == 8000) flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT; - else if (enc->sample_rate == 16000) + else if (par->sample_rate == 16000) flags |= FLV_CODECID_NELLYMOSER_16KHZ_MONO | FLV_SAMPLESSIZE_16BIT; else flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT; @@ -150,7 +150,7 @@ static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc) flags = FLV_CODECID_PCM_ALAW | FLV_SAMPLERATE_SPECIAL | FLV_SAMPLESSIZE_16BIT; break; case 0: - flags |= enc->codec_tag << 4; + flags |= par->codec_tag << 4; break; default: av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n"); @@ -216,9 +216,9 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) /* mixed array (hash) with size and string/type/data tuples */ avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY); metadata_count_pos = avio_tell(pb); - metadata_count = 4 * !!flv->video_enc + - 5 * !!flv->audio_enc + - 1 * !!flv->data_enc + + metadata_count = 4 * !!flv->video_par + + 5 * !!flv->audio_par + + 1 * !!flv->data_par + 2; // +2 for duration and file size avio_wb32(pb, metadata_count); @@ -229,15 +229,15 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) // fill in the guessed duration, it'll be corrected later if incorrect put_amf_double(pb, s->duration / AV_TIME_BASE); - if (flv->video_enc) { + if (flv->video_par) { put_amf_string(pb, "width"); - put_amf_double(pb, flv->video_enc->width); + put_amf_double(pb, flv->video_par->width); put_amf_string(pb, "height"); - put_amf_double(pb, flv->video_enc->height); + put_amf_double(pb, flv->video_par->height); put_amf_string(pb, "videodatarate"); - put_amf_double(pb, flv->video_enc->bit_rate / 1024.0); + put_amf_double(pb, flv->video_par->bit_rate / 1024.0); if (flv->framerate != 0.0) { put_amf_string(pb, "framerate"); @@ -246,27 +246,27 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) } put_amf_string(pb, "videocodecid"); - put_amf_double(pb, flv->video_enc->codec_tag); + put_amf_double(pb, flv->video_par->codec_tag); } - if (flv->audio_enc) { + if (flv->audio_par) { put_amf_string(pb, "audiodatarate"); - put_amf_double(pb, flv->audio_enc->bit_rate / 1024.0); + put_amf_double(pb, flv->audio_par->bit_rate / 1024.0); put_amf_string(pb, "audiosamplerate"); - put_amf_double(pb, flv->audio_enc->sample_rate); + put_amf_double(pb, flv->audio_par->sample_rate); put_amf_string(pb, "audiosamplesize"); - put_amf_double(pb, flv->audio_enc->codec_id == AV_CODEC_ID_PCM_U8 ? 8 : 16); + put_amf_double(pb, flv->audio_par->codec_id == AV_CODEC_ID_PCM_U8 ? 8 : 16); put_amf_string(pb, "stereo"); - put_amf_bool(pb, flv->audio_enc->channels == 2); + put_amf_bool(pb, flv->audio_par->channels == 2); put_amf_string(pb, "audiocodecid"); - put_amf_double(pb, flv->audio_enc->codec_tag); + put_amf_double(pb, flv->audio_par->codec_tag); } - if (flv->data_enc) { + if (flv->data_par) { put_amf_string(pb, "datastream"); put_amf_double(pb, 0.0); } @@ -316,37 +316,37 @@ static int flv_write_header(AVFormatContext *s) int64_t data_size; for (i = 0; i < s->nb_streams; i++) { - AVCodecContext *enc = s->streams[i]->codec; + AVCodecParameters *par = s->streams[i]->codecpar; FLVStreamContext *sc; - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: if (s->streams[i]->avg_frame_rate.den && s->streams[i]->avg_frame_rate.num) { flv->framerate = av_q2d(s->streams[i]->avg_frame_rate); } - if (flv->video_enc) { + if (flv->video_par) { av_log(s, AV_LOG_ERROR, "at most one video stream is supported in flv\n"); return AVERROR(EINVAL); } - flv->video_enc = enc; - if (!ff_codec_get_tag(flv_video_codec_ids, enc->codec_id)) - return unsupported_codec(s, "Video", enc->codec_id); + flv->video_par = par; + if (!ff_codec_get_tag(flv_video_codec_ids, par->codec_id)) + return unsupported_codec(s, "Video", par->codec_id); break; case AVMEDIA_TYPE_AUDIO: - if (flv->audio_enc) { + if (flv->audio_par) { av_log(s, AV_LOG_ERROR, "at most one audio stream is supported in flv\n"); return AVERROR(EINVAL); } - flv->audio_enc = enc; - if (get_audio_flags(s, enc) < 0) - return unsupported_codec(s, "Audio", enc->codec_id); + flv->audio_par = par; + if (get_audio_flags(s, par) < 0) + return unsupported_codec(s, "Audio", par->codec_id); break; case AVMEDIA_TYPE_DATA: - if (enc->codec_id != AV_CODEC_ID_TEXT) - return unsupported_codec(s, "Data", enc->codec_id); - flv->data_enc = enc; + if (par->codec_id != AV_CODEC_ID_TEXT) + return unsupported_codec(s, "Data", par->codec_id); + flv->data_par = par; break; default: av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n"); @@ -365,13 +365,13 @@ static int flv_write_header(AVFormatContext *s) avio_write(pb, "FLV", 3); avio_w8(pb, 1); - avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!flv->audio_enc + - FLV_HEADER_FLAG_HASVIDEO * !!flv->video_enc); + avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!flv->audio_par + + FLV_HEADER_FLAG_HASVIDEO * !!flv->video_par); avio_wb32(pb, 9); avio_wb32(pb, 0); for (i = 0; i < s->nb_streams; i++) - if (s->streams[i]->codec->codec_tag == 5) { + if (s->streams[i]->codecpar->codec_tag == 5) { avio_w8(pb, 8); // message type avio_wb24(pb, 0); // include flags avio_wb24(pb, 0); // time stamp @@ -383,25 +383,25 @@ static int flv_write_header(AVFormatContext *s) write_metadata(s, 0); for (i = 0; i < s->nb_streams; i++) { - AVCodecContext *enc = s->streams[i]->codec; - if (enc->codec_id == AV_CODEC_ID_AAC || enc->codec_id == AV_CODEC_ID_H264) { + AVCodecParameters *par = s->streams[i]->codecpar; + if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264) { int64_t pos; - avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ? + avio_w8(pb, par->codec_type == AVMEDIA_TYPE_VIDEO ? FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO); avio_wb24(pb, 0); // size patched later avio_wb24(pb, 0); // ts avio_w8(pb, 0); // ts ext avio_wb24(pb, 0); // streamid pos = avio_tell(pb); - if (enc->codec_id == AV_CODEC_ID_AAC) { - avio_w8(pb, get_audio_flags(s, enc)); + if (par->codec_id == AV_CODEC_ID_AAC) { + avio_w8(pb, get_audio_flags(s, par)); avio_w8(pb, 0); // AAC sequence header - avio_write(pb, enc->extradata, enc->extradata_size); + avio_write(pb, par->extradata, par->extradata_size); } else { - avio_w8(pb, enc->codec_tag | FLV_FRAME_KEY); // flags + avio_w8(pb, par->codec_tag | FLV_FRAME_KEY); // flags avio_w8(pb, 0); // AVC sequence header avio_wb24(pb, 0); // composition time - ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size); + ff_isom_write_avcc(pb, par->extradata, par->extradata_size); } data_size = avio_tell(pb) - pos; avio_seek(pb, -data_size - 10, SEEK_CUR); @@ -424,10 +424,10 @@ static int flv_write_trailer(AVFormatContext *s) /* Add EOS tag */ for (i = 0; i < s->nb_streams; i++) { - AVCodecContext *enc = s->streams[i]->codec; + AVCodecParameters *par = s->streams[i]->codecpar; FLVStreamContext *sc = s->streams[i]->priv_data; - if (enc->codec_type == AVMEDIA_TYPE_VIDEO && - enc->codec_id == AV_CODEC_ID_H264) + if (par->codec_type == AVMEDIA_TYPE_VIDEO && + par->codec_id == AV_CODEC_ID_H264) put_avc_eos_tag(pb, sc->last_ts); } @@ -450,7 +450,7 @@ static int flv_write_trailer(AVFormatContext *s) static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; FLVContext *flv = s->priv_data; FLVStreamContext *sc = s->streams[pkt->stream_index]->priv_data; unsigned ts; @@ -458,10 +458,10 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) uint8_t *data = NULL; int flags = 0, flags_size; - if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_VP6A || - enc->codec_id == AV_CODEC_ID_AAC) + if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A || + par->codec_id == AV_CODEC_ID_AAC) flags_size = 2; - else if (enc->codec_id == AV_CODEC_ID_H264) + else if (par->codec_id == AV_CODEC_ID_H264) flags_size = 5; else flags_size = 1; @@ -482,16 +482,16 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) s->event_flags &= ~AVSTREAM_EVENT_FLAG_METADATA_UPDATED; } - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: avio_w8(pb, FLV_TAG_TYPE_VIDEO); - flags = ff_codec_get_tag(flv_video_codec_ids, enc->codec_id); + flags = ff_codec_get_tag(flv_video_codec_ids, par->codec_id); flags |= pkt->flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER; break; case AVMEDIA_TYPE_AUDIO: - flags = get_audio_flags(s, enc); + flags = get_audio_flags(s, par); assert(size); @@ -504,14 +504,14 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EINVAL); } - if (enc->codec_id == AV_CODEC_ID_H264) + if (par->codec_id == AV_CODEC_ID_H264) /* check if extradata looks like MP4 */ - if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) + if (par->extradata_size > 0 && *(uint8_t*)par->extradata != 1) if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0) return -1; /* check Speex packet duration */ - if (enc->codec_id == AV_CODEC_ID_SPEEX && ts - sc->last_ts > 160) + if (par->codec_id == AV_CODEC_ID_SPEEX && ts - sc->last_ts > 160) av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than " "8 frames per packet. Adobe Flash " "Player cannot handle this!\n"); @@ -524,7 +524,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) avio_w8(pb, (ts >> 24) & 0x7F); // timestamps are 32 bits _signed_ avio_wb24(pb, flv->reserved); - if (enc->codec_type == AVMEDIA_TYPE_DATA) { + if (par->codec_type == AVMEDIA_TYPE_DATA) { int data_size; int64_t metadata_size_pos = avio_tell(pb); avio_w8(pb, AMF_DATA_TYPE_STRING); @@ -547,15 +547,15 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) avio_wb32(pb, data_size + 11); } else { avio_w8(pb,flags); - if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_VP6A) { - if (enc->extradata_size) - avio_w8(pb, enc->extradata[0]); + if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A) { + if (par->extradata_size) + avio_w8(pb, par->extradata[0]); else - avio_w8(pb, ((FFALIGN(enc->width, 16) - enc->width) << 4) | - (FFALIGN(enc->height, 16) - enc->height)); - } else if (enc->codec_id == AV_CODEC_ID_AAC) + avio_w8(pb, ((FFALIGN(par->width, 16) - par->width) << 4) | + (FFALIGN(par->height, 16) - par->height)); + } else if (par->codec_id == AV_CODEC_ID_AAC) avio_w8(pb, 1); // AAC raw - else if (enc->codec_id == AV_CODEC_ID_H264) { + else if (par->codec_id == AV_CODEC_ID_H264) { avio_w8(pb, 1); // AVC NALU avio_wb24(pb, pkt->pts - pkt->dts); } diff --git a/libavformat/g722.c b/libavformat/g722.c index 8052939c79..7e60e4e58c 100644 --- a/libavformat/g722.c +++ b/libavformat/g722.c @@ -31,17 +31,17 @@ static int g722_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_G722; - st->codec->sample_rate = 16000; - st->codec->channels = 1; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_G722; + st->codecpar->sample_rate = 16000; + st->codecpar->channels = 1; - st->codec->bits_per_coded_sample = - av_get_bits_per_sample(st->codec->codec_id); + st->codecpar->bits_per_coded_sample = + av_get_bits_per_sample(st->codecpar->codec_id); - assert(st->codec->bits_per_coded_sample > 0); + assert(st->codecpar->bits_per_coded_sample > 0); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/g723_1.c b/libavformat/g723_1.c index 716fbb9dd2..9eca3f9bb8 100644 --- a/libavformat/g723_1.c +++ b/libavformat/g723_1.c @@ -39,13 +39,13 @@ static av_cold int g723_1_init(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_G723_1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->channels = 1; - st->codec->sample_rate = 8000; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_G723_1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->sample_rate = 8000; - 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; return 0; diff --git a/libavformat/gif.c b/libavformat/gif.c index ddec778d82..e7fa37cfc7 100644 --- a/libavformat/gif.c +++ b/libavformat/gif.c @@ -264,7 +264,7 @@ static int gif_write_header(AVFormatContext *s) { GIFContext *gif = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *enc, *video_enc; + AVCodecParameters *par, *video_par; int i, width, height /*, rate*/; /* XXX: do we reject audio streams or just ignore them ? @@ -274,23 +274,23 @@ static int gif_write_header(AVFormatContext *s) gif->time = 0; gif->file_time = 0; - video_enc = NULL; + video_par = NULL; for (i = 0; i < s->nb_streams; i++) { - enc = s->streams[i]->codec; - if (enc->codec_type != AVMEDIA_TYPE_AUDIO) - video_enc = enc; + par = s->streams[i]->codecpar; + if (par->codec_type != AVMEDIA_TYPE_AUDIO) + video_par = par; } - if (!video_enc) { + if (!video_par) { av_free(gif); return -1; } else { - width = video_enc->width; - height = video_enc->height; + width = video_par->width; + height = video_par->height; // rate = video_enc->time_base.den; } - if (video_enc->pix_fmt != AV_PIX_FMT_RGB24) { + if (video_par->format != AV_PIX_FMT_RGB24) { av_log(s, AV_LOG_ERROR, "ERROR: gif only handles the rgb24 pixel format. Use -pix_fmt rgb24.\n"); return AVERROR(EIO); @@ -302,9 +302,10 @@ static int gif_write_header(AVFormatContext *s) return 0; } -static int gif_write_video(AVFormatContext *s, AVCodecContext *enc, +static int gif_write_video(AVFormatContext *s, AVStream *st, const uint8_t *buf, int size) { + AVCodecParameters *par = st->codecpar; AVIOContext *pb = s->pb; int jiffies; @@ -319,26 +320,26 @@ static int gif_write_video(AVFormatContext *s, AVCodecContext *enc, /* XXX: should use delay, in order to be more accurate */ /* instead of using the same rounded value each time */ /* XXX: don't even remember if I really use it for now */ - jiffies = (70 * enc->time_base.num / enc->time_base.den) - 1; + jiffies = (70 * st->time_base.num / st->time_base.den) - 1; avio_wl16(pb, jiffies); avio_w8(pb, 0x1f); /* transparent color index */ avio_w8(pb, 0x00); - gif_image_write_image(pb, 0, 0, enc->width, enc->height, - buf, enc->width * 3, AV_PIX_FMT_RGB24); + gif_image_write_image(pb, 0, 0, par->width, par->height, + buf, par->width * 3, AV_PIX_FMT_RGB24); return 0; } static int gif_write_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; - if (codec->codec_type == AVMEDIA_TYPE_AUDIO) + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; + if (par->codec_type == AVMEDIA_TYPE_AUDIO) return 0; /* just ignore audio */ else - return gif_write_video(s, codec, pkt->data, pkt->size); + return gif_write_video(s, s->streams[pkt->stream_index], pkt->data, pkt->size); } static int gif_write_trailer(AVFormatContext *s) diff --git a/libavformat/gsmdec.c b/libavformat/gsmdec.c index 1bc7eed856..d13327d879 100644 --- a/libavformat/gsmdec.c +++ b/libavformat/gsmdec.c @@ -62,12 +62,12 @@ static int gsm_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = c->sample_rate; - st->codec->bit_rate = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->iformat->raw_codec_id; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = c->sample_rate; + st->codecpar->bit_rate = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES; avpriv_set_pts_info(st, 64, GSM_BLOCK_SAMPLES, GSM_SAMPLE_RATE); diff --git a/libavformat/gxf.c b/libavformat/gxf.c index 189584035b..e6ebb27af9 100644 --- a/libavformat/gxf.c +++ b/libavformat/gxf.c @@ -92,69 +92,69 @@ static int get_sindex(AVFormatContext *s, int id, int format) { switch (format) { case 3: case 4: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MJPEG; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MJPEG; break; case 13: case 15: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DVVIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DVVIDEO; break; case 14: case 16: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DVVIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DVVIDEO; break; case 11: case 12: case 20: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG2VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 22: case 23: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG1VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG1VIDEO; st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 9: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S24LE; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = 48000; - st->codec->bit_rate = 3 * 1 * 48000 * 8; - st->codec->block_align = 3 * 1; - st->codec->bits_per_coded_sample = 24; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = 48000; + st->codecpar->bit_rate = 3 * 1 * 48000 * 8; + st->codecpar->block_align = 3 * 1; + st->codecpar->bits_per_coded_sample = 24; break; case 10: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = 48000; - st->codec->bit_rate = 2 * 1 * 48000 * 8; - st->codec->block_align = 2 * 1; - st->codec->bits_per_coded_sample = 16; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = 48000; + st->codecpar->bit_rate = 2 * 1 * 48000 * 8; + st->codecpar->block_align = 2 * 1; + st->codecpar->bits_per_coded_sample = 16; break; case 17: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_AC3; - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = 48000; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_AC3; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->sample_rate = 48000; break; // timecode tracks: case 7: case 8: case 24: - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_NONE; break; default: - st->codec->codec_type = AVMEDIA_TYPE_UNKNOWN; - st->codec->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_type = AVMEDIA_TYPE_UNKNOWN; + st->codecpar->codec_id = AV_CODEC_ID_NONE; break; } return s->nb_streams - 1; @@ -479,11 +479,11 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) { avio_rb32(pb); // "timeline" field number avio_r8(pb); // flags avio_r8(pb); // reserved - if (st->codec->codec_id == AV_CODEC_ID_PCM_S24LE || - st->codec->codec_id == AV_CODEC_ID_PCM_S16LE) { + if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE || + st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) { int first = field_info >> 16; int last = field_info & 0xffff; // last is exclusive - int bps = av_get_bits_per_sample(st->codec->codec_id)>>3; + int bps = av_get_bits_per_sample(st->codecpar->codec_id)>>3; if (first <= last && last*bps <= pkt_len) { avio_skip(pb, first*bps); skip = pkt_len - last*bps; @@ -498,7 +498,7 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) { pkt->dts = field_nr; //set duration manually for DV or else lavf misdetects the frame rate - if (st->codec->codec_id == AV_CODEC_ID_DVVIDEO) + if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) pkt->duration = si->fields_per_frame; return ret; diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c index fea1d5d818..22ae315e2d 100644 --- a/libavformat/gxfenc.c +++ b/libavformat/gxfenc.c @@ -107,7 +107,7 @@ static int gxf_find_lines_index(AVStream *st) int i; for (i = 0; i < 6; ++i) { - if (st->codec->height == gxf_lines_tab[i].height) { + if (st->codecpar->height == gxf_lines_tab[i].height) { sc->lines_index = gxf_lines_tab[i].index; return 0; } @@ -181,18 +181,18 @@ static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st) if (sc->b_per_i_or_p > 9) sc->b_per_i_or_p = 9; /* ensure value won't take more than one char */ } - if (st->codec->height == 512 || st->codec->height == 608) + if (st->codecpar->height == 512 || st->codecpar->height == 608) starting_line = 7; // VBI - else if (st->codec->height == 480) + else if (st->codecpar->height == 480) starting_line = 20; else starting_line = 23; // default PAL size = snprintf(buffer, 1024, "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n" "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\n", - (float)st->codec->bit_rate, sc->p_per_gop, sc->b_per_i_or_p, - st->codec->pix_fmt == AV_PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1, - starting_line, (st->codec->height + 15) / 16); + (float)st->codecpar->bit_rate, sc->p_per_gop, sc->b_per_i_or_p, + st->codecpar->format == AV_PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1, + starting_line, (st->codecpar->height + 15) / 16); avio_w8(pb, TRACK_MPG_AUX); avio_w8(pb, size + 1); avio_write(pb, (uint8_t *)buffer, size + 1); @@ -472,7 +472,7 @@ static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st) { GXFStreamContext *sc = st->priv_data; - if (st->codec->pix_fmt == AV_PIX_FMT_YUV422P) + if (st->codecpar->format == AV_PIX_FMT_YUV422P) avio_wl32(pb, 2); else avio_wl32(pb, 1); /* default to 420 */ @@ -481,9 +481,9 @@ static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st) avio_wl32(pb, 1); /* I picture per GOP */ avio_wl32(pb, sc->p_per_gop); avio_wl32(pb, sc->b_per_i_or_p); - if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) avio_wl32(pb, 2); - else if (st->codec->codec_id == AV_CODEC_ID_MPEG1VIDEO) + else if (st->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO) avio_wl32(pb, 1); else avio_wl32(pb, 0); @@ -565,7 +565,7 @@ static int gxf_write_umf_media_description(AVFormatContext *s) gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */ else { AVStream *st = s->streams[i]; - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: gxf_write_umf_media_mpeg(pb, st); @@ -646,22 +646,22 @@ static int gxf_write_header(AVFormatContext *s) return AVERROR(ENOMEM); st->priv_data = sc; - sc->media_type = ff_codec_get_tag(gxf_media_types, st->codec->codec_id); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->codec->codec_id != AV_CODEC_ID_PCM_S16LE) { + sc->media_type = ff_codec_get_tag(gxf_media_types, st->codecpar->codec_id); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE) { av_log(s, AV_LOG_ERROR, "only 16 BIT PCM LE allowed for now\n"); return -1; } - if (st->codec->sample_rate != 48000) { + if (st->codecpar->sample_rate != 48000) { av_log(s, AV_LOG_ERROR, "only 48000hz sampling rate is allowed\n"); return -1; } - if (st->codec->channels != 1) { + if (st->codecpar->channels != 1) { av_log(s, AV_LOG_ERROR, "only mono tracks are allowed\n"); return -1; } sc->track_type = 2; - sc->sample_rate = st->codec->sample_rate; + sc->sample_rate = st->codecpar->sample_rate; avpriv_set_pts_info(st, 64, 1, sc->sample_rate); sc->sample_size = 16; sc->frame_rate_index = -2; @@ -670,18 +670,18 @@ static int gxf_write_header(AVFormatContext *s) gxf->audio_tracks++; gxf->flags |= 0x04000000; /* audio is 16 bit pcm */ media_info = 'A'; - } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (i != 0) { av_log(s, AV_LOG_ERROR, "video stream must be the first track\n"); return -1; } /* FIXME check from time_base ? */ - if (st->codec->height == 480 || st->codec->height == 512) { /* NTSC or NTSC+VBI */ + if (st->codecpar->height == 480 || st->codecpar->height == 512) { /* NTSC or NTSC+VBI */ sc->frame_rate_index = 5; sc->sample_rate = 60; gxf->flags |= 0x00000080; gxf->time_base = (AVRational){ 1001, 60000 }; - } else if (st->codec->height == 576 || st->codec->height == 608) { /* PAL or PAL+VBI */ + } else if (st->codecpar->height == 576 || st->codecpar->height == 608) { /* PAL or PAL+VBI */ sc->frame_rate_index = 6; sc->media_type++; sc->sample_rate = 50; @@ -695,12 +695,12 @@ static int gxf_write_header(AVFormatContext *s) avpriv_set_pts_info(st, 64, gxf->time_base.num, gxf->time_base.den); if (gxf_find_lines_index(st) < 0) sc->lines_index = -1; - sc->sample_size = st->codec->bit_rate; + sc->sample_size = st->codecpar->bit_rate; sc->fields = 2; /* interlaced */ vsc = sc; - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MJPEG: sc->track_type = 1; gxf->flags |= 0x00004000; @@ -719,7 +719,7 @@ static int gxf_write_header(AVFormatContext *s) media_info = 'M'; break; case AV_CODEC_ID_DVVIDEO: - if (st->codec->pix_fmt == AV_PIX_FMT_YUV422P) { + if (st->codecpar->format == AV_PIX_FMT_YUV422P) { sc->media_type += 2; sc->track_type = 6; gxf->flags |= 0x00002000; @@ -818,7 +818,7 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) /* If the video is frame-encoded, the frame numbers shall be represented by * even field numbers. * see SMPTE360M-2004 6.4.2.1.3 Media field number */ - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { field_nb = gxf->nb_fields; } else { field_nb = av_rescale_rnd(pkt->dts, gxf->time_base.den, @@ -828,10 +828,10 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) avio_w8(pb, sc->media_type); avio_w8(pb, st->index); avio_wb32(pb, field_nb); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { avio_wb16(pb, 0); avio_wb16(pb, size / 2); - } else if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) { int frame_type = gxf_parse_mpeg_frame(sc, pkt->data, pkt->size); if (frame_type == AV_PICTURE_TYPE_I) { avio_w8(pb, 0x0d); @@ -844,7 +844,7 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) sc->pframes++; } avio_wb24(pb, size); - } else if (st->codec->codec_id == AV_CODEC_ID_DVVIDEO) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) { avio_w8(pb, size / 4096); avio_wb24(pb, 0); } else @@ -865,15 +865,15 @@ static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt) int packet_start_offset = avio_tell(pb) / 1024; gxf_write_packet_header(pb, PKT_MEDIA); - if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ padding = 4 - pkt->size % 4; - else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) padding = GXF_AUDIO_PACKET_SIZE - pkt->size; gxf_write_media_preamble(s, pkt, pkt->size + padding); avio_write(pb, pkt->data, pkt->size); gxf_write_padding(pb, padding); - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (!(gxf->flt_entries_nb % 500)) { int err; if ((err = av_reallocp_array(&gxf->flt_entries, @@ -909,7 +909,7 @@ static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cu for (i = 0; i < 2; i++) { AVStream *st = s->streams[pkt[i]->stream_index]; sc[i] = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { field_nb[i] = av_rescale_rnd(pkt[i]->dts, gxf->time_base.den, (int64_t)48000*gxf->time_base.num, AV_ROUND_UP); field_nb[i] &= ~1; // compare against even field number because audio must be before video @@ -923,7 +923,7 @@ static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cu static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - if (pkt && s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (pkt && s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) pkt->duration = 2; // enforce 2 fields return ff_audio_rechunk_interleave(s, out, pkt, flush, ff_interleave_packet_per_dts, gxf_compare_field_nb); diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c index a2710ded40..e32c36503e 100644 --- a/libavformat/hdsenc.c +++ b/libavformat/hdsenc.c @@ -338,18 +338,18 @@ static int hds_write_header(AVFormatContext *s) AVFormatContext *ctx; AVStream *st = s->streams[i]; - if (!st->codec->bit_rate) { + if (!st->codecpar->bit_rate) { av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i); ret = AVERROR(EINVAL); goto fail; } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (os->has_video) { c->nb_streams++; os++; } os->has_video = 1; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if (os->has_audio) { c->nb_streams++; os++; @@ -360,7 +360,7 @@ static int hds_write_header(AVFormatContext *s) ret = AVERROR(EINVAL); goto fail; } - os->bitrate += s->streams[i]->codec->bit_rate; + os->bitrate += s->streams[i]->codecpar->bit_rate; if (!os->ctx) { os->first_stream = i; @@ -389,8 +389,8 @@ static int hds_write_header(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } - avcodec_copy_context(st->codec, s->streams[i]->codec); - st->codec->codec_tag = 0; + avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); + st->codecpar->codec_tag = 0; st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; } @@ -517,7 +517,7 @@ static int hds_write_packet(AVFormatContext *s, AVPacket *pkt) if (st->first_dts == AV_NOPTS_VALUE) st->first_dts = pkt->dts; - if ((!os->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && + if ((!os->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && av_compare_ts(pkt->dts - st->first_dts, st->time_base, end_dts, AV_TIME_BASE_Q) >= 0 && pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) { diff --git a/libavformat/hls.c b/libavformat/hls.c index daee8625af..8459f12269 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -617,7 +617,7 @@ static int hls_read_header(AVFormatContext *s) ff_program_add_stream_index(s, i, stream_offset + j); st->id = i; avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den); - avcodec_copy_context(st->codec, v->ctx->streams[j]->codec); + avcodec_parameters_copy(st->codecpar, v->ctx->streams[j]->codecpar); if (v->bandwidth) av_dict_set(&st->metadata, "variant_bitrate", bitrate_str, 0); diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 843f37d82c..96b780fe37 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -82,7 +82,7 @@ static int hls_mux_init(AVFormatContext *s) AVStream *st; if (!(st = avformat_new_stream(oc, NULL))) return AVERROR(ENOMEM); - avcodec_copy_context(st->codec, s->streams[i]->codec); + avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; } @@ -220,7 +220,7 @@ static int hls_write_header(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) hls->has_video += - s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO; + s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO; if (hls->has_video > 1) av_log(s, AV_LOG_WARNING, @@ -284,7 +284,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) } if (hls->has_video) { - can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->flags & AV_PKT_FLAG_KEY; } if (pkt->pts == AV_NOPTS_VALUE) diff --git a/libavformat/hnm.c b/libavformat/hnm.c index 31fc42e05d..8476e51aa6 100644 --- a/libavformat/hnm.c +++ b/libavformat/hnm.c @@ -108,15 +108,15 @@ static int hnm_read_header(AVFormatContext *s) if (!(vst = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_HNM4_VIDEO; - vst->codec->codec_tag = 0; - vst->codec->width = hnm->width; - vst->codec->height = hnm->height; - vst->codec->extradata = av_mallocz(1); - - vst->codec->extradata_size = 1; - memcpy(vst->codec->extradata, &hnm->version, 1); + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_HNM4_VIDEO; + vst->codecpar->codec_tag = 0; + vst->codecpar->width = hnm->width; + vst->codecpar->height = hnm->height; + vst->codecpar->extradata = av_mallocz(1); + + vst->codecpar->extradata_size = 1; + memcpy(vst->codecpar->extradata, &hnm->version, 1); vst->start_time = 0; diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index d63d5a1171..5e9825de7d 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -761,8 +761,8 @@ int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta) return AVERROR(ENOMEM); st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = apic->id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = apic->id; if (apic->description[0]) av_dict_set(&st->metadata, "title", apic->description, 0); diff --git a/libavformat/id3v2enc.c b/libavformat/id3v2enc.c index 89181c26a0..827431aee3 100644 --- a/libavformat/id3v2enc.c +++ b/libavformat/id3v2enc.c @@ -171,7 +171,7 @@ int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt) /* get the mimetype*/ while (mime->id != AV_CODEC_ID_NONE) { - if (mime->id == st->codec->codec_id) { + if (mime->id == st->codecpar->codec_id) { mimetype = mime->str; break; } diff --git a/libavformat/idcin.c b/libavformat/idcin.c index 32cba3adba..b7b85c99cf 100644 --- a/libavformat/idcin.c +++ b/libavformat/idcin.c @@ -189,16 +189,16 @@ static int idcin_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 33, 1, IDCIN_FPS); st->start_time = 0; idcin->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_IDCIN; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = width; - st->codec->height = height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_IDCIN; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = width; + st->codecpar->height = height; /* load up the Huffman tables into extradata */ - st->codec->extradata_size = HUFFMAN_TABLE_SIZE; - st->codec->extradata = av_malloc(HUFFMAN_TABLE_SIZE); - ret = avio_read(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE); + st->codecpar->extradata_size = HUFFMAN_TABLE_SIZE; + st->codecpar->extradata = av_malloc(HUFFMAN_TABLE_SIZE); + ret = avio_read(pb, st->codecpar->extradata, HUFFMAN_TABLE_SIZE); if (ret < 0) { return ret; } else if (ret != HUFFMAN_TABLE_SIZE) { @@ -214,19 +214,19 @@ static int idcin_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 63, 1, sample_rate); st->start_time = 0; idcin->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 1; - st->codec->channels = channels; - st->codec->channel_layout = channels > 1 ? AV_CH_LAYOUT_STEREO : - AV_CH_LAYOUT_MONO; - st->codec->sample_rate = sample_rate; - st->codec->bits_per_coded_sample = bytes_per_sample * 8; - st->codec->bit_rate = sample_rate * bytes_per_sample * 8 * channels; - st->codec->block_align = idcin->block_align = bytes_per_sample * channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 1; + st->codecpar->channels = channels; + st->codecpar->channel_layout = channels > 1 ? AV_CH_LAYOUT_STEREO : + AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = sample_rate; + st->codecpar->bits_per_coded_sample = bytes_per_sample * 8; + st->codecpar->bit_rate = sample_rate * bytes_per_sample * 8 * channels; + st->codecpar->block_align = idcin->block_align = bytes_per_sample * channels; if (bytes_per_sample == 1) - st->codec->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; else - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; if (sample_rate % 14 != 0) { idcin->audio_chunk_size1 = (sample_rate / 14) * diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c index 82eff24e94..62d81f6658 100644 --- a/libavformat/idroqdec.c +++ b/libavformat/idroqdec.c @@ -127,14 +127,14 @@ static int roq_read_packet(AVFormatContext *s, return AVERROR(ENOMEM); avpriv_set_pts_info(st, 63, 1, roq->frame_rate); roq->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_ROQ; - st->codec->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_ROQ; + st->codecpar->codec_tag = 0; /* no fourcc */ if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) return AVERROR(EIO); - st->codec->width = roq->width = AV_RL16(preamble); - st->codec->height = roq->height = AV_RL16(preamble + 2); + st->codecpar->width = roq->width = AV_RL16(preamble); + st->codecpar->height = roq->height = AV_RL16(preamble + 2); break; } /* don't care about this chunk anymore */ @@ -175,22 +175,22 @@ static int roq_read_packet(AVFormatContext *s, return AVERROR(ENOMEM); avpriv_set_pts_info(st, 32, 1, RoQ_AUDIO_SAMPLE_RATE); roq->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ROQ_DPCM; - st->codec->codec_tag = 0; /* no tag */ + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ROQ_DPCM; + st->codecpar->codec_tag = 0; /* no tag */ if (chunk_type == RoQ_SOUND_STEREO) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - roq->audio_channels = st->codec->channels; - st->codec->sample_rate = RoQ_AUDIO_SAMPLE_RATE; - st->codec->bits_per_coded_sample = 16; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * - st->codec->bits_per_coded_sample; - st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + roq->audio_channels = st->codecpar->channels; + st->codecpar->sample_rate = RoQ_AUDIO_SAMPLE_RATE; + st->codecpar->bits_per_coded_sample = 16; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample; } case RoQ_QUAD_VQ: if (chunk_type == RoQ_QUAD_VQ) { diff --git a/libavformat/iff.c b/libavformat/iff.c index bf092152bd..d81a1ff561 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -122,11 +122,11 @@ static int iff_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; avio_skip(pb, 8); // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content - st->codec->codec_tag = avio_rl32(pb); + st->codecpar->codec_tag = avio_rl32(pb); while(!pb->eof_reached) { uint64_t orig_pos; @@ -138,12 +138,12 @@ static int iff_read_header(AVFormatContext *s) switch(chunk_id) { case ID_VHDR: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if (data_size < 14) return AVERROR_INVALIDDATA; avio_skip(pb, 12); - st->codec->sample_rate = avio_rb16(pb); + st->codecpar->sample_rate = avio_rb16(pb); if (data_size >= 16) { avio_skip(pb, 1); compression = avio_r8(pb); @@ -159,11 +159,11 @@ static int iff_read_header(AVFormatContext *s) if (data_size < 4) return AVERROR_INVALIDDATA; if (avio_rb32(pb) < 6) { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } else { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } break; @@ -173,22 +173,22 @@ static int iff_read_header(AVFormatContext *s) data_size); return AVERROR_INVALIDDATA; } - st->codec->extradata_size = data_size; - st->codec->extradata = av_malloc(data_size); - if (!st->codec->extradata) + st->codecpar->extradata_size = data_size; + st->codecpar->extradata = av_malloc(data_size); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - if (avio_read(pb, st->codec->extradata, data_size) < 0) + if (avio_read(pb, st->codecpar->extradata, data_size) < 0) return AVERROR(EIO); break; case ID_BMHD: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; if (data_size <= 8) return AVERROR_INVALIDDATA; - st->codec->width = avio_rb16(pb); - st->codec->height = avio_rb16(pb); + st->codecpar->width = avio_rb16(pb); + st->codecpar->height = avio_rb16(pb); avio_skip(pb, 4); // x, y offset - st->codec->bits_per_coded_sample = avio_r8(pb); + st->codecpar->bits_per_coded_sample = avio_r8(pb); if (data_size >= 11) { avio_skip(pb, 1); // masking compression = avio_r8(pb); @@ -229,37 +229,37 @@ static int iff_read_header(AVFormatContext *s) avio_seek(pb, iff->body_pos, SEEK_SET); - switch(st->codec->codec_type) { + switch(st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate); switch(compression) { case COMP_NONE: - st->codec->codec_id = AV_CODEC_ID_PCM_S8_PLANAR; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S8_PLANAR; break; case COMP_FIB: - st->codec->codec_id = AV_CODEC_ID_8SVX_FIB; + st->codecpar->codec_id = AV_CODEC_ID_8SVX_FIB; break; case COMP_EXP: - st->codec->codec_id = AV_CODEC_ID_8SVX_EXP; + st->codecpar->codec_id = AV_CODEC_ID_8SVX_EXP; break; default: av_log(s, AV_LOG_ERROR, "unknown compression method\n"); return -1; } - st->codec->bits_per_coded_sample = 8; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample; - st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + st->codecpar->bits_per_coded_sample = 8; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample; break; case AVMEDIA_TYPE_VIDEO: switch (compression) { case BITMAP_RAW: - st->codec->codec_id = AV_CODEC_ID_IFF_ILBM; + st->codecpar->codec_id = AV_CODEC_ID_IFF_ILBM; break; case BITMAP_BYTERUN1: - st->codec->codec_id = AV_CODEC_ID_IFF_BYTERUN1; + st->codecpar->codec_id = AV_CODEC_ID_IFF_BYTERUN1; break; default: av_log(s, AV_LOG_ERROR, "unknown compression method\n"); diff --git a/libavformat/ilbc.c b/libavformat/ilbc.c index 5ed8899a9e..b8549f3332 100644 --- a/libavformat/ilbc.c +++ b/libavformat/ilbc.c @@ -28,22 +28,22 @@ static const char mode30_header[] = "#!iLBC30\n"; static int ilbc_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; - AVCodecContext *enc; + AVCodecParameters *par; if (s->nb_streams != 1) { av_log(s, AV_LOG_ERROR, "Unsupported number of streams\n"); return AVERROR(EINVAL); } - enc = s->streams[0]->codec; + par = s->streams[0]->codecpar; - if (enc->codec_id != AV_CODEC_ID_ILBC) { + if (par->codec_id != AV_CODEC_ID_ILBC) { av_log(s, AV_LOG_ERROR, "Unsupported codec\n"); return AVERROR(EINVAL); } - if (enc->block_align == 50) { + if (par->block_align == 50) { avio_write(pb, mode30_header, sizeof(mode30_header) - 1); - } else if (enc->block_align == 38) { + } else if (par->block_align == 38) { avio_write(pb, mode20_header, sizeof(mode20_header) - 1); } else { av_log(s, AV_LOG_ERROR, "Unsupported mode\n"); @@ -79,18 +79,18 @@ static int ilbc_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_ILBC; - st->codec->sample_rate = 8000; - st->codec->channels = 1; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ILBC; + st->codecpar->sample_rate = 8000; + st->codecpar->channels = 1; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->start_time = 0; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); if (!memcmp(header, mode20_header, sizeof(mode20_header) - 1)) { - st->codec->block_align = 38; - st->codec->bit_rate = 15200; + st->codecpar->block_align = 38; + st->codecpar->bit_rate = 15200; } else if (!memcmp(header, mode30_header, sizeof(mode30_header) - 1)) { - st->codec->block_align = 50; - st->codec->bit_rate = 13333; + st->codecpar->block_align = 50; + st->codecpar->bit_rate = 13333; } else { av_log(s, AV_LOG_ERROR, "Unrecognized iLBC file header\n"); return AVERROR_INVALIDDATA; @@ -102,16 +102,16 @@ static int ilbc_read_header(AVFormatContext *s) static int ilbc_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int ret; - if ((ret = av_new_packet(pkt, enc->block_align)) < 0) + if ((ret = av_new_packet(pkt, par->block_align)) < 0) return ret; pkt->stream_index = 0; pkt->pos = avio_tell(s->pb); - pkt->duration = enc->block_align == 38 ? 160 : 240; - if ((ret = avio_read(s->pb, pkt->data, enc->block_align)) != enc->block_align) { + pkt->duration = par->block_align == 38 ? 160 : 240; + if ((ret = avio_read(s->pb, pkt->data, par->block_align)) != par->block_align) { av_packet_unref(pkt); return ret < 0 ? ret : AVERROR(EIO); } diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index ec3a829532..3d2383139c 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -184,8 +184,8 @@ static int img_read_header(AVFormatContext *s1) avpriv_set_pts_info(st, 60, framerate.den, framerate.num); if (width && height) { - st->codec->width = width; - st->codec->height = height; + st->codecpar->width = width; + st->codecpar->height = height; } if (!s->is_pipe) { @@ -201,18 +201,18 @@ static int img_read_header(AVFormatContext *s1) } if (s1->video_codec_id) { - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = s1->video_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = s1->video_codec_id; } else if (s1->audio_codec_id) { - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s1->audio_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s1->audio_codec_id; } else { - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = ff_guess_image2_codec(s->path); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = ff_guess_image2_codec(s->path); } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pix_fmt != AV_PIX_FMT_NONE) - st->codec->pix_fmt = pix_fmt; + st->codecpar->format = pix_fmt; return 0; } @@ -224,7 +224,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) int i, res; int size[3] = { 0 }, ret[3] = { 0 }; AVIOContext *f[3] = { NULL }; - AVCodecContext *codec = s1->streams[0]->codec; + AVCodecParameters *par = s1->streams[0]->codecpar; if (!s->is_pipe) { /* loop over input */ @@ -247,13 +247,13 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) } size[i] = avio_size(f[i]); - if (codec->codec_id != AV_CODEC_ID_RAWVIDEO) + if (par->codec_id != AV_CODEC_ID_RAWVIDEO) break; filename[strlen(filename) - 1] = 'U' + i; } - if (codec->codec_id == AV_CODEC_ID_RAWVIDEO && !codec->width) - infer_size(&codec->width, &codec->height, size[0]); + if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width) + infer_size(&par->width, &par->height, size[0]); } else { f[0] = s1->pb; if (f[0]->eof_reached) diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index 4071c3545c..1bdccc16e5 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -58,7 +58,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) VideoMuxData *img = s->priv_data; AVIOContext *pb[3]; char filename[1024]; - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; int i; if (!img->is_pipe) { @@ -77,7 +77,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EIO); } - if (codec->codec_id != AV_CODEC_ID_RAWVIDEO) + if (par->codec_id != AV_CODEC_ID_RAWVIDEO) break; filename[strlen(filename) - 1] = 'U' + i; } @@ -85,8 +85,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) pb[0] = s->pb; } - if (codec->codec_id == AV_CODEC_ID_RAWVIDEO) { - int ysize = codec->width * codec->height; + if (par->codec_id == AV_CODEC_ID_RAWVIDEO) { + int ysize = par->width * par->height; avio_write(pb[0], pkt->data, ysize); avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize) / 2); avio_write(pb[2], pkt->data + ysize + (pkt->size - ysize) / 2, (pkt->size - ysize) / 2); @@ -95,8 +95,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } else { if (ff_guess_image2_codec(s->filename) == AV_CODEC_ID_JPEG2000) { AVStream *st = s->streams[0]; - if (st->codec->extradata_size > 8 && - AV_RL32(st->codec->extradata + 4) == MKTAG('j', 'p', '2', 'h')) { + if (st->codecpar->extradata_size > 8 && + AV_RL32(st->codecpar->extradata + 4) == MKTAG('j', 'p', '2', 'h')) { if (pkt->size < 8 || AV_RL32(pkt->data + 4) != MKTAG('j', 'p', '2', 'c')) goto error; @@ -108,9 +108,9 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) ffio_wfourcc(pb[0], "jp2 "); avio_wb32(pb[0], 0); ffio_wfourcc(pb[0], "jp2 "); - avio_write(pb[0], st->codec->extradata, st->codec->extradata_size); + avio_write(pb[0], st->codecpar->extradata, st->codecpar->extradata_size); } else if (pkt->size < 8 || - (!st->codec->extradata_size && + (!st->codecpar->extradata_size && AV_RL32(pkt->data + 4) != MKTAG('j', 'P', ' ', ' '))) { // signature error: av_log(s, AV_LOG_ERROR, "malformed JPEG 2000 codestream\n"); diff --git a/libavformat/internal.h b/libavformat/internal.h index ed9893033a..c87d0ebde6 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -102,6 +102,22 @@ struct AVStreamInternal { * from dts. */ int reorder; + /** + * The codec context used by avformat_find_stream_info, the parser, etc. + */ + AVCodecContext *avctx; + /** + * 1 if avctx has been initialized with the values from the codec parameters + */ + int avctx_inited; + + enum AVCodecID orig_codec_id; + +#if FF_API_LAVF_AVCTX + // whether the deprecated stream codec context needs + // to be filled from the codec parameters + int need_codec_update; +#endif }; void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem); diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c index fb5124d685..2ef5ca0739 100644 --- a/libavformat/ipmovie.c +++ b/libavformat/ipmovie.c @@ -584,12 +584,12 @@ static int ipmovie_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 63, 1, 1000000); ipmovie->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_INTERPLAY_VIDEO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = ipmovie->video_width; - st->codec->height = ipmovie->video_height; - st->codec->bits_per_coded_sample = ipmovie->video_bpp; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_INTERPLAY_VIDEO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = ipmovie->video_width; + st->codecpar->height = ipmovie->video_height; + st->codecpar->bits_per_coded_sample = ipmovie->video_bpp; if (ipmovie->audio_type) { st = avformat_new_stream(s, NULL); @@ -597,19 +597,19 @@ static int ipmovie_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate); ipmovie->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = ipmovie->audio_type; - st->codec->codec_tag = 0; /* no tag */ - st->codec->channels = ipmovie->audio_channels; - st->codec->channel_layout = st->codec->channels == 1 ? AV_CH_LAYOUT_MONO : - AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = ipmovie->audio_sample_rate; - st->codec->bits_per_coded_sample = ipmovie->audio_bits; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * - st->codec->bits_per_coded_sample; - if (st->codec->codec_id == AV_CODEC_ID_INTERPLAY_DPCM) - st->codec->bit_rate /= 2; - st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = ipmovie->audio_type; + st->codecpar->codec_tag = 0; /* no tag */ + st->codecpar->channels = ipmovie->audio_channels; + st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO : + AV_CH_LAYOUT_STEREO; + st->codecpar->sample_rate = ipmovie->audio_sample_rate; + st->codecpar->bits_per_coded_sample = ipmovie->audio_bits; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; + if (st->codecpar->codec_id == AV_CODEC_ID_INTERPLAY_DPCM) + st->codecpar->bit_rate /= 2; + st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample; } return 0; diff --git a/libavformat/isom.c b/libavformat/isom.c index d421a1a4bd..21697e8a01 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -449,37 +449,37 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext avio_rb32(pb); /* max bitrate */ avio_rb32(pb); /* avg bitrate */ - st->codec->codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id); + st->codecpar->codec_id = ff_codec_get_id(ff_mp4_obj_type, object_type_id); av_log(fc, AV_LOG_TRACE, "esds object type id 0x%02x\n", object_type_id); len = ff_mp4_read_descr(fc, pb, &tag); if (tag == MP4DecSpecificDescrTag) { av_log(fc, AV_LOG_TRACE, "Specific MPEG4 header len=%d\n", len); if (!len || (uint64_t)len > (1<<30)) return -1; - av_free(st->codec->extradata); - st->codec->extradata = av_mallocz(len + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_free(st->codecpar->extradata); + st->codecpar->extradata = av_mallocz(len + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - avio_read(pb, st->codec->extradata, len); - st->codec->extradata_size = len; - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + avio_read(pb, st->codecpar->extradata, len); + st->codecpar->extradata_size = len; + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { MPEG4AudioConfig cfg; - avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, - st->codec->extradata_size * 8, 1); - st->codec->channels = cfg.channels; + avpriv_mpeg4audio_get_config(&cfg, st->codecpar->extradata, + st->codecpar->extradata_size * 8, 1); + st->codecpar->channels = cfg.channels; if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4 - st->codec->sample_rate = avpriv_mpa_freq_tab[cfg.sampling_index]; + st->codecpar->sample_rate = avpriv_mpa_freq_tab[cfg.sampling_index]; else if (cfg.ext_sample_rate) - st->codec->sample_rate = cfg.ext_sample_rate; + st->codecpar->sample_rate = cfg.ext_sample_rate; else - st->codec->sample_rate = cfg.sample_rate; + st->codecpar->sample_rate = cfg.sample_rate; av_log(fc, AV_LOG_TRACE, "mp4a config channels %d obj %d ext obj %d " - "sample rate %d ext sample rate %d\n", st->codec->channels, + "sample rate %d ext sample rate %d\n", st->codecpar->channels, cfg.object_type, cfg.ext_object_type, cfg.sample_rate, cfg.ext_sample_rate); - if (!(st->codec->codec_id = ff_codec_get_id(mp4_audio_types, + if (!(st->codecpar->codec_id = ff_codec_get_id(mp4_audio_types, cfg.object_type))) - st->codec->codec_id = AV_CODEC_ID_AAC; + st->codecpar->codec_id = AV_CODEC_ID_AAC; } } return 0; diff --git a/libavformat/iss.c b/libavformat/iss.c index c86b4250c8..1653b27408 100644 --- a/libavformat/iss.c +++ b/libavformat/iss.c @@ -93,23 +93,23 @@ static av_cold int iss_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_ISS; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_ISS; if (stereo) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - st->codec->sample_rate = 44100; + st->codecpar->sample_rate = 44100; if(rate_divisor > 0) - st->codec->sample_rate /= rate_divisor; - st->codec->bits_per_coded_sample = 4; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate - * st->codec->bits_per_coded_sample; - st->codec->block_align = iss->packet_size; - avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + st->codecpar->sample_rate /= rate_divisor; + st->codecpar->bits_per_coded_sample = 4; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate + * st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = iss->packet_size; + avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate); return 0; } @@ -124,8 +124,8 @@ static int iss_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = 0; pkt->pts = avio_tell(s->pb) - iss->sample_start_pos; - if(s->streams[0]->codec->channels > 0) - pkt->pts /= s->streams[0]->codec->channels*2; + if(s->streams[0]->codecpar->channels > 0) + pkt->pts /= s->streams[0]->codecpar->channels*2; return 0; } diff --git a/libavformat/iv8.c b/libavformat/iv8.c index ad630b3eb4..1fa88c4eeb 100644 --- a/libavformat/iv8.c +++ b/libavformat/iv8.c @@ -45,8 +45,8 @@ static int read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG4; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG4; st->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 90000); diff --git a/libavformat/ivfdec.c b/libavformat/ivfdec.c index b3555f42a4..a602f7c9ba 100644 --- a/libavformat/ivfdec.c +++ b/libavformat/ivfdec.c @@ -46,11 +46,11 @@ static int read_header(AVFormatContext *s) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = avio_rl32(s->pb); - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag); - st->codec->width = avio_rl16(s->pb); - st->codec->height = avio_rl16(s->pb); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = avio_rl32(s->pb); + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codecpar->codec_tag); + st->codecpar->width = avio_rl16(s->pb); + st->codecpar->height = avio_rl16(s->pb); time_base.den = avio_rl32(s->pb); time_base.num = avio_rl32(s->pb); st->duration = avio_rl64(s->pb); diff --git a/libavformat/ivfenc.c b/libavformat/ivfenc.c index 3cd16166c7..1e57106993 100644 --- a/libavformat/ivfenc.c +++ b/libavformat/ivfenc.c @@ -22,24 +22,24 @@ static int ivf_write_header(AVFormatContext *s) { - AVCodecContext *ctx; + AVCodecParameters *par; AVIOContext *pb = s->pb; if (s->nb_streams != 1) { av_log(s, AV_LOG_ERROR, "Format supports only exactly one video stream\n"); return AVERROR(EINVAL); } - ctx = s->streams[0]->codec; - if (ctx->codec_type != AVMEDIA_TYPE_VIDEO || ctx->codec_id != AV_CODEC_ID_VP8) { + par = s->streams[0]->codecpar; + if (par->codec_type != AVMEDIA_TYPE_VIDEO || par->codec_id != AV_CODEC_ID_VP8) { av_log(s, AV_LOG_ERROR, "Currently only VP8 is supported!\n"); return AVERROR(EINVAL); } avio_write(pb, "DKIF", 4); avio_wl16(pb, 0); // version avio_wl16(pb, 32); // header length - avio_wl32(pb, ctx->codec_tag ? ctx->codec_tag : AV_RL32("VP80")); - avio_wl16(pb, ctx->width); - avio_wl16(pb, ctx->height); + avio_wl32(pb, par->codec_tag ? par->codec_tag : AV_RL32("VP80")); + avio_wl16(pb, par->width); + avio_wl16(pb, par->height); avio_wl32(pb, s->streams[0]->time_base.den); avio_wl32(pb, s->streams[0]->time_base.num); avio_wl64(pb, s->streams[0]->duration); // TODO: duration or number of frames?!? diff --git a/libavformat/jvdec.c b/libavformat/jvdec.c index 1b1c5428bf..7fc3131847 100644 --- a/libavformat/jvdec.c +++ b/libavformat/jvdec.c @@ -85,11 +85,11 @@ static int read_header(AVFormatContext *s) if (!ast || !vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_JV; - vst->codec->codec_tag = 0; /* no fourcc */ - vst->codec->width = avio_rl16(pb); - vst->codec->height = avio_rl16(pb); + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_JV; + vst->codecpar->codec_tag = 0; /* no fourcc */ + vst->codecpar->width = avio_rl16(pb); + vst->codecpar->height = avio_rl16(pb); vst->duration = vst->nb_frames = ast->nb_index_entries = avio_rl16(pb); @@ -97,13 +97,13 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 4); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_U8; - ast->codec->codec_tag = 0; /* no fourcc */ - ast->codec->sample_rate = avio_rl16(pb); - ast->codec->channels = 1; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + ast->codecpar->codec_tag = 0; /* no fourcc */ + ast->codecpar->sample_rate = avio_rl16(pb); + ast->codecpar->channels = 1; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); avio_skip(pb, 10); diff --git a/libavformat/latmenc.c b/libavformat/latmenc.c index 5190ac7b20..a98a6ff6b0 100644 --- a/libavformat/latmenc.c +++ b/libavformat/latmenc.c @@ -74,10 +74,10 @@ static int latm_decode_extradata(LATMContext *ctx, uint8_t *buf, int size) static int latm_write_header(AVFormatContext *s) { LATMContext *ctx = s->priv_data; - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - if (avctx->extradata_size > 0 && - latm_decode_extradata(ctx, avctx->extradata, avctx->extradata_size) < 0) + if (par->extradata_size > 0 && + latm_decode_extradata(ctx, par->extradata, par->extradata_size) < 0) return AVERROR_INVALIDDATA; return 0; @@ -86,7 +86,7 @@ static int latm_write_header(AVFormatContext *s) static int latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) { LATMContext *ctx = s->priv_data; - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; GetBitContext gb; int header_size; @@ -94,7 +94,7 @@ static int latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) put_bits(bs, 1, !!ctx->counter); if (!ctx->counter) { - init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8); + init_get_bits(&gb, par->extradata, par->extradata_size * 8); /* StreamMuxConfig */ put_bits(bs, 1, 0); /* audioMuxVersion */ @@ -105,10 +105,10 @@ static int latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) /* AudioSpecificConfig */ if (ctx->object_type == AOT_ALS) { - header_size = avctx->extradata_size-(ctx->off + 7) >> 3; - avpriv_copy_bits(bs, &avctx->extradata[ctx->off], header_size); + header_size = par->extradata_size-(ctx->off + 7) >> 3; + avpriv_copy_bits(bs, &par->extradata[ctx->off], header_size); } else { - avpriv_copy_bits(bs, avctx->extradata, ctx->off + 3); + avpriv_copy_bits(bs, par->extradata, ctx->off + 3); if (!ctx->channel_conf) { avpriv_copy_pce_data(bs, &gb); diff --git a/libavformat/lmlm4.c b/libavformat/lmlm4.c index 1fb03e7e11..447b3d34b7 100644 --- a/libavformat/lmlm4.c +++ b/libavformat/lmlm4.c @@ -65,15 +65,15 @@ static int lmlm4_read_header(AVFormatContext *s) if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG4; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG4; st->need_parsing = AVSTREAM_PARSE_HEADERS; avpriv_set_pts_info(st, 64, 1001, 30000); if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MP2; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MP2; st->need_parsing = AVSTREAM_PARSE_HEADERS; /* the parameters will be extracted from the compressed bitstream */ diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c index 73d8bdf41c..9c884ba9b5 100644 --- a/libavformat/lxfdec.c +++ b/libavformat/lxfdec.c @@ -177,25 +177,25 @@ static int get_packet_header(AVFormatContext *s) //set codec based on specified audio bitdepth //we only support tightly packed 16-, 20-, 24- and 32-bit PCM at the moment - st->codec->bits_per_coded_sample = (audio_format >> 6) & 0x3F; + st->codecpar->bits_per_coded_sample = (audio_format >> 6) & 0x3F; - if (st->codec->bits_per_coded_sample != (audio_format & 0x3F)) { + if (st->codecpar->bits_per_coded_sample != (audio_format & 0x3F)) { av_log(s, AV_LOG_WARNING, "only tightly packed PCM currently supported\n"); return AVERROR_PATCHWELCOME; } - switch (st->codec->bits_per_coded_sample) { - case 16: st->codec->codec_id = AV_CODEC_ID_PCM_S16LE_PLANAR; break; - case 20: st->codec->codec_id = AV_CODEC_ID_PCM_LXF; break; - case 24: st->codec->codec_id = AV_CODEC_ID_PCM_S24LE_PLANAR; break; - case 32: st->codec->codec_id = AV_CODEC_ID_PCM_S32LE_PLANAR; break; + switch (st->codecpar->bits_per_coded_sample) { + case 16: st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE_PLANAR; break; + case 20: st->codecpar->codec_id = AV_CODEC_ID_PCM_LXF; break; + case 24: st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE_PLANAR; break; + case 32: st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE_PLANAR; break; default: av_log(s, AV_LOG_WARNING, "only 16-, 20-, 24- and 32-bit PCM currently supported\n"); return AVERROR_PATCHWELCOME; } - samples = track_size * 8 / st->codec->bits_per_coded_sample; + samples = track_size * 8 / st->codecpar->bits_per_coded_sample; //use audio packet size to determine video standard //for NTSC we have one 8008-sample audio frame per five video frames @@ -256,10 +256,10 @@ static int lxf_read_header(AVFormatContext *s) expiration_date = AV_RL16(&header_data[58]); disk_params = AV_RL32(&header_data[116]); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->bit_rate = 1000000 * ((video_params >> 14) & 0xFF); - st->codec->codec_tag = video_params & 0xF; - st->codec->codec_id = ff_codec_get_id(lxf_tags, st->codec->codec_tag); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->bit_rate = 1000000 * ((video_params >> 14) & 0xFF); + st->codecpar->codec_tag = video_params & 0xF; + st->codecpar->codec_id = ff_codec_get_id(lxf_tags, st->codecpar->codec_tag); av_log(s, AV_LOG_DEBUG, "record: %x = %i-%02i-%02i\n", record_date, 1900 + (record_date & 0x7F), (record_date >> 7) & 0xF, @@ -276,11 +276,11 @@ static int lxf_read_header(AVFormatContext *s) if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->sample_rate = LXF_SAMPLERATE; - st->codec->channels = lxf->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->sample_rate = LXF_SAMPLERATE; + st->codecpar->channels = lxf->channels; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); } avio_skip(s->pb, lxf->extended_size); diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 50f9ccbe74..0ed56af1bd 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1513,7 +1513,7 @@ static int matroska_parse_flac(AVFormatContext *s, av_log(s, AV_LOG_WARNING, "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n"); } else - st->codec->channel_layout = mask; + st->codecpar->channel_layout = mask; } av_dict_free(&dict); } @@ -1653,10 +1653,10 @@ static int matroska_parse_tracks(AVFormatContext *s) ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size, 0, NULL, NULL, NULL, NULL); - ret = ff_get_wav_header(s, &b, st->codec, track->codec_priv.size); + ret = ff_get_wav_header(s, &b, st->codecpar, track->codec_priv.size); if (ret < 0) return ret; - codec_id = st->codec->codec_id; + codec_id = st->codecpar->codec_id; extradata_offset = FFMIN(track->codec_priv.size, 18); } else if (!strcmp(track->codec_id, "V_QUICKTIME") && (track->codec_priv.size >= 86) && @@ -1775,15 +1775,15 @@ static int matroska_parse_tracks(AVFormatContext *s) if (!track->audio.buf) return AVERROR(ENOMEM); if (codec_id == AV_CODEC_ID_RA_288) { - st->codec->block_align = track->audio.coded_framesize; + st->codecpar->block_align = track->audio.coded_framesize; track->codec_priv.size = 0; } else { if (codec_id == AV_CODEC_ID_SIPR && flavor < 4) { const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 }; track->audio.sub_packet_size = ff_sipr_subpk_size[flavor]; - st->codec->bit_rate = sipr_bit_rate[flavor]; + st->codecpar->bit_rate = sipr_bit_rate[flavor]; } - st->codec->block_align = track->audio.sub_packet_size; + st->codecpar->block_align = track->audio.sub_packet_size; extradata_offset = 78; } } else if (codec_id == AV_CODEC_ID_FLAC && track->codec_priv.size) { @@ -1807,7 +1807,7 @@ static int matroska_parse_tracks(AVFormatContext *s) (AVRational){ 1, 1000000000 }, st->time_base); - st->codec->codec_id = codec_id; + st->codecpar->codec_id = codec_id; st->start_time = 0; if (strcmp(track->language, "und")) av_dict_set(&st->metadata, "language", track->language, 0); @@ -1818,17 +1818,17 @@ static int matroska_parse_tracks(AVFormatContext *s) if (track->flag_forced) st->disposition |= AV_DISPOSITION_FORCED; - if (!st->codec->extradata) { + if (!st->codecpar->extradata) { if (extradata) { - st->codec->extradata = extradata; - st->codec->extradata_size = extradata_size; + st->codecpar->extradata = extradata; + st->codecpar->extradata_size = extradata_size; } else if (track->codec_priv.data && track->codec_priv.size > 0) { - st->codec->extradata = av_mallocz(track->codec_priv.size + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata = av_mallocz(track->codec_priv.size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = track->codec_priv.size; - memcpy(st->codec->extradata, + st->codecpar->extradata_size = track->codec_priv.size; + memcpy(st->codecpar->extradata, track->codec_priv.data + extradata_offset, track->codec_priv.size); } @@ -1838,21 +1838,21 @@ static int matroska_parse_tracks(AVFormatContext *s) int display_width_mul = 1; int display_height_mul = 1; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = track->video.fourcc; - st->codec->width = track->video.pixel_width; - st->codec->height = track->video.pixel_height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = track->video.fourcc; + st->codecpar->width = track->video.pixel_width; + st->codecpar->height = track->video.pixel_height; if (track->video.stereo_mode && track->video.stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB) mkv_stereo_mode_display_mul(track->video.stereo_mode, &display_width_mul, &display_height_mul); av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, - st->codec->height * track->video.display_width * display_width_mul, - st->codec->width * track->video.display_height * display_height_mul, + st->codecpar->height * track->video.display_width * display_width_mul, + st->codecpar->width * track->video.display_height * display_height_mul, 255); - if (st->codec->codec_id != AV_CODEC_ID_H264 && - st->codec->codec_id != AV_CODEC_ID_HEVC) + if (st->codecpar->codec_id != AV_CODEC_ID_H264 && + st->codecpar->codec_id != AV_CODEC_ID_HEVC) st->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->default_duration) { av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, @@ -1866,16 +1866,16 @@ static int matroska_parse_tracks(AVFormatContext *s) return ret; } } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->sample_rate = track->audio.out_samplerate; - st->codec->channels = track->audio.channels; - if (st->codec->codec_id != AV_CODEC_ID_AAC) + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->sample_rate = track->audio.out_samplerate; + st->codecpar->channels = track->audio.channels; + if (st->codecpar->codec_id != AV_CODEC_ID_AAC) st->need_parsing = AVSTREAM_PARSE_HEADERS; - if (st->codec->codec_id == AV_CODEC_ID_MP3) + if (st->codecpar->codec_id == AV_CODEC_ID_MP3) st->need_parsing = AVSTREAM_PARSE_FULL; } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) { - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - if (st->codec->codec_id == AV_CODEC_ID_SSA) + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + if (st->codecpar->codec_id == AV_CODEC_ID_SSA) matroska->contains_ssa = 1; } } @@ -1961,21 +1961,21 @@ static int matroska_read_header(AVFormatContext *s) break; av_dict_set(&st->metadata, "filename", attachments[j].filename, 0); av_dict_set(&st->metadata, "mimetype", attachments[j].mime, 0); - st->codec->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_id = AV_CODEC_ID_NONE; for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++) { if (!strncmp(ff_mkv_image_mime_tags[i].str, attachments[j].mime, strlen(ff_mkv_image_mime_tags[i].str))) { - st->codec->codec_id = ff_mkv_image_mime_tags[i].id; + st->codecpar->codec_id = ff_mkv_image_mime_tags[i].id; break; } } attachments[j].stream = st; - if (st->codec->codec_id != AV_CODEC_ID_NONE) { - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { + st->disposition |= AV_DISPOSITION_ATTACHED_PIC; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; av_init_packet(&st->attached_pic); if ((res = av_new_packet(&st->attached_pic, attachments[j].bin.size)) < 0) @@ -1984,19 +1984,19 @@ static int matroska_read_header(AVFormatContext *s) st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; } else { - st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; - st->codec->extradata = av_malloc(attachments[j].bin.size); - if (!st->codec->extradata) + st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT; + st->codecpar->extradata = av_malloc(attachments[j].bin.size); + if (!st->codecpar->extradata) break; - st->codec->extradata_size = attachments[j].bin.size; - memcpy(st->codec->extradata, attachments[j].bin.data, + st->codecpar->extradata_size = attachments[j].bin.size; + memcpy(st->codecpar->extradata, attachments[j].bin.data, attachments[j].bin.size); for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) { if (!strncmp(ff_mkv_mime_tags[i].str, attachments[j].mime, strlen(ff_mkv_mime_tags[i].str))) { - st->codec->codec_id = ff_mkv_mime_tags[i].id; + st->codecpar->codec_id = ff_mkv_mime_tags[i].id; break; } } @@ -2184,7 +2184,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, uint8_t *data, int size, uint64_t timecode, uint64_t duration, int64_t pos) { - int a = st->codec->block_align; + int a = st->codecpar->block_align; int sps = track->audio.sub_packet_size; int cfs = track->audio.coded_framesize; int h = track->audio.sub_packet_h; @@ -2195,7 +2195,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, if (!track->audio.pkt_cnt) { if (track->audio.sub_packet_cnt == 0) track->audio.buf_timecode = timecode; - if (st->codec->codec_id == AV_CODEC_ID_RA_288) { + if (st->codecpar->codec_id == AV_CODEC_ID_RA_288) { if (size < cfs * h / 2) { av_log(matroska->ctx, AV_LOG_ERROR, "Corrupt int4 RM-style audio packet size\n"); @@ -2204,7 +2204,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, for (x = 0; x < h / 2; x++) memcpy(track->audio.buf + x * 2 * w + y * cfs, data + x * cfs, cfs); - } else if (st->codec->codec_id == AV_CODEC_ID_SIPR) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_SIPR) { if (size < w) { av_log(matroska->ctx, AV_LOG_ERROR, "Corrupt sipr RM-style audio packet size\n"); @@ -2224,7 +2224,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, } if (++track->audio.sub_packet_cnt >= h) { - if (st->codec->codec_id == AV_CODEC_ID_SIPR) + if (st->codecpar->codec_id == AV_CODEC_ID_SIPR) ff_rm_reorder_sipr_data(track->audio.buf, h, w); track->audio.sub_packet_cnt = 0; track->audio.pkt_cnt = h * w / a; @@ -2266,10 +2266,10 @@ static int matroska_parse_wavpack(MatroskaTrack *track, uint8_t *src, uint16_t ver; int ret, offset = 0; - if (srclen < 12 || track->stream->codec->extradata_size < 2) + if (srclen < 12 || track->stream->codecpar->extradata_size < 2) return AVERROR_INVALIDDATA; - ver = AV_RL16(track->stream->codec->extradata); + ver = AV_RL16(track->stream->codecpar->extradata); samples = AV_RL32(src); src += 4; @@ -2353,7 +2353,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, return res; } - if (st->codec->codec_id == AV_CODEC_ID_WAVPACK) { + if (st->codecpar->codec_id == AV_CODEC_ID_WAVPACK) { uint8_t *wv_data; res = matroska_parse_wavpack(track, pkt_data, &wv_data, &pkt_size); if (res < 0) { @@ -2366,7 +2366,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, pkt_data = wv_data; } - if (st->codec->codec_id == AV_CODEC_ID_PRORES) + if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) offset = 8; pkt = av_mallocz(sizeof(AVPacket)); @@ -2381,7 +2381,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, return AVERROR(ENOMEM); } - if (st->codec->codec_id == AV_CODEC_ID_PRORES) { + if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) { uint8_t *buf = pkt->data; bytestream_put_be32(&buf, pkt_size); bytestream_put_be32(&buf, MKBETAG('i', 'c', 'p', 'f')); @@ -2400,23 +2400,23 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, else pkt->pts = timecode; pkt->pos = pos; - if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE || st->codec->codec_id == AV_CODEC_ID_TEXT) + if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE || st->codecpar->codec_id == AV_CODEC_ID_TEXT) pkt->duration = duration; #if FF_API_CONVERGENCE_DURATION FF_DISABLE_DEPRECATION_WARNINGS - if (st->codec->codec_id == AV_CODEC_ID_TEXT) + if (st->codecpar->codec_id == AV_CODEC_ID_TEXT) pkt->convergence_duration = duration; FF_ENABLE_DEPRECATION_WARNINGS #endif - if (st->codec->codec_id == AV_CODEC_ID_SSA) + if (st->codecpar->codec_id == AV_CODEC_ID_SSA) matroska_fix_ass_packet(matroska, pkt, duration); if (matroska->prev_pkt && timecode != AV_NOPTS_VALUE && matroska->prev_pkt->pts == timecode && matroska->prev_pkt->stream_index == st->index && - st->codec->codec_id == AV_CODEC_ID_SSA) + st->codecpar->codec_id == AV_CODEC_ID_SSA) matroska_merge_packets(matroska->prev_pkt, pkt); else { dynarray_add(&matroska->packets, &matroska->num_packets, pkt); @@ -2510,11 +2510,11 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, FFMAX(track->end_timecode, timecode + block_duration); for (n = 0; n < laces; n++) { - if ((st->codec->codec_id == AV_CODEC_ID_RA_288 || - st->codec->codec_id == AV_CODEC_ID_COOK || - st->codec->codec_id == AV_CODEC_ID_SIPR || - st->codec->codec_id == AV_CODEC_ID_ATRAC3) && - st->codec->block_align && track->audio.sub_packet_size) { + if ((st->codecpar->codec_id == AV_CODEC_ID_RA_288 || + st->codecpar->codec_id == AV_CODEC_ID_COOK || + st->codecpar->codec_id == AV_CODEC_ID_SIPR || + st->codecpar->codec_id == AV_CODEC_ID_ATRAC3) && + st->codecpar->block_align && track->audio.sub_packet_size) { res = matroska_parse_rm_audio(matroska, track, st, data, lace_size[n], timecode, duration, pos); diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index baffd54340..ebde61264e 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -439,19 +439,19 @@ static int64_t mkv_write_cues(AVIOContext *pb, mkv_cues *cues, int num_tracks) return currentpos; } -static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContext *codec) +static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par) { uint8_t *header_start[3]; int header_len[3]; int first_header_size; int j; - if (codec->codec_id == AV_CODEC_ID_VORBIS) + if (par->codec_id == AV_CODEC_ID_VORBIS) first_header_size = 30; else first_header_size = 42; - if (avpriv_split_xiph_headers(codec->extradata, codec->extradata_size, + if (avpriv_split_xiph_headers(par->extradata, par->extradata_size, first_header_size, header_start, header_len) < 0) { av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); return -1; @@ -467,22 +467,22 @@ static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContex return 0; } -static int put_wv_codecpriv(AVIOContext *pb, AVCodecContext *codec) +static int put_wv_codecpriv(AVIOContext *pb, AVCodecParameters *par) { - if (codec->extradata && codec->extradata_size == 2) - avio_write(pb, codec->extradata, 2); + if (par->extradata && par->extradata_size == 2) + avio_write(pb, par->extradata, 2); else avio_wl16(pb, 0x403); // fallback to the version mentioned in matroska specs return 0; } static int put_flac_codecpriv(AVFormatContext *s, - AVIOContext *pb, AVCodecContext *codec) + AVIOContext *pb, AVCodecParameters *par) { - int write_comment = (codec->channel_layout && - !(codec->channel_layout & ~0x3ffffULL) && - !ff_flac_is_native_layout(codec->channel_layout)); - int ret = ff_flac_write_header(pb, codec->extradata, codec->extradata_size, + int write_comment = (par->channel_layout && + !(par->channel_layout & ~0x3ffffULL) && + !ff_flac_is_native_layout(par->channel_layout)); + int ret = ff_flac_write_header(pb, par->extradata, par->extradata_size, !write_comment); if (ret < 0) @@ -495,7 +495,7 @@ static int put_flac_codecpriv(AVFormatContext *s, uint8_t buf[32], *data, *p; int len; - snprintf(buf, sizeof(buf), "0x%"PRIx64, codec->channel_layout); + snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout); av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0); len = ff_vorbiscomment_length(dict, vendor); @@ -520,13 +520,13 @@ static int put_flac_codecpriv(AVFormatContext *s, return 0; } -static int get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, +static int get_aac_sample_rates(AVFormatContext *s, AVCodecParameters *par, int *sample_rate, int *output_sample_rate) { MPEG4AudioConfig mp4ac; - if (avpriv_mpeg4audio_get_config(&mp4ac, codec->extradata, - codec->extradata_size * 8, 1) < 0) { + if (avpriv_mpeg4audio_get_config(&mp4ac, par->extradata, + par->extradata_size * 8, 1) < 0) { av_log(s, AV_LOG_ERROR, "Error parsing AAC extradata, unable to determine samplerate.\n"); return AVERROR(EINVAL); @@ -538,44 +538,44 @@ static int get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, } static int mkv_write_native_codecprivate(AVFormatContext *s, - AVCodecContext *codec, + AVCodecParameters *par, AVIOContext *dyn_cp) { - switch (codec->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_VORBIS: case AV_CODEC_ID_THEORA: - return put_xiph_codecpriv(s, dyn_cp, codec); + return put_xiph_codecpriv(s, dyn_cp, par); case AV_CODEC_ID_FLAC: - return put_flac_codecpriv(s, dyn_cp, codec); + return put_flac_codecpriv(s, dyn_cp, par); case AV_CODEC_ID_WAVPACK: - return put_wv_codecpriv(dyn_cp, codec); + return put_wv_codecpriv(dyn_cp, par); case AV_CODEC_ID_H264: - return ff_isom_write_avcc(dyn_cp, codec->extradata, - codec->extradata_size); + return ff_isom_write_avcc(dyn_cp, par->extradata, + par->extradata_size); case AV_CODEC_ID_HEVC: - return ff_isom_write_hvcc(dyn_cp, codec->extradata, - codec->extradata_size, 0); + return ff_isom_write_hvcc(dyn_cp, par->extradata, + par->extradata_size, 0); case AV_CODEC_ID_ALAC: - if (codec->extradata_size < 36) { + if (par->extradata_size < 36) { av_log(s, AV_LOG_ERROR, "Invalid extradata found, ALAC expects a 36-byte " "QuickTime atom."); return AVERROR_INVALIDDATA; } else - avio_write(dyn_cp, codec->extradata + 12, - codec->extradata_size - 12); + avio_write(dyn_cp, par->extradata + 12, + par->extradata_size - 12); break; default: - if (codec->extradata_size) - avio_write(dyn_cp, codec->extradata, codec->extradata_size); + if (par->extradata_size) + avio_write(dyn_cp, par->extradata, par->extradata_size); } return 0; } static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, - AVCodecContext *codec, int native_id, - int qt_id) + AVCodecParameters *par, + int native_id, int qt_id) { AVIOContext *dyn_cp; uint8_t *codecpriv; @@ -586,36 +586,36 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, return ret; if (native_id) { - ret = mkv_write_native_codecprivate(s, codec, dyn_cp); - } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { + ret = mkv_write_native_codecprivate(s, par, dyn_cp); + } else if (par->codec_type == AVMEDIA_TYPE_VIDEO) { if (qt_id) { - if (!codec->codec_tag) - codec->codec_tag = ff_codec_get_tag(ff_codec_movvideo_tags, - codec->codec_id); - if (codec->extradata_size) - avio_write(dyn_cp, codec->extradata, codec->extradata_size); + if (!par->codec_tag) + par->codec_tag = ff_codec_get_tag(ff_codec_movvideo_tags, + par->codec_id); + if (par->extradata_size) + avio_write(dyn_cp, par->extradata, par->extradata_size); } else { - if (!codec->codec_tag) - codec->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, - codec->codec_id); - if (!codec->codec_tag) { + if (!par->codec_tag) + par->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, + par->codec_id); + if (!par->codec_tag) { av_log(s, AV_LOG_ERROR, "No bmp codec ID found.\n"); ret = -1; } - ff_put_bmp_header(dyn_cp, codec, ff_codec_bmp_tags, 0); + ff_put_bmp_header(dyn_cp, par, ff_codec_bmp_tags, 0); } - } else if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) { unsigned int tag; - tag = ff_codec_get_tag(ff_codec_wav_tags, codec->codec_id); + tag = ff_codec_get_tag(ff_codec_wav_tags, par->codec_id); if (!tag) { av_log(s, AV_LOG_ERROR, "No wav codec ID found.\n"); ret = -1; } - if (!codec->codec_tag) - codec->codec_tag = tag; + if (!par->codec_tag) + par->codec_tag = tag; - ff_put_wav_header(dyn_cp, codec); + ff_put_wav_header(s, dyn_cp, par); } codecpriv_size = avio_close_dyn_buf(dyn_cp, &codecpriv); @@ -632,7 +632,7 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, int i; int display_width, display_height; int h_width = 1, h_height = 1; - AVCodecContext *codec = st->codec; + AVCodecParameters *par = st->codecpar; AVDictionaryEntry *tag; MatroskaVideoStereoModeType format = MATROSKA_VIDEO_STEREOMODE_TYPE_NB; @@ -709,8 +709,8 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, // write DisplayWidth and DisplayHeight, they contain the size of // a single source view and/or the display aspect ratio - display_width = codec->width / h_width; - display_height = codec->height / h_height; + display_width = par->width / h_width; + display_height = par->height / h_height; if (st->sample_aspect_ratio.num) { display_width *= av_q2d(st->sample_aspect_ratio); put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYUNIT, 3); // DAR @@ -728,12 +728,12 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, int i, AVIOContext *pb) { AVStream *st = s->streams[i]; - AVCodecContext *codec = st->codec; + AVCodecParameters *par = st->codecpar; ebml_master subinfo, track; int native_id = 0; int qt_id = 0; - int bit_depth = av_get_bits_per_sample(codec->codec_id); - int sample_rate = codec->sample_rate; + int bit_depth = av_get_bits_per_sample(par->codec_id); + int sample_rate = par->sample_rate; int output_sample_rate = 0; int j, ret; AVDictionaryEntry *tag; @@ -741,16 +741,16 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, // ms precision is the de-facto standard timescale for mkv files avpriv_set_pts_info(st, 64, 1, 1000); - if (codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) { + if (par->codec_type == AVMEDIA_TYPE_ATTACHMENT) { mkv->have_attachments = 1; return 0; } if (!bit_depth) - bit_depth = av_get_bytes_per_sample(codec->sample_fmt) << 3; + bit_depth = av_get_bytes_per_sample(par->format) << 3; - if (codec->codec_id == AV_CODEC_ID_AAC) { - ret = get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate); + if (par->codec_id == AV_CODEC_ID_AAC) { + ret = get_aac_sample_rates(s, par, &sample_rate, &output_sample_rate); if (ret < 0) return ret; } @@ -772,48 +772,48 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, if (st->disposition & AV_DISPOSITION_FORCED) put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGFORCED, !!(st->disposition & AV_DISPOSITION_FORCED)); - if (codec->codec_type == AVMEDIA_TYPE_AUDIO && codec->initial_padding) { - mkv->tracks[i].ts_offset = av_rescale_q(codec->initial_padding, - (AVRational){ 1, codec->sample_rate }, + if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->initial_padding) { + mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding, + (AVRational){ 1, par->sample_rate }, st->time_base); put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, - av_rescale_q(codec->initial_padding, - (AVRational){ 1, codec->sample_rate }, + av_rescale_q(par->initial_padding, + (AVRational){ 1, par->sample_rate }, (AVRational){ 1, 1000000000 })); } // look for a codec ID string specific to mkv to use, // if none are found, use AVI codes for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) { - if (ff_mkv_codec_tags[j].id == codec->codec_id) { + if (ff_mkv_codec_tags[j].id == par->codec_id) { put_ebml_string(pb, MATROSKA_ID_CODECID, ff_mkv_codec_tags[j].str); native_id = 1; break; } } - if (mkv->mode == MODE_WEBM && !(codec->codec_id == AV_CODEC_ID_VP8 || - codec->codec_id == AV_CODEC_ID_VP9 || - codec->codec_id == AV_CODEC_ID_OPUS || - codec->codec_id == AV_CODEC_ID_VORBIS)) { + if (mkv->mode == MODE_WEBM && !(par->codec_id == AV_CODEC_ID_VP8 || + par->codec_id == AV_CODEC_ID_VP9 || + par->codec_id == AV_CODEC_ID_OPUS || + par->codec_id == AV_CODEC_ID_VORBIS)) { av_log(s, AV_LOG_ERROR, "Only VP8 or VP9 video and Vorbis or Opus audio are supported for WebM.\n"); return AVERROR(EINVAL); } - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO); if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0) put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1E9 / av_q2d(st->avg_frame_rate)); if (!native_id && - ff_codec_get_tag(ff_codec_movvideo_tags, codec->codec_id) && - (!ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id) || - codec->codec_id == AV_CODEC_ID_SVQ1 || - codec->codec_id == AV_CODEC_ID_SVQ3 || - codec->codec_id == AV_CODEC_ID_CINEPAK)) + ff_codec_get_tag(ff_codec_movvideo_tags, par->codec_id) && + (!ff_codec_get_tag(ff_codec_bmp_tags, par->codec_id) || + par->codec_id == AV_CODEC_ID_SVQ1 || + par->codec_id == AV_CODEC_ID_SVQ3 || + par->codec_id == AV_CODEC_ID_CINEPAK)) qt_id = 1; if (qt_id) @@ -826,8 +826,8 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0); // XXX: interlace flag? - put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width); - put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height); + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , par->width); + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, par->height); // check both side data and metadata for stereo information, // write the result to the bitstream if any is found @@ -846,7 +846,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM"); subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 0); - put_ebml_uint (pb, MATROSKA_ID_AUDIOCHANNELS , codec->channels); + put_ebml_uint (pb, MATROSKA_ID_AUDIOCHANNELS , par->channels); put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate); if (output_sample_rate) put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate); @@ -858,7 +858,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, case AVMEDIA_TYPE_SUBTITLE: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_SUBTITLE); if (!native_id) { - av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", codec->codec_id); + av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", par->codec_id); return AVERROR(ENOSYS); } break; @@ -866,7 +866,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska.\n"); break; } - ret = mkv_write_codecprivate(s, pb, codec, native_id, qt_id); + ret = mkv_write_codecprivate(s, pb, par, native_id, qt_id); if (ret < 0) return ret; @@ -1079,7 +1079,7 @@ static int mkv_write_attachments(AVFormatContext *s) AVDictionaryEntry *t; const char *mimetype = NULL; - if (st->codec->codec_type != AVMEDIA_TYPE_ATTACHMENT) + if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT) continue; attached_file = start_ebml_master(pb, MATROSKA_ID_ATTACHEDFILE, 0); @@ -1093,15 +1093,15 @@ static int mkv_write_attachments(AVFormatContext *s) put_ebml_string(pb, MATROSKA_ID_FILENAME, t->value); if (t = av_dict_get(st->metadata, "mimetype", NULL, 0)) mimetype = t->value; - else if (st->codec->codec_id != AV_CODEC_ID_NONE ) { + else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) { int i; for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) - if (ff_mkv_mime_tags[i].id == st->codec->codec_id) { + if (ff_mkv_mime_tags[i].id == st->codecpar->codec_id) { mimetype = ff_mkv_mime_tags[i].str; break; } for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++) - if (ff_mkv_image_mime_tags[i].id == st->codec->codec_id) { + if (ff_mkv_image_mime_tags[i].id == st->codecpar->codec_id) { mimetype = ff_mkv_image_mime_tags[i].str; break; } @@ -1113,7 +1113,7 @@ static int mkv_write_attachments(AVFormatContext *s) } put_ebml_string(pb, MATROSKA_ID_FILEMIMETYPE, mimetype); - put_ebml_binary(pb, MATROSKA_ID_FILEDATA, st->codec->extradata, st->codec->extradata_size); + put_ebml_binary(pb, MATROSKA_ID_FILEDATA, st->codecpar->extradata, st->codecpar->extradata_size); put_ebml_uint(pb, MATROSKA_ID_FILEUID, av_lfg_get(&c)); end_ebml_master(pb, attached_file); } @@ -1390,7 +1390,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, unsigned int blockid, AVPacket *pkt, int flags) { MatroskaMuxContext *mkv = s->priv_data; - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; uint8_t *data = NULL; int offset = 0, size = pkt->size; int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts; @@ -1398,14 +1398,14 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, " "pts %" PRId64 ", dts %" PRId64 ", duration %" PRId64 ", flags %d\n", avio_tell(pb), pkt->size, pkt->pts, pkt->dts, pkt->duration, flags); - if (codec->codec_id == AV_CODEC_ID_H264 && codec->extradata_size > 0 && - (AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1)) + if (par->codec_id == AV_CODEC_ID_H264 && par->extradata_size > 0 && + (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) ff_avc_parse_nal_units_buf(pkt->data, &data, &size); - else if (codec->codec_id == AV_CODEC_ID_HEVC && codec->extradata_size > 6 && - (AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1)) + else if (par->codec_id == AV_CODEC_ID_HEVC && par->extradata_size > 6 && + (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) /* extradata is Annex B, assume the bitstream is too and convert it */ ff_hevc_annexb2mp4_buf(pkt->data, &data, &size, 0, NULL); - else if (codec->codec_id == AV_CODEC_ID_WAVPACK) { + else if (par->codec_id == AV_CODEC_ID_WAVPACK) { int ret = mkv_strip_wavpack(pkt->data, &data, &size); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Error stripping a WavPack packet.\n"); @@ -1414,7 +1414,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, } else data = pkt->data; - if (codec->codec_id == AV_CODEC_ID_PRORES) { + if (par->codec_id == AV_CODEC_ID_PRORES) { /* Matroska specification requires to remove the first QuickTime atom */ size -= 8; @@ -1492,7 +1492,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt) { MatroskaMuxContext *mkv = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); int duration = pkt->duration; int ret; @@ -1520,11 +1520,11 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt) mkv->cluster_pts = FFMAX(0, ts); } - if (codec->codec_type != AVMEDIA_TYPE_SUBTITLE) { + if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) { mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe << 7); - } else if (codec->codec_id == AV_CODEC_ID_SSA) { + } else if (par->codec_id == AV_CODEC_ID_SSA) { duration = mkv_write_ass_blocks(s, pb, pkt); - } else if (codec->codec_id == AV_CODEC_ID_SRT) { + } else if (par->codec_id == AV_CODEC_ID_SRT) { duration = mkv_write_srt_blocks(s, pb, pkt); } else { ebml_master blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, @@ -1541,7 +1541,7 @@ FF_ENABLE_DEPRECATION_WARNINGS end_ebml_master(pb, blockgroup); } - if (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe) { + if (par->codec_type == AVMEDIA_TYPE_VIDEO && keyframe) { ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, ts, mkv->cluster_pos); if (ret < 0) @@ -1555,7 +1555,7 @@ FF_ENABLE_DEPRECATION_WARNINGS static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) { MatroskaMuxContext *mkv = s->priv_data; - int codec_type = s->streams[pkt->stream_index]->codec->codec_type; + int codec_type = s->streams[pkt->stream_index]->codecpar->codec_type; int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); int cluster_size; int64_t cluster_time; diff --git a/libavformat/mm.c b/libavformat/mm.c index cdf1010dc6..16505502fd 100644 --- a/libavformat/mm.c +++ b/libavformat/mm.c @@ -109,11 +109,11 @@ static int read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MMVIDEO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = width; - st->codec->height = height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MMVIDEO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = width; + st->codecpar->height = height; avpriv_set_pts_info(st, 64, 1, frame_rate); /* audio stream */ @@ -121,12 +121,12 @@ static int read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->codec_id = AV_CODEC_ID_PCM_U8; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = 8000; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = 8000; avpriv_set_pts_info(st, 64, 1, 8000); /* 8000 hz */ } diff --git a/libavformat/mmf.c b/libavformat/mmf.c index 2150bd5911..55aeff410f 100644 --- a/libavformat/mmf.c +++ b/libavformat/mmf.c @@ -68,10 +68,10 @@ static int mmf_write_header(AVFormatContext *s) int64_t pos; int rate; - rate = mmf_rate_code(s->streams[0]->codec->sample_rate); + rate = mmf_rate_code(s->streams[0]->codecpar->sample_rate); if (rate < 0) { av_log(s, AV_LOG_ERROR, "Unsupported sample rate %d\n", - s->streams[0]->codec->sample_rate); + s->streams[0]->codecpar->sample_rate); return -1; } @@ -107,7 +107,7 @@ static int mmf_write_header(AVFormatContext *s) mmf->awapos = ff_start_tag(pb, "Awa\x01"); - avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); + avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codecpar->sample_rate); avio_flush(pb); @@ -155,7 +155,7 @@ static int mmf_write_trailer(AVFormatContext *s) /* "play wav" */ avio_w8(pb, 0); /* start time */ avio_w8(pb, 1); /* (channel << 6) | wavenum */ - gatetime = size * 500 / s->streams[0]->codec->sample_rate; + gatetime = size * 500 / s->streams[0]->codecpar->sample_rate; put_varlength(pb, gatetime); /* duration */ /* "nop" */ @@ -255,16 +255,16 @@ static int mmf_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_YAMAHA; - st->codec->sample_rate = rate; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->bits_per_coded_sample = 4; - st->codec->bit_rate = st->codec->sample_rate * - st->codec->bits_per_coded_sample; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_YAMAHA; + st->codecpar->sample_rate = rate; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->bits_per_coded_sample = 4; + st->codecpar->bit_rate = st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/mov.c b/libavformat/mov.c index 2b8ccd28e8..0dee5ec59b 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -214,8 +214,8 @@ static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len) st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; return 0; } @@ -613,13 +613,13 @@ static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "stype= %.4s\n", (char*)&type); if (type == MKTAG('v','i','d','e')) - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; else if (type == MKTAG('s','o','u','n')) - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; else if (type == MKTAG('m','1','a',' ')) - st->codec->codec_id = AV_CODEC_ID_MP2; + st->codecpar->codec_id = AV_CODEC_ID_MP2; else if ((type == MKTAG('s','u','b','p')) || (type == MKTAG('c','l','c','p'))) - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; avio_rb32(pb); /* component manufacture */ avio_rb32(pb); /* component flags */ @@ -693,15 +693,19 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom) bsmod = (ac3info >> 14) & 0x7; acmod = (ac3info >> 11) & 0x7; lfeon = (ac3info >> 10) & 0x1; - st->codec->channels = ((int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon; - st->codec->channel_layout = avpriv_ac3_channel_layout_tab[acmod]; + st->codecpar->channels = ((int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon; + st->codecpar->channel_layout = avpriv_ac3_channel_layout_tab[acmod]; if (lfeon) - st->codec->channel_layout |= AV_CH_LOW_FREQUENCY; + st->codecpar->channel_layout |= AV_CH_LOW_FREQUENCY; *ast = bsmod; - if (st->codec->channels > 1 && bsmod == 0x7) + if (st->codecpar->channels > 1 && bsmod == 0x7) *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE; +#if FF_API_LAVF_AVCTX + FF_DISABLE_DEPRECATION_WARNINGS st->codec->audio_service_type = *ast; + FF_ENABLE_DEPRECATION_WARNINGS +#endif return 0; } @@ -729,15 +733,19 @@ static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom) bsmod = (eac3info >> 12) & 0x1f; acmod = (eac3info >> 9) & 0x7; lfeon = (eac3info >> 8) & 0x1; - st->codec->channel_layout = avpriv_ac3_channel_layout_tab[acmod]; + st->codecpar->channel_layout = avpriv_ac3_channel_layout_tab[acmod]; if (lfeon) - st->codec->channel_layout |= AV_CH_LOW_FREQUENCY; - st->codec->channels = av_get_channel_layout_nb_channels(st->codec->channel_layout); + st->codecpar->channel_layout |= AV_CH_LOW_FREQUENCY; + st->codecpar->channels = av_get_channel_layout_nb_channels(st->codecpar->channel_layout); *ast = bsmod; - if (st->codec->channels > 1 && bsmod == 0x7) + if (st->codecpar->channels > 1 && bsmod == 0x7) *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE; +#if FF_API_LAVF_AVCTX + FF_DISABLE_DEPRECATION_WARNINGS st->codec->audio_service_type = *ast; + FF_ENABLE_DEPRECATION_WARNINGS +#endif return 0; } @@ -769,7 +777,7 @@ static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; st = c->fc->streams[c->fc->nb_streams-1]; - return ff_get_wav_header(c->fc, pb, st->codec, atom.size); + return ff_get_wav_header(c->fc, pb, st->codecpar, atom.size); } static int mov_read_pasp(MOVContext *c, AVIOContext *pb, MOVAtom atom) @@ -973,18 +981,18 @@ static int mov_read_smi(MOVContext *c, AVIOContext *pb, MOVAtom atom) // currently SVQ3 decoder expect full STSD header - so let's fake it // this should be fixed and just SMI header should be passed - av_free(st->codec->extradata); - st->codec->extradata = av_mallocz(atom.size + 0x5a + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_free(st->codecpar->extradata); + st->codecpar->extradata = av_mallocz(atom.size + 0x5a + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = 0x5a + atom.size; - memcpy(st->codec->extradata, "SVQ3", 4); // fake + st->codecpar->extradata_size = 0x5a + atom.size; + memcpy(st->codecpar->extradata, "SVQ3", 4); // fake - ret = ffio_read_size(pb, st->codec->extradata + 0x5a, atom.size); + ret = ffio_read_size(pb, st->codecpar->extradata + 0x5a, atom.size); if (ret < 0) return ret; - av_log(c->fc, AV_LOG_TRACE, "Reading SMI %"PRId64" %s\n", atom.size, st->codec->extradata + 0x5a); + av_log(c->fc, AV_LOG_TRACE, "Reading SMI %"PRId64" %s\n", atom.size, st->codecpar->extradata + 0x5a); return 0; } @@ -1000,18 +1008,18 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom) little_endian = !!avio_rb16(pb); av_log(c->fc, AV_LOG_TRACE, "enda %d\n", little_endian); if (little_endian == 1) { - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_PCM_S24BE: - st->codec->codec_id = AV_CODEC_ID_PCM_S24LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE; break; case AV_CODEC_ID_PCM_S32BE: - st->codec->codec_id = AV_CODEC_ID_PCM_S32LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE; break; case AV_CODEC_ID_PCM_F32BE: - st->codec->codec_id = AV_CODEC_ID_PCM_F32LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE; break; case AV_CODEC_ID_PCM_F64BE: - st->codec->codec_id = AV_CODEC_ID_PCM_F64LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_F64LE; break; default: break; @@ -1053,9 +1061,9 @@ static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom) uint8_t color_range = avio_r8(pb) >> 7; av_log(c->fc, AV_LOG_TRACE, " full %"PRIu8"", color_range); if (color_range) - st->codec->color_range = AVCOL_RANGE_JPEG; + st->codecpar->color_range = AVCOL_RANGE_JPEG; else - st->codec->color_range = AVCOL_RANGE_MPEG; + st->codecpar->color_range = AVCOL_RANGE_MPEG; /* 14496-12 references JPEG XR specs (rather than the more complete * 23001-8) so some adjusting is required */ if (color_primaries >= AVCOL_PRI_FILM) @@ -1066,26 +1074,26 @@ static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom) color_trc = AVCOL_TRC_UNSPECIFIED; if (color_matrix >= AVCOL_SPC_BT2020_NCL) color_matrix = AVCOL_SPC_UNSPECIFIED; - st->codec->color_primaries = color_primaries; - st->codec->color_trc = color_trc; - st->codec->colorspace = color_matrix; + st->codecpar->color_primaries = color_primaries; + st->codecpar->color_trc = color_trc; + st->codecpar->color_space = color_matrix; } else if (!strncmp(color_parameter_type, "nclc", 4)) { /* color primaries, Table 4-4 */ switch (color_primaries) { - case 1: st->codec->color_primaries = AVCOL_PRI_BT709; break; - case 5: st->codec->color_primaries = AVCOL_PRI_SMPTE170M; break; - case 6: st->codec->color_primaries = AVCOL_PRI_SMPTE240M; break; + case 1: st->codecpar->color_primaries = AVCOL_PRI_BT709; break; + case 5: st->codecpar->color_primaries = AVCOL_PRI_SMPTE170M; break; + case 6: st->codecpar->color_primaries = AVCOL_PRI_SMPTE240M; break; } /* color transfer, Table 4-5 */ switch (color_trc) { - case 1: st->codec->color_trc = AVCOL_TRC_BT709; break; - case 7: st->codec->color_trc = AVCOL_TRC_SMPTE240M; break; + case 1: st->codecpar->color_trc = AVCOL_TRC_BT709; break; + case 7: st->codecpar->color_trc = AVCOL_TRC_SMPTE240M; break; } /* color matrix, Table 4-6 */ switch (color_matrix) { - case 1: st->codec->colorspace = AVCOL_SPC_BT709; break; - case 6: st->codec->colorspace = AVCOL_SPC_BT470BG; break; - case 7: st->codec->colorspace = AVCOL_SPC_SMPTE240M; break; + case 1: st->codecpar->color_space = AVCOL_SPC_BT709; break; + case 6: st->codecpar->color_space = AVCOL_SPC_BT470BG; break; + case 7: st->codecpar->color_space = AVCOL_SPC_SMPTE240M; break; } } av_log(c->fc, AV_LOG_TRACE, "\n"); @@ -1122,7 +1130,7 @@ static int mov_read_fiel(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (decoded_field_order == AV_FIELD_UNKNOWN && mov_field_order) { av_log(NULL, AV_LOG_ERROR, "Unknown MOV field order 0x%04x\n", mov_field_order); } - st->codec->field_order = decoded_field_order; + st->codecpar->field_order = decoded_field_order; return 0; } @@ -1138,15 +1146,15 @@ static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (c->fc->nb_streams < 1) // will happen with jp2 files return 0; st= c->fc->streams[c->fc->nb_streams-1]; - size= (uint64_t)st->codec->extradata_size + atom.size + 8 + AV_INPUT_BUFFER_PADDING_SIZE; + size= (uint64_t)st->codecpar->extradata_size + atom.size + 8 + AV_INPUT_BUFFER_PADDING_SIZE; if (size > INT_MAX || (uint64_t)atom.size > INT_MAX) return AVERROR_INVALIDDATA; - if ((err = av_reallocp(&st->codec->extradata, size)) < 0) { - st->codec->extradata_size = 0; + if ((err = av_reallocp(&st->codecpar->extradata, size)) < 0) { + st->codecpar->extradata_size = 0; return err; } - buf = st->codec->extradata + st->codec->extradata_size; - st->codec->extradata_size= size - AV_INPUT_BUFFER_PADDING_SIZE; + buf = st->codecpar->extradata + st->codecpar->extradata_size; + st->codecpar->extradata_size= size - AV_INPUT_BUFFER_PADDING_SIZE; AV_WB32( buf , atom.size + 8); AV_WL32( buf + 4, atom.type); @@ -1169,15 +1177,15 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom) if ((uint64_t)atom.size > (1<<30)) return AVERROR_INVALIDDATA; - if (st->codec->codec_id == AV_CODEC_ID_QDM2 || st->codec->codec_id == AV_CODEC_ID_QDMC) { + if (st->codecpar->codec_id == AV_CODEC_ID_QDM2 || st->codecpar->codec_id == AV_CODEC_ID_QDMC) { // pass all frma atom to codec, needed at least for QDMC and QDM2 - av_free(st->codec->extradata); - st->codec->extradata = av_mallocz(atom.size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_free(st->codecpar->extradata); + st->codecpar->extradata = av_mallocz(atom.size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = atom.size; + st->codecpar->extradata_size = atom.size; - ret = ffio_read_size(pb, st->codec->extradata, atom.size); + ret = ffio_read_size(pb, st->codecpar->extradata, atom.size); if (ret < 0) return ret; } else if (atom.size > 8) { /* to read frma, esds atoms */ @@ -1213,13 +1221,13 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (type == MKTAG('f','i','e','l') && size == atom.size) return mov_read_default(c, pb, atom); } - av_free(st->codec->extradata); - st->codec->extradata = av_mallocz(atom.size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_free(st->codecpar->extradata); + st->codecpar->extradata = av_mallocz(atom.size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = atom.size; + st->codecpar->extradata_size = atom.size; - ret = ffio_read_size(pb, st->codec->extradata, atom.size); + ret = ffio_read_size(pb, st->codecpar->extradata, atom.size); if (ret < 0) return ret; @@ -1243,14 +1251,14 @@ static int mov_read_dvc1(MOVContext *c, AVIOContext *pb, MOVAtom atom) if ((profile_level & 0xf0) != 0xc0) return 0; - av_free(st->codec->extradata); - st->codec->extradata = av_mallocz(atom.size - 7 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_free(st->codecpar->extradata); + st->codecpar->extradata = av_mallocz(atom.size - 7 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = atom.size - 7; + st->codecpar->extradata_size = atom.size - 7; avio_seek(pb, 6, SEEK_CUR); - ret = ffio_read_size(pb, st->codec->extradata, st->codec->extradata_size); + ret = ffio_read_size(pb, st->codecpar->extradata, st->codecpar->extradata_size); if (ret < 0) return ret; @@ -1276,14 +1284,14 @@ static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom) if ((uint64_t)atom.size > (1<<30)) return AVERROR_INVALIDDATA; - av_free(st->codec->extradata); - st->codec->extradata = av_mallocz(atom.size - 40 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_free(st->codecpar->extradata); + st->codecpar->extradata = av_mallocz(atom.size - 40 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = atom.size - 40; + st->codecpar->extradata_size = atom.size - 40; avio_skip(pb, 40); - ret = ffio_read_size(pb, st->codec->extradata, atom.size - 40); + ret = ffio_read_size(pb, st->codecpar->extradata, atom.size - 40); if (ret < 0) return ret; @@ -1356,24 +1364,24 @@ static int mov_codec_id(AVStream *st, uint32_t format) (format & 0xFFFF) == 'T' + ('S' << 8))) id = ff_codec_get_id(ff_codec_wav_tags, av_bswap32(format) & 0xFFFF); - if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO && id > 0) { - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - } else if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO && + if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO && id > 0) { + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + } else if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO && /* skip old asf mpeg4 tag */ format && format != MKTAG('m','p','4','s')) { id = ff_codec_get_id(ff_codec_movvideo_tags, format); if (id <= 0) id = ff_codec_get_id(ff_codec_bmp_tags, format); if (id > 0) - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - else if (st->codec->codec_type == AVMEDIA_TYPE_DATA) { + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { id = ff_codec_get_id(ff_codec_movsubtitle_tags, format); if (id > 0) - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; } } - st->codec->codec_tag = format; + st->codecpar->codec_tag = format; return id; } @@ -1392,8 +1400,8 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb, avio_rb32(pb); /* temporal quality */ avio_rb32(pb); /* spatial quality */ - st->codec->width = avio_rb16(pb); /* width */ - st->codec->height = avio_rb16(pb); /* height */ + st->codecpar->width = avio_rb16(pb); /* width */ + st->codecpar->height = avio_rb16(pb); /* height */ avio_rb32(pb); /* horiz resolution */ avio_rb32(pb); /* vert resolution */ @@ -1412,19 +1420,19 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb, /* codec_tag YV12 triggers an UV swap in rawdec.c */ if (!memcmp(codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25)) - st->codec->codec_tag = MKTAG('I', '4', '2', '0'); + st->codecpar->codec_tag = MKTAG('I', '4', '2', '0'); /* Flash Media Server uses tag H263 with Sorenson Spark */ - if (st->codec->codec_tag == MKTAG('H','2','6','3') && + if (st->codecpar->codec_tag == MKTAG('H','2','6','3') && !memcmp(codec_name, "Sorenson H263", 13)) - st->codec->codec_id = AV_CODEC_ID_FLV1; + st->codecpar->codec_id = AV_CODEC_ID_FLV1; - st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */ + st->codecpar->bits_per_coded_sample = avio_rb16(pb); /* depth */ color_table_id = avio_rb16(pb); /* colortable id */ av_log(c->fc, AV_LOG_TRACE, "depth %d, ctab id %d\n", - st->codec->bits_per_coded_sample, color_table_id); + st->codecpar->bits_per_coded_sample, color_table_id); /* figure out the palette situation */ - color_depth = st->codec->bits_per_coded_sample & 0x1F; - color_greyscale = st->codec->bits_per_coded_sample & 0x20; + color_depth = st->codecpar->bits_per_coded_sample & 0x1F; + color_greyscale = st->codecpar->bits_per_coded_sample & 0x20; /* if the depth is 2, 4, or 8 bpp, file is palettized */ if ((color_depth == 2) || (color_depth == 4) || (color_depth == 8)) { @@ -1435,7 +1443,7 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb, if (color_greyscale) { int color_index, color_dec; /* compute the greyscale palette */ - st->codec->bits_per_coded_sample = color_depth; + st->codecpar->bits_per_coded_sample = color_depth; color_count = 1 << color_depth; color_index = 255; color_dec = 256 / (color_count - 1); @@ -1498,14 +1506,14 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, avio_rb16(pb); /* revision level */ avio_rb32(pb); /* vendor */ - st->codec->channels = avio_rb16(pb); /* channel count */ - st->codec->bits_per_coded_sample = avio_rb16(pb); /* sample size */ - av_log(c->fc, AV_LOG_TRACE, "audio channels %d\n", st->codec->channels); + st->codecpar->channels = avio_rb16(pb); /* channel count */ + st->codecpar->bits_per_coded_sample = avio_rb16(pb); /* sample size */ + av_log(c->fc, AV_LOG_TRACE, "audio channels %d\n", st->codecpar->channels); sc->audio_cid = avio_rb16(pb); avio_rb16(pb); /* packet size = 0 */ - st->codec->sample_rate = ((avio_rb32(pb) >> 16)); + st->codecpar->sample_rate = ((avio_rb32(pb) >> 16)); // Read QT version 1 fields. In version 0 these do not exist. av_log(c->fc, AV_LOG_TRACE, "version =%d, isom =%d\n", version, c->isom); @@ -1517,22 +1525,22 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, avio_rb32(pb); /* bytes per sample */ } else if (version == 2) { avio_rb32(pb); /* sizeof struct only */ - st->codec->sample_rate = av_int2double(avio_rb64(pb)); - st->codec->channels = avio_rb32(pb); + st->codecpar->sample_rate = av_int2double(avio_rb64(pb)); + st->codecpar->channels = avio_rb32(pb); avio_rb32(pb); /* always 0x7F000000 */ - st->codec->bits_per_coded_sample = avio_rb32(pb); + st->codecpar->bits_per_coded_sample = avio_rb32(pb); flags = avio_rb32(pb); /* lpcm format specific flag */ sc->bytes_per_frame = avio_rb32(pb); sc->samples_per_frame = avio_rb32(pb); - if (st->codec->codec_tag == MKTAG('l','p','c','m')) - st->codec->codec_id = - ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, + if (st->codecpar->codec_tag == MKTAG('l','p','c','m')) + st->codecpar->codec_id = + ff_mov_get_lpcm_codec_id(st->codecpar->bits_per_coded_sample, flags); } if (version == 0 || (version == 1 && sc->audio_cid != -2)) { /* can't correctly handle variable sized packet as audio unit */ - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: st->need_parsing = AVSTREAM_PARSE_FULL; @@ -1541,33 +1549,33 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, } } - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_PCM_S8: case AV_CODEC_ID_PCM_U8: - if (st->codec->bits_per_coded_sample == 16) - st->codec->codec_id = AV_CODEC_ID_PCM_S16BE; + if (st->codecpar->bits_per_coded_sample == 16) + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; break; case AV_CODEC_ID_PCM_S16LE: case AV_CODEC_ID_PCM_S16BE: - if (st->codec->bits_per_coded_sample == 8) - st->codec->codec_id = AV_CODEC_ID_PCM_S8; - else if (st->codec->bits_per_coded_sample == 24) - st->codec->codec_id = - st->codec->codec_id == AV_CODEC_ID_PCM_S16BE ? + if (st->codecpar->bits_per_coded_sample == 8) + st->codecpar->codec_id = AV_CODEC_ID_PCM_S8; + else if (st->codecpar->bits_per_coded_sample == 24) + st->codecpar->codec_id = + st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE ? AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE; break; /* set values for old format before stsd version 1 appeared */ case AV_CODEC_ID_MACE3: sc->samples_per_frame = 6; - sc->bytes_per_frame = 2 * st->codec->channels; + sc->bytes_per_frame = 2 * st->codecpar->channels; break; case AV_CODEC_ID_MACE6: sc->samples_per_frame = 6; - sc->bytes_per_frame = 1 * st->codec->channels; + sc->bytes_per_frame = 1 * st->codecpar->channels; break; case AV_CODEC_ID_ADPCM_IMA_QT: sc->samples_per_frame = 64; - sc->bytes_per_frame = 34 * st->codec->channels; + sc->bytes_per_frame = 34 * st->codecpar->channels; break; case AV_CODEC_ID_GSM: sc->samples_per_frame = 160; @@ -1577,10 +1585,10 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, break; } - bits_per_sample = av_get_bits_per_sample(st->codec->codec_id); + bits_per_sample = av_get_bits_per_sample(st->codecpar->codec_id); if (bits_per_sample) { - st->codec->bits_per_coded_sample = bits_per_sample; - sc->sample_size = (bits_per_sample >> 3) * st->codec->channels; + st->codecpar->bits_per_coded_sample = bits_per_sample; + sc->sample_size = (bits_per_sample >> 3) * st->codecpar->channels; } } @@ -1592,10 +1600,10 @@ static void mov_parse_stsd_subtitle(MOVContext *c, AVIOContext *pb, // color, fonts, and default styles, so fake an atom to read it MOVAtom fake_atom = { .size = size }; // mp4s contains a regular esds atom - if (st->codec->codec_tag != AV_RL32("mp4s")) + if (st->codecpar->codec_tag != AV_RL32("mp4s")) mov_read_glbl(c, pb, fake_atom); - st->codec->width = sc->width; - st->codec->height = sc->height; + st->codecpar->width = sc->width; + st->codecpar->height = sc->height; } static uint32_t yuv_to_rgba(uint32_t ycbcr) @@ -1617,15 +1625,15 @@ static uint32_t yuv_to_rgba(uint32_t ycbcr) static int mov_rewrite_dvd_sub_extradata(AVStream *st) { char buf[256] = {0}; - uint8_t *src = st->codec->extradata; + uint8_t *src = st->codecpar->extradata; int i; - if (st->codec->extradata_size != 64) + if (st->codecpar->extradata_size != 64) return 0; - if (st->codec->width > 0 && st->codec->height > 0) + if (st->codecpar->width > 0 && st->codecpar->height > 0) snprintf(buf, sizeof(buf), "size: %dx%d\n", - st->codec->width, st->codec->height); + st->codecpar->width, st->codecpar->height); av_strlcat(buf, "palette: ", sizeof(buf)); for (i = 0; i < 16; i++) { @@ -1638,13 +1646,13 @@ static int mov_rewrite_dvd_sub_extradata(AVStream *st) if (av_strlcat(buf, "\n", sizeof(buf)) >= sizeof(buf)) return 0; - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; - st->codec->extradata = av_mallocz(strlen(buf) + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; + st->codecpar->extradata = av_mallocz(strlen(buf) + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = strlen(buf); - memcpy(st->codec->extradata, buf, st->codec->extradata_size); + st->codecpar->extradata_size = strlen(buf); + memcpy(st->codecpar->extradata, buf, st->codecpar->extradata_size); return 0; } @@ -1655,12 +1663,12 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb, { int ret; - if (st->codec->codec_tag == MKTAG('t','m','c','d')) { - st->codec->extradata_size = size; - st->codec->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (st->codecpar->codec_tag == MKTAG('t','m','c','d')) { + st->codecpar->extradata_size = size; + st->codecpar->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - ret = ffio_read_size(pb, st->codec->extradata, size); + ret = ffio_read_size(pb, st->codecpar->extradata, size); if (ret < 0) return ret; } else { @@ -1673,12 +1681,12 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb, static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, AVStream *st, MOVStreamContext *sc) { - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - !st->codec->sample_rate && sc->time_scale > 1) - st->codec->sample_rate = sc->time_scale; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + !st->codecpar->sample_rate && sc->time_scale > 1) + st->codecpar->sample_rate = sc->time_scale; /* special codec parameters handling */ - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { #if CONFIG_DV_DEMUXER case AV_CODEC_ID_DVAUDIO: c->dv_fctx = avformat_alloc_context(); @@ -1692,40 +1700,40 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, return AVERROR(ENOMEM); } sc->dv_audio_container = 1; - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; break; #endif /* no ifdef since parameters are always those */ case AV_CODEC_ID_QCELP: - st->codec->channels = 1; + st->codecpar->channels = 1; // force sample rate for qcelp when not stored in mov - if (st->codec->codec_tag != MKTAG('Q','c','l','p')) - st->codec->sample_rate = 8000; + if (st->codecpar->codec_tag != MKTAG('Q','c','l','p')) + st->codecpar->sample_rate = 8000; break; case AV_CODEC_ID_AMR_NB: - st->codec->channels = 1; + st->codecpar->channels = 1; /* force sample rate for amr, stsd in 3gp does not store sample rate */ - st->codec->sample_rate = 8000; + st->codecpar->sample_rate = 8000; break; case AV_CODEC_ID_AMR_WB: - st->codec->channels = 1; - st->codec->sample_rate = 16000; + st->codecpar->channels = 1; + st->codecpar->sample_rate = 16000; break; case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: /* force type after stsd for m1a hdlr */ - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; break; case AV_CODEC_ID_GSM: case AV_CODEC_ID_ADPCM_MS: case AV_CODEC_ID_ADPCM_IMA_WAV: case AV_CODEC_ID_ILBC: - st->codec->block_align = sc->bytes_per_frame; + st->codecpar->block_align = sc->bytes_per_frame; break; case AV_CODEC_ID_ALAC: - if (st->codec->extradata_size == 36) { - st->codec->channels = AV_RB8 (st->codec->extradata + 21); - st->codec->sample_rate = AV_RB32(st->codec->extradata + 32); + if (st->codecpar->extradata_size == 36) { + st->codecpar->channels = AV_RB8 (st->codecpar->extradata + 21); + st->codecpar->sample_rate = AV_RB32(st->codecpar->extradata + 32); } break; case AV_CODEC_ID_VC1: @@ -1794,27 +1802,27 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) return AVERROR_INVALIDDATA; } - if (mov_skip_multiple_stsd(c, pb, st->codec->codec_tag, format, + if (mov_skip_multiple_stsd(c, pb, st->codecpar->codec_tag, format, size - (avio_tell(pb) - start_pos))) continue; - sc->pseudo_stream_id = st->codec->codec_tag ? -1 : pseudo_stream_id; + sc->pseudo_stream_id = st->codecpar->codec_tag ? -1 : pseudo_stream_id; sc->dref_id= dref_id; id = mov_codec_id(st, format); av_log(c->fc, AV_LOG_TRACE, "size=%"PRId64" format=0x%08x codec_type=%d\n", - size, format, st->codec->codec_type); + size, format, st->codecpar->codec_type); - if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) { - st->codec->codec_id = id; + if (st->codecpar->codec_type==AVMEDIA_TYPE_VIDEO) { + st->codecpar->codec_id = id; mov_parse_stsd_video(c, pb, st, sc); - } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) { - st->codec->codec_id = id; + } else if (st->codecpar->codec_type==AVMEDIA_TYPE_AUDIO) { + st->codecpar->codec_id = id; mov_parse_stsd_audio(c, pb, st, sc); - } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){ - st->codec->codec_id = id; + } else if (st->codecpar->codec_type==AVMEDIA_TYPE_SUBTITLE){ + st->codecpar->codec_id = id; mov_parse_stsd_subtitle(c, pb, st, sc, size - (avio_tell(pb) - start_pos)); } else { @@ -2216,12 +2224,12 @@ static void mov_build_index(MOVContext *mov, AVStream *st) /* more than 16 frames delay, dts are likely wrong this happens with files created by iMovie */ sc->wrong_dts = 1; - st->codec->has_b_frames = 1; + st->internal->avctx->has_b_frames = 1; } } /* only use old uncompressed audio chunk demuxing when stts specifies it */ - if (!(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && + if (!(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && sc->stts_count == 1 && sc->stts_data[0].duration == 1)) { unsigned int current_sample = 0; unsigned int stts_sample = 0; @@ -2304,7 +2312,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } if (st->duration > 0) - st->codec->bit_rate = stream_size*8*sc->time_scale/st->duration; + st->codecpar->bit_rate = stream_size*8*sc->time_scale/st->duration; } else { unsigned chunk_samples, total = 0; @@ -2458,7 +2466,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!sc) return AVERROR(ENOMEM); st->priv_data = sc; - st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; sc->ffindex = st->index; if ((ret = mov_read_default(c, pb, atom)) < 0) @@ -2504,23 +2512,23 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) } else sc->pb = c->fc->pb; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (!st->sample_aspect_ratio.num && - (st->codec->width != sc->width || st->codec->height != sc->height)) { - st->sample_aspect_ratio = av_d2q(((double)st->codec->height * sc->width) / - ((double)st->codec->width * sc->height), INT_MAX); + (st->codecpar->width != sc->width || st->codecpar->height != sc->height)) { + st->sample_aspect_ratio = av_d2q(((double)st->codecpar->height * sc->width) / + ((double)st->codecpar->width * sc->height), INT_MAX); } } // done for ai5q, ai52, ai55, ai1q, ai12 and ai15. - if (!st->codec->extradata_size && st->codec->codec_id == AV_CODEC_ID_H264 && - TAG_IS_AVCI(st->codec->codec_tag)) { + if (!st->codecpar->extradata_size && st->codecpar->codec_id == AV_CODEC_ID_H264 && + TAG_IS_AVCI(st->codecpar->codec_tag)) { ret = ff_generate_avci_extradata(st); if (ret < 0) return ret; } - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { #if CONFIG_H261_DECODER case AV_CODEC_ID_H261: #endif @@ -2530,8 +2538,8 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) #if CONFIG_MPEG4_DECODER case AV_CODEC_ID_MPEG4: #endif - st->codec->width = 0; /* let decoder init width/height */ - st->codec->height= 0; + st->codecpar->width = 0; /* let decoder init width/height */ + st->codecpar->height= 0; break; case AV_CODEC_ID_MP3: st->need_parsing = AVSTREAM_PARSE_FULL; @@ -2923,7 +2931,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->ctts_data[sc->ctts_count].duration = (flags & MOV_TRUN_SAMPLE_CTS) ? avio_rb32(pb) : 0; sc->ctts_count++; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) keyframe = 1; else keyframe = @@ -3396,12 +3404,12 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { - if (st->codec->width <= 0 || st->codec->height <= 0) { - st->codec->width = sc->width; - st->codec->height = sc->height; + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { + if (st->codecpar->width <= 0 || st->codecpar->height <= 0) { + st->codecpar->width = sc->width; + st->codecpar->height = sc->height; } - if (st->codec->codec_id == AV_CODEC_ID_DVD_SUBTITLE) { + if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) { if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0) return err; } @@ -3413,7 +3421,7 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; if (st->duration > 0) - st->codec->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration; + st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration; } } @@ -3421,7 +3429,7 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: err = ff_replaygain_export(st, s->metadata); if (err < 0) { diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 94b93cf39c..19f657ad7c 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -586,9 +586,9 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, } if (layout_tag == 0) { if (label_mask) - st->codec->channel_layout = label_mask; + st->codecpar->channel_layout = label_mask; } else - st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap); + st->codecpar->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap); return 0; } diff --git a/libavformat/movenc-test.c b/libavformat/movenc-test.c index cfd07aa9ce..2847522f50 100644 --- a/libavformat/movenc-test.c +++ b/libavformat/movenc-test.c @@ -159,33 +159,33 @@ static void init_fps(int bf, int audio_preroll, int fps) st = avformat_new_stream(ctx, NULL); if (!st) exit(1); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_H264; - st->codec->width = 640; - st->codec->height = 480; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_H264; + st->codecpar->width = 640; + st->codecpar->height = 480; st->time_base.num = 1; st->time_base.den = 30; - st->codec->extradata_size = sizeof(h264_extradata); - st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata_size = sizeof(h264_extradata); + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) exit(1); - memcpy(st->codec->extradata, h264_extradata, sizeof(h264_extradata)); + memcpy(st->codecpar->extradata, h264_extradata, sizeof(h264_extradata)); video_st = st; st = avformat_new_stream(ctx, NULL); if (!st) exit(1); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_AAC; - st->codec->sample_rate = 44100; - st->codec->channels = 2; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_AAC; + st->codecpar->sample_rate = 44100; + st->codecpar->channels = 2; st->time_base.num = 1; st->time_base.den = 44100; - st->codec->extradata_size = sizeof(aac_extradata); - st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata_size = sizeof(aac_extradata); + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) exit(1); - memcpy(st->codec->extradata, aac_extradata, sizeof(aac_extradata)); + memcpy(st->codecpar->extradata, aac_extradata, sizeof(aac_extradata)); audio_st = st; if (avformat_write_header(ctx, &opts) < 0) @@ -195,9 +195,9 @@ static void init_fps(int bf, int audio_preroll, int fps) frames = 0; gop_size = 30; duration = video_st->time_base.den / fps; - audio_duration = 1024LL * audio_st->time_base.den / audio_st->codec->sample_rate; + audio_duration = 1024LL * audio_st->time_base.den / audio_st->codecpar->sample_rate; if (audio_preroll) - audio_preroll = 2048LL * audio_st->time_base.den / audio_st->codec->sample_rate; + audio_preroll = 2048LL * audio_st->time_base.den / audio_st->codecpar->sample_rate; bframes = bf; video_dts = bframes ? -duration : 0; diff --git a/libavformat/movenc.c b/libavformat/movenc.c index c91286350c..446c1ad2ee 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -290,8 +290,8 @@ static int mov_write_ac3_tag(AVIOContext *pb, MOVTrack *track) */ static int mov_write_extradata_tag(AVIOContext *pb, MOVTrack *track) { - avio_write(pb, track->enc->extradata, track->enc->extradata_size); - return track->enc->extradata_size; + avio_write(pb, track->par->extradata, track->par->extradata_size); + return track->par->extradata_size; } static void put_descr(AVIOContext *pb, int tag, unsigned int size) @@ -322,18 +322,18 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic put_descr(pb, 0x04, 13 + decoder_specific_info_len); // Object type indication - if ((track->enc->codec_id == AV_CODEC_ID_MP2 || - track->enc->codec_id == AV_CODEC_ID_MP3) && - track->enc->sample_rate > 24000) + if ((track->par->codec_id == AV_CODEC_ID_MP2 || + track->par->codec_id == AV_CODEC_ID_MP3) && + track->par->sample_rate > 24000) avio_w8(pb, 0x6B); // 11172-3 else - avio_w8(pb, ff_codec_get_tag(ff_mp4_obj_type, track->enc->codec_id)); + avio_w8(pb, ff_codec_get_tag(ff_mp4_obj_type, track->par->codec_id)); // the following fields is made of 6 bits to identify the streamtype (4 for video, 5 for audio) // plus 1 bit to indicate upstream and 1 bit set to 1 (reserved) - if (track->enc->codec_id == AV_CODEC_ID_DVD_SUBTITLE) + if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE) avio_w8(pb, (0x38 << 2) | 1); // flags (= NeroSubpicStream) - else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) + else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) avio_w8(pb, 0x15); // flags (= Audiostream) else avio_w8(pb, 0x11); // flags (= Visualstream) @@ -343,7 +343,7 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic avio_wb24(pb, props ? props->buffer_size / 8 : 0); // Buffersize DB - avio_wb32(pb, props ? FFMAX(props->max_bitrate, props->avg_bitrate) : track->enc->bit_rate); // maxbitrate (FIXME should be max rate in any 1 sec window) + avio_wb32(pb, props ? FFMAX(props->max_bitrate, props->avg_bitrate) : track->par->bit_rate); // maxbitrate (FIXME should be max rate in any 1 sec window) if (!props || !props->min_bitrate || props->max_bitrate != props->min_bitrate) avio_wb32(pb, 0); // vbr else @@ -361,35 +361,35 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic return update_size(pb, pos); } -static int mov_write_ms_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_ms_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); avio_wl32(pb, track->tag); // store it byteswapped - track->enc->codec_tag = av_bswap16(track->tag >> 16); - ff_put_wav_header(pb, track->enc); + track->par->codec_tag = av_bswap16(track->tag >> 16); + ff_put_wav_header(s, pb, track->st->codecpar); return update_size(pb, pos); } -static int mov_write_wfex_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_wfex_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); ffio_wfourcc(pb, "wfex"); - ff_put_wav_header(pb, track->enc); + ff_put_wav_header(s, pb, track->st->codecpar); return update_size(pb, pos); } -static int mov_write_chan_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_chan_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { uint32_t layout_tag, bitmap; int64_t pos = avio_tell(pb); - layout_tag = ff_mov_get_channel_layout_tag(track->enc->codec_id, - track->enc->channel_layout, + layout_tag = ff_mov_get_channel_layout_tag(track->par->codec_id, + track->par->channel_layout, &bitmap); if (!layout_tag) { - av_log(track->enc, AV_LOG_WARNING, "not writing 'chan' tag due to " + av_log(s, AV_LOG_WARNING, "not writing 'chan' tag due to " "lack of channel information\n"); return 0; } @@ -405,7 +405,7 @@ static int mov_write_chan_tag(AVIOContext *pb, MOVTrack *track) return update_size(pb, pos); } -static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_wave_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); @@ -416,21 +416,21 @@ static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "frma"); avio_wl32(pb, track->tag); - if (track->enc->codec_id == AV_CODEC_ID_AAC) { + if (track->par->codec_id == AV_CODEC_ID_AAC) { /* useless atom needed by mplayer, ipod, not needed by quicktime */ avio_wb32(pb, 12); /* size */ ffio_wfourcc(pb, "mp4a"); avio_wb32(pb, 0); mov_write_esds_tag(pb, track); - } else if (track->enc->codec_id == AV_CODEC_ID_AMR_NB) { + } else if (track->par->codec_id == AV_CODEC_ID_AMR_NB) { mov_write_amr_tag(pb, track); - } else if (track->enc->codec_id == AV_CODEC_ID_AC3) { + } else if (track->par->codec_id == AV_CODEC_ID_AC3) { mov_write_ac3_tag(pb, track); - } else if (track->enc->codec_id == AV_CODEC_ID_ALAC) { + } else if (track->par->codec_id == AV_CODEC_ID_ALAC) { mov_write_extradata_tag(pb, track); - } else if (track->enc->codec_id == AV_CODEC_ID_ADPCM_MS || - track->enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { - mov_write_ms_tag(pb, track); + } else if (track->par->codec_id == AV_CODEC_ID_ADPCM_MS || + track->par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { + mov_write_ms_tag(s, pb, track); } avio_wb32(pb, 8); /* size */ @@ -609,14 +609,14 @@ static int get_samples_per_packet(MOVTrack *track) return first_duration; } -static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); int version = 0; uint32_t tag = track->tag; if (track->mode == MODE_MOV) { - if (mov_get_lpcm_flags(track->enc->codec_id)) + if (mov_get_lpcm_flags(track->par->codec_id)) tag = AV_RL32("lpcm"); version = 2; } @@ -639,11 +639,11 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) avio_wb16(pb, 0); avio_wb32(pb, 0x00010000); avio_wb32(pb, 72); - avio_wb64(pb, av_double2int(track->enc->sample_rate)); - avio_wb32(pb, track->enc->channels); + avio_wb64(pb, av_double2int(track->par->sample_rate)); + avio_wb32(pb, track->par->channels); avio_wb32(pb, 0x7F000000); - avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id)); - avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id)); + avio_wb32(pb, av_get_bits_per_sample(track->par->codec_id)); + avio_wb32(pb, mov_get_lpcm_flags(track->par->codec_id)); avio_wb32(pb, track->sample_size); avio_wb32(pb, get_samples_per_packet(track)); } else { @@ -653,34 +653,34 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) avio_wb16(pb, 0); avio_wb16(pb, 0); /* packet size (= 0) */ - avio_wb16(pb, track->enc->sample_rate <= UINT16_MAX ? - track->enc->sample_rate : 0); + avio_wb16(pb, track->par->sample_rate <= UINT16_MAX ? + track->par->sample_rate : 0); avio_wb16(pb, 0); /* Reserved */ } if (track->mode == MODE_MOV && - (track->enc->codec_id == AV_CODEC_ID_AAC || - track->enc->codec_id == AV_CODEC_ID_AC3 || - track->enc->codec_id == AV_CODEC_ID_AMR_NB || - track->enc->codec_id == AV_CODEC_ID_ALAC || - track->enc->codec_id == AV_CODEC_ID_ADPCM_MS || - track->enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV)) - mov_write_wave_tag(pb, track); + (track->par->codec_id == AV_CODEC_ID_AAC || + track->par->codec_id == AV_CODEC_ID_AC3 || + track->par->codec_id == AV_CODEC_ID_AMR_NB || + track->par->codec_id == AV_CODEC_ID_ALAC || + track->par->codec_id == AV_CODEC_ID_ADPCM_MS || + track->par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV)) + mov_write_wave_tag(s, pb, track); else if (track->tag == MKTAG('m','p','4','a')) mov_write_esds_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_AMR_NB) + else if (track->par->codec_id == AV_CODEC_ID_AMR_NB) mov_write_amr_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_AC3) + else if (track->par->codec_id == AV_CODEC_ID_AC3) mov_write_ac3_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_ALAC) + else if (track->par->codec_id == AV_CODEC_ID_ALAC) mov_write_extradata_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_WMAPRO) - mov_write_wfex_tag(pb, track); + else if (track->par->codec_id == AV_CODEC_ID_WMAPRO) + mov_write_wfex_tag(s, pb, track); else if (track->vos_len > 0) mov_write_glbl_tag(pb, track); - if (track->mode == MODE_MOV && track->enc->codec_type == AVMEDIA_TYPE_AUDIO) - mov_write_chan_tag(pb, track); + if (track->mode == MODE_MOV && track->par->codec_type == AVMEDIA_TYPE_AUDIO) + mov_write_chan_tag(s, pb, track); return update_size(pb, pos); } @@ -753,18 +753,18 @@ static int mov_write_avid_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "ARES"); ffio_wfourcc(pb, "0001"); avio_wb32(pb, AV_RB32(track->vos_data + 0x28)); /* dnxhd cid, some id ? */ - avio_wb32(pb, track->enc->width); + avio_wb32(pb, track->par->width); /* values below are based on samples created with quicktime and avid codecs */ if (track->vos_data[5] & 2) { // interlaced - avio_wb32(pb, track->enc->height / 2); + avio_wb32(pb, track->par->height / 2); avio_wb32(pb, 2); /* unknown */ avio_wb32(pb, 0); /* unknown */ avio_wb32(pb, 4); /* unknown */ } else { - avio_wb32(pb, track->enc->height); + avio_wb32(pb, track->par->height); avio_wb32(pb, 1); /* unknown */ avio_wb32(pb, 0); /* unknown */ - if (track->enc->height == 1080) + if (track->par->height == 1080) avio_wb32(pb, 5); /* unknown */ else avio_wb32(pb, 6); /* unknown */ @@ -780,20 +780,20 @@ static int mov_write_avid_tag(AVIOContext *pb, MOVTrack *track) static int mp4_get_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; + int tag = track->par->codec_tag; - if (!ff_codec_get_tag(ff_mp4_obj_type, track->enc->codec_id)) + if (!ff_codec_get_tag(ff_mp4_obj_type, track->par->codec_id)) return 0; - if (track->enc->codec_id == AV_CODEC_ID_H264) tag = MKTAG('a','v','c','1'); - else if (track->enc->codec_id == AV_CODEC_ID_HEVC) tag = MKTAG('h','e','v','1'); - else if (track->enc->codec_id == AV_CODEC_ID_AC3) tag = MKTAG('a','c','-','3'); - else if (track->enc->codec_id == AV_CODEC_ID_DIRAC) tag = MKTAG('d','r','a','c'); - else if (track->enc->codec_id == AV_CODEC_ID_MOV_TEXT) tag = MKTAG('t','x','3','g'); - else if (track->enc->codec_id == AV_CODEC_ID_VC1) tag = MKTAG('v','c','-','1'); - else if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) tag = MKTAG('m','p','4','v'); - else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) tag = MKTAG('m','p','4','a'); - else if (track->enc->codec_id == AV_CODEC_ID_DVD_SUBTITLE) tag = MKTAG('m','p','4','s'); + if (track->par->codec_id == AV_CODEC_ID_H264) tag = MKTAG('a','v','c','1'); + else if (track->par->codec_id == AV_CODEC_ID_HEVC) tag = MKTAG('h','e','v','1'); + else if (track->par->codec_id == AV_CODEC_ID_AC3) tag = MKTAG('a','c','-','3'); + else if (track->par->codec_id == AV_CODEC_ID_DIRAC) tag = MKTAG('d','r','a','c'); + else if (track->par->codec_id == AV_CODEC_ID_MOV_TEXT) tag = MKTAG('t','x','3','g'); + else if (track->par->codec_id == AV_CODEC_ID_VC1) tag = MKTAG('v','c','-','1'); + else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) tag = MKTAG('m','p','4','v'); + else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) tag = MKTAG('m','p','4','a'); + else if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE) tag = MKTAG('m','p','4','s'); return tag; } @@ -811,13 +811,13 @@ static const AVCodecTag codec_ipod_tags[] = { static int ipod_get_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; + int tag = track->par->codec_tag; // keep original tag for subs, ipod supports both formats - if (!(track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE && + if (!(track->par->codec_type == AVMEDIA_TYPE_SUBTITLE && (tag == MKTAG('t', 'x', '3', 'g') || tag == MKTAG('t', 'e', 'x', 't')))) - tag = ff_codec_get_tag(codec_ipod_tags, track->enc->codec_id); + tag = ff_codec_get_tag(codec_ipod_tags, track->par->codec_id); if (!av_match_ext(s->filename, "m4a") && !av_match_ext(s->filename, "m4v")) av_log(s, AV_LOG_WARNING, "Warning, extension is not .m4a nor .m4v " @@ -830,17 +830,17 @@ static int mov_get_dv_codec_tag(AVFormatContext *s, MOVTrack *track) { int tag; - if (track->enc->width == 720) /* SD */ - if (track->enc->height == 480) /* NTSC */ - if (track->enc->pix_fmt == AV_PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n'); + if (track->par->width == 720) /* SD */ + if (track->par->height == 480) /* NTSC */ + if (track->par->format == AV_PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n'); else tag = MKTAG('d','v','c',' '); - else if (track->enc->pix_fmt == AV_PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p'); - else if (track->enc->pix_fmt == AV_PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p'); + else if (track->par->format == AV_PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p'); + else if (track->par->format == AV_PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p'); else tag = MKTAG('d','v','p','p'); - else if (track->enc->height == 720) /* HD 720 line */ + else if (track->par->height == 720) /* HD 720 line */ if (track->st->time_base.den == 50) tag = MKTAG('d','v','h','q'); else tag = MKTAG('d','v','h','p'); - else if (track->enc->height == 1080) /* HD 1080 line */ + else if (track->par->height == 1080) /* HD 1080 line */ if (track->st->time_base.den == 25) tag = MKTAG('d','v','h','5'); else tag = MKTAG('d','v','h','6'); else { @@ -874,13 +874,13 @@ static const struct { static int mov_get_rawvideo_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; + int tag = track->par->codec_tag; int i; for (i = 0; i < FF_ARRAY_ELEMS(mov_pix_fmt_tags); i++) { - if (track->enc->pix_fmt == mov_pix_fmt_tags[i].pix_fmt) { + if (track->par->format == mov_pix_fmt_tags[i].pix_fmt) { tag = mov_pix_fmt_tags[i].tag; - track->enc->bits_per_coded_sample = mov_pix_fmt_tags[i].bps; + track->par->bits_per_coded_sample = mov_pix_fmt_tags[i].bps; break; } } @@ -890,37 +890,37 @@ static int mov_get_rawvideo_codec_tag(AVFormatContext *s, MOVTrack *track) static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; + int tag = track->par->codec_tag; if (!tag || (s->strict_std_compliance >= FF_COMPLIANCE_NORMAL && - (track->enc->codec_id == AV_CODEC_ID_DVVIDEO || - track->enc->codec_id == AV_CODEC_ID_RAWVIDEO || - track->enc->codec_id == AV_CODEC_ID_H263 || - av_get_bits_per_sample(track->enc->codec_id)))) { // pcm audio - if (track->enc->codec_id == AV_CODEC_ID_DVVIDEO) + (track->par->codec_id == AV_CODEC_ID_DVVIDEO || + track->par->codec_id == AV_CODEC_ID_RAWVIDEO || + track->par->codec_id == AV_CODEC_ID_H263 || + av_get_bits_per_sample(track->par->codec_id)))) { // pcm audio + if (track->par->codec_id == AV_CODEC_ID_DVVIDEO) tag = mov_get_dv_codec_tag(s, track); - else if (track->enc->codec_id == AV_CODEC_ID_RAWVIDEO) + else if (track->par->codec_id == AV_CODEC_ID_RAWVIDEO) tag = mov_get_rawvideo_codec_tag(s, track); - else if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { - tag = ff_codec_get_tag(ff_codec_movvideo_tags, track->enc->codec_id); + else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { + tag = ff_codec_get_tag(ff_codec_movvideo_tags, track->par->codec_id); if (!tag) { // if no mac fcc found, try with Microsoft tags - tag = ff_codec_get_tag(ff_codec_bmp_tags, track->enc->codec_id); + tag = ff_codec_get_tag(ff_codec_bmp_tags, track->par->codec_id); if (tag) av_log(s, AV_LOG_WARNING, "Using MS style video codec tag, " "the file may be unplayable!\n"); } - } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { - tag = ff_codec_get_tag(ff_codec_movaudio_tags, track->enc->codec_id); + } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) { + tag = ff_codec_get_tag(ff_codec_movaudio_tags, track->par->codec_id); if (!tag) { // if no mac fcc found, try with Microsoft tags - int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->enc->codec_id); + int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->par->codec_id); if (ms_tag) { tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff)); av_log(s, AV_LOG_WARNING, "Using MS style audio codec tag, " "the file may be unplayable!\n"); } } - } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) - tag = ff_codec_get_tag(ff_codec_movsubtitle_tags, track->enc->codec_id); + } else if (track->par->codec_type == AVMEDIA_TYPE_SUBTITLE) + tag = ff_codec_get_tag(ff_codec_movsubtitle_tags, track->par->codec_id); } return tag; @@ -954,14 +954,14 @@ static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) tag = mp4_get_codec_tag(s, track); else if (track->mode == MODE_ISM) { tag = mp4_get_codec_tag(s, track); - if (!tag && track->enc->codec_id == AV_CODEC_ID_WMAPRO) + if (!tag && track->par->codec_id == AV_CODEC_ID_WMAPRO) tag = MKTAG('w', 'm', 'a', ' '); } else if (track->mode == MODE_IPOD) tag = ipod_get_codec_tag(s, track); else if (track->mode & MODE_3GP) - tag = ff_codec_get_tag(codec_3gp_tags, track->enc->codec_id); + tag = ff_codec_get_tag(codec_3gp_tags, track->par->codec_id); else if (track->mode == MODE_F4V) - tag = ff_codec_get_tag(codec_f4v_tags, track->enc->codec_id); + tag = ff_codec_get_tag(codec_f4v_tags, track->par->codec_id); else tag = mov_get_codec_tag(s, track); @@ -991,8 +991,8 @@ static const uint16_t fiel_data[] = { static int mov_write_fiel_tag(AVIOContext *pb, MOVTrack *track) { unsigned mov_field_order = 0; - if (track->enc->field_order < FF_ARRAY_ELEMS(fiel_data)) - mov_field_order = fiel_data[track->enc->field_order]; + if (track->par->field_order < FF_ARRAY_ELEMS(fiel_data)) + mov_field_order = fiel_data[track->par->field_order]; else return 0; avio_wb32(pb, 10); @@ -1010,10 +1010,10 @@ static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track) avio_wb16(pb, 0); /* Reserved */ avio_wb16(pb, 1); /* Data-reference index */ - if (track->enc->codec_id == AV_CODEC_ID_DVD_SUBTITLE) + if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE) mov_write_esds_tag(pb, track); - else if (track->enc->extradata_size) - avio_write(pb, track->enc->extradata, track->enc->extradata_size); + else if (track->par->extradata_size) + avio_write(pb, track->par->extradata, track->par->extradata_size); return update_size(pb, pos); } @@ -1021,8 +1021,8 @@ static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track) static int mov_write_pasp_tag(AVIOContext *pb, MOVTrack *track) { AVRational sar; - av_reduce(&sar.num, &sar.den, track->enc->sample_aspect_ratio.num, - track->enc->sample_aspect_ratio.den, INT_MAX); + av_reduce(&sar.num, &sar.den, track->par->sample_aspect_ratio.num, + track->par->sample_aspect_ratio.den, INT_MAX); avio_wb32(pb, 16); ffio_wfourcc(pb, "pasp"); @@ -1047,7 +1047,7 @@ static int mov_write_video_tag(AVIOContext *pb, MOVTrack *track) avio_wb16(pb, 0); /* Codec stream revision (=0) */ if (track->mode == MODE_MOV) { ffio_wfourcc(pb, "FFMP"); /* Vendor */ - if (track->enc->codec_id == AV_CODEC_ID_RAWVIDEO) { + if (track->par->codec_id == AV_CODEC_ID_RAWVIDEO) { avio_wb32(pb, 0); /* Temporal Quality */ avio_wb32(pb, 0x400); /* Spatial Quality = lossless*/ } else { @@ -1059,7 +1059,7 @@ static int mov_write_video_tag(AVIOContext *pb, MOVTrack *track) avio_wb32(pb, 0); /* Reserved */ avio_wb32(pb, 0); /* Reserved */ } - avio_wb16(pb, track->enc->width); /* Video width */ + avio_wb16(pb, track->par->width); /* Video width */ avio_wb16(pb, track->height); /* Video height */ avio_wb32(pb, 0x00480000); /* Horizontal resolution 72dpi */ avio_wb32(pb, 0x00480000); /* Vertical resolution 72dpi */ @@ -1073,38 +1073,38 @@ static int mov_write_video_tag(AVIOContext *pb, MOVTrack *track) avio_w8(pb, strlen(compressor_name)); avio_write(pb, compressor_name, 31); - if (track->mode == MODE_MOV && track->enc->bits_per_coded_sample) - avio_wb16(pb, track->enc->bits_per_coded_sample); + if (track->mode == MODE_MOV && track->par->bits_per_coded_sample) + avio_wb16(pb, track->par->bits_per_coded_sample); else avio_wb16(pb, 0x18); /* Reserved */ avio_wb16(pb, 0xffff); /* Reserved */ if (track->tag == MKTAG('m','p','4','v')) mov_write_esds_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_H263) + else if (track->par->codec_id == AV_CODEC_ID_H263) mov_write_d263_tag(pb); - else if (track->enc->codec_id == AV_CODEC_ID_SVQ3) + else if (track->par->codec_id == AV_CODEC_ID_SVQ3) mov_write_svq3_tag(pb); - else if (track->enc->codec_id == AV_CODEC_ID_DNXHD) + else if (track->par->codec_id == AV_CODEC_ID_DNXHD) mov_write_avid_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_HEVC) + else if (track->par->codec_id == AV_CODEC_ID_HEVC) mov_write_hvcc_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_H264) { + else if (track->par->codec_id == AV_CODEC_ID_H264) { mov_write_avcc_tag(pb, track); if (track->mode == MODE_IPOD) mov_write_uuid_tag_ipod(pb); - } else if (track->enc->field_order != AV_FIELD_UNKNOWN) + } else if (track->par->field_order != AV_FIELD_UNKNOWN) mov_write_fiel_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_VC1 && track->vos_len > 0) + else if (track->par->codec_id == AV_CODEC_ID_VC1 && track->vos_len > 0) mov_write_dvc1_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_VP6F || - track->enc->codec_id == AV_CODEC_ID_VP6A) { + else if (track->par->codec_id == AV_CODEC_ID_VP6F || + track->par->codec_id == AV_CODEC_ID_VP6A) { /* Don't write any potential extradata here - the cropping * is signalled via the normal width/height fields. */ } else if (track->vos_len > 0) mov_write_glbl_tag(pb, track); - if (track->enc->sample_aspect_ratio.den && track->enc->sample_aspect_ratio.num && - track->enc->sample_aspect_ratio.den != track->enc->sample_aspect_ratio.num) { + if (track->par->sample_aspect_ratio.den && track->par->sample_aspect_ratio.num && + track->par->sample_aspect_ratio.den != track->par->sample_aspect_ratio.num) { mov_write_pasp_tag(pb, track); } @@ -1139,27 +1139,27 @@ static int mov_write_tmcd_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "tmcd"); /* Data format */ avio_wb32(pb, 0); /* Reserved */ avio_wb32(pb, 1); /* Data reference index */ - if (track->enc->extradata_size) - avio_write(pb, track->enc->extradata, track->enc->extradata_size); + if (track->par->extradata_size) + avio_write(pb, track->par->extradata, track->par->extradata_size); return update_size(pb, pos); } -static int mov_write_stsd_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_stsd_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "stsd"); avio_wb32(pb, 0); /* version & flags */ avio_wb32(pb, 1); /* entry count */ - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) mov_write_video_tag(pb, track); - else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) - mov_write_audio_tag(pb, track); - else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) + else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) + mov_write_audio_tag(s, pb, track); + else if (track->par->codec_type == AVMEDIA_TYPE_SUBTITLE) mov_write_subtitle_tag(pb, track); - else if (track->enc->codec_tag == MKTAG('r','t','p',' ')) + else if (track->par->codec_tag == MKTAG('r','t','p',' ')) mov_write_rtp_tag(pb, track); - else if (track->enc->codec_tag == MKTAG('t','m','c','d')) + else if (track->par->codec_tag == MKTAG('t','m','c','d')) mov_write_tmcd_tag(pb, track); return update_size(pb, pos); } @@ -1207,7 +1207,7 @@ static int mov_write_stts_tag(AVIOContext *pb, MOVTrack *track) uint32_t atom_size; int i; - if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO && !track->audio_vbr) { + if (track->par->codec_type == AVMEDIA_TYPE_AUDIO && !track->audio_vbr) { stts_entries = av_malloc(sizeof(*stts_entries)); /* one entry */ if (!stts_entries) return AVERROR(ENOMEM); @@ -1259,20 +1259,20 @@ static int mov_write_dref_tag(AVIOContext *pb) return 28; } -static int mov_write_stbl_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_stbl_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "stbl"); - mov_write_stsd_tag(pb, track); + mov_write_stsd_tag(s, pb, track); mov_write_stts_tag(pb, track); - if ((track->enc->codec_type == AVMEDIA_TYPE_VIDEO || - track->enc->codec_tag == MKTAG('r','t','p',' ')) && + if ((track->par->codec_type == AVMEDIA_TYPE_VIDEO || + track->par->codec_tag == MKTAG('r','t','p',' ')) && track->has_keyframes && track->has_keyframes < track->entry) mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE); if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS) mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE); - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO && + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO && track->flags & MOV_TRACK_CTTS && track->entry) mov_write_ctts_tag(pb, track); mov_write_stsc_tag(pb, track); @@ -1339,7 +1339,7 @@ static int is_clcp_track(MOVTrack *track) track->tag == MKTAG('c','6','0','8'); } -static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_hdlr_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { const char *hdlr, *descr = NULL, *hdlr_type = NULL; int64_t pos = avio_tell(pb); @@ -1350,13 +1350,13 @@ static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track) if (track) { hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0"; - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { hdlr_type = "vide"; descr = "VideoHandler"; - } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) { hdlr_type = "soun"; descr = "SoundHandler"; - } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) { + } else if (track->par->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (track->tag == MKTAG('t','x','3','g')) { hdlr_type = "sbtl"; } else if (track->tag == MKTAG('m','p','4','s')) { @@ -1367,20 +1367,20 @@ static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track) hdlr_type = "text"; } descr = "SubtitleHandler"; - } else if (track->enc->codec_tag == MKTAG('r','t','p',' ')) { + } else if (track->par->codec_tag == MKTAG('r','t','p',' ')) { hdlr_type = "hint"; descr = "HintHandler"; - } else if (track->enc->codec_tag == MKTAG('t','m','c','d')) { + } else if (track->par->codec_tag == MKTAG('t','m','c','d')) { hdlr_type = "tmcd"; descr = "TimeCodeHandler"; } else { char tag_buf[32]; av_get_codec_tag_string(tag_buf, sizeof(tag_buf), - track->enc->codec_tag); + track->par->codec_tag); - av_log(track->enc, AV_LOG_WARNING, + av_log(s, AV_LOG_WARNING, "Unknown hldr_type for %s / 0x%04X, writing dummy values\n", - tag_buf, track->enc->codec_tag); + tag_buf, track->par->codec_tag); } if (track->st) { // hdlr.name is used by some players to identify the content title @@ -1424,16 +1424,16 @@ static int mov_write_hmhd_tag(AVIOContext *pb) return 28; } -static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_minf_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "minf"); - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) mov_write_vmhd_tag(pb); - else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) + else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) mov_write_smhd_tag(pb); - else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) { + else if (track->par->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (track->tag == MKTAG('t','e','x','t') || is_clcp_track(track)) { mov_write_gmhd_tag(pb); } else { @@ -1445,9 +1445,9 @@ static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track) mov_write_gmhd_tag(pb); } if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */ - mov_write_hdlr_tag(pb, NULL); + mov_write_hdlr_tag(s, pb, NULL); mov_write_dinf_tag(pb); - mov_write_stbl_tag(pb, track); + mov_write_stbl_tag(s, pb, track); return update_size(pb, pos); } @@ -1490,15 +1490,15 @@ static int mov_write_mdhd_tag(AVIOContext *pb, MOVMuxContext *mov, return 32; } -static int mov_write_mdia_tag(AVIOContext *pb, MOVMuxContext *mov, - MOVTrack *track) +static int mov_write_mdia_tag(AVFormatContext *s, AVIOContext *pb, + MOVMuxContext *mov, MOVTrack *track) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "mdia"); mov_write_mdhd_tag(pb, mov, track); - mov_write_hdlr_tag(pb, track); - mov_write_minf_tag(pb, track); + mov_write_hdlr_tag(s, pb, track); + mov_write_minf_tag(s, pb, track); return update_size(pb, pos); } @@ -1518,7 +1518,7 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov, if (mov->per_stream_grouping) group = st->index; else - group = st->codec->codec_type; + group = st->codecpar->codec_type; display_matrix = (uint32_t*)av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, &display_matrix_size); @@ -1557,7 +1557,7 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov, avio_wb16(pb, 0); /* layer */ avio_wb16(pb, group); /* alternate group) */ /* Volume, only for audio */ - if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) + if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) avio_wb16(pb, 0x0100); else avio_wb16(pb, 0); @@ -1580,16 +1580,16 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov, } /* Track width and height, for visual only */ - if (st && (track->enc->codec_type == AVMEDIA_TYPE_VIDEO || - track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE)) { + if (st && (track->par->codec_type == AVMEDIA_TYPE_VIDEO || + track->par->codec_type == AVMEDIA_TYPE_SUBTITLE)) { if (track->mode == MODE_MOV) { - avio_wb32(pb, track->enc->width << 16); + avio_wb32(pb, track->par->width << 16); avio_wb32(pb, track->height << 16); } else { double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio); - if (!sample_aspect_ratio || track->height != track->enc->height) + if (!sample_aspect_ratio || track->height != track->par->height) sample_aspect_ratio = 1; - avio_wb32(pb, sample_aspect_ratio * track->enc->width * 0x10000); + avio_wb32(pb, sample_aspect_ratio * track->par->width * 0x10000); avio_wb32(pb, track->height * 0x10000); } } else { @@ -1601,8 +1601,8 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov, static int mov_write_tapt_tag(AVIOContext *pb, MOVTrack *track) { - int32_t width = av_rescale(track->enc->sample_aspect_ratio.num, track->enc->width, - track->enc->sample_aspect_ratio.den); + int32_t width = av_rescale(track->par->sample_aspect_ratio.num, track->par->width, + track->par->sample_aspect_ratio.den); int64_t pos = avio_tell(pb); @@ -1613,19 +1613,19 @@ static int mov_write_tapt_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "clef"); avio_wb32(pb, 0); avio_wb32(pb, width << 16); - avio_wb32(pb, track->enc->height << 16); + avio_wb32(pb, track->par->height << 16); avio_wb32(pb, 20); ffio_wfourcc(pb, "prof"); avio_wb32(pb, 0); avio_wb32(pb, width << 16); - avio_wb32(pb, track->enc->height << 16); + avio_wb32(pb, track->par->height << 16); avio_wb32(pb, 20); ffio_wfourcc(pb, "enof"); avio_wb32(pb, 0); - avio_wb32(pb, track->enc->width << 16); - avio_wb32(pb, track->enc->height << 16); + avio_wb32(pb, track->par->width << 16); + avio_wb32(pb, track->par->height << 16); return update_size(pb, pos); } @@ -1816,13 +1816,13 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov, } if (track->tref_tag) mov_write_tref_tag(pb, track); - mov_write_mdia_tag(pb, mov, track); + mov_write_mdia_tag(mov->fc, pb, mov, track); if (track->mode == MODE_PSP) mov_write_uuid_tag_psp(pb, track); // PSP Movies require this uuid box if (track->tag == MKTAG('r','t','p',' ')) mov_write_udta_sdp(pb, track); if (track->mode == MODE_MOV) { - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio); if ((0.0 != sample_aspect_ratio && 1.0 != sample_aspect_ratio)) { mov_write_tapt_tag(pb, track); @@ -1845,8 +1845,8 @@ static int mov_write_iods_tag(AVIOContext *pb, MOVMuxContext *mov) int video_profile = mov->iods_video_profile; for (i = 0; i < mov->nb_streams; i++) { if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_EMPTY_MOOV) { - has_audio |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_AUDIO; - has_video |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_VIDEO; + has_audio |= mov->tracks[i].par->codec_type == AVMEDIA_TYPE_AUDIO; + has_video |= mov->tracks[i].par->codec_type == AVMEDIA_TYPE_VIDEO; } } if (audio_profile < 0) @@ -2292,7 +2292,7 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov, if (track->tag == MKTAG('r','t','p',' ')) { track->tref_tag = MKTAG('h','i','n','t'); track->tref_id = mov->tracks[track->src_track].track_id; - } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) { int * fallback, size; fallback = (int*)av_stream_get_side_data(track->st, AV_PKT_DATA_FALLBACK_TRACK, @@ -2373,53 +2373,53 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov) * here yet */ int track_id = i + 1; - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { type = "video"; - } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) { type = "audio"; } else { continue; } avio_printf(pb, "<%s systemBitrate=\"%d\">\n", type, - track->enc->bit_rate); - param_write_int(pb, "systemBitrate", track->enc->bit_rate); + track->par->bit_rate); + param_write_int(pb, "systemBitrate", track->par->bit_rate); param_write_int(pb, "trackID", track_id); - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { - if (track->enc->codec_id == AV_CODEC_ID_H264) { + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { + if (track->par->codec_id == AV_CODEC_ID_H264) { uint8_t *ptr; - int size = track->enc->extradata_size; - if (!ff_avc_write_annexb_extradata(track->enc->extradata, &ptr, + int size = track->par->extradata_size; + if (!ff_avc_write_annexb_extradata(track->par->extradata, &ptr, &size)) { param_write_hex(pb, "CodecPrivateData", - ptr ? ptr : track->enc->extradata, + ptr ? ptr : track->par->extradata, size); av_free(ptr); } param_write_string(pb, "FourCC", "H264"); - } else if (track->enc->codec_id == AV_CODEC_ID_VC1) { + } else if (track->par->codec_id == AV_CODEC_ID_VC1) { param_write_string(pb, "FourCC", "WVC1"); - param_write_hex(pb, "CodecPrivateData", track->enc->extradata, - track->enc->extradata_size); + param_write_hex(pb, "CodecPrivateData", track->par->extradata, + track->par->extradata_size); } - param_write_int(pb, "MaxWidth", track->enc->width); - param_write_int(pb, "MaxHeight", track->enc->height); - param_write_int(pb, "DisplayWidth", track->enc->width); - param_write_int(pb, "DisplayHeight", track->enc->height); + param_write_int(pb, "MaxWidth", track->par->width); + param_write_int(pb, "MaxHeight", track->par->height); + param_write_int(pb, "DisplayWidth", track->par->width); + param_write_int(pb, "DisplayHeight", track->par->height); } else { - if (track->enc->codec_id == AV_CODEC_ID_AAC) { + if (track->par->codec_id == AV_CODEC_ID_AAC) { param_write_string(pb, "FourCC", "AACL"); - } else if (track->enc->codec_id == AV_CODEC_ID_WMAPRO) { + } else if (track->par->codec_id == AV_CODEC_ID_WMAPRO) { param_write_string(pb, "FourCC", "WMAP"); } - param_write_hex(pb, "CodecPrivateData", track->enc->extradata, - track->enc->extradata_size); + param_write_hex(pb, "CodecPrivateData", track->par->extradata, + track->par->extradata_size); param_write_int(pb, "AudioTag", ff_codec_get_tag(ff_codec_wav_tags, - track->enc->codec_id)); - param_write_int(pb, "Channels", track->enc->channels); - param_write_int(pb, "SamplingRate", track->enc->sample_rate); + track->par->codec_id)); + param_write_int(pb, "Channels", track->par->channels); + param_write_int(pb, "SamplingRate", track->par->sample_rate); param_write_int(pb, "BitsPerSample", 16); - param_write_int(pb, "PacketSize", track->enc->block_align ? - track->enc->block_align : 4); + param_write_int(pb, "PacketSize", track->par->block_align ? + track->par->block_align : 4); } avio_printf(pb, "</%s>\n", type); } @@ -2496,7 +2496,7 @@ static int mov_write_tfhd_tag(AVIOContext *pb, MOVMuxContext *mov, track->default_sample_flags = get_sample_flags(track, &track->cluster[1]); else track->default_sample_flags = - track->enc->codec_type == AVMEDIA_TYPE_VIDEO ? + track->par->codec_type == AVMEDIA_TYPE_VIDEO ? (MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES | MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC) : MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO; avio_wb32(pb, track->default_sample_flags); @@ -2932,9 +2932,9 @@ static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) has_video = 1; - if (st->codec->codec_id == AV_CODEC_ID_H264) + if (st->codecpar->codec_id == AV_CODEC_ID_H264) has_h264 = 1; } @@ -3000,13 +3000,13 @@ static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) static void mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s) { AVStream *video_st = s->streams[0]; - AVCodecContext *video_codec = s->streams[0]->codec; - AVCodecContext *audio_codec = s->streams[1]->codec; - int audio_rate = audio_codec->sample_rate; + AVCodecParameters *video_par = s->streams[0]->codecpar; + AVCodecParameters *audio_par = s->streams[1]->codecpar; + int audio_rate = audio_par->sample_rate; // TODO: should be avg_frame_rate int frame_rate = ((video_st->time_base.den) * (0x10000)) / (video_st->time_base.num); - int audio_kbitrate = audio_codec->bit_rate / 1000; - int video_kbitrate = FFMIN(video_codec->bit_rate / 1000, 800 - audio_kbitrate); + int audio_kbitrate = audio_par->bit_rate / 1000; + int video_kbitrate = FFMIN(video_par->bit_rate / 1000, 800 - audio_kbitrate); avio_wb32(pb, 0x94); /* size */ ffio_wfourcc(pb, "uuid"); @@ -3035,13 +3035,13 @@ static void mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s) avio_wb32(pb, audio_kbitrate); avio_wb32(pb, audio_kbitrate); avio_wb32(pb, audio_rate); - avio_wb32(pb, audio_codec->channels); + avio_wb32(pb, audio_par->channels); avio_wb32(pb, 0x34); /* size */ ffio_wfourcc(pb, "VPRF"); /* video */ avio_wb32(pb, 0x0); avio_wb32(pb, 0x1); /* TrackID */ - if (video_codec->codec_id == AV_CODEC_ID_H264) { + if (video_par->codec_id == AV_CODEC_ID_H264) { ffio_wfourcc(pb, "avc1"); avio_wb16(pb, 0x014D); avio_wb16(pb, 0x0015); @@ -3055,8 +3055,8 @@ static void mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s) avio_wb32(pb, video_kbitrate); avio_wb32(pb, frame_rate); avio_wb32(pb, frame_rate); - avio_wb16(pb, video_codec->width); - avio_wb16(pb, video_codec->height); + avio_wb16(pb, video_par->width); + avio_wb16(pb, video_par->height); avio_wb32(pb, 0x010001); /* ? */ } @@ -3376,7 +3376,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) MOVMuxContext *mov = s->priv_data; AVIOContext *pb = s->pb; MOVTrack *trk = &mov->tracks[pkt->stream_index]; - AVCodecContext *enc = trk->enc; + AVCodecParameters *par = trk->par; unsigned int samples_in_chunk = 0; int size = pkt->size, ret = 0; uint8_t *reformatted_data = NULL; @@ -3405,7 +3405,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) } } - if (enc->codec_id == AV_CODEC_ID_AMR_NB) { + if (par->codec_id == AV_CODEC_ID_AMR_NB) { /* We must find out how many AMR blocks there are in one packet */ static uint16_t packed_size[16] = {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1}; @@ -3425,17 +3425,17 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) samples_in_chunk = 1; /* copy extradata if it exists */ - if (trk->vos_len == 0 && enc->extradata_size > 0) { - trk->vos_len = enc->extradata_size; + if (trk->vos_len == 0 && par->extradata_size > 0) { + trk->vos_len = par->extradata_size; trk->vos_data = av_malloc(trk->vos_len); if (!trk->vos_data) { ret = AVERROR(ENOMEM); goto err; } - memcpy(trk->vos_data, enc->extradata, trk->vos_len); + memcpy(trk->vos_data, par->extradata, trk->vos_len); } - if (enc->codec_id == AV_CODEC_ID_H264 && trk->vos_len > 0 && *(uint8_t *)trk->vos_data != 1) { + if (par->codec_id == AV_CODEC_ID_H264 && trk->vos_len > 0 && *(uint8_t *)trk->vos_data != 1) { /* from x264 or from bytestream h264 */ /* nal reformating needed */ if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) { @@ -3445,7 +3445,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) } else { size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size); } - } else if (enc->codec_id == AV_CODEC_ID_HEVC && trk->vos_len > 6 && + } else if (par->codec_id == AV_CODEC_ID_HEVC && trk->vos_len > 6 && (AV_RB24(trk->vos_data) == 1 || AV_RB32(trk->vos_data) == 1)) { /* extradata is Annex B, assume the bitstream is too and convert it */ if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) { @@ -3458,8 +3458,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) avio_write(pb, pkt->data, size); } - if ((enc->codec_id == AV_CODEC_ID_DNXHD || - enc->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len) { + if ((par->codec_id == AV_CODEC_ID_DNXHD || + par->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len) { /* copy frame to create needed atoms */ trk->vos_len = size; trk->vos_data = av_malloc(size); @@ -3560,10 +3560,10 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) trk->cluster[trk->entry].cts + pkt->duration); - if (enc->codec_id == AV_CODEC_ID_VC1) { + if (par->codec_id == AV_CODEC_ID_VC1) { mov_parse_vc1_frame(pkt, trk); } else if (pkt->flags & AV_PKT_FLAG_KEY) { - if (mov->mode == MODE_MOV && enc->codec_id == AV_CODEC_ID_MPEG2VIDEO && + if (mov->mode == MODE_MOV && par->codec_id == AV_CODEC_ID_MPEG2VIDEO && trk->entry > 0) { // force sync sample for the first key frame mov_parse_mpeg2_frame(pkt, &trk->cluster[trk->entry].flags); if (trk->cluster[trk->entry].flags & MOV_PARTIAL_SYNC_SAMPLE) @@ -3595,7 +3595,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) } else { MOVMuxContext *mov = s->priv_data; MOVTrack *trk = &mov->tracks[pkt->stream_index]; - AVCodecContext *enc = trk->enc; + AVCodecParameters *par = trk->par; int64_t frag_duration = 0; int size = pkt->size; @@ -3626,7 +3626,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) frag_duration >= mov->max_fragment_duration) || (mov->max_fragment_size && mov->mdat_size + size >= mov->max_fragment_size) || (mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME && - enc->codec_type == AVMEDIA_TYPE_VIDEO && + par->codec_type == AVMEDIA_TYPE_VIDEO && trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) { if (frag_duration >= mov->min_fragment_duration) { // Set the duration of this track to line up with the next @@ -3657,15 +3657,15 @@ static int mov_create_chapter_track(AVFormatContext *s, int tracknum) track->mode = mov->mode; track->tag = MKTAG('t','e','x','t'); track->timescale = MOV_TIMESCALE; - track->enc = avcodec_alloc_context3(NULL); - if (!track->enc) + track->par = avcodec_parameters_alloc(); + if (!track->par) return AVERROR(ENOMEM); - track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE; - track->enc->extradata = av_malloc(sizeof(chapter_properties)); - if (!track->enc->extradata) + track->par->codec_type = AVMEDIA_TYPE_SUBTITLE; + track->par->extradata = av_malloc(sizeof(chapter_properties)); + if (!track->par->extradata) return AVERROR(ENOMEM); - track->enc->extradata_size = sizeof(chapter_properties); - memcpy(track->enc->extradata, chapter_properties, sizeof(chapter_properties)); + track->par->extradata_size = sizeof(chapter_properties); + memcpy(track->par->extradata, chapter_properties, sizeof(chapter_properties)); for (i = 0; i < s->nb_chapters; i++) { AVChapter *c = s->chapters[i]; @@ -3722,15 +3722,15 @@ static void enable_tracks(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type <= AVMEDIA_TYPE_UNKNOWN || - st->codec->codec_type >= AVMEDIA_TYPE_NB) + if (st->codecpar->codec_type <= AVMEDIA_TYPE_UNKNOWN || + st->codecpar->codec_type >= AVMEDIA_TYPE_NB) continue; - if (first[st->codec->codec_type] < 0) - first[st->codec->codec_type] = i; + if (first[st->codecpar->codec_type] < 0) + first[st->codecpar->codec_type] = i; if (st->disposition & AV_DISPOSITION_DEFAULT) { mov->tracks[i].flags |= MOV_TRACK_ENABLED; - enabled[st->codec->codec_type]++; + enabled[st->codecpar->codec_type]++; } } @@ -3753,11 +3753,8 @@ static void mov_free(AVFormatContext *s) MOVMuxContext *mov = s->priv_data; int i; - if (mov->chapter_track) { - if (mov->tracks[mov->chapter_track].enc) - av_free(mov->tracks[mov->chapter_track].enc->extradata); - av_freep(&mov->tracks[mov->chapter_track].enc); - } + if (mov->chapter_track) + avcodec_parameters_free(&mov->tracks[mov->chapter_track].par); for (i = 0; i < mov->nb_streams; i++) { if (mov->tracks[i].tag == MKTAG('r','t','p',' ')) @@ -3794,7 +3791,7 @@ static int mov_create_dvd_sub_decoder_specific_info(MOVTrack *track, int i, width = 720, height = 480; int have_palette = 0, have_size = 0; uint32_t palette[16]; - char *cur = st->codec->extradata; + char *cur = st->codecpar->extradata; while (cur && *cur) { if (strncmp("palette:", cur, 8) == 0) { @@ -3831,8 +3828,8 @@ static int mov_create_dvd_sub_decoder_specific_info(MOVTrack *track, } track->vos_len = 16 * 4; } - st->codec->width = width; - st->codec->height = track->height = height; + st->codecpar->width = width; + st->codecpar->height = track->height = height; return 0; } @@ -3935,8 +3932,8 @@ static int mov_write_header(AVFormatContext *s) hint_track = mov->nb_streams; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || - st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { mov->nb_streams++; } } @@ -3954,7 +3951,7 @@ static int mov_write_header(AVFormatContext *s) AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0); track->st = st; - track->enc = st->codec; + track->par = st->codecpar; track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV); if (track->language < 0) track->language = 0; @@ -3971,11 +3968,11 @@ static int mov_write_header(AVFormatContext *s) track->start_dts = AV_NOPTS_VALUE; track->start_cts = AV_NOPTS_VALUE; track->end_pts = AV_NOPTS_VALUE; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') || track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') || track->tag == MKTAG('m','x','5','p') || track->tag == MKTAG('m','x','5','n')) { - if (st->codec->width != 720 || (st->codec->height != 608 && st->codec->height != 512)) { + if (st->codecpar->width != 720 || (st->codecpar->height != 608 && st->codecpar->height != 512)) { av_log(s, AV_LOG_ERROR, "D-10/IMX must use 720x608 or 720x512 video resolution\n"); goto error; } @@ -3987,34 +3984,34 @@ static int mov_write_header(AVFormatContext *s) "WARNING codec timebase is very high. If duration is too long,\n" "file may not be playable by quicktime. Specify a shorter timebase\n" "or choose different container.\n"); - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - track->timescale = st->codec->sample_rate; + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + track->timescale = st->codecpar->sample_rate; /* set sample_size for PCM and ADPCM */ - if (av_get_bits_per_sample(st->codec->codec_id) || - st->codec->codec_id == AV_CODEC_ID_ILBC) { - if (!st->codec->block_align) { + if (av_get_bits_per_sample(st->codecpar->codec_id) || + st->codecpar->codec_id == AV_CODEC_ID_ILBC) { + if (!st->codecpar->block_align) { av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set\n", i); goto error; } - track->sample_size = st->codec->block_align; + track->sample_size = st->codecpar->block_align; } /* set audio_vbr for compressed audio */ - if (av_get_bits_per_sample(st->codec->codec_id) < 8) { + if (av_get_bits_per_sample(st->codecpar->codec_id) < 8) { track->audio_vbr = 1; } if (track->mode != MODE_MOV && - track->enc->codec_id == AV_CODEC_ID_MP3 && track->timescale < 16000) { + track->par->codec_id == AV_CODEC_ID_MP3 && track->timescale < 16000) { av_log(s, AV_LOG_ERROR, "track %d: muxing mp3 at %dhz is not supported\n", - i, track->enc->sample_rate); + i, track->par->sample_rate); goto error; } - } else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { track->timescale = st->time_base.den; - } else if (st->codec->codec_type == AVMEDIA_TYPE_DATA) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { track->timescale = st->time_base.den; } if (!track->height) - track->height = st->codec->height; + track->height = st->codecpar->height; /* The ism specific timescale isn't mandatory, but is assumed by * some tools, such as mp4split. */ if (mov->mode == MODE_ISM) @@ -4023,15 +4020,15 @@ static int mov_write_header(AVFormatContext *s) avpriv_set_pts_info(st, 64, 1, track->timescale); /* copy extradata if it exists */ - if (st->codec->extradata_size) { - if (st->codec->codec_id == AV_CODEC_ID_DVD_SUBTITLE) + if (st->codecpar->extradata_size) { + if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) mov_create_dvd_sub_decoder_specific_info(track, st); else { - track->vos_len = st->codec->extradata_size; + track->vos_len = st->codecpar->extradata_size; track->vos_data = av_malloc(track->vos_len); if (!track->vos_data) goto error; - memcpy(track->vos_data, st->codec->extradata, track->vos_len); + memcpy(track->vos_data, st->codecpar->extradata, track->vos_len); } } } @@ -4063,8 +4060,8 @@ static int mov_write_header(AVFormatContext *s) /* Initialize the hint tracks for each audio and video stream */ for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || - st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { ff_mov_init_hinting(s, hint_track, i); hint_track++; } diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 22b883296a..fccf1f3b34 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -93,7 +93,7 @@ typedef struct MOVTrack { int track_id; int tag; ///< stsd fourcc AVStream *st; - AVCodecContext *enc; + AVCodecParameters *par; int vos_len; uint8_t *vos_data; diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c index 73498e4547..58ad9e4c0a 100644 --- a/libavformat/movenchint.c +++ b/libavformat/movenchint.c @@ -37,11 +37,11 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) track->tag = MKTAG('r','t','p',' '); track->src_track = src_index; - track->enc = avcodec_alloc_context3(NULL); - if (!track->enc) + track->par = avcodec_parameters_alloc(); + if (!track->par) goto fail; - track->enc->codec_type = AVMEDIA_TYPE_DATA; - track->enc->codec_tag = track->tag; + track->par->codec_type = AVMEDIA_TYPE_DATA; + track->par->codec_tag = track->tag; ret = ff_rtp_chain_mux_open(&track->rtp_ctx, s, src_st, NULL, RTP_MAX_PACKET_SIZE, src_index); @@ -58,7 +58,7 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) fail: av_log(s, AV_LOG_WARNING, "Unable to initialize hinting of stream %d\n", src_index); - av_freep(&track->enc); + avcodec_parameters_free(&track->par); /* Set a default timescale, to avoid crashes in av_dump_format */ track->timescale = 90000; return ret; @@ -459,7 +459,7 @@ void ff_mov_close_hinting(MOVTrack *track) { AVFormatContext *rtp_ctx = track->rtp_ctx; - av_freep(&track->enc); + avcodec_parameters_free(&track->par); sample_queue_free(&track->sample_queue); if (!rtp_ctx) return; diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index fd2c695037..89fb376a06 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -302,7 +302,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base) st->duration = av_rescale_q(mp3->frames, (AVRational){spf, c.sample_rate}, st->time_base); if (mp3->size && mp3->frames && !mp3->is_cbr) - st->codec->bit_rate = av_rescale(mp3->size, 8 * c.sample_rate, mp3->frames * (int64_t)spf); + st->codecpar->bit_rate = av_rescale(mp3->size, 8 * c.sample_rate, mp3->frames * (int64_t)spf); return 0; } @@ -317,8 +317,8 @@ static int mp3_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MP3; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MP3; st->need_parsing = AVSTREAM_PARSE_FULL; st->start_time = 0; 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); } diff --git a/libavformat/mpc.c b/libavformat/mpc.c index e92cab6242..8127996e01 100644 --- a/libavformat/mpc.c +++ b/libavformat/mpc.c @@ -89,17 +89,17 @@ static int mpc_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MUSEPACK7; - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; - st->codec->bits_per_coded_sample = 16; - - st->codec->extradata_size = 16; - st->codec->extradata = av_mallocz(st->codec->extradata_size+AV_INPUT_BUFFER_PADDING_SIZE); - avio_read(s->pb, st->codec->extradata, 16); - st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3]; - avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MUSEPACK7; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->bits_per_coded_sample = 16; + + st->codecpar->extradata_size = 16; + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size+AV_INPUT_BUFFER_PADDING_SIZE); + avio_read(s->pb, st->codecpar->extradata, 16); + st->codecpar->sample_rate = mpc_rate[st->codecpar->extradata[2] & 3]; + avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codecpar->sample_rate); /* scan for seekpoints */ st->start_time = 0; st->duration = c->fcount; diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c index 3bc868e502..2349ea5bb8 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -237,19 +237,19 @@ static int mpc8_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MUSEPACK8; - st->codec->bits_per_coded_sample = 16; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MUSEPACK8; + st->codecpar->bits_per_coded_sample = 16; - st->codec->extradata_size = 2; - st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - avio_read(pb, st->codec->extradata, st->codec->extradata_size); + st->codecpar->extradata_size = 2; + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + avio_read(pb, st->codecpar->extradata, st->codecpar->extradata_size); - st->codec->channels = (st->codec->extradata[1] >> 4) + 1; - st->codec->sample_rate = mpc8_rate[st->codec->extradata[0] >> 5]; - avpriv_set_pts_info(st, 32, 1152 << (st->codec->extradata[1]&3)*2, st->codec->sample_rate); + st->codecpar->channels = (st->codecpar->extradata[1] >> 4) + 1; + st->codecpar->sample_rate = mpc8_rate[st->codecpar->extradata[0] >> 5]; + avpriv_set_pts_info(st, 32, 1152 << (st->codecpar->extradata[1]&3)*2, st->codecpar->sample_rate); st->start_time = 0; - st->duration = c->samples / (1152 << (st->codec->extradata[1]&3)*2); + st->duration = c->samples / (1152 << (st->codecpar->extradata[1]&3)*2); size -= avio_tell(pb) - pos; if (pb->seekable) { diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index ffabe28683..f405c4e801 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -517,8 +517,8 @@ skip: if (!st) goto skip; st->id = startcode; - st->codec->codec_type = type; - st->codec->codec_id = codec_id; + st->codecpar->codec_type = type; + st->codecpar->codec_id = codec_id; st->need_parsing = AVSTREAM_PARSE_FULL; found: diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index ac5a83c8c8..5178746010 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -351,26 +351,26 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) avpriv_set_pts_info(st, 64, 1, 90000); - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - if (st->codec->codec_id == AV_CODEC_ID_AC3) { + if (st->codecpar->codec_id == AV_CODEC_ID_AC3) { stream->id = ac3_id++; - } else if (st->codec->codec_id == AV_CODEC_ID_DTS) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DTS) { stream->id = dts_id++; - } else if (st->codec->codec_id == AV_CODEC_ID_PCM_S16BE) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) { stream->id = lpcm_id++; for (j = 0; j < 4; j++) { - if (lpcm_freq_tab[j] == st->codec->sample_rate) + if (lpcm_freq_tab[j] == st->codecpar->sample_rate) break; } if (j == 4) goto fail; - if (st->codec->channels > 8) + if (st->codecpar->channels > 8) return -1; stream->lpcm_header[0] = 0x0c; - stream->lpcm_header[1] = (st->codec->channels - 1) | (j << 4); + stream->lpcm_header[1] = (st->codecpar->channels - 1) | (j << 4); stream->lpcm_header[2] = 0x80; - stream->lpcm_align = st->codec->channels * 2; + stream->lpcm_align = st->codecpar->channels * 2; } else { stream->id = mpa_id++; } @@ -381,7 +381,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) s->audio_bound++; break; case AVMEDIA_TYPE_VIDEO: - if (st->codec->codec_id == AV_CODEC_ID_H264) + if (st->codecpar->codec_id == AV_CODEC_ID_H264) stream->id = h264_id++; else stream->id = mpv_id++; @@ -421,7 +421,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) if (props) codec_rate = props->max_bitrate; else - codec_rate = st->codec->bit_rate; + codec_rate = st->codecpar->bit_rate; if (!codec_rate) codec_rate = (1 << 21) * 8 * 50 / ctx->nb_streams; @@ -430,7 +430,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) if ((stream->id & 0xe0) == AUDIO_ID) audio_bitrate += codec_rate; - else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) video_bitrate += codec_rate; } @@ -963,7 +963,7 @@ retry: /* for subtitle, a single PES packet must be generated, * so we flush after every single subtitle packet */ if (s->packet_size > avail_data && !flush - && st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) + && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) return 0; if (avail_data == 0) continue; @@ -1081,7 +1081,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) int64_t pts, dts; PacketDesc *pkt_desc; int preload; - const int is_iframe = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + const int is_iframe = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY); preload = av_rescale(s->preload, 90000, AV_TIME_BASE); diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 01af597894..63e333b505 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -639,8 +639,8 @@ static void mpegts_find_stream_type(AVStream *st, { for (; types->stream_type; types++) if (stream_type == types->stream_type) { - st->codec->codec_type = types->codec_type; - st->codec->codec_id = types->codec_id; + st->codecpar->codec_type = types->codec_type; + st->codecpar->codec_id = types->codec_id; return; } } @@ -650,8 +650,8 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, { avpriv_set_pts_info(st, 33, 1, 90000); st->priv_data = pes; - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_NONE; st->need_parsing = AVSTREAM_PARSE_FULL; pes->st = st; pes->stream_type = stream_type; @@ -660,11 +660,11 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n", st->index, pes->stream_type, pes->pid, (char *)&prog_reg_desc); - st->codec->codec_tag = pes->stream_type; + st->codecpar->codec_tag = pes->stream_type; mpegts_find_stream_type(st, pes->stream_type, ISO_types); if (prog_reg_desc == AV_RL32("HDMV") && - st->codec->codec_id == AV_CODEC_ID_NONE) { + st->codecpar->codec_id == AV_CODEC_ID_NONE) { mpegts_find_stream_type(st, pes->stream_type, HDMV_types); if (pes->stream_type == 0x83) { // HDMV TrueHD streams also contain an AC3 coded version of the @@ -685,13 +685,13 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, sub_st->id = pes->pid; avpriv_set_pts_info(sub_st, 33, 1, 90000); sub_st->priv_data = sub_pes; - sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - sub_st->codec->codec_id = AV_CODEC_ID_AC3; + sub_st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + sub_st->codecpar->codec_id = AV_CODEC_ID_AC3; sub_st->need_parsing = AVSTREAM_PARSE_FULL; sub_pes->sub_st = pes->sub_st = sub_st; } } - if (st->codec->codec_id == AV_CODEC_ID_NONE) + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) mpegts_find_stream_type(st, pes->stream_type, MISC_types); return 0; @@ -873,12 +873,12 @@ static int mpegts_push_data(MpegTSFilter *filter, code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */ code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */ pes->state = MPEGTS_PESHEADER; - if (pes->st->codec->codec_id == AV_CODEC_ID_NONE) { + if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE) { av_log(pes->stream, AV_LOG_TRACE, "pid=%x stream_type=%x probing\n", pes->pid, pes->stream_type); - pes->st->codec->codec_id = AV_CODEC_ID_PROBE; + pes->st->codecpar->codec_id = AV_CODEC_ID_PROBE; } } else { pes->state = MPEGTS_PAYLOAD; @@ -1304,14 +1304,14 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ff_mp4_read_dec_config_descr(s, st, &pb); - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size > 0) + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size > 0) st->need_parsing = 0; - if (st->codec->codec_id == AV_CODEC_ID_H264 && - st->codec->extradata_size > 0) + if (st->codecpar->codec_id == AV_CODEC_ID_H264 && + st->codecpar->extradata_size > 0) st->need_parsing = 0; - st->codec->codec_type = avcodec_get_type(st->codec->codec_id); + st->codecpar->codec_type = avcodec_get_type(st->codecpar->codec_id); } } for (i = 0; i < mp4_descr_count; i++) @@ -1359,7 +1359,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type av_log(fc, AV_LOG_TRACE, "tag: 0x%02x len=%d\n", desc_tag, desc_len); - if (st->codec->codec_id == AV_CODEC_ID_NONE && + if (st->codecpar->codec_id == AV_CODEC_ID_NONE && stream_type == STREAM_TYPE_PRIVATE_DATA) mpegts_find_stream_type(st, desc_tag, DESC_types); @@ -1378,10 +1378,10 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ff_mp4_read_dec_config_descr(fc, st, &pb); - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size > 0) + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size > 0) st->need_parsing = 0; - if (st->codec->codec_id == AV_CODEC_ID_MPEG4SYSTEMS) + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4SYSTEMS) mpegts_open_section_filter(ts, pid, m4sl_cb, ts, 1); } break; @@ -1389,15 +1389,15 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type if (get16(pp, desc_end) < 0) break; if (mp4_descr_count > 0 && - st->codec->codec_id == AV_CODEC_ID_AAC_LATM && + st->codecpar->codec_id == AV_CODEC_ID_AAC_LATM && mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) { AVIOContext pb; ffio_init_context(&pb, mp4_descr->dec_config_descr, mp4_descr->dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ff_mp4_read_dec_config_descr(fc, st, &pb); - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size > 0) + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size > 0) st->need_parsing = 0; } break; @@ -1424,15 +1424,15 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED; break; } - if (st->codec->extradata) { - if (st->codec->extradata_size == 4 && - memcmp(st->codec->extradata, *pp, 4)) + if (st->codecpar->extradata) { + if (st->codecpar->extradata_size == 4 && + memcmp(st->codecpar->extradata, *pp, 4)) avpriv_request_sample(fc, "DVB sub with multiple IDs"); } else { - st->codec->extradata = av_malloc(4 + AV_INPUT_BUFFER_PADDING_SIZE); - if (st->codec->extradata) { - st->codec->extradata_size = 4; - memcpy(st->codec->extradata, *pp, 4); + st->codecpar->extradata = av_malloc(4 + AV_INPUT_BUFFER_PADDING_SIZE); + if (st->codecpar->extradata) { + st->codecpar->extradata_size = 4; + memcpy(st->codecpar->extradata, *pp, 4); } } *pp += 4; @@ -1462,35 +1462,35 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type } break; case 0x05: /* registration descriptor */ - st->codec->codec_tag = bytestream_get_le32(pp); - av_log(fc, AV_LOG_TRACE, "reg_desc=%.4s\n", (char *)&st->codec->codec_tag); - if (st->codec->codec_id == AV_CODEC_ID_NONE) - mpegts_find_stream_type(st, st->codec->codec_tag, REGD_types); + st->codecpar->codec_tag = bytestream_get_le32(pp); + av_log(fc, AV_LOG_TRACE, "reg_desc=%.4s\n", (char *)&st->codecpar->codec_tag); + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) + mpegts_find_stream_type(st, st->codecpar->codec_tag, REGD_types); break; case 0x7f: /* DVB extension descriptor */ ext_desc_tag = get8(pp, desc_end); if (ext_desc_tag < 0) return AVERROR_INVALIDDATA; - if (st->codec->codec_id == AV_CODEC_ID_OPUS && + if (st->codecpar->codec_id == AV_CODEC_ID_OPUS && ext_desc_tag == 0x80) { /* User defined (provisional Opus) */ - if (!st->codec->extradata) { - st->codec->extradata = av_mallocz(sizeof(opus_default_extradata) + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (!st->codecpar->extradata) { + st->codecpar->extradata = av_mallocz(sizeof(opus_default_extradata) + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = sizeof(opus_default_extradata); - memcpy(st->codec->extradata, opus_default_extradata, sizeof(opus_default_extradata)); + st->codecpar->extradata_size = sizeof(opus_default_extradata); + memcpy(st->codecpar->extradata, opus_default_extradata, sizeof(opus_default_extradata)); channel_config_code = get8(pp, desc_end); if (channel_config_code < 0) return AVERROR_INVALIDDATA; if (channel_config_code <= 0x8) { - st->codec->extradata[9] = channels = channel_config_code ? channel_config_code : 2; - st->codec->extradata[18] = channel_config_code ? (channels > 2) : 255; - st->codec->extradata[19] = opus_stream_cnt[channel_config_code]; - st->codec->extradata[20] = opus_coupled_stream_cnt[channel_config_code]; - memcpy(&st->codec->extradata[21], opus_channel_map[channels - 1], channels); + st->codecpar->extradata[9] = channels = channel_config_code ? channel_config_code : 2; + st->codecpar->extradata[18] = channel_config_code ? (channels > 2) : 255; + st->codecpar->extradata[19] = opus_stream_cnt[channel_config_code]; + st->codecpar->extradata[20] = opus_coupled_stream_cnt[channel_config_code]; + memcpy(&st->codecpar->extradata[21], opus_channel_map[channels - 1], channels); } else { avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code > 0x8"); } @@ -1617,7 +1617,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len } else { st = avformat_new_stream(ts->stream, NULL); st->id = pid; - st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; } } @@ -1648,7 +1648,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len stream_type == 0x83 && pes->sub_st) { ff_program_add_stream_index(ts->stream, h->id, pes->sub_st->index); - pes->sub_st->codec->codec_tag = st->codec->codec_tag; + pes->sub_st->codecpar->codec_tag = st->codecpar->codec_tag; } } p = desc_list_end; @@ -2104,8 +2104,8 @@ static int mpegts_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 60, 1, 27000000); - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_MPEG2TS; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_MPEG2TS; /* we iterate until we find two PCRs to estimate the bitrate */ pcr_pid = -1; @@ -2136,7 +2136,7 @@ static int mpegts_read_header(AVFormatContext *s) ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]); ts->cur_pcr = pcrs[0] - ts->pcr_incr * packet_count[0]; s->bit_rate = TS_PACKET_SIZE * 8 * 27e6 / ts->pcr_incr; - st->codec->bit_rate = s->bit_rate; + st->codecpar->bit_rate = s->bit_rate; st->start_time = ts->cur_pcr; av_log(ts->stream, AV_LOG_TRACE, "start=%0.3f pcr=%0.3f incr=%d\n", st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr); diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 8ef8eebc54..ffbea97633 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -252,7 +252,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) err = 1; break; } - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: stream_type = STREAM_TYPE_VIDEO_MPEG2; @@ -299,9 +299,9 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) q += 2; /* patched after */ /* write optional descriptors here */ - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - if (st->codec->codec_id == AV_CODEC_ID_AC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { + if (st->codecpar->codec_id == AV_CODEC_ID_AC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { *q++ = 0x6a; /* ETSI EN 300 468 AC-3 descriptor */ *q++ = 1; *q++ = 0x00; @@ -361,8 +361,8 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) break; } - if (st->codec->extradata_size == 4) { - memcpy(q, st->codec->extradata, 4); + if (st->codecpar->extradata_size == 4) { + memcpy(q, st->codecpar->extradata, 4); q += 4; } else { put16(&q, 1); /* page id */ @@ -607,13 +607,13 @@ static int mpegts_write_header(AVFormatContext *s) ts_st->first_pts_check = 1; ts_st->cc = 15; /* update PCR pid by using the first video stream */ - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && service->pcr_pid == 0x1fff) { service->pcr_pid = ts_st->pid; pcr_st = st; } - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size > 0) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size > 0) { AVStream *ast; ts_st->amux = avformat_alloc_context(); if (!ts_st->amux) { @@ -631,7 +631,7 @@ static int mpegts_write_header(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } - ret = avcodec_copy_context(ast->codec, st->codec); + ret = avcodec_parameters_copy(ast->codecpar, st->codecpar); if (ret != 0) goto fail; ast->time_base = st->time_base; @@ -664,14 +664,15 @@ static int mpegts_write_header(AVFormatContext *s) /* Arbitrary values, PAT/PMT could be written on key frames */ ts->sdt_packet_period = 200; ts->pat_packet_period = 40; - if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (!pcr_st->codec->frame_size) { + if (pcr_st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + int frame_size = av_get_audio_frame_duration2(pcr_st->codecpar, 0); + if (!frame_size) { av_log(s, AV_LOG_WARNING, "frame size not set\n"); service->pcr_packet_period = - pcr_st->codec->sample_rate / (10 * 512); + pcr_st->codecpar->sample_rate / (10 * 512); } else { service->pcr_packet_period = - pcr_st->codec->sample_rate / (10 * pcr_st->codec->frame_size); + pcr_st->codecpar->sample_rate / (10 * frame_size); } } else { // max delta PCR 0.1s @@ -926,19 +927,19 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, *q++ = 0x00; *q++ = 0x01; private_code = 0; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - if (st->codec->codec_id == AV_CODEC_ID_DIRAC) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC) *q++ = 0xfd; else *q++ = 0xe0; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - (st->codec->codec_id == AV_CODEC_ID_MP2 || - st->codec->codec_id == AV_CODEC_ID_MP3 || - st->codec->codec_id == AV_CODEC_ID_AAC)) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + (st->codecpar->codec_id == AV_CODEC_ID_MP2 || + st->codecpar->codec_id == AV_CODEC_ID_MP3 || + st->codecpar->codec_id == AV_CODEC_ID_AAC)) { *q++ = 0xc0; } else { *q++ = 0xbd; - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) private_code = 0x20; } header_len = 0; @@ -951,8 +952,8 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, header_len += 5; flags |= 0x40; } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && - st->codec->codec_id == AV_CODEC_ID_DIRAC) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { /* set PES_extension_flag */ pes_extension = 1; flags |= 0x01; @@ -971,7 +972,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, *q++ = len; val = 0x80; /* data alignment indicator is required for subtitle data */ - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) val |= 0x04; *q++ = val; *q++ = flags; @@ -984,7 +985,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, write_pts(q, 1, dts); q += 5; } - if (pes_extension && st->codec->codec_id == AV_CODEC_ID_DIRAC) { + if (pes_extension && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { flags = 0x01; /* set PES_extension_flag_2 */ *q++ = flags; *q++ = 0x80 | 0x01; /* marker bit + extension length */ @@ -1068,7 +1069,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) } ts_st->first_pts_check = 0; - if (st->codec->codec_id == AV_CODEC_ID_H264) { + if (st->codecpar->codec_id == AV_CODEC_ID_H264) { const uint8_t *p = buf, *buf_end = p + size; uint32_t state = -1; @@ -1095,7 +1096,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) buf = data; size = pkt->size + 6; } - } else if (st->codec->codec_id == AV_CODEC_ID_AAC) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { if (pkt->size < 2) { av_log(s, AV_LOG_ERROR, "AAC packet too short\n"); return AVERROR_INVALIDDATA; @@ -1129,7 +1130,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) } } - if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) { // for video and subtitle, write a single pes packet mpegts_write_pes(s, st, buf, size, pts, dts, pkt->flags & AV_PKT_FLAG_KEY); diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c index 2888fb5cd2..886bdfcbef 100644 --- a/libavformat/mpjpegdec.c +++ b/libavformat/mpjpegdec.c @@ -126,8 +126,8 @@ static int mpjpeg_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MJPEG; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MJPEG; avpriv_set_pts_info(st, 60, 1, 25); diff --git a/libavformat/msnwc_tcp.c b/libavformat/msnwc_tcp.c index 6cf7f9f009..6b9589d916 100644 --- a/libavformat/msnwc_tcp.c +++ b/libavformat/msnwc_tcp.c @@ -74,17 +74,17 @@ static int msnwc_tcp_probe(AVProbeData *p) static int msnwc_tcp_read_header(AVFormatContext *ctx) { AVIOContext *pb = ctx->pb; - AVCodecContext *codec; + AVCodecParameters *par; AVStream *st; st = avformat_new_stream(ctx, NULL); if (!st) return AVERROR(ENOMEM); - codec = st->codec; - codec->codec_type = AVMEDIA_TYPE_VIDEO; - codec->codec_id = AV_CODEC_ID_MIMIC; - codec->codec_tag = MKTAG('M', 'L', '2', '0'); + par = st->codecpar; + par->codec_type = AVMEDIA_TYPE_VIDEO; + par->codec_id = AV_CODEC_ID_MIMIC; + par->codec_tag = MKTAG('M', 'L', '2', '0'); avpriv_set_pts_info(st, 32, 1, 1000); diff --git a/libavformat/mtv.c b/libavformat/mtv.c index aad30d7a41..fdf13bbf39 100644 --- a/libavformat/mtv.c +++ b/libavformat/mtv.c @@ -131,13 +131,13 @@ static int mtv_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, mtv->video_fps); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->pix_fmt = AV_PIX_FMT_RGB565BE; - st->codec->width = mtv->img_width; - st->codec->height = mtv->img_height; - st->codec->extradata = av_strdup("BottomUp"); - st->codec->extradata_size = 9; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->format = AV_PIX_FMT_RGB565BE; + st->codecpar->width = mtv->img_width; + st->codecpar->height = mtv->img_height; + st->codecpar->extradata = av_strdup("BottomUp"); + st->codecpar->extradata_size = 9; // audio - mp3 @@ -146,10 +146,10 @@ static int mtv_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MP3; - st->codec->bit_rate = mtv->audio_br; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MP3; + st->codecpar->bit_rate = mtv->audio_br; + st->need_parsing = AVSTREAM_PARSE_FULL; // Jump over header diff --git a/libavformat/mux.c b/libavformat/mux.c index ddc69f94a5..76662ee033 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -67,12 +67,12 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) for (n = 0; s->oformat->codec_tag[n]; n++) { avctag = s->oformat->codec_tag[n]; while (avctag->id != AV_CODEC_ID_NONE) { - if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codec->codec_tag)) { + if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codecpar->codec_tag)) { id = avctag->id; - if (id == st->codec->codec_id) + if (id == st->codecpar->codec_id) return 1; } - if (avctag->id == st->codec->codec_id) + if (avctag->id == st->codecpar->codec_id) tag = avctag->tag; avctag++; } @@ -90,7 +90,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) int ret = 0, i; AVStream *st; AVDictionary *tmp = NULL; - AVCodecContext *codec = NULL; + AVCodecParameters *par = NULL; AVOutputFormat *of = s->oformat; const AVCodecDescriptor *desc; @@ -101,8 +101,10 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) goto fail; #if FF_API_LAVF_BITEXACT +FF_DISABLE_DEPRECATION_WARNINGS if (s->nb_streams && s->streams[0]->codec->flags & AV_CODEC_FLAG_BITEXACT) s->flags |= AVFMT_FLAG_BITEXACT; +FF_ENABLE_DEPRECATION_WARNINGS #endif // some sanity checks @@ -113,41 +115,55 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) } for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; - codec = st->codec; + st = s->streams[i]; + par = st->codecpar; #if FF_API_LAVF_CODEC_TB FF_DISABLE_DEPRECATION_WARNINGS - if (!st->time_base.num && codec->time_base.num) { + if (!st->time_base.num && st->codec->time_base.num) { av_log(s, AV_LOG_WARNING, "Using AVStream.codec.time_base as a " "timebase hint to the muxer is deprecated. Set " "AVStream.time_base instead.\n"); - avpriv_set_pts_info(st, 64, codec->time_base.num, codec->time_base.den); + avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den); + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + if (st->codecpar->codec_type == AVMEDIA_TYPE_UNKNOWN && + st->codec->codec_type != AVMEDIA_TYPE_UNKNOWN) { + av_log(s, AV_LOG_WARNING, "Using AVStream.codec to pass codec " + "parameters to muxers is deprecated, use AVStream.codecpar " + "instead.\n"); + ret = avcodec_parameters_from_context(st->codecpar, st->codec); + if (ret < 0) + goto fail; } FF_ENABLE_DEPRECATION_WARNINGS #endif if (!st->time_base.num) { /* fall back on the default timebase values */ - if (codec->codec_type == AVMEDIA_TYPE_AUDIO && codec->sample_rate) - avpriv_set_pts_info(st, 64, 1, codec->sample_rate); + if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->sample_rate) + avpriv_set_pts_info(st, 64, 1, par->sample_rate); else avpriv_set_pts_info(st, 33, 1, 90000); } - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: - if (codec->sample_rate <= 0) { + if (par->sample_rate <= 0) { av_log(s, AV_LOG_ERROR, "sample rate not set\n"); ret = AVERROR(EINVAL); goto fail; } - if (!codec->block_align) - codec->block_align = codec->channels * - av_get_bits_per_sample(codec->codec_id) >> 3; + if (!par->block_align) + par->block_align = par->channels * + av_get_bits_per_sample(par->codec_id) >> 3; break; case AVMEDIA_TYPE_VIDEO: - if ((codec->width <= 0 || codec->height <= 0) && + if ((par->width <= 0 || par->height <= 0) && !(of->flags & AVFMT_NODIMENSIONS)) { av_log(s, AV_LOG_ERROR, "dimensions not set\n"); ret = AVERROR(EINVAL); @@ -155,16 +171,16 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (av_cmp_q(st->sample_aspect_ratio, - codec->sample_aspect_ratio)) { + par->sample_aspect_ratio)) { if (st->sample_aspect_ratio.num != 0 && st->sample_aspect_ratio.den != 0 && - codec->sample_aspect_ratio.den != 0 && - codec->sample_aspect_ratio.den != 0) { + par->sample_aspect_ratio.den != 0 && + par->sample_aspect_ratio.den != 0) { av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer " "(%d/%d) and encoder layer (%d/%d)\n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, - codec->sample_aspect_ratio.num, - codec->sample_aspect_ratio.den); + par->sample_aspect_ratio.num, + par->sample_aspect_ratio.den); ret = AVERROR(EINVAL); goto fail; } @@ -172,34 +188,34 @@ FF_ENABLE_DEPRECATION_WARNINGS break; } - desc = avcodec_descriptor_get(codec->codec_id); + desc = avcodec_descriptor_get(par->codec_id); if (desc && desc->props & AV_CODEC_PROP_REORDER) st->internal->reorder = 1; if (of->codec_tag) { - if (codec->codec_tag && - codec->codec_id == AV_CODEC_ID_RAWVIDEO && - !av_codec_get_tag(of->codec_tag, codec->codec_id) && + if (par->codec_tag && + par->codec_id == AV_CODEC_ID_RAWVIDEO && + !av_codec_get_tag(of->codec_tag, par->codec_id) && !validate_codec_tag(s, st)) { // the current rawvideo encoding system ends up setting // the wrong codec_tag for avi, we override it here - codec->codec_tag = 0; + par->codec_tag = 0; } - if (codec->codec_tag) { + if (par->codec_tag) { if (!validate_codec_tag(s, st)) { char tagbuf[32]; - av_get_codec_tag_string(tagbuf, sizeof(tagbuf), codec->codec_tag); + av_get_codec_tag_string(tagbuf, sizeof(tagbuf), par->codec_tag); av_log(s, AV_LOG_ERROR, "Tag %s/0x%08x incompatible with output codec id '%d'\n", - tagbuf, codec->codec_tag, codec->codec_id); + tagbuf, par->codec_tag, par->codec_id); ret = AVERROR_INVALIDDATA; goto fail; } } else - codec->codec_tag = av_codec_get_tag(of->codec_tag, codec->codec_id); + par->codec_tag = av_codec_get_tag(of->codec_tag, par->codec_id); } - if (codec->codec_type != AVMEDIA_TYPE_ATTACHMENT) + if (par->codec_type != AVMEDIA_TYPE_ATTACHMENT) s->internal->nb_interleaved_streams++; } @@ -258,6 +274,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) } #if FF_API_COMPUTE_PKT_FIELDS2 +FF_DISABLE_DEPRECATION_WARNINGS //FIXME merge with compute_pkt_fields static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) { @@ -324,6 +341,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) return 0; } +FF_ENABLE_DEPRECATION_WARNINGS #endif /* @@ -384,7 +402,7 @@ static int check_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EINVAL); } - if (s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) { + if (s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT) { av_log(s, AV_LOG_ERROR, "Received a packet for an attachment stream.\n"); return AVERROR(EINVAL); } diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c index e21ec06b74..f13359c815 100644 --- a/libavformat/mvdec.c +++ b/libavformat/mvdec.c @@ -101,9 +101,9 @@ static int set_channels(AVFormatContext *avctx, AVStream *st, int channels) av_log(avctx, AV_LOG_ERROR, "Channel count %d invalid.\n", channels); return AVERROR_INVALIDDATA; } - st->codec->channels = channels; - st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO - : AV_CH_LAYOUT_STEREO; + st->codecpar->channels = channels; + st->codecpar->channel_layout = (st->codecpar->channels == 1) ? AV_CH_LAYOUT_MONO + : AV_CH_LAYOUT_STEREO; return 0; } @@ -151,10 +151,10 @@ static int parse_audio_var(AVFormatContext *avctx, AVStream *st, } else if (!strcmp(name, "NUM_CHANNELS")) { return set_channels(avctx, st, var_read_int(pb, size)); } else if (!strcmp(name, "SAMPLE_RATE")) { - st->codec->sample_rate = var_read_int(pb, size); - avpriv_set_pts_info(st, 33, 1, st->codec->sample_rate); + st->codecpar->sample_rate = var_read_int(pb, size); + avpriv_set_pts_info(st, 33, 1, st->codecpar->sample_rate); } else if (!strcmp(name, "SAMPLE_WIDTH")) { - st->codec->bits_per_coded_sample = var_read_int(pb, size) * 8; + st->codecpar->bits_per_coded_sample = var_read_int(pb, size) * 8; } else return AVERROR_INVALIDDATA; @@ -176,16 +176,16 @@ static int parse_video_var(AVFormatContext *avctx, AVStream *st, if (!str) return AVERROR_INVALIDDATA; if (!strcmp(str, "1")) { - st->codec->codec_id = AV_CODEC_ID_MVC1; + st->codecpar->codec_id = AV_CODEC_ID_MVC1; } else if (!strcmp(str, "2")) { - st->codec->pix_fmt = AV_PIX_FMT_ABGR; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->format = AV_PIX_FMT_ABGR; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; } else if (!strcmp(str, "3")) { - st->codec->codec_id = AV_CODEC_ID_SGIRLE; + st->codecpar->codec_id = AV_CODEC_ID_SGIRLE; } else if (!strcmp(str, "10")) { - st->codec->codec_id = AV_CODEC_ID_MJPEG; + st->codecpar->codec_id = AV_CODEC_ID_MJPEG; } else if (!strcmp(str, "MVC2")) { - st->codec->codec_id = AV_CODEC_ID_MVC2; + st->codecpar->codec_id = AV_CODEC_ID_MVC2; } else { avpriv_request_sample(avctx, "Video compression %s", str); } @@ -195,18 +195,18 @@ static int parse_video_var(AVFormatContext *avctx, AVStream *st, avpriv_set_pts_info(st, 64, fps.den, fps.num); st->avg_frame_rate = fps; } else if (!strcmp(name, "HEIGHT")) { - st->codec->height = var_read_int(pb, size); + st->codecpar->height = var_read_int(pb, size); } else if (!strcmp(name, "PIXEL_ASPECT")) { st->sample_aspect_ratio = var_read_float(pb, size); av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, INT_MAX); } else if (!strcmp(name, "WIDTH")) { - st->codec->width = var_read_int(pb, size); + st->codecpar->width = var_read_int(pb, size); } else if (!strcmp(name, "ORIENTATION")) { if (var_read_int(pb, size) == 1101) { - st->codec->extradata = av_strdup("BottomUp"); - st->codec->extradata_size = 9; + st->codecpar->extradata = av_strdup("BottomUp"); + st->codecpar->extradata_size = 9; } } else if (!strcmp(name, "Q_SPATIAL") || !strcmp(name, "Q_TEMPORAL")) { var_read_metadata(avctx, name, size); @@ -249,8 +249,8 @@ static void read_index(AVIOContext *pb, AVStream *st) uint32_t size = avio_rb32(pb); avio_skip(pb, 8); av_add_index_entry(st, pos, timestamp, size, 0, AVINDEX_KEYFRAME); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - timestamp += size / (st->codec->channels * 2); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + timestamp += size / (st->codecpar->channels * 2); } else { timestamp++; } @@ -282,37 +282,37 @@ static int mv_read_header(AVFormatContext *avctx) if (!vst) return AVERROR(ENOMEM); avpriv_set_pts_info(vst, 64, 1, 15); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; vst->avg_frame_rate = av_inv_q(vst->time_base); vst->nb_frames = avio_rb32(pb); v = avio_rb32(pb); switch (v) { case 1: - vst->codec->codec_id = AV_CODEC_ID_MVC1; + vst->codecpar->codec_id = AV_CODEC_ID_MVC1; break; case 2: - vst->codec->pix_fmt = AV_PIX_FMT_ARGB; - vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO; + vst->codecpar->format = AV_PIX_FMT_ARGB; + vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; break; default: avpriv_request_sample(avctx, "Video compression %i", v); break; } - vst->codec->codec_tag = 0; - vst->codec->width = avio_rb32(pb); - vst->codec->height = avio_rb32(pb); + vst->codecpar->codec_tag = 0; + vst->codecpar->width = avio_rb32(pb); + vst->codecpar->height = avio_rb32(pb); avio_skip(pb, 12); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; ast->nb_frames = vst->nb_frames; - ast->codec->sample_rate = avio_rb32(pb); - avpriv_set_pts_info(ast, 33, 1, ast->codec->sample_rate); + ast->codecpar->sample_rate = avio_rb32(pb); + avpriv_set_pts_info(ast, 33, 1, ast->codecpar->sample_rate); if (set_channels(avctx, ast, avio_rb32(pb)) < 0) return AVERROR_INVALIDDATA; v = avio_rb32(pb); if (v == AUDIO_FORMAT_SIGNED) { - ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; } else { avpriv_request_sample(avctx, "Audio compression (format %i)", v); } @@ -330,7 +330,7 @@ static int mv_read_header(AVFormatContext *avctx) avio_skip(pb, 8); av_add_index_entry(ast, pos, timestamp, asize, 0, AVINDEX_KEYFRAME); av_add_index_entry(vst, pos + asize, i, vsize, 0, AVINDEX_KEYFRAME); - timestamp += asize / (ast->codec->channels * 2); + timestamp += asize / (ast->codecpar->channels * 2); } } else if (!version && avio_rb16(pb) == 3) { avio_skip(pb, 4); @@ -344,20 +344,20 @@ static int mv_read_header(AVFormatContext *avctx) ast = avformat_new_stream(avctx, NULL); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; read_table(avctx, ast, parse_audio_var); if (mv->acompression == 100 && mv->aformat == AUDIO_FORMAT_SIGNED && - ast->codec->bits_per_coded_sample == 16) { - ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE; + ast->codecpar->bits_per_coded_sample == 16) { + ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; } else { avpriv_request_sample(avctx, "Audio compression %i (format %i, sr %i)", mv->acompression, mv->aformat, - ast->codec->bits_per_coded_sample); - ast->codec->codec_id = AV_CODEC_ID_NONE; + ast->codecpar->bits_per_coded_sample); + ast->codecpar->codec_id = AV_CODEC_ID_NONE; } - if (ast->codec->channels <= 0) { + if (ast->codecpar->channels <= 0) { av_log(avctx, AV_LOG_ERROR, "No valid channel count found.\n"); return AVERROR_INVALIDDATA; } @@ -370,7 +370,7 @@ static int mv_read_header(AVFormatContext *avctx) vst = avformat_new_stream(avctx, NULL); if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; read_table(avctx, vst, parse_video_var); } diff --git a/libavformat/mvi.c b/libavformat/mvi.c index 4abd1c670f..187407492f 100644 --- a/libavformat/mvi.c +++ b/libavformat/mvi.c @@ -54,18 +54,18 @@ static int read_header(AVFormatContext *s) if (!vst) return AVERROR(ENOMEM); - vst->codec->extradata_size = 2; - vst->codec->extradata = av_mallocz(2 + AV_INPUT_BUFFER_PADDING_SIZE); + vst->codecpar->extradata_size = 2; + vst->codecpar->extradata = av_mallocz(2 + AV_INPUT_BUFFER_PADDING_SIZE); version = avio_r8(pb); - vst->codec->extradata[0] = avio_r8(pb); - vst->codec->extradata[1] = avio_r8(pb); + vst->codecpar->extradata[0] = avio_r8(pb); + vst->codecpar->extradata[1] = avio_r8(pb); frames_count = avio_rl32(pb); msecs_per_frame = avio_rl32(pb); - vst->codec->width = avio_rl16(pb); - vst->codec->height = avio_rl16(pb); + vst->codecpar->width = avio_rl16(pb); + vst->codecpar->height = avio_rl16(pb); avio_r8(pb); - ast->codec->sample_rate = avio_rl16(pb); + ast->codecpar->sample_rate = avio_rl16(pb); mvi->audio_data_size = avio_rl32(pb); avio_r8(pb); player_version = avio_rl32(pb); @@ -80,20 +80,20 @@ static int read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_U8; - ast->codec->channels = 1; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; - ast->codec->bits_per_coded_sample = 8; - ast->codec->bit_rate = ast->codec->sample_rate * 8; + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + ast->codecpar->channels = 1; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + ast->codecpar->bits_per_coded_sample = 8; + ast->codecpar->bit_rate = ast->codecpar->sample_rate * 8; avpriv_set_pts_info(vst, 64, msecs_per_frame, 1000000); vst->avg_frame_rate = av_inv_q(vst->time_base); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_MOTIONPIXELS; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_MOTIONPIXELS; - mvi->get_int = (vst->codec->width * vst->codec->height < (1 << 16)) ? avio_rl16 : avio_rl24; + mvi->get_int = (vst->codecpar->width * vst->codecpar->height < (1 << 16)) ? avio_rl16 : avio_rl24; mvi->audio_frame_size = ((uint64_t)mvi->audio_data_size << MVI_FRAC_BITS) / frames_count; if (mvi->audio_frame_size <= 1 << MVI_FRAC_BITS - 1) { @@ -103,7 +103,7 @@ static int read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } - mvi->audio_size_counter = (ast->codec->sample_rate * 830 / mvi->audio_frame_size - 1) * mvi->audio_frame_size; + mvi->audio_size_counter = (ast->codecpar->sample_rate * 830 / mvi->audio_frame_size - 1) * mvi->audio_frame_size; mvi->audio_size_left = mvi->audio_data_size; return 0; diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 8678dc161b..c09e4f6dba 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -320,15 +320,15 @@ static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt, data_ptr = pkt->data; end_ptr = pkt->data + length; buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */ - for (; end_ptr - buf_ptr >= st->codec->channels * 4; ) { - for (i = 0; i < st->codec->channels; i++) { + for (; end_ptr - buf_ptr >= st->codecpar->channels * 4; ) { + for (i = 0; i < st->codecpar->channels; i++) { uint32_t sample = bytestream_get_le32(&buf_ptr); - if (st->codec->bits_per_coded_sample == 24) + if (st->codecpar->bits_per_coded_sample == 24) bytestream_put_le24(&data_ptr, (sample >> 4) & 0xffffff); else bytestream_put_le16(&data_ptr, (sample >> 12) & 0xffff); } - buf_ptr += 32 - st->codec->channels*4; // always 8 channels stored SMPTE 331M + buf_ptr += 32 - st->codecpar->channels*4; // always 8 channels stored SMPTE 331M } av_shrink_packet(pkt, data_ptr - pkt->data); return 0; @@ -1484,7 +1484,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) PRINT_KEY(mxf->fc, "data definition ul", source_track->sequence->data_definition_ul); codec_ul = mxf_get_codec_ul(ff_mxf_data_definition_uls, &source_track->sequence->data_definition_ul); - st->codec->codec_type = codec_ul->id; + st->codecpar->codec_type = codec_ul->id; source_package->descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor_ref, AnyType); if (source_package->descriptor) { @@ -1526,16 +1526,16 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) /* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */ codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->essence_codec_ul); - st->codec->codec_id = codec_ul->id; + st->codecpar->codec_id = codec_ul->id; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { source_track->intra_only = mxf_is_intra_only(descriptor); container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, essence_container_ul); - if (st->codec->codec_id == AV_CODEC_ID_NONE) - st->codec->codec_id = container_ul->id; - st->codec->width = descriptor->width; + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) + st->codecpar->codec_id = container_ul->id; + st->codecpar->width = descriptor->width; /* Field height, not frame height */ - st->codec->height = descriptor->height; + st->codecpar->height = descriptor->height; switch (descriptor->frame_layout) { case SegmentedFrame: /* This one is a weird layout I don't fully understand. */ @@ -1543,7 +1543,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) "SegmentedFrame layout isn't currently supported\n"); break; case FullFrame: - st->codec->field_order = AV_FIELD_PROGRESSIVE; + st->codecpar->field_order = AV_FIELD_PROGRESSIVE; break; case OneField: /* Every other line is stored and needs to be duplicated. */ @@ -1558,10 +1558,10 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) case MixedFields: switch (descriptor->field_dominance) { case MXF_TFF: - st->codec->field_order = AV_FIELD_TT; + st->codecpar->field_order = AV_FIELD_TT; break; case MXF_BFF: - st->codec->field_order = AV_FIELD_BB; + st->codecpar->field_order = AV_FIELD_BB; break; default: avpriv_request_sample(mxf->fc, @@ -1570,26 +1570,26 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) break; } /* Turn field height into frame height. */ - st->codec->height *= 2; + st->codecpar->height *= 2; break; default: av_log(mxf->fc, AV_LOG_INFO, "Unknown frame layout type: %d\n", descriptor->frame_layout); } - if (st->codec->codec_id == AV_CODEC_ID_RAWVIDEO) { - st->codec->pix_fmt = descriptor->pix_fmt; - if (st->codec->pix_fmt == AV_PIX_FMT_NONE) { + if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) { + st->codecpar->format = descriptor->pix_fmt; + if (st->codecpar->format == AV_PIX_FMT_NONE) { pix_fmt_ul = mxf_get_codec_ul(ff_mxf_pixel_format_uls, &descriptor->essence_codec_ul); - st->codec->pix_fmt = pix_fmt_ul->id; - if (st->codec->pix_fmt == AV_PIX_FMT_NONE) { + st->codecpar->format = pix_fmt_ul->id; + if (st->codecpar->format == AV_PIX_FMT_NONE) { /* support files created before RP224v10 by defaulting to UYVY422 if subsampling is 4:2:2 and component depth is 8-bit */ if (descriptor->horiz_subsampling == 2 && descriptor->vert_subsampling == 1 && descriptor->component_depth == 8) { - st->codec->pix_fmt = AV_PIX_FMT_UYVY422; + st->codecpar->format = AV_PIX_FMT_UYVY422; } } } @@ -1605,15 +1605,15 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) snprintf(source_origin, sizeof(source_origin), "%d", source_track->sequence->origin); av_dict_set(&st->metadata, "source_track_origin", source_origin, 0); } - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul); - if (st->codec->codec_id == AV_CODEC_ID_NONE) - st->codec->codec_id = container_ul->id; - st->codec->channels = descriptor->channels; - st->codec->bits_per_coded_sample = descriptor->bits_per_sample; + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) + st->codecpar->codec_id = container_ul->id; + st->codecpar->channels = descriptor->channels; + st->codecpar->bits_per_coded_sample = descriptor->bits_per_sample; if (descriptor->sample_rate.den > 0) { - st->codec->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den; + st->codecpar->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den; avpriv_set_pts_info(st, 64, descriptor->sample_rate.den, descriptor->sample_rate.num); } else { av_log(mxf->fc, AV_LOG_WARNING, "invalid sample rate (%d/%d) " @@ -1630,20 +1630,20 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) st->time_base); /* TODO: implement AV_CODEC_ID_RAWAUDIO */ - if (st->codec->codec_id == AV_CODEC_ID_PCM_S16LE) { + if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) { if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24) - st->codec->codec_id = AV_CODEC_ID_PCM_S24LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE; else if (descriptor->bits_per_sample == 32) - st->codec->codec_id = AV_CODEC_ID_PCM_S32LE; - } else if (st->codec->codec_id == AV_CODEC_ID_PCM_S16BE) { + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE; + } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) { if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24) - st->codec->codec_id = AV_CODEC_ID_PCM_S24BE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24BE; else if (descriptor->bits_per_sample == 32) - st->codec->codec_id = AV_CODEC_ID_PCM_S32BE; - } else if (st->codec->codec_id == AV_CODEC_ID_MP2) { + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE; + } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) { st->need_parsing = AVSTREAM_PARSE_FULL; } - } else if (st->codec->codec_type == AVMEDIA_TYPE_DATA) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { int codec_id = mxf_get_codec_ul(mxf_data_essence_container_uls, essence_container_ul)->id; if (codec_id >= 0 && @@ -1653,17 +1653,17 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } } if (descriptor->extradata) { - st->codec->extradata = av_mallocz(descriptor->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (st->codec->extradata) { - memcpy(st->codec->extradata, descriptor->extradata, descriptor->extradata_size); - st->codec->extradata_size = descriptor->extradata_size; + st->codecpar->extradata = av_mallocz(descriptor->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (st->codecpar->extradata) { + memcpy(st->codecpar->extradata, descriptor->extradata, descriptor->extradata_size); + st->codecpar->extradata_size = descriptor->extradata_size; } - } else if (st->codec->codec_id == AV_CODEC_ID_H264) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_H264) { ret = ff_generate_avci_extradata(st); if (ret < 0) return ret; } - if (st->codec->codec_type != AVMEDIA_TYPE_DATA && (*essence_container_ul)[15] > 0x01) { + if (st->codecpar->codec_type != AVMEDIA_TYPE_DATA && (*essence_container_ul)[15] > 0x01) { /* TODO: decode timestamps */ st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; } @@ -2059,8 +2059,8 @@ static void mxf_handle_small_eubc(AVFormatContext *s) /* expect PCM with exactly one index table segment and a small (< 32) EUBC */ if (s->nb_streams != 1 || - s->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO || - !is_pcm(s->streams[0]->codec->codec_id) || + s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || + !is_pcm(s->streams[0]->codecpar->codec_id) || mxf->nb_index_tables != 1 || mxf->index_tables[0].nb_segments != 1 || mxf->index_tables[0].segments[0]->edit_unit_byte_count >= 32) @@ -2315,21 +2315,21 @@ static int mxf_compute_sample_count(MXFContext *mxf, int stream_index, return 0; } -static int mxf_set_audio_pts(MXFContext *mxf, AVCodecContext *codec, +static int mxf_set_audio_pts(MXFContext *mxf, AVCodecParameters *par, AVPacket *pkt) { MXFTrack *track = mxf->fc->streams[pkt->stream_index]->priv_data; - int64_t bits_per_sample = codec->bits_per_coded_sample; + int64_t bits_per_sample = par->bits_per_coded_sample; if (!bits_per_sample) - bits_per_sample = av_get_bits_per_sample(codec->codec_id); + bits_per_sample = av_get_bits_per_sample(par->codec_id); pkt->pts = track->sample_count; - if (codec->channels <= 0 || codec->channels * bits_per_sample < 8) + if (par->channels <= 0 || par->channels * bits_per_sample < 8) return AVERROR_INVALIDDATA; - track->sample_count += pkt->size / (codec->channels * bits_per_sample / 8); + track->sample_count += pkt->size / (par->channels * bits_per_sample / 8); return 0; } @@ -2358,7 +2358,7 @@ static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt) int64_t next_ofs, next_klv; AVStream *st; MXFTrack *track; - AVCodecContext *codec; + AVCodecParameters *par; if (index < 0) { av_log(s, AV_LOG_ERROR, @@ -2404,9 +2404,9 @@ static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = index; pkt->pos = klv.offset; - codec = s->streams[index]->codec; + par = s->streams[index]->codecpar; - if (codec->codec_type == AVMEDIA_TYPE_VIDEO && next_ofs >= 0) { + if (par->codec_type == AVMEDIA_TYPE_VIDEO && next_ofs >= 0) { /* mxf->current_edit_unit good - see if we have an * index table to derive timestamps from */ MXFIndexTable *t = &mxf->index_tables[0]; @@ -2421,8 +2421,8 @@ static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt) * < PTS if low_delay = 0 (Sony IMX30) */ pkt->pts = mxf->current_edit_unit; } - } else if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { - ret = mxf_set_audio_pts(mxf, codec, pkt); + } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) { + ret = mxf_set_audio_pts(mxf, par, pkt); if (ret < 0) return ret; } @@ -2484,12 +2484,12 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = 0; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && t->ptses && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && t->ptses && mxf->current_edit_unit >= 0 && mxf->current_edit_unit < t->nb_ptses) { pkt->dts = mxf->current_edit_unit + t->first_dts; pkt->pts = t->ptses[mxf->current_edit_unit]; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - int ret = mxf_set_audio_pts(mxf, st->codec, pkt); + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + int ret = mxf_set_audio_pts(mxf, st->codecpar, pkt); if (ret < 0) return ret; } @@ -2581,7 +2581,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti MXFTrack *source_track = st->priv_data; /* if audio then truncate sample_time to EditRate */ - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) sample_time = av_rescale_q(sample_time, st->time_base, av_inv_q(source_track->edit_rate)); @@ -2628,7 +2628,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti AVStream *cur_st = s->streams[i]; MXFTrack *cur_track = cur_st->priv_data; uint64_t current_sample_count = 0; - if (cur_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (cur_st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { ret = mxf_compute_sample_count(mxf, i, ¤t_sample_count); if (ret < 0) return ret; diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 3a3008b9d3..c5d2de0a4d 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -611,7 +611,7 @@ static void mxf_write_common_fields(AVFormatContext *s, AVStream *st) if (st == mxf->timecode_track) avio_write(pb, smpte_12m_timecode_track_data_ul, 16); else { - const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codec->codec_type); + const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codecpar->codec_type); avio_write(pb, data_def_ul->uid, 16); } @@ -782,27 +782,27 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke { MXFStreamContext *sc = st->priv_data; AVIOContext *pb = s->pb; - int stored_height = (st->codec->height+15)/16*16; + int stored_height = (st->codecpar->height+15)/16*16; int display_height; int f1, f2; mxf_write_generic_desc(s, st, key, size+8+8+8+8+8+8+5+16+sc->interlaced*4+12+20); mxf_write_local_tag(pb, 4, 0x3203); - avio_wb32(pb, st->codec->width); + avio_wb32(pb, st->codecpar->width); mxf_write_local_tag(pb, 4, 0x3202); avio_wb32(pb, stored_height>>sc->interlaced); mxf_write_local_tag(pb, 4, 0x3209); - avio_wb32(pb, st->codec->width); + avio_wb32(pb, st->codecpar->width); - if (st->codec->height == 608) // PAL + VBI + if (st->codecpar->height == 608) // PAL + VBI display_height = 576; - else if (st->codec->height == 512) // NTSC + VBI + else if (st->codecpar->height == 512) // NTSC + VBI display_height = 486; else - display_height = st->codec->height; + display_height = st->codecpar->height; mxf_write_local_tag(pb, 4, 0x3208); avio_wb32(pb, display_height>>sc->interlaced); @@ -820,7 +820,7 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke avio_w8(pb, sc->interlaced); // video line map - switch (st->codec->height) { + switch (st->codecpar->height) { case 576: f1 = 23; f2 = 336; break; case 608: f1 = 7; f2 = 320; break; case 480: f1 = 20; f2 = 283; break; @@ -858,17 +858,17 @@ static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st) static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st) { AVIOContext *pb = s->pb; - int profile_and_level = (st->codec->profile<<4) | st->codec->level; + int profile_and_level = (st->codecpar->profile<<4) | st->codecpar->level; mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5); // bit rate mxf_write_local_tag(pb, 4, 0x8000); - avio_wb32(pb, st->codec->bit_rate); + avio_wb32(pb, st->codecpar->bit_rate); // profile and level mxf_write_local_tag(pb, 1, 0x8007); - if (!st->codec->profile) + if (!st->codecpar->profile) profile_and_level |= 0x80; // escape bit avio_w8(pb, profile_and_level); } @@ -885,14 +885,14 @@ static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con // write audio sampling rate mxf_write_local_tag(pb, 8, 0x3D03); - avio_wb32(pb, st->codec->sample_rate); + avio_wb32(pb, st->codecpar->sample_rate); avio_wb32(pb, 1); mxf_write_local_tag(pb, 4, 0x3D07); - avio_wb32(pb, st->codec->channels); + avio_wb32(pb, st->codecpar->channels); mxf_write_local_tag(pb, 4, 0x3D01); - avio_wb32(pb, av_get_bits_per_sample(st->codec->codec_id)); + avio_wb32(pb, av_get_bits_per_sample(st->codecpar->codec_id)); } static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size) @@ -902,11 +902,11 @@ static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key mxf_write_generic_sound_common(s, st, key, size+6+8); mxf_write_local_tag(pb, 2, 0x3D0A); - avio_wb16(pb, st->codec->block_align); + avio_wb16(pb, st->codecpar->block_align); // avg bytes per sec mxf_write_local_tag(pb, 4, 0x3D09); - avio_wb32(pb, st->codec->block_align*st->codec->sample_rate); + avio_wb32(pb, st->codecpar->block_align*st->codecpar->sample_rate); } static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st) @@ -1293,21 +1293,21 @@ static const UID mxf_mpeg2_codec_uls[] = { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP }; -static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx) +static const UID *mxf_get_mpeg2_codec_ul(AVCodecParameters *par) { int long_gop = 1; - if (avctx->profile == 4) { // Main - if (avctx->level == 8) // Main + if (par->profile == 4) { // Main + if (par->level == 8) // Main return &mxf_mpeg2_codec_uls[0+long_gop]; - else if (avctx->level == 4) // High + else if (par->level == 4) // High return &mxf_mpeg2_codec_uls[4+long_gop]; - else if (avctx->level == 6) // High 14 + else if (par->level == 6) // High 14 return &mxf_mpeg2_codec_uls[8+long_gop]; - } else if (avctx->profile == 0) { // 422 - if (avctx->level == 5) // Main + } else if (par->profile == 0) { // 422 + if (par->level == 5) // Main return &mxf_mpeg2_codec_uls[2+long_gop]; - else if (avctx->level == 2) // High + else if (par->level == 2) // High return &mxf_mpeg2_codec_uls[6+long_gop]; } return NULL; @@ -1325,8 +1325,8 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, c = (c<<8) + pkt->data[i]; if (c == 0x1b5) { if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext - st->codec->profile = pkt->data[i+1] & 0x07; - st->codec->level = pkt->data[i+2] >> 4; + st->codecpar->profile = pkt->data[i+1] & 0x07; + st->codecpar->level = pkt->data[i+2] >> 4; } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame break; @@ -1360,7 +1360,7 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, case 4: sc->aspect_ratio = (AVRational){221,100}; break; default: av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, - st->codec->width, st->codec->height, 1024*1024); + st->codecpar->width, st->codecpar->height, 1024*1024); } } else if (c == 0x100) { // pic int pict_type = (pkt->data[i+2]>>3) & 0x07; @@ -1381,7 +1381,7 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, } } if (s->oformat != &ff_mxf_d10_muxer) - sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codec); + sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codecpar); return !!sc->codec_ul; } @@ -1430,7 +1430,7 @@ static int mxf_write_header(AVFormatContext *s) return AVERROR(ENOMEM); st->priv_data = sc; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (i != 0) { av_log(s, AV_LOG_ERROR, "video stream must be first track\n"); return -1; @@ -1450,13 +1450,13 @@ static int mxf_write_header(AVFormatContext *s) } avpriv_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den); if (s->oformat == &ff_mxf_d10_muxer) { - if (st->codec->bit_rate == 50000000) + if (st->codecpar->bit_rate == 50000000) if (mxf->time_base.den == 25) sc->index = 3; else sc->index = 5; - else if (st->codec->bit_rate == 40000000) + else if (st->codecpar->bit_rate == 40000000) if (mxf->time_base.den == 25) sc->index = 7; else sc->index = 9; - else if (st->codec->bit_rate == 30000000) + else if (st->codecpar->bit_rate == 30000000) if (mxf->time_base.den == 25) sc->index = 11; else sc->index = 13; else { @@ -1465,25 +1465,25 @@ static int mxf_write_header(AVFormatContext *s) } mxf->edit_unit_byte_count = KAG_SIZE; // system element - mxf->edit_unit_byte_count += 16 + 4 + (uint64_t)st->codec->bit_rate * + mxf->edit_unit_byte_count += 16 + 4 + (uint64_t)st->codecpar->bit_rate * mxf->time_base.num / (8*mxf->time_base.den); mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); mxf->edit_unit_byte_count += 16 + 4 + 4 + samples_per_frame[0]*8*4; mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); } - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->codec->sample_rate != 48000) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->sample_rate != 48000) { av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n"); return -1; } - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); if (s->oformat == &ff_mxf_d10_muxer) { if (st->index != 1) { av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n"); return -1; } - if (st->codec->codec_id != AV_CODEC_ID_PCM_S16LE && - st->codec->codec_id != AV_CODEC_ID_PCM_S24LE) { + if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE && + st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) { av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n"); } sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1; @@ -1492,7 +1492,7 @@ static int mxf_write_header(AVFormatContext *s) } if (!sc->index) { - sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id); + sc->index = mxf_get_essence_container_ul_index(st->codecpar->codec_id); if (sc->index == -1) { av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, " "codec not currently supported in container\n", i); @@ -1615,7 +1615,7 @@ static void mxf_write_d10_video_packet(AVFormatContext *s, AVStream *st, AVPacke { MXFContext *mxf = s->priv_data; AVIOContext *pb = s->pb; - int packet_size = (uint64_t)st->codec->bit_rate*mxf->time_base.num / + int packet_size = (uint64_t)st->codecpar->bit_rate*mxf->time_base.num / (8*mxf->time_base.den); // frame size int pad; @@ -1645,7 +1645,7 @@ static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacke { MXFContext *mxf = s->priv_data; AVIOContext *pb = s->pb; - int frame_size = pkt->size / st->codec->block_align; + int frame_size = pkt->size / st->codecpar->block_align; uint8_t *samples = pkt->data; uint8_t *end = pkt->data + pkt->size; int i; @@ -1654,12 +1654,12 @@ static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacke avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1)); avio_wl16(pb, frame_size); - avio_w8(pb, (1<<st->codec->channels)-1); + avio_w8(pb, (1<<st->codecpar->channels)-1); while (samples < end) { - for (i = 0; i < st->codec->channels; i++) { + for (i = 0; i < st->codecpar->channels; i++) { uint32_t sample; - if (st->codec->codec_id == AV_CODEC_ID_PCM_S24LE) { + if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) { sample = AV_RL24(samples)<< 4; samples += 3; } else { @@ -1691,7 +1691,7 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) } } - if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) { + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) { if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) { av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n"); return -1; @@ -1740,7 +1740,7 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) mxf_write_klv_fill(s); avio_write(pb, sc->track_essence_element_key, 16); // write key if (s->oformat == &ff_mxf_d10_muxer) { - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) mxf_write_d10_video_packet(s, st, pkt); else mxf_write_d10_audio_packet(s, st, pkt); diff --git a/libavformat/mxg.c b/libavformat/mxg.c index 396dbdeaf6..245afb40ef 100644 --- a/libavformat/mxg.c +++ b/libavformat/mxg.c @@ -48,20 +48,20 @@ static int mxg_read_header(AVFormatContext *s) video_st = avformat_new_stream(s, NULL); if (!video_st) return AVERROR(ENOMEM); - video_st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - video_st->codec->codec_id = AV_CODEC_ID_MXPEG; + video_st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + video_st->codecpar->codec_id = AV_CODEC_ID_MXPEG; avpriv_set_pts_info(video_st, 64, 1, 1000000); audio_st = avformat_new_stream(s, NULL); if (!audio_st) return AVERROR(ENOMEM); - audio_st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - audio_st->codec->codec_id = AV_CODEC_ID_PCM_ALAW; - audio_st->codec->channels = 1; - audio_st->codec->channel_layout = AV_CH_LAYOUT_MONO; - audio_st->codec->sample_rate = 8000; - audio_st->codec->bits_per_coded_sample = 8; - audio_st->codec->block_align = 1; + audio_st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + audio_st->codecpar->codec_id = AV_CODEC_ID_PCM_ALAW; + audio_st->codecpar->channels = 1; + audio_st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + audio_st->codecpar->sample_rate = 8000; + audio_st->codecpar->bits_per_coded_sample = 8; + audio_st->codecpar->block_align = 1; avpriv_set_pts_info(audio_st, 64, 1, 1000000); mxg->soi_ptr = mxg->buffer_ptr = mxg->buffer = 0; diff --git a/libavformat/ncdec.c b/libavformat/ncdec.c index ee2aee3664..d726a2e42b 100644 --- a/libavformat/ncdec.c +++ b/libavformat/ncdec.c @@ -51,8 +51,8 @@ static int nc_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG4; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG4; st->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 100); diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index 6e31d9b0b8..601357b793 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -435,12 +435,12 @@ static int nsv_parse_NSVs_header(AVFormatContext *s) if (!nst) goto fail; st->priv_data = nst; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = vtag; - st->codec->codec_id = ff_codec_get_id(nsv_codec_video_tags, vtag); - st->codec->width = vwidth; - st->codec->height = vheight; - st->codec->bits_per_coded_sample = 24; /* depth XXX */ + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = vtag; + st->codecpar->codec_id = ff_codec_get_id(nsv_codec_video_tags, vtag); + st->codecpar->width = vwidth; + st->codecpar->height = vheight; + st->codecpar->bits_per_coded_sample = 24; /* depth XXX */ avpriv_set_pts_info(st, 64, framerate.den, framerate.num); st->start_time = 0; @@ -466,9 +466,9 @@ static int nsv_parse_NSVs_header(AVFormatContext *s) if (!nst) goto fail; st->priv_data = nst; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = atag; - st->codec->codec_id = ff_codec_get_id(nsv_codec_audio_tags, atag); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = atag; + st->codecpar->codec_id = ff_codec_get_id(nsv_codec_audio_tags, atag); st->need_parsing = AVSTREAM_PARSE_FULL; /* for PCM we will read a chunk later and put correct info */ @@ -613,7 +613,7 @@ null_chunk_retry: pkt = &nsv->ahead[NSV_ST_AUDIO]; /* read raw audio specific header on the first audio chunk... */ /* on ALL audio chunks ?? seems so! */ - if (asize && st[NSV_ST_AUDIO]->codec->codec_tag == MKTAG('P', 'C', 'M', ' ')/* && fill_header*/) { + if (asize && st[NSV_ST_AUDIO]->codecpar->codec_tag == MKTAG('P', 'C', 'M', ' ')/* && fill_header*/) { uint8_t bps; uint8_t channels; uint16_t samplerate; @@ -631,11 +631,11 @@ null_chunk_retry: } bps /= channels; // ??? if (bps == 8) - st[NSV_ST_AUDIO]->codec->codec_id = AV_CODEC_ID_PCM_U8; + st[NSV_ST_AUDIO]->codecpar->codec_id = AV_CODEC_ID_PCM_U8; samplerate /= 4;/* UGH ??? XXX */ channels = 1; - st[NSV_ST_AUDIO]->codec->channels = channels; - st[NSV_ST_AUDIO]->codec->sample_rate = samplerate; + st[NSV_ST_AUDIO]->codecpar->channels = channels; + st[NSV_ST_AUDIO]->codecpar->sample_rate = samplerate; av_log(s, AV_LOG_TRACE, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate); } } diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index e39f7d3e54..b554f85101 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -367,11 +367,11 @@ static int decode_stream_header(NUTContext *nut) class = ffio_read_varlen(bc); tmp = get_fourcc(bc); - st->codec->codec_tag = tmp; + st->codecpar->codec_tag = tmp; switch (class) { case 0: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) { + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) { ff_nut_video_tags, ff_codec_bmp_tags, 0 @@ -379,8 +379,8 @@ static int decode_stream_header(NUTContext *nut) tmp); break; case 1: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) { + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) { ff_nut_audio_tags, ff_codec_wav_tags, 0 @@ -388,18 +388,18 @@ static int decode_stream_header(NUTContext *nut) tmp); break; case 2: - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = ff_codec_get_id(ff_nut_subtitle_tags, tmp); + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = ff_codec_get_id(ff_nut_subtitle_tags, tmp); break; case 3: - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = ff_codec_get_id(ff_nut_data_tags, tmp); + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = ff_codec_get_id(ff_nut_data_tags, tmp); break; default: av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class); return AVERROR(ENOSYS); } - if (class < 3 && st->codec->codec_id == AV_CODEC_ID_NONE) + if (class < 3 && st->codecpar->codec_id == AV_CODEC_ID_NONE) av_log(s, AV_LOG_ERROR, "Unknown codec tag '0x%04x' for stream number %d\n", (unsigned int) tmp, stream_id); @@ -410,18 +410,18 @@ static int decode_stream_header(NUTContext *nut) GET_V(stc->decode_delay, tmp < 1000); // sanity limit, raise this if Moore's law is true ffio_read_varlen(bc); // stream flags - GET_V(st->codec->extradata_size, tmp < (1 << 30)); - if (st->codec->extradata_size) { - st->codec->extradata = av_mallocz(st->codec->extradata_size + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + GET_V(st->codecpar->extradata_size, tmp < (1 << 30)); + if (st->codecpar->extradata_size) { + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - avio_read(bc, st->codec->extradata, st->codec->extradata_size); + avio_read(bc, st->codecpar->extradata, st->codecpar->extradata_size); } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - GET_V(st->codec->width, tmp > 0); - GET_V(st->codec->height, tmp > 0); + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + GET_V(st->codecpar->width, tmp > 0); + GET_V(st->codecpar->height, tmp > 0); st->sample_aspect_ratio.num = ffio_read_varlen(bc); st->sample_aspect_ratio.den = ffio_read_varlen(bc); if ((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)) { @@ -430,10 +430,10 @@ static int decode_stream_header(NUTContext *nut) return AVERROR_INVALIDDATA; } ffio_read_varlen(bc); /* csp type */ - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - GET_V(st->codec->sample_rate, tmp > 0); + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + GET_V(st->codecpar->sample_rate, tmp > 0); ffio_read_varlen(bc); // samplerate_den - GET_V(st->codec->channels, tmp > 0); + GET_V(st->codecpar->channels, tmp > 0); } if (skip_reserved(bc, end) || ffio_get_checksum(bc)) { av_log(s, AV_LOG_ERROR, diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 7b69ff3099..bf23b58a3b 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -33,32 +33,32 @@ #include "avio_internal.h" #include "riff.h" -static int find_expected_header(AVCodecContext *c, int size, int key_frame, +static int find_expected_header(AVCodecParameters *p, int size, int key_frame, uint8_t out[64]) { - int sample_rate = c->sample_rate; + int sample_rate = p->sample_rate; if (size > 4096) return 0; AV_WB24(out, 1); - if (c->codec_id == AV_CODEC_ID_MPEG4) { + if (p->codec_id == AV_CODEC_ID_MPEG4) { if (key_frame) { return 3; } else { out[3] = 0xB6; return 4; } - } else if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO || - c->codec_id == AV_CODEC_ID_MPEG2VIDEO) { + } else if (p->codec_id == AV_CODEC_ID_MPEG1VIDEO || + p->codec_id == AV_CODEC_ID_MPEG2VIDEO) { return 3; - } else if (c->codec_id == AV_CODEC_ID_H264) { + } else if (p->codec_id == AV_CODEC_ID_H264) { return 3; - } else if (c->codec_id == AV_CODEC_ID_MP3 || - c->codec_id == AV_CODEC_ID_MP2) { + } else if (p->codec_id == AV_CODEC_ID_MP3 || + p->codec_id == AV_CODEC_ID_MP2) { int lsf, mpeg25, sample_rate_index, bitrate_index, frame_size; - int layer = c->codec_id == AV_CODEC_ID_MP3 ? 3 : 2; + int layer = p->codec_id == AV_CODEC_ID_MP3 ? 3 : 2; unsigned int header = 0xFFF00000; lsf = sample_rate < (24000 + 32000) / 2; @@ -103,13 +103,13 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, return 0; } -static int find_header_idx(AVFormatContext *s, AVCodecContext *c, int size, +static int find_header_idx(AVFormatContext *s, AVCodecParameters *p, int size, int frame_type) { NUTContext *nut = s->priv_data; uint8_t out[64]; int i; - int len = find_expected_header(c, size, frame_type, out); + int len = find_expected_header(p, size, frame_type, out); for (i = 1; i < nut->header_count; i++) { if (len == nut->header_len[i] && !memcmp(out, nut->header[i], len)) { @@ -169,9 +169,9 @@ static void build_frame_code(AVFormatContext *s) for (stream_id = 0; stream_id < s->nb_streams; stream_id++) { int start2 = start + (end - start) * stream_id / s->nb_streams; int end2 = start + (end - start) * (stream_id + 1) / s->nb_streams; - AVCodecContext *codec = s->streams[stream_id]->codec; - const AVCodecDescriptor *desc = avcodec_descriptor_get(codec->codec_id); - int is_audio = codec->codec_type == AVMEDIA_TYPE_AUDIO; + AVCodecParameters *par = s->streams[stream_id]->codecpar; + const AVCodecDescriptor *desc = avcodec_descriptor_get(par->codec_id); + int is_audio = par->codec_type == AVMEDIA_TYPE_AUDIO; int intra_only = /*codec->intra_only || */ is_audio; int pred_count; @@ -183,7 +183,7 @@ static void build_frame_code(AVFormatContext *s) ft->stream_id = stream_id; ft->size_mul = 1; if (is_audio) - ft->header_idx = find_header_idx(s, codec, -1, key_frame); + ft->header_idx = find_header_idx(s, par, -1, key_frame); start2++; } } @@ -193,11 +193,11 @@ static void build_frame_code(AVFormatContext *s) int frame_bytes; int pts; - if (codec->block_align > 0) { - frame_bytes = codec->block_align; + if (par->block_align > 0) { + frame_bytes = par->block_align; } else { - int frame_size = av_get_audio_frame_duration(codec, 0); - frame_bytes = frame_size * (int64_t)codec->bit_rate / (8 * codec->sample_rate); + int frame_size = av_get_audio_frame_duration2(par, 0); + frame_bytes = frame_size * (int64_t)par->bit_rate / (8 * par->sample_rate); } for (pts = 0; pts < 2; pts++) @@ -208,7 +208,7 @@ static void build_frame_code(AVFormatContext *s) ft->size_mul = frame_bytes + 2; ft->size_lsb = frame_bytes + pred; ft->pts_delta = pts; - ft->header_idx = find_header_idx(s, codec, frame_bytes + pred, key_frame); + ft->header_idx = find_header_idx(s, par, frame_bytes + pred, key_frame); start2++; } } else { @@ -227,7 +227,7 @@ static void build_frame_code(AVFormatContext *s) pred_table[2] = 1; pred_table[3] = 3; pred_table[4] = 4; - } else if (codec->codec_id == AV_CODEC_ID_VORBIS) { + } else if (par->codec_id == AV_CODEC_ID_VORBIS) { pred_count = 3; pred_table[0] = 2; pred_table[1] = 9; @@ -251,7 +251,7 @@ static void build_frame_code(AVFormatContext *s) ft->size_lsb = index - start3; ft->pts_delta = pred_table[pred]; if (is_audio) - ft->header_idx = find_header_idx(s, codec, -1, key_frame); + ft->header_idx = find_header_idx(s, par, -1, key_frame); } } } @@ -424,12 +424,12 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream *st, int i) { NUTContext *nut = avctx->priv_data; - AVCodecContext *codec = st->codec; - const AVCodecDescriptor *desc = avcodec_descriptor_get(codec->codec_id); - unsigned codec_tag = av_codec_get_tag(ff_nut_codec_tags, codec->codec_id); + AVCodecParameters *par = st->codecpar; + const AVCodecDescriptor *desc = avcodec_descriptor_get(par->codec_id); + unsigned codec_tag = av_codec_get_tag(ff_nut_codec_tags, par->codec_id); ff_put_v(bc, i); - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0); break; @@ -445,9 +445,9 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, } ff_put_v(bc, 4); - if (av_codec_get_id(ff_nut_codec_tags, codec->codec_tag) == codec->codec_id || - !codec_tag || codec->codec_id == AV_CODEC_ID_RAWVIDEO) - codec_tag = codec->codec_tag; + if (av_codec_get_id(ff_nut_codec_tags, par->codec_tag) == par->codec_id || + !codec_tag || par->codec_id == AV_CODEC_ID_RAWVIDEO) + codec_tag = par->codec_tag; if (codec_tag) { avio_wl32(bc, codec_tag); @@ -462,18 +462,18 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, ff_put_v(bc, (desc && desc->props & AV_CODEC_PROP_REORDER) ? 16 : 0); avio_w8(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */ - ff_put_v(bc, codec->extradata_size); - avio_write(bc, codec->extradata, codec->extradata_size); + ff_put_v(bc, par->extradata_size); + avio_write(bc, par->extradata, par->extradata_size); - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: - ff_put_v(bc, codec->sample_rate); + ff_put_v(bc, par->sample_rate); ff_put_v(bc, 1); - ff_put_v(bc, codec->channels); + ff_put_v(bc, par->channels); break; case AVMEDIA_TYPE_VIDEO: - ff_put_v(bc, codec->width); - ff_put_v(bc, codec->height); + ff_put_v(bc, par->width); + ff_put_v(bc, par->height); if (st->sample_aspect_ratio.num <= 0 || st->sample_aspect_ratio.den <= 0) { diff --git a/libavformat/nuv.c b/libavformat/nuv.c index f553dd1e25..7fc339a2fe 100644 --- a/libavformat/nuv.c +++ b/libavformat/nuv.c @@ -83,15 +83,15 @@ static int get_codec_data(AVIOContext *pb, AVStream *vst, avio_skip(pb, 6); size = PKTSIZE(avio_rl32(pb)); if (vst && subtype == 'R') { - if (vst->codec->extradata) { - av_freep(&vst->codec->extradata); - vst->codec->extradata_size = 0; + if (vst->codecpar->extradata) { + av_freep(&vst->codecpar->extradata); + vst->codecpar->extradata_size = 0; } - vst->codec->extradata = av_malloc(size); - if (!vst->codec->extradata) + vst->codecpar->extradata = av_malloc(size); + if (!vst->codecpar->extradata) return AVERROR(ENOMEM); - vst->codec->extradata_size = size; - avio_read(pb, vst->codec->extradata, size); + vst->codecpar->extradata_size = size; + avio_read(pb, vst->codecpar->extradata, size); size = 0; if (!myth) return 0; @@ -104,32 +104,32 @@ static int get_codec_data(AVIOContext *pb, AVStream *vst, break; avio_rl32(pb); // version if (vst) { - vst->codec->codec_tag = avio_rl32(pb); - vst->codec->codec_id = - ff_codec_get_id(ff_codec_bmp_tags, vst->codec->codec_tag); - if (vst->codec->codec_tag == MKTAG('R', 'J', 'P', 'G')) - vst->codec->codec_id = AV_CODEC_ID_NUV; + vst->codecpar->codec_tag = avio_rl32(pb); + vst->codecpar->codec_id = + ff_codec_get_id(ff_codec_bmp_tags, vst->codecpar->codec_tag); + if (vst->codecpar->codec_tag == MKTAG('R', 'J', 'P', 'G')) + vst->codecpar->codec_id = AV_CODEC_ID_NUV; } else avio_skip(pb, 4); if (ast) { int id; - ast->codec->codec_tag = avio_rl32(pb); - ast->codec->sample_rate = avio_rl32(pb); - ast->codec->bits_per_coded_sample = avio_rl32(pb); - ast->codec->channels = avio_rl32(pb); - ast->codec->channel_layout = 0; + ast->codecpar->codec_tag = avio_rl32(pb); + ast->codecpar->sample_rate = avio_rl32(pb); + ast->codecpar->bits_per_coded_sample = avio_rl32(pb); + ast->codecpar->channels = avio_rl32(pb); + ast->codecpar->channel_layout = 0; - id = ff_wav_codec_get_id(ast->codec->codec_tag, - ast->codec->bits_per_coded_sample); + id = ff_wav_codec_get_id(ast->codecpar->codec_tag, + ast->codecpar->bits_per_coded_sample); if (id == AV_CODEC_ID_NONE) { - id = ff_codec_get_id(nuv_audio_tags, ast->codec->codec_tag); + id = ff_codec_get_id(nuv_audio_tags, ast->codecpar->codec_tag); if (id == AV_CODEC_ID_PCM_S16LE) - id = ff_get_pcm_codec_id(ast->codec->bits_per_coded_sample, + id = ff_get_pcm_codec_id(ast->codecpar->bits_per_coded_sample, 0, 0, ~1); } - ast->codec->codec_id = id; + ast->codecpar->codec_id = id; ast->need_parsing = AVSTREAM_PARSE_FULL; } else @@ -202,11 +202,11 @@ static int nuv_header(AVFormatContext *s) if (ret < 0) return ret; - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_NUV; - vst->codec->width = width; - vst->codec->height = height; - vst->codec->bits_per_coded_sample = 10; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_NUV; + vst->codecpar->width = width; + vst->codecpar->height = height; + vst->codecpar->bits_per_coded_sample = 10; vst->sample_aspect_ratio = av_d2q(aspect * height / width, 10000); vst->avg_frame_rate = av_d2q(fps, 60000); @@ -220,14 +220,14 @@ static int nuv_header(AVFormatContext *s) return AVERROR(ENOMEM); ctx->a_id = ast->index; - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_S16LE; - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; - ast->codec->sample_rate = 44100; - ast->codec->bit_rate = 2 * 2 * 44100 * 8; - ast->codec->block_align = 2 * 2; - ast->codec->bits_per_coded_sample = 16; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->sample_rate = 44100; + ast->codecpar->bit_rate = 2 * 2 * 44100 * 8; + ast->codecpar->block_align = 2 * 2; + ast->codecpar->bits_per_coded_sample = 16; avpriv_set_pts_info(ast, 32, 1, 1000); } else ctx->a_id = -1; @@ -235,7 +235,7 @@ static int nuv_header(AVFormatContext *s) if ((ret = get_codec_data(pb, vst, ast, is_mythtv)) < 0) return ret; - ctx->rtjpg_video = vst && vst->codec->codec_id == AV_CODEC_ID_NUV; + ctx->rtjpg_video = vst && vst->codecpar->codec_id == AV_CODEC_ID_NUV; return 0; } diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index 15526ffa01..9ec24973c6 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -691,7 +691,7 @@ static int ogg_read_seek(AVFormatContext *s, int stream_index, // Try seeking to a keyframe first. If this fails (very possible), // av_seek_frame will fall back to ignoring keyframes - if (s->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO + if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && !(flags & AVSEEK_FLAG_ANY)) os->keyframe_seek = 1; diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index 8f8a08f1bd..2fef74ad7a 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -212,7 +212,7 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st, int i, segments, len, flush = 0; // Handles VFR by flushing page because this frame needs to have a timestamp - if (st->codec->codec_id == AV_CODEC_ID_THEORA && !header && + if (st->codecpar->codec_id == AV_CODEC_ID_THEORA && !header && ogg_granule_to_timestamp(oggstream, granule) > ogg_granule_to_timestamp(oggstream, oggstream->last_granule) + 1) { if (oggstream->page.granule != -1) @@ -294,13 +294,13 @@ static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact, return p0; } -static int ogg_build_flac_headers(AVCodecContext *avctx, +static int ogg_build_flac_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m) { uint8_t *p; - if (avctx->extradata_size < FLAC_STREAMINFO_SIZE) + if (par->extradata_size < FLAC_STREAMINFO_SIZE) return AVERROR(EINVAL); // first packet: STREAMINFO @@ -317,7 +317,7 @@ static int ogg_build_flac_headers(AVCodecContext *avctx, bytestream_put_buffer(&p, "fLaC", 4); bytestream_put_byte(&p, 0x00); // streaminfo bytestream_put_be24(&p, 34); - bytestream_put_buffer(&p, avctx->extradata, FLAC_STREAMINFO_SIZE); + bytestream_put_buffer(&p, par->extradata, FLAC_STREAMINFO_SIZE); // second packet: VorbisComment p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0); @@ -332,13 +332,13 @@ static int ogg_build_flac_headers(AVCodecContext *avctx, #define SPEEX_HEADER_SIZE 80 -static int ogg_build_speex_headers(AVCodecContext *avctx, +static int ogg_build_speex_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m) { uint8_t *p; - if (avctx->extradata_size < SPEEX_HEADER_SIZE) + if (par->extradata_size < SPEEX_HEADER_SIZE) return -1; // first packet: Speex header @@ -347,7 +347,7 @@ static int ogg_build_speex_headers(AVCodecContext *avctx, return AVERROR(ENOMEM); oggstream->header[0] = p; oggstream->header_len[0] = SPEEX_HEADER_SIZE; - bytestream_put_buffer(&p, avctx->extradata, SPEEX_HEADER_SIZE); + bytestream_put_buffer(&p, par->extradata, SPEEX_HEADER_SIZE); AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0 // second packet: VorbisComment @@ -361,22 +361,22 @@ static int ogg_build_speex_headers(AVCodecContext *avctx, #define OPUS_HEADER_SIZE 19 -static int ogg_build_opus_headers(AVCodecContext *avctx, +static int ogg_build_opus_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m) { uint8_t *p; - if (avctx->extradata_size < OPUS_HEADER_SIZE) + if (par->extradata_size < OPUS_HEADER_SIZE) return -1; /* first packet: Opus header */ - p = av_mallocz(avctx->extradata_size); + p = av_mallocz(par->extradata_size); if (!p) return AVERROR(ENOMEM); oggstream->header[0] = p; - oggstream->header_len[0] = avctx->extradata_size; - bytestream_put_buffer(&p, avctx->extradata, avctx->extradata_size); + oggstream->header_len[0] = par->extradata_size; + bytestream_put_buffer(&p, par->extradata, par->extradata_size); /* second packet: VorbisComment */ p = ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0); @@ -423,23 +423,23 @@ static int ogg_write_header(AVFormatContext *s) AVStream *st = s->streams[i]; unsigned serial_num = i + ogg->serial_offset; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) - if (st->codec->codec_id == AV_CODEC_ID_OPUS) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) /* Opus requires a fixed 48kHz clock */ avpriv_set_pts_info(st, 64, 1, 48000); else - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); - if (st->codec->codec_id != AV_CODEC_ID_VORBIS && - st->codec->codec_id != AV_CODEC_ID_THEORA && - st->codec->codec_id != AV_CODEC_ID_SPEEX && - st->codec->codec_id != AV_CODEC_ID_FLAC && - st->codec->codec_id != AV_CODEC_ID_OPUS) { + if (st->codecpar->codec_id != AV_CODEC_ID_VORBIS && + st->codecpar->codec_id != AV_CODEC_ID_THEORA && + st->codecpar->codec_id != AV_CODEC_ID_SPEEX && + st->codecpar->codec_id != AV_CODEC_ID_FLAC && + st->codecpar->codec_id != AV_CODEC_ID_OPUS) { av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i); return -1; } - if (!st->codec->extradata || !st->codec->extradata_size) { + if (!st->codecpar->extradata || !st->codecpar->extradata_size) { av_log(s, AV_LOG_ERROR, "No extradata present\n"); return -1; } @@ -460,8 +460,8 @@ static int ogg_write_header(AVFormatContext *s) oggstream->serial_num = serial_num; st->priv_data = oggstream; - if (st->codec->codec_id == AV_CODEC_ID_FLAC) { - int err = ogg_build_flac_headers(st->codec, oggstream, + if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) { + int err = ogg_build_flac_headers(st->codecpar, oggstream, s->flags & AVFMT_FLAG_BITEXACT, &s->metadata); if (err) { @@ -469,8 +469,8 @@ static int ogg_write_header(AVFormatContext *s) av_freep(&st->priv_data); return err; } - } else if (st->codec->codec_id == AV_CODEC_ID_SPEEX) { - int err = ogg_build_speex_headers(st->codec, oggstream, + } else if (st->codecpar->codec_id == AV_CODEC_ID_SPEEX) { + int err = ogg_build_speex_headers(st->codecpar, oggstream, s->flags & AVFMT_FLAG_BITEXACT, &s->metadata); if (err) { @@ -478,8 +478,8 @@ static int ogg_write_header(AVFormatContext *s) av_freep(&st->priv_data); return err; } - } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) { - int err = ogg_build_opus_headers(st->codec, oggstream, + } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { + int err = ogg_build_opus_headers(st->codecpar, oggstream, s->flags & AVFMT_FLAG_BITEXACT, &s->metadata); if (err) { @@ -489,12 +489,12 @@ static int ogg_write_header(AVFormatContext *s) } } else { uint8_t *p; - const char *cstr = st->codec->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora"; - int header_type = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81; - int framing_bit = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0; + const char *cstr = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora"; + int header_type = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81; + int framing_bit = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0; - if (avpriv_split_xiph_headers(st->codec->extradata, st->codec->extradata_size, - st->codec->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42, + if (avpriv_split_xiph_headers(st->codecpar->extradata, st->codecpar->extradata_size, + st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42, oggstream->header, oggstream->header_len) < 0) { av_log(s, AV_LOG_ERROR, "Extradata corrupted\n"); av_freep(&st->priv_data); @@ -511,7 +511,7 @@ static int ogg_write_header(AVFormatContext *s) bytestream_put_byte(&p, header_type); bytestream_put_buffer(&p, cstr, 6); - if (st->codec->codec_id == AV_CODEC_ID_THEORA) { + if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) { /** KFGSHIFT is the width of the less significant section of the granule position The less significant section is the frame count since the last keyframe */ oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5); @@ -554,7 +554,7 @@ static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt) int ret; int64_t granule; - if (st->codec->codec_id == AV_CODEC_ID_THEORA) { + if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) { int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration; int pframe_count; if (pkt->flags & AV_PKT_FLAG_KEY) @@ -566,10 +566,10 @@ static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt) pframe_count = 0; } granule = (oggstream->last_kf_pts<<oggstream->kfgshift) | pframe_count; - } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) + } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) granule = pkt->pts + pkt->duration + - av_rescale_q(st->codec->initial_padding, - (AVRational){ 1, st->codec->sample_rate }, + av_rescale_q(st->codecpar->initial_padding, + (AVRational){ 1, st->codecpar->sample_rate }, st->time_base); else granule = pkt->pts + pkt->duration; @@ -622,9 +622,9 @@ static int ogg_write_trailer(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; OGGStreamContext *oggstream = st->priv_data; - if (st->codec->codec_id == AV_CODEC_ID_FLAC || - st->codec->codec_id == AV_CODEC_ID_SPEEX || - st->codec->codec_id == AV_CODEC_ID_OPUS) { + if (st->codecpar->codec_id == AV_CODEC_ID_FLAC || + st->codecpar->codec_id == AV_CODEC_ID_SPEEX || + st->codecpar->codec_id == AV_CODEC_ID_OPUS) { av_free(oggstream->header[0]); } av_freep(&oggstream->header[1]); diff --git a/libavformat/oggparsecelt.c b/libavformat/oggparsecelt.c index ab8532090e..291a6b5aab 100644 --- a/libavformat/oggparsecelt.c +++ b/libavformat/oggparsecelt.c @@ -62,13 +62,13 @@ static int celt_header(AVFormatContext *s, int idx) /* unused bytes per packet field skipped */ extra_headers = AV_RL32(p + 56); av_free(os->private); - av_free(st->codec->extradata); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_CELT; - st->codec->sample_rate = sample_rate; - st->codec->channels = nb_channels; - st->codec->extradata = extradata; - st->codec->extradata_size = 2 * sizeof(uint32_t); + av_free(st->codecpar->extradata); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_CELT; + st->codecpar->sample_rate = sample_rate; + st->codecpar->channels = nb_channels; + st->codecpar->extradata = extradata; + st->codecpar->extradata_size = 2 * sizeof(uint32_t); if (sample_rate) avpriv_set_pts_info(st, 64, 1, sample_rate); priv->extra_headers_left = 1 + extra_headers; diff --git a/libavformat/oggparsedirac.c b/libavformat/oggparsedirac.c index 5685e0085c..a53197e3a3 100644 --- a/libavformat/oggparsedirac.c +++ b/libavformat/oggparsedirac.c @@ -33,24 +33,24 @@ static int dirac_header(AVFormatContext *s, int idx) int ret; // already parsed the header - if (st->codec->codec_id == AV_CODEC_ID_DIRAC) + if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC) return 0; ret = av_dirac_parse_sequence_header(&dsh, os->buf + os->pstart + 13, (os->psize - 13) * 8, s); if (ret < 0) return ret; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DIRAC; - st->codec->width = dsh->width; - st->codec->height = dsh->height; - st->codec->pix_fmt = dsh->pix_fmt; - st->codec->color_range = dsh->color_range; - st->codec->color_trc = dsh->color_trc; - st->codec->color_primaries = dsh->color_primaries; - st->codec->colorspace = dsh->colorspace; - st->codec->profile = dsh->profile; - st->codec->level = dsh->level; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DIRAC; + st->codecpar->width = dsh->width; + st->codecpar->height = dsh->height; + st->codecpar->format = dsh->pix_fmt; + st->codecpar->color_range = dsh->color_range; + st->codecpar->color_trc = dsh->color_trc; + st->codecpar->color_primaries = dsh->color_primaries; + st->codecpar->color_space = dsh->colorspace; + st->codecpar->profile = dsh->profile; + st->codecpar->level = dsh->level; // dirac in ogg always stores timestamps as though the video were interlaced avpriv_set_pts_info(st, 64, dsh->framerate.den, 2 * dsh->framerate.num); @@ -91,8 +91,8 @@ static int old_dirac_header(AVFormatContext *s, int idx) if (buf[0] != 'K') return 0; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DIRAC; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DIRAC; avpriv_set_pts_info(st, 64, AV_RB32(buf+12), AV_RB32(buf+8)); return 1; } diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c index 30a4840120..dab1040cc4 100644 --- a/libavformat/oggparseflac.c +++ b/libavformat/oggparseflac.c @@ -57,16 +57,16 @@ flac_header (AVFormatContext * s, int idx) if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE) return -1; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_FLAC; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_FLAC; st->need_parsing = AVSTREAM_PARSE_HEADERS; - st->codec->extradata = + st->codecpar->extradata = av_malloc(FLAC_STREAMINFO_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); - memcpy(st->codec->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE); - st->codec->extradata_size = FLAC_STREAMINFO_SIZE; + memcpy(st->codecpar->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE); + st->codecpar->extradata_size = FLAC_STREAMINFO_SIZE; - samplerate = AV_RB24(st->codec->extradata + 10) >> 4; + samplerate = AV_RB24(st->codecpar->extradata + 10) >> 4; if (!samplerate) return AVERROR_INVALIDDATA; @@ -82,8 +82,8 @@ static int old_flac_header (AVFormatContext * s, int idx) { AVStream *st = s->streams[idx]; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_FLAC; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_FLAC; return 0; } diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c index 913282ab36..3ce11bdaff 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -50,24 +50,24 @@ ogm_header(AVFormatContext *s, int idx) if (bytestream2_peek_byte(&p) == 'v'){ int tag; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; bytestream2_skip(&p, 8); tag = bytestream2_get_le32(&p); - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); - st->codec->codec_tag = tag; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); + st->codecpar->codec_tag = tag; } else if (bytestream2_peek_byte(&p) == 't') { - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; bytestream2_skip(&p, 12); } else { uint8_t acid[5] = { 0 }; int cid; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; bytestream2_skip(&p, 8); bytestream2_get_buffer(&p, acid, 4); acid[4] = 0; cid = strtol(acid, NULL, 16); - st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, cid); + st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags, cid); st->need_parsing = AVSTREAM_PARSE_FULL; } @@ -83,16 +83,16 @@ ogm_header(AVFormatContext *s, int idx) bytestream2_skip(&p, 4); /* default_len */ bytestream2_skip(&p, 8); /* buffersize + bits_per_sample */ - if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ - st->codec->width = bytestream2_get_le32(&p); - st->codec->height = bytestream2_get_le32(&p); + if(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO){ + st->codecpar->width = bytestream2_get_le32(&p); + st->codecpar->height = bytestream2_get_le32(&p); avpriv_set_pts_info(st, 64, time_unit, spu * 10000000); } else { - st->codec->channels = bytestream2_get_le16(&p); + st->codecpar->channels = bytestream2_get_le16(&p); bytestream2_skip(&p, 2); /* block_align */ - st->codec->bit_rate = bytestream2_get_le32(&p) * 8; - st->codec->sample_rate = spu * 10000000 / time_unit; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + st->codecpar->bit_rate = bytestream2_get_le32(&p) * 8; + st->codecpar->sample_rate = spu * 10000000 / time_unit; + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); } } else if (bytestream2_peek_byte(&p) == 3) { bytestream2_skip(&p, 7); @@ -120,17 +120,17 @@ ogm_dshow_header(AVFormatContext *s, int idx) t = AV_RL32(p + 96); if(t == 0x05589f80){ - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(p + 68)); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(p + 68)); avpriv_set_pts_info(st, 64, AV_RL64(p + 164), 10000000); - st->codec->width = AV_RL32(p + 176); - st->codec->height = AV_RL32(p + 180); + st->codecpar->width = AV_RL32(p + 176); + st->codecpar->height = AV_RL32(p + 180); } else if(t == 0x05589f81){ - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, AV_RL16(p + 124)); - st->codec->channels = AV_RL16(p + 126); - st->codec->sample_rate = AV_RL32(p + 128); - st->codec->bit_rate = AV_RL32(p + 132) * 8; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags, AV_RL16(p + 124)); + st->codecpar->channels = AV_RL16(p + 126); + st->codecpar->sample_rate = AV_RL32(p + 128); + st->codecpar->bit_rate = AV_RL32(p + 132) * 8; } return 1; diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c index 1851ff11ee..86d0803f0f 100644 --- a/libavformat/oggparseopus.c +++ b/libavformat/oggparseopus.c @@ -52,9 +52,9 @@ static int opus_header(AVFormatContext *avf, int idx) if (os->psize < OPUS_HEAD_SIZE || (AV_RL8(packet + 8) & 0xF0) != 0) return AVERROR_INVALIDDATA; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_OPUS; - st->codec->channels = AV_RL8(packet + 9); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_OPUS; + st->codecpar->channels = AV_RL8(packet + 9); priv->pre_skip = AV_RL16(packet + 10); extradata = av_malloc(os->psize + AV_INPUT_BUFFER_PADDING_SIZE); @@ -62,10 +62,10 @@ static int opus_header(AVFormatContext *avf, int idx) return AVERROR(ENOMEM); memcpy(extradata, packet, os->psize); - st->codec->extradata = extradata; - st->codec->extradata_size = os->psize; + st->codecpar->extradata = extradata; + st->codecpar->extradata_size = os->psize; - st->codec->sample_rate = 48000; + st->codecpar->sample_rate = 48000; avpriv_set_pts_info(st, 64, 1, 48000); priv->need_comments = 1; return 1; diff --git a/libavformat/oggparseskeleton.c b/libavformat/oggparseskeleton.c index 5333e17de6..bcbfe7382f 100644 --- a/libavformat/oggparseskeleton.c +++ b/libavformat/oggparseskeleton.c @@ -34,7 +34,7 @@ static int skeleton_header(AVFormatContext *s, int idx) uint64_t start_granule; int target_idx, start_time; - st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; if (os->psize < 8) return -1; diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c index 3cc901299c..fa24c127dc 100644 --- a/libavformat/oggparsespeex.c +++ b/libavformat/oggparsespeex.c @@ -57,29 +57,29 @@ static int speex_header(AVFormatContext *s, int idx) { if (spxp->seq == 0) { int frames_per_packet; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_SPEEX; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_SPEEX; - st->codec->sample_rate = AV_RL32(p + 36); - st->codec->channels = AV_RL32(p + 48); - if (st->codec->channels < 1 || st->codec->channels > 2) { + st->codecpar->sample_rate = AV_RL32(p + 36); + st->codecpar->channels = AV_RL32(p + 48); + if (st->codecpar->channels < 1 || st->codecpar->channels > 2) { av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\n"); return AVERROR_INVALIDDATA; } - st->codec->channel_layout = st->codec->channels == 1 ? AV_CH_LAYOUT_MONO : - AV_CH_LAYOUT_STEREO; + st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO : + AV_CH_LAYOUT_STEREO; spxp->packet_size = AV_RL32(p + 56); frames_per_packet = AV_RL32(p + 64); if (frames_per_packet) spxp->packet_size *= frames_per_packet; - st->codec->extradata_size = os->psize; - st->codec->extradata = av_malloc(st->codec->extradata_size - + AV_INPUT_BUFFER_PADDING_SIZE); - memcpy(st->codec->extradata, p, st->codec->extradata_size); + st->codecpar->extradata_size = os->psize; + st->codecpar->extradata = av_malloc(st->codecpar->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + memcpy(st->codecpar->extradata, p, st->codecpar->extradata_size); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); } else ff_vorbis_stream_comment(s, st, p, os->psize); diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c index 01d1518c2a..1e7a776c06 100644 --- a/libavformat/oggparsetheora.c +++ b/libavformat/oggparsetheora.c @@ -41,7 +41,7 @@ static int theora_header(AVFormatContext *s, int idx) struct ogg_stream *os = ogg->streams + idx; AVStream *st = s->streams[idx]; TheoraParams *thp = os->private; - int cds = st->codec->extradata_size + os->psize + 2; + int cds = st->codecpar->extradata_size + os->psize + 2; int err; uint8_t *cdp; @@ -72,8 +72,8 @@ static int theora_header(AVFormatContext *s, int idx) return AVERROR(ENOSYS); } - st->codec->width = get_bits(&gb, 16) << 4; - st->codec->height = get_bits(&gb, 16) << 4; + st->codecpar->width = get_bits(&gb, 16) << 4; + st->codecpar->height = get_bits(&gb, 16) << 4; if (thp->version >= 0x030400) skip_bits(&gb, 100); @@ -81,10 +81,10 @@ static int theora_header(AVFormatContext *s, int idx) if (thp->version >= 0x030200) { int width = get_bits_long(&gb, 24); int height = get_bits_long(&gb, 24); - if (width <= st->codec->width && width > st->codec->width - 16 && - height <= st->codec->height && height > st->codec->height - 16) { - st->codec->width = width; - st->codec->height = height; + if (width <= st->codecpar->width && width > st->codecpar->width - 16 && + height <= st->codecpar->height && height > st->codecpar->height - 16) { + st->codecpar->width = width; + st->codecpar->height = height; } skip_bits(&gb, 16); @@ -110,8 +110,8 @@ static int theora_header(AVFormatContext *s, int idx) thp->gpshift = get_bits(&gb, 5); thp->gpmask = (1 << thp->gpshift) - 1; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_THEORA; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_THEORA; st->need_parsing = AVSTREAM_PARSE_HEADERS; } break; @@ -125,16 +125,16 @@ static int theora_header(AVFormatContext *s, int idx) return AVERROR_INVALIDDATA; } - if ((err = av_reallocp(&st->codec->extradata, + if ((err = av_reallocp(&st->codecpar->extradata, cds + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = 0; return err; } - cdp = st->codec->extradata + st->codec->extradata_size; + cdp = st->codecpar->extradata + st->codecpar->extradata_size; *cdp++ = os->psize >> 8; *cdp++ = os->psize & 0xff; memcpy(cdp, os->buf + os->pstart, os->psize); - st->codec->extradata_size = cds; + st->codecpar->extradata_size = cds; return 1; } diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 519a0a7371..4cb10a1070 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -295,10 +295,10 @@ static int vorbis_header(AVFormatContext *s, int idx) if (bytestream_get_le32(&p) != 0) /* vorbis_version */ return AVERROR_INVALIDDATA; - st->codec->channels = bytestream_get_byte(&p); + st->codecpar->channels = bytestream_get_byte(&p); srate = bytestream_get_le32(&p); p += 4; // skip maximum bitrate - st->codec->bit_rate = bytestream_get_le32(&p); // nominal bitrate + st->codecpar->bit_rate = bytestream_get_le32(&p); // nominal bitrate p += 4; // skip minimum bitrate blocksize = bytestream_get_byte(&p); @@ -313,11 +313,11 @@ static int vorbis_header(AVFormatContext *s, int idx) if (bytestream_get_byte(&p) != 1) /* framing_flag */ return AVERROR_INVALIDDATA; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_VORBIS; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_VORBIS; if (srate > 0) { - st->codec->sample_rate = srate; + st->codecpar->sample_rate = srate; avpriv_set_pts_info(st, 64, 1, srate); } } else if (os->buf[os->pstart] == 3) { @@ -339,17 +339,17 @@ static int vorbis_header(AVFormatContext *s, int idx) } } } else { - int ret = fixup_vorbis_headers(s, priv, &st->codec->extradata); + int ret = fixup_vorbis_headers(s, priv, &st->codecpar->extradata); if (ret < 0) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = 0; return ret; } - st->codec->extradata_size = ret; + st->codecpar->extradata_size = ret; - priv->vp = av_vorbis_parse_init(st->codec->extradata, st->codec->extradata_size); + priv->vp = av_vorbis_parse_init(st->codecpar->extradata, st->codecpar->extradata_size); if (!priv->vp) { - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; return ret; } } diff --git a/libavformat/oggparsevp8.c b/libavformat/oggparsevp8.c index b4f71de017..f38cc56ce7 100644 --- a/libavformat/oggparsevp8.c +++ b/libavformat/oggparsevp8.c @@ -51,16 +51,16 @@ static int vp8_header(AVFormatContext *s, int idx) return AVERROR_INVALIDDATA; } - st->codec->width = AV_RB16(p + 8); - st->codec->height = AV_RB16(p + 10); + st->codecpar->width = AV_RB16(p + 8); + st->codecpar->height = AV_RB16(p + 10); st->sample_aspect_ratio.num = AV_RB24(p + 12); st->sample_aspect_ratio.den = AV_RB24(p + 15); framerate.num = AV_RB32(p + 18); framerate.den = AV_RB32(p + 22); avpriv_set_pts_info(st, 64, framerate.den, framerate.num); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_VP8; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_VP8; st->need_parsing = AVSTREAM_PARSE_HEADERS; break; case 0x02: 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); diff --git a/libavformat/omaenc.c b/libavformat/omaenc.c index bfd552a03d..50f369d967 100644 --- a/libavformat/omaenc.c +++ b/libavformat/omaenc.c @@ -30,21 +30,21 @@ static av_cold int oma_write_header(AVFormatContext *s) { int i; - AVCodecContext *format; + AVCodecParameters *par; int srate_index; int isjointstereo; - format = s->streams[0]->codec; + par = s->streams[0]->codecpar; /* check for support of the format first */ for (srate_index = 0; ; srate_index++) { if (ff_oma_srate_tab[srate_index] == 0) { av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG audio\n", - format->sample_rate); + par->sample_rate); return AVERROR(EINVAL); } - if (ff_oma_srate_tab[srate_index] * 100 == format->sample_rate) + if (ff_oma_srate_tab[srate_index] * 100 == par->sample_rate) break; } @@ -58,16 +58,16 @@ static av_cold int oma_write_header(AVFormatContext *s) for (i = 0; i < 6; i++) avio_wl32(s->pb, 0); /* Padding + DRM id */ - switch(format->codec_tag) { + switch (par->codec_tag) { case OMA_CODECID_ATRAC3: - if (format->channels != 2) { + if (par->channels != 2) { av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels"); return AVERROR(EINVAL); } - if (format->extradata_size == 14) /* WAV format extradata */ - isjointstereo = format->extradata[6] != 0; - else if(format->extradata_size == 10) /* RM format extradata */ - isjointstereo = format->extradata[8] == 0x12; + if (par->extradata_size == 14) /* WAV format extradata */ + isjointstereo = par->extradata[6] != 0; + else if(par->extradata_size == 10) /* RM format extradata */ + isjointstereo = par->extradata[8] == 0x12; else { av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata size\n"); return AVERROR(EINVAL); @@ -75,17 +75,17 @@ static av_cold int oma_write_header(AVFormatContext *s) avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) | (isjointstereo << 17) | (srate_index << 13) | - (format->block_align/8)); + (par->block_align/8)); break; case OMA_CODECID_ATRAC3P: avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) | (srate_index << 13) | - (format->channels << 10) | - (format->block_align/8 - 1)); + (par->channels << 10) | + (par->block_align/8 - 1)); break; default: av_log(s, AV_LOG_ERROR, "OMA: unsupported codec tag %d for write\n", - format->codec_tag); + par->codec_tag); } for (i = 0; i < (EA3_HEADER_SIZE - 36)/4; i++) avio_wl32(s->pb, 0); /* Padding */ diff --git a/libavformat/paf.c b/libavformat/paf.c index 9ee4cd8cb6..81a45cecee 100644 --- a/libavformat/paf.c +++ b/libavformat/paf.c @@ -106,13 +106,13 @@ static int read_header(AVFormatContext *s) p->nb_frames = avio_rl32(pb); avio_skip(pb, 4); - vst->codec->width = avio_rl32(pb); - vst->codec->height = avio_rl32(pb); + vst->codecpar->width = avio_rl32(pb); + vst->codecpar->height = avio_rl32(pb); avio_skip(pb, 4); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_tag = 0; - vst->codec->codec_id = AV_CODEC_ID_PAF_VIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_tag = 0; + vst->codecpar->codec_id = AV_CODEC_ID_PAF_VIDEO; avpriv_set_pts_info(vst, 64, 1, 10); ast = avformat_new_stream(s, 0); @@ -120,12 +120,12 @@ static int read_header(AVFormatContext *s) return AVERROR(ENOMEM); ast->start_time = 0; - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_tag = 0; - ast->codec->codec_id = AV_CODEC_ID_PAF_AUDIO; - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; - ast->codec->sample_rate = 22050; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_tag = 0; + ast->codecpar->codec_id = AV_CODEC_ID_PAF_AUDIO; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->sample_rate = 22050; avpriv_set_pts_info(ast, 64, 1, 22050); p->buffer_size = avio_rl32(pb); diff --git a/libavformat/pcm.c b/libavformat/pcm.c index e4f2a5e627..c506edd777 100644 --- a/libavformat/pcm.c +++ b/libavformat/pcm.c @@ -33,10 +33,10 @@ int ff_pcm_read_seek(AVFormatContext *s, st = s->streams[0]; - block_align = st->codec->block_align ? st->codec->block_align : - (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3; - byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 : - block_align * st->codec->sample_rate; + block_align = st->codecpar->block_align ? st->codecpar->block_align : + (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3; + byte_rate = st->codecpar->bit_rate ? st->codecpar->bit_rate >> 3 : + block_align * st->codecpar->sample_rate; if (block_align <= 0 || byte_rate <= 0) return -1; diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c index 1bbbc66d17..69789b62e8 100644 --- a/libavformat/pcmdec.c +++ b/libavformat/pcmdec.c @@ -43,20 +43,20 @@ static int pcm_read_header(AVFormatContext *s) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; - st->codec->sample_rate = s1->sample_rate; - st->codec->channels = s1->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->iformat->raw_codec_id; + st->codecpar->sample_rate = s1->sample_rate; + st->codecpar->channels = s1->channels; - st->codec->bits_per_coded_sample = - av_get_bits_per_sample(st->codec->codec_id); + st->codecpar->bits_per_coded_sample = + av_get_bits_per_sample(st->codecpar->codec_id); - assert(st->codec->bits_per_coded_sample > 0); + assert(st->codecpar->bits_per_coded_sample > 0); - st->codec->block_align = - st->codec->bits_per_coded_sample * st->codec->channels / 8; + st->codecpar->block_align = + st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } @@ -65,7 +65,7 @@ static int pcm_read_packet(AVFormatContext *s, AVPacket *pkt) int ret, size, bps; // AVStream *st = s->streams[0]; - size= RAW_SAMPLES*s->streams[0]->codec->block_align; + size= RAW_SAMPLES*s->streams[0]->codecpar->block_align; ret= av_get_packet(s->pb, pkt, size); @@ -73,14 +73,14 @@ static int pcm_read_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) return ret; - bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id); + bps= av_get_bits_per_sample(s->streams[0]->codecpar->codec_id); if (!bps) { av_log(s, AV_LOG_ERROR, "Unknown number of bytes per sample.\n"); return AVERROR(EINVAL); } pkt->dts= - pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels); + pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codecpar->channels); return ret; } diff --git a/libavformat/pmpdec.c b/libavformat/pmpdec.c index 8ae147f391..e2709bbbe3 100644 --- a/libavformat/pmpdec.c +++ b/libavformat/pmpdec.c @@ -52,22 +52,22 @@ static int pmp_header(AVFormatContext *s) AVStream *vst = avformat_new_stream(s, NULL); if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; avio_skip(pb, 8); switch (avio_rl32(pb)) { case 0: - vst->codec->codec_id = AV_CODEC_ID_MPEG4; + vst->codecpar->codec_id = AV_CODEC_ID_MPEG4; break; case 1: - vst->codec->codec_id = AV_CODEC_ID_H264; + vst->codecpar->codec_id = AV_CODEC_ID_H264; break; default: av_log(s, AV_LOG_ERROR, "Unsupported video format\n"); break; } index_cnt = avio_rl32(pb); - vst->codec->width = avio_rl32(pb); - vst->codec->height = avio_rl32(pb); + vst->codecpar->width = avio_rl32(pb); + vst->codecpar->height = avio_rl32(pb); tb_num = avio_rl32(pb); tb_den = avio_rl32(pb); @@ -95,10 +95,10 @@ static int pmp_header(AVFormatContext *s) AVStream *ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = audio_codec_id; - ast->codec->channels = channels; - ast->codec->sample_rate = srate; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = audio_codec_id; + ast->codecpar->channels = channels; + ast->codecpar->sample_rate = srate; avpriv_set_pts_info(ast, 32, 1, srate); } pos = avio_tell(pb) + 4 * index_cnt; diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c index e1371c089e..8b6ecc88b4 100644 --- a/libavformat/psxstr.c +++ b/libavformat/psxstr.c @@ -171,11 +171,11 @@ static int str_read_packet(AVFormatContext *s, str->channels[channel].video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MDEC; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = AV_RL16(§or[0x28]); - st->codec->height = AV_RL16(§or[0x2A]); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MDEC; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = AV_RL16(§or[0x28]); + st->codecpar->height = AV_RL16(§or[0x2A]); } /* if this is the first sector of the frame, allocate a pkt */ @@ -219,22 +219,22 @@ static int str_read_packet(AVFormatContext *s, str->channels[channel].audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_XA; - st->codec->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_XA; + st->codecpar->codec_tag = 0; /* no fourcc */ if (fmt & 1) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - st->codec->sample_rate = (fmt&4)?18900:37800; - // st->codec->bit_rate = 0; //FIXME; - st->codec->block_align = 128; + st->codecpar->sample_rate = (fmt&4)?18900:37800; + // st->codecpar->bit_rate = 0; //FIXME; + st->codecpar->block_align = 128; - avpriv_set_pts_info(st, 64, 18 * 224 / st->codec->channels, - st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 18 * 224 / st->codecpar->channels, + st->codecpar->sample_rate); st->start_time = 0; } pkt = ret_pkt; diff --git a/libavformat/pva.c b/libavformat/pva.c index 2c485d6dcf..458d21995f 100644 --- a/libavformat/pva.c +++ b/libavformat/pva.c @@ -46,16 +46,16 @@ static int pva_read_header(AVFormatContext *s) { if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG2VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; st->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 32, 1, 90000); av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MP2; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MP2; st->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 33, 1, 90000); av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); diff --git a/libavformat/qcp.c b/libavformat/qcp.c index be06e2f4ec..4069dbe8c0 100644 --- a/libavformat/qcp.c +++ b/libavformat/qcp.c @@ -95,12 +95,12 @@ static int qcp_read_header(AVFormatContext *s) avio_rb32(pb); // "RIFF" avio_skip(pb, 4 + 8 + 4 + 1 + 1); // filesize + "QLCMfmt " + chunk-size + major-version + minor-version - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; avio_read(pb, buf, 16); if (is_qcelp_13k_guid(buf)) { - st->codec->codec_id = AV_CODEC_ID_QCELP; + st->codecpar->codec_id = AV_CODEC_ID_QCELP; } else if (!memcmp(buf, guid_evrc, 16)) { av_log(s, AV_LOG_ERROR, "EVRC codec is not supported.\n"); return AVERROR_PATCHWELCOME; @@ -112,11 +112,11 @@ static int qcp_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } avio_skip(pb, 2 + 80); // codec-version + codec-name - st->codec->bit_rate = avio_rl16(pb); + st->codecpar->bit_rate = avio_rl16(pb); s->packet_size = avio_rl16(pb); avio_skip(pb, 2); // block-size - st->codec->sample_rate = avio_rl16(pb); + st->codecpar->sample_rate = avio_rl16(pb); avio_skip(pb, 2); // sample-size memset(c->rates_per_mode, -1, sizeof(c->rates_per_mode)); diff --git a/libavformat/r3d.c b/libavformat/r3d.c index 9db1d4bbfd..4b28379fc9 100644 --- a/libavformat/r3d.c +++ b/libavformat/r3d.c @@ -62,8 +62,8 @@ static int r3d_read_red1(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_JPEG2000; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_JPEG2000; tmp = avio_r8(s->pb); // major version tmp2 = avio_r8(s->pb); // minor version @@ -80,8 +80,8 @@ static int r3d_read_red1(AVFormatContext *s) avio_skip(s->pb, 32); // unknown - st->codec->width = avio_rb32(s->pb); - st->codec->height = avio_rb32(s->pb); + st->codecpar->width = avio_rb32(s->pb); + st->codecpar->height = avio_rb32(s->pb); tmp = avio_rb16(s->pb); // unknown av_log(s, AV_LOG_TRACE, "unknown2 %d\n", tmp); @@ -100,7 +100,7 @@ static int r3d_read_red1(AVFormatContext *s) av_dict_set(&st->metadata, "filename", filename, 0); av_log(s, AV_LOG_TRACE, "filename %s\n", filename); - av_log(s, AV_LOG_TRACE, "resolution %dx%d\n", st->codec->width, st->codec->height); + av_log(s, AV_LOG_TRACE, "resolution %dx%d\n", st->codecpar->width, st->codecpar->height); av_log(s, AV_LOG_TRACE, "timescale %d\n", st->time_base.den); av_log(s, AV_LOG_TRACE, "frame rate %d/%d\n", framerate.num, framerate.den); @@ -282,9 +282,9 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S32BE; - st->codec->channels = r3d->audio_channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE; + st->codecpar->channels = r3d->audio_channels; avpriv_set_pts_info(st, 32, 1, s->streams[0]->time_base.den); } else { st = s->streams[1]; @@ -292,8 +292,8 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom) dts = avio_rb32(s->pb); - st->codec->sample_rate = avio_rb32(s->pb); - if (st->codec->sample_rate <= 0) { + st->codecpar->sample_rate = avio_rb32(s->pb); + if (st->codecpar->sample_rate <= 0) { av_log(s, AV_LOG_ERROR, "Bad sample rate\n"); return AVERROR_INVALIDDATA; } @@ -324,9 +324,9 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom) pkt->stream_index = 1; pkt->dts = dts; - pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate); + pkt->duration = av_rescale(samples, st->time_base.den, st->codecpar->sample_rate); av_log(s, AV_LOG_TRACE, "pkt dts %"PRId64" duration %"PRId64" samples %d sample rate %d\n", - pkt->dts, pkt->duration, samples, st->codec->sample_rate); + pkt->dts, pkt->duration, samples, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 5f2a39801a..3b1bea6429 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -60,8 +60,8 @@ int ff_raw_audio_read_header(AVFormatContext *s) AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->iformat->raw_codec_id; st->need_parsing = AVSTREAM_PARSE_FULL; st->start_time = 0; /* the parameters will be extracted from the compressed bitstream */ @@ -84,8 +84,8 @@ int ff_raw_video_read_header(AVFormatContext *s) goto fail; } - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = s->iformat->raw_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = s->iformat->raw_codec_id; st->need_parsing = AVSTREAM_PARSE_FULL; if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) { diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c index c7de844765..cea1b0bc84 100644 --- a/libavformat/rawvideodec.c +++ b/libavformat/rawvideodec.c @@ -46,9 +46,9 @@ static int rawvideo_read_header(AVFormatContext *ctx) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = ctx->iformat->raw_codec_id; + st->codecpar->codec_id = ctx->iformat->raw_codec_id; if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { @@ -70,9 +70,9 @@ static int rawvideo_read_header(AVFormatContext *ctx) avpriv_set_pts_info(st, 64, framerate.den, framerate.num); - st->codec->width = width; - st->codec->height = height; - st->codec->pix_fmt = pix_fmt; + st->codecpar->width = width; + st->codecpar->height = height; + st->codecpar->format = pix_fmt; return 0; } @@ -83,10 +83,10 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) int packet_size, ret, width, height; AVStream *st = s->streams[0]; - width = st->codec->width; - height = st->codec->height; + width = st->codecpar->width; + height = st->codecpar->height; - packet_size = av_image_get_buffer_size(st->codec->pix_fmt, width, height, 1); + packet_size = av_image_get_buffer_size(st->codecpar->format, width, height, 1); if (packet_size < 0) return -1; diff --git a/libavformat/rdt.c b/libavformat/rdt.c index 091bff2981..dac5091417 100644 --- a/libavformat/rdt.c +++ b/libavformat/rdt.c @@ -309,7 +309,7 @@ rdt_parse_packet (AVFormatContext *ctx, PayloadContext *rdt, AVStream *st, if (res < 0) return res; if (res > 0) { - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { memcpy (rdt->buffer, buf + pos, len - pos); rdt->rmctx->pb = avio_alloc_context (rdt->buffer, len - pos, 0, NULL, NULL, NULL, NULL); @@ -322,7 +322,7 @@ get_cache: ff_rm_retrieve_cache (rdt->rmctx, rdt->rmctx->pb, st, rdt->rmst[st->index], pkt); if (rdt->audio_pkt_cnt == 0 && - st->codec->codec_id == AV_CODEC_ID_AAC) + st->codecpar->codec_id == AV_CODEC_ID_AAC) av_freep(&rdt->rmctx->pb); } pkt->stream_index = st->index; @@ -448,7 +448,7 @@ real_parse_asm_rule(AVStream *st, const char *p, const char *end) { do { /* can be either averagebandwidth= or AverageBandwidth= */ - if (sscanf(p, " %*1[Aa]verage%*1[Bb]andwidth=%d", &st->codec->bit_rate) == 1) + if (sscanf(p, " %*1[Aa]verage%*1[Bb]andwidth=%d", &st->codecpar->bit_rate) == 1) break; if (!(p = strchr(p, ',')) || p > end) p = end; @@ -464,7 +464,7 @@ add_dstream(AVFormatContext *s, AVStream *orig_st) if (!(st = avformat_new_stream(s, NULL))) return NULL; st->id = orig_st->id; - st->codec->codec_type = orig_st->codec->codec_type; + st->codecpar->codec_type = orig_st->codecpar->codec_type; st->first_dts = orig_st->first_dts; return st; diff --git a/libavformat/riff.h b/libavformat/riff.h index 5bac95a853..a45c7f301c 100644 --- a/libavformat/riff.h +++ b/libavformat/riff.h @@ -45,10 +45,10 @@ void ff_end_tag(AVIOContext *pb, int64_t start); */ int ff_get_bmp_header(AVIOContext *pb, AVStream *st); -void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf); -int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc); +void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, const AVCodecTag *tags, int for_asf); +int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par); enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps); -int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecContext *codec, int size); +int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int size); extern const AVCodecTag ff_codec_bmp_tags[]; extern const AVCodecTag ff_codec_wav_tags[]; diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c index 41b7a9c865..531413c943 100644 --- a/libavformat/riffdec.c +++ b/libavformat/riffdec.c @@ -54,29 +54,29 @@ enum AVCodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid) * an openended structure. */ -static void parse_waveformatex(AVIOContext *pb, AVCodecContext *c) +static void parse_waveformatex(AVIOContext *pb, AVCodecParameters *par) { ff_asf_guid subformat; - c->bits_per_coded_sample = avio_rl16(pb); - c->channel_layout = avio_rl32(pb); /* dwChannelMask */ + par->bits_per_coded_sample = avio_rl16(pb); + par->channel_layout = avio_rl32(pb); /* dwChannelMask */ ff_get_guid(pb, &subformat); if (!memcmp(subformat + 4, (const uint8_t[]){ FF_MEDIASUBTYPE_BASE_GUID }, 12)) { - c->codec_tag = AV_RL32(subformat); - c->codec_id = ff_wav_codec_get_id(c->codec_tag, - c->bits_per_coded_sample); + par->codec_tag = AV_RL32(subformat); + par->codec_id = ff_wav_codec_get_id(par->codec_tag, + par->bits_per_coded_sample); } else { - c->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subformat); - if (!c->codec_id) - av_log(c, AV_LOG_WARNING, + par->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subformat); + if (!par->codec_id) + av_log(pb, AV_LOG_WARNING, "unknown subformat:"FF_PRI_GUID"\n", FF_ARG_GUID(subformat)); } } int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, - AVCodecContext *codec, int size) + AVCodecParameters *par, int size) { int id; uint64_t bitrate; @@ -85,39 +85,38 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, return AVERROR_INVALIDDATA; id = avio_rl16(pb); - codec->codec_type = AVMEDIA_TYPE_AUDIO; - codec->channels = avio_rl16(pb); - codec->sample_rate = avio_rl32(pb); + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->channels = avio_rl16(pb); + par->sample_rate = avio_rl32(pb); bitrate = avio_rl32(pb) * 8; - codec->block_align = avio_rl16(pb); + par->block_align = avio_rl16(pb); if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */ - codec->bits_per_coded_sample = 8; + par->bits_per_coded_sample = 8; } else - codec->bits_per_coded_sample = avio_rl16(pb); + par->bits_per_coded_sample = avio_rl16(pb); if (id == 0xFFFE) { - codec->codec_tag = 0; + par->codec_tag = 0; } else { - codec->codec_tag = id; - codec->codec_id = ff_wav_codec_get_id(id, - codec->bits_per_coded_sample); + par->codec_tag = id; + par->codec_id = ff_wav_codec_get_id(id, par->bits_per_coded_sample); } if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */ int cbSize = avio_rl16(pb); /* cbSize */ size -= 18; cbSize = FFMIN(size, cbSize); if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */ - parse_waveformatex(pb, codec); + parse_waveformatex(pb, par); cbSize -= 22; size -= 22; } - codec->extradata_size = cbSize; + par->extradata_size = cbSize; if (cbSize > 0) { - av_free(codec->extradata); - codec->extradata = av_mallocz(codec->extradata_size + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!codec->extradata) + av_free(par->extradata); + par->extradata = av_mallocz(par->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!par->extradata) return AVERROR(ENOMEM); - avio_read(pb, codec->extradata, codec->extradata_size); + avio_read(pb, par->extradata, par->extradata_size); size -= cbSize; } @@ -136,26 +135,26 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, av_log(s, AV_LOG_WARNING, "The bitrate %"PRIu64" is too large, resetting to 0.", bitrate); - codec->bit_rate = 0; + par->bit_rate = 0; } } else { - codec->bit_rate = bitrate; + par->bit_rate = bitrate; } - if (codec->sample_rate <= 0) { + if (par->sample_rate <= 0) { av_log(s, AV_LOG_ERROR, - "Invalid sample rate: %d\n", codec->sample_rate); + "Invalid sample rate: %d\n", par->sample_rate); return AVERROR_INVALIDDATA; } - if (codec->codec_id == AV_CODEC_ID_AAC_LATM) { + if (par->codec_id == AV_CODEC_ID_AAC_LATM) { /* Channels and sample_rate values are those prior to applying SBR * and/or PS. */ - codec->channels = 0; - codec->sample_rate = 0; + par->channels = 0; + par->sample_rate = 0; } /* override bits_per_coded_sample for G.726 */ - if (codec->codec_id == AV_CODEC_ID_ADPCM_G726) - codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate; + if (par->codec_id == AV_CODEC_ID_ADPCM_G726) + par->bits_per_coded_sample = par->bit_rate / par->sample_rate; return 0; } @@ -181,11 +180,11 @@ int ff_get_bmp_header(AVIOContext *pb, AVStream *st) { int tag1; avio_rl32(pb); /* size */ - st->codec->width = avio_rl32(pb); - st->codec->height = (int32_t)avio_rl32(pb); + st->codecpar->width = avio_rl32(pb); + st->codecpar->height = (int32_t)avio_rl32(pb); avio_rl16(pb); /* planes */ - st->codec->bits_per_coded_sample = avio_rl16(pb); /* depth */ - tag1 = avio_rl32(pb); + st->codecpar->bits_per_coded_sample = avio_rl16(pb); /* depth */ + tag1 = avio_rl32(pb); avio_rl32(pb); /* ImageSize */ avio_rl32(pb); /* XPelsPerMeter */ avio_rl32(pb); /* YPelsPerMeter */ diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c index 2e4b7e0b18..e6b8411529 100644 --- a/libavformat/riffenc.c +++ b/libavformat/riffenc.c @@ -47,7 +47,8 @@ void ff_end_tag(AVIOContext *pb, int64_t start) /* WAVEFORMATEX header */ /* returns the size or -1 on error */ -int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) +int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, + AVCodecParameters *par) { int bps, blkalign, bytespersec, frame_size; int hdrsize = 18; @@ -56,82 +57,82 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) uint8_t *riff_extradata = temp; uint8_t *riff_extradata_start = temp; - if (!enc->codec_tag || enc->codec_tag > 0xffff) + if (!par->codec_tag || par->codec_tag > 0xffff) return -1; /* We use the known constant frame size for the codec if known, otherwise * fall back on using AVCodecContext.frame_size, which is not as reliable * for indicating packet duration. */ - frame_size = av_get_audio_frame_duration(enc, enc->block_align); + frame_size = av_get_audio_frame_duration2(par, par->block_align); - waveformatextensible = (enc->channels > 2 && enc->channel_layout) || - enc->sample_rate > 48000 || - av_get_bits_per_sample(enc->codec_id) > 16; + waveformatextensible = (par->channels > 2 && par->channel_layout) || + par->sample_rate > 48000 || + av_get_bits_per_sample(par->codec_id) > 16; if (waveformatextensible) avio_wl16(pb, 0xfffe); else - avio_wl16(pb, enc->codec_tag); + avio_wl16(pb, par->codec_tag); - avio_wl16(pb, enc->channels); - avio_wl32(pb, enc->sample_rate); - if (enc->codec_id == AV_CODEC_ID_MP2 || - enc->codec_id == AV_CODEC_ID_MP3 || - enc->codec_id == AV_CODEC_ID_GSM_MS) { + avio_wl16(pb, par->channels); + avio_wl32(pb, par->sample_rate); + if (par->codec_id == AV_CODEC_ID_MP2 || + par->codec_id == AV_CODEC_ID_MP3 || + par->codec_id == AV_CODEC_ID_GSM_MS) { bps = 0; } else { - if (!(bps = av_get_bits_per_sample(enc->codec_id))) { - if (enc->bits_per_coded_sample) - bps = enc->bits_per_coded_sample; + if (!(bps = av_get_bits_per_sample(par->codec_id))) { + if (par->bits_per_coded_sample) + bps = par->bits_per_coded_sample; else bps = 16; // default to 16 } } - if (bps != enc->bits_per_coded_sample && enc->bits_per_coded_sample) { - av_log(enc, AV_LOG_WARNING, + if (bps != par->bits_per_coded_sample && par->bits_per_coded_sample) { + av_log(s, AV_LOG_WARNING, "requested bits_per_coded_sample (%d) " "and actually stored (%d) differ\n", - enc->bits_per_coded_sample, bps); + par->bits_per_coded_sample, bps); } - if (enc->codec_id == AV_CODEC_ID_MP2) { + if (par->codec_id == AV_CODEC_ID_MP2) { blkalign = frame_size; - } else if (enc->codec_id == AV_CODEC_ID_MP3) { - blkalign = 576 * (enc->sample_rate <= 24000 ? 1 : 2); - } else if (enc->codec_id == AV_CODEC_ID_AC3) { + } else if (par->codec_id == AV_CODEC_ID_MP3) { + blkalign = 576 * (par->sample_rate <= 24000 ? 1 : 2); + } else if (par->codec_id == AV_CODEC_ID_AC3) { blkalign = 3840; /* maximum bytes per frame */ - } else if (enc->block_align != 0) { /* specified by the codec */ - blkalign = enc->block_align; + } else if (par->block_align != 0) { /* specified by the codec */ + blkalign = par->block_align; } else - blkalign = bps * enc->channels / av_gcd(8, bps); - if (enc->codec_id == AV_CODEC_ID_PCM_U8 || - enc->codec_id == AV_CODEC_ID_PCM_S24LE || - enc->codec_id == AV_CODEC_ID_PCM_S32LE || - enc->codec_id == AV_CODEC_ID_PCM_F32LE || - enc->codec_id == AV_CODEC_ID_PCM_F64LE || - enc->codec_id == AV_CODEC_ID_PCM_S16LE) { - bytespersec = enc->sample_rate * blkalign; + blkalign = bps * par->channels / av_gcd(8, bps); + if (par->codec_id == AV_CODEC_ID_PCM_U8 || + par->codec_id == AV_CODEC_ID_PCM_S24LE || + par->codec_id == AV_CODEC_ID_PCM_S32LE || + par->codec_id == AV_CODEC_ID_PCM_F32LE || + par->codec_id == AV_CODEC_ID_PCM_F64LE || + par->codec_id == AV_CODEC_ID_PCM_S16LE) { + bytespersec = par->sample_rate * blkalign; } else { - bytespersec = enc->bit_rate / 8; + bytespersec = par->bit_rate / 8; } avio_wl32(pb, bytespersec); /* bytes per second */ avio_wl16(pb, blkalign); /* block align */ avio_wl16(pb, bps); /* bits per sample */ - if (enc->codec_id == AV_CODEC_ID_MP3) { + if (par->codec_id == AV_CODEC_ID_MP3) { hdrsize += 12; bytestream_put_le16(&riff_extradata, 1); /* wID */ bytestream_put_le32(&riff_extradata, 2); /* fdwFlags */ bytestream_put_le16(&riff_extradata, 1152); /* nBlockSize */ bytestream_put_le16(&riff_extradata, 1); /* nFramesPerBlock */ bytestream_put_le16(&riff_extradata, 1393); /* nCodecDelay */ - } else if (enc->codec_id == AV_CODEC_ID_MP2) { + } else if (par->codec_id == AV_CODEC_ID_MP2) { hdrsize += 22; /* fwHeadLayer */ bytestream_put_le16(&riff_extradata, 2); /* dwHeadBitrate */ - bytestream_put_le32(&riff_extradata, enc->bit_rate); + bytestream_put_le32(&riff_extradata, par->bit_rate); /* fwHeadMode */ - bytestream_put_le16(&riff_extradata, enc->channels == 2 ? 1 : 8); + bytestream_put_le16(&riff_extradata, par->channels == 2 ? 1 : 8); /* fwHeadModeExt */ bytestream_put_le16(&riff_extradata, 0); /* wHeadEmphasis */ @@ -142,15 +143,15 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) bytestream_put_le32(&riff_extradata, 0); /* dwPTSHigh */ bytestream_put_le32(&riff_extradata, 0); - } else if (enc->codec_id == AV_CODEC_ID_GSM_MS || - enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { + } else if (par->codec_id == AV_CODEC_ID_GSM_MS || + par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { hdrsize += 2; /* wSamplesPerBlock */ bytestream_put_le16(&riff_extradata, frame_size); - } else if (enc->extradata_size) { - riff_extradata_start = enc->extradata; - riff_extradata = enc->extradata + enc->extradata_size; - hdrsize += enc->extradata_size; + } else if (par->extradata_size) { + riff_extradata_start = par->extradata; + riff_extradata = par->extradata + par->extradata_size; + hdrsize += par->extradata_size; } /* write WAVEFORMATEXTENSIBLE extensions */ if (waveformatextensible) { @@ -160,9 +161,9 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) /* ValidBitsPerSample || SamplesPerBlock || Reserved */ avio_wl16(pb, bps); /* dwChannelMask */ - avio_wl32(pb, enc->channel_layout); + avio_wl32(pb, par->channel_layout); /* GUID + next 3 */ - avio_wl32(pb, enc->codec_tag); + avio_wl32(pb, par->codec_tag); avio_wl32(pb, 0x00100000); avio_wl32(pb, 0xAA000080); avio_wl32(pb, 0x719B3800); @@ -179,54 +180,54 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) } /* BITMAPINFOHEADER header */ -void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, +void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, const AVCodecTag *tags, int for_asf) { /* size */ - avio_wl32(pb, 40 + enc->extradata_size); - avio_wl32(pb, enc->width); + avio_wl32(pb, 40 + par->extradata_size); + avio_wl32(pb, par->width); //We always store RGB TopDown - avio_wl32(pb, enc->codec_tag ? enc->height : -enc->height); + avio_wl32(pb, par->codec_tag ? par->height : -par->height); /* planes */ avio_wl16(pb, 1); /* depth */ - avio_wl16(pb, enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24); + avio_wl16(pb, par->bits_per_coded_sample ? par->bits_per_coded_sample : 24); /* compression type */ - avio_wl32(pb, enc->codec_tag); - avio_wl32(pb, enc->width * enc->height * 3); + avio_wl32(pb, par->codec_tag); + avio_wl32(pb, par->width * par->height * 3); avio_wl32(pb, 0); avio_wl32(pb, 0); avio_wl32(pb, 0); avio_wl32(pb, 0); - avio_write(pb, enc->extradata, enc->extradata_size); + avio_write(pb, par->extradata, par->extradata_size); - if (!for_asf && enc->extradata_size & 1) + if (!for_asf && par->extradata_size & 1) avio_w8(pb, 0); } void ff_parse_specific_params(AVStream *st, int *au_rate, int *au_ssize, int *au_scale) { - AVCodecContext *codec = st->codec; + AVCodecParameters *par = st->codecpar; int gcd; int audio_frame_size; - audio_frame_size = av_get_audio_frame_duration(codec, 0); + audio_frame_size = av_get_audio_frame_duration2(par, 0); - *au_ssize = codec->block_align; - if (audio_frame_size && codec->sample_rate) { + *au_ssize = par->block_align; + if (audio_frame_size && par->sample_rate) { *au_scale = audio_frame_size; - *au_rate = codec->sample_rate; - } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO || - codec->codec_type == AVMEDIA_TYPE_DATA || - codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { + *au_rate = par->sample_rate; + } else if (par->codec_type == AVMEDIA_TYPE_VIDEO || + par->codec_type == AVMEDIA_TYPE_DATA || + par->codec_type == AVMEDIA_TYPE_SUBTITLE) { *au_scale = st->time_base.num; *au_rate = st->time_base.den; } else { - *au_scale = codec->block_align ? codec->block_align * 8 : 8; - *au_rate = codec->bit_rate ? codec->bit_rate : - 8 * codec->sample_rate; + *au_scale = par->block_align ? par->block_align * 8 : 8; + *au_rate = par->bit_rate ? par->bit_rate : + 8 * par->sample_rate; } gcd = av_gcd(*au_scale, *au_rate); *au_scale /= gcd; diff --git a/libavformat/rl2.c b/libavformat/rl2.c index 51de3473da..1bd9d15960 100644 --- a/libavformat/rl2.c +++ b/libavformat/rl2.c @@ -119,25 +119,25 @@ static av_cold int rl2_read_header(AVFormatContext *s) if(!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RL2; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = 320; - st->codec->height = 200; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RL2; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = 320; + st->codecpar->height = 200; /** allocate and fill extradata */ - st->codec->extradata_size = EXTRADATA1_SIZE; + st->codecpar->extradata_size = EXTRADATA1_SIZE; if(signature == RLV3_TAG && back_size > 0) - st->codec->extradata_size += back_size; + st->codecpar->extradata_size += back_size; - st->codec->extradata = av_mallocz(st->codec->extradata_size + - AV_INPUT_BUFFER_PADDING_SIZE); - if(!st->codec->extradata) + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if(!st->codecpar->extradata) return AVERROR(ENOMEM); - if(avio_read(pb,st->codec->extradata,st->codec->extradata_size) != - st->codec->extradata_size) + if(avio_read(pb,st->codecpar->extradata,st->codecpar->extradata_size) != + st->codecpar->extradata_size) return AVERROR(EIO); /** setup audio stream if present */ @@ -148,16 +148,16 @@ static av_cold int rl2_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_U8; - st->codec->codec_tag = 1; - st->codec->channels = channels; - st->codec->bits_per_coded_sample = 8; - st->codec->sample_rate = rate; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * - st->codec->bits_per_coded_sample; - st->codec->block_align = st->codec->channels * - st->codec->bits_per_coded_sample / 8; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->codec_tag = 1; + st->codecpar->channels = channels; + st->codecpar->bits_per_coded_sample = 8; + st->codecpar->sample_rate = rate; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = st->codecpar->channels * + st->codecpar->bits_per_coded_sample / 8; avpriv_set_pts_info(st,32,1,rate); } diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 5110b0369c..504f111ac0 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -82,15 +82,15 @@ static void get_str8(AVIOContext *pb, char *buf, int buf_size) get_strl(pb, buf, buf_size, avio_r8(pb)); } -static int rm_read_extradata(AVIOContext *pb, AVCodecContext *avctx, unsigned size) +static int rm_read_extradata(AVIOContext *pb, AVCodecParameters *par, unsigned size) { if (size >= 1<<24) return -1; - avctx->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!avctx->extradata) + par->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!par->extradata) return AVERROR(ENOMEM); - avctx->extradata_size = avio_read(pb, avctx->extradata, size); - if (avctx->extradata_size != size) + par->extradata_size = avio_read(pb, par->extradata, size); + if (par->extradata_size != size) return AVERROR(EIO); return 0; } @@ -142,11 +142,11 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, // Skip extra header crap (this should never happen) if ((startpos + header_size) > avio_tell(pb)) avio_skip(pb, header_size + startpos - avio_tell(pb)); - st->codec->sample_rate = 8000; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_RA_144; + st->codecpar->sample_rate = 8000; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_RA_144; ast->deint_id = DEINT_ID_INT0; } else { int flavor, sub_packet_h, coded_framesize, sub_packet_size; @@ -163,15 +163,15 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, avio_rb32(pb); /* ??? */ avio_rb32(pb); /* ??? */ ast->sub_packet_h = sub_packet_h = avio_rb16(pb); /* 1 */ - st->codec->block_align= avio_rb16(pb); /* frame size */ + st->codecpar->block_align= avio_rb16(pb); /* frame size */ ast->sub_packet_size = sub_packet_size = avio_rb16(pb); /* sub packet size */ avio_rb16(pb); /* ??? */ if (version == 5) { avio_rb16(pb); avio_rb16(pb); avio_rb16(pb); } - st->codec->sample_rate = avio_rb16(pb); + st->codecpar->sample_rate = avio_rb16(pb); avio_rb32(pb); - st->codec->channels = avio_rb16(pb); + st->codecpar->channels = avio_rb16(pb); if (version == 5) { ast->deint_id = avio_rl32(pb); avio_read(pb, buf, 4); @@ -181,19 +181,19 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, ast->deint_id = AV_RL32(buf); get_str8(pb, buf, sizeof(buf)); /* desc */ } - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = AV_RL32(buf); - st->codec->codec_id = ff_codec_get_id(ff_rm_codec_tags, - st->codec->codec_tag); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = AV_RL32(buf); + st->codecpar->codec_id = ff_codec_get_id(ff_rm_codec_tags, + st->codecpar->codec_tag); - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_AC3: st->need_parsing = AVSTREAM_PARSE_FULL; break; case AV_CODEC_ID_RA_288: - st->codec->extradata_size= 0; - ast->audio_framesize = st->codec->block_align; - st->codec->block_align = coded_framesize; + st->codecpar->extradata_size= 0; + ast->audio_framesize = st->codecpar->block_align; + st->codecpar->block_align = coded_framesize; break; case AV_CODEC_ID_COOK: st->need_parsing = AVSTREAM_PARSE_HEADERS; @@ -208,22 +208,22 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, return -1; } - ast->audio_framesize = st->codec->block_align; - if (st->codec->codec_id == AV_CODEC_ID_SIPR) { + ast->audio_framesize = st->codecpar->block_align; + if (st->codecpar->codec_id == AV_CODEC_ID_SIPR) { if (flavor > 3) { av_log(s, AV_LOG_ERROR, "bad SIPR file flavor %d\n", flavor); return -1; } - st->codec->block_align = ff_sipr_subpk_size[flavor]; + st->codecpar->block_align = ff_sipr_subpk_size[flavor]; } else { if(sub_packet_size <= 0){ av_log(s, AV_LOG_ERROR, "sub_packet_size is invalid\n"); return -1; } - st->codec->block_align = ast->sub_packet_size; + st->codecpar->block_align = ast->sub_packet_size; } - if ((ret = rm_read_extradata(pb, st->codec, codecdata_length)) < 0) + if ((ret = rm_read_extradata(pb, st->codecpar, codecdata_length)) < 0) return ret; break; case AV_CODEC_ID_AAC: @@ -237,7 +237,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, } if (codecdata_length >= 1) { avio_r8(pb); - if ((ret = rm_read_extradata(pb, st->codec, codecdata_length - 1)) < 0) + if ((ret = rm_read_extradata(pb, st->codecpar, codecdata_length - 1)) < 0) return ret; } break; @@ -245,9 +245,9 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, if (ast->deint_id == DEINT_ID_INT4 || ast->deint_id == DEINT_ID_GENR || ast->deint_id == DEINT_ID_SIPR) { - if (st->codec->block_align <= 0 || + if (st->codecpar->block_align <= 0 || ast->audio_framesize * sub_packet_h > (unsigned)INT_MAX || - ast->audio_framesize * sub_packet_h < st->codec->block_align) + ast->audio_framesize * sub_packet_h < st->codecpar->block_align) return AVERROR_INVALIDDATA; if (av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h) < 0) return AVERROR(ENOMEM); @@ -302,13 +302,13 @@ int ff_rm_read_mdpr_codecdata(AVFormatContext *s, AVIOContext *pb, return -1; } else if (v == MKBETAG('L', 'S', 'D', ':')) { avio_seek(pb, -4, SEEK_CUR); - if ((ret = rm_read_extradata(pb, st->codec, codec_data_size)) < 0) + if ((ret = rm_read_extradata(pb, st->codecpar, codec_data_size)) < 0) return ret; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = AV_RL32(st->codec->extradata); - st->codec->codec_id = ff_codec_get_id(ff_rm_codec_tags, - st->codec->codec_tag); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = AV_RL32(st->codecpar->extradata); + st->codecpar->codec_id = ff_codec_get_id(ff_rm_codec_tags, + st->codecpar->codec_tag); } else { int fps; if (avio_rl32(pb) != MKTAG('V', 'I', 'D', 'O')) { @@ -316,21 +316,21 @@ int ff_rm_read_mdpr_codecdata(AVFormatContext *s, AVIOContext *pb, av_log(s, AV_LOG_WARNING, "Unsupported stream type %08x\n", v); goto skip; } - st->codec->codec_tag = avio_rl32(pb); - st->codec->codec_id = ff_codec_get_id(ff_rm_codec_tags, - st->codec->codec_tag); - av_log(s, AV_LOG_TRACE, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0')); - if (st->codec->codec_id == AV_CODEC_ID_NONE) + st->codecpar->codec_tag = avio_rl32(pb); + st->codecpar->codec_id = ff_codec_get_id(ff_rm_codec_tags, + st->codecpar->codec_tag); + av_log(s, AV_LOG_TRACE, "%X %X\n", st->codecpar->codec_tag, MKTAG('R', 'V', '2', '0')); + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) goto fail1; - st->codec->width = avio_rb16(pb); - st->codec->height = avio_rb16(pb); + st->codecpar->width = avio_rb16(pb); + st->codecpar->height = avio_rb16(pb); avio_skip(pb, 2); // looks like bits per sample avio_skip(pb, 4); // always zero? - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; fps = avio_rb32(pb); - if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (avio_tell(pb) - codec_pos))) < 0) + if ((ret = rm_read_extradata(pb, st->codecpar, codec_data_size - (avio_tell(pb) - codec_pos))) < 0) return ret; if (fps > 0) { @@ -485,7 +485,7 @@ static int rm_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->id = avio_rb16(pb); avio_rb32(pb); /* max bit rate */ - st->codec->bit_rate = avio_rb32(pb); /* bit rate */ + st->codecpar->bit_rate = avio_rb32(pb); /* bit rate */ avio_rb32(pb); /* max packet size */ avio_rb32(pb); /* avg packet size */ start_time = avio_rb32(pb); /* start time */ @@ -495,7 +495,7 @@ static int rm_read_header(AVFormatContext *s) st->duration = duration; get_str8(pb, buf, sizeof(buf)); /* desc */ get_str8(pb, buf, sizeof(buf)); /* mimetype */ - st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->priv_data = ff_rm_alloc_rmstream(); if (!st->priv_data) return AVERROR(ENOMEM); @@ -706,7 +706,7 @@ rm_ac3_swap_bytes (AVStream *st, AVPacket *pkt) uint8_t *ptr; int j; - if (st->codec->codec_id == AV_CODEC_ID_AC3) { + if (st->codecpar->codec_id == AV_CODEC_ID_AC3) { ptr = pkt->data; for (j=0;j<pkt->size;j+=2) { FFSWAP(int, ptr[0], ptr[1]); @@ -722,11 +722,11 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb, { RMDemuxContext *rm = s->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { rm->current_stream= st->id; if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, ×tamp)) return -1; //got partial frame - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if ((ast->deint_id == DEINT_ID_GENR) || (ast->deint_id == DEINT_ID_INT4) || (ast->deint_id == DEINT_ID_SIPR)) { @@ -763,7 +763,7 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb, ast->sub_packet_cnt = 0; rm->audio_stream_num = st->index; - rm->audio_pkt_cnt = h * w / st->codec->block_align; + rm->audio_pkt_cnt = h * w / st->codecpar->block_align; } else if ((ast->deint_id == DEINT_ID_VBRF) || (ast->deint_id == DEINT_ID_VBRS)) { int x; @@ -786,8 +786,8 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb, pkt->stream_index = st->index; #if 0 - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - if(st->codec->codec_id == AV_CODEC_ID_RV20){ + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if(st->codecpar->codec_id == AV_CODEC_ID_RV20){ int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1); av_log(s, AV_LOG_DEBUG, "%d %"PRId64" %d\n", *timestamp, *timestamp*512LL/25, seq); @@ -802,7 +802,7 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb, if (flags & 2) pkt->flags |= AV_PKT_FLAG_KEY; - return st->codec->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0; + return st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0; } int @@ -817,12 +817,12 @@ ff_rm_retrieve_cache (AVFormatContext *s, AVIOContext *pb, ast->deint_id == DEINT_ID_VBRS) av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]); else { - int ret = av_new_packet(pkt, st->codec->block_align); + int ret = av_new_packet(pkt, st->codecpar->block_align); if (ret < 0) return ret; - memcpy(pkt->data, ast->pkt.data + st->codec->block_align * //FIXME avoid this - (ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt), - st->codec->block_align); + memcpy(pkt->data, ast->pkt.data + st->codecpar->block_align * //FIXME avoid this + (ast->sub_packet_h * ast->audio_framesize / st->codecpar->block_align - rm->audio_pkt_cnt), + st->codecpar->block_align); } rm->audio_pkt_cnt--; if ((pkt->pts = ast->audiotimestamp) != AV_NOPTS_VALUE) { @@ -933,7 +933,7 @@ static int64_t rm_read_dts(AVFormatContext *s, int stream_index, return AV_NOPTS_VALUE; st = s->streams[stream_index2]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { h= avio_r8(s->pb); len--; if(!(h & 0x40)){ seq = avio_r8(s->pb); len--; diff --git a/libavformat/rmenc.c b/libavformat/rmenc.c index bbfd550a3b..e4a0d60a42 100644 --- a/libavformat/rmenc.c +++ b/libavformat/rmenc.c @@ -33,7 +33,7 @@ typedef struct StreamInfo { int nb_frames; /* current frame number */ int total_frames; /* total number of frames */ int num; - AVCodecContext *enc; + AVCodecParameters *par; } StreamInfo; typedef struct RMMuxContext { @@ -147,7 +147,7 @@ static int rv10_write_header(AVFormatContext *ctx, stream = &rm->streams[i]; - if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) { + if (stream->par->codec_type == AVMEDIA_TYPE_AUDIO) { desc = "The Audio Stream"; mimetype = "audio/x-pn-realaudio"; codec_data_size = 73; @@ -183,11 +183,11 @@ static int rv10_write_header(AVFormatContext *ctx, put_str8(s, mimetype); avio_wb32(s, codec_data_size); - if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) { + if (stream->par->codec_type == AVMEDIA_TYPE_AUDIO) { int coded_frame_size, fscode, sample_rate; - int frame_size = av_get_audio_frame_duration(stream->enc, 0); - sample_rate = stream->enc->sample_rate; - coded_frame_size = (stream->enc->bit_rate * + int frame_size = av_get_audio_frame_duration2(stream->par, 0); + sample_rate = stream->par->sample_rate; + coded_frame_size = (stream->par->bit_rate * frame_size) / (8 * sample_rate); /* audio codec info */ avio_write(s, ".ra", 3); @@ -228,13 +228,13 @@ static int rv10_write_header(AVFormatContext *ctx, /* frame length : seems to be very important */ avio_wb16(s, coded_frame_size); avio_wb32(s, 0); /* unknown */ - avio_wb16(s, stream->enc->sample_rate); /* sample rate */ + avio_wb16(s, stream->par->sample_rate); /* sample rate */ avio_wb32(s, 0x10); /* unknown */ - avio_wb16(s, stream->enc->channels); + avio_wb16(s, stream->par->channels); put_str8(s, "Int0"); /* codec name */ - if (stream->enc->codec_tag) { + if (stream->par->codec_tag) { avio_w8(s, 4); /* tag length */ - avio_wl32(s, stream->enc->codec_tag); + avio_wl32(s, stream->par->codec_tag); } else { av_log(ctx, AV_LOG_ERROR, "Invalid codec tag\n"); return -1; @@ -247,12 +247,12 @@ static int rv10_write_header(AVFormatContext *ctx, /* video codec info */ avio_wb32(s,34); /* size */ ffio_wfourcc(s, "VIDO"); - if(stream->enc->codec_id == AV_CODEC_ID_RV10) + if(stream->par->codec_id == AV_CODEC_ID_RV10) ffio_wfourcc(s,"RV10"); else ffio_wfourcc(s,"RV20"); - avio_wb16(s, stream->enc->width); - avio_wb16(s, stream->enc->height); + avio_wb16(s, stream->par->width); + avio_wb16(s, stream->par->height); avio_wb16(s, (int) stream->frame_rate); /* frames per seconds ? */ avio_wb32(s,0); /* unknown meaning */ avio_wb16(s, (int) stream->frame_rate); /* unknown meaning */ @@ -261,7 +261,7 @@ static int rv10_write_header(AVFormatContext *ctx, /* Seems to be the codec version: only use basic H263. The next versions seems to add a diffential DC coding as in MPEG... nothing new under the sun */ - if(stream->enc->codec_id == AV_CODEC_ID_RV10) + if(stream->par->codec_id == AV_CODEC_ID_RV10) avio_wb32(s,0x10000000); else avio_wb32(s,0x20103001); @@ -312,25 +312,25 @@ static int rm_write_header(AVFormatContext *s) RMMuxContext *rm = s->priv_data; StreamInfo *stream; int n; - AVCodecContext *codec; + AVCodecParameters *par; for(n=0;n<s->nb_streams;n++) { AVStream *st = s->streams[n]; int frame_size; s->streams[n]->id = n; - codec = s->streams[n]->codec; + par = s->streams[n]->codecpar; stream = &rm->streams[n]; memset(stream, 0, sizeof(StreamInfo)); stream->num = n; - stream->bit_rate = codec->bit_rate; - stream->enc = codec; + stream->bit_rate = par->bit_rate; + stream->par = par; - switch(codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: rm->audio_stream = stream; - frame_size = av_get_audio_frame_duration(codec, 0); - stream->frame_rate = (float)codec->sample_rate / (float)frame_size; + frame_size = av_get_audio_frame_duration2(par, 0); + stream->frame_rate = (float)par->sample_rate / (float)frame_size; /* XXX: dummy values */ stream->packet_max_size = 1024; stream->nb_packets = 0; @@ -365,7 +365,7 @@ static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY)); - if (stream->enc->codec_id == AV_CODEC_ID_AC3) { + if (stream->par->codec_id == AV_CODEC_ID_AC3) { /* for AC-3, the words seem to be reversed */ for (i = 0; i < size; i += 2) { avio_w8(pb, buf[i + 1]); @@ -428,7 +428,7 @@ static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int static int rm_write_packet(AVFormatContext *s, AVPacket *pkt) { - if (s->streams[pkt->stream_index]->codec->codec_type == + if (s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) return rm_write_audio(s, pkt->data, pkt->size, pkt->flags); else diff --git a/libavformat/rpl.c b/libavformat/rpl.c index fdcefdbf72..0fa940e524 100644 --- a/libavformat/rpl.c +++ b/libavformat/rpl.c @@ -145,35 +145,35 @@ static int rpl_read_header(AVFormatContext *s) vst = avformat_new_stream(s, NULL); if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_tag = read_line_and_int(pb, &error); // video format - vst->codec->width = read_line_and_int(pb, &error); // video width - vst->codec->height = read_line_and_int(pb, &error); // video height - vst->codec->bits_per_coded_sample = read_line_and_int(pb, &error); // video bits per sample + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_tag = read_line_and_int(pb, &error); // video format + vst->codecpar->width = read_line_and_int(pb, &error); // video width + vst->codecpar->height = read_line_and_int(pb, &error); // video height + vst->codecpar->bits_per_coded_sample = read_line_and_int(pb, &error); // video bits per sample error |= read_line(pb, line, sizeof(line)); // video frames per second fps = read_fps(line, &error); avpriv_set_pts_info(vst, 32, fps.den, fps.num); // Figure out the video codec - switch (vst->codec->codec_tag) { + switch (vst->codecpar->codec_tag) { #if 0 case 122: - vst->codec->codec_id = AV_CODEC_ID_ESCAPE122; + vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE122; break; #endif case 124: - vst->codec->codec_id = AV_CODEC_ID_ESCAPE124; + vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE124; // The header is wrong here, at least sometimes - vst->codec->bits_per_coded_sample = 16; + vst->codecpar->bits_per_coded_sample = 16; break; case 130: - vst->codec->codec_id = AV_CODEC_ID_ESCAPE130; + vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE130; break; default: av_log(s, AV_LOG_WARNING, "RPL video format %i not supported yet!\n", - vst->codec->codec_tag); - vst->codec->codec_id = AV_CODEC_ID_NONE; + vst->codecpar->codec_tag); + vst->codecpar->codec_id = AV_CODEC_ID_NONE; } // Audio headers @@ -185,59 +185,59 @@ static int rpl_read_header(AVFormatContext *s) ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_tag = audio_format; - ast->codec->sample_rate = read_line_and_int(pb, &error); // audio bitrate - ast->codec->channels = read_line_and_int(pb, &error); // number of audio channels - ast->codec->bits_per_coded_sample = read_line_and_int(pb, &error); // audio bits per sample + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_tag = audio_format; + ast->codecpar->sample_rate = read_line_and_int(pb, &error); // audio bitrate + ast->codecpar->channels = read_line_and_int(pb, &error); // number of audio channels + ast->codecpar->bits_per_coded_sample = read_line_and_int(pb, &error); // audio bits per sample // At least one sample uses 0 for ADPCM, which is really 4 bits // per sample. - if (ast->codec->bits_per_coded_sample == 0) - ast->codec->bits_per_coded_sample = 4; + if (ast->codecpar->bits_per_coded_sample == 0) + ast->codecpar->bits_per_coded_sample = 4; - ast->codec->bit_rate = ast->codec->sample_rate * - ast->codec->bits_per_coded_sample * - ast->codec->channels; + ast->codecpar->bit_rate = ast->codecpar->sample_rate * + ast->codecpar->bits_per_coded_sample * + ast->codecpar->channels; - ast->codec->codec_id = AV_CODEC_ID_NONE; + ast->codecpar->codec_id = AV_CODEC_ID_NONE; switch (audio_format) { case 1: - if (ast->codec->bits_per_coded_sample == 16) { + if (ast->codecpar->bits_per_coded_sample == 16) { // 16-bit audio is always signed - ast->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; break; } // There are some other formats listed as legal per the spec; // samples needed. break; case 101: - if (ast->codec->bits_per_coded_sample == 8) { + if (ast->codecpar->bits_per_coded_sample == 8) { // The samples with this kind of audio that I have // are all unsigned. - ast->codec->codec_id = AV_CODEC_ID_PCM_U8; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8; break; - } else if (ast->codec->bits_per_coded_sample == 4) { - ast->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_EA_SEAD; + } else if (ast->codecpar->bits_per_coded_sample == 4) { + ast->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_EA_SEAD; break; } break; } - if (ast->codec->codec_id == AV_CODEC_ID_NONE) { + if (ast->codecpar->codec_id == AV_CODEC_ID_NONE) { av_log(s, AV_LOG_WARNING, "RPL audio format %"PRId32" not supported yet!\n", audio_format); } - avpriv_set_pts_info(ast, 32, 1, ast->codec->bit_rate); + avpriv_set_pts_info(ast, 32, 1, ast->codecpar->bit_rate); } else { for (i = 0; i < 3; i++) error |= read_line(pb, line, sizeof(line)); } rpl->frames_per_chunk = read_line_and_int(pb, &error); // video frames per chunk - if (rpl->frames_per_chunk > 1 && vst->codec->codec_tag != 124) + if (rpl->frames_per_chunk > 1 && vst->codecpar->codec_tag != 124) av_log(s, AV_LOG_WARNING, "Don't know how to split frames for video format %i. " - "Video stream will be broken!\n", vst->codec->codec_tag); + "Video stream will be broken!\n", vst->codecpar->codec_tag); number_of_chunks = read_line_and_int(pb, &error); // number of chunks in the file // The number in the header is actually the index of the last chunk. @@ -297,8 +297,8 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0) return AVERROR(EIO); - if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO && - stream->codec->codec_tag == 124) { + if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + stream->codecpar->codec_tag == 124) { // We have to split Escape 124 frames because there are // multiple frames per chunk in Escape 124 samples. uint32_t frame_size; @@ -329,7 +329,7 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EIO); } - if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { // frames_per_chunk should always be one here; the header // parsing will warn if it isn't. pkt->duration = rpl->frames_per_chunk; diff --git a/libavformat/rsodec.c b/libavformat/rsodec.c index 1612572b56..6f352af96c 100644 --- a/libavformat/rsodec.c +++ b/libavformat/rsodec.c @@ -59,12 +59,12 @@ static int rso_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->duration = (size * 8) / bps; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = id; - st->codec->codec_id = codec; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = id; + st->codecpar->codec_id = codec; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = rate; avpriv_set_pts_info(st, 64, 1, rate); @@ -75,7 +75,7 @@ static int rso_read_header(AVFormatContext *s) static int rso_read_packet(AVFormatContext *s, AVPacket *pkt) { - int bps = av_get_bits_per_sample(s->streams[0]->codec->codec_id); + int bps = av_get_bits_per_sample(s->streams[0]->codecpar->codec_id); int ret = av_get_packet(s->pb, pkt, BLOCK_SIZE * bps >> 3); if (ret < 0) diff --git a/libavformat/rsoenc.c b/libavformat/rsoenc.c index 8ebcf8193b..dd0fbf8c41 100644 --- a/libavformat/rsoenc.c +++ b/libavformat/rsoenc.c @@ -28,12 +28,12 @@ static int rso_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - if (!enc->codec_tag) + if (!par->codec_tag) return AVERROR_INVALIDDATA; - if (enc->channels != 1) { + if (par->channels != 1) { av_log(s, AV_LOG_ERROR, "RSO only supports mono\n"); return AVERROR_INVALIDDATA; } @@ -44,20 +44,20 @@ static int rso_write_header(AVFormatContext *s) } /* XXX: find legal sample rates (if any) */ - if (enc->sample_rate >= 1u<<16) { + if (par->sample_rate >= 1u<<16) { av_log(s, AV_LOG_ERROR, "Sample rate must be < 65536\n"); return AVERROR_INVALIDDATA; } - if (enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { + if (par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { av_log(s, AV_LOG_ERROR, "ADPCM in RSO not implemented\n"); return AVERROR_PATCHWELCOME; } /* format header */ - avio_wb16(pb, enc->codec_tag); /* codec ID */ + avio_wb16(pb, par->codec_tag); /* codec ID */ avio_wb16(pb, 0); /* data size, will be written at EOF */ - avio_wb16(pb, enc->sample_rate); + avio_wb16(pb, par->sample_rate); avio_wb16(pb, 0x0000); /* play mode ? (0x0000 = don't loop) */ avio_flush(pb); diff --git a/libavformat/rtp.c b/libavformat/rtp.c index 0a3c411f51..5eb92e4df0 100644 --- a/libavformat/rtp.c +++ b/libavformat/rtp.c @@ -67,19 +67,19 @@ static const struct { {-1, "", AVMEDIA_TYPE_UNKNOWN, AV_CODEC_ID_NONE, -1, -1} }; -int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type) +int ff_rtp_get_codec_info(AVCodecParameters *par, int payload_type) { int i = 0; for (i = 0; rtp_payload_types[i].pt >= 0; i++) if (rtp_payload_types[i].pt == payload_type) { if (rtp_payload_types[i].codec_id != AV_CODEC_ID_NONE) { - codec->codec_type = rtp_payload_types[i].codec_type; - codec->codec_id = rtp_payload_types[i].codec_id; + par->codec_type = rtp_payload_types[i].codec_type; + par->codec_id = rtp_payload_types[i].codec_id; if (rtp_payload_types[i].audio_channels > 0) - codec->channels = rtp_payload_types[i].audio_channels; + par->channels = rtp_payload_types[i].audio_channels; if (rtp_payload_types[i].clock_rate > 0) - codec->sample_rate = rtp_payload_types[i].clock_rate; + par->sample_rate = rtp_payload_types[i].clock_rate; return 0; } } @@ -87,7 +87,7 @@ int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type) } int ff_rtp_get_payload_type(AVFormatContext *fmt, - AVCodecContext *codec, int idx) + AVCodecParameters *par, int idx) { int i; AVOutputFormat *ofmt = fmt ? fmt->oformat : NULL; @@ -102,27 +102,27 @@ int ff_rtp_get_payload_type(AVFormatContext *fmt, /* static payload type */ for (i = 0; rtp_payload_types[i].pt >= 0; ++i) - if (rtp_payload_types[i].codec_id == codec->codec_id) { - if (codec->codec_id == AV_CODEC_ID_H263 && (!fmt || !fmt->oformat || + if (rtp_payload_types[i].codec_id == par->codec_id) { + if (par->codec_id == AV_CODEC_ID_H263 && (!fmt || !fmt->oformat || !fmt->oformat->priv_class || !fmt->priv_data || !av_opt_flag_is_set(fmt->priv_data, "rtpflags", "rfc2190"))) continue; /* G722 has 8000 as nominal rate even if the sample rate is 16000, * see section 4.5.2 in RFC 3551. */ - if (codec->codec_id == AV_CODEC_ID_ADPCM_G722 && - codec->sample_rate == 16000 && codec->channels == 1) + if (par->codec_id == AV_CODEC_ID_ADPCM_G722 && + par->sample_rate == 16000 && par->channels == 1) return rtp_payload_types[i].pt; - if (codec->codec_type == AVMEDIA_TYPE_AUDIO && + if (par->codec_type == AVMEDIA_TYPE_AUDIO && ((rtp_payload_types[i].clock_rate > 0 && - codec->sample_rate != rtp_payload_types[i].clock_rate) || + par->sample_rate != rtp_payload_types[i].clock_rate) || (rtp_payload_types[i].audio_channels > 0 && - codec->channels != rtp_payload_types[i].audio_channels))) + par->channels != rtp_payload_types[i].audio_channels))) continue; return rtp_payload_types[i].pt; } if (idx < 0) - idx = codec->codec_type == AVMEDIA_TYPE_AUDIO; + idx = par->codec_type == AVMEDIA_TYPE_AUDIO; /* dynamic payload type */ return RTP_PT_PRIVATE + idx; diff --git a/libavformat/rtp.h b/libavformat/rtp.h index feaf167965..01b83dfa23 100644 --- a/libavformat/rtp.h +++ b/libavformat/rtp.h @@ -32,11 +32,11 @@ * The format context private option payload_type overrides both. * * @param fmt The context of the format - * @param codec The context of the codec + * @param par The codec parameters * @param idx The stream index * @return The payload type (the 'PT' field in the RTP header). */ -int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec, +int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecParameters *par, int idx); /** @@ -46,12 +46,12 @@ int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec, * information depending on the payload type; for audio codecs, the * channels and sample_rate fields are also filled. * - * @param codec The context of the codec + * @param par The codec parameters * @param payload_type The payload type (the 'PT' field in the RTP header) * @return In case of unknown payload type or dynamic payload type, a * negative value is returned; otherwise, 0 is returned */ -int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type); +int ff_rtp_get_codec_info(AVCodecParameters *par, int payload_type); /** * Return the encoding name (as defined in diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index dfeb529435..3bb6b19ad9 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -518,12 +518,12 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, rtp_init_statistics(&s->statistics, 0); if (st) { - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_ADPCM_G722: /* According to RFC 3551, the stream clock rate is 8000 * even if the sample rate is 16000. */ - if (st->codec->sample_rate == 8000) - st->codec->sample_rate = 16000; + if (st->codecpar->sample_rate == 8000) + st->codecpar->sample_rate = 16000; break; default: break; diff --git a/libavformat/rtpdec_amr.c b/libavformat/rtpdec_amr.c index b6a8c29052..baf4de9918 100644 --- a/libavformat/rtpdec_amr.c +++ b/libavformat/rtpdec_amr.c @@ -55,20 +55,20 @@ static int amr_handle_packet(AVFormatContext *ctx, PayloadContext *data, const uint8_t *speech_data; uint8_t *ptr; - if (st->codec->codec_id == AV_CODEC_ID_AMR_NB) { + if (st->codecpar->codec_id == AV_CODEC_ID_AMR_NB) { frame_sizes = frame_sizes_nb; - } else if (st->codec->codec_id == AV_CODEC_ID_AMR_WB) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_AMR_WB) { frame_sizes = frame_sizes_wb; } else { av_log(ctx, AV_LOG_ERROR, "Bad codec ID\n"); return AVERROR_INVALIDDATA; } - if (st->codec->channels != 1) { + if (st->codecpar->channels != 1) { av_log(ctx, AV_LOG_ERROR, "Only mono AMR is supported\n"); return AVERROR_INVALIDDATA; } - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; /* The AMR RTP packet consists of one header byte, followed * by one TOC byte for each AMR frame in the packet, followed diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c index 10a4dcd8ab..d4972bd65d 100644 --- a/libavformat/rtpdec_asf.c +++ b/libavformat/rtpdec_asf.c @@ -150,12 +150,10 @@ static int asfrtp_parse_sdp_line(AVFormatContext *s, int stream_index, for (i = 0; i < rt->asf_ctx->nb_streams; i++) { if (s->streams[stream_index]->id == rt->asf_ctx->streams[i]->id) { - *s->streams[stream_index]->codec = - *rt->asf_ctx->streams[i]->codec; + avcodec_parameters_copy(s->streams[stream_index]->codecpar, + rt->asf_ctx->streams[i]->codecpar); s->streams[stream_index]->need_parsing = rt->asf_ctx->streams[i]->need_parsing; - rt->asf_ctx->streams[i]->codec->extradata_size = 0; - rt->asf_ctx->streams[i]->codec->extradata = NULL; avpriv_set_pts_info(s->streams[stream_index], 32, 1, 1000); } } diff --git a/libavformat/rtpdec_formats.h b/libavformat/rtpdec_formats.h index b71b1ae907..5424c1735b 100644 --- a/libavformat/rtpdec_formats.h +++ b/libavformat/rtpdec_formats.h @@ -45,7 +45,7 @@ int ff_h264_handle_aggregated_packet(AVFormatContext *ctx, AVPacket *pkt, int ff_h264_handle_frag_packet(AVPacket *pkt, const uint8_t *buf, int len, int start_bit, const uint8_t *nal_header, int nal_header_len); -void ff_h264_parse_framesize(AVCodecContext *codec, const char *p); +void ff_h264_parse_framesize(AVCodecParameters *par, const char *p); extern RTPDynamicProtocolHandler ff_ac3_dynamic_handler; extern RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler; diff --git a/libavformat/rtpdec_g726.c b/libavformat/rtpdec_g726.c index 7b3f6cbb89..53889bf741 100644 --- a/libavformat/rtpdec_g726.c +++ b/libavformat/rtpdec_g726.c @@ -27,10 +27,10 @@ static av_cold int g726_ ## bitrate ##_init(AVFormatContext *s, int st_index, \ PayloadContext *data) \ { \ AVStream *stream = s->streams[st_index]; \ - AVCodecContext *codec = stream->codec; \ + AVCodecParameters *par = stream->codecpar; \ \ - codec->bits_per_coded_sample = bitrate/8; \ - codec->bit_rate = codec->bits_per_coded_sample * codec->sample_rate; \ + par->bits_per_coded_sample = bitrate/8; \ + par->bit_rate = par->bits_per_coded_sample * par->sample_rate; \ \ return 0; \ } \ diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index e8543ee06d..d7b39ac895 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -146,7 +146,7 @@ static int sdp_parse_fmtp_config_h264(AVFormatContext *s, PayloadContext *h264_data, const char *attr, const char *value) { - AVCodecContext *codec = stream->codec; + AVCodecParameters *par = stream->codecpar; if (!strcmp(attr, "packetization-mode")) { av_log(s, AV_LOG_DEBUG, "RTP Packetization Mode: %d\n", atoi(value)); @@ -166,18 +166,18 @@ static int sdp_parse_fmtp_config_h264(AVFormatContext *s, parse_profile_level_id(s, h264_data, value); } else if (!strcmp(attr, "sprop-parameter-sets")) { int ret; - codec->extradata_size = 0; - av_freep(&codec->extradata); - ret = ff_h264_parse_sprop_parameter_sets(s, &codec->extradata, - &codec->extradata_size, value); + par->extradata_size = 0; + av_freep(&par->extradata); + ret = ff_h264_parse_sprop_parameter_sets(s, &par->extradata, + &par->extradata_size, value); av_log(s, AV_LOG_DEBUG, "Extradata set to %p (size: %d)\n", - codec->extradata, codec->extradata_size); + par->extradata, par->extradata_size); return ret; } return 0; } -void ff_h264_parse_framesize(AVCodecContext *codec, const char *p) +void ff_h264_parse_framesize(AVCodecParameters *par, const char *p) { char buf1[50]; char *dst = buf1; @@ -195,8 +195,8 @@ void ff_h264_parse_framesize(AVCodecContext *codec, const char *p) // a='framesize:96 320-240' // set our parameters - codec->width = atoi(buf1); - codec->height = atoi(p + 1); // skip the - + par->width = atoi(buf1); + par->height = atoi(p + 1); // skip the - } int ff_h264_handle_aggregated_packet(AVFormatContext *ctx, AVPacket *pkt, @@ -396,7 +396,7 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index, stream = s->streams[st_index]; if (av_strstart(p, "framesize:", &p)) { - ff_h264_parse_framesize(stream->codec, p); + ff_h264_parse_framesize(stream->codecpar, p); } else if (av_strstart(p, "fmtp:", &p)) { return ff_parse_fmtp(s, stream, h264_data, p, sdp_parse_fmtp_config_h264); } else if (av_strstart(p, "cliprect:", &p)) { diff --git a/libavformat/rtpdec_hevc.c b/libavformat/rtpdec_hevc.c index 2a802882f9..97f87aeec3 100644 --- a/libavformat/rtpdec_hevc.c +++ b/libavformat/rtpdec_hevc.c @@ -127,41 +127,41 @@ static av_cold int hevc_parse_sdp_line(AVFormatContext *ctx, int st_index, PayloadContext *hevc_data, const char *line) { AVStream *current_stream; - AVCodecContext *codec; + AVCodecParameters *par; const char *sdp_line_ptr = line; if (st_index < 0) return 0; current_stream = ctx->streams[st_index]; - codec = current_stream->codec; + par = current_stream->codecpar; if (av_strstart(sdp_line_ptr, "framesize:", &sdp_line_ptr)) { - ff_h264_parse_framesize(codec, sdp_line_ptr); + ff_h264_parse_framesize(par, sdp_line_ptr); } else if (av_strstart(sdp_line_ptr, "fmtp:", &sdp_line_ptr)) { int ret = ff_parse_fmtp(ctx, current_stream, hevc_data, sdp_line_ptr, hevc_sdp_parse_fmtp_config); if (hevc_data->vps_size || hevc_data->sps_size || hevc_data->pps_size || hevc_data->sei_size) { - av_freep(&codec->extradata); - codec->extradata_size = hevc_data->vps_size + hevc_data->sps_size + - hevc_data->pps_size + hevc_data->sei_size; - codec->extradata = av_malloc(codec->extradata_size + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!codec->extradata) { + av_freep(&par->extradata); + par->extradata_size = hevc_data->vps_size + hevc_data->sps_size + + hevc_data->pps_size + hevc_data->sei_size; + par->extradata = av_malloc(par->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!par->extradata) { ret = AVERROR(ENOMEM); - codec->extradata_size = 0; + par->extradata_size = 0; } else { int pos = 0; - memcpy(codec->extradata + pos, hevc_data->vps, hevc_data->vps_size); + memcpy(par->extradata + pos, hevc_data->vps, hevc_data->vps_size); pos += hevc_data->vps_size; - memcpy(codec->extradata + pos, hevc_data->sps, hevc_data->sps_size); + memcpy(par->extradata + pos, hevc_data->sps, hevc_data->sps_size); pos += hevc_data->sps_size; - memcpy(codec->extradata + pos, hevc_data->pps, hevc_data->pps_size); + memcpy(par->extradata + pos, hevc_data->pps, hevc_data->pps_size); pos += hevc_data->pps_size; - memcpy(codec->extradata + pos, hevc_data->sei, hevc_data->sei_size); + memcpy(par->extradata + pos, hevc_data->sei, hevc_data->sei_size); pos += hevc_data->sei_size; - memset(codec->extradata + pos, 0, AV_INPUT_BUFFER_PADDING_SIZE); + memset(par->extradata + pos, 0, AV_INPUT_BUFFER_PADDING_SIZE); } av_freep(&hevc_data->vps); diff --git a/libavformat/rtpdec_ilbc.c b/libavformat/rtpdec_ilbc.c index f47abc1f96..798ae36033 100644 --- a/libavformat/rtpdec_ilbc.c +++ b/libavformat/rtpdec_ilbc.c @@ -31,10 +31,10 @@ static int ilbc_parse_fmtp(AVFormatContext *s, int mode = atoi(value); switch (mode) { case 20: - stream->codec->block_align = 38; + stream->codecpar->block_align = 38; break; case 30: - stream->codec->block_align = 50; + stream->codecpar->block_align = 50; break; default: av_log(s, AV_LOG_ERROR, "Unsupported iLBC mode %d\n", mode); @@ -58,7 +58,7 @@ static int ilbc_parse_sdp_line(AVFormatContext *s, int st_index, int ret = ff_parse_fmtp(s, st, data, p, ilbc_parse_fmtp); if (ret < 0) return ret; - if (!st->codec->block_align) { + if (!st->codecpar->block_align) { av_log(s, AV_LOG_ERROR, "No iLBC mode set\n"); return AVERROR(EINVAL); } diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c index d22cc1d215..6be0a25d2b 100644 --- a/libavformat/rtpdec_latm.c +++ b/libavformat/rtpdec_latm.c @@ -115,16 +115,16 @@ static int parse_fmtp_config(AVStream *st, const char *value) ret = AVERROR_PATCHWELCOME; goto end; } - av_freep(&st->codec->extradata); - st->codec->extradata_size = (get_bits_left(&gb) + 7)/8; - st->codec->extradata = av_mallocz(st->codec->extradata_size + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) { + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = (get_bits_left(&gb) + 7)/8; + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) { ret = AVERROR(ENOMEM); goto end; } - for (i = 0; i < st->codec->extradata_size; i++) - st->codec->extradata[i] = get_bits(&gb, 8); + for (i = 0; i < st->codecpar->extradata_size; i++) + st->codecpar->extradata[i] = get_bits(&gb, 8); end: av_free(config); diff --git a/libavformat/rtpdec_mpeg12.c b/libavformat/rtpdec_mpeg12.c index 2b884be75a..89ecd3042d 100644 --- a/libavformat/rtpdec_mpeg12.c +++ b/libavformat/rtpdec_mpeg12.c @@ -34,7 +34,7 @@ static int mpeg_parse_packet(AVFormatContext *ctx, PayloadContext *data, h = AV_RB32(buf); buf += 4; len -= 4; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && h & (1 << 26)) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && h & (1 << 26)) { /* MPEG-2 */ if (len <= 4) return AVERROR_INVALIDDATA; diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index a8c9943537..58bcdff786 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -97,16 +97,16 @@ static void close_context(PayloadContext *data) av_free(data->mode); } -static int parse_fmtp_config(AVCodecContext *codec, const char *value) +static int parse_fmtp_config(AVCodecParameters *par, char *value) { /* decode the hexa encoded parameter */ int len = ff_hex_to_data(NULL, value); - av_free(codec->extradata); - codec->extradata = av_mallocz(len + AV_INPUT_BUFFER_PADDING_SIZE); - if (!codec->extradata) + av_free(par->extradata); + par->extradata = av_mallocz(len + AV_INPUT_BUFFER_PADDING_SIZE); + if (!par->extradata) return AVERROR(ENOMEM); - codec->extradata_size = len; - ff_hex_to_data(codec->extradata, value); + par->extradata_size = len; + ff_hex_to_data(par->extradata, value); return 0; } @@ -275,17 +275,17 @@ static int parse_fmtp(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *attr, const char *value) { - AVCodecContext *codec = stream->codec; + AVCodecParameters *par = stream->codecpar; int res, i; if (!strcmp(attr, "config")) { - res = parse_fmtp_config(codec, value); + res = parse_fmtp_config(par, value); if (res < 0) return res; } - if (codec->codec_id == AV_CODEC_ID_AAC) { + if (par->codec_id == AV_CODEC_ID_AAC) { /* Looking for a known attribute */ for (i = 0; attr_names[i].str; ++i) { if (!av_strcasecmp(attr, attr_names[i].str)) { diff --git a/libavformat/rtpdec_qdm2.c b/libavformat/rtpdec_qdm2.c index 16dd48920e..9a77a705bf 100644 --- a/libavformat/rtpdec_qdm2.c +++ b/libavformat/rtpdec_qdm2.c @@ -102,20 +102,20 @@ static int qdm2_parse_config(PayloadContext *qdm, AVStream *st, case 4: /* stream with extradata */ if (item_len < 30) return AVERROR_INVALIDDATA; - av_freep(&st->codec->extradata); - st->codec->extradata_size = 26 + item_len; - if (!(st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE))) { - st->codec->extradata_size = 0; + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 26 + item_len; + if (!(st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE))) { + st->codecpar->extradata_size = 0; return AVERROR(ENOMEM); } - AV_WB32(st->codec->extradata, 12); - memcpy(st->codec->extradata + 4, "frma", 4); - memcpy(st->codec->extradata + 8, "QDM2", 4); - AV_WB32(st->codec->extradata + 12, 6 + item_len); - memcpy(st->codec->extradata + 16, "QDCA", 4); - memcpy(st->codec->extradata + 20, p + 2, item_len - 2); - AV_WB32(st->codec->extradata + 18 + item_len, 8); - AV_WB32(st->codec->extradata + 22 + item_len, 0); + AV_WB32(st->codecpar->extradata, 12); + memcpy(st->codecpar->extradata + 4, "frma", 4); + memcpy(st->codecpar->extradata + 8, "QDM2", 4); + AV_WB32(st->codecpar->extradata + 12, 6 + item_len); + memcpy(st->codecpar->extradata + 16, "QDCA", 4); + memcpy(st->codecpar->extradata + 20, p + 2, item_len - 2); + AV_WB32(st->codecpar->extradata + 18 + item_len, 8); + AV_WB32(st->codecpar->extradata + 22 + item_len, 0); qdm->block_size = AV_RB32(p + 26); break; @@ -265,9 +265,9 @@ static int qdm2_parse_packet(AVFormatContext *s, PayloadContext *qdm, * carried within the RTP stream, not SDP. Here, * by setting codec_id to AV_CODEC_ID_QDM2, we are signalling * to the decoder that it is OK to initialize. */ - st->codec->codec_id = AV_CODEC_ID_QDM2; + st->codecpar->codec_id = AV_CODEC_ID_QDM2; } - if (st->codec->codec_id == AV_CODEC_ID_NONE) + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) return AVERROR(EAGAIN); /* subpackets */ diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c index f87e8affc9..9566c3d311 100644 --- a/libavformat/rtpdec_qt.c +++ b/libavformat/rtpdec_qt.c @@ -106,9 +106,9 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, avio_seek(&pb, pos + 4, SEEK_SET); tag = avio_rl32(&pb); - if ((st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && tag != MKTAG('v','i','d','e')) || - (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && + (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && tag != MKTAG('s','o','u','n'))) return AVERROR_INVALIDDATA; avpriv_set_pts_info(st, 32, 1, avio_rb32(&pb)); diff --git a/libavformat/rtpdec_svq3.c b/libavformat/rtpdec_svq3.c index 004696fa54..267d9dbcfe 100644 --- a/libavformat/rtpdec_svq3.c +++ b/libavformat/rtpdec_svq3.c @@ -58,24 +58,24 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv, if (config_packet) { - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; - if (len < 2 || !(st->codec->extradata = + if (len < 2 || !(st->codecpar->extradata = av_malloc(len + 8 + AV_INPUT_BUFFER_PADDING_SIZE))) return AVERROR_INVALIDDATA; - st->codec->extradata_size = len + 8; - memcpy(st->codec->extradata, "SEQH", 4); - AV_WB32(st->codec->extradata + 4, len); - memcpy(st->codec->extradata + 8, buf, len); + st->codecpar->extradata_size = len + 8; + memcpy(st->codecpar->extradata, "SEQH", 4); + AV_WB32(st->codecpar->extradata + 4, len); + memcpy(st->codecpar->extradata + 8, buf, len); /* We set codec_id to AV_CODEC_ID_NONE initially to * delay decoder initialization since extradata is * carried within the RTP stream, not SDP. Here, * by setting codec_id to AV_CODEC_ID_SVQ3, we are signalling * to the decoder that it is OK to initialize. */ - st->codec->codec_id = AV_CODEC_ID_SVQ3; + st->codecpar->codec_id = AV_CODEC_ID_SVQ3; return AVERROR(EAGAIN); } diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c index c79cfeb7b5..5ad6974703 100644 --- a/libavformat/rtpdec_xiph.c +++ b/libavformat/rtpdec_xiph.c @@ -222,16 +222,17 @@ static int get_base128(const uint8_t ** buf, const uint8_t * buf_end) * Based off parse_packed_headers in Vorbis RTP */ static int -parse_packed_headers(const uint8_t * packed_headers, +parse_packed_headers(AVFormatContext *s, + const uint8_t * packed_headers, const uint8_t * packed_headers_end, - AVCodecContext * codec, PayloadContext * xiph_data) + AVCodecParameters *par, PayloadContext * xiph_data) { unsigned num_packed, num_headers, length, length1, length2, extradata_alloc; uint8_t *ptr; if (packed_headers_end - packed_headers < 9) { - av_log(codec, AV_LOG_ERROR, + av_log(s, AV_LOG_ERROR, "Invalid %td byte packed header.", packed_headers_end - packed_headers); return AVERROR_INVALIDDATA; @@ -245,7 +246,7 @@ parse_packed_headers(const uint8_t * packed_headers, length2 = get_base128(&packed_headers, packed_headers_end); if (num_packed != 1 || num_headers > 3) { - av_log(codec, AV_LOG_ERROR, + av_log(s, AV_LOG_ERROR, "Unimplemented number of headers: %d packed headers, %d headers\n", num_packed, num_headers); return AVERROR_PATCHWELCOME; @@ -253,7 +254,7 @@ parse_packed_headers(const uint8_t * packed_headers, if (packed_headers_end - packed_headers != length || length1 > length || length2 > length - length1) { - av_log(codec, AV_LOG_ERROR, + av_log(s, AV_LOG_ERROR, "Bad packed header lengths (%d,%d,%td,%d)\n", length1, length2, packed_headers_end - packed_headers, length); return AVERROR_INVALIDDATA; @@ -265,9 +266,9 @@ parse_packed_headers(const uint8_t * packed_headers, * -- AV_INPUT_BUFFER_PADDING_SIZE required */ extradata_alloc = length + length/255 + 3 + AV_INPUT_BUFFER_PADDING_SIZE; - ptr = codec->extradata = av_malloc(extradata_alloc); + ptr = par->extradata = av_malloc(extradata_alloc); if (!ptr) { - av_log(codec, AV_LOG_ERROR, "Out of memory\n"); + av_log(s, AV_LOG_ERROR, "Out of memory\n"); return AVERROR(ENOMEM); } *ptr++ = 2; @@ -275,9 +276,9 @@ parse_packed_headers(const uint8_t * packed_headers, ptr += av_xiphlacing(ptr, length2); memcpy(ptr, packed_headers, length); ptr += length; - codec->extradata_size = ptr - codec->extradata; + par->extradata_size = ptr - par->extradata; // clear out remaining parts of the buffer - memset(ptr, 0, extradata_alloc - codec->extradata_size); + memset(ptr, 0, extradata_alloc - par->extradata_size); return 0; } @@ -287,16 +288,16 @@ static int xiph_parse_fmtp_pair(AVFormatContext *s, PayloadContext *xiph_data, const char *attr, const char *value) { - AVCodecContext *codec = stream->codec; + AVCodecParameters *par = stream->codecpar; int result = 0; if (!strcmp(attr, "sampling")) { if (!strcmp(value, "YCbCr-4:2:0")) { - codec->pix_fmt = AV_PIX_FMT_YUV420P; + par->format = AV_PIX_FMT_YUV420P; } else if (!strcmp(value, "YCbCr-4:4:2")) { - codec->pix_fmt = AV_PIX_FMT_YUV422P; + par->format = AV_PIX_FMT_YUV422P; } else if (!strcmp(value, "YCbCr-4:4:4")) { - codec->pix_fmt = AV_PIX_FMT_YUV444P; + par->format = AV_PIX_FMT_YUV444P; } else { av_log(s, AV_LOG_ERROR, "Unsupported pixel format %s\n", attr); @@ -305,12 +306,12 @@ static int xiph_parse_fmtp_pair(AVFormatContext *s, } else if (!strcmp(attr, "width")) { /* This is an integer between 1 and 1048561 * and MUST be in multiples of 16. */ - codec->width = atoi(value); + par->width = atoi(value); return 0; } else if (!strcmp(attr, "height")) { /* This is an integer between 1 and 1048561 * and MUST be in multiples of 16. */ - codec->height = atoi(value); + par->height = atoi(value); return 0; } else if (!strcmp(attr, "delivery-method")) { /* Possible values are: inline, in_band, out_band/specific_name. */ @@ -334,7 +335,7 @@ static int xiph_parse_fmtp_pair(AVFormatContext *s, av_base64_decode(decoded_packet, value, decoded_alloc); result = parse_packed_headers - (decoded_packet, decoded_packet + packet_size, codec, + (s, decoded_packet, decoded_packet + packet_size, par, xiph_data); } else { av_log(s, AV_LOG_ERROR, diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c index 6158934900..c7733a6862 100644 --- a/libavformat/rtpenc.c +++ b/libavformat/rtpenc.c @@ -97,8 +97,8 @@ static int rtp_write_header(AVFormatContext *s1) return AVERROR(EINVAL); } st = s1->streams[0]; - if (!is_supported(st->codec->codec_id)) { - av_log(s1, AV_LOG_ERROR, "Unsupported codec %x\n", st->codec->codec_id); + if (!is_supported(st->codecpar->codec_id)) { + av_log(s1, AV_LOG_ERROR, "Unsupported codec %x\n", st->codecpar->codec_id); return -1; } @@ -106,7 +106,7 @@ static int rtp_write_header(AVFormatContext *s1) if (s->payload_type < 0) { /* Re-validate non-dynamic payload types */ if (st->id < RTP_PT_PRIVATE) - st->id = ff_rtp_get_payload_type(s1, st->codec, -1); + st->id = ff_rtp_get_payload_type(s1, st->codecpar, -1); s->payload_type = st->id; } else { @@ -149,13 +149,13 @@ static int rtp_write_header(AVFormatContext *s1) } s->max_payload_size = s1->packet_size - 12; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate); } else { avpriv_set_pts_info(st, 32, 1, 90000); } s->buf_ptr = s->buf; - switch(st->codec->codec_id) { + switch(st->codecpar->codec_id) { case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: s->buf_ptr = s->buf + 4; @@ -183,8 +183,8 @@ static int rtp_write_header(AVFormatContext *s1) break; case AV_CODEC_ID_H264: /* check for H.264 MP4 syntax */ - if (st->codec->extradata_size > 4 && st->codec->extradata[0] == 1) { - s->nal_length_size = (st->codec->extradata[4] & 0x03) + 1; + if (st->codecpar->extradata_size > 4 && st->codecpar->extradata[0] == 1) { + s->nal_length_size = (st->codecpar->extradata[4] & 0x03) + 1; } break; case AV_CODEC_ID_HEVC: @@ -192,8 +192,8 @@ static int rtp_write_header(AVFormatContext *s1) * things simple and similar to the avcC/H264 case above, instead * of trying to handle the pre-standardization versions (as in * libavcodec/hevc.c). */ - if (st->codec->extradata_size > 21 && st->codec->extradata[0] == 1) { - s->nal_length_size = (st->codec->extradata[21] & 0x03) + 1; + if (st->codecpar->extradata_size > 21 && st->codecpar->extradata[0] == 1) { + s->nal_length_size = (st->codecpar->extradata[21] & 0x03) + 1; } break; case AV_CODEC_ID_VORBIS: @@ -206,7 +206,7 @@ static int rtp_write_header(AVFormatContext *s1) avpriv_set_pts_info(st, 32, 1, 8000); break; case AV_CODEC_ID_OPUS: - if (st->codec->channels > 2) { + if (st->codecpar->channels > 2) { av_log(s1, AV_LOG_ERROR, "Multistream opus not supported in RTP\n"); goto fail; } @@ -216,16 +216,16 @@ static int rtp_write_header(AVFormatContext *s1) avpriv_set_pts_info(st, 32, 1, 48000); break; case AV_CODEC_ID_ILBC: - if (st->codec->block_align != 38 && st->codec->block_align != 50) { + if (st->codecpar->block_align != 38 && st->codecpar->block_align != 50) { av_log(s1, AV_LOG_ERROR, "Incorrect iLBC block size specified\n"); goto fail; } - s->max_frames_per_packet = s->max_payload_size / st->codec->block_align; + s->max_frames_per_packet = s->max_payload_size / st->codecpar->block_align; break; case AV_CODEC_ID_AMR_NB: case AV_CODEC_ID_AMR_WB: s->max_frames_per_packet = 50; - if (st->codec->codec_id == AV_CODEC_ID_AMR_NB) + if (st->codecpar->codec_id == AV_CODEC_ID_AMR_NB) n = 31; else n = 61; @@ -234,7 +234,7 @@ static int rtp_write_header(AVFormatContext *s1) av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n"); goto fail; } - if (st->codec->channels != 1) { + if (st->codecpar->channels != 1) { av_log(s1, AV_LOG_ERROR, "Only mono is supported\n"); goto fail; } @@ -454,8 +454,8 @@ static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size) { RTPMuxContext *s = s1->priv_data; AVStream *st = s1->streams[0]; - int frame_duration = av_get_audio_frame_duration(st->codec, 0); - int frame_size = st->codec->block_align; + int frame_duration = av_get_audio_frame_duration2(st->codecpar, 0); + int frame_size = st->codecpar->block_align; int frames = size / frame_size; while (frames > 0) { @@ -505,26 +505,26 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) } s->cur_timestamp = s->base_timestamp + pkt->pts; - switch(st->codec->codec_id) { + switch(st->codecpar->codec_id) { case AV_CODEC_ID_PCM_MULAW: case AV_CODEC_ID_PCM_ALAW: case AV_CODEC_ID_PCM_U8: case AV_CODEC_ID_PCM_S8: - return rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); + return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels); case AV_CODEC_ID_PCM_U16BE: case AV_CODEC_ID_PCM_U16LE: case AV_CODEC_ID_PCM_S16BE: case AV_CODEC_ID_PCM_S16LE: - return rtp_send_samples(s1, pkt->data, size, 16 * st->codec->channels); + return rtp_send_samples(s1, pkt->data, size, 16 * st->codecpar->channels); case AV_CODEC_ID_ADPCM_G722: /* The actual sample size is half a byte per sample, but since the * stream clock rate is 8000 Hz while the sample rate is 16000 Hz, * the correct parameter for send_samples_bits is 8 bits per stream * clock. */ - return rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); + return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels); case AV_CODEC_ID_ADPCM_G726: return rtp_send_samples(s1, pkt->data, size, - st->codec->bits_per_coded_sample * st->codec->channels); + st->codecpar->bits_per_coded_sample * st->codecpar->channels); case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: rtp_send_mpegaudio(s1, pkt->data, size); diff --git a/libavformat/rtpenc_aac.c b/libavformat/rtpenc_aac.c index d0b4ca0964..ee01b040e7 100644 --- a/libavformat/rtpenc_aac.c +++ b/libavformat/rtpenc_aac.c @@ -33,7 +33,7 @@ void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size) uint8_t *p; /* skip ADTS header, if present */ - if ((s1->streams[0]->codec->extradata_size) == 0) { + if ((s1->streams[0]->codecpar->extradata_size) == 0) { size -= 7; buff += 7; } diff --git a/libavformat/rtpenc_chain.c b/libavformat/rtpenc_chain.c index e58eb545b8..7b061308b8 100644 --- a/libavformat/rtpenc_chain.c +++ b/libavformat/rtpenc_chain.c @@ -62,7 +62,7 @@ int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s, /* Get the payload type from the codec */ if (st->id < RTP_PT_PRIVATE) rtpctx->streams[0]->id = - ff_rtp_get_payload_type(s, st->codec, idx); + ff_rtp_get_payload_type(s, st->codecpar, idx); else rtpctx->streams[0]->id = st->id; @@ -72,7 +72,7 @@ int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s, /* Set the synchronized start time. */ rtpctx->start_time_realtime = s->start_time_realtime; - avcodec_copy_context(rtpctx->streams[0]->codec, st->codec); + avcodec_parameters_copy(rtpctx->streams[0]->codecpar, st->codecpar); rtpctx->streams[0]->time_base = st->time_base; if (handle) { diff --git a/libavformat/rtpenc_h264_hevc.c b/libavformat/rtpenc_h264_hevc.c index 9cfe0e2c64..9f329a6459 100644 --- a/libavformat/rtpenc_h264_hevc.c +++ b/libavformat/rtpenc_h264_hevc.c @@ -40,7 +40,7 @@ static void flush_buffered(AVFormatContext *s1, int last) // If we're only sending one single NAL unit, send it as such, skip // the STAP-A/AP framing if (s->buffered_nals == 1) { - enum AVCodecID codec = s1->streams[0]->codec->codec_id; + enum AVCodecID codec = s1->streams[0]->codecpar->codec_id; if (codec == AV_CODEC_ID_H264) ff_rtp_send_data(s1, s->buf + 3, s->buf_ptr - s->buf - 3, last); else @@ -55,7 +55,7 @@ static void flush_buffered(AVFormatContext *s1, int last) static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last) { RTPMuxContext *s = s1->priv_data; - enum AVCodecID codec = s1->streams[0]->codec->codec_id; + enum AVCodecID codec = s1->streams[0]->codecpar->codec_id; av_log(s1, AV_LOG_DEBUG, "Sending NAL %x of len %d M=%d\n", buf[0] & 0x1F, size, last); if (size <= s->max_payload_size) { diff --git a/libavformat/rtpenc_jpeg.c b/libavformat/rtpenc_jpeg.c index b8c880aadf..00ff9744b1 100644 --- a/libavformat/rtpenc_jpeg.c +++ b/libavformat/rtpenc_jpeg.c @@ -40,17 +40,17 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size) s->timestamp = s->cur_timestamp; /* convert video pixel dimensions from pixels to blocks */ - w = (s1->streams[0]->codec->width + 7) >> 3; - h = (s1->streams[0]->codec->height + 7) >> 3; + w = (s1->streams[0]->codecpar->width + 7) >> 3; + h = (s1->streams[0]->codecpar->height + 7) >> 3; /* get the pixel format type or fail */ - if (s1->streams[0]->codec->pix_fmt == AV_PIX_FMT_YUVJ422P || - (s1->streams[0]->codec->color_range == AVCOL_RANGE_JPEG && - s1->streams[0]->codec->pix_fmt == AV_PIX_FMT_YUV422P)) { + if (s1->streams[0]->codecpar->format == AV_PIX_FMT_YUVJ422P || + (s1->streams[0]->codecpar->color_range == AVCOL_RANGE_JPEG && + s1->streams[0]->codecpar->format == AV_PIX_FMT_YUV422P)) { type = 0; - } else if (s1->streams[0]->codec->pix_fmt == AV_PIX_FMT_YUVJ420P || - (s1->streams[0]->codec->color_range == AVCOL_RANGE_JPEG && - s1->streams[0]->codec->pix_fmt == AV_PIX_FMT_YUV420P)) { + } else if (s1->streams[0]->codecpar->format == AV_PIX_FMT_YUVJ420P || + (s1->streams[0]->codecpar->color_range == AVCOL_RANGE_JPEG && + s1->streams[0]->codecpar->format == AV_PIX_FMT_YUV420P)) { type = 1; } else { av_log(s1, AV_LOG_ERROR, "Unsupported pixel format\n"); diff --git a/libavformat/rtpenc_latm.c b/libavformat/rtpenc_latm.c index 64676771a7..d07dd523a6 100644 --- a/libavformat/rtpenc_latm.c +++ b/libavformat/rtpenc_latm.c @@ -34,7 +34,7 @@ void ff_rtp_send_latm(AVFormatContext *s1, const uint8_t *buff, int size) int len = 0; /* skip ADTS header, if present */ - if ((s1->streams[0]->codec->extradata_size) == 0) { + if ((s1->streams[0]->codecpar->extradata_size) == 0) { size -= 7; buff += 7; } diff --git a/libavformat/rtpenc_mpegts.c b/libavformat/rtpenc_mpegts.c index 585d1adc6d..d93a26a209 100644 --- a/libavformat/rtpenc_mpegts.c +++ b/libavformat/rtpenc_mpegts.c @@ -66,7 +66,7 @@ static int rtp_mpegts_write_header(AVFormatContext *s) goto fail; st->time_base = s->streams[i]->time_base; st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; - avcodec_copy_context(st->codec, s->streams[i]->codec); + avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); } if ((ret = avio_open_dyn_buf(&mpegts_ctx->pb)) < 0) goto fail; @@ -87,7 +87,7 @@ static int rtp_mpegts_write_header(AVFormatContext *s) st = avformat_new_stream(rtp_ctx, NULL); st->time_base.num = 1; st->time_base.den = 90000; - st->codec->codec_id = AV_CODEC_ID_MPEG2TS; + st->codecpar->codec_id = AV_CODEC_ID_MPEG2TS; rtp_ctx->pb = s->pb; if ((ret = avformat_write_header(rtp_ctx, NULL)) < 0) goto fail; diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index f1e0780b47..dc07422349 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -200,11 +200,11 @@ static int get_sockaddr(AVFormatContext *s, static void init_rtp_handler(RTPDynamicProtocolHandler *handler, RTSPStream *rtsp_st, AVStream *st) { - AVCodecContext *codec = st ? st->codec : NULL; + AVCodecParameters *par = st ? st->codecpar : NULL; if (!handler) return; - if (codec) - codec->codec_id = handler->codec_id; + if (par) + par->codec_id = handler->codec_id; rtsp_st->dynamic_handler = handler; if (st) st->need_parsing = handler->need_parsing; @@ -239,7 +239,7 @@ static int sdp_parse_rtpmap(AVFormatContext *s, AVStream *st, RTSPStream *rtsp_st, int payload_type, const char *p) { - AVCodecContext *codec = st->codec; + AVCodecParameters *par = st->codecpar; char buf[256]; int i; AVCodec *c; @@ -253,22 +253,22 @@ static int sdp_parse_rtpmap(AVFormatContext *s, if (payload_type < RTP_PT_PRIVATE) { /* We are in a standard case * (from http://www.iana.org/assignments/rtp-parameters). */ - codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type); + par->codec_id = ff_rtp_codec_id(buf, par->codec_type); } - if (codec->codec_id == AV_CODEC_ID_NONE) { + if (par->codec_id == AV_CODEC_ID_NONE) { RTPDynamicProtocolHandler *handler = - ff_rtp_handler_find_by_name(buf, codec->codec_type); + ff_rtp_handler_find_by_name(buf, par->codec_type); init_rtp_handler(handler, rtsp_st, st); /* If no dynamic handler was found, check with the list of standard * allocated types, if such a stream for some reason happens to * use a private payload type. This isn't handled in rtpdec.c, since * the format name from the rtpmap line never is passed into rtpdec. */ if (!rtsp_st->dynamic_handler) - codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type); + par->codec_id = ff_rtp_codec_id(buf, par->codec_type); } - c = avcodec_find_decoder(codec->codec_id); + c = avcodec_find_decoder(par->codec_id); if (c && c->name) c_name = c->name; else @@ -276,23 +276,23 @@ static int sdp_parse_rtpmap(AVFormatContext *s, get_word_sep(buf, sizeof(buf), "/", &p); i = atoi(buf); - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: av_log(s, AV_LOG_DEBUG, "audio codec set to: %s\n", c_name); - codec->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE; - codec->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS; + par->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE; + par->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS; if (i > 0) { - codec->sample_rate = i; - avpriv_set_pts_info(st, 32, 1, codec->sample_rate); + par->sample_rate = i; + avpriv_set_pts_info(st, 32, 1, par->sample_rate); get_word_sep(buf, sizeof(buf), "/", &p); i = atoi(buf); if (i > 0) - codec->channels = i; + par->channels = i; } av_log(s, AV_LOG_DEBUG, "audio samplerate set to: %i\n", - codec->sample_rate); + par->sample_rate); av_log(s, AV_LOG_DEBUG, "audio channels set to: %i\n", - codec->channels); + par->channels); break; case AVMEDIA_TYPE_VIDEO: av_log(s, AV_LOG_DEBUG, "video codec set to: %s\n", c_name); @@ -495,17 +495,17 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, return; st->id = rt->nb_rtsp_streams - 1; rtsp_st->stream_index = st->index; - st->codec->codec_type = codec_type; + st->codecpar->codec_type = codec_type; if (rtsp_st->sdp_payload_type < RTP_PT_PRIVATE) { RTPDynamicProtocolHandler *handler; /* if standard payload type, we can find the codec right now */ - ff_rtp_get_codec_info(st->codec, rtsp_st->sdp_payload_type); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - st->codec->sample_rate > 0) - avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + ff_rtp_get_codec_info(st->codecpar, rtsp_st->sdp_payload_type); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + st->codecpar->sample_rate > 0) + avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate); /* Even static payload types may need a custom depacketizer */ handler = ff_rtp_handler_find_by_id( - rtsp_st->sdp_payload_type, st->codec->codec_type); + rtsp_st->sdp_payload_type, st->codecpar->codec_type); init_rtp_handler(handler, rtsp_st, st); finalize_rtp_handler_init(s, rtsp_st, st); } @@ -590,7 +590,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, } else if (av_strstart(p, "SampleRate:integer;", &p) && s->nb_streams > 0) { st = s->streams[s->nb_streams - 1]; - st->codec->sample_rate = atoi(p); + st->codecpar->sample_rate = atoi(p); } else if (av_strstart(p, "crypto:", &p) && s->nb_streams > 0) { // RFC 4568 rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1]; @@ -1499,7 +1499,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, * will return an error. Therefore, we skip those streams. */ if (rt->server_type == RTSP_SERVER_WMS && (rtsp_st->stream_index < 0 || - s->streams[rtsp_st->stream_index]->codec->codec_type == + s->streams[rtsp_st->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_DATA)) continue; snprintf(transport, sizeof(transport) - 1, @@ -2371,7 +2371,7 @@ static int rtp_read_header(AVFormatContext *s) int ret, port; URLContext* in = NULL; int payload_type; - AVCodecContext codec = { 0 }; + AVCodecParameters *par = NULL; struct sockaddr_storage addr; AVIOContext pb; socklen_t addrlen = sizeof(addr); @@ -2419,13 +2419,19 @@ static int rtp_read_header(AVFormatContext *s) ffurl_close(in); in = NULL; - if (ff_rtp_get_codec_info(&codec, payload_type)) { + par = avcodec_parameters_alloc(); + if (!par) { + ret = AVERROR(ENOMEM); + goto fail; + } + + if (ff_rtp_get_codec_info(par, payload_type)) { av_log(s, AV_LOG_ERROR, "Unable to receive RTP payload type %d " "without an SDP file describing it\n", payload_type); goto fail; } - if (codec.codec_type != AVMEDIA_TYPE_DATA) { + if (par->codec_type != AVMEDIA_TYPE_DATA) { av_log(s, AV_LOG_WARNING, "Guessing on RTP content - if not received " "properly you need an SDP file " "describing it\n"); @@ -2437,10 +2443,11 @@ static int rtp_read_header(AVFormatContext *s) snprintf(sdp, sizeof(sdp), "v=0\r\nc=IN IP%d %s\r\nm=%s %d RTP/AVP %d\r\n", addr.ss_family == AF_INET ? 4 : 6, host, - codec.codec_type == AVMEDIA_TYPE_DATA ? "application" : - codec.codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio", + par->codec_type == AVMEDIA_TYPE_DATA ? "application" : + par->codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio", port, payload_type); av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sdp); + avcodec_parameters_free(&par); ffio_init_context(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL); s->pb = &pb; @@ -2455,6 +2462,7 @@ static int rtp_read_header(AVFormatContext *s) return ret; fail: + avcodec_parameters_free(&par); if (in) ffurl_close(in); ff_network_close(); diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c index fc85f65735..0e99ace614 100644 --- a/libavformat/sapdec.c +++ b/libavformat/sapdec.c @@ -180,7 +180,7 @@ static int sap_read_header(AVFormatContext *s) goto fail; } st->id = i; - avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec); + avcodec_parameters_copy(st->codecpar, sap->sdp_ctx->streams[i]->codecpar); st->time_base = sap->sdp_ctx->streams[i]->time_base; } @@ -229,7 +229,7 @@ static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(ENOMEM); } st->id = i; - avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec); + avcodec_parameters_copy(st->codecpar, sap->sdp_ctx->streams[i]->codecpar); st->time_base = sap->sdp_ctx->streams[i]->time_base; } } diff --git a/libavformat/sauce.c b/libavformat/sauce.c index a125241335..335c989253 100644 --- a/libavformat/sauce.c +++ b/libavformat/sauce.c @@ -65,18 +65,18 @@ int ff_sauce_read(AVFormatContext *avctx, uint64_t *fsize, int *got_width, int g if (got_width && datatype && filetype) { if ((datatype == 1 && filetype <=2) || (datatype == 5 && filetype == 255) || datatype == 6) { if (t1) { - avctx->streams[0]->codec->width = t1<<3; + avctx->streams[0]->codecpar->width = t1<<3; *got_width = 1; } if (get_height && t2) - avctx->streams[0]->codec->height = t2<<4; + avctx->streams[0]->codecpar->height = t2<<4; } else if (datatype == 5) { if (filetype > 1) { - avctx->streams[0]->codec->width = (filetype == 1 ? t1 : filetype) << 4; + avctx->streams[0]->codecpar->width = (filetype == 1 ? t1 : filetype) << 4; *got_width = 1; } if (get_height && t2) - avctx->streams[0]->codec->height = t2<<4; + avctx->streams[0]->codecpar->height = t2<<4; } } diff --git a/libavformat/sdp.c b/libavformat/sdp.c index fe43e04361..d21ffacabc 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -151,24 +151,24 @@ static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url) } #define MAX_PSET_SIZE 1024 -static char *extradata2psets(AVCodecContext *c) +static char *extradata2psets(AVFormatContext *s, AVCodecParameters *par) { char *psets, *p; const uint8_t *r; static const char pset_string[] = "; sprop-parameter-sets="; static const char profile_string[] = "; profile-level-id="; - uint8_t *extradata = c->extradata; - int extradata_size = c->extradata_size; + uint8_t *extradata = par->extradata; + int extradata_size = par->extradata_size; uint8_t *tmpbuf = NULL; const uint8_t *sps = NULL, *sps_end; - if (c->extradata_size > MAX_EXTRADATA_SIZE) { - av_log(c, AV_LOG_ERROR, "Too much extradata!\n"); + if (par->extradata_size > MAX_EXTRADATA_SIZE) { + av_log(s, AV_LOG_ERROR, "Too much extradata!\n"); return NULL; } - if (c->extradata[0] == 1) { - if (ff_avc_write_annexb_extradata(c->extradata, &extradata, + if (par->extradata[0] == 1) { + if (ff_avc_write_annexb_extradata(par->extradata, &extradata, &extradata_size)) return NULL; tmpbuf = extradata; @@ -176,7 +176,7 @@ static char *extradata2psets(AVCodecContext *c) psets = av_mallocz(MAX_PSET_SIZE); if (!psets) { - av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the parameter sets.\n"); + av_log(s, AV_LOG_ERROR, "Cannot allocate memory for the parameter sets.\n"); av_free(tmpbuf); return NULL; } @@ -203,7 +203,7 @@ static char *extradata2psets(AVCodecContext *c) sps_end = r1; } if (!av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - r)) { - av_log(c, AV_LOG_ERROR, "Cannot Base64-encode %td %td!\n", MAX_PSET_SIZE - (p - psets), r1 - r); + av_log(s, AV_LOG_ERROR, "Cannot Base64-encode %td %td!\n", MAX_PSET_SIZE - (p - psets), r1 - r); av_free(psets); av_free(tmpbuf); @@ -223,11 +223,11 @@ static char *extradata2psets(AVCodecContext *c) return psets; } -static char *extradata2psets_hevc(AVCodecContext *c) +static char *extradata2psets_hevc(AVCodecParameters *par) { char *psets; - uint8_t *extradata = c->extradata; - int extradata_size = c->extradata_size; + uint8_t *extradata = par->extradata; + int extradata_size = par->extradata_size; uint8_t *tmpbuf = NULL; int ps_pos[3] = { 0 }; static const char * const ps_names[3] = { "vps", "sps", "pps" }; @@ -238,11 +238,11 @@ static char *extradata2psets_hevc(AVCodecContext *c) // the same type, and we might need to convert from one format to the // other anyway, we get away with a little less work by using the hvcc // format. - if (c->extradata[0] != 1) { + if (par->extradata[0] != 1) { AVIOContext *pb; if (avio_open_dyn_buf(&pb) < 0) return NULL; - if (ff_isom_write_hvcc(pb, c->extradata, c->extradata_size, 0) < 0) { + if (ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0) < 0) { avio_close_dyn_buf(pb, &tmpbuf); goto err; } @@ -324,35 +324,35 @@ err: return NULL; } -static char *extradata2config(AVCodecContext *c) +static char *extradata2config(AVFormatContext *s, AVCodecParameters *par) { char *config; - if (c->extradata_size > MAX_EXTRADATA_SIZE) { - av_log(c, AV_LOG_ERROR, "Too much extradata!\n"); + if (par->extradata_size > MAX_EXTRADATA_SIZE) { + av_log(s, AV_LOG_ERROR, "Too much extradata!\n"); return NULL; } - config = av_malloc(10 + c->extradata_size * 2); + config = av_malloc(10 + par->extradata_size * 2); if (!config) { - av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the config info.\n"); + av_log(s, AV_LOG_ERROR, "Cannot allocate memory for the config info.\n"); return NULL; } memcpy(config, "; config=", 9); - ff_data_to_hex(config + 9, c->extradata, c->extradata_size, 0); - config[9 + c->extradata_size * 2] = 0; + ff_data_to_hex(config + 9, par->extradata, par->extradata_size, 0); + config[9 + par->extradata_size * 2] = 0; return config; } -static char *xiph_extradata2config(AVCodecContext *c) +static char *xiph_extradata2config(AVFormatContext *s, AVCodecParameters *par) { char *config, *encoded_config; uint8_t *header_start[3]; int headers_len, header_len[3], config_len; int first_header_size; - switch (c->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_THEORA: first_header_size = 42; break; @@ -360,14 +360,14 @@ static char *xiph_extradata2config(AVCodecContext *c) first_header_size = 30; break; default: - av_log(c, AV_LOG_ERROR, "Unsupported Xiph codec ID\n"); + av_log(s, AV_LOG_ERROR, "Unsupported Xiph codec ID\n"); return NULL; } - if (avpriv_split_xiph_headers(c->extradata, c->extradata_size, + if (avpriv_split_xiph_headers(par->extradata, par->extradata_size, first_header_size, header_start, header_len) < 0) { - av_log(c, AV_LOG_ERROR, "Extradata corrupt.\n"); + av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); return NULL; } @@ -409,12 +409,12 @@ static char *xiph_extradata2config(AVCodecContext *c) return encoded_config; xiph_fail: - av_log(c, AV_LOG_ERROR, + av_log(s, AV_LOG_ERROR, "Not enough memory for configuration string\n"); return NULL; } -static int latm_context2profilelevel(AVCodecContext *c) +static int latm_context2profilelevel(AVCodecParameters *par) { /* MP4A-LATM * The RTP payload format specification is described in RFC 3016 @@ -425,17 +425,17 @@ static int latm_context2profilelevel(AVCodecContext *c) /* TODO: AAC Profile only supports AAC LC Object Type. * Different Object Types should implement different Profile Levels */ - if (c->sample_rate <= 24000) { - if (c->channels <= 2) + if (par->sample_rate <= 24000) { + if (par->channels <= 2) profile_level = 0x28; // AAC Profile, Level 1 - } else if (c->sample_rate <= 48000) { - if (c->channels <= 2) { + } else if (par->sample_rate <= 48000) { + if (par->channels <= 2) { profile_level = 0x29; // AAC Profile, Level 2 - } else if (c->channels <= 5) { + } else if (par->channels <= 5) { profile_level = 0x2A; // AAC Profile, Level 4 } - } else if (c->sample_rate <= 96000) { - if (c->channels <= 5) { + } else if (par->sample_rate <= 96000) { + if (par->channels <= 5) { profile_level = 0x2B; // AAC Profile, Level 5 } } @@ -443,7 +443,7 @@ static int latm_context2profilelevel(AVCodecContext *c) return profile_level; } -static char *latm_context2config(AVCodecContext *c) +static char *latm_context2config(AVFormatContext *s, AVCodecParameters *par) { /* MP4A-LATM * The RTP payload format specification is described in RFC 3016 @@ -454,23 +454,23 @@ static char *latm_context2config(AVCodecContext *c) char *config; for (rate_index = 0; rate_index < 16; rate_index++) - if (avpriv_mpeg4audio_sample_rates[rate_index] == c->sample_rate) + if (avpriv_mpeg4audio_sample_rates[rate_index] == par->sample_rate) break; if (rate_index == 16) { - av_log(c, AV_LOG_ERROR, "Unsupported sample rate\n"); + av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n"); return NULL; } config_byte[0] = 0x40; config_byte[1] = 0; config_byte[2] = 0x20 | rate_index; - config_byte[3] = c->channels << 4; + config_byte[3] = par->channels << 4; config_byte[4] = 0x3f; config_byte[5] = 0xc0; config = av_malloc(6*2+1); if (!config) { - av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the config info.\n"); + av_log(s, AV_LOG_ERROR, "Cannot allocate memory for the config info.\n"); return NULL; } ff_data_to_hex(config, config_byte, 6, 1); @@ -479,18 +479,18 @@ static char *latm_context2config(AVCodecContext *c) return config; } -static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, int payload_type, AVFormatContext *fmt) +static char *sdp_write_media_attributes(char *buff, int size, AVCodecParameters *p, int payload_type, AVFormatContext *fmt) { char *config = NULL; - switch (c->codec_id) { + switch (p->codec_id) { case AV_CODEC_ID_H264: { int mode = 1; if (fmt && fmt->oformat && fmt->oformat->priv_class && av_opt_flag_is_set(fmt->priv_data, "rtpflags", "h264_mode0")) mode = 0; - if (c->extradata_size) { - config = extradata2psets(c); + if (p->extradata_size) { + config = extradata2psets(fmt, p); } av_strlcatf(buff, size, "a=rtpmap:%d H264/90000\r\n" "a=fmtp:%d packetization-mode=%d%s\r\n", @@ -502,9 +502,9 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, { const char *pic_fmt = NULL; /* only QCIF and CIF are specified as supported in RFC 4587 */ - if (c->width == 176 && c->height == 144) + if (p->width == 176 && p->height == 144) pic_fmt = "QCIF=1"; - else if (c->width == 352 && c->height == 288) + else if (p->width == 352 && p->height == 288) pic_fmt = "CIF=1"; if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d H261/90000\r\n", payload_type); @@ -520,23 +520,23 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, * stagefright and on Samsung bada. */ if (!fmt || !fmt->oformat->priv_class || !av_opt_flag_is_set(fmt->priv_data, "rtpflags", "rfc2190") || - c->codec_id == AV_CODEC_ID_H263P) + p->codec_id == AV_CODEC_ID_H263P) av_strlcatf(buff, size, "a=rtpmap:%d H263-2000/90000\r\n" "a=framesize:%d %d-%d\r\n", payload_type, - payload_type, c->width, c->height); + payload_type, p->width, p->height); break; case AV_CODEC_ID_HEVC: - if (c->extradata_size) - config = extradata2psets_hevc(c); + if (p->extradata_size) + config = extradata2psets_hevc(p); av_strlcatf(buff, size, "a=rtpmap:%d H265/90000\r\n", payload_type); if (config) av_strlcatf(buff, size, "a=fmtp:%d %s\r\n", payload_type, config); break; case AV_CODEC_ID_MPEG4: - if (c->extradata_size) { - config = extradata2config(c); + if (p->extradata_size) { + config = extradata2config(fmt, p); } av_strlcatf(buff, size, "a=rtpmap:%d MP4V-ES/90000\r\n" "a=fmtp:%d profile-level-id=1%s\r\n", @@ -546,21 +546,21 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, case AV_CODEC_ID_AAC: if (fmt && fmt->oformat->priv_class && av_opt_flag_is_set(fmt->priv_data, "rtpflags", "latm")) { - config = latm_context2config(c); + config = latm_context2config(fmt, p); if (!config) return NULL; av_strlcatf(buff, size, "a=rtpmap:%d MP4A-LATM/%d/%d\r\n" "a=fmtp:%d profile-level-id=%d;cpresent=0;config=%s\r\n", - payload_type, c->sample_rate, c->channels, - payload_type, latm_context2profilelevel(c), config); + payload_type, p->sample_rate, p->channels, + payload_type, latm_context2profilelevel(p), config); } else { - if (c->extradata_size) { - config = extradata2config(c); + if (p->extradata_size) { + config = extradata2config(fmt, p); } else { /* FIXME: maybe we can forge config information based on the * codec parameters... */ - av_log(c, AV_LOG_ERROR, "AAC with no global headers is currently not supported.\n"); + av_log(fmt, AV_LOG_ERROR, "AAC with no global headers is currently not supported.\n"); return NULL; } if (!config) { @@ -570,7 +570,7 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, "a=fmtp:%d profile-level-id=1;" "mode=AAC-hbr;sizelength=13;indexlength=3;" "indexdeltalength=3%s\r\n", - payload_type, c->sample_rate, c->channels, + payload_type, p->sample_rate, p->channels, payload_type, config); } break; @@ -578,48 +578,48 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d L16/%d/%d\r\n", payload_type, - c->sample_rate, c->channels); + p->sample_rate, p->channels); break; case AV_CODEC_ID_PCM_MULAW: if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d PCMU/%d/%d\r\n", payload_type, - c->sample_rate, c->channels); + p->sample_rate, p->channels); break; case AV_CODEC_ID_PCM_ALAW: if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d PCMA/%d/%d\r\n", payload_type, - c->sample_rate, c->channels); + p->sample_rate, p->channels); break; case AV_CODEC_ID_AMR_NB: av_strlcatf(buff, size, "a=rtpmap:%d AMR/%d/%d\r\n" "a=fmtp:%d octet-align=1\r\n", - payload_type, c->sample_rate, c->channels, + payload_type, p->sample_rate, p->channels, payload_type); break; case AV_CODEC_ID_AMR_WB: av_strlcatf(buff, size, "a=rtpmap:%d AMR-WB/%d/%d\r\n" "a=fmtp:%d octet-align=1\r\n", - payload_type, c->sample_rate, c->channels, + payload_type, p->sample_rate, p->channels, payload_type); break; case AV_CODEC_ID_VORBIS: - if (c->extradata_size) - config = xiph_extradata2config(c); + if (p->extradata_size) + config = xiph_extradata2config(fmt, p); else - av_log(c, AV_LOG_ERROR, "Vorbis configuration info missing\n"); + av_log(fmt, AV_LOG_ERROR, "Vorbis configuration info missing\n"); if (!config) return NULL; av_strlcatf(buff, size, "a=rtpmap:%d vorbis/%d/%d\r\n" "a=fmtp:%d configuration=%s\r\n", - payload_type, c->sample_rate, c->channels, + payload_type, p->sample_rate, p->channels, payload_type, config); break; case AV_CODEC_ID_THEORA: { const char *pix_fmt; - switch (c->pix_fmt) { + switch (p->format) { case AV_PIX_FMT_YUV420P: pix_fmt = "YCbCr-4:2:0"; break; @@ -630,14 +630,14 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, pix_fmt = "YCbCr-4:4:4"; break; default: - av_log(c, AV_LOG_ERROR, "Unsupported pixel format.\n"); + av_log(fmt, AV_LOG_ERROR, "Unsupported pixel format.\n"); return NULL; } - if (c->extradata_size) - config = xiph_extradata2config(c); + if (p->extradata_size) + config = xiph_extradata2config(fmt, p); else - av_log(c, AV_LOG_ERROR, "Theora configuation info missing\n"); + av_log(fmt, AV_LOG_ERROR, "Theora configuation info missing\n"); if (!config) return NULL; @@ -646,7 +646,7 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, "width=%d; height=%d; sampling=%s; " "configuration=%s\r\n", payload_type, payload_type, - c->width, c->height, pix_fmt, config); + p->width, p->height, pix_fmt, config); break; } case AV_CODEC_ID_VP8: @@ -662,25 +662,25 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d G722/%d/%d\r\n", payload_type, - 8000, c->channels); + 8000, p->channels); break; case AV_CODEC_ID_ADPCM_G726: { if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d G726-%d/%d\r\n", payload_type, - c->bits_per_coded_sample*8, - c->sample_rate); + p->bits_per_coded_sample*8, + p->sample_rate); break; } case AV_CODEC_ID_ILBC: av_strlcatf(buff, size, "a=rtpmap:%d iLBC/%d\r\n" "a=fmtp:%d mode=%d\r\n", - payload_type, c->sample_rate, - payload_type, c->block_align == 38 ? 20 : 30); + payload_type, p->sample_rate, + payload_type, p->block_align == 38 ? 20 : 30); break; case AV_CODEC_ID_SPEEX: av_strlcatf(buff, size, "a=rtpmap:%d speex/%d\r\n", - payload_type, c->sample_rate); + payload_type, p->sample_rate); break; case AV_CODEC_ID_OPUS: /* The opus RTP draft says that all opus streams MUST be declared @@ -691,7 +691,7 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, receivers MUST be able to receive and process stereo packets. */ av_strlcatf(buff, size, "a=rtpmap:%d opus/48000/2\r\n", payload_type); - if (c->channels == 2) { + if (p->channels == 2) { av_strlcatf(buff, size, "a=fmtp:%d sprop-stereo:1\r\n", payload_type); } @@ -710,13 +710,13 @@ void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, const char *dest_addr, const char *dest_type, int port, int ttl, AVFormatContext *fmt) { - AVCodecContext *c = st->codec; + AVCodecParameters *p = st->codecpar; const char *type; int payload_type; - payload_type = ff_rtp_get_payload_type(fmt, c, idx); + payload_type = ff_rtp_get_payload_type(fmt, st->codecpar, idx); - switch (c->codec_type) { + switch (p->codec_type) { case AVMEDIA_TYPE_VIDEO : type = "video" ; break; case AVMEDIA_TYPE_AUDIO : type = "audio" ; break; case AVMEDIA_TYPE_SUBTITLE: type = "text" ; break; @@ -725,11 +725,11 @@ void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, av_strlcatf(buff, size, "m=%s %d RTP/AVP %d\r\n", type, port, payload_type); sdp_write_address(buff, size, dest_addr, dest_type, ttl); - if (c->bit_rate) { - av_strlcatf(buff, size, "b=AS:%d\r\n", c->bit_rate / 1000); + if (p->bit_rate) { + av_strlcatf(buff, size, "b=AS:%d\r\n", p->bit_rate / 1000); } - sdp_write_media_attributes(buff, size, c, payload_type, fmt); + sdp_write_media_attributes(buff, size, p, payload_type, fmt); } int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size) diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c index 5516019d77..f74c3c0fad 100644 --- a/libavformat/segafilm.c +++ b/libavformat/segafilm.c @@ -151,15 +151,15 @@ static int film_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); film->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = film->video_type; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = AV_RB32(&scratch[16]); - st->codec->height = AV_RB32(&scratch[12]); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = film->video_type; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = AV_RB32(&scratch[16]); + st->codecpar->height = AV_RB32(&scratch[12]); if (film->video_type == AV_CODEC_ID_RAWVIDEO) { if (scratch[20] == 24) { - st->codec->pix_fmt = AV_PIX_FMT_RGB24; + st->codecpar->format = AV_PIX_FMT_RGB24; } else { av_log(s, AV_LOG_ERROR, "raw video is using unhandled %dbpp\n", scratch[20]); return -1; @@ -172,24 +172,24 @@ static int film_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); film->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = film->audio_type; - st->codec->codec_tag = 1; - st->codec->channels = film->audio_channels; - st->codec->sample_rate = film->audio_samplerate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = film->audio_type; + st->codecpar->codec_tag = 1; + st->codecpar->channels = film->audio_channels; + st->codecpar->sample_rate = film->audio_samplerate; if (film->audio_type == AV_CODEC_ID_ADPCM_ADX) { - st->codec->bits_per_coded_sample = 18 * 8 / 32; - st->codec->block_align = st->codec->channels * 18; + st->codecpar->bits_per_coded_sample = 18 * 8 / 32; + st->codecpar->block_align = st->codecpar->channels * 18; st->need_parsing = AVSTREAM_PARSE_FULL; } else { - st->codec->bits_per_coded_sample = film->audio_bits; - st->codec->block_align = st->codec->channels * - st->codec->bits_per_coded_sample / 8; + st->codecpar->bits_per_coded_sample = film->audio_bits; + st->codecpar->block_align = st->codecpar->channels * + st->codecpar->bits_per_coded_sample / 8; } - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * - st->codec->bits_per_coded_sample; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; } /* load the sample table */ @@ -207,7 +207,7 @@ static int film_read_header(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) avpriv_set_pts_info(st, 33, 1, film->base_clock); else avpriv_set_pts_info(st, 64, 1, film->audio_samplerate); diff --git a/libavformat/segment.c b/libavformat/segment.c index 58e285911a..fd68a9f753 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -75,7 +75,7 @@ static int segment_mux_init(AVFormatContext *s) AVStream *st; if (!(st = avformat_new_stream(oc, NULL))) return AVERROR(ENOMEM); - avcodec_copy_context(st->codec, s->streams[i]->codec); + avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; } @@ -215,7 +215,7 @@ static int seg_write_header(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) seg->has_video += - (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO); + (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO); if (seg->has_video > 1) av_log(s, AV_LOG_WARNING, @@ -293,7 +293,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EINVAL); if (seg->has_video) { - can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->flags & AV_PKT_FLAG_KEY; } diff --git a/libavformat/sierravmd.c b/libavformat/sierravmd.c index 9be07cbdfa..36b98f5032 100644 --- a/libavformat/sierravmd.c +++ b/libavformat/sierravmd.c @@ -110,18 +110,18 @@ static int vmd_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(vst, 33, 1, 10); vmd->video_stream_index = vst->index; - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = vmd->is_indeo3 ? AV_CODEC_ID_INDEO3 : AV_CODEC_ID_VMDVIDEO; - vst->codec->codec_tag = 0; /* no fourcc */ - vst->codec->width = AV_RL16(&vmd->vmd_header[12]); - vst->codec->height = AV_RL16(&vmd->vmd_header[14]); - if(vmd->is_indeo3 && vst->codec->width > 320){ - vst->codec->width >>= 1; - vst->codec->height >>= 1; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = vmd->is_indeo3 ? AV_CODEC_ID_INDEO3 : AV_CODEC_ID_VMDVIDEO; + vst->codecpar->codec_tag = 0; /* no fourcc */ + vst->codecpar->width = AV_RL16(&vmd->vmd_header[12]); + vst->codecpar->height = AV_RL16(&vmd->vmd_header[14]); + if(vmd->is_indeo3 && vst->codecpar->width > 320){ + vst->codecpar->width >>= 1; + vst->codecpar->height >>= 1; } - vst->codec->extradata_size = VMD_HEADER_SIZE; - vst->codec->extradata = av_mallocz(VMD_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); - memcpy(vst->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE); + vst->codecpar->extradata_size = VMD_HEADER_SIZE; + vst->codecpar->extradata = av_mallocz(VMD_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); + memcpy(vst->codecpar->extradata, vmd->vmd_header, VMD_HEADER_SIZE); /* if sample rate is 0, assume no audio */ vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]); @@ -130,30 +130,30 @@ static int vmd_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); vmd->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_VMDAUDIO; - st->codec->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_VMDAUDIO; + st->codecpar->codec_tag = 0; /* no fourcc */ if (vmd->vmd_header[811] & 0x80) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - st->codec->sample_rate = vmd->sample_rate; - st->codec->block_align = AV_RL16(&vmd->vmd_header[806]); - if (st->codec->block_align & 0x8000) { - st->codec->bits_per_coded_sample = 16; - st->codec->block_align = -(st->codec->block_align - 0x10000); + st->codecpar->sample_rate = vmd->sample_rate; + st->codecpar->block_align = AV_RL16(&vmd->vmd_header[806]); + if (st->codecpar->block_align & 0x8000) { + st->codecpar->bits_per_coded_sample = 16; + st->codecpar->block_align = -(st->codecpar->block_align - 0x10000); } else { - st->codec->bits_per_coded_sample = 8; + st->codecpar->bits_per_coded_sample = 8; } - st->codec->bit_rate = st->codec->sample_rate * - st->codec->bits_per_coded_sample * st->codec->channels; + st->codecpar->bit_rate = st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample * st->codecpar->channels; /* calculate pts */ - num = st->codec->block_align; - den = st->codec->sample_rate * st->codec->channels; + num = st->codecpar->block_align; + den = st->codecpar->sample_rate * st->codecpar->channels; av_reduce(&den, &num, den, num, (1UL<<31)-1); avpriv_set_pts_info(vst, 33, num, den); avpriv_set_pts_info(st, 33, num, den); diff --git a/libavformat/siff.c b/libavformat/siff.c index d97c8b018c..e11d5bd489 100644 --- a/libavformat/siff.c +++ b/libavformat/siff.c @@ -77,12 +77,12 @@ static int create_audio_stream(AVFormatContext *s, SIFFContext *c) ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_U8; - ast->codec->channels = 1; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; - ast->codec->bits_per_coded_sample = 8; - ast->codec->sample_rate = c->rate; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + ast->codecpar->channels = 1; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + ast->codecpar->bits_per_coded_sample = 8; + ast->codecpar->sample_rate = c->rate; avpriv_set_pts_info(ast, 16, 1, c->rate); ast->start_time = 0; return 0; @@ -122,12 +122,12 @@ static int siff_parse_vbv1(AVFormatContext *s, SIFFContext *c, AVIOContext *pb) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_VB; - st->codec->codec_tag = MKTAG('V', 'B', 'V', '1'); - st->codec->width = width; - st->codec->height = height; - st->codec->pix_fmt = AV_PIX_FMT_PAL8; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_VB; + st->codecpar->codec_tag = MKTAG('V', 'B', 'V', '1'); + st->codecpar->width = width; + st->codecpar->height = height; + st->codecpar->format = AV_PIX_FMT_PAL8; avpriv_set_pts_info(st, 16, 1, 12); c->cur_frame = 0; diff --git a/libavformat/smacker.c b/libavformat/smacker.c index b1d8e95f5c..eb4b63fdad 100644 --- a/libavformat/smacker.c +++ b/libavformat/smacker.c @@ -162,12 +162,12 @@ static int smacker_read_header(AVFormatContext *s) if (!st) return -1; smk->videoindex = st->index; - st->codec->width = smk->width; - st->codec->height = smk->height; - st->codec->pix_fmt = AV_PIX_FMT_PAL8; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_SMACKVIDEO; - st->codec->codec_tag = smk->magic; + st->codecpar->width = smk->width; + st->codecpar->height = smk->height; + st->codecpar->format = AV_PIX_FMT_PAL8; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_SMACKVIDEO; + st->codecpar->codec_tag = smk->magic; /* Smacker uses 100000 as internal timebase */ if(smk->pts_inc < 0) smk->pts_inc = -smk->pts_inc; @@ -183,39 +183,39 @@ static int smacker_read_header(AVFormatContext *s) if (smk->rates[i]) { ast[i] = avformat_new_stream(s, NULL); smk->indexes[i] = ast[i]->index; - ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if (smk->aflags[i] & SMK_AUD_BINKAUD) { - ast[i]->codec->codec_id = AV_CODEC_ID_BINKAUDIO_RDFT; + ast[i]->codecpar->codec_id = AV_CODEC_ID_BINKAUDIO_RDFT; } else if (smk->aflags[i] & SMK_AUD_USEDCT) { - ast[i]->codec->codec_id = AV_CODEC_ID_BINKAUDIO_DCT; + ast[i]->codecpar->codec_id = AV_CODEC_ID_BINKAUDIO_DCT; } else if (smk->aflags[i] & SMK_AUD_PACKED){ - ast[i]->codec->codec_id = AV_CODEC_ID_SMACKAUDIO; - ast[i]->codec->codec_tag = MKTAG('S', 'M', 'K', 'A'); + ast[i]->codecpar->codec_id = AV_CODEC_ID_SMACKAUDIO; + ast[i]->codecpar->codec_tag = MKTAG('S', 'M', 'K', 'A'); } else { - ast[i]->codec->codec_id = AV_CODEC_ID_PCM_U8; + ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_U8; } if (smk->aflags[i] & SMK_AUD_STEREO) { - ast[i]->codec->channels = 2; - ast[i]->codec->channel_layout = AV_CH_LAYOUT_STEREO; + ast[i]->codecpar->channels = 2; + ast[i]->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - ast[i]->codec->channels = 1; - ast[i]->codec->channel_layout = AV_CH_LAYOUT_MONO; + ast[i]->codecpar->channels = 1; + ast[i]->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - ast[i]->codec->sample_rate = smk->rates[i]; - ast[i]->codec->bits_per_coded_sample = (smk->aflags[i] & SMK_AUD_16BITS) ? 16 : 8; - if(ast[i]->codec->bits_per_coded_sample == 16 && ast[i]->codec->codec_id == AV_CODEC_ID_PCM_U8) - ast[i]->codec->codec_id = AV_CODEC_ID_PCM_S16LE; - avpriv_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate - * ast[i]->codec->channels * ast[i]->codec->bits_per_coded_sample / 8); + ast[i]->codecpar->sample_rate = smk->rates[i]; + ast[i]->codecpar->bits_per_coded_sample = (smk->aflags[i] & SMK_AUD_16BITS) ? 16 : 8; + if(ast[i]->codecpar->bits_per_coded_sample == 16 && ast[i]->codecpar->codec_id == AV_CODEC_ID_PCM_U8) + ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; + avpriv_set_pts_info(ast[i], 64, 1, ast[i]->codecpar->sample_rate + * ast[i]->codecpar->channels * ast[i]->codecpar->bits_per_coded_sample / 8); } } /* load trees to extradata, they will be unpacked by decoder */ - st->codec->extradata = av_mallocz(smk->treesize + 16 + - AV_INPUT_BUFFER_PADDING_SIZE); - st->codec->extradata_size = smk->treesize + 16; - if(!st->codec->extradata){ + st->codecpar->extradata = av_mallocz(smk->treesize + 16 + + AV_INPUT_BUFFER_PADDING_SIZE); + st->codecpar->extradata_size = smk->treesize + 16; + if (!st->codecpar->extradata) { av_log(s, AV_LOG_ERROR, "Cannot allocate %"PRIu32" bytes of extradata\n", smk->treesize + 16); @@ -223,16 +223,16 @@ static int smacker_read_header(AVFormatContext *s) av_free(smk->frm_flags); return -1; } - ret = avio_read(pb, st->codec->extradata + 16, st->codec->extradata_size - 16); - if(ret != st->codec->extradata_size - 16){ + ret = avio_read(pb, st->codecpar->extradata + 16, st->codecpar->extradata_size - 16); + if(ret != st->codecpar->extradata_size - 16){ av_free(smk->frm_size); av_free(smk->frm_flags); return AVERROR(EIO); } - ((int32_t*)st->codec->extradata)[0] = av_le2ne32(smk->mmap_size); - ((int32_t*)st->codec->extradata)[1] = av_le2ne32(smk->mclr_size); - ((int32_t*)st->codec->extradata)[2] = av_le2ne32(smk->full_size); - ((int32_t*)st->codec->extradata)[3] = av_le2ne32(smk->type_size); + ((int32_t*)st->codecpar->extradata)[0] = av_le2ne32(smk->mmap_size); + ((int32_t*)st->codecpar->extradata)[1] = av_le2ne32(smk->mclr_size); + ((int32_t*)st->codecpar->extradata)[2] = av_le2ne32(smk->full_size); + ((int32_t*)st->codecpar->extradata)[3] = av_le2ne32(smk->type_size); smk->curstream = -1; smk->nextpos = avio_tell(pb); diff --git a/libavformat/smjpegdec.c b/libavformat/smjpegdec.c index a9ed28e261..bc69c89e2b 100644 --- a/libavformat/smjpegdec.c +++ b/libavformat/smjpegdec.c @@ -88,13 +88,13 @@ static int smjpeg_read_header(AVFormatContext *s) ast = avformat_new_stream(s, 0); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->sample_rate = avio_rb16(pb); - ast->codec->bits_per_coded_sample = avio_r8(pb); - ast->codec->channels = avio_r8(pb); - ast->codec->codec_tag = avio_rl32(pb); - ast->codec->codec_id = ff_codec_get_id(ff_codec_smjpeg_audio_tags, - ast->codec->codec_tag); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->sample_rate = avio_rb16(pb); + ast->codecpar->bits_per_coded_sample = avio_r8(pb); + ast->codecpar->channels = avio_r8(pb); + ast->codecpar->codec_tag = avio_rl32(pb); + ast->codecpar->codec_id = ff_codec_get_id(ff_codec_smjpeg_audio_tags, + ast->codecpar->codec_tag); ast->duration = duration; sc->audio_stream_index = ast->index; avpriv_set_pts_info(ast, 32, 1, 1000); @@ -112,12 +112,12 @@ static int smjpeg_read_header(AVFormatContext *s) vst = avformat_new_stream(s, 0); if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->width = avio_rb16(pb); - vst->codec->height = avio_rb16(pb); - vst->codec->codec_tag = avio_rl32(pb); - vst->codec->codec_id = ff_codec_get_id(ff_codec_smjpeg_video_tags, - vst->codec->codec_tag); + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->width = avio_rb16(pb); + vst->codecpar->height = avio_rb16(pb); + vst->codecpar->codec_tag = avio_rl32(pb); + vst->codecpar->codec_id = ff_codec_get_id(ff_codec_smjpeg_video_tags, + vst->codecpar->codec_tag); vst->duration = duration; sc->video_stream_index = vst->index; avpriv_set_pts_info(vst, 32, 1, 1000); diff --git a/libavformat/smjpegenc.c b/libavformat/smjpegenc.c index 551af8911d..2a9505947f 100644 --- a/libavformat/smjpegenc.c +++ b/libavformat/smjpegenc.c @@ -56,22 +56,22 @@ static int smjpeg_write_header(AVFormatContext *s) for (n = 0; n < s->nb_streams; n++) { AVStream *st = s->streams[n]; - AVCodecContext *codec = st->codec; - if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { - tag = ff_codec_get_tag(ff_codec_smjpeg_audio_tags, codec->codec_id); + AVCodecParameters *par = st->codecpar; + if (par->codec_type == AVMEDIA_TYPE_AUDIO) { + tag = ff_codec_get_tag(ff_codec_smjpeg_audio_tags, par->codec_id); if (!tag) { av_log(s, AV_LOG_ERROR, "unsupported audio codec\n"); return AVERROR(EINVAL); } avio_wl32(pb, SMJPEG_SND); avio_wb32(pb, 8); - avio_wb16(pb, codec->sample_rate); - avio_w8(pb, av_get_bits_per_sample(codec->codec_id)); - avio_w8(pb, codec->channels); + avio_wb16(pb, par->sample_rate); + avio_w8(pb, av_get_bits_per_sample(par->codec_id)); + avio_w8(pb, par->channels); avio_wl32(pb, tag); avpriv_set_pts_info(st, 32, 1, 1000); - } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { - tag = ff_codec_get_tag(ff_codec_smjpeg_video_tags, codec->codec_id); + } else if (par->codec_type == AVMEDIA_TYPE_VIDEO) { + tag = ff_codec_get_tag(ff_codec_smjpeg_video_tags, par->codec_id); if (!tag) { av_log(s, AV_LOG_ERROR, "unsupported video codec\n"); return AVERROR(EINVAL); @@ -79,8 +79,8 @@ static int smjpeg_write_header(AVFormatContext *s) avio_wl32(pb, SMJPEG_VID); avio_wb32(pb, 12); avio_wb32(pb, 0); - avio_wb16(pb, codec->width); - avio_wb16(pb, codec->height); + avio_wb16(pb, par->width); + avio_wb16(pb, par->height); avio_wl32(pb, tag); avpriv_set_pts_info(st, 32, 1, 1000); } @@ -97,11 +97,11 @@ static int smjpeg_write_packet(AVFormatContext *s, AVPacket *pkt) SMJPEGMuxContext *smc = s->priv_data; AVIOContext *pb = s->pb; AVStream *st = s->streams[pkt->stream_index]; - AVCodecContext *codec = st->codec; + AVCodecParameters *par = st->codecpar; - if (codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (par->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl32(pb, SMJPEG_SNDD); - else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) + else if (par->codec_type == AVMEDIA_TYPE_VIDEO) avio_wl32(pb, SMJPEG_VIDD); else return 0; diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c index 1dbae7013d..8eba9c9a45 100644 --- a/libavformat/smoothstreamingenc.c +++ b/libavformat/smoothstreamingenc.c @@ -149,14 +149,14 @@ static int64_t ism_seek(void *opaque, int64_t offset, int whence) static void get_private_data(OutputStream *os) { - AVCodecContext *codec = os->ctx->streams[0]->codec; - uint8_t *ptr = codec->extradata; - int size = codec->extradata_size; + AVCodecParameters *par = os->ctx->streams[0]->codecpar; + uint8_t *ptr = par->extradata; + int size = par->extradata_size; int i; - if (codec->codec_id == AV_CODEC_ID_H264) { + if (par->codec_id == AV_CODEC_ID_H264) { ff_avc_write_annexb_extradata(ptr, &ptr, &size); if (!ptr) - ptr = codec->extradata; + ptr = par->extradata; } if (!ptr) return; @@ -166,7 +166,7 @@ static void get_private_data(OutputStream *os) for (i = 0; i < size; i++) snprintf(&os->private_str[2*i], 3, "%02x", ptr[i]); fail: - if (ptr != codec->extradata) + if (ptr != par->extradata) av_free(ptr); } @@ -241,7 +241,7 @@ static int write_manifest(AVFormatContext *s, int final) Fragment *last = os->fragments[os->nb_fragments - 1]; duration = last->start_time + last->duration; } - if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { video_chunks = os->nb_fragments; video_streams++; } else { @@ -266,10 +266,10 @@ static int write_manifest(AVFormatContext *s, int final) avio_printf(out, "<StreamIndex Type=\"video\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n", video_streams, video_chunks); for (i = 0; i < s->nb_streams; i++) { OutputStream *os = &c->streams[i]; - if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_VIDEO) + if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) continue; last = i; - avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%d\" FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->width, s->streams[i]->codec->height, os->private_str); + avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%d\" FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codecpar->bit_rate, os->fourcc, s->streams[i]->codecpar->width, s->streams[i]->codecpar->height, os->private_str); index++; } output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size); @@ -280,10 +280,10 @@ static int write_manifest(AVFormatContext *s, int final) avio_printf(out, "<StreamIndex Type=\"audio\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n", audio_streams, audio_chunks); for (i = 0; i < s->nb_streams; i++) { OutputStream *os = &c->streams[i]; - if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_AUDIO) + if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) continue; last = i; - avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%d\" FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" BitsPerSample=\"16\" PacketSize=\"%d\" AudioTag=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->sample_rate, s->streams[i]->codec->channels, os->packet_size, os->audio_tag, os->private_str); + avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%d\" FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" BitsPerSample=\"16\" PacketSize=\"%d\" AudioTag=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codecpar->bit_rate, os->fourcc, s->streams[i]->codecpar->sample_rate, s->streams[i]->codecpar->channels, os->packet_size, os->audio_tag, os->private_str); index++; } output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size); @@ -331,12 +331,12 @@ static int ism_write_header(AVFormatContext *s) AVDictionary *opts = NULL; char buf[10]; - if (!s->streams[i]->codec->bit_rate) { + if (!s->streams[i]->codecpar->bit_rate) { av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i); ret = AVERROR(EINVAL); goto fail; } - snprintf(os->dirname, sizeof(os->dirname), "%s/QualityLevels(%d)", s->filename, s->streams[i]->codec->bit_rate); + snprintf(os->dirname, sizeof(os->dirname), "%s/QualityLevels(%d)", s->filename, s->streams[i]->codecpar->bit_rate); if (mkdir(os->dirname, 0777) == -1 && errno != EEXIST) { ret = AVERROR(errno); goto fail; @@ -357,7 +357,7 @@ static int ism_write_header(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } - avcodec_copy_context(st->codec, s->streams[i]->codec); + avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; @@ -377,12 +377,12 @@ static int ism_write_header(AVFormatContext *s) avio_flush(ctx->pb); av_dict_free(&opts); s->streams[i]->time_base = st->time_base; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { c->has_video = 1; os->stream_type_tag = "video"; - if (st->codec->codec_id == AV_CODEC_ID_H264) { + if (st->codecpar->codec_id == AV_CODEC_ID_H264) { os->fourcc = "H264"; - } else if (st->codec->codec_id == AV_CODEC_ID_VC1) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_VC1) { os->fourcc = "WVC1"; } else { av_log(s, AV_LOG_ERROR, "Unsupported video codec\n"); @@ -392,10 +392,10 @@ static int ism_write_header(AVFormatContext *s) } else { c->has_audio = 1; os->stream_type_tag = "audio"; - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { os->fourcc = "AACL"; os->audio_tag = 0xff; - } else if (st->codec->codec_id == AV_CODEC_ID_WMAPRO) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_WMAPRO) { os->fourcc = "WMAP"; os->audio_tag = 0x0162; } else { @@ -403,7 +403,7 @@ static int ism_write_header(AVFormatContext *s) ret = AVERROR(EINVAL); goto fail; } - os->packet_size = st->codec->block_align ? st->codec->block_align : 4; + os->packet_size = st->codecpar->block_align ? st->codecpar->block_align : 4; } get_private_data(os); } @@ -603,7 +603,7 @@ static int ism_write_packet(AVFormatContext *s, AVPacket *pkt) if (st->first_dts == AV_NOPTS_VALUE) st->first_dts = pkt->dts; - if ((!c->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && + if ((!c->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && av_compare_ts(pkt->dts - st->first_dts, st->time_base, end_dts, AV_TIME_BASE_Q) >= 0 && pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) { diff --git a/libavformat/smush.c b/libavformat/smush.c index 94ecb5cb17..262b941241 100644 --- a/libavformat/smush.c +++ b/libavformat/smush.c @@ -151,23 +151,23 @@ static int smush_read_header(AVFormatContext *ctx) vst->duration = vst->nb_frames = nframes; vst->avg_frame_rate = av_inv_q(vst->time_base); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_SANM; - vst->codec->codec_tag = 0; - vst->codec->width = width; - vst->codec->height = height; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_SANM; + vst->codecpar->codec_tag = 0; + vst->codecpar->width = width; + vst->codecpar->height = height; if (!smush->version) { - av_free(vst->codec->extradata); - vst->codec->extradata_size = 1024 + 2; - vst->codec->extradata = av_malloc(vst->codec->extradata_size + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!vst->codec->extradata) + av_free(vst->codecpar->extradata); + vst->codecpar->extradata_size = 1024 + 2; + vst->codecpar->extradata = av_malloc(vst->codecpar->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!vst->codecpar->extradata) return AVERROR(ENOMEM); - AV_WL16(vst->codec->extradata, subversion); + AV_WL16(vst->codecpar->extradata, subversion); for (i = 0; i < 256; i++) - AV_WL32(vst->codec->extradata + 2 + i * 4, palette[i]); + AV_WL32(vst->codecpar->extradata + 2 + i * 4, palette[i]); } if (got_audio) { @@ -178,13 +178,13 @@ static int smush_read_header(AVFormatContext *ctx) smush->audio_stream_index = ast->index; ast->start_time = 0; - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_ADPCM_VIMA; - ast->codec->codec_tag = 0; - ast->codec->sample_rate = sample_rate; - ast->codec->channels = channels; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_ADPCM_VIMA; + ast->codecpar->codec_tag = 0; + ast->codecpar->sample_rate = sample_rate; + ast->codecpar->channels = channels; - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); } return 0; diff --git a/libavformat/sol.c b/libavformat/sol.c index 30f0547d1d..5c7f43da03 100644 --- a/libavformat/sol.c +++ b/libavformat/sol.c @@ -110,13 +110,13 @@ static int sol_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return -1; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = id; - st->codec->codec_id = codec; - st->codec->channels = channels; - st->codec->channel_layout = channels == 1 ? AV_CH_LAYOUT_MONO : - AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = id; + st->codecpar->codec_id = codec; + st->codecpar->channels = channels; + st->codecpar->channel_layout = channels == 1 ? AV_CH_LAYOUT_MONO : + AV_CH_LAYOUT_STEREO; + st->codecpar->sample_rate = rate; avpriv_set_pts_info(st, 64, 1, rate); return 0; } diff --git a/libavformat/soxdec.c b/libavformat/soxdec.c index ec94675830..ee3d1dc560 100644 --- a/libavformat/soxdec.c +++ b/libavformat/soxdec.c @@ -55,21 +55,21 @@ static int sox_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if (avio_rl32(pb) == SOX_TAG) { - st->codec->codec_id = AV_CODEC_ID_PCM_S32LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE; header_size = avio_rl32(pb); avio_skip(pb, 8); /* sample count */ sample_rate = av_int2double(avio_rl64(pb)); - st->codec->channels = avio_rl32(pb); + st->codecpar->channels = avio_rl32(pb); comment_size = avio_rl32(pb); } else { - st->codec->codec_id = AV_CODEC_ID_PCM_S32BE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE; header_size = avio_rb32(pb); avio_skip(pb, 8); /* sample count */ sample_rate = av_int2double(avio_rb64(pb)); - st->codec->channels = avio_rb32(pb); + st->codecpar->channels = avio_rb32(pb); comment_size = avio_rb32(pb); } @@ -90,7 +90,7 @@ static int sox_read_header(AVFormatContext *s) sample_rate_frac); if ((header_size + 4) & 7 || header_size < SOX_FIXED_HDR + comment_size - || st->codec->channels > 65535) /* Reserve top 16 bits */ { + || st->codecpar->channels > 65535) /* Reserve top 16 bits */ { av_log(s, AV_LOG_ERROR, "invalid header\n"); return -1; } @@ -109,15 +109,15 @@ static int sox_read_header(AVFormatContext *s) avio_skip(pb, header_size - SOX_FIXED_HDR - comment_size); - st->codec->sample_rate = sample_rate; - st->codec->bits_per_coded_sample = 32; - st->codec->bit_rate = st->codec->sample_rate * - st->codec->bits_per_coded_sample * - st->codec->channels; - st->codec->block_align = st->codec->bits_per_coded_sample * - st->codec->channels / 8; + st->codecpar->sample_rate = sample_rate; + st->codecpar->bits_per_coded_sample = 32; + st->codecpar->bit_rate = st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample * + st->codecpar->channels; + st->codecpar->block_align = st->codecpar->bits_per_coded_sample * + st->codecpar->channels / 8; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } @@ -132,7 +132,7 @@ static int sox_read_packet(AVFormatContext *s, if (s->pb->eof_reached) return AVERROR_EOF; - size = SOX_SAMPLES*s->streams[0]->codec->block_align; + size = SOX_SAMPLES*s->streams[0]->codecpar->block_align; ret = av_get_packet(s->pb, pkt, size); if (ret < 0) return AVERROR(EIO); diff --git a/libavformat/soxenc.c b/libavformat/soxenc.c index 17de1789a1..ea05f36892 100644 --- a/libavformat/soxenc.c +++ b/libavformat/soxenc.c @@ -44,7 +44,7 @@ static int sox_write_header(AVFormatContext *s) { SoXContext *sox = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; AVDictionaryEntry *comment; size_t comment_len = 0, comment_size; @@ -55,19 +55,19 @@ static int sox_write_header(AVFormatContext *s) sox->header_size = SOX_FIXED_HDR + comment_size; - if (enc->codec_id == AV_CODEC_ID_PCM_S32LE) { + if (par->codec_id == AV_CODEC_ID_PCM_S32LE) { ffio_wfourcc(pb, ".SoX"); avio_wl32(pb, sox->header_size); avio_wl64(pb, 0); /* number of samples */ - avio_wl64(pb, av_double2int(enc->sample_rate)); - avio_wl32(pb, enc->channels); + avio_wl64(pb, av_double2int(par->sample_rate)); + avio_wl32(pb, par->channels); avio_wl32(pb, comment_size); - } else if (enc->codec_id == AV_CODEC_ID_PCM_S32BE) { + } else if (par->codec_id == AV_CODEC_ID_PCM_S32BE) { ffio_wfourcc(pb, "XoS."); avio_wb32(pb, sox->header_size); avio_wb64(pb, 0); /* number of samples */ - avio_wb64(pb, av_double2int(enc->sample_rate)); - avio_wb32(pb, enc->channels); + avio_wb64(pb, av_double2int(par->sample_rate)); + avio_wb32(pb, par->channels); avio_wb32(pb, comment_size); } else { av_log(s, AV_LOG_ERROR, "invalid codec; use pcm_s32le or pcm_s32be\n"); @@ -96,14 +96,14 @@ static int sox_write_trailer(AVFormatContext *s) { SoXContext *sox = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; if (s->pb->seekable) { /* update number of samples */ int64_t file_size = avio_tell(pb); int64_t num_samples = (file_size - sox->header_size - 4LL) >> 2LL; avio_seek(pb, 8, SEEK_SET); - if (enc->codec_id == AV_CODEC_ID_PCM_S32LE) { + if (par->codec_id == AV_CODEC_ID_PCM_S32LE) { avio_wl64(pb, num_samples); } else avio_wb64(pb, num_samples); diff --git a/libavformat/spdifdec.c b/libavformat/spdifdec.c index a28adf8224..7c212353f1 100644 --- a/libavformat/spdifdec.c +++ b/libavformat/spdifdec.c @@ -210,17 +210,17 @@ static int spdif_read_packet(AVFormatContext *s, AVPacket *pkt) av_packet_unref(pkt); return AVERROR(ENOMEM); } - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = codec_id; - } else if (codec_id != s->streams[0]->codec->codec_id) { + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = codec_id; + } else if (codec_id != s->streams[0]->codecpar->codec_id) { avpriv_report_missing_feature(s, "Codec change in IEC 61937"); return AVERROR_PATCHWELCOME; } - if (!s->bit_rate && s->streams[0]->codec->sample_rate) + if (!s->bit_rate && s->streams[0]->codecpar->sample_rate) /* stream bitrate matches 16-bit stereo PCM bitrate for currently supported codecs */ - s->bit_rate = 2 * 16 * s->streams[0]->codec->sample_rate; + s->bit_rate = 2 * 16 * s->streams[0]->codecpar->sample_rate; return 0; } diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c index 7162f0827b..0e1f1d4c47 100644 --- a/libavformat/spdifenc.c +++ b/libavformat/spdifenc.c @@ -444,7 +444,7 @@ static int spdif_write_header(AVFormatContext *s) { IEC61937Context *ctx = s->priv_data; - switch (s->streams[0]->codec->codec_id) { + switch (s->streams[0]->codecpar->codec_id) { case AV_CODEC_ID_AC3: ctx->header_info = spdif_header_ac3; break; diff --git a/libavformat/srtdec.c b/libavformat/srtdec.c index 9db5133a21..6f8206c755 100644 --- a/libavformat/srtdec.c +++ b/libavformat/srtdec.c @@ -46,8 +46,8 @@ static int srt_read_header(AVFormatContext *s) if (!st) return -1; avpriv_set_pts_info(st, 64, 1, 1000); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_SRT; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_SRT; return 0; } diff --git a/libavformat/swf.h b/libavformat/swf.h index f18aa7cc58..93473e7dd7 100644 --- a/libavformat/swf.h +++ b/libavformat/swf.h @@ -81,7 +81,7 @@ typedef struct SWFContext { int frame_rate; int tag; AVFifoBuffer *audio_fifo; - AVCodecContext *audio_enc, *video_enc; + AVCodecParameters *audio_par, *video_par; AVStream *video_st; #if CONFIG_ZLIB #define ZBUF_SIZE 4096 diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c index 7b5cd358ba..7bb67de8d8 100644 --- a/libavformat/swfdec.c +++ b/libavformat/swfdec.c @@ -173,7 +173,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) for (i=0; i<s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->id == ch_id) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->id == ch_id) goto skip; } @@ -186,8 +186,8 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) if (!vst) return -1; vst->id = ch_id; - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = ff_codec_get_id(ff_swf_codec_tags, avio_r8(pb)); + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = ff_codec_get_id(ff_swf_codec_tags, avio_r8(pb)); avpriv_set_pts_info(vst, 16, 256, swf->frame_rate); len -= 8; } else if (tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) { @@ -196,7 +196,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) for (i=0; i<s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->id == -1) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->id == -1) goto skip; } @@ -208,25 +208,25 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) return -1; ast->id = -1; /* -1 to avoid clash with video stream ch_id */ if (v & 1) { - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - ast->codec->channels = 1; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; + ast->codecpar->channels = 1; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = ff_codec_get_id(swf_audio_codec_tags, (v>>4) & 15); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = ff_codec_get_id(swf_audio_codec_tags, (v>>4) & 15); ast->need_parsing = AVSTREAM_PARSE_FULL; sample_rate_code= (v>>2) & 3; - ast->codec->sample_rate = 44100 >> (3 - sample_rate_code); - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + ast->codecpar->sample_rate = 44100 >> (3 - sample_rate_code); + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); len -= 4; } else if (tag == TAG_VIDEOFRAME) { int ch_id = avio_rl16(pb); len -= 2; for(i=0; i<s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->id == ch_id) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->id == ch_id) { frame = avio_rl16(pb); len -= 2; if (len <= 0) @@ -242,8 +242,8 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) } else if (tag == TAG_STREAMBLOCK) { for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->id == -1) { - if (st->codec->codec_id == AV_CODEC_ID_MP3) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->id == -1) { + if (st->codecpar->codec_id == AV_CODEC_ID_MP3) { avio_skip(pb, 4); len -= 4; if (len <= 0) @@ -264,7 +264,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) } else if (tag == TAG_JPEG2) { for (i=0; i<s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_id == AV_CODEC_ID_MJPEG && st->id == -2) + if (st->codecpar->codec_id == AV_CODEC_ID_MJPEG && st->id == -2) break; } if (i == s->nb_streams) { @@ -272,8 +272,8 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) if (!vst) return -1; vst->id = -2; /* -2 to avoid clash with video stream and audio stream */ - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_MJPEG; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_MJPEG; avpriv_set_pts_info(vst, 64, 256, swf->frame_rate); st = vst; } diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c index 877c847acb..f8db3e9196 100644 --- a/libavformat/swfenc.c +++ b/libavformat/swfenc.c @@ -184,14 +184,14 @@ static int swf_write_header(AVFormatContext *s) swf->video_frame_number = 0; for(i=0;i<s->nb_streams;i++) { - AVCodecContext *enc = s->streams[i]->codec; - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { - if (swf->audio_enc) { + AVCodecParameters *par = s->streams[i]->codecpar; + if (par->codec_type == AVMEDIA_TYPE_AUDIO) { + if (swf->audio_par) { av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 audio stream\n"); return AVERROR_INVALIDDATA; } - if (enc->codec_id == AV_CODEC_ID_MP3) { - swf->audio_enc = enc; + if (par->codec_id == AV_CODEC_ID_MP3) { + swf->audio_par = par; swf->audio_fifo= av_fifo_alloc(AUDIO_FIFO_SIZE); if (!swf->audio_fifo) return AVERROR(ENOMEM); @@ -200,15 +200,15 @@ static int swf_write_header(AVFormatContext *s) return -1; } } else { - if (swf->video_enc) { + if (swf->video_par) { av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 video stream\n"); return AVERROR_INVALIDDATA; } - if (enc->codec_id == AV_CODEC_ID_VP6F || - enc->codec_id == AV_CODEC_ID_FLV1 || - enc->codec_id == AV_CODEC_ID_MJPEG) { + if (par->codec_id == AV_CODEC_ID_VP6F || + par->codec_id == AV_CODEC_ID_FLV1 || + par->codec_id == AV_CODEC_ID_MJPEG) { swf->video_st = s->streams[i]; - swf->video_enc = enc; + swf->video_par = par; } else { av_log(s, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV1 and MJPEG\n"); return -1; @@ -216,32 +216,32 @@ static int swf_write_header(AVFormatContext *s) } } - if (!swf->video_enc) { + if (!swf->video_par) { /* currently, cannot work correctly if audio only */ width = 320; height = 200; rate = 10; rate_base= 1; } else { - width = swf->video_enc->width; - height = swf->video_enc->height; + width = swf->video_par->width; + height = swf->video_par->height; // TODO: should be avg_frame_rate rate = swf->video_st->time_base.den; rate_base = swf->video_st->time_base.num; } - if (!swf->audio_enc) + if (!swf->audio_par) swf->samples_per_frame = (44100.0 * rate_base) / rate; else - swf->samples_per_frame = (swf->audio_enc->sample_rate * rate_base) / rate; + swf->samples_per_frame = (swf->audio_par->sample_rate * rate_base) / rate; avio_write(pb, "FWS", 3); if (!strcmp("avm2", s->oformat->name)) version = 9; - else if (swf->video_enc && swf->video_enc->codec_id == AV_CODEC_ID_VP6F) + else if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_VP6F) version = 8; /* version 8 and above support VP6 codec */ - else if (swf->video_enc && swf->video_enc->codec_id == AV_CODEC_ID_FLV1) + else if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_FLV1) version = 6; /* version 6 and above support FLV1 codec */ else version = 4; /* version 4 for mpeg audio support */ @@ -263,7 +263,7 @@ static int swf_write_header(AVFormatContext *s) } /* define a shape with the jpeg inside */ - if (swf->video_enc && swf->video_enc->codec_id == AV_CODEC_ID_MJPEG) { + if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_MJPEG) { put_swf_tag(s, TAG_DEFINESHAPE); avio_wl16(pb, SHAPE_ID); /* ID of shape */ @@ -306,12 +306,12 @@ static int swf_write_header(AVFormatContext *s) put_swf_end_tag(s); } - if (swf->audio_enc && swf->audio_enc->codec_id == AV_CODEC_ID_MP3) { + if (swf->audio_par && swf->audio_par->codec_id == AV_CODEC_ID_MP3) { int v = 0; /* start sound */ put_swf_tag(s, TAG_STREAMHEAD2); - switch(swf->audio_enc->sample_rate) { + switch(swf->audio_par->sample_rate) { case 11025: v |= 1 << 2; break; case 22050: v |= 2 << 2; break; case 44100: v |= 3 << 2; break; @@ -321,7 +321,7 @@ static int swf_write_header(AVFormatContext *s) return -1; } v |= 0x02; /* 16 bit playback */ - if (swf->audio_enc->channels == 2) + if (swf->audio_par->channels == 2) v |= 0x01; /* stereo playback */ avio_w8(s->pb, v); v |= 0x20; /* mp3 compressed */ @@ -337,27 +337,27 @@ static int swf_write_header(AVFormatContext *s) } static int swf_write_video(AVFormatContext *s, - AVCodecContext *enc, const uint8_t *buf, int size) + AVCodecParameters *par, const uint8_t *buf, int size) { SWFContext *swf = s->priv_data; AVIOContext *pb = s->pb; /* Flash Player limit */ if (swf->swf_frame_number == 16000) - av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n"); + av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n"); - if (enc->codec_id == AV_CODEC_ID_VP6F || - enc->codec_id == AV_CODEC_ID_FLV1) { + if (par->codec_id == AV_CODEC_ID_VP6F || + par->codec_id == AV_CODEC_ID_FLV1) { if (swf->video_frame_number == 0) { /* create a new video object */ put_swf_tag(s, TAG_VIDEOSTREAM); avio_wl16(pb, VIDEO_ID); swf->vframes_pos = avio_tell(pb); avio_wl16(pb, 15000); /* hard flash player limit */ - avio_wl16(pb, enc->width); - avio_wl16(pb, enc->height); + avio_wl16(pb, par->width); + avio_wl16(pb, par->height); avio_w8(pb, 0); - avio_w8(pb,ff_codec_get_tag(ff_swf_codec_tags, enc->codec_id)); + avio_w8(pb,ff_codec_get_tag(ff_swf_codec_tags, par->codec_id)); put_swf_end_tag(s); /* place the video object for the first time */ @@ -385,7 +385,7 @@ static int swf_write_video(AVFormatContext *s, avio_wl16(pb, swf->video_frame_number++); avio_write(pb, buf, size); put_swf_end_tag(s); - } else if (enc->codec_id == AV_CODEC_ID_MJPEG) { + } else if (par->codec_id == AV_CODEC_ID_MJPEG) { if (swf->swf_frame_number > 0) { /* remove the shape */ put_swf_tag(s, TAG_REMOVEOBJECT); @@ -422,7 +422,7 @@ static int swf_write_video(AVFormatContext *s, swf->swf_frame_number++; /* streaming sound always should be placed just before showframe tags */ - if (swf->audio_enc && av_fifo_size(swf->audio_fifo)) { + if (swf->audio_par && av_fifo_size(swf->audio_fifo)) { int frame_size = av_fifo_size(swf->audio_fifo); put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG); avio_wl16(pb, swf->sound_samples); @@ -443,13 +443,13 @@ static int swf_write_video(AVFormatContext *s, } static int swf_write_audio(AVFormatContext *s, - AVCodecContext *enc, uint8_t *buf, int size) + AVCodecParameters *par, uint8_t *buf, int size) { SWFContext *swf = s->priv_data; /* Flash Player limit */ if (swf->swf_frame_number == 16000) - av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n"); + av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n"); if (av_fifo_size(swf->audio_fifo) + size > AUDIO_FIFO_SIZE) { av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n"); @@ -457,36 +457,36 @@ static int swf_write_audio(AVFormatContext *s, } av_fifo_generic_write(swf->audio_fifo, buf, size, NULL); - swf->sound_samples += av_get_audio_frame_duration(enc, size); + swf->sound_samples += av_get_audio_frame_duration2(par, size); /* if audio only stream make sure we add swf frames */ - if (!swf->video_enc) - swf_write_video(s, enc, 0, 0); + if (!swf->video_par) + swf_write_video(s, par, 0, 0); return 0; } static int swf_write_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; - if (codec->codec_type == AVMEDIA_TYPE_AUDIO) - return swf_write_audio(s, codec, pkt->data, pkt->size); + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; + if (par->codec_type == AVMEDIA_TYPE_AUDIO) + return swf_write_audio(s, par, pkt->data, pkt->size); else - return swf_write_video(s, codec, pkt->data, pkt->size); + return swf_write_video(s, par, pkt->data, pkt->size); } static int swf_write_trailer(AVFormatContext *s) { SWFContext *swf = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *enc, *video_enc; + AVCodecParameters *par, *video_par; int file_size, i; - video_enc = NULL; + video_par = NULL; for(i=0;i<s->nb_streams;i++) { - enc = s->streams[i]->codec; - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) - video_enc = enc; + par = s->streams[i]->codecpar; + if (par->codec_type == AVMEDIA_TYPE_VIDEO) + video_par = par; else av_fifo_free(swf->audio_fifo); } @@ -495,7 +495,7 @@ static int swf_write_trailer(AVFormatContext *s) put_swf_end_tag(s); /* patch file size and number of frames if not streamed */ - if (s->pb->seekable && video_enc) { + if (s->pb->seekable && video_par) { file_size = avio_tell(pb); avio_seek(pb, 4, SEEK_SET); avio_wl32(pb, file_size); diff --git a/libavformat/takdec.c b/libavformat/takdec.c index 902ba05097..61ead31f9e 100644 --- a/libavformat/takdec.c +++ b/libavformat/takdec.c @@ -50,8 +50,8 @@ static int tak_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_TAK; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_TAK; st->need_parsing = AVSTREAM_PARSE_FULL; tc->mlast_frame = 0; @@ -119,15 +119,15 @@ static int tak_read_header(AVFormatContext *s) avpriv_tak_parse_streaminfo(&gb, &ti); if (ti.samples > 0) st->duration = ti.samples; - st->codec->bits_per_coded_sample = ti.bps; + st->codecpar->bits_per_coded_sample = ti.bps; if (ti.ch_layout) - st->codec->channel_layout = ti.ch_layout; - st->codec->sample_rate = ti.sample_rate; - st->codec->channels = ti.channels; + st->codecpar->channel_layout = ti.ch_layout; + st->codecpar->sample_rate = ti.sample_rate; + st->codecpar->channels = ti.channels; st->start_time = 0; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); - st->codec->extradata = buffer; - st->codec->extradata_size = size; + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); + st->codecpar->extradata = buffer; + st->codecpar->extradata_size = size; buffer = NULL; } else if (type == TAK_METADATA_LAST_FRAME) { if (size != 11) diff --git a/libavformat/thp.c b/libavformat/thp.c index 27d7ab433b..c9ec5c131d 100644 --- a/libavformat/thp.c +++ b/libavformat/thp.c @@ -101,12 +101,12 @@ static int thp_read_header(AVFormatContext *s) /* The denominator and numerator are switched because 1/fps is required. */ avpriv_set_pts_info(st, 64, thp->fps.den, thp->fps.num); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_THP; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = avio_rb32(pb); - st->codec->height = avio_rb32(pb); - st->codec->sample_rate = av_q2d(thp->fps); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_THP; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = avio_rb32(pb); + st->codecpar->height = avio_rb32(pb); + st->codecpar->sample_rate = av_q2d(thp->fps); thp->vst = st; thp->video_stream_index = st->index; @@ -121,14 +121,14 @@ static int thp_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_THP; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->channels = avio_rb32(pb); /* numChannels. */ - st->codec->sample_rate = avio_rb32(pb); /* Frequency. */ + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_THP; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->channels = avio_rb32(pb); /* numChannels. */ + st->codecpar->sample_rate = avio_rb32(pb); /* Frequency. */ st->duration = avio_rb32(pb); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); thp->audio_stream_index = st->index; thp->has_audio = 1; diff --git a/libavformat/tiertexseq.c b/libavformat/tiertexseq.c index 45300f9e8a..8427f92145 100644 --- a/libavformat/tiertexseq.c +++ b/libavformat/tiertexseq.c @@ -214,11 +214,11 @@ static int seq_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 32, 1, SEQ_FRAME_RATE); seq->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_TIERTEXSEQVIDEO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = SEQ_FRAME_W; - st->codec->height = SEQ_FRAME_H; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_TIERTEXSEQVIDEO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = SEQ_FRAME_W; + st->codecpar->height = SEQ_FRAME_H; /* initialize the audio decoder stream */ st = avformat_new_stream(s, NULL); @@ -228,15 +228,15 @@ static int seq_read_header(AVFormatContext *s) st->start_time = 0; avpriv_set_pts_info(st, 32, 1, SEQ_SAMPLE_RATE); seq->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S16BE; - st->codec->codec_tag = 0; /* no tag */ - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = SEQ_SAMPLE_RATE; - st->codec->bits_per_coded_sample = 16; - st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_coded_sample * st->codec->channels; - st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample / 8; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; + st->codecpar->codec_tag = 0; /* no tag */ + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = SEQ_SAMPLE_RATE; + st->codecpar->bits_per_coded_sample = 16; + st->codecpar->bit_rate = st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample * st->codecpar->channels; + st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample / 8; return 0; } diff --git a/libavformat/tmv.c b/libavformat/tmv.c index 103ac4af20..0283ddaad9 100644 --- a/libavformat/tmv.c +++ b/libavformat/tmv.c @@ -81,8 +81,8 @@ static int tmv_read_header(AVFormatContext *s) if (!(ast = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - ast->codec->sample_rate = avio_rl16(pb); - if (!ast->codec->sample_rate) { + ast->codecpar->sample_rate = avio_rl16(pb); + if (!ast->codecpar->sample_rate) { av_log(s, AV_LOG_ERROR, "invalid sample rate\n"); return -1; } @@ -111,29 +111,29 @@ static int tmv_read_header(AVFormatContext *s) return -1; } - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_U8; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8; if (features & TMV_STEREO) { - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - ast->codec->channels = 1; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; + ast->codecpar->channels = 1; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - ast->codec->bits_per_coded_sample = 8; - ast->codec->bit_rate = ast->codec->sample_rate * - ast->codec->bits_per_coded_sample; - avpriv_set_pts_info(ast, 32, 1, ast->codec->sample_rate); + ast->codecpar->bits_per_coded_sample = 8; + ast->codecpar->bit_rate = ast->codecpar->sample_rate * + ast->codecpar->bits_per_coded_sample; + avpriv_set_pts_info(ast, 32, 1, ast->codecpar->sample_rate); - fps.num = ast->codec->sample_rate * ast->codec->channels; + fps.num = ast->codecpar->sample_rate * ast->codecpar->channels; fps.den = tmv->audio_chunk_size; av_reduce(&fps.num, &fps.den, fps.num, fps.den, 0xFFFFFFFFLL); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_TMV; - vst->codec->pix_fmt = AV_PIX_FMT_PAL8; - vst->codec->width = char_cols * 8; - vst->codec->height = char_rows * 8; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_TMV; + vst->codecpar->format = AV_PIX_FMT_PAL8; + vst->codecpar->width = char_cols * 8; + vst->codecpar->height = char_rows * 8; avpriv_set_pts_info(vst, 32, fps.den, fps.num); if (features & TMV_PADDING) @@ -141,8 +141,8 @@ static int tmv_read_header(AVFormatContext *s) ((tmv->video_chunk_size + tmv->audio_chunk_size + 511) & ~511) - (tmv->video_chunk_size + tmv->audio_chunk_size); - vst->codec->bit_rate = ((tmv->video_chunk_size + tmv->padding) * - fps.num * 8) / fps.den; + vst->codecpar->bit_rate = ((tmv->video_chunk_size + tmv->padding) * + fps.num * 8) / fps.den; return 0; } diff --git a/libavformat/tta.c b/libavformat/tta.c index f5304f31ed..be22527eab 100644 --- a/libavformat/tta.c +++ b/libavformat/tta.c @@ -106,25 +106,25 @@ static int tta_read_header(AVFormatContext *s) } avio_skip(s->pb, 4); // seektable crc - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_TTA; - st->codec->channels = channels; - st->codec->sample_rate = samplerate; - st->codec->bits_per_coded_sample = bps; - - st->codec->extradata_size = avio_tell(s->pb) - start_offset; - if(st->codec->extradata_size+AV_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_TTA; + st->codecpar->channels = channels; + st->codecpar->sample_rate = samplerate; + st->codecpar->bits_per_coded_sample = bps; + + st->codecpar->extradata_size = avio_tell(s->pb) - start_offset; + if (st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codecpar->extradata_size) { //this check is redundant as avio_read should fail av_log(s, AV_LOG_ERROR, "extradata_size too large\n"); return -1; } - st->codec->extradata = av_mallocz(st->codec->extradata_size+AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) { - st->codec->extradata_size = 0; + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) { + st->codecpar->extradata_size = 0; return AVERROR(ENOMEM); } avio_seek(s->pb, start_offset, SEEK_SET); - avio_read(s->pb, st->codec->extradata, st->codec->extradata_size); + avio_read(s->pb, st->codecpar->extradata, st->codecpar->extradata_size); return 0; } diff --git a/libavformat/tty.c b/libavformat/tty.c index 3a34dd865a..d4c4873b81 100644 --- a/libavformat/tty.c +++ b/libavformat/tty.c @@ -83,9 +83,9 @@ static int read_header(AVFormatContext *avctx) ret = AVERROR(ENOMEM); goto fail; } - st->codec->codec_tag = 0; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_ANSI; + st->codecpar->codec_tag = 0; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_ANSI; if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { av_log (avctx, AV_LOG_ERROR, "Couldn't parse video size.\n"); @@ -95,8 +95,8 @@ static int read_header(AVFormatContext *avctx) av_log(avctx, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate); goto fail; } - st->codec->width = width; - st->codec->height = height; + st->codecpar->width = width; + st->codecpar->height = height; avpriv_set_pts_info(st, 60, framerate.den, framerate.num); st->avg_frame_rate = framerate; diff --git a/libavformat/txd.c b/libavformat/txd.c index e6522c3a73..809ec3302d 100644 --- a/libavformat/txd.c +++ b/libavformat/txd.c @@ -44,8 +44,8 @@ static int txd_read_header(AVFormatContext *s) { st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_TXD; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_TXD; avpriv_set_pts_info(st, 64, 1, 5); st->avg_frame_rate = av_inv_q(st->time_base); /* the parameters will be extracted from the compressed bitstream */ diff --git a/libavformat/utils.c b/libavformat/utils.c index c5cc8b951c..a70746aa99 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -167,8 +167,14 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, fmt->name, score); for (i = 0; fmt_id_type[i].name; i++) { if (!strcmp(fmt->name, fmt_id_type[i].name)) { - st->codec->codec_id = fmt_id_type[i].id; - st->codec->codec_type = fmt_id_type[i].type; + st->codecpar->codec_id = fmt_id_type[i].id; + st->codecpar->codec_type = fmt_id_type[i].type; +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + st->codec->codec_type = st->codecpar->codec_type; + st->codec->codec_id = st->codecpar->codec_id; +FF_ENABLE_DEPRECATION_WARNINGS +#endif break; } } @@ -253,11 +259,33 @@ static int queue_attached_pictures(AVFormatContext *s) return 0; } +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS +static int update_stream_avctx(AVFormatContext *s) +{ + int i, ret; + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + + if (!st->internal->need_codec_update) + continue; + + ret = avcodec_parameters_to_context(st->codec, st->codecpar); + if (ret < 0) + return ret; + + st->internal->need_codec_update = 0; + } + return 0; +} +FF_ENABLE_DEPRECATION_WARNINGS +#endif + int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options) { AVFormatContext *s = *ps; - int ret = 0; + int i, ret = 0; AVDictionary *tmp = NULL; ID3v2ExtraMeta *id3v2_extra_meta = NULL; @@ -321,6 +349,13 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; +#if FF_API_LAVF_AVCTX + update_stream_avctx(s); +#endif + + for (i = 0; i < s->nb_streams; i++) + s->streams[i]->internal->orig_codec_id = s->streams[i]->codecpar->codec_id; + if (options) { av_dict_free(options); *options = tmp; @@ -342,7 +377,7 @@ fail: static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { - if (st->codec->codec_id == AV_CODEC_ID_PROBE) { + if (st->codecpar->codec_id == AV_CODEC_ID_PROBE) { AVProbeData *pd = &st->probe_data; av_log(s, AV_LOG_DEBUG, "probing stream %d\n", st->index); --st->probe_packets; @@ -368,7 +403,7 @@ static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX / 4 : 0); - if (st->codec->codec_id != AV_CODEC_ID_PROBE) { + if (st->codecpar->codec_id != AV_CODEC_ID_PROBE) { pd->buf_size = 0; av_freep(&pd->buf); av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); @@ -389,7 +424,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if (pktl) { *pkt = pktl->pkt; st = s->streams[pkt->stream_index]; - if (st->codec->codec_id != AV_CODEC_ID_PROBE || + if (st->codecpar->codec_id != AV_CODEC_ID_PROBE || !st->probe_packets || s->internal->raw_packet_buffer_remaining_size < pkt->size) { AVProbeData *pd; @@ -441,22 +476,22 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) st = s->streams[pkt->stream_index]; - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: if (s->video_codec_id) - st->codec->codec_id = s->video_codec_id; + st->codecpar->codec_id = s->video_codec_id; break; case AVMEDIA_TYPE_AUDIO: if (s->audio_codec_id) - st->codec->codec_id = s->audio_codec_id; + st->codecpar->codec_id = s->audio_codec_id; break; case AVMEDIA_TYPE_SUBTITLE: if (s->subtitle_codec_id) - st->codec->codec_id = s->subtitle_codec_id; + st->codecpar->codec_id = s->subtitle_codec_id; break; } - if (!pktl && (st->codec->codec_id != AV_CODEC_ID_PROBE || + if (!pktl && (st->codecpar->codec_id != AV_CODEC_ID_PROBE || !st->probe_packets)) return ret; @@ -479,13 +514,13 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt) { - AVRational codec_framerate = s->iformat ? st->codec->framerate : - av_inv_q(st->codec->time_base); + AVRational codec_framerate = s->iformat ? st->internal->avctx->framerate : + (AVRational){ 0, 1 }; int frame_size; *pnum = 0; *pden = 0; - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: if (st->avg_frame_rate.num) { *pnum = st->avg_frame_rate.den; @@ -505,16 +540,16 @@ void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStrea /* If this codec can be interlaced or progressive then we need * a parser to compute duration of a packet. Thus if we have * no parser in such case leave duration undefined. */ - if (st->codec->ticks_per_frame > 1 && !pc) + if (st->internal->avctx->ticks_per_frame > 1 && !pc) *pnum = *pden = 0; } break; case AVMEDIA_TYPE_AUDIO: - frame_size = av_get_audio_frame_duration(st->codec, pkt->size); - if (frame_size <= 0 || st->codec->sample_rate <= 0) + frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size); + if (frame_size <= 0 || st->codecpar->sample_rate <= 0) break; *pnum = frame_size; - *pden = st->codec->sample_rate; + *pden = st->codecpar->sample_rate; break; default: break; @@ -591,10 +626,10 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, pktl->pkt.dts == AV_NOPTS_VALUE && !pktl->pkt.duration) { pktl->pkt.dts = cur_dts; - if (!st->codec->has_b_frames) + if (!st->internal->avctx->has_b_frames) pktl->pkt.pts = cur_dts; cur_dts += duration; - if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) pktl->pkt.duration = duration; } else break; @@ -616,7 +651,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, pkt->dts = AV_NOPTS_VALUE; /* do we have a video B-frame ? */ - delay = st->codec->has_b_frames; + delay = st->internal->avctx->has_b_frames; presentation_delayed = 0; /* XXX: need has_b_frame, but cannot get it if the codec is @@ -641,7 +676,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, pkt->dts = AV_NOPTS_VALUE; } - if (pkt->duration == 0 && st->codec->codec_type != AVMEDIA_TYPE_AUDIO) { + if (pkt->duration == 0 && st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) { ff_compute_frame_duration(s, &num, &den, st, pc, pkt); if (den && num) { pkt->duration = av_rescale_rnd(1, num * (int64_t) st->time_base.den, @@ -679,7 +714,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, /* Interpolate PTS and DTS if they are not present. We skip H.264 * currently because delay and has_b_frames are not reliably set. */ if ((delay == 0 || (delay == 1 && pc)) && - st->codec->codec_id != AV_CODEC_ID_H264) { + st->codecpar->codec_id != AV_CODEC_ID_H264) { if (presentation_delayed) { /* DTS = decompression timestamp */ /* PTS = presentation timestamp */ @@ -702,9 +737,9 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, } else if (pkt->pts != AV_NOPTS_VALUE || pkt->dts != AV_NOPTS_VALUE || pkt->duration || - st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { int duration = pkt->duration; - if (!duration && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (!duration && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { ff_compute_frame_duration(s, &num, &den, st, pc, pkt); if (den && num) { duration = av_rescale_rnd(1, @@ -740,7 +775,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, if (pkt->dts == AV_NOPTS_VALUE) pkt->dts = st->pts_buffer[0]; // We skipped it above so we try here. - if (st->codec->codec_id == AV_CODEC_ID_H264) + if (st->codecpar->codec_id == AV_CODEC_ID_H264) // This should happen on the first packet update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts); if (pkt->dts > st->cur_dts) @@ -752,7 +787,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, presentation_delayed, delay, pkt->pts, pkt->dts, st->cur_dts); /* update flags */ - if (is_intra_only(st->codec->codec_id)) + if (is_intra_only(st->codecpar->codec_id)) pkt->flags |= AV_PKT_FLAG_KEY; #if FF_API_CONVERGENCE_DURATION FF_DISABLE_DEPRECATION_WARNINGS @@ -796,7 +831,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) int len; av_init_packet(&out_pkt); - len = av_parser_parse2(st->parser, st->codec, + len = av_parser_parse2(st->parser, st->internal->avctx, &out_pkt.data, &out_pkt.size, data, size, pkt->pts, pkt->dts, pkt->pos); @@ -819,11 +854,11 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) /* set the duration */ out_pkt.duration = 0; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->codec->sample_rate > 0) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->internal->avctx->sample_rate > 0) { out_pkt.duration = av_rescale_q_rnd(st->parser->duration, - (AVRational) { 1, st->codec->sample_rate }, + (AVRational) { 1, st->internal->avctx->sample_rate }, st->time_base, AV_ROUND_DOWN); } @@ -928,7 +963,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) cur_pkt.size, cur_pkt.duration, cur_pkt.flags); if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { - st->parser = av_parser_init(st->codec->codec_id); + st->parser = av_parser_init(st->codecpar->codec_id); if (!st->parser) /* no parser available: just output the raw packets */ st->need_parsing = AVSTREAM_PARSE_NONE; @@ -969,6 +1004,10 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN); } +#if FF_API_LAVF_AVCTX + update_stream_avctx(s); +#endif + if (s->debug & FF_FDEBUG_TS) av_log(s, AV_LOG_DEBUG, "read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", " @@ -1057,12 +1096,12 @@ int av_find_default_stream_index(AVFormatContext *s) return -1; for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && !(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) { return i; } if (first_audio_index < 0 && - st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) first_audio_index = i; } return first_audio_index >= 0 ? first_audio_index : 0; @@ -1665,12 +1704,12 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) int bit_rate = 0; for (i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; - if (st->codec->bit_rate > 0) { - if (INT_MAX - st->codec->bit_rate < bit_rate) { + if (st->codecpar->bit_rate > 0) { + if (INT_MAX - st->codecpar->bit_rate < bit_rate) { bit_rate = 0; break; } - bit_rate += st->codec->bit_rate; + bit_rate += st->codecpar->bit_rate; } } ic->bit_rate = bit_rate; @@ -1712,7 +1751,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) for (i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time == AV_NOPTS_VALUE && st->first_dts == AV_NOPTS_VALUE) - av_log(st->codec, AV_LOG_WARNING, + av_log(ic, AV_LOG_WARNING, "start time is not set in estimate_timings_from_pts\n"); if (st->parser) { @@ -1822,7 +1861,7 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset) static int has_codec_parameters(AVStream *st) { - AVCodecContext *avctx = st->codec; + AVCodecContext *avctx = st->internal->avctx; int val; switch (avctx->codec_type) { @@ -1846,14 +1885,15 @@ static int has_codec_parameters(AVStream *st) static int has_decode_delay_been_guessed(AVStream *st) { - return st->codec->codec_id != AV_CODEC_ID_H264 || + return st->internal->avctx->codec_id != AV_CODEC_ID_H264 || st->info->nb_decoded_frames >= 6; } /* returns 1 or 0 if or if not decoded data was returned, or a negative error */ -static int try_decode_frame(AVStream *st, AVPacket *avpkt, +static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt, AVDictionary **options) { + AVCodecContext *avctx = st->internal->avctx; const AVCodec *codec; int got_picture = 1, ret = 0; AVFrame *frame = av_frame_alloc(); @@ -1862,11 +1902,17 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, if (!frame) return AVERROR(ENOMEM); - if (!avcodec_is_open(st->codec) && !st->info->found_decoder) { + if (!avcodec_is_open(avctx) && !st->info->found_decoder) { AVDictionary *thread_opt = NULL; +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS codec = st->codec->codec ? st->codec->codec - : avcodec_find_decoder(st->codec->codec_id); + : avcodec_find_decoder(st->codecpar->codec_id); +FF_ENABLE_DEPRECATION_WARNINGS +#else + codec = avcodec_find_decoder(st->codecpar->codec_id); +#endif if (!codec) { st->info->found_decoder = -1; @@ -1877,7 +1923,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, /* Force thread count to 1 since the H.264 decoder will not extract * SPS and PPS to extradata during multi-threaded decoding. */ av_dict_set(options ? options : &thread_opt, "threads", "1", 0); - ret = avcodec_open2(st->codec, codec, options ? options : &thread_opt); + ret = avcodec_open2(avctx, codec, options ? options : &thread_opt); if (!options) av_dict_free(&thread_opt); if (ret < 0) { @@ -1897,15 +1943,15 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, ret >= 0 && (!has_codec_parameters(st) || !has_decode_delay_been_guessed(st) || (!st->codec_info_nb_frames && - (st->codec->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)))) { + (avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)))) { got_picture = 0; - switch (st->codec->codec_type) { + switch (avctx->codec_type) { case AVMEDIA_TYPE_VIDEO: - ret = avcodec_decode_video2(st->codec, frame, + ret = avcodec_decode_video2(avctx, frame, &got_picture, &pkt); break; case AVMEDIA_TYPE_AUDIO: - ret = avcodec_decode_audio4(st->codec, frame, &got_picture, &pkt); + ret = avcodec_decode_audio4(avctx, frame, &got_picture, &pkt); break; default: break; @@ -2047,6 +2093,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { int i, count, ret, read_size, j; AVStream *st; + AVCodecContext *avctx; AVPacket pkt1, *pkt; int64_t old_offset = avio_tell(ic->pb); // new streams might appear, no options for those @@ -2056,30 +2103,58 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) const AVCodec *codec; AVDictionary *thread_opt = NULL; st = ic->streams[i]; + avctx = st->internal->avctx; // only for the split stuff if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE)) { - st->parser = av_parser_init(st->codec->codec_id); + st->parser = av_parser_init(st->codecpar->codec_id); if (st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser) st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; } + + /* check if the caller has overridden the codec id */ +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + if (st->codec->codec_id != st->internal->orig_codec_id) { + st->codecpar->codec_id = st->codec->codec_id; + st->codecpar->codec_type = st->codec->codec_type; + st->internal->orig_codec_id = st->codec->codec_id; + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (st->codecpar->codec_id != st->internal->orig_codec_id) + st->internal->orig_codec_id = st->codecpar->codec_id; + + ret = avcodec_parameters_to_context(avctx, st->codecpar); + if (ret < 0) + goto find_stream_info_err; + if (st->codecpar->codec_id != AV_CODEC_ID_PROBE && + st->codecpar->codec_id != AV_CODEC_ID_NONE) + st->internal->avctx_inited = 1; + +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS codec = st->codec->codec ? st->codec->codec - : avcodec_find_decoder(st->codec->codec_id); + : avcodec_find_decoder(st->codecpar->codec_id); +FF_ENABLE_DEPRECATION_WARNINGS +#else + codec = avcodec_find_decoder(st->codecpar->codec_id); +#endif /* Force thread count to 1 since the H.264 decoder will not extract * SPS and PPS to extradata during multi-threaded decoding. */ av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0); /* Ensure that subtitle_header is properly set. */ - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE - && codec && !st->codec->codec) - avcodec_open2(st->codec, codec, + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE + && codec && !avctx->codec) + avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt); // Try to just open decoders, in case this is enough to get parameters. if (!has_codec_parameters(st)) { - if (codec && !st->codec->codec) - avcodec_open2(st->codec, codec, + if (codec && !avctx->codec) + avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt); } if (!options) @@ -2117,15 +2192,15 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* variable fps and no guess at the real fps */ if (!st->avg_frame_rate.num && st->codec_info_nb_frames < fps_analyze_framecount && - st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) break; if (st->parser && st->parser->parser->split && - !st->codec->extradata) + !st->codecpar->extradata) break; if (st->first_dts == AV_NOPTS_VALUE && st->codec_info_nb_frames < ic->max_ts_probe && - (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || - st->codec->codec_type == AVMEDIA_TYPE_AUDIO)) + (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) break; } if (i == ic->nb_streams) { @@ -2166,7 +2241,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* flush the decoders */ if (st->info->found_decoder == 1) { do { - err = try_decode_frame(st, &empty_pkt, + err = try_decode_frame(ic, st, &empty_pkt, (options && i < orig_nb_streams) ? &options[i] : NULL); } while (err > 0 && !has_codec_parameters(st)); @@ -2177,7 +2252,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) "decoding for stream %d failed\n", st->index); } else if (!has_codec_parameters(st)) { char buf[256]; - avcodec_string(buf, sizeof(buf), st->codec, 0); + avcodec_string(buf, sizeof(buf), st->internal->avctx, 0); av_log(ic, AV_LOG_WARNING, "Could not find codec parameters (%s)\n", buf); } else { @@ -2199,6 +2274,14 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) read_size += pkt->size; st = ic->streams[pkt->stream_index]; + avctx = st->internal->avctx; + if (!st->internal->avctx_inited) { + ret = avcodec_parameters_to_context(avctx, st->codecpar); + if (ret < 0) + goto find_stream_info_err; + st->internal->avctx_inited = 1; + } + if (pkt->dts != AV_NOPTS_VALUE && st->codec_info_nb_frames > 1) { /* check for non-increasing dts */ if (st->info->fps_last_dts != AV_NOPTS_VALUE && @@ -2248,16 +2331,16 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) break; } } - if (st->parser && st->parser->parser->split && !st->codec->extradata) { - int i = st->parser->parser->split(st->codec, pkt->data, pkt->size); + if (st->parser && st->parser->parser->split && !avctx->extradata) { + int i = st->parser->parser->split(avctx, pkt->data, pkt->size); if (i > 0 && i < FF_MAX_EXTRADATA_SIZE) { - st->codec->extradata_size = i; - st->codec->extradata = av_mallocz(st->codec->extradata_size + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + avctx->extradata_size = i; + avctx->extradata = av_mallocz(avctx->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!avctx->extradata) return AVERROR(ENOMEM); - memcpy(st->codec->extradata, pkt->data, - st->codec->extradata_size); + memcpy(avctx->extradata, pkt->data, + avctx->extradata_size); } } @@ -2270,7 +2353,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) * least one frame of codec data, this makes sure the codec initializes * the channel configuration and does not only trust the values from * the container. */ - try_decode_frame(st, pkt, + try_decode_frame(ic, st, pkt, (options && i < orig_nb_streams) ? &options[i] : NULL); if (ic->flags & AVFMT_FLAG_NOBUFFER) @@ -2283,11 +2366,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) // close codecs which were opened in try_decode_frame() for (i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; - avcodec_close(st->codec); + avcodec_close(st->internal->avctx); } for (i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + avctx = st->internal->avctx; + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { /* estimate average framerate if not set by demuxer */ if (!st->avg_frame_rate.num && st->info->fps_last_dts != st->info->fps_first_dts) { @@ -2322,12 +2406,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, best_fps, 12 * 1001, INT_MAX); } - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (!st->codec->bits_per_coded_sample) - st->codec->bits_per_coded_sample = - av_get_bits_per_sample(st->codec->codec_id); + } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { + if (!avctx->bits_per_coded_sample) + avctx->bits_per_coded_sample = + av_get_bits_per_sample(avctx->codec_id); // set stream disposition based on audio service type - switch (st->codec->audio_service_type) { + switch (avctx->audio_service_type) { case AV_AUDIO_SERVICE_TYPE_EFFECTS: st->disposition = AV_DISPOSITION_CLEAN_EFFECTS; break; @@ -2351,9 +2435,38 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) compute_chapters_end(ic); + /* update the stream parameters from the internal codec contexts */ + for (i = 0; i < ic->nb_streams; i++) { + st = ic->streams[i]; + if (!st->internal->avctx_inited) + continue; + + ret = avcodec_parameters_from_context(st->codecpar, st->internal->avctx); + if (ret < 0) + goto find_stream_info_err; + +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + ret = avcodec_parameters_to_context(st->codec, st->codecpar); + if (ret < 0) + goto find_stream_info_err; + + if (st->internal->avctx->subtitle_header) { + st->codec->subtitle_header = av_malloc(st->internal->avctx->subtitle_header_size); + if (!st->codec->subtitle_header) + goto find_stream_info_err; + st->codec->subtitle_header_size = st->internal->avctx->subtitle_header_size; + memcpy(st->codec->subtitle_header, st->internal->avctx->subtitle_header, + st->codec->subtitle_header_size); + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + + st->internal->avctx_inited = 0; + } + find_stream_info_err: for (i = 0; i < ic->nb_streams; i++) { - ic->streams[i]->codec->thread_count = 0; av_freep(&ic->streams[i]->info); } return ret; @@ -2389,8 +2502,8 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, for (i = 0; i < nb_streams; i++) { int real_stream_index = program ? program[i] : i; AVStream *st = ic->streams[real_stream_index]; - AVCodecContext *avctx = st->codec; - if (avctx->codec_type != type) + AVCodecParameters *par = st->codecpar; + if (par->codec_type != type) continue; if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb) continue; @@ -2398,7 +2511,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, AV_DISPOSITION_VISUAL_IMPAIRED)) continue; if (decoder_ret) { - decoder = avcodec_find_decoder(st->codec->codec_id); + decoder = avcodec_find_decoder(par->codec_id); if (!decoder) { if (ret < 0) ret = AVERROR_DECODER_NOT_FOUND; @@ -2460,14 +2573,22 @@ static void free_stream(AVStream **pst) if (st->attached_pic.data) av_packet_unref(&st->attached_pic); + if (st->internal) { + avcodec_free_context(&st->internal->avctx); + } av_freep(&st->internal); av_dict_free(&st->metadata); + avcodec_parameters_free(&st->codecpar); av_freep(&st->probe_data.buf); av_free(st->index_entries); +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS av_free(st->codec->extradata); av_free(st->codec->subtitle_header); av_free(st->codec); +FF_ENABLE_DEPRECATION_WARNINGS +#endif av_free(st->priv_data); av_free(st->info); @@ -2547,20 +2668,28 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) return NULL; } +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS st->codec = avcodec_alloc_context3(c); if (!st->codec) { av_free(st->info); av_free(st); return NULL; } +FF_ENABLE_DEPRECATION_WARNINGS +#endif st->internal = av_mallocz(sizeof(*st->internal)); if (!st->internal) goto fail; if (s->iformat) { +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS /* no default bitrate if decoding */ st->codec->bit_rate = 0; +FF_ENABLE_DEPRECATION_WARNINGS +#endif /* default pts setting is MPEG-like */ avpriv_set_pts_info(st, 33, 1, 90000); @@ -2573,6 +2702,14 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) st->cur_dts = AV_NOPTS_VALUE; } + st->codecpar = avcodec_parameters_alloc(); + if (!st->codecpar) + goto fail; + + st->internal->avctx = avcodec_alloc_context3(NULL); + if (!st->internal->avctx) + goto fail; + st->index = s->nb_streams; st->start_time = AV_NOPTS_VALUE; st->duration = AV_NOPTS_VALUE; @@ -2588,6 +2725,10 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) st->info->fps_first_dts = AV_NOPTS_VALUE; st->info->fps_last_dts = AV_NOPTS_VALUE; +#if FF_API_LAVF_AVCTX + st->internal->need_codec_update = 1; +#endif + s->streams[s->nb_streams++] = st; return st; fail: @@ -3094,18 +3235,18 @@ int ff_generate_avci_extradata(AVStream *st) const uint8_t *data = NULL; int size = 0; - if (st->codec->width == 1920) { - if (st->codec->field_order == AV_FIELD_PROGRESSIVE) { + if (st->codecpar->width == 1920) { + if (st->codecpar->field_order == AV_FIELD_PROGRESSIVE) { data = avci100_1080p_extradata; size = sizeof(avci100_1080p_extradata); } else { data = avci100_1080i_extradata; size = sizeof(avci100_1080i_extradata); } - } else if (st->codec->width == 1440) { + } else if (st->codecpar->width == 1440) { data = avci50_1080i_extradata; size = sizeof(avci50_1080i_extradata); - } else if (st->codec->width == 1280) { + } else if (st->codecpar->width == 1280) { data = avci100_720p_extradata; size = sizeof(avci100_720p_extradata); } @@ -3113,14 +3254,14 @@ int ff_generate_avci_extradata(AVStream *st) if (!size) return 0; - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; - st->codec->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; + st->codecpar->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - memcpy(st->codec->extradata, data, size); - st->codec->extradata_size = size; + memcpy(st->codecpar->extradata, data, size); + st->codecpar->extradata_size = size; return 0; } diff --git a/libavformat/vc1test.c b/libavformat/vc1test.c index f302c2b12a..e127941a35 100644 --- a/libavformat/vc1test.c +++ b/libavformat/vc1test.c @@ -58,16 +58,16 @@ static int vc1t_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_WMV3; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_WMV3; - st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata = av_malloc(VC1_EXTRADATA_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = VC1_EXTRADATA_SIZE; - avio_read(pb, st->codec->extradata, VC1_EXTRADATA_SIZE); - st->codec->height = avio_rl32(pb); - st->codec->width = avio_rl32(pb); + st->codecpar->extradata_size = VC1_EXTRADATA_SIZE; + avio_read(pb, st->codecpar->extradata, VC1_EXTRADATA_SIZE); + st->codecpar->height = avio_rl32(pb); + st->codecpar->width = avio_rl32(pb); if(avio_rl32(pb) != 0xC) return AVERROR_INVALIDDATA; avio_skip(pb, 8); diff --git a/libavformat/vc1testenc.c b/libavformat/vc1testenc.c index 9d55fee46d..dc23c1461d 100644 --- a/libavformat/vc1testenc.c +++ b/libavformat/vc1testenc.c @@ -27,19 +27,19 @@ typedef struct RCVContext { static int vc1test_write_header(AVFormatContext *s) { - AVCodecContext *avc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; AVIOContext *pb = s->pb; - if (avc->codec_id != AV_CODEC_ID_WMV3) { + if (par->codec_id != AV_CODEC_ID_WMV3) { av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n"); return -1; } avio_wl24(pb, 0); //frames count will be here avio_w8(pb, 0xC5); avio_wl32(pb, 4); - avio_write(pb, avc->extradata, 4); - avio_wl32(pb, avc->height); - avio_wl32(pb, avc->width); + avio_write(pb, par->extradata, 4); + avio_wl32(pb, par->height); + avio_wl32(pb, par->width); avio_wl32(pb, 0xC); avio_wl24(pb, 0); // hrd_buffer avio_w8(pb, 0x80); // level|cbr|res1 diff --git a/libavformat/version.h b/libavformat/version.h index 990592144f..58544c9659 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -63,5 +63,8 @@ #ifndef FF_API_COMPUTE_PKT_FIELDS2 #define FF_API_COMPUTE_PKT_FIELDS2 (LIBAVFORMAT_VERSION_MAJOR < 58) #endif +#ifndef FF_API_LAVF_AVCTX +#define FF_API_LAVF_AVCTX (LIBAVFORMAT_VERSION_MAJOR < 58) +#endif #endif /* AVFORMAT_VERSION_H */ diff --git a/libavformat/voc_packet.c b/libavformat/voc_packet.c index 9e1c7469da..ff48d502f2 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; diff --git a/libavformat/vocdec.c b/libavformat/vocdec.c index aca77ced63..5ed7117182 100644 --- a/libavformat/vocdec.c +++ b/libavformat/vocdec.c @@ -63,7 +63,7 @@ static int voc_read_packet(AVFormatContext *s, AVPacket *pkt) AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; } return ff_voc_get_packet(s, pkt, s->streams[0], 0); } diff --git a/libavformat/vocenc.c b/libavformat/vocenc.c index ed10a96f7a..033fc5633b 100644 --- a/libavformat/vocenc.c +++ b/libavformat/vocenc.c @@ -34,7 +34,7 @@ static int voc_write_header(AVFormatContext *s) const int version = 0x0114; if (s->nb_streams != 1 - || s->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO) + || s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) return AVERROR_PATCHWELCOME; avio_write(pb, ff_voc_magic, sizeof(ff_voc_magic) - 1); @@ -48,30 +48,30 @@ static int voc_write_header(AVFormatContext *s) static int voc_write_packet(AVFormatContext *s, AVPacket *pkt) { VocEncContext *voc = s->priv_data; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; AVIOContext *pb = s->pb; if (!voc->param_written) { - if (enc->codec_tag > 0xFF) { + if (par->codec_tag > 0xFF) { avio_w8(pb, VOC_TYPE_NEW_VOICE_DATA); avio_wl24(pb, pkt->size + 12); - avio_wl32(pb, enc->sample_rate); - avio_w8(pb, enc->bits_per_coded_sample); - avio_w8(pb, enc->channels); - avio_wl16(pb, enc->codec_tag); + avio_wl32(pb, par->sample_rate); + avio_w8(pb, par->bits_per_coded_sample); + avio_w8(pb, par->channels); + avio_wl16(pb, par->codec_tag); avio_wl32(pb, 0); } else { - if (s->streams[0]->codec->channels > 1) { + if (s->streams[0]->codecpar->channels > 1) { avio_w8(pb, VOC_TYPE_EXTENDED); avio_wl24(pb, 4); - avio_wl16(pb, 65536-256000000/(enc->sample_rate*enc->channels)); - avio_w8(pb, enc->codec_tag); - avio_w8(pb, enc->channels - 1); + avio_wl16(pb, 65536-256000000/(par->sample_rate*par->channels)); + avio_w8(pb, par->codec_tag); + avio_w8(pb, par->channels - 1); } avio_w8(pb, VOC_TYPE_VOICE_DATA); avio_wl24(pb, pkt->size + 2); - avio_w8(pb, 256 - 1000000 / enc->sample_rate); - avio_w8(pb, enc->codec_tag); + avio_w8(pb, 256 - 1000000 / par->sample_rate); + avio_w8(pb, par->codec_tag); } voc->param_written = 1; } else { diff --git a/libavformat/vqf.c b/libavformat/vqf.c index baff8fcb53..c3a6a97720 100644 --- a/libavformat/vqf.c +++ b/libavformat/vqf.c @@ -104,8 +104,8 @@ static int vqf_read_header(AVFormatContext *s) header_size = avio_rb32(s->pb); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_TWINVQ; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_TWINVQ; st->start_time = 0; do { @@ -127,12 +127,12 @@ static int vqf_read_header(AVFormatContext *s) switch(chunk_tag){ case MKTAG('C','O','M','M'): avio_read(s->pb, comm_chunk, 12); - st->codec->channels = AV_RB32(comm_chunk ) + 1; + st->codecpar->channels = AV_RB32(comm_chunk ) + 1; read_bitrate = AV_RB32(comm_chunk + 4); rate_flag = AV_RB32(comm_chunk + 8); avio_skip(s->pb, len-12); - st->codec->bit_rate = read_bitrate*1000; + st->codecpar->bit_rate = read_bitrate * 1000; break; case MKTAG('D','S','I','Z'): // size of compressed data { @@ -165,32 +165,32 @@ static int vqf_read_header(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "COMM tag not found!\n"); return -1; case 44: - st->codec->sample_rate = 44100; + st->codecpar->sample_rate = 44100; break; case 22: - st->codec->sample_rate = 22050; + st->codecpar->sample_rate = 22050; break; case 11: - st->codec->sample_rate = 11025; + st->codecpar->sample_rate = 11025; break; default: if (rate_flag < 8 || rate_flag > 44) { av_log(s, AV_LOG_ERROR, "Invalid rate flag %d\n", rate_flag); return AVERROR_INVALIDDATA; } - st->codec->sample_rate = rate_flag*1000; + st->codecpar->sample_rate = rate_flag*1000; break; } - if (read_bitrate / st->codec->channels < 8 || - read_bitrate / st->codec->channels > 48) { + if (read_bitrate / st->codecpar->channels < 8 || + read_bitrate / st->codecpar->channels > 48) { av_log(s, AV_LOG_ERROR, "Invalid bitrate per channel %d\n", - read_bitrate / st->codec->channels); + read_bitrate / st->codecpar->channels); return AVERROR_INVALIDDATA; } - switch (((st->codec->sample_rate/1000) << 8) + - read_bitrate/st->codec->channels) { + switch (((st->codecpar->sample_rate/1000) << 8) + + read_bitrate/st->codecpar->channels) { case (11<<8) + 8 : case (8 <<8) + 8 : case (11<<8) + 10: @@ -208,17 +208,17 @@ static int vqf_read_header(AVFormatContext *s) break; default: av_log(s, AV_LOG_ERROR, "Mode not suported: %d Hz, %d kb/s.\n", - st->codec->sample_rate, st->codec->bit_rate); + st->codecpar->sample_rate, st->codecpar->bit_rate); return -1; } - c->frame_bit_len = st->codec->bit_rate*size/st->codec->sample_rate; - avpriv_set_pts_info(st, 64, size, st->codec->sample_rate); + c->frame_bit_len = st->codecpar->bit_rate*size/st->codecpar->sample_rate; + avpriv_set_pts_info(st, 64, size, st->codecpar->sample_rate); /* put first 12 bytes of COMM chunk in extradata */ - if (!(st->codec->extradata = av_malloc(12 + AV_INPUT_BUFFER_PADDING_SIZE))) + if (!(st->codecpar->extradata = av_malloc(12 + AV_INPUT_BUFFER_PADDING_SIZE))) return AVERROR(ENOMEM); - st->codec->extradata_size = 12; - memcpy(st->codec->extradata, comm_chunk, 12); + st->codecpar->extradata_size = 12; + memcpy(st->codecpar->extradata, comm_chunk, 12); ff_metadata_conv_ctx(s, NULL, vqf_metadata_conv); @@ -262,7 +262,7 @@ static int vqf_read_seek(AVFormatContext *s, int64_t pos; st = s->streams[stream_index]; - pos = av_rescale_rnd(timestamp * st->codec->bit_rate, + pos = av_rescale_rnd(timestamp * st->codecpar->bit_rate, st->time_base.num, st->time_base.den * (int64_t)c->frame_bit_len, (flags & AVSEEK_FLAG_BACKWARD) ? @@ -270,7 +270,7 @@ static int vqf_read_seek(AVFormatContext *s, pos *= c->frame_bit_len; st->cur_dts = av_rescale(pos, st->time_base.den, - st->codec->bit_rate * (int64_t)st->time_base.num); + st->codecpar->bit_rate * (int64_t)st->time_base.num); if ((ret = avio_seek(s->pb, ((pos-7) >> 3) + s->internal->data_offset, SEEK_SET)) < 0) return ret; diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 83c860d3cd..4bd2642d77 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -102,12 +102,12 @@ static int wav_parse_fmt_tag(AVFormatContext *s, int64_t size, AVStream **st) if (!*st) return AVERROR(ENOMEM); - ret = ff_get_wav_header(s, pb, (*st)->codec, size); + ret = ff_get_wav_header(s, pb, (*st)->codecpar, size); if (ret < 0) return ret; (*st)->need_parsing = AVSTREAM_PARSE_FULL; - avpriv_set_pts_info(*st, 64, 1, (*st)->codec->sample_rate); + avpriv_set_pts_info(*st, 64, 1, (*st)->codecpar->sample_rate); return 0; } @@ -328,11 +328,11 @@ break_loop: avio_seek(pb, data_ofs, SEEK_SET); - if (!sample_count && st->codec->channels && - av_get_bits_per_sample(st->codec->codec_id)) + if (!sample_count && st->codecpar->channels && + av_get_bits_per_sample(st->codecpar->codec_id)) sample_count = (data_size << 3) / - (st->codec->channels * - (uint64_t)av_get_bits_per_sample(st->codec->codec_id)); + (st->codecpar->channels * + (uint64_t)av_get_bits_per_sample(st->codecpar->codec_id)); if (sample_count) st->duration = sample_count; @@ -391,10 +391,10 @@ static int wav_read_packet(AVFormatContext *s, AVPacket *pkt) } size = MAX_SIZE; - if (st->codec->block_align > 1) { - if (size < st->codec->block_align) - size = st->codec->block_align; - size = (size / st->codec->block_align) * st->codec->block_align; + if (st->codecpar->block_align > 1) { + if (size < st->codecpar->block_align) + size = st->codecpar->block_align; + size = (size / st->codecpar->block_align) * st->codecpar->block_align; } size = FFMIN(size, left); ret = av_get_packet(s->pb, pkt, size); @@ -411,7 +411,7 @@ static int wav_read_seek(AVFormatContext *s, AVStream *st; st = s->streams[0]; - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: case AV_CODEC_ID_AC3: @@ -498,14 +498,14 @@ static int w64_read_header(AVFormatContext *s) return AVERROR(ENOMEM); /* subtract chunk header size - normal wav file doesn't count it */ - ret = ff_get_wav_header(s, pb, st->codec, size - 24); + ret = ff_get_wav_header(s, pb, st->codecpar, size - 24); if (ret < 0) return ret; avio_skip(pb, FFALIGN(size, INT64_C(8)) - size); st->need_parsing = AVSTREAM_PARSE_FULL; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); size = find_guid(pb, guid_data); if (size < 0) { diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c index 25f6ffcde0..32d4bc184d 100644 --- a/libavformat/wavenc.c +++ b/libavformat/wavenc.c @@ -109,15 +109,15 @@ static int wav_write_header(AVFormatContext *s) /* format header */ fmt = ff_start_tag(pb, "fmt "); - if (ff_put_wav_header(pb, s->streams[0]->codec) < 0) { - const AVCodecDescriptor *desc = avcodec_descriptor_get(s->streams[0]->codec->codec_id); + if (ff_put_wav_header(s, pb, s->streams[0]->codecpar) < 0) { + const AVCodecDescriptor *desc = avcodec_descriptor_get(s->streams[0]->codecpar->codec_id); av_log(s, AV_LOG_ERROR, "%s codec not supported in WAVE format\n", desc ? desc->name : "unknown"); return AVERROR(ENOSYS); } ff_end_tag(pb, fmt); - if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */ + if (s->streams[0]->codecpar->codec_tag != 0x01 /* hence for all other than PCM */ && s->pb->seekable) { wav->fact_pos = ff_start_tag(pb, "fact"); avio_wl32(pb, 0); @@ -127,7 +127,7 @@ static int wav_write_header(AVFormatContext *s) if (wav->write_bext) bwf_write_bext_chunk(s); - avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); + avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codecpar->sample_rate); wav->maxpts = wav->last_duration = 0; wav->minpts = INT64_MAX; @@ -175,11 +175,11 @@ static int wav_write_trailer(AVFormatContext *s) avio_flush(pb); - if(s->streams[0]->codec->codec_tag != 0x01) { + if(s->streams[0]->codecpar->codec_tag != 0x01) { /* Update num_samps in fact chunk */ int number_of_samples; number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration, - s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num, + s->streams[0]->codecpar->sample_rate * (int64_t)s->streams[0]->time_base.num, s->streams[0]->time_base.den); avio_seek(pb, wav->fact_pos, SEEK_SET); avio_wl32(pb, number_of_samples); diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c index c673fad6df..c74b4404f9 100644 --- a/libavformat/wc3movie.c +++ b/libavformat/wc3movie.c @@ -169,27 +169,27 @@ static int wc3_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 33, 1, WC3_FRAME_FPS); wc3->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_XAN_WC3; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = wc3->width; - st->codec->height = wc3->height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_XAN_WC3; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = wc3->width; + st->codecpar->height = wc3->height; st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 33, 1, WC3_FRAME_FPS); wc3->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; - st->codec->codec_tag = 1; - st->codec->channels = WC3_AUDIO_CHANNELS; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->bits_per_coded_sample = WC3_AUDIO_BITS; - st->codec->sample_rate = WC3_SAMPLE_RATE; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * - st->codec->bits_per_coded_sample; - st->codec->block_align = WC3_AUDIO_BITS * WC3_AUDIO_CHANNELS; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_tag = 1; + st->codecpar->channels = WC3_AUDIO_CHANNELS; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->bits_per_coded_sample = WC3_AUDIO_BITS; + st->codecpar->sample_rate = WC3_SAMPLE_RATE; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = WC3_AUDIO_BITS * WC3_AUDIO_CHANNELS; return 0; } diff --git a/libavformat/westwood_aud.c b/libavformat/westwood_aud.c index 611d223238..bc8f40a954 100644 --- a/libavformat/westwood_aud.c +++ b/libavformat/westwood_aud.c @@ -107,23 +107,23 @@ static int wsaud_read_header(AVFormatContext *s) avpriv_request_sample(s, "Stereo WS-SND1"); return AVERROR_PATCHWELCOME; } - st->codec->codec_id = AV_CODEC_ID_WESTWOOD_SND1; + st->codecpar->codec_id = AV_CODEC_ID_WESTWOOD_SND1; break; case 99: - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_WS; - st->codec->bits_per_coded_sample = 4; - st->codec->bit_rate = channels * sample_rate * 4; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_WS; + st->codecpar->bits_per_coded_sample = 4; + st->codecpar->bit_rate = channels * sample_rate * 4; break; default: avpriv_request_sample(s, "Unknown codec: %d", codec); return AVERROR_PATCHWELCOME; } avpriv_set_pts_info(st, 64, 1, sample_rate); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = channels; - st->codec->channel_layout = channels == 1 ? AV_CH_LAYOUT_MONO : - AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = sample_rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = channels; + st->codecpar->channel_layout = channels == 1 ? AV_CH_LAYOUT_MONO : + AV_CH_LAYOUT_STEREO; + st->codecpar->sample_rate = sample_rate; return 0; } @@ -147,7 +147,7 @@ static int wsaud_read_packet(AVFormatContext *s, chunk_size = AV_RL16(&preamble[0]); - if (st->codec->codec_id == AV_CODEC_ID_WESTWOOD_SND1) { + if (st->codecpar->codec_id == AV_CODEC_ID_WESTWOOD_SND1) { /* For Westwood SND1 audio we need to add the output size and input size to the start of the packet to match what is in VQA. Specifically, this is needed to signal when a packet should be @@ -167,7 +167,7 @@ static int wsaud_read_packet(AVFormatContext *s, return AVERROR(EIO); /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ - pkt->duration = (chunk_size * 2) / st->codec->channels; + pkt->duration = (chunk_size * 2) / st->codecpar->channels; } pkt->stream_index = st->index; diff --git a/libavformat/westwood_vqa.c b/libavformat/westwood_vqa.c index 4323914675..9400956c92 100644 --- a/libavformat/westwood_vqa.c +++ b/libavformat/westwood_vqa.c @@ -93,23 +93,23 @@ static int wsvqa_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->start_time = 0; wsvqa->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_WS_VQA; - st->codec->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_WS_VQA; + st->codecpar->codec_tag = 0; /* no fourcc */ /* skip to the start of the VQA header */ avio_seek(pb, 20, SEEK_SET); /* the VQA header needs to go to the decoder */ - st->codec->extradata_size = VQA_HEADER_SIZE; - st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); - header = (unsigned char *)st->codec->extradata; - if (avio_read(pb, st->codec->extradata, VQA_HEADER_SIZE) != + st->codecpar->extradata_size = VQA_HEADER_SIZE; + st->codecpar->extradata = av_mallocz(VQA_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); + header = (unsigned char *)st->codecpar->extradata; + if (avio_read(pb, st->codecpar->extradata, VQA_HEADER_SIZE) != VQA_HEADER_SIZE) { return AVERROR(EIO); } - st->codec->width = AV_RL16(&header[6]); - st->codec->height = AV_RL16(&header[8]); + st->codecpar->width = AV_RL16(&header[6]); + st->codecpar->height = AV_RL16(&header[8]); fps = header[12]; st->nb_frames = st->duration = AV_RL16(&header[4]); @@ -204,30 +204,30 @@ static int wsvqa_read_packet(AVFormatContext *s, wsvqa->channels = 1; if (!wsvqa->bps) wsvqa->bps = 8; - st->codec->sample_rate = wsvqa->sample_rate; - st->codec->bits_per_coded_sample = wsvqa->bps; - st->codec->channels = wsvqa->channels; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->sample_rate = wsvqa->sample_rate; + st->codecpar->bits_per_coded_sample = wsvqa->bps; + st->codecpar->channels = wsvqa->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); switch (chunk_type) { case SND0_TAG: if (wsvqa->bps == 16) - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; else - st->codec->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; break; case SND1_TAG: - st->codec->codec_id = AV_CODEC_ID_WESTWOOD_SND1; + st->codecpar->codec_id = AV_CODEC_ID_WESTWOOD_SND1; break; case SND2_TAG: - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_WS; - st->codec->extradata_size = 2; - st->codec->extradata = av_mallocz(2 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_WS; + st->codecpar->extradata_size = 2; + st->codecpar->extradata = av_mallocz(2 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - AV_WL16(st->codec->extradata, wsvqa->version); + AV_WL16(st->codecpar->extradata, wsvqa->version); break; } } diff --git a/libavformat/wtv.c b/libavformat/wtv.c index 67a4cef5f2..eaae2a4277 100644 --- a/libavformat/wtv.c +++ b/libavformat/wtv.c @@ -486,14 +486,14 @@ static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length) if (!st) goto done; av_dict_set(&st->metadata, "title", description, 0); - st->codec->codec_id = AV_CODEC_ID_MJPEG; - st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; - st->codec->extradata = av_mallocz(filesize); + st->codecpar->codec_id = AV_CODEC_ID_MJPEG; + st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT; + st->codecpar->extradata = av_mallocz(filesize); st->id = -1; - if (!st->codec->extradata) + if (!st->codecpar->extradata) goto done; - st->codec->extradata_size = filesize; - avio_read(pb, st->codec->extradata, filesize); + st->codecpar->extradata_size = filesize; + avio_read(pb, st->codecpar->extradata, filesize); done: avio_seek(pb, pos + length, SEEK_SET); } @@ -597,23 +597,23 @@ static int parse_videoinfoheader2(AVFormatContext *s, AVStream *st) static void parse_mpeg1waveformatex(AVStream *st) { /* fwHeadLayer */ - switch (AV_RL16(st->codec->extradata)) { - case 0x0001 : st->codec->codec_id = AV_CODEC_ID_MP1; break; - case 0x0002 : st->codec->codec_id = AV_CODEC_ID_MP2; break; - case 0x0004 : st->codec->codec_id = AV_CODEC_ID_MP3; break; + switch (AV_RL16(st->codecpar->extradata)) { + case 0x0001 : st->codecpar->codec_id = AV_CODEC_ID_MP1; break; + case 0x0002 : st->codecpar->codec_id = AV_CODEC_ID_MP2; break; + case 0x0004 : st->codecpar->codec_id = AV_CODEC_ID_MP3; break; } - st->codec->bit_rate = AV_RL32(st->codec->extradata + 2); /* dwHeadBitrate */ + st->codecpar->bit_rate = AV_RL32(st->codecpar->extradata + 2); /* dwHeadBitrate */ /* dwHeadMode */ - switch (AV_RL16(st->codec->extradata + 6)) { + switch (AV_RL16(st->codecpar->extradata + 6)) { case 1 : case 2 : - case 4 : st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + case 4 : st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; break; - case 8 : st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + case 8 : st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; break; } } @@ -626,9 +626,9 @@ static void parse_mpeg1waveformatex(AVStream *st) static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int codec_type) { if (st) { - if (st->codec->extradata) { - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; + if (st->codecpar->extradata) { + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; } } else { WtvStream *wst = av_mallocz(sizeof(WtvStream)); @@ -642,7 +642,7 @@ static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int code st->id = sid; st->priv_data = wst; } - st->codec->codec_type = codec_type; + st->codecpar->codec_type = codec_type; st->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 10000000); return st; @@ -687,7 +687,7 @@ static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid, if (!st) return NULL; if (!ff_guidcmp(formattype, format_waveformatex)) { - int ret = ff_get_wav_header(s, pb, st->codec, size); + int ret = ff_get_wav_header(s, pb, st->codecpar, size); if (ret < 0) return NULL; } else { @@ -697,15 +697,15 @@ static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid, } if (!memcmp(subtype + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) { - st->codec->codec_id = ff_wav_codec_get_id(AV_RL32(subtype), st->codec->bits_per_coded_sample); + st->codecpar->codec_id = ff_wav_codec_get_id(AV_RL32(subtype), st->codecpar->bits_per_coded_sample); } else if (!ff_guidcmp(subtype, mediasubtype_mpeg1payload)) { - if (st->codec->extradata && st->codec->extradata_size >= 22) + if (st->codecpar->extradata && st->codecpar->extradata_size >= 22) parse_mpeg1waveformatex(st); else av_log(s, AV_LOG_WARNING, "MPEG1WAVEFORMATEX underflow\n"); } else { - st->codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subtype); - if (st->codec->codec_id == AV_CODEC_ID_NONE) + st->codecpar->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subtype); + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) av_log(s, AV_LOG_WARNING, "unknown subtype:"FF_PRI_GUID"\n", FF_ARG_GUID(subtype)); } return st; @@ -726,11 +726,11 @@ static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid, } if (!memcmp(subtype + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) { - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(subtype)); + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(subtype)); } else { - st->codec->codec_id = ff_codec_guid_get_id(video_guids, subtype); + st->codecpar->codec_id = ff_codec_guid_get_id(video_guids, subtype); } - if (st->codec->codec_id == AV_CODEC_ID_NONE) + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) av_log(s, AV_LOG_WARNING, "unknown subtype:"FF_PRI_GUID"\n", FF_ARG_GUID(subtype)); return st; } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_pes) && @@ -741,7 +741,7 @@ static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid, if (ff_guidcmp(formattype, format_none)) av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype)); avio_skip(pb, size); - st->codec->codec_id = AV_CODEC_ID_DVB_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_DVB_SUBTITLE; return st; } else if (!ff_guidcmp(mediatype, mediatype_mstvcaption) && (!ff_guidcmp(subtype, mediasubtype_teletext) || !ff_guidcmp(subtype, mediasubtype_dtvccdata))) { @@ -751,7 +751,7 @@ static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid, if (ff_guidcmp(formattype, format_none)) av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype)); avio_skip(pb, size); - st->codec->codec_id = AV_CODEC_ID_DVB_TELETEXT; + st->codecpar->codec_id = AV_CODEC_ID_DVB_TELETEXT; return st; } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_sections) && !ff_guidcmp(subtype, mediasubtype_mpeg2_sections)) { diff --git a/libavformat/wvdec.c b/libavformat/wvdec.c index e9a2a6227e..c78bac1ff9 100644 --- a/libavformat/wvdec.c +++ b/libavformat/wvdec.c @@ -227,12 +227,12 @@ static int wv_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_WAVPACK; - st->codec->channels = wc->chan; - st->codec->channel_layout = wc->chmask; - st->codec->sample_rate = wc->rate; - st->codec->bits_per_coded_sample = wc->bpp; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_WAVPACK; + st->codecpar->channels = wc->chan; + st->codecpar->channel_layout = wc->chmask; + st->codecpar->sample_rate = wc->rate; + st->codecpar->bits_per_coded_sample = wc->bpp; avpriv_set_pts_info(st, 64, 1, wc->rate); st->start_time = 0; st->duration = wc->header.total_samples; diff --git a/libavformat/wvenc.c b/libavformat/wvenc.c index 2e150e1a7a..a753c199db 100644 --- a/libavformat/wvenc.c +++ b/libavformat/wvenc.c @@ -29,7 +29,7 @@ typedef struct WvMuxContext { static av_cold int wv_write_header(AVFormatContext *ctx) { if (ctx->nb_streams > 1 || - ctx->streams[0]->codec->codec_id != AV_CODEC_ID_WAVPACK) { + ctx->streams[0]->codecpar->codec_id != AV_CODEC_ID_WAVPACK) { av_log(ctx, AV_LOG_ERROR, "This muxer only supports a single WavPack stream.\n"); return AVERROR(EINVAL); } diff --git a/libavformat/xa.c b/libavformat/xa.c index 57a36bcbe2..06b9c3f9bb 100644 --- a/libavformat/xa.c +++ b/libavformat/xa.c @@ -73,21 +73,21 @@ static int xa_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_EA_MAXIS_XA; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_EA_MAXIS_XA; avio_skip(pb, 4); /* Skip the XA ID */ xa->out_size = avio_rl32(pb); avio_skip(pb, 2); /* Skip the tag */ - st->codec->channels = avio_rl16(pb); - st->codec->sample_rate = avio_rl32(pb); + st->codecpar->channels = avio_rl16(pb); + st->codecpar->sample_rate = avio_rl32(pb); avio_skip(pb, 4); /* Skip average byte rate */ avio_skip(pb, 2); /* Skip block align */ avio_skip(pb, 2); /* Skip bits-per-sample */ - st->codec->bit_rate = av_clip(15LL * st->codec->channels * 8 * - st->codec->sample_rate / 28, 0, INT_MAX); + st->codecpar->bit_rate = av_clip(15LL * st->codecpar->channels * 8 * + st->codecpar->sample_rate / 28, 0, INT_MAX); - 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; return 0; @@ -105,7 +105,7 @@ static int xa_read_packet(AVFormatContext *s, if (xa->sent_bytes >= xa->out_size) return AVERROR_EOF; /* 1 byte header and 14 bytes worth of samples * number channels per block */ - packet_size = 15*st->codec->channels; + packet_size = 15*st->codecpar->channels; ret = av_get_packet(pb, pkt, packet_size); if(ret < 0) diff --git a/libavformat/xmv.c b/libavformat/xmv.c index b8e3191607..b2112b0e95 100644 --- a/libavformat/xmv.c +++ b/libavformat/xmv.c @@ -169,11 +169,11 @@ static int xmv_read_header(AVFormatContext *s) avpriv_set_pts_info(vst, 32, 1, 1000); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_WMV2; - vst->codec->codec_tag = MKBETAG('W', 'M', 'V', '2'); - vst->codec->width = avio_rl32(pb); - vst->codec->height = avio_rl32(pb); + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_WMV2; + vst->codecpar->codec_tag = MKBETAG('W', 'M', 'V', '2'); + vst->codecpar->width = avio_rl32(pb); + vst->codecpar->height = avio_rl32(pb); vst->duration = avio_rl32(pb); @@ -240,14 +240,14 @@ static int xmv_read_header(AVFormatContext *s) goto fail; } - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = track->codec_id; - ast->codec->codec_tag = track->compression; - ast->codec->channels = track->channels; - ast->codec->sample_rate = track->sample_rate; - ast->codec->bits_per_coded_sample = track->bits_per_sample; - ast->codec->bit_rate = track->bit_rate; - ast->codec->block_align = 36 * track->channels; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = track->codec_id; + ast->codecpar->codec_tag = track->compression; + ast->codecpar->channels = track->channels; + ast->codecpar->sample_rate = track->sample_rate; + ast->codecpar->bits_per_coded_sample = track->bits_per_sample; + ast->codecpar->bit_rate = track->bit_rate; + ast->codecpar->block_align = 36 * track->channels; avpriv_set_pts_info(ast, 32, track->block_samples, track->sample_rate); @@ -389,15 +389,15 @@ static int xmv_process_packet_header(AVFormatContext *s) assert(xmv->video.stream_index < s->nb_streams); - if (vst->codec->extradata_size < 4) { - av_free(vst->codec->extradata); + if (vst->codecpar->extradata_size < 4) { + av_free(vst->codecpar->extradata); - vst->codec->extradata = + vst->codecpar->extradata = av_malloc(4 + AV_INPUT_BUFFER_PADDING_SIZE); - vst->codec->extradata_size = 4; + vst->codecpar->extradata_size = 4; } - memcpy(vst->codec->extradata, xmv->video.extradata, 4); + memcpy(vst->codecpar->extradata, xmv->video.extradata, 4); } } } diff --git a/libavformat/xwma.c b/libavformat/xwma.c index b24cde857b..e6e72d9b52 100644 --- a/libavformat/xwma.c +++ b/libavformat/xwma.c @@ -75,7 +75,7 @@ static int xwma_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - ret = ff_get_wav_header(s, pb, st->codec, size); + ret = ff_get_wav_header(s, pb, st->codecpar, size); if (ret < 0) return ret; st->need_parsing = AVSTREAM_PARSE_NONE; @@ -85,9 +85,9 @@ static int xwma_read_header(AVFormatContext *s) * extradata for that. Thus, ask the user for feedback, but try to go on * anyway. */ - if (st->codec->codec_id != AV_CODEC_ID_WMAV2) { + if (st->codecpar->codec_id != AV_CODEC_ID_WMAV2) { avpriv_request_sample(s, "Unexpected codec (tag 0x04%x; id %d)", - st->codec->codec_tag, st->codec->codec_id); + st->codecpar->codec_tag, st->codecpar->codec_id); } else { /* In all xWMA files I have seen, there is no extradata. But the WMA * codecs require extradata, so we provide our own fake extradata. @@ -96,37 +96,37 @@ static int xwma_read_header(AVFormatContext *s) * there was, then try to use it, after asking the user to provide a * sample of this unusual file. */ - if (st->codec->extradata_size != 0) { + if (st->codecpar->extradata_size != 0) { /* Surprise, surprise: We *did* get some extradata. No idea * if it will work, but just go on and try it, after asking * the user for a sample. */ avpriv_request_sample(s, "Unexpected extradata (%d bytes)", - st->codec->extradata_size); + st->codecpar->extradata_size); } else { - st->codec->extradata_size = 6; - st->codec->extradata = av_mallocz(6 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata_size = 6; + st->codecpar->extradata = av_mallocz(6 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); /* setup extradata with our experimentally obtained value */ - st->codec->extradata[4] = 31; + st->codecpar->extradata[4] = 31; } } - if (!st->codec->channels) { + if (!st->codecpar->channels) { av_log(s, AV_LOG_WARNING, "Invalid channel count: %d\n", - st->codec->channels); + st->codecpar->channels); return AVERROR_INVALIDDATA; } - if (!st->codec->bits_per_coded_sample) { + if (!st->codecpar->bits_per_coded_sample) { av_log(s, AV_LOG_WARNING, "Invalid bits_per_coded_sample: %d\n", - st->codec->bits_per_coded_sample); + st->codecpar->bits_per_coded_sample); return AVERROR_INVALIDDATA; } /* set the sample rate */ - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); /* parse the remaining RIFF chunks */ for (;;) { @@ -146,7 +146,7 @@ static int xwma_read_header(AVFormatContext *s) * number of bytes accumulated after the corresponding xWMA packet * is decoded in order." * - * Each packet has size equal to st->codec->block_align, which in + * Each packet has size equal to st->codecpar->block_align, which in * all cases I saw so far was always 2230. Thus, we can use the * dpds data to compute a seeking index. */ @@ -200,7 +200,7 @@ static int xwma_read_header(AVFormatContext *s) if (dpds_table && dpds_table_size) { int64_t cur_pos; const uint32_t bytes_per_sample - = (st->codec->channels * st->codec->bits_per_coded_sample) >> 3; + = (st->codecpar->channels * st->codecpar->bits_per_coded_sample) >> 3; /* Estimate the duration from the total number of output bytes. */ const uint64_t total_decoded_bytes = dpds_table[dpds_table_size - 1]; @@ -208,7 +208,7 @@ static int xwma_read_header(AVFormatContext *s) if (!bytes_per_sample) { av_log(s, AV_LOG_ERROR, "Invalid bits_per_coded_sample %d for %d channels\n", - st->codec->bits_per_coded_sample, st->codec->channels); + st->codecpar->bits_per_coded_sample, st->codecpar->channels); ret = AVERROR_INVALIDDATA; goto fail; } @@ -231,18 +231,18 @@ static int xwma_read_header(AVFormatContext *s) * an offset / timestamp pair. */ av_add_index_entry(st, - cur_pos + (i+1) * st->codec->block_align, /* pos */ - dpds_table[i] / bytes_per_sample, /* timestamp */ - st->codec->block_align, /* size */ - 0, /* duration */ + cur_pos + (i+1) * st->codecpar->block_align, /* pos */ + dpds_table[i] / bytes_per_sample, /* timestamp */ + st->codecpar->block_align, /* size */ + 0, /* duration */ AVINDEX_KEYFRAME); } - } else if (st->codec->bit_rate) { + } else if (st->codecpar->bit_rate) { /* No dpds chunk was present (or only an empty one), so estimate * the total duration using the average bits per sample and the * total data length. */ - st->duration = (size<<3) * st->codec->sample_rate / st->codec->bit_rate; + st->duration = (size<<3) * st->codecpar->sample_rate / st->codecpar->bit_rate; } fail: @@ -266,7 +266,7 @@ static int xwma_read_packet(AVFormatContext *s, AVPacket *pkt) } /* read a single block; the default block size is 2230. */ - size = (st->codec->block_align > 1) ? st->codec->block_align : 2230; + size = (st->codecpar->block_align > 1) ? st->codecpar->block_align : 2230; size = FFMIN(size, left); ret = av_get_packet(s->pb, pkt, size); diff --git a/libavformat/yop.c b/libavformat/yop.c index 933c57d757..c782ecd77d 100644 --- a/libavformat/yop.c +++ b/libavformat/yop.c @@ -53,7 +53,7 @@ static int yop_read_header(AVFormatContext *s) YopDecContext *yop = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *audio_dec, *video_dec; + AVCodecParameters *audio_par, *video_par; AVStream *audio_stream, *video_stream; int frame_rate, ret; @@ -63,40 +63,40 @@ static int yop_read_header(AVFormatContext *s) // Extra data that will be passed to the decoder - video_stream->codec->extradata = av_mallocz(8 + AV_INPUT_BUFFER_PADDING_SIZE); + video_stream->codecpar->extradata = av_mallocz(8 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!video_stream->codec->extradata) + if (!video_stream->codecpar->extradata) return AVERROR(ENOMEM); - video_stream->codec->extradata_size = 8; + video_stream->codecpar->extradata_size = 8; // Audio - audio_dec = audio_stream->codec; - audio_dec->codec_type = AVMEDIA_TYPE_AUDIO; - audio_dec->codec_id = AV_CODEC_ID_ADPCM_IMA_APC; - audio_dec->channels = 1; - audio_dec->channel_layout = AV_CH_LAYOUT_MONO; - audio_dec->sample_rate = 22050; + audio_par = audio_stream->codecpar; + audio_par->codec_type = AVMEDIA_TYPE_AUDIO; + audio_par->codec_id = AV_CODEC_ID_ADPCM_IMA_APC; + audio_par->channels = 1; + audio_par->channel_layout = AV_CH_LAYOUT_MONO; + audio_par->sample_rate = 22050; // Video - video_dec = video_stream->codec; - video_dec->codec_type = AVMEDIA_TYPE_VIDEO; - video_dec->codec_id = AV_CODEC_ID_YOP; + video_par = video_stream->codecpar; + video_par->codec_type = AVMEDIA_TYPE_VIDEO; + video_par->codec_id = AV_CODEC_ID_YOP; avio_skip(pb, 6); frame_rate = avio_r8(pb); yop->frame_size = avio_r8(pb) * 2048; - video_dec->width = avio_rl16(pb); - video_dec->height = avio_rl16(pb); + video_par->width = avio_rl16(pb); + video_par->height = avio_rl16(pb); video_stream->sample_aspect_ratio = (AVRational){1, 2}; - ret = avio_read(pb, video_dec->extradata, 8); + ret = avio_read(pb, video_par->extradata, 8); if (ret < 8) return ret < 0 ? ret : AVERROR_EOF; - yop->palette_size = video_dec->extradata[0] * 3 + 4; - yop->audio_block_length = AV_RL16(video_dec->extradata + 6); + yop->palette_size = video_par->extradata[0] * 3 + 4; + yop->audio_block_length = AV_RL16(video_par->extradata + 6); // 1840 samples per frame, 1 nibble per sample; hence 1840/2 = 920 if (yop->audio_block_length < 920 || diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c index 0805274144..f30e188397 100644 --- a/libavformat/yuv4mpegdec.c +++ b/libavformat/yuv4mpegdec.c @@ -186,17 +186,17 @@ static int yuv4_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->width = width; - st->codec->height = height; + st->codecpar->width = width; + st->codecpar->height = height; av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1); avpriv_set_pts_info(st, 64, rated, raten); - st->avg_frame_rate = av_inv_q(st->time_base); - st->codec->pix_fmt = pix_fmt; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->sample_aspect_ratio = (AVRational){ aspectn, aspectd }; - st->codec->chroma_sample_location = chroma_sample_location; - st->codec->field_order = field_order; + st->avg_frame_rate = av_inv_q(st->time_base); + st->codecpar->format = pix_fmt; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->sample_aspect_ratio = (AVRational){ aspectn, aspectd }; + st->codecpar->chroma_location = chroma_sample_location; + st->codecpar->field_order = field_order; return 0; } @@ -225,10 +225,10 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return AVERROR_INVALIDDATA; - width = st->codec->width; - height = st->codec->height; + width = st->codecpar->width; + height = st->codecpar->height; - packet_size = av_image_get_buffer_size(st->codec->pix_fmt, + packet_size = av_image_get_buffer_size(st->codecpar->format, width, height, 1); if (packet_size < 0) return packet_size; diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c index 83f79d2ce3..8721c21227 100644 --- a/libavformat/yuv4mpegenc.c +++ b/libavformat/yuv4mpegenc.c @@ -35,8 +35,8 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf) const char *colorspace = ""; st = s->streams[0]; - width = st->codec->width; - height = st->codec->height; + width = st->codecpar->width; + height = st->codecpar->height; // TODO: should be avg_frame_rate av_reduce(&raten, &rated, st->time_base.den, @@ -48,13 +48,13 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf) if (aspectn == 0 && aspectd == 1) aspectd = 0; // 0:0 means unknown - switch (st->codec->field_order) { + switch (st->codecpar->field_order) { case AV_FIELD_TT: inter = 't'; break; case AV_FIELD_BB: inter = 'b'; break; default: inter = 'p'; break; } - switch (st->codec->pix_fmt) { + switch (st->codecpar->format) { case AV_PIX_FMT_GRAY8: colorspace = " Cmono"; break; @@ -62,7 +62,7 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf) colorspace = " C411 XYSCSS=411"; break; case AV_PIX_FMT_YUV420P: - switch (st->codec->chroma_sample_location) { + switch (st->codecpar->chroma_location) { case AVCHROMA_LOC_TOPLEFT: colorspace = " C420paldv XYSCSS=420PALDV"; break; case AVCHROMA_LOC_LEFT: colorspace = " C420mpeg2 XYSCSS=420MPEG2"; break; default: colorspace = " C420jpeg XYSCSS=420JPEG"; break; @@ -115,8 +115,8 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC); avio_write(pb, buf1, strlen(buf1)); - width = st->codec->width; - height = st->codec->height; + width = st->codecpar->width; + height = st->codecpar->height; ptr = frame->data[0]; for (i = 0; i < height; i++) { @@ -124,9 +124,9 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) ptr += frame->linesize[0]; } - if (st->codec->pix_fmt != AV_PIX_FMT_GRAY8) { + if (st->codecpar->format != AV_PIX_FMT_GRAY8) { // Adjust for smaller Cb and Cr planes - av_pix_fmt_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift, + av_pix_fmt_get_chroma_sub_sample(st->codecpar->format, &h_chroma_shift, &v_chroma_shift); // Shift right, rounding up width = AV_CEIL_RSHIFT(width, h_chroma_shift); @@ -153,18 +153,18 @@ static int yuv4_write_header(AVFormatContext *s) if (s->nb_streams != 1) return AVERROR(EIO); - if (s->streams[0]->codec->codec_id != AV_CODEC_ID_WRAPPED_AVFRAME) { + if (s->streams[0]->codecpar->codec_id != AV_CODEC_ID_WRAPPED_AVFRAME) { av_log(s, AV_LOG_ERROR, "ERROR: Codec not supported.\n"); return AVERROR_INVALIDDATA; } - if (s->streams[0]->codec->pix_fmt == AV_PIX_FMT_YUV411P) { + if (s->streams[0]->codecpar->format == AV_PIX_FMT_YUV411P) { av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV " "stream, some mjpegtools might not work.\n"); - } else if ((s->streams[0]->codec->pix_fmt != AV_PIX_FMT_YUV420P) && - (s->streams[0]->codec->pix_fmt != AV_PIX_FMT_YUV422P) && - (s->streams[0]->codec->pix_fmt != AV_PIX_FMT_GRAY8) && - (s->streams[0]->codec->pix_fmt != AV_PIX_FMT_YUV444P)) { + } else if ((s->streams[0]->codecpar->format != AV_PIX_FMT_YUV420P) && + (s->streams[0]->codecpar->format != AV_PIX_FMT_YUV422P) && + (s->streams[0]->codecpar->format != AV_PIX_FMT_GRAY8) && + (s->streams[0]->codecpar->format != AV_PIX_FMT_YUV444P)) { av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles yuv444p, " "yuv422p, yuv420p, yuv411p and gray pixel formats. " "Use -pix_fmt to select one.\n"); |