diff options
Diffstat (limited to 'demux')
-rw-r--r-- | demux/asfheader.c | 4 | ||||
-rw-r--r-- | demux/aviheader.c | 3 | ||||
-rw-r--r-- | demux/codec_tags.c | 379 | ||||
-rw-r--r-- | demux/codec_tags.h | 31 | ||||
-rw-r--r-- | demux/demux.c | 66 | ||||
-rw-r--r-- | demux/demux_lavf.c | 19 | ||||
-rw-r--r-- | demux/demux_mkv.c | 11 | ||||
-rw-r--r-- | demux/demux_mng.c | 4 | ||||
-rw-r--r-- | demux/demux_mpg.c | 5 | ||||
-rw-r--r-- | demux/demux_rawaudio.c | 15 | ||||
-rw-r--r-- | demux/demux_rawvideo.c | 14 | ||||
-rw-r--r-- | demux/demux_ts.c | 4 | ||||
-rw-r--r-- | demux/stheader.h | 14 |
13 files changed, 479 insertions, 90 deletions
diff --git a/demux/asfheader.c b/demux/asfheader.c index 9bbe8e3dce..e3f19840cd 100644 --- a/demux/asfheader.c +++ b/demux/asfheader.c @@ -349,6 +349,7 @@ static int asf_init_audio_stream(demuxer_t *demuxer,struct asf_priv* asf, sh_aud memcpy(sh_audio->wf,buffer,streamh->type_size); le2me_WAVEFORMATEX(sh_audio->wf); sh_audio->format=sh_audio->wf->wFormatTag; + mp_set_audio_codec_from_tag(sh_audio); if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf,MSGL_V); if(ASF_LOAD_GUID_PREFIX(streamh->concealment)==ASF_GUID_PREFIX_audio_conceal_interleave){ buffer = &hdr[pos]; @@ -516,6 +517,9 @@ int read_asf_header(demuxer_t *demuxer,struct asf_priv* asf){ sh_video->bih->biHeight; } sh_video->i_bps = asf->bps; + sh_video->format = sh_video->bih->biCompression; + mp_set_video_codec_from_tag(sh_video); + sh_video->format = mp_video_fourcc_alias(sh_video->format); if( mp_msg_test(MSGT_DEMUX,MSGL_V) ) print_video_header(sh_video->bih, MSGL_V); //asf_video_id=streamh.stream_no & 0x7F; diff --git a/demux/aviheader.c b/demux/aviheader.c index 7bf1803799..2226be25d4 100644 --- a/demux/aviheader.c +++ b/demux/aviheader.c @@ -279,6 +279,8 @@ while(1){ sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; sh_video->format = sh_video->bih->biCompression; + mp_set_video_codec_from_tag(sh_video); + sh_video->format = mp_video_fourcc_alias(sh_video->format); // if(demuxer->video->id==-1) demuxer->video->id=stream_id; // IdxFix: idxfix_videostream=stream_id; @@ -335,6 +337,7 @@ while(1){ if (sh_audio->format == 1 && last_fccHandler == mmioFOURCC('A', 'x', 'a', 'n')) sh_audio->format = last_fccHandler; + mp_set_audio_codec_from_tag(sh_audio); sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; chunksize=0; if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf,MSGL_V); diff --git a/demux/codec_tags.c b/demux/codec_tags.c new file mode 100644 index 0000000000..1719a4373f --- /dev/null +++ b/demux/codec_tags.c @@ -0,0 +1,379 @@ +/* + * This file is part of mpv. + * + * mpv is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mpv. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <libavformat/avformat.h> +#include <libavcodec/avcodec.h> +#include <libavutil/common.h> +#include "codec_tags.h" +#include "stheader.h" +#include "core/av_common.h" + +/* The following tables map FourCCs to codec names (as defined by libavcodec). + * However, this includes only names that are not defined by libavformat's + * RIFF tag tables, or which are mapped differently (for unknown reasons). + * These mappings were extracted from the codecs.conf file when it was removed, + * and these mappings have been maintained for years, meaning they are well + * tested and possibly make some files work. Or they could just be bugs. + * + * Note that demux_lavf does not use these tables, and always uses the native + * libavformat mappings. + * + * Note about internal mplayer FourCCs: + * + * These are made-up FourCCs which don't actually show up in files, but which + * were used by the original MPlayer to identify codecs. Since we don't quite + * know/care if there are still some uses of them left, they're still here. + */ + +struct mp_codec_tag { + uint32_t tag; + const char *codec; +}; + +static const struct mp_codec_tag mp_audio_codec_tags[] = { + {MKTAG('Q', 'D', 'M', '2'), "qdm2"}, + {MKTAG('Q', 'c', 'l', 'p'), "qcelp"}, + {MKTAG('s', 'q', 'c', 'p'), "qcelp"}, + {MKTAG('Q', 'c', 'l', 'q'), "qcelp"}, + {MKTAG('1', '4', '_', '4'), "ra_144"}, + {MKTAG('l', 'p', 'c', 'J'), "ra_144"}, + {MKTAG('2', '8', '_', '8'), "ra_288"}, + {MKTAG('c', 'o', 'o', 'k'), "cook"}, + {MKTAG('a', 't', 'r', 'c'), "atrac3"}, + {MKTAG('s', 'i', 'p', 'r'), "sipr"}, + {MKTAG('S', 'M', 'K', 'A'), "smackaudio"}, + {MKTAG('A', 'x', 'a', 'n'), "xan_dpcm"}, + {0x594a , "xan_dpcm"}, + {MKTAG('T', 'H', 'P', 'A'), "adpcm_thp"}, + {MKTAG('R', 'A', 'D', 'V'), "dvaudio"}, + {MKTAG('v', 'd', 'v', 'a'), "dvaudio"}, + {MKTAG('d', 'v', 'c', 'a'), "dvaudio"}, + {MKTAG('d', 'v', 'a', 'u'), "dvaudio"}, + {MKTAG('m', 'p', '4', 'a'), "aac"}, + {MKTAG('M', 'P', '4', 'A'), "aac"}, + {MKTAG('r', 'a', 'a', 'c'), "aac"}, + {MKTAG('r', 'a', 'c', 'p'), "aac"}, + {0xa106 , "aac"}, // libav 0.8: -, ffmpeg 1.1: aac + {0xaac0 , "aac"}, + {MKTAG('f', 'L', 'a', 'C'), "flac"}, + {MKTAG('m', 's', 241, 172), "flac"}, + {MKTAG('a', 'l', 'a', 'c'), "alac"}, + {MKTAG('A', 'P', 'E', ' '), "ape"}, + {MKTAG('d', 'a', 'u', 'd'), "pcm_s24daud"}, + {MKTAG('W', 'M', 'A', '3'), "wmapro"}, + {MKTAG('M', 'A', 'C', '3'), "mace3"}, + {MKTAG('M', 'A', 'C', '6'), "mace6"}, + {MKTAG('S', 'O', 'N', 'C'), "sonic"}, + {0x2048 , "sonic"}, // libav 0.8: -, ffmpeg 1.1: sonic + {MKTAG('T', 'S', 0 , 'U'), "mp3"}, + {MKTAG('G', 'S', 'M', ' '), "gsm"}, + {0x1500 , "gsm"}, // lavf: gsm_ms + {MKTAG('a', 'g', 's', 'm'), "gsm"}, + {0x32 , "gsm_ms"}, + {MKTAG(1 , 0 , 1 , 0 ), "pcm_dvd"}, + {MKTAG('B', 'S', 'S', 'D'), "s302m"}, + {MKTAG('A', 'C', '-', '3'), "ac3"}, + {MKTAG('d', 'n', 'e', 't'), "ac3"}, + {MKTAG('s', 'a', 'c', '3'), "ac3"}, + {MKTAG('E', 'A', 'C', '3'), "eac3"}, + {0x86 , "dts"}, + {MKTAG('M', 'P', 'C', ' '), "musepack7"}, + {MKTAG('M', 'P', 'C', '8'), "musepack8"}, + {MKTAG('M', 'P', 'C', 'K'), "musepack8"}, + {MKTAG('s', 'a', 'm', 'r'), "amr_nb"}, + {MKTAG('s', 'a', 'w', 'b'), "amr_wb"}, + {MKTAG('v', 'r', 'b', 's'), "vorbis"}, + // Special cased in ad_lavc: + {0 , "pcm"}, + {0x1 , "pcm"}, // lavf: pcm_s16le + {0x3 , "pcm"}, // lavf: pcm_f32le + {0xfffe , "pcm"}, + // ------- internal mplayer FourCCs ------ + {MKTAG('S', 'a', 'd', 'x'), "adpcm_adx"}, + {MKTAG('A', 'M', 'V', 'A'), "adpcm_ima_amv"}, + {MKTAG('R', 'o', 'Q', 'A'), "roq_dpcm"}, + {MKTAG('B', 'A', 'U', '1'), "binkaudio_dct"}, + {MKTAG('B', 'A', 'U', '2'), "binkaudio_rdft"}, + {MKTAG('D', 'C', 'I', 'A'), "dsicinaudio"}, + {MKTAG('4', 'X', 'M', 'A'), "adpcm_4xm"}, + {MKTAG('A', 'I', 'W', 'S'), "adpcm_ima_ws"}, + {MKTAG('S', 'N', 'D', '1'), "westwood_snd1"}, + {MKTAG('I', 'N', 'P', 'A'), "interplay_dpcm"}, + {MKTAG('A', 'D', 'E', 'A'), "adpcm_ea"}, + {MKTAG('A', 'D', 'X', 'A'), "adpcm_ea_maxis_xa"}, + {MKTAG('P', 'S', 'X', 'A'), "adpcm_xa"}, + {MKTAG('M', 'P', '4', 'L'), "aac_latm"}, + {MKTAG('T', 'T', 'A', '1'), "tta"}, + {MKTAG('W', 'V', 'P', 'K'), "wavpack"}, + {MKTAG('s', 'h', 'r', 'n'), "shorten"}, + {MKTAG('A', 'L', 'S', ' '), "mp4als"}, + {MKTAG('M', 'L', 'P', ' '), "mlp"}, + {MKTAG('T', 'R', 'H', 'D'), "truehd"}, + {MKTAG('N', 'E', 'L', 'L'), "nellymoser"}, + {MKTAG('m', '4', 'a', 29 ), "mp3on4"}, + {MKTAG('a', 'd', 'u', 'U'), "mp3adu"}, + {MKTAG('B', 'P', 'C', 'M'), "pcm_bluray"}, + {MKTAG('P', 'L', 'X', 'F'), "pcm_lxf"}, + {MKTAG('T', 'W', 'I', '2'), "twinvq"}, + {0x20776172, "pcm"}, // demux_mpg.c dvdpcm + {0}, +}; + +static const struct mp_codec_tag mp_video_codec_tags[] = { + {MKTAG('V', 'B', 'V', '1'), "vb"}, + {MKTAG('M', 'L', '2', '0'), "mimic"}, + {MKTAG('R', '1', '0', 'g'), "r10k"}, + {MKTAG('m', '1', 'v', '1'), "mpeg1video"}, + {MKTAG('m', 'p', 'g', '2'), "mpeg2video"}, // lavf: mpeg1video + {MKTAG('M', 'P', 'G', '2'), "mpeg2video"}, // lavf: mpeg1video + {MKTAG('m', 'x', '5', 'p'), "mpeg2video"}, + {MKTAG('h', 'd', 'v', '1'), "mpeg2video"}, + {MKTAG('h', 'd', 'v', '2'), "mpeg2video"}, + {MKTAG('h', 'd', 'v', '3'), "mpeg2video"}, + {MKTAG('h', 'd', 'v', '4'), "mpeg2video"}, + {MKTAG('h', 'd', 'v', '5'), "mpeg2video"}, + {MKTAG('h', 'd', 'v', '6'), "mpeg2video"}, + {MKTAG('h', 'd', 'v', '7'), "mpeg2video"}, + {MKTAG('h', 'd', 'v', '8'), "mpeg2video"}, + {MKTAG('h', 'd', 'v', '9'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', '1'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', '2'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', '3'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', '4'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', '5'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', '6'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', '7'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', '8'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', '9'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', 'a'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', 'b'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', 'c'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', 'd'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', 'e'), "mpeg2video"}, + {MKTAG('x', 'd', 'v', 'f'), "mpeg2video"}, + {MKTAG('x', 'd', '5', 'a'), "mpeg2video"}, + {MKTAG('x', 'd', '5', 'b'), "mpeg2video"}, + {MKTAG('x', 'd', '5', 'c'), "mpeg2video"}, + {MKTAG('x', 'd', '5', 'd'), "mpeg2video"}, + {MKTAG('x', 'd', '5', 'e'), "mpeg2video"}, + {MKTAG('x', 'd', '5', 'f'), "mpeg2video"}, + {MKTAG('x', 'd', '5', '9'), "mpeg2video"}, + {MKTAG('x', 'd', '5', '4'), "mpeg2video"}, + {MKTAG('x', 'd', '5', '5'), "mpeg2video"}, + {MKTAG('m', 'x', '5', 'n'), "mpeg2video"}, + {MKTAG('m', 'x', '4', 'n'), "mpeg2video"}, + {MKTAG('m', 'x', '4', 'p'), "mpeg2video"}, + {MKTAG('m', 'x', '3', 'n'), "mpeg2video"}, + {MKTAG('m', 'x', '3', 'p'), "mpeg2video"}, + {MKTAG('A', 'V', 'm', 'p'), "mpeg2video"}, + {MKTAG('V', 'C', 'R', '2'), "mpeg2video"}, // lavf: mpeg1video + {MKTAG('m', 'p', '2', 'v'), "mpeg2video"}, + {MKTAG('m', '2', 'v', '1'), "mpeg2video"}, + {MKTAG('R', 'J', 'P', 'G'), "nuv"}, + {MKTAG('b', 'm', 'p', ' '), "bmp"}, + {MKTAG('b', 'm', 'p', 0 ), "bmp"}, + {MKTAG('g', 'i', 'f', ' '), "gif"}, + {MKTAG('t', 'i', 'f', 'f'), "tiff"}, + {MKTAG('p', 'c', 'x', ' '), "pcx"}, + {MKTAG('m', 't', 'g', 'a'), "targa"}, + {MKTAG('M', 'T', 'G', 'A'), "targa"}, + {MKTAG('r', 'l', 'e', ' '), "qtrle"}, + {MKTAG('s', 'm', 'c', ' '), "smc"}, + {MKTAG('8', 'B', 'P', 'S'), "8bps"}, + {MKTAG('W', 'R', 'L', 'E'), "msrle"}, + {MKTAG('F', 'F', 'V', 'H'), "huffyuv"}, // lavf: ffvhuff + {MKTAG('P', 'I', 'X', 'L'), "vixl"}, + {MKTAG('X', 'I', 'X', 'L'), "vixl"}, + {MKTAG('q', 'd', 'r', 'w'), "qdraw"}, + {MKTAG('D', 'I', 'V', 'F'), "msmpeg4v3"}, + {MKTAG('d', 'i', 'v', 'f'), "msmpeg4v3"}, + {MKTAG('3', 'I', 'V', 'D'), "msmpeg4v3"}, + {MKTAG('3', 'i', 'v', 'd'), "msmpeg4v3"}, + {MKTAG('w', 'm', 'v', 'p'), "wmv3"}, // lavf: wmv3image + {MKTAG('W', 'M', 'V', 'P'), "wmv3"}, // lavf: wmv3image + {MKTAG('v', 'c', '-', '1'), "vc1"}, + {MKTAG('V', 'C', '-', '1'), "vc1"}, + {MKTAG('v', 'v', 'v', 'c'), "h264"}, + {MKTAG('a', 'i', '5', '5'), "h264"}, + {MKTAG('a', 'i', '1', '5'), "h264"}, + {MKTAG('a', 'i', '1', 'q'), "h264"}, + {MKTAG('a', 'i', '5', 'q'), "h264"}, + {MKTAG('a', 'i', '1', '2'), "h264"}, + {MKTAG(5 , 0 , 0 , 16 ), "h264"}, + {MKTAG('S', 'V', 'Q', '3'), "svq3"}, // libav 0.8: -, ffmpeg 1.1: svq3 + {MKTAG('d', 'r', 'a', 'c'), "dirac"}, // libav 0.8: -, ffmpeg 1.1: dirac + {MKTAG('A', 'V', 'R', 'n'), "mjpeg"}, // libav 0.8: mjpeg, ffmpeg 1.1: avrn + {MKTAG('A', 'V', 'D', 'J'), "mjpeg"}, + {MKTAG('A', 'D', 'J', 'V'), "mjpeg"}, + {MKTAG('J', 'F', 'I', 'F'), "mjpeg"}, + {MKTAG('M', 'J', 'L', 'S'), "mjpeg"}, // lavf: jpegls + {MKTAG('m', 'j', 'p', 'b'), "mjpegb"}, + {MKTAG('U', '2', '6', '3'), "h263"}, // libav 0.8: -, ffmpeg 1.1: h263 + {MKTAG('v', 'i', 'v', '1'), "h263"}, + {MKTAG('s', '2', '6', '3'), "h263"}, // libav 0.8: -, ffmpeg 1.1: flv1 + {MKTAG('S', '2', '6', '3'), "h263"}, // same + {MKTAG('D', '2', '6', '3'), "h263"}, + {MKTAG('I', 'L', 'V', 'R'), "h263"}, + {MKTAG('d', 'v', 'p', ' '), "dvvideo"}, + {MKTAG('d', 'v', 'p', 'p'), "dvvideo"}, + {MKTAG('A', 'V', 'd', 'v'), "dvvideo"}, + {MKTAG('A', 'V', 'd', '1'), "dvvideo"}, + {MKTAG('d', 'v', 'h', 'q'), "dvvideo"}, + {MKTAG('d', 'v', 'h', 'p'), "dvvideo"}, + {MKTAG('d', 'v', 'h', '5'), "dvvideo"}, + {MKTAG('d', 'v', 'h', '6'), "dvvideo"}, + {MKTAG('d', 'v', 'h', '3'), "dvvideo"}, + {MKTAG('d', 'v', 's', '1'), "dvvideo"}, + {MKTAG('R', 'V', '2', '0'), "rv20"}, + {MKTAG('r', 'v', '2', '0'), "rv20"}, + {MKTAG('R', 'V', 'T', 'R'), "rv20"}, + {MKTAG('R', 'V', '3', '0'), "rv30"}, + {MKTAG('r', 'v', '3', '0'), "rv30"}, + {MKTAG('R', 'V', '4', '0'), "rv40"}, + {MKTAG('r', 'v', '4', '0'), "rv40"}, + {MKTAG('R', 'V', '1', '0'), "rv10"}, + {MKTAG('r', 'v', '1', '0'), "rv10"}, + {MKTAG('R', 'V', '1', '3'), "rv10"}, + {MKTAG('r', 'v', '1', '3'), "rv10"}, + {MKTAG('T', 'h', 'r', 'a'), "theora"}, + {0xfffc , "theora"}, + {MKTAG('V', 'P', '6', 'A'), "vp6a"}, + {MKTAG('S', 'P', '5', '3'), "sp5x"}, + {MKTAG('S', 'P', '5', '5'), "sp5x"}, + {MKTAG('S', 'P', '5', '6'), "sp5x"}, + {MKTAG('S', 'P', '5', '7'), "sp5x"}, + {MKTAG('S', 'P', '5', '8'), "sp5x"}, + {MKTAG('S', 'M', 'K', '2'), "smackvideo"}, + {MKTAG('S', 'M', 'K', '4'), "smackvideo"}, + {MKTAG('a', 'v', 's', '2'), "cavs"}, + {MKTAG('A', 'V', 'd', 'n'), "dnxhd"}, + {MKTAG('a', 'p', 'c', 'h'), "prores"}, + {MKTAG('a', 'p', 'c', 'n'), "prores"}, + {MKTAG('a', 'p', 'c', 's'), "prores"}, + {MKTAG('a', 'p', 'c', 'o'), "prores"}, + {MKTAG('a', 'p', '4', 'h'), "prores"}, + {MKTAG('f', 'V', 'G', 'T'), "tgv"}, + // These are probably not correctly handled. The original codecs.conf + // entries mapped these to separate pixel formats via vd_raw and the + // "out" directive (look at MPlayer's codecs.conf). + // Should they be aliased to supported FourCCs of the same formats? + {MKTAG('A', 'V', '1', 'x'), "rawvideo"}, + {MKTAG('A', 'V', 'u', 'p'), "rawvideo"}, + {MKTAG('4', '4', '4', 'p'), "rawvideo"}, + {MKTAG('4', '4', '4', 'P'), "rawvideo"}, + {MKTAG('4', '2', '2', 'p'), "rawvideo"}, + {MKTAG('4', '2', '2', 'P'), "rawvideo"}, + // Unknown: + {MKTAG('r', 'a', 'w', ' '), "rawvideo"}, + {MKTAG('D', 'V', 'O', 'O'), "rawvideo"}, + // ------- internal mplayer FourCCs ------ + {MKTAG('A', 'N', 'M', ' '), "anm"}, + {MKTAG('B', 'I', 'K', 'f'), "binkvideo"}, + {MKTAG('B', 'I', 'K', 'g'), "binkvideo"}, + {MKTAG('B', 'I', 'K', 'h'), "binkvideo"}, + {MKTAG('B', 'I', 'K', 'i'), "binkvideo"}, + {MKTAG('C', 'D', 'G', 'R'), "cdgraphics"}, + {MKTAG('M', 'V', 'I', '1'), "motionpixels"}, + {MKTAG('M', 'D', 'E', 'C'), "mdec"}, + {MKTAG('N', 'U', 'V', '1'), "nuv"}, + {MKTAG('p', 't', 'x', ' '), "ptx"}, + {MKTAG('S', 'G', 'I', '1'), "sgi"}, + {MKTAG('s', 'u', 'n', ' '), "sunrast"}, + {MKTAG('F', 'L', 'I', 'C'), "flic"}, + {MKTAG('R', 'o', 'Q', 'V'), "roq"}, + {MKTAG('A', 'M', 'V', 'V'), "amv"}, + {MKTAG('F', 'F', 'J', 'V'), "jv"}, + {MKTAG('T', 'S', 'E', 'Q'), "tiertexseqvideo"}, + {MKTAG('V', 'M', 'D', 'V'), "vmdvideo"}, + {MKTAG('D', 'X', 'A', '1'), "dxa"}, + {MKTAG('D', 'C', 'I', 'V'), "dsicinvideo"}, + {MKTAG('T', 'H', 'P', 'V'), "thp"}, + {MKTAG('B', 'F', 'I', 'V'), "bfi"}, + {MKTAG('B', 'E', 'T', 'H'), "bethsoftvid"}, + {MKTAG('R', 'L', '2', 'V'), "rl2"}, + {MKTAG('T', 'X', 'D', 'V'), "txd"}, + {MKTAG('W', 'C', '3', 'V'), "xan_wc3"}, + {MKTAG('I', 'D', 'C', 'I'), "idcin"}, + {MKTAG('I', 'N', 'P', 'V'), "interplayvideo"}, + {MKTAG('V', 'Q', 'A', 'V'), "ws_vqa"}, + {MKTAG('C', '9', '3', 'V'), "c93"}, + {0}, +}; + +static const int mp_fourcc_video_aliases[][2] = { + // msmpeg4 + {MKTAG('M', 'P', 'G', '3'), MKTAG('d', 'i', 'v', '3')}, + {MKTAG('m', 'p', 'g', '3'), MKTAG('d', 'i', 'v', '3')}, + {MKTAG('M', 'P', '4', '3'), MKTAG('d', 'i', 'v', '3')}, + {MKTAG('m', 'p', '4', '3'), MKTAG('d', 'i', 'v', '3')}, + {MKTAG('D', 'I', 'V', '5'), MKTAG('d', 'i', 'v', '3')}, + {MKTAG('d', 'i', 'v', '5'), MKTAG('d', 'i', 'v', '3')}, + {MKTAG('D', 'I', 'V', '6'), MKTAG('d', 'i', 'v', '4')}, + {MKTAG('d', 'i', 'v', '6'), MKTAG('d', 'i', 'v', '4')}, + {MKTAG('A', 'P', '4', '1'), MKTAG('d', 'i', 'v', '3')}, + + // msmpeg4v2 + {MKTAG('D', 'I', 'V', '2'), MKTAG('m', 'p', '4', '2')}, + {MKTAG('d', 'i', 'v', '2'), MKTAG('m', 'p', '4', '2')}, + {MKTAG('D', 'I', 'V', '1'), MKTAG('d', 'i', 'v', 'x')}, + {MKTAG('d', 'i', 'v', '1'), MKTAG('d', 'i', 'v', 'x')}, + + // mpeg4 + {MKTAG('d', 'x', '5', '0'), MKTAG('D', 'X', '5', '0')}, + {MKTAG('B', 'L', 'Z', '0'), MKTAG('D', 'X', '5', '0')}, + + {MKTAG('v', 'i', 'v', '1'), MKTAG('h', '2', '6', '3')}, + {MKTAG('T', 'h', 'r', 'a'), MKTAG('t', 'h', 'e', 'o')}, + + {0}, +}; + +static const char *lookup_tag(const struct mp_codec_tag *mp_table, + const struct AVCodecTag *av_table, + uint32_t tag) +{ + for (int n = 0; mp_table[n].codec; n++) { + if (mp_table[n].tag == tag) + return mp_table[n].codec; + } + const struct AVCodecTag *av_tags[] = {av_table, NULL}; + int id = av_codec_get_id(av_tags, tag); + return id == CODEC_ID_NONE ? NULL : mp_codec_from_av_codec_id(id); +} + +void mp_set_video_codec_from_tag(struct sh_video *sh) +{ + sh->gsh->codec = lookup_tag(mp_video_codec_tags, + avformat_get_riff_video_tags(), + sh->format); +} + +void mp_set_audio_codec_from_tag(struct sh_audio *sh) +{ + sh->gsh->codec = lookup_tag(mp_audio_codec_tags, + avformat_get_riff_audio_tags(), + sh->format); +} + +uint32_t mp_video_fourcc_alias(uint32_t fourcc) +{ + for (int n = 0; mp_fourcc_video_aliases[n][0]; n++) { + if (mp_fourcc_video_aliases[n][0] == fourcc) + return mp_fourcc_video_aliases[n][1]; + } + return fourcc; +} diff --git a/demux/codec_tags.h b/demux/codec_tags.h new file mode 100644 index 0000000000..790dd03ae9 --- /dev/null +++ b/demux/codec_tags.h @@ -0,0 +1,31 @@ +/* + * This file is part of mpv. + * + * mpv is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mpv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MP_CODEC_TAGS_H +#define MP_CODEC_TAGS_H + +#include <stdint.h> + +uint32_t mp_video_fourcc_alias(uint32_t fourcc); + +struct sh_video; +struct sh_audio; + +void mp_set_audio_codec_from_tag(struct sh_audio *sh); +void mp_set_video_codec_from_tag(struct sh_video *sh); + +#endif 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; } diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 342d6231db..c0d62eeef5 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -38,6 +38,7 @@ #include "core/options.h" #include "core/mp_msg.h" #include "core/av_opts.h" +#include "core/av_common.h" #include "core/bstr.h" #include "stream/stream.h" @@ -344,8 +345,7 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) if (override_tag) codec->codec_tag = override_tag; - AVCodec *avc = avcodec_find_decoder(codec->codec_id); - const char *codec_name = avc ? avc->name : "unknown"; + const char *mp_codec = mp_codec_from_av_codec_id(codec->codec_id); bool set_demuxer_id = matches_avinputformat_name(priv, "mpeg"); @@ -356,12 +356,11 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) sh_audio = new_sh_audio_aid(demuxer, i, priv->audio_streams); if (!sh_audio) break; - sh_audio->demuxer_codecname = codec_name; if (set_demuxer_id) sh_audio->gsh->demuxer_id = st->id; stream_type = "audio"; priv->astreams[priv->audio_streams] = i; - sh_audio->libav_codec_id = codec->codec_id; + sh_audio->gsh->codec = mp_codec; sh_audio->gsh->lavf_codec_tag = lavf_codec_tag; wf = calloc(sizeof(*wf) + codec->extradata_size, 1); // mp4a tag is used for all mp4 files no matter what they actually contain @@ -430,12 +429,11 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) sh_video = new_sh_video_vid(demuxer, i, priv->video_streams); if (!sh_video) break; - sh_video->demuxer_codecname = codec_name; if (set_demuxer_id) sh_video->gsh->demuxer_id = st->id; stream_type = "video"; priv->vstreams[priv->video_streams] = i; - sh_video->libav_codec_id = codec->codec_id; + sh_video->gsh->codec = mp_codec; sh_video->gsh->lavf_codec_tag = lavf_codec_tag; if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) sh_video->gsh->attached_picture = true; @@ -547,12 +545,11 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) sh_sub = new_sh_sub_sid(demuxer, i, priv->sub_streams); if (!sh_sub) break; - sh_sub->demuxer_codecname = codec_name; if (set_demuxer_id) sh_sub->gsh->demuxer_id = st->id; stream_type = "subtitle"; priv->sstreams[priv->sub_streams] = i; - sh_sub->libav_codec_id = codec->codec_id; + sh_sub->gsh->codec = mp_codec; sh_sub->gsh->lavf_codec_tag = lavf_codec_tag; sh_sub->type = type; if (codec->extradata_size) { @@ -590,10 +587,8 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) st->discard = AVDISCARD_ALL; } if (stream_type) { - if (!avc && *stream_type == 's' && demuxer->s_streams[i]) - codec_name = sh_sub_type2str((demuxer->s_streams[i])->type); - mp_msg(MSGT_DEMUX, MSGL_V, "[lavf] stream %d: %s (%s), -%cid %d", - i, stream_type, codec_name, *stream_type, stream_id); + mp_msg(MSGT_DEMUX, MSGL_V, "[lavf] stream %d: %s, -%cid %d", + i, stream_type, *stream_type, stream_id); if (lang && lang->value && *stream_type != 'v') mp_msg(MSGT_DEMUX, MSGL_V, ", -%clang %s", *stream_type, lang->value); diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index c635601986..824d6df6ee 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -1261,13 +1261,14 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track, sh_v = new_sh_video(demuxer, vid); sh_v->gsh->demuxer_id = track->tnum; - sh_v->demuxer_codecname = track->codec_id; sh_v->gsh->title = talloc_strdup(sh_v, track->name); sh_v->bih = bih; sh_v->format = sh_v->bih->biCompression; if (raw) { - sh_v->format = mmioFOURCC('M', 'P', 'r', 'v'); - sh_v->imgfmt = sh_v->bih->biCompression; + sh_v->gsh->codec = "rawvideo"; + } else { + mp_set_video_codec_from_tag(sh_v); + sh_v->format = mp_video_fourcc_alias(sh_v->format); } if (track->v_frate == 0.0) track->v_frate = 25.0; @@ -1338,7 +1339,6 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track, if (track->language && (strcmp(track->language, "und") != 0)) sh_a->lang = talloc_strdup(sh_a, track->language); sh_a->gsh->demuxer_id = track->tnum; - sh_a->demuxer_codecname = track->codec_id; sh_a->gsh->title = talloc_strdup(sh_a, track->name); sh_a->gsh->default_track = track->default_track; sh_a->ds = demuxer->audio; @@ -1569,6 +1569,8 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track, goto error; } + mp_set_audio_codec_from_tag(sh_a); + return 0; error: @@ -1586,7 +1588,6 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer; sh_sub_t *sh = new_sh_sub(demuxer, sid); sh->gsh->demuxer_id = track->tnum; - sh->demuxer_codecname = track->codec_id; track->sh_sub = sh; sh->type = track->subtitle_type; size = track->private_size; diff --git a/demux/demux_mng.c b/demux/demux_mng.c index 74f633d64e..5863cbc9c1 100644 --- a/demux/demux_mng.c +++ b/demux/demux_mng.c @@ -437,8 +437,8 @@ static demuxer_t * demux_mng_open(demuxer_t * demuxer) sh_video->ds = demuxer->video; // set format of pixels in video packets - sh_video->format = MP_FOURCC_RAWVIDEO; - sh_video->imgfmt = MP_FOURCC_RGB32; + sh_video->gsh->codec = "rawvideo"; + sh_video->format = MP_FOURCC_RGB32; // set framerate to some value (MNG does not have a fixed framerate) sh_video->fps = 5.0f; diff --git a/demux/demux_mpg.c b/demux/demux_mpg.c index 4223a33c92..458ed9f926 100644 --- a/demux/demux_mpg.c +++ b/demux/demux_mpg.c @@ -282,6 +282,7 @@ static void new_audio_stream(demuxer_t *demux, int aid){ if((aid & 0xC0) == 0xC0) sh_a->format=0x2000; else if(aid >= 0x98 && aid <= 0x9f) sh_a->format=0x2001; if (mpg_d) mpg_d->a_stream_ids[mpg_d->num_a_streams++] = aid; + mp_set_audio_codec_from_tag(sh_a); } if(demux->audio->id==-1) demux->audio->id=aid; } @@ -487,6 +488,7 @@ static int demux_mpg_read_packet(demuxer_t *demux,int id){ if(priv && ds->sh) { sh_video_t *sh = (sh_video_t *)ds->sh; sh->format = mmioFOURCC('W', 'V', 'C', '1'); + mp_set_video_codec_from_tag(sh); } } } @@ -604,6 +606,7 @@ static int demux_mpg_read_packet(demuxer_t *demux,int id){ sh->format = priv->es_map[id - 0x1B0]; mp_dbg(MSGT_DEMUX,MSGL_DBG2,"ASSIGNED TO STREAM %d CODEC %x\n", id, priv->es_map[id - 0x1B0]); dvdpcm_header(sh); + mp_set_audio_codec_from_tag(sh); } } } else @@ -619,6 +622,7 @@ static int demux_mpg_read_packet(demuxer_t *demux,int id){ sh_video_t *sh = (sh_video_t *)ds->sh; if(priv->es_map[id - 0x1B0]) { sh->format = priv->es_map[id - 0x1B0]; + mp_set_video_codec_from_tag(sh); mp_dbg(MSGT_DEMUX,MSGL_DBG2,"ASSIGNED TO STREAM %d CODEC %x\n", id, priv->es_map[id - 0x1B0]); } } @@ -1186,6 +1190,7 @@ static demuxer_t* demux_mpg_ps_open(demuxer_t* demuxer) num_elementary_packets1B6==0) sh_video->format = 0x10000005; else sh_video->format = 0x10000002; + mp_set_video_codec_from_tag(sh_video); } return demuxer; diff --git a/demux/demux_rawaudio.c b/demux/demux_rawaudio.c index 6afcfce470..c6aad60806 100644 --- a/demux/demux_rawaudio.c +++ b/demux/demux_rawaudio.c @@ -51,17 +51,16 @@ static demuxer_t* demux_rawaudio_open(demuxer_t* demuxer) { return NULL; sh_audio = new_sh_audio(demuxer,0); + sh_audio->gsh->codec = "mp-pcm"; + sh_audio->format = format; sh_audio->wf = w = malloc(sizeof(*w)); - // Not a WAVEFORMATEX format; just abuse it to pass the internal mplayer - // format to ad_pcm.c - w->wFormatTag = format; - sh_audio->format = MKTAG('M', 'P', 'a', 'f'); + w->wFormatTag = 0; w->nChannels = sh_audio->channels = channels; w->nSamplesPerSec = sh_audio->samplerate = samplerate; - sh_audio->samplesize = (af_fmt2bits(format) + 7) / 8; - w->nAvgBytesPerSec = samplerate * sh_audio->samplesize * channels; - w->nBlockAlign = channels * sh_audio->samplesize; - w->wBitsPerSample = 8 * sh_audio->samplesize; + int samplesize = (af_fmt2bits(format) + 7) / 8; + w->nAvgBytesPerSec = samplerate * samplesize * channels; + w->nBlockAlign = channels * samplesize; + w->wBitsPerSample = 8 * samplesize; w->cbSize = 0; demuxer->movi_start = demuxer->stream->start_pos; diff --git a/demux/demux_rawvideo.c b/demux/demux_rawvideo.c index 47d32f933e..43b2ca0cae 100644 --- a/demux/demux_rawvideo.c +++ b/demux/demux_rawvideo.c @@ -81,10 +81,11 @@ static demuxer_t* demux_rawvideo_open(demuxer_t* demuxer) { return 0; } - int tag, fmt; + const char *decoder = "rawvideo"; + int imgfmt = format; if (mp_format) { - tag = MP_FOURCC_IMGFMT; - fmt = mp_format; + decoder = "mp-rawvideo"; + imgfmt = mp_format; if (!imgsize) { struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(mp_format); for (int p = 0; p < desc.num_planes; p++) { @@ -92,9 +93,6 @@ static demuxer_t* demux_rawvideo_open(demuxer_t* demuxer) { desc.bpp[p] + 7) / 8; } } - } else { - tag = MP_FOURCC_RAWVIDEO; - fmt = format; } if (!imgsize) { @@ -131,8 +129,8 @@ static demuxer_t* demux_rawvideo_open(demuxer_t* demuxer) { } sh_video = new_sh_video(demuxer,0); - sh_video->format=tag; - sh_video->imgfmt=fmt; + sh_video->gsh->codec=decoder; |