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