1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_AUDIOSYSTEM_LEGACY_H_
18#define ANDROID_AUDIOSYSTEM_LEGACY_H_
19
20#include <utils/Errors.h>
21#include <media/AudioParameter.h>
22
23#include <system/audio.h>
24#include <system/audio_policy.h>
25
26namespace android_audio_legacy {
27
28using android::status_t;
29using android::AudioParameter;
30
31enum {
32    OK                  = android::OK,
33    NO_ERROR            = android::NO_ERROR,
34
35    UNKNOWN_ERROR       = android::UNKNOWN_ERROR,
36
37    NO_MEMORY           = android::NO_MEMORY,
38    INVALID_OPERATION   = android::INVALID_OPERATION,
39    BAD_VALUE           = android::BAD_VALUE,
40    BAD_TYPE            = android::BAD_TYPE,
41    NAME_NOT_FOUND      = android::NAME_NOT_FOUND,
42    PERMISSION_DENIED   = android::PERMISSION_DENIED,
43    NO_INIT             = android::NO_INIT,
44    ALREADY_EXISTS      = android::ALREADY_EXISTS,
45    DEAD_OBJECT         = android::DEAD_OBJECT,
46    FAILED_TRANSACTION  = android::FAILED_TRANSACTION,
47    BAD_INDEX           = android::BAD_INDEX,
48    NOT_ENOUGH_DATA     = android::NOT_ENOUGH_DATA,
49    WOULD_BLOCK         = android::WOULD_BLOCK,
50    TIMED_OUT           = android::TIMED_OUT,
51    UNKNOWN_TRANSACTION = android::UNKNOWN_TRANSACTION,
52};
53
54enum audio_source {
55    AUDIO_SOURCE_DEFAULT = 0,
56    AUDIO_SOURCE_MIC = 1,
57    AUDIO_SOURCE_VOICE_UPLINK = 2,
58    AUDIO_SOURCE_VOICE_DOWNLINK = 3,
59    AUDIO_SOURCE_VOICE_CALL = 4,
60    AUDIO_SOURCE_CAMCORDER = 5,
61    AUDIO_SOURCE_VOICE_RECOGNITION = 6,
62    AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
63    AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_COMMUNICATION,
64
65    AUDIO_SOURCE_LIST_END  // must be last - used to validate audio source type
66};
67
68class AudioSystem {
69public:
70#if 1
71    enum stream_type {
72        DEFAULT          =-1,
73        VOICE_CALL       = 0,
74        SYSTEM           = 1,
75        RING             = 2,
76        MUSIC            = 3,
77        ALARM            = 4,
78        NOTIFICATION     = 5,
79        BLUETOOTH_SCO    = 6,
80        ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
81        DTMF             = 8,
82        TTS              = 9,
83        NUM_STREAM_TYPES
84    };
85
86    // Audio sub formats (see AudioSystem::audio_format).
87    enum pcm_sub_format {
88        PCM_SUB_16_BIT          = 0x1, // must be 1 for backward compatibility
89        PCM_SUB_8_BIT           = 0x2, // must be 2 for backward compatibility
90    };
91
92    enum audio_sessions {
93        SESSION_OUTPUT_STAGE = AUDIO_SESSION_OUTPUT_STAGE,
94        SESSION_OUTPUT_MIX = AUDIO_SESSION_OUTPUT_MIX,
95    };
96
97    // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify
98    // bit rate, stereo mode, version...
99    enum mp3_sub_format {
100        //TODO
101    };
102
103    // AMR NB/WB sub format field definition: specify frame block interleaving, bandwidth efficient or octet aligned,
104    // encoding mode for recording...
105    enum amr_sub_format {
106        //TODO
107    };
108
109    // AAC sub format field definition: specify profile or bitrate for recording...
110    enum aac_sub_format {
111        //TODO
112    };
113
114    // VORBIS sub format field definition: specify quality for recording...
115    enum vorbis_sub_format {
116        //TODO
117    };
118
119    // Audio format consists in a main format field (upper 8 bits) and a sub format field (lower 24 bits).
120    // The main format indicates the main codec type. The sub format field indicates options and parameters
121    // for each format. The sub format is mainly used for record to indicate for instance the requested bitrate
122    // or profile. It can also be used for certain formats to give informations not present in the encoded
123    // audio stream (e.g. octet alignement for AMR).
124    enum audio_format {
125        INVALID_FORMAT      = -1,
126        FORMAT_DEFAULT      = 0,
127        PCM                 = 0x00000000, // must be 0 for backward compatibility
128        MP3                 = 0x01000000,
129        AMR_NB              = 0x02000000,
130        AMR_WB              = 0x03000000,
131        AAC                 = 0x04000000,
132        HE_AAC_V1           = 0x05000000,
133        HE_AAC_V2           = 0x06000000,
134        VORBIS              = 0x07000000,
135        MAIN_FORMAT_MASK    = 0xFF000000,
136        SUB_FORMAT_MASK     = 0x00FFFFFF,
137        // Aliases
138        PCM_16_BIT          = (PCM|PCM_SUB_16_BIT),
139        PCM_8_BIT          = (PCM|PCM_SUB_8_BIT)
140    };
141
142    enum audio_channels {
143        // output channels
144        CHANNEL_OUT_FRONT_LEFT            = 0x1,
145        CHANNEL_OUT_FRONT_RIGHT           = 0x2,
146        CHANNEL_OUT_FRONT_CENTER          = 0x4,
147        CHANNEL_OUT_LOW_FREQUENCY         = 0x8,
148        CHANNEL_OUT_BACK_LEFT             = 0x10,
149        CHANNEL_OUT_BACK_RIGHT            = 0x20,
150        CHANNEL_OUT_FRONT_LEFT_OF_CENTER  = 0x40,
151        CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80,
152        CHANNEL_OUT_BACK_CENTER           = 0x100,
153        CHANNEL_OUT_SIDE_LEFT             = 0x200,
154        CHANNEL_OUT_SIDE_RIGHT            = 0x400,
155        CHANNEL_OUT_TOP_CENTER            = 0x800,
156        CHANNEL_OUT_TOP_FRONT_LEFT        = 0x1000,
157        CHANNEL_OUT_TOP_FRONT_CENTER      = 0x2000,
158        CHANNEL_OUT_TOP_FRONT_RIGHT       = 0x4000,
159        CHANNEL_OUT_TOP_BACK_LEFT         = 0x8000,
160        CHANNEL_OUT_TOP_BACK_CENTER       = 0x10000,
161        CHANNEL_OUT_TOP_BACK_RIGHT        = 0x20000,
162
163        CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT,
164        CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT),
165        CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
166                CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
167        CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
168                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER),
169        CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
170                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY |
171                CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
172        // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1
173        CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
174                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY |
175                CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
176                CHANNEL_OUT_SIDE_LEFT | CHANNEL_OUT_SIDE_RIGHT),
177        CHANNEL_OUT_ALL = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
178                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT |
179                CHANNEL_OUT_BACK_RIGHT | CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
180                CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | CHANNEL_OUT_BACK_CENTER |
181                CHANNEL_OUT_SIDE_LEFT | CHANNEL_OUT_SIDE_RIGHT | CHANNEL_OUT_TOP_CENTER |
182                CHANNEL_OUT_TOP_FRONT_LEFT | CHANNEL_OUT_TOP_FRONT_CENTER |
183                CHANNEL_OUT_TOP_FRONT_RIGHT | CHANNEL_OUT_TOP_BACK_LEFT |
184                CHANNEL_OUT_TOP_BACK_CENTER | CHANNEL_OUT_TOP_BACK_RIGHT),
185
186        // input channels
187        CHANNEL_IN_LEFT = 0x4,
188        CHANNEL_IN_RIGHT = 0x8,
189        CHANNEL_IN_FRONT = 0x10,
190        CHANNEL_IN_BACK = 0x20,
191        CHANNEL_IN_LEFT_PROCESSED = 0x40,
192        CHANNEL_IN_RIGHT_PROCESSED = 0x80,
193        CHANNEL_IN_FRONT_PROCESSED = 0x100,
194        CHANNEL_IN_BACK_PROCESSED = 0x200,
195        CHANNEL_IN_PRESSURE = 0x400,
196        CHANNEL_IN_X_AXIS = 0x800,
197        CHANNEL_IN_Y_AXIS = 0x1000,
198        CHANNEL_IN_Z_AXIS = 0x2000,
199        CHANNEL_IN_VOICE_UPLINK = 0x4000,
200        CHANNEL_IN_VOICE_DNLINK = 0x8000,
201        CHANNEL_IN_MONO = CHANNEL_IN_FRONT,
202        CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT),
203        CHANNEL_IN_ALL = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_FRONT | CHANNEL_IN_BACK|
204                CHANNEL_IN_LEFT_PROCESSED | CHANNEL_IN_RIGHT_PROCESSED | CHANNEL_IN_FRONT_PROCESSED | CHANNEL_IN_BACK_PROCESSED|
205                CHANNEL_IN_PRESSURE | CHANNEL_IN_X_AXIS | CHANNEL_IN_Y_AXIS | CHANNEL_IN_Z_AXIS |
206                CHANNEL_IN_VOICE_UPLINK | CHANNEL_IN_VOICE_DNLINK)
207    };
208
209    enum audio_mode {
210        MODE_INVALID = -2,
211        MODE_CURRENT = -1,
212        MODE_NORMAL = 0,
213        MODE_RINGTONE,
214        MODE_IN_CALL,
215        MODE_IN_COMMUNICATION,
216        NUM_MODES  // not a valid entry, denotes end-of-list
217    };
218
219    enum audio_in_acoustics {
220        AGC_ENABLE    = 0x0001,
221        AGC_DISABLE   = 0,
222        NS_ENABLE     = 0x0002,
223        NS_DISABLE    = 0,
224        TX_IIR_ENABLE = 0x0004,
225        TX_DISABLE    = 0
226    };
227
228    // DO NOT USE: the "audio_devices" enumeration below is obsolete, use type "audio_devices_t" and
229    //   audio device enumeration from system/audio.h instead.
230    enum audio_devices {
231        // output devices
232        DEVICE_OUT_EARPIECE = 0x1,
233        DEVICE_OUT_SPEAKER = 0x2,
234        DEVICE_OUT_WIRED_HEADSET = 0x4,
235        DEVICE_OUT_WIRED_HEADPHONE = 0x8,
236        DEVICE_OUT_BLUETOOTH_SCO = 0x10,
237        DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
238        DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
239        DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
240        DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
241        DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
242        DEVICE_OUT_AUX_DIGITAL = 0x400,
243        DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
244        DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
245        DEVICE_OUT_DEFAULT = 0x8000,
246        DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
247                DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
248                DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
249                DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL |
250                DEVICE_OUT_ANLG_DOCK_HEADSET | DEVICE_OUT_DGTL_DOCK_HEADSET |
251                DEVICE_OUT_DEFAULT),
252        DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
253                DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
254
255        // input devices
256        DEVICE_IN_COMMUNICATION = 0x10000,
257        DEVICE_IN_AMBIENT = 0x20000,
258        DEVICE_IN_BUILTIN_MIC = 0x40000,
259        DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
260        DEVICE_IN_WIRED_HEADSET = 0x100000,
261        DEVICE_IN_AUX_DIGITAL = 0x200000,
262        DEVICE_IN_VOICE_CALL = 0x400000,
263        DEVICE_IN_BACK_MIC = 0x800000,
264        DEVICE_IN_DEFAULT = 0x80000000,
265
266        DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC |
267                DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL |
268                DEVICE_IN_VOICE_CALL | DEVICE_IN_BACK_MIC | DEVICE_IN_DEFAULT)
269    };
270
271    // request to open a direct output with getOutput() (by opposition to sharing an output with other AudioTracks)
272    enum output_flags {
273        OUTPUT_FLAG_INDIRECT = 0x0,
274        OUTPUT_FLAG_DIRECT = 0x1
275    };
276
277    // device categories used for setForceUse()
278    enum forced_config {
279        FORCE_NONE,
280        FORCE_SPEAKER,
281        FORCE_HEADPHONES,
282        FORCE_BT_SCO,
283        FORCE_BT_A2DP,
284        FORCE_WIRED_ACCESSORY,
285        FORCE_BT_CAR_DOCK,
286        FORCE_BT_DESK_DOCK,
287        FORCE_ANALOG_DOCK,
288        FORCE_DIGITAL_DOCK,
289        FORCE_NO_BT_A2DP,
290        FORCE_SYSTEM_ENFORCED,
291        NUM_FORCE_CONFIG,
292        FORCE_DEFAULT = FORCE_NONE
293    };
294
295    // usages used for setForceUse()
296    enum force_use {
297        FOR_COMMUNICATION,
298        FOR_MEDIA,
299        FOR_RECORD,
300        FOR_DOCK,
301        FOR_SYSTEM,
302        NUM_FORCE_USE
303    };
304
305    //
306    // AudioPolicyService interface
307    //
308
309    // device connection states used for setDeviceConnectionState()
310    enum device_connection_state {
311        DEVICE_STATE_UNAVAILABLE,
312        DEVICE_STATE_AVAILABLE,
313        NUM_DEVICE_STATES
314    };
315
316#endif
317
318    static uint32_t popCount(uint32_t u) {
319        return popcount(u);
320    }
321
322#if 1
323    static bool isOutputDevice(audio_devices device) {
324        if ((popcount(device) == 1) && ((device & ~DEVICE_OUT_ALL) == 0))
325             return true;
326         else
327             return false;
328    }
329    static bool isInputDevice(audio_devices device) {
330        if ((popcount(device) == 1) && ((device & ~DEVICE_IN_ALL) == 0))
331             return true;
332         else
333             return false;
334    }
335    static bool isA2dpDevice(audio_devices device) {
336        return audio_is_a2dp_device((audio_devices_t)device);
337    }
338    static bool isBluetoothScoDevice(audio_devices device) {
339        return audio_is_bluetooth_sco_device((audio_devices_t)device);
340    }
341    static bool isLowVisibility(stream_type stream) {
342        return audio_is_low_visibility((audio_stream_type_t)stream);
343    }
344    static bool isValidFormat(uint32_t format) {
345        return audio_is_valid_format((audio_format_t) format);
346    }
347    static bool isLinearPCM(uint32_t format) {
348        return audio_is_linear_pcm((audio_format_t) format);
349    }
350    static bool isOutputChannel(uint32_t channel) {
351        return audio_is_output_channel(channel);
352    }
353    static bool isInputChannel(uint32_t channel) {
354        return audio_is_input_channel(channel);
355    }
356
357#endif
358};
359
360};  // namespace android
361
362#endif // ANDROID_AUDIOSYSTEM_LEGACY_H_
363