blob: 3a3a714c9e9db69a7efc206065a7765531f77db5 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
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_H_
18#define ANDROID_AUDIOSYSTEM_H_
19
20#include <utils/RefBase.h>
21#include <utils/threads.h>
22#include <media/IAudioFlinger.h>
23
24namespace android {
25
26typedef void (*audio_error_callback)(status_t err);
27
28class AudioSystem
29{
30public:
31
32 enum stream_type {
33 DEFAULT =-1,
34 VOICE_CALL = 0,
35 SYSTEM = 1,
36 RING = 2,
37 MUSIC = 3,
38 ALARM = 4,
39 NOTIFICATION = 5,
40 BLUETOOTH_SCO = 6,
Eric Laurent29a65002009-03-27 18:18:46 -070041 ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080042 NUM_STREAM_TYPES
43 };
44
45 enum audio_output_type {
46 AUDIO_OUTPUT_DEFAULT =-1,
47 AUDIO_OUTPUT_HARDWARE = 0,
48 AUDIO_OUTPUT_A2DP = 1,
49 NUM_AUDIO_OUTPUT_TYPES
50 };
51
52 enum audio_format {
53 FORMAT_DEFAULT = 0,
54 PCM_16_BIT,
55 PCM_8_BIT,
56 INVALID_FORMAT
57 };
58
59 enum audio_mode {
60 MODE_INVALID = -2,
61 MODE_CURRENT = -1,
62 MODE_NORMAL = 0,
63 MODE_RINGTONE,
64 MODE_IN_CALL,
65 NUM_MODES // not a valid entry, denotes end-of-list
66 };
67
68 enum audio_routes {
69 ROUTE_EARPIECE = (1 << 0),
70 ROUTE_SPEAKER = (1 << 1),
71 ROUTE_BLUETOOTH_SCO = (1 << 2),
72 ROUTE_HEADSET = (1 << 3),
73 ROUTE_BLUETOOTH_A2DP = (1 << 4),
74 ROUTE_ALL = -1UL,
75 };
76
77 enum audio_in_acoustics {
78 AGC_ENABLE = 0x0001,
79 AGC_DISABLE = 0,
80 NS_ENABLE = 0x0002,
81 NS_DISABLE = 0,
82 TX_IIR_ENABLE = 0x0004,
83 TX_DISABLE = 0
84 };
85
86 /* These are static methods to control the system-wide AudioFlinger
87 * only privileged processes can have access to them
88 */
89
90 // routing helper functions
91 static status_t speakerphone(bool state);
92 static status_t isSpeakerphoneOn(bool* state);
93 static status_t bluetoothSco(bool state);
94 static status_t isBluetoothScoOn(bool* state);
95 static status_t muteMicrophone(bool state);
96 static status_t isMicrophoneMuted(bool *state);
97
98 static status_t setMasterVolume(float value);
99 static status_t setMasterMute(bool mute);
100 static status_t getMasterVolume(float* volume);
101 static status_t getMasterMute(bool* mute);
102
103 static status_t setStreamVolume(int stream, float value);
104 static status_t setStreamMute(int stream, bool mute);
105 static status_t getStreamVolume(int stream, float* volume);
106 static status_t getStreamMute(int stream, bool* mute);
107
108 static status_t setMode(int mode);
109 static status_t getMode(int* mode);
110
111 static status_t setRouting(int mode, uint32_t routes, uint32_t mask);
112 static status_t getRouting(int mode, uint32_t* routes);
113
114 static status_t isMusicActive(bool *state);
115
116 // Temporary interface, do not use
117 // TODO: Replace with a more generic key:value get/set mechanism
118 static status_t setParameter(const char* key, const char* value);
119
120 static void setErrorCallback(audio_error_callback cb);
121
122 // helper function to obtain AudioFlinger service handle
123 static const sp<IAudioFlinger>& get_audio_flinger();
124
125 static float linearToLog(int volume);
126 static int logToLinear(float volume);
127
128 static status_t getOutputSamplingRate(int* samplingRate, int stream = DEFAULT);
129 static status_t getOutputFrameCount(int* frameCount, int stream = DEFAULT);
130 static status_t getOutputLatency(uint32_t* latency, int stream = DEFAULT);
131
132 static bool routedToA2dpOutput(int streamType);
133
134 static status_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount,
135 size_t* buffSize);
136
137 // ----------------------------------------------------------------------------
138
139private:
140
141 class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient
142 {
143 public:
144 AudioFlingerClient() {
145 }
146
147 // DeathRecipient
148 virtual void binderDied(const wp<IBinder>& who);
149
150 // IAudioFlingerClient
151 virtual void a2dpEnabledChanged(bool enabled);
152
153 };
154 static int getOutput(int streamType);
155
156 static sp<AudioFlingerClient> gAudioFlingerClient;
157
158 friend class AudioFlingerClient;
159
160 static Mutex gLock;
161 static sp<IAudioFlinger> gAudioFlinger;
162 static audio_error_callback gAudioErrorCallback;
163 static int gOutSamplingRate[NUM_AUDIO_OUTPUT_TYPES];
164 static int gOutFrameCount[NUM_AUDIO_OUTPUT_TYPES];
165 static uint32_t gOutLatency[NUM_AUDIO_OUTPUT_TYPES];
166 static bool gA2dpEnabled;
167
168 static size_t gInBuffSize;
169 // previous parameters for recording buffer size queries
170 static uint32_t gPrevInSamplingRate;
171 static int gPrevInFormat;
172 static int gPrevInChannelCount;
173
174};
175
176}; // namespace android
177
178#endif /*ANDROID_AUDIOSYSTEM_H_*/