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