| 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> | 
| Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 22 | #include <binder/ProcessState.h> | 
| François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 23 | #include <binder/IPCThreadState.h> | 
| Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 24 | #include <media/AudioResamplerPublic.h> | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <media/AudioSystem.h> | 
| Glenn Kasten | 1ab85ec | 2013-05-31 09:18:43 -0700 | [diff] [blame] | 26 | #include <media/IAudioFlinger.h> | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 27 | #include <media/IAudioPolicyService.h> | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <math.h> | 
 | 29 |  | 
| Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 30 | #include <system/audio.h> | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 31 |  | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 32 | // ---------------------------------------------------------------------------- | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 33 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | namespace android { | 
 | 35 |  | 
 | 36 | // client singleton for AudioFlinger binder interface | 
 | 37 | Mutex AudioSystem::gLock; | 
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 38 | Mutex AudioSystem::gLockAPS; | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | sp<IAudioFlinger> AudioSystem::gAudioFlinger; | 
 | 40 | sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient; | 
 | 41 | audio_error_callback AudioSystem::gAudioErrorCallback = NULL; | 
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 42 | dynamic_policy_callback AudioSystem::gDynPolicyCallback = NULL; | 
| Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 43 | record_config_callback AudioSystem::gRecordConfigCallback = NULL; | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | // establish binder interface to AudioFlinger service | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 46 | const sp<IAudioFlinger> AudioSystem::get_audio_flinger() | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | { | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 48 |     sp<IAudioFlinger> af; | 
 | 49 |     sp<AudioFlingerClient> afc; | 
 | 50 |     { | 
 | 51 |         Mutex::Autolock _l(gLock); | 
 | 52 |         if (gAudioFlinger == 0) { | 
 | 53 |             sp<IServiceManager> sm = defaultServiceManager(); | 
 | 54 |             sp<IBinder> binder; | 
 | 55 |             do { | 
 | 56 |                 binder = sm->getService(String16("media.audio_flinger")); | 
 | 57 |                 if (binder != 0) | 
 | 58 |                     break; | 
 | 59 |                 ALOGW("AudioFlinger not published, waiting..."); | 
 | 60 |                 usleep(500000); // 0.5 s | 
 | 61 |             } while (true); | 
 | 62 |             if (gAudioFlingerClient == NULL) { | 
 | 63 |                 gAudioFlingerClient = new AudioFlingerClient(); | 
 | 64 |             } else { | 
 | 65 |                 if (gAudioErrorCallback) { | 
 | 66 |                     gAudioErrorCallback(NO_ERROR); | 
 | 67 |                 } | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 |             } | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 69 |             binder->linkToDeath(gAudioFlingerClient); | 
 | 70 |             gAudioFlinger = interface_cast<IAudioFlinger>(binder); | 
 | 71 |             LOG_ALWAYS_FATAL_IF(gAudioFlinger == 0); | 
 | 72 |             afc = gAudioFlingerClient; | 
| Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 73 |             // Make sure callbacks can be received by gAudioFlingerClient | 
 | 74 |             ProcessState::self()->startThreadPool(); | 
| Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 75 |         } | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 76 |         af = gAudioFlinger; | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 |     } | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 78 |     if (afc != 0) { | 
| François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 79 |         int64_t token = IPCThreadState::self()->clearCallingIdentity(); | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 80 |         af->registerClient(afc); | 
| François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 81 |         IPCThreadState::self()->restoreCallingIdentity(token); | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 82 |     } | 
 | 83 |     return af; | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | } | 
 | 85 |  | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 86 | const sp<AudioSystem::AudioFlingerClient> AudioSystem::getAudioFlingerClient() | 
 | 87 | { | 
 | 88 |     // calling get_audio_flinger() will initialize gAudioFlingerClient if needed | 
 | 89 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 90 |     if (af == 0) return 0; | 
 | 91 |     Mutex::Autolock _l(gLock); | 
 | 92 |     return gAudioFlingerClient; | 
 | 93 | } | 
 | 94 |  | 
 | 95 | sp<AudioIoDescriptor> AudioSystem::getIoDescriptor(audio_io_handle_t ioHandle) | 
 | 96 | { | 
 | 97 |     sp<AudioIoDescriptor> desc; | 
 | 98 |     const sp<AudioFlingerClient> afc = getAudioFlingerClient(); | 
 | 99 |     if (afc != 0) { | 
 | 100 |         desc = afc->getIoDescriptor(ioHandle); | 
 | 101 |     } | 
 | 102 |     return desc; | 
 | 103 | } | 
 | 104 |  | 
| Eric Laurent | 4629161 | 2013-07-18 14:38:44 -0700 | [diff] [blame] | 105 | /* static */ status_t AudioSystem::checkAudioFlinger() | 
 | 106 | { | 
 | 107 |     if (defaultServiceManager()->checkService(String16("media.audio_flinger")) != 0) { | 
 | 108 |         return NO_ERROR; | 
 | 109 |     } | 
 | 110 |     return DEAD_OBJECT; | 
 | 111 | } | 
 | 112 |  | 
| Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 113 | // FIXME Declare in binder opcode order, similarly to IAudioFlinger.h and IAudioFlinger.cpp | 
 | 114 |  | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 115 | status_t AudioSystem::muteMicrophone(bool state) | 
 | 116 | { | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 118 |     if (af == 0) return PERMISSION_DENIED; | 
 | 119 |     return af->setMicMute(state); | 
 | 120 | } | 
 | 121 |  | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 122 | status_t AudioSystem::isMicrophoneMuted(bool* state) | 
 | 123 | { | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 125 |     if (af == 0) return PERMISSION_DENIED; | 
 | 126 |     *state = af->getMicMute(); | 
 | 127 |     return NO_ERROR; | 
 | 128 | } | 
 | 129 |  | 
 | 130 | status_t AudioSystem::setMasterVolume(float value) | 
 | 131 | { | 
 | 132 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 133 |     if (af == 0) return PERMISSION_DENIED; | 
 | 134 |     af->setMasterVolume(value); | 
 | 135 |     return NO_ERROR; | 
 | 136 | } | 
 | 137 |  | 
 | 138 | status_t AudioSystem::setMasterMute(bool mute) | 
 | 139 | { | 
 | 140 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 141 |     if (af == 0) return PERMISSION_DENIED; | 
 | 142 |     af->setMasterMute(mute); | 
 | 143 |     return NO_ERROR; | 
 | 144 | } | 
 | 145 |  | 
 | 146 | status_t AudioSystem::getMasterVolume(float* volume) | 
 | 147 | { | 
 | 148 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 149 |     if (af == 0) return PERMISSION_DENIED; | 
 | 150 |     *volume = af->masterVolume(); | 
 | 151 |     return NO_ERROR; | 
 | 152 | } | 
 | 153 |  | 
 | 154 | status_t AudioSystem::getMasterMute(bool* mute) | 
 | 155 | { | 
 | 156 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 157 |     if (af == 0) return PERMISSION_DENIED; | 
 | 158 |     *mute = af->masterMute(); | 
 | 159 |     return NO_ERROR; | 
 | 160 | } | 
 | 161 |  | 
| Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 162 | status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value, | 
 | 163 |         audio_io_handle_t output) | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | { | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 165 |     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] | 166 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 167 |     if (af == 0) return PERMISSION_DENIED; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 168 |     af->setStreamVolume(stream, value, output); | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 |     return NO_ERROR; | 
 | 170 | } | 
 | 171 |  | 
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 172 | status_t AudioSystem::setStreamMute(audio_stream_type_t stream, bool mute) | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | { | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 174 |     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] | 175 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 176 |     if (af == 0) return PERMISSION_DENIED; | 
 | 177 |     af->setStreamMute(stream, mute); | 
 | 178 |     return NO_ERROR; | 
 | 179 | } | 
 | 180 |  | 
| Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 181 | status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume, | 
 | 182 |         audio_io_handle_t output) | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | { | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 184 |     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] | 185 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 186 |     if (af == 0) return PERMISSION_DENIED; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 187 |     *volume = af->streamVolume(stream, output); | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 |     return NO_ERROR; | 
 | 189 | } | 
 | 190 |  | 
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 191 | status_t AudioSystem::getStreamMute(audio_stream_type_t stream, bool* mute) | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | { | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 193 |     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] | 194 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 195 |     if (af == 0) return PERMISSION_DENIED; | 
 | 196 |     *mute = af->streamMute(stream); | 
 | 197 |     return NO_ERROR; | 
 | 198 | } | 
 | 199 |  | 
| Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 200 | status_t AudioSystem::setMode(audio_mode_t mode) | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | { | 
| Glenn Kasten | 930f4ca | 2012-01-06 16:47:31 -0800 | [diff] [blame] | 202 |     if (uint32_t(mode) >= AUDIO_MODE_CNT) return BAD_VALUE; | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 204 |     if (af == 0) return PERMISSION_DENIED; | 
 | 205 |     return af->setMode(mode); | 
 | 206 | } | 
 | 207 |  | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 208 | status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) | 
 | 209 | { | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 211 |     if (af == 0) return PERMISSION_DENIED; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 212 |     return af->setParameters(ioHandle, keyValuePairs); | 
 | 213 | } | 
 | 214 |  | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 215 | String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys) | 
 | 216 | { | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 217 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 218 |     String8 result = String8(""); | 
 | 219 |     if (af == 0) return result; | 
 | 220 |  | 
 | 221 |     result = af->getParameters(ioHandle, keys); | 
 | 222 |     return result; | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | } | 
 | 224 |  | 
| Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 225 | status_t AudioSystem::setParameters(const String8& keyValuePairs) | 
 | 226 | { | 
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 227 |     return setParameters(AUDIO_IO_HANDLE_NONE, keyValuePairs); | 
| Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 228 | } | 
 | 229 |  | 
 | 230 | String8 AudioSystem::getParameters(const String8& keys) | 
 | 231 | { | 
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 232 |     return getParameters(AUDIO_IO_HANDLE_NONE, keys); | 
| Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 233 | } | 
 | 234 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | // convert volume steps to natural log scale | 
 | 236 |  | 
 | 237 | // change this value to change volume scaling | 
 | 238 | static const float dBPerStep = 0.5f; | 
 | 239 | // shouldn't need to touch these | 
 | 240 | static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f; | 
 | 241 | static const float dBConvertInverse = 1.0f / dBConvert; | 
 | 242 |  | 
 | 243 | float AudioSystem::linearToLog(int volume) | 
 | 244 | { | 
 | 245 |     // float v = volume ? exp(float(100 - volume) * dBConvert) : 0; | 
| Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 246 |     // ALOGD("linearToLog(%d)=%f", volume, v); | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 |     // return v; | 
 | 248 |     return volume ? exp(float(100 - volume) * dBConvert) : 0; | 
 | 249 | } | 
 | 250 |  | 
 | 251 | int AudioSystem::logToLinear(float volume) | 
 | 252 | { | 
 | 253 |     // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; | 
| Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 254 |     // ALOGD("logTolinear(%d)=%f", v, volume); | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 |     // return v; | 
 | 256 |     return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; | 
 | 257 | } | 
 | 258 |  | 
| Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 259 | /* static */ size_t AudioSystem::calculateMinFrameCount( | 
 | 260 |         uint32_t afLatencyMs, uint32_t afFrameCount, uint32_t afSampleRate, | 
 | 261 |         uint32_t sampleRate, float speed /*, uint32_t notificationsPerBufferReq*/) | 
 | 262 | { | 
 | 263 |     // Ensure that buffer depth covers at least audio hardware latency | 
 | 264 |     uint32_t minBufCount = afLatencyMs / ((1000 * afFrameCount) / afSampleRate); | 
 | 265 |     if (minBufCount < 2) { | 
 | 266 |         minBufCount = 2; | 
 | 267 |     } | 
 | 268 | #if 0 | 
 | 269 |     // The notificationsPerBufferReq parameter is not yet used for non-fast tracks, | 
 | 270 |     // but keeping the code here to make it easier to add later. | 
 | 271 |     if (minBufCount < notificationsPerBufferReq) { | 
 | 272 |         minBufCount = notificationsPerBufferReq; | 
 | 273 |     } | 
 | 274 | #endif | 
 | 275 |     ALOGV("calculateMinFrameCount afLatency %u  afFrameCount %u  afSampleRate %u  " | 
 | 276 |             "sampleRate %u  speed %f  minBufCount: %u" /*"  notificationsPerBufferReq %u"*/, | 
 | 277 |             afLatencyMs, afFrameCount, afSampleRate, sampleRate, speed, minBufCount | 
 | 278 |             /*, notificationsPerBufferReq*/); | 
 | 279 |     return minBufCount * sourceFramesNeededWithTimestretch( | 
 | 280 |             sampleRate, afFrameCount, afSampleRate, speed); | 
 | 281 | } | 
 | 282 |  | 
 | 283 |  | 
| Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 284 | status_t AudioSystem::getOutputSamplingRate(uint32_t* samplingRate, audio_stream_type_t streamType) | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | { | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 286 |     audio_io_handle_t output; | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 |  | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 288 |     if (streamType == AUDIO_STREAM_DEFAULT) { | 
 | 289 |         streamType = AUDIO_STREAM_MUSIC; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 290 |     } | 
 | 291 |  | 
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 292 |     output = getOutput(streamType); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 293 |     if (output == 0) { | 
 | 294 |         return PERMISSION_DENIED; | 
 | 295 |     } | 
 | 296 |  | 
| Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 297 |     return getSamplingRate(output, samplingRate); | 
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 298 | } | 
 | 299 |  | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 300 | status_t AudioSystem::getSamplingRate(audio_io_handle_t ioHandle, | 
| Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 301 |                                       uint32_t* samplingRate) | 
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 302 | { | 
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 303 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 304 |     if (af == 0) return PERMISSION_DENIED; | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 305 |     sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); | 
 | 306 |     if (desc == 0) { | 
 | 307 |         *samplingRate = af->sampleRate(ioHandle); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 308 |     } else { | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 309 |         *samplingRate = desc->mSamplingRate; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 310 |     } | 
| Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 311 |     if (*samplingRate == 0) { | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 312 |         ALOGE("AudioSystem::getSamplingRate failed for ioHandle %d", ioHandle); | 
| Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 313 |         return BAD_VALUE; | 
 | 314 |     } | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 315 |  | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 316 |     ALOGV("getSamplingRate() ioHandle %d, sampling rate %u", ioHandle, *samplingRate); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 317 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 |     return NO_ERROR; | 
 | 319 | } | 
 | 320 |  | 
| Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 321 | status_t AudioSystem::getOutputFrameCount(size_t* frameCount, audio_stream_type_t streamType) | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | { | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 323 |     audio_io_handle_t output; | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 |  | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 325 |     if (streamType == AUDIO_STREAM_DEFAULT) { | 
 | 326 |         streamType = AUDIO_STREAM_MUSIC; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 327 |     } | 
| Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 328 |  | 
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 329 |     output = getOutput(streamType); | 
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 330 |     if (output == AUDIO_IO_HANDLE_NONE) { | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 331 |         return PERMISSION_DENIED; | 
 | 332 |     } | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 |  | 
| Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 334 |     return getFrameCount(output, frameCount); | 
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 335 | } | 
 | 336 |  | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 337 | status_t AudioSystem::getFrameCount(audio_io_handle_t ioHandle, | 
| Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 338 |                                     size_t* frameCount) | 
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 339 | { | 
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 340 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 341 |     if (af == 0) return PERMISSION_DENIED; | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 342 |     sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); | 
 | 343 |     if (desc == 0) { | 
 | 344 |         *frameCount = af->frameCount(ioHandle); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 345 |     } else { | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 346 |         *frameCount = desc->mFrameCount; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 347 |     } | 
| Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 348 |     if (*frameCount == 0) { | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 349 |         ALOGE("AudioSystem::getFrameCount failed for ioHandle %d", ioHandle); | 
| Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 350 |         return BAD_VALUE; | 
 | 351 |     } | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 352 |  | 
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 353 |     ALOGV("getFrameCount() ioHandle %d, frameCount %zu", ioHandle, *frameCount); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 354 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 |     return NO_ERROR; | 
 | 356 | } | 
 | 357 |  | 
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 358 | status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType) | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | { | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 360 |     audio_io_handle_t output; | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 |  | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 362 |     if (streamType == AUDIO_STREAM_DEFAULT) { | 
 | 363 |         streamType = AUDIO_STREAM_MUSIC; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 364 |     } | 
| Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 365 |  | 
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 366 |     output = getOutput(streamType); | 
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 367 |     if (output == AUDIO_IO_HANDLE_NONE) { | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 368 |         return PERMISSION_DENIED; | 
 | 369 |     } | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 |  | 
| Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 371 |     return getLatency(output, latency); | 
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 372 | } | 
 | 373 |  | 
 | 374 | status_t AudioSystem::getLatency(audio_io_handle_t output, | 
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 375 |                                  uint32_t* latency) | 
 | 376 | { | 
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 377 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 378 |     if (af == 0) return PERMISSION_DENIED; | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 379 |     sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output); | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 380 |     if (outputDesc == 0) { | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 381 |         *latency = af->latency(output); | 
 | 382 |     } else { | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 383 |         *latency = outputDesc->mLatency; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 384 |     } | 
 | 385 |  | 
| Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 386 |     ALOGV("getLatency() output %d, latency %d", output, *latency); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 387 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 |     return NO_ERROR; | 
 | 389 | } | 
 | 390 |  | 
| Glenn Kasten | dd8104c | 2012-07-02 12:42:44 -0700 | [diff] [blame] | 391 | status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format, | 
 | 392 |         audio_channel_mask_t channelMask, size_t* buffSize) | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | { | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 394 |     const sp<AudioFlingerClient> afc = getAudioFlingerClient(); | 
 | 395 |     if (afc == 0) { | 
 | 396 |         return NO_INIT; | 
 | 397 |     } | 
 | 398 |     return afc->getInputBufferSize(sampleRate, format, channelMask, buffSize); | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | } | 
 | 400 |  | 
| Eric Laurent | f0ee6f4 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 401 | status_t AudioSystem::setVoiceVolume(float value) | 
 | 402 | { | 
 | 403 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 404 |     if (af == 0) return PERMISSION_DENIED; | 
 | 405 |     return af->setVoiceVolume(value); | 
 | 406 | } | 
 | 407 |  | 
| Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 408 | status_t AudioSystem::getRenderPosition(audio_io_handle_t output, uint32_t *halFrames, | 
| Glenn Kasten | 0ed1959 | 2014-03-26 07:50:05 -0700 | [diff] [blame] | 409 |                                         uint32_t *dspFrames) | 
| Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 410 | { | 
 | 411 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 412 |     if (af == 0) return PERMISSION_DENIED; | 
 | 413 |  | 
| Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 414 |     return af->getRenderPosition(halFrames, dspFrames, output); | 
| Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 415 | } | 
 | 416 |  | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 417 | uint32_t AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) | 
 | 418 | { | 
| Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 419 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
| Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 420 |     uint32_t result = 0; | 
| Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 421 |     if (af == 0) return result; | 
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 422 |     if (ioHandle == AUDIO_IO_HANDLE_NONE) return result; | 
| Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 423 |  | 
 | 424 |     result = af->getInputFramesLost(ioHandle); | 
 | 425 |     return result; | 
 | 426 | } | 
 | 427 |  | 
| Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 428 | audio_unique_id_t AudioSystem::newAudioUniqueId(audio_unique_id_use_t use) | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 429 | { | 
| Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 430 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
| Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 431 |     if (af == 0) return AUDIO_UNIQUE_ID_ALLOCATE; | 
| Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 432 |     return af->newAudioUniqueId(use); | 
| Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 433 | } | 
 | 434 |  | 
| Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 435 | void AudioSystem::acquireAudioSessionId(audio_session_t audioSession, pid_t pid) | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 436 | { | 
| Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 437 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 438 |     if (af != 0) { | 
| Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 439 |         af->acquireAudioSessionId(audioSession, pid); | 
| Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 440 |     } | 
 | 441 | } | 
 | 442 |  | 
| Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 443 | void AudioSystem::releaseAudioSessionId(audio_session_t audioSession, pid_t pid) | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 444 | { | 
| Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 445 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 446 |     if (af != 0) { | 
| Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 447 |         af->releaseAudioSessionId(audioSession, pid); | 
| Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 448 |     } | 
 | 449 | } | 
 | 450 |  | 
| Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 451 | audio_hw_sync_t AudioSystem::getAudioHwSyncForSession(audio_session_t sessionId) | 
 | 452 | { | 
 | 453 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 454 |     if (af == 0) return AUDIO_HW_SYNC_INVALID; | 
 | 455 |     return af->getAudioHwSyncForSession(sessionId); | 
 | 456 | } | 
 | 457 |  | 
| Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 458 | status_t AudioSystem::systemReady() | 
 | 459 | { | 
 | 460 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 461 |     if (af == 0) return NO_INIT; | 
 | 462 |     return af->systemReady(); | 
 | 463 | } | 
 | 464 |  | 
| Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 465 | status_t AudioSystem::getFrameCountHAL(audio_io_handle_t ioHandle, | 
 | 466 |                                        size_t* frameCount) | 
 | 467 | { | 
 | 468 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 469 |     if (af == 0) return PERMISSION_DENIED; | 
 | 470 |     sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); | 
 | 471 |     if (desc == 0) { | 
 | 472 |         *frameCount = af->frameCountHAL(ioHandle); | 
 | 473 |     } else { | 
 | 474 |         *frameCount = desc->mFrameCountHAL; | 
 | 475 |     } | 
 | 476 |     if (*frameCount == 0) { | 
 | 477 |         ALOGE("AudioSystem::getFrameCountHAL failed for ioHandle %d", ioHandle); | 
 | 478 |         return BAD_VALUE; | 
 | 479 |     } | 
 | 480 |  | 
 | 481 |     ALOGV("getFrameCountHAL() ioHandle %d, frameCount %zu", ioHandle, *frameCount); | 
 | 482 |  | 
 | 483 |     return NO_ERROR; | 
 | 484 | } | 
 | 485 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | // --------------------------------------------------------------------------- | 
 | 487 |  | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 488 |  | 
 | 489 | void AudioSystem::AudioFlingerClient::clearIoCache() | 
 | 490 | { | 
 | 491 |     Mutex::Autolock _l(mLock); | 
 | 492 |     mIoDescriptors.clear(); | 
 | 493 |     mInBuffSize = 0; | 
 | 494 |     mInSamplingRate = 0; | 
 | 495 |     mInFormat = AUDIO_FORMAT_DEFAULT; | 
 | 496 |     mInChannelMask = AUDIO_CHANNEL_NONE; | 
 | 497 | } | 
 | 498 |  | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 499 | void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who __unused) | 
 | 500 | { | 
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 501 |     audio_error_callback cb = NULL; | 
 | 502 |     { | 
 | 503 |         Mutex::Autolock _l(AudioSystem::gLock); | 
 | 504 |         AudioSystem::gAudioFlinger.clear(); | 
 | 505 |         cb = gAudioErrorCallback; | 
 | 506 |     } | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 |  | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 508 |     // clear output handles and stream to output map caches | 
 | 509 |     clearIoCache(); | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 |  | 
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 511 |     if (cb) { | 
 | 512 |         cb(DEAD_OBJECT); | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 |     } | 
| Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 514 |     ALOGW("AudioFlinger server died!"); | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | } | 
 | 516 |  | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 517 | void AudioSystem::AudioFlingerClient::ioConfigChanged(audio_io_config_event event, | 
 | 518 |                                                       const sp<AudioIoDescriptor>& ioDesc) { | 
| Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 519 |     ALOGV("ioConfigChanged() event %d", event); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 520 |  | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 521 |     if (ioDesc == 0 || ioDesc->mIoHandle == AUDIO_IO_HANDLE_NONE) return; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 522 |  | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 523 |     audio_port_handle_t deviceId = AUDIO_PORT_HANDLE_NONE; | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 524 |     Vector < wp<AudioDeviceCallback> > callbacks; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 525 |  | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 526 |     { | 
 | 527 |         Mutex::Autolock _l(mLock); | 
 | 528 |  | 
 | 529 |         switch (event) { | 
 | 530 |         case AUDIO_OUTPUT_OPENED: | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 531 |         case AUDIO_OUTPUT_REGISTERED: | 
 | 532 |         case AUDIO_INPUT_OPENED: | 
 | 533 |         case AUDIO_INPUT_REGISTERED: { | 
| Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 534 |             sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle); | 
| Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 535 |             if (oldDesc == 0) { | 
 | 536 |                 mIoDescriptors.add(ioDesc->mIoHandle, ioDesc); | 
 | 537 |             } else { | 
 | 538 |                 deviceId = oldDesc->getDeviceId(); | 
 | 539 |                 mIoDescriptors.replaceValueFor(ioDesc->mIoHandle, ioDesc); | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 540 |             } | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 541 |  | 
 | 542 |             if (ioDesc->getDeviceId() != AUDIO_PORT_HANDLE_NONE) { | 
 | 543 |                 deviceId = ioDesc->getDeviceId(); | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 544 |                 if (event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED) { | 
 | 545 |                     ssize_t ioIndex = mAudioDeviceCallbacks.indexOfKey(ioDesc->mIoHandle); | 
 | 546 |                     if (ioIndex >= 0) { | 
 | 547 |                         callbacks = mAudioDeviceCallbacks.valueAt(ioIndex); | 
 | 548 |                     } | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 549 |                 } | 
 | 550 |             } | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 551 |             ALOGV("ioConfigChanged() new %s %s %d samplingRate %u, format %#x channel mask %#x " | 
 | 552 |                     "frameCount %zu deviceId %d", | 
 | 553 |                     event == AUDIO_OUTPUT_OPENED || event == AUDIO_OUTPUT_REGISTERED ? | 
 | 554 |                             "output" : "input", | 
 | 555 |                             event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED ? | 
 | 556 |                             "opened" : "registered", | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 557 |                     ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat, ioDesc->mChannelMask, | 
 | 558 |                     ioDesc->mFrameCount, ioDesc->getDeviceId()); | 
 | 559 |             } break; | 
 | 560 |         case AUDIO_OUTPUT_CLOSED: | 
 | 561 |         case AUDIO_INPUT_CLOSED: { | 
| Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 562 |             if (getIoDescriptor_l(ioDesc->mIoHandle) == 0) { | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 563 |                 ALOGW("ioConfigChanged() closing unknown %s %d", | 
 | 564 |                       event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle); | 
 | 565 |                 break; | 
 | 566 |             } | 
 | 567 |             ALOGV("ioConfigChanged() %s %d closed", | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 568 |                   event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 569 |  | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 570 |             mIoDescriptors.removeItem(ioDesc->mIoHandle); | 
 | 571 |             mAudioDeviceCallbacks.removeItem(ioDesc->mIoHandle); | 
 | 572 |             } break; | 
 | 573 |  | 
 | 574 |         case AUDIO_OUTPUT_CONFIG_CHANGED: | 
 | 575 |         case AUDIO_INPUT_CONFIG_CHANGED: { | 
| Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 576 |             sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle); | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 577 |             if (oldDesc == 0) { | 
 | 578 |                 ALOGW("ioConfigChanged() modifying unknown output! %d", ioDesc->mIoHandle); | 
 | 579 |                 break; | 
 | 580 |             } | 
 | 581 |  | 
 | 582 |             deviceId = oldDesc->getDeviceId(); | 
 | 583 |             mIoDescriptors.replaceValueFor(ioDesc->mIoHandle, ioDesc); | 
 | 584 |  | 
 | 585 |             if (deviceId != ioDesc->getDeviceId()) { | 
 | 586 |                 deviceId = ioDesc->getDeviceId(); | 
 | 587 |                 ssize_t ioIndex = mAudioDeviceCallbacks.indexOfKey(ioDesc->mIoHandle); | 
 | 588 |                 if (ioIndex >= 0) { | 
 | 589 |                     callbacks = mAudioDeviceCallbacks.valueAt(ioIndex); | 
 | 590 |                 } | 
 | 591 |             } | 
 | 592 |             ALOGV("ioConfigChanged() new config for %s %d samplingRate %u, format %#x " | 
| Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 593 |                     "channel mask %#x frameCount %zu frameCountHAL %zu deviceId %d", | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 594 |                     event == AUDIO_OUTPUT_CONFIG_CHANGED ? "output" : "input", | 
 | 595 |                     ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat, | 
| Glenn Kasten | d3bb645 | 2016-12-05 18:14:37 -0800 | [diff] [blame] | 596 |                     ioDesc->mChannelMask, ioDesc->mFrameCount, ioDesc->mFrameCountHAL, | 
 | 597 |                     ioDesc->getDeviceId()); | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 598 |  | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 599 |         } break; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 600 |         } | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 601 |     } | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 602 |     bool callbackRemoved = false; | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 603 |     // callbacks.size() != 0 =>  ioDesc->mIoHandle and deviceId are valid | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 604 |     for (size_t i = 0; i < callbacks.size(); ) { | 
 | 605 |         sp<AudioDeviceCallback> callback = callbacks[i].promote(); | 
 | 606 |         if (callback.get() != nullptr) { | 
 | 607 |             callback->onAudioDeviceUpdate(ioDesc->mIoHandle, deviceId); | 
 | 608 |             i++; | 
 | 609 |         } else { | 
 | 610 |             callbacks.removeAt(i); | 
 | 611 |             callbackRemoved = true; | 
 | 612 |         } | 
 | 613 |     } | 
 | 614 |     // clean up callback list while we are here if some clients have disappeared without | 
 | 615 |     // unregistering their callback | 
 | 616 |     if (callbackRemoved) { | 
 | 617 |         Mutex::Autolock _l(mLock); | 
 | 618 |         mAudioDeviceCallbacks.replaceValueFor(ioDesc->mIoHandle, callbacks); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 619 |     } | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | } | 
 | 621 |  | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 622 | status_t AudioSystem::AudioFlingerClient::getInputBufferSize( | 
 | 623 |                                                 uint32_t sampleRate, audio_format_t format, | 
 | 624 |                                                 audio_channel_mask_t channelMask, size_t* buffSize) | 
 | 625 | { | 
 | 626 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 627 |     if (af == 0) { | 
 | 628 |         return PERMISSION_DENIED; | 
 | 629 |     } | 
 | 630 |     Mutex::Autolock _l(mLock); | 
 | 631 |     // Do we have a stale mInBuffSize or are we requesting the input buffer size for new values | 
 | 632 |     if ((mInBuffSize == 0) || (sampleRate != mInSamplingRate) || (format != mInFormat) | 
 | 633 |         || (channelMask != mInChannelMask)) { | 
 | 634 |         size_t inBuffSize = af->getInputBufferSize(sampleRate, format, channelMask); | 
 | 635 |         if (inBuffSize == 0) { | 
| Glenn Kasten | 49f36ba | 2017-12-06 13:02:02 -0800 | [diff] [blame] | 636 |             ALOGE("AudioSystem::getInputBufferSize failed sampleRate %d format %#x channelMask %#x", | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 637 |                     sampleRate, format, channelMask); | 
 | 638 |             return BAD_VALUE; | 
 | 639 |         } | 
 | 640 |         // A benign race is possible here: we could overwrite a fresher cache entry | 
 | 641 |         // save the request params | 
 | 642 |         mInSamplingRate = sampleRate; | 
 | 643 |         mInFormat = format; | 
 | 644 |         mInChannelMask = channelMask; | 
 | 645 |  | 
 | 646 |         mInBuffSize = inBuffSize; | 
 | 647 |     } | 
 | 648 |  | 
 | 649 |     *buffSize = mInBuffSize; | 
 | 650 |  | 
 | 651 |     return NO_ERROR; | 
 | 652 | } | 
 | 653 |  | 
| Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 654 | sp<AudioIoDescriptor> AudioSystem::AudioFlingerClient::getIoDescriptor_l(audio_io_handle_t ioHandle) | 
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 655 | { | 
 | 656 |     sp<AudioIoDescriptor> desc; | 
 | 657 |     ssize_t index = mIoDescriptors.indexOfKey(ioHandle); | 
 | 658 |     if (index >= 0) { | 
 | 659 |         desc = mIoDescriptors.valueAt(index); | 
 | 660 |     } | 
 | 661 |     return desc; | 
 | 662 | } | 
 | 663 |  | 
| Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 664 | sp<AudioIoDescriptor> AudioSystem::AudioFlingerClient::getIoDescriptor(audio_io_handle_t ioHandle) | 
 | 665 | { | 
 | 666 |     Mutex::Autolock _l(mLock); | 
 | 667 |     return getIoDescriptor_l(ioHandle); | 
 | 668 | } | 
 | 669 |  | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 670 | status_t AudioSystem::AudioFlingerClient::addAudioDeviceCallback( | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 671 |         const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo) | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 672 | { | 
 | 673 |     Mutex::Autolock _l(mLock); | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 674 |     Vector < wp<AudioDeviceCallback> > callbacks; | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 675 |     ssize_t ioIndex = mAudioDeviceCallbacks.indexOfKey(audioIo); | 
 | 676 |     if (ioIndex >= 0) { | 
 | 677 |         callbacks = mAudioDeviceCallbacks.valueAt(ioIndex); | 
 | 678 |     } | 
 | 679 |  | 
 | 680 |     for (size_t cbIndex = 0; cbIndex < callbacks.size(); cbIndex++) { | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 681 |         if (callbacks[cbIndex].unsafe_get() == callback.unsafe_get()) { | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 682 |             return INVALID_OPERATION; | 
 | 683 |         } | 
 | 684 |     } | 
 | 685 |     callbacks.add(callback); | 
 | 686 |  | 
 | 687 |     mAudioDeviceCallbacks.replaceValueFor(audioIo, callbacks); | 
 | 688 |     return NO_ERROR; | 
 | 689 | } | 
 | 690 |  | 
 | 691 | status_t AudioSystem::AudioFlingerClient::removeAudioDeviceCallback( | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 692 |         const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo) | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 693 | { | 
 | 694 |     Mutex::Autolock _l(mLock); | 
 | 695 |     ssize_t ioIndex = mAudioDeviceCallbacks.indexOfKey(audioIo); | 
 | 696 |     if (ioIndex < 0) { | 
 | 697 |         return INVALID_OPERATION; | 
 | 698 |     } | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 699 |     Vector < wp<AudioDeviceCallback> > callbacks = mAudioDeviceCallbacks.valueAt(ioIndex); | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 700 |  | 
 | 701 |     size_t cbIndex; | 
 | 702 |     for (cbIndex = 0; cbIndex < callbacks.size(); cbIndex++) { | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 703 |         if (callbacks[cbIndex].unsafe_get() == callback.unsafe_get()) { | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 704 |             break; | 
 | 705 |         } | 
 | 706 |     } | 
 | 707 |     if (cbIndex == callbacks.size()) { | 
 | 708 |         return INVALID_OPERATION; | 
 | 709 |     } | 
 | 710 |     callbacks.removeAt(cbIndex); | 
 | 711 |     if (callbacks.size() != 0) { | 
 | 712 |         mAudioDeviceCallbacks.replaceValueFor(audioIo, callbacks); | 
 | 713 |     } else { | 
 | 714 |         mAudioDeviceCallbacks.removeItem(audioIo); | 
 | 715 |     } | 
 | 716 |     return NO_ERROR; | 
 | 717 | } | 
 | 718 |  | 
 | 719 | /* static */ void AudioSystem::setErrorCallback(audio_error_callback cb) | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 720 | { | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 721 |     Mutex::Autolock _l(gLock); | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 |     gAudioErrorCallback = cb; | 
 | 723 | } | 
 | 724 |  | 
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 725 | /*static*/ void AudioSystem::setDynPolicyCallback(dynamic_policy_callback cb) | 
 | 726 | { | 
 | 727 |     Mutex::Autolock _l(gLock); | 
 | 728 |     gDynPolicyCallback = cb; | 
 | 729 | } | 
 | 730 |  | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 731 | /*static*/ void AudioSystem::setRecordConfigCallback(record_config_callback cb) | 
 | 732 | { | 
 | 733 |     Mutex::Autolock _l(gLock); | 
 | 734 |     gRecordConfigCallback = cb; | 
 | 735 | } | 
 | 736 |  | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 737 | // client singleton for AudioPolicyService binder interface | 
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 738 | // protected by gLockAPS | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 739 | sp<IAudioPolicyService> AudioSystem::gAudioPolicyService; | 
 | 740 | sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient; | 
 | 741 |  | 
 | 742 |  | 
| Glenn Kasten | 18a6d90 | 2012-09-24 11:27:56 -0700 | [diff] [blame] | 743 | // establish binder interface to AudioPolicy service | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 744 | const sp<IAudioPolicyService> AudioSystem::get_audio_policy_service() | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 745 | { | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 746 |     sp<IAudioPolicyService> ap; | 
 | 747 |     sp<AudioPolicyServiceClient> apc; | 
 | 748 |     { | 
 | 749 |         Mutex::Autolock _l(gLockAPS); | 
 | 750 |         if (gAudioPolicyService == 0) { | 
 | 751 |             sp<IServiceManager> sm = defaultServiceManager(); | 
 | 752 |             sp<IBinder> binder; | 
 | 753 |             do { | 
 | 754 |                 binder = sm->getService(String16("media.audio_policy")); | 
 | 755 |                 if (binder != 0) | 
 | 756 |                     break; | 
 | 757 |                 ALOGW("AudioPolicyService not published, waiting..."); | 
 | 758 |                 usleep(500000); // 0.5 s | 
 | 759 |             } while (true); | 
 | 760 |             if (gAudioPolicyServiceClient == NULL) { | 
 | 761 |                 gAudioPolicyServiceClient = new AudioPolicyServiceClient(); | 
 | 762 |             } | 
 | 763 |             binder->linkToDeath(gAudioPolicyServiceClient); | 
 | 764 |             gAudioPolicyService = interface_cast<IAudioPolicyService>(binder); | 
 | 765 |             LOG_ALWAYS_FATAL_IF(gAudioPolicyService == 0); | 
 | 766 |             apc = gAudioPolicyServiceClient; | 
| Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 767 |             // Make sure callbacks can be received by gAudioPolicyServiceClient | 
 | 768 |             ProcessState::self()->startThreadPool(); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 769 |         } | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 770 |         ap = gAudioPolicyService; | 
 | 771 |     } | 
 | 772 |     if (apc != 0) { | 
| François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 773 |         int64_t token = IPCThreadState::self()->clearCallingIdentity(); | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 774 |         ap->registerClient(apc); | 
| François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 775 |         ap->setAudioPortCallbacksEnabled(apc->isAudioPortCbEnabled()); | 
 | 776 |         IPCThreadState::self()->restoreCallingIdentity(token); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 777 |     } | 
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 778 |  | 
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 779 |     return ap; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 780 | } | 
 | 781 |  | 
| Glenn Kasten | fb1fdc9 | 2013-07-10 17:03:19 -0700 | [diff] [blame] | 782 | // --------------------------------------------------------------------------- | 
 | 783 |  | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 784 | status_t AudioSystem::setDeviceConnectionState(audio_devices_t device, | 
 | 785 |                                                audio_policy_dev_state_t state, | 
| Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 786 |                                                const char *device_address, | 
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 787 |                                                const char *device_name, | 
 | 788 |                                                audio_format_t encodedFormat) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 789 | { | 
 | 790 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
| Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 791 |     const char *address = ""; | 
| Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 792 |     const char *name = ""; | 
| Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 793 |  | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 794 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 795 |  | 
| Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 796 |     if (device_address != NULL) { | 
 | 797 |         address = device_address; | 
 | 798 |     } | 
| Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 799 |     if (device_name != NULL) { | 
 | 800 |         name = device_name; | 
 | 801 |     } | 
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 802 |     return aps->setDeviceConnectionState(device, state, address, name, encodedFormat); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 803 | } | 
 | 804 |  | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 805 | audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device, | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 806 |                                                   const char *device_address) | 
 | 807 | { | 
 | 808 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 809 |     if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 810 |  | 
 | 811 |     return aps->getDeviceConnectionState(device, device_address); | 
 | 812 | } | 
 | 813 |  | 
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 814 | status_t AudioSystem::handleDeviceConfigChange(audio_devices_t device, | 
 | 815 |                                                const char *device_address, | 
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 816 |                                                const char *device_name, | 
 | 817 |                                                audio_format_t encodedFormat) | 
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 818 | { | 
 | 819 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 820 |     const char *address = ""; | 
 | 821 |     const char *name = ""; | 
 | 822 |  | 
 | 823 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 824 |  | 
 | 825 |     if (device_address != NULL) { | 
 | 826 |         address = device_address; | 
 | 827 |     } | 
 | 828 |     if (device_name != NULL) { | 
 | 829 |         name = device_name; | 
 | 830 |     } | 
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 831 |     return aps->handleDeviceConfigChange(device, address, name, encodedFormat); | 
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 832 | } | 
 | 833 |  | 
| Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 834 | status_t AudioSystem::setPhoneState(audio_mode_t state) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 835 | { | 
| Glenn Kasten | 347966c | 2012-01-18 14:58:32 -0800 | [diff] [blame] | 836 |     if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 837 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 838 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 839 |  | 
 | 840 |     return aps->setPhoneState(state); | 
 | 841 | } | 
 | 842 |  | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 843 | 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] | 844 | { | 
 | 845 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 846 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 847 |     return aps->setForceUse(usage, config); | 
 | 848 | } | 
 | 849 |  | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 850 | 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] | 851 | { | 
 | 852 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 853 |     if (aps == 0) return AUDIO_POLICY_FORCE_NONE; | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 854 |     return aps->getForceUse(usage); | 
 | 855 | } | 
 | 856 |  | 
 | 857 |  | 
| Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 858 | audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 859 | { | 
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 860 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 861 |     if (aps == 0) return 0; | 
| Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 862 |     return aps->getOutput(stream); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 863 | } | 
 | 864 |  | 
| Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 865 | status_t AudioSystem::getOutputForAttr(const audio_attributes_t *attr, | 
 | 866 |                                         audio_io_handle_t *output, | 
 | 867 |                                         audio_session_t session, | 
 | 868 |                                         audio_stream_type_t *stream, | 
| Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 869 |                                         pid_t pid, | 
| Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 870 |                                         uid_t uid, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 871 |                                         const audio_config_t *config, | 
| Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 872 |                                         audio_output_flags_t flags, | 
| Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 873 |                                         audio_port_handle_t *selectedDeviceId, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 874 |                                         audio_port_handle_t *portId) | 
| Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 875 | { | 
| Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 876 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
| Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 877 |     if (aps == 0) return NO_INIT; | 
| Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 878 |     return aps->getOutputForAttr(attr, output, session, stream, pid, uid, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 879 |                                  config, | 
 | 880 |                                  flags, selectedDeviceId, portId); | 
| Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 881 | } | 
 | 882 |  | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 883 | status_t AudioSystem::startOutput(audio_port_handle_t portId) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 884 | { | 
 | 885 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 886 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 887 |     return aps->startOutput(portId); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 888 | } | 
 | 889 |  | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 890 | status_t AudioSystem::stopOutput(audio_port_handle_t portId) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 891 | { | 
 | 892 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 893 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 894 |     return aps->stopOutput(portId); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 895 | } | 
 | 896 |  | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 897 | void AudioSystem::releaseOutput(audio_port_handle_t portId) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 898 | { | 
 | 899 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 900 |     if (aps == 0) return; | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 901 |     aps->releaseOutput(portId); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 902 | } | 
 | 903 |  | 
| Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 904 | status_t AudioSystem::getInputForAttr(const audio_attributes_t *attr, | 
 | 905 |                                 audio_io_handle_t *input, | 
 | 906 |                                 audio_session_t session, | 
| Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 907 |                                 pid_t pid, | 
| Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 908 |                                 uid_t uid, | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 909 |                                 const String16& opPackageName, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 910 |                                 const audio_config_base_t *config, | 
| Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 911 |                                 audio_input_flags_t flags, | 
| Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 912 |                                 audio_port_handle_t *selectedDeviceId, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 913 |                                 audio_port_handle_t *portId) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 914 | { | 
 | 915 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
| Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 916 |     if (aps == 0) return NO_INIT; | 
| Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 917 |     return aps->getInputForAttr( | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 918 |             attr, input, session, pid, uid, opPackageName, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 919 |             config, flags, selectedDeviceId, portId); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 920 | } | 
 | 921 |  | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 922 | status_t AudioSystem::startInput(audio_port_handle_t portId) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 923 | { | 
 | 924 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 925 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 926 |     return aps->startInput(portId); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 927 | } | 
 | 928 |  | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 929 | status_t AudioSystem::stopInput(audio_port_handle_t portId) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 930 | { | 
 | 931 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 932 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 933 |     return aps->stopInput(portId); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 934 | } | 
 | 935 |  | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 936 | void AudioSystem::releaseInput(audio_port_handle_t portId) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 937 | { | 
 | 938 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 939 |     if (aps == 0) return; | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 940 |     aps->releaseInput(portId); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 941 | } | 
 | 942 |  | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 943 | status_t AudioSystem::initStreamVolume(audio_stream_type_t stream, | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 944 |                                     int indexMin, | 
 | 945 |                                     int indexMax) | 
 | 946 | { | 
 | 947 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 948 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 949 |     return aps->initStreamVolume(stream, indexMin, indexMax); | 
 | 950 | } | 
 | 951 |  | 
| Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 952 | status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream, | 
 | 953 |                                            int index, | 
 | 954 |                                            audio_devices_t device) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 955 | { | 
 | 956 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 957 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 958 |     return aps->setStreamVolumeIndex(stream, index, device); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 959 | } | 
 | 960 |  | 
| Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 961 | status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream, | 
 | 962 |                                            int *index, | 
 | 963 |                                            audio_devices_t device) | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 964 | { | 
 | 965 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 966 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 967 |     return aps->getStreamVolumeIndex(stream, index, device); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 968 | } | 
 | 969 |  | 
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 970 | uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream) | 
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 971 | { | 
 | 972 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 973 |     if (aps == 0) return 0; | 
 | 974 |     return aps->getStrategyForStream(stream); | 
 | 975 | } | 
 | 976 |  | 
| Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 977 | audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream) | 
| Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 978 | { | 
 | 979 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
| Glenn Kasten | 45faf7e | 2014-01-17 10:23:01 -0800 | [diff] [blame] | 980 |     if (aps == 0) return AUDIO_DEVICE_NONE; | 
| Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 981 |     return aps->getDevicesForStream(stream); | 
 | 982 | } | 
 | 983 |  | 
| Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 984 | audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t *desc) | 
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 985 | { | 
 | 986 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
| Glenn Kasten | efa6ea9 | 2014-01-08 09:10:43 -0800 | [diff] [blame] | 987 |     // FIXME change return type to status_t, and return PERMISSION_DENIED here | 
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 988 |     if (aps == 0) return AUDIO_IO_HANDLE_NONE; | 
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 989 |     return aps->getOutputForEffect(desc); | 
 | 990 | } | 
 | 991 |  | 
| Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 992 | status_t AudioSystem::registerEffect(const effect_descriptor_t *desc, | 
| Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 993 |                                 audio_io_handle_t io, | 
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 994 |                                 uint32_t strategy, | 
| Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 995 |                                 audio_session_t session, | 
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 996 |                                 int id) | 
 | 997 | { | 
 | 998 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 999 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1000 |     return aps->registerEffect(desc, io, strategy, session, id); | 
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1001 | } | 
 | 1002 |  | 
 | 1003 | status_t AudioSystem::unregisterEffect(int id) | 
 | 1004 | { | 
 | 1005 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1006 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1007 |     return aps->unregisterEffect(id); | 
 | 1008 | } | 
 | 1009 |  | 
| Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1010 | status_t AudioSystem::setEffectEnabled(int id, bool enabled) | 
 | 1011 | { | 
 | 1012 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1013 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1014 |     return aps->setEffectEnabled(id, enabled); | 
 | 1015 | } | 
 | 1016 |  | 
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1017 | status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs) | 
| Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1018 | { | 
| Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1019 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1020 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1021 |     if (state == NULL) return BAD_VALUE; | 
| Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1022 |     *state = aps->isStreamActive(stream, inPastMs); | 
 | 1023 |     return NO_ERROR; | 
 | 1024 | } | 
 | 1025 |  | 
| Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1026 | status_t AudioSystem::isStreamActiveRemotely(audio_stream_type_t stream, bool* state, | 
 | 1027 |         uint32_t inPastMs) | 
 | 1028 | { | 
 | 1029 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1030 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1031 |     if (state == NULL) return BAD_VALUE; | 
 | 1032 |     *state = aps->isStreamActiveRemotely(stream, inPastMs); | 
 | 1033 |     return NO_ERROR; | 
 | 1034 | } | 
 | 1035 |  | 
| Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 1036 | status_t AudioSystem::isSourceActive(audio_source_t stream, bool* state) | 
 | 1037 | { | 
 | 1038 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1039 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1040 |     if (state == NULL) return BAD_VALUE; | 
 | 1041 |     *state = aps->isSourceActive(stream); | 
 | 1042 |     return NO_ERROR; | 
 | 1043 | } | 
 | 1044 |  | 
| Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 1045 | uint32_t AudioSystem::getPrimaryOutputSamplingRate() | 
| Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1046 | { | 
 | 1047 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 1048 |     if (af == 0) return 0; | 
 | 1049 |     return af->getPrimaryOutputSamplingRate(); | 
 | 1050 | } | 
 | 1051 |  | 
| Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 1052 | size_t AudioSystem::getPrimaryOutputFrameCount() | 
| Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1053 | { | 
 | 1054 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 1055 |     if (af == 0) return 0; | 
 | 1056 |     return af->getPrimaryOutputFrameCount(); | 
 | 1057 | } | 
| Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1058 |  | 
| Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 1059 | status_t AudioSystem::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) | 
| Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1060 | { | 
 | 1061 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 1062 |     if (af == 0) return PERMISSION_DENIED; | 
| Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 1063 |     return af->setLowRamDevice(isLowRamDevice, totalMemory); | 
| Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1064 | } | 
 | 1065 |  | 
| Eric Laurent | 9f6530f | 2011-08-30 10:18:54 -0700 | [diff] [blame] | 1066 | void AudioSystem::clearAudioConfigCache() | 
 | 1067 | { | 
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1068 |     // called by restoreTrack_l(), which needs new IAudioFlinger and IAudioPolicyService instances | 
| Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1069 |     ALOGV("clearAudioConfigCache()"); | 
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 1070 |     { | 
 | 1071 |         Mutex::Autolock _l(gLock); | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1072 |         if (gAudioFlingerClient != 0) { | 
 | 1073 |             gAudioFlingerClient->clearIoCache(); | 
 | 1074 |         } | 
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1075 |         gAudioFlinger.clear(); | 
 | 1076 |     } | 
 | 1077 |     { | 
 | 1078 |         Mutex::Autolock _l(gLockAPS); | 
 | 1079 |         gAudioPolicyService.clear(); | 
 | 1080 |     } | 
| Eric Laurent | 9f6530f | 2011-08-30 10:18:54 -0700 | [diff] [blame] | 1081 | } | 
 | 1082 |  | 
| Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 1083 | bool AudioSystem::isOffloadSupported(const audio_offload_info_t& info) | 
 | 1084 | { | 
 | 1085 |     ALOGV("isOffloadSupported()"); | 
 | 1086 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1087 |     if (aps == 0) return false; | 
 | 1088 |     return aps->isOffloadSupported(info); | 
 | 1089 | } | 
 | 1090 |  | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1091 | status_t AudioSystem::listAudioPorts(audio_port_role_t role, | 
 | 1092 |                                      audio_port_type_t type, | 
 | 1093 |                                      unsigned int *num_ports, | 
 | 1094 |                                      struct audio_port *ports, | 
 | 1095 |                                      unsigned int *generation) | 
 | 1096 | { | 
 | 1097 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1098 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1099 |     return aps->listAudioPorts(role, type, num_ports, ports, generation); | 
 | 1100 | } | 
 | 1101 |  | 
 | 1102 | status_t AudioSystem::getAudioPort(struct audio_port *port) | 
 | 1103 | { | 
 | 1104 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1105 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1106 |     return aps->getAudioPort(port); | 
 | 1107 | } | 
 | 1108 |  | 
 | 1109 | status_t AudioSystem::createAudioPatch(const struct audio_patch *patch, | 
 | 1110 |                                    audio_patch_handle_t *handle) | 
 | 1111 | { | 
 | 1112 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1113 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1114 |     return aps->createAudioPatch(patch, handle); | 
 | 1115 | } | 
 | 1116 |  | 
 | 1117 | status_t AudioSystem::releaseAudioPatch(audio_patch_handle_t handle) | 
 | 1118 | { | 
 | 1119 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1120 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1121 |     return aps->releaseAudioPatch(handle); | 
 | 1122 | } | 
 | 1123 |  | 
 | 1124 | status_t AudioSystem::listAudioPatches(unsigned int *num_patches, | 
 | 1125 |                                   struct audio_patch *patches, | 
 | 1126 |                                   unsigned int *generation) | 
 | 1127 | { | 
 | 1128 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1129 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1130 |     return aps->listAudioPatches(num_patches, patches, generation); | 
 | 1131 | } | 
 | 1132 |  | 
 | 1133 | status_t AudioSystem::setAudioPortConfig(const struct audio_port_config *config) | 
 | 1134 | { | 
 | 1135 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1136 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1137 |     return aps->setAudioPortConfig(config); | 
 | 1138 | } | 
 | 1139 |  | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1140 | status_t AudioSystem::addAudioPortCallback(const sp<AudioPortCallback>& callback) | 
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1141 | { | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1142 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1143 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1144 |  | 
 | 1145 |     Mutex::Autolock _l(gLockAPS); | 
 | 1146 |     if (gAudioPolicyServiceClient == 0) { | 
 | 1147 |         return NO_INIT; | 
 | 1148 |     } | 
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1149 |     int ret = gAudioPolicyServiceClient->addAudioPortCallback(callback); | 
 | 1150 |     if (ret == 1) { | 
 | 1151 |         aps->setAudioPortCallbacksEnabled(true); | 
 | 1152 |     } | 
 | 1153 |     return (ret < 0) ? INVALID_OPERATION : NO_ERROR; | 
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1154 | } | 
 | 1155 |  | 
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 1156 | /*static*/ | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1157 | status_t AudioSystem::removeAudioPortCallback(const sp<AudioPortCallback>& callback) | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1158 | { | 
 | 1159 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1160 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1161 |  | 
 | 1162 |     Mutex::Autolock _l(gLockAPS); | 
 | 1163 |     if (gAudioPolicyServiceClient == 0) { | 
 | 1164 |         return NO_INIT; | 
 | 1165 |     } | 
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1166 |     int ret = gAudioPolicyServiceClient->removeAudioPortCallback(callback); | 
 | 1167 |     if (ret == 0) { | 
 | 1168 |         aps->setAudioPortCallbacksEnabled(false); | 
 | 1169 |     } | 
 | 1170 |     return (ret < 0) ? INVALID_OPERATION : NO_ERROR; | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1171 | } | 
 | 1172 |  | 
 | 1173 | status_t AudioSystem::addAudioDeviceCallback( | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 1174 |         const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo) | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1175 | { | 
 | 1176 |     const sp<AudioFlingerClient> afc = getAudioFlingerClient(); | 
 | 1177 |     if (afc == 0) { | 
 | 1178 |         return NO_INIT; | 
 | 1179 |     } | 
| Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1180 |     status_t status = afc->addAudioDeviceCallback(callback, audioIo); | 
 | 1181 |     if (status == NO_ERROR) { | 
 | 1182 |         const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 1183 |         if (af != 0) { | 
 | 1184 |             af->registerClient(afc); | 
 | 1185 |         } | 
 | 1186 |     } | 
 | 1187 |     return status; | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1188 | } | 
 | 1189 |  | 
 | 1190 | status_t AudioSystem::removeAudioDeviceCallback( | 
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 1191 |         const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo) | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1192 | { | 
 | 1193 |     const sp<AudioFlingerClient> afc = getAudioFlingerClient(); | 
 | 1194 |     if (afc == 0) { | 
 | 1195 |         return NO_INIT; | 
 | 1196 |     } | 
 | 1197 |     return afc->removeAudioDeviceCallback(callback, audioIo); | 
 | 1198 | } | 
 | 1199 |  | 
 | 1200 | audio_port_handle_t AudioSystem::getDeviceIdForIo(audio_io_handle_t audioIo) | 
 | 1201 | { | 
 | 1202 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 1203 |     if (af == 0) return PERMISSION_DENIED; | 
 | 1204 |     const sp<AudioIoDescriptor> desc = getIoDescriptor(audioIo); | 
 | 1205 |     if (desc == 0) { | 
 | 1206 |         return AUDIO_PORT_HANDLE_NONE; | 
 | 1207 |     } | 
 | 1208 |     return desc->getDeviceId(); | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1209 | } | 
 | 1210 |  | 
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1211 | status_t AudioSystem::acquireSoundTriggerSession(audio_session_t *session, | 
 | 1212 |                                        audio_io_handle_t *ioHandle, | 
 | 1213 |                                        audio_devices_t *device) | 
 | 1214 | { | 
 | 1215 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1216 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1217 |     return aps->acquireSoundTriggerSession(session, ioHandle, device); | 
 | 1218 | } | 
 | 1219 |  | 
 | 1220 | status_t AudioSystem::releaseSoundTriggerSession(audio_session_t session) | 
 | 1221 | { | 
 | 1222 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1223 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1224 |     return aps->releaseSoundTriggerSession(session); | 
 | 1225 | } | 
| Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1226 |  | 
 | 1227 | audio_mode_t AudioSystem::getPhoneState() | 
 | 1228 | { | 
 | 1229 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1230 |     if (aps == 0) return AUDIO_MODE_INVALID; | 
 | 1231 |     return aps->getPhoneState(); | 
 | 1232 | } | 
 | 1233 |  | 
| Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 1234 | status_t AudioSystem::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) | 
| Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1235 | { | 
 | 1236 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1237 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1238 |     return aps->registerPolicyMixes(mixes, registration); | 
 | 1239 | } | 
| Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1240 |  | 
| Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1241 | status_t AudioSystem::setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices) | 
 | 1242 | { | 
 | 1243 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1244 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1245 |     return aps->setUidDeviceAffinities(uid, devices); | 
 | 1246 | } | 
 | 1247 |  | 
 | 1248 | status_t AudioSystem::removeUidDeviceAffinities(uid_t uid) { | 
 | 1249 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1250 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1251 |     return aps->removeUidDeviceAffinities(uid); | 
 | 1252 | } | 
 | 1253 |  | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1254 | status_t AudioSystem::startAudioSource(const struct audio_port_config *source, | 
 | 1255 |                                        const audio_attributes_t *attributes, | 
| Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1256 |                                        audio_port_handle_t *portId) | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1257 | { | 
 | 1258 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1259 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1260 |     return aps->startAudioSource(source, attributes, portId); | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1261 | } | 
 | 1262 |  | 
| Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1263 | status_t AudioSystem::stopAudioSource(audio_port_handle_t portId) | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1264 | { | 
 | 1265 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1266 |     if (aps == 0) return PERMISSION_DENIED; | 
| Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1267 |     return aps->stopAudioSource(portId); | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1268 | } | 
 | 1269 |  | 
| Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1270 | status_t AudioSystem::setMasterMono(bool mono) | 
 | 1271 | { | 
 | 1272 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1273 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1274 |     return aps->setMasterMono(mono); | 
 | 1275 | } | 
 | 1276 |  | 
 | 1277 | status_t AudioSystem::getMasterMono(bool *mono) | 
 | 1278 | { | 
 | 1279 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1280 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1281 |     return aps->getMasterMono(mono); | 
 | 1282 | } | 
 | 1283 |  | 
| Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1284 | float AudioSystem::getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device) | 
 | 1285 | { | 
 | 1286 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1287 |     if (aps == 0) return NAN; | 
 | 1288 |     return aps->getStreamVolumeDB(stream, index, device); | 
 | 1289 | } | 
 | 1290 |  | 
| jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 1291 | status_t AudioSystem::getMicrophones(std::vector<media::MicrophoneInfo> *microphones) | 
 | 1292 | { | 
 | 1293 |     const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); | 
 | 1294 |     if (af == 0) return PERMISSION_DENIED; | 
 | 1295 |     return af->getMicrophones(microphones); | 
 | 1296 | } | 
 | 1297 |  | 
| jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1298 | status_t AudioSystem::getSurroundFormats(unsigned int *numSurroundFormats, | 
 | 1299 |                                          audio_format_t *surroundFormats, | 
 | 1300 |                                          bool *surroundFormatsEnabled, | 
 | 1301 |                                          bool reported) | 
 | 1302 | { | 
 | 1303 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1304 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1305 |     return aps->getSurroundFormats( | 
 | 1306 |             numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported); | 
 | 1307 | } | 
 | 1308 |  | 
 | 1309 | status_t AudioSystem::setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) | 
 | 1310 | { | 
 | 1311 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1312 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1313 |     return aps->setSurroundFormatEnabled(audioFormat, enabled); | 
 | 1314 | } | 
 | 1315 |  | 
| Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1316 |  | 
 | 1317 | status_t AudioSystem::setAssistantUid(uid_t uid) | 
 | 1318 | { | 
 | 1319 |     const sp <IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1320 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1321 |  | 
 | 1322 |     return aps->setAssistantUid(uid); | 
 | 1323 | } | 
 | 1324 |  | 
 | 1325 | status_t AudioSystem::setA11yServicesUids(const std::vector<uid_t>& uids) | 
 | 1326 | { | 
 | 1327 |     const sp <IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1328 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1329 |  | 
 | 1330 |     return aps->setA11yServicesUids(uids); | 
 | 1331 | } | 
 | 1332 |  | 
| jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1333 | bool AudioSystem::isHapticPlaybackSupported() | 
 | 1334 | { | 
 | 1335 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1336 |     if (aps == 0) return false; | 
 | 1337 |     return aps->isHapticPlaybackSupported(); | 
 | 1338 | } | 
 | 1339 |  | 
| Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame^] | 1340 | status_t AudioSystem::getHwOffloadEncodingFormatsSupportedForA2DP( | 
 | 1341 |                                 std::vector<audio_format_t> *formats) | 
 | 1342 | { | 
 | 1343 |     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); | 
 | 1344 |     if (aps == 0) return PERMISSION_DENIED; | 
 | 1345 |     return aps->getHwOffloadEncodingFormatsSupportedForA2DP(formats); | 
 | 1346 | } | 
| Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1347 |  | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1348 | // --------------------------------------------------------------------------- | 
 | 1349 |  | 
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1350 | int AudioSystem::AudioPolicyServiceClient::addAudioPortCallback( | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1351 |         const sp<AudioPortCallback>& callback) | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1352 | { | 
 | 1353 |     Mutex::Autolock _l(mLock); | 
 | 1354 |     for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1355 |         if (mAudioPortCallbacks[i] == callback) { | 
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1356 |             return -1; | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1357 |         } | 
 | 1358 |     } | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1359 |     mAudioPortCallbacks.add(callback); | 
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1360 |     return mAudioPortCallbacks.size(); | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1361 | } | 
 | 1362 |  | 
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1363 | int AudioSystem::AudioPolicyServiceClient::removeAudioPortCallback( | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1364 |         const sp<AudioPortCallback>& callback) | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1365 | { | 
 | 1366 |     Mutex::Autolock _l(mLock); | 
 | 1367 |     size_t i; | 
 | 1368 |     for (i = 0; i < mAudioPortCallbacks.size(); i++) { | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1369 |         if (mAudioPortCallbacks[i] == callback) { | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1370 |             break; | 
 | 1371 |         } | 
 | 1372 |     } | 
 | 1373 |     if (i == mAudioPortCallbacks.size()) { | 
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1374 |         return -1; | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1375 |     } | 
 | 1376 |     mAudioPortCallbacks.removeAt(i); | 
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1377 |     return mAudioPortCallbacks.size(); | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1378 | } | 
 | 1379 |  | 
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1380 |  | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1381 | void AudioSystem::AudioPolicyServiceClient::onAudioPortListUpdate() | 
 | 1382 | { | 
 | 1383 |     Mutex::Autolock _l(mLock); | 
 | 1384 |     for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { | 
 | 1385 |         mAudioPortCallbacks[i]->onAudioPortListUpdate(); | 
 | 1386 |     } | 
 | 1387 | } | 
 | 1388 |  | 
 | 1389 | void AudioSystem::AudioPolicyServiceClient::onAudioPatchListUpdate() | 
 | 1390 | { | 
 | 1391 |     Mutex::Autolock _l(mLock); | 
 | 1392 |     for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { | 
 | 1393 |         mAudioPortCallbacks[i]->onAudioPatchListUpdate(); | 
 | 1394 |     } | 
 | 1395 | } | 
 | 1396 |  | 
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1397 | void AudioSystem::AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate( | 
 | 1398 |         String8 regId, int32_t state) | 
 | 1399 | { | 
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 1400 |     ALOGV("AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate(%s, %d)", regId.string(), state); | 
 | 1401 |     dynamic_policy_callback cb = NULL; | 
 | 1402 |     { | 
 | 1403 |         Mutex::Autolock _l(AudioSystem::gLock); | 
 | 1404 |         cb = gDynPolicyCallback; | 
 | 1405 |     } | 
 | 1406 |  | 
 | 1407 |     if (cb != NULL) { | 
 | 1408 |         cb(DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE, regId, state); | 
 | 1409 |     } | 
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1410 | } | 
 | 1411 |  | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1412 | void AudioSystem::AudioPolicyServiceClient::onRecordingConfigurationUpdate( | 
| Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1413 |                                                 int event, | 
 | 1414 |                                                 const record_client_info_t *clientInfo, | 
 | 1415 |                                                 const audio_config_base_t *clientConfig, | 
 | 1416 |                                                 std::vector<effect_descriptor_t> clientEffects, | 
 | 1417 |                                                 const audio_config_base_t *deviceConfig, | 
 | 1418 |                                                 std::vector<effect_descriptor_t> effects, | 
 | 1419 |                                                 audio_patch_handle_t patchHandle, | 
 | 1420 |                                                 audio_source_t source) { | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1421 |     record_config_callback cb = NULL; | 
 | 1422 |     { | 
 | 1423 |         Mutex::Autolock _l(AudioSystem::gLock); | 
 | 1424 |         cb = gRecordConfigCallback; | 
 | 1425 |     } | 
 | 1426 |  | 
 | 1427 |     if (cb != NULL) { | 
| Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1428 |         cb(event, clientInfo, clientConfig, clientEffects, | 
 | 1429 |            deviceConfig, effects, patchHandle, source); | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1430 |     } | 
 | 1431 | } | 
 | 1432 |  | 
| Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 1433 | void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who __unused) | 
 | 1434 | { | 
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1435 |     { | 
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1436 |         Mutex::Autolock _l(mLock); | 
 | 1437 |         for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { | 
 | 1438 |             mAudioPortCallbacks[i]->onServiceDied(); | 
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1439 |         } | 
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1440 |     } | 
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1441 |     { | 
 | 1442 |         Mutex::Autolock _l(gLockAPS); | 
 | 1443 |         AudioSystem::gAudioPolicyService.clear(); | 
 | 1444 |     } | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1445 |  | 
| Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1446 |     ALOGW("AudioPolicyService server died!"); | 
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1447 | } | 
 | 1448 |  | 
| Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 1449 | } // namespace android |