00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include <stdint.h>
00027
00028 #include "libavutil/audioconvert.h"
00029 #include "libavcodec/avcodec.h"
00030 #include "mov_chan.h"
00031
00047 enum MovChannelLayoutTag {
00048 MOV_CH_LAYOUT_UNKNOWN = 0xFFFF0000,
00049 MOV_CH_LAYOUT_USE_DESCRIPTIONS = ( 0 << 16) | 0,
00050 MOV_CH_LAYOUT_USE_BITMAP = ( 1 << 16) | 0,
00051 MOV_CH_LAYOUT_DISCRETEINORDER = (147 << 16) | 0,
00052 MOV_CH_LAYOUT_MONO = (100 << 16) | 1,
00053 MOV_CH_LAYOUT_STEREO = (101 << 16) | 2,
00054 MOV_CH_LAYOUT_STEREOHEADPHONES = (102 << 16) | 2,
00055 MOV_CH_LAYOUT_MATRIXSTEREO = (103 << 16) | 2,
00056 MOV_CH_LAYOUT_MIDSIDE = (104 << 16) | 2,
00057 MOV_CH_LAYOUT_XY = (105 << 16) | 2,
00058 MOV_CH_LAYOUT_BINAURAL = (106 << 16) | 2,
00059 MOV_CH_LAYOUT_AMBISONIC_B_FORMAT = (107 << 16) | 4,
00060 MOV_CH_LAYOUT_QUADRAPHONIC = (108 << 16) | 4,
00061 MOV_CH_LAYOUT_PENTAGONAL = (109 << 16) | 5,
00062 MOV_CH_LAYOUT_HEXAGONAL = (110 << 16) | 6,
00063 MOV_CH_LAYOUT_OCTAGONAL = (111 << 16) | 8,
00064 MOV_CH_LAYOUT_CUBE = (112 << 16) | 8,
00065 MOV_CH_LAYOUT_MPEG_3_0_A = (113 << 16) | 3,
00066 MOV_CH_LAYOUT_MPEG_3_0_B = (114 << 16) | 3,
00067 MOV_CH_LAYOUT_MPEG_4_0_A = (115 << 16) | 4,
00068 MOV_CH_LAYOUT_MPEG_4_0_B = (116 << 16) | 4,
00069 MOV_CH_LAYOUT_MPEG_5_0_A = (117 << 16) | 5,
00070 MOV_CH_LAYOUT_MPEG_5_0_B = (118 << 16) | 5,
00071 MOV_CH_LAYOUT_MPEG_5_0_C = (119 << 16) | 5,
00072 MOV_CH_LAYOUT_MPEG_5_0_D = (120 << 16) | 5,
00073 MOV_CH_LAYOUT_MPEG_5_1_A = (121 << 16) | 6,
00074 MOV_CH_LAYOUT_MPEG_5_1_B = (122 << 16) | 6,
00075 MOV_CH_LAYOUT_MPEG_5_1_C = (123 << 16) | 6,
00076 MOV_CH_LAYOUT_MPEG_5_1_D = (124 << 16) | 6,
00077 MOV_CH_LAYOUT_MPEG_6_1_A = (125 << 16) | 7,
00078 MOV_CH_LAYOUT_MPEG_7_1_A = (126 << 16) | 8,
00079 MOV_CH_LAYOUT_MPEG_7_1_B = (127 << 16) | 8,
00080 MOV_CH_LAYOUT_MPEG_7_1_C = (128 << 16) | 8,
00081 MOV_CH_LAYOUT_EMAGIC_DEFAULT_7_1 = (129 << 16) | 8,
00082 MOV_CH_LAYOUT_SMPTE_DTV = (130 << 16) | 8,
00083 MOV_CH_LAYOUT_ITU_2_1 = (131 << 16) | 3,
00084 MOV_CH_LAYOUT_ITU_2_2 = (132 << 16) | 4,
00085 MOV_CH_LAYOUT_DVD_4 = (133 << 16) | 3,
00086 MOV_CH_LAYOUT_DVD_5 = (134 << 16) | 4,
00087 MOV_CH_LAYOUT_DVD_6 = (135 << 16) | 5,
00088 MOV_CH_LAYOUT_DVD_10 = (136 << 16) | 4,
00089 MOV_CH_LAYOUT_DVD_11 = (137 << 16) | 5,
00090 MOV_CH_LAYOUT_DVD_18 = (138 << 16) | 5,
00091 MOV_CH_LAYOUT_AUDIOUNIT_6_0 = (139 << 16) | 6,
00092 MOV_CH_LAYOUT_AUDIOUNIT_7_0 = (140 << 16) | 7,
00093 MOV_CH_LAYOUT_AUDIOUNIT_7_0_FRONT = (148 << 16) | 7,
00094 MOV_CH_LAYOUT_AAC_6_0 = (141 << 16) | 6,
00095 MOV_CH_LAYOUT_AAC_6_1 = (142 << 16) | 7,
00096 MOV_CH_LAYOUT_AAC_7_0 = (143 << 16) | 7,
00097 MOV_CH_LAYOUT_AAC_OCTAGONAL = (144 << 16) | 8,
00098 MOV_CH_LAYOUT_TMH_10_2_STD = (145 << 16) | 16,
00099 MOV_CH_LAYOUT_TMH_10_2_FULL = (146 << 16) | 21,
00100 MOV_CH_LAYOUT_AC3_1_0_1 = (149 << 16) | 2,
00101 MOV_CH_LAYOUT_AC3_3_0 = (150 << 16) | 3,
00102 MOV_CH_LAYOUT_AC3_3_1 = (151 << 16) | 4,
00103 MOV_CH_LAYOUT_AC3_3_0_1 = (152 << 16) | 4,
00104 MOV_CH_LAYOUT_AC3_2_1_1 = (153 << 16) | 4,
00105 MOV_CH_LAYOUT_AC3_3_1_1 = (154 << 16) | 5,
00106 MOV_CH_LAYOUT_EAC3_6_0_A = (155 << 16) | 6,
00107 MOV_CH_LAYOUT_EAC3_7_0_A = (156 << 16) | 7,
00108 MOV_CH_LAYOUT_EAC3_6_1_A = (157 << 16) | 7,
00109 MOV_CH_LAYOUT_EAC3_6_1_B = (158 << 16) | 7,
00110 MOV_CH_LAYOUT_EAC3_6_1_C = (159 << 16) | 7,
00111 MOV_CH_LAYOUT_EAC3_7_1_A = (160 << 16) | 8,
00112 MOV_CH_LAYOUT_EAC3_7_1_B = (161 << 16) | 8,
00113 MOV_CH_LAYOUT_EAC3_7_1_C = (162 << 16) | 8,
00114 MOV_CH_LAYOUT_EAC3_7_1_D = (163 << 16) | 8,
00115 MOV_CH_LAYOUT_EAC3_7_1_E = (164 << 16) | 8,
00116 MOV_CH_LAYOUT_EAC3_7_1_F = (165 << 16) | 8,
00117 MOV_CH_LAYOUT_EAC3_7_1_G = (166 << 16) | 8,
00118 MOV_CH_LAYOUT_EAC3_7_1_H = (167 << 16) | 8,
00119 MOV_CH_LAYOUT_DTS_3_1 = (168 << 16) | 4,
00120 MOV_CH_LAYOUT_DTS_4_1 = (169 << 16) | 5,
00121 MOV_CH_LAYOUT_DTS_6_0_A = (170 << 16) | 6,
00122 MOV_CH_LAYOUT_DTS_6_0_B = (171 << 16) | 6,
00123 MOV_CH_LAYOUT_DTS_6_0_C = (172 << 16) | 6,
00124 MOV_CH_LAYOUT_DTS_6_1_A = (173 << 16) | 7,
00125 MOV_CH_LAYOUT_DTS_6_1_B = (174 << 16) | 7,
00126 MOV_CH_LAYOUT_DTS_6_1_C = (175 << 16) | 7,
00127 MOV_CH_LAYOUT_DTS_6_1_D = (182 << 16) | 7,
00128 MOV_CH_LAYOUT_DTS_7_0 = (176 << 16) | 7,
00129 MOV_CH_LAYOUT_DTS_7_1 = (177 << 16) | 8,
00130 MOV_CH_LAYOUT_DTS_8_0_A = (178 << 16) | 8,
00131 MOV_CH_LAYOUT_DTS_8_0_B = (179 << 16) | 8,
00132 MOV_CH_LAYOUT_DTS_8_1_A = (180 << 16) | 9,
00133 MOV_CH_LAYOUT_DTS_8_1_B = (181 << 16) | 9,
00134 };
00135
00136 struct MovChannelLayoutMap {
00137 uint32_t tag;
00138 uint64_t layout;
00139 };
00140
00141 static const struct MovChannelLayoutMap mov_ch_layout_map_misc[] = {
00142 { MOV_CH_LAYOUT_USE_DESCRIPTIONS, 0 },
00143 { MOV_CH_LAYOUT_USE_BITMAP, 0 },
00144 { MOV_CH_LAYOUT_DISCRETEINORDER, 0 },
00145 { MOV_CH_LAYOUT_UNKNOWN, 0 },
00146 { MOV_CH_LAYOUT_TMH_10_2_STD, 0 },
00147
00148
00149 { MOV_CH_LAYOUT_TMH_10_2_FULL, 0 },
00150
00151
00152
00153 { 0, 0 },
00154 };
00155
00156 static const struct MovChannelLayoutMap mov_ch_layout_map_1ch[] = {
00157 { MOV_CH_LAYOUT_MONO, AV_CH_LAYOUT_MONO },
00158 };
00159
00160 static const struct MovChannelLayoutMap mov_ch_layout_map_2ch[] = {
00161 { MOV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO },
00162 { MOV_CH_LAYOUT_STEREOHEADPHONES, AV_CH_LAYOUT_STEREO },
00163 { MOV_CH_LAYOUT_BINAURAL, AV_CH_LAYOUT_STEREO },
00164 { MOV_CH_LAYOUT_MIDSIDE, AV_CH_LAYOUT_STEREO },
00165 { MOV_CH_LAYOUT_XY, AV_CH_LAYOUT_STEREO },
00166
00167 { MOV_CH_LAYOUT_MATRIXSTEREO, AV_CH_LAYOUT_STEREO_DOWNMIX },
00168
00169 { MOV_CH_LAYOUT_AC3_1_0_1, AV_CH_LAYOUT_MONO |
00170 AV_CH_LOW_FREQUENCY },
00171 { 0, 0 },
00172 };
00173
00174 static const struct MovChannelLayoutMap mov_ch_layout_map_3ch[] = {
00175 { MOV_CH_LAYOUT_MPEG_3_0_A, AV_CH_LAYOUT_SURROUND },
00176 { MOV_CH_LAYOUT_MPEG_3_0_B, AV_CH_LAYOUT_SURROUND },
00177 { MOV_CH_LAYOUT_AC3_3_0, AV_CH_LAYOUT_SURROUND },
00178
00179 { MOV_CH_LAYOUT_ITU_2_1, AV_CH_LAYOUT_2_1 },
00180
00181 { MOV_CH_LAYOUT_DVD_4, AV_CH_LAYOUT_2POINT1 },
00182 { 0, 0 },
00183 };
00184
00185 static const struct MovChannelLayoutMap mov_ch_layout_map_4ch[] = {
00186 { MOV_CH_LAYOUT_AMBISONIC_B_FORMAT, 0 },
00187
00188 { MOV_CH_LAYOUT_QUADRAPHONIC, AV_CH_LAYOUT_QUAD },
00189
00190 { MOV_CH_LAYOUT_MPEG_4_0_A, AV_CH_LAYOUT_4POINT0 },
00191 { MOV_CH_LAYOUT_MPEG_4_0_B, AV_CH_LAYOUT_4POINT0 },
00192 { MOV_CH_LAYOUT_AC3_3_1, AV_CH_LAYOUT_4POINT0 },
00193
00194 { MOV_CH_LAYOUT_ITU_2_2, AV_CH_LAYOUT_2_2 },
00195
00196 { MOV_CH_LAYOUT_DVD_5, AV_CH_LAYOUT_2_1 |
00197 AV_CH_LOW_FREQUENCY },
00198 { MOV_CH_LAYOUT_AC3_2_1_1, AV_CH_LAYOUT_2_1 |
00199 AV_CH_LOW_FREQUENCY },
00200
00201 { MOV_CH_LAYOUT_DVD_10, AV_CH_LAYOUT_3POINT1 },
00202 { MOV_CH_LAYOUT_AC3_3_0_1, AV_CH_LAYOUT_3POINT1 },
00203 { MOV_CH_LAYOUT_DTS_3_1, AV_CH_LAYOUT_3POINT1 },
00204 { 0, 0 },
00205 };
00206
00207 static const struct MovChannelLayoutMap mov_ch_layout_map_5ch[] = {
00208 { MOV_CH_LAYOUT_PENTAGONAL, AV_CH_LAYOUT_5POINT0_BACK },
00209
00210 { MOV_CH_LAYOUT_MPEG_5_0_A, AV_CH_LAYOUT_5POINT0 },
00211 { MOV_CH_LAYOUT_MPEG_5_0_B, AV_CH_LAYOUT_5POINT0 },
00212 { MOV_CH_LAYOUT_MPEG_5_0_C, AV_CH_LAYOUT_5POINT0 },
00213 { MOV_CH_LAYOUT_MPEG_5_0_D, AV_CH_LAYOUT_5POINT0 },
00214
00215 { MOV_CH_LAYOUT_DVD_6, AV_CH_LAYOUT_2_2 |
00216 AV_CH_LOW_FREQUENCY },
00217 { MOV_CH_LAYOUT_DVD_18, AV_CH_LAYOUT_2_2 |
00218 AV_CH_LOW_FREQUENCY },
00219
00220 { MOV_CH_LAYOUT_DVD_11, AV_CH_LAYOUT_4POINT1 },
00221 { MOV_CH_LAYOUT_AC3_3_1_1, AV_CH_LAYOUT_4POINT1 },
00222 { MOV_CH_LAYOUT_DTS_4_1, AV_CH_LAYOUT_4POINT1 },
00223 { 0, 0 },
00224 };
00225
00226 static const struct MovChannelLayoutMap mov_ch_layout_map_6ch[] = {
00227 { MOV_CH_LAYOUT_HEXAGONAL, AV_CH_LAYOUT_HEXAGONAL },
00228 { MOV_CH_LAYOUT_DTS_6_0_C, AV_CH_LAYOUT_HEXAGONAL },
00229
00230 { MOV_CH_LAYOUT_MPEG_5_1_A, AV_CH_LAYOUT_5POINT1 },
00231 { MOV_CH_LAYOUT_MPEG_5_1_B, AV_CH_LAYOUT_5POINT1 },
00232 { MOV_CH_LAYOUT_MPEG_5_1_C, AV_CH_LAYOUT_5POINT1 },
00233 { MOV_CH_LAYOUT_MPEG_5_1_D, AV_CH_LAYOUT_5POINT1 },
00234
00235 { MOV_CH_LAYOUT_AUDIOUNIT_6_0, AV_CH_LAYOUT_6POINT0 },
00236 { MOV_CH_LAYOUT_AAC_6_0, AV_CH_LAYOUT_6POINT0 },
00237 { MOV_CH_LAYOUT_EAC3_6_0_A, AV_CH_LAYOUT_6POINT0 },
00238
00239 { MOV_CH_LAYOUT_DTS_6_0_A, AV_CH_LAYOUT_6POINT0_FRONT },
00240
00241 { MOV_CH_LAYOUT_DTS_6_0_B, AV_CH_LAYOUT_5POINT0_BACK |
00242 AV_CH_TOP_CENTER },
00243 { 0, 0 },
00244 };
00245
00246 static const struct MovChannelLayoutMap mov_ch_layout_map_7ch[] = {
00247 { MOV_CH_LAYOUT_MPEG_6_1_A, AV_CH_LAYOUT_6POINT1 },
00248 { MOV_CH_LAYOUT_AAC_6_1, AV_CH_LAYOUT_6POINT1 },
00249 { MOV_CH_LAYOUT_EAC3_6_1_A, AV_CH_LAYOUT_6POINT1 },
00250 { MOV_CH_LAYOUT_DTS_6_1_D, AV_CH_LAYOUT_6POINT1 },
00251
00252 { MOV_CH_LAYOUT_AUDIOUNIT_7_0, AV_CH_LAYOUT_7POINT0 },
00253 { MOV_CH_LAYOUT_AAC_7_0, AV_CH_LAYOUT_7POINT0 },
00254 { MOV_CH_LAYOUT_EAC3_7_0_A, AV_CH_LAYOUT_7POINT0 },
00255
00256 { MOV_CH_LAYOUT_AUDIOUNIT_7_0_FRONT, AV_CH_LAYOUT_7POINT0_FRONT },
00257 { MOV_CH_LAYOUT_DTS_7_0, AV_CH_LAYOUT_7POINT0_FRONT },
00258
00259 { MOV_CH_LAYOUT_EAC3_6_1_B, AV_CH_LAYOUT_5POINT1 |
00260 AV_CH_TOP_CENTER },
00261
00262 { MOV_CH_LAYOUT_EAC3_6_1_C, AV_CH_LAYOUT_5POINT1 |
00263 AV_CH_TOP_FRONT_CENTER },
00264
00265 { MOV_CH_LAYOUT_DTS_6_1_A, AV_CH_LAYOUT_6POINT1_FRONT },
00266
00267 { MOV_CH_LAYOUT_DTS_6_1_B, AV_CH_LAYOUT_5POINT1_BACK |
00268 AV_CH_TOP_CENTER },
00269
00270 { MOV_CH_LAYOUT_DTS_6_1_C, AV_CH_LAYOUT_6POINT1_BACK },
00271 { 0, 0 },
00272 };
00273
00274 static const struct MovChannelLayoutMap mov_ch_layout_map_8ch[] = {
00275 { MOV_CH_LAYOUT_OCTAGONAL, AV_CH_LAYOUT_OCTAGONAL },
00276 { MOV_CH_LAYOUT_AAC_OCTAGONAL, AV_CH_LAYOUT_OCTAGONAL },
00277
00278 { MOV_CH_LAYOUT_CUBE, AV_CH_LAYOUT_QUAD |
00279 AV_CH_TOP_FRONT_LEFT |
00280 AV_CH_TOP_FRONT_RIGHT |
00281 AV_CH_TOP_BACK_LEFT |
00282 AV_CH_TOP_BACK_RIGHT },
00283
00284 { MOV_CH_LAYOUT_MPEG_7_1_A, AV_CH_LAYOUT_7POINT1_WIDE },
00285 { MOV_CH_LAYOUT_MPEG_7_1_B, AV_CH_LAYOUT_7POINT1_WIDE },
00286 { MOV_CH_LAYOUT_EMAGIC_DEFAULT_7_1, AV_CH_LAYOUT_7POINT1_WIDE },
00287 { MOV_CH_LAYOUT_EAC3_7_1_B, AV_CH_LAYOUT_7POINT1_WIDE },
00288 { MOV_CH_LAYOUT_DTS_7_1, AV_CH_LAYOUT_7POINT1_WIDE },
00289
00290 { MOV_CH_LAYOUT_MPEG_7_1_C, AV_CH_LAYOUT_7POINT1 },
00291 { MOV_CH_LAYOUT_EAC3_7_1_A, AV_CH_LAYOUT_7POINT1 },
00292
00293 { MOV_CH_LAYOUT_SMPTE_DTV, AV_CH_LAYOUT_5POINT1 |
00294 AV_CH_LAYOUT_STEREO_DOWNMIX },
00295
00296 { MOV_CH_LAYOUT_EAC3_7_1_C, AV_CH_LAYOUT_5POINT1 |
00297 AV_CH_SURROUND_DIRECT_LEFT |
00298 AV_CH_SURROUND_DIRECT_RIGHT },
00299
00300 { MOV_CH_LAYOUT_EAC3_7_1_D, AV_CH_LAYOUT_5POINT1 |
00301 AV_CH_WIDE_LEFT |
00302 AV_CH_WIDE_RIGHT },
00303
00304 { MOV_CH_LAYOUT_EAC3_7_1_E, AV_CH_LAYOUT_5POINT1 |
00305 AV_CH_TOP_FRONT_LEFT |
00306 AV_CH_TOP_FRONT_RIGHT },
00307
00308 { MOV_CH_LAYOUT_EAC3_7_1_F, AV_CH_LAYOUT_5POINT1 |
00309 AV_CH_BACK_CENTER |
00310 AV_CH_TOP_CENTER },
00311
00312 { MOV_CH_LAYOUT_EAC3_7_1_G, AV_CH_LAYOUT_5POINT1 |
00313 AV_CH_BACK_CENTER |
00314 AV_CH_TOP_FRONT_CENTER },
00315
00316 { MOV_CH_LAYOUT_EAC3_7_1_H, AV_CH_LAYOUT_5POINT1 |
00317 AV_CH_TOP_CENTER |
00318 AV_CH_TOP_FRONT_CENTER },
00319
00320 { MOV_CH_LAYOUT_DTS_8_0_A, AV_CH_LAYOUT_2_2 |
00321 AV_CH_BACK_LEFT |
00322 AV_CH_BACK_RIGHT |
00323 AV_CH_FRONT_LEFT_OF_CENTER |
00324 AV_CH_FRONT_RIGHT_OF_CENTER },
00325
00326 { MOV_CH_LAYOUT_DTS_8_0_B, AV_CH_LAYOUT_5POINT0 |
00327 AV_CH_FRONT_LEFT_OF_CENTER |
00328 AV_CH_FRONT_RIGHT_OF_CENTER |
00329 AV_CH_BACK_CENTER },
00330 { 0, 0 },
00331 };
00332
00333 static const struct MovChannelLayoutMap mov_ch_layout_map_9ch[] = {
00334 { MOV_CH_LAYOUT_DTS_8_1_A, AV_CH_LAYOUT_2_2 |
00335 AV_CH_BACK_LEFT |
00336 AV_CH_BACK_RIGHT |
00337 AV_CH_FRONT_LEFT_OF_CENTER |
00338 AV_CH_FRONT_RIGHT_OF_CENTER |
00339 AV_CH_LOW_FREQUENCY },
00340
00341 { MOV_CH_LAYOUT_DTS_8_1_B, AV_CH_LAYOUT_7POINT1_WIDE |
00342 AV_CH_BACK_CENTER },
00343 { 0, 0 },
00344 };
00345
00346 static const struct MovChannelLayoutMap *mov_ch_layout_map[] = {
00347 mov_ch_layout_map_misc,
00348 mov_ch_layout_map_1ch,
00349 mov_ch_layout_map_2ch,
00350 mov_ch_layout_map_3ch,
00351 mov_ch_layout_map_4ch,
00352 mov_ch_layout_map_5ch,
00353 mov_ch_layout_map_6ch,
00354 mov_ch_layout_map_7ch,
00355 mov_ch_layout_map_8ch,
00356 mov_ch_layout_map_9ch,
00357 };
00358
00359 static const enum MovChannelLayoutTag mov_ch_layouts_aac[] = {
00360 MOV_CH_LAYOUT_MONO,
00361 MOV_CH_LAYOUT_STEREO,
00362 MOV_CH_LAYOUT_AC3_1_0_1,
00363 MOV_CH_LAYOUT_MPEG_3_0_B,
00364 MOV_CH_LAYOUT_ITU_2_1,
00365 MOV_CH_LAYOUT_DVD_4,
00366 MOV_CH_LAYOUT_QUADRAPHONIC,
00367 MOV_CH_LAYOUT_MPEG_4_0_B,
00368 MOV_CH_LAYOUT_ITU_2_2,
00369 MOV_CH_LAYOUT_AC3_2_1_1,
00370 MOV_CH_LAYOUT_DTS_3_1,
00371 MOV_CH_LAYOUT_MPEG_5_0_D,
00372 MOV_CH_LAYOUT_DVD_18,
00373 MOV_CH_LAYOUT_DTS_4_1,
00374 MOV_CH_LAYOUT_MPEG_5_1_D,
00375 MOV_CH_LAYOUT_AAC_6_0,
00376 MOV_CH_LAYOUT_DTS_6_0_A,
00377 MOV_CH_LAYOUT_AAC_6_1,
00378 MOV_CH_LAYOUT_AAC_7_0,
00379 MOV_CH_LAYOUT_DTS_6_1_A,
00380 MOV_CH_LAYOUT_AAC_OCTAGONAL,
00381 MOV_CH_LAYOUT_MPEG_7_1_B,
00382 MOV_CH_LAYOUT_DTS_8_0_A,
00383 0,
00384 };
00385
00386 static const enum MovChannelLayoutTag mov_ch_layouts_ac3[] = {
00387 MOV_CH_LAYOUT_MONO,
00388 MOV_CH_LAYOUT_STEREO,
00389 MOV_CH_LAYOUT_AC3_1_0_1,
00390 MOV_CH_LAYOUT_AC3_3_0,
00391 MOV_CH_LAYOUT_ITU_2_1,
00392 MOV_CH_LAYOUT_DVD_4,
00393 MOV_CH_LAYOUT_AC3_3_1,
00394 MOV_CH_LAYOUT_ITU_2_2,
00395 MOV_CH_LAYOUT_AC3_2_1_1,
00396 MOV_CH_LAYOUT_AC3_3_0_1,
00397 MOV_CH_LAYOUT_MPEG_5_0_C,
00398 MOV_CH_LAYOUT_DVD_18,
00399 MOV_CH_LAYOUT_AC3_3_1_1,
00400 MOV_CH_LAYOUT_MPEG_5_1_C,
00401 0,
00402 };
00403
00404 static const enum MovChannelLayoutTag mov_ch_layouts_alac[] = {
00405 MOV_CH_LAYOUT_MONO,
00406 MOV_CH_LAYOUT_STEREO,
00407 MOV_CH_LAYOUT_MPEG_3_0_B,
00408 MOV_CH_LAYOUT_MPEG_4_0_B,
00409 MOV_CH_LAYOUT_MPEG_5_0_D,
00410 MOV_CH_LAYOUT_MPEG_5_1_D,
00411 MOV_CH_LAYOUT_AAC_6_1,
00412 MOV_CH_LAYOUT_MPEG_7_1_B,
00413 0,
00414 };
00415
00416 static const struct {
00417 enum CodecID codec_id;
00418 const enum MovChannelLayoutTag *layouts;
00419 } mov_codec_ch_layouts[] = {
00420 { CODEC_ID_AAC, mov_ch_layouts_aac },
00421 { CODEC_ID_AC3, mov_ch_layouts_ac3 },
00422 { CODEC_ID_ALAC, mov_ch_layouts_alac },
00423 { CODEC_ID_NONE, NULL },
00424 };
00425
00426 uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap)
00427 {
00428 int i, channels;
00429 const struct MovChannelLayoutMap *layout_map;
00430
00431
00432
00433 if (tag == MOV_CH_LAYOUT_USE_DESCRIPTIONS)
00434 return 0;
00435
00436
00437 if (tag == MOV_CH_LAYOUT_USE_BITMAP)
00438 return bitmap < 0x40000 ? bitmap : 0;
00439
00440
00441 channels = tag & 0xFFFF;
00442 if (channels > 9)
00443 channels = 0;
00444 layout_map = mov_ch_layout_map[channels];
00445
00446
00447 for (i = 0; layout_map[i].tag != 0; i++) {
00448 if (layout_map[i].tag == tag)
00449 break;
00450 }
00451 return layout_map[i].layout;
00452 }
00453
00454 uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id,
00455 uint64_t channel_layout,
00456 uint32_t *bitmap)
00457 {
00458 int i, j;
00459 uint32_t tag = 0;
00460 const enum MovChannelLayoutTag *layouts = NULL;
00461
00462
00463 for (i = 0; mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE; i++) {
00464 if (mov_codec_ch_layouts[i].codec_id == codec_id)
00465 break;
00466 }
00467 if (mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE)
00468 layouts = mov_codec_ch_layouts[i].layouts;
00469
00470 if (layouts) {
00471 int channels;
00472 const struct MovChannelLayoutMap *layout_map;
00473
00474
00475 channels = av_get_channel_layout_nb_channels(channel_layout);
00476 if (channels > 9)
00477 channels = 0;
00478 layout_map = mov_ch_layout_map[channels];
00479
00480
00481 for (i = 0; layouts[i] != 0; i++) {
00482 if (layouts[i] & 0xFFFF != channels)
00483 continue;
00484 for (j = 0; layout_map[j].tag != 0; j++) {
00485 if (layout_map[j].tag == layouts[i] &&
00486 layout_map[j].layout == channel_layout)
00487 break;
00488 }
00489 if (layout_map[j].tag)
00490 break;
00491 }
00492 tag = layouts[i];
00493 }
00494
00495
00496 if (tag == 0 && channel_layout > 0 && channel_layout < 0x40000) {
00497 tag = MOV_CH_LAYOUT_USE_BITMAP;
00498 *bitmap = (uint32_t)channel_layout;
00499 } else
00500 *bitmap = 0;
00501
00502
00503
00504 return tag;
00505 }