diff options
author | wm4 <wm4@nowhere> | 2013-02-09 15:15:37 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-02-10 17:25:57 +0100 |
commit | 01869d1391fc5cc843e132f9d05d6896ba5b4d6b (patch) | |
tree | 52220117ec9cb63328ab2a7cbbbcbec0ade61a85 /core | |
parent | dd61fac9438a0ba83513c9346debf73e7f9d2b4d (diff) | |
download | mpv-01869d1391fc5cc843e132f9d05d6896ba5b4d6b.tar.bz2 mpv-01869d1391fc5cc843e132f9d05d6896ba5b4d6b.tar.xz |
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
Diffstat (limited to 'core')
-rw-r--r-- | core/av_common.c | 34 | ||||
-rw-r--r-- | core/av_common.h | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/core/av_common.c b/core/av_common.c index 55fa5e086b..d67852eb86 100644 --- a/core/av_common.c +++ b/core/av_common.c @@ -23,6 +23,40 @@ #include "codecs.h" +// Copy the codec-related fields from st into avctx. This does not set the +// codec itself, only codec related header data provided by libavformat. +// The goal is to initialize a new decoder with the header data provided by +// libavformat, and unlike avcodec_copy_context(), allow the user to create +// a clean AVCodecContext for a manually selected AVCodec. +// This is strictly for decoding only. +void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st) +{ + if (st->extradata_size) { + av_free(avctx->extradata); + avctx->extradata_size = 0; + avctx->extradata = + av_mallocz(st->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + if (avctx->extradata) { + avctx->extradata_size = st->extradata_size; + memcpy(avctx->extradata, st->extradata, st->extradata_size); + } + } + avctx->codec_tag = st->codec_tag; + avctx->stream_codec_tag = st->stream_codec_tag; + avctx->bit_rate = st->bit_rate; + avctx->width = st->width; + avctx->height = st->height; + avctx->pix_fmt = st->pix_fmt; + avctx->sample_aspect_ratio = st->sample_aspect_ratio; + avctx->chroma_sample_location = st->chroma_sample_location; + avctx->sample_rate = st->sample_rate; + avctx->channels = st->channels; + avctx->block_align = st->block_align; + avctx->channel_layout = st->channel_layout; + avctx->audio_service_type = st->audio_service_type; + avctx->bits_per_coded_sample = st->bits_per_coded_sample; +} + #if !HAVE_AVCODEC_IS_DECODER_API static int av_codec_is_decoder(AVCodec *codec) { diff --git a/core/av_common.h b/core/av_common.h index 4fbe592f11..25593ed3d0 100644 --- a/core/av_common.h +++ b/core/av_common.h @@ -23,6 +23,7 @@ struct mp_decoder_list; +void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st); void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type); int mp_codec_to_av_codec_id(const char *codec); const char *mp_codec_from_av_codec_id(int codec_id); |