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/dvenc.c | |
parent | a8068346e48e123f8d3bdf4d64464d81e53e5fc7 (diff) |
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
Diffstat (limited to 'libavformat/dvenc.c')
-rw-r--r-- | libavformat/dvenc.c | 25 |
1 files changed, 13 insertions, 12 deletions
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); |