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