1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_AUDIO_BASE_UTILS_H
18 #define ANDROID_AUDIO_BASE_UTILS_H
19 
20 #include "audio-base.h"
21 
22 /** Define helper values to iterate over enum, extend them or checking value validity.
23  *  Those values are compatible with the O corresponding enum values.
24  *  They are not macro like similar values in audio.h to avoid conflicting
25  *  with the libhardware_legacy audio.h.
26  */
27 enum {
28     /** Number of audio stream available to vendors. */
29     AUDIO_STREAM_PUBLIC_CNT = AUDIO_STREAM_ASSISTANT + 1,
30 
31 #ifndef AUDIO_NO_SYSTEM_DECLARATIONS
32     /** Total number of stream handled by the policy*/
33     AUDIO_STREAM_FOR_POLICY_CNT= AUDIO_STREAM_REROUTING + 1,
34 #endif
35 
36    /** Total number of stream. */
37     AUDIO_STREAM_CNT          = AUDIO_STREAM_PATCH + 1,
38 
39     AUDIO_SOURCE_MAX          = AUDIO_SOURCE_VOICE_PERFORMANCE,
40     AUDIO_SOURCE_CNT          = AUDIO_SOURCE_MAX + 1,
41 
42     AUDIO_MODE_MAX            = AUDIO_MODE_IN_COMMUNICATION,
43     AUDIO_MODE_CNT            = AUDIO_MODE_MAX + 1,
44 
45     /** For retrocompatibility AUDIO_MODE_* and AUDIO_STREAM_* must be signed. */
46     AUDIO_DETAIL_NEGATIVE_VALUE = -1,
47 };
48 
49 // TODO: remove audio device combination as it is not allowed to use as bit mask since R.
50 enum {
51     AUDIO_CHANNEL_OUT_ALL     = AUDIO_CHANNEL_OUT_FRONT_LEFT |
52                                 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
53                                 AUDIO_CHANNEL_OUT_FRONT_CENTER |
54                                 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
55                                 AUDIO_CHANNEL_OUT_BACK_LEFT |
56                                 AUDIO_CHANNEL_OUT_BACK_RIGHT |
57                                 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
58                                 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
59                                 AUDIO_CHANNEL_OUT_BACK_CENTER |
60                                 AUDIO_CHANNEL_OUT_SIDE_LEFT |
61                                 AUDIO_CHANNEL_OUT_SIDE_RIGHT |
62                                 AUDIO_CHANNEL_OUT_TOP_CENTER |
63                                 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT |
64                                 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER |
65                                 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT |
66                                 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT |
67                                 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER |
68                                 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT |
69                                 AUDIO_CHANNEL_OUT_TOP_SIDE_LEFT |
70                                 AUDIO_CHANNEL_OUT_TOP_SIDE_RIGHT |
71                                 AUDIO_CHANNEL_OUT_HAPTIC_B |
72                                 AUDIO_CHANNEL_OUT_HAPTIC_A,
73 
74     AUDIO_CHANNEL_IN_ALL      = AUDIO_CHANNEL_IN_LEFT |
75                                 AUDIO_CHANNEL_IN_RIGHT |
76                                 AUDIO_CHANNEL_IN_FRONT |
77                                 AUDIO_CHANNEL_IN_BACK|
78                                 AUDIO_CHANNEL_IN_LEFT_PROCESSED |
79                                 AUDIO_CHANNEL_IN_RIGHT_PROCESSED |
80                                 AUDIO_CHANNEL_IN_FRONT_PROCESSED |
81                                 AUDIO_CHANNEL_IN_BACK_PROCESSED|
82                                 AUDIO_CHANNEL_IN_PRESSURE |
83                                 AUDIO_CHANNEL_IN_X_AXIS |
84                                 AUDIO_CHANNEL_IN_Y_AXIS |
85                                 AUDIO_CHANNEL_IN_Z_AXIS |
86                                 AUDIO_CHANNEL_IN_VOICE_UPLINK |
87                                 AUDIO_CHANNEL_IN_VOICE_DNLINK |
88                                 AUDIO_CHANNEL_IN_BACK_LEFT |
89                                 AUDIO_CHANNEL_IN_BACK_RIGHT |
90                                 AUDIO_CHANNEL_IN_CENTER |
91                                 AUDIO_CHANNEL_IN_LOW_FREQUENCY |
92                                 AUDIO_CHANNEL_IN_TOP_LEFT |
93                                 AUDIO_CHANNEL_IN_TOP_RIGHT,
94 
95     AUDIO_CHANNEL_HAPTIC_ALL  = AUDIO_CHANNEL_OUT_HAPTIC_B |
96                                 AUDIO_CHANNEL_OUT_HAPTIC_A,
97 
98     AUDIO_DEVICE_OUT_ALL      = AUDIO_DEVICE_OUT_EARPIECE |
99                                 AUDIO_DEVICE_OUT_SPEAKER |
100                                 AUDIO_DEVICE_OUT_WIRED_HEADSET |
101                                 AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
102                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
103                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
104                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
105                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
106                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
107                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
108                                 AUDIO_DEVICE_OUT_HDMI |
109                                 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
110                                 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
111                                 AUDIO_DEVICE_OUT_USB_ACCESSORY |
112                                 AUDIO_DEVICE_OUT_USB_DEVICE |
113                                 AUDIO_DEVICE_OUT_REMOTE_SUBMIX |
114                                 AUDIO_DEVICE_OUT_TELEPHONY_TX |
115                                 AUDIO_DEVICE_OUT_LINE |
116                                 AUDIO_DEVICE_OUT_HDMI_ARC |
117                                 AUDIO_DEVICE_OUT_SPDIF |
118                                 AUDIO_DEVICE_OUT_FM |
119                                 AUDIO_DEVICE_OUT_AUX_LINE |
120                                 AUDIO_DEVICE_OUT_SPEAKER_SAFE |
121                                 AUDIO_DEVICE_OUT_IP |
122                                 AUDIO_DEVICE_OUT_BUS |
123                                 AUDIO_DEVICE_OUT_PROXY |
124                                 AUDIO_DEVICE_OUT_USB_HEADSET |
125                                 AUDIO_DEVICE_OUT_HEARING_AID |
126                                 AUDIO_DEVICE_OUT_ECHO_CANCELLER |
127                                 AUDIO_DEVICE_OUT_DEFAULT,
128 
129     AUDIO_DEVICE_OUT_ALL_A2DP = AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
130                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
131                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER,
132 
133     AUDIO_DEVICE_OUT_ALL_SCO  = AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
134                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
135                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT,
136 
137     AUDIO_DEVICE_OUT_ALL_USB  = AUDIO_DEVICE_OUT_USB_ACCESSORY |
138                                 AUDIO_DEVICE_OUT_USB_DEVICE |
139                                 AUDIO_DEVICE_OUT_USB_HEADSET,
140 
141     AUDIO_DEVICE_IN_ALL       = AUDIO_DEVICE_IN_COMMUNICATION |
142                                 AUDIO_DEVICE_IN_AMBIENT |
143                                 AUDIO_DEVICE_IN_BUILTIN_MIC |
144                                 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET |
145                                 AUDIO_DEVICE_IN_WIRED_HEADSET |
146                                 AUDIO_DEVICE_IN_HDMI |
147                                 AUDIO_DEVICE_IN_TELEPHONY_RX |
148                                 AUDIO_DEVICE_IN_BACK_MIC |
149                                 AUDIO_DEVICE_IN_REMOTE_SUBMIX |
150                                 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET |
151                                 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET |
152                                 AUDIO_DEVICE_IN_USB_ACCESSORY |
153                                 AUDIO_DEVICE_IN_USB_DEVICE |
154                                 AUDIO_DEVICE_IN_FM_TUNER |
155                                 AUDIO_DEVICE_IN_TV_TUNER |
156                                 AUDIO_DEVICE_IN_LINE |
157                                 AUDIO_DEVICE_IN_SPDIF |
158                                 AUDIO_DEVICE_IN_BLUETOOTH_A2DP |
159                                 AUDIO_DEVICE_IN_LOOPBACK |
160                                 AUDIO_DEVICE_IN_IP |
161                                 AUDIO_DEVICE_IN_BUS |
162                                 AUDIO_DEVICE_IN_PROXY |
163                                 AUDIO_DEVICE_IN_USB_HEADSET |
164                                 AUDIO_DEVICE_IN_BLUETOOTH_BLE |
165                                 AUDIO_DEVICE_IN_HDMI_ARC |
166                                 AUDIO_DEVICE_IN_ECHO_REFERENCE |
167                                 AUDIO_DEVICE_IN_DEFAULT,
168 
169     AUDIO_DEVICE_IN_ALL_SCO   = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
170 
171     AUDIO_DEVICE_IN_ALL_USB   = AUDIO_DEVICE_IN_USB_ACCESSORY |
172                                 AUDIO_DEVICE_IN_USB_DEVICE |
173                                 AUDIO_DEVICE_IN_USB_HEADSET,
174 
175     AUDIO_USAGE_MAX           = AUDIO_USAGE_ASSISTANT,
176     AUDIO_USAGE_CNT           = AUDIO_USAGE_ASSISTANT + 1,
177 
178     AUDIO_PORT_CONFIG_ALL     = AUDIO_PORT_CONFIG_SAMPLE_RATE |
179                                 AUDIO_PORT_CONFIG_CHANNEL_MASK |
180                                 AUDIO_PORT_CONFIG_FORMAT |
181                                 AUDIO_PORT_CONFIG_GAIN,
182 }; // enum
183 
184 // Add new aliases
185 enum {
186     AUDIO_CHANNEL_OUT_TRI                   = 0x7u,     // OUT_FRONT_LEFT | OUT_FRONT_RIGHT | OUT_FRONT_CENTER
187     AUDIO_CHANNEL_OUT_TRI_BACK              = 0x103u,   // OUT_FRONT_LEFT | OUT_FRONT_RIGHT | OUT_BACK_CENTER
188     AUDIO_CHANNEL_OUT_3POINT1               = 0xFu,     // OUT_FRONT_LEFT | OUT_FRONT_RIGHT | OUT_FRONT_CENTER | OUT_LOW_FREQUENCY
189 };
190 
191 // Microphone Field Dimension Constants
192 #define MIC_FIELD_DIMENSION_WIDE (-1.0f)
193 #define MIC_FIELD_DIMENSION_NORMAL (0.0f)
194 #define MIC_FIELD_DIMENSION_NARROW (1.0f)
195 #define MIC_FIELD_DIMENSION_DEFAULT MIC_FIELD_DIMENSION_NORMAL
196 
197 #ifdef __cplusplus
198 #define CONST_ARRAY inline constexpr
199 #else
200 #define CONST_ARRAY const
201 #endif
202 
203 // Keep the device arrays in order from low to high as they may be needed to do binary search.
204 // inline constexpr
205 static CONST_ARRAY uint32_t AUDIO_DEVICE_OUT_ALL_ARRAY[] = {
206     AUDIO_DEVICE_OUT_EARPIECE,                  // 0x00000001u
207     AUDIO_DEVICE_OUT_SPEAKER,                   // 0x00000002u
208     AUDIO_DEVICE_OUT_WIRED_HEADSET,             // 0x00000004u
209     AUDIO_DEVICE_OUT_WIRED_HEADPHONE,           // 0x00000008u
210     AUDIO_DEVICE_OUT_BLUETOOTH_SCO,             // 0x00000010u
211     AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET,     // 0x00000020u
212     AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT,      // 0x00000040u
213     AUDIO_DEVICE_OUT_BLUETOOTH_A2DP,            // 0x00000080u
214     AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, // 0x00000100u
215     AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER,    // 0x00000200u
216     AUDIO_DEVICE_OUT_HDMI,                      // 0x00000400u, OUT_AUX_DIGITAL
217     AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET,         // 0x00000800u
218     AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET,         // 0x00001000u
219     AUDIO_DEVICE_OUT_USB_ACCESSORY,             // 0x00002000u
220     AUDIO_DEVICE_OUT_USB_DEVICE,                // 0x00004000u
221     AUDIO_DEVICE_OUT_REMOTE_SUBMIX,             // 0x00008000u
222     AUDIO_DEVICE_OUT_TELEPHONY_TX,              // 0x00010000u
223     AUDIO_DEVICE_OUT_LINE,                      // 0x00020000u
224     AUDIO_DEVICE_OUT_HDMI_ARC,                  // 0x00040000u
225     AUDIO_DEVICE_OUT_SPDIF,                     // 0x00080000u
226     AUDIO_DEVICE_OUT_FM,                        // 0x00100000u
227     AUDIO_DEVICE_OUT_AUX_LINE,                  // 0x00200000u
228     AUDIO_DEVICE_OUT_SPEAKER_SAFE,              // 0x00400000u
229     AUDIO_DEVICE_OUT_IP,                        // 0x00800000u
230     AUDIO_DEVICE_OUT_BUS,                       // 0x01000000u
231     AUDIO_DEVICE_OUT_PROXY,                     // 0x02000000u
232     AUDIO_DEVICE_OUT_USB_HEADSET,               // 0x04000000u
233     AUDIO_DEVICE_OUT_HEARING_AID,               // 0x08000000u
234     AUDIO_DEVICE_OUT_ECHO_CANCELLER,            // 0x10000000u
235     AUDIO_DEVICE_OUT_DEFAULT,                   // 0x40000000u, BIT_DEFAULT
236 };
237 
238 // inline constexpr
239 static CONST_ARRAY uint32_t AUDIO_DEVICE_OUT_ALL_A2DP_ARRAY[] = {
240     AUDIO_DEVICE_OUT_BLUETOOTH_A2DP,            // 0x00000080u,
241     AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, // 0x00000100u,
242     AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER,    // 0x00000200u,
243 };
244 
245 // inline constexpr
246 static CONST_ARRAY uint32_t AUDIO_DEVICE_OUT_ALL_SCO_ARRAY[] = {
247     AUDIO_DEVICE_OUT_BLUETOOTH_SCO,             // 0x00000010u,
248     AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET,     // 0x00000020u,
249     AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT,      // 0x00000040u,
250 };
251 
252 // inline constexpr
253 static CONST_ARRAY uint32_t AUDIO_DEVICE_OUT_ALL_USB_ARRAY[] = {
254     AUDIO_DEVICE_OUT_USB_ACCESSORY,             // 0x00002000u
255     AUDIO_DEVICE_OUT_USB_DEVICE,                // 0x00004000u
256     AUDIO_DEVICE_OUT_USB_HEADSET,               // 0x04000000u
257 };
258 
259 // Digital out device array should contain all usb out devices
260 // inline constexpr
261 static CONST_ARRAY uint32_t AUDIO_DEVICE_OUT_ALL_DIGITAL_ARRAY[] = {
262     AUDIO_DEVICE_OUT_HDMI,                      // 0x00000400u, OUT_AUX_DIGITAL
263     AUDIO_DEVICE_OUT_USB_ACCESSORY,             // 0x00002000u
264     AUDIO_DEVICE_OUT_USB_DEVICE,                // 0x00004000u
265     AUDIO_DEVICE_OUT_HDMI_ARC,                  // 0x00040000u
266     AUDIO_DEVICE_OUT_SPDIF,                     // 0x00080000u
267     AUDIO_DEVICE_OUT_IP,                        // 0x00800000u
268     AUDIO_DEVICE_OUT_BUS,                       // 0x01000000u
269     AUDIO_DEVICE_OUT_USB_HEADSET,               // 0x04000000u
270 };
271 
272 // inline constexpr
273 static CONST_ARRAY uint32_t AUDIO_DEVICE_IN_ALL_ARRAY[] = {
274     AUDIO_DEVICE_IN_COMMUNICATION,              // 0x80000001u
275     AUDIO_DEVICE_IN_AMBIENT,                    // 0x80000002u
276     AUDIO_DEVICE_IN_BUILTIN_MIC,                // 0x80000004u
277     AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,      // 0x80000008u
278     AUDIO_DEVICE_IN_WIRED_HEADSET,              // 0x80000010u
279     AUDIO_DEVICE_IN_HDMI,                       // 0x80000020u, IN_AUX_DIGITAL
280     AUDIO_DEVICE_IN_TELEPHONY_RX,               // 0x80000040u, IN_VOICE_CALL
281     AUDIO_DEVICE_IN_BACK_MIC,                   // 0x80000080u
282     AUDIO_DEVICE_IN_REMOTE_SUBMIX,              // 0x80000100u
283     AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET,          // 0x80000200u
284     AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET,          // 0x80000400u
285     AUDIO_DEVICE_IN_USB_ACCESSORY,              // 0x80000800u
286     AUDIO_DEVICE_IN_USB_DEVICE,                 // 0x80001000u
287     AUDIO_DEVICE_IN_FM_TUNER,                   // 0x80002000u
288     AUDIO_DEVICE_IN_TV_TUNER,                   // 0x80004000u
289     AUDIO_DEVICE_IN_LINE,                       // 0x80008000u
290     AUDIO_DEVICE_IN_SPDIF,                      // 0x80010000u
291     AUDIO_DEVICE_IN_BLUETOOTH_A2DP,             // 0x80020000u
292     AUDIO_DEVICE_IN_LOOPBACK,                   // 0x80040000u
293     AUDIO_DEVICE_IN_IP,                         // 0x80080000u
294     AUDIO_DEVICE_IN_BUS,                        // 0x80100000u
295     AUDIO_DEVICE_IN_PROXY,                      // 0x81000000u
296     AUDIO_DEVICE_IN_USB_HEADSET,                // 0x82000000u
297     AUDIO_DEVICE_IN_BLUETOOTH_BLE,              // 0x84000000u
298     AUDIO_DEVICE_IN_HDMI_ARC,                   // 0x88000000u
299     AUDIO_DEVICE_IN_ECHO_REFERENCE,             // 0x90000000u
300     AUDIO_DEVICE_IN_DEFAULT,                    // 0xC0000000u
301 };
302 
303 // inline constexpr
304 static CONST_ARRAY uint32_t AUDIO_DEVICE_IN_ALL_SCO_ARRAY[] = {
305     AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,      // 0x80000008u
306 };
307 
308 // inline constexpr
309 static CONST_ARRAY uint32_t AUDIO_DEVICE_IN_ALL_USB_ARRAY[] = {
310     AUDIO_DEVICE_IN_USB_ACCESSORY,              // 0x80000800u
311     AUDIO_DEVICE_IN_USB_DEVICE,                 // 0x80001000u
312     AUDIO_DEVICE_IN_USB_HEADSET,                // 0x82000000u
313 };
314 
315 // Digital in device array should contain all usb in devices
316 // inline constexpr
317 static CONST_ARRAY uint32_t AUDIO_DEVICE_IN_ALL_DIGITAL_ARRAY[] = {
318     AUDIO_DEVICE_IN_HDMI,                       // 0x80000020u, IN_AUX_DIGITAL
319     AUDIO_DEVICE_IN_USB_ACCESSORY,              // 0x80000800u
320     AUDIO_DEVICE_IN_USB_DEVICE,                 // 0x80001000u
321     AUDIO_DEVICE_IN_SPDIF,                      // 0x80010000u
322     AUDIO_DEVICE_IN_IP,                         // 0x80080000u
323     AUDIO_DEVICE_IN_BUS,                        // 0x80100000u
324     AUDIO_DEVICE_IN_USB_HEADSET,                // 0x82000000u
325     AUDIO_DEVICE_IN_HDMI_ARC,                   // 0x88000000u
326 };
327 
328 #ifndef AUDIO_ARRAY_SIZE
329 // std::size()
330 #define AUDIO_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
331 #endif
332 
333 // inline constexpr
334 static const uint32_t AUDIO_DEVICE_OUT_CNT = AUDIO_ARRAY_SIZE(AUDIO_DEVICE_OUT_ALL_ARRAY);
335 static const uint32_t AUDIO_DEVICE_OUT_A2DP_CNT = AUDIO_ARRAY_SIZE(AUDIO_DEVICE_OUT_ALL_A2DP_ARRAY);
336 static const uint32_t AUDIO_DEVICE_OUT_SCO_CNT = AUDIO_ARRAY_SIZE(AUDIO_DEVICE_OUT_ALL_SCO_ARRAY);
337 static const uint32_t AUDIO_DEVICE_OUT_USB_CNT = AUDIO_ARRAY_SIZE(AUDIO_DEVICE_OUT_ALL_USB_ARRAY);
338 static const uint32_t AUDIO_DEVICE_OUT_DIGITAL_CNT = AUDIO_ARRAY_SIZE(
339                                                      AUDIO_DEVICE_OUT_ALL_DIGITAL_ARRAY);
340 static const uint32_t AUDIO_DEVICE_IN_CNT = AUDIO_ARRAY_SIZE(AUDIO_DEVICE_IN_ALL_ARRAY);
341 static const uint32_t AUDIO_DEVICE_IN_SCO_CNT = AUDIO_ARRAY_SIZE(AUDIO_DEVICE_IN_ALL_SCO_ARRAY);
342 static const uint32_t AUDIO_DEVICE_IN_USB_CNT = AUDIO_ARRAY_SIZE(AUDIO_DEVICE_IN_ALL_USB_ARRAY);
343 static const uint32_t AUDIO_DEVICE_IN_DIGITAL_CNT = AUDIO_ARRAY_SIZE(
344                                                     AUDIO_DEVICE_IN_ALL_DIGITAL_ARRAY);
345 
346 #if AUDIO_ARRAYS_STATIC_CHECK
347 
348 template<typename T, size_t N>
isSorted(const T (& a)[N])349 constexpr bool isSorted(const T(&a)[N]) {
350     for (size_t i = 1; i < N; ++i) {
351         if (a[i - 1] > a[i]) {
352             return false;
353         }
354     }
355     return true;
356 }
357 
358 static_assert(isSorted(AUDIO_DEVICE_OUT_ALL_ARRAY),
359               "AUDIO_DEVICE_OUT_ALL_ARRAY must be sorted");
360 static_assert(isSorted(AUDIO_DEVICE_OUT_ALL_A2DP_ARRAY),
361               "AUDIO_DEVICE_OUT_ALL_A2DP_ARRAY must be sorted");
362 static_assert(isSorted(AUDIO_DEVICE_OUT_ALL_SCO_ARRAY),
363               "AUDIO_DEVICE_OUT_ALL_SCO_ARRAY must be sorted");
364 static_assert(isSorted(AUDIO_DEVICE_OUT_ALL_USB_ARRAY),
365               "AUDIO_DEVICE_OUT_ALL_USB_ARRAY must be sorted");
366 static_assert(isSorted(AUDIO_DEVICE_OUT_ALL_DIGITAL_ARRAY),
367               "AUDIO_DEVICE_OUT_ALL_DIGITAL_ARRAY must be sorted");
368 static_assert(isSorted(AUDIO_DEVICE_IN_ALL_ARRAY),
369               "AUDIO_DEVICE_IN_ALL_ARRAY must be sorted");
370 static_assert(isSorted(AUDIO_DEVICE_IN_ALL_SCO_ARRAY),
371               "AUDIO_DEVICE_IN_ALL_SCO_ARRAY must be sorted");
372 static_assert(isSorted(AUDIO_DEVICE_IN_ALL_USB_ARRAY),
373               "AUDIO_DEVICE_IN_ALL_USB_ARRAY must be sorted");
374 static_assert(isSorted(AUDIO_DEVICE_IN_ALL_DIGITAL_ARRAY),
375               "AUDIO_DEVICE_IN_ALL_DIGITAL_ARRAY must be sorted");
376 
377 static_assert(AUDIO_DEVICE_OUT_CNT == std::size(AUDIO_DEVICE_OUT_ALL_ARRAY));
378 static_assert(AUDIO_DEVICE_OUT_A2DP_CNT == std::size(AUDIO_DEVICE_OUT_ALL_A2DP_ARRAY));
379 static_assert(AUDIO_DEVICE_OUT_SCO_CNT == std::size(AUDIO_DEVICE_OUT_ALL_SCO_ARRAY));
380 static_assert(AUDIO_DEVICE_OUT_USB_CNT == std::size(AUDIO_DEVICE_OUT_ALL_USB_ARRAY));
381 static_assert(AUDIO_DEVICE_OUT_DIGITAL_CNT == std::size(AUDIO_DEVICE_OUT_ALL_DIGITAL_ARRAY));
382 static_assert(AUDIO_DEVICE_IN_CNT == std::size(AUDIO_DEVICE_IN_ALL_ARRAY));
383 static_assert(AUDIO_DEVICE_IN_SCO_CNT == std::size(AUDIO_DEVICE_IN_ALL_SCO_ARRAY));
384 static_assert(AUDIO_DEVICE_IN_USB_CNT == std::size(AUDIO_DEVICE_IN_ALL_USB_ARRAY));
385 static_assert(AUDIO_DEVICE_IN_DIGITAL_CNT == std::size(AUDIO_DEVICE_IN_ALL_DIGITAL_ARRAY));
386 
387 #endif  // AUDIO_ARRAYS_STATIC_CHECK
388 
389 #endif  // ANDROID_AUDIO_BASE_UTILS_H
390