1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18#ifndef ANDROID_AUDIO_CORE_H
19#define ANDROID_AUDIO_CORE_H
20
21#include <stdbool.h>
22#include <stdint.h>
23#include <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
34typedef int audio_io_handle_t;
35
36/* Audio stream types */
37typedef enum {
38    AUDIO_STREAM_DEFAULT          = -1,
39    AUDIO_STREAM_VOICE_CALL       = 0,
40    AUDIO_STREAM_SYSTEM           = 1,
41    AUDIO_STREAM_RING             = 2,
42    AUDIO_STREAM_MUSIC            = 3,
43    AUDIO_STREAM_ALARM            = 4,
44    AUDIO_STREAM_NOTIFICATION     = 5,
45    AUDIO_STREAM_BLUETOOTH_SCO    = 6,
46    AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user and must be routed to speaker */
47    AUDIO_STREAM_DTMF             = 8,
48    AUDIO_STREAM_TTS              = 9,
49
50    AUDIO_STREAM_CNT,
51    AUDIO_STREAM_MAX              = AUDIO_STREAM_CNT - 1,
52} audio_stream_type_t;
53
54/* Do not change these values without updating their counterparts
55 * in media/java/android/media/MediaRecorder.java!
56 */
57typedef enum {
58    AUDIO_SOURCE_DEFAULT             = 0,
59    AUDIO_SOURCE_MIC                 = 1,
60    AUDIO_SOURCE_VOICE_UPLINK        = 2,
61    AUDIO_SOURCE_VOICE_DOWNLINK      = 3,
62    AUDIO_SOURCE_VOICE_CALL          = 4,
63    AUDIO_SOURCE_CAMCORDER           = 5,
64    AUDIO_SOURCE_VOICE_RECOGNITION   = 6,
65    AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
66    AUDIO_SOURCE_REMOTE_SUBMIX       = 8, /* Source for the mix to be presented remotely.      */
67                                          /* An example of remote presentation is Wifi Display */
68                                          /*  where a dongle attached to a TV can be used to   */
69                                          /*  play the mix captured by this audio source.      */
70    AUDIO_SOURCE_CNT,
71    AUDIO_SOURCE_MAX                 = AUDIO_SOURCE_CNT - 1,
72} audio_source_t;
73
74/* special audio session values
75 * (XXX: should this be living in the audio effects land?)
76 */
77typedef enum {
78    /* session for effects attached to a particular output stream
79     * (value must be less than 0)
80     */
81    AUDIO_SESSION_OUTPUT_STAGE = -1,
82
83    /* session for effects applied to output mix. These effects can
84     * be moved by audio policy manager to another output stream
85     * (value must be 0)
86     */
87    AUDIO_SESSION_OUTPUT_MIX = 0,
88} audio_session_t;
89
90/* Audio sub formats (see enum audio_format). */
91
92/* PCM sub formats */
93typedef enum {
94    AUDIO_FORMAT_PCM_SUB_16_BIT          = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */
95    AUDIO_FORMAT_PCM_SUB_8_BIT           = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */
96    AUDIO_FORMAT_PCM_SUB_32_BIT          = 0x3, /* PCM signed .31 fixed point */
97    AUDIO_FORMAT_PCM_SUB_8_24_BIT        = 0x4, /* PCM signed 7.24 fixed point */
98} audio_format_pcm_sub_fmt_t;
99
100/* MP3 sub format field definition : can use 11 LSBs in the same way as MP3
101 * frame header to specify bit rate, stereo mode, version...
102 */
103typedef enum {
104    AUDIO_FORMAT_MP3_SUB_NONE            = 0x0,
105} audio_format_mp3_sub_fmt_t;
106
107/* AMR NB/WB sub format field definition: specify frame block interleaving,
108 * bandwidth efficient or octet aligned, encoding mode for recording...
109 */
110typedef enum {
111    AUDIO_FORMAT_AMR_SUB_NONE            = 0x0,
112} audio_format_amr_sub_fmt_t;
113
114/* AAC sub format field definition: specify profile or bitrate for recording... */
115typedef enum {
116    AUDIO_FORMAT_AAC_SUB_NONE            = 0x0,
117} audio_format_aac_sub_fmt_t;
118
119/* VORBIS sub format field definition: specify quality for recording... */
120typedef enum {
121    AUDIO_FORMAT_VORBIS_SUB_NONE         = 0x0,
122} audio_format_vorbis_sub_fmt_t;
123
124/* Audio format consists in a main format field (upper 8 bits) and a sub format
125 * field (lower 24 bits).
126 *
127 * The main format indicates the main codec type. The sub format field
128 * indicates options and parameters for each format. The sub format is mainly
129 * used for record to indicate for instance the requested bitrate or profile.
130 * It can also be used for certain formats to give informations not present in
131 * the encoded audio stream (e.g. octet alignement for AMR).
132 */
133typedef enum {
134    AUDIO_FORMAT_INVALID             = 0xFFFFFFFFUL,
135    AUDIO_FORMAT_DEFAULT             = 0,
136    AUDIO_FORMAT_PCM                 = 0x00000000UL, /* DO NOT CHANGE */
137    AUDIO_FORMAT_MP3                 = 0x01000000UL,
138    AUDIO_FORMAT_AMR_NB              = 0x02000000UL,
139    AUDIO_FORMAT_AMR_WB              = 0x03000000UL,
140    AUDIO_FORMAT_AAC                 = 0x04000000UL,
141    AUDIO_FORMAT_HE_AAC_V1           = 0x05000000UL,
142    AUDIO_FORMAT_HE_AAC_V2           = 0x06000000UL,
143    AUDIO_FORMAT_VORBIS              = 0x07000000UL,
144    AUDIO_FORMAT_MAIN_MASK           = 0xFF000000UL,
145    AUDIO_FORMAT_SUB_MASK            = 0x00FFFFFFUL,
146
147    /* Aliases */
148    AUDIO_FORMAT_PCM_16_BIT          = (AUDIO_FORMAT_PCM |
149                                        AUDIO_FORMAT_PCM_SUB_16_BIT),
150    AUDIO_FORMAT_PCM_8_BIT           = (AUDIO_FORMAT_PCM |
151                                        AUDIO_FORMAT_PCM_SUB_8_BIT),
152    AUDIO_FORMAT_PCM_32_BIT          = (AUDIO_FORMAT_PCM |
153                                        AUDIO_FORMAT_PCM_SUB_32_BIT),
154    AUDIO_FORMAT_PCM_8_24_BIT        = (AUDIO_FORMAT_PCM |
155                                        AUDIO_FORMAT_PCM_SUB_8_24_BIT),
156} audio_format_t;
157
158enum {
159    /* output channels */
160    AUDIO_CHANNEL_OUT_FRONT_LEFT            = 0x1,
161    AUDIO_CHANNEL_OUT_FRONT_RIGHT           = 0x2,
162    AUDIO_CHANNEL_OUT_FRONT_CENTER          = 0x4,
163    AUDIO_CHANNEL_OUT_LOW_FREQUENCY         = 0x8,
164    AUDIO_CHANNEL_OUT_BACK_LEFT             = 0x10,
165    AUDIO_CHANNEL_OUT_BACK_RIGHT            = 0x20,
166    AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER  = 0x40,
167    AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80,
168    AUDIO_CHANNEL_OUT_BACK_CENTER           = 0x100,
169    AUDIO_CHANNEL_OUT_SIDE_LEFT             = 0x200,
170    AUDIO_CHANNEL_OUT_SIDE_RIGHT            = 0x400,
171    AUDIO_CHANNEL_OUT_TOP_CENTER            = 0x800,
172    AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT        = 0x1000,
173    AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER      = 0x2000,
174    AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT       = 0x4000,
175    AUDIO_CHANNEL_OUT_TOP_BACK_LEFT         = 0x8000,
176    AUDIO_CHANNEL_OUT_TOP_BACK_CENTER       = 0x10000,
177    AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT        = 0x20000,
178
179    AUDIO_CHANNEL_OUT_MONO     = AUDIO_CHANNEL_OUT_FRONT_LEFT,
180    AUDIO_CHANNEL_OUT_STEREO   = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
181                                  AUDIO_CHANNEL_OUT_FRONT_RIGHT),
182    AUDIO_CHANNEL_OUT_QUAD     = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
183                                  AUDIO_CHANNEL_OUT_FRONT_RIGHT |
184                                  AUDIO_CHANNEL_OUT_BACK_LEFT |
185                                  AUDIO_CHANNEL_OUT_BACK_RIGHT),
186    AUDIO_CHANNEL_OUT_SURROUND = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
187                                  AUDIO_CHANNEL_OUT_FRONT_RIGHT |
188                                  AUDIO_CHANNEL_OUT_FRONT_CENTER |
189                                  AUDIO_CHANNEL_OUT_BACK_CENTER),
190    AUDIO_CHANNEL_OUT_5POINT1  = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
191                                  AUDIO_CHANNEL_OUT_FRONT_RIGHT |
192                                  AUDIO_CHANNEL_OUT_FRONT_CENTER |
193                                  AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
194                                  AUDIO_CHANNEL_OUT_BACK_LEFT |
195                                  AUDIO_CHANNEL_OUT_BACK_RIGHT),
196    // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1
197    AUDIO_CHANNEL_OUT_7POINT1  = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
198                                  AUDIO_CHANNEL_OUT_FRONT_RIGHT |
199                                  AUDIO_CHANNEL_OUT_FRONT_CENTER |
200                                  AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
201                                  AUDIO_CHANNEL_OUT_BACK_LEFT |
202                                  AUDIO_CHANNEL_OUT_BACK_RIGHT |
203                                  AUDIO_CHANNEL_OUT_SIDE_LEFT |
204                                  AUDIO_CHANNEL_OUT_SIDE_RIGHT),
205    AUDIO_CHANNEL_OUT_ALL      = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
206                                  AUDIO_CHANNEL_OUT_FRONT_RIGHT |
207                                  AUDIO_CHANNEL_OUT_FRONT_CENTER |
208                                  AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
209                                  AUDIO_CHANNEL_OUT_BACK_LEFT |
210                                  AUDIO_CHANNEL_OUT_BACK_RIGHT |
211                                  AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
212                                  AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
213                                  AUDIO_CHANNEL_OUT_BACK_CENTER|
214                                  AUDIO_CHANNEL_OUT_SIDE_LEFT|
215                                  AUDIO_CHANNEL_OUT_SIDE_RIGHT|
216                                  AUDIO_CHANNEL_OUT_TOP_CENTER|
217                                  AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT|
218                                  AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER|
219                                  AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT|
220                                  AUDIO_CHANNEL_OUT_TOP_BACK_LEFT|
221                                  AUDIO_CHANNEL_OUT_TOP_BACK_CENTER|
222                                  AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT),
223
224    /* input channels */
225    AUDIO_CHANNEL_IN_LEFT            = 0x4,
226    AUDIO_CHANNEL_IN_RIGHT           = 0x8,
227    AUDIO_CHANNEL_IN_FRONT           = 0x10,
228    AUDIO_CHANNEL_IN_BACK            = 0x20,
229    AUDIO_CHANNEL_IN_LEFT_PROCESSED  = 0x40,
230    AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80,
231    AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100,
232    AUDIO_CHANNEL_IN_BACK_PROCESSED  = 0x200,
233    AUDIO_CHANNEL_IN_PRESSURE        = 0x400,
234    AUDIO_CHANNEL_IN_X_AXIS          = 0x800,
235    AUDIO_CHANNEL_IN_Y_AXIS          = 0x1000,
236    AUDIO_CHANNEL_IN_Z_AXIS          = 0x2000,
237    AUDIO_CHANNEL_IN_VOICE_UPLINK    = 0x4000,
238    AUDIO_CHANNEL_IN_VOICE_DNLINK    = 0x8000,
239
240    AUDIO_CHANNEL_IN_MONO   = AUDIO_CHANNEL_IN_FRONT,
241    AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT),
242    AUDIO_CHANNEL_IN_ALL    = (AUDIO_CHANNEL_IN_LEFT |
243                               AUDIO_CHANNEL_IN_RIGHT |
244                               AUDIO_CHANNEL_IN_FRONT |
245                               AUDIO_CHANNEL_IN_BACK|
246                               AUDIO_CHANNEL_IN_LEFT_PROCESSED |
247                               AUDIO_CHANNEL_IN_RIGHT_PROCESSED |
248                               AUDIO_CHANNEL_IN_FRONT_PROCESSED |
249                               AUDIO_CHANNEL_IN_BACK_PROCESSED|
250                               AUDIO_CHANNEL_IN_PRESSURE |
251                               AUDIO_CHANNEL_IN_X_AXIS |
252                               AUDIO_CHANNEL_IN_Y_AXIS |
253                               AUDIO_CHANNEL_IN_Z_AXIS |
254                               AUDIO_CHANNEL_IN_VOICE_UPLINK |
255                               AUDIO_CHANNEL_IN_VOICE_DNLINK),
256};
257
258typedef uint32_t audio_channel_mask_t;
259
260typedef enum {
261    AUDIO_MODE_INVALID          = -2,
262    AUDIO_MODE_CURRENT          = -1,
263    AUDIO_MODE_NORMAL           = 0,
264    AUDIO_MODE_RINGTONE         = 1,
265    AUDIO_MODE_IN_CALL          = 2,
266    AUDIO_MODE_IN_COMMUNICATION = 3,
267
268    AUDIO_MODE_CNT,
269    AUDIO_MODE_MAX              = AUDIO_MODE_CNT - 1,
270} audio_mode_t;
271
272typedef enum {
273    AUDIO_IN_ACOUSTICS_AGC_ENABLE    = 0x0001,
274    AUDIO_IN_ACOUSTICS_AGC_DISABLE   = 0,
275    AUDIO_IN_ACOUSTICS_NS_ENABLE     = 0x0002,
276    AUDIO_IN_ACOUSTICS_NS_DISABLE    = 0,
277    AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004,
278    AUDIO_IN_ACOUSTICS_TX_DISABLE    = 0,
279} audio_in_acoustics_t;
280
281enum {
282    AUDIO_DEVICE_NONE                          = 0x0,
283    /* reserved bits */
284    AUDIO_DEVICE_BIT_IN                        = 0x80000000,
285    AUDIO_DEVICE_BIT_DEFAULT                   = 0x40000000,
286    /* output devices */
287    AUDIO_DEVICE_OUT_EARPIECE                  = 0x1,
288    AUDIO_DEVICE_OUT_SPEAKER                   = 0x2,
289    AUDIO_DEVICE_OUT_WIRED_HEADSET             = 0x4,
290    AUDIO_DEVICE_OUT_WIRED_HEADPHONE           = 0x8,
291    AUDIO_DEVICE_OUT_BLUETOOTH_SCO             = 0x10,
292    AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET     = 0x20,
293    AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT      = 0x40,
294    AUDIO_DEVICE_OUT_BLUETOOTH_A2DP            = 0x80,
295    AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
296    AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER    = 0x200,
297    AUDIO_DEVICE_OUT_AUX_DIGITAL               = 0x400,
298    AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET         = 0x800,
299    AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET         = 0x1000,
300    AUDIO_DEVICE_OUT_USB_ACCESSORY             = 0x2000,
301    AUDIO_DEVICE_OUT_USB_DEVICE                = 0x4000,
302    AUDIO_DEVICE_OUT_REMOTE_SUBMIX             = 0x8000,
303    AUDIO_DEVICE_OUT_DEFAULT                   = AUDIO_DEVICE_BIT_DEFAULT,
304    AUDIO_DEVICE_OUT_ALL      = (AUDIO_DEVICE_OUT_EARPIECE |
305                                 AUDIO_DEVICE_OUT_SPEAKER |
306                                 AUDIO_DEVICE_OUT_WIRED_HEADSET |
307                                 AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
308                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
309                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
310                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
311                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
312                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
313                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
314                                 AUDIO_DEVICE_OUT_AUX_DIGITAL |
315                                 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
316                                 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
317                                 AUDIO_DEVICE_OUT_USB_ACCESSORY |
318                                 AUDIO_DEVICE_OUT_USB_DEVICE |
319                                 AUDIO_DEVICE_OUT_REMOTE_SUBMIX |
320                                 AUDIO_DEVICE_OUT_DEFAULT),
321    AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
322                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
323                                 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
324    AUDIO_DEVICE_OUT_ALL_SCO  = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
325                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
326                                 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
327    AUDIO_DEVICE_OUT_ALL_USB  = (AUDIO_DEVICE_OUT_USB_ACCESSORY |
328                                 AUDIO_DEVICE_OUT_USB_DEVICE),
329
330    /* input devices */
331    AUDIO_DEVICE_IN_COMMUNICATION         = AUDIO_DEVICE_BIT_IN | 0x1,
332    AUDIO_DEVICE_IN_AMBIENT               = AUDIO_DEVICE_BIT_IN | 0x2,
333    AUDIO_DEVICE_IN_BUILTIN_MIC           = AUDIO_DEVICE_BIT_IN | 0x4,
334    AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8,
335    AUDIO_DEVICE_IN_WIRED_HEADSET         = AUDIO_DEVICE_BIT_IN | 0x10,
336    AUDIO_DEVICE_IN_AUX_DIGITAL           = AUDIO_DEVICE_BIT_IN | 0x20,
337    AUDIO_DEVICE_IN_VOICE_CALL            = AUDIO_DEVICE_BIT_IN | 0x40,
338    AUDIO_DEVICE_IN_BACK_MIC              = AUDIO_DEVICE_BIT_IN | 0x80,
339    AUDIO_DEVICE_IN_REMOTE_SUBMIX         = AUDIO_DEVICE_BIT_IN | 0x100,
340    AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET     = AUDIO_DEVICE_BIT_IN | 0x200,
341    AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET     = AUDIO_DEVICE_BIT_IN | 0x400,
342    AUDIO_DEVICE_IN_USB_ACCESSORY         = AUDIO_DEVICE_BIT_IN | 0x800,
343    AUDIO_DEVICE_IN_USB_DEVICE            = AUDIO_DEVICE_BIT_IN | 0x1000,
344    AUDIO_DEVICE_IN_DEFAULT               = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT,
345
346    AUDIO_DEVICE_IN_ALL     = (AUDIO_DEVICE_IN_COMMUNICATION |
347                               AUDIO_DEVICE_IN_AMBIENT |
348                               AUDIO_DEVICE_IN_BUILTIN_MIC |
349                               AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET |
350                               AUDIO_DEVICE_IN_WIRED_HEADSET |
351                               AUDIO_DEVICE_IN_AUX_DIGITAL |
352                               AUDIO_DEVICE_IN_VOICE_CALL |
353                               AUDIO_DEVICE_IN_BACK_MIC |
354                               AUDIO_DEVICE_IN_REMOTE_SUBMIX |
355                               AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET |
356                               AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET |
357                               AUDIO_DEVICE_IN_USB_ACCESSORY |
358                               AUDIO_DEVICE_IN_USB_DEVICE |
359                               AUDIO_DEVICE_IN_DEFAULT),
360    AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
361};
362
363typedef uint32_t audio_devices_t;
364
365/* the audio output flags serve two purposes:
366 * - when an AudioTrack is created they indicate a "wish" to be connected to an
367 * output stream with attributes corresponding to the specified flags
368 * - when present in an output profile descriptor listed for a particular audio
369 * hardware module, they indicate that an output stream can be opened that
370 * supports the attributes indicated by the flags.
371 * the audio policy manager will try to match the flags in the request
372 * (when getOuput() is called) to an available output stream.
373 */
374typedef enum {
375    AUDIO_OUTPUT_FLAG_NONE = 0x0,       // no attributes
376    AUDIO_OUTPUT_FLAG_DIRECT = 0x1,     // this output directly connects a track
377                                        // to one output stream: no software mixer
378    AUDIO_OUTPUT_FLAG_PRIMARY = 0x2,    // this output is the primary output of
379                                        // the device. It is unique and must be
380                                        // present. It is opened by default and
381                                        // receives routing, audio mode and volume
382                                        // controls related to voice calls.
383    AUDIO_OUTPUT_FLAG_FAST = 0x4,       // output supports "fast tracks",
384                                        // defined elsewhere
385    AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8 // use deep audio buffers
386} audio_output_flags_t;
387
388static inline bool audio_is_output_device(audio_devices_t device)
389{
390    if (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
391            (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0))
392        return true;
393    else
394        return false;
395}
396
397static inline bool audio_is_input_device(audio_devices_t device)
398{
399    if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
400        device &= ~AUDIO_DEVICE_BIT_IN;
401        if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0))
402            return true;
403    }
404    return false;
405}
406
407static inline bool audio_is_output_devices(audio_devices_t device)
408{
409    return (device & AUDIO_DEVICE_BIT_IN) == 0;
410}
411
412
413static inline bool audio_is_a2dp_device(audio_devices_t device)
414{
415    if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP))
416        return true;
417    else
418        return false;
419}
420
421static inline bool audio_is_bluetooth_sco_device(audio_devices_t device)
422{
423    device &= ~AUDIO_DEVICE_BIT_IN;
424    if ((popcount(device) == 1) && (device & (AUDIO_DEVICE_OUT_ALL_SCO |
425                   AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET)))
426        return true;
427    else
428        return false;
429}
430
431static inline bool audio_is_usb_device(audio_devices_t device)
432{
433    if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB))
434        return true;
435    else
436        return false;
437}
438
439static inline bool audio_is_remote_submix_device(audio_devices_t device)
440{
441    if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX))
442        return true;
443    else
444        return false;
445}
446
447static inline bool audio_is_input_channel(uint32_t channel)
448{
449    if ((channel & ~AUDIO_CHANNEL_IN_ALL) == 0)
450        return true;
451    else
452        return false;
453}
454
455static inline bool audio_is_output_channel(uint32_t channel)
456{
457    if ((channel & ~AUDIO_CHANNEL_OUT_ALL) == 0)
458        return true;
459    else
460        return false;
461}
462
463/* Derive an output channel mask from a channel count.
464 * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel
465 * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad,
466 * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC
467 * for continuity with stereo.
468 * Returns the matching channel mask, or 0 if the number of channels exceeds that of the
469 * configurations for which a default channel mask is defined.
470 */
471static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count)
472{
473    switch(channel_count) {
474    case 1:
475        return AUDIO_CHANNEL_OUT_MONO;
476    case 2:
477        return AUDIO_CHANNEL_OUT_STEREO;
478    case 3:
479        return (AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER);
480    case 4: // 4.0
481        return AUDIO_CHANNEL_OUT_QUAD;
482    case 5: // 5.0
483        return (AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER);
484    case 6: // 5.1
485        return AUDIO_CHANNEL_OUT_5POINT1;
486    case 7: // 6.1
487        return (AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER);
488    case 8:
489        return AUDIO_CHANNEL_OUT_7POINT1;
490    default:
491        return 0;
492    }
493}
494
495/* Similar to above, but for input.  Currently handles only mono and stereo. */
496static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count)
497{
498    switch (channel_count) {
499    case 1:
500        return AUDIO_CHANNEL_IN_MONO;
501    case 2:
502        return AUDIO_CHANNEL_IN_STEREO;
503    default:
504        return 0;
505    }
506}
507
508static inline bool audio_is_valid_format(audio_format_t format)
509{
510    switch (format & AUDIO_FORMAT_MAIN_MASK) {
511    case AUDIO_FORMAT_PCM:
512        if (format != AUDIO_FORMAT_PCM_16_BIT &&
513                format != AUDIO_FORMAT_PCM_8_BIT) {
514            return false;
515        }
516    case AUDIO_FORMAT_MP3:
517    case AUDIO_FORMAT_AMR_NB:
518    case AUDIO_FORMAT_AMR_WB:
519    case AUDIO_FORMAT_AAC:
520    case AUDIO_FORMAT_HE_AAC_V1:
521    case AUDIO_FORMAT_HE_AAC_V2:
522    case AUDIO_FORMAT_VORBIS:
523        return true;
524    default:
525        return false;
526    }
527}
528
529static inline bool audio_is_linear_pcm(audio_format_t format)
530{
531    return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM);
532}
533
534static inline size_t audio_bytes_per_sample(audio_format_t format)
535{
536    size_t size = 0;
537
538    switch (format) {
539    case AUDIO_FORMAT_PCM_32_BIT:
540    case AUDIO_FORMAT_PCM_8_24_BIT:
541        size = sizeof(int32_t);
542        break;
543    case AUDIO_FORMAT_PCM_16_BIT:
544        size = sizeof(int16_t);
545        break;
546    case AUDIO_FORMAT_PCM_8_BIT:
547        size = sizeof(uint8_t);
548        break;
549    default:
550        break;
551    }
552    return size;
553}
554
555__END_DECLS
556
557#endif  // ANDROID_AUDIO_CORE_H
558