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