diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-12-10 01:25:15 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-12-10 02:01:03 +0100 |
commit | c59b80c8d3e46f176172d582f27c14d772e306fc (patch) | |
tree | 8457ccf4abee25effcc243b22764b969127493d7 /libavformat | |
parent | 5b98ea1b7309fd43694b92e990439636630f408a (diff) | |
parent | 4c386333529dd773e673e1366d1f6243d2c5af92 (diff) | |
download | ffmpeg-c59b80c8d3e46f176172d582f27c14d772e306fc.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
isom: sort and pretty-print codec_movaudio_tags[]
isom: remove pointless comments in codec_movaudio_tags[]
isom: remove commented-out tag for vorbis
movenc: write 'chan' tag for AC-3 in MOV
mov: add support for reading and writing the 'chan' tag
audioconvert: add some additional channel and channel layout macros
audioconvert: change 7.1 "wide" layout to use side surround channels
movenc: simplify handling of pcm vs. adpcm vs. other compressed codecs
doc: update documentation to use avconv
doc: update demuxers section
doc: extend external library coverage
doc: split platform specific information
doc: port the git-howto to texinfo
doc: provide fallback css and customize @float
doc: document fate in a texinfo
doxy: change hue value to match our green
Conflicts:
doc/fate.txt
doc/ffserver.texi
doc/general.texi
doc/muxers.texi
doc/protocols.texi
doc/t2h.init
libavformat/isom.c
libavformat/mov.c
libavutil/avutil.h
tests/ref/acodec/pcm_s16be
tests/ref/acodec/pcm_s24be
tests/ref/acodec/pcm_s32be
tests/ref/acodec/pcm_s8
tests/ref/lavf/mov
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/Makefile | 5 | ||||
-rw-r--r-- | libavformat/isom.c | 101 | ||||
-rw-r--r-- | libavformat/mov.c | 50 | ||||
-rw-r--r-- | libavformat/mov_chan.c | 505 | ||||
-rw-r--r-- | libavformat/mov_chan.h | 55 | ||||
-rw-r--r-- | libavformat/movenc.c | 88 |
6 files changed, 699 insertions, 105 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile index 4e3a1836ad..ca66a39677 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -148,9 +148,10 @@ OBJS-$(CONFIG_MLP_MUXER) += rawenc.o OBJS-$(CONFIG_MM_DEMUXER) += mm.o OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o pcm.o OBJS-$(CONFIG_MMF_MUXER) += mmf.o riff.o -OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o +OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o mov_chan.o OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o avc.o \ - movenchint.o rtpenc_chain.o + movenchint.o rtpenc_chain.o \ + mov_chan.o OBJS-$(CONFIG_MP2_MUXER) += mp3enc.o rawenc.o OBJS-$(CONFIG_MP3_DEMUXER) += mp3dec.o OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o diff --git a/libavformat/isom.c b/libavformat/isom.c index 8e5e14514d..7a625780f3 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -224,64 +224,49 @@ const AVCodecTag codec_movvideo_tags[] = { }; const AVCodecTag codec_movaudio_tags[] = { - { CODEC_ID_PCM_S32BE, MKTAG('i', 'n', '3', '2') }, - { CODEC_ID_PCM_S32LE, MKTAG('i', 'n', '3', '2') }, - { CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') }, - { CODEC_ID_PCM_S24LE, MKTAG('i', 'n', '2', '4') }, - { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */ - { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */ - { CODEC_ID_PCM_S16LE, MKTAG('l', 'p', 'c', 'm') }, - { CODEC_ID_PCM_F32BE, MKTAG('f', 'l', '3', '2') }, - { CODEC_ID_PCM_F32LE, MKTAG('f', 'l', '3', '2') }, - { CODEC_ID_PCM_F64BE, MKTAG('f', 'l', '6', '4') }, - { CODEC_ID_PCM_F64LE, MKTAG('f', 'l', '6', '4') }, - { CODEC_ID_PCM_S8, MKTAG('s', 'o', 'w', 't') }, - { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */ - { CODEC_ID_PCM_U8, MKTAG('N', 'O', 'N', 'E') }, /* uncompressed */ - { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */ - { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */ - - { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */ - - { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, /* Macintosh Audio Compression and Expansion 3:1 */ - { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, /* Macintosh Audio Compression and Expansion 6:1 */ - - { CODEC_ID_MP1, MKTAG('.', 'm', 'p', '1') }, /* MPEG layer 1 */ - { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '2') }, /* MPEG layer 2 */ - - { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */ - { CODEC_ID_MP3, 0x6D730055 }, /* MPEG layer 3 */ - -/* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */ - - { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, /* MPEG-4 AAC */ - { CODEC_ID_AC3, MKTAG('a', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F */ - { CODEC_ID_AC3, MKTAG('s', 'a', 'c', '3') }, /* Nero Recode */ - { CODEC_ID_DTS, MKTAG('d', 't', 's', 'c') }, /* mp4ra.org */ - { CODEC_ID_DTS, MKTAG('D', 'T', 'S', ' ') }, /* non-standard */ - { CODEC_ID_EAC3, MKTAG('e', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F */ - - { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */ - { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */ - - { CODEC_ID_GSM, MKTAG('a', 'g', 's', 'm') }, - { CODEC_ID_NELLYMOSER, MKTAG('n', 'm', 'o', 's') }, /* Flash Media Server */ - { CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') }, /* Apple Lossless */ - - { CODEC_ID_QCELP, MKTAG('Q','c','l','p') }, - { CODEC_ID_QCELP, MKTAG('Q','c','l','q') }, - { CODEC_ID_QCELP, MKTAG('s','q','c','p') }, /* ISO Media fourcc */ - - { CODEC_ID_QDMC, MKTAG('Q', 'D', 'M', 'C') }, /* QDMC */ - { CODEC_ID_QDM2, MKTAG('Q', 'D', 'M', '2') }, /* QDM2 */ - - { CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') }, - { CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') }, - - { CODEC_ID_SPEEX, MKTAG('s','p','e','x') }, /* Flash Media Server */ - - { CODEC_ID_WMAV2, MKTAG('W', 'M', 'A', '2') }, - + { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, + { CODEC_ID_AC3, MKTAG('a', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F */ + { CODEC_ID_AC3, MKTAG('s', 'a', 'c', '3') }, /* Nero Recode */ + { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, + { CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') }, + { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */ + { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */ + { CODEC_ID_DTS, MKTAG('d', 't', 's', 'c') }, /* mp4ra.org */ + { CODEC_ID_DTS, MKTAG('D', 'T', 'S', ' ') }, /* non-standard */ + { CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') }, + { CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') }, + { CODEC_ID_EAC3, MKTAG('e', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F */ + { CODEC_ID_GSM, MKTAG('a', 'g', 's', 'm') }, + { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, + { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, + { CODEC_ID_MP1, MKTAG('.', 'm', 'p', '1') }, + { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '2') }, + { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') }, + { CODEC_ID_MP3, 0x6D730055 }, + { CODEC_ID_NELLYMOSER, MKTAG('n', 'm', 'o', 's') }, /* Flash Media Server */ + { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, + { CODEC_ID_PCM_F32BE, MKTAG('f', 'l', '3', '2') }, + { CODEC_ID_PCM_F32LE, MKTAG('f', 'l', '3', '2') }, + { CODEC_ID_PCM_F64BE, MKTAG('f', 'l', '6', '4') }, + { CODEC_ID_PCM_F64LE, MKTAG('f', 'l', '6', '4') }, + { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, + { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, + { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, + { CODEC_ID_PCM_S16LE, MKTAG('l', 'p', 'c', 'm') }, + { CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') }, + { CODEC_ID_PCM_S24LE, MKTAG('i', 'n', '2', '4') }, + { CODEC_ID_PCM_S32BE, MKTAG('i', 'n', '3', '2') }, + { CODEC_ID_PCM_S32LE, MKTAG('i', 'n', '3', '2') }, + { CODEC_ID_PCM_S8, MKTAG('s', 'o', 'w', 't') }, + { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, + { CODEC_ID_PCM_U8, MKTAG('N', 'O', 'N', 'E') }, + { CODEC_ID_QCELP, MKTAG('Q', 'c', 'l', 'p') }, + { CODEC_ID_QCELP, MKTAG('Q', 'c', 'l', 'q') }, + { CODEC_ID_QCELP, MKTAG('s', 'q', 'c', 'p') }, /* ISO Media fourcc */ + { CODEC_ID_QDM2, MKTAG('Q', 'D', 'M', '2') }, + { CODEC_ID_QDMC, MKTAG('Q', 'D', 'M', 'C') }, + { CODEC_ID_SPEEX, MKTAG('s', 'p', 'e', 'x') }, /* Flash Media Server */ + { CODEC_ID_WMAV2, MKTAG('W', 'M', 'A', '2') }, { CODEC_ID_NONE, 0 }, }; diff --git a/libavformat/mov.c b/libavformat/mov.c index 0bb7362179..12af19ed50 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -37,6 +37,7 @@ #include "isom.h" #include "libavcodec/get_bits.h" #include "id3v1.h" +#include "mov_chan.h" #if CONFIG_ZLIB #include <zlib.h> @@ -568,6 +569,51 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + uint8_t version; + uint32_t flags, layout_tag, bitmap, num_descr; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + + if (atom.size < 16) + return 0; + + version = avio_r8(pb); + flags = avio_rb24(pb); + + layout_tag = avio_rb32(pb); + bitmap = avio_rb32(pb); + num_descr = avio_rb32(pb); + + if (atom.size < 16ULL + num_descr * 20ULL) + return 0; + + av_dlog(c->fc, "chan: size=%ld version=%u flags=%u layout=%u bitmap=%u num_descr=%u\n", + atom.size, version, flags, layout_tag, bitmap, num_descr); + +#if 0 + /* TODO: use the channel descriptions if the layout tag is 0 */ + int i; + for (i = 0; i < num_descr; i++) { + uint32_t label, cflags; + float coords[3]; + label = avio_rb32(pb); // mChannelLabel + cflags = avio_rb32(pb); // mChannelFlags + AV_WN32(&coords[0], avio_rl32(pb)); // mCoordinates[0] + AV_WN32(&coords[1], avio_rl32(pb)); // mCoordinates[1] + AV_WN32(&coords[2], avio_rl32(pb)); // mCoordinates[2] + } +#endif + + st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap); + + return 0; +} + static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; @@ -2346,7 +2392,7 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } -static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom) +static int mov_read_chan2(MOVContext *c, AVIOContext *pb, MOVAtom atom) { if (atom.size < 16) return 0; @@ -2409,7 +2455,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */ { MKTAG('w','f','e','x'), mov_read_wfex }, { MKTAG('c','m','o','v'), mov_read_cmov }, -{ MKTAG('c','h','a','n'), mov_read_chan }, +{ MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout */ { 0, NULL } }; diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c new file mode 100644 index 0000000000..a8e6b94c51 --- /dev/null +++ b/libavformat/mov_chan.c @@ -0,0 +1,505 @@ +/* + * Copyright (c) 2011 Justin Ruggles + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * mov 'chan' tag reading/writing. + * @author Justin Ruggles + */ + +#include <stdint.h> + +#include "libavutil/audioconvert.h" +#include "libavcodec/avcodec.h" +#include "mov_chan.h" + +/** + * Channel Layout Tag + * This tells which channels are present in the audio stream and the order in + * which they appear. + * + * @note We're using the channel layout tag to indicate channel order + * when the value is greater than 0x10000. The Apple documentation has + * some contradictions as to how this is actually supposed to be handled. + * + * Core Audio File Format Spec: + * "The high 16 bits indicates a specific ordering of the channels." + * Core Audio Data Types Reference: + * "These identifiers specify the channels included in a layout but + * do not specify a particular ordering of those channels." + */ +enum MovChannelLayoutTag { + MOV_CH_LAYOUT_UNKNOWN = 0xFFFF0000, + MOV_CH_LAYOUT_USE_DESCRIPTIONS = ( 0 << 16) | 0, + MOV_CH_LAYOUT_USE_BITMAP = ( 1 << 16) | 0, + MOV_CH_LAYOUT_DISCRETEINORDER = (147 << 16) | 0, + MOV_CH_LAYOUT_MONO = (100 << 16) | 1, + MOV_CH_LAYOUT_STEREO = (101 << 16) | 2, + MOV_CH_LAYOUT_STEREOHEADPHONES = (102 << 16) | 2, + MOV_CH_LAYOUT_MATRIXSTEREO = (103 << 16) | 2, + MOV_CH_LAYOUT_MIDSIDE = (104 << 16) | 2, + MOV_CH_LAYOUT_XY = (105 << 16) | 2, + MOV_CH_LAYOUT_BINAURAL = (106 << 16) | 2, + MOV_CH_LAYOUT_AMBISONIC_B_FORMAT = (107 << 16) | 4, + MOV_CH_LAYOUT_QUADRAPHONIC = (108 << 16) | 4, + MOV_CH_LAYOUT_PENTAGONAL = (109 << 16) | 5, + MOV_CH_LAYOUT_HEXAGONAL = (110 << 16) | 6, + MOV_CH_LAYOUT_OCTAGONAL = (111 << 16) | 8, + MOV_CH_LAYOUT_CUBE = (112 << 16) | 8, + MOV_CH_LAYOUT_MPEG_3_0_A = (113 << 16) | 3, + MOV_CH_LAYOUT_MPEG_3_0_B = (114 << 16) | 3, + MOV_CH_LAYOUT_MPEG_4_0_A = (115 << 16) | 4, + MOV_CH_LAYOUT_MPEG_4_0_B = (116 << 16) | 4, + MOV_CH_LAYOUT_MPEG_5_0_A = (117 << 16) | 5, + MOV_CH_LAYOUT_MPEG_5_0_B = (118 << 16) | 5, + MOV_CH_LAYOUT_MPEG_5_0_C = (119 << 16) | 5, + MOV_CH_LAYOUT_MPEG_5_0_D = (120 << 16) | 5, + MOV_CH_LAYOUT_MPEG_5_1_A = (121 << 16) | 6, + MOV_CH_LAYOUT_MPEG_5_1_B = (122 << 16) | 6, + MOV_CH_LAYOUT_MPEG_5_1_C = (123 << 16) | 6, + MOV_CH_LAYOUT_MPEG_5_1_D = (124 << 16) | 6, + MOV_CH_LAYOUT_MPEG_6_1_A = (125 << 16) | 7, + MOV_CH_LAYOUT_MPEG_7_1_A = (126 << 16) | 8, + MOV_CH_LAYOUT_MPEG_7_1_B = (127 << 16) | 8, + MOV_CH_LAYOUT_MPEG_7_1_C = (128 << 16) | 8, + MOV_CH_LAYOUT_EMAGIC_DEFAULT_7_1 = (129 << 16) | 8, + MOV_CH_LAYOUT_SMPTE_DTV = (130 << 16) | 8, + MOV_CH_LAYOUT_ITU_2_1 = (131 << 16) | 3, + MOV_CH_LAYOUT_ITU_2_2 = (132 << 16) | 4, + MOV_CH_LAYOUT_DVD_4 = (133 << 16) | 3, + MOV_CH_LAYOUT_DVD_5 = (134 << 16) | 4, + MOV_CH_LAYOUT_DVD_6 = (135 << 16) | 5, + MOV_CH_LAYOUT_DVD_10 = (136 << 16) | 4, + MOV_CH_LAYOUT_DVD_11 = (137 << 16) | 5, + MOV_CH_LAYOUT_DVD_18 = (138 << 16) | 5, + MOV_CH_LAYOUT_AUDIOUNIT_6_0 = (139 << 16) | 6, + MOV_CH_LAYOUT_AUDIOUNIT_7_0 = (140 << 16) | 7, + MOV_CH_LAYOUT_AUDIOUNIT_7_0_FRONT = (148 << 16) | 7, + MOV_CH_LAYOUT_AAC_6_0 = (141 << 16) | 6, + MOV_CH_LAYOUT_AAC_6_1 = (142 << 16) | 7, + MOV_CH_LAYOUT_AAC_7_0 = (143 << 16) | 7, + MOV_CH_LAYOUT_AAC_OCTAGONAL = (144 << 16) | 8, + MOV_CH_LAYOUT_TMH_10_2_STD = (145 << 16) | 16, + MOV_CH_LAYOUT_TMH_10_2_FULL = (146 << 16) | 21, + MOV_CH_LAYOUT_AC3_1_0_1 = (149 << 16) | 2, + MOV_CH_LAYOUT_AC3_3_0 = (150 << 16) | 3, + MOV_CH_LAYOUT_AC3_3_1 = (151 << 16) | 4, + MOV_CH_LAYOUT_AC3_3_0_1 = (152 << 16) | 4, + MOV_CH_LAYOUT_AC3_2_1_1 = (153 << 16) | 4, + MOV_CH_LAYOUT_AC3_3_1_1 = (154 << 16) | 5, + MOV_CH_LAYOUT_EAC3_6_0_A = (155 << 16) | 6, + MOV_CH_LAYOUT_EAC3_7_0_A = (156 << 16) | 7, + MOV_CH_LAYOUT_EAC3_6_1_A = (157 << 16) | 7, + MOV_CH_LAYOUT_EAC3_6_1_B = (158 << 16) | 7, + MOV_CH_LAYOUT_EAC3_6_1_C = (159 << 16) | 7, + MOV_CH_LAYOUT_EAC3_7_1_A = (160 << 16) | 8, + MOV_CH_LAYOUT_EAC3_7_1_B = (161 << 16) | 8, + MOV_CH_LAYOUT_EAC3_7_1_C = (162 << 16) | 8, + MOV_CH_LAYOUT_EAC3_7_1_D = (163 << 16) | 8, + MOV_CH_LAYOUT_EAC3_7_1_E = (164 << 16) | 8, + MOV_CH_LAYOUT_EAC3_7_1_F = (165 << 16) | 8, + MOV_CH_LAYOUT_EAC3_7_1_G = (166 << 16) | 8, + MOV_CH_LAYOUT_EAC3_7_1_H = (167 << 16) | 8, + MOV_CH_LAYOUT_DTS_3_1 = (168 << 16) | 4, + MOV_CH_LAYOUT_DTS_4_1 = (169 << 16) | 5, + MOV_CH_LAYOUT_DTS_6_0_A = (170 << 16) | 6, + MOV_CH_LAYOUT_DTS_6_0_B = (171 << 16) | 6, + MOV_CH_LAYOUT_DTS_6_0_C = (172 << 16) | 6, + MOV_CH_LAYOUT_DTS_6_1_A = (173 << 16) | 7, + MOV_CH_LAYOUT_DTS_6_1_B = (174 << 16) | 7, + MOV_CH_LAYOUT_DTS_6_1_C = (175 << 16) | 7, + MOV_CH_LAYOUT_DTS_6_1_D = (182 << 16) | 7, + MOV_CH_LAYOUT_DTS_7_0 = (176 << 16) | 7, + MOV_CH_LAYOUT_DTS_7_1 = (177 << 16) | 8, + MOV_CH_LAYOUT_DTS_8_0_A = (178 << 16) | 8, + MOV_CH_LAYOUT_DTS_8_0_B = (179 << 16) | 8, + MOV_CH_LAYOUT_DTS_8_1_A = (180 << 16) | 9, + MOV_CH_LAYOUT_DTS_8_1_B = (181 << 16) | 9, +}; + +struct MovChannelLayoutMap { + uint32_t tag; + uint64_t layout; +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_misc[] = { + { MOV_CH_LAYOUT_USE_DESCRIPTIONS, 0 }, + { MOV_CH_LAYOUT_USE_BITMAP, 0 }, + { MOV_CH_LAYOUT_DISCRETEINORDER, 0 }, + { MOV_CH_LAYOUT_UNKNOWN, 0 }, + { MOV_CH_LAYOUT_TMH_10_2_STD, 0 }, // L, R, C, Vhc, Lsd, Rsd, + // Ls, Rs, Vhl, Vhr, Lw, Rw, + // Csd, Cs, LFE1, LFE2 + { MOV_CH_LAYOUT_TMH_10_2_FULL, 0 }, // L, R, C, Vhc, Lsd, Rsd, + // Ls, Rs, Vhl, Vhr, Lw, Rw, + // Csd, Cs, LFE1, LFE2, Lc, Rc, + // HI, VI, Haptic + { 0, 0 }, +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_1ch[] = { + { MOV_CH_LAYOUT_MONO, AV_CH_LAYOUT_MONO }, // C +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_2ch[] = { + { MOV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO }, // L, R + { MOV_CH_LAYOUT_STEREOHEADPHONES, AV_CH_LAYOUT_STEREO }, // L, R + { MOV_CH_LAYOUT_BINAURAL, AV_CH_LAYOUT_STEREO }, // L, R + { MOV_CH_LAYOUT_MIDSIDE, AV_CH_LAYOUT_STEREO }, // C, sides + { MOV_CH_LAYOUT_XY, AV_CH_LAYOUT_STEREO }, // X (left), Y (right) + + { MOV_CH_LAYOUT_MATRIXSTEREO, AV_CH_LAYOUT_STEREO_DOWNMIX }, // Lt, Rt + + { MOV_CH_LAYOUT_AC3_1_0_1, AV_CH_LAYOUT_MONO | // C, LFE + AV_CH_LOW_FREQUENCY }, + { 0, 0 }, +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_3ch[] = { + { MOV_CH_LAYOUT_MPEG_3_0_A, AV_CH_LAYOUT_SURROUND }, // L, R, C + { MOV_CH_LAYOUT_MPEG_3_0_B, AV_CH_LAYOUT_SURROUND }, // C, L, R + { MOV_CH_LAYOUT_AC3_3_0, AV_CH_LAYOUT_SURROUND }, // L, C, R + + { MOV_CH_LAYOUT_ITU_2_1, AV_CH_LAYOUT_2_1 }, // L, R, Cs + + { MOV_CH_LAYOUT_DVD_4, AV_CH_LAYOUT_2POINT1 }, // L, R, LFE + { 0, 0 }, +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_4ch[] = { + { MOV_CH_LAYOUT_AMBISONIC_B_FORMAT, 0 }, // W, X, Y, Z + + { MOV_CH_LAYOUT_QUADRAPHONIC, AV_CH_LAYOUT_QUAD }, // L, R, Rls, Rrs + + { MOV_CH_LAYOUT_MPEG_4_0_A, AV_CH_LAYOUT_4POINT0 }, // L, R, C, Cs + { MOV_CH_LAYOUT_MPEG_4_0_B, AV_CH_LAYOUT_4POINT0 }, // C, L, R, Cs + { MOV_CH_LAYOUT_AC3_3_1, AV_CH_LAYOUT_4POINT0 }, // L, C, R, Cs + + { MOV_CH_LAYOUT_ITU_2_2, AV_CH_LAYOUT_2_2 }, // L, R, Ls, Rs + + { MOV_CH_LAYOUT_DVD_5, AV_CH_LAYOUT_2_1 | // L, R, LFE, Cs + AV_CH_LOW_FREQUENCY }, + { MOV_CH_LAYOUT_AC3_2_1_1, AV_CH_LAYOUT_2_1 | // L, R, Cs, LFE + AV_CH_LOW_FREQUENCY }, + + { MOV_CH_LAYOUT_DVD_10, AV_CH_LAYOUT_3POINT1 }, // L, R, C, LFE + { MOV_CH_LAYOUT_AC3_3_0_1, AV_CH_LAYOUT_3POINT1 }, // L, C, R, LFE + { MOV_CH_LAYOUT_DTS_3_1, AV_CH_LAYOUT_3POINT1 }, // C, L, R, LFE + { 0, 0 }, +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_5ch[] = { + { MOV_CH_LAYOUT_PENTAGONAL, AV_CH_LAYOUT_5POINT0_BACK }, // L, R, Rls, Rrs, C + + { MOV_CH_LAYOUT_MPEG_5_0_A, AV_CH_LAYOUT_5POINT0 }, // L, R, C, Ls, Rs + { MOV_CH_LAYOUT_MPEG_5_0_B, AV_CH_LAYOUT_5POINT0 }, // L, R, Ls, Rs, C + { MOV_CH_LAYOUT_MPEG_5_0_C, AV_CH_LAYOUT_5POINT0 }, // L, C, R, Ls, Rs + { MOV_CH_LAYOUT_MPEG_5_0_D, AV_CH_LAYOUT_5POINT0 }, // C, L, R, Ls, Rs + + { MOV_CH_LAYOUT_DVD_6, AV_CH_LAYOUT_2_2 | // L, R, LFE, Ls, Rs + AV_CH_LOW_FREQUENCY }, + { MOV_CH_LAYOUT_DVD_18, AV_CH_LAYOUT_2_2 | // L, R, Ls, Rs, LFE + AV_CH_LOW_FREQUENCY }, + + { MOV_CH_LAYOUT_DVD_11, AV_CH_LAYOUT_4POINT1 }, // L, R, C, LFE, Cs + { MOV_CH_LAYOUT_AC3_3_1_1, AV_CH_LAYOUT_4POINT1 }, // L, C, R, Cs, LFE + { MOV_CH_LAYOUT_DTS_4_1, AV_CH_LAYOUT_4POINT1 }, // C, L, R, Cs, LFE + { 0, 0 }, +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_6ch[] = { + { MOV_CH_LAYOUT_HEXAGONAL, AV_CH_LAYOUT_HEXAGONAL }, // L, R, Rls, Rrs, C, Cs + { MOV_CH_LAYOUT_DTS_6_0_C, AV_CH_LAYOUT_HEXAGONAL }, // C, Cs, L, R, Rls, Rrs + + { MOV_CH_LAYOUT_MPEG_5_1_A, AV_CH_LAYOUT_5POINT1 }, // L, R, C, LFE, Ls, Rs + { MOV_CH_LAYOUT_MPEG_5_1_B, AV_CH_LAYOUT_5POINT1 }, // L, R, Ls, Rs, C, LFE + { MOV_CH_LAYOUT_MPEG_5_1_C, AV_CH_LAYOUT_5POINT1 }, // L, C, R, Ls, Rs, LFE + { MOV_CH_LAYOUT_MPEG_5_1_D, AV_CH_LAYOUT_5POINT1 }, // C, L, R, Ls, Rs, LFE + + { MOV_CH_LAYOUT_AUDIOUNIT_6_0, AV_CH_LAYOUT_6POINT0 }, // L, R, Ls, Rs, C, Cs + { MOV_CH_LAYOUT_AAC_6_0, AV_CH_LAYOUT_6POINT0 }, // C, L, R, Ls, Rs, Cs + { MOV_CH_LAYOUT_EAC3_6_0_A, AV_CH_LAYOUT_6POINT0 }, // L, C, R, Ls, Rs, Cs + + { MOV_CH_LAYOUT_DTS_6_0_A, AV_CH_LAYOUT_6POINT0_FRONT }, // Lc, Rc, L, R, Ls, Rs + + { MOV_CH_LAYOUT_DTS_6_0_B, AV_CH_LAYOUT_5POINT0_BACK | // C, L, R, Rls, Rrs, Ts + AV_CH_TOP_CENTER }, + { 0, 0 }, +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_7ch[] = { + { MOV_CH_LAYOUT_MPEG_6_1_A, AV_CH_LAYOUT_6POINT1 }, // L, R, C, LFE, Ls, Rs, Cs + { MOV_CH_LAYOUT_AAC_6_1, AV_CH_LAYOUT_6POINT1 }, // C, L, R, Ls, Rs, Cs, LFE + { MOV_CH_LAYOUT_EAC3_6_1_A, AV_CH_LAYOUT_6POINT1 }, // L, C, R, Ls, Rs, LFE, Cs + { MOV_CH_LAYOUT_DTS_6_1_D, AV_CH_LAYOUT_6POINT1 }, // C, L, R, Ls, Rs, LFE, Cs + + { MOV_CH_LAYOUT_AUDIOUNIT_7_0, AV_CH_LAYOUT_7POINT0 }, // L, R, Ls, Rs, C, Rls, Rrs + { MOV_CH_LAYOUT_AAC_7_0, AV_CH_LAYOUT_7POINT0 }, // C, L, R, Ls, Rs, Rls, Rrs + { MOV_CH_LAYOUT_EAC3_7_0_A, AV_CH_LAYOUT_7POINT0 }, // L, C, R, Ls, Rs, Rls, Rrs + + { MOV_CH_LAYOUT_AUDIOUNIT_7_0_FRONT, AV_CH_LAYOUT_7POINT0_FRONT }, // L, R, Ls, Rs, C, Lc, Rc + { MOV_CH_LAYOUT_DTS_7_0, AV_CH_LAYOUT_7POINT0_FRONT }, // Lc, C, Rc, L, R, Ls, Rs + + { MOV_CH_LAYOUT_EAC3_6_1_B, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Ts + AV_CH_TOP_CENTER }, + + { MOV_CH_LAYOUT_EAC3_6_1_C, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Vhc + AV_CH_TOP_FRONT_CENTER }, + + { MOV_CH_LAYOUT_DTS_6_1_A, AV_CH_LAYOUT_6POINT1_FRONT }, // Lc, Rc, L, R, Ls, Rs, LFE + + { MOV_CH_LAYOUT_DTS_6_1_B, AV_CH_LAYOUT_5POINT1_BACK | // C, L, R, Rls, Rrs, Ts, LFE + AV_CH_TOP_CENTER }, + + { MOV_CH_LAYOUT_DTS_6_1_C, AV_CH_LAYOUT_6POINT1_BACK }, // C, Cs, L, R, Rls, Rrs, LFE + { 0, 0 }, +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_8ch[] = { + { MOV_CH_LAYOUT_OCTAGONAL, AV_CH_LAYOUT_OCTAGONAL }, // L, R, Rls, Rrs, C, Cs, Ls, Rs + { MOV_CH_LAYOUT_AAC_OCTAGONAL, AV_CH_LAYOUT_OCTAGONAL }, // C, L, R, Ls, Rs, Rls, Rrs, Cs + + { MOV_CH_LAYOUT_CUBE, AV_CH_LAYOUT_QUAD | // L, R, Rls, Rrs, Vhl, Vhr, Rlt, Rrt + AV_CH_TOP_FRONT_LEFT | + AV_CH_TOP_FRONT_RIGHT | + AV_CH_TOP_BACK_LEFT | + AV_CH_TOP_BACK_RIGHT }, + + { MOV_CH_LAYOUT_MPEG_7_1_A, AV_CH_LAYOUT_7POINT1_WIDE }, // L, R, C, LFE, Ls, Rs, Lc, Rc + { MOV_CH_LAYOUT_MPEG_7_1_B, AV_CH_LAYOUT_7POINT1_WIDE }, // C, Lc, Rc, L, R, Ls, Rs, LFE + { MOV_CH_LAYOUT_EMAGIC_DEFAULT_7_1, AV_CH_LAYOUT_7POINT1_WIDE }, // L, R, Ls, Rs, C, LFE, Lc, Rc + { MOV_CH_LAYOUT_EAC3_7_1_B, AV_CH_LAYOUT_7POINT1_WIDE }, // L, C, R, Ls, Rs, LFE, Lc, Rc + { MOV_CH_LAYOUT_DTS_7_1, AV_CH_LAYOUT_7POINT1_WIDE }, // Lc, C, Rc, L, R, Ls, Rs, LFE + + { MOV_CH_LAYOUT_MPEG_7_1_C, AV_CH_LAYOUT_7POINT1 }, // L, R, C, LFE, Ls, Rs, Rls, Rrs + { MOV_CH_LAYOUT_EAC3_7_1_A, AV_CH_LAYOUT_7POINT1 }, // L, C, R, Ls, Rs, LFE, Rls, Rrs + + { MOV_CH_LAYOUT_SMPTE_DTV, AV_CH_LAYOUT_5POINT1 | // L, R, C, LFE, Ls, Rs, Lt, Rt + AV_CH_LAYOUT_STEREO_DOWNMIX }, + + { MOV_CH_LAYOUT_EAC3_7_1_C, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Lsd, Rsd + AV_CH_SURROUND_DIRECT_LEFT | + AV_CH_SURROUND_DIRECT_RIGHT }, + + { MOV_CH_LAYOUT_EAC3_7_1_D, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Lw, Rw + AV_CH_WIDE_LEFT | + AV_CH_WIDE_RIGHT }, + + { MOV_CH_LAYOUT_EAC3_7_1_E, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Vhl, Vhr + AV_CH_TOP_FRONT_LEFT | + AV_CH_TOP_FRONT_RIGHT }, + + { MOV_CH_LAYOUT_EAC3_7_1_F, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Cs, Ts + AV_CH_BACK_CENTER | + AV_CH_TOP_CENTER }, + + { MOV_CH_LAYOUT_EAC3_7_1_G, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Cs, Vhc + AV_CH_BACK_CENTER | + AV_CH_TOP_FRONT_CENTER }, + + { MOV_CH_LAYOUT_EAC3_7_1_H, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Ts, Vhc + AV_CH_TOP_CENTER | + AV_CH_TOP_FRONT_CENTER }, + + { MOV_CH_LAYOUT_DTS_8_0_A, AV_CH_LAYOUT_2_2 | // Lc, Rc, L, R, Ls, Rs, Rls, Rrs + AV_CH_BACK_LEFT | + AV_CH_BACK_RIGHT | + AV_CH_FRONT_LEFT_OF_CENTER | + AV_CH_FRONT_RIGHT_OF_CENTER }, + + { MOV_CH_LAYOUT_DTS_8_0_B, AV_CH_LAYOUT_5POINT0 | // Lc, C, Rc, L, R, Ls, Cs, Rs + AV_CH_FRONT_LEFT_OF_CENTER | + AV_CH_FRONT_RIGHT_OF_CENTER | + AV_CH_BACK_CENTER }, + { 0, 0 }, +}; + +static const struct MovChannelLayoutMap mov_ch_layout_map_9ch[] = { + { MOV_CH_LAYOUT_DTS_8_1_A, AV_CH_LAYOUT_2_2 | // Lc, Rc, L, R, Ls, Rs, Rls, Rrs, LFE + AV_CH_BACK_LEFT | + AV_CH_BACK_RIGHT | + AV_CH_FRONT_LEFT_OF_CENTER | + AV_CH_FRONT_RIGHT_OF_CENTER | + AV_CH_LOW_FREQUENCY }, + + { MOV_CH_LAYOUT_DTS_8_1_B, AV_CH_LAYOUT_7POINT1_WIDE | // Lc, C, Rc, L, R, Ls, Cs, Rs, LFE + AV_CH_BACK_CENTER }, + { 0, 0 }, +}; + +static const struct MovChannelLayoutMap *mov_ch_layout_map[] = { + mov_ch_layout_map_misc, + mov_ch_layout_map_1ch, + mov_ch_layout_map_2ch, + mov_ch_layout_map_3ch, + mov_ch_layout_map_4ch, + mov_ch_layout_map_5ch, + mov_ch_layout_map_6ch, + mov_ch_layout_map_7ch, + mov_ch_layout_map_8ch, + mov_ch_layout_map_9ch, +}; + +static const enum MovChannelLayoutTag mov_ch_layouts_aac[] = { + MOV_CH_LAYOUT_MONO, + MOV_CH_LAYOUT_STEREO, + MOV_CH_LAYOUT_AC3_1_0_1, + MOV_CH_LAYOUT_MPEG_3_0_B, + MOV_CH_LAYOUT_ITU_2_1, + MOV_CH_LAYOUT_DVD_4, + MOV_CH_LAYOUT_QUADRAPHONIC, + MOV_CH_LAYOUT_MPEG_4_0_B, + MOV_CH_LAYOUT_ITU_2_2, + MOV_CH_LAYOUT_AC3_2_1_1, + MOV_CH_LAYOUT_DTS_3_1, + MOV_CH_LAYOUT_MPEG_5_0_D, + MOV_CH_LAYOUT_DVD_18, + MOV_CH_LAYOUT_DTS_4_1, + MOV_CH_LAYOUT_MPEG_5_1_D, + MOV_CH_LAYOUT_AAC_6_0, + MOV_CH_LAYOUT_DTS_6_0_A, + MOV_CH_LAYOUT_AAC_6_1, + MOV_CH_LAYOUT_AAC_7_0, + MOV_CH_LAYOUT_DTS_6_1_A, + MOV_CH_LAYOUT_AAC_OCTAGONAL, + MOV_CH_LAYOUT_MPEG_7_1_B, + MOV_CH_LAYOUT_DTS_8_0_A, + 0, +}; + +static const enum MovChannelLayoutTag mov_ch_layouts_ac3[] = { + MOV_CH_LAYOUT_MONO, + MOV_CH_LAYOUT_STEREO, + MOV_CH_LAYOUT_AC3_1_0_1, + MOV_CH_LAYOUT_AC3_3_0, + MOV_CH_LAYOUT_ITU_2_1, + MOV_CH_LAYOUT_DVD_4, + MOV_CH_LAYOUT_AC3_3_1, + MOV_CH_LAYOUT_ITU_2_2, + MOV_CH_LAYOUT_AC3_2_1_1, + MOV_CH_LAYOUT_AC3_3_0_1, + MOV_CH_LAYOUT_MPEG_5_0_C, + MOV_CH_LAYOUT_DVD_18, + MOV_CH_LAYOUT_AC3_3_1_1, + MOV_CH_LAYOUT_MPEG_5_1_C, + 0, +}; + +static const enum MovChannelLayoutTag mov_ch_layouts_alac[] = { + MOV_CH_LAYOUT_MONO, + MOV_CH_LAYOUT_STEREO, + MOV_CH_LAYOUT_MPEG_3_0_B, + MOV_CH_LAYOUT_MPEG_4_0_B, + MOV_CH_LAYOUT_MPEG_5_0_D, + MOV_CH_LAYOUT_MPEG_5_1_D, + MOV_CH_LAYOUT_AAC_6_1, + MOV_CH_LAYOUT_MPEG_7_1_B, + 0, +}; + +static const struct { + enum CodecID codec_id; + const enum MovChannelLayoutTag *layouts; +} mov_codec_ch_layouts[] = { + { CODEC_ID_AAC, mov_ch_layouts_aac }, + { CODEC_ID_AC3, mov_ch_layouts_ac3 }, + { CODEC_ID_ALAC, mov_ch_layouts_alac }, + { CODEC_ID_NONE, NULL }, +}; + +uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap) +{ + int i, channels; + const struct MovChannelLayoutMap *layout_map; + + /* handle the use of the channel descriptions */ + /* TODO: map MOV channel labels to FFmpeg channels */ + if (tag == MOV_CH_LAYOUT_USE_DESCRIPTIONS) + return 0; + + /* handle the use of the channel bitmap */ + if (tag == MOV_CH_LAYOUT_USE_BITMAP) + return bitmap < 0x40000 ? bitmap : 0; + + /* get the layout map based on the channel count for the specified layout tag */ + channels = tag & 0xFFFF; + if (channels > 9) + channels = 0; + layout_map = mov_ch_layout_map[channels]; + + /* find the channel layout for the specified layout tag */ + for (i = 0; layout_map[i].tag != 0; i++) { + if (layout_map[i].tag == tag) + break; + } + return layout_map[i].layout; +} + +uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, + uint64_t channel_layout, + uint32_t *bitmap) +{ + int i, j; + uint32_t tag = 0; + const enum MovChannelLayoutTag *layouts = NULL; + + /* find the layout list for the specified codec */ + for (i = 0; mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE; i++) { + if (mov_codec_ch_layouts[i].codec_id == codec_id) + break; + } + if (mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE) + layouts = mov_codec_ch_layouts[i].layouts; + + if (layouts) { + int channels; + const struct MovChannelLayoutMap *layout_map; + + /* get the layout map based on the channel count */ + channels = av_get_channel_layout_nb_channels(channel_layout); + if (channels > 9) + channels = 0; + layout_map = mov_ch_layout_map[channels]; + + /* find the layout tag for the specified channel layout */ + for (i = 0; layouts[i] != 0; i++) { + if (layouts[i] & 0xFFFF != channels) + continue; + for (j = 0; layout_map[j].tag != 0; j++) { + if (layout_map[j].tag == layouts[i] && + layout_map[j].layout == channel_layout) + break; + } + if (layout_map[j].tag) + break; + } + tag = layouts[i]; + } + + /* if no tag was found, use channel bitmap as a backup if possible */ + if (tag == 0 && channel_layout > 0 && channel_layout < 0x40000) { + tag = MOV_CH_LAYOUT_USE_BITMAP; + *bitmap = (uint32_t)channel_layout; + } else + *bitmap = 0; + + /* TODO: set channel descriptions as a secondary backup */ + + return tag; +} diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h new file mode 100644 index 0000000000..9723340102 --- /dev/null +++ b/libavformat/mov_chan.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011 Justin Ruggles + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * mov 'chan' tag reading/writing. + * @author Justin Ruggles + */ + +#ifndef AVFORMAT_MOV_CHAN_H +#define AVFORMAT_MOV_CHAN_H + +#include <stdint.h> + +#include "libavcodec/avcodec.h" + +/** + * Get the channel layout for the specified channel layout tag. + * + * @param[in] tag channel layout tag + * @param[out] bitmap channel bitmap (only used if needed) + * @return channel layout + */ +uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap); + +/** + * Get the channel layout tag for the specified codec id and channel layout. + * If the layout tag was not found, use a channel bitmap if possible. + * + * @param[in] codec_id codec id + * @param[in] channel_layout channel layout + * @param[out] bitmap channel bitmap + * @return channel layout tag + */ +uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, + uint64_t channel_layout, + uint32_t *bitmap); + +#endif /* AVFORMAT_MOV_CHAN_H */ diff --git a/libavformat/movenc.c b/libavformat/movenc.c index d718cf1974..181965f720 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -37,6 +37,7 @@ #include "libavutil/opt.h" #include "libavutil/dict.h" #include "rtpenc.h" +#include "mov_chan.h" #undef NDEBUG #include <assert.h> @@ -354,6 +355,31 @@ static int mov_write_ms_tag(AVIOContext *pb, MOVTrack *track) return updateSize(pb, pos); } +static int mov_write_chan_tag(AVIOContext *pb, MOVTrack *track) +{ + uint32_t layout_tag, bitmap; + int64_t pos = avio_tell(pb); + + layout_tag = ff_mov_get_channel_layout_tag(track->enc->codec_id, + track->enc->channel_layout, + &bitmap); + if (!layout_tag) { + av_log(track->enc, AV_LOG_WARNING, "not writing 'chan' tag due to " + "lack of channel information\n"); + return 0; + } + + avio_wb32(pb, 0); // Size + ffio_wfourcc(pb, "chan"); // Type + avio_w8(pb, 0); // Version + avio_wb24(pb, 0); // Flags + avio_wb32(pb, layout_tag); // mChannelLayoutTag + avio_wb32(pb, bitmap); // mChannelBitmap + avio_wb32(pb, 0); // mNumberChannelDescriptions + + return updateSize(pb, pos); +} + static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); @@ -376,6 +402,7 @@ static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track) } else if (track->enc->codec_id == CODEC_ID_AMR_NB) { mov_write_amr_tag(pb, track); } else if (track->enc->codec_id == CODEC_ID_AC3) { + mov_write_chan_tag(pb, track); mov_write_ac3_tag(pb, track); } else if (track->enc->codec_id == CODEC_ID_ALAC) { mov_write_extradata_tag(pb, track); @@ -434,15 +461,9 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) uint32_t tag = track->tag; if (track->mode == MODE_MOV) { - if (track->timescale > UINT16_MAX) { - if (mov_get_lpcm_flags(track->enc->codec_id)) - tag = AV_RL32("lpcm"); - version = 2; - } else if (track->audio_vbr || mov_pcm_le_gt16(track->enc->codec_id) || - track->enc->codec_id == CODEC_ID_ADPCM_MS || - track->enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) { - version = 1; - } + if (mov_get_lpcm_flags(track->enc->codec_id)) + tag = AV_RL32("lpcm"); + version = 2; } avio_wb32(pb, 0); /* size */ @@ -469,34 +490,18 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id)); avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id)); avio_wb32(pb, track->sampleSize); - avio_wb32(pb, track->enc->frame_size); + avio_wb32(pb, track->audio_vbr ? track->enc->frame_size : 1); } else { - if (track->mode == MODE_MOV) { - avio_wb16(pb, track->enc->channels); - if (track->enc->codec_id == CODEC_ID_PCM_U8 || - track->enc->codec_id == CODEC_ID_PCM_S8) - avio_wb16(pb, 8); /* bits per sample */ - else - avio_wb16(pb, 16); - avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */ - } else { /* reserved for mp4/3gp */ - avio_wb16(pb, 2); - avio_wb16(pb, 16); - avio_wb16(pb, 0); - } + /* reserved for mp4/3gp */ + avio_wb16(pb, 2); + avio_wb16(pb, 16); + avio_wb16(pb, 0); avio_wb16(pb, 0); /* packet size (= 0) */ avio_wb16(pb, track->timescale); /* Time scale */ avio_wb16(pb, 0); /* Reserved */ } - if(version == 1) { /* SoundDescription V1 extended info */ - avio_wb32(pb, track->enc->frame_size); /* Samples per packet */ - avio_wb32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */ - avio_wb32(pb, track->sampleSize); /* Bytes per frame */ - avio_wb32(pb, 2); /* Bytes per sample */ - } - if(track->mode == MODE_MOV && (track->enc->codec_id == CODEC_ID_AAC || track->enc->codec_id == CODEC_ID_AC3 || @@ -2226,9 +2231,6 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, implement a AVParser for it\n"); return -1; } - } else if (enc->codec_id == CODEC_ID_ADPCM_MS || - enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) { - samplesInChunk = enc->frame_size; } else if (trk->sampleSize) samplesInChunk = size/trk->sampleSize; else @@ -2458,21 +2460,21 @@ static int mov_write_header(AVFormatContext *s) "or choose different container.\n"); }else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO){ track->timescale = st->codec->sample_rate; - if(!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) { - av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i); - goto error; - }else if(st->codec->codec_id == CODEC_ID_ADPCM_MS || - st->codec->codec_id == CODEC_ID_ADPCM_IMA_WAV){ + /* set sampleSize for PCM and ADPCM */ + if (av_get_bits_per_sample(st->codec->codec_id)) { if (!st->codec->block_align) { - av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set for adpcm\n", i); + av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set\n", i); goto error; } track->sampleSize = st->codec->block_align; - }else if(st->codec->frame_size > 1){ /* assume compressed audio */ + } + /* set audio_vbr for compressed audio */ + if (av_get_bits_per_sample(st->codec->codec_id) < 8) { + if (!st->codec->frame_size) { + av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i); + goto error; + } track->audio_vbr = 1; - }else{ - st->codec->frame_size = 1; - track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels; } if (track->mode != MODE_MOV) { if (track->timescale > UINT16_MAX) { |