blob: ec39a79cf60f8c0fa2ca45898aca11d39ac8d928 [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>
Chih-Hung Hsiehc84d9d22014-11-14 13:33:34 -080037#include <media/AudioParameter.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070038
Dima Zavinfce7a472011-04-19 22:30:36 -070039#include <hardware/hardware.h>
Dima Zavin64760242011-05-11 14:15:23 -070040#include <system/audio.h>
Dima Zavin7394a4f2011-06-13 18:16:26 -070041#include <system/audio_policy.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070042#include <hardware/audio_policy.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070043
Mathias Agopian65ab4712010-07-14 17:59:35 -070044namespace android {
45
Glenn Kasten8dad0e32012-01-09 08:41:22 -080046static const char kDeadlockedString[] = "AudioPolicyService may be deadlocked\n";
47static const char kCmdDeadlockedString[] = "AudioPolicyService command thread may be deadlocked\n";
Mathias Agopian65ab4712010-07-14 17:59:35 -070048
49static const int kDumpLockRetries = 50;
Glenn Kasten22ecc912012-01-09 08:33:38 -080050static const int kDumpLockSleepUs = 20000;
Mathias Agopian65ab4712010-07-14 17:59:35 -070051
Eric Laurent0ede8922014-05-09 18:04:42 -070052static const nsecs_t kAudioCommandTimeoutNs = seconds(3); // 3 seconds
Christer Fletcher5fa8c4b2013-01-18 15:27:03 +010053
Glenn Kastenfcddb0b2016-07-08 17:19:25 -070054#ifdef USE_LEGACY_AUDIO_POLICY
Dima Zavinfce7a472011-04-19 22:30:36 -070055namespace {
56 extern struct audio_policy_service_ops aps_ops;
57};
Glenn Kastenfcddb0b2016-07-08 17:19:25 -070058#endif
Dima Zavinfce7a472011-04-19 22:30:36 -070059
Mathias Agopian65ab4712010-07-14 17:59:35 -070060// ----------------------------------------------------------------------------
61
62AudioPolicyService::AudioPolicyService()
Eric Laurentdce54a12014-03-10 12:19:46 -070063 : BnAudioPolicyService(), mpAudioPolicyDev(NULL), mpAudioPolicy(NULL),
Eric Laurentbb6c9a02014-09-25 14:11:47 -070064 mAudioPolicyManager(NULL), mAudioPolicyClient(NULL), mPhoneState(AUDIO_MODE_INVALID)
Mathias Agopian65ab4712010-07-14 17:59:35 -070065{
Eric Laurentf5ada6e2014-10-09 17:49:00 -070066}
67
68void AudioPolicyService::onFirstRef()
69{
Eric Laurent8b1e80b2014-10-07 09:08:47 -070070 {
71 Mutex::Autolock _l(mLock);
Eric Laurent93575202011-01-18 18:39:02 -080072
Eric Laurent8b1e80b2014-10-07 09:08:47 -070073 // start tone playback thread
74 mTonePlaybackThread = new AudioCommandThread(String8("ApmTone"), this);
75 // start audio commands thread
76 mAudioCommandThread = new AudioCommandThread(String8("ApmAudio"), this);
77 // start output activity command thread
78 mOutputCommandThread = new AudioCommandThread(String8("ApmOutput"), this);
Eric Laurentdce54a12014-03-10 12:19:46 -070079
80#ifdef USE_LEGACY_AUDIO_POLICY
Eric Laurent8b1e80b2014-10-07 09:08:47 -070081 ALOGI("AudioPolicyService CSTOR in legacy mode");
Eric Laurentdce54a12014-03-10 12:19:46 -070082
Eric Laurent8b1e80b2014-10-07 09:08:47 -070083 /* instantiate the audio policy manager */
Glenn Kastenfcddb0b2016-07-08 17:19:25 -070084 const struct hw_module_t *module;
85 int rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module);
Eric Laurent8b1e80b2014-10-07 09:08:47 -070086 if (rc) {
87 return;
88 }
89 rc = audio_policy_dev_open(module, &mpAudioPolicyDev);
90 ALOGE_IF(rc, "couldn't open audio policy device (%s)", strerror(-rc));
91 if (rc) {
92 return;
93 }
Eric Laurent93575202011-01-18 18:39:02 -080094
Eric Laurent8b1e80b2014-10-07 09:08:47 -070095 rc = mpAudioPolicyDev->create_audio_policy(mpAudioPolicyDev, &aps_ops, this,
96 &mpAudioPolicy);
97 ALOGE_IF(rc, "couldn't create audio policy (%s)", strerror(-rc));
98 if (rc) {
99 return;
100 }
Dima Zavinfce7a472011-04-19 22:30:36 -0700101
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700102 rc = mpAudioPolicy->init_check(mpAudioPolicy);
103 ALOGE_IF(rc, "couldn't init_check the audio policy (%s)", strerror(-rc));
104 if (rc) {
105 return;
106 }
107 ALOGI("Loaded audio policy from %s (%s)", module->name, module->id);
Eric Laurentdce54a12014-03-10 12:19:46 -0700108#else
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700109 ALOGI("AudioPolicyService CSTOR in new mode");
Eric Laurentdce54a12014-03-10 12:19:46 -0700110
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700111 mAudioPolicyClient = new AudioPolicyClient(this);
112 mAudioPolicyManager = createAudioPolicyManager(mAudioPolicyClient);
Eric Laurentdce54a12014-03-10 12:19:46 -0700113#endif
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700114 }
bryant_liuba2b4392014-06-11 16:49:30 +0800115 // load audio processing modules
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700116 sp<AudioPolicyEffects>audioPolicyEffects = new AudioPolicyEffects();
117 {
118 Mutex::Autolock _l(mLock);
119 mAudioPolicyEffects = audioPolicyEffects;
120 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700121}
122
123AudioPolicyService::~AudioPolicyService()
124{
125 mTonePlaybackThread->exit();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700126 mAudioCommandThread->exit();
Eric Laurent657ff612014-05-07 11:58:24 -0700127 mOutputCommandThread->exit();
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700128
Eric Laurentdce54a12014-03-10 12:19:46 -0700129#ifdef USE_LEGACY_AUDIO_POLICY
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700130 if (mpAudioPolicy != NULL && mpAudioPolicyDev != NULL) {
Dima Zavinfce7a472011-04-19 22:30:36 -0700131 mpAudioPolicyDev->destroy_audio_policy(mpAudioPolicyDev, mpAudioPolicy);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700132 }
133 if (mpAudioPolicyDev != NULL) {
Dima Zavinfce7a472011-04-19 22:30:36 -0700134 audio_policy_dev_close(mpAudioPolicyDev);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700135 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700136#else
Eric Laurentf269b8e2014-06-09 20:01:29 -0700137 destroyAudioPolicyManager(mAudioPolicyManager);
Eric Laurentdce54a12014-03-10 12:19:46 -0700138 delete mAudioPolicyClient;
139#endif
Eric Laurentb52c1522014-05-20 11:27:36 -0700140
141 mNotificationClients.clear();
bryant_liuba2b4392014-06-11 16:49:30 +0800142 mAudioPolicyEffects.clear();
Eric Laurentb52c1522014-05-20 11:27:36 -0700143}
144
145// A notification client is always registered by AudioSystem when the client process
146// connects to AudioPolicyService.
147void AudioPolicyService::registerClient(const sp<IAudioPolicyServiceClient>& client)
148{
Eric Laurent12590252015-08-21 18:40:20 -0700149 if (client == 0) {
150 ALOGW("%s got NULL client", __FUNCTION__);
151 return;
152 }
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800153 Mutex::Autolock _l(mNotificationClientsLock);
Eric Laurentb52c1522014-05-20 11:27:36 -0700154
155 uid_t uid = IPCThreadState::self()->getCallingUid();
156 if (mNotificationClients.indexOfKey(uid) < 0) {
157 sp<NotificationClient> notificationClient = new NotificationClient(this,
158 client,
159 uid);
160 ALOGV("registerClient() client %p, uid %d", client.get(), uid);
161
162 mNotificationClients.add(uid, notificationClient);
163
Marco Nelissenf8880202014-11-14 07:58:25 -0800164 sp<IBinder> binder = IInterface::asBinder(client);
Eric Laurentb52c1522014-05-20 11:27:36 -0700165 binder->linkToDeath(notificationClient);
166 }
167}
168
Eric Laurente8726fe2015-06-26 09:39:24 -0700169void AudioPolicyService::setAudioPortCallbacksEnabled(bool enabled)
170{
171 Mutex::Autolock _l(mNotificationClientsLock);
172
173 uid_t uid = IPCThreadState::self()->getCallingUid();
174 if (mNotificationClients.indexOfKey(uid) < 0) {
175 return;
176 }
177 mNotificationClients.valueFor(uid)->setAudioPortCallbacksEnabled(enabled);
178}
179
Eric Laurentb52c1522014-05-20 11:27:36 -0700180// removeNotificationClient() is called when the client process dies.
181void AudioPolicyService::removeNotificationClient(uid_t uid)
182{
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800183 {
184 Mutex::Autolock _l(mNotificationClientsLock);
185 mNotificationClients.removeItem(uid);
186 }
Eric Laurentb52c1522014-05-20 11:27:36 -0700187#ifndef USE_LEGACY_AUDIO_POLICY
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800188 {
189 Mutex::Autolock _l(mLock);
Eric Laurentb52c1522014-05-20 11:27:36 -0700190 if (mAudioPolicyManager) {
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700191 mAudioPolicyManager->releaseResourcesForUid(uid);
Eric Laurentb52c1522014-05-20 11:27:36 -0700192 }
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800193 }
Eric Laurentb52c1522014-05-20 11:27:36 -0700194#endif
195}
196
197void AudioPolicyService::onAudioPortListUpdate()
198{
199 mOutputCommandThread->updateAudioPortListCommand();
200}
201
202void AudioPolicyService::doOnAudioPortListUpdate()
203{
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800204 Mutex::Autolock _l(mNotificationClientsLock);
Eric Laurentb52c1522014-05-20 11:27:36 -0700205 for (size_t i = 0; i < mNotificationClients.size(); i++) {
206 mNotificationClients.valueAt(i)->onAudioPortListUpdate();
207 }
208}
209
210void AudioPolicyService::onAudioPatchListUpdate()
211{
212 mOutputCommandThread->updateAudioPatchListCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700213}
214
Eric Laurentb52c1522014-05-20 11:27:36 -0700215void AudioPolicyService::doOnAudioPatchListUpdate()
216{
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800217 Mutex::Autolock _l(mNotificationClientsLock);
Eric Laurentb52c1522014-05-20 11:27:36 -0700218 for (size_t i = 0; i < mNotificationClients.size(); i++) {
219 mNotificationClients.valueAt(i)->onAudioPatchListUpdate();
220 }
221}
222
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700223void AudioPolicyService::onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state)
Jean-Michel Trivide801052015-04-14 19:10:14 -0700224{
225 ALOGV("AudioPolicyService::onDynamicPolicyMixStateUpdate(%s, %d)",
226 regId.string(), state);
227 mOutputCommandThread->dynamicPolicyMixStateUpdateCommand(regId, state);
228}
229
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700230void AudioPolicyService::doOnDynamicPolicyMixStateUpdate(const String8& regId, int32_t state)
Jean-Michel Trivide801052015-04-14 19:10:14 -0700231{
232 Mutex::Autolock _l(mNotificationClientsLock);
233 for (size_t i = 0; i < mNotificationClients.size(); i++) {
234 mNotificationClients.valueAt(i)->onDynamicPolicyMixStateUpdate(regId, state);
235 }
236}
237
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800238void AudioPolicyService::onRecordingConfigurationUpdate(int event, audio_session_t session,
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800239 audio_source_t source, const audio_config_base_t *clientConfig,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800240 const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle)
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800241{
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800242 mOutputCommandThread->recordingConfigurationUpdateCommand(event, session, source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800243 clientConfig, deviceConfig, patchHandle);
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800244}
245
246void AudioPolicyService::doOnRecordingConfigurationUpdate(int event, audio_session_t session,
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800247 audio_source_t source, const audio_config_base_t *clientConfig,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800248 const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle)
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800249{
250 Mutex::Autolock _l(mNotificationClientsLock);
251 for (size_t i = 0; i < mNotificationClients.size(); i++) {
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800252 mNotificationClients.valueAt(i)->onRecordingConfigurationUpdate(event, session, source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800253 clientConfig, deviceConfig, patchHandle);
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800254 }
255}
256
257status_t AudioPolicyService::clientCreateAudioPatch(const struct audio_patch *patch,
258 audio_patch_handle_t *handle,
259 int delayMs)
260{
261 return mAudioCommandThread->createAudioPatchCommand(patch, handle, delayMs);
262}
263
264status_t AudioPolicyService::clientReleaseAudioPatch(audio_patch_handle_t handle,
265 int delayMs)
266{
267 return mAudioCommandThread->releaseAudioPatchCommand(handle, delayMs);
268}
269
Eric Laurente1715a42014-05-20 11:30:42 -0700270status_t AudioPolicyService::clientSetAudioPortConfig(const struct audio_port_config *config,
271 int delayMs)
272{
273 return mAudioCommandThread->setAudioPortConfigCommand(config, delayMs);
274}
275
Eric Laurentb52c1522014-05-20 11:27:36 -0700276AudioPolicyService::NotificationClient::NotificationClient(const sp<AudioPolicyService>& service,
277 const sp<IAudioPolicyServiceClient>& client,
278 uid_t uid)
Eric Laurente8726fe2015-06-26 09:39:24 -0700279 : mService(service), mUid(uid), mAudioPolicyServiceClient(client),
280 mAudioPortCallbacksEnabled(false)
Eric Laurentb52c1522014-05-20 11:27:36 -0700281{
282}
283
284AudioPolicyService::NotificationClient::~NotificationClient()
285{
286}
287
288void AudioPolicyService::NotificationClient::binderDied(const wp<IBinder>& who __unused)
289{
290 sp<NotificationClient> keep(this);
291 sp<AudioPolicyService> service = mService.promote();
292 if (service != 0) {
293 service->removeNotificationClient(mUid);
294 }
295}
296
297void AudioPolicyService::NotificationClient::onAudioPortListUpdate()
298{
Eric Laurente8726fe2015-06-26 09:39:24 -0700299 if (mAudioPolicyServiceClient != 0 && mAudioPortCallbacksEnabled) {
Eric Laurentb52c1522014-05-20 11:27:36 -0700300 mAudioPolicyServiceClient->onAudioPortListUpdate();
301 }
302}
303
304void AudioPolicyService::NotificationClient::onAudioPatchListUpdate()
305{
Eric Laurente8726fe2015-06-26 09:39:24 -0700306 if (mAudioPolicyServiceClient != 0 && mAudioPortCallbacksEnabled) {
Eric Laurentb52c1522014-05-20 11:27:36 -0700307 mAudioPolicyServiceClient->onAudioPatchListUpdate();
308 }
309}
Eric Laurent57dae992011-07-24 13:36:09 -0700310
Jean-Michel Trivide801052015-04-14 19:10:14 -0700311void AudioPolicyService::NotificationClient::onDynamicPolicyMixStateUpdate(
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700312 const String8& regId, int32_t state)
Jean-Michel Trivide801052015-04-14 19:10:14 -0700313{
314 if (mAudioPolicyServiceClient != 0) {
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800315 mAudioPolicyServiceClient->onDynamicPolicyMixStateUpdate(regId, state);
316 }
317}
318
319void AudioPolicyService::NotificationClient::onRecordingConfigurationUpdate(
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800320 int event, audio_session_t session, audio_source_t source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800321 const audio_config_base_t *clientConfig, const audio_config_base_t *deviceConfig,
322 audio_patch_handle_t patchHandle)
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800323{
324 if (mAudioPolicyServiceClient != 0) {
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800325 mAudioPolicyServiceClient->onRecordingConfigurationUpdate(event, session, source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800326 clientConfig, deviceConfig, patchHandle);
Jean-Michel Trivide801052015-04-14 19:10:14 -0700327 }
328}
329
Eric Laurente8726fe2015-06-26 09:39:24 -0700330void AudioPolicyService::NotificationClient::setAudioPortCallbacksEnabled(bool enabled)
331{
332 mAudioPortCallbacksEnabled = enabled;
333}
334
335
Mathias Agopian65ab4712010-07-14 17:59:35 -0700336void AudioPolicyService::binderDied(const wp<IBinder>& who) {
Glenn Kasten411e4472012-11-02 10:00:06 -0700337 ALOGW("binderDied() %p, calling pid %d", who.unsafe_get(),
Eric Laurentde070132010-07-13 04:45:46 -0700338 IPCThreadState::self()->getCallingPid());
Mathias Agopian65ab4712010-07-14 17:59:35 -0700339}
340
341static bool tryLock(Mutex& mutex)
342{
343 bool locked = false;
344 for (int i = 0; i < kDumpLockRetries; ++i) {
345 if (mutex.tryLock() == NO_ERROR) {
346 locked = true;
347 break;
348 }
Glenn Kasten22ecc912012-01-09 08:33:38 -0800349 usleep(kDumpLockSleepUs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700350 }
351 return locked;
352}
353
354status_t AudioPolicyService::dumpInternals(int fd)
355{
356 const size_t SIZE = 256;
357 char buffer[SIZE];
358 String8 result;
359
Eric Laurentdce54a12014-03-10 12:19:46 -0700360#ifdef USE_LEGACY_AUDIO_POLICY
Dima Zavinfce7a472011-04-19 22:30:36 -0700361 snprintf(buffer, SIZE, "PolicyManager Interface: %p\n", mpAudioPolicy);
Eric Laurentdce54a12014-03-10 12:19:46 -0700362#else
363 snprintf(buffer, SIZE, "AudioPolicyManager: %p\n", mAudioPolicyManager);
364#endif
Mathias Agopian65ab4712010-07-14 17:59:35 -0700365 result.append(buffer);
366 snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get());
367 result.append(buffer);
368 snprintf(buffer, SIZE, "Tones Thread: %p\n", mTonePlaybackThread.get());
369 result.append(buffer);
370
371 write(fd, result.string(), result.size());
372 return NO_ERROR;
373}
374
Glenn Kasten0f11b512014-01-31 16:18:54 -0800375status_t AudioPolicyService::dump(int fd, const Vector<String16>& args __unused)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700376{
Glenn Kasten44deb052012-02-05 18:09:08 -0800377 if (!dumpAllowed()) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700378 dumpPermissionDenial(fd);
379 } else {
380 bool locked = tryLock(mLock);
381 if (!locked) {
382 String8 result(kDeadlockedString);
383 write(fd, result.string(), result.size());
384 }
385
386 dumpInternals(fd);
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800387 if (mAudioCommandThread != 0) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700388 mAudioCommandThread->dump(fd);
389 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800390 if (mTonePlaybackThread != 0) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700391 mTonePlaybackThread->dump(fd);
392 }
393
Eric Laurentdce54a12014-03-10 12:19:46 -0700394#ifdef USE_LEGACY_AUDIO_POLICY
Dima Zavinfce7a472011-04-19 22:30:36 -0700395 if (mpAudioPolicy) {
396 mpAudioPolicy->dump(mpAudioPolicy, fd);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700397 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700398#else
399 if (mAudioPolicyManager) {
400 mAudioPolicyManager->dump(fd);
401 }
402#endif
Mathias Agopian65ab4712010-07-14 17:59:35 -0700403
404 if (locked) mLock.unlock();
405 }
406 return NO_ERROR;
407}
408
409status_t AudioPolicyService::dumpPermissionDenial(int fd)
410{
411 const size_t SIZE = 256;
412 char buffer[SIZE];
413 String8 result;
414 snprintf(buffer, SIZE, "Permission Denial: "
415 "can't dump AudioPolicyService from pid=%d, uid=%d\n",
416 IPCThreadState::self()->getCallingPid(),
417 IPCThreadState::self()->getCallingUid());
418 result.append(buffer);
419 write(fd, result.string(), result.size());
420 return NO_ERROR;
421}
422
423status_t AudioPolicyService::onTransact(
424 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
425{
426 return BnAudioPolicyService::onTransact(code, data, reply, flags);
427}
428
429
Mathias Agopian65ab4712010-07-14 17:59:35 -0700430// ----------- AudioPolicyService::AudioCommandThread implementation ----------
431
Eric Laurentbfb1b832013-01-07 09:53:42 -0800432AudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name,
433 const wp<AudioPolicyService>& service)
434 : Thread(false), mName(name), mService(service)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700435{
436 mpToneGenerator = NULL;
437}
438
439
440AudioPolicyService::AudioCommandThread::~AudioCommandThread()
441{
Eric Laurentbfb1b832013-01-07 09:53:42 -0800442 if (!mAudioCommands.isEmpty()) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700443 release_wake_lock(mName.string());
444 }
445 mAudioCommands.clear();
Glenn Kastene9dd0172012-01-27 18:08:45 -0800446 delete mpToneGenerator;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700447}
448
449void AudioPolicyService::AudioCommandThread::onFirstRef()
450{
Eric Laurentbfb1b832013-01-07 09:53:42 -0800451 run(mName.string(), ANDROID_PRIORITY_AUDIO);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700452}
453
454bool AudioPolicyService::AudioCommandThread::threadLoop()
455{
Eric Laurentd7eda8d2016-02-02 17:18:39 -0800456 nsecs_t waitTime = -1;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700457
458 mLock.lock();
459 while (!exitPending())
460 {
Eric Laurent59a89232014-06-08 14:14:17 -0700461 sp<AudioPolicyService> svc;
462 while (!mAudioCommands.isEmpty() && !exitPending()) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700463 nsecs_t curTime = systemTime();
464 // commands are sorted by increasing time stamp: execute them from index 0 and up
465 if (mAudioCommands[0]->mTime <= curTime) {
Eric Laurent0ede8922014-05-09 18:04:42 -0700466 sp<AudioCommand> command = mAudioCommands[0];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700467 mAudioCommands.removeAt(0);
Eric Laurent0ede8922014-05-09 18:04:42 -0700468 mLastCommand = command;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700469
470 switch (command->mCommand) {
471 case START_TONE: {
472 mLock.unlock();
Eric Laurent0ede8922014-05-09 18:04:42 -0700473 ToneData *data = (ToneData *)command->mParam.get();
Steve Block3856b092011-10-20 11:56:00 +0100474 ALOGV("AudioCommandThread() processing start tone %d on stream %d",
Mathias Agopian65ab4712010-07-14 17:59:35 -0700475 data->mType, data->mStream);
Glenn Kastene9dd0172012-01-27 18:08:45 -0800476 delete mpToneGenerator;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700477 mpToneGenerator = new ToneGenerator(data->mStream, 1.0);
478 mpToneGenerator->startTone(data->mType);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700479 mLock.lock();
480 }break;
481 case STOP_TONE: {
482 mLock.unlock();
Steve Block3856b092011-10-20 11:56:00 +0100483 ALOGV("AudioCommandThread() processing stop tone");
Mathias Agopian65ab4712010-07-14 17:59:35 -0700484 if (mpToneGenerator != NULL) {
485 mpToneGenerator->stopTone();
486 delete mpToneGenerator;
487 mpToneGenerator = NULL;
488 }
489 mLock.lock();
490 }break;
491 case SET_VOLUME: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700492 VolumeData *data = (VolumeData *)command->mParam.get();
Steve Block3856b092011-10-20 11:56:00 +0100493 ALOGV("AudioCommandThread() processing set volume stream %d, \
Eric Laurentde070132010-07-13 04:45:46 -0700494 volume %f, output %d", data->mStream, data->mVolume, data->mIO);
495 command->mStatus = AudioSystem::setStreamVolume(data->mStream,
496 data->mVolume,
497 data->mIO);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700498 }break;
499 case SET_PARAMETERS: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700500 ParametersData *data = (ParametersData *)command->mParam.get();
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700501 ALOGV("AudioCommandThread() processing set parameters string %s, io %d",
502 data->mKeyValuePairs.string(), data->mIO);
503 command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs);
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700504 }break;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700505 case SET_VOICE_VOLUME: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700506 VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get();
Steve Block3856b092011-10-20 11:56:00 +0100507 ALOGV("AudioCommandThread() processing set voice volume volume %f",
Eric Laurentde070132010-07-13 04:45:46 -0700508 data->mVolume);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700509 command->mStatus = AudioSystem::setVoiceVolume(data->mVolume);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700510 }break;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800511 case STOP_OUTPUT: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700512 StopOutputData *data = (StopOutputData *)command->mParam.get();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800513 ALOGV("AudioCommandThread() processing stop output %d",
514 data->mIO);
Eric Laurent59a89232014-06-08 14:14:17 -0700515 svc = mService.promote();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800516 if (svc == 0) {
517 break;
518 }
519 mLock.unlock();
520 svc->doStopOutput(data->mIO, data->mStream, data->mSession);
521 mLock.lock();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800522 }break;
523 case RELEASE_OUTPUT: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700524 ReleaseOutputData *data = (ReleaseOutputData *)command->mParam.get();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800525 ALOGV("AudioCommandThread() processing release output %d",
526 data->mIO);
Eric Laurent59a89232014-06-08 14:14:17 -0700527 svc = mService.promote();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800528 if (svc == 0) {
529 break;
530 }
531 mLock.unlock();
Eric Laurente83b55d2014-11-14 10:06:21 -0800532 svc->doReleaseOutput(data->mIO, data->mStream, data->mSession);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800533 mLock.lock();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800534 }break;
Eric Laurent951f4552014-05-20 10:48:17 -0700535 case CREATE_AUDIO_PATCH: {
536 CreateAudioPatchData *data = (CreateAudioPatchData *)command->mParam.get();
537 ALOGV("AudioCommandThread() processing create audio patch");
538 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
539 if (af == 0) {
540 command->mStatus = PERMISSION_DENIED;
541 } else {
542 command->mStatus = af->createAudioPatch(&data->mPatch, &data->mHandle);
543 }
544 } break;
545 case RELEASE_AUDIO_PATCH: {
546 ReleaseAudioPatchData *data = (ReleaseAudioPatchData *)command->mParam.get();
547 ALOGV("AudioCommandThread() processing release audio patch");
548 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
549 if (af == 0) {
550 command->mStatus = PERMISSION_DENIED;
551 } else {
552 command->mStatus = af->releaseAudioPatch(data->mHandle);
553 }
554 } break;
Eric Laurentb52c1522014-05-20 11:27:36 -0700555 case UPDATE_AUDIOPORT_LIST: {
556 ALOGV("AudioCommandThread() processing update audio port list");
Eric Laurent59a89232014-06-08 14:14:17 -0700557 svc = mService.promote();
Eric Laurentb52c1522014-05-20 11:27:36 -0700558 if (svc == 0) {
559 break;
560 }
561 mLock.unlock();
562 svc->doOnAudioPortListUpdate();
563 mLock.lock();
564 }break;
565 case UPDATE_AUDIOPATCH_LIST: {
566 ALOGV("AudioCommandThread() processing update audio patch list");
Eric Laurent59a89232014-06-08 14:14:17 -0700567 svc = mService.promote();
Eric Laurentb52c1522014-05-20 11:27:36 -0700568 if (svc == 0) {
569 break;
570 }
571 mLock.unlock();
572 svc->doOnAudioPatchListUpdate();
573 mLock.lock();
574 }break;
Eric Laurente1715a42014-05-20 11:30:42 -0700575 case SET_AUDIOPORT_CONFIG: {
576 SetAudioPortConfigData *data = (SetAudioPortConfigData *)command->mParam.get();
577 ALOGV("AudioCommandThread() processing set port config");
578 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
579 if (af == 0) {
580 command->mStatus = PERMISSION_DENIED;
581 } else {
582 command->mStatus = af->setAudioPortConfig(&data->mConfig);
583 }
584 } break;
Jean-Michel Trivide801052015-04-14 19:10:14 -0700585 case DYN_POLICY_MIX_STATE_UPDATE: {
586 DynPolicyMixStateUpdateData *data =
587 (DynPolicyMixStateUpdateData *)command->mParam.get();
Jean-Michel Trivide801052015-04-14 19:10:14 -0700588 ALOGV("AudioCommandThread() processing dyn policy mix state update %s %d",
589 data->mRegId.string(), data->mState);
590 svc = mService.promote();
591 if (svc == 0) {
592 break;
593 }
594 mLock.unlock();
595 svc->doOnDynamicPolicyMixStateUpdate(data->mRegId, data->mState);
596 mLock.lock();
597 } break;
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800598 case RECORDING_CONFIGURATION_UPDATE: {
599 RecordingConfigurationUpdateData *data =
600 (RecordingConfigurationUpdateData *)command->mParam.get();
601 ALOGV("AudioCommandThread() processing recording configuration update");
602 svc = mService.promote();
603 if (svc == 0) {
604 break;
605 }
606 mLock.unlock();
607 svc->doOnRecordingConfigurationUpdate(data->mEvent, data->mSession,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800608 data->mSource, &data->mClientConfig, &data->mDeviceConfig,
609 data->mPatchHandle);
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800610 mLock.lock();
611 } break;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700612 default:
Steve Block5ff1dd52012-01-05 23:22:43 +0000613 ALOGW("AudioCommandThread() unknown command %d", command->mCommand);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700614 }
Eric Laurent0ede8922014-05-09 18:04:42 -0700615 {
616 Mutex::Autolock _l(command->mLock);
617 if (command->mWaitStatus) {
618 command->mWaitStatus = false;
619 command->mCond.signal();
620 }
621 }
Eric Laurentd7eda8d2016-02-02 17:18:39 -0800622 waitTime = -1;
Zach Janga754b4f2015-10-27 01:29:34 +0000623 // release mLock before releasing strong reference on the service as
624 // AudioPolicyService destructor calls AudioCommandThread::exit() which
625 // acquires mLock.
626 mLock.unlock();
627 svc.clear();
628 mLock.lock();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700629 } else {
630 waitTime = mAudioCommands[0]->mTime - curTime;
631 break;
632 }
633 }
Zach Janga754b4f2015-10-27 01:29:34 +0000634
635 // release delayed commands wake lock if the queue is empty
636 if (mAudioCommands.isEmpty()) {
Ricardo Garcia05f2fdc2014-07-24 15:48:24 -0700637 release_wake_lock(mName.string());
Zach Janga754b4f2015-10-27 01:29:34 +0000638 }
639
640 // At this stage we have either an empty command queue or the first command in the queue
641 // has a finite delay. So unless we are exiting it is safe to wait.
642 if (!exitPending()) {
Eric Laurent59a89232014-06-08 14:14:17 -0700643 ALOGV("AudioCommandThread() going to sleep");
Eric Laurentd7eda8d2016-02-02 17:18:39 -0800644 if (waitTime == -1) {
645 mWaitWorkCV.wait(mLock);
646 } else {
647 mWaitWorkCV.waitRelative(mLock, waitTime);
648 }
Eric Laurent59a89232014-06-08 14:14:17 -0700649 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700650 }
Ricardo Garcia05f2fdc2014-07-24 15:48:24 -0700651 // release delayed commands wake lock before quitting
652 if (!mAudioCommands.isEmpty()) {
653 release_wake_lock(mName.string());
654 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700655 mLock.unlock();
656 return false;
657}
658
659status_t AudioPolicyService::AudioCommandThread::dump(int fd)
660{
661 const size_t SIZE = 256;
662 char buffer[SIZE];
663 String8 result;
664
665 snprintf(buffer, SIZE, "AudioCommandThread %p Dump\n", this);
666 result.append(buffer);
667 write(fd, result.string(), result.size());
668
669 bool locked = tryLock(mLock);
670 if (!locked) {
671 String8 result2(kCmdDeadlockedString);
672 write(fd, result2.string(), result2.size());
673 }
674
675 snprintf(buffer, SIZE, "- Commands:\n");
676 result = String8(buffer);
677 result.append(" Command Time Wait pParam\n");
Glenn Kasten8d6a2442012-02-08 14:04:28 -0800678 for (size_t i = 0; i < mAudioCommands.size(); i++) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700679 mAudioCommands[i]->dump(buffer, SIZE);
680 result.append(buffer);
681 }
682 result.append(" Last Command\n");
Eric Laurent0ede8922014-05-09 18:04:42 -0700683 if (mLastCommand != 0) {
684 mLastCommand->dump(buffer, SIZE);
685 result.append(buffer);
686 } else {
687 result.append(" none\n");
688 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700689
690 write(fd, result.string(), result.size());
691
692 if (locked) mLock.unlock();
693
694 return NO_ERROR;
695}
696
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800697void AudioPolicyService::AudioCommandThread::startToneCommand(ToneGenerator::tone_type type,
698 audio_stream_type_t stream)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700699{
Eric Laurent0ede8922014-05-09 18:04:42 -0700700 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700701 command->mCommand = START_TONE;
Eric Laurent0ede8922014-05-09 18:04:42 -0700702 sp<ToneData> data = new ToneData();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700703 data->mType = type;
704 data->mStream = stream;
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100705 command->mParam = data;
Steve Block3856b092011-10-20 11:56:00 +0100706 ALOGV("AudioCommandThread() adding tone start type %d, stream %d", type, stream);
Eric Laurent0ede8922014-05-09 18:04:42 -0700707 sendCommand(command);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700708}
709
710void AudioPolicyService::AudioCommandThread::stopToneCommand()
711{
Eric Laurent0ede8922014-05-09 18:04:42 -0700712 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700713 command->mCommand = STOP_TONE;
Steve Block3856b092011-10-20 11:56:00 +0100714 ALOGV("AudioCommandThread() adding tone stop");
Eric Laurent0ede8922014-05-09 18:04:42 -0700715 sendCommand(command);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700716}
717
Glenn Kastenfff6d712012-01-12 16:38:12 -0800718status_t AudioPolicyService::AudioCommandThread::volumeCommand(audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700719 float volume,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800720 audio_io_handle_t output,
Eric Laurentde070132010-07-13 04:45:46 -0700721 int delayMs)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700722{
Eric Laurent0ede8922014-05-09 18:04:42 -0700723 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700724 command->mCommand = SET_VOLUME;
Eric Laurent0ede8922014-05-09 18:04:42 -0700725 sp<VolumeData> data = new VolumeData();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700726 data->mStream = stream;
727 data->mVolume = volume;
728 data->mIO = output;
729 command->mParam = data;
Eric Laurent0ede8922014-05-09 18:04:42 -0700730 command->mWaitStatus = true;
Steve Block3856b092011-10-20 11:56:00 +0100731 ALOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d",
Eric Laurentde070132010-07-13 04:45:46 -0700732 stream, volume, output);
Eric Laurent0ede8922014-05-09 18:04:42 -0700733 return sendCommand(command, delayMs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700734}
735
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800736status_t AudioPolicyService::AudioCommandThread::parametersCommand(audio_io_handle_t ioHandle,
Dima Zavinfce7a472011-04-19 22:30:36 -0700737 const char *keyValuePairs,
Eric Laurentde070132010-07-13 04:45:46 -0700738 int delayMs)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700739{
Eric Laurent0ede8922014-05-09 18:04:42 -0700740 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700741 command->mCommand = SET_PARAMETERS;
Eric Laurent0ede8922014-05-09 18:04:42 -0700742 sp<ParametersData> data = new ParametersData();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700743 data->mIO = ioHandle;
Dima Zavinfce7a472011-04-19 22:30:36 -0700744 data->mKeyValuePairs = String8(keyValuePairs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700745 command->mParam = data;
Eric Laurent0ede8922014-05-09 18:04:42 -0700746 command->mWaitStatus = true;
Steve Block3856b092011-10-20 11:56:00 +0100747 ALOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d",
Dima Zavinfce7a472011-04-19 22:30:36 -0700748 keyValuePairs, ioHandle, delayMs);
Eric Laurent0ede8922014-05-09 18:04:42 -0700749 return sendCommand(command, delayMs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700750}
751
752status_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs)
753{
Eric Laurent0ede8922014-05-09 18:04:42 -0700754 sp<AudioCommand> command = new AudioCommand();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700755 command->mCommand = SET_VOICE_VOLUME;
Eric Laurent0ede8922014-05-09 18:04:42 -0700756 sp<VoiceVolumeData> data = new VoiceVolumeData();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700757 data->mVolume = volume;
758 command->mParam = data;
Eric Laurent0ede8922014-05-09 18:04:42 -0700759 command->mWaitStatus = true;
Steve Block3856b092011-10-20 11:56:00 +0100760 ALOGV("AudioCommandThread() adding set voice volume volume %f", volume);
Eric Laurent0ede8922014-05-09 18:04:42 -0700761 return sendCommand(command, delayMs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700762}
763
Eric Laurentbfb1b832013-01-07 09:53:42 -0800764void AudioPolicyService::AudioCommandThread::stopOutputCommand(audio_io_handle_t output,
765 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800766 audio_session_t session)
Eric Laurentbfb1b832013-01-07 09:53:42 -0800767{
Eric Laurent0ede8922014-05-09 18:04:42 -0700768 sp<AudioCommand> command = new AudioCommand();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800769 command->mCommand = STOP_OUTPUT;
Eric Laurent0ede8922014-05-09 18:04:42 -0700770 sp<StopOutputData> data = new StopOutputData();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800771 data->mIO = output;
772 data->mStream = stream;
773 data->mSession = session;
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100774 command->mParam = data;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800775 ALOGV("AudioCommandThread() adding stop output %d", output);
Eric Laurent0ede8922014-05-09 18:04:42 -0700776 sendCommand(command);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800777}
778
Eric Laurente83b55d2014-11-14 10:06:21 -0800779void AudioPolicyService::AudioCommandThread::releaseOutputCommand(audio_io_handle_t output,
780 audio_stream_type_t stream,
781 audio_session_t session)
Eric Laurentbfb1b832013-01-07 09:53:42 -0800782{
Eric Laurent0ede8922014-05-09 18:04:42 -0700783 sp<AudioCommand> command = new AudioCommand();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800784 command->mCommand = RELEASE_OUTPUT;
Eric Laurent0ede8922014-05-09 18:04:42 -0700785 sp<ReleaseOutputData> data = new ReleaseOutputData();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800786 data->mIO = output;
Eric Laurente83b55d2014-11-14 10:06:21 -0800787 data->mStream = stream;
788 data->mSession = session;
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100789 command->mParam = data;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800790 ALOGV("AudioCommandThread() adding release output %d", output);
Eric Laurent0ede8922014-05-09 18:04:42 -0700791 sendCommand(command);
792}
793
Eric Laurent951f4552014-05-20 10:48:17 -0700794status_t AudioPolicyService::AudioCommandThread::createAudioPatchCommand(
795 const struct audio_patch *patch,
796 audio_patch_handle_t *handle,
797 int delayMs)
798{
799 status_t status = NO_ERROR;
800
801 sp<AudioCommand> command = new AudioCommand();
802 command->mCommand = CREATE_AUDIO_PATCH;
803 CreateAudioPatchData *data = new CreateAudioPatchData();
804 data->mPatch = *patch;
805 data->mHandle = *handle;
806 command->mParam = data;
807 command->mWaitStatus = true;
808 ALOGV("AudioCommandThread() adding create patch delay %d", delayMs);
809 status = sendCommand(command, delayMs);
810 if (status == NO_ERROR) {
811 *handle = data->mHandle;
812 }
813 return status;
814}
815
816status_t AudioPolicyService::AudioCommandThread::releaseAudioPatchCommand(audio_patch_handle_t handle,
817 int delayMs)
818{
819 sp<AudioCommand> command = new AudioCommand();
820 command->mCommand = RELEASE_AUDIO_PATCH;
821 ReleaseAudioPatchData *data = new ReleaseAudioPatchData();
822 data->mHandle = handle;
823 command->mParam = data;
824 command->mWaitStatus = true;
825 ALOGV("AudioCommandThread() adding release patch delay %d", delayMs);
826 return sendCommand(command, delayMs);
827}
828
Eric Laurentb52c1522014-05-20 11:27:36 -0700829void AudioPolicyService::AudioCommandThread::updateAudioPortListCommand()
830{
831 sp<AudioCommand> command = new AudioCommand();
832 command->mCommand = UPDATE_AUDIOPORT_LIST;
833 ALOGV("AudioCommandThread() adding update audio port list");
834 sendCommand(command);
835}
836
837void AudioPolicyService::AudioCommandThread::updateAudioPatchListCommand()
838{
839 sp<AudioCommand>command = new AudioCommand();
840 command->mCommand = UPDATE_AUDIOPATCH_LIST;
841 ALOGV("AudioCommandThread() adding update audio patch list");
842 sendCommand(command);
843}
844
Eric Laurente1715a42014-05-20 11:30:42 -0700845status_t AudioPolicyService::AudioCommandThread::setAudioPortConfigCommand(
846 const struct audio_port_config *config, int delayMs)
847{
848 sp<AudioCommand> command = new AudioCommand();
849 command->mCommand = SET_AUDIOPORT_CONFIG;
850 SetAudioPortConfigData *data = new SetAudioPortConfigData();
851 data->mConfig = *config;
852 command->mParam = data;
853 command->mWaitStatus = true;
854 ALOGV("AudioCommandThread() adding set port config delay %d", delayMs);
855 return sendCommand(command, delayMs);
856}
857
Jean-Michel Trivide801052015-04-14 19:10:14 -0700858void AudioPolicyService::AudioCommandThread::dynamicPolicyMixStateUpdateCommand(
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700859 const String8& regId, int32_t state)
Jean-Michel Trivide801052015-04-14 19:10:14 -0700860{
861 sp<AudioCommand> command = new AudioCommand();
862 command->mCommand = DYN_POLICY_MIX_STATE_UPDATE;
863 DynPolicyMixStateUpdateData *data = new DynPolicyMixStateUpdateData();
864 data->mRegId = regId;
865 data->mState = state;
866 command->mParam = data;
867 ALOGV("AudioCommandThread() sending dynamic policy mix (id=%s) state update to %d",
868 regId.string(), state);
869 sendCommand(command);
870}
871
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800872void AudioPolicyService::AudioCommandThread::recordingConfigurationUpdateCommand(
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800873 int event, audio_session_t session, audio_source_t source,
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800874 const audio_config_base_t *clientConfig, const audio_config_base_t *deviceConfig,
875 audio_patch_handle_t patchHandle)
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800876{
877 sp<AudioCommand>command = new AudioCommand();
878 command->mCommand = RECORDING_CONFIGURATION_UPDATE;
879 RecordingConfigurationUpdateData *data = new RecordingConfigurationUpdateData();
880 data->mEvent = event;
881 data->mSession = session;
882 data->mSource = source;
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800883 data->mClientConfig = *clientConfig;
884 data->mDeviceConfig = *deviceConfig;
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800885 data->mPatchHandle = patchHandle;
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800886 command->mParam = data;
887 ALOGV("AudioCommandThread() adding recording configuration update event %d, source %d",
888 event, source);
889 sendCommand(command);
890}
891
Eric Laurent0ede8922014-05-09 18:04:42 -0700892status_t AudioPolicyService::AudioCommandThread::sendCommand(sp<AudioCommand>& command, int delayMs)
893{
894 {
895 Mutex::Autolock _l(mLock);
896 insertCommand_l(command, delayMs);
897 mWaitWorkCV.signal();
898 }
899 Mutex::Autolock _l(command->mLock);
900 while (command->mWaitStatus) {
901 nsecs_t timeOutNs = kAudioCommandTimeoutNs + milliseconds(delayMs);
902 if (command->mCond.waitRelative(command->mLock, timeOutNs) != NO_ERROR) {
903 command->mStatus = TIMED_OUT;
904 command->mWaitStatus = false;
905 }
906 }
907 return command->mStatus;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800908}
909
Mathias Agopian65ab4712010-07-14 17:59:35 -0700910// insertCommand_l() must be called with mLock held
Eric Laurent0ede8922014-05-09 18:04:42 -0700911void AudioPolicyService::AudioCommandThread::insertCommand_l(sp<AudioCommand>& command, int delayMs)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700912{
Glenn Kasten8d6a2442012-02-08 14:04:28 -0800913 ssize_t i; // not size_t because i will count down to -1
Eric Laurent0ede8922014-05-09 18:04:42 -0700914 Vector < sp<AudioCommand> > removedCommands;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700915 command->mTime = systemTime() + milliseconds(delayMs);
916
917 // acquire wake lock to make sure delayed commands are processed
Eric Laurentbfb1b832013-01-07 09:53:42 -0800918 if (mAudioCommands.isEmpty()) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700919 acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string());
920 }
921
922 // check same pending commands with later time stamps and eliminate them
923 for (i = mAudioCommands.size()-1; i >= 0; i--) {
Eric Laurent0ede8922014-05-09 18:04:42 -0700924 sp<AudioCommand> command2 = mAudioCommands[i];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700925 // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands
926 if (command2->mTime <= command->mTime) break;
Eric Laurente45b48a2014-09-04 16:40:57 -0700927
928 // create audio patch or release audio patch commands are equivalent
929 // with regard to filtering
930 if ((command->mCommand == CREATE_AUDIO_PATCH) ||
931 (command->mCommand == RELEASE_AUDIO_PATCH)) {
932 if ((command2->mCommand != CREATE_AUDIO_PATCH) &&
933 (command2->mCommand != RELEASE_AUDIO_PATCH)) {
934 continue;
935 }
936 } else if (command2->mCommand != command->mCommand) continue;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700937
938 switch (command->mCommand) {
939 case SET_PARAMETERS: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700940 ParametersData *data = (ParametersData *)command->mParam.get();
941 ParametersData *data2 = (ParametersData *)command2->mParam.get();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700942 if (data->mIO != data2->mIO) break;
Steve Block3856b092011-10-20 11:56:00 +0100943 ALOGV("Comparing parameter command %s to new command %s",
Eric Laurentde070132010-07-13 04:45:46 -0700944 data2->mKeyValuePairs.string(), data->mKeyValuePairs.string());
Mathias Agopian65ab4712010-07-14 17:59:35 -0700945 AudioParameter param = AudioParameter(data->mKeyValuePairs);
946 AudioParameter param2 = AudioParameter(data2->mKeyValuePairs);
947 for (size_t j = 0; j < param.size(); j++) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700948 String8 key;
949 String8 value;
950 param.getAt(j, key, value);
951 for (size_t k = 0; k < param2.size(); k++) {
952 String8 key2;
953 String8 value2;
954 param2.getAt(k, key2, value2);
955 if (key2 == key) {
956 param2.remove(key2);
957 ALOGV("Filtering out parameter %s", key2.string());
958 break;
959 }
960 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700961 }
962 // if all keys have been filtered out, remove the command.
963 // otherwise, update the key value pairs
964 if (param2.size() == 0) {
965 removedCommands.add(command2);
966 } else {
967 data2->mKeyValuePairs = param2.toString();
968 }
Eric Laurent21e54562013-09-23 12:08:05 -0700969 command->mTime = command2->mTime;
970 // force delayMs to non 0 so that code below does not request to wait for
971 // command status as the command is now delayed
972 delayMs = 1;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700973 } break;
974
975 case SET_VOLUME: {
Eric Laurent0ede8922014-05-09 18:04:42 -0700976 VolumeData *data = (VolumeData *)command->mParam.get();
977 VolumeData *data2 = (VolumeData *)command2->mParam.get();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700978 if (data->mIO != data2->mIO) break;
979 if (data->mStream != data2->mStream) break;
Steve Block3856b092011-10-20 11:56:00 +0100980 ALOGV("Filtering out volume command on output %d for stream %d",
Eric Laurentde070132010-07-13 04:45:46 -0700981 data->mIO, data->mStream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700982 removedCommands.add(command2);
Eric Laurent21e54562013-09-23 12:08:05 -0700983 command->mTime = command2->mTime;
984 // force delayMs to non 0 so that code below does not request to wait for
985 // command status as the command is now delayed
986 delayMs = 1;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700987 } break;
Eric Laurente45b48a2014-09-04 16:40:57 -0700988
Eric Laurentbaf35fe2016-07-27 15:36:53 -0700989 case SET_VOICE_VOLUME: {
990 VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get();
991 VoiceVolumeData *data2 = (VoiceVolumeData *)command2->mParam.get();
992 ALOGV("Filtering out voice volume command value %f replaced by %f",
993 data2->mVolume, data->mVolume);
994 removedCommands.add(command2);
995 command->mTime = command2->mTime;
996 // force delayMs to non 0 so that code below does not request to wait for
997 // command status as the command is now delayed
998 delayMs = 1;
999 } break;
1000
Eric Laurente45b48a2014-09-04 16:40:57 -07001001 case CREATE_AUDIO_PATCH:
1002 case RELEASE_AUDIO_PATCH: {
1003 audio_patch_handle_t handle;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001004 struct audio_patch patch;
Eric Laurente45b48a2014-09-04 16:40:57 -07001005 if (command->mCommand == CREATE_AUDIO_PATCH) {
1006 handle = ((CreateAudioPatchData *)command->mParam.get())->mHandle;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001007 patch = ((CreateAudioPatchData *)command->mParam.get())->mPatch;
Eric Laurente45b48a2014-09-04 16:40:57 -07001008 } else {
1009 handle = ((ReleaseAudioPatchData *)command->mParam.get())->mHandle;
1010 }
1011 audio_patch_handle_t handle2;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001012 struct audio_patch patch2;
Eric Laurente45b48a2014-09-04 16:40:57 -07001013 if (command2->mCommand == CREATE_AUDIO_PATCH) {
1014 handle2 = ((CreateAudioPatchData *)command2->mParam.get())->mHandle;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001015 patch2 = ((CreateAudioPatchData *)command2->mParam.get())->mPatch;
Eric Laurente45b48a2014-09-04 16:40:57 -07001016 } else {
1017 handle2 = ((ReleaseAudioPatchData *)command2->mParam.get())->mHandle;
Glenn Kastenf60b6b62015-07-06 10:53:26 -07001018 memset(&patch2, 0, sizeof(patch2));
Eric Laurente45b48a2014-09-04 16:40:57 -07001019 }
1020 if (handle != handle2) break;
Haynes Mathew Georgea2d4a6d2014-10-13 13:05:22 -07001021 /* Filter CREATE_AUDIO_PATCH commands only when they are issued for
1022 same output. */
1023 if( (command->mCommand == CREATE_AUDIO_PATCH) &&
1024 (command2->mCommand == CREATE_AUDIO_PATCH) ) {
1025 bool isOutputDiff = false;
1026 if (patch.num_sources == patch2.num_sources) {
1027 for (unsigned count = 0; count < patch.num_sources; count++) {
1028 if (patch.sources[count].id != patch2.sources[count].id) {
1029 isOutputDiff = true;
1030 break;
1031 }
1032 }
1033 if (isOutputDiff)
1034 break;
1035 }
1036 }
Eric Laurente45b48a2014-09-04 16:40:57 -07001037 ALOGV("Filtering out %s audio patch command for handle %d",
1038 (command->mCommand == CREATE_AUDIO_PATCH) ? "create" : "release", handle);
1039 removedCommands.add(command2);
1040 command->mTime = command2->mTime;
1041 // force delayMs to non 0 so that code below does not request to wait for
1042 // command status as the command is now delayed
1043 delayMs = 1;
1044 } break;
1045
Jean-Michel Trivide801052015-04-14 19:10:14 -07001046 case DYN_POLICY_MIX_STATE_UPDATE: {
1047
1048 } break;
1049
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -08001050 case RECORDING_CONFIGURATION_UPDATE: {
1051
1052 } break;
1053
Mathias Agopian65ab4712010-07-14 17:59:35 -07001054 case START_TONE:
1055 case STOP_TONE:
1056 default:
1057 break;
1058 }
1059 }
1060
1061 // remove filtered commands
1062 for (size_t j = 0; j < removedCommands.size(); j++) {
1063 // removed commands always have time stamps greater than current command
1064 for (size_t k = i + 1; k < mAudioCommands.size(); k++) {
Eric Laurent0ede8922014-05-09 18:04:42 -07001065 if (mAudioCommands[k].get() == removedCommands[j].get()) {
Steve Block3856b092011-10-20 11:56:00 +01001066 ALOGV("suppressing command: %d", mAudioCommands[k]->mCommand);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001067 mAudioCommands.removeAt(k);
1068 break;
1069 }
1070 }
1071 }
1072 removedCommands.clear();
1073
Eric Laurentaa79bef2015-01-15 14:33:51 -08001074 // Disable wait for status if delay is not 0.
1075 // Except for create audio patch command because the returned patch handle
1076 // is needed by audio policy manager
1077 if (delayMs != 0 && command->mCommand != CREATE_AUDIO_PATCH) {
Eric Laurentcec4abb2012-07-03 12:23:02 -07001078 command->mWaitStatus = false;
1079 }
Eric Laurentcec4abb2012-07-03 12:23:02 -07001080
Mathias Agopian65ab4712010-07-14 17:59:35 -07001081 // insert command at the right place according to its time stamp
Eric Laurent1e693b52014-07-09 15:03:28 -07001082 ALOGV("inserting command: %d at index %zd, num commands %zu",
1083 command->mCommand, i+1, mAudioCommands.size());
Mathias Agopian65ab4712010-07-14 17:59:35 -07001084 mAudioCommands.insertAt(command, i + 1);
1085}
1086
1087void AudioPolicyService::AudioCommandThread::exit()
1088{
Steve Block3856b092011-10-20 11:56:00 +01001089 ALOGV("AudioCommandThread::exit");
Mathias Agopian65ab4712010-07-14 17:59:35 -07001090 {
1091 AutoMutex _l(mLock);
1092 requestExit();
1093 mWaitWorkCV.signal();
1094 }
Zach Janga754b4f2015-10-27 01:29:34 +00001095 // Note that we can call it from the thread loop if all other references have been released
1096 // but it will safely return WOULD_BLOCK in this case
Mathias Agopian65ab4712010-07-14 17:59:35 -07001097 requestExitAndWait();
1098}
1099
1100void AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size)
1101{
1102 snprintf(buffer, size, " %02d %06d.%03d %01u %p\n",
1103 mCommand,
1104 (int)ns2s(mTime),
1105 (int)ns2ms(mTime)%1000,
1106 mWaitStatus,
Eric Laurent0ede8922014-05-09 18:04:42 -07001107 mParam.get());
Mathias Agopian65ab4712010-07-14 17:59:35 -07001108}
1109
Dima Zavinfce7a472011-04-19 22:30:36 -07001110/******* helpers for the service_ops callbacks defined below *********/
1111void AudioPolicyService::setParameters(audio_io_handle_t ioHandle,
1112 const char *keyValuePairs,
1113 int delayMs)
1114{
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001115 mAudioCommandThread->parametersCommand(ioHandle, keyValuePairs,
Dima Zavinfce7a472011-04-19 22:30:36 -07001116 delayMs);
1117}
1118
1119int AudioPolicyService::setStreamVolume(audio_stream_type_t stream,
1120 float volume,
1121 audio_io_handle_t output,
1122 int delayMs)
1123{
Glenn Kastenfff6d712012-01-12 16:38:12 -08001124 return (int)mAudioCommandThread->volumeCommand(stream, volume,
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001125 output, delayMs);
Dima Zavinfce7a472011-04-19 22:30:36 -07001126}
1127
1128int AudioPolicyService::startTone(audio_policy_tone_t tone,
1129 audio_stream_type_t stream)
1130{
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001131 if (tone != AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION) {
Steve Block29357bc2012-01-06 19:20:56 +00001132 ALOGE("startTone: illegal tone requested (%d)", tone);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001133 }
1134 if (stream != AUDIO_STREAM_VOICE_CALL) {
Steve Block29357bc2012-01-06 19:20:56 +00001135 ALOGE("startTone: illegal stream (%d) requested for tone %d", stream,
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001136 tone);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001137 }
Dima Zavinfce7a472011-04-19 22:30:36 -07001138 mTonePlaybackThread->startToneCommand(ToneGenerator::TONE_SUP_CALL_WAITING,
1139 AUDIO_STREAM_VOICE_CALL);
1140 return 0;
1141}
1142
1143int AudioPolicyService::stopTone()
1144{
1145 mTonePlaybackThread->stopToneCommand();
1146 return 0;
1147}
1148
1149int AudioPolicyService::setVoiceVolume(float volume, int delayMs)
1150{
1151 return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs);
1152}
1153
Dima Zavinfce7a472011-04-19 22:30:36 -07001154extern "C" {
Eric Laurent2d388ec2014-03-07 13:25:54 -08001155audio_module_handle_t aps_load_hw_module(void *service __unused,
1156 const char *name);
1157audio_io_handle_t aps_open_output(void *service __unused,
Eric Laurenta4c5a552012-03-29 10:12:40 -07001158 audio_devices_t *pDevices,
1159 uint32_t *pSamplingRate,
1160 audio_format_t *pFormat,
1161 audio_channel_mask_t *pChannelMask,
1162 uint32_t *pLatencyMs,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001163 audio_output_flags_t flags);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001164
Eric Laurent2d388ec2014-03-07 13:25:54 -08001165audio_io_handle_t aps_open_output_on_module(void *service __unused,
Eric Laurenta4c5a552012-03-29 10:12:40 -07001166 audio_module_handle_t module,
1167 audio_devices_t *pDevices,
1168 uint32_t *pSamplingRate,
1169 audio_format_t *pFormat,
1170 audio_channel_mask_t *pChannelMask,
1171 uint32_t *pLatencyMs,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +00001172 audio_output_flags_t flags,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001173 const audio_offload_info_t *offloadInfo);
1174audio_io_handle_t aps_open_dup_output(void *service __unused,
Dima Zavinfce7a472011-04-19 22:30:36 -07001175 audio_io_handle_t output1,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001176 audio_io_handle_t output2);
1177int aps_close_output(void *service __unused, audio_io_handle_t output);
1178int aps_suspend_output(void *service __unused, audio_io_handle_t output);
1179int aps_restore_output(void *service __unused, audio_io_handle_t output);
1180audio_io_handle_t aps_open_input(void *service __unused,
Eric Laurenta4c5a552012-03-29 10:12:40 -07001181 audio_devices_t *pDevices,
1182 uint32_t *pSamplingRate,
1183 audio_format_t *pFormat,
1184 audio_channel_mask_t *pChannelMask,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001185 audio_in_acoustics_t acoustics __unused);
1186audio_io_handle_t aps_open_input_on_module(void *service __unused,
Eric Laurenta4c5a552012-03-29 10:12:40 -07001187 audio_module_handle_t module,
1188 audio_devices_t *pDevices,
1189 uint32_t *pSamplingRate,
1190 audio_format_t *pFormat,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001191 audio_channel_mask_t *pChannelMask);
1192int aps_close_input(void *service __unused, audio_io_handle_t input);
1193int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream);
Glenn Kastend848eb42016-03-08 13:42:11 -08001194int aps_move_effects(void *service __unused, audio_session_t session,
Dima Zavinfce7a472011-04-19 22:30:36 -07001195 audio_io_handle_t src_output,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001196 audio_io_handle_t dst_output);
1197char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle,
1198 const char *keys);
1199void aps_set_parameters(void *service, audio_io_handle_t io_handle,
1200 const char *kv_pairs, int delay_ms);
1201int aps_set_stream_volume(void *service, audio_stream_type_t stream,
Dima Zavinfce7a472011-04-19 22:30:36 -07001202 float volume, audio_io_handle_t output,
Eric Laurent2d388ec2014-03-07 13:25:54 -08001203 int delay_ms);
1204int aps_start_tone(void *service, audio_policy_tone_t tone,
1205 audio_stream_type_t stream);
1206int aps_stop_tone(void *service);
1207int aps_set_voice_volume(void *service, float volume, int delay_ms);
1208};
Dima Zavinfce7a472011-04-19 22:30:36 -07001209
Glenn Kastenfcddb0b2016-07-08 17:19:25 -07001210#ifdef USE_LEGACY_AUDIO_POLICY
Dima Zavinfce7a472011-04-19 22:30:36 -07001211namespace {
1212 struct audio_policy_service_ops aps_ops = {
Glenn Kasten01d3acb2014-02-06 08:24:07 -08001213 .open_output = aps_open_output,
1214 .open_duplicate_output = aps_open_dup_output,
1215 .close_output = aps_close_output,
1216 .suspend_output = aps_suspend_output,
1217 .restore_output = aps_restore_output,
1218 .open_input = aps_open_input,
1219 .close_input = aps_close_input,
1220 .set_stream_volume = aps_set_stream_volume,
Glenn Kastend2304db2014-02-03 07:40:31 -08001221 .invalidate_stream = aps_invalidate_stream,
Glenn Kasten01d3acb2014-02-06 08:24:07 -08001222 .set_parameters = aps_set_parameters,
1223 .get_parameters = aps_get_parameters,
1224 .start_tone = aps_start_tone,
1225 .stop_tone = aps_stop_tone,
1226 .set_voice_volume = aps_set_voice_volume,
1227 .move_effects = aps_move_effects,
1228 .load_hw_module = aps_load_hw_module,
1229 .open_output_on_module = aps_open_output_on_module,
1230 .open_input_on_module = aps_open_input_on_module,
Dima Zavinfce7a472011-04-19 22:30:36 -07001231 };
1232}; // namespace <unnamed>
Glenn Kastenfcddb0b2016-07-08 17:19:25 -07001233#endif
Dima Zavinfce7a472011-04-19 22:30:36 -07001234
Mathias Agopian65ab4712010-07-14 17:59:35 -07001235}; // namespace android