blob: bf3dee7fb685c1246661a61c4b94562160978047 [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,
Glenn Kasten432b7c62014-04-14 17:47:03 -070055 AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user
56 * and must be routed to speaker
57 */
Dima Zavine8e4be52011-05-12 10:25:33 -070058 AUDIO_STREAM_DTMF = 8,
59 AUDIO_STREAM_TTS = 9,
60
61 AUDIO_STREAM_CNT,
62 AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1,
63} audio_stream_type_t;
64
65/* Do not change these values without updating their counterparts
Jean-Michel Trivi0d580e82014-05-21 14:43:14 -070066 * in frameworks/base/media/java/android/media/AudioAttributes.java
67 */
68typedef enum {
69 AUDIO_CONTENT_TYPE_UNKNOWN = 0,
70 AUDIO_CONTENT_TYPE_SPEECH = 1,
71 AUDIO_CONTENT_TYPE_MUSIC = 2,
72 AUDIO_CONTENT_TYPE_MOVIE = 3,
73 AUDIO_CONTENT_TYPE_SONIFICATION = 4,
74
75 AUDIO_CONTENT_TYPE_CNT,
76 AUDIO_CONTENT_TYPE_MAX = AUDIO_CONTENT_TYPE_CNT - 1,
77} audio_content_type_t;
78
79/* Do not change these values without updating their counterparts
80 * in frameworks/base/media/java/android/media/AudioAttributes.java
81 */
82typedef enum {
83 AUDIO_USAGE_UNKNOWN = 0,
84 AUDIO_USAGE_MEDIA = 1,
85 AUDIO_USAGE_VOICE_COMMUNICATION = 2,
86 AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
87 AUDIO_USAGE_ALARM = 4,
88 AUDIO_USAGE_NOTIFICATION = 5,
89 AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE = 6,
90 AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST = 7,
91 AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT = 8,
92 AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED = 9,
93 AUDIO_USAGE_NOTIFICATION_EVENT = 10,
94 AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
95 AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
96 AUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
97 AUDIO_USAGE_GAME = 14,
98
99 AUDIO_USAGE_CNT,
100 AUDIO_USAGE_MAX = AUDIO_USAGE_CNT - 1,
101} audio_usage_t;
102
103typedef uint32_t audio_flags_mask_t;
104
105/* Do not change these values without updating their counterparts
106 * in frameworks/base/media/java/android/media/AudioAttributes.java
107 */
108enum {
109 AUDIO_FLAG_AUDIBILITY_ENFORCED = 0x1,
110 AUDIO_FLAG_SECURE = 0x2,
111 AUDIO_FLAG_SCO = 0x4,
112};
113
114/* Do not change these values without updating their counterparts
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800115 * in frameworks/base/media/java/android/media/MediaRecorder.java,
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700116 * frameworks/av/services/audiopolicy/AudioPolicyService.cpp,
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800117 * and system/media/audio_effects/include/audio_effects/audio_effects_conf.h!
Dima Zavine8e4be52011-05-12 10:25:33 -0700118 */
119typedef enum {
120 AUDIO_SOURCE_DEFAULT = 0,
121 AUDIO_SOURCE_MIC = 1,
122 AUDIO_SOURCE_VOICE_UPLINK = 2,
123 AUDIO_SOURCE_VOICE_DOWNLINK = 3,
124 AUDIO_SOURCE_VOICE_CALL = 4,
125 AUDIO_SOURCE_CAMCORDER = 5,
126 AUDIO_SOURCE_VOICE_RECOGNITION = 6,
127 AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
Jean-Michel Trivie11866a2012-08-16 17:53:30 -0700128 AUDIO_SOURCE_REMOTE_SUBMIX = 8, /* Source for the mix to be presented remotely. */
129 /* An example of remote presentation is Wifi Display */
130 /* where a dongle attached to a TV can be used to */
131 /* play the mix captured by this audio source. */
Dima Zavine8e4be52011-05-12 10:25:33 -0700132 AUDIO_SOURCE_CNT,
133 AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1,
Eric Laurent04c12ca2013-09-09 10:39:54 -0700134 AUDIO_SOURCE_HOTWORD = 1999, /* A low-priority, preemptible audio source for
135 for background software hotword detection.
136 Same tuning as AUDIO_SOURCE_VOICE_RECOGNITION.
137 Used only internally to the framework. Not exposed
138 at the audio HAL. */
Dima Zavine8e4be52011-05-12 10:25:33 -0700139} audio_source_t;
140
Jean-Michel Trivi0d580e82014-05-21 14:43:14 -0700141/* Audio attributes */
142#define AUDIO_ATTRIBUTES_TAGS_MAX_SIZE 256
143typedef struct {
144 audio_content_type_t content_type;
145 audio_usage_t usage;
146 audio_source_t source;
147 audio_flags_mask_t flags;
148 char tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE]; /* UTF8 */
149} audio_attributes_t;
150
Dima Zavine8e4be52011-05-12 10:25:33 -0700151/* special audio session values
152 * (XXX: should this be living in the audio effects land?)
153 */
154typedef enum {
155 /* session for effects attached to a particular output stream
156 * (value must be less than 0)
157 */
158 AUDIO_SESSION_OUTPUT_STAGE = -1,
159
160 /* session for effects applied to output mix. These effects can
161 * be moved by audio policy manager to another output stream
162 * (value must be 0)
163 */
164 AUDIO_SESSION_OUTPUT_MIX = 0,
Glenn Kastenb4f2b4e2012-06-25 14:57:36 -0700165
166 /* application does not specify an explicit session ID to be used,
167 * and requests a new session ID to be allocated
168 * TODO use unique values for AUDIO_SESSION_OUTPUT_MIX and AUDIO_SESSION_ALLOCATE,
169 * after all uses have been updated from 0 to the appropriate symbol, and have been tested.
170 */
171 AUDIO_SESSION_ALLOCATE = 0,
Dima Zavine8e4be52011-05-12 10:25:33 -0700172} audio_session_t;
173
174/* Audio sub formats (see enum audio_format). */
175
176/* PCM sub formats */
177typedef enum {
Glenn Kastenc0a51092014-01-31 07:51:17 -0800178 /* All of these are in native byte order */
Eric Laurent9714b272011-05-26 13:52:47 -0700179 AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */
180 AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */
181 AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */
182 AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800183 AUDIO_FORMAT_PCM_SUB_FLOAT = 0x5, /* PCM single-precision floating point */
Glenn Kastenc0a51092014-01-31 07:51:17 -0800184 AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED = 0x6, /* PCM signed .23 fixed point packed in 3 bytes */
Dima Zavine8e4be52011-05-12 10:25:33 -0700185} audio_format_pcm_sub_fmt_t;
186
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800187/* The audio_format_*_sub_fmt_t declarations are not currently used */
188
Dima Zavine8e4be52011-05-12 10:25:33 -0700189/* MP3 sub format field definition : can use 11 LSBs in the same way as MP3
190 * frame header to specify bit rate, stereo mode, version...
191 */
192typedef enum {
193 AUDIO_FORMAT_MP3_SUB_NONE = 0x0,
194} audio_format_mp3_sub_fmt_t;
195
196/* AMR NB/WB sub format field definition: specify frame block interleaving,
197 * bandwidth efficient or octet aligned, encoding mode for recording...
198 */
199typedef enum {
200 AUDIO_FORMAT_AMR_SUB_NONE = 0x0,
201} audio_format_amr_sub_fmt_t;
202
203/* AAC sub format field definition: specify profile or bitrate for recording... */
204typedef enum {
aarti jadhav-gaikwad923e7402014-06-18 15:23:09 +0530205 AUDIO_FORMAT_AAC_SUB_MAIN = 0x1,
206 AUDIO_FORMAT_AAC_SUB_LC = 0x2,
207 AUDIO_FORMAT_AAC_SUB_SSR = 0x4,
208 AUDIO_FORMAT_AAC_SUB_LTP = 0x8,
209 AUDIO_FORMAT_AAC_SUB_HE_V1 = 0x10,
210 AUDIO_FORMAT_AAC_SUB_SCALABLE = 0x20,
211 AUDIO_FORMAT_AAC_SUB_ERLC = 0x40,
212 AUDIO_FORMAT_AAC_SUB_LD = 0x80,
213 AUDIO_FORMAT_AAC_SUB_HE_V2 = 0x100,
214 AUDIO_FORMAT_AAC_SUB_ELD = 0x200,
Dima Zavine8e4be52011-05-12 10:25:33 -0700215} audio_format_aac_sub_fmt_t;
216
217/* VORBIS sub format field definition: specify quality for recording... */
218typedef enum {
219 AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0,
220} audio_format_vorbis_sub_fmt_t;
221
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800222/* Audio format consists of a main format field (upper 8 bits) and a sub format
Dima Zavine8e4be52011-05-12 10:25:33 -0700223 * field (lower 24 bits).
224 *
225 * The main format indicates the main codec type. The sub format field
226 * indicates options and parameters for each format. The sub format is mainly
227 * used for record to indicate for instance the requested bitrate or profile.
228 * It can also be used for certain formats to give informations not present in
229 * the encoded audio stream (e.g. octet alignement for AMR).
230 */
231typedef enum {
232 AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL,
233 AUDIO_FORMAT_DEFAULT = 0,
234 AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */
235 AUDIO_FORMAT_MP3 = 0x01000000UL,
236 AUDIO_FORMAT_AMR_NB = 0x02000000UL,
237 AUDIO_FORMAT_AMR_WB = 0x03000000UL,
238 AUDIO_FORMAT_AAC = 0x04000000UL,
aarti jadhav-gaikwad923e7402014-06-18 15:23:09 +0530239 AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V1*/
240 AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V2*/
Dima Zavine8e4be52011-05-12 10:25:33 -0700241 AUDIO_FORMAT_VORBIS = 0x07000000UL,
Vignesh Venkatasubramanian76edb1c2014-01-29 09:47:56 -0800242 AUDIO_FORMAT_OPUS = 0x08000000UL,
Eric Laurentce30de32014-06-10 15:39:16 -0700243 AUDIO_FORMAT_AC3 = 0x09000000UL,
244 AUDIO_FORMAT_E_AC3 = 0x0A000000UL,
Dima Zavine8e4be52011-05-12 10:25:33 -0700245 AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL,
246 AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL,
247
248 /* Aliases */
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800249 /* note != AudioFormat.ENCODING_PCM_16BIT */
Dima Zavine8e4be52011-05-12 10:25:33 -0700250 AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM |
251 AUDIO_FORMAT_PCM_SUB_16_BIT),
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800252 /* note != AudioFormat.ENCODING_PCM_8BIT */
Dima Zavine8e4be52011-05-12 10:25:33 -0700253 AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM |
254 AUDIO_FORMAT_PCM_SUB_8_BIT),
Eric Laurent9714b272011-05-26 13:52:47 -0700255 AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM |
256 AUDIO_FORMAT_PCM_SUB_32_BIT),
257 AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM |
258 AUDIO_FORMAT_PCM_SUB_8_24_BIT),
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800259 AUDIO_FORMAT_PCM_FLOAT = (AUDIO_FORMAT_PCM |
260 AUDIO_FORMAT_PCM_SUB_FLOAT),
Glenn Kastenc0a51092014-01-31 07:51:17 -0800261 AUDIO_FORMAT_PCM_24_BIT_PACKED = (AUDIO_FORMAT_PCM |
262 AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED),
aarti jadhav-gaikwad923e7402014-06-18 15:23:09 +0530263 AUDIO_FORMAT_AAC_MAIN = (AUDIO_FORMAT_AAC |
264 AUDIO_FORMAT_AAC_SUB_MAIN),
265 AUDIO_FORMAT_AAC_LC = (AUDIO_FORMAT_AAC |
266 AUDIO_FORMAT_AAC_SUB_LC),
267 AUDIO_FORMAT_AAC_SSR = (AUDIO_FORMAT_AAC |
268 AUDIO_FORMAT_AAC_SUB_SSR),
269 AUDIO_FORMAT_AAC_LTP = (AUDIO_FORMAT_AAC |
270 AUDIO_FORMAT_AAC_SUB_LTP),
271 AUDIO_FORMAT_AAC_HE_V1 = (AUDIO_FORMAT_AAC |
272 AUDIO_FORMAT_AAC_SUB_HE_V1),
273 AUDIO_FORMAT_AAC_SCALABLE = (AUDIO_FORMAT_AAC |
274 AUDIO_FORMAT_AAC_SUB_SCALABLE),
275 AUDIO_FORMAT_AAC_ERLC = (AUDIO_FORMAT_AAC |
276 AUDIO_FORMAT_AAC_SUB_ERLC),
277 AUDIO_FORMAT_AAC_LD = (AUDIO_FORMAT_AAC |
278 AUDIO_FORMAT_AAC_SUB_LD),
279 AUDIO_FORMAT_AAC_HE_V2 = (AUDIO_FORMAT_AAC |
280 AUDIO_FORMAT_AAC_SUB_HE_V2),
281 AUDIO_FORMAT_AAC_ELD = (AUDIO_FORMAT_AAC |
282 AUDIO_FORMAT_AAC_SUB_ELD),
Dima Zavine8e4be52011-05-12 10:25:33 -0700283} audio_format_t;
284
Glenn Kasten432b7c62014-04-14 17:47:03 -0700285/* For the channel mask for position assignment representation */
Glenn Kasten16a7a042012-07-03 15:21:05 -0700286enum {
Glenn Kasten432b7c62014-04-14 17:47:03 -0700287
288/* These can be a complete audio_channel_mask_t. */
289
Eric Laurent4cd05012014-02-18 12:40:36 -0800290 AUDIO_CHANNEL_NONE = 0x0,
Glenn Kasten432b7c62014-04-14 17:47:03 -0700291 AUDIO_CHANNEL_INVALID = 0xC0000000,
292
293/* These can be the bits portion of an audio_channel_mask_t
294 * with representation AUDIO_CHANNEL_REPRESENTATION_POSITION.
295 * Using these bits as a complete audio_channel_mask_t is deprecated.
296 */
297
Dima Zavine8e4be52011-05-12 10:25:33 -0700298 /* output channels */
Jean-Michel Trivi6d4f3972011-07-25 16:19:07 -0700299 AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x1,
300 AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x2,
301 AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x4,
302 AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x8,
303 AUDIO_CHANNEL_OUT_BACK_LEFT = 0x10,
304 AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x20,
305 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40,
306 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80,
307 AUDIO_CHANNEL_OUT_BACK_CENTER = 0x100,
308 AUDIO_CHANNEL_OUT_SIDE_LEFT = 0x200,
309 AUDIO_CHANNEL_OUT_SIDE_RIGHT = 0x400,
310 AUDIO_CHANNEL_OUT_TOP_CENTER = 0x800,
311 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT = 0x1000,
312 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER = 0x2000,
313 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT = 0x4000,
314 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT = 0x8000,
315 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER = 0x10000,
316 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT = 0x20000,
Dima Zavine8e4be52011-05-12 10:25:33 -0700317
Glenn Kasten432b7c62014-04-14 17:47:03 -0700318/* TODO: should these be considered complete channel masks, or only bits? */
319
Dima Zavine8e4be52011-05-12 10:25:33 -0700320 AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT,
321 AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
322 AUDIO_CHANNEL_OUT_FRONT_RIGHT),
323 AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
324 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
325 AUDIO_CHANNEL_OUT_BACK_LEFT |
326 AUDIO_CHANNEL_OUT_BACK_RIGHT),
Glenn Kastenb8d59392014-04-29 08:41:46 -0700327 AUDIO_CHANNEL_OUT_QUAD_BACK = AUDIO_CHANNEL_OUT_QUAD,
Glenn Kastenee7c17b2014-04-29 08:43:19 -0700328 /* like AUDIO_CHANNEL_OUT_QUAD_BACK with *_SIDE_* instead of *_BACK_* */
329 AUDIO_CHANNEL_OUT_QUAD_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
330 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
331 AUDIO_CHANNEL_OUT_SIDE_LEFT |
332 AUDIO_CHANNEL_OUT_SIDE_RIGHT),
Dima Zavine8e4be52011-05-12 10:25:33 -0700333 AUDIO_CHANNEL_OUT_5POINT1 = (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),
Glenn Kastenb8d59392014-04-29 08:41:46 -0700339 AUDIO_CHANNEL_OUT_5POINT1_BACK = AUDIO_CHANNEL_OUT_5POINT1,
Glenn Kastenee7c17b2014-04-29 08:43:19 -0700340 /* like AUDIO_CHANNEL_OUT_5POINT1_BACK with *_SIDE_* instead of *_BACK_* */
341 AUDIO_CHANNEL_OUT_5POINT1_SIDE = (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_SIDE_LEFT |
346 AUDIO_CHANNEL_OUT_SIDE_RIGHT),
Jean-Michel Trivi33fad992011-07-24 16:31:03 -0700347 // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1
Dima Zavine8e4be52011-05-12 10:25:33 -0700348 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
349 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
350 AUDIO_CHANNEL_OUT_FRONT_CENTER |
351 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
352 AUDIO_CHANNEL_OUT_BACK_LEFT |
353 AUDIO_CHANNEL_OUT_BACK_RIGHT |
Jean-Michel Trivi33fad992011-07-24 16:31:03 -0700354 AUDIO_CHANNEL_OUT_SIDE_LEFT |
355 AUDIO_CHANNEL_OUT_SIDE_RIGHT),
Dima Zavine8e4be52011-05-12 10:25:33 -0700356 AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
357 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
358 AUDIO_CHANNEL_OUT_FRONT_CENTER |
359 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
360 AUDIO_CHANNEL_OUT_BACK_LEFT |
361 AUDIO_CHANNEL_OUT_BACK_RIGHT |
362 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
363 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
Jean-Michel Trivi33fad992011-07-24 16:31:03 -0700364 AUDIO_CHANNEL_OUT_BACK_CENTER|
365 AUDIO_CHANNEL_OUT_SIDE_LEFT|
366 AUDIO_CHANNEL_OUT_SIDE_RIGHT|
367 AUDIO_CHANNEL_OUT_TOP_CENTER|
368 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT|
369 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER|
370 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT|
371 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT|
372 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER|
373 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT),
Dima Zavine8e4be52011-05-12 10:25:33 -0700374
Glenn Kasten432b7c62014-04-14 17:47:03 -0700375/* These are bits only, not complete values */
376
Dima Zavine8e4be52011-05-12 10:25:33 -0700377 /* input channels */
378 AUDIO_CHANNEL_IN_LEFT = 0x4,
379 AUDIO_CHANNEL_IN_RIGHT = 0x8,
380 AUDIO_CHANNEL_IN_FRONT = 0x10,
381 AUDIO_CHANNEL_IN_BACK = 0x20,
382 AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40,
383 AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80,
384 AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100,
385 AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200,
386 AUDIO_CHANNEL_IN_PRESSURE = 0x400,
387 AUDIO_CHANNEL_IN_X_AXIS = 0x800,
388 AUDIO_CHANNEL_IN_Y_AXIS = 0x1000,
389 AUDIO_CHANNEL_IN_Z_AXIS = 0x2000,
390 AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000,
391 AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000,
392
Glenn Kasten432b7c62014-04-14 17:47:03 -0700393/* TODO: should these be considered complete channel masks, or only bits, or deprecated? */
394
Dima Zavine8e4be52011-05-12 10:25:33 -0700395 AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT,
396 AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT),
Eric Laurent6c70cee2013-01-17 17:31:49 -0800397 AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK),
Dima Zavine8e4be52011-05-12 10:25:33 -0700398 AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT |
399 AUDIO_CHANNEL_IN_RIGHT |
400 AUDIO_CHANNEL_IN_FRONT |
401 AUDIO_CHANNEL_IN_BACK|
402 AUDIO_CHANNEL_IN_LEFT_PROCESSED |
403 AUDIO_CHANNEL_IN_RIGHT_PROCESSED |
404 AUDIO_CHANNEL_IN_FRONT_PROCESSED |
405 AUDIO_CHANNEL_IN_BACK_PROCESSED|
406 AUDIO_CHANNEL_IN_PRESSURE |
407 AUDIO_CHANNEL_IN_X_AXIS |
408 AUDIO_CHANNEL_IN_Y_AXIS |
409 AUDIO_CHANNEL_IN_Z_AXIS |
410 AUDIO_CHANNEL_IN_VOICE_UPLINK |
411 AUDIO_CHANNEL_IN_VOICE_DNLINK),
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -0800412};
413
Glenn Kastenee7c17b2014-04-29 08:43:19 -0700414/* A channel mask per se only defines the presence or absence of a channel, not the order.
415 * But see AUDIO_INTERLEAVE_* below for the platform convention of order.
Glenn Kasten432b7c62014-04-14 17:47:03 -0700416 *
417 * audio_channel_mask_t is an opaque type and its internal layout should not
418 * be assumed as it may change in the future.
419 * Instead, always use the functions declared in this header to examine.
420 *
421 * These are the current representations:
422 *
423 * AUDIO_CHANNEL_REPRESENTATION_POSITION
424 * is a channel mask representation for position assignment.
425 * Each low-order bit corresponds to the spatial position of a transducer (output),
426 * or interpretation of channel (input).
427 * The user of a channel mask needs to know the context of whether it is for output or input.
428 * The constants AUDIO_CHANNEL_OUT_* or AUDIO_CHANNEL_IN_* apply to the bits portion.
429 * It is not permitted for no bits to be set.
430 *
431 * AUDIO_CHANNEL_REPRESENTATION_INDEX
432 * is a channel mask representation for index assignment.
433 * Each low-order bit corresponds to a selected channel.
434 * There is no platform interpretation of the various bits.
435 * There is no concept of output or input.
436 * It is not permitted for no bits to be set.
437 *
438 * All other representations are reserved for future use.
439 *
440 * Warning: current representation distinguishes between input and output, but this will not the be
441 * case in future revisions of the platform. Wherever there is an ambiguity between input and output
442 * that is currently resolved by checking the channel mask, the implementer should look for ways to
443 * fix it with additional information outside of the mask.
Glenn Kastenee7c17b2014-04-29 08:43:19 -0700444 */
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -0800445typedef uint32_t audio_channel_mask_t;
Dima Zavine8e4be52011-05-12 10:25:33 -0700446
Glenn Kasten432b7c62014-04-14 17:47:03 -0700447/* Maximum number of channels for all representations */
448#define AUDIO_CHANNEL_COUNT_MAX 30
449
450/* log(2) of maximum number of representations, not part of public API */
451#define AUDIO_CHANNEL_REPRESENTATION_LOG2 2
452
453/* Representations */
454typedef enum {
455 AUDIO_CHANNEL_REPRESENTATION_POSITION = 0, // must be zero for compatibility
456 // 1 is reserved for future use
457 AUDIO_CHANNEL_REPRESENTATION_INDEX = 2,
458 // 3 is reserved for future use
459} audio_channel_representation_t;
460
461/* The return value is undefined if the channel mask is invalid. */
462static inline uint32_t audio_channel_mask_get_bits(audio_channel_mask_t channel)
463{
464 return channel & ((1 << AUDIO_CHANNEL_COUNT_MAX) - 1);
465}
466
467/* The return value is undefined if the channel mask is invalid. */
468static inline audio_channel_representation_t audio_channel_mask_get_representation(
469 audio_channel_mask_t channel)
470{
471 // The right shift should be sufficient, but also "and" for safety in case mask is not 32 bits
472 return (audio_channel_representation_t)
473 ((channel >> AUDIO_CHANNEL_COUNT_MAX) & ((1 << AUDIO_CHANNEL_REPRESENTATION_LOG2) - 1));
474}
475
476/* Returns true if the channel mask is valid,
477 * or returns false for AUDIO_CHANNEL_NONE, AUDIO_CHANNEL_INVALID, and other invalid values.
478 * This function is unable to determine whether a channel mask for position assignment
479 * is invalid because an output mask has an invalid output bit set,
480 * or because an input mask has an invalid input bit set.
481 * All other APIs that take a channel mask assume that it is valid.
482 */
483static inline bool audio_channel_mask_is_valid(audio_channel_mask_t channel)
484{
485 uint32_t bits = audio_channel_mask_get_bits(channel);
486 audio_channel_representation_t representation = audio_channel_mask_get_representation(channel);
487 switch (representation) {
488 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
489 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
490 break;
491 default:
492 bits = 0;
493 break;
494 }
495 return bits != 0;
496}
497
498/* Not part of public API */
499static inline audio_channel_mask_t audio_channel_mask_from_representation_and_bits(
500 audio_channel_representation_t representation, uint32_t bits)
501{
502 return (audio_channel_mask_t) ((representation << AUDIO_CHANNEL_COUNT_MAX) | bits);
503}
504
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800505/* Expresses the convention when stereo audio samples are stored interleaved
506 * in an array. This should improve readability by allowing code to use
507 * symbolic indices instead of hard-coded [0] and [1].
Glenn Kastenee7c17b2014-04-29 08:43:19 -0700508 *
509 * For multi-channel beyond stereo, the platform convention is that channels
510 * are interleaved in order from least significant channel mask bit
511 * to most significant channel mask bit, with unused bits skipped.
512 * Any exceptions to this convention will be noted at the appropriate API.
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800513 */
514enum {
515 AUDIO_INTERLEAVE_LEFT = 0,
516 AUDIO_INTERLEAVE_RIGHT = 1,
517};
518
Dima Zavine8e4be52011-05-12 10:25:33 -0700519typedef enum {
520 AUDIO_MODE_INVALID = -2,
521 AUDIO_MODE_CURRENT = -1,
522 AUDIO_MODE_NORMAL = 0,
523 AUDIO_MODE_RINGTONE = 1,
524 AUDIO_MODE_IN_CALL = 2,
525 AUDIO_MODE_IN_COMMUNICATION = 3,
526
527 AUDIO_MODE_CNT,
528 AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1,
529} audio_mode_t;
530
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800531/* This enum is deprecated */
Dima Zavine8e4be52011-05-12 10:25:33 -0700532typedef enum {
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800533 AUDIO_IN_ACOUSTICS_NONE = 0,
Dima Zavine8e4be52011-05-12 10:25:33 -0700534 AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001,
535 AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0,
536 AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002,
537 AUDIO_IN_ACOUSTICS_NS_DISABLE = 0,
538 AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004,
539 AUDIO_IN_ACOUSTICS_TX_DISABLE = 0,
540} audio_in_acoustics_t;
541
Glenn Kasten16a7a042012-07-03 15:21:05 -0700542enum {
Eric Laurenteeeee802012-08-28 14:29:07 -0700543 AUDIO_DEVICE_NONE = 0x0,
544 /* reserved bits */
545 AUDIO_DEVICE_BIT_IN = 0x80000000,
546 AUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
Dima Zavine8e4be52011-05-12 10:25:33 -0700547 /* output devices */
548 AUDIO_DEVICE_OUT_EARPIECE = 0x1,
549 AUDIO_DEVICE_OUT_SPEAKER = 0x2,
550 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
551 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
552 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10,
553 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
554 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
555 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
556 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
557 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
558 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400,
Eric Laurentabcb9992014-05-16 15:11:08 -0700559 AUDIO_DEVICE_OUT_HDMI = AUDIO_DEVICE_OUT_AUX_DIGITAL,
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800560 /* uses an analog connection (multiplexed over the USB connector pins for instance) */
Dima Zavine8e4be52011-05-12 10:25:33 -0700561 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
562 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800563 /* USB accessory mode: your Android device is a USB device and the dock is a USB host */
Eric Laurent79f90bd2012-04-06 08:57:48 -0700564 AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000,
Glenn Kasten1c3e16f2011-12-19 09:21:48 -0800565 /* USB host mode: your Android device is a USB host and the dock is a USB device */
Eric Laurent79f90bd2012-04-06 08:57:48 -0700566 AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000,
Eric Laurenteeeee802012-08-28 14:29:07 -0700567 AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000,
Eric Laurentabcb9992014-05-16 15:11:08 -0700568 /* Telephony voice TX path */
569 AUDIO_DEVICE_OUT_TELEPHONY_TX = 0x10000,
570 /* Analog jack with line impedance detected */
571 AUDIO_DEVICE_OUT_LINE = 0x20000,
572 /* HDMI Audio Return Channel */
573 AUDIO_DEVICE_OUT_HDMI_ARC = 0x40000,
574 /* S/PDIF out */
575 AUDIO_DEVICE_OUT_SPDIF = 0x80000,
576 /* FM transmitter out */
577 AUDIO_DEVICE_OUT_FM = 0x100000,
Jungshik Jangcadd5bb2014-07-15 19:40:32 +0900578 /* Line out for av devices */
579 AUDIO_DEVICE_OUT_AUX_LINE = 0x200000,
Eric Laurenteeeee802012-08-28 14:29:07 -0700580 AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT,
Dima Zavine8e4be52011-05-12 10:25:33 -0700581 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE |
582 AUDIO_DEVICE_OUT_SPEAKER |
583 AUDIO_DEVICE_OUT_WIRED_HEADSET |
584 AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
585 AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
586 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
587 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
588 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
589 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
590 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
Eric Laurentabcb9992014-05-16 15:11:08 -0700591 AUDIO_DEVICE_OUT_HDMI |
Dima Zavine8e4be52011-05-12 10:25:33 -0700592 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
593 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
Eric Laurent79f90bd2012-04-06 08:57:48 -0700594 AUDIO_DEVICE_OUT_USB_ACCESSORY |
595 AUDIO_DEVICE_OUT_USB_DEVICE |
Eric Laurenteeeee802012-08-28 14:29:07 -0700596 AUDIO_DEVICE_OUT_REMOTE_SUBMIX |
Eric Laurentabcb9992014-05-16 15:11:08 -0700597 AUDIO_DEVICE_OUT_TELEPHONY_TX |
598 AUDIO_DEVICE_OUT_LINE |
599 AUDIO_DEVICE_OUT_HDMI_ARC |
600 AUDIO_DEVICE_OUT_SPDIF |
601 AUDIO_DEVICE_OUT_FM |
Jungshik Jangcadd5bb2014-07-15 19:40:32 +0900602 AUDIO_DEVICE_OUT_AUX_LINE |
Dima Zavine8e4be52011-05-12 10:25:33 -0700603 AUDIO_DEVICE_OUT_DEFAULT),
604 AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
605 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
606 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
607 AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
608 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
609 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
Eric Laurent79f90bd2012-04-06 08:57:48 -0700610 AUDIO_DEVICE_OUT_ALL_USB = (AUDIO_DEVICE_OUT_USB_ACCESSORY |
611 AUDIO_DEVICE_OUT_USB_DEVICE),
Dima Zavine8e4be52011-05-12 10:25:33 -0700612
613 /* input devices */
Eric Laurenteeeee802012-08-28 14:29:07 -0700614 AUDIO_DEVICE_IN_COMMUNICATION = AUDIO_DEVICE_BIT_IN | 0x1,
615 AUDIO_DEVICE_IN_AMBIENT = AUDIO_DEVICE_BIT_IN | 0x2,
616 AUDIO_DEVICE_IN_BUILTIN_MIC = AUDIO_DEVICE_BIT_IN | 0x4,
617 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8,
618 AUDIO_DEVICE_IN_WIRED_HEADSET = AUDIO_DEVICE_BIT_IN | 0x10,
619 AUDIO_DEVICE_IN_AUX_DIGITAL = AUDIO_DEVICE_BIT_IN | 0x20,
Eric Laurentabcb9992014-05-16 15:11:08 -0700620 AUDIO_DEVICE_IN_HDMI = AUDIO_DEVICE_IN_AUX_DIGITAL,
621 /* Telephony voice RX path */
Eric Laurenteeeee802012-08-28 14:29:07 -0700622 AUDIO_DEVICE_IN_VOICE_CALL = AUDIO_DEVICE_BIT_IN | 0x40,
Eric Laurentabcb9992014-05-16 15:11:08 -0700623 AUDIO_DEVICE_IN_TELEPHONY_RX = AUDIO_DEVICE_IN_VOICE_CALL,
Eric Laurenteeeee802012-08-28 14:29:07 -0700624 AUDIO_DEVICE_IN_BACK_MIC = AUDIO_DEVICE_BIT_IN | 0x80,
625 AUDIO_DEVICE_IN_REMOTE_SUBMIX = AUDIO_DEVICE_BIT_IN | 0x100,
626 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x200,
627 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x400,
628 AUDIO_DEVICE_IN_USB_ACCESSORY = AUDIO_DEVICE_BIT_IN | 0x800,
629 AUDIO_DEVICE_IN_USB_DEVICE = AUDIO_DEVICE_BIT_IN | 0x1000,
Eric Laurentabcb9992014-05-16 15:11:08 -0700630 /* FM tuner input */
631 AUDIO_DEVICE_IN_FM_TUNER = AUDIO_DEVICE_BIT_IN | 0x2000,
632 /* TV tuner input */
633 AUDIO_DEVICE_IN_TV_TUNER = AUDIO_DEVICE_BIT_IN | 0x4000,
634 /* Analog jack with line impedance detected */
635 AUDIO_DEVICE_IN_LINE = AUDIO_DEVICE_BIT_IN | 0x8000,
636 /* S/PDIF in */
637 AUDIO_DEVICE_IN_SPDIF = AUDIO_DEVICE_BIT_IN | 0x10000,
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700638 AUDIO_DEVICE_IN_BLUETOOTH_A2DP = AUDIO_DEVICE_BIT_IN | 0x20000,
Terry Heob63dd8a2014-06-27 15:25:56 +0900639 AUDIO_DEVICE_IN_LOOPBACK = AUDIO_DEVICE_BIT_IN | 0x40000,
Eric Laurenteeeee802012-08-28 14:29:07 -0700640 AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT,
Dima Zavine8e4be52011-05-12 10:25:33 -0700641
642 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION |
643 AUDIO_DEVICE_IN_AMBIENT |
644 AUDIO_DEVICE_IN_BUILTIN_MIC |
645 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET |
646 AUDIO_DEVICE_IN_WIRED_HEADSET |
Eric Laurentabcb9992014-05-16 15:11:08 -0700647 AUDIO_DEVICE_IN_HDMI |
648 AUDIO_DEVICE_IN_TELEPHONY_RX |
Dima Zavine8e4be52011-05-12 10:25:33 -0700649 AUDIO_DEVICE_IN_BACK_MIC |
Eric Laurenteeeee802012-08-28 14:29:07 -0700650 AUDIO_DEVICE_IN_REMOTE_SUBMIX |
651 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET |
652 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET |
653 AUDIO_DEVICE_IN_USB_ACCESSORY |
654 AUDIO_DEVICE_IN_USB_DEVICE |
Eric Laurentabcb9992014-05-16 15:11:08 -0700655 AUDIO_DEVICE_IN_FM_TUNER |
656 AUDIO_DEVICE_IN_TV_TUNER |
657 AUDIO_DEVICE_IN_LINE |
658 AUDIO_DEVICE_IN_SPDIF |
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700659 AUDIO_DEVICE_IN_BLUETOOTH_A2DP |
Terry Heob63dd8a2014-06-27 15:25:56 +0900660 AUDIO_DEVICE_IN_LOOPBACK |
Dima Zavine8e4be52011-05-12 10:25:33 -0700661 AUDIO_DEVICE_IN_DEFAULT),
662 AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
Paul McLean00b89722014-04-18 14:29:22 -0700663 AUDIO_DEVICE_IN_ALL_USB = (AUDIO_DEVICE_IN_USB_ACCESSORY |
664 AUDIO_DEVICE_IN_USB_DEVICE),
Glenn Kasten16a7a042012-07-03 15:21:05 -0700665};
666
667typedef uint32_t audio_devices_t;
Dima Zavine8e4be52011-05-12 10:25:33 -0700668
Eric Laurent545ab462012-04-16 18:05:39 -0700669/* the audio output flags serve two purposes:
670 * - when an AudioTrack is created they indicate a "wish" to be connected to an
671 * output stream with attributes corresponding to the specified flags
672 * - when present in an output profile descriptor listed for a particular audio
673 * hardware module, they indicate that an output stream can be opened that
674 * supports the attributes indicated by the flags.
675 * the audio policy manager will try to match the flags in the request
676 * (when getOuput() is called) to an available output stream.
677 */
678typedef enum {
Eric Laurent9aec3622012-04-13 16:52:58 -0700679 AUDIO_OUTPUT_FLAG_NONE = 0x0, // no attributes
680 AUDIO_OUTPUT_FLAG_DIRECT = 0x1, // this output directly connects a track
681 // to one output stream: no software mixer
682 AUDIO_OUTPUT_FLAG_PRIMARY = 0x2, // this output is the primary output of
683 // the device. It is unique and must be
684 // present. It is opened by default and
685 // receives routing, audio mode and volume
686 // controls related to voice calls.
687 AUDIO_OUTPUT_FLAG_FAST = 0x4, // output supports "fast tracks",
688 // defined elsewhere
Richard Fitzgerald05529a12013-03-25 16:07:43 +0000689 AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8, // use deep audio buffers
690 AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD = 0x10, // offload playback of compressed
691 // streams to hardware codec
692 AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20 // use non-blocking write
Eric Laurent545ab462012-04-16 18:05:39 -0700693} audio_output_flags_t;
694
Glenn Kastenc051ffd2013-08-01 07:35:33 -0700695/* The audio input flags are analogous to audio output flags.
696 * Currently they are used only when an AudioRecord is created,
697 * to indicate a preference to be connected to an input stream with
698 * attributes corresponding to the specified flags.
699 */
700typedef enum {
701 AUDIO_INPUT_FLAG_NONE = 0x0, // no attributes
702 AUDIO_INPUT_FLAG_FAST = 0x1, // prefer an input that supports "fast tracks"
703} audio_input_flags_t;
704
Richard Fitzgerald05529a12013-03-25 16:07:43 +0000705/* Additional information about compressed streams offloaded to
706 * hardware playback
707 * The version and size fields must be initialized by the caller by using
708 * one of the constants defined here.
709 */
710typedef struct {
711 uint16_t version; // version of the info structure
712 uint16_t size; // total size of the structure including version and size
713 uint32_t sample_rate; // sample rate in Hz
714 audio_channel_mask_t channel_mask; // channel mask
715 audio_format_t format; // audio format
716 audio_stream_type_t stream_type; // stream type
717 uint32_t bit_rate; // bit rate in bits per second
718 int64_t duration_us; // duration in microseconds, -1 if unknown
719 bool has_video; // true if stream is tied to a video stream
720 bool is_streaming; // true if streaming, false if local playback
721} audio_offload_info_t;
722
723#define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \
724 ((((maj) & 0xff) << 8) | ((min) & 0xff))
725
726#define AUDIO_OFFLOAD_INFO_VERSION_0_1 AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1)
727#define AUDIO_OFFLOAD_INFO_VERSION_CURRENT AUDIO_OFFLOAD_INFO_VERSION_0_1
728
729static const audio_offload_info_t AUDIO_INFO_INITIALIZER = {
730 version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
731 size: sizeof(audio_offload_info_t),
Mark Salyzyn48878422014-05-22 16:08:52 -0700732 sample_rate: 0,
733 channel_mask: 0,
734 format: AUDIO_FORMAT_DEFAULT,
735 stream_type: AUDIO_STREAM_VOICE_CALL,
736 bit_rate: 0,
737 duration_us: 0,
738 has_video: false,
739 is_streaming: false
Richard Fitzgerald05529a12013-03-25 16:07:43 +0000740};
741
Eric Laurent4cd05012014-02-18 12:40:36 -0800742
743/* audio hw module handle functions or structures referencing a module */
744typedef int audio_module_handle_t;
745
746/******************************
747 * Volume control
748 *****************************/
749
750/* If the audio hardware supports gain control on some audio paths,
751 * the platform can expose them in the audio_policy.conf file. The audio HAL
752 * will then implement gain control functions that will use the following data
753 * structures. */
754
755/* Type of gain control exposed by an audio port */
756#define AUDIO_GAIN_MODE_JOINT 0x1 /* supports joint channel gain control */
757#define AUDIO_GAIN_MODE_CHANNELS 0x2 /* supports separate channel gain control */
758#define AUDIO_GAIN_MODE_RAMP 0x4 /* supports gain ramps */
759
760typedef uint32_t audio_gain_mode_t;
761
762
763/* An audio_gain struct is a representation of a gain stage.
764 * A gain stage is always attached to an audio port. */
765struct audio_gain {
766 audio_gain_mode_t mode; /* e.g. AUDIO_GAIN_MODE_JOINT */
767 audio_channel_mask_t channel_mask; /* channels which gain an be controlled.
768 N/A if AUDIO_GAIN_MODE_CHANNELS is not supported */
769 int min_value; /* minimum gain value in millibels */
770 int max_value; /* maximum gain value in millibels */
771 int default_value; /* default gain value in millibels */
772 unsigned int step_value; /* gain step in millibels */
773 unsigned int min_ramp_ms; /* minimum ramp duration in ms */
774 unsigned int max_ramp_ms; /* maximum ramp duration in ms */
775};
776
777/* The gain configuration structure is used to get or set the gain values of a
778 * given port */
779struct audio_gain_config {
780 int index; /* index of the corresponding audio_gain in the
781 audio_port gains[] table */
782 audio_gain_mode_t mode; /* mode requested for this command */
783 audio_channel_mask_t channel_mask; /* channels which gain value follows.
784 N/A in joint mode */
Jungshik Jangf7e5aea2014-07-11 09:50:45 +0900785 int values[sizeof(audio_channel_mask_t) * 8]; /* gain values in millibels
786 for each channel ordered from LSb to MSb in
787 channel mask. The number of values is 1 in joint
788 mode or popcount(channel_mask) */
Eric Laurent4cd05012014-02-18 12:40:36 -0800789 unsigned int ramp_duration_ms; /* ramp duration in ms */
790};
791
792/******************************
793 * Routing control
794 *****************************/
795
796/* Types defined here are used to describe an audio source or sink at internal
797 * framework interfaces (audio policy, patch panel) or at the audio HAL.
798 * Sink and sources are grouped in a concept of “audio port” representing an
799 * audio end point at the edge of the system managed by the module exposing
800 * the interface. */
801
802/* Audio port role: either source or sink */
803typedef enum {
804 AUDIO_PORT_ROLE_NONE,
805 AUDIO_PORT_ROLE_SOURCE,
806 AUDIO_PORT_ROLE_SINK,
807} audio_port_role_t;
808
809/* Audio port type indicates if it is a session (e.g AudioTrack),
810 * a mix (e.g PlaybackThread output) or a physical device
811 * (e.g AUDIO_DEVICE_OUT_SPEAKER) */
812typedef enum {
813 AUDIO_PORT_TYPE_NONE,
814 AUDIO_PORT_TYPE_DEVICE,
815 AUDIO_PORT_TYPE_MIX,
816 AUDIO_PORT_TYPE_SESSION,
817} audio_port_type_t;
818
819/* Each port has a unique ID or handle allocated by policy manager */
820typedef int audio_port_handle_t;
821#define AUDIO_PORT_HANDLE_NONE 0
822
823
824/* maximum audio device address length */
825#define AUDIO_DEVICE_MAX_ADDRESS_LEN 32
826
827/* extension for audio port configuration structure when the audio port is a
828 * hardware device */
829struct audio_port_config_device_ext {
830 audio_module_handle_t hw_module; /* module the device is attached to */
831 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
832 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; /* device address. "" if N/A */
833};
834
835/* extension for audio port configuration structure when the audio port is a
836 * sub mix */
837struct audio_port_config_mix_ext {
838 audio_module_handle_t hw_module; /* module the stream is attached to */
839 audio_io_handle_t handle; /* I/O handle of the input/output stream */
840 union {
841 //TODO: change use case for output streams: use strategy and mixer attributes
842 audio_stream_type_t stream;
843 audio_source_t source;
844 } usecase;
845};
846
847/* extension for audio port configuration structure when the audio port is an
848 * audio session */
849struct audio_port_config_session_ext {
850 audio_session_t session; /* audio session */
851};
852
853/* Flags indicating which fields are to be considered in struct audio_port_config */
854#define AUDIO_PORT_CONFIG_SAMPLE_RATE 0x1
855#define AUDIO_PORT_CONFIG_CHANNEL_MASK 0x2
856#define AUDIO_PORT_CONFIG_FORMAT 0x4
857#define AUDIO_PORT_CONFIG_GAIN 0x8
858#define AUDIO_PORT_CONFIG_ALL (AUDIO_PORT_CONFIG_SAMPLE_RATE | \
859 AUDIO_PORT_CONFIG_CHANNEL_MASK | \
860 AUDIO_PORT_CONFIG_FORMAT | \
861 AUDIO_PORT_CONFIG_GAIN)
862
863/* audio port configuration structure used to specify a particular configuration of
864 * an audio port */
865struct audio_port_config {
866 audio_port_handle_t id; /* port unique ID */
867 audio_port_role_t role; /* sink or source */
868 audio_port_type_t type; /* device, mix ... */
869 unsigned int config_mask; /* e.g AUDIO_PORT_CONFIG_ALL */
870 unsigned int sample_rate; /* sampling rate in Hz */
871 audio_channel_mask_t channel_mask; /* channel mask if applicable */
872 audio_format_t format; /* format if applicable */
873 struct audio_gain_config gain; /* gain to apply if applicable */
874 union {
875 struct audio_port_config_device_ext device; /* device specific info */
876 struct audio_port_config_mix_ext mix; /* mix specific info */
877 struct audio_port_config_session_ext session; /* session specific info */
878 } ext;
879};
880
881
882/* max number of sampling rates in audio port */
883#define AUDIO_PORT_MAX_SAMPLING_RATES 16
884/* max number of channel masks in audio port */
885#define AUDIO_PORT_MAX_CHANNEL_MASKS 16
886/* max number of audio formats in audio port */
887#define AUDIO_PORT_MAX_FORMATS 16
888/* max number of gain controls in audio port */
889#define AUDIO_PORT_MAX_GAINS 16
890
891/* extension for audio port structure when the audio port is a hardware device */
892struct audio_port_device_ext {
893 audio_module_handle_t hw_module; /* module the device is attached to */
894 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
895 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
896};
897
898/* Latency class of the audio mix */
899typedef enum {
900 AUDIO_LATENCY_LOW,
901 AUDIO_LATENCY_NORMAL,
902} audio_mix_latency_class_t;
903
904/* extension for audio port structure when the audio port is a sub mix */
905struct audio_port_mix_ext {
906 audio_module_handle_t hw_module; /* module the stream is attached to */
907 audio_io_handle_t handle; /* I/O handle of the input.output stream */
908 audio_mix_latency_class_t latency_class; /* latency class */
909 // other attributes: routing strategies
910};
911
912/* extension for audio port structure when the audio port is an audio session */
913struct audio_port_session_ext {
914 audio_session_t session; /* audio session */
915};
916
917
918struct audio_port {
919 audio_port_handle_t id; /* port unique ID */
920 audio_port_role_t role; /* sink or source */
921 audio_port_type_t type; /* device, mix ... */
922 unsigned int num_sample_rates; /* number of sampling rates in following array */
923 unsigned int sample_rates[AUDIO_PORT_MAX_SAMPLING_RATES];
924 unsigned int num_channel_masks; /* number of channel masks in following array */
925 audio_channel_mask_t channel_masks[AUDIO_PORT_MAX_CHANNEL_MASKS];
926 unsigned int num_formats; /* number of formats in following array */
927 audio_format_t formats[AUDIO_PORT_MAX_FORMATS];
928 unsigned int num_gains; /* number of gains in following array */
929 struct audio_gain gains[AUDIO_PORT_MAX_GAINS];
930 struct audio_port_config active_config; /* current audio port configuration */
931 union {
932 struct audio_port_device_ext device;
933 struct audio_port_mix_ext mix;
934 struct audio_port_session_ext session;
935 } ext;
936};
937
938/* An audio patch represents a connection between one or more source ports and
939 * one or more sink ports. Patches are connected and disconnected by audio policy manager or by
940 * applications via framework APIs.
941 * Each patch is identified by a handle at the interface used to create that patch. For instance,
942 * when a patch is created by the audio HAL, the HAL allocates and returns a handle.
943 * This handle is unique to a given audio HAL hardware module.
944 * But the same patch receives another system wide unique handle allocated by the framework.
945 * This unique handle is used for all transactions inside the framework.
946 */
947typedef int audio_patch_handle_t;
948#define AUDIO_PATCH_HANDLE_NONE 0
949
950#define AUDIO_PATCH_PORTS_MAX 16
951
952struct audio_patch {
953 audio_patch_handle_t id; /* patch unique ID */
954 unsigned int num_sources; /* number of sources in following array */
955 struct audio_port_config sources[AUDIO_PATCH_PORTS_MAX];
956 unsigned int num_sinks; /* number of sinks in following array */
957 struct audio_port_config sinks[AUDIO_PATCH_PORTS_MAX];
958};
959
960
Dima Zavine8e4be52011-05-12 10:25:33 -0700961static inline bool audio_is_output_device(audio_devices_t device)
962{
Eric Laurenteeeee802012-08-28 14:29:07 -0700963 if (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
964 (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0))
Dima Zavine8e4be52011-05-12 10:25:33 -0700965 return true;
966 else
967 return false;
968}
969
970static inline bool audio_is_input_device(audio_devices_t device)
971{
Eric Laurenteeeee802012-08-28 14:29:07 -0700972 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
973 device &= ~AUDIO_DEVICE_BIT_IN;
974 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0))
975 return true;
976 }
977 return false;
Dima Zavine8e4be52011-05-12 10:25:33 -0700978}
979
Eric Laurenteeeee802012-08-28 14:29:07 -0700980static inline bool audio_is_output_devices(audio_devices_t device)
981{
982 return (device & AUDIO_DEVICE_BIT_IN) == 0;
983}
984
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700985static inline bool audio_is_a2dp_in_device(audio_devices_t device)
986{
987 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
988 device &= ~AUDIO_DEVICE_BIT_IN;
989 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP))
990 return true;
991 }
992 return false;
993}
Eric Laurenteeeee802012-08-28 14:29:07 -0700994
Mike Lockwoodc8183af2014-05-12 12:56:03 -0700995static inline bool audio_is_a2dp_out_device(audio_devices_t device)
Dima Zavine8e4be52011-05-12 10:25:33 -0700996{
997 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP))
998 return true;
999 else
1000 return false;
1001}
1002
Mike Lockwoodc8183af2014-05-12 12:56:03 -07001003// Deprecated - use audio_is_a2dp_out_device() instead
1004static inline bool audio_is_a2dp_device(audio_devices_t device)
1005{
1006 return audio_is_a2dp_out_device(device);
1007}
1008
Dima Zavine8e4be52011-05-12 10:25:33 -07001009static inline bool audio_is_bluetooth_sco_device(audio_devices_t device)
1010{
Eric Laurentb5266302014-04-24 13:36:47 -07001011 if ((device & AUDIO_DEVICE_BIT_IN) == 0) {
1012 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL_SCO) == 0))
1013 return true;
1014 } else {
1015 device &= ~AUDIO_DEVICE_BIT_IN;
1016 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) == 0))
1017 return true;
1018 }
1019
1020 return false;
Dima Zavine8e4be52011-05-12 10:25:33 -07001021}
1022
Paul McLean00b89722014-04-18 14:29:22 -07001023static inline bool audio_is_usb_out_device(audio_devices_t device)
1024{
1025 return ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB));
1026}
1027
1028static inline bool audio_is_usb_in_device(audio_devices_t device)
1029{
1030 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
1031 device &= ~AUDIO_DEVICE_BIT_IN;
1032 if (popcount(device) == 1 && (device & AUDIO_DEVICE_IN_ALL_USB) != 0)
1033 return true;
1034 }
1035 return false;
1036}
1037
1038/* OBSOLETE - use audio_is_usb_out_device() instead. */
Eric Laurent79f90bd2012-04-06 08:57:48 -07001039static inline bool audio_is_usb_device(audio_devices_t device)
1040{
Paul McLean00b89722014-04-18 14:29:22 -07001041 return audio_is_usb_out_device(device);
Eric Laurent79f90bd2012-04-06 08:57:48 -07001042}
1043
Jean-Michel Trivie11866a2012-08-16 17:53:30 -07001044static inline bool audio_is_remote_submix_device(audio_devices_t device)
1045{
Jeff Brown8ecc7af2013-08-16 20:09:37 -07001046 if ((device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX
1047 || (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX)
Jean-Michel Trivie11866a2012-08-16 17:53:30 -07001048 return true;
1049 else
1050 return false;
1051}
1052
Glenn Kasten432b7c62014-04-14 17:47:03 -07001053/* Returns true if:
1054 * representation is valid, and
1055 * there is at least one channel bit set which _could_ correspond to an input channel, and
1056 * there are no channel bits set which could _not_ correspond to an input channel.
1057 * Otherwise returns false.
1058 */
Glenn Kastenf7326dc2013-07-19 14:50:21 -07001059static inline bool audio_is_input_channel(audio_channel_mask_t channel)
Dima Zavine8e4be52011-05-12 10:25:33 -07001060{
Glenn Kasten432b7c62014-04-14 17:47:03 -07001061 uint32_t bits = audio_channel_mask_get_bits(channel);
1062 switch (audio_channel_mask_get_representation(channel)) {
1063 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
1064 if (bits & ~AUDIO_CHANNEL_IN_ALL) {
1065 bits = 0;
1066 }
1067 // fall through
1068 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
1069 return bits != 0;
1070 default:
Dima Zavine8e4be52011-05-12 10:25:33 -07001071 return false;
Glenn Kasten432b7c62014-04-14 17:47:03 -07001072 }
Dima Zavine8e4be52011-05-12 10:25:33 -07001073}
1074
Glenn Kasten432b7c62014-04-14 17:47:03 -07001075/* Returns true if:
1076 * representation is valid, and
1077 * there is at least one channel bit set which _could_ correspond to an output channel, and
1078 * there are no channel bits set which could _not_ correspond to an output channel.
1079 * Otherwise returns false.
1080 */
Glenn Kastenf7326dc2013-07-19 14:50:21 -07001081static inline bool audio_is_output_channel(audio_channel_mask_t channel)
Dima Zavine8e4be52011-05-12 10:25:33 -07001082{
Glenn Kasten432b7c62014-04-14 17:47:03 -07001083 uint32_t bits = audio_channel_mask_get_bits(channel);
1084 switch (audio_channel_mask_get_representation(channel)) {
1085 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
1086 if (bits & ~AUDIO_CHANNEL_OUT_ALL) {
1087 bits = 0;
1088 }
1089 // fall through
1090 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
1091 return bits != 0;
1092 default:
Dima Zavine8e4be52011-05-12 10:25:33 -07001093 return false;
Glenn Kasten432b7c62014-04-14 17:47:03 -07001094 }
Dima Zavine8e4be52011-05-12 10:25:33 -07001095}
1096
Andy Hunga7e8f862014-05-15 18:35:38 -07001097/* Returns the number of channels from an input channel mask,
1098 * used in the context of audio input or recording.
Glenn Kasten432b7c62014-04-14 17:47:03 -07001099 * If a channel bit is set which could _not_ correspond to an input channel,
1100 * it is excluded from the count.
1101 * Returns zero if the representation is invalid.
Andy Hunga7e8f862014-05-15 18:35:38 -07001102 */
1103static inline uint32_t audio_channel_count_from_in_mask(audio_channel_mask_t channel)
1104{
Glenn Kasten432b7c62014-04-14 17:47:03 -07001105 uint32_t bits = audio_channel_mask_get_bits(channel);
1106 switch (audio_channel_mask_get_representation(channel)) {
1107 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
1108 // TODO: We can now merge with from_out_mask and remove anding
1109 bits &= AUDIO_CHANNEL_IN_ALL;
1110 // fall through
1111 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
1112 return popcount(bits);
1113 default:
1114 return 0;
1115 }
Andy Hunga7e8f862014-05-15 18:35:38 -07001116}
1117
1118/* Returns the number of channels from an output channel mask,
1119 * used in the context of audio output or playback.
Glenn Kasten432b7c62014-04-14 17:47:03 -07001120 * If a channel bit is set which could _not_ correspond to an output channel,
1121 * it is excluded from the count.
1122 * Returns zero if the representation is invalid.
Andy Hunga7e8f862014-05-15 18:35:38 -07001123 */
1124static inline uint32_t audio_channel_count_from_out_mask(audio_channel_mask_t channel)
1125{
Glenn Kasten432b7c62014-04-14 17:47:03 -07001126 uint32_t bits = audio_channel_mask_get_bits(channel);
1127 switch (audio_channel_mask_get_representation(channel)) {
1128 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
1129 // TODO: We can now merge with from_in_mask and remove anding
1130 bits &= AUDIO_CHANNEL_OUT_ALL;
1131 // fall through
1132 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
1133 return popcount(bits);
1134 default:
1135 return 0;
1136 }
Andy Hunga7e8f862014-05-15 18:35:38 -07001137}
1138
Glenn Kasten432b7c62014-04-14 17:47:03 -07001139/* Derive an output channel mask for position assignment from a channel count.
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001140 * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel
1141 * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad,
1142 * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC
1143 * for continuity with stereo.
Glenn Kasten432b7c62014-04-14 17:47:03 -07001144 * Returns the matching channel mask,
1145 * or AUDIO_CHANNEL_NONE if the channel count is zero,
1146 * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
1147 * configurations for which a default output channel mask is defined.
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001148 */
Glenn Kasten89f7ba32012-03-14 13:45:31 -07001149static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count)
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001150{
Glenn Kasten432b7c62014-04-14 17:47:03 -07001151 uint32_t bits;
Glenn Kasten1c3e16f2011-12-19 09:21:48 -08001152 switch (channel_count) {
Glenn Kasten432b7c62014-04-14 17:47:03 -07001153 case 0:
1154 return AUDIO_CHANNEL_NONE;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001155 case 1:
Glenn Kasten432b7c62014-04-14 17:47:03 -07001156 bits = AUDIO_CHANNEL_OUT_MONO;
1157 break;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001158 case 2:
Glenn Kasten432b7c62014-04-14 17:47:03 -07001159 bits = AUDIO_CHANNEL_OUT_STEREO;
1160 break;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001161 case 3:
Glenn Kasten432b7c62014-04-14 17:47:03 -07001162 bits = AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER;
1163 break;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001164 case 4: // 4.0
Glenn Kasten432b7c62014-04-14 17:47:03 -07001165 bits = AUDIO_CHANNEL_OUT_QUAD;
1166 break;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001167 case 5: // 5.0
Glenn Kasten432b7c62014-04-14 17:47:03 -07001168 bits = AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER;
1169 break;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001170 case 6: // 5.1
Glenn Kasten432b7c62014-04-14 17:47:03 -07001171 bits = AUDIO_CHANNEL_OUT_5POINT1;
1172 break;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001173 case 7: // 6.1
Glenn Kasten432b7c62014-04-14 17:47:03 -07001174 bits = AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER;
1175 break;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001176 case 8:
Glenn Kasten432b7c62014-04-14 17:47:03 -07001177 bits = AUDIO_CHANNEL_OUT_7POINT1;
1178 break;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001179 default:
Glenn Kasten432b7c62014-04-14 17:47:03 -07001180 return AUDIO_CHANNEL_INVALID;
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001181 }
Glenn Kasten432b7c62014-04-14 17:47:03 -07001182 return audio_channel_mask_from_representation_and_bits(
1183 AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
Jean-Michel Trivi4ab051a2012-03-02 16:41:35 -08001184}
1185
Glenn Kasten432b7c62014-04-14 17:47:03 -07001186/* Derive an input channel mask for position assignment from a channel count.
1187 * Currently handles only mono and stereo.
1188 * Returns the matching channel mask,
1189 * or AUDIO_CHANNEL_NONE if the channel count is zero,
1190 * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
1191 * configurations for which a default input channel mask is defined.
1192 */
Glenn Kasten89f7ba32012-03-14 13:45:31 -07001193static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count)
1194{
Glenn Kasten432b7c62014-04-14 17:47:03 -07001195 uint32_t bits;
Glenn Kasten89f7ba32012-03-14 13:45:31 -07001196 switch (channel_count) {
Glenn Kasten432b7c62014-04-14 17:47:03 -07001197 case 0:
1198 return AUDIO_CHANNEL_NONE;
Glenn Kasten89f7ba32012-03-14 13:45:31 -07001199 case 1:
Glenn Kasten432b7c62014-04-14 17:47:03 -07001200 bits = AUDIO_CHANNEL_IN_MONO;
1201 break;
Glenn Kasten89f7ba32012-03-14 13:45:31 -07001202 case 2:
Glenn Kasten432b7c62014-04-14 17:47:03 -07001203 bits = AUDIO_CHANNEL_IN_STEREO;
1204 break;
Glenn Kasten89f7ba32012-03-14 13:45:31 -07001205 default:
Glenn Kasten432b7c62014-04-14 17:47:03 -07001206 return AUDIO_CHANNEL_INVALID;
Glenn Kasten89f7ba32012-03-14 13:45:31 -07001207 }
Glenn Kasten432b7c62014-04-14 17:47:03 -07001208 return audio_channel_mask_from_representation_and_bits(
1209 AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
1210}
1211
1212/* Derive a channel mask for index assignment from a channel count.
1213 * Returns the matching channel mask,
1214 * or AUDIO_CHANNEL_NONE if the channel count is zero,
1215 * or AUDIO_CHANNEL_INVALID if the channel count exceeds AUDIO_CHANNEL_COUNT_MAX.
1216 */
1217static inline audio_channel_mask_t audio_channel_mask_for_index_assignment_from_count(
1218 uint32_t channel_count)
1219{
1220 if (channel_count == 0) {
1221 return AUDIO_CHANNEL_NONE;
1222 }
1223 if (channel_count > AUDIO_CHANNEL_COUNT_MAX) {
1224 return AUDIO_CHANNEL_INVALID;
1225 }
1226 uint32_t bits = (1 << channel_count) - 1;
1227 return audio_channel_mask_from_representation_and_bits(
1228 AUDIO_CHANNEL_REPRESENTATION_INDEX, bits);
Glenn Kasten89f7ba32012-03-14 13:45:31 -07001229}
1230
Glenn Kasten828bf0c2012-01-12 12:34:42 -08001231static inline bool audio_is_valid_format(audio_format_t format)
Dima Zavine8e4be52011-05-12 10:25:33 -07001232{
1233 switch (format & AUDIO_FORMAT_MAIN_MASK) {
1234 case AUDIO_FORMAT_PCM:
Glenn Kasten45b95812014-03-07 12:31:03 -08001235 switch (format) {
1236 case AUDIO_FORMAT_PCM_16_BIT:
1237 case AUDIO_FORMAT_PCM_8_BIT:
1238 case AUDIO_FORMAT_PCM_32_BIT:
1239 case AUDIO_FORMAT_PCM_8_24_BIT:
1240 case AUDIO_FORMAT_PCM_FLOAT:
1241 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1242 return true;
1243 default:
Eric Laurentda382242011-06-16 21:13:43 -07001244 return false;
1245 }
Glenn Kasten45b95812014-03-07 12:31:03 -08001246 /* not reached */
Dima Zavine8e4be52011-05-12 10:25:33 -07001247 case AUDIO_FORMAT_MP3:
1248 case AUDIO_FORMAT_AMR_NB:
1249 case AUDIO_FORMAT_AMR_WB:
1250 case AUDIO_FORMAT_AAC:
1251 case AUDIO_FORMAT_HE_AAC_V1:
1252 case AUDIO_FORMAT_HE_AAC_V2:
1253 case AUDIO_FORMAT_VORBIS:
Eric Laurentce30de32014-06-10 15:39:16 -07001254 case AUDIO_FORMAT_OPUS:
1255 case AUDIO_FORMAT_AC3:
1256 case AUDIO_FORMAT_E_AC3:
Dima Zavine8e4be52011-05-12 10:25:33 -07001257 return true;
1258 default:
1259 return false;
1260 }
1261}
1262
Glenn Kasten828bf0c2012-01-12 12:34:42 -08001263static inline bool audio_is_linear_pcm(audio_format_t format)
Dima Zavine8e4be52011-05-12 10:25:33 -07001264{
Eric Laurentda382242011-06-16 21:13:43 -07001265 return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM);
Dima Zavine8e4be52011-05-12 10:25:33 -07001266}
1267
Glenn Kasten828bf0c2012-01-12 12:34:42 -08001268static inline size_t audio_bytes_per_sample(audio_format_t format)
Eric Laurentda382242011-06-16 21:13:43 -07001269{
1270 size_t size = 0;
1271
1272 switch (format) {
Jean-Michel Trivi427d2b42012-03-05 15:38:15 -08001273 case AUDIO_FORMAT_PCM_32_BIT:
1274 case AUDIO_FORMAT_PCM_8_24_BIT:
1275 size = sizeof(int32_t);
1276 break;
Andy Hung173f4992014-03-06 17:18:58 -08001277 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1278 size = sizeof(uint8_t) * 3;
1279 break;
Jean-Michel Trivi427d2b42012-03-05 15:38:15 -08001280 case AUDIO_FORMAT_PCM_16_BIT:
1281 size = sizeof(int16_t);
1282 break;
1283 case AUDIO_FORMAT_PCM_8_BIT:
1284 size = sizeof(uint8_t);
1285 break;
Glenn Kasten1c3e16f2011-12-19 09:21:48 -08001286 case AUDIO_FORMAT_PCM_FLOAT:
1287 size = sizeof(float);
1288 break;
Jean-Michel Trivi427d2b42012-03-05 15:38:15 -08001289 default:
1290 break;
Eric Laurentda382242011-06-16 21:13:43 -07001291 }
1292 return size;
1293}
Dima Zavine8e4be52011-05-12 10:25:33 -07001294
1295__END_DECLS
1296
1297#endif // ANDROID_AUDIO_CORE_H