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 { 0, 0 },
00159 };
00160
00161 static const struct MovChannelLayoutMap mov_ch_layout_map_2ch[] = {
00162 { MOV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO },
00163 { MOV_CH_LAYOUT_STEREOHEADPHONES, AV_CH_LAYOUT_STEREO },
00164 { MOV_CH_LAYOUT_BINAURAL, AV_CH_LAYOUT_STEREO },
00165 { MOV_CH_LAYOUT_MIDSIDE, AV_CH_LAYOUT_STEREO },
00166 { MOV_CH_LAYOUT_XY, AV_CH_LAYOUT_STEREO },
00167
00168 { MOV_CH_LAYOUT_MATRIXSTEREO, AV_CH_LAYOUT_STEREO_DOWNMIX },
00169
00170 { MOV_CH_LAYOUT_AC3_1_0_1, AV_CH_LAYOUT_MONO |
00171 AV_CH_LOW_FREQUENCY },
00172 { 0, 0 },
00173 };
00174
00175 static const struct MovChannelLayoutMap mov_ch_layout_map_3ch[] = {
00176 { MOV_CH_LAYOUT_MPEG_3_0_A, AV_CH_LAYOUT_SURROUND },
00177 { MOV_CH_LAYOUT_MPEG_3_0_B, AV_CH_LAYOUT_SURROUND },
00178 { MOV_CH_LAYOUT_AC3_3_0, AV_CH_LAYOUT_SURROUND },
00179
00180 { MOV_CH_LAYOUT_ITU_2_1, AV_CH_LAYOUT_2_1 },
00181
00182 { MOV_CH_LAYOUT_DVD_4, AV_CH_LAYOUT_2POINT1 },
00183 { 0, 0 },
00184 };
00185
00186 static const struct MovChannelLayoutMap mov_ch_layout_map_4ch[] = {
00187 { MOV_CH_LAYOUT_AMBISONIC_B_FORMAT, 0 },
00188
00189 { MOV_CH_LAYOUT_QUADRAPHONIC, AV_CH_LAYOUT_QUAD },
00190
00191 { MOV_CH_LAYOUT_MPEG_4_0_A, AV_CH_LAYOUT_4POINT0 },
00192 { MOV_CH_LAYOUT_MPEG_4_0_B, AV_CH_LAYOUT_4POINT0 },
00193 { MOV_CH_LAYOUT_AC3_3_1, AV_CH_LAYOUT_4POINT0 },
00194
00195 { MOV_CH_LAYOUT_ITU_2_2, AV_CH_LAYOUT_2_2 },
00196
00197 { MOV_CH_LAYOUT_DVD_5, AV_CH_LAYOUT_2_1 |
00198 AV_CH_LOW_FREQUENCY },
00199 { MOV_CH_LAYOUT_AC3_2_1_1, AV_CH_LAYOUT_2_1 |
00200 AV_CH_LOW_FREQUENCY },
00201
00202 { MOV_CH_LAYOUT_DVD_10, AV_CH_LAYOUT_3POINT1 },
00203 { MOV_CH_LAYOUT_AC3_3_0_1, AV_CH_LAYOUT_3POINT1 },
00204 { MOV_CH_LAYOUT_DTS_3_1, AV_CH_LAYOUT_3POINT1 },
00205 { 0, 0 },
00206 };
00207
00208 static const struct MovChannelLayoutMap mov_ch_layout_map_5ch[] = {
00209 { MOV_CH_LAYOUT_PENTAGONAL, AV_CH_LAYOUT_5POINT0_BACK },
00210
00211 { MOV_CH_LAYOUT_MPEG_5_0_A, AV_CH_LAYOUT_5POINT0 },
00212 { MOV_CH_LAYOUT_MPEG_5_0_B, AV_CH_LAYOUT_5POINT0 },
00213 { MOV_CH_LAYOUT_MPEG_5_0_C, AV_CH_LAYOUT_5POINT0 },
00214 { MOV_CH_LAYOUT_MPEG_5_0_D, AV_CH_LAYOUT_5POINT0 },
00215
00216 { MOV_CH_LAYOUT_DVD_6, AV_CH_LAYOUT_2_2 |
00217 AV_CH_LOW_FREQUENCY },
00218 { MOV_CH_LAYOUT_DVD_18, AV_CH_LAYOUT_2_2 |
00219 AV_CH_LOW_FREQUENCY },
00220
00221 { MOV_CH_LAYOUT_DVD_11, AV_CH_LAYOUT_4POINT1 },
00222 { MOV_CH_LAYOUT_AC3_3_1_1, AV_CH_LAYOUT_4POINT1 },
00223 { MOV_CH_LAYOUT_DTS_4_1, AV_CH_LAYOUT_4POINT1 },
00224 { 0, 0 },
00225 };
00226
00227 static const struct MovChannelLayoutMap mov_ch_layout_map_6ch[] = {
00228 { MOV_CH_LAYOUT_HEXAGONAL, AV_CH_LAYOUT_HEXAGONAL },
00229 { MOV_CH_LAYOUT_DTS_6_0_C, AV_CH_LAYOUT_HEXAGONAL },
00230
00231 { MOV_CH_LAYOUT_MPEG_5_1_A, AV_CH_LAYOUT_5POINT1 },
00232 { MOV_CH_LAYOUT_MPEG_5_1_B, AV_CH_LAYOUT_5POINT1 },
00233 { MOV_CH_LAYOUT_MPEG_5_1_C, AV_CH_LAYOUT_5POINT1 },
00234 { MOV_CH_LAYOUT_MPEG_5_1_D, AV_CH_LAYOUT_5POINT1 },
00235
00236 { MOV_CH_LAYOUT_AUDIOUNIT_6_0, AV_CH_LAYOUT_6POINT0 },
00237 { MOV_CH_LAYOUT_AAC_6_0, AV_CH_LAYOUT_6POINT0 },
00238 { MOV_CH_LAYOUT_EAC3_6_0_A, AV_CH_LAYOUT_6POINT0 },
00239
00240 { MOV_CH_LAYOUT_DTS_6_0_A, AV_CH_LAYOUT_6POINT0_FRONT },
00241
00242 { MOV_CH_LAYOUT_DTS_6_0_B, AV_CH_LAYOUT_5POINT0_BACK |
00243 AV_CH_TOP_CENTER },
00244 { 0, 0 },
00245 };
00246
00247 static const struct MovChannelLayoutMap mov_ch_layout_map_7ch[] = {
00248 { MOV_CH_LAYOUT_MPEG_6_1_A, AV_CH_LAYOUT_6POINT1 },
00249 { MOV_CH_LAYOUT_AAC_6_1, AV_CH_LAYOUT_6POINT1 },
00250 { MOV_CH_LAYOUT_EAC3_6_1_A, AV_CH_LAYOUT_6POINT1 },
00251 { MOV_CH_LAYOUT_DTS_6_1_D, AV_CH_LAYOUT_6POINT1 },
00252
00253 { MOV_CH_LAYOUT_AUDIOUNIT_7_0, AV_CH_LAYOUT_7POINT0 },
00254 { MOV_CH_LAYOUT_AAC_7_0, AV_CH_LAYOUT_7POINT0 },
00255 { MOV_CH_LAYOUT_EAC3_7_0_A, AV_CH_LAYOUT_7POINT0 },
00256
00257 { MOV_CH_LAYOUT_AUDIOUNIT_7_0_FRONT, AV_CH_LAYOUT_7POINT0_FRONT },
00258 { MOV_CH_LAYOUT_DTS_7_0, AV_CH_LAYOUT_7POINT0_FRONT },
00259
00260 { MOV_CH_LAYOUT_EAC3_6_1_B, AV_CH_LAYOUT_5POINT1 |
00261 AV_CH_TOP_CENTER },
00262
00263 { MOV_CH_LAYOUT_EAC3_6_1_C, AV_CH_LAYOUT_5POINT1 |
00264 AV_CH_TOP_FRONT_CENTER },
00265
00266 { MOV_CH_LAYOUT_DTS_6_1_A, AV_CH_LAYOUT_6POINT1_FRONT },
00267
00268 { MOV_CH_LAYOUT_DTS_6_1_B, AV_CH_LAYOUT_5POINT1_BACK |
00269 AV_CH_TOP_CENTER },
00270
00271 { MOV_CH_LAYOUT_DTS_6_1_C, AV_CH_LAYOUT_6POINT1_BACK },
00272 { 0, 0 },
00273 };
00274
00275 static const struct MovChannelLayoutMap mov_ch_layout_map_8ch[] = {
00276 { MOV_CH_LAYOUT_OCTAGONAL, AV_CH_LAYOUT_OCTAGONAL },
00277 { MOV_CH_LAYOUT_AAC_OCTAGONAL, AV_CH_LAYOUT_OCTAGONAL },
00278
00279 { MOV_CH_LAYOUT_CUBE, AV_CH_LAYOUT_QUAD |
00280 AV_CH_TOP_FRONT_LEFT |
00281 AV_CH_TOP_FRONT_RIGHT |
00282 AV_CH_TOP_BACK_LEFT |
00283 AV_CH_TOP_BACK_RIGHT },
00284
00285 { MOV_CH_LAYOUT_MPEG_7_1_A, AV_CH_LAYOUT_7POINT1_WIDE },
00286 { MOV_CH_LAYOUT_MPEG_7_1_B, AV_CH_LAYOUT_7POINT1_WIDE },
00287 { MOV_CH_LAYOUT_EMAGIC_DEFAULT_7_1, AV_CH_LAYOUT_7POINT1_WIDE },
00288 { MOV_CH_LAYOUT_EAC3_7_1_B, AV_CH_LAYOUT_7POINT1_WIDE },
00289 { MOV_CH_LAYOUT_DTS_7_1, AV_CH_LAYOUT_7POINT1_WIDE },
00290
00291 { MOV_CH_LAYOUT_MPEG_7_1_C, AV_CH_LAYOUT_7POINT1 },
00292 { MOV_CH_LAYOUT_EAC3_7_1_A, AV_CH_LAYOUT_7POINT1 },
00293
00294 { MOV_CH_LAYOUT_SMPTE_DTV, AV_CH_LAYOUT_5POINT1 |
00295 AV_CH_LAYOUT_STEREO_DOWNMIX },
00296
00297 { MOV_CH_LAYOUT_EAC3_7_1_C, AV_CH_LAYOUT_5POINT1 |
00298 AV_CH_SURROUND_DIRECT_LEFT |
00299 AV_CH_SURROUND_DIRECT_RIGHT },
00300
00301 { MOV_CH_LAYOUT_EAC3_7_1_D, AV_CH_LAYOUT_5POINT1 |
00302 AV_CH_WIDE_LEFT |
00303 AV_CH_WIDE_RIGHT },
00304
00305 { MOV_CH_LAYOUT_EAC3_7_1_E, AV_CH_LAYOUT_5POINT1 |
00306 AV_CH_TOP_FRONT_LEFT |
00307 AV_CH_TOP_FRONT_RIGHT },
00308
00309 { MOV_CH_LAYOUT_EAC3_7_1_F, AV_CH_LAYOUT_5POINT1 |
00310 AV_CH_BACK_CENTER |
00311 AV_CH_TOP_CENTER },
00312
00313 { MOV_CH_LAYOUT_EAC3_7_1_G, AV_CH_LAYOUT_5POINT1 |
00314 AV_CH_BACK_CENTER |
00315 AV_CH_TOP_FRONT_CENTER },
00316
00317 { MOV_CH_LAYOUT_EAC3_7_1_H, AV_CH_LAYOUT_5POINT1 |
00318 AV_CH_TOP_CENTER |
00319 AV_CH_TOP_FRONT_CENTER },
00320
00321 { MOV_CH_LAYOUT_DTS_8_0_A, AV_CH_LAYOUT_2_2 |
00322 AV_CH_BACK_LEFT |
00323 AV_CH_BACK_RIGHT |
00324 AV_CH_FRONT_LEFT_OF_CENTER |
00325 AV_CH_FRONT_RIGHT_OF_CENTER },
00326
00327 { MOV_CH_LAYOUT_DTS_8_0_B, AV_CH_LAYOUT_5POINT0 |
00328 AV_CH_FRONT_LEFT_OF_CENTER |
00329 AV_CH_FRONT_RIGHT_OF_CENTER |
00330 AV_CH_BACK_CENTER },
00331 { 0, 0 },
00332 };
00333
00334 static const struct MovChannelLayoutMap mov_ch_layout_map_9ch[] = {
00335 { MOV_CH_LAYOUT_DTS_8_1_A, AV_CH_LAYOUT_2_2 |
00336 AV_CH_BACK_LEFT |
00337 AV_CH_BACK_RIGHT |
00338 AV_CH_FRONT_LEFT_OF_CENTER |
00339 AV_CH_FRONT_RIGHT_OF_CENTER |
00340 AV_CH_LOW_FREQUENCY },
00341
00342 { MOV_CH_LAYOUT_DTS_8_1_B, AV_CH_LAYOUT_7POINT1_WIDE |
00343 AV_CH_BACK_CENTER },
00344 { 0, 0 },
00345 };
00346
00347 static const struct MovChannelLayoutMap *mov_ch_layout_map[] = {
00348 mov_ch_layout_map_misc,
00349 mov_ch_layout_map_1ch,
00350 mov_ch_layout_map_2ch,
00351 mov_ch_layout_map_3ch,
00352 mov_ch_layout_map_4ch,
00353 mov_ch_layout_map_5ch,
00354 mov_ch_layout_map_6ch,
00355 mov_ch_layout_map_7ch,
00356 mov_ch_layout_map_8ch,
00357 mov_ch_layout_map_9ch,
00358 };
00359
00360 static const enum MovChannelLayoutTag mov_ch_layouts_aac[] = {
00361 MOV_CH_LAYOUT_MONO,
00362 MOV_CH_LAYOUT_STEREO,
00363 MOV_CH_LAYOUT_AC3_1_0_1,
00364 MOV_CH_LAYOUT_MPEG_3_0_B,
00365 MOV_CH_LAYOUT_ITU_2_1,
00366 MOV_CH_LAYOUT_DVD_4,
00367 MOV_CH_LAYOUT_QUADRAPHONIC,
00368 MOV_CH_LAYOUT_MPEG_4_0_B,
00369 MOV_CH_LAYOUT_ITU_2_2,
00370 MOV_CH_LAYOUT_AC3_2_1_1,
00371 MOV_CH_LAYOUT_DTS_3_1,
00372 MOV_CH_LAYOUT_MPEG_5_0_D,
00373 MOV_CH_LAYOUT_DVD_18,
00374 MOV_CH_LAYOUT_DTS_4_1,
00375 MOV_CH_LAYOUT_MPEG_5_1_D,
00376 MOV_CH_LAYOUT_AAC_6_0,
00377 MOV_CH_LAYOUT_DTS_6_0_A,
00378 MOV_CH_LAYOUT_AAC_6_1,
00379 MOV_CH_LAYOUT_AAC_7_0,
00380 MOV_CH_LAYOUT_DTS_6_1_A,
00381 MOV_CH_LAYOUT_AAC_OCTAGONAL,
00382 MOV_CH_LAYOUT_MPEG_7_1_B,
00383 MOV_CH_LAYOUT_DTS_8_0_A,
00384 0,
00385 };
00386
00387 static const enum MovChannelLayoutTag mov_ch_layouts_ac3[] = {
00388 MOV_CH_LAYOUT_MONO,
00389 MOV_CH_LAYOUT_STEREO,
00390 MOV_CH_LAYOUT_AC3_1_0_1,
00391 MOV_CH_LAYOUT_AC3_3_0,
00392 MOV_CH_LAYOUT_ITU_2_1,
00393 MOV_CH_LAYOUT_DVD_4,
00394 MOV_CH_LAYOUT_AC3_3_1,
00395 MOV_CH_LAYOUT_ITU_2_2,
00396 MOV_CH_LAYOUT_AC3_2_1_1,
00397 MOV_CH_LAYOUT_AC3_3_0_1,
00398 MOV_CH_LAYOUT_MPEG_5_0_C,
00399 MOV_CH_LAYOUT_DVD_18,
00400 MOV_CH_LAYOUT_AC3_3_1_1,
00401 MOV_CH_LAYOUT_MPEG_5_1_C,
00402 0,
00403 };
00404
00405 static const enum MovChannelLayoutTag mov_ch_layouts_alac[] = {
00406 MOV_CH_LAYOUT_MONO,
00407 MOV_CH_LAYOUT_STEREO,
00408 MOV_CH_LAYOUT_MPEG_3_0_B,
00409 MOV_CH_LAYOUT_MPEG_4_0_B,
00410 MOV_CH_LAYOUT_MPEG_5_0_D,
00411 MOV_CH_LAYOUT_MPEG_5_1_D,
00412 MOV_CH_LAYOUT_AAC_6_1,
00413 MOV_CH_LAYOUT_MPEG_7_1_B,
00414 0,
00415 };
00416
00417 static const struct {
00418 enum CodecID codec_id;
00419 const enum MovChannelLayoutTag *layouts;
00420 } mov_codec_ch_layouts[] = {
00421 { CODEC_ID_AAC, mov_ch_layouts_aac },
00422 { CODEC_ID_AC3, mov_ch_layouts_ac3 },
00423 { CODEC_ID_ALAC, mov_ch_layouts_alac },
00424 { CODEC_ID_NONE, NULL },
00425 };
00426
00427 uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap)
00428 {
00429 int i, channels;
00430 const struct MovChannelLayoutMap *layout_map;
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_label(uint32_t label)
00455 {
00456 if (label == 0)
00457 return 0;
00458 if (label <= 18)
00459 return 1U << (label - 1);
00460 if (label == 38)
00461 return AV_CH_STEREO_LEFT;
00462 if (label == 39)
00463 return AV_CH_STEREO_RIGHT;
00464 return 0;
00465 }
00466
00467 uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id,
00468 uint64_t channel_layout,
00469 uint32_t *bitmap)
00470 {
00471 int i, j;
00472 uint32_t tag = 0;
00473 const enum MovChannelLayoutTag *layouts = NULL;
00474
00475
00476 for (i = 0; mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE; i++) {
00477 if (mov_codec_ch_layouts[i].codec_id == codec_id)
00478 break;
00479 }
00480 if (mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE)
00481 layouts = mov_codec_ch_layouts[i].layouts;
00482
00483 if (layouts) {
00484 int channels;
00485 const struct MovChannelLayoutMap *layout_map;
00486
00487
00488 channels = av_get_channel_layout_nb_channels(channel_layout);
00489 if (channels > 9)
00490 channels = 0;
00491 layout_map = mov_ch_layout_map[channels];
00492
00493
00494 for (i = 0; layouts[i] != 0; i++) {
00495 if (layouts[i] & 0xFFFF != channels)
00496 continue;
00497 for (j = 0; layout_map[j].tag != 0; j++) {
00498 if (layout_map[j].tag == layouts[i] &&
00499 layout_map[j].layout == channel_layout)
00500 break;
00501 }
00502 if (layout_map[j].tag)
00503 break;
00504 }
00505 tag = layouts[i];
00506 }
00507
00508
00509 if (tag == 0 && channel_layout > 0 && channel_layout < 0x40000) {
00510 tag = MOV_CH_LAYOUT_USE_BITMAP;
00511 *bitmap = (uint32_t)channel_layout;
00512 } else
00513 *bitmap = 0;
00514
00515
00516
00517 return tag;
00518 }