1 /*
2 * Copyright (C) 2011 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
18 #ifndef ANDROID_AUDIO_CORE_H
19 #define ANDROID_AUDIO_CORE_H
20
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <sys/cdefs.h>
25 #include <sys/types.h>
26
27 #include <cutils/bitops.h>
28
29 __BEGIN_DECLS
30
31 /* The enums were moved here mostly from
32 * frameworks/base/include/media/AudioSystem.h
33 */
34
35 /* device address used to refer to the standard remote submix */
36 #define AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS "0"
37
38 /* AudioFlinger and AudioPolicy services use I/O handles to identify audio sources and sinks */
39 typedef int audio_io_handle_t;
40 #define AUDIO_IO_HANDLE_NONE 0
41
42 /* Audio stream types */
43 typedef enum {
44 /* These values must kept in sync with
45 * frameworks/base/media/java/android/media/AudioSystem.java
46 */
47 AUDIO_STREAM_DEFAULT = -1,
48 AUDIO_STREAM_MIN = 0,
49 AUDIO_STREAM_VOICE_CALL = 0,
50 AUDIO_STREAM_SYSTEM = 1,
51 AUDIO_STREAM_RING = 2,
52 AUDIO_STREAM_MUSIC = 3,
53 AUDIO_STREAM_ALARM = 4,
54 AUDIO_STREAM_NOTIFICATION = 5,
55 AUDIO_STREAM_BLUETOOTH_SCO = 6,
56 AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user
57 * and must be routed to speaker
58 */
59 AUDIO_STREAM_DTMF = 8,
60 AUDIO_STREAM_TTS = 9, /* Transmitted Through Speaker.
61 * Plays over speaker only, silent on other devices.
62 */
63 AUDIO_STREAM_ACCESSIBILITY = 10, /* For accessibility talk back prompts */
64 AUDIO_STREAM_REROUTING = 11, /* For dynamic policy output mixes */
65 AUDIO_STREAM_PATCH = 12, /* For internal audio flinger tracks. Fixed volume */
66 AUDIO_STREAM_PUBLIC_CNT = AUDIO_STREAM_TTS + 1,
67 AUDIO_STREAM_CNT = AUDIO_STREAM_PATCH + 1,
68 } audio_stream_type_t;
69
70 /* Do not change these values without updating their counterparts
71 * in frameworks/base/media/java/android/media/AudioAttributes.java
72 */
73 typedef enum {
74 AUDIO_CONTENT_TYPE_UNKNOWN = 0,
75 AUDIO_CONTENT_TYPE_SPEECH = 1,
76 AUDIO_CONTENT_TYPE_MUSIC = 2,
77 AUDIO_CONTENT_TYPE_MOVIE = 3,
78 AUDIO_CONTENT_TYPE_SONIFICATION = 4,
79
80 AUDIO_CONTENT_TYPE_CNT,
81 AUDIO_CONTENT_TYPE_MAX = AUDIO_CONTENT_TYPE_CNT - 1,
82 } audio_content_type_t;
83
84 /* Do not change these values without updating their counterparts
85 * in frameworks/base/media/java/android/media/AudioAttributes.java
86 */
87 typedef enum {
88 AUDIO_USAGE_UNKNOWN = 0,
89 AUDIO_USAGE_MEDIA = 1,
90 AUDIO_USAGE_VOICE_COMMUNICATION = 2,
91 AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
92 AUDIO_USAGE_ALARM = 4,
93 AUDIO_USAGE_NOTIFICATION = 5,
94 AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE = 6,
95 AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST = 7,
96 AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT = 8,
97 AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED = 9,
98 AUDIO_USAGE_NOTIFICATION_EVENT = 10,
99 AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
100 AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
101 AUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
102 AUDIO_USAGE_GAME = 14,
103 AUDIO_USAGE_VIRTUAL_SOURCE = 15,
104
105 AUDIO_USAGE_CNT,
106 AUDIO_USAGE_MAX = AUDIO_USAGE_CNT - 1,
107 } audio_usage_t;
108
109 typedef uint32_t audio_flags_mask_t;
110
111 /* Do not change these values without updating their counterparts
112 * in frameworks/base/media/java/android/media/AudioAttributes.java
113 */
114 enum {
115 AUDIO_FLAG_AUDIBILITY_ENFORCED = 0x1,
116 AUDIO_FLAG_SECURE = 0x2,
117 AUDIO_FLAG_SCO = 0x4,
118 AUDIO_FLAG_BEACON = 0x8,
119 AUDIO_FLAG_HW_AV_SYNC = 0x10,
120 AUDIO_FLAG_HW_HOTWORD = 0x20,
121 AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY = 0x40,
122 AUDIO_FLAG_BYPASS_MUTE = 0x80,
123 };
124
125 /* Do not change these values without updating their counterparts
126 * in frameworks/base/media/java/android/media/MediaRecorder.java,
127 * frameworks/av/services/audiopolicy/AudioPolicyService.cpp,
128 * and system/media/audio_effects/include/audio_effects/audio_effects_conf.h!
129 */
130 typedef enum {
131 AUDIO_SOURCE_DEFAULT = 0,
132 AUDIO_SOURCE_MIC = 1,
133 AUDIO_SOURCE_VOICE_UPLINK = 2,
134 AUDIO_SOURCE_VOICE_DOWNLINK = 3,
135 AUDIO_SOURCE_VOICE_CALL = 4,
136 AUDIO_SOURCE_CAMCORDER = 5,
137 AUDIO_SOURCE_VOICE_RECOGNITION = 6,
138 AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
139 AUDIO_SOURCE_REMOTE_SUBMIX = 8, /* Source for the mix to be presented remotely. */
140 /* An example of remote presentation is Wifi Display */
141 /* where a dongle attached to a TV can be used to */
142 /* play the mix captured by this audio source. */
143 AUDIO_SOURCE_CNT,
144 AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1,
145 AUDIO_SOURCE_FM_TUNER = 1998,
146 AUDIO_SOURCE_HOTWORD = 1999, /* A low-priority, preemptible audio source for
147 for background software hotword detection.
148 Same tuning as AUDIO_SOURCE_VOICE_RECOGNITION.
149 Used only internally to the framework. Not exposed
150 at the audio HAL. */
151 } audio_source_t;
152
153 /* Audio attributes */
154 #define AUDIO_ATTRIBUTES_TAGS_MAX_SIZE 256
155 typedef struct {
156 audio_content_type_t content_type;
157 audio_usage_t usage;
158 audio_source_t source;
159 audio_flags_mask_t flags;
160 char tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE]; /* UTF8 */
161 } audio_attributes_t;
162
163 /* special audio session values
164 * (XXX: should this be living in the audio effects land?)
165 */
166 typedef enum {
167 /* session for effects attached to a particular output stream
168 * (value must be less than 0)
169 */
170 AUDIO_SESSION_OUTPUT_STAGE = -1,
171
172 /* session for effects applied to output mix. These effects can
173 * be moved by audio policy manager to another output stream
174 * (value must be 0)
175 */
176 AUDIO_SESSION_OUTPUT_MIX = 0,
177
178 /* application does not specify an explicit session ID to be used,
179 * and requests a new session ID to be allocated
180 * TODO use unique values for AUDIO_SESSION_OUTPUT_MIX and AUDIO_SESSION_ALLOCATE,
181 * after all uses have been updated from 0 to the appropriate symbol, and have been tested.
182 */
183 AUDIO_SESSION_ALLOCATE = 0,
184 } audio_session_t;
185
186 /* a unique ID allocated by AudioFlinger for use as a audio_io_handle_t or audio_session_t */
187 typedef int audio_unique_id_t;
188
189 #define AUDIO_UNIQUE_ID_ALLOCATE AUDIO_SESSION_ALLOCATE
190
191 /* Audio sub formats (see enum audio_format). */
192
193 /* PCM sub formats */
194 typedef enum {
195 /* All of these are in native byte order */
196 AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */
197 AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */
198 AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */
199 AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 8.23 fixed point */
200 AUDIO_FORMAT_PCM_SUB_FLOAT = 0x5, /* PCM single-precision floating point */
201 AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED = 0x6, /* PCM signed .23 fixed point packed in 3 bytes */
202 } audio_format_pcm_sub_fmt_t;
203
204 /* The audio_format_*_sub_fmt_t declarations are not currently used */
205
206 /* MP3 sub format field definition : can use 11 LSBs in the same way as MP3
207 * frame header to specify bit rate, stereo mode, version...
208 */
209 typedef enum {
210 AUDIO_FORMAT_MP3_SUB_NONE = 0x0,
211 } audio_format_mp3_sub_fmt_t;
212
213 /* AMR NB/WB sub format field definition: specify frame block interleaving,
214 * bandwidth efficient or octet aligned, encoding mode for recording...
215 */
216 typedef enum {
217 AUDIO_FORMAT_AMR_SUB_NONE = 0x0,
218 } audio_format_amr_sub_fmt_t;
219
220 /* AAC sub format field definition: specify profile or bitrate for recording... */
221 typedef enum {
222 AUDIO_FORMAT_AAC_SUB_MAIN = 0x1,
223 AUDIO_FORMAT_AAC_SUB_LC = 0x2,
224 AUDIO_FORMAT_AAC_SUB_SSR = 0x4,
225 AUDIO_FORMAT_AAC_SUB_LTP = 0x8,
226 AUDIO_FORMAT_AAC_SUB_HE_V1 = 0x10,
227 AUDIO_FORMAT_AAC_SUB_SCALABLE = 0x20,
228 AUDIO_FORMAT_AAC_SUB_ERLC = 0x40,
229 AUDIO_FORMAT_AAC_SUB_LD = 0x80,
230 AUDIO_FORMAT_AAC_SUB_HE_V2 = 0x100,
231 AUDIO_FORMAT_AAC_SUB_ELD = 0x200,
232 } audio_format_aac_sub_fmt_t;
233
234 /* VORBIS sub format field definition: specify quality for recording... */
235 typedef enum {
236 AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0,
237 } audio_format_vorbis_sub_fmt_t;
238
239
240 /* Audio format consists of a main format field (upper 8 bits) and a sub format
241 * field (lower 24 bits).
242 *
243 * The main format indicates the main codec type. The sub format field
244 * indicates options and parameters for each format. The sub format is mainly
245 * used for record to indicate for instance the requested bitrate or profile.
246 * It can also be used for certain formats to give informations not present in
247 * the encoded audio stream (e.g. octet alignement for AMR).
248 */
249 typedef enum {
250 AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL,
251 AUDIO_FORMAT_DEFAULT = 0,
252 AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */
253 AUDIO_FORMAT_MP3 = 0x01000000UL,
254 AUDIO_FORMAT_AMR_NB = 0x02000000UL,
255 AUDIO_FORMAT_AMR_WB = 0x03000000UL,
256 AUDIO_FORMAT_AAC = 0x04000000UL,
257 AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V1*/
258 AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V2*/
259 AUDIO_FORMAT_VORBIS = 0x07000000UL,
260 AUDIO_FORMAT_OPUS = 0x08000000UL,
261 AUDIO_FORMAT_AC3 = 0x09000000UL,
262 AUDIO_FORMAT_E_AC3 = 0x0A000000UL,
263 AUDIO_FORMAT_DTS = 0x0B000000UL,
264 AUDIO_FORMAT_DTS_HD = 0x0C000000UL,
265 AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL,
266 AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL,
267
268 /* Aliases */
269 /* note != AudioFormat.ENCODING_PCM_16BIT */
270 AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM |
271 AUDIO_FORMAT_PCM_SUB_16_BIT),
272 /* note != AudioFormat.ENCODING_PCM_8BIT */
273 AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM |
274 AUDIO_FORMAT_PCM_SUB_8_BIT),
275 AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM |
276 AUDIO_FORMAT_PCM_SUB_32_BIT),
277 AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM |
278 AUDIO_FORMAT_PCM_SUB_8_24_BIT),
279 AUDIO_FORMAT_PCM_FLOAT = (AUDIO_FORMAT_PCM |
280 AUDIO_FORMAT_PCM_SUB_FLOAT),
281 AUDIO_FORMAT_PCM_24_BIT_PACKED = (AUDIO_FORMAT_PCM |
282 AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED),
283 AUDIO_FORMAT_AAC_MAIN = (AUDIO_FORMAT_AAC |
284 AUDIO_FORMAT_AAC_SUB_MAIN),
285 AUDIO_FORMAT_AAC_LC = (AUDIO_FORMAT_AAC |
286 AUDIO_FORMAT_AAC_SUB_LC),
287 AUDIO_FORMAT_AAC_SSR = (AUDIO_FORMAT_AAC |
288 AUDIO_FORMAT_AAC_SUB_SSR),
289 AUDIO_FORMAT_AAC_LTP = (AUDIO_FORMAT_AAC |
290 AUDIO_FORMAT_AAC_SUB_LTP),
291 AUDIO_FORMAT_AAC_HE_V1 = (AUDIO_FORMAT_AAC |
292 AUDIO_FORMAT_AAC_SUB_HE_V1),
293 AUDIO_FORMAT_AAC_SCALABLE = (AUDIO_FORMAT_AAC |
294 AUDIO_FORMAT_AAC_SUB_SCALABLE),
295 AUDIO_FORMAT_AAC_ERLC = (AUDIO_FORMAT_AAC |
296 AUDIO_FORMAT_AAC_SUB_ERLC),
297 AUDIO_FORMAT_AAC_LD = (AUDIO_FORMAT_AAC |
298 AUDIO_FORMAT_AAC_SUB_LD),
299 AUDIO_FORMAT_AAC_HE_V2 = (AUDIO_FORMAT_AAC |
300 AUDIO_FORMAT_AAC_SUB_HE_V2),
301 AUDIO_FORMAT_AAC_ELD = (AUDIO_FORMAT_AAC |
302 AUDIO_FORMAT_AAC_SUB_ELD),
303 } audio_format_t;
304
305 /* For the channel mask for position assignment representation */
306 enum {
307
308 /* These can be a complete audio_channel_mask_t. */
309
310 AUDIO_CHANNEL_NONE = 0x0,
311 AUDIO_CHANNEL_INVALID = 0xC0000000,
312
313 /* These can be the bits portion of an audio_channel_mask_t
314 * with representation AUDIO_CHANNEL_REPRESENTATION_POSITION.
315 * Using these bits as a complete audio_channel_mask_t is deprecated.
316 */
317
318 /* output channels */
319 AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x1,
320 AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x2,
321 AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x4,
322 AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x8,
323 AUDIO_CHANNEL_OUT_BACK_LEFT = 0x10,
324 AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x20,
325 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40,
326 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80,
327 AUDIO_CHANNEL_OUT_BACK_CENTER = 0x100,
328 AUDIO_CHANNEL_OUT_SIDE_LEFT = 0x200,
329 AUDIO_CHANNEL_OUT_SIDE_RIGHT = 0x400,
330 AUDIO_CHANNEL_OUT_TOP_CENTER = 0x800,
331 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT = 0x1000,
332 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER = 0x2000,
333 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT = 0x4000,
334 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT = 0x8000,
335 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER = 0x10000,
336 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT = 0x20000,
337
338 /* TODO: should these be considered complete channel masks, or only bits? */
339
340 AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT,
341 AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
342 AUDIO_CHANNEL_OUT_FRONT_RIGHT),
343 AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
344 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
345 AUDIO_CHANNEL_OUT_BACK_LEFT |
346 AUDIO_CHANNEL_OUT_BACK_RIGHT),
347 AUDIO_CHANNEL_OUT_QUAD_BACK = AUDIO_CHANNEL_OUT_QUAD,
348 /* like AUDIO_CHANNEL_OUT_QUAD_BACK with *_SIDE_* instead of *_BACK_* */
349 AUDIO_CHANNEL_OUT_QUAD_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
350 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
351 AUDIO_CHANNEL_OUT_SIDE_LEFT |
352 AUDIO_CHANNEL_OUT_SIDE_RIGHT),
353 AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
354 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
355 AUDIO_CHANNEL_OUT_FRONT_CENTER |
356 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
357 AUDIO_CHANNEL_OUT_BACK_LEFT |
358 AUDIO_CHANNEL_OUT_BACK_RIGHT),
359 AUDIO_CHANNEL_OUT_5POINT1_BACK = AUDIO_CHANNEL_OUT_5POINT1,
360 /* like AUDIO_CHANNEL_OUT_5POINT1_BACK with *_SIDE_* instead of *_BACK_* */
361 AUDIO_CHANNEL_OUT_5POINT1_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
362 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
363 AUDIO_CHANNEL_OUT_FRONT_CENTER |
364 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
365 AUDIO_CHANNEL_OUT_SIDE_LEFT |
366 AUDIO_CHANNEL_OUT_SIDE_RIGHT),
367 // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1
368 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
369 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
370 AUDIO_CHANNEL_OUT_FRONT_CENTER |
371 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
372 AUDIO_CHANNEL_OUT_BACK_LEFT |
373 AUDIO_CHANNEL_OUT_BACK_RIGHT |
374 AUDIO_CHANNEL_OUT_SIDE_LEFT |
375 AUDIO_CHANNEL_OUT_SIDE_RIGHT),
376 AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
377 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
378 AUDIO_CHANNEL_OUT_FRONT_CENTER |
379 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
380 AUDIO_CHANNEL_OUT_BACK_LEFT |
381 AUDIO_CHANNEL_OUT_BACK_RIGHT |
382 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
383 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
384 AUDIO_CHANNEL_OUT_BACK_CENTER|
385 AUDIO_CHANNEL_OUT_SIDE_LEFT|
386 AUDIO_CHANNEL_OUT_SIDE_RIGHT|
387 AUDIO_CHANNEL_OUT_TOP_CENTER|
388 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT|
389 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER|
390 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT|
391 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT|
392 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER|
393 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT),
394
395 /* These are bits only, not complete values */
396
397 /* input channels */
398 AUDIO_CHANNEL_IN_LEFT = 0x4,
399 AUDIO_CHANNEL_IN_RIGHT = 0x8,
400 AUDIO_CHANNEL_IN_FRONT = 0x10,
401 AUDIO_CHANNEL_IN_BACK = 0x20,
402 AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40,
403 AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80,
404 AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100,
405 AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200,
406 AUDIO_CHANNEL_IN_PRESSURE = 0x400,
407 AUDIO_CHANNEL_IN_X_AXIS = 0x800,
408 AUDIO_CHANNEL_IN_Y_AXIS = 0x1000,
409 AUDIO_CHANNEL_IN_Z_AXIS = 0x2000,
410 AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000,
411 AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000,
412
413 /* TODO: should these be considered complete channel masks, or only bits, or deprecated? */
414
415 AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT,
416 AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT),
417 AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK),
418 AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT |
419 AUDIO_CHANNEL_IN_RIGHT |
420 AUDIO_CHANNEL_IN_FRONT |
421 AUDIO_CHANNEL_IN_BACK|
422 AUDIO_CHANNEL_IN_LEFT_PROCESSED |
423 AUDIO_CHANNEL_IN_RIGHT_PROCESSED |
424 AUDIO_CHANNEL_IN_FRONT_PROCESSED |
425 AUDIO_CHANNEL_IN_BACK_PROCESSED|
426 AUDIO_CHANNEL_IN_PRESSURE |
427 AUDIO_CHANNEL_IN_X_AXIS |
428 AUDIO_CHANNEL_IN_Y_AXIS |
429 AUDIO_CHANNEL_IN_Z_AXIS |
430 AUDIO_CHANNEL_IN_VOICE_UPLINK |
431 AUDIO_CHANNEL_IN_VOICE_DNLINK),
432 };
433
434 /* A channel mask per se only defines the presence or absence of a channel, not the order.
435 * But see AUDIO_INTERLEAVE_* below for the platform convention of order.
436 *
437 * audio_channel_mask_t is an opaque type and its internal layout should not
438 * be assumed as it may change in the future.
439 * Instead, always use the functions declared in this header to examine.
440 *
441 * These are the current representations:
442 *
443 * AUDIO_CHANNEL_REPRESENTATION_POSITION
444 * is a channel mask representation for position assignment.
445 * Each low-order bit corresponds to the spatial position of a transducer (output),
446 * or interpretation of channel (input).
447 * The user of a channel mask needs to know the context of whether it is for output or input.
448 * The constants AUDIO_CHANNEL_OUT_* or AUDIO_CHANNEL_IN_* apply to the bits portion.
449 * It is not permitted for no bits to be set.
450 *
451 * AUDIO_CHANNEL_REPRESENTATION_INDEX
452 * is a channel mask representation for index assignment.
453 * Each low-order bit corresponds to a selected channel.
454 * There is no platform interpretation of the various bits.
455 * There is no concept of output or input.
456 * It is not permitted for no bits to be set.
457 *
458 * All other representations are reserved for future use.
459 *
460 * Warning: current representation distinguishes between input and output, but this will not the be
461 * case in future revisions of the platform. Wherever there is an ambiguity between input and output
462 * that is currently resolved by checking the channel mask, the implementer should look for ways to
463 * fix it with additional information outside of the mask.
464 */
465 typedef uint32_t audio_channel_mask_t;
466
467 /* Maximum number of channels for all representations */
468 #define AUDIO_CHANNEL_COUNT_MAX 30
469
470 /* log(2) of maximum number of representations, not part of public API */
471 #define AUDIO_CHANNEL_REPRESENTATION_LOG2 2
472
473 /* Representations */
474 typedef enum {
475 AUDIO_CHANNEL_REPRESENTATION_POSITION = 0, // must be zero for compatibility
476 // 1 is reserved for future use
477 AUDIO_CHANNEL_REPRESENTATION_INDEX = 2,
478 // 3 is reserved for future use
479 } audio_channel_representation_t;
480
481 /* The channel index masks defined here are the canonical masks for 1 to 8 channel
482 * endpoints and apply to both source and sink.
483 */
484 enum {
485 AUDIO_CHANNEL_INDEX_HDR = AUDIO_CHANNEL_REPRESENTATION_INDEX << AUDIO_CHANNEL_COUNT_MAX,
486 AUDIO_CHANNEL_INDEX_MASK_1 = AUDIO_CHANNEL_INDEX_HDR | (1 << 1) - 1,
487 AUDIO_CHANNEL_INDEX_MASK_2 = AUDIO_CHANNEL_INDEX_HDR | (1 << 2) - 1,
488 AUDIO_CHANNEL_INDEX_MASK_3 = AUDIO_CHANNEL_INDEX_HDR | (1 << 3) - 1,
489 AUDIO_CHANNEL_INDEX_MASK_4 = AUDIO_CHANNEL_INDEX_HDR | (1 << 4) - 1,
490 AUDIO_CHANNEL_INDEX_MASK_5 = AUDIO_CHANNEL_INDEX_HDR | (1 << 5) - 1,
491 AUDIO_CHANNEL_INDEX_MASK_6 = AUDIO_CHANNEL_INDEX_HDR | (1 << 6) - 1,
492 AUDIO_CHANNEL_INDEX_MASK_7 = AUDIO_CHANNEL_INDEX_HDR | (1 << 7) - 1,
493 AUDIO_CHANNEL_INDEX_MASK_8 = AUDIO_CHANNEL_INDEX_HDR | (1 << 8) - 1,
494 // FIXME FCC_8
495 };
496
497 /* The return value is undefined if the channel mask is invalid. */
audio_channel_mask_get_bits(audio_channel_mask_t channel)498 static inline uint32_t audio_channel_mask_get_bits(audio_channel_mask_t channel)
499 {
500 return channel & ((1 << AUDIO_CHANNEL_COUNT_MAX) - 1);
501 }
502
503 /* The return value is undefined if the channel mask is invalid. */
audio_channel_mask_get_representation(audio_channel_mask_t channel)504 static inline audio_channel_representation_t audio_channel_mask_get_representation(
505 audio_channel_mask_t channel)
506 {
507 // The right shift should be sufficient, but also "and" for safety in case mask is not 32 bits
508 return (audio_channel_representation_t)
509 ((channel >> AUDIO_CHANNEL_COUNT_MAX) & ((1 << AUDIO_CHANNEL_REPRESENTATION_LOG2) - 1));
510 }
511
512 /* Returns true if the channel mask is valid,
513 * or returns false for AUDIO_CHANNEL_NONE, AUDIO_CHANNEL_INVALID, and other invalid values.
514 * This function is unable to determine whether a channel mask for position assignment
515 * is invalid because an output mask has an invalid output bit set,
516 * or because an input mask has an invalid input bit set.
517 * All other APIs that take a channel mask assume that it is valid.
518 */
audio_channel_mask_is_valid(audio_channel_mask_t channel)519 static inline bool audio_channel_mask_is_valid(audio_channel_mask_t channel)
520 {
521 uint32_t bits = audio_channel_mask_get_bits(channel);
522 audio_channel_representation_t representation = audio_channel_mask_get_representation(channel);
523 switch (representation) {
524 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
525 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
526 break;
527 default:
528 bits = 0;
529 break;
530 }
531 return bits != 0;
532 }
533
534 /* Not part of public API */
audio_channel_mask_from_representation_and_bits(audio_channel_representation_t representation,uint32_t bits)535 static inline audio_channel_mask_t audio_channel_mask_from_representation_and_bits(
536 audio_channel_representation_t representation, uint32_t bits)
537 {
538 return (audio_channel_mask_t) ((representation << AUDIO_CHANNEL_COUNT_MAX) | bits);
539 }
540
541 /* Expresses the convention when stereo audio samples are stored interleaved
542 * in an array. This should improve readability by allowing code to use
543 * symbolic indices instead of hard-coded [0] and [1].
544 *
545 * For multi-channel beyond stereo, the platform convention is that channels
546 * are interleaved in order from least significant channel mask bit
547 * to most significant channel mask bit, with unused bits skipped.
548 * Any exceptions to this convention will be noted at the appropriate API.
549 */
550 enum {
551 AUDIO_INTERLEAVE_LEFT = 0,
552 AUDIO_INTERLEAVE_RIGHT = 1,
553 };
554
555 typedef enum {
556 AUDIO_MODE_INVALID = -2,
557 AUDIO_MODE_CURRENT = -1,
558 AUDIO_MODE_NORMAL = 0,
559 AUDIO_MODE_RINGTONE = 1,
560 AUDIO_MODE_IN_CALL = 2,
561 AUDIO_MODE_IN_COMMUNICATION = 3,
562
563 AUDIO_MODE_CNT,
564 AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1,
565 } audio_mode_t;
566
567 /* This enum is deprecated */
568 typedef enum {
569 AUDIO_IN_ACOUSTICS_NONE = 0,
570 AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001,
571 AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0,
572 AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002,
573 AUDIO_IN_ACOUSTICS_NS_DISABLE = 0,
574 AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004,
575 AUDIO_IN_ACOUSTICS_TX_DISABLE = 0,
576 } audio_in_acoustics_t;
577
578 enum {
579 AUDIO_DEVICE_NONE = 0x0,
580 /* reserved bits */
581 AUDIO_DEVICE_BIT_IN = 0x80000000,
582 AUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
583 /* output devices */
584 AUDIO_DEVICE_OUT_EARPIECE = 0x1,
585 AUDIO_DEVICE_OUT_SPEAKER = 0x2,
586 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
587 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
588 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10,
589 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
590 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
591 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
592 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
593 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
594 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400,
595 AUDIO_DEVICE_OUT_HDMI = AUDIO_DEVICE_OUT_AUX_DIGITAL,
596 /* uses an analog connection (multiplexed over the USB connector pins for instance) */
597 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
598 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
599 /* USB accessory mode: your Android device is a USB device and the dock is a USB host */
600 AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000,
601 /* USB host mode: your Android device is a USB host and the dock is a USB device */
602 AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000,
603 AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000,
604 /* Telephony voice TX path */
605 AUDIO_DEVICE_OUT_TELEPHONY_TX = 0x10000,
606 /* Analog jack with line impedance detected */
607 AUDIO_DEVICE_OUT_LINE = 0x20000,
608 /* HDMI Audio Return Channel */
609 AUDIO_DEVICE_OUT_HDMI_ARC = 0x40000,
610 /* S/PDIF out */
611 AUDIO_DEVICE_OUT_SPDIF = 0x80000,
612 /* FM transmitter out */
613 AUDIO_DEVICE_OUT_FM = 0x100000,
614 /* Line out for av devices */
615 AUDIO_DEVICE_OUT_AUX_LINE = 0x200000,
616 /* limited-output speaker device for acoustic safety */
617 AUDIO_DEVICE_OUT_SPEAKER_SAFE = 0x400000,
618 AUDIO_DEVICE_OUT_IP = 0x800000,
619 AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT,
620 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE |
621 AUDIO_DEVICE_OUT_SPEAKER |
622 AUDIO_DEVICE_OUT_WIRED_HEADSET |
623 AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
624 AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
625 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
626 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
627 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
628 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
629 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
630 AUDIO_DEVICE_OUT_HDMI |
631 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
632 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
633 AUDIO_DEVICE_OUT_USB_ACCESSORY |
634 AUDIO_DEVICE_OUT_USB_DEVICE |
635 AUDIO_DEVICE_OUT_REMOTE_SUBMIX |
636 AUDIO_DEVICE_OUT_TELEPHONY_TX |
637 AUDIO_DEVICE_OUT_LINE |
638 AUDIO_DEVICE_OUT_HDMI_ARC |
639 AUDIO_DEVICE_OUT_SPDIF |
640 AUDIO_DEVICE_OUT_FM |
641 AUDIO_DEVICE_OUT_AUX_LINE |
642 AUDIO_DEVICE_OUT_SPEAKER_SAFE |
643 AUDIO_DEVICE_OUT_IP |
644 AUDIO_DEVICE_OUT_DEFAULT),
645 AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
646 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
647 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
648 AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
649 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
650 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
651 AUDIO_DEVICE_OUT_ALL_USB = (AUDIO_DEVICE_OUT_USB_ACCESSORY |
652 AUDIO_DEVICE_OUT_USB_DEVICE),
653 /* input devices */
654 AUDIO_DEVICE_IN_COMMUNICATION = AUDIO_DEVICE_BIT_IN | 0x1,
655 AUDIO_DEVICE_IN_AMBIENT = AUDIO_DEVICE_BIT_IN | 0x2,
656 AUDIO_DEVICE_IN_BUILTIN_MIC = AUDIO_DEVICE_BIT_IN | 0x4,
657 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8,
658 AUDIO_DEVICE_IN_WIRED_HEADSET = AUDIO_DEVICE_BIT_IN | 0x10,
659 AUDIO_DEVICE_IN_AUX_DIGITAL = AUDIO_DEVICE_BIT_IN | 0x20,
660 AUDIO_DEVICE_IN_HDMI = AUDIO_DEVICE_IN_AUX_DIGITAL,
661 /* Telephony voice RX path */
662 AUDIO_DEVICE_IN_VOICE_CALL = AUDIO_DEVICE_BIT_IN | 0x40,
663 AUDIO_DEVICE_IN_TELEPHONY_RX = AUDIO_DEVICE_IN_VOICE_CALL,
664 AUDIO_DEVICE_IN_BACK_MIC = AUDIO_DEVICE_BIT_IN | 0x80,
665 AUDIO_DEVICE_IN_REMOTE_SUBMIX = AUDIO_DEVICE_BIT_IN | 0x100,
666 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x200,
667 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x400,
668 AUDIO_DEVICE_IN_USB_ACCESSORY = AUDIO_DEVICE_BIT_IN | 0x800,
669 AUDIO_DEVICE_IN_USB_DEVICE = AUDIO_DEVICE_BIT_IN | 0x1000,
670 /* FM tuner input */
671 AUDIO_DEVICE_IN_FM_TUNER = AUDIO_DEVICE_BIT_IN | 0x2000,
672 /* TV tuner input */
673 AUDIO_DEVICE_IN_TV_TUNER = AUDIO_DEVICE_BIT_IN | 0x4000,
674 /* Analog jack with line impedance detected */
675 AUDIO_DEVICE_IN_LINE = AUDIO_DEVICE_BIT_IN | 0x8000,
676 /* S/PDIF in */
677 AUDIO_DEVICE_IN_SPDIF = AUDIO_DEVICE_BIT_IN | 0x10000,
678 AUDIO_DEVICE_IN_BLUETOOTH_A2DP = AUDIO_DEVICE_BIT_IN | 0x20000,
679 AUDIO_DEVICE_IN_LOOPBACK = AUDIO_DEVICE_BIT_IN | 0x40000,
680 AUDIO_DEVICE_IN_IP = AUDIO_DEVICE_BIT_IN | 0x80000,
681 AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT,
682
683 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION |
684 AUDIO_DEVICE_IN_AMBIENT |
685 AUDIO_DEVICE_IN_BUILTIN_MIC |
686 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET |
687 AUDIO_DEVICE_IN_WIRED_HEADSET |
688 AUDIO_DEVICE_IN_HDMI |
689 AUDIO_DEVICE_IN_TELEPHONY_RX |
690 AUDIO_DEVICE_IN_BACK_MIC |
691 AUDIO_DEVICE_IN_REMOTE_SUBMIX |
692 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET |
693 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET |
694 AUDIO_DEVICE_IN_USB_ACCESSORY |
695 AUDIO_DEVICE_IN_USB_DEVICE |
696 AUDIO_DEVICE_IN_FM_TUNER |
697 AUDIO_DEVICE_IN_TV_TUNER |
698 AUDIO_DEVICE_IN_LINE |
699 AUDIO_DEVICE_IN_SPDIF |
700 AUDIO_DEVICE_IN_BLUETOOTH_A2DP |
701 AUDIO_DEVICE_IN_LOOPBACK |
702 AUDIO_DEVICE_IN_IP |
703 AUDIO_DEVICE_IN_DEFAULT),
704 AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
705 AUDIO_DEVICE_IN_ALL_USB = (AUDIO_DEVICE_IN_USB_ACCESSORY |
706 AUDIO_DEVICE_IN_USB_DEVICE),
707 };
708
709 typedef uint32_t audio_devices_t;
710
711 /* the audio output flags serve two purposes:
712 * - when an AudioTrack is created they indicate a "wish" to be connected to an
713 * output stream with attributes corresponding to the specified flags
714 * - when present in an output profile descriptor listed for a particular audio
715 * hardware module, they indicate that an output stream can be opened that
716 * supports the attributes indicated by the flags.
717 * the audio policy manager will try to match the flags in the request
718 * (when getOuput() is called) to an available output stream.
719 */
720 typedef enum {
721 AUDIO_OUTPUT_FLAG_NONE = 0x0, // no attributes
722 AUDIO_OUTPUT_FLAG_DIRECT = 0x1, // this output directly connects a track
723 // to one output stream: no software mixer
724 AUDIO_OUTPUT_FLAG_PRIMARY = 0x2, // this output is the primary output of
725 // the device. It is unique and must be
726 // present. It is opened by default and
727 // receives routing, audio mode and volume
728 // controls related to voice calls.
729 AUDIO_OUTPUT_FLAG_FAST = 0x4, // output supports "fast tracks",
730 // defined elsewhere
731 AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8, // use deep audio buffers
732 AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD = 0x10, // offload playback of compressed
733 // streams to hardware codec
734 AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20, // use non-blocking write
735 AUDIO_OUTPUT_FLAG_HW_AV_SYNC = 0x40, // output uses a hardware A/V synchronization source
736 AUDIO_OUTPUT_FLAG_TTS = 0x80, // output for streams transmitted through speaker
737 // at a sample rate high enough to accommodate
738 // lower-range ultrasonic playback
739 AUDIO_OUTPUT_FLAG_RAW = 0x100, // minimize signal processing
740 AUDIO_OUTPUT_FLAG_SYNC = 0x200, // synchronize I/O streams
741
742 AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO = 0x400, // Audio stream contains compressed audio in
743 // SPDIF data bursts, not PCM.
744 } audio_output_flags_t;
745
746 /* The audio input flags are analogous to audio output flags.
747 * Currently they are used only when an AudioRecord is created,
748 * to indicate a preference to be connected to an input stream with
749 * attributes corresponding to the specified flags.
750 */
751 typedef enum {
752 AUDIO_INPUT_FLAG_NONE = 0x0, // no attributes
753 AUDIO_INPUT_FLAG_FAST = 0x1, // prefer an input that supports "fast tracks"
754 AUDIO_INPUT_FLAG_HW_HOTWORD = 0x2, // prefer an input that captures from hw hotword source
755 AUDIO_INPUT_FLAG_RAW = 0x4, // minimize signal processing
756 AUDIO_INPUT_FLAG_SYNC = 0x8, // synchronize I/O streams
757
758 } audio_input_flags_t;
759
760 /* Additional information about compressed streams offloaded to
761 * hardware playback
762 * The version and size fields must be initialized by the caller by using
763 * one of the constants defined here.
764 */
765 typedef struct {
766 uint16_t version; // version of the info structure
767 uint16_t size; // total size of the structure including version and size
768 uint32_t sample_rate; // sample rate in Hz
769 audio_channel_mask_t channel_mask; // channel mask
770 audio_format_t format; // audio format
771 audio_stream_type_t stream_type; // stream type
772 uint32_t bit_rate; // bit rate in bits per second
773 int64_t duration_us; // duration in microseconds, -1 if unknown
774 bool has_video; // true if stream is tied to a video stream
775 bool is_streaming; // true if streaming, false if local playback
776 } audio_offload_info_t;
777
778 #define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \
779 ((((maj) & 0xff) << 8) | ((min) & 0xff))
780
781 #define AUDIO_OFFLOAD_INFO_VERSION_0_1 AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1)
782 #define AUDIO_OFFLOAD_INFO_VERSION_CURRENT AUDIO_OFFLOAD_INFO_VERSION_0_1
783
784 static const audio_offload_info_t AUDIO_INFO_INITIALIZER = {
785 version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
786 size: sizeof(audio_offload_info_t),
787 sample_rate: 0,
788 channel_mask: 0,
789 format: AUDIO_FORMAT_DEFAULT,
790 stream_type: AUDIO_STREAM_VOICE_CALL,
791 bit_rate: 0,
792 duration_us: 0,
793 has_video: false,
794 is_streaming: false
795 };
796
797 /* common audio stream configuration parameters
798 * You should memset() the entire structure to zero before use to
799 * ensure forward compatibility
800 */
801 struct audio_config {
802 uint32_t sample_rate;
803 audio_channel_mask_t channel_mask;
804 audio_format_t format;
805 audio_offload_info_t offload_info;
806 size_t frame_count;
807 };
808 typedef struct audio_config audio_config_t;
809
810 static const audio_config_t AUDIO_CONFIG_INITIALIZER = {
811 sample_rate: 0,
812 channel_mask: AUDIO_CHANNEL_NONE,
813 format: AUDIO_FORMAT_DEFAULT,
814 offload_info: {
815 version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
816 size: sizeof(audio_offload_info_t),
817 sample_rate: 0,
818 channel_mask: 0,
819 format: AUDIO_FORMAT_DEFAULT,
820 stream_type: AUDIO_STREAM_VOICE_CALL,
821 bit_rate: 0,
822 duration_us: 0,
823 has_video: false,
824 is_streaming: false
825 },
826 frame_count: 0,
827 };
828
829
830 /* audio hw module handle functions or structures referencing a module */
831 typedef int audio_module_handle_t;
832
833 /******************************
834 * Volume control
835 *****************************/
836
837 /* If the audio hardware supports gain control on some audio paths,
838 * the platform can expose them in the audio_policy.conf file. The audio HAL
839 * will then implement gain control functions that will use the following data
840 * structures. */
841
842 /* Type of gain control exposed by an audio port */
843 #define AUDIO_GAIN_MODE_JOINT 0x1 /* supports joint channel gain control */
844 #define AUDIO_GAIN_MODE_CHANNELS 0x2 /* supports separate channel gain control */
845 #define AUDIO_GAIN_MODE_RAMP 0x4 /* supports gain ramps */
846
847 typedef uint32_t audio_gain_mode_t;
848
849
850 /* An audio_gain struct is a representation of a gain stage.
851 * A gain stage is always attached to an audio port. */
852 struct audio_gain {
853 audio_gain_mode_t mode; /* e.g. AUDIO_GAIN_MODE_JOINT */
854 audio_channel_mask_t channel_mask; /* channels which gain an be controlled.
855 N/A if AUDIO_GAIN_MODE_CHANNELS is not supported */
856 int min_value; /* minimum gain value in millibels */
857 int max_value; /* maximum gain value in millibels */
858 int default_value; /* default gain value in millibels */
859 unsigned int step_value; /* gain step in millibels */
860 unsigned int min_ramp_ms; /* minimum ramp duration in ms */
861 unsigned int max_ramp_ms; /* maximum ramp duration in ms */
862 };
863
864 /* The gain configuration structure is used to get or set the gain values of a
865 * given port */
866 struct audio_gain_config {
867 int index; /* index of the corresponding audio_gain in the
868 audio_port gains[] table */
869 audio_gain_mode_t mode; /* mode requested for this command */
870 audio_channel_mask_t channel_mask; /* channels which gain value follows.
871 N/A in joint mode */
872
873 // note this "8" is not FCC_8, so it won't need to be changed for > 8 channels
874 int values[sizeof(audio_channel_mask_t) * 8]; /* gain values in millibels
875 for each channel ordered from LSb to MSb in
876 channel mask. The number of values is 1 in joint
877 mode or popcount(channel_mask) */
878 unsigned int ramp_duration_ms; /* ramp duration in ms */
879 };
880
881 /******************************
882 * Routing control
883 *****************************/
884
885 /* Types defined here are used to describe an audio source or sink at internal
886 * framework interfaces (audio policy, patch panel) or at the audio HAL.
887 * Sink and sources are grouped in a concept of “audio port” representing an
888 * audio end point at the edge of the system managed by the module exposing
889 * the interface. */
890
891 /* Audio port role: either source or sink */
892 typedef enum {
893 AUDIO_PORT_ROLE_NONE,
894 AUDIO_PORT_ROLE_SOURCE,
895 AUDIO_PORT_ROLE_SINK,
896 } audio_port_role_t;
897
898 /* Audio port type indicates if it is a session (e.g AudioTrack),
899 * a mix (e.g PlaybackThread output) or a physical device
900 * (e.g AUDIO_DEVICE_OUT_SPEAKER) */
901 typedef enum {
902 AUDIO_PORT_TYPE_NONE,
903 AUDIO_PORT_TYPE_DEVICE,
904 AUDIO_PORT_TYPE_MIX,
905 AUDIO_PORT_TYPE_SESSION,
906 } audio_port_type_t;
907
908 /* Each port has a unique ID or handle allocated by policy manager */
909 typedef int audio_port_handle_t;
910 #define AUDIO_PORT_HANDLE_NONE 0
911
912 /* the maximum length for the human-readable device name */
913 #define AUDIO_PORT_MAX_NAME_LEN 128
914
915 /* maximum audio device address length */
916 #define AUDIO_DEVICE_MAX_ADDRESS_LEN 32
917
918 /* extension for audio port configuration structure when the audio port is a
919 * hardware device */
920 struct audio_port_config_device_ext {
921 audio_module_handle_t hw_module; /* module the device is attached to */
922 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
923 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; /* device address. "" if N/A */
924 };
925
926 /* extension for audio port configuration structure when the audio port is a
927 * sub mix */
928 struct audio_port_config_mix_ext {
929 audio_module_handle_t hw_module; /* module the stream is attached to */
930 audio_io_handle_t handle; /* I/O handle of the input/output stream */
931 union {
932 //TODO: change use case for output streams: use strategy and mixer attributes
933 audio_stream_type_t stream;
934 audio_source_t source;
935 } usecase;
936 };
937
938 /* extension for audio port configuration structure when the audio port is an
939 * audio session */
940 struct audio_port_config_session_ext {
941 audio_session_t session; /* audio session */
942 };
943
944 /* Flags indicating which fields are to be considered in struct audio_port_config */
945 #define AUDIO_PORT_CONFIG_SAMPLE_RATE 0x1
946 #define AUDIO_PORT_CONFIG_CHANNEL_MASK 0x2
947 #define AUDIO_PORT_CONFIG_FORMAT 0x4
948 #define AUDIO_PORT_CONFIG_GAIN 0x8
949 #define AUDIO_PORT_CONFIG_ALL (AUDIO_PORT_CONFIG_SAMPLE_RATE | \
950 AUDIO_PORT_CONFIG_CHANNEL_MASK | \
951 AUDIO_PORT_CONFIG_FORMAT | \
952 AUDIO_PORT_CONFIG_GAIN)
953
954 /* audio port configuration structure used to specify a particular configuration of
955 * an audio port */
956 struct audio_port_config {
957 audio_port_handle_t id; /* port unique ID */
958 audio_port_role_t role; /* sink or source */
959 audio_port_type_t type; /* device, mix ... */
960 unsigned int config_mask; /* e.g AUDIO_PORT_CONFIG_ALL */
961 unsigned int sample_rate; /* sampling rate in Hz */
962 audio_channel_mask_t channel_mask; /* channel mask if applicable */
963 audio_format_t format; /* format if applicable */
964 struct audio_gain_config gain; /* gain to apply if applicable */
965 union {
966 struct audio_port_config_device_ext device; /* device specific info */
967 struct audio_port_config_mix_ext mix; /* mix specific info */
968 struct audio_port_config_session_ext session; /* session specific info */
969 } ext;
970 };
971
972
973 /* max number of sampling rates in audio port */
974 #define AUDIO_PORT_MAX_SAMPLING_RATES 16
975 /* max number of channel masks in audio port */
976 #define AUDIO_PORT_MAX_CHANNEL_MASKS 16
977 /* max number of audio formats in audio port */
978 #define AUDIO_PORT_MAX_FORMATS 16
979 /* max number of gain controls in audio port */
980 #define AUDIO_PORT_MAX_GAINS 16
981
982 /* extension for audio port structure when the audio port is a hardware device */
983 struct audio_port_device_ext {
984 audio_module_handle_t hw_module; /* module the device is attached to */
985 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
986 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
987 };
988
989 /* Latency class of the audio mix */
990 typedef enum {
991 AUDIO_LATENCY_LOW,
992 AUDIO_LATENCY_NORMAL,
993 } audio_mix_latency_class_t;
994
995 /* extension for audio port structure when the audio port is a sub mix */
996 struct audio_port_mix_ext {
997 audio_module_handle_t hw_module; /* module the stream is attached to */
998 audio_io_handle_t handle; /* I/O handle of the input.output stream */
999 audio_mix_latency_class_t latency_class; /* latency class */
1000 // other attributes: routing strategies
1001 };
1002
1003 /* extension for audio port structure when the audio port is an audio session */
1004 struct audio_port_session_ext {
1005 audio_session_t session; /* audio session */
1006 };
1007
1008 struct audio_port {
1009 audio_port_handle_t id; /* port unique ID */
1010 audio_port_role_t role; /* sink or source */
1011 audio_port_type_t type; /* device, mix ... */
1012 char name[AUDIO_PORT_MAX_NAME_LEN];
1013 unsigned int num_sample_rates; /* number of sampling rates in following array */
1014 unsigned int sample_rates[AUDIO_PORT_MAX_SAMPLING_RATES];
1015 unsigned int num_channel_masks; /* number of channel masks in following array */
1016 audio_channel_mask_t channel_masks[AUDIO_PORT_MAX_CHANNEL_MASKS];
1017 unsigned int num_formats; /* number of formats in following array */
1018 audio_format_t formats[AUDIO_PORT_MAX_FORMATS];
1019 unsigned int num_gains; /* number of gains in following array */
1020 struct audio_gain gains[AUDIO_PORT_MAX_GAINS];
1021 struct audio_port_config active_config; /* current audio port configuration */
1022 union {
1023 struct audio_port_device_ext device;
1024 struct audio_port_mix_ext mix;
1025 struct audio_port_session_ext session;
1026 } ext;
1027 };
1028
1029 /* An audio patch represents a connection between one or more source ports and
1030 * one or more sink ports. Patches are connected and disconnected by audio policy manager or by
1031 * applications via framework APIs.
1032 * Each patch is identified by a handle at the interface used to create that patch. For instance,
1033 * when a patch is created by the audio HAL, the HAL allocates and returns a handle.
1034 * This handle is unique to a given audio HAL hardware module.
1035 * But the same patch receives another system wide unique handle allocated by the framework.
1036 * This unique handle is used for all transactions inside the framework.
1037 */
1038 typedef int audio_patch_handle_t;
1039 #define AUDIO_PATCH_HANDLE_NONE 0
1040
1041 #define AUDIO_PATCH_PORTS_MAX 16
1042
1043 struct audio_patch {
1044 audio_patch_handle_t id; /* patch unique ID */
1045 unsigned int num_sources; /* number of sources in following array */
1046 struct audio_port_config sources[AUDIO_PATCH_PORTS_MAX];
1047 unsigned int num_sinks; /* number of sinks in following array */
1048 struct audio_port_config sinks[AUDIO_PATCH_PORTS_MAX];
1049 };
1050
1051
1052
1053 /* a HW synchronization source returned by the audio HAL */
1054 typedef uint32_t audio_hw_sync_t;
1055
1056 /* an invalid HW synchronization source indicating an error */
1057 #define AUDIO_HW_SYNC_INVALID 0
1058
audio_is_output_device(audio_devices_t device)1059 static inline bool audio_is_output_device(audio_devices_t device)
1060 {
1061 if (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
1062 (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0))
1063 return true;
1064 else
1065 return false;
1066 }
1067
audio_is_input_device(audio_devices_t device)1068 static inline bool audio_is_input_device(audio_devices_t device)
1069 {
1070 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
1071 device &= ~AUDIO_DEVICE_BIT_IN;
1072 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0))
1073 return true;
1074 }
1075 return false;
1076 }
1077
audio_is_output_devices(audio_devices_t device)1078 static inline bool audio_is_output_devices(audio_devices_t device)
1079 {
1080 return (device & AUDIO_DEVICE_BIT_IN) == 0;
1081 }
1082
audio_is_a2dp_in_device(audio_devices_t device)1083 static inline bool audio_is_a2dp_in_device(audio_devices_t device)
1084 {
1085 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
1086 device &= ~AUDIO_DEVICE_BIT_IN;
1087 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP))
1088 return true;
1089 }
1090 return false;
1091 }
1092
audio_is_a2dp_out_device(audio_devices_t device)1093 static inline bool audio_is_a2dp_out_device(audio_devices_t device)
1094 {
1095 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP))
1096 return true;
1097 else
1098 return false;
1099 }
1100
1101 // Deprecated - use audio_is_a2dp_out_device() instead
audio_is_a2dp_device(audio_devices_t device)1102 static inline bool audio_is_a2dp_device(audio_devices_t device)
1103 {
1104 return audio_is_a2dp_out_device(device);
1105 }
1106
audio_is_bluetooth_sco_device(audio_devices_t device)1107 static inline bool audio_is_bluetooth_sco_device(audio_devices_t device)
1108 {
1109 if ((device & AUDIO_DEVICE_BIT_IN) == 0) {
1110 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL_SCO) == 0))
1111 return true;
1112 } else {
1113 device &= ~AUDIO_DEVICE_BIT_IN;
1114 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) == 0))
1115 return true;
1116 }
1117
1118 return false;
1119 }
1120
audio_is_usb_out_device(audio_devices_t device)1121 static inline bool audio_is_usb_out_device(audio_devices_t device)
1122 {
1123 return ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB));
1124 }
1125
audio_is_usb_in_device(audio_devices_t device)1126 static inline bool audio_is_usb_in_device(audio_devices_t device)
1127 {
1128 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
1129 device &= ~AUDIO_DEVICE_BIT_IN;
1130 if (popcount(device) == 1 && (device & AUDIO_DEVICE_IN_ALL_USB) != 0)
1131 return true;
1132 }
1133 return false;
1134 }
1135
1136 /* OBSOLETE - use audio_is_usb_out_device() instead. */
audio_is_usb_device(audio_devices_t device)1137 static inline bool audio_is_usb_device(audio_devices_t device)
1138 {
1139 return audio_is_usb_out_device(device);
1140 }
1141
audio_is_remote_submix_device(audio_devices_t device)1142 static inline bool audio_is_remote_submix_device(audio_devices_t device)
1143 {
1144 if ((audio_is_output_devices(device) &&
1145 (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
1146 || (!audio_is_output_devices(device) &&
1147 (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX))
1148 return true;
1149 else
1150 return false;
1151 }
1152
1153 /* Returns true if:
1154 * representation is valid, and
1155 * there is at least one channel bit set which _could_ correspond to an input channel, and
1156 * there are no channel bits set which could _not_ correspond to an input channel.
1157 * Otherwise returns false.
1158 */
audio_is_input_channel(audio_channel_mask_t channel)1159 static inline bool audio_is_input_channel(audio_channel_mask_t channel)
1160 {
1161 uint32_t bits = audio_channel_mask_get_bits(channel);
1162 switch (audio_channel_mask_get_representation(channel)) {
1163 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
1164 if (bits & ~AUDIO_CHANNEL_IN_ALL) {
1165 bits = 0;
1166 }
1167 // fall through
1168 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
1169 return bits != 0;
1170 default:
1171 return false;
1172 }
1173 }
1174
1175 /* Returns true if:
1176 * representation is valid, and
1177 * there is at least one channel bit set which _could_ correspond to an output channel, and
1178 * there are no channel bits set which could _not_ correspond to an output channel.
1179 * Otherwise returns false.
1180 */
audio_is_output_channel(audio_channel_mask_t channel)1181 static inline bool audio_is_output_channel(audio_channel_mask_t channel)
1182 {
1183 uint32_t bits = audio_channel_mask_get_bits(channel);
1184 switch (audio_channel_mask_get_representation(channel)) {
1185 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
1186 if (bits & ~AUDIO_CHANNEL_OUT_ALL) {
1187 bits = 0;
1188 }
1189 // fall through
1190 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
1191 return bits != 0;
1192 default:
1193 return false;
1194 }
1195 }
1196
1197 /* Returns the number of channels from an input channel mask,
1198 * used in the context of audio input or recording.
1199 * If a channel bit is set which could _not_ correspond to an input channel,
1200 * it is excluded from the count.
1201 * Returns zero if the representation is invalid.
1202 */
audio_channel_count_from_in_mask(audio_channel_mask_t channel)1203 static inline uint32_t audio_channel_count_from_in_mask(audio_channel_mask_t channel)
1204 {
1205 uint32_t bits = audio_channel_mask_get_bits(channel);
1206 switch (audio_channel_mask_get_representation(channel)) {
1207 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
1208 // TODO: We can now merge with from_out_mask and remove anding
1209 bits &= AUDIO_CHANNEL_IN_ALL;
1210 // fall through
1211 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
1212 return popcount(bits);
1213 default:
1214 return 0;
1215 }
1216 }
1217
1218 /* Returns the number of channels from an output channel mask,
1219 * used in the context of audio output or playback.
1220 * If a channel bit is set which could _not_ correspond to an output channel,
1221 * it is excluded from the count.
1222 * Returns zero if the representation is invalid.
1223 */
audio_channel_count_from_out_mask(audio_channel_mask_t channel)1224 static inline uint32_t audio_channel_count_from_out_mask(audio_channel_mask_t channel)
1225 {
1226 uint32_t bits = audio_channel_mask_get_bits(channel);
1227 switch (audio_channel_mask_get_representation(channel)) {
1228 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
1229 // TODO: We can now merge with from_in_mask and remove anding
1230 bits &= AUDIO_CHANNEL_OUT_ALL;
1231 // fall through
1232 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
1233 return popcount(bits);
1234 default:
1235 return 0;
1236 }
1237 }
1238
1239 /* Derive a channel mask for index assignment from a channel count.
1240 * Returns the matching channel mask,
1241 * or AUDIO_CHANNEL_NONE if the channel count is zero,
1242 * or AUDIO_CHANNEL_INVALID if the channel count exceeds AUDIO_CHANNEL_COUNT_MAX.
1243 */
audio_channel_mask_for_index_assignment_from_count(uint32_t channel_count)1244 static inline audio_channel_mask_t audio_channel_mask_for_index_assignment_from_count(
1245 uint32_t channel_count)
1246 {
1247 if (channel_count == 0) {
1248 return AUDIO_CHANNEL_NONE;
1249 }
1250 if (channel_count > AUDIO_CHANNEL_COUNT_MAX) {
1251 return AUDIO_CHANNEL_INVALID;
1252 }
1253 uint32_t bits = (1 << channel_count) - 1;
1254 return audio_channel_mask_from_representation_and_bits(
1255 AUDIO_CHANNEL_REPRESENTATION_INDEX, bits);
1256 }
1257
1258 /* Derive an output channel mask for position assignment from a channel count.
1259 * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel
1260 * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad,
1261 * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC
1262 * for continuity with stereo.
1263 * Returns the matching channel mask,
1264 * or AUDIO_CHANNEL_NONE if the channel count is zero,
1265 * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
1266 * configurations for which a default output channel mask is defined.
1267 */
audio_channel_out_mask_from_count(uint32_t channel_count)1268 static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count)
1269 {
1270 uint32_t bits;
1271 switch (channel_count) {
1272 case 0:
1273 return AUDIO_CHANNEL_NONE;
1274 case 1:
1275 bits = AUDIO_CHANNEL_OUT_MONO;
1276 break;
1277 case 2:
1278 bits = AUDIO_CHANNEL_OUT_STEREO;
1279 break;
1280 case 3:
1281 bits = AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER;
1282 break;
1283 case 4: // 4.0
1284 bits = AUDIO_CHANNEL_OUT_QUAD;
1285 break;
1286 case 5: // 5.0
1287 bits = AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER;
1288 break;
1289 case 6: // 5.1
1290 bits = AUDIO_CHANNEL_OUT_5POINT1;
1291 break;
1292 case 7: // 6.1
1293 bits = AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER;
1294 break;
1295 case 8:
1296 bits = AUDIO_CHANNEL_OUT_7POINT1;
1297 break;
1298 // FIXME FCC_8
1299 default:
1300 return AUDIO_CHANNEL_INVALID;
1301 }
1302 return audio_channel_mask_from_representation_and_bits(
1303 AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
1304 }
1305
1306 /* Derive a default input channel mask from a channel count.
1307 * Assumes a position mask for mono and stereo, or an index mask for channel counts > 2.
1308 * Returns the matching channel mask,
1309 * or AUDIO_CHANNEL_NONE if the channel count is zero,
1310 * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
1311 * configurations for which a default input channel mask is defined.
1312 */
audio_channel_in_mask_from_count(uint32_t channel_count)1313 static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count)
1314 {
1315 uint32_t bits;
1316 switch (channel_count) {
1317 case 0:
1318 return AUDIO_CHANNEL_NONE;
1319 case 1:
1320 bits = AUDIO_CHANNEL_IN_MONO;
1321 break;
1322 case 2:
1323 bits = AUDIO_CHANNEL_IN_STEREO;
1324 break;
1325 case 3:
1326 case 4:
1327 case 5:
1328 case 6:
1329 case 7:
1330 case 8:
1331 // FIXME FCC_8
1332 return audio_channel_mask_for_index_assignment_from_count(channel_count);
1333 default:
1334 return AUDIO_CHANNEL_INVALID;
1335 }
1336 return audio_channel_mask_from_representation_and_bits(
1337 AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
1338 }
1339
audio_is_valid_format(audio_format_t format)1340 static inline bool audio_is_valid_format(audio_format_t format)
1341 {
1342 switch (format & AUDIO_FORMAT_MAIN_MASK) {
1343 case AUDIO_FORMAT_PCM:
1344 switch (format) {
1345 case AUDIO_FORMAT_PCM_16_BIT:
1346 case AUDIO_FORMAT_PCM_8_BIT:
1347 case AUDIO_FORMAT_PCM_32_BIT:
1348 case AUDIO_FORMAT_PCM_8_24_BIT:
1349 case AUDIO_FORMAT_PCM_FLOAT:
1350 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1351 return true;
1352 default:
1353 return false;
1354 }
1355 /* not reached */
1356 case AUDIO_FORMAT_MP3:
1357 case AUDIO_FORMAT_AMR_NB:
1358 case AUDIO_FORMAT_AMR_WB:
1359 case AUDIO_FORMAT_AAC:
1360 case AUDIO_FORMAT_HE_AAC_V1:
1361 case AUDIO_FORMAT_HE_AAC_V2:
1362 case AUDIO_FORMAT_VORBIS:
1363 case AUDIO_FORMAT_OPUS:
1364 case AUDIO_FORMAT_AC3:
1365 case AUDIO_FORMAT_E_AC3:
1366 case AUDIO_FORMAT_DTS:
1367 case AUDIO_FORMAT_DTS_HD:
1368 return true;
1369 default:
1370 return false;
1371 }
1372 }
1373
audio_is_linear_pcm(audio_format_t format)1374 static inline bool audio_is_linear_pcm(audio_format_t format)
1375 {
1376 return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM);
1377 }
1378
audio_bytes_per_sample(audio_format_t format)1379 static inline size_t audio_bytes_per_sample(audio_format_t format)
1380 {
1381 size_t size = 0;
1382
1383 switch (format) {
1384 case AUDIO_FORMAT_PCM_32_BIT:
1385 case AUDIO_FORMAT_PCM_8_24_BIT:
1386 size = sizeof(int32_t);
1387 break;
1388 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1389 size = sizeof(uint8_t) * 3;
1390 break;
1391 case AUDIO_FORMAT_PCM_16_BIT:
1392 size = sizeof(int16_t);
1393 break;
1394 case AUDIO_FORMAT_PCM_8_BIT:
1395 size = sizeof(uint8_t);
1396 break;
1397 case AUDIO_FORMAT_PCM_FLOAT:
1398 size = sizeof(float);
1399 break;
1400 default:
1401 break;
1402 }
1403 return size;
1404 }
1405
1406 /* converts device address to string sent to audio HAL via set_parameters */
audio_device_address_to_parameter(audio_devices_t device,const char * address)1407 static inline char *audio_device_address_to_parameter(audio_devices_t device, const char *address)
1408 {
1409 const size_t kSize = AUDIO_DEVICE_MAX_ADDRESS_LEN + sizeof("a2dp_sink_address=");
1410 char param[kSize];
1411
1412 if (device & AUDIO_DEVICE_OUT_ALL_A2DP)
1413 snprintf(param, kSize, "%s=%s", "a2dp_sink_address", address);
1414 else if (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
1415 snprintf(param, kSize, "%s=%s", "mix", address);
1416 else
1417 snprintf(param, kSize, "%s", address);
1418
1419 return strdup(param);
1420 }
1421
audio_device_is_digital(audio_devices_t device)1422 static inline bool audio_device_is_digital(audio_devices_t device) {
1423 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
1424 // input
1425 return (~AUDIO_DEVICE_BIT_IN & device & (AUDIO_DEVICE_IN_ALL_USB |
1426 AUDIO_DEVICE_IN_HDMI |
1427 AUDIO_DEVICE_IN_SPDIF |
1428 AUDIO_DEVICE_IN_IP)) != 0;
1429 } else {
1430 // output
1431 return (device & (AUDIO_DEVICE_OUT_ALL_USB |
1432 AUDIO_DEVICE_OUT_HDMI |
1433 AUDIO_DEVICE_OUT_HDMI_ARC |
1434 AUDIO_DEVICE_OUT_SPDIF |
1435 AUDIO_DEVICE_OUT_IP)) != 0;
1436 }
1437 }
1438
1439 __END_DECLS
1440
1441 #endif // ANDROID_AUDIO_CORE_H
1442