You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
5.2KB

  1. /*
  2. * CAF common code
  3. * Copyright (c) 2007 Justin Ruggles
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * CAF common code
  24. */
  25. #include "avformat.h"
  26. #include "internal.h"
  27. #include "caf.h"
  28. /**
  29. * Known codec tags for CAF
  30. */
  31. const AVCodecTag ff_codec_caf_tags[] = {
  32. { CODEC_ID_AAC, MKBETAG('a','a','c',' ') },
  33. { CODEC_ID_AC3, MKBETAG('a','c','-','3') },
  34. { CODEC_ID_ALAC, MKBETAG('a','l','a','c') },
  35. /* FIXME: use DV demuxer, as done in MOV */
  36. /*{ CODEC_ID_DVAUDIO, MKBETAG('v','d','v','a') },*/
  37. /*{ CODEC_ID_DVAUDIO, MKBETAG('d','v','c','a') },*/
  38. { CODEC_ID_ADPCM_IMA_QT, MKBETAG('i','m','a','4') },
  39. { CODEC_ID_MACE3, MKBETAG('M','A','C','3') },
  40. { CODEC_ID_MACE6, MKBETAG('M','A','C','6') },
  41. { CODEC_ID_MP3, MKBETAG('.','m','p','3') },
  42. { CODEC_ID_MP2, MKBETAG('.','m','p','2') },
  43. { CODEC_ID_MP1, MKBETAG('.','m','p','1') },
  44. { CODEC_ID_PCM_ALAW, MKBETAG('a','l','a','w') },
  45. { CODEC_ID_PCM_MULAW, MKBETAG('u','l','a','w') },
  46. { CODEC_ID_QCELP, MKBETAG('Q','c','l','p') },
  47. { CODEC_ID_QDM2, MKBETAG('Q','D','M','2') },
  48. { CODEC_ID_QDM2, MKBETAG('Q','D','M','C') },
  49. /* currently unsupported codecs */
  50. /*{ AC-3 over S/PDIF MKBETAG('c','a','c','3') },*/
  51. /*{ MPEG4CELP MKBETAG('c','e','l','p') },*/
  52. /*{ MPEG4HVXC MKBETAG('h','v','x','c') },*/
  53. /*{ MPEG4TwinVQ MKBETAG('t','w','v','q') },*/
  54. { CODEC_ID_NONE, 0 },
  55. };
  56. typedef struct CafChannelLayout {
  57. int64_t channel_layout;
  58. uint32_t layout_tag;
  59. } CafChannelLayout;
  60. static const CafChannelLayout caf_channel_layout[] = {
  61. { AV_CH_LAYOUT_MONO, (100<<16) | 1}, //< kCAFChannelLayoutTag_Mono
  62. { AV_CH_LAYOUT_STEREO, (101<<16) | 2}, //< kCAFChannelLayoutTag_Stereo
  63. { AV_CH_LAYOUT_STEREO, (102<<16) | 2}, //< kCAFChannelLayoutTag_StereoHeadphones
  64. { AV_CH_LAYOUT_2_1, (131<<16) | 3}, //< kCAFChannelLayoutTag_ITU_2_1
  65. { AV_CH_LAYOUT_2_2, (132<<16) | 4}, //< kCAFChannelLayoutTag_ITU_2_2
  66. { AV_CH_LAYOUT_QUAD, (108<<16) | 4}, //< kCAFChannelLayoutTag_Quadraphonic
  67. { AV_CH_LAYOUT_SURROUND, (113<<16) | 3}, //< kCAFChannelLayoutTag_MPEG_3_0_A
  68. { AV_CH_LAYOUT_4POINT0, (115<<16) | 4}, //< kCAFChannelLayoutTag_MPEG_4_0_A
  69. { AV_CH_LAYOUT_5POINT0_BACK, (117<<16) | 5}, //< kCAFChannelLayoutTag_MPEG_5_0_A
  70. { AV_CH_LAYOUT_5POINT0, (117<<16) | 5}, //< kCAFChannelLayoutTag_MPEG_5_0_A
  71. { AV_CH_LAYOUT_5POINT1_BACK, (121<<16) | 6}, //< kCAFChannelLayoutTag_MPEG_5_1_A
  72. { AV_CH_LAYOUT_5POINT1, (121<<16) | 6}, //< kCAFChannelLayoutTag_MPEG_5_1_A
  73. { AV_CH_LAYOUT_7POINT1, (128<<16) | 8}, //< kCAFChannelLayoutTag_MPEG_7_1_C
  74. { AV_CH_LAYOUT_7POINT1_WIDE, (126<<16) | 8}, //< kCAFChannelLayoutTag_MPEG_7_1_A
  75. { AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, (133<<16) | 3}, //< kCAFChannelLayoutTag_DVD_4
  76. { AV_CH_LAYOUT_2_1|AV_CH_LOW_FREQUENCY, (134<<16) | 4}, //< kCAFChannelLayoutTag_DVD_5
  77. { AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY, (135<<16) | 4}, //< kCAFChannelLayoutTag_DVD_6
  78. { AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY, (136<<16) | 4}, //< kCAFChannelLayoutTag_DVD_10
  79. { AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY, (137<<16) | 5}, //< kCAFChannelLayoutTag_DVD_11
  80. { 0, 0},
  81. };
  82. void ff_read_chan_chunk(AVFormatContext *s, int64_t size, AVCodecContext *codec)
  83. {
  84. uint32_t layout_tag;
  85. AVIOContext *pb = s->pb;
  86. const CafChannelLayout *caf_layout = caf_channel_layout;
  87. if (size != 12) {
  88. // Channel descriptions not implemented
  89. av_log_ask_for_sample(s, "Unimplemented channel layout.\n");
  90. avio_skip(pb, size);
  91. return;
  92. }
  93. layout_tag = avio_rb32(pb);
  94. if (layout_tag == 0x10000) { //< kCAFChannelLayoutTag_UseChannelBitmap
  95. codec->channel_layout = avio_rb32(pb);
  96. avio_skip(pb, 4);
  97. return;
  98. }
  99. while (caf_layout->channel_layout) {
  100. if (layout_tag == caf_layout->layout_tag) {
  101. codec->channel_layout = caf_layout->channel_layout;
  102. break;
  103. }
  104. caf_layout++;
  105. }
  106. if (!codec->channel_layout)
  107. av_log(s, AV_LOG_WARNING, "Unknown channel layout.\n");
  108. avio_skip(pb, 8);
  109. }