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.
This commit is contained in:
wm4
2013-02-09 15:15:37 +01:00
parent dd61fac943
commit 01869d1391
10 changed files with 81 additions and 283 deletions

View File

@@ -221,24 +221,23 @@ static int init(sh_audio_t *sh_audio, const char *decoder)
lavc_context = avcodec_alloc_context3(lavc_codec);
ctx->avctx = lavc_context;
ctx->avframe = avcodec_alloc_frame();
lavc_context->codec_type = AVMEDIA_TYPE_AUDIO;
lavc_context->codec_id = lavc_codec->id;
lavc_context->request_channels = opts->audio_output_channels;
// Always try to set - option only exists for AC3 at the moment
av_opt_set_double(lavc_context, "drc_scale", opts->drc_level,
AV_OPT_SEARCH_CHILDREN);
lavc_context->codec_tag = sh_audio->format;
lavc_context->sample_rate = sh_audio->samplerate;
lavc_context->bit_rate = sh_audio->i_bps * 8;
lavc_context->request_channels = opts->audio_output_channels;
lavc_context->codec_tag = sh_audio->format; //FOURCC
if (sh_audio->gsh->lavf_codec_tag)
lavc_context->codec_tag = sh_audio->gsh->lavf_codec_tag;
lavc_context->codec_type = AVMEDIA_TYPE_AUDIO;
lavc_context->codec_id = lavc_codec->id; // not sure if required, imho not --A'rpi
if (sh_audio->wf)
set_from_wf(lavc_context, sh_audio->wf);
// for QDM2
// demux_mkv, demux_mpg
if (sh_audio->codecdata_len && sh_audio->codecdata &&
!lavc_context->extradata) {
lavc_context->extradata = av_malloc(sh_audio->codecdata_len +
@@ -248,6 +247,9 @@ static int init(sh_audio_t *sh_audio, const char *decoder)
lavc_context->extradata_size);
}
if (sh_audio->gsh->lav_headers)
mp_copy_lav_codec_headers(lavc_context, sh_audio->gsh->lav_headers);
/* open it */
if (avcodec_open2(lavc_context, lavc_codec, NULL) < 0) {
mp_tmsg(MSGT_DECAUDIO, MSGL_ERR, "Could not open codec.\n");