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/dv.c | |
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/dv.c')
-rw-r--r-- | libavformat/dv.c | 43 |
1 files changed, 21 insertions, 22 deletions
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; |