blob: 52ed73e938a6ee0a9c0e1eb6ca2414c398bc8d82 [file] [log] [blame]
Mathias Agopian65ab4712010-07-14 17:59:35 -07001/*
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 Kasten153b9fe2013-07-15 11:23:36 -070020#include "Configuration.h"
Mathias Agopian65ab4712010-07-14 17:59:35 -070021#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 Kasten44deb052012-02-05 18:09:08 -080034#include "ServiceUtilities.h"
Mathias Agopian65ab4712010-07-14 17:59:35 -070035#include <hardware_legacy/power.h>
Eric Laurent7c7f10b2011-06-17 21:29:58 -070036#include <media/AudioEffect.h>
37#include <media/EffectsFactoryApi.h>
Chih-Hung Hsiehc84d9d22014-11-14 13:33:34 -080038#include <media/AudioParameter.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070039
Dima Zavinfce7a472011-04-19 22:30:36 -070040#include <hardware/hardware.h>
Dima Zavin64760242011-05-11 14:15:23 -070041#include <system/audio.h>
Dima Zavin7394a4f2011-06-13 18:16:26 -070042#include <system/audio_policy.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070043#include <hardware/audio_policy.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070044
Mathias Agopian65ab4712010-07-14 17:59:35 -070045namespace android {
46
Glenn Kasten8dad0e32012-01-09 08:41:22 -080047static const char kDeadlockedString[] = "AudioPolicyService may be deadlocked\n";
48static const char kCmdDeadlockedString[] = "AudioPolicyService command thread may be deadlocked\n";
Mathias Agopian65ab4712010-07-14 17:59:35 -070049
50static const int kDumpLockRetries = 50;
Glenn Kasten22ecc912012-01-09 08:33:38 -080051static const int kDumpLockSleepUs = 20000;
Mathias Agopian65ab4712010-07-14 17:59:35 -070052
Eric Laurent0ede8922014-05-09 18:04:42 -070053static const nsecs_t kAudioCommandTimeoutNs = seconds(3); // 3 seconds
Christer Fletcher5fa8c4b2013-01-18 15:27:03 +010054
Glenn Kastenfcddb0b2016-07-08 17:19:25 -070055#ifdef USE_LEGACY_AUDIO_POLICY
Dima Zavinfce7a472011-04-19 22:30:36 -070056namespace {
57 extern struct audio_policy_service_ops aps_ops;
58};
Glenn Kastenfcddb0b2016-07-08 17:19:25 -070059#endif
Dima Zavinfce7a472011-04-19 22:30:36 -070060
Mathias Agopian65ab4712010-07-14 17:59:35 -070061// ----------------------------------------------------------------------------
62
63AudioPolicyService::AudioPolicyService()
Eric Laurentdce54a12014-03-10 12:19:46 -070064 : BnAudioPolicyService(), mpAudioPolicyDev(NULL), mpAudioPolicy(NULL),
Eric Laurentbb6c9a02014-09-25 14:11:47 -070065 mAudioPolicyManager(NULL), mAudioPolicyClient(NULL), mPhoneState(AUDIO_MODE_INVALID)
Mathias Agopian65ab4712010-07-14 17:59:35 -070066{
Eric Laurentf5ada6e2014-10-09 17:49:00 -070067}
68
69void AudioPolicyService::onFirstRef()
70{
Eric Laurent8b1e80b2014-10-07 09:08:47 -070071 {
72 Mutex::Autolock _l(mLock);
Eric Laurent93575202011-01-18 18:39:02 -080073
Eric Laurent8b1e80b2014-10-07 09:08:47 -070074 // start tone playback thread
75 mTonePlaybackThread = new AudioCommandThread(String8("ApmTone"), this);
76 // start audio commands thread
77 mAudioCommandThread = new AudioCommandThread(String8("ApmAudio"), this);
78 // start output activity command thread
79 mOutputCommandThread = new AudioCommandThread(String8("ApmOutput"), this);
Eric Laurentdce54a12014-03-10 12:19:46 -070080
81#ifdef USE_LEGACY_AUDIO_POLICY
Eric Laurent8b1e80b2014-10-07 09:08:47 -070082 ALOGI("AudioPolicyService CSTOR in legacy mode");
Eric Laurentdce54a12014-03-10 12:19:46 -070083
Eric Laurent8b1e80b2014-10-07 09:08:47 -070084 /* instantiate the audio policy manager */
Glenn Kastenfcddb0b2016-07-08 17:19:25 -070085 const struct hw_module_t *module;
86 int rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module);
Eric Laurent8b1e80b2014-10-07 09:08:47 -070087 if (rc) {
88 return;
89 }
90 rc = audio_policy_dev_open(module, &mpAudioPolicyDev);
91 ALOGE_IF(rc, "couldn't open audio policy device (%s)", strerror(-rc));
92 if (rc) {
93 return;
94 }
Eric Laurent93575202011-01-18 18:39:02 -080095
Eric Laurent8b1e80b2014-10-07 09:08:47 -070096 rc = mpAudioPolicyDev->create_audio_policy(mpAudioPolicyDev, &aps_ops, this,
97 &mpAudioPolicy);
98 ALOGE_IF(rc, "couldn't create audio policy (%s)", strerror(-rc));
99 if (rc) {
100 return;
101 }
Dima Zavinfce7a472011-04-19 22:30:36 -0700102
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700103 rc = mpAudioPolicy->init_check(mpAudioPolicy);
104 ALOGE_IF(rc, "couldn't init_check the audio policy (%s)", strerror(-rc));
105 if (rc) {
106 return;
107 }
108 ALOGI("Loaded audio policy from %s (%s)", module->name, module->id);
Eric Laurentdce54a12014-03-10 12:19:46 -0700109#else
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700110 ALOGI("AudioPolicyService CSTOR in new mode");
Eric Laurentdce54a12014-03-10 12:19:46 -0700111
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700112 mAudioPolicyClient = new AudioPolicyClient(this);
113 mAudioPolicyManager = createAudioPolicyManager(mAudioPolicyClient);
Eric Laurentdce54a12014-03-10 12:19:46 -0700114#endif
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700115 }
bryant_liuba2b4392014-06-11 16:49:30 +0800116 // load audio processing modules
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700117 sp<AudioPolicyEffects>audioPolicyEffects = new AudioPolicyEffects();
118 {
119 Mutex::Autolock _l(mLock);
120 mAudioPolicyEffects = audioPolicyEffects;
121 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700122}
123
124AudioPolicyService::~AudioPolicyService()
125{
126 mTonePlaybackThread->exit();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700127 mAudioCommandThread->exit();
Eric Laurent657ff612014-05-07 11:58:24 -0700128 mOutputCommandThread->exit();
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700129
Eric Laurentdce54a12014-03-10 12:19:46 -0700130#ifdef USE_LEGACY_AUDIO_POLICY
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700131 if (mpAudioPolicy != NULL && mpAudioPolicyDev != NULL) {
Dima Zavinfce7a472011-04-19 22:30:36 -0700132 mpAudioPolicyDev->destroy_audio_policy(mpAudioPolicyDev, mpAudioPolicy);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700133 }
134 if (mpAudioPolicyDev != NULL) {
Dima Zavinfce7a472011-04-19 22:30:36 -0700135 audio_policy_dev_close(mpAudioPolicyDev);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700136 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700137#else
Eric Laurentf269b8e2014-06-09 20:01:29 -0700138 destroyAudioPolicyManager(mAudioPolicyManager);
Eric Laurentdce54a12014-03-10 12:19:46 -0700139 delete mAudioPolicyClient;
140#endif
Eric Laurentb52c1522014-05-20 11:27:36 -0700141
142 mNotificationClients.clear();
bryant_liuba2b4392014-06-11 16:49:30 +0800143 mAudioPolicyEffects.clear();
Eric Laurentb52c1522014-05-20 11:27:36 -0700144}
145
146// A notification client is always registered by AudioSystem when the client process
147// connects to AudioPolicyService.
148void AudioPolicyService::registerClient(const sp<IAudioPolicyServiceClient>& client)
149{
Eric Laurent12590252015-08-21 18:40:20 -0700150 if (client == 0) {
151 ALOGW("%s got NULL client", __FUNCTION__);
152 return;
153 }
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800154 Mutex::Autolock _l(mNotificationClientsLock);
Eric Laurentb52c1522014-05-20 11:27:36 -0700155
156 uid_t uid = IPCThreadState::self()->getCallingUid();
157 if (mNotificationClients.indexOfKey(uid) < 0) {
158 sp<NotificationClient> notificationClient = new NotificationClient(this,
159 client,
160 uid);
161 ALOGV("registerClient() client %p, uid %d", client.get(), uid);
162
163 mNotificationClients.add(uid, notificationClient);
164
Marco Nelissenf8880202014-11-14 07:58:25 -0800165 sp<IBinder> binder = IInterface::asBinder(client);
Eric Laurentb52c1522014-05-20 11:27:36 -0700166 binder->linkToDeath(notificationClient);
167 }
168}
169
Eric Laurente8726fe2015-06-26 09:39:24 -0700170void AudioPolicyService::setAudioPortCallbacksEnabled(bool enabled)
171{
172 Mutex::Autolock _l(mNotificationClientsLock);
173
174 uid_t uid = IPCThreadState::self()->getCallingUid();
175 if (mNotificationClients.indexOfKey(uid) < 0) {
176 return;
177 }
178 mNotificationClients.valueFor(uid)->setAudioPortCallbacksEnabled(enabled);
179}
180
Eric Laurentb52c1522014-05-20 11:27:36 -0700181// removeNotificationClient() is called when the client process dies.
182void AudioPolicyService::removeNotificationClient(uid_t uid)
183{
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800184 {
185 Mutex::Autolock _l(mNotificationClientsLock);
186 mNotificationClients.removeItem(uid);
187 }
Eric Laurentb52c1522014-05-20 11:27:36 -0700188#ifndef USE_LEGACY_AUDIO_POLICY
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800189 {
190 Mutex::Autolock _l(mLock);
Eric Laurentb52c1522014-05-20 11:27:36 -0700191 if (mAudioPolicyManager) {
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700192 mAudioPolicyManager->releaseResourcesForUid(uid);
Eric Laurentb52c1522014-05-20 11:27:36 -0700193 }
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800194 }
Eric Laurentb52c1522014-05-20 11:27:36 -0700195#endif
196}
197
198void AudioPolicyService::onAudioPortListUpdate()
199{
200 mOutputCommandThread->updateAudioPortListCommand();
201}
202
203void AudioPolicyService::doOnAudioPortListUpdate()
204{
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800205 Mutex::Autolock _l(mNotificationClientsLock);
Eric Laurentb52c1522014-05-20 11:27:36 -0700206 for (size_t i = 0; i < mNotificationClients.size(); i++) {
207 mNotificationClients.valueAt(i)->onAudioPortListUpdate();
208 }
209}
210
211void AudioPolicyService::onAudioPatchListUpdate()
212{
213 mOutputCommandThread->updateAudioPatchListCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700214}
215
Eric Laurentb52c1522014-05-20 11:27:36 -0700216void AudioPolicyService::doOnAudioPatchListUpdate()
217{
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800218 Mutex::Autolock _l(mNotificationClientsLock);
Eric Laurentb52c1522014-05-20 11:27:36 -0700219 for (size_t i = 0; i < mNotificationClients.size(); i++) {
220 mNotificationClients.valueAt(i)->onAudioPatchListUpdate();
221 }
222}
223
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700224void AudioPolicyService::onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state)
Jean-Michel Trivide801052015-04-14 19:10:14 -0700225{
226 ALOGV("AudioPolicyService::onDynamicPolicyMixStateUpdate(%s, %d)",
227 regId.string(), state);
228 mOutputCommandThread->dynamicPolicyMixStateUpdateCommand(regId, state);
229}
230
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700231void AudioPolicyService::doOnDynamicPolicyMixStateUpdate(const String8& regId, int32_t state)
Jean-Michel Trivide801052015-04-14 19:10:14 -0700232{
233 Mutex::Autolock _l(mNotificationClientsLock);
234 for (size_t i = 0; i < mNotificationClients.size(); i++) {
235 mNotificationClients.valueAt(i)->onDynamicPolicyMixStateUpdate(regId, state);
236 }
237}
238
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800239void AudioPolicyService::onRecordingConfigurationUpdate(int event, audio_session_t session,
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800240 audio_source_t source, const audio_config_base_t *clientConfig,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800241 const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle)
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800242{
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800243 mOutputCommandThread->recordingConfigurationUpdateCommand(event, session, source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800244 clientConfig, deviceConfig, patchHandle);
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800245}
246
247void AudioPolicyService::doOnRecordingConfigurationUpdate(int event, audio_session_t session,
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800248 audio_source_t source, const audio_config_base_t *clientConfig,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800249 const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle)
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800250{
251 Mutex::Autolock _l(mNotificationClientsLock);
252 for (size_t i = 0; i < mNotificationClients.size(); i++) {
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800253 mNotificationClients.valueAt(i)->onRecordingConfigurationUpdate(event, session, source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800254 clientConfig, deviceConfig, patchHandle);
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800255 }
256}
257
258status_t AudioPolicyService::clientCreateAudioPatch(const struct audio_patch *patch,
259 audio_patch_handle_t *handle,
260 int delayMs)
261{
262 return mAudioCommandThread->createAudioPatchCommand(patch, handle, delayMs);
263}
264
265status_t AudioPolicyService::clientReleaseAudioPatch(audio_patch_handle_t handle,
266 int delayMs)
267{
268 return mAudioCommandThread->releaseAudioPatchCommand(handle, delayMs);
269}
270
Eric Laurente1715a42014-05-20 11:30:42 -0700271status_t AudioPolicyService::clientSetAudioPortConfig(const struct audio_port_config *config,
272 int delayMs)
273{
274 return mAudioCommandThread->setAudioPortConfigCommand(config, delayMs);
275}
276
Eric Laurentb52c1522014-05-20 11:27:36 -0700277AudioPolicyService::NotificationClient::NotificationClient(const sp<AudioPolicyService>& service,
278 const sp<IAudioPolicyServiceClient>& client,
279 uid_t uid)
Eric Laurente8726fe2015-06-26 09:39:24 -0700280 : mService(service), mUid(uid), mAudioPolicyServiceClient(client),
281 mAudioPortCallbacksEnabled(false)
Eric Laurentb52c1522014-05-20 11:27:36 -0700282{
283}
284
285AudioPolicyService::NotificationClient::~NotificationClient()
286{
287}
288
289void AudioPolicyService::NotificationClient::binderDied(const wp<IBinder>& who __unused)
290{
291 sp<NotificationClient> keep(this);
292 sp<AudioPolicyService> service = mService.promote();
293 if (service != 0) {
294 service->removeNotificationClient(mUid);
295 }
296}
297
298void AudioPolicyService::NotificationClient::onAudioPortListUpdate()
299{
Eric Laurente8726fe2015-06-26 09:39:24 -0700300 if (mAudioPolicyServiceClient != 0 && mAudioPortCallbacksEnabled) {
Eric Laurentb52c1522014-05-20 11:27:36 -0700301 mAudioPolicyServiceClient->onAudioPortListUpdate();
302 }
303}
304
305void AudioPolicyService::NotificationClient::onAudioPatchListUpdate()
306{
Eric Laurente8726fe2015-06-26 09:39:24 -0700307 if (mAudioPolicyServiceClient != 0 && mAudioPortCallbacksEnabled) {
Eric Laurentb52c1522014-05-20 11:27:36 -0700308 mAudioPolicyServiceClient->onAudioPatchListUpdate();
309 }
310}
Eric Laurent57dae992011-07-24 13:36:09 -0700311
Jean-Michel Trivide801052015-04-14 19:10:14 -0700312void AudioPolicyService::NotificationClient::onDynamicPolicyMixStateUpdate(
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700313 const String8& regId, int32_t state)
Jean-Michel Trivide801052015-04-14 19:10:14 -0700314{
315 if (mAudioPolicyServiceClient != 0) {
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800316 mAudioPolicyServiceClient->onDynamicPolicyMixStateUpdate(regId, state);
317 }
318}
319
320void AudioPolicyService::NotificationClient::onRecordingConfigurationUpdate(
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800321 int event, audio_session_t session, audio_source_t source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800322 const audio_config_base_t *clientConfig, const audio_config_base_t *deviceConfig,
323 audio_patch_handle_t patchHandle)
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800324{
325 if (mAudioPolicyServiceClient != 0) {
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800326 mAudioPolicyServiceClient->onRecordingConfigurationUpdate(event, session, source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800327 clientConfig, deviceConfig, patchHandle);
Jean-Michel Trivide801052015-04-14 19:10:14 -0700328 }
329}
330
Eric Laurente8726fe2015-06-26 09:39:24 -0700331void AudioPolicyService::NotificationClient::setAudioPortCallbacksEnabled(bool enabled)
332{
333 mAudioPortCallbacksEnabled = enabled;
334}
335
336
Mathias Agopian65ab4712010-07-14 17:59:35 -0700337void AudioPolicyService::binderDied(const wp<IBinder>& who) {
Glenn Kasten411e4472012-11-02 10:00:06 -0700338 ALOGW("binderDied() %p, calling pid %d", who.unsafe_get(),
Eric Laurentde070132010-07-13 04:45:46 -0700339 IPCThreadState::self()->getCallingPid());
Mathias Agopian65ab4712010-07-14 17:59:35 -0700340}
341
342static bool tryLock(Mutex& mutex)
343{
344 bool locked = false;
345 for (int i = 0; i < kDumpLockRetries; ++i) {
346 if (mutex.tryLock() == NO_ERROR) {
347 locked = true;
348 break;
349 }
Glenn Kasten22ecc912012-01-09 08:33:38 -0800350 usleep(kDumpLockSleepUs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700351 }
352 return locked;
353}
354
355status_t AudioPolicyService::dumpInternals(int fd)
356{
357 const size_t SIZE = 256;
358 char buffer[SIZE];
359 String8 result;
360
Eric Laurentdce54a12014-03-10 12:19:46 -0700361#ifdef USE_LEGACY_AUDIO_POLICY
Dima Zavinfce7a472011-04-19 22:30:36 -0700362 snprintf(buffer, SIZE, "PolicyManager Interface: %p\n", mpAudioPolicy);
Eric Laurentdce54a12014-03-10 12:19:46 -0700363#else
364 snprintf(buffer, SIZE, "AudioPolicyManager: %p\n", mAudioPolicyManager);
365#endif
Mathias Agopian65ab4712010-07-14 17:59:35 -0700366 result.append(buffer);
367 snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get());
368 result.append(buffer);
369 snprintf(buffer, SIZE, "Tones Thread: %p\n", mTonePlaybackThread.get());
370 result.append(buffer);
371
372 write(fd, result.string(), result.size());
373 return NO_ERROR;
374}
375
Glenn Kasten0f11b512014-01-31 16:18:54 -0800376status_t AudioPolicyService::dump(int fd, const Vector<String16>& args __unused)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700377{
Glenn Kasten44deb052012-02-05 18:09:08 -0800378 if (!dumpAllowed()) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700379 dumpPermissionDenial(fd);
380 } else {
381 bool locked = tryLock(mLock);
382 if (!locked) {
383 String8 result(kDeadlockedString);
384 write(fd, result.string(), result.size());
385 }
386
387 dumpInternals(fd);
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800388 if (mAudioCommandThread != 0) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700389 mAudioCommandThread->dump(fd);
390 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800391 if (mTonePlaybackThread != 0) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700392 mTonePlaybackThread->dump(fd);
393 }
394
Eric Laurentdce54a12014-03-10 12:19:46 -0700395#ifdef USE_LEGACY_AUDIO_POLICY
Dima Zavinfce7a472011-04-19 22:30:36 -0700396 if (mpAudioPolicy) {
397 mpAudioPolicy->dump(mpAudioPolicy, fd);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700398 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700399#else
400 if (mAudioPolicyManager) {
401 mAudioPolicyManager->dump(fd);
402 }
403#endif
Mathias Agopian65ab4712010-07-14 17:59:35 -0700404
405 if (locked) mLock.unlock();
406 }
407 return NO_ERROR;
408}
409
410status_t AudioPolicyService::dumpPermissionDenial(int fd)
411{
412 const size_t SIZE = 256;
413 char buffer[SIZE];
414 String8 result;
415 snprintf(buffer, SIZE, "Permission Denial: "
416 "can't dump AudioPolicyService from pid=%d, uid=%d\n",
417 IPCThreadState::self()->getCallingPid(),
418 IPCThreadState::self()->getCallingUid());
419 result.append(buffer);
420 write(fd, result.string(), result.size());
421 return NO_ERROR;
422}
423
424status_t AudioPolicyService::onTransact(
425 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
426{
427 return BnAudioPolicyService::onTransact(code, data, reply, flags);
428}
429
430
Mathias Agopian65ab4712010-07-14 17:59:35 -0700431// ----------- AudioPolicyService::AudioCommandThread implementation ----------
432
Eric Laurentbfb1b832013-01-07 09:53:42 -0800433AudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name,
434 const wp<AudioPolicyService>& service)
435 : Thread(false), mName(name), mService(service)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700436{
437 mpToneGenerator = NULL;
438}
439
440
441AudioPolicyService::AudioCommandThread::~AudioCommandThread()
442{
Eric Laurentbfb1b832013-01-07 09:53:42 -0800443 if (!mAudioCommands.isEmpty()) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700444 release_wake_lock(mName.string());
445 }
446 mAudioCommands.clear();
Glenn Kastene9dd0172012-01-27 18:08:45 -0800447 delete mpToneGenerator;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700448}
449
450void AudioPolicyService::AudioCommandThread::onFirstRef()
451{
Eric Laurentbfb1b832013-01-07 09:53:42 -0800452 run(mName.string(), ANDROID_PRIORITY_AUDIO);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700453}
454
455bool AudioPolicyService::AudioCommandThread::threadLoop()
456{
Eric Laurentd7eda8d2016-02-02 17:18:39 -0800457 nsecs_t waitTime = -1;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700458
459 mLock.lock();
460 while (!exitPending())
461 {
Eric Laurent59a89232014-06-08 14:14:17 -0700462 sp<AudioPolicyService> svc;
463 while (!mAudioCommands.isEmpty() && !exitPending()) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700464 nsecs_t curTime = systemTime();
465 // commands are sorted by increasing time stamp: execute them from index 0 and up
466 if (mAudioCommands[0]->mTime <= curTime) {
Eric Laurent0ede8922014-05-09 18:04:42 -0700467 sp<AudioCommand> command = mAudioCommands[0];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700468 mAudioCommands.removeAt(0);
Eric Laurent0ede8922014-05-09 18:04:42 -0700469 mLastCommand = command;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700470
471 switch (command->mCommand) {
472 case START_TONE: {
473 mLock.unlock();
Eric Laurent0ede8922014-05-09 18:04:42 -0700474 ToneData *data = (ToneData *)command->mParam.get();
Steve Block3856b092011-10-20 11:56:00 +0100475 ALOGV("AudioCommandThread() processing start tone %d on stream %d",
Mathias Agopian65ab4712010-07-14 17:59:35 -0700476 data->mType, data->mStream);
Glenn Kastene9dd0172012-01-27 18:08:45 -0800477 delete mpToneGenerator;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700478 mpToneGenerator = new ToneGenerator(data->mStream, 1.0);
479 mpToneGenerator->startTone(data->mType);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700480 mLock.lock();
481 }break;
482 case STOP_TONE: {
483 mLock.unlock();
Steve Block3856b092011-10-20 11:56:00 +0100484 ALOGV("AudioCommandThread() processing stop tone");
Mathias Agopian65ab4712010-07-14 17:59:35 -0700485 if (mpToneGenerator != NULL) {
486 mpToneGenerator->stopTone();
487 delete mpToneGenerator;
488 mpToneGenerator = NULL;
489 }
490 mLock.lock();
491 }break;
492 case SET_VOLUME: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700493 VolumeData *data = (VolumeData *)command->mParam.get();
Steve Block3856b092011-10-20 11:56:00 +0100494 ALOGV("AudioCommandThread() processing set volume stream %d, \
Eric Laurentde070132010-07-13 04:45:46 -0700495 volume %f, output %d", data->mStream, data->mVolume, data->mIO);
496 command->mStatus = AudioSystem::setStreamVolume(data->mStream,
497 data->mVolume,
498 data->mIO);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700499 }break;
500 case SET_PARAMETERS: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700501 ParametersData *data = (ParametersData *)command->mParam.get();
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700502 ALOGV("AudioCommandThread() processing set parameters string %s, io %d",
503 data->mKeyValuePairs.string(), data->mIO);
504 command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs);
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700505 }break;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700506 case SET_VOICE_VOLUME: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700507 VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get();
Steve Block3856b092011-10-20 11:56:00 +0100508 ALOGV("AudioCommandThread() processing set voice volume volume %f",
Eric Laurentde070132010-07-13 04:45:46 -0700509 data->mVolume);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700510 command->mStatus = AudioSystem::setVoiceVolume(data->mVolume);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700511 }break;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800512 case STOP_OUTPUT: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700513 StopOutputData *data = (StopOutputData *)command->mParam.get();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800514 ALOGV("AudioCommandThread() processing stop output %d",
515 data->mIO);
Eric Laurent59a89232014-06-08 14:14:17 -0700516 svc = mService.promote();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800517 if (svc == 0) {
518 break;
519 }
520 mLock.unlock();
521 svc->doStopOutput(data->mIO, data->mStream, data->mSession);
522 mLock.lock();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800523 }break;
524 case RELEASE_OUTPUT: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700525 ReleaseOutputData *data = (ReleaseOutputData *)command->mParam.get();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800526 ALOGV("AudioCommandThread() processing release output %d",
527 data->mIO);
Eric Laurent59a89232014-06-08 14:14:17 -0700528 svc = mService.promote();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800529 if (svc == 0) {
530 break;
531 }
532 mLock.unlock();
Eric Laurente83b55d2014-11-14 10:06:21 -0800533 svc->doReleaseOutput(data->mIO, data->mStream, data->mSession);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800534 mLock.lock();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800535 }break;
Eric Laurent951f4552014-05-20 10:48:17 -0700536 case CREATE_AUDIO_PATCH: {
537 CreateAudioPatchData *data = (CreateAudioPatchData *)command->mParam.get();
538 ALOGV("AudioCommandThread() processing create audio patch");
539 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
540 if (af == 0) {
541 command->mStatus = PERMISSION_DENIED;
542 } else {
543 command->mStatus = af->createAudioPatch(&data->mPatch, &data->mHandle);
544 }
545 } break;
546 case RELEASE_AUDIO_PATCH: {
547 ReleaseAudioPatchData *data = (ReleaseAudioPatchData *)command->mParam.get();
548 ALOGV("AudioCommandThread() processing release audio patch");
549 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
550 if (af == 0) {
551 command->mStatus = PERMISSION_DENIED;
552 } else {
553 command->mStatus = af->releaseAudioPatch(data->mHandle);
554 }
555 } break;
Eric Laurentb52c1522014-05-20 11:27:36 -0700556 case UPDATE_AUDIOPORT_LIST: {
557 ALOGV("AudioCommandThread() processing update audio port list");
Eric Laurent59a89232014-06-08 14:14:17 -0700558 svc = mService.promote();
Eric Laurentb52c1522014-05-20 11:27:36 -0700559 if (svc == 0) {
560 break;
561 }
562 mLock.unlock();
563 svc->doOnAudioPortListUpdate();
564 mLock.lock();
565 }break;
566 case UPDATE_AUDIOPATCH_LIST: {
567 ALOGV("AudioCommandThread() processing update audio patch list");
Eric Laurent59a89232014-06-08 14:14:17 -0700568 svc = mService.promote();
Eric Laurentb52c1522014-05-20 11:27:36 -0700569 if (svc == 0) {
570 break;
571 }
572 mLock.unlock();
573 svc->doOnAudioPatchListUpdate();
574 mLock.lock();
575 }break;
Eric Laurente1715a42014-05-20 11:30:42 -0700576 case SET_AUDIOPORT_CONFIG: {
577 SetAudioPortConfigData *data = (SetAudioPortConfigData *)command->mParam.get();
578 ALOGV("AudioCommandThread() processing set port config");
579 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
580 if (af == 0) {
581 command->mStatus = PERMISSION_DENIED;
582 } else {
583 command->mStatus = af->setAudioPortConfig(&data->mConfig);
584 }
585 } break;
Jean-Michel Trivide801052015-04-14 19:10:14 -0700586 case DYN_POLICY_MIX_STATE_UPDATE: {
587 DynPolicyMixStateUpdateData *data =
588 (DynPolicyMixStateUpdateData *)command->mParam.get();
Jean-Michel Trivide801052015-04-14 19:10:14 -0700589 ALOGV("AudioCommandThread() processing dyn policy mix state update %s %d",
590 data->mRegId.string(), data->mState);
591 svc = mService.promote();
592 if (svc == 0) {
593 break;
594 }
595 mLock.unlock();
596 svc->doOnDynamicPolicyMixStateUpdate(data->mRegId, data->mState);
597 mLock.lock();
598 } break;
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800599 case RECORDING_CONFIGURATION_UPDATE: {
600 RecordingConfigurationUpdateData *data =
601 (RecordingConfigurationUpdateData *)command->mParam.get();
602 ALOGV("AudioCommandThread() processing recording configuration update");
603 svc = mService.promote();
604 if (svc == 0) {
605 break;
606 }
607 mLock.unlock();
608 svc->doOnRecordingConfigurationUpdate(data->mEvent, data->mSession,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800609 data->mSource, &data->mClientConfig, &data->mDeviceConfig,
610 data->mPatchHandle);
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800611 mLock.lock();
612 } break;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700613 default:
Steve Block5ff1dd52012-01-05 23:22:43 +0000614 ALOGW("AudioCommandThread() unknown command %d", command->mCommand);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700615 }
Eric Laurent0ede8922014-05-09 18:04:42 -0700616 {
617 Mutex::Autolock _l(command->mLock);
618 if (command->mWaitStatus) {
619 command->mWaitStatus = false;
620 command->mCond.signal();
621 }
622 }
Eric Laurentd7eda8d2016-02-02 17:18:39 -0800623 waitTime = -1;
Zach Janga754b4f2015-10-27 01:29:34 +0000624 // release mLock before releasing strong reference on the service as
625 // AudioPolicyService destructor calls AudioCommandThread::exit() which
626 // acquires mLock.
627 mLock.unlock();
628 svc.clear();
629 mLock.lock();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700630 } else {
631 waitTime = mAudioCommands[0]->mTime - curTime;
632 break;
633 }
634 }
Zach Janga754b4f2015-10-27 01:29:34 +0000635
636 // release delayed commands wake lock if the queue is empty
637 if (mAudioCommands.isEmpty()) {
Ricardo Garcia05f2fdc2014-07-24 15:48:24 -0700638 release_wake_lock(mName.string());
Zach Janga754b4f2015-10-27 01:29:34 +0000639 }
640
641 // At this stage we have either an empty command queue or the first command in the queue
642 // has a finite delay. So unless we are exiting it is safe to wait.
643 if (!exitPending()) {
Eric Laurent59a89232014-06-08 14:14:17 -0700644 ALOGV("AudioCommandThread() going to sleep");
Eric Laurentd7eda8d2016-02-02 17:18:39 -0800645 if (waitTime == -1) {
646 mWaitWorkCV.wait(mLock);
647 } else {
648 mWaitWorkCV.waitRelative(mLock, waitTime);
649 }
Eric Laurent59a89232014-06-08 14:14:17 -0700650 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700651 }
Ricardo Garcia05f2fdc2014-07-24 15:48:24 -0700652 // release delayed commands wake lock before quitting
653 if (!mAudioCommands.isEmpty()) {
654 release_wake_lock(mName.string());
655 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700656 mLock.unlock();
657 return false;
658}
659
660status_t AudioPolicyService::AudioCommandThread::dump(int fd)
661{
662 const size_t SIZE = 256;
663 char buffer[SIZE];
664 String8 result;
665
666 snprintf(buffer, SIZE, "AudioCommandThread %p Dump\n", this);
667 result.append(buffer);
668 write(fd, result.string(), result.size());
669
670 bool locked = tryLock(mLock);
671 if (!locked) {
672 String8 result2(kCmdDeadlockedString);
673 write(fd, result2.string(), result2.size());
674 }
675
676 snprintf(buffer, SIZE, "- Commands:\n");
677 result = String8(buffer);
678 result.append(" Command Time Wait pParam\n");
Glenn Kasten8d6a2442012-02-08 14:04:28 -0800679 for (size_t i = 0; i < mAudioCommands.size(); i++) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700680 mAudioCommands[i]->dump(buffer, SIZE);
681 result.append(buffer);
682 }
683 result.append(" Last Command\n");
Eric Laurent0ede8922014-05-09 18:04:42 -0700684 if (mLastCommand != 0) {
685 mLastCommand->dump(buffer, SIZE);
686 result.append(buffer);
687 } else {
688 result.append(" none\n");
689 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700690
691 write(fd, result.string(), result.size());
692
693 if (locked) mLock.unlock();
694
695 return NO_ERROR;
696}
697
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800698void AudioPolicyService::AudioCommandThread::startToneCommand(ToneGenerator::tone_type type,
699 audio_stream_type_t stream)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700700{
Eric Laurent0ede8922014-05-09 18:04:42 -0700701 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700702 command->mCommand = START_TONE;
Eric Laurent0ede8922014-05-09 18:04:42 -0700703 sp<ToneData> data = new ToneData();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700704 data->mType = type;
705 data->mStream = stream;
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100706 command->mParam = data;
Steve Block3856b092011-10-20 11:56:00 +0100707 ALOGV("AudioCommandThread() adding tone start type %d, stream %d", type, stream);
Eric Laurent0ede8922014-05-09 18:04:42 -0700708 sendCommand(command);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700709}
710
711void AudioPolicyService::AudioCommandThread::stopToneCommand()
712{
Eric Laurent0ede8922014-05-09 18:04:42 -0700713 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700714 command->mCommand = STOP_TONE;
Steve Block3856b092011-10-20 11:56:00 +0100715 ALOGV("AudioCommandThread() adding tone stop");
Eric Laurent0ede8922014-05-09 18:04:42 -0700716 sendCommand(command);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700717}
718
Glenn Kastenfff6d712012-01-12 16:38:12 -0800719status_t AudioPolicyService::AudioCommandThread::volumeCommand(audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700720 float volume,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800721 audio_io_handle_t output,
Eric Laurentde070132010-07-13 04:45:46 -0700722 int delayMs)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700723{
Eric Laurent0ede8922014-05-09 18:04:42 -0700724 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700725 command->mCommand = SET_VOLUME;
Eric Laurent0ede8922014-05-09 18:04:42 -0700726 sp<VolumeData> data = new VolumeData();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700727 data->mStream = stream;
728 data->mVolume = volume;
729 data->mIO = output;
730 command->mParam = data;
Eric Laurent0ede8922014-05-09 18:04:42 -0700731 command->mWaitStatus = true;
Steve Block3856b092011-10-20 11:56:00 +0100732 ALOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d",
Eric Laurentde070132010-07-13 04:45:46 -0700733 stream, volume, output);
Eric Laurent0ede8922014-05-09 18:04:42 -0700734 return sendCommand(command, delayMs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700735}
736
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800737status_t AudioPolicyService::AudioCommandThread::parametersCommand(audio_io_handle_t ioHandle,
Dima Zavinfce7a472011-04-19 22:30:36 -0700738 const char *keyValuePairs,
Eric Laurentde070132010-07-13 04:45:46 -0700739 int delayMs)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700740{
Eric Laurent0ede8922014-05-09 18:04:42 -0700741 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700742 command->mCommand = SET_PARAMETERS;
Eric Laurent0ede8922014-05-09 18:04:42 -0700743 sp<ParametersData> data = new ParametersData();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700744 data->mIO = ioHandle;
Dima Zavinfce7a472011-04-19 22:30:36 -0700745 data->mKeyValuePairs = String8(keyValuePairs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700746 command->mParam = data;
Eric Laurent0ede8922014-05-09 18:04:42 -0700747 command->mWaitStatus = true;
Steve Block3856b092011-10-20 11:56:00 +0100748 ALOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d",
Dima Zavinfce7a472011-04-19 22:30:36 -0700749 keyValuePairs, ioHandle, delayMs);
Eric Laurent0ede8922014-05-09 18:04:42 -0700750 return sendCommand(command, delayMs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700751}
752
753status_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs)
754{
Eric Laurent0ede8922014-05-09 18:04:42 -0700755 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700756 command->mCommand = SET_VOICE_VOLUME;
Eric Laurent0ede8922014-05-09 18:04:42 -0700757 sp<VoiceVolumeData> data = new VoiceVolumeData();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700758 data->mVolume = volume;
759 command->mParam = data;
Eric Laurent0ede8922014-05-09 18:04:42 -0700760 command->mWaitStatus = true;
Steve Block3856b092011-10-20 11:56:00 +0100761 ALOGV("AudioCommandThread() adding set voice volume volume %f", volume);
Eric Laurent0ede8922014-05-09 18:04:42 -0700762 return sendCommand(command, delayMs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700763}
764
Eric Laurentbfb1b832013-01-07 09:53:42 -0800765void AudioPolicyService::AudioCommandThread::stopOutputCommand(audio_io_handle_t output,
766 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800767 audio_session_t session)
Eric Laurentbfb1b832013-01-07 09:53:42 -0800768{
Eric Laurent0ede8922014-05-09 18:04:42 -0700769 sp<AudioCommand> command = new AudioCommand();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800770 command->mCommand = STOP_OUTPUT;
Eric Laurent0ede8922014-05-09 18:04:42 -0700771 sp<StopOutputData> data = new StopOutputData();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800772 data->mIO = output;
773 data->mStream = stream;
774 data->mSession = session;
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100775 command->mParam = data;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800776 ALOGV("AudioCommandThread() adding stop output %d", output);
Eric Laurent0ede8922014-05-09 18:04:42 -0700777 sendCommand(command);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800778}
779
Eric Laurente83b55d2014-11-14 10:06:21 -0800780void AudioPolicyService::AudioCommandThread::releaseOutputCommand(audio_io_handle_t output,
781 audio_stream_type_t stream,
782 audio_session_t session)
Eric Laurentbfb1b832013-01-07 09:53:42 -0800783{
Eric Laurent0ede8922014-05-09 18:04:42 -0700784 sp<AudioCommand> command = new AudioCommand();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800785 command->mCommand = RELEASE_OUTPUT;
Eric Laurent0ede8922014-05-09 18:04:42 -0700786 sp<ReleaseOutputData> data = new ReleaseOutputData();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800787 data->mIO = output;
Eric Laurente83b55d2014-11-14 10:06:21 -0800788 data->mStream = stream;
789 data->mSession = session;
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100790 command->mParam = data;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800791 ALOGV("AudioCommandThread() adding release output %d", output);
Eric Laurent0ede8922014-05-09 18:04:42 -0700792 sendCommand(command);
793}
794
Eric Laurent951f4552014-05-20 10:48:17 -0700795status_t AudioPolicyService::AudioCommandThread::createAudioPatchCommand(
796 const struct audio_patch *patch,
797 audio_patch_handle_t *handle,
798 int delayMs)
799{
800 status_t status = NO_ERROR;
801
802 sp<AudioCommand> command = new AudioCommand();
803 command->mCommand = CREATE_AUDIO_PATCH;
804 CreateAudioPatchData *data = new CreateAudioPatchData();
805 data->mPatch = *patch;
806 data->mHandle = *handle;
807 command->mParam = data;
808 command->mWaitStatus = true;
809 ALOGV("AudioCommandThread() adding create patch delay %d", delayMs);
810 status = sendCommand(command, delayMs);
811 if (status == NO_ERROR) {
812 *handle = data->mHandle;
813 }
814 return status;
815}
816
817status_t AudioPolicyService::AudioCommandThread::releaseAudioPatchCommand(audio_patch_handle_t handle,
818 int delayMs)
819{
820 sp<AudioCommand> command = new AudioCommand();
821 command->mCommand = RELEASE_AUDIO_PATCH;
822 ReleaseAudioPatchData *data = new ReleaseAudioPatchData();
823 data->mHandle = handle;
824 command->mParam = data;
825 command->mWaitStatus = true;
826 ALOGV("AudioCommandThread() adding release patch delay %d", delayMs);
827 return sendCommand(command, delayMs);
828}
829
Eric Laurentb52c1522014-05-20 11:27:36 -0700830void AudioPolicyService::AudioCommandThread::updateAudioPortListCommand()
831{
832 sp<AudioCommand> command = new AudioCommand();
833 command->mCommand = UPDATE_AUDIOPORT_LIST;
834 ALOGV("AudioCommandThread() adding update audio port list");
835 sendCommand(command);
836}
837
838void AudioPolicyService::AudioCommandThread::updateAudioPatchListCommand()
839{
840 sp<AudioCommand>command = new AudioCommand();
841 command->mCommand = UPDATE_AUDIOPATCH_LIST;
842 ALOGV("AudioCommandThread() adding update audio patch list");
843 sendCommand(command);
844}
845
Eric Laurente1715a42014-05-20 11:30:42 -0700846status_t AudioPolicyService::AudioCommandThread::setAudioPortConfigCommand(
847 const struct audio_port_config *config, int delayMs)
848{
849 sp<AudioCommand> command = new AudioCommand();
850 command->mCommand = SET_AUDIOPORT_CONFIG;
851 SetAudioPortConfigData *data = new SetAudioPortConfigData();
852 data->mConfig = *config;
853 command->mParam = data;
854 command->mWaitStatus = true;
855 ALOGV("AudioCommandThread() adding set port config delay %d", delayMs);
856 return sendCommand(command, delayMs);
857}
858
Jean-Michel Trivide801052015-04-14 19:10:14 -0700859void AudioPolicyService::AudioCommandThread::dynamicPolicyMixStateUpdateCommand(
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700860 const String8& regId, int32_t state)
Jean-Michel Trivide801052015-04-14 19:10:14 -0700861{
862 sp<AudioCommand> command = new AudioCommand();
863 command->mCommand = DYN_POLICY_MIX_STATE_UPDATE;
864 DynPolicyMixStateUpdateData *data = new DynPolicyMixStateUpdateData();
865 data->mRegId = regId;
866 data->mState = state;
867 command->mParam = data;
868 ALOGV("AudioCommandThread() sending dynamic policy mix (id=%s) state update to %d",
869 regId.string(), state);
870 sendCommand(command);
871}
872
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800873void AudioPolicyService::AudioCommandThread::recordingConfigurationUpdateCommand(
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800874 int event, audio_session_t session, audio_source_t source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800875 const audio_config_base_t *clientConfig, const audio_config_base_t *deviceConfig,
876 audio_patch_handle_t patchHandle)
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800877{
878 sp<AudioCommand>command = new AudioCommand();
879 command->mCommand = RECORDING_CONFIGURATION_UPDATE;
880 RecordingConfigurationUpdateData *data = new RecordingConfigurationUpdateData();
881 data->mEvent = event;
882 data->mSession = session;
883 data->mSource = source;
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800884 data->mClientConfig = *clientConfig;
885 data->mDeviceConfig = *deviceConfig;
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800886 data->mPatchHandle = patchHandle;
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800887 command->mParam = data;
888 ALOGV("AudioCommandThread() adding recording configuration update event %d, source %d",
889 event, source);
890 sendCommand(command);
891}
892
Eric Laurent0ede8922014-05-09 18:04:42 -0700893status_t AudioPolicyService::AudioCommandThread::sendCommand(sp<AudioCommand>& command, int delayMs)
894{
895 {
896 Mutex::Autolock _l(mLock);
897 insertCommand_l(command, delayMs);
898 mWaitWorkCV.signal();
899 }
900 Mutex::Autolock _l(command->mLock);
901 while (command->mWaitStatus) {
902 nsecs_t timeOutNs = kAudioCommandTimeoutNs + milliseconds(delayMs);
903 if (command->mCond.waitRelative(command->mLock, timeOutNs) != NO_ERROR) {
904 command->mStatus = TIMED_OUT;
905 command->mWaitStatus = false;
906 }
907 }
908 return command->mStatus;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800909}
910
Mathias Agopian65ab4712010-07-14 17:59:35 -0700911// insertCommand_l() must be called with mLock held
Eric Laurent0ede8922014-05-09 18:04:42 -0700912void AudioPolicyService::AudioCommandThread::insertCommand_l(sp<AudioCommand>& command, int delayMs)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700913{
Glenn Kasten8d6a2442012-02-08 14:04:28 -0800914 ssize_t i; // not size_t because i will count down to -1
Eric Laurent0ede8922014-05-09 18:04:42 -0700915 Vector < sp<AudioCommand> > removedCommands;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700916 command->mTime = systemTime() + milliseconds(delayMs);
917
918 // acquire wake lock to make sure delayed commands are processed
Eric Laurentbfb1b832013-01-07 09:53:42 -0800919 if (mAudioCommands.isEmpty()) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700920 acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string());
921 }
922
923 // check same pending commands with later time stamps and eliminate them
924 for (i = mAudioCommands.size()-1; i >= 0; i--) {
Eric Laurent0ede8922014-05-09 18:04:42 -0700925 sp<AudioCommand> command2 = mAudioCommands[i];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700926 // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands
927 if (command2->mTime <= command->mTime) break;
Eric Laurente45b48a2014-09-04 16:40:57 -0700928
929 // create audio patch or release audio patch commands are equivalent
930 // with regard to filtering
931 if ((command->mCommand == CREATE_AUDIO_PATCH) ||
932 (command->mCommand == RELEASE_AUDIO_PATCH)) {
933 if ((command2->mCommand != CREATE_AUDIO_PATCH) &&
934 (command2->mCommand != RELEASE_AUDIO_PATCH)) {
935 continue;
936 }
937 } else if (command2->mCommand != command->mCommand) continue;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700938
939 switch (command->mCommand) {
940 case SET_PARAMETERS: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700941 ParametersData *data = (ParametersData *)command->mParam.get();
942 ParametersData *data2 = (ParametersData *)command2->mParam.get();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700943 if (data->mIO != data2->mIO) break;
Steve Block3856b092011-10-20 11:56:00 +0100944 ALOGV("Comparing parameter command %s to new command %s",
Eric Laurentde070132010-07-13 04:45:46 -0700945 data2->mKeyValuePairs.string(), data->mKeyValuePairs.string());
Mathias Agopian65ab4712010-07-14 17:59:35 -0700946 AudioParameter param = AudioParameter(data->mKeyValuePairs);
947 AudioParameter param2 = AudioParameter(data2->mKeyValuePairs);
948 for (size_t j = 0; j < param.size(); j++) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700949 String8 key;
950 String8 value;
951 param.getAt(j, key, value);
952 for (size_t k = 0; k < param2.size(); k++) {
953 String8 key2;
954 String8 value2;
955 param2.getAt(k, key2, value2);
956 if (key2 == key) {
957 param2.remove(key2);
958 ALOGV("Filtering out parameter %s", key2.string());
959 break;
960 }
961 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700962 }
963 // if all keys have been filtered out, remove the command.
964 // otherwise, update the key value pairs
965 if (param2.size() == 0) {
966 removedCommands.add(command2);
967 } else {
968 data2->mKeyValuePairs = param2.toString();
969 }
Eric Laurent21e54562013-09-23 12:08:05 -0700970 command->mTime = command2->mTime;
971 // force delayMs to non 0 so that code below does not request to wait for
972 // command status as the command is now delayed
973 delayMs = 1;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700974 } break;
975
976 case SET_VOLUME: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700977 VolumeData *data = (VolumeData *)command->mParam.get();
978 VolumeData *data2 = (VolumeData *)command2->mParam.get();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700979 if (data->mIO != data2->mIO) break;
980 if (data->mStream != data2->mStream) break;
Steve Block3856b092011-10-20 11:56:00 +0100981 ALOGV("Filtering out volume command on output %d for stream %d",
Eric Laurentde070132010-07-13 04:45:46 -0700982 data->mIO, data->mStream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700983 removedCommands.add(command2);
Eric Laurent21e54562013-09-23 12:08:05 -0700984 command->mTime = command2->mTime;
985 // force delayMs to non 0 so that code below does not request to wait for
986 // command status as the command is now delayed
987 delayMs = 1;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700988 } break;
Eric Laurente45b48a2014-09-04 16:40:57 -0700989
Eric Laurentbaf35fe2016-07-27 15:36:53 -0700990 case SET_VOICE_VOLUME: {
991 VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get();
992 VoiceVolumeData *data2 = (VoiceVolumeData *)command2->mParam.get();
993 ALOGV("Filtering out voice volume command value %f replaced by %f",
994 data2->mVolume, data->mVolume);
995 removedCommands.add(command2);
996 command->mTime = command2->mTime;
997 // force delayMs to non 0 so that code below does not request to wait for
998 // command status as the command is now delayed
999 delayMs = 1;
1000 } break;
1001
Eric Laurente45b48a2014-09-04 16:40:57 -07001002 case CREATE_AUDIO_PATCH:
1003 case RELEASE_AUDIO_PATCH: {
1004 audio_patch_handle_t handle;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001005 struct audio_patch patch;
Eric Laurente45b48a2014-09-04 16:40:57 -07001006 if (command->mCommand == CREATE_AUDIO_PATCH) {
1007 handle = ((CreateAudioPatchData *)command->mParam.get())->mHandle;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001008 patch = ((CreateAudioPatchData *)command->mParam.get())->mPatch;
Eric Laurente45b48a2014-09-04 16:40:57 -07001009 } else {
1010 handle = ((ReleaseAudioPatchData *)command->mParam.get())->mHandle;
1011 }
1012 audio_patch_handle_t handle2;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001013 struct audio_patch patch2;
Eric Laurente45b48a2014-09-04 16:40:57 -07001014 if (command2->mCommand == CREATE_AUDIO_PATCH) {
1015 handle2 = ((CreateAudioPatchData *)command2->mParam.get())->mHandle;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001016 patch2 = ((CreateAudioPatchData *)command2->mParam.get())->mPatch;
Eric Laurente45b48a2014-09-04 16:40:57 -07001017 } else {
1018 handle2 = ((ReleaseAudioPatchData *)command2->mParam.get())->mHandle;
Glenn Kastenf60b6b62015-07-06 10:53:26 -07001019 memset(&patch2, 0, sizeof(patch2));
Eric Laurente45b48a2014-09-04 16:40:57 -07001020 }
1021 if (handle != handle2) break;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001022 /* Filter CREATE_AUDIO_PATCH commands only when they are issued for
1023 same output. */
1024 if( (command->mCommand == CREATE_AUDIO_PATCH) &&
1025 (command2->mCommand == CREATE_AUDIO_PATCH) ) {
1026 bool isOutputDiff = false;
1027 if (patch.num_sources == patch2.num_sources) {
1028 for (unsigned count = 0; count < patch.num_sources; count++) {
1029 if (patch.sources[count].id != patch2.sources[count].id) {
1030 isOutputDiff = true;
1031 break;
1032 }
1033 }
1034 if (isOutputDiff)
1035 break;
1036 }
1037 }
Eric Laurente45b48a2014-09-04 16:40:57 -07001038 ALOGV("Filtering out %s audio patch command for handle %d",
1039 (command->mCommand == CREATE_AUDIO_PATCH) ? "create" : "release", handle);
1040 removedCommands.add(command2);
1041 command->mTime = command2->mTime;
1042 // force delayMs to non 0 so that code below does not request to wait for
1043 // command status as the command is now delayed
1044 delayMs = 1;
1045 } break;
1046
Jean-Michel Trivide801052015-04-14 19:10:14 -07001047 case DYN_POLICY_MIX_STATE_UPDATE: {
1048
1049 } break;
1050
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -08001051 case RECORDING_CONFIGURATION_UPDATE: {
1052
1053 } break;
1054
Mathias Agopian65ab4712010-07-14 17:59:35 -07001055 case START_TONE:
1056 case STOP_TONE:
1057 default:
1058 break;
1059 }
1060 }
1061
1062 // remove filtered commands
1063 for (size_t j = 0; j < removedCommands.size(); j++) {
1064 // removed commands always have time stamps greater than current command
1065 for (size_t k = i + 1; k < mAudioCommands.size(); k++) {
Eric Laurent0ede8922014-05-09 18:04:42 -07001066 if (mAudioCommands[k].get() == removedCommands[j].get()) {
Steve Block3856b092011-10-20 11:56:00 +01001067 ALOGV("suppressing command: %d", mAudioCommands[k]->mCommand);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001068 mAudioCommands.removeAt(k);
1069 break;
1070 }
1071 }
1072 }
1073 removedCommands.clear();
1074
Eric Laurentaa79bef2015-01-15 14:33:51 -08001075 // Disable wait for status if delay is not 0.
1076 // Except for create audio patch command because the returned patch handle
1077 // is needed by audio policy manager
1078 if (delayMs != 0 && command->mCommand != CREATE_AUDIO_PATCH) {
Eric Laurentcec4abb2012-07-03 12:23:02 -07001079 command->mWaitStatus = false;
1080 }
Eric Laurentcec4abb2012-07-03 12:23:02 -07001081
Mathias Agopian65ab4712010-07-14 17:59:35 -07001082 // insert command at the right place according to its time stamp
Eric Laurent1e693b52014-07-09 15:03:28 -07001083 ALOGV("inserting command: %d at index %zd, num commands %zu",
1084 command->mCommand, i+1, mAudioCommands.size());
Mathias Agopian65ab4712010-07-14 17:59:35 -07001085 mAudioCommands.insertAt(command, i + 1);
1086}
1087
1088void AudioPolicyService::AudioCommandThread::exit()
1089{
Steve Block3856b092011-10-20 11:56:00 +01001090 ALOGV("AudioCommandThread::exit");
Mathias Agopian65ab4712010-07-14 17:59:35 -07001091 {
1092 AutoMutex _l(mLock);
1093 requestExit();
1094 mWaitWorkCV.signal();
1095 }
Zach Janga754b4f2015-10-27 01:29:34 +00001096 // Note that we can call it from the thread loop if all other references have been released
1097 // but it will safely return WOULD_BLOCK in this case
Mathias Agopian65ab4712010-07-14 17:59:35 -07001098 requestExitAndWait();
1099}
1100
1101void AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size)
1102{
1103 snprintf(buffer, size, " %02d %06d.%03d %01u %p\n",
1104 mCommand,
1105 (int)ns2s(mTime),
1106 (int)ns2ms(mTime)%1000,
1107 mWaitStatus,
Eric Laurent0ede8922014-05-09 18:04:42 -07001108 mParam.get());
Mathias Agopian65ab4712010-07-14 17:59:35 -07001109}
1110
Dima Zavinfce7a472011-04-19 22:30:36 -07001111/******* helpers for the service_ops callbacks defined below *********/
1112void AudioPolicyService::setParameters(audio_io_handle_t ioHandle,
1113 const char *keyValuePairs,
1114 int delayMs)
1115{
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001116 mAudioCommandThread->parametersCommand(ioHandle, keyValuePairs,
Dima Zavinfce7a472011-04-19 22:30:36 -07001117 delayMs);
1118}
1119
1120int AudioPolicyService::setStreamVolume(audio_stream_type_t stream,
1121 float volume,
1122 audio_io_handle_t output,
1123 int delayMs)
1124{
Glenn Kastenfff6d712012-01-12 16:38:12 -08001125 return (int)mAudioCommandThread->volumeCommand(stream, volume,
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001126 output, delayMs);
Dima Zavinfce7a472011-04-19 22:30:36 -07001127}
1128
1129int AudioPolicyService::startTone(audio_policy_tone_t tone,
1130 audio_stream_type_t stream)
1131{
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001132 if (tone != AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION) {
Steve Block29357bc2012-01-06 19:20:56 +00001133 ALOGE("startTone: illegal tone requested (%d)", tone);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001134 }
1135 if (stream != AUDIO_STREAM_VOICE_CALL) {
Steve Block29357bc2012-01-06 19:20:56 +00001136 ALOGE("startTone: illegal stream (%d) requested for tone %d", stream,
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001137 tone);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001138 }
Dima Zavinfce7a472011-04-19 22:30:36 -07001139 mTonePlaybackThread->startToneCommand(ToneGenerator::TONE_SUP_CALL_WAITING,
1140 AUDIO_STREAM_VOICE_CALL);
1141 return 0;
1142}
1143
1144int AudioPolicyService::stopTone()
1145{
1146 mTonePlaybackThread->stopToneCommand();
1147 return 0;
1148}
1149
1150int AudioPolicyService::setVoiceVolume(float volume, int delayMs)
1151{
1152 return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs);
1153}
1154
Dima Zavinfce7a472011-04-19 22:30:36 -07001155extern "C" {
Eric Laurent2d388ec2014-03-07 13:25:54 -08001156audio_module_handle_t aps_load_hw_module(void *service __unused,
1157 const char *name);
1158audio_io_handle_t aps_open_output(void *service __unused,
Eric Laurenta4c5a552012-03-29 10:12:40 -07001159 audio_devices_t *pDevices,
1160 uint32_t *pSamplingRate,
1161 audio_format_t *pFormat,
1162 audio_channel_mask_t *pChannelMask,
1163 uint32_t *pLatencyMs,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001164 audio_output_flags_t flags);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001165
Eric Laurent2d388ec2014-03-07 13:25:54 -08001166audio_io_handle_t aps_open_output_on_module(void *service __unused,
Eric Laurenta4c5a552012-03-29 10:12:40 -07001167 audio_module_handle_t module,
1168 audio_devices_t *pDevices,
1169 uint32_t *pSamplingRate,
1170 audio_format_t *pFormat,
1171 audio_channel_mask_t *pChannelMask,
1172 uint32_t *pLatencyMs,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +00001173 audio_output_flags_t flags,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001174 const audio_offload_info_t *offloadInfo);
1175audio_io_handle_t aps_open_dup_output(void *service __unused,
Dima Zavinfce7a472011-04-19 22:30:36 -07001176 audio_io_handle_t output1,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001177 audio_io_handle_t output2);
1178int aps_close_output(void *service __unused, audio_io_handle_t output);
1179int aps_suspend_output(void *service __unused, audio_io_handle_t output);
1180int aps_restore_output(void *service __unused, audio_io_handle_t output);
1181audio_io_handle_t aps_open_input(void *service __unused,
Eric Laurenta4c5a552012-03-29 10:12:40 -07001182 audio_devices_t *pDevices,
1183 uint32_t *pSamplingRate,
1184 audio_format_t *pFormat,
1185 audio_channel_mask_t *pChannelMask,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001186 audio_in_acoustics_t acoustics __unused);
1187audio_io_handle_t aps_open_input_on_module(void *service __unused,
Eric Laurenta4c5a552012-03-29 10:12:40 -07001188 audio_module_handle_t module,
1189 audio_devices_t *pDevices,
1190 uint32_t *pSamplingRate,
1191 audio_format_t *pFormat,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001192 audio_channel_mask_t *pChannelMask);
1193int aps_close_input(void *service __unused, audio_io_handle_t input);
1194int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream);
Glenn Kastend848eb42016-03-08 13:42:11 -08001195int aps_move_effects(void *service __unused, audio_session_t session,
Dima Zavinfce7a472011-04-19 22:30:36 -07001196 audio_io_handle_t src_output,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001197 audio_io_handle_t dst_output);
1198char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle,
1199 const char *keys);
1200void aps_set_parameters(void *service, audio_io_handle_t io_handle,
1201 const char *kv_pairs, int delay_ms);
1202int aps_set_stream_volume(void *service, audio_stream_type_t stream,
Dima Zavinfce7a472011-04-19 22:30:36 -07001203 float volume, audio_io_handle_t output,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001204 int delay_ms);
1205int aps_start_tone(void *service, audio_policy_tone_t tone,
1206 audio_stream_type_t stream);
1207int aps_stop_tone(void *service);
1208int aps_set_voice_volume(void *service, float volume, int delay_ms);
1209};
Dima Zavinfce7a472011-04-19 22:30:36 -07001210
Glenn Kastenfcddb0b2016-07-08 17:19:25 -07001211#ifdef USE_LEGACY_AUDIO_POLICY
Dima Zavinfce7a472011-04-19 22:30:36 -07001212namespace {
1213 struct audio_policy_service_ops aps_ops = {
Glenn Kasten01d3acb2014-02-06 08:24:07 -08001214 .open_output = aps_open_output,
1215 .open_duplicate_output = aps_open_dup_output,
1216 .close_output = aps_close_output,
1217 .suspend_output = aps_suspend_output,
1218 .restore_output = aps_restore_output,
1219 .open_input = aps_open_input,
1220 .close_input = aps_close_input,
1221 .set_stream_volume = aps_set_stream_volume,
Glenn Kastend2304db2014-02-03 07:40:31 -08001222 .invalidate_stream = aps_invalidate_stream,
Glenn Kasten01d3acb2014-02-06 08:24:07 -08001223 .set_parameters = aps_set_parameters,
1224 .get_parameters = aps_get_parameters,
1225 .start_tone = aps_start_tone,
1226 .stop_tone = aps_stop_tone,
1227 .set_voice_volume = aps_set_voice_volume,
1228 .move_effects = aps_move_effects,
1229 .load_hw_module = aps_load_hw_module,
1230 .open_output_on_module = aps_open_output_on_module,
1231 .open_input_on_module = aps_open_input_on_module,
Dima Zavinfce7a472011-04-19 22:30:36 -07001232 };
1233}; // namespace <unnamed>
Glenn Kastenfcddb0b2016-07-08 17:19:25 -07001234#endif
Dima Zavinfce7a472011-04-19 22:30:36 -07001235
Mathias Agopian65ab4712010-07-14 17:59:35 -07001236}; // namespace android