Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 "AudioPolicyService" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
Glenn Kasten | 153b9fe | 2013-07-15 11:23:36 -0700 | [diff] [blame] | 20 | #include "Configuration.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 21 | #undef __STRICT_ANSI__ |
| 22 | #define __STDINT_LIMITS |
| 23 | #define __STDC_LIMIT_MACROS |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | #include <sys/time.h> |
| 27 | #include <binder/IServiceManager.h> |
| 28 | #include <utils/Log.h> |
| 29 | #include <cutils/properties.h> |
| 30 | #include <binder/IPCThreadState.h> |
| 31 | #include <utils/String16.h> |
| 32 | #include <utils/threads.h> |
| 33 | #include "AudioPolicyService.h" |
Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 34 | #include "ServiceUtilities.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 35 | #include <hardware_legacy/power.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 36 | #include <media/AudioEffect.h> |
| 37 | #include <media/EffectsFactoryApi.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 38 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 39 | #include <hardware/hardware.h> |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 40 | #include <system/audio.h> |
Dima Zavin | 7394a4f | 2011-06-13 18:16:26 -0700 | [diff] [blame] | 41 | #include <system/audio_policy.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 42 | #include <hardware/audio_policy.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 43 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 44 | namespace android { |
| 45 | |
Glenn Kasten | 8dad0e3 | 2012-01-09 08:41:22 -0800 | [diff] [blame] | 46 | static const char kDeadlockedString[] = "AudioPolicyService may be deadlocked\n"; |
| 47 | static const char kCmdDeadlockedString[] = "AudioPolicyService command thread may be deadlocked\n"; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 48 | |
| 49 | static const int kDumpLockRetries = 50; |
Glenn Kasten | 22ecc91 | 2012-01-09 08:33:38 -0800 | [diff] [blame] | 50 | static const int kDumpLockSleepUs = 20000; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 51 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 52 | static const nsecs_t kAudioCommandTimeoutNs = seconds(3); // 3 seconds |
Christer Fletcher | 5fa8c4b | 2013-01-18 15:27:03 +0100 | [diff] [blame] | 53 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 54 | namespace { |
| 55 | extern struct audio_policy_service_ops aps_ops; |
| 56 | }; |
| 57 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 58 | // ---------------------------------------------------------------------------- |
| 59 | |
| 60 | AudioPolicyService::AudioPolicyService() |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 61 | : BnAudioPolicyService(), mpAudioPolicyDev(NULL), mpAudioPolicy(NULL), |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 62 | mAudioPolicyManager(NULL), mAudioPolicyClient(NULL), mPhoneState(AUDIO_MODE_INVALID) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 63 | { |
Eric Laurent | f5ada6e | 2014-10-09 17:49:00 -0700 | [diff] [blame^] | 64 | } |
| 65 | |
| 66 | void AudioPolicyService::onFirstRef() |
| 67 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 68 | char value[PROPERTY_VALUE_MAX]; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 69 | const struct hw_module_t *module; |
| 70 | int forced_val; |
| 71 | int rc; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 72 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 73 | { |
| 74 | Mutex::Autolock _l(mLock); |
Eric Laurent | 9357520 | 2011-01-18 18:39:02 -0800 | [diff] [blame] | 75 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 76 | // start tone playback thread |
| 77 | mTonePlaybackThread = new AudioCommandThread(String8("ApmTone"), this); |
| 78 | // start audio commands thread |
| 79 | mAudioCommandThread = new AudioCommandThread(String8("ApmAudio"), this); |
| 80 | // start output activity command thread |
| 81 | mOutputCommandThread = new AudioCommandThread(String8("ApmOutput"), this); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 82 | |
| 83 | #ifdef USE_LEGACY_AUDIO_POLICY |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 84 | ALOGI("AudioPolicyService CSTOR in legacy mode"); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 85 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 86 | /* instantiate the audio policy manager */ |
| 87 | rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module); |
| 88 | if (rc) { |
| 89 | return; |
| 90 | } |
| 91 | rc = audio_policy_dev_open(module, &mpAudioPolicyDev); |
| 92 | ALOGE_IF(rc, "couldn't open audio policy device (%s)", strerror(-rc)); |
| 93 | if (rc) { |
| 94 | return; |
| 95 | } |
Eric Laurent | 9357520 | 2011-01-18 18:39:02 -0800 | [diff] [blame] | 96 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 97 | rc = mpAudioPolicyDev->create_audio_policy(mpAudioPolicyDev, &aps_ops, this, |
| 98 | &mpAudioPolicy); |
| 99 | ALOGE_IF(rc, "couldn't create audio policy (%s)", strerror(-rc)); |
| 100 | if (rc) { |
| 101 | return; |
| 102 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 103 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 104 | rc = mpAudioPolicy->init_check(mpAudioPolicy); |
| 105 | ALOGE_IF(rc, "couldn't init_check the audio policy (%s)", strerror(-rc)); |
| 106 | if (rc) { |
| 107 | return; |
| 108 | } |
| 109 | ALOGI("Loaded audio policy from %s (%s)", module->name, module->id); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 110 | #else |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 111 | ALOGI("AudioPolicyService CSTOR in new mode"); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 112 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 113 | mAudioPolicyClient = new AudioPolicyClient(this); |
| 114 | mAudioPolicyManager = createAudioPolicyManager(mAudioPolicyClient); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 115 | #endif |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 116 | } |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 117 | // load audio processing modules |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 118 | sp<AudioPolicyEffects>audioPolicyEffects = new AudioPolicyEffects(); |
| 119 | { |
| 120 | Mutex::Autolock _l(mLock); |
| 121 | mAudioPolicyEffects = audioPolicyEffects; |
| 122 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | AudioPolicyService::~AudioPolicyService() |
| 126 | { |
| 127 | mTonePlaybackThread->exit(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 128 | mAudioCommandThread->exit(); |
Eric Laurent | 657ff61 | 2014-05-07 11:58:24 -0700 | [diff] [blame] | 129 | mOutputCommandThread->exit(); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 130 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 131 | #ifdef USE_LEGACY_AUDIO_POLICY |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 132 | if (mpAudioPolicy != NULL && mpAudioPolicyDev != NULL) { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 133 | mpAudioPolicyDev->destroy_audio_policy(mpAudioPolicyDev, mpAudioPolicy); |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 134 | } |
| 135 | if (mpAudioPolicyDev != NULL) { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 136 | audio_policy_dev_close(mpAudioPolicyDev); |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 137 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 138 | #else |
Eric Laurent | f269b8e | 2014-06-09 20:01:29 -0700 | [diff] [blame] | 139 | destroyAudioPolicyManager(mAudioPolicyManager); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 140 | delete mAudioPolicyClient; |
| 141 | #endif |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 142 | |
| 143 | mNotificationClients.clear(); |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 144 | mAudioPolicyEffects.clear(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | // A notification client is always registered by AudioSystem when the client process |
| 148 | // connects to AudioPolicyService. |
| 149 | void AudioPolicyService::registerClient(const sp<IAudioPolicyServiceClient>& client) |
| 150 | { |
| 151 | |
| 152 | Mutex::Autolock _l(mLock); |
| 153 | |
| 154 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 155 | if (mNotificationClients.indexOfKey(uid) < 0) { |
| 156 | sp<NotificationClient> notificationClient = new NotificationClient(this, |
| 157 | client, |
| 158 | uid); |
| 159 | ALOGV("registerClient() client %p, uid %d", client.get(), uid); |
| 160 | |
| 161 | mNotificationClients.add(uid, notificationClient); |
| 162 | |
| 163 | sp<IBinder> binder = client->asBinder(); |
| 164 | binder->linkToDeath(notificationClient); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | // removeNotificationClient() is called when the client process dies. |
| 169 | void AudioPolicyService::removeNotificationClient(uid_t uid) |
| 170 | { |
| 171 | Mutex::Autolock _l(mLock); |
| 172 | |
| 173 | mNotificationClients.removeItem(uid); |
| 174 | |
| 175 | #ifndef USE_LEGACY_AUDIO_POLICY |
| 176 | if (mAudioPolicyManager) { |
| 177 | mAudioPolicyManager->clearAudioPatches(uid); |
| 178 | } |
| 179 | #endif |
| 180 | } |
| 181 | |
| 182 | void AudioPolicyService::onAudioPortListUpdate() |
| 183 | { |
| 184 | mOutputCommandThread->updateAudioPortListCommand(); |
| 185 | } |
| 186 | |
| 187 | void AudioPolicyService::doOnAudioPortListUpdate() |
| 188 | { |
| 189 | Mutex::Autolock _l(mLock); |
| 190 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 191 | mNotificationClients.valueAt(i)->onAudioPortListUpdate(); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | void AudioPolicyService::onAudioPatchListUpdate() |
| 196 | { |
| 197 | mOutputCommandThread->updateAudioPatchListCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 200 | status_t AudioPolicyService::clientCreateAudioPatch(const struct audio_patch *patch, |
| 201 | audio_patch_handle_t *handle, |
| 202 | int delayMs) |
| 203 | { |
| 204 | return mAudioCommandThread->createAudioPatchCommand(patch, handle, delayMs); |
| 205 | } |
| 206 | |
| 207 | status_t AudioPolicyService::clientReleaseAudioPatch(audio_patch_handle_t handle, |
| 208 | int delayMs) |
| 209 | { |
| 210 | return mAudioCommandThread->releaseAudioPatchCommand(handle, delayMs); |
| 211 | } |
| 212 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 213 | void AudioPolicyService::doOnAudioPatchListUpdate() |
| 214 | { |
| 215 | Mutex::Autolock _l(mLock); |
| 216 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 217 | mNotificationClients.valueAt(i)->onAudioPatchListUpdate(); |
| 218 | } |
| 219 | } |
| 220 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 221 | status_t AudioPolicyService::clientSetAudioPortConfig(const struct audio_port_config *config, |
| 222 | int delayMs) |
| 223 | { |
| 224 | return mAudioCommandThread->setAudioPortConfigCommand(config, delayMs); |
| 225 | } |
| 226 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 227 | AudioPolicyService::NotificationClient::NotificationClient(const sp<AudioPolicyService>& service, |
| 228 | const sp<IAudioPolicyServiceClient>& client, |
| 229 | uid_t uid) |
| 230 | : mService(service), mUid(uid), mAudioPolicyServiceClient(client) |
| 231 | { |
| 232 | } |
| 233 | |
| 234 | AudioPolicyService::NotificationClient::~NotificationClient() |
| 235 | { |
| 236 | } |
| 237 | |
| 238 | void AudioPolicyService::NotificationClient::binderDied(const wp<IBinder>& who __unused) |
| 239 | { |
| 240 | sp<NotificationClient> keep(this); |
| 241 | sp<AudioPolicyService> service = mService.promote(); |
| 242 | if (service != 0) { |
| 243 | service->removeNotificationClient(mUid); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | void AudioPolicyService::NotificationClient::onAudioPortListUpdate() |
| 248 | { |
| 249 | if (mAudioPolicyServiceClient != 0) { |
| 250 | mAudioPolicyServiceClient->onAudioPortListUpdate(); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | void AudioPolicyService::NotificationClient::onAudioPatchListUpdate() |
| 255 | { |
| 256 | if (mAudioPolicyServiceClient != 0) { |
| 257 | mAudioPolicyServiceClient->onAudioPatchListUpdate(); |
| 258 | } |
| 259 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 260 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 261 | void AudioPolicyService::binderDied(const wp<IBinder>& who) { |
Glenn Kasten | 411e447 | 2012-11-02 10:00:06 -0700 | [diff] [blame] | 262 | ALOGW("binderDied() %p, calling pid %d", who.unsafe_get(), |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 263 | IPCThreadState::self()->getCallingPid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static bool tryLock(Mutex& mutex) |
| 267 | { |
| 268 | bool locked = false; |
| 269 | for (int i = 0; i < kDumpLockRetries; ++i) { |
| 270 | if (mutex.tryLock() == NO_ERROR) { |
| 271 | locked = true; |
| 272 | break; |
| 273 | } |
Glenn Kasten | 22ecc91 | 2012-01-09 08:33:38 -0800 | [diff] [blame] | 274 | usleep(kDumpLockSleepUs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 275 | } |
| 276 | return locked; |
| 277 | } |
| 278 | |
| 279 | status_t AudioPolicyService::dumpInternals(int fd) |
| 280 | { |
| 281 | const size_t SIZE = 256; |
| 282 | char buffer[SIZE]; |
| 283 | String8 result; |
| 284 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 285 | #ifdef USE_LEGACY_AUDIO_POLICY |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 286 | snprintf(buffer, SIZE, "PolicyManager Interface: %p\n", mpAudioPolicy); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 287 | #else |
| 288 | snprintf(buffer, SIZE, "AudioPolicyManager: %p\n", mAudioPolicyManager); |
| 289 | #endif |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 290 | result.append(buffer); |
| 291 | snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get()); |
| 292 | result.append(buffer); |
| 293 | snprintf(buffer, SIZE, "Tones Thread: %p\n", mTonePlaybackThread.get()); |
| 294 | result.append(buffer); |
| 295 | |
| 296 | write(fd, result.string(), result.size()); |
| 297 | return NO_ERROR; |
| 298 | } |
| 299 | |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 300 | status_t AudioPolicyService::dump(int fd, const Vector<String16>& args __unused) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 301 | { |
Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 302 | if (!dumpAllowed()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 303 | dumpPermissionDenial(fd); |
| 304 | } else { |
| 305 | bool locked = tryLock(mLock); |
| 306 | if (!locked) { |
| 307 | String8 result(kDeadlockedString); |
| 308 | write(fd, result.string(), result.size()); |
| 309 | } |
| 310 | |
| 311 | dumpInternals(fd); |
Glenn Kasten | 9d1f02d | 2012-02-08 17:47:58 -0800 | [diff] [blame] | 312 | if (mAudioCommandThread != 0) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 313 | mAudioCommandThread->dump(fd); |
| 314 | } |
Glenn Kasten | 9d1f02d | 2012-02-08 17:47:58 -0800 | [diff] [blame] | 315 | if (mTonePlaybackThread != 0) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 316 | mTonePlaybackThread->dump(fd); |
| 317 | } |
| 318 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 319 | #ifdef USE_LEGACY_AUDIO_POLICY |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 320 | if (mpAudioPolicy) { |
| 321 | mpAudioPolicy->dump(mpAudioPolicy, fd); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 322 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 323 | #else |
| 324 | if (mAudioPolicyManager) { |
| 325 | mAudioPolicyManager->dump(fd); |
| 326 | } |
| 327 | #endif |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 328 | |
| 329 | if (locked) mLock.unlock(); |
| 330 | } |
| 331 | return NO_ERROR; |
| 332 | } |
| 333 | |
| 334 | status_t AudioPolicyService::dumpPermissionDenial(int fd) |
| 335 | { |
| 336 | const size_t SIZE = 256; |
| 337 | char buffer[SIZE]; |
| 338 | String8 result; |
| 339 | snprintf(buffer, SIZE, "Permission Denial: " |
| 340 | "can't dump AudioPolicyService from pid=%d, uid=%d\n", |
| 341 | IPCThreadState::self()->getCallingPid(), |
| 342 | IPCThreadState::self()->getCallingUid()); |
| 343 | result.append(buffer); |
| 344 | write(fd, result.string(), result.size()); |
| 345 | return NO_ERROR; |
| 346 | } |
| 347 | |
| 348 | status_t AudioPolicyService::onTransact( |
| 349 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 350 | { |
| 351 | return BnAudioPolicyService::onTransact(code, data, reply, flags); |
| 352 | } |
| 353 | |
| 354 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 355 | // ----------- AudioPolicyService::AudioCommandThread implementation ---------- |
| 356 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 357 | AudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name, |
| 358 | const wp<AudioPolicyService>& service) |
| 359 | : Thread(false), mName(name), mService(service) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 360 | { |
| 361 | mpToneGenerator = NULL; |
| 362 | } |
| 363 | |
| 364 | |
| 365 | AudioPolicyService::AudioCommandThread::~AudioCommandThread() |
| 366 | { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 367 | if (!mAudioCommands.isEmpty()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 368 | release_wake_lock(mName.string()); |
| 369 | } |
| 370 | mAudioCommands.clear(); |
Glenn Kasten | e9dd017 | 2012-01-27 18:08:45 -0800 | [diff] [blame] | 371 | delete mpToneGenerator; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void AudioPolicyService::AudioCommandThread::onFirstRef() |
| 375 | { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 376 | run(mName.string(), ANDROID_PRIORITY_AUDIO); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | bool AudioPolicyService::AudioCommandThread::threadLoop() |
| 380 | { |
| 381 | nsecs_t waitTime = INT64_MAX; |
| 382 | |
| 383 | mLock.lock(); |
| 384 | while (!exitPending()) |
| 385 | { |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 386 | sp<AudioPolicyService> svc; |
| 387 | while (!mAudioCommands.isEmpty() && !exitPending()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 388 | nsecs_t curTime = systemTime(); |
| 389 | // commands are sorted by increasing time stamp: execute them from index 0 and up |
| 390 | if (mAudioCommands[0]->mTime <= curTime) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 391 | sp<AudioCommand> command = mAudioCommands[0]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 392 | mAudioCommands.removeAt(0); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 393 | mLastCommand = command; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 394 | |
| 395 | switch (command->mCommand) { |
| 396 | case START_TONE: { |
| 397 | mLock.unlock(); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 398 | ToneData *data = (ToneData *)command->mParam.get(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 399 | ALOGV("AudioCommandThread() processing start tone %d on stream %d", |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 400 | data->mType, data->mStream); |
Glenn Kasten | e9dd017 | 2012-01-27 18:08:45 -0800 | [diff] [blame] | 401 | delete mpToneGenerator; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 402 | mpToneGenerator = new ToneGenerator(data->mStream, 1.0); |
| 403 | mpToneGenerator->startTone(data->mType); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 404 | mLock.lock(); |
| 405 | }break; |
| 406 | case STOP_TONE: { |
| 407 | mLock.unlock(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 408 | ALOGV("AudioCommandThread() processing stop tone"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 409 | if (mpToneGenerator != NULL) { |
| 410 | mpToneGenerator->stopTone(); |
| 411 | delete mpToneGenerator; |
| 412 | mpToneGenerator = NULL; |
| 413 | } |
| 414 | mLock.lock(); |
| 415 | }break; |
| 416 | case SET_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 417 | VolumeData *data = (VolumeData *)command->mParam.get(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 418 | ALOGV("AudioCommandThread() processing set volume stream %d, \ |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 419 | volume %f, output %d", data->mStream, data->mVolume, data->mIO); |
| 420 | command->mStatus = AudioSystem::setStreamVolume(data->mStream, |
| 421 | data->mVolume, |
| 422 | data->mIO); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 423 | }break; |
| 424 | case SET_PARAMETERS: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 425 | ParametersData *data = (ParametersData *)command->mParam.get(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 426 | ALOGV("AudioCommandThread() processing set parameters string %s, io %d", |
| 427 | data->mKeyValuePairs.string(), data->mIO); |
| 428 | command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 429 | }break; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 430 | case SET_VOICE_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 431 | VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 432 | ALOGV("AudioCommandThread() processing set voice volume volume %f", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 433 | data->mVolume); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 434 | command->mStatus = AudioSystem::setVoiceVolume(data->mVolume); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 435 | }break; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 436 | case STOP_OUTPUT: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 437 | StopOutputData *data = (StopOutputData *)command->mParam.get(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 438 | ALOGV("AudioCommandThread() processing stop output %d", |
| 439 | data->mIO); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 440 | svc = mService.promote(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 441 | if (svc == 0) { |
| 442 | break; |
| 443 | } |
| 444 | mLock.unlock(); |
| 445 | svc->doStopOutput(data->mIO, data->mStream, data->mSession); |
| 446 | mLock.lock(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 447 | }break; |
| 448 | case RELEASE_OUTPUT: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 449 | ReleaseOutputData *data = (ReleaseOutputData *)command->mParam.get(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 450 | ALOGV("AudioCommandThread() processing release output %d", |
| 451 | data->mIO); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 452 | svc = mService.promote(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 453 | if (svc == 0) { |
| 454 | break; |
| 455 | } |
| 456 | mLock.unlock(); |
| 457 | svc->doReleaseOutput(data->mIO); |
| 458 | mLock.lock(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 459 | }break; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 460 | case CREATE_AUDIO_PATCH: { |
| 461 | CreateAudioPatchData *data = (CreateAudioPatchData *)command->mParam.get(); |
| 462 | ALOGV("AudioCommandThread() processing create audio patch"); |
| 463 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 464 | if (af == 0) { |
| 465 | command->mStatus = PERMISSION_DENIED; |
| 466 | } else { |
| 467 | command->mStatus = af->createAudioPatch(&data->mPatch, &data->mHandle); |
| 468 | } |
| 469 | } break; |
| 470 | case RELEASE_AUDIO_PATCH: { |
| 471 | ReleaseAudioPatchData *data = (ReleaseAudioPatchData *)command->mParam.get(); |
| 472 | ALOGV("AudioCommandThread() processing release audio patch"); |
| 473 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 474 | if (af == 0) { |
| 475 | command->mStatus = PERMISSION_DENIED; |
| 476 | } else { |
| 477 | command->mStatus = af->releaseAudioPatch(data->mHandle); |
| 478 | } |
| 479 | } break; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 480 | case UPDATE_AUDIOPORT_LIST: { |
| 481 | ALOGV("AudioCommandThread() processing update audio port list"); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 482 | svc = mService.promote(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 483 | if (svc == 0) { |
| 484 | break; |
| 485 | } |
| 486 | mLock.unlock(); |
| 487 | svc->doOnAudioPortListUpdate(); |
| 488 | mLock.lock(); |
| 489 | }break; |
| 490 | case UPDATE_AUDIOPATCH_LIST: { |
| 491 | ALOGV("AudioCommandThread() processing update audio patch list"); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 492 | svc = mService.promote(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 493 | if (svc == 0) { |
| 494 | break; |
| 495 | } |
| 496 | mLock.unlock(); |
| 497 | svc->doOnAudioPatchListUpdate(); |
| 498 | mLock.lock(); |
| 499 | }break; |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 500 | case SET_AUDIOPORT_CONFIG: { |
| 501 | SetAudioPortConfigData *data = (SetAudioPortConfigData *)command->mParam.get(); |
| 502 | ALOGV("AudioCommandThread() processing set port config"); |
| 503 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 504 | if (af == 0) { |
| 505 | command->mStatus = PERMISSION_DENIED; |
| 506 | } else { |
| 507 | command->mStatus = af->setAudioPortConfig(&data->mConfig); |
| 508 | } |
| 509 | } break; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 510 | default: |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 511 | ALOGW("AudioCommandThread() unknown command %d", command->mCommand); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 512 | } |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 513 | { |
| 514 | Mutex::Autolock _l(command->mLock); |
| 515 | if (command->mWaitStatus) { |
| 516 | command->mWaitStatus = false; |
| 517 | command->mCond.signal(); |
| 518 | } |
| 519 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 520 | waitTime = INT64_MAX; |
| 521 | } else { |
| 522 | waitTime = mAudioCommands[0]->mTime - curTime; |
| 523 | break; |
| 524 | } |
| 525 | } |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 526 | // release mLock before releasing strong reference on the service as |
| 527 | // AudioPolicyService destructor calls AudioCommandThread::exit() which acquires mLock. |
| 528 | mLock.unlock(); |
| 529 | svc.clear(); |
| 530 | mLock.lock(); |
Ricardo Garcia | 05f2fdc | 2014-07-24 15:48:24 -0700 | [diff] [blame] | 531 | if (!exitPending() && mAudioCommands.isEmpty()) { |
| 532 | // release delayed commands wake lock |
| 533 | release_wake_lock(mName.string()); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 534 | ALOGV("AudioCommandThread() going to sleep"); |
| 535 | mWaitWorkCV.waitRelative(mLock, waitTime); |
| 536 | ALOGV("AudioCommandThread() waking up"); |
| 537 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 538 | } |
Ricardo Garcia | 05f2fdc | 2014-07-24 15:48:24 -0700 | [diff] [blame] | 539 | // release delayed commands wake lock before quitting |
| 540 | if (!mAudioCommands.isEmpty()) { |
| 541 | release_wake_lock(mName.string()); |
| 542 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 543 | mLock.unlock(); |
| 544 | return false; |
| 545 | } |
| 546 | |
| 547 | status_t AudioPolicyService::AudioCommandThread::dump(int fd) |
| 548 | { |
| 549 | const size_t SIZE = 256; |
| 550 | char buffer[SIZE]; |
| 551 | String8 result; |
| 552 | |
| 553 | snprintf(buffer, SIZE, "AudioCommandThread %p Dump\n", this); |
| 554 | result.append(buffer); |
| 555 | write(fd, result.string(), result.size()); |
| 556 | |
| 557 | bool locked = tryLock(mLock); |
| 558 | if (!locked) { |
| 559 | String8 result2(kCmdDeadlockedString); |
| 560 | write(fd, result2.string(), result2.size()); |
| 561 | } |
| 562 | |
| 563 | snprintf(buffer, SIZE, "- Commands:\n"); |
| 564 | result = String8(buffer); |
| 565 | result.append(" Command Time Wait pParam\n"); |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 566 | for (size_t i = 0; i < mAudioCommands.size(); i++) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 567 | mAudioCommands[i]->dump(buffer, SIZE); |
| 568 | result.append(buffer); |
| 569 | } |
| 570 | result.append(" Last Command\n"); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 571 | if (mLastCommand != 0) { |
| 572 | mLastCommand->dump(buffer, SIZE); |
| 573 | result.append(buffer); |
| 574 | } else { |
| 575 | result.append(" none\n"); |
| 576 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 577 | |
| 578 | write(fd, result.string(), result.size()); |
| 579 | |
| 580 | if (locked) mLock.unlock(); |
| 581 | |
| 582 | return NO_ERROR; |
| 583 | } |
| 584 | |
Glenn Kasten | 3d2f877 | 2012-01-27 15:25:25 -0800 | [diff] [blame] | 585 | void AudioPolicyService::AudioCommandThread::startToneCommand(ToneGenerator::tone_type type, |
| 586 | audio_stream_type_t stream) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 587 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 588 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 589 | command->mCommand = START_TONE; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 590 | sp<ToneData> data = new ToneData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 591 | data->mType = type; |
| 592 | data->mStream = stream; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 593 | command->mParam = data; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 594 | ALOGV("AudioCommandThread() adding tone start type %d, stream %d", type, stream); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 595 | sendCommand(command); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | void AudioPolicyService::AudioCommandThread::stopToneCommand() |
| 599 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 600 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 601 | command->mCommand = STOP_TONE; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 602 | ALOGV("AudioCommandThread() adding tone stop"); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 603 | sendCommand(command); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 606 | status_t AudioPolicyService::AudioCommandThread::volumeCommand(audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 607 | float volume, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 608 | audio_io_handle_t output, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 609 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 610 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 611 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 612 | command->mCommand = SET_VOLUME; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 613 | sp<VolumeData> data = new VolumeData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 614 | data->mStream = stream; |
| 615 | data->mVolume = volume; |
| 616 | data->mIO = output; |
| 617 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 618 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 619 | ALOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 620 | stream, volume, output); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 621 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 624 | status_t AudioPolicyService::AudioCommandThread::parametersCommand(audio_io_handle_t ioHandle, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 625 | const char *keyValuePairs, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 626 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 627 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 628 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 629 | command->mCommand = SET_PARAMETERS; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 630 | sp<ParametersData> data = new ParametersData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 631 | data->mIO = ioHandle; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 632 | data->mKeyValuePairs = String8(keyValuePairs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 633 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 634 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 635 | ALOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d", |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 636 | keyValuePairs, ioHandle, delayMs); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 637 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | status_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs) |
| 641 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 642 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 643 | command->mCommand = SET_VOICE_VOLUME; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 644 | sp<VoiceVolumeData> data = new VoiceVolumeData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 645 | data->mVolume = volume; |
| 646 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 647 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 648 | ALOGV("AudioCommandThread() adding set voice volume volume %f", volume); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 649 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 652 | void AudioPolicyService::AudioCommandThread::stopOutputCommand(audio_io_handle_t output, |
| 653 | audio_stream_type_t stream, |
| 654 | int session) |
| 655 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 656 | sp<AudioCommand> command = new AudioCommand(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 657 | command->mCommand = STOP_OUTPUT; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 658 | sp<StopOutputData> data = new StopOutputData(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 659 | data->mIO = output; |
| 660 | data->mStream = stream; |
| 661 | data->mSession = session; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 662 | command->mParam = data; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 663 | ALOGV("AudioCommandThread() adding stop output %d", output); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 664 | sendCommand(command); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | void AudioPolicyService::AudioCommandThread::releaseOutputCommand(audio_io_handle_t output) |
| 668 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 669 | sp<AudioCommand> command = new AudioCommand(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 670 | command->mCommand = RELEASE_OUTPUT; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 671 | sp<ReleaseOutputData> data = new ReleaseOutputData(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 672 | data->mIO = output; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 673 | command->mParam = data; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 674 | ALOGV("AudioCommandThread() adding release output %d", output); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 675 | sendCommand(command); |
| 676 | } |
| 677 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 678 | status_t AudioPolicyService::AudioCommandThread::createAudioPatchCommand( |
| 679 | const struct audio_patch *patch, |
| 680 | audio_patch_handle_t *handle, |
| 681 | int delayMs) |
| 682 | { |
| 683 | status_t status = NO_ERROR; |
| 684 | |
| 685 | sp<AudioCommand> command = new AudioCommand(); |
| 686 | command->mCommand = CREATE_AUDIO_PATCH; |
| 687 | CreateAudioPatchData *data = new CreateAudioPatchData(); |
| 688 | data->mPatch = *patch; |
| 689 | data->mHandle = *handle; |
| 690 | command->mParam = data; |
| 691 | command->mWaitStatus = true; |
| 692 | ALOGV("AudioCommandThread() adding create patch delay %d", delayMs); |
| 693 | status = sendCommand(command, delayMs); |
| 694 | if (status == NO_ERROR) { |
| 695 | *handle = data->mHandle; |
| 696 | } |
| 697 | return status; |
| 698 | } |
| 699 | |
| 700 | status_t AudioPolicyService::AudioCommandThread::releaseAudioPatchCommand(audio_patch_handle_t handle, |
| 701 | int delayMs) |
| 702 | { |
| 703 | sp<AudioCommand> command = new AudioCommand(); |
| 704 | command->mCommand = RELEASE_AUDIO_PATCH; |
| 705 | ReleaseAudioPatchData *data = new ReleaseAudioPatchData(); |
| 706 | data->mHandle = handle; |
| 707 | command->mParam = data; |
| 708 | command->mWaitStatus = true; |
| 709 | ALOGV("AudioCommandThread() adding release patch delay %d", delayMs); |
| 710 | return sendCommand(command, delayMs); |
| 711 | } |
| 712 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 713 | void AudioPolicyService::AudioCommandThread::updateAudioPortListCommand() |
| 714 | { |
| 715 | sp<AudioCommand> command = new AudioCommand(); |
| 716 | command->mCommand = UPDATE_AUDIOPORT_LIST; |
| 717 | ALOGV("AudioCommandThread() adding update audio port list"); |
| 718 | sendCommand(command); |
| 719 | } |
| 720 | |
| 721 | void AudioPolicyService::AudioCommandThread::updateAudioPatchListCommand() |
| 722 | { |
| 723 | sp<AudioCommand>command = new AudioCommand(); |
| 724 | command->mCommand = UPDATE_AUDIOPATCH_LIST; |
| 725 | ALOGV("AudioCommandThread() adding update audio patch list"); |
| 726 | sendCommand(command); |
| 727 | } |
| 728 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 729 | status_t AudioPolicyService::AudioCommandThread::setAudioPortConfigCommand( |
| 730 | const struct audio_port_config *config, int delayMs) |
| 731 | { |
| 732 | sp<AudioCommand> command = new AudioCommand(); |
| 733 | command->mCommand = SET_AUDIOPORT_CONFIG; |
| 734 | SetAudioPortConfigData *data = new SetAudioPortConfigData(); |
| 735 | data->mConfig = *config; |
| 736 | command->mParam = data; |
| 737 | command->mWaitStatus = true; |
| 738 | ALOGV("AudioCommandThread() adding set port config delay %d", delayMs); |
| 739 | return sendCommand(command, delayMs); |
| 740 | } |
| 741 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 742 | status_t AudioPolicyService::AudioCommandThread::sendCommand(sp<AudioCommand>& command, int delayMs) |
| 743 | { |
| 744 | { |
| 745 | Mutex::Autolock _l(mLock); |
| 746 | insertCommand_l(command, delayMs); |
| 747 | mWaitWorkCV.signal(); |
| 748 | } |
| 749 | Mutex::Autolock _l(command->mLock); |
| 750 | while (command->mWaitStatus) { |
| 751 | nsecs_t timeOutNs = kAudioCommandTimeoutNs + milliseconds(delayMs); |
| 752 | if (command->mCond.waitRelative(command->mLock, timeOutNs) != NO_ERROR) { |
| 753 | command->mStatus = TIMED_OUT; |
| 754 | command->mWaitStatus = false; |
| 755 | } |
| 756 | } |
| 757 | return command->mStatus; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 760 | // insertCommand_l() must be called with mLock held |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 761 | void AudioPolicyService::AudioCommandThread::insertCommand_l(sp<AudioCommand>& command, int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 762 | { |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 763 | ssize_t i; // not size_t because i will count down to -1 |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 764 | Vector < sp<AudioCommand> > removedCommands; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 765 | command->mTime = systemTime() + milliseconds(delayMs); |
| 766 | |
| 767 | // acquire wake lock to make sure delayed commands are processed |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 768 | if (mAudioCommands.isEmpty()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 769 | acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string()); |
| 770 | } |
| 771 | |
| 772 | // check same pending commands with later time stamps and eliminate them |
| 773 | for (i = mAudioCommands.size()-1; i >= 0; i--) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 774 | sp<AudioCommand> command2 = mAudioCommands[i]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 775 | // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands |
| 776 | if (command2->mTime <= command->mTime) break; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 777 | |
| 778 | // create audio patch or release audio patch commands are equivalent |
| 779 | // with regard to filtering |
| 780 | if ((command->mCommand == CREATE_AUDIO_PATCH) || |
| 781 | (command->mCommand == RELEASE_AUDIO_PATCH)) { |
| 782 | if ((command2->mCommand != CREATE_AUDIO_PATCH) && |
| 783 | (command2->mCommand != RELEASE_AUDIO_PATCH)) { |
| 784 | continue; |
| 785 | } |
| 786 | } else if (command2->mCommand != command->mCommand) continue; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 787 | |
| 788 | switch (command->mCommand) { |
| 789 | case SET_PARAMETERS: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 790 | ParametersData *data = (ParametersData *)command->mParam.get(); |
| 791 | ParametersData *data2 = (ParametersData *)command2->mParam.get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 792 | if (data->mIO != data2->mIO) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 793 | ALOGV("Comparing parameter command %s to new command %s", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 794 | data2->mKeyValuePairs.string(), data->mKeyValuePairs.string()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 795 | AudioParameter param = AudioParameter(data->mKeyValuePairs); |
| 796 | AudioParameter param2 = AudioParameter(data2->mKeyValuePairs); |
| 797 | for (size_t j = 0; j < param.size(); j++) { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 798 | String8 key; |
| 799 | String8 value; |
| 800 | param.getAt(j, key, value); |
| 801 | for (size_t k = 0; k < param2.size(); k++) { |
| 802 | String8 key2; |
| 803 | String8 value2; |
| 804 | param2.getAt(k, key2, value2); |
| 805 | if (key2 == key) { |
| 806 | param2.remove(key2); |
| 807 | ALOGV("Filtering out parameter %s", key2.string()); |
| 808 | break; |
| 809 | } |
| 810 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 811 | } |
| 812 | // if all keys have been filtered out, remove the command. |
| 813 | // otherwise, update the key value pairs |
| 814 | if (param2.size() == 0) { |
| 815 | removedCommands.add(command2); |
| 816 | } else { |
| 817 | data2->mKeyValuePairs = param2.toString(); |
| 818 | } |
Eric Laurent | 21e5456 | 2013-09-23 12:08:05 -0700 | [diff] [blame] | 819 | command->mTime = command2->mTime; |
| 820 | // force delayMs to non 0 so that code below does not request to wait for |
| 821 | // command status as the command is now delayed |
| 822 | delayMs = 1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 823 | } break; |
| 824 | |
| 825 | case SET_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 826 | VolumeData *data = (VolumeData *)command->mParam.get(); |
| 827 | VolumeData *data2 = (VolumeData *)command2->mParam.get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 828 | if (data->mIO != data2->mIO) break; |
| 829 | if (data->mStream != data2->mStream) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 830 | ALOGV("Filtering out volume command on output %d for stream %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 831 | data->mIO, data->mStream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 832 | removedCommands.add(command2); |
Eric Laurent | 21e5456 | 2013-09-23 12:08:05 -0700 | [diff] [blame] | 833 | command->mTime = command2->mTime; |
| 834 | // force delayMs to non 0 so that code below does not request to wait for |
| 835 | // command status as the command is now delayed |
| 836 | delayMs = 1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 837 | } break; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 838 | |
| 839 | case CREATE_AUDIO_PATCH: |
| 840 | case RELEASE_AUDIO_PATCH: { |
| 841 | audio_patch_handle_t handle; |
| 842 | if (command->mCommand == CREATE_AUDIO_PATCH) { |
| 843 | handle = ((CreateAudioPatchData *)command->mParam.get())->mHandle; |
| 844 | } else { |
| 845 | handle = ((ReleaseAudioPatchData *)command->mParam.get())->mHandle; |
| 846 | } |
| 847 | audio_patch_handle_t handle2; |
| 848 | if (command2->mCommand == CREATE_AUDIO_PATCH) { |
| 849 | handle2 = ((CreateAudioPatchData *)command2->mParam.get())->mHandle; |
| 850 | } else { |
| 851 | handle2 = ((ReleaseAudioPatchData *)command2->mParam.get())->mHandle; |
| 852 | } |
| 853 | if (handle != handle2) break; |
| 854 | ALOGV("Filtering out %s audio patch command for handle %d", |
| 855 | (command->mCommand == CREATE_AUDIO_PATCH) ? "create" : "release", handle); |
| 856 | removedCommands.add(command2); |
| 857 | command->mTime = command2->mTime; |
| 858 | // force delayMs to non 0 so that code below does not request to wait for |
| 859 | // command status as the command is now delayed |
| 860 | delayMs = 1; |
| 861 | } break; |
| 862 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 863 | case START_TONE: |
| 864 | case STOP_TONE: |
| 865 | default: |
| 866 | break; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | // remove filtered commands |
| 871 | for (size_t j = 0; j < removedCommands.size(); j++) { |
| 872 | // removed commands always have time stamps greater than current command |
| 873 | for (size_t k = i + 1; k < mAudioCommands.size(); k++) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 874 | if (mAudioCommands[k].get() == removedCommands[j].get()) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 875 | ALOGV("suppressing command: %d", mAudioCommands[k]->mCommand); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 876 | mAudioCommands.removeAt(k); |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | removedCommands.clear(); |
| 882 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 883 | // Disable wait for status if delay is not 0 |
| 884 | if (delayMs != 0) { |
Eric Laurent | cec4abb | 2012-07-03 12:23:02 -0700 | [diff] [blame] | 885 | command->mWaitStatus = false; |
| 886 | } |
Eric Laurent | cec4abb | 2012-07-03 12:23:02 -0700 | [diff] [blame] | 887 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 888 | // insert command at the right place according to its time stamp |
Eric Laurent | 1e693b5 | 2014-07-09 15:03:28 -0700 | [diff] [blame] | 889 | ALOGV("inserting command: %d at index %zd, num commands %zu", |
| 890 | command->mCommand, i+1, mAudioCommands.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 891 | mAudioCommands.insertAt(command, i + 1); |
| 892 | } |
| 893 | |
| 894 | void AudioPolicyService::AudioCommandThread::exit() |
| 895 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 896 | ALOGV("AudioCommandThread::exit"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 897 | { |
| 898 | AutoMutex _l(mLock); |
| 899 | requestExit(); |
| 900 | mWaitWorkCV.signal(); |
| 901 | } |
| 902 | requestExitAndWait(); |
| 903 | } |
| 904 | |
| 905 | void AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size) |
| 906 | { |
| 907 | snprintf(buffer, size, " %02d %06d.%03d %01u %p\n", |
| 908 | mCommand, |
| 909 | (int)ns2s(mTime), |
| 910 | (int)ns2ms(mTime)%1000, |
| 911 | mWaitStatus, |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 912 | mParam.get()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 915 | /******* helpers for the service_ops callbacks defined below *********/ |
| 916 | void AudioPolicyService::setParameters(audio_io_handle_t ioHandle, |
| 917 | const char *keyValuePairs, |
| 918 | int delayMs) |
| 919 | { |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 920 | mAudioCommandThread->parametersCommand(ioHandle, keyValuePairs, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 921 | delayMs); |
| 922 | } |
| 923 | |
| 924 | int AudioPolicyService::setStreamVolume(audio_stream_type_t stream, |
| 925 | float volume, |
| 926 | audio_io_handle_t output, |
| 927 | int delayMs) |
| 928 | { |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 929 | return (int)mAudioCommandThread->volumeCommand(stream, volume, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 930 | output, delayMs); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | int AudioPolicyService::startTone(audio_policy_tone_t tone, |
| 934 | audio_stream_type_t stream) |
| 935 | { |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 936 | if (tone != AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 937 | ALOGE("startTone: illegal tone requested (%d)", tone); |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 938 | } |
| 939 | if (stream != AUDIO_STREAM_VOICE_CALL) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 940 | ALOGE("startTone: illegal stream (%d) requested for tone %d", stream, |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 941 | tone); |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 942 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 943 | mTonePlaybackThread->startToneCommand(ToneGenerator::TONE_SUP_CALL_WAITING, |
| 944 | AUDIO_STREAM_VOICE_CALL); |
| 945 | return 0; |
| 946 | } |
| 947 | |
| 948 | int AudioPolicyService::stopTone() |
| 949 | { |
| 950 | mTonePlaybackThread->stopToneCommand(); |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | int AudioPolicyService::setVoiceVolume(float volume, int delayMs) |
| 955 | { |
| 956 | return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs); |
| 957 | } |
| 958 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 959 | extern "C" { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 960 | audio_module_handle_t aps_load_hw_module(void *service __unused, |
| 961 | const char *name); |
| 962 | audio_io_handle_t aps_open_output(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 963 | audio_devices_t *pDevices, |
| 964 | uint32_t *pSamplingRate, |
| 965 | audio_format_t *pFormat, |
| 966 | audio_channel_mask_t *pChannelMask, |
| 967 | uint32_t *pLatencyMs, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 968 | audio_output_flags_t flags); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 969 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 970 | audio_io_handle_t aps_open_output_on_module(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 971 | audio_module_handle_t module, |
| 972 | audio_devices_t *pDevices, |
| 973 | uint32_t *pSamplingRate, |
| 974 | audio_format_t *pFormat, |
| 975 | audio_channel_mask_t *pChannelMask, |
| 976 | uint32_t *pLatencyMs, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 977 | audio_output_flags_t flags, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 978 | const audio_offload_info_t *offloadInfo); |
| 979 | audio_io_handle_t aps_open_dup_output(void *service __unused, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 980 | audio_io_handle_t output1, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 981 | audio_io_handle_t output2); |
| 982 | int aps_close_output(void *service __unused, audio_io_handle_t output); |
| 983 | int aps_suspend_output(void *service __unused, audio_io_handle_t output); |
| 984 | int aps_restore_output(void *service __unused, audio_io_handle_t output); |
| 985 | audio_io_handle_t aps_open_input(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 986 | audio_devices_t *pDevices, |
| 987 | uint32_t *pSamplingRate, |
| 988 | audio_format_t *pFormat, |
| 989 | audio_channel_mask_t *pChannelMask, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 990 | audio_in_acoustics_t acoustics __unused); |
| 991 | audio_io_handle_t aps_open_input_on_module(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 992 | audio_module_handle_t module, |
| 993 | audio_devices_t *pDevices, |
| 994 | uint32_t *pSamplingRate, |
| 995 | audio_format_t *pFormat, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 996 | audio_channel_mask_t *pChannelMask); |
| 997 | int aps_close_input(void *service __unused, audio_io_handle_t input); |
| 998 | int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream); |
| 999 | int aps_move_effects(void *service __unused, int session, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1000 | audio_io_handle_t src_output, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1001 | audio_io_handle_t dst_output); |
| 1002 | char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle, |
| 1003 | const char *keys); |
| 1004 | void aps_set_parameters(void *service, audio_io_handle_t io_handle, |
| 1005 | const char *kv_pairs, int delay_ms); |
| 1006 | int aps_set_stream_volume(void *service, audio_stream_type_t stream, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1007 | float volume, audio_io_handle_t output, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1008 | int delay_ms); |
| 1009 | int aps_start_tone(void *service, audio_policy_tone_t tone, |
| 1010 | audio_stream_type_t stream); |
| 1011 | int aps_stop_tone(void *service); |
| 1012 | int aps_set_voice_volume(void *service, float volume, int delay_ms); |
| 1013 | }; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1014 | |
| 1015 | namespace { |
| 1016 | struct audio_policy_service_ops aps_ops = { |
Glenn Kasten | 01d3acb | 2014-02-06 08:24:07 -0800 | [diff] [blame] | 1017 | .open_output = aps_open_output, |
| 1018 | .open_duplicate_output = aps_open_dup_output, |
| 1019 | .close_output = aps_close_output, |
| 1020 | .suspend_output = aps_suspend_output, |
| 1021 | .restore_output = aps_restore_output, |
| 1022 | .open_input = aps_open_input, |
| 1023 | .close_input = aps_close_input, |
| 1024 | .set_stream_volume = aps_set_stream_volume, |
Glenn Kasten | d2304db | 2014-02-03 07:40:31 -0800 | [diff] [blame] | 1025 | .invalidate_stream = aps_invalidate_stream, |
Glenn Kasten | 01d3acb | 2014-02-06 08:24:07 -0800 | [diff] [blame] | 1026 | .set_parameters = aps_set_parameters, |
| 1027 | .get_parameters = aps_get_parameters, |
| 1028 | .start_tone = aps_start_tone, |
| 1029 | .stop_tone = aps_stop_tone, |
| 1030 | .set_voice_volume = aps_set_voice_volume, |
| 1031 | .move_effects = aps_move_effects, |
| 1032 | .load_hw_module = aps_load_hw_module, |
| 1033 | .open_output_on_module = aps_open_output_on_module, |
| 1034 | .open_input_on_module = aps_open_input_on_module, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1035 | }; |
| 1036 | }; // namespace <unnamed> |
| 1037 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1038 | }; // namespace android |