channel_layout.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef API_AUDIO_CHANNEL_LAYOUT_H_
  11. #define API_AUDIO_CHANNEL_LAYOUT_H_
  12. namespace webrtc {
  13. // This file is derived from Chromium's base/channel_layout.h.
  14. // Enumerates the various representations of the ordering of audio channels.
  15. // Logged to UMA, so never reuse a value, always add new/greater ones!
  16. enum ChannelLayout {
  17. CHANNEL_LAYOUT_NONE = 0,
  18. CHANNEL_LAYOUT_UNSUPPORTED = 1,
  19. // Front C
  20. CHANNEL_LAYOUT_MONO = 2,
  21. // Front L, Front R
  22. CHANNEL_LAYOUT_STEREO = 3,
  23. // Front L, Front R, Back C
  24. CHANNEL_LAYOUT_2_1 = 4,
  25. // Front L, Front R, Front C
  26. CHANNEL_LAYOUT_SURROUND = 5,
  27. // Front L, Front R, Front C, Back C
  28. CHANNEL_LAYOUT_4_0 = 6,
  29. // Front L, Front R, Side L, Side R
  30. CHANNEL_LAYOUT_2_2 = 7,
  31. // Front L, Front R, Back L, Back R
  32. CHANNEL_LAYOUT_QUAD = 8,
  33. // Front L, Front R, Front C, Side L, Side R
  34. CHANNEL_LAYOUT_5_0 = 9,
  35. // Front L, Front R, Front C, LFE, Side L, Side R
  36. CHANNEL_LAYOUT_5_1 = 10,
  37. // Front L, Front R, Front C, Back L, Back R
  38. CHANNEL_LAYOUT_5_0_BACK = 11,
  39. // Front L, Front R, Front C, LFE, Back L, Back R
  40. CHANNEL_LAYOUT_5_1_BACK = 12,
  41. // Front L, Front R, Front C, Side L, Side R, Back L, Back R
  42. CHANNEL_LAYOUT_7_0 = 13,
  43. // Front L, Front R, Front C, LFE, Side L, Side R, Back L, Back R
  44. CHANNEL_LAYOUT_7_1 = 14,
  45. // Front L, Front R, Front C, LFE, Side L, Side R, Front LofC, Front RofC
  46. CHANNEL_LAYOUT_7_1_WIDE = 15,
  47. // Stereo L, Stereo R
  48. CHANNEL_LAYOUT_STEREO_DOWNMIX = 16,
  49. // Stereo L, Stereo R, LFE
  50. CHANNEL_LAYOUT_2POINT1 = 17,
  51. // Stereo L, Stereo R, Front C, LFE
  52. CHANNEL_LAYOUT_3_1 = 18,
  53. // Stereo L, Stereo R, Front C, Rear C, LFE
  54. CHANNEL_LAYOUT_4_1 = 19,
  55. // Stereo L, Stereo R, Front C, Side L, Side R, Back C
  56. CHANNEL_LAYOUT_6_0 = 20,
  57. // Stereo L, Stereo R, Side L, Side R, Front LofC, Front RofC
  58. CHANNEL_LAYOUT_6_0_FRONT = 21,
  59. // Stereo L, Stereo R, Front C, Rear L, Rear R, Rear C
  60. CHANNEL_LAYOUT_HEXAGONAL = 22,
  61. // Stereo L, Stereo R, Front C, LFE, Side L, Side R, Rear Center
  62. CHANNEL_LAYOUT_6_1 = 23,
  63. // Stereo L, Stereo R, Front C, LFE, Back L, Back R, Rear Center
  64. CHANNEL_LAYOUT_6_1_BACK = 24,
  65. // Stereo L, Stereo R, Side L, Side R, Front LofC, Front RofC, LFE
  66. CHANNEL_LAYOUT_6_1_FRONT = 25,
  67. // Front L, Front R, Front C, Side L, Side R, Front LofC, Front RofC
  68. CHANNEL_LAYOUT_7_0_FRONT = 26,
  69. // Front L, Front R, Front C, LFE, Back L, Back R, Front LofC, Front RofC
  70. CHANNEL_LAYOUT_7_1_WIDE_BACK = 27,
  71. // Front L, Front R, Front C, Side L, Side R, Rear L, Back R, Back C.
  72. CHANNEL_LAYOUT_OCTAGONAL = 28,
  73. // Channels are not explicitly mapped to speakers.
  74. CHANNEL_LAYOUT_DISCRETE = 29,
  75. // Front L, Front R, Front C. Front C contains the keyboard mic audio. This
  76. // layout is only intended for input for WebRTC. The Front C channel
  77. // is stripped away in the WebRTC audio input pipeline and never seen outside
  78. // of that.
  79. CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC = 30,
  80. // Front L, Front R, Side L, Side R, LFE
  81. CHANNEL_LAYOUT_4_1_QUAD_SIDE = 31,
  82. // Actual channel layout is specified in the bitstream and the actual channel
  83. // count is unknown at Chromium media pipeline level (useful for audio
  84. // pass-through mode).
  85. CHANNEL_LAYOUT_BITSTREAM = 32,
  86. // Max value, must always equal the largest entry ever logged.
  87. CHANNEL_LAYOUT_MAX = CHANNEL_LAYOUT_BITSTREAM
  88. };
  89. // Note: Do not reorder or reassign these values; other code depends on their
  90. // ordering to operate correctly. E.g., CoreAudio channel layout computations.
  91. enum Channels {
  92. LEFT = 0,
  93. RIGHT,
  94. CENTER,
  95. LFE,
  96. BACK_LEFT,
  97. BACK_RIGHT,
  98. LEFT_OF_CENTER,
  99. RIGHT_OF_CENTER,
  100. BACK_CENTER,
  101. SIDE_LEFT,
  102. SIDE_RIGHT,
  103. CHANNELS_MAX =
  104. SIDE_RIGHT, // Must always equal the largest value ever logged.
  105. };
  106. // The maximum number of concurrently active channels for all possible layouts.
  107. // ChannelLayoutToChannelCount() will never return a value higher than this.
  108. constexpr int kMaxConcurrentChannels = 8;
  109. // Returns the expected channel position in an interleaved stream. Values of -1
  110. // mean the channel at that index is not used for that layout. Values range
  111. // from 0 to ChannelLayoutToChannelCount(layout) - 1.
  112. int ChannelOrder(ChannelLayout layout, Channels channel);
  113. // Returns the number of channels in a given ChannelLayout.
  114. int ChannelLayoutToChannelCount(ChannelLayout layout);
  115. // Given the number of channels, return the best layout,
  116. // or return CHANNEL_LAYOUT_UNSUPPORTED if there is no good match.
  117. ChannelLayout GuessChannelLayout(int channels);
  118. // Returns a string representation of the channel layout.
  119. const char* ChannelLayoutToString(ChannelLayout layout);
  120. } // namespace webrtc
  121. #endif // API_AUDIO_CHANNEL_LAYOUT_H_