File size: 29,381 Bytes
8ead80b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 |
/*
* Copyright (c) 2011 Justin Ruggles
*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 FFmpeg; 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/channel_layout.h"
#include "libavcodec/codec_id.h"
#include "mov_chan.h"
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
{ 0, 0 },
};
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_CUBE }, // L, R, Rls, Rrs, Vhl, Vhr, Rlt, Rrt
{ 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 * const 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 enum MovChannelLayoutTag mov_ch_layouts_wav[] = {
MOV_CH_LAYOUT_MONO,
MOV_CH_LAYOUT_STEREO,
MOV_CH_LAYOUT_MATRIXSTEREO,
MOV_CH_LAYOUT_MPEG_3_0_A,
MOV_CH_LAYOUT_QUADRAPHONIC,
MOV_CH_LAYOUT_MPEG_5_0_A,
MOV_CH_LAYOUT_MPEG_5_1_A,
MOV_CH_LAYOUT_MPEG_6_1_A,
MOV_CH_LAYOUT_MPEG_7_1_A,
MOV_CH_LAYOUT_MPEG_7_1_C,
MOV_CH_LAYOUT_SMPTE_DTV,
0,
};
static const struct {
enum AVCodecID codec_id;
const enum MovChannelLayoutTag *layouts;
} mov_codec_ch_layouts[] = {
{ AV_CODEC_ID_AAC, mov_ch_layouts_aac },
{ AV_CODEC_ID_AC3, mov_ch_layouts_ac3 },
{ AV_CODEC_ID_ALAC, mov_ch_layouts_alac },
{ AV_CODEC_ID_PCM_U8, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_S8, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_S16LE, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_S16BE, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_S24LE, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_S24BE, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_S32LE, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_S32BE, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_F32LE, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_F32BE, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_F64LE, mov_ch_layouts_wav },
{ AV_CODEC_ID_PCM_F64BE, mov_ch_layouts_wav },
{ AV_CODEC_ID_NONE, NULL },
};
/**
* 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
*/
static uint64_t mov_get_channel_layout(uint32_t tag, uint32_t bitmap)
{
int i, channels;
const struct MovChannelLayoutMap *layout_map;
/* use ff_mov_get_channel_label() to build a layout instead */
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;
}
static uint64_t mov_get_channel_mask(uint32_t label)
{
if (label == 0)
return 0;
if (label <= 18)
return 1U << (label - 1);
if (label == 35)
return AV_CH_WIDE_LEFT;
if (label == 36)
return AV_CH_WIDE_RIGHT;
if (label == 37)
return AV_CH_LOW_FREQUENCY_2;
if (label == 38)
return AV_CH_STEREO_LEFT;
if (label == 39)
return AV_CH_STEREO_RIGHT;
return 0;
}
static uint32_t mov_get_channel_label(enum AVChannel channel)
{
if (channel < 0)
return 0;
if (channel <= AV_CHAN_TOP_BACK_RIGHT)
return channel + 1;
if (channel == AV_CHAN_WIDE_LEFT)
return 35;
if (channel == AV_CHAN_WIDE_RIGHT)
return 36;
if (channel == AV_CHAN_LOW_FREQUENCY_2)
return 37;
if (channel == AV_CHAN_STEREO_LEFT)
return 38;
if (channel == AV_CHAN_STEREO_RIGHT)
return 39;
return 0;
}
int ff_mov_get_channel_layout_tag(const AVCodecParameters *par,
uint32_t *layout,
uint32_t *bitmap,
uint32_t **pchannel_desc)
{
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 != AV_CODEC_ID_NONE; i++) {
if (mov_codec_ch_layouts[i].codec_id == par->codec_id)
break;
}
if (mov_codec_ch_layouts[i].codec_id != AV_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 = par->ch_layout.nb_channels;
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] &&
(par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
layout_map[j].layout == par->ch_layout.u.mask))
break;
}
if (layout_map[j].tag)
break;
}
tag = layouts[i];
}
*layout = tag;
*bitmap = 0;
*pchannel_desc = NULL;
/* if no tag was found, use channel bitmap or description as a backup if possible */
if (tag == 0) {
uint32_t *channel_desc;
if (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
par->ch_layout.u.mask < 0x40000) {
*layout = MOV_CH_LAYOUT_USE_BITMAP;
*bitmap = (uint32_t)par->ch_layout.u.mask;
return 0;
} else if (par->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
return AVERROR(ENOSYS);
channel_desc = av_malloc_array(par->ch_layout.nb_channels, sizeof(*channel_desc));
if (!channel_desc)
return AVERROR(ENOMEM);
for (i = 0; i < par->ch_layout.nb_channels; i++) {
channel_desc[i] =
mov_get_channel_label(av_channel_layout_channel_from_index(&par->ch_layout, i));
if (channel_desc[i] == 0) {
av_free(channel_desc);
return AVERROR(ENOSYS);
}
}
*pchannel_desc = channel_desc;
}
return 0;
}
int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
int64_t size)
{
uint32_t layout_tag, bitmap, num_descr;
uint64_t label_mask, mask = 0;
int i;
if (size < 12)
return AVERROR_INVALIDDATA;
layout_tag = avio_rb32(pb);
bitmap = avio_rb32(pb);
num_descr = avio_rb32(pb);
av_log(s, AV_LOG_DEBUG, "chan: layout=%"PRIu32" "
"bitmap=%"PRIu32" num_descr=%"PRIu32"\n",
layout_tag, bitmap, num_descr);
if (size < 12ULL + num_descr * 20ULL)
return 0;
label_mask = 0;
for (i = 0; i < num_descr; i++) {
uint32_t label;
if (pb->eof_reached) {
av_log(s, AV_LOG_ERROR,
"reached EOF while reading channel layout\n");
return AVERROR_INVALIDDATA;
}
label = avio_rb32(pb); // mChannelLabel
avio_rb32(pb); // mChannelFlags
avio_rl32(pb); // mCoordinates[0]
avio_rl32(pb); // mCoordinates[1]
avio_rl32(pb); // mCoordinates[2]
size -= 20;
if (layout_tag == 0) {
uint64_t mask_incr = mov_get_channel_mask(label);
if (mask_incr == 0) {
label_mask = 0;
break;
}
label_mask |= mask_incr;
}
}
if (layout_tag == 0) {
if (label_mask)
mask = label_mask;
} else
mask = mov_get_channel_layout(layout_tag, bitmap);
if (mask) {
av_channel_layout_uninit(&st->codecpar->ch_layout);
av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
}
avio_skip(pb, size - 12);
return 0;
}
/* ISO/IEC 23001-8, 8.2 */
static const AVChannelLayout iso_channel_configuration[] = {
// 0: any setup
{0},
// 1: centre front
AV_CHANNEL_LAYOUT_MONO,
// 2: left front, right front
AV_CHANNEL_LAYOUT_STEREO,
// 3: centre front, left front, right front
AV_CHANNEL_LAYOUT_SURROUND,
// 4: centre front, left front, right front, rear centre
AV_CHANNEL_LAYOUT_4POINT0,
// 5: centre front, left front, right front, left surround, right surround
AV_CHANNEL_LAYOUT_5POINT0,
// 6: 5 + LFE
AV_CHANNEL_LAYOUT_5POINT1,
// 7: centre front, left front centre, right front centre,
// left front, right front, left surround, right surround, LFE
AV_CHANNEL_LAYOUT_7POINT1_WIDE,
// 8: channel1, channel2
AV_CHANNEL_LAYOUT_STEREO_DOWNMIX,
// 9: left front, right front, rear centre
AV_CHANNEL_LAYOUT_2_1,
// 10: left front, right front, left surround, right surround
AV_CHANNEL_LAYOUT_2_2,
// 11: centre front, left front, right front, left surround, right surround, rear centre, LFE
AV_CHANNEL_LAYOUT_6POINT1,
// 12: centre front, left front, right front
// left surround, right surround
// rear surround left, rear surround right
// LFE
AV_CHANNEL_LAYOUT_7POINT1,
// 13:
AV_CHANNEL_LAYOUT_22POINT2,
// 14:
AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK,
// TODO: 15 - 20
};
/* ISO/IEC 23001-8, table 8 */
static const enum AVChannel iso_channel_position[] = {
// 0: left front
AV_CHAN_FRONT_LEFT,
// 1: right front
AV_CHAN_FRONT_RIGHT,
// 2: centre front
AV_CHAN_FRONT_CENTER,
// 3: low frequence enhancement
AV_CHAN_LOW_FREQUENCY,
// 4: left surround
// TODO
AV_CHAN_NONE,
// 5: right surround
// TODO
AV_CHAN_NONE,
// 6: left front centre
AV_CHAN_FRONT_LEFT_OF_CENTER,
// 7: right front centre
AV_CHAN_FRONT_RIGHT_OF_CENTER,
// 8: rear surround left
AV_CHAN_BACK_LEFT,
// 9: rear surround right
AV_CHAN_BACK_RIGHT,
// 10: rear centre
AV_CHAN_BACK_CENTER,
// 11: left surround direct
AV_CHAN_SURROUND_DIRECT_LEFT,
// 12: right surround direct
AV_CHAN_SURROUND_DIRECT_RIGHT,
// 13: left side surround
AV_CHAN_SIDE_LEFT,
// 14: right side surround
AV_CHAN_SIDE_RIGHT,
// 15: left wide front
AV_CHAN_WIDE_LEFT,
// 16: right wide front
AV_CHAN_WIDE_RIGHT,
// 17: left front vertical height
AV_CHAN_TOP_FRONT_LEFT,
// 18: right front vertical height
AV_CHAN_TOP_FRONT_RIGHT,
// 19: centre front vertical height
AV_CHAN_TOP_FRONT_CENTER,
// 20: left surround vertical height rear
AV_CHAN_TOP_BACK_LEFT,
// 21: right surround vertical height rear
AV_CHAN_TOP_BACK_RIGHT,
// 22: centre vertical height rear
AV_CHAN_TOP_BACK_CENTER,
// 23: left vertical height side surround
AV_CHAN_TOP_SIDE_LEFT,
// 24: right vertical height side surround
AV_CHAN_TOP_SIDE_RIGHT,
// 25: top centre surround
AV_CHAN_TOP_CENTER,
// 26: low frequency enhancement 2
AV_CHAN_LOW_FREQUENCY_2,
// 27: left front vertical bottom
AV_CHAN_BOTTOM_FRONT_LEFT,
// 28: right front vertical bottom
AV_CHAN_BOTTOM_FRONT_RIGHT,
// 29: centre front vertical bottom
AV_CHAN_BOTTOM_FRONT_CENTER,
// 30: left vertical height surround
// TODO
AV_CHAN_NONE,
// 31: right vertical height surround
// TODO
AV_CHAN_NONE,
// 32, 33, 34, 35, reserved
AV_CHAN_NONE,
AV_CHAN_NONE,
AV_CHAN_NONE,
AV_CHAN_NONE,
// 36: low frequency enhancement 3
AV_CHAN_NONE,
// 37: left edge of screen
AV_CHAN_NONE,
// 38: right edge of screen
AV_CHAN_NONE,
// 39: half-way between centre of screen and left edge of screen
AV_CHAN_NONE,
// 40: half-way between centre of screen and right edge of screen
AV_CHAN_NONE,
// 41: left back surround
AV_CHAN_NONE,
// 42: right back surround
AV_CHAN_NONE,
// 43 - 125: reserved
// 126: explicit position
// 127: unknown /undefined
};
int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *config)
{
// Set default value which means any setup in 23001-8
*config = 0;
for (int i = 0; i < FF_ARRAY_ELEMS(iso_channel_configuration); i++) {
if (!av_channel_layout_compare(layout, iso_channel_configuration + i)) {
*config = i;
break;
}
}
return 0;
}
int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout)
{
if (config > 0 && config < FF_ARRAY_ELEMS(iso_channel_configuration)) {
av_channel_layout_copy(layout, &iso_channel_configuration[config]);
return 0;
}
return -1;
}
int ff_mov_get_channel_positions_from_layout(const AVChannelLayout *layout,
uint8_t *position, int position_num)
{
enum AVChannel channel;
if (position_num < layout->nb_channels)
return AVERROR(EINVAL);
for (int i = 0; i < layout->nb_channels; i++) {
position[i] = 127;
channel = av_channel_layout_channel_from_index(layout, i);
if (channel == AV_CHAN_NONE)
return AVERROR(EINVAL);
for (int j = 0; j < FF_ARRAY_ELEMS(iso_channel_position); j++) {
if (iso_channel_position[j] == channel) {
position[i] = j;
break;
}
}
if (position[i] == 127)
return AVERROR(EINVAL);
}
return 0;
}
int ff_mov_get_layout_from_channel_positions(const uint8_t *position, int position_num,
AVChannelLayout *layout)
{
int ret;
enum AVChannel channel;
av_channel_layout_uninit(layout);
if (position_num <= 63) {
layout->order = AV_CHANNEL_ORDER_NATIVE;
layout->nb_channels = position_num;
for (int i = 0; i < position_num; i++) {
if (position[i] >= FF_ARRAY_ELEMS(iso_channel_position)) {
ret = AVERROR_PATCHWELCOME;
goto error;
}
channel = iso_channel_position[position[i]];
// unsupported layout
if (channel == AV_CHAN_NONE) {
ret = AVERROR_PATCHWELCOME;
goto error;
}
layout->u.mask |= 1ULL << channel;
}
} else {
layout->order = AV_CHANNEL_ORDER_CUSTOM;
layout->nb_channels = position_num;
layout->u.map = av_calloc(position_num, sizeof(*layout->u.map));
if (!layout->u.map) {
ret = AVERROR(ENOMEM);
goto error;
}
for (int i = 0; i < position_num; i++) {
if (position[i] >= FF_ARRAY_ELEMS(iso_channel_position)) {
ret = AVERROR_PATCHWELCOME;
goto error;
}
channel = iso_channel_position[position[i]];
// unsupported layout
if (channel == AV_CHAN_NONE) {
ret = AVERROR_PATCHWELCOME;
goto error;
}
layout->u.map[i].id = channel;
}
}
return 0;
error:
av_channel_layout_uninit(layout);
return ret;
}
|