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.

167 lines
5.9KB

  1. /*
  2. * DCA compatible decoder
  3. * Copyright (C) 2004 Gildas Bazin
  4. * Copyright (C) 2004 Benjamin Zores
  5. * Copyright (C) 2006 Benjamin Larsson
  6. * Copyright (C) 2007 Konstantin Shishkov
  7. * Copyright (C) 2016 foo86
  8. *
  9. * This file is part of FFmpeg.
  10. *
  11. * FFmpeg is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2.1 of the License, or (at your option) any later version.
  15. *
  16. * FFmpeg is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with FFmpeg; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. */
  25. #ifndef AVCODEC_DCA_H
  26. #define AVCODEC_DCA_H
  27. #include <stdint.h>
  28. #include "libavutil/common.h"
  29. #include "libavutil/internal.h"
  30. #include "libavutil/intreadwrite.h"
  31. enum DCASpeaker {
  32. DCA_SPEAKER_C, DCA_SPEAKER_L, DCA_SPEAKER_R, DCA_SPEAKER_Ls,
  33. DCA_SPEAKER_Rs, DCA_SPEAKER_LFE1, DCA_SPEAKER_Cs, DCA_SPEAKER_Lsr,
  34. DCA_SPEAKER_Rsr, DCA_SPEAKER_Lss, DCA_SPEAKER_Rss, DCA_SPEAKER_Lc,
  35. DCA_SPEAKER_Rc, DCA_SPEAKER_Lh, DCA_SPEAKER_Ch, DCA_SPEAKER_Rh,
  36. DCA_SPEAKER_LFE2, DCA_SPEAKER_Lw, DCA_SPEAKER_Rw, DCA_SPEAKER_Oh,
  37. DCA_SPEAKER_Lhs, DCA_SPEAKER_Rhs, DCA_SPEAKER_Chr, DCA_SPEAKER_Lhr,
  38. DCA_SPEAKER_Rhr, DCA_SPEAKER_Cl, DCA_SPEAKER_Ll, DCA_SPEAKER_Rl,
  39. DCA_SPEAKER_RSV1, DCA_SPEAKER_RSV2, DCA_SPEAKER_RSV3, DCA_SPEAKER_RSV4,
  40. DCA_SPEAKER_COUNT
  41. };
  42. enum DCASpeakerMask {
  43. DCA_SPEAKER_MASK_C = 0x00000001,
  44. DCA_SPEAKER_MASK_L = 0x00000002,
  45. DCA_SPEAKER_MASK_R = 0x00000004,
  46. DCA_SPEAKER_MASK_Ls = 0x00000008,
  47. DCA_SPEAKER_MASK_Rs = 0x00000010,
  48. DCA_SPEAKER_MASK_LFE1 = 0x00000020,
  49. DCA_SPEAKER_MASK_Cs = 0x00000040,
  50. DCA_SPEAKER_MASK_Lsr = 0x00000080,
  51. DCA_SPEAKER_MASK_Rsr = 0x00000100,
  52. DCA_SPEAKER_MASK_Lss = 0x00000200,
  53. DCA_SPEAKER_MASK_Rss = 0x00000400,
  54. DCA_SPEAKER_MASK_Lc = 0x00000800,
  55. DCA_SPEAKER_MASK_Rc = 0x00001000,
  56. DCA_SPEAKER_MASK_Lh = 0x00002000,
  57. DCA_SPEAKER_MASK_Ch = 0x00004000,
  58. DCA_SPEAKER_MASK_Rh = 0x00008000,
  59. DCA_SPEAKER_MASK_LFE2 = 0x00010000,
  60. DCA_SPEAKER_MASK_Lw = 0x00020000,
  61. DCA_SPEAKER_MASK_Rw = 0x00040000,
  62. DCA_SPEAKER_MASK_Oh = 0x00080000,
  63. DCA_SPEAKER_MASK_Lhs = 0x00100000,
  64. DCA_SPEAKER_MASK_Rhs = 0x00200000,
  65. DCA_SPEAKER_MASK_Chr = 0x00400000,
  66. DCA_SPEAKER_MASK_Lhr = 0x00800000,
  67. DCA_SPEAKER_MASK_Rhr = 0x01000000,
  68. DCA_SPEAKER_MASK_Cl = 0x02000000,
  69. DCA_SPEAKER_MASK_Ll = 0x04000000,
  70. DCA_SPEAKER_MASK_Rl = 0x08000000,
  71. };
  72. #define DCA_SPEAKER_LAYOUT_MONO (DCA_SPEAKER_MASK_C)
  73. #define DCA_SPEAKER_LAYOUT_STEREO (DCA_SPEAKER_MASK_L | DCA_SPEAKER_MASK_R)
  74. #define DCA_SPEAKER_LAYOUT_2POINT1 (DCA_SPEAKER_LAYOUT_STEREO | DCA_SPEAKER_MASK_LFE1)
  75. #define DCA_SPEAKER_LAYOUT_3_0 (DCA_SPEAKER_LAYOUT_STEREO | DCA_SPEAKER_MASK_C)
  76. #define DCA_SPEAKER_LAYOUT_2_1 (DCA_SPEAKER_LAYOUT_STEREO | DCA_SPEAKER_MASK_Cs)
  77. #define DCA_SPEAKER_LAYOUT_3_1 (DCA_SPEAKER_LAYOUT_3_0 | DCA_SPEAKER_MASK_Cs)
  78. #define DCA_SPEAKER_LAYOUT_2_2 (DCA_SPEAKER_LAYOUT_STEREO | DCA_SPEAKER_MASK_Ls | DCA_SPEAKER_MASK_Rs)
  79. #define DCA_SPEAKER_LAYOUT_5POINT0 (DCA_SPEAKER_LAYOUT_3_0 | DCA_SPEAKER_MASK_Ls | DCA_SPEAKER_MASK_Rs)
  80. #define DCA_SPEAKER_LAYOUT_5POINT1 (DCA_SPEAKER_LAYOUT_5POINT0 | DCA_SPEAKER_MASK_LFE1)
  81. #define DCA_SPEAKER_LAYOUT_7POINT0_WIDE (DCA_SPEAKER_LAYOUT_5POINT0 | DCA_SPEAKER_MASK_Lw | DCA_SPEAKER_MASK_Rw)
  82. #define DCA_SPEAKER_LAYOUT_7POINT1_WIDE (DCA_SPEAKER_LAYOUT_7POINT0_WIDE | DCA_SPEAKER_MASK_LFE1)
  83. #define DCA_HAS_STEREO(mask) \
  84. ((mask & DCA_SPEAKER_LAYOUT_STEREO) == DCA_SPEAKER_LAYOUT_STEREO)
  85. enum DCASpeakerPair {
  86. DCA_SPEAKER_PAIR_C = 0x0001,
  87. DCA_SPEAKER_PAIR_LR = 0x0002,
  88. DCA_SPEAKER_PAIR_LsRs = 0x0004,
  89. DCA_SPEAKER_PAIR_LFE1 = 0x0008,
  90. DCA_SPEAKER_PAIR_Cs = 0x0010,
  91. DCA_SPEAKER_PAIR_LhRh = 0x0020,
  92. DCA_SPEAKER_PAIR_LsrRsr = 0x0040,
  93. DCA_SPEAKER_PAIR_Ch = 0x0080,
  94. DCA_SPEAKER_PAIR_Oh = 0x0100,
  95. DCA_SPEAKER_PAIR_LcRc = 0x0200,
  96. DCA_SPEAKER_PAIR_LwRw = 0x0400,
  97. DCA_SPEAKER_PAIR_LssRss = 0x0800,
  98. DCA_SPEAKER_PAIR_LFE2 = 0x1000,
  99. DCA_SPEAKER_PAIR_LhsRhs = 0x2000,
  100. DCA_SPEAKER_PAIR_Chr = 0x4000,
  101. DCA_SPEAKER_PAIR_LhrRhr = 0x8000
  102. };
  103. /**
  104. * Return number of individual channels in DCASpeakerPair mask
  105. */
  106. static inline int ff_dca_count_chs_for_mask(unsigned int mask)
  107. {
  108. return av_popcount((mask & 0xffff) | ((mask & 0xae66) << 16));
  109. }
  110. enum DCARepresentationType {
  111. DCA_REPR_TYPE_LtRt = 2,
  112. DCA_REPR_TYPE_LhRh = 3
  113. };
  114. enum DCAExtensionMask {
  115. DCA_CSS_CORE = 0x001,
  116. DCA_CSS_XXCH = 0x002,
  117. DCA_CSS_X96 = 0x004,
  118. DCA_CSS_XCH = 0x008,
  119. DCA_CSS_MASK = 0x00f,
  120. DCA_EXSS_CORE = 0x010,
  121. DCA_EXSS_XBR = 0x020,
  122. DCA_EXSS_XXCH = 0x040,
  123. DCA_EXSS_X96 = 0x080,
  124. DCA_EXSS_LBR = 0x100,
  125. DCA_EXSS_XLL = 0x200,
  126. DCA_EXSS_RSV1 = 0x400,
  127. DCA_EXSS_RSV2 = 0x800,
  128. DCA_EXSS_MASK = 0xff0,
  129. };
  130. enum DCADownMixType {
  131. DCA_DMIX_TYPE_1_0,
  132. DCA_DMIX_TYPE_LoRo,
  133. DCA_DMIX_TYPE_LtRt,
  134. DCA_DMIX_TYPE_3_0,
  135. DCA_DMIX_TYPE_2_1,
  136. DCA_DMIX_TYPE_2_2,
  137. DCA_DMIX_TYPE_3_1,
  138. DCA_DMIX_TYPE_COUNT
  139. };
  140. extern av_export const uint32_t avpriv_dca_sample_rates[16];
  141. extern const uint32_t ff_dca_sampling_freqs[16];
  142. extern const uint8_t ff_dca_freq_ranges[16];
  143. /**
  144. * Convert bitstream to one representation based on sync marker
  145. */
  146. int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
  147. int max_size);
  148. #endif /* AVCODEC_DCA_H */