blob: 175aee71e53a1fdb7d75416b26e0d6f65b54fd6a [file] [log] [blame]
henrika2250b052019-07-04 11:27:52 +02001/*
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
11#ifndef API_AUDIO_CHANNEL_LAYOUT_H_
12#define API_AUDIO_CHANNEL_LAYOUT_H_
13
14namespace webrtc {
15
16// This file is derived from Chromium's base/channel_layout.h.
17
18// Enumerates the various representations of the ordering of audio channels.
19// Logged to UMA, so never reuse a value, always add new/greater ones!
20enum ChannelLayout {
21 CHANNEL_LAYOUT_NONE = 0,
22 CHANNEL_LAYOUT_UNSUPPORTED = 1,
23
24 // Front C
25 CHANNEL_LAYOUT_MONO = 2,
26
27 // Front L, Front R
28 CHANNEL_LAYOUT_STEREO = 3,
29
30 // Front L, Front R, Back C
31 CHANNEL_LAYOUT_2_1 = 4,
32
33 // Front L, Front R, Front C
34 CHANNEL_LAYOUT_SURROUND = 5,
35
36 // Front L, Front R, Front C, Back C
37 CHANNEL_LAYOUT_4_0 = 6,
38
39 // Front L, Front R, Side L, Side R
40 CHANNEL_LAYOUT_2_2 = 7,
41
42 // Front L, Front R, Back L, Back R
43 CHANNEL_LAYOUT_QUAD = 8,
44
45 // Front L, Front R, Front C, Side L, Side R
46 CHANNEL_LAYOUT_5_0 = 9,
47
48 // Front L, Front R, Front C, LFE, Side L, Side R
49 CHANNEL_LAYOUT_5_1 = 10,
50
51 // Front L, Front R, Front C, Back L, Back R
52 CHANNEL_LAYOUT_5_0_BACK = 11,
53
54 // Front L, Front R, Front C, LFE, Back L, Back R
55 CHANNEL_LAYOUT_5_1_BACK = 12,
56
57 // Front L, Front R, Front C, Side L, Side R, Back L, Back R
58 CHANNEL_LAYOUT_7_0 = 13,
59
60 // Front L, Front R, Front C, LFE, Side L, Side R, Back L, Back R
61 CHANNEL_LAYOUT_7_1 = 14,
62
63 // Front L, Front R, Front C, LFE, Side L, Side R, Front LofC, Front RofC
64 CHANNEL_LAYOUT_7_1_WIDE = 15,
65
66 // Stereo L, Stereo R
67 CHANNEL_LAYOUT_STEREO_DOWNMIX = 16,
68
69 // Stereo L, Stereo R, LFE
70 CHANNEL_LAYOUT_2POINT1 = 17,
71
72 // Stereo L, Stereo R, Front C, LFE
73 CHANNEL_LAYOUT_3_1 = 18,
74
75 // Stereo L, Stereo R, Front C, Rear C, LFE
76 CHANNEL_LAYOUT_4_1 = 19,
77
78 // Stereo L, Stereo R, Front C, Side L, Side R, Back C
79 CHANNEL_LAYOUT_6_0 = 20,
80
81 // Stereo L, Stereo R, Side L, Side R, Front LofC, Front RofC
82 CHANNEL_LAYOUT_6_0_FRONT = 21,
83
84 // Stereo L, Stereo R, Front C, Rear L, Rear R, Rear C
85 CHANNEL_LAYOUT_HEXAGONAL = 22,
86
87 // Stereo L, Stereo R, Front C, LFE, Side L, Side R, Rear Center
88 CHANNEL_LAYOUT_6_1 = 23,
89
90 // Stereo L, Stereo R, Front C, LFE, Back L, Back R, Rear Center
91 CHANNEL_LAYOUT_6_1_BACK = 24,
92
93 // Stereo L, Stereo R, Side L, Side R, Front LofC, Front RofC, LFE
94 CHANNEL_LAYOUT_6_1_FRONT = 25,
95
96 // Front L, Front R, Front C, Side L, Side R, Front LofC, Front RofC
97 CHANNEL_LAYOUT_7_0_FRONT = 26,
98
99 // Front L, Front R, Front C, LFE, Back L, Back R, Front LofC, Front RofC
100 CHANNEL_LAYOUT_7_1_WIDE_BACK = 27,
101
102 // Front L, Front R, Front C, Side L, Side R, Rear L, Back R, Back C.
103 CHANNEL_LAYOUT_OCTAGONAL = 28,
104
105 // Channels are not explicitly mapped to speakers.
106 CHANNEL_LAYOUT_DISCRETE = 29,
107
108 // Front L, Front R, Front C. Front C contains the keyboard mic audio. This
109 // layout is only intended for input for WebRTC. The Front C channel
110 // is stripped away in the WebRTC audio input pipeline and never seen outside
111 // of that.
112 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC = 30,
113
114 // Front L, Front R, Side L, Side R, LFE
115 CHANNEL_LAYOUT_4_1_QUAD_SIDE = 31,
116
117 // Actual channel layout is specified in the bitstream and the actual channel
118 // count is unknown at Chromium media pipeline level (useful for audio
119 // pass-through mode).
120 CHANNEL_LAYOUT_BITSTREAM = 32,
121
122 // Max value, must always equal the largest entry ever logged.
123 CHANNEL_LAYOUT_MAX = CHANNEL_LAYOUT_BITSTREAM
124};
125
126// Note: Do not reorder or reassign these values; other code depends on their
127// ordering to operate correctly. E.g., CoreAudio channel layout computations.
128enum Channels {
129 LEFT = 0,
130 RIGHT,
131 CENTER,
132 LFE,
133 BACK_LEFT,
134 BACK_RIGHT,
135 LEFT_OF_CENTER,
136 RIGHT_OF_CENTER,
137 BACK_CENTER,
138 SIDE_LEFT,
139 SIDE_RIGHT,
140 CHANNELS_MAX =
141 SIDE_RIGHT, // Must always equal the largest value ever logged.
142};
143
144// The maximum number of concurrently active channels for all possible layouts.
145// ChannelLayoutToChannelCount() will never return a value higher than this.
146constexpr int kMaxConcurrentChannels = 8;
147
148// Returns the expected channel position in an interleaved stream. Values of -1
149// mean the channel at that index is not used for that layout. Values range
150// from 0 to ChannelLayoutToChannelCount(layout) - 1.
151int ChannelOrder(ChannelLayout layout, Channels channel);
152
153// Returns the number of channels in a given ChannelLayout.
154int ChannelLayoutToChannelCount(ChannelLayout layout);
155
156// Given the number of channels, return the best layout,
157// or return CHANNEL_LAYOUT_UNSUPPORTED if there is no good match.
158ChannelLayout GuessChannelLayout(int channels);
159
160// Returns a string representation of the channel layout.
161const char* ChannelLayoutToString(ChannelLayout layout);
162
163} // namespace webrtc
164
165#endif // API_AUDIO_CHANNEL_LAYOUT_H_