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