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 | } |
| 517 | // release delayed commands wake lock |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 518 | if (mAudioCommands.isEmpty()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 519 | release_wake_lock(mName.string()); |
| 520 | } |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 521 | // release mLock before releasing strong reference on the service as |
| 522 | // AudioPolicyService destructor calls AudioCommandThread::exit() which acquires mLock. |
| 523 | mLock.unlock(); |
| 524 | svc.clear(); |
| 525 | mLock.lock(); |
| 526 | if (!exitPending()) { |
| 527 | ALOGV("AudioCommandThread() going to sleep"); |
| 528 | mWaitWorkCV.waitRelative(mLock, waitTime); |
| 529 | ALOGV("AudioCommandThread() waking up"); |
| 530 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 531 | } |
| 532 | mLock.unlock(); |
| 533 | return false; |
| 534 | } |
| 535 | |
| 536 | status_t AudioPolicyService::AudioCommandThread::dump(int fd) |
| 537 | { |
| 538 | const size_t SIZE = 256; |
| 539 | char buffer[SIZE]; |
| 540 | String8 result; |
| 541 | |
| 542 | snprintf(buffer, SIZE, "AudioCommandThread %p Dump\n", this); |
| 543 | result.append(buffer); |
| 544 | write(fd, result.string(), result.size()); |
| 545 | |
| 546 | bool locked = tryLock(mLock); |
| 547 | if (!locked) { |
| 548 | String8 result2(kCmdDeadlockedString); |
| 549 | write(fd, result2.string(), result2.size()); |
| 550 | } |
| 551 | |
| 552 | snprintf(buffer, SIZE, "- Commands:\n"); |
| 553 | result = String8(buffer); |
| 554 | result.append(" Command Time Wait pParam\n"); |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 555 | for (size_t i = 0; i < mAudioCommands.size(); i++) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 556 | mAudioCommands[i]->dump(buffer, SIZE); |
| 557 | result.append(buffer); |
| 558 | } |
| 559 | result.append(" Last Command\n"); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 560 | if (mLastCommand != 0) { |
| 561 | mLastCommand->dump(buffer, SIZE); |
| 562 | result.append(buffer); |
| 563 | } else { |
| 564 | result.append(" none\n"); |
| 565 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 566 | |
| 567 | write(fd, result.string(), result.size()); |
| 568 | |
| 569 | if (locked) mLock.unlock(); |
| 570 | |
| 571 | return NO_ERROR; |
| 572 | } |
| 573 | |
Glenn Kasten | 3d2f877 | 2012-01-27 15:25:25 -0800 | [diff] [blame] | 574 | void AudioPolicyService::AudioCommandThread::startToneCommand(ToneGenerator::tone_type type, |
| 575 | audio_stream_type_t stream) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 576 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 577 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 578 | command->mCommand = START_TONE; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 579 | sp<ToneData> data = new ToneData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 580 | data->mType = type; |
| 581 | data->mStream = stream; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 582 | command->mParam = data; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 583 | ALOGV("AudioCommandThread() adding tone start type %d, stream %d", type, stream); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 584 | sendCommand(command); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | void AudioPolicyService::AudioCommandThread::stopToneCommand() |
| 588 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 589 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 590 | command->mCommand = STOP_TONE; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 591 | ALOGV("AudioCommandThread() adding tone stop"); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 592 | sendCommand(command); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 595 | status_t AudioPolicyService::AudioCommandThread::volumeCommand(audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 596 | float volume, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 597 | audio_io_handle_t output, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 598 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 599 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 600 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 601 | command->mCommand = SET_VOLUME; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 602 | sp<VolumeData> data = new VolumeData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 603 | data->mStream = stream; |
| 604 | data->mVolume = volume; |
| 605 | data->mIO = output; |
| 606 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 607 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 608 | ALOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 609 | stream, volume, output); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 610 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 613 | status_t AudioPolicyService::AudioCommandThread::parametersCommand(audio_io_handle_t ioHandle, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 614 | const char *keyValuePairs, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 615 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 616 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 617 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 618 | command->mCommand = SET_PARAMETERS; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 619 | sp<ParametersData> data = new ParametersData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 620 | data->mIO = ioHandle; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 621 | data->mKeyValuePairs = String8(keyValuePairs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 622 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 623 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 624 | ALOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d", |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 625 | keyValuePairs, ioHandle, delayMs); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 626 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | status_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs) |
| 630 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 631 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 632 | command->mCommand = SET_VOICE_VOLUME; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 633 | sp<VoiceVolumeData> data = new VoiceVolumeData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 634 | data->mVolume = volume; |
| 635 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 636 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 637 | ALOGV("AudioCommandThread() adding set voice volume volume %f", volume); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 638 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 641 | void AudioPolicyService::AudioCommandThread::stopOutputCommand(audio_io_handle_t output, |
| 642 | audio_stream_type_t stream, |
| 643 | int session) |
| 644 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 645 | sp<AudioCommand> command = new AudioCommand(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 646 | command->mCommand = STOP_OUTPUT; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 647 | sp<StopOutputData> data = new StopOutputData(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 648 | data->mIO = output; |
| 649 | data->mStream = stream; |
| 650 | data->mSession = session; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 651 | command->mParam = data; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 652 | ALOGV("AudioCommandThread() adding stop output %d", output); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 653 | sendCommand(command); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | void AudioPolicyService::AudioCommandThread::releaseOutputCommand(audio_io_handle_t output) |
| 657 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 658 | sp<AudioCommand> command = new AudioCommand(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 659 | command->mCommand = RELEASE_OUTPUT; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 660 | sp<ReleaseOutputData> data = new ReleaseOutputData(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 661 | data->mIO = output; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 662 | command->mParam = data; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 663 | ALOGV("AudioCommandThread() adding release output %d", output); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 664 | sendCommand(command); |
| 665 | } |
| 666 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 667 | status_t AudioPolicyService::AudioCommandThread::createAudioPatchCommand( |
| 668 | const struct audio_patch *patch, |
| 669 | audio_patch_handle_t *handle, |
| 670 | int delayMs) |
| 671 | { |
| 672 | status_t status = NO_ERROR; |
| 673 | |
| 674 | sp<AudioCommand> command = new AudioCommand(); |
| 675 | command->mCommand = CREATE_AUDIO_PATCH; |
| 676 | CreateAudioPatchData *data = new CreateAudioPatchData(); |
| 677 | data->mPatch = *patch; |
| 678 | data->mHandle = *handle; |
| 679 | command->mParam = data; |
| 680 | command->mWaitStatus = true; |
| 681 | ALOGV("AudioCommandThread() adding create patch delay %d", delayMs); |
| 682 | status = sendCommand(command, delayMs); |
| 683 | if (status == NO_ERROR) { |
| 684 | *handle = data->mHandle; |
| 685 | } |
| 686 | return status; |
| 687 | } |
| 688 | |
| 689 | status_t AudioPolicyService::AudioCommandThread::releaseAudioPatchCommand(audio_patch_handle_t handle, |
| 690 | int delayMs) |
| 691 | { |
| 692 | sp<AudioCommand> command = new AudioCommand(); |
| 693 | command->mCommand = RELEASE_AUDIO_PATCH; |
| 694 | ReleaseAudioPatchData *data = new ReleaseAudioPatchData(); |
| 695 | data->mHandle = handle; |
| 696 | command->mParam = data; |
| 697 | command->mWaitStatus = true; |
| 698 | ALOGV("AudioCommandThread() adding release patch delay %d", delayMs); |
| 699 | return sendCommand(command, delayMs); |
| 700 | } |
| 701 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 702 | void AudioPolicyService::AudioCommandThread::updateAudioPortListCommand() |
| 703 | { |
| 704 | sp<AudioCommand> command = new AudioCommand(); |
| 705 | command->mCommand = UPDATE_AUDIOPORT_LIST; |
| 706 | ALOGV("AudioCommandThread() adding update audio port list"); |
| 707 | sendCommand(command); |
| 708 | } |
| 709 | |
| 710 | void AudioPolicyService::AudioCommandThread::updateAudioPatchListCommand() |
| 711 | { |
| 712 | sp<AudioCommand>command = new AudioCommand(); |
| 713 | command->mCommand = UPDATE_AUDIOPATCH_LIST; |
| 714 | ALOGV("AudioCommandThread() adding update audio patch list"); |
| 715 | sendCommand(command); |
| 716 | } |
| 717 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 718 | status_t AudioPolicyService::AudioCommandThread::setAudioPortConfigCommand( |
| 719 | const struct audio_port_config *config, int delayMs) |
| 720 | { |
| 721 | sp<AudioCommand> command = new AudioCommand(); |
| 722 | command->mCommand = SET_AUDIOPORT_CONFIG; |
| 723 | SetAudioPortConfigData *data = new SetAudioPortConfigData(); |
| 724 | data->mConfig = *config; |
| 725 | command->mParam = data; |
| 726 | command->mWaitStatus = true; |
| 727 | ALOGV("AudioCommandThread() adding set port config delay %d", delayMs); |
| 728 | return sendCommand(command, delayMs); |
| 729 | } |
| 730 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 731 | status_t AudioPolicyService::AudioCommandThread::sendCommand(sp<AudioCommand>& command, int delayMs) |
| 732 | { |
| 733 | { |
| 734 | Mutex::Autolock _l(mLock); |
| 735 | insertCommand_l(command, delayMs); |
| 736 | mWaitWorkCV.signal(); |
| 737 | } |
| 738 | Mutex::Autolock _l(command->mLock); |
| 739 | while (command->mWaitStatus) { |
| 740 | nsecs_t timeOutNs = kAudioCommandTimeoutNs + milliseconds(delayMs); |
| 741 | if (command->mCond.waitRelative(command->mLock, timeOutNs) != NO_ERROR) { |
| 742 | command->mStatus = TIMED_OUT; |
| 743 | command->mWaitStatus = false; |
| 744 | } |
| 745 | } |
| 746 | return command->mStatus; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 747 | } |
| 748 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 749 | // insertCommand_l() must be called with mLock held |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 750 | void AudioPolicyService::AudioCommandThread::insertCommand_l(sp<AudioCommand>& command, int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 751 | { |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 752 | 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] | 753 | Vector < sp<AudioCommand> > removedCommands; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 754 | command->mTime = systemTime() + milliseconds(delayMs); |
| 755 | |
| 756 | // acquire wake lock to make sure delayed commands are processed |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 757 | if (mAudioCommands.isEmpty()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 758 | acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string()); |
| 759 | } |
| 760 | |
| 761 | // check same pending commands with later time stamps and eliminate them |
| 762 | for (i = mAudioCommands.size()-1; i >= 0; i--) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 763 | sp<AudioCommand> command2 = mAudioCommands[i]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 764 | // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands |
| 765 | if (command2->mTime <= command->mTime) break; |
| 766 | if (command2->mCommand != command->mCommand) continue; |
| 767 | |
| 768 | switch (command->mCommand) { |
| 769 | case SET_PARAMETERS: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 770 | ParametersData *data = (ParametersData *)command->mParam.get(); |
| 771 | ParametersData *data2 = (ParametersData *)command2->mParam.get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 772 | if (data->mIO != data2->mIO) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 773 | ALOGV("Comparing parameter command %s to new command %s", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 774 | data2->mKeyValuePairs.string(), data->mKeyValuePairs.string()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 775 | AudioParameter param = AudioParameter(data->mKeyValuePairs); |
| 776 | AudioParameter param2 = AudioParameter(data2->mKeyValuePairs); |
| 777 | for (size_t j = 0; j < param.size(); j++) { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 778 | String8 key; |
| 779 | String8 value; |
| 780 | param.getAt(j, key, value); |
| 781 | for (size_t k = 0; k < param2.size(); k++) { |
| 782 | String8 key2; |
| 783 | String8 value2; |
| 784 | param2.getAt(k, key2, value2); |
| 785 | if (key2 == key) { |
| 786 | param2.remove(key2); |
| 787 | ALOGV("Filtering out parameter %s", key2.string()); |
| 788 | break; |
| 789 | } |
| 790 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 791 | } |
| 792 | // if all keys have been filtered out, remove the command. |
| 793 | // otherwise, update the key value pairs |
| 794 | if (param2.size() == 0) { |
| 795 | removedCommands.add(command2); |
| 796 | } else { |
| 797 | data2->mKeyValuePairs = param2.toString(); |
| 798 | } |
Eric Laurent | 21e5456 | 2013-09-23 12:08:05 -0700 | [diff] [blame] | 799 | command->mTime = command2->mTime; |
| 800 | // force delayMs to non 0 so that code below does not request to wait for |
| 801 | // command status as the command is now delayed |
| 802 | delayMs = 1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 803 | } break; |
| 804 | |
| 805 | case SET_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 806 | VolumeData *data = (VolumeData *)command->mParam.get(); |
| 807 | VolumeData *data2 = (VolumeData *)command2->mParam.get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 808 | if (data->mIO != data2->mIO) break; |
| 809 | if (data->mStream != data2->mStream) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 810 | ALOGV("Filtering out volume command on output %d for stream %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 811 | data->mIO, data->mStream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 812 | removedCommands.add(command2); |
Eric Laurent | 21e5456 | 2013-09-23 12:08:05 -0700 | [diff] [blame] | 813 | command->mTime = command2->mTime; |
| 814 | // force delayMs to non 0 so that code below does not request to wait for |
| 815 | // command status as the command is now delayed |
| 816 | delayMs = 1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 817 | } break; |
| 818 | case START_TONE: |
| 819 | case STOP_TONE: |
| 820 | default: |
| 821 | break; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | // remove filtered commands |
| 826 | for (size_t j = 0; j < removedCommands.size(); j++) { |
| 827 | // removed commands always have time stamps greater than current command |
| 828 | for (size_t k = i + 1; k < mAudioCommands.size(); k++) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 829 | if (mAudioCommands[k].get() == removedCommands[j].get()) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 830 | ALOGV("suppressing command: %d", mAudioCommands[k]->mCommand); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 831 | mAudioCommands.removeAt(k); |
| 832 | break; |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | removedCommands.clear(); |
| 837 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 838 | // Disable wait for status if delay is not 0 |
| 839 | if (delayMs != 0) { |
Eric Laurent | cec4abb | 2012-07-03 12:23:02 -0700 | [diff] [blame] | 840 | command->mWaitStatus = false; |
| 841 | } |
Eric Laurent | cec4abb | 2012-07-03 12:23:02 -0700 | [diff] [blame] | 842 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 843 | // insert command at the right place according to its time stamp |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 844 | ALOGV("inserting command: %d at index %d, num commands %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 845 | command->mCommand, (int)i+1, mAudioCommands.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 846 | mAudioCommands.insertAt(command, i + 1); |
| 847 | } |
| 848 | |
| 849 | void AudioPolicyService::AudioCommandThread::exit() |
| 850 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 851 | ALOGV("AudioCommandThread::exit"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 852 | { |
| 853 | AutoMutex _l(mLock); |
| 854 | requestExit(); |
| 855 | mWaitWorkCV.signal(); |
| 856 | } |
| 857 | requestExitAndWait(); |
| 858 | } |
| 859 | |
| 860 | void AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size) |
| 861 | { |
| 862 | snprintf(buffer, size, " %02d %06d.%03d %01u %p\n", |
| 863 | mCommand, |
| 864 | (int)ns2s(mTime), |
| 865 | (int)ns2ms(mTime)%1000, |
| 866 | mWaitStatus, |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 867 | mParam.get()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 870 | /******* helpers for the service_ops callbacks defined below *********/ |
| 871 | void AudioPolicyService::setParameters(audio_io_handle_t ioHandle, |
| 872 | const char *keyValuePairs, |
| 873 | int delayMs) |
| 874 | { |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 875 | mAudioCommandThread->parametersCommand(ioHandle, keyValuePairs, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 876 | delayMs); |
| 877 | } |
| 878 | |
| 879 | int AudioPolicyService::setStreamVolume(audio_stream_type_t stream, |
| 880 | float volume, |
| 881 | audio_io_handle_t output, |
| 882 | int delayMs) |
| 883 | { |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 884 | return (int)mAudioCommandThread->volumeCommand(stream, volume, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 885 | output, delayMs); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | int AudioPolicyService::startTone(audio_policy_tone_t tone, |
| 889 | audio_stream_type_t stream) |
| 890 | { |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 891 | if (tone != AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 892 | ALOGE("startTone: illegal tone requested (%d)", tone); |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 893 | } |
| 894 | if (stream != AUDIO_STREAM_VOICE_CALL) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 895 | ALOGE("startTone: illegal stream (%d) requested for tone %d", stream, |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 896 | tone); |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 897 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 898 | mTonePlaybackThread->startToneCommand(ToneGenerator::TONE_SUP_CALL_WAITING, |
| 899 | AUDIO_STREAM_VOICE_CALL); |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | int AudioPolicyService::stopTone() |
| 904 | { |
| 905 | mTonePlaybackThread->stopToneCommand(); |
| 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | int AudioPolicyService::setVoiceVolume(float volume, int delayMs) |
| 910 | { |
| 911 | return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs); |
| 912 | } |
| 913 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 914 | extern "C" { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 915 | audio_module_handle_t aps_load_hw_module(void *service __unused, |
| 916 | const char *name); |
| 917 | audio_io_handle_t aps_open_output(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 918 | audio_devices_t *pDevices, |
| 919 | uint32_t *pSamplingRate, |
| 920 | audio_format_t *pFormat, |
| 921 | audio_channel_mask_t *pChannelMask, |
| 922 | uint32_t *pLatencyMs, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 923 | audio_output_flags_t flags); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 924 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 925 | audio_io_handle_t aps_open_output_on_module(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 926 | audio_module_handle_t module, |
| 927 | audio_devices_t *pDevices, |
| 928 | uint32_t *pSamplingRate, |
| 929 | audio_format_t *pFormat, |
| 930 | audio_channel_mask_t *pChannelMask, |
| 931 | uint32_t *pLatencyMs, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 932 | audio_output_flags_t flags, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 933 | const audio_offload_info_t *offloadInfo); |
| 934 | audio_io_handle_t aps_open_dup_output(void *service __unused, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 935 | audio_io_handle_t output1, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 936 | audio_io_handle_t output2); |
| 937 | int aps_close_output(void *service __unused, audio_io_handle_t output); |
| 938 | int aps_suspend_output(void *service __unused, audio_io_handle_t output); |
| 939 | int aps_restore_output(void *service __unused, audio_io_handle_t output); |
| 940 | audio_io_handle_t aps_open_input(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 941 | audio_devices_t *pDevices, |
| 942 | uint32_t *pSamplingRate, |
| 943 | audio_format_t *pFormat, |
| 944 | audio_channel_mask_t *pChannelMask, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 945 | audio_in_acoustics_t acoustics __unused); |
| 946 | audio_io_handle_t aps_open_input_on_module(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 947 | audio_module_handle_t module, |
| 948 | audio_devices_t *pDevices, |
| 949 | uint32_t *pSamplingRate, |
| 950 | audio_format_t *pFormat, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 951 | audio_channel_mask_t *pChannelMask); |
| 952 | int aps_close_input(void *service __unused, audio_io_handle_t input); |
| 953 | int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream); |
| 954 | int aps_move_effects(void *service __unused, int session, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 955 | audio_io_handle_t src_output, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 956 | audio_io_handle_t dst_output); |
| 957 | char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle, |
| 958 | const char *keys); |
| 959 | void aps_set_parameters(void *service, audio_io_handle_t io_handle, |
| 960 | const char *kv_pairs, int delay_ms); |
| 961 | int aps_set_stream_volume(void *service, audio_stream_type_t stream, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 962 | float volume, audio_io_handle_t output, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 963 | int delay_ms); |
| 964 | int aps_start_tone(void *service, audio_policy_tone_t tone, |
| 965 | audio_stream_type_t stream); |
| 966 | int aps_stop_tone(void *service); |
| 967 | int aps_set_voice_volume(void *service, float volume, int delay_ms); |
| 968 | }; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 969 | |
| 970 | namespace { |
| 971 | struct audio_policy_service_ops aps_ops = { |
Glenn Kasten | 01d3acb | 2014-02-06 08:24:07 -0800 | [diff] [blame] | 972 | .open_output = aps_open_output, |
| 973 | .open_duplicate_output = aps_open_dup_output, |
| 974 | .close_output = aps_close_output, |
| 975 | .suspend_output = aps_suspend_output, |
| 976 | .restore_output = aps_restore_output, |
| 977 | .open_input = aps_open_input, |
| 978 | .close_input = aps_close_input, |
| 979 | .set_stream_volume = aps_set_stream_volume, |
Glenn Kasten | d2304db | 2014-02-03 07:40:31 -0800 | [diff] [blame] | 980 | .invalidate_stream = aps_invalidate_stream, |
Glenn Kasten | 01d3acb | 2014-02-06 08:24:07 -0800 | [diff] [blame] | 981 | .set_parameters = aps_set_parameters, |
| 982 | .get_parameters = aps_get_parameters, |
| 983 | .start_tone = aps_start_tone, |
| 984 | .stop_tone = aps_stop_tone, |
| 985 | .set_voice_volume = aps_set_voice_volume, |
| 986 | .move_effects = aps_move_effects, |
| 987 | .load_hw_module = aps_load_hw_module, |
| 988 | .open_output_on_module = aps_open_output_on_module, |
| 989 | .open_input_on_module = aps_open_input_on_module, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 990 | }; |
| 991 | }; // namespace <unnamed> |
| 992 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 993 | }; // namespace android |