The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2007 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 | #define LOG_TAG "AudioSystem" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <utils/Log.h> |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/IServiceManager.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <media/AudioSystem.h> |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 23 | #include <media/IAudioPolicyService.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <math.h> |
| 25 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame^] | 26 | #include <system/audio.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 27 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 28 | // ---------------------------------------------------------------------------- |
| 29 | // the sim build doesn't have gettid |
| 30 | |
| 31 | #ifndef HAVE_GETTID |
| 32 | # define gettid getpid |
| 33 | #endif |
| 34 | |
| 35 | // ---------------------------------------------------------------------------- |
| 36 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | namespace android { |
| 38 | |
| 39 | // client singleton for AudioFlinger binder interface |
| 40 | Mutex AudioSystem::gLock; |
| 41 | sp<IAudioFlinger> AudioSystem::gAudioFlinger; |
| 42 | sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient; |
| 43 | audio_error_callback AudioSystem::gAudioErrorCallback = NULL; |
| 44 | // Cached values |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 45 | DefaultKeyedVector<int, audio_io_handle_t> AudioSystem::gStreamOutputMap(0); |
| 46 | DefaultKeyedVector<audio_io_handle_t, AudioSystem::OutputDescriptor *> AudioSystem::gOutputs(0); |
| 47 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | // Cached values for recording queries |
| 49 | uint32_t AudioSystem::gPrevInSamplingRate = 16000; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 50 | int AudioSystem::gPrevInFormat = AUDIO_FORMAT_PCM_16_BIT; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | int AudioSystem::gPrevInChannelCount = 1; |
| 52 | size_t AudioSystem::gInBuffSize = 0; |
| 53 | |
| 54 | |
| 55 | // establish binder interface to AudioFlinger service |
| 56 | const sp<IAudioFlinger>& AudioSystem::get_audio_flinger() |
| 57 | { |
| 58 | Mutex::Autolock _l(gLock); |
| 59 | if (gAudioFlinger.get() == 0) { |
| 60 | sp<IServiceManager> sm = defaultServiceManager(); |
| 61 | sp<IBinder> binder; |
| 62 | do { |
| 63 | binder = sm->getService(String16("media.audio_flinger")); |
| 64 | if (binder != 0) |
| 65 | break; |
| 66 | LOGW("AudioFlinger not published, waiting..."); |
| 67 | usleep(500000); // 0.5 s |
| 68 | } while(true); |
| 69 | if (gAudioFlingerClient == NULL) { |
| 70 | gAudioFlingerClient = new AudioFlingerClient(); |
| 71 | } else { |
| 72 | if (gAudioErrorCallback) { |
| 73 | gAudioErrorCallback(NO_ERROR); |
| 74 | } |
| 75 | } |
| 76 | binder->linkToDeath(gAudioFlingerClient); |
| 77 | gAudioFlinger = interface_cast<IAudioFlinger>(binder); |
| 78 | gAudioFlinger->registerClient(gAudioFlingerClient); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | } |
| 80 | LOGE_IF(gAudioFlinger==0, "no AudioFlinger!?"); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 81 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | return gAudioFlinger; |
| 83 | } |
| 84 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | status_t AudioSystem::muteMicrophone(bool state) { |
| 86 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 87 | if (af == 0) return PERMISSION_DENIED; |
| 88 | return af->setMicMute(state); |
| 89 | } |
| 90 | |
| 91 | status_t AudioSystem::isMicrophoneMuted(bool* state) { |
| 92 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 93 | if (af == 0) return PERMISSION_DENIED; |
| 94 | *state = af->getMicMute(); |
| 95 | return NO_ERROR; |
| 96 | } |
| 97 | |
| 98 | status_t AudioSystem::setMasterVolume(float value) |
| 99 | { |
| 100 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 101 | if (af == 0) return PERMISSION_DENIED; |
| 102 | af->setMasterVolume(value); |
| 103 | return NO_ERROR; |
| 104 | } |
| 105 | |
| 106 | status_t AudioSystem::setMasterMute(bool mute) |
| 107 | { |
| 108 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 109 | if (af == 0) return PERMISSION_DENIED; |
| 110 | af->setMasterMute(mute); |
| 111 | return NO_ERROR; |
| 112 | } |
| 113 | |
| 114 | status_t AudioSystem::getMasterVolume(float* volume) |
| 115 | { |
| 116 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 117 | if (af == 0) return PERMISSION_DENIED; |
| 118 | *volume = af->masterVolume(); |
| 119 | return NO_ERROR; |
| 120 | } |
| 121 | |
| 122 | status_t AudioSystem::getMasterMute(bool* mute) |
| 123 | { |
| 124 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 125 | if (af == 0) return PERMISSION_DENIED; |
| 126 | *mute = af->masterMute(); |
| 127 | return NO_ERROR; |
| 128 | } |
| 129 | |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 130 | status_t AudioSystem::setStreamVolume(int stream, float value, int output) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 132 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 134 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 135 | af->setStreamVolume(stream, value, output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | return NO_ERROR; |
| 137 | } |
| 138 | |
| 139 | status_t AudioSystem::setStreamMute(int stream, bool mute) |
| 140 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 141 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 143 | if (af == 0) return PERMISSION_DENIED; |
| 144 | af->setStreamMute(stream, mute); |
| 145 | return NO_ERROR; |
| 146 | } |
| 147 | |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 148 | status_t AudioSystem::getStreamVolume(int stream, float* volume, int output) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 150 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 152 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 153 | *volume = af->streamVolume(stream, output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | return NO_ERROR; |
| 155 | } |
| 156 | |
| 157 | status_t AudioSystem::getStreamMute(int stream, bool* mute) |
| 158 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 159 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 161 | if (af == 0) return PERMISSION_DENIED; |
| 162 | *mute = af->streamMute(stream); |
| 163 | return NO_ERROR; |
| 164 | } |
| 165 | |
| 166 | status_t AudioSystem::setMode(int mode) |
| 167 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 168 | if (mode >= AUDIO_MODE_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 170 | if (af == 0) return PERMISSION_DENIED; |
| 171 | return af->setMode(mode); |
| 172 | } |
| 173 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 174 | status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 176 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 177 | return af->setParameters(ioHandle, keyValuePairs); |
| 178 | } |
| 179 | |
| 180 | String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys) { |
| 181 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 182 | String8 result = String8(""); |
| 183 | if (af == 0) return result; |
| 184 | |
| 185 | result = af->getParameters(ioHandle, keys); |
| 186 | return result; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | // convert volume steps to natural log scale |
| 190 | |
| 191 | // change this value to change volume scaling |
| 192 | static const float dBPerStep = 0.5f; |
| 193 | // shouldn't need to touch these |
| 194 | static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f; |
| 195 | static const float dBConvertInverse = 1.0f / dBConvert; |
| 196 | |
| 197 | float AudioSystem::linearToLog(int volume) |
| 198 | { |
| 199 | // float v = volume ? exp(float(100 - volume) * dBConvert) : 0; |
| 200 | // LOGD("linearToLog(%d)=%f", volume, v); |
| 201 | // return v; |
| 202 | return volume ? exp(float(100 - volume) * dBConvert) : 0; |
| 203 | } |
| 204 | |
| 205 | int AudioSystem::logToLinear(float volume) |
| 206 | { |
| 207 | // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
| 208 | // LOGD("logTolinear(%d)=%f", v, volume); |
| 209 | // return v; |
| 210 | return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
| 211 | } |
| 212 | |
| 213 | status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType) |
| 214 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 215 | OutputDescriptor *outputDesc; |
| 216 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 218 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 219 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 222 | output = getOutput((audio_stream_type_t)streamType); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 223 | if (output == 0) { |
| 224 | return PERMISSION_DENIED; |
| 225 | } |
| 226 | |
| 227 | gLock.lock(); |
| 228 | outputDesc = AudioSystem::gOutputs.valueFor(output); |
| 229 | if (outputDesc == 0) { |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 230 | LOGV("getOutputSamplingRate() no output descriptor for output %d in gOutputs", output); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 231 | gLock.unlock(); |
| 232 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 233 | if (af == 0) return PERMISSION_DENIED; |
| 234 | *samplingRate = af->sampleRate(output); |
| 235 | } else { |
| 236 | LOGV("getOutputSamplingRate() reading from output desc"); |
| 237 | *samplingRate = outputDesc->samplingRate; |
| 238 | gLock.unlock(); |
| 239 | } |
| 240 | |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 241 | LOGV("getOutputSamplingRate() streamType %d, output %d, sampling rate %d", streamType, output, *samplingRate); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 242 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | return NO_ERROR; |
| 244 | } |
| 245 | |
| 246 | status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType) |
| 247 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 248 | OutputDescriptor *outputDesc; |
| 249 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 251 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 252 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 253 | } |
Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 254 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 255 | output = getOutput((audio_stream_type_t)streamType); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 256 | if (output == 0) { |
| 257 | return PERMISSION_DENIED; |
| 258 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 260 | gLock.lock(); |
| 261 | outputDesc = AudioSystem::gOutputs.valueFor(output); |
| 262 | if (outputDesc == 0) { |
| 263 | gLock.unlock(); |
| 264 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 265 | if (af == 0) return PERMISSION_DENIED; |
| 266 | *frameCount = af->frameCount(output); |
| 267 | } else { |
| 268 | *frameCount = outputDesc->frameCount; |
| 269 | gLock.unlock(); |
| 270 | } |
| 271 | |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 272 | LOGV("getOutputFrameCount() streamType %d, output %d, frameCount %d", streamType, output, *frameCount); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 273 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | return NO_ERROR; |
| 275 | } |
| 276 | |
| 277 | status_t AudioSystem::getOutputLatency(uint32_t* latency, int streamType) |
| 278 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 279 | OutputDescriptor *outputDesc; |
| 280 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 282 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 283 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 284 | } |
Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 285 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 286 | output = getOutput((audio_stream_type_t)streamType); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 287 | if (output == 0) { |
| 288 | return PERMISSION_DENIED; |
| 289 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 291 | gLock.lock(); |
| 292 | outputDesc = AudioSystem::gOutputs.valueFor(output); |
| 293 | if (outputDesc == 0) { |
| 294 | gLock.unlock(); |
| 295 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 296 | if (af == 0) return PERMISSION_DENIED; |
| 297 | *latency = af->latency(output); |
| 298 | } else { |
| 299 | *latency = outputDesc->latency; |
| 300 | gLock.unlock(); |
| 301 | } |
| 302 | |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 303 | LOGV("getOutputLatency() streamType %d, output %d, latency %d", streamType, output, *latency); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 304 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | return NO_ERROR; |
| 306 | } |
| 307 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 308 | status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, int format, int channelCount, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | size_t* buffSize) |
| 310 | { |
| 311 | // Do we have a stale gInBufferSize or are we requesting the input buffer size for new values |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 312 | if ((gInBuffSize == 0) || (sampleRate != gPrevInSamplingRate) || (format != gPrevInFormat) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | || (channelCount != gPrevInChannelCount)) { |
| 314 | // save the request params |
| 315 | gPrevInSamplingRate = sampleRate; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 316 | gPrevInFormat = format; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | gPrevInChannelCount = channelCount; |
| 318 | |
| 319 | gInBuffSize = 0; |
| 320 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 321 | if (af == 0) { |
| 322 | return PERMISSION_DENIED; |
| 323 | } |
| 324 | gInBuffSize = af->getInputBufferSize(sampleRate, format, channelCount); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 325 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | *buffSize = gInBuffSize; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 327 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | return NO_ERROR; |
| 329 | } |
| 330 | |
Eric Laurent | f0ee6f4 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 331 | status_t AudioSystem::setVoiceVolume(float value) |
| 332 | { |
| 333 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 334 | if (af == 0) return PERMISSION_DENIED; |
| 335 | return af->setVoiceVolume(value); |
| 336 | } |
| 337 | |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 338 | status_t AudioSystem::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int stream) |
| 339 | { |
| 340 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 341 | if (af == 0) return PERMISSION_DENIED; |
| 342 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 343 | if (stream == AUDIO_STREAM_DEFAULT) { |
| 344 | stream = AUDIO_STREAM_MUSIC; |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 347 | return af->getRenderPosition(halFrames, dspFrames, getOutput((audio_stream_type_t)stream)); |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 350 | unsigned int AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) { |
| 351 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 352 | unsigned int result = 0; |
| 353 | if (af == 0) return result; |
Eric Laurent | be55a2d | 2010-03-11 14:47:00 -0800 | [diff] [blame] | 354 | if (ioHandle == 0) return result; |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 355 | |
| 356 | result = af->getInputFramesLost(ioHandle); |
| 357 | return result; |
| 358 | } |
| 359 | |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 360 | int AudioSystem::newAudioSessionId() { |
| 361 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 362 | if (af == 0) return 0; |
| 363 | return af->newAudioSessionId(); |
| 364 | } |
| 365 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | // --------------------------------------------------------------------------- |
| 367 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 368 | void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | Mutex::Autolock _l(AudioSystem::gLock); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 371 | AudioSystem::gAudioFlinger.clear(); |
Eric Laurent | 0ef583f | 2010-01-25 10:27:15 -0800 | [diff] [blame] | 372 | // clear output handles and stream to output map caches |
| 373 | AudioSystem::gStreamOutputMap.clear(); |
| 374 | AudioSystem::gOutputs.clear(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | |
| 376 | if (gAudioErrorCallback) { |
| 377 | gAudioErrorCallback(DEAD_OBJECT); |
| 378 | } |
| 379 | LOGW("AudioFlinger server died!"); |
| 380 | } |
| 381 | |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 382 | void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, int ioHandle, void *param2) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 383 | LOGV("ioConfigChanged() event %d", event); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 384 | OutputDescriptor *desc; |
| 385 | uint32_t stream; |
| 386 | |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 387 | if (ioHandle == 0) return; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 388 | |
| 389 | Mutex::Autolock _l(AudioSystem::gLock); |
| 390 | |
| 391 | switch (event) { |
| 392 | case STREAM_CONFIG_CHANGED: |
| 393 | if (param2 == 0) break; |
| 394 | stream = *(uint32_t *)param2; |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 395 | LOGV("ioConfigChanged() STREAM_CONFIG_CHANGED stream %d, output %d", stream, ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 396 | if (gStreamOutputMap.indexOfKey(stream) >= 0) { |
| 397 | gStreamOutputMap.replaceValueFor(stream, ioHandle); |
| 398 | } |
| 399 | break; |
| 400 | case OUTPUT_OPENED: { |
| 401 | if (gOutputs.indexOfKey(ioHandle) >= 0) { |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 402 | LOGV("ioConfigChanged() opening already existing output! %d", ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 403 | break; |
| 404 | } |
| 405 | if (param2 == 0) break; |
| 406 | desc = (OutputDescriptor *)param2; |
| 407 | |
| 408 | OutputDescriptor *outputDesc = new OutputDescriptor(*desc); |
| 409 | gOutputs.add(ioHandle, outputDesc); |
| 410 | LOGV("ioConfigChanged() new output samplingRate %d, format %d channels %d frameCount %d latency %d", |
| 411 | outputDesc->samplingRate, outputDesc->format, outputDesc->channels, outputDesc->frameCount, outputDesc->latency); |
| 412 | } break; |
| 413 | case OUTPUT_CLOSED: { |
| 414 | if (gOutputs.indexOfKey(ioHandle) < 0) { |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 415 | LOGW("ioConfigChanged() closing unknow output! %d", ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 416 | break; |
| 417 | } |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 418 | LOGV("ioConfigChanged() output %d closed", ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 419 | |
| 420 | gOutputs.removeItem(ioHandle); |
| 421 | for (int i = gStreamOutputMap.size() - 1; i >= 0 ; i--) { |
| 422 | if (gStreamOutputMap.valueAt(i) == ioHandle) { |
| 423 | gStreamOutputMap.removeItemsAt(i); |
| 424 | } |
| 425 | } |
| 426 | } break; |
| 427 | |
| 428 | case OUTPUT_CONFIG_CHANGED: { |
| 429 | int index = gOutputs.indexOfKey(ioHandle); |
| 430 | if (index < 0) { |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 431 | LOGW("ioConfigChanged() modifying unknow output! %d", ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 432 | break; |
| 433 | } |
| 434 | if (param2 == 0) break; |
| 435 | desc = (OutputDescriptor *)param2; |
| 436 | |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 437 | LOGV("ioConfigChanged() new config for output %d samplingRate %d, format %d channels %d frameCount %d latency %d", |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 438 | ioHandle, desc->samplingRate, desc->format, |
| 439 | desc->channels, desc->frameCount, desc->latency); |
| 440 | OutputDescriptor *outputDesc = gOutputs.valueAt(index); |
| 441 | delete outputDesc; |
| 442 | outputDesc = new OutputDescriptor(*desc); |
| 443 | gOutputs.replaceValueFor(ioHandle, outputDesc); |
| 444 | } break; |
| 445 | case INPUT_OPENED: |
| 446 | case INPUT_CLOSED: |
| 447 | case INPUT_CONFIG_CHANGED: |
| 448 | break; |
| 449 | |
| 450 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | void AudioSystem::setErrorCallback(audio_error_callback cb) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 454 | Mutex::Autolock _l(gLock); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | gAudioErrorCallback = cb; |
| 456 | } |
| 457 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | bool AudioSystem::routedToA2dpOutput(int streamType) { |
| 459 | switch(streamType) { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 460 | case AUDIO_STREAM_MUSIC: |
| 461 | case AUDIO_STREAM_VOICE_CALL: |
| 462 | case AUDIO_STREAM_BLUETOOTH_SCO: |
| 463 | case AUDIO_STREAM_SYSTEM: |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | return true; |
| 465 | default: |
| 466 | return false; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 471 | // client singleton for AudioPolicyService binder interface |
| 472 | sp<IAudioPolicyService> AudioSystem::gAudioPolicyService; |
| 473 | sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient; |
| 474 | |
| 475 | |
| 476 | // establish binder interface to AudioFlinger service |
| 477 | const sp<IAudioPolicyService>& AudioSystem::get_audio_policy_service() |
| 478 | { |
| 479 | gLock.lock(); |
| 480 | if (gAudioPolicyService.get() == 0) { |
| 481 | sp<IServiceManager> sm = defaultServiceManager(); |
| 482 | sp<IBinder> binder; |
| 483 | do { |
| 484 | binder = sm->getService(String16("media.audio_policy")); |
| 485 | if (binder != 0) |
| 486 | break; |
| 487 | LOGW("AudioPolicyService not published, waiting..."); |
| 488 | usleep(500000); // 0.5 s |
| 489 | } while(true); |
| 490 | if (gAudioPolicyServiceClient == NULL) { |
| 491 | gAudioPolicyServiceClient = new AudioPolicyServiceClient(); |
| 492 | } |
| 493 | binder->linkToDeath(gAudioPolicyServiceClient); |
| 494 | gAudioPolicyService = interface_cast<IAudioPolicyService>(binder); |
| 495 | gLock.unlock(); |
| 496 | } else { |
| 497 | gLock.unlock(); |
| 498 | } |
| 499 | return gAudioPolicyService; |
| 500 | } |
| 501 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 502 | status_t AudioSystem::setDeviceConnectionState(audio_devices_t device, |
| 503 | audio_policy_dev_state_t state, |
| 504 | const char *device_address) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 505 | { |
| 506 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 507 | if (aps == 0) return PERMISSION_DENIED; |
| 508 | |
| 509 | return aps->setDeviceConnectionState(device, state, device_address); |
| 510 | } |
| 511 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 512 | audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 513 | const char *device_address) |
| 514 | { |
| 515 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 516 | if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 517 | |
| 518 | return aps->getDeviceConnectionState(device, device_address); |
| 519 | } |
| 520 | |
| 521 | status_t AudioSystem::setPhoneState(int state) |
| 522 | { |
| 523 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 524 | if (aps == 0) return PERMISSION_DENIED; |
| 525 | |
| 526 | return aps->setPhoneState(state); |
| 527 | } |
| 528 | |
| 529 | status_t AudioSystem::setRingerMode(uint32_t mode, uint32_t mask) |
| 530 | { |
| 531 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 532 | if (aps == 0) return PERMISSION_DENIED; |
| 533 | return aps->setRingerMode(mode, mask); |
| 534 | } |
| 535 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 536 | status_t AudioSystem::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 537 | { |
| 538 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 539 | if (aps == 0) return PERMISSION_DENIED; |
| 540 | return aps->setForceUse(usage, config); |
| 541 | } |
| 542 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 543 | audio_policy_forced_cfg_t AudioSystem::getForceUse(audio_policy_force_use_t usage) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 544 | { |
| 545 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 546 | if (aps == 0) return AUDIO_POLICY_FORCE_NONE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 547 | return aps->getForceUse(usage); |
| 548 | } |
| 549 | |
| 550 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 551 | audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 552 | uint32_t samplingRate, |
| 553 | uint32_t format, |
| 554 | uint32_t channels, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 555 | audio_policy_output_flags_t flags) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 556 | { |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 557 | audio_io_handle_t output = 0; |
Eric Laurent | be55a2d | 2010-03-11 14:47:00 -0800 | [diff] [blame] | 558 | // Do not use stream to output map cache if the direct output |
| 559 | // flag is set or if we are likely to use a direct output |
| 560 | // (e.g voice call stream @ 8kHz could use BT SCO device and be routed to |
| 561 | // a direct output on some platforms). |
| 562 | // TODO: the output cache and stream to output mapping implementation needs to |
| 563 | // be reworked for proper operation with direct outputs. This code is too specific |
| 564 | // to the first use case we want to cover (Voice Recognition and Voice Dialer over |
| 565 | // Bluetooth SCO |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 566 | if ((flags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT) == 0 && |
| 567 | ((stream != AUDIO_STREAM_VOICE_CALL && stream != AUDIO_STREAM_BLUETOOTH_SCO) || |
| 568 | channels != AUDIO_CHANNEL_OUT_MONO || |
Eric Laurent | be55a2d | 2010-03-11 14:47:00 -0800 | [diff] [blame] | 569 | (samplingRate != 8000 && samplingRate != 16000))) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 570 | Mutex::Autolock _l(gLock); |
| 571 | output = AudioSystem::gStreamOutputMap.valueFor(stream); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 572 | LOGV_IF((output != 0), "getOutput() read %d from cache for stream %d", output, stream); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 573 | } |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 574 | if (output == 0) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 575 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 576 | if (aps == 0) return 0; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 577 | output = aps->getOutput(stream, samplingRate, format, channels, flags); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 578 | if ((flags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT) == 0) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 579 | Mutex::Autolock _l(gLock); |
| 580 | AudioSystem::gStreamOutputMap.add(stream, output); |
| 581 | } |
| 582 | } |
| 583 | return output; |
| 584 | } |
| 585 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 586 | status_t AudioSystem::startOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 587 | audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 588 | int session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 589 | { |
| 590 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 591 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 592 | return aps->startOutput(output, stream, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 595 | status_t AudioSystem::stopOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 596 | audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 597 | int session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 598 | { |
| 599 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 600 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 601 | return aps->stopOutput(output, stream, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | void AudioSystem::releaseOutput(audio_io_handle_t output) |
| 605 | { |
| 606 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 607 | if (aps == 0) return; |
| 608 | aps->releaseOutput(output); |
| 609 | } |
| 610 | |
| 611 | audio_io_handle_t AudioSystem::getInput(int inputSource, |
| 612 | uint32_t samplingRate, |
| 613 | uint32_t format, |
| 614 | uint32_t channels, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 615 | audio_in_acoustics_t acoustics) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 616 | { |
| 617 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 618 | if (aps == 0) return 0; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 619 | return aps->getInput(inputSource, samplingRate, format, channels, acoustics); |
| 620 | } |
| 621 | |
| 622 | status_t AudioSystem::startInput(audio_io_handle_t input) |
| 623 | { |
| 624 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 625 | if (aps == 0) return PERMISSION_DENIED; |
| 626 | return aps->startInput(input); |
| 627 | } |
| 628 | |
| 629 | status_t AudioSystem::stopInput(audio_io_handle_t input) |
| 630 | { |
| 631 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 632 | if (aps == 0) return PERMISSION_DENIED; |
| 633 | return aps->stopInput(input); |
| 634 | } |
| 635 | |
| 636 | void AudioSystem::releaseInput(audio_io_handle_t input) |
| 637 | { |
| 638 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 639 | if (aps == 0) return; |
| 640 | aps->releaseInput(input); |
| 641 | } |
| 642 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 643 | status_t AudioSystem::initStreamVolume(audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 644 | int indexMin, |
| 645 | int indexMax) |
| 646 | { |
| 647 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 648 | if (aps == 0) return PERMISSION_DENIED; |
| 649 | return aps->initStreamVolume(stream, indexMin, indexMax); |
| 650 | } |
| 651 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 652 | status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream, int index) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 653 | { |
| 654 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 655 | if (aps == 0) return PERMISSION_DENIED; |
| 656 | return aps->setStreamVolumeIndex(stream, index); |
| 657 | } |
| 658 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 659 | status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream, int *index) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 660 | { |
| 661 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 662 | if (aps == 0) return PERMISSION_DENIED; |
| 663 | return aps->getStreamVolumeIndex(stream, index); |
| 664 | } |
| 665 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 666 | uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 667 | { |
| 668 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 669 | if (aps == 0) return 0; |
| 670 | return aps->getStrategyForStream(stream); |
| 671 | } |
| 672 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 673 | uint32_t AudioSystem::getDevicesForStream(audio_stream_type_t stream) |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 674 | { |
| 675 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 676 | if (aps == 0) return 0; |
| 677 | return aps->getDevicesForStream(stream); |
| 678 | } |
| 679 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 680 | audio_io_handle_t AudioSystem::getOutputForEffect(effect_descriptor_t *desc) |
| 681 | { |
| 682 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 683 | if (aps == 0) return PERMISSION_DENIED; |
| 684 | return aps->getOutputForEffect(desc); |
| 685 | } |
| 686 | |
| 687 | status_t AudioSystem::registerEffect(effect_descriptor_t *desc, |
| 688 | audio_io_handle_t output, |
| 689 | uint32_t strategy, |
| 690 | int session, |
| 691 | int id) |
| 692 | { |
| 693 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 694 | if (aps == 0) return PERMISSION_DENIED; |
| 695 | return aps->registerEffect(desc, output, strategy, session, id); |
| 696 | } |
| 697 | |
| 698 | status_t AudioSystem::unregisterEffect(int id) |
| 699 | { |
| 700 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 701 | if (aps == 0) return PERMISSION_DENIED; |
| 702 | return aps->unregisterEffect(id); |
| 703 | } |
| 704 | |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 705 | status_t AudioSystem::isStreamActive(int stream, bool* state, uint32_t inPastMs) { |
| 706 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 707 | if (aps == 0) return PERMISSION_DENIED; |
| 708 | *state = aps->isStreamActive(stream, inPastMs); |
| 709 | return NO_ERROR; |
| 710 | } |
| 711 | |
| 712 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 713 | // --------------------------------------------------------------------------- |
| 714 | |
| 715 | void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who) { |
| 716 | Mutex::Autolock _l(AudioSystem::gLock); |
| 717 | AudioSystem::gAudioPolicyService.clear(); |
| 718 | |
| 719 | LOGW("AudioPolicyService server died!"); |
| 720 | } |
| 721 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | }; // namespace android |
| 723 | |