From 4d016a92c876e98797c362d05468bf27d5a85414 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 9 Feb 2013 15:15:19 +0100 Subject: core: redo how codecs are mapped, remove codecs.conf Use codec names instead of FourCCs to identify codecs. Rewrite how codecs are selected and initialized. Now each decoder exports a list of decoders (and the codec it supports) via add_decoders(). The order matters, and the first decoder for a given decoder is preferred over the other decoders. E.g. all ad_mpg123 decoders are preferred over ad_lavc, because it comes first in the mpcodecs_ad_drivers array. Likewise, decoders within ad_lavc that are enumerated first by libavcodec (using av_codec_next()) are preferred. (This is actually critical to select h264 software decoding by default instead of vdpau. libavcodec and ffmpeg/avconv use the same method to select decoders by default, so we hope this is sane.) The codec names follow libavcodec's codec names as defined by AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders have names different from the canonical codec name. The AVCodecDescriptor API is relatively new, so we need a compatibility layer for older libavcodec versions for codec names that are referenced internally, and which are different from the decoder name. (Add a configure check for that, because checking versions is getting way too messy.) demux/codec_tags.c is generated from the former codecs.conf (minus "special" decoders like vdpau, and excluding the mappings that are the same as the mappings libavformat's exported RIFF tables). It contains all the mappings from FourCCs to codec name. This is needed for demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the codec as determined by libavformat, while the other demuxers have to do this on their own, using the mp_set_audio/video_codec_from_tag() functions. Note that the sh_audio/video->format members don't uniquely identify the codec anymore, and sh->codec takes over this role. Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which provide cover the functionality of the removed switched. Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure container/video combinations (e.g. the sample Film_200_zygo_pro.mov) are played flipped. ffplay/avplay doesn't handle this properly either, so we don't care and blame ffmeg/libav instead. --- demux/demux.c | 66 +++++++++++++++-------------------------------------------- 1 file changed, 16 insertions(+), 50 deletions(-) (limited to 'demux/demux.c') diff --git a/demux/demux.c b/demux/demux.c index af710131b9..32ef281f8c 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -29,6 +29,7 @@ #include "config.h" #include "core/options.h" +#include "core/av_common.h" #include "talloc.h" #include "core/mp_msg.h" @@ -485,63 +486,28 @@ void ds_add_packet(demux_stream_t *ds, demux_packet_t *dp) ds->demuxer->video->packs); } -static void allocate_parser(AVCodecContext **avctx, AVCodecParserContext **parser, unsigned format) +static void allocate_parser(AVCodecContext **avctx, AVCodecParserContext **parser, const char *format) { - enum CodecID codec_id = CODEC_ID_NONE; + enum CodecID codec_id = mp_codec_to_av_codec_id(format); - switch (format) { - case MKTAG('M', 'P', '4', 'L'): - codec_id = CODEC_ID_AAC_LATM; - break; - case 0x2000: - case 0x332D6361: - case 0x332D4341: - case 0x20736D: - case MKTAG('s', 'a', 'c', '3'): - codec_id = CODEC_ID_AC3; - break; - case MKTAG('d', 'n', 'e', 't'): - // DNET/byte-swapped AC-3 - there is no parser for that yet - //codec_id = CODEC_ID_DNET; - break; - case MKTAG('E', 'A', 'C', '3'): - codec_id = CODEC_ID_EAC3; - break; - case 0x2001: - case 0x86: - codec_id = CODEC_ID_DTS; - break; - case MKTAG('f', 'L', 'a', 'C'): - codec_id = CODEC_ID_FLAC; - break; - case MKTAG('M', 'L', 'P', ' '): - codec_id = CODEC_ID_MLP; - break; - case 0x55: - case 0x5500736d: - case 0x55005354: - case MKTAG('.', 'm', 'p', '3'): - case MKTAG('M', 'P', '3', ' '): - case MKTAG('L', 'A', 'M', 'E'): - codec_id = CODEC_ID_MP3; - break; - case 0x50: - case 0x5000736d: - case MKTAG('.', 'm', 'p', '2'): - case MKTAG('.', 'm', 'p', '1'): - codec_id = CODEC_ID_MP2; - break; - case MKTAG('T', 'R', 'H', 'D'): - codec_id = CODEC_ID_TRUEHD; - break; - } - if (codec_id != CODEC_ID_NONE) { + switch (codec_id) { + case CODEC_ID_AAC_LATM: + case CODEC_ID_AC3: + case CODEC_ID_EAC3: + case CODEC_ID_DTS: + case CODEC_ID_FLAC: + case CODEC_ID_MLP: + case CODEC_ID_MP3: + case CODEC_ID_MP2: + case CODEC_ID_TRUEHD: *avctx = avcodec_alloc_context3(NULL); if (!*avctx) return; *parser = av_parser_init(codec_id); if (!*parser) av_freep(avctx); + break; + default: ; } } @@ -558,7 +524,7 @@ static void get_parser(sh_common_t *sh, AVCodecContext **avctx, AVCodecParserCon if (*parser) return; - allocate_parser(avctx, parser, sh->format); + allocate_parser(avctx, parser, sh->gsh->codec); sh->avctx = *avctx; sh->parser = *parser; } -- cgit v1.2.3