blob: 1e3ba0e599b775edc7c6be18e562bc077e3ce1de [file] [log] [blame]
Dima Zavine8e4be52011-05-12 10:25:33 -07001/*
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 <sys/cdefs.h>
24#include <sys/types.h>
25
26#include <cutils/bitops.h>
27
28__BEGIN_DECLS
29
30/* The enums were moved here mostly from
31 * frameworks/base/include/media/AudioSystem.h
32 */
33
Jeff Brown8ecc7af2013-08-16 20:09:37 -070034/* device address used to refer to the standard remote submix */
35#define AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS "0"
36
Glenn Kasten1c3e16f2011-12-19 09:21:48 -080037/* AudioFlinger and AudioPolicy services use I/O handles to identify audio sources and sinks */
Dima Zavine8e4be52011-05-12 10:25:33 -070038typedef int audio_io_handle_t;
Glenn Kasten1c3e16f2011-12-19 09:21:48 -080039#define AUDIO_IO_HANDLE_NONE 0
Dima Zavine8e4be52011-05-12 10:25:33 -070040
41/* Audio stream types */
42typedef enum {
Glenn Kasten1c3e16f2011-12-19 09:21:48 -080043 /* These values must kept in sync with
44 * frameworks/base/media/java/android/media/AudioSystem.java
45 */
Dima Zavine8e4be52011-05-12 10:25:33 -070046 AUDIO_STREAM_DEFAULT = -1,
Glenn Kasten1c3e16f2011-12-19 09:21:48 -080047 AUDIO_STREAM_MIN = 0,
Dima Zavine8e4be52011-05-12 10:25:33 -070048 AUDIO_STREAM_VOICE_CALL = 0,
49 AUDIO_STREAM_SYSTEM = 1,
50 AUDIO_STREAM_RING = 2,
51 AUDIO_STREAM_MUSIC = 3,
52 AUDIO_STREAM_ALARM = 4,
53 AUDIO_STREAM_NOTIFICATION = 5,
54 AUDIO_STREAM_BLUETOOTH_SCO = 6,
55 AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user and must be routed to speaker */
56 AUDIO_STREAM_DTMF = 8,
57 AUDIO_STREAM_TTS = 9,
58
59 AUDIO_STREAM_CNT,
60 AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1,
61} audio_stream_type_t;
62
63/* Do not change these values without updating their counterparts
Jean-Michel Trivi0d580e82014-05-21 14:43:14 -070064 * in frameworks/base/media/java/android/media/AudioAttributes.java
65 */
66typedef enum {
67 AUDIO_CONTENT_TYPE_UNKNOWN = 0,
68 AUDIO_CONTENT_TYPE_SPEECH = 1,
69 AUDIO_CONTENT_TYPE_MUSIC = 2,
70 AUDIO_CONTENT_TYPE_MOVIE = 3,
71 AUDIO_CONTENT_TYPE_SONIFICATION = 4,
72
73 AUDIO_CONTENT_TYPE_CNT,
74 AUDIO_CONTENT_TYPE_MAX = AUDIO_CONTENT_TYPE_CNT - 1,
75} audio_content_type_t;
76
77/* Do not change these values without updating their counterparts
78 * in frameworks/base/media/java/android/media/AudioAttributes.java
79 */
80typedef enum {
81 AUDIO_USAGE_UNKNOWN = 0,
82 AUDIO_USAGE_MEDIA = 1,
83 AUDIO_USAGE_VOICE_COMMUNICATION = 2,
84 AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
85 AUDIO_USAGE_ALARM = 4,
86 AUDIO_USAGE_NOTIFICATION = 5,
87 AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE = 6,
88 AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST = 7,
89 AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT = 8,
90 AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED = 9,
91 AUDIO_USAGE_NOTIFICATION_EVENT = 10,
92 AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
93 AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
94 AUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
95 AUDIO_USAGE_GAME = 14,
96
97 AUDIO_USAGE_CNT,
98 AUDIO_USAGE_MAX = AUDIO_USAGE_CNT - 1,
99} audio_usage_t;
100
101typedef uint32_t audio_flags_mask_t;
102
103/* Do not change these values without updating their counterparts
104 * in frameworks/base/media/java/android/media/AudioAttributes.java
105 */
106enum {
107 AUDIO_FLAG_AUDIBILITY_ENFORCED = 0x1,
108 AUDIO_FLAG_SECURE = 0x2,
109 AUDIO_FLAG_SCO = 0x4,
110};
111
112/* Do not change these values without updating their counterparts
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800113 * in frameworks/base/media/java/android/media/MediaRecorder.java,
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700114 * frameworks/av/services/audiopolicy/AudioPolicyService.cpp,
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800115 * and system/media/audio_effects/include/audio_effects/audio_effects_conf.h!
Dima Zavine8e4be52011-05-12 10:25:33 -0700116 */
117typedef enum {
118 AUDIO_SOURCE_DEFAULT = 0,
119 AUDIO_SOURCE_MIC = 1,
120 AUDIO_SOURCE_VOICE_UPLINK = 2,
121 AUDIO_SOURCE_VOICE_DOWNLINK = 3,
122 AUDIO_SOURCE_VOICE_CALL = 4,
123 AUDIO_SOURCE_CAMCORDER = 5,
124 AUDIO_SOURCE_VOICE_RECOGNITION = 6,
125 AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
Jean-Michel Trivie11866a2012-08-16 17:53:30 -0700126 AUDIO_SOURCE_REMOTE_SUBMIX = 8, /* Source for the mix to be presented remotely. */
127 /* An example of remote presentation is Wifi Display */
128 /* where a dongle attached to a TV can be used to */
129 /* play the mix captured by this audio source. */
Dima Zavine8e4be52011-05-12 10:25:33 -0700130 AUDIO_SOURCE_CNT,
131 AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1,
Eric Laurent04c12ca2013-09-09 10:39:54 -0700132 AUDIO_SOURCE_HOTWORD = 1999, /* A low-priority, preemptible audio source for
133 for background software hotword detection.
134 Same tuning as AUDIO_SOURCE_VOICE_RECOGNITION.
135 Used only internally to the framework. Not exposed
136 at the audio HAL. */
Dima Zavine8e4be52011-05-12 10:25:33 -0700137} audio_source_t;
138
Jean-Michel Trivi0d580e82014-05-21 14:43:14 -0700139/* Audio attributes */
140#define AUDIO_ATTRIBUTES_TAGS_MAX_SIZE 256
141typedef struct {
142 audio_content_type_t content_type;
143 audio_usage_t usage;
144 audio_source_t source;
145 audio_flags_mask_t flags;
146 char tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE]; /* UTF8 */
147} audio_attributes_t;
148
Dima Zavine8e4be52011-05-12 10:25:33 -0700149/* special audio session values
150 * (XXX: should this be living in the audio effects land?)
151 */
152typedef enum {
153 /* session for effects attached to a particular output stream
154 * (value must be less than 0)
155 */
156 AUDIO_SESSION_OUTPUT_STAGE = -1,
157
158 /* session for effects applied to output mix. These effects can
159 * be moved by audio policy manager to another output stream
160 * (value must be 0)
161 */
162 AUDIO_SESSION_OUTPUT_MIX = 0,
Glenn Kastenb4f2b4e2012-06-25 14:57:36 -0700163
164 /* application does not specify an explicit session ID to be used,
165 * and requests a new session ID to be allocated
166 * TODO use unique values for AUDIO_SESSION_OUTPUT_MIX and AUDIO_SESSION_ALLOCATE,
167 * after all uses have been updated from 0 to the appropriate symbol, and have been tested.
168 */
169 AUDIO_SESSION_ALLOCATE = 0,
Dima Zavine8e4be52011-05-12 10:25:33 -0700170} audio_session_t;
171
172/* Audio sub formats (see enum audio_format). */
173
174/* PCM sub formats */
175typedef enum {
Glenn Kastenc0a51092014-01-31 07:51:17 -0800176 /* All of these are in native byte order */
Eric Laurent9714b272011-05-26 13:52:47 -0700177 AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */
178 AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */
179 AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */
180 AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800181 AUDIO_FORMAT_PCM_SUB_FLOAT = 0x5, /* PCM single-precision floating point */
Glenn Kastenc0a51092014-01-31 07:51:17 -0800182 AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED = 0x6, /* PCM signed .23 fixed point packed in 3 bytes */
Dima Zavine8e4be52011-05-12 10:25:33 -0700183} audio_format_pcm_sub_fmt_t;
184
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800185/* The audio_format_*_sub_fmt_t declarations are not currently used */
186
Dima Zavine8e4be52011-05-12 10:25:33 -0700187/* MP3 sub format field definition : can use 11 LSBs in the same way as MP3
188 * frame header to specify bit rate, stereo mode, version...
189 */
190typedef enum {
191 AUDIO_FORMAT_MP3_SUB_NONE = 0x0,
192} audio_format_mp3_sub_fmt_t;
193
194/* AMR NB/WB sub format field definition: specify frame block interleaving,
195 * bandwidth efficient or octet aligned, encoding mode for recording...
196 */
197typedef enum {
198 AUDIO_FORMAT_AMR_SUB_NONE = 0x0,
199} audio_format_amr_sub_fmt_t;
200
201/* AAC sub format field definition: specify profile or bitrate for recording... */
202typedef enum {
aarti jadhav-gaikwad923e7402014-06-18 15:23:09 +0530203 AUDIO_FORMAT_AAC_SUB_MAIN = 0x1,
204 AUDIO_FORMAT_AAC_SUB_LC = 0x2,
205 AUDIO_FORMAT_AAC_SUB_SSR = 0x4,
206 AUDIO_FORMAT_AAC_SUB_LTP = 0x8,
207 AUDIO_FORMAT_AAC_SUB_HE_V1 = 0x10,
208 AUDIO_FORMAT_AAC_SUB_SCALABLE = 0x20,
209 AUDIO_FORMAT_AAC_SUB_ERLC = 0x40,
210 AUDIO_FORMAT_AAC_SUB_LD = 0x80,
211 AUDIO_FORMAT_AAC_SUB_HE_V2 = 0x100,
212 AUDIO_FORMAT_AAC_SUB_ELD = 0x200,
Dima Zavine8e4be52011-05-12 10:25:33 -0700213} audio_format_aac_sub_fmt_t;
214
215/* VORBIS sub format field definition: specify quality for recording... */
216typedef enum {
217 AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0,
218} audio_format_vorbis_sub_fmt_t;
219
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800220/* Audio format consists of a main format field (upper 8 bits) and a sub format
Dima Zavine8e4be52011-05-12 10:25:33 -0700221 * field (lower 24 bits).
222 *
223 * The main format indicates the main codec type. The sub format field
224 * indicates options and parameters for each format. The sub format is mainly
225 * used for record to indicate for instance the requested bitrate or profile.
226 * It can also be used for certain formats to give informations not present in
227 * the encoded audio stream (e.g. octet alignement for AMR).
228 */
229typedef enum {
230 AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL,
231 AUDIO_FORMAT_DEFAULT = 0,
232 AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */
233 AUDIO_FORMAT_MP3 = 0x01000000UL,
234 AUDIO_FORMAT_AMR_NB = 0x02000000UL,
235 AUDIO_FORMAT_AMR_WB = 0x03000000UL,
236 AUDIO_FORMAT_AAC = 0x04000000UL,
aarti jadhav-gaikwad923e7402014-06-18 15:23:09 +0530237 AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V1*/
238 AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V2*/
Dima Zavine8e4be52011-05-12 10:25:33 -0700239 AUDIO_FORMAT_VORBIS = 0x07000000UL,
Vignesh Venkatasubramanian76edb1c2014-01-29 09:47:56 -0800240 AUDIO_FORMAT_OPUS = 0x08000000UL,
Eric Laurentce30de32014-06-10 15:39:16 -0700241 AUDIO_FORMAT_AC3 = 0x09000000UL,
242 AUDIO_FORMAT_E_AC3 = 0x0A000000UL,
Dima Zavine8e4be52011-05-12 10:25:33 -0700243 AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL,
244 AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL,
245
246 /* Aliases */
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800247 /* note != AudioFormat.ENCODING_PCM_16BIT */
Dima Zavine8e4be52011-05-12 10:25:33 -0700248 AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM |
249 AUDIO_FORMAT_PCM_SUB_16_BIT),
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800250 /* note != AudioFormat.ENCODING_PCM_8BIT */
Dima Zavine8e4be52011-05-12 10:25:33 -0700251 AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM |
252 AUDIO_FORMAT_PCM_SUB_8_BIT),
Eric Laurent9714b272011-05-26 13:52:47 -0700253 AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM |
254 AUDIO_FORMAT_PCM_SUB_32_BIT),
255 AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM |
256 AUDIO_FORMAT_PCM_SUB_8_24_BIT),
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800257 AUDIO_FORMAT_PCM_FLOAT = (AUDIO_FORMAT_PCM |
258 AUDIO_FORMAT_PCM_SUB_FLOAT),
Glenn Kastenc0a51092014-01-31 07:51:17 -0800259 AUDIO_FORMAT_PCM_24_BIT_PACKED = (AUDIO_FORMAT_PCM |
260 AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED),
aarti jadhav-gaikwad923e7402014-06-18 15:23:09 +0530261 AUDIO_FORMAT_AAC_MAIN = (AUDIO_FORMAT_AAC |
262 AUDIO_FORMAT_AAC_SUB_MAIN),
263 AUDIO_FORMAT_AAC_LC = (AUDIO_FORMAT_AAC |
264 AUDIO_FORMAT_AAC_SUB_LC),
265 AUDIO_FORMAT_AAC_SSR = (AUDIO_FORMAT_AAC |
266 AUDIO_FORMAT_AAC_SUB_SSR),
267 AUDIO_FORMAT_AAC_LTP = (AUDIO_FORMAT_AAC |
268 AUDIO_FORMAT_AAC_SUB_LTP),
269 AUDIO_FORMAT_AAC_HE_V1 = (AUDIO_FORMAT_AAC |
270 AUDIO_FORMAT_AAC_SUB_HE_V1),
271 AUDIO_FORMAT_AAC_SCALABLE = (AUDIO_FORMAT_AAC |
272 AUDIO_FORMAT_AAC_SUB_SCALABLE),
273 AUDIO_FORMAT_AAC_ERLC = (AUDIO_FORMAT_AAC |
274 AUDIO_FORMAT_AAC_SUB_ERLC),
275 AUDIO_FORMAT_AAC_LD = (AUDIO_FORMAT_AAC |
276 AUDIO_FORMAT_AAC_SUB_LD),
277 AUDIO_FORMAT_AAC_HE_V2 = (AUDIO_FORMAT_AAC |
278 AUDIO_FORMAT_AAC_SUB_HE_V2),
279 AUDIO_FORMAT_AAC_ELD = (AUDIO_FORMAT_AAC |
280 AUDIO_FORMAT_AAC_SUB_ELD),
Dima Zavine8e4be52011-05-12 10:25:33 -0700281} audio_format_t;
282
Glenn Kasten16a7a042012-07-03 15:21:05 -0700283enum {
Eric Laurent4cd05012014-02-18 12:40:36 -0800284 AUDIO_CHANNEL_NONE = 0x0,
Dima Zavine8e4be52011-05-12 10:25:33 -0700285 /* output channels */
Jean-Michel Trivi6d4f3972011-07-25 16:19:07 -0700286 AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x1,
287 AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x2,
288 AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x4,
289 AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x8,
290 AUDIO_CHANNEL_OUT_BACK_LEFT = 0x10,
291 AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x20,
292 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40,
293 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80,
294 AUDIO_CHANNEL_OUT_BACK_CENTER = 0x100,
295 AUDIO_CHANNEL_OUT_SIDE_LEFT = 0x200,
296 AUDIO_CHANNEL_OUT_SIDE_RIGHT = 0x400,
297 AUDIO_CHANNEL_OUT_TOP_CENTER = 0x800,
298 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT = 0x1000,
299 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER = 0x2000,
300 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT = 0x4000,
301 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT = 0x8000,
302 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER = 0x10000,
303 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT = 0x20000,
Dima Zavine8e4be52011-05-12 10:25:33 -0700304
305 AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT,
306 AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
307 AUDIO_CHANNEL_OUT_FRONT_RIGHT),
308 AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
309 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
310 AUDIO_CHANNEL_OUT_BACK_LEFT |
311 AUDIO_CHANNEL_OUT_BACK_RIGHT),
Glenn Kastenb8d59392014-04-29 08:41:46 -0700312 AUDIO_CHANNEL_OUT_QUAD_BACK = AUDIO_CHANNEL_OUT_QUAD,
Glenn Kastenee7c17b2014-04-29 08:43:19 -0700313 /* like AUDIO_CHANNEL_OUT_QUAD_BACK with *_SIDE_* instead of *_BACK_* */
314 AUDIO_CHANNEL_OUT_QUAD_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
315 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
316 AUDIO_CHANNEL_OUT_SIDE_LEFT |
317 AUDIO_CHANNEL_OUT_SIDE_RIGHT),
Dima Zavine8e4be52011-05-12 10:25:33 -0700318 AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
319 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
320 AUDIO_CHANNEL_OUT_FRONT_CENTER |
321 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
322 AUDIO_CHANNEL_OUT_BACK_LEFT |
323 AUDIO_CHANNEL_OUT_BACK_RIGHT),
Glenn Kastenb8d59392014-04-29 08:41:46 -0700324 AUDIO_CHANNEL_OUT_5POINT1_BACK = AUDIO_CHANNEL_OUT_5POINT1,
Glenn Kastenee7c17b2014-04-29 08:43:19 -0700325 /* like AUDIO_CHANNEL_OUT_5POINT1_BACK with *_SIDE_* instead of *_BACK_* */
326 AUDIO_CHANNEL_OUT_5POINT1_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
327 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
328 AUDIO_CHANNEL_OUT_FRONT_CENTER |
329 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
330 AUDIO_CHANNEL_OUT_SIDE_LEFT |
331 AUDIO_CHANNEL_OUT_SIDE_RIGHT),
Jean-Michel Trivi33fad992011-07-24 16:31:03 -0700332 // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1
Dima Zavine8e4be52011-05-12 10:25:33 -0700333 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
334 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
335 AUDIO_CHANNEL_OUT_FRONT_CENTER |
336 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
337 AUDIO_CHANNEL_OUT_BACK_LEFT |
338 AUDIO_CHANNEL_OUT_BACK_RIGHT |
Jean-Michel Trivi33fad992011-07-24 16:31:03 -0700339 AUDIO_CHANNEL_OUT_SIDE_LEFT |
340 AUDIO_CHANNEL_OUT_SIDE_RIGHT),
Dima Zavine8e4be52011-05-12 10:25:33 -0700341 AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
342 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
343 AUDIO_CHANNEL_OUT_FRONT_CENTER |
344 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
345 AUDIO_CHANNEL_OUT_BACK_LEFT |
346 AUDIO_CHANNEL_OUT_BACK_RIGHT |
347 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
348 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
Jean-Michel Trivi33fad992011-07-24 16:31:03 -0700349 AUDIO_CHANNEL_OUT_BACK_CENTER|
350 AUDIO_CHANNEL_OUT_SIDE_LEFT|
351 AUDIO_CHANNEL_OUT_SIDE_RIGHT|
352 AUDIO_CHANNEL_OUT_TOP_CENTER|
353 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT|
354 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER|
355 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT|
356 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT|
357 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER|
358 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT),
Dima Zavine8e4be52011-05-12 10:25:33 -0700359
360 /* input channels */
361 AUDIO_CHANNEL_IN_LEFT = 0x4,
362 AUDIO_CHANNEL_IN_RIGHT = 0x8,
363 AUDIO_CHANNEL_IN_FRONT = 0x10,
364 AUDIO_CHANNEL_IN_BACK = 0x20,
365 AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40,
366 AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80,
367 AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100,
368 AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200,
369 AUDIO_CHANNEL_IN_PRESSURE = 0x400,
370 AUDIO_CHANNEL_IN_X_AXIS = 0x800,
371 AUDIO_CHANNEL_IN_Y_AXIS = 0x1000,
372 AUDIO_CHANNEL_IN_Z_AXIS = 0x2000,
373 AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000,
374 AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000,
375
376 AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT,
377 AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT),
Eric Laurent6c70cee2013-01-17 17:31:49 -0800378 AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK),
Dima Zavine8e4be52011-05-12 10:25:33 -0700379 AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT |
380 AUDIO_CHANNEL_IN_RIGHT |
381 AUDIO_CHANNEL_IN_FRONT |
382 AUDIO_CHANNEL_IN_BACK|
383 AUDIO_CHANNEL_IN_LEFT_PROCESSED |
384 AUDIO_CHANNEL_IN_RIGHT_PROCESSED |
385 AUDIO_CHANNEL_IN_FRONT_PROCESSED |
386 AUDIO_CHANNEL_IN_BACK_PROCESSED|
387 AUDIO_CHANNEL_IN_PRESSURE |
388 AUDIO_CHANNEL_IN_X_AXIS |
389 AUDIO_CHANNEL_IN_Y_AXIS |
390 AUDIO_CHANNEL_IN_Z_AXIS |
391 AUDIO_CHANNEL_IN_VOICE_UPLINK |
392 AUDIO_CHANNEL_IN_VOICE_DNLINK),
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -0800393};
394
Glenn Kastenee7c17b2014-04-29 08:43:19 -0700395/* A channel mask per se only defines the presence or absence of a channel, not the order.
396 * But see AUDIO_INTERLEAVE_* below for the platform convention of order.
397 */
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -0800398typedef uint32_t audio_channel_mask_t;
Dima Zavine8e4be52011-05-12 10:25:33 -0700399
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800400/* Expresses the convention when stereo audio samples are stored interleaved
401 * in an array. This should improve readability by allowing code to use
402 * symbolic indices instead of hard-coded [0] and [1].
Glenn Kastenee7c17b2014-04-29 08:43:19 -0700403 *
404 * For multi-channel beyond stereo, the platform convention is that channels
405 * are interleaved in order from least significant channel mask bit
406 * to most significant channel mask bit, with unused bits skipped.
407 * Any exceptions to this convention will be noted at the appropriate API.
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800408 */
409enum {
410 AUDIO_INTERLEAVE_LEFT = 0,
411 AUDIO_INTERLEAVE_RIGHT = 1,
412};
413
Dima Zavine8e4be52011-05-12 10:25:33 -0700414typedef enum {
415 AUDIO_MODE_INVALID = -2,
416 AUDIO_MODE_CURRENT = -1,
417 AUDIO_MODE_NORMAL = 0,
418 AUDIO_MODE_RINGTONE = 1,
419 AUDIO_MODE_IN_CALL = 2,
420 AUDIO_MODE_IN_COMMUNICATION = 3,
421
422 AUDIO_MODE_CNT,
423 AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1,
424} audio_mode_t;
425
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800426/* This enum is deprecated */
Dima Zavine8e4be52011-05-12 10:25:33 -0700427typedef enum {
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800428 AUDIO_IN_ACOUSTICS_NONE = 0,
Dima Zavine8e4be52011-05-12 10:25:33 -0700429 AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001,
430 AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0,
431 AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002,
432 AUDIO_IN_ACOUSTICS_NS_DISABLE = 0,
433 AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004,
434 AUDIO_IN_ACOUSTICS_TX_DISABLE = 0,
435} audio_in_acoustics_t;
436
Glenn Kasten16a7a042012-07-03 15:21:05 -0700437enum {
Eric Laurenteeeee802012-08-28 14:29:07 -0700438 AUDIO_DEVICE_NONE = 0x0,
439 /* reserved bits */
440 AUDIO_DEVICE_BIT_IN = 0x80000000,
441 AUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
Dima Zavine8e4be52011-05-12 10:25:33 -0700442 /* output devices */
443 AUDIO_DEVICE_OUT_EARPIECE = 0x1,
444 AUDIO_DEVICE_OUT_SPEAKER = 0x2,
445 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
446 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
447 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10,
448 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
449 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
450 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
451 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
452 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
453 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400,
Eric Laurentabcb9992014-05-16 15:11:08 -0700454 AUDIO_DEVICE_OUT_HDMI = AUDIO_DEVICE_OUT_AUX_DIGITAL,
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800455 /* uses an analog connection (multiplexed over the USB connector pins for instance) */
Dima Zavine8e4be52011-05-12 10:25:33 -0700456 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
457 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800458 /* USB accessory mode: your Android device is a USB device and the dock is a USB host */
Eric Laurent79f90bd2012-04-06 08:57:48 -0700459 AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000,
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800460 /* USB host mode: your Android device is a USB host and the dock is a USB device */
Eric Laurent79f90bd2012-04-06 08:57:48 -0700461 AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000,
Eric Laurenteeeee802012-08-28 14:29:07 -0700462 AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000,
Eric Laurentabcb9992014-05-16 15:11:08 -0700463 /* Telephony voice TX path */
464 AUDIO_DEVICE_OUT_TELEPHONY_TX = 0x10000,
465 /* Analog jack with line impedance detected */
466 AUDIO_DEVICE_OUT_LINE = 0x20000,
467 /* HDMI Audio Return Channel */
468 AUDIO_DEVICE_OUT_HDMI_ARC = 0x40000,
469 /* S/PDIF out */
470 AUDIO_DEVICE_OUT_SPDIF = 0x80000,
471 /* FM transmitter out */
472 AUDIO_DEVICE_OUT_FM = 0x100000,
Eric Laurenteeeee802012-08-28 14:29:07 -0700473 AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT,
Dima Zavine8e4be52011-05-12 10:25:33 -0700474 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE |
475 AUDIO_DEVICE_OUT_SPEAKER |
476 AUDIO_DEVICE_OUT_WIRED_HEADSET |
477 AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
478 AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
479 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
480 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
481 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
482 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
483 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
Eric Laurentabcb9992014-05-16 15:11:08 -0700484 AUDIO_DEVICE_OUT_HDMI |
Dima Zavine8e4be52011-05-12 10:25:33 -0700485 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
486 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
Eric Laurent79f90bd2012-04-06 08:57:48 -0700487 AUDIO_DEVICE_OUT_USB_ACCESSORY |
488 AUDIO_DEVICE_OUT_USB_DEVICE |
Eric Laurenteeeee802012-08-28 14:29:07 -0700489 AUDIO_DEVICE_OUT_REMOTE_SUBMIX |
Eric Laurentabcb9992014-05-16 15:11:08 -0700490 AUDIO_DEVICE_OUT_TELEPHONY_TX |
491 AUDIO_DEVICE_OUT_LINE |
492 AUDIO_DEVICE_OUT_HDMI_ARC |
493 AUDIO_DEVICE_OUT_SPDIF |
494 AUDIO_DEVICE_OUT_FM |
Dima Zavine8e4be52011-05-12 10:25:33 -0700495 AUDIO_DEVICE_OUT_DEFAULT),
496 AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
497 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
498 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
499 AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
500 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
501 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
Eric Laurent79f90bd2012-04-06 08:57:48 -0700502 AUDIO_DEVICE_OUT_ALL_USB = (AUDIO_DEVICE_OUT_USB_ACCESSORY |
503 AUDIO_DEVICE_OUT_USB_DEVICE),
Dima Zavine8e4be52011-05-12 10:25:33 -0700504
505 /* input devices */
Eric Laurenteeeee802012-08-28 14:29:07 -0700506 AUDIO_DEVICE_IN_COMMUNICATION = AUDIO_DEVICE_BIT_IN | 0x1,
507 AUDIO_DEVICE_IN_AMBIENT = AUDIO_DEVICE_BIT_IN | 0x2,
508 AUDIO_DEVICE_IN_BUILTIN_MIC = AUDIO_DEVICE_BIT_IN | 0x4,
509 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8,
510 AUDIO_DEVICE_IN_WIRED_HEADSET = AUDIO_DEVICE_BIT_IN | 0x10,
511 AUDIO_DEVICE_IN_AUX_DIGITAL = AUDIO_DEVICE_BIT_IN | 0x20,
Eric Laurentabcb9992014-05-16 15:11:08 -0700512 AUDIO_DEVICE_IN_HDMI = AUDIO_DEVICE_IN_AUX_DIGITAL,
513 /* Telephony voice RX path */
Eric Laurenteeeee802012-08-28 14:29:07 -0700514 AUDIO_DEVICE_IN_VOICE_CALL = AUDIO_DEVICE_BIT_IN | 0x40,
Eric Laurentabcb9992014-05-16 15:11:08 -0700515 AUDIO_DEVICE_IN_TELEPHONY_RX = AUDIO_DEVICE_IN_VOICE_CALL,
Eric Laurenteeeee802012-08-28 14:29:07 -0700516 AUDIO_DEVICE_IN_BACK_MIC = AUDIO_DEVICE_BIT_IN | 0x80,
517 AUDIO_DEVICE_IN_REMOTE_SUBMIX = AUDIO_DEVICE_BIT_IN | 0x100,
518 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x200,
519 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x400,
520 AUDIO_DEVICE_IN_USB_ACCESSORY = AUDIO_DEVICE_BIT_IN | 0x800,
521 AUDIO_DEVICE_IN_USB_DEVICE = AUDIO_DEVICE_BIT_IN | 0x1000,
Eric Laurentabcb9992014-05-16 15:11:08 -0700522 /* FM tuner input */
523 AUDIO_DEVICE_IN_FM_TUNER = AUDIO_DEVICE_BIT_IN | 0x2000,
524 /* TV tuner input */
525 AUDIO_DEVICE_IN_TV_TUNER = AUDIO_DEVICE_BIT_IN | 0x4000,
526 /* Analog jack with line impedance detected */
527 AUDIO_DEVICE_IN_LINE = AUDIO_DEVICE_BIT_IN | 0x8000,
528 /* S/PDIF in */
529 AUDIO_DEVICE_IN_SPDIF = AUDIO_DEVICE_BIT_IN | 0x10000,
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700530 AUDIO_DEVICE_IN_BLUETOOTH_A2DP = AUDIO_DEVICE_BIT_IN | 0x20000,
Terry Heob63dd8a2014-06-27 15:25:56 +0900531 AUDIO_DEVICE_IN_LOOPBACK = AUDIO_DEVICE_BIT_IN | 0x40000,
Eric Laurenteeeee802012-08-28 14:29:07 -0700532 AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT,
Dima Zavine8e4be52011-05-12 10:25:33 -0700533
534 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION |
535 AUDIO_DEVICE_IN_AMBIENT |
536 AUDIO_DEVICE_IN_BUILTIN_MIC |
537 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET |
538 AUDIO_DEVICE_IN_WIRED_HEADSET |
Eric Laurentabcb9992014-05-16 15:11:08 -0700539 AUDIO_DEVICE_IN_HDMI |
540 AUDIO_DEVICE_IN_TELEPHONY_RX |
Dima Zavine8e4be52011-05-12 10:25:33 -0700541 AUDIO_DEVICE_IN_BACK_MIC |
Eric Laurenteeeee802012-08-28 14:29:07 -0700542 AUDIO_DEVICE_IN_REMOTE_SUBMIX |
543 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET |
544 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET |
545 AUDIO_DEVICE_IN_USB_ACCESSORY |
546 AUDIO_DEVICE_IN_USB_DEVICE |
Eric Laurentabcb9992014-05-16 15:11:08 -0700547 AUDIO_DEVICE_IN_FM_TUNER |
548 AUDIO_DEVICE_IN_TV_TUNER |
549 AUDIO_DEVICE_IN_LINE |
550 AUDIO_DEVICE_IN_SPDIF |
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700551 AUDIO_DEVICE_IN_BLUETOOTH_A2DP |
Terry Heob63dd8a2014-06-27 15:25:56 +0900552 AUDIO_DEVICE_IN_LOOPBACK |
Dima Zavine8e4be52011-05-12 10:25:33 -0700553 AUDIO_DEVICE_IN_DEFAULT),
554 AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
Paul McLean00b89722014-04-18 14:29:22 -0700555 AUDIO_DEVICE_IN_ALL_USB = (AUDIO_DEVICE_IN_USB_ACCESSORY |
556 AUDIO_DEVICE_IN_USB_DEVICE),
Glenn Kasten16a7a042012-07-03 15:21:05 -0700557};
558
559typedef uint32_t audio_devices_t;
Dima Zavine8e4be52011-05-12 10:25:33 -0700560
Eric Laurent545ab462012-04-16 18:05:39 -0700561/* the audio output flags serve two purposes:
562 * - when an AudioTrack is created they indicate a "wish" to be connected to an
563 * output stream with attributes corresponding to the specified flags
564 * - when present in an output profile descriptor listed for a particular audio
565 * hardware module, they indicate that an output stream can be opened that
566 * supports the attributes indicated by the flags.
567 * the audio policy manager will try to match the flags in the request
568 * (when getOuput() is called) to an available output stream.
569 */
570typedef enum {
Eric Laurent9aec3622012-04-13 16:52:58 -0700571 AUDIO_OUTPUT_FLAG_NONE = 0x0, // no attributes
572 AUDIO_OUTPUT_FLAG_DIRECT = 0x1, // this output directly connects a track
573 // to one output stream: no software mixer
574 AUDIO_OUTPUT_FLAG_PRIMARY = 0x2, // this output is the primary output of
575 // the device. It is unique and must be
576 // present. It is opened by default and
577 // receives routing, audio mode and volume
578 // controls related to voice calls.
579 AUDIO_OUTPUT_FLAG_FAST = 0x4, // output supports "fast tracks",
580 // defined elsewhere
Richard Fitzgerald05529a12013-03-25 16:07:43 +0000581 AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8, // use deep audio buffers
582 AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD = 0x10, // offload playback of compressed
583 // streams to hardware codec
584 AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20 // use non-blocking write
Eric Laurent545ab462012-04-16 18:05:39 -0700585} audio_output_flags_t;
586
Glenn Kastenc051ffd2013-08-01 07:35:33 -0700587/* The audio input flags are analogous to audio output flags.
588 * Currently they are used only when an AudioRecord is created,
589 * to indicate a preference to be connected to an input stream with
590 * attributes corresponding to the specified flags.
591 */
592typedef enum {
593 AUDIO_INPUT_FLAG_NONE = 0x0, // no attributes
594 AUDIO_INPUT_FLAG_FAST = 0x1, // prefer an input that supports "fast tracks"
595} audio_input_flags_t;
596
Richard Fitzgerald05529a12013-03-25 16:07:43 +0000597/* Additional information about compressed streams offloaded to
598 * hardware playback
599 * The version and size fields must be initialized by the caller by using
600 * one of the constants defined here.
601 */
602typedef struct {
603 uint16_t version; // version of the info structure
604 uint16_t size; // total size of the structure including version and size
605 uint32_t sample_rate; // sample rate in Hz
606 audio_channel_mask_t channel_mask; // channel mask
607 audio_format_t format; // audio format
608 audio_stream_type_t stream_type; // stream type
609 uint32_t bit_rate; // bit rate in bits per second
610 int64_t duration_us; // duration in microseconds, -1 if unknown
611 bool has_video; // true if stream is tied to a video stream
612 bool is_streaming; // true if streaming, false if local playback
613} audio_offload_info_t;
614
615#define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \
616 ((((maj) & 0xff) << 8) | ((min) & 0xff))
617
618#define AUDIO_OFFLOAD_INFO_VERSION_0_1 AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1)
619#define AUDIO_OFFLOAD_INFO_VERSION_CURRENT AUDIO_OFFLOAD_INFO_VERSION_0_1
620
621static const audio_offload_info_t AUDIO_INFO_INITIALIZER = {
622 version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
623 size: sizeof(audio_offload_info_t),
Mark Salyzyn48878422014-05-22 16:08:52 -0700624 sample_rate: 0,
625 channel_mask: 0,
626 format: AUDIO_FORMAT_DEFAULT,
627 stream_type: AUDIO_STREAM_VOICE_CALL,
628 bit_rate: 0,
629 duration_us: 0,
630 has_video: false,
631 is_streaming: false
Richard Fitzgerald05529a12013-03-25 16:07:43 +0000632};
633
Eric Laurent4cd05012014-02-18 12:40:36 -0800634
635/* audio hw module handle functions or structures referencing a module */
636typedef int audio_module_handle_t;
637
638/******************************
639 * Volume control
640 *****************************/
641
642/* If the audio hardware supports gain control on some audio paths,
643 * the platform can expose them in the audio_policy.conf file. The audio HAL
644 * will then implement gain control functions that will use the following data
645 * structures. */
646
647/* Type of gain control exposed by an audio port */
648#define AUDIO_GAIN_MODE_JOINT 0x1 /* supports joint channel gain control */
649#define AUDIO_GAIN_MODE_CHANNELS 0x2 /* supports separate channel gain control */
650#define AUDIO_GAIN_MODE_RAMP 0x4 /* supports gain ramps */
651
652typedef uint32_t audio_gain_mode_t;
653
654
655/* An audio_gain struct is a representation of a gain stage.
656 * A gain stage is always attached to an audio port. */
657struct audio_gain {
658 audio_gain_mode_t mode; /* e.g. AUDIO_GAIN_MODE_JOINT */
659 audio_channel_mask_t channel_mask; /* channels which gain an be controlled.
660 N/A if AUDIO_GAIN_MODE_CHANNELS is not supported */
661 int min_value; /* minimum gain value in millibels */
662 int max_value; /* maximum gain value in millibels */
663 int default_value; /* default gain value in millibels */
664 unsigned int step_value; /* gain step in millibels */
665 unsigned int min_ramp_ms; /* minimum ramp duration in ms */
666 unsigned int max_ramp_ms; /* maximum ramp duration in ms */
667};
668
669/* The gain configuration structure is used to get or set the gain values of a
670 * given port */
671struct audio_gain_config {
672 int index; /* index of the corresponding audio_gain in the
673 audio_port gains[] table */
674 audio_gain_mode_t mode; /* mode requested for this command */
675 audio_channel_mask_t channel_mask; /* channels which gain value follows.
676 N/A in joint mode */
Jungshik Jangf7e5aea2014-07-11 09:50:45 +0900677 int values[sizeof(audio_channel_mask_t) * 8]; /* gain values in millibels
678 for each channel ordered from LSb to MSb in
679 channel mask. The number of values is 1 in joint
680 mode or popcount(channel_mask) */
Eric Laurent4cd05012014-02-18 12:40:36 -0800681 unsigned int ramp_duration_ms; /* ramp duration in ms */
682};
683
684/******************************
685 * Routing control
686 *****************************/
687
688/* Types defined here are used to describe an audio source or sink at internal
689 * framework interfaces (audio policy, patch panel) or at the audio HAL.
690 * Sink and sources are grouped in a concept of “audio port” representing an
691 * audio end point at the edge of the system managed by the module exposing
692 * the interface. */
693
694/* Audio port role: either source or sink */
695typedef enum {
696 AUDIO_PORT_ROLE_NONE,
697 AUDIO_PORT_ROLE_SOURCE,
698 AUDIO_PORT_ROLE_SINK,
699} audio_port_role_t;
700
701/* Audio port type indicates if it is a session (e.g AudioTrack),
702 * a mix (e.g PlaybackThread output) or a physical device
703 * (e.g AUDIO_DEVICE_OUT_SPEAKER) */
704typedef enum {
705 AUDIO_PORT_TYPE_NONE,
706 AUDIO_PORT_TYPE_DEVICE,
707 AUDIO_PORT_TYPE_MIX,
708 AUDIO_PORT_TYPE_SESSION,
709} audio_port_type_t;
710
711/* Each port has a unique ID or handle allocated by policy manager */
712typedef int audio_port_handle_t;
713#define AUDIO_PORT_HANDLE_NONE 0
714
715
716/* maximum audio device address length */
717#define AUDIO_DEVICE_MAX_ADDRESS_LEN 32
718
719/* extension for audio port configuration structure when the audio port is a
720 * hardware device */
721struct audio_port_config_device_ext {
722 audio_module_handle_t hw_module; /* module the device is attached to */
723 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
724 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; /* device address. "" if N/A */
725};
726
727/* extension for audio port configuration structure when the audio port is a
728 * sub mix */
729struct audio_port_config_mix_ext {
730 audio_module_handle_t hw_module; /* module the stream is attached to */
731 audio_io_handle_t handle; /* I/O handle of the input/output stream */
732 union {
733 //TODO: change use case for output streams: use strategy and mixer attributes
734 audio_stream_type_t stream;
735 audio_source_t source;
736 } usecase;
737};
738
739/* extension for audio port configuration structure when the audio port is an
740 * audio session */
741struct audio_port_config_session_ext {
742 audio_session_t session; /* audio session */
743};
744
745/* Flags indicating which fields are to be considered in struct audio_port_config */
746#define AUDIO_PORT_CONFIG_SAMPLE_RATE 0x1
747#define AUDIO_PORT_CONFIG_CHANNEL_MASK 0x2
748#define AUDIO_PORT_CONFIG_FORMAT 0x4
749#define AUDIO_PORT_CONFIG_GAIN 0x8
750#define AUDIO_PORT_CONFIG_ALL (AUDIO_PORT_CONFIG_SAMPLE_RATE | \
751 AUDIO_PORT_CONFIG_CHANNEL_MASK | \
752 AUDIO_PORT_CONFIG_FORMAT | \
753 AUDIO_PORT_CONFIG_GAIN)
754
755/* audio port configuration structure used to specify a particular configuration of
756 * an audio port */
757struct audio_port_config {
758 audio_port_handle_t id; /* port unique ID */
759 audio_port_role_t role; /* sink or source */
760 audio_port_type_t type; /* device, mix ... */
761 unsigned int config_mask; /* e.g AUDIO_PORT_CONFIG_ALL */
762 unsigned int sample_rate; /* sampling rate in Hz */
763 audio_channel_mask_t channel_mask; /* channel mask if applicable */
764 audio_format_t format; /* format if applicable */
765 struct audio_gain_config gain; /* gain to apply if applicable */
766 union {
767 struct audio_port_config_device_ext device; /* device specific info */
768 struct audio_port_config_mix_ext mix; /* mix specific info */
769 struct audio_port_config_session_ext session; /* session specific info */
770 } ext;
771};
772
773
774/* max number of sampling rates in audio port */
775#define AUDIO_PORT_MAX_SAMPLING_RATES 16
776/* max number of channel masks in audio port */
777#define AUDIO_PORT_MAX_CHANNEL_MASKS 16
778/* max number of audio formats in audio port */
779#define AUDIO_PORT_MAX_FORMATS 16
780/* max number of gain controls in audio port */
781#define AUDIO_PORT_MAX_GAINS 16
782
783/* extension for audio port structure when the audio port is a hardware device */
784struct audio_port_device_ext {
785 audio_module_handle_t hw_module; /* module the device is attached to */
786 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
787 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
788};
789
790/* Latency class of the audio mix */
791typedef enum {
792 AUDIO_LATENCY_LOW,
793 AUDIO_LATENCY_NORMAL,
794} audio_mix_latency_class_t;
795
796/* extension for audio port structure when the audio port is a sub mix */
797struct audio_port_mix_ext {
798 audio_module_handle_t hw_module; /* module the stream is attached to */
799 audio_io_handle_t handle; /* I/O handle of the input.output stream */
800 audio_mix_latency_class_t latency_class; /* latency class */
801 // other attributes: routing strategies
802};
803
804/* extension for audio port structure when the audio port is an audio session */
805struct audio_port_session_ext {
806 audio_session_t session; /* audio session */
807};
808
809
810struct audio_port {
811 audio_port_handle_t id; /* port unique ID */
812 audio_port_role_t role; /* sink or source */
813 audio_port_type_t type; /* device, mix ... */
814 unsigned int num_sample_rates; /* number of sampling rates in following array */
815 unsigned int sample_rates[AUDIO_PORT_MAX_SAMPLING_RATES];
816 unsigned int num_channel_masks; /* number of channel masks in following array */
817 audio_channel_mask_t channel_masks[AUDIO_PORT_MAX_CHANNEL_MASKS];
818 unsigned int num_formats; /* number of formats in following array */
819 audio_format_t formats[AUDIO_PORT_MAX_FORMATS];
820 unsigned int num_gains; /* number of gains in following array */
821 struct audio_gain gains[AUDIO_PORT_MAX_GAINS];
822 struct audio_port_config active_config; /* current audio port configuration */
823 union {
824 struct audio_port_device_ext device;
825 struct audio_port_mix_ext mix;
826 struct audio_port_session_ext session;
827 } ext;
828};
829
830/* An audio patch represents a connection between one or more source ports and
831 * one or more sink ports. Patches are connected and disconnected by audio policy manager or by
832 * applications via framework APIs.
833 * Each patch is identified by a handle at the interface used to create that patch. For instance,
834 * when a patch is created by the audio HAL, the HAL allocates and returns a handle.
835 * This handle is unique to a given audio HAL hardware module.
836 * But the same patch receives another system wide unique handle allocated by the framework.
837 * This unique handle is used for all transactions inside the framework.
838 */
839typedef int audio_patch_handle_t;
840#define AUDIO_PATCH_HANDLE_NONE 0
841
842#define AUDIO_PATCH_PORTS_MAX 16
843
844struct audio_patch {
845 audio_patch_handle_t id; /* patch unique ID */
846 unsigned int num_sources; /* number of sources in following array */
847 struct audio_port_config sources[AUDIO_PATCH_PORTS_MAX];
848 unsigned int num_sinks; /* number of sinks in following array */
849 struct audio_port_config sinks[AUDIO_PATCH_PORTS_MAX];
850};
851
852
Dima Zavine8e4be52011-05-12 10:25:33 -0700853static inline bool audio_is_output_device(audio_devices_t device)
854{
Eric Laurenteeeee802012-08-28 14:29:07 -0700855 if (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
856 (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0))
Dima Zavine8e4be52011-05-12 10:25:33 -0700857 return true;
858 else
859 return false;
860}
861
862static inline bool audio_is_input_device(audio_devices_t device)
863{
Eric Laurenteeeee802012-08-28 14:29:07 -0700864 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
865 device &= ~AUDIO_DEVICE_BIT_IN;
866 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0))
867 return true;
868 }
869 return false;
Dima Zavine8e4be52011-05-12 10:25:33 -0700870}
871
Eric Laurenteeeee802012-08-28 14:29:07 -0700872static inline bool audio_is_output_devices(audio_devices_t device)
873{
874 return (device & AUDIO_DEVICE_BIT_IN) == 0;
875}
876
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700877static inline bool audio_is_a2dp_in_device(audio_devices_t device)
878{
879 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
880 device &= ~AUDIO_DEVICE_BIT_IN;
881 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP))
882 return true;
883 }
884 return false;
885}
Eric Laurenteeeee802012-08-28 14:29:07 -0700886
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700887static inline bool audio_is_a2dp_out_device(audio_devices_t device)
Dima Zavine8e4be52011-05-12 10:25:33 -0700888{
889 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP))
890 return true;
891 else
892 return false;
893}
894
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700895// Deprecated - use audio_is_a2dp_out_device() instead
896static inline bool audio_is_a2dp_device(audio_devices_t device)
897{
898 return audio_is_a2dp_out_device(device);
899}
900
Dima Zavine8e4be52011-05-12 10:25:33 -0700901static inline bool audio_is_bluetooth_sco_device(audio_devices_t device)
902{
Eric Laurentb5266302014-04-24 13:36:47 -0700903 if ((device & AUDIO_DEVICE_BIT_IN) == 0) {
904 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL_SCO) == 0))
905 return true;
906 } else {
907 device &= ~AUDIO_DEVICE_BIT_IN;
908 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) == 0))
909 return true;
910 }
911
912 return false;
Dima Zavine8e4be52011-05-12 10:25:33 -0700913}
914
Paul McLean00b89722014-04-18 14:29:22 -0700915static inline bool audio_is_usb_out_device(audio_devices_t device)
916{
917 return ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB));
918}
919
920static inline bool audio_is_usb_in_device(audio_devices_t device)
921{
922 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
923 device &= ~AUDIO_DEVICE_BIT_IN;
924 if (popcount(device) == 1 && (device & AUDIO_DEVICE_IN_ALL_USB) != 0)
925 return true;
926 }
927 return false;
928}
929
930/* OBSOLETE - use audio_is_usb_out_device() instead. */
Eric Laurent79f90bd2012-04-06 08:57:48 -0700931static inline bool audio_is_usb_device(audio_devices_t device)
932{
Paul McLean00b89722014-04-18 14:29:22 -0700933 return audio_is_usb_out_device(device);
Eric Laurent79f90bd2012-04-06 08:57:48 -0700934}
935
Jean-Michel Trivie11866a2012-08-16 17:53:30 -0700936static inline bool audio_is_remote_submix_device(audio_devices_t device)
937{
Jeff Brown8ecc7af2013-08-16 20:09:37 -0700938 if ((device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX
939 || (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX)
Jean-Michel Trivie11866a2012-08-16 17:53:30 -0700940 return true;
941 else
942 return false;
943}
944
Glenn Kastenf7326dc2013-07-19 14:50:21 -0700945static inline bool audio_is_input_channel(audio_channel_mask_t channel)
Dima Zavine8e4be52011-05-12 10:25:33 -0700946{
947 if ((channel & ~AUDIO_CHANNEL_IN_ALL) == 0)
Glenn Kastenf7326dc2013-07-19 14:50:21 -0700948 return channel != 0;
Dima Zavine8e4be52011-05-12 10:25:33 -0700949 else
950 return false;
951}
952
Glenn Kastenf7326dc2013-07-19 14:50:21 -0700953static inline bool audio_is_output_channel(audio_channel_mask_t channel)
Dima Zavine8e4be52011-05-12 10:25:33 -0700954{
955 if ((channel & ~AUDIO_CHANNEL_OUT_ALL) == 0)
Glenn Kastenf7326dc2013-07-19 14:50:21 -0700956 return channel != 0;
Dima Zavine8e4be52011-05-12 10:25:33 -0700957 else
958 return false;
959}
960
Andy Hunga7e8f862014-05-15 18:35:38 -0700961/* Returns the number of channels from an input channel mask,
962 * used in the context of audio input or recording.
963 */
964static inline uint32_t audio_channel_count_from_in_mask(audio_channel_mask_t channel)
965{
966 return popcount(channel & AUDIO_CHANNEL_IN_ALL);
967}
968
969/* Returns the number of channels from an output channel mask,
970 * used in the context of audio output or playback.
971 */
972static inline uint32_t audio_channel_count_from_out_mask(audio_channel_mask_t channel)
973{
974 return popcount(channel & AUDIO_CHANNEL_OUT_ALL);
975}
976
Glenn Kasten89f7ba32012-03-14 13:45:31 -0700977/* Derive an output channel mask from a channel count.
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -0800978 * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel
979 * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad,
980 * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC
981 * for continuity with stereo.
982 * Returns the matching channel mask, or 0 if the number of channels exceeds that of the
983 * configurations for which a default channel mask is defined.
984 */
Glenn Kasten89f7ba32012-03-14 13:45:31 -0700985static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count)
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -0800986{
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800987 switch (channel_count) {
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -0800988 case 1:
989 return AUDIO_CHANNEL_OUT_MONO;
990 case 2:
991 return AUDIO_CHANNEL_OUT_STEREO;
992 case 3:
993 return (AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER);
994 case 4: // 4.0
995 return AUDIO_CHANNEL_OUT_QUAD;
996 case 5: // 5.0
997 return (AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER);
998 case 6: // 5.1
999 return AUDIO_CHANNEL_OUT_5POINT1;
1000 case 7: // 6.1
1001 return (AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER);
1002 case 8:
1003 return AUDIO_CHANNEL_OUT_7POINT1;
1004 default:
1005 return 0;
1006 }
1007}
1008
Glenn Kasten89f7ba32012-03-14 13:45:31 -07001009/* Similar to above, but for input. Currently handles only mono and stereo. */
1010static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count)
1011{
1012 switch (channel_count) {
1013 case 1:
1014 return AUDIO_CHANNEL_IN_MONO;
1015 case 2:
1016 return AUDIO_CHANNEL_IN_STEREO;
1017 default:
1018 return 0;
1019 }
1020}
1021
Glenn Kasten828bf0c2012-01-12 12:34:42 -08001022static inline bool audio_is_valid_format(audio_format_t format)
Dima Zavine8e4be52011-05-12 10:25:33 -07001023{
1024 switch (format & AUDIO_FORMAT_MAIN_MASK) {
1025 case AUDIO_FORMAT_PCM:
Glenn Kasten45b95812014-03-07 12:31:03 -08001026 switch (format) {
1027 case AUDIO_FORMAT_PCM_16_BIT:
1028 case AUDIO_FORMAT_PCM_8_BIT:
1029 case AUDIO_FORMAT_PCM_32_BIT:
1030 case AUDIO_FORMAT_PCM_8_24_BIT:
1031 case AUDIO_FORMAT_PCM_FLOAT:
1032 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1033 return true;
1034 default:
Eric Laurentda382242011-06-16 21:13:43 -07001035 return false;
1036 }
Glenn Kasten45b95812014-03-07 12:31:03 -08001037 /* not reached */
Dima Zavine8e4be52011-05-12 10:25:33 -07001038 case AUDIO_FORMAT_MP3:
1039 case AUDIO_FORMAT_AMR_NB:
1040 case AUDIO_FORMAT_AMR_WB:
1041 case AUDIO_FORMAT_AAC:
1042 case AUDIO_FORMAT_HE_AAC_V1:
1043 case AUDIO_FORMAT_HE_AAC_V2:
1044 case AUDIO_FORMAT_VORBIS:
Eric Laurentce30de32014-06-10 15:39:16 -07001045 case AUDIO_FORMAT_OPUS:
1046 case AUDIO_FORMAT_AC3:
1047 case AUDIO_FORMAT_E_AC3:
Dima Zavine8e4be52011-05-12 10:25:33 -07001048 return true;
1049 default:
1050 return false;
1051 }
1052}
1053
Glenn Kasten828bf0c2012-01-12 12:34:42 -08001054static inline bool audio_is_linear_pcm(audio_format_t format)
Dima Zavine8e4be52011-05-12 10:25:33 -07001055{
Eric Laurentda382242011-06-16 21:13:43 -07001056 return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM);
Dima Zavine8e4be52011-05-12 10:25:33 -07001057}
1058
Glenn Kasten828bf0c2012-01-12 12:34:42 -08001059static inline size_t audio_bytes_per_sample(audio_format_t format)
Eric Laurentda382242011-06-16 21:13:43 -07001060{
1061 size_t size = 0;
1062
1063 switch (format) {
Jean-Michel Trivi427d2b42012-03-05 15:38:15 -08001064 case AUDIO_FORMAT_PCM_32_BIT:
1065 case AUDIO_FORMAT_PCM_8_24_BIT:
1066 size = sizeof(int32_t);
1067 break;
Andy Hung173f4992014-03-06 17:18:58 -08001068 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1069 size = sizeof(uint8_t) * 3;
1070 break;
Jean-Michel Trivi427d2b42012-03-05 15:38:15 -08001071 case AUDIO_FORMAT_PCM_16_BIT:
1072 size = sizeof(int16_t);
1073 break;
1074 case AUDIO_FORMAT_PCM_8_BIT:
1075 size = sizeof(uint8_t);
1076 break;
Glenn Kasten1c3e16f2011-12-19 09:21:48 -08001077 case AUDIO_FORMAT_PCM_FLOAT:
1078 size = sizeof(float);
1079 break;
Jean-Michel Trivi427d2b42012-03-05 15:38:15 -08001080 default:
1081 break;
Eric Laurentda382242011-06-16 21:13:43 -07001082 }
1083 return size;
1084}
Dima Zavine8e4be52011-05-12 10:25:33 -07001085
1086__END_DECLS
1087
1088#endif // ANDROID_AUDIO_CORE_H