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 enum MovChannelLayoutTag mov_ch_layouts_wav[] = {
00418 MOV_CH_LAYOUT_MONO,
00419 MOV_CH_LAYOUT_STEREO,
00420 MOV_CH_LAYOUT_MATRIXSTEREO,
00421 MOV_CH_LAYOUT_MPEG_3_0_A,
00422 MOV_CH_LAYOUT_QUADRAPHONIC,
00423 MOV_CH_LAYOUT_MPEG_5_0_A,
00424 MOV_CH_LAYOUT_MPEG_5_1_A,
00425 MOV_CH_LAYOUT_MPEG_6_1_A,
00426 MOV_CH_LAYOUT_MPEG_7_1_A,
00427 MOV_CH_LAYOUT_MPEG_7_1_C,
00428 MOV_CH_LAYOUT_SMPTE_DTV,
00429 };
00430
00431 static const struct {
00432 enum AVCodecID codec_id;
00433 const enum MovChannelLayoutTag *layouts;
00434 } mov_codec_ch_layouts[] = {
00435 { AV_CODEC_ID_AAC, mov_ch_layouts_aac },
00436 { AV_CODEC_ID_AC3, mov_ch_layouts_ac3 },
00437 { AV_CODEC_ID_ALAC, mov_ch_layouts_alac },
00438 { AV_CODEC_ID_PCM_U8, mov_ch_layouts_wav },
00439 { AV_CODEC_ID_PCM_S8, mov_ch_layouts_wav },
00440 { AV_CODEC_ID_PCM_S16LE, mov_ch_layouts_wav },
00441 { AV_CODEC_ID_PCM_S16BE, mov_ch_layouts_wav },
00442 { AV_CODEC_ID_PCM_S24LE, mov_ch_layouts_wav },
00443 { AV_CODEC_ID_PCM_S24BE, mov_ch_layouts_wav },
00444 { AV_CODEC_ID_PCM_S32LE, mov_ch_layouts_wav },
00445 { AV_CODEC_ID_PCM_S32BE, mov_ch_layouts_wav },
00446 { AV_CODEC_ID_PCM_F32LE, mov_ch_layouts_wav },
00447 { AV_CODEC_ID_PCM_F32BE, mov_ch_layouts_wav },
00448 { AV_CODEC_ID_PCM_F64LE, mov_ch_layouts_wav },
00449 { AV_CODEC_ID_PCM_F64BE, mov_ch_layouts_wav },
00450 { AV_CODEC_ID_NONE, NULL },
00451 };
00452
00453 uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap)
00454 {
00455 int i, channels;
00456 const struct MovChannelLayoutMap *layout_map;
00457
00458
00459 if (tag == MOV_CH_LAYOUT_USE_DESCRIPTIONS)
00460 return 0;
00461
00462
00463 if (tag == MOV_CH_LAYOUT_USE_BITMAP)
00464 return bitmap < 0x40000 ? bitmap : 0;
00465
00466
00467 channels = tag & 0xFFFF;
00468 if (channels > 9)
00469 channels = 0;
00470 layout_map = mov_ch_layout_map[channels];
00471
00472
00473 for (i = 0; layout_map[i].tag != 0; i++) {
00474 if (layout_map[i].tag == tag)
00475 break;
00476 }
00477 return layout_map[i].layout;
00478 }
00479
00480 static uint32_t mov_get_channel_label(uint32_t label)
00481 {
00482 if (label == 0)
00483 return 0;
00484 if (label <= 18)
00485 return 1U << (label - 1);
00486 if (label == 38)
00487 return AV_CH_STEREO_LEFT;
00488 if (label == 39)
00489 return AV_CH_STEREO_RIGHT;
00490 return 0;
00491 }
00492
00493 uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
00494 uint64_t channel_layout,
00495 uint32_t *bitmap)
00496 {
00497 int i, j;
00498 uint32_t tag = 0;
00499 const enum MovChannelLayoutTag *layouts = NULL;
00500
00501
00502 for (i = 0; mov_codec_ch_layouts[i].codec_id != AV_CODEC_ID_NONE; i++) {
00503 if (mov_codec_ch_layouts[i].codec_id == codec_id)
00504 break;
00505 }
00506 if (mov_codec_ch_layouts[i].codec_id != AV_CODEC_ID_NONE)
00507 layouts = mov_codec_ch_layouts[i].layouts;
00508
00509 if (layouts) {
00510 int channels;
00511 const struct MovChannelLayoutMap *layout_map;
00512
00513
00514 channels = av_get_channel_layout_nb_channels(channel_layout);
00515 if (channels > 9)
00516 channels = 0;
00517 layout_map = mov_ch_layout_map[channels];
00518
00519
00520 for (i = 0; layouts[i] != 0; i++) {
00521 if ((layouts[i] & 0xFFFF) != channels)
00522 continue;
00523 for (j = 0; layout_map[j].tag != 0; j++) {
00524 if (layout_map[j].tag == layouts[i] &&
00525 layout_map[j].layout == channel_layout)
00526 break;
00527 }
00528 if (layout_map[j].tag)
00529 break;
00530 }
00531 tag = layouts[i];
00532 }
00533
00534
00535 if (tag == 0 && channel_layout > 0 && channel_layout < 0x40000) {
00536 tag = MOV_CH_LAYOUT_USE_BITMAP;
00537 *bitmap = (uint32_t)channel_layout;
00538 } else
00539 *bitmap = 0;
00540
00541
00542
00543 return tag;
00544 }
00545
00546 int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
00547 int64_t size)
00548 {
00549 uint32_t layout_tag, bitmap, num_descr, label_mask;
00550 int i;
00551
00552 if (size < 12)
00553 return AVERROR_INVALIDDATA;
00554
00555 layout_tag = avio_rb32(pb);
00556 bitmap = avio_rb32(pb);
00557 num_descr = avio_rb32(pb);
00558
00559 av_dlog(s, "chan: layout=%u bitmap=%u num_descr=%u\n",
00560 layout_tag, bitmap, num_descr);
00561
00562 if (size < 12ULL + num_descr * 20ULL)
00563 return 0;
00564
00565 label_mask = 0;
00566 for (i = 0; i < num_descr; i++) {
00567 uint32_t label;
00568 label = avio_rb32(pb);
00569 avio_rb32(pb);
00570 avio_rl32(pb);
00571 avio_rl32(pb);
00572 avio_rl32(pb);
00573 size -= 20;
00574 if (layout_tag == 0) {
00575 uint32_t mask_incr = mov_get_channel_label(label);
00576 if (mask_incr == 0) {
00577 label_mask = 0;
00578 break;
00579 }
00580 label_mask |= mask_incr;
00581 }
00582 }
00583 if (layout_tag == 0) {
00584 if (label_mask)
00585 st->codec->channel_layout = label_mask;
00586 } else
00587 st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap);
00588 avio_skip(pb, size - 12);
00589
00590 return 0;
00591 }