blob: 2124f85b67dc59dfae45fab1ec678de7dcbd7ef9 [file] [log] [blame]
Glenn Kasten99e53b82012-01-19 08:59:58 -08001/*
Mathias Agopian65ab4712010-07-14 17:59:35 -07002**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18
19#define LOG_TAG "AudioFlinger"
20//#define LOG_NDEBUG 0
21
Glenn Kasten153b9fe2013-07-15 11:23:36 -070022#include "Configuration.h"
Glenn Kastenda6ef132013-01-10 12:31:01 -080023#include <dirent.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070024#include <math.h>
25#include <signal.h>
26#include <sys/time.h>
27#include <sys/resource.h>
28
Gloria Wang9ee159b2011-02-24 14:51:45 -080029#include <binder/IPCThreadState.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070030#include <binder/IServiceManager.h>
31#include <utils/Log.h>
Glenn Kastend8e6fd32012-05-07 11:07:57 -070032#include <utils/Trace.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070033#include <binder/Parcel.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070034#include <utils/String16.h>
35#include <utils/threads.h>
Eric Laurent38ccae22011-03-28 18:37:07 -070036#include <utils/Atomic.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070037
Dima Zavinfce7a472011-04-19 22:30:36 -070038#include <cutils/bitops.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070039#include <cutils/properties.h>
40
Dima Zavin64760242011-05-11 14:15:23 -070041#include <system/audio.h>
Dima Zavin7394a4f2011-06-13 18:16:26 -070042#include <hardware/audio.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070043
44#include "AudioMixer.h"
45#include "AudioFlinger.h"
Glenn Kasten44deb052012-02-05 18:09:08 -080046#include "ServiceUtilities.h"
Mathias Agopian65ab4712010-07-14 17:59:35 -070047
Mathias Agopian65ab4712010-07-14 17:59:35 -070048#include <media/EffectsFactoryApi.h>
Eric Laurent6d8b6942011-06-24 07:01:31 -070049#include <audio_effects/effect_visualizer.h>
Eric Laurent59bd0da2011-08-01 09:52:20 -070050#include <audio_effects/effect_ns.h>
51#include <audio_effects/effect_aec.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070052
Glenn Kasten3b21c502011-12-15 09:52:39 -080053#include <audio_utils/primitives.h>
54
Eric Laurentfeb0db62011-07-22 09:04:31 -070055#include <powermanager/PowerManager.h>
Glenn Kasten190a46f2012-03-06 11:27:10 -080056
John Grossman4ff14ba2012-02-08 16:37:41 -080057#include <common_time/cc_helper.h>
Glenn Kasten58912562012-04-03 10:45:00 -070058
Glenn Kasten9e58b552013-01-18 15:09:48 -080059#include <media/IMediaLogService.h>
60
Glenn Kastenda6ef132013-01-10 12:31:01 -080061#include <media/nbaio/Pipe.h>
62#include <media/nbaio/PipeReader.h>
Glenn Kasten1ab85ec2013-05-31 09:18:43 -070063#include <media/AudioParameter.h>
Glenn Kasten4182c4e2013-07-15 14:45:07 -070064#include <private/android_filesystem_config.h>
Glenn Kastenda6ef132013-01-10 12:31:01 -080065
Mathias Agopian65ab4712010-07-14 17:59:35 -070066// ----------------------------------------------------------------------------
Mathias Agopian65ab4712010-07-14 17:59:35 -070067
John Grossman1c345192012-03-27 14:00:17 -070068// Note: the following macro is used for extremely verbose logging message. In
69// order to run with ALOG_ASSERT turned on, we need to have LOG_NDEBUG set to
70// 0; but one side effect of this is to turn all LOGV's as well. Some messages
71// are so verbose that we want to suppress them even when we have ALOG_ASSERT
72// turned on. Do not uncomment the #def below unless you really know what you
73// are doing and want to see all of the extremely verbose messages.
74//#define VERY_VERY_VERBOSE_LOGGING
75#ifdef VERY_VERY_VERBOSE_LOGGING
76#define ALOGVV ALOGV
77#else
78#define ALOGVV(a...) do { } while(0)
79#endif
Eric Laurentde070132010-07-13 04:45:46 -070080
Mathias Agopian65ab4712010-07-14 17:59:35 -070081namespace android {
82
Glenn Kastenec1d6b52011-12-12 09:04:45 -080083static const char kDeadlockedString[] = "AudioFlinger may be deadlocked\n";
84static const char kHardwareLockedString[] = "Hardware lock is taken\n";
Eric Laurent021cf962014-05-13 10:18:14 -070085static const char kClientLockedString[] = "Client lock is taken\n";
Mathias Agopian65ab4712010-07-14 17:59:35 -070086
Glenn Kasten58912562012-04-03 10:45:00 -070087
John Grossman4ff14ba2012-02-08 16:37:41 -080088nsecs_t AudioFlinger::mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs;
Eric Laurent7cafbb32011-11-22 18:50:29 -080089
Eric Laurent81784c32012-11-19 14:55:58 -080090uint32_t AudioFlinger::mScreenState;
Glenn Kasten3ed29202012-08-07 15:24:44 -070091
Glenn Kasten46909e72013-02-26 09:20:22 -080092#ifdef TEE_SINK
Glenn Kastenda6ef132013-01-10 12:31:01 -080093bool AudioFlinger::mTeeSinkInputEnabled = false;
94bool AudioFlinger::mTeeSinkOutputEnabled = false;
95bool AudioFlinger::mTeeSinkTrackEnabled = false;
96
97size_t AudioFlinger::mTeeSinkInputFrames = kTeeSinkInputFramesDefault;
98size_t AudioFlinger::mTeeSinkOutputFrames = kTeeSinkOutputFramesDefault;
99size_t AudioFlinger::mTeeSinkTrackFrames = kTeeSinkTrackFramesDefault;
Glenn Kasten46909e72013-02-26 09:20:22 -0800100#endif
Glenn Kastenda6ef132013-01-10 12:31:01 -0800101
Eric Laurent813e2a72013-08-31 12:59:48 -0700102// In order to avoid invalidating offloaded tracks each time a Visualizer is turned on and off
103// we define a minimum time during which a global effect is considered enabled.
104static const nsecs_t kMinGlobalEffectEnabletimeNs = seconds(7200);
105
Mathias Agopian65ab4712010-07-14 17:59:35 -0700106// ----------------------------------------------------------------------------
107
Marco Nelissenb2208842014-02-07 14:00:50 -0800108const char *formatToString(audio_format_t format) {
109 switch(format) {
110 case AUDIO_FORMAT_PCM_SUB_8_BIT: return "pcm8";
111 case AUDIO_FORMAT_PCM_SUB_16_BIT: return "pcm16";
112 case AUDIO_FORMAT_PCM_SUB_32_BIT: return "pcm32";
113 case AUDIO_FORMAT_PCM_SUB_8_24_BIT: return "pcm8.24";
114 case AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED: return "pcm24";
115 case AUDIO_FORMAT_PCM_SUB_FLOAT: return "pcmfloat";
116 case AUDIO_FORMAT_MP3: return "mp3";
117 case AUDIO_FORMAT_AMR_NB: return "amr-nb";
118 case AUDIO_FORMAT_AMR_WB: return "amr-wb";
119 case AUDIO_FORMAT_AAC: return "aac";
120 case AUDIO_FORMAT_HE_AAC_V1: return "he-aac-v1";
121 case AUDIO_FORMAT_HE_AAC_V2: return "he-aac-v2";
122 case AUDIO_FORMAT_VORBIS: return "vorbis";
123 default:
124 break;
125 }
126 return "unknown";
127}
128
Eric Laurentf7ffb8b2012-04-14 09:06:57 -0700129static int load_audio_interface(const char *if_name, audio_hw_device_t **dev)
Dima Zavin799a70e2011-04-18 16:57:27 -0700130{
Eric Laurentf7ffb8b2012-04-14 09:06:57 -0700131 const hw_module_t *mod;
Dima Zavin799a70e2011-04-18 16:57:27 -0700132 int rc;
133
Eric Laurentf7ffb8b2012-04-14 09:06:57 -0700134 rc = hw_get_module_by_class(AUDIO_HARDWARE_MODULE_ID, if_name, &mod);
135 ALOGE_IF(rc, "%s couldn't load audio hw module %s.%s (%s)", __func__,
136 AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc));
137 if (rc) {
Dima Zavin799a70e2011-04-18 16:57:27 -0700138 goto out;
Eric Laurentf7ffb8b2012-04-14 09:06:57 -0700139 }
140 rc = audio_hw_device_open(mod, dev);
141 ALOGE_IF(rc, "%s couldn't open audio hw device in %s.%s (%s)", __func__,
142 AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc));
143 if (rc) {
Dima Zavin799a70e2011-04-18 16:57:27 -0700144 goto out;
Eric Laurentf7ffb8b2012-04-14 09:06:57 -0700145 }
Eric Laurent5806b352014-05-22 12:23:26 -0700146 if ((*dev)->common.version < AUDIO_DEVICE_API_VERSION_MIN) {
Eric Laurentf7ffb8b2012-04-14 09:06:57 -0700147 ALOGE("%s wrong audio hw device version %04x", __func__, (*dev)->common.version);
148 rc = BAD_VALUE;
149 goto out;
150 }
Dima Zavin799a70e2011-04-18 16:57:27 -0700151 return 0;
152
153out:
Dima Zavin799a70e2011-04-18 16:57:27 -0700154 *dev = NULL;
155 return rc;
156}
157
Mathias Agopian65ab4712010-07-14 17:59:35 -0700158// ----------------------------------------------------------------------------
159
160AudioFlinger::AudioFlinger()
161 : BnAudioFlinger(),
John Grossman4ff14ba2012-02-08 16:37:41 -0800162 mPrimaryHardwareDev(NULL),
Glenn Kasten9ea65d02014-01-17 10:21:24 -0800163 mAudioHwDevs(NULL),
Glenn Kasten7d6c35b2012-07-02 12:45:10 -0700164 mHardwareStatus(AUDIO_HW_IDLE),
John Grossman4ff14ba2012-02-08 16:37:41 -0800165 mMasterVolume(1.0f),
John Grossman4ff14ba2012-02-08 16:37:41 -0800166 mMasterMute(false),
167 mNextUniqueId(1),
168 mMode(AUDIO_MODE_INVALID),
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700169 mBtNrecIsOff(false),
170 mIsLowRamDevice(true),
Eric Laurent813e2a72013-08-31 12:59:48 -0700171 mIsDeviceTypeKnown(false),
Glenn Kasten4ea00a22014-06-02 08:29:22 -0700172 mGlobalEffectEnableTime(0),
173 mPrimaryOutputSampleRate(0)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700174{
Glenn Kasten949a9262013-04-16 12:35:20 -0700175 getpid_cached = getpid();
Glenn Kasten9e58b552013-01-18 15:09:48 -0800176 char value[PROPERTY_VALUE_MAX];
177 bool doLog = (property_get("ro.test_harness", value, "0") > 0) && (atoi(value) == 1);
178 if (doLog) {
Glenn Kastencf515ab2014-03-14 16:01:58 -0700179 mLogMemoryDealer = new MemoryDealer(kLogMemorySize, "LogWriters", MemoryHeapBase::READ_ONLY);
Glenn Kasten9e58b552013-01-18 15:09:48 -0800180 }
Eric Laurent1c333e22014-05-20 10:48:17 -0700181
Glenn Kasten46909e72013-02-26 09:20:22 -0800182#ifdef TEE_SINK
Glenn Kastenda6ef132013-01-10 12:31:01 -0800183 (void) property_get("ro.debuggable", value, "0");
184 int debuggable = atoi(value);
185 int teeEnabled = 0;
186 if (debuggable) {
187 (void) property_get("af.tee", value, "0");
188 teeEnabled = atoi(value);
189 }
Glenn Kastenf66b4222014-02-20 10:23:28 -0800190 // FIXME symbolic constants here
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700191 if (teeEnabled & 1) {
Glenn Kastenda6ef132013-01-10 12:31:01 -0800192 mTeeSinkInputEnabled = true;
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700193 }
194 if (teeEnabled & 2) {
Glenn Kastenda6ef132013-01-10 12:31:01 -0800195 mTeeSinkOutputEnabled = true;
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700196 }
197 if (teeEnabled & 4) {
Glenn Kastenda6ef132013-01-10 12:31:01 -0800198 mTeeSinkTrackEnabled = true;
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700199 }
Glenn Kasten46909e72013-02-26 09:20:22 -0800200#endif
Dima Zavin5a61d2f2011-04-19 19:04:32 -0700201}
202
203void AudioFlinger::onFirstRef()
204{
Dima Zavin799a70e2011-04-18 16:57:27 -0700205 int rc = 0;
Dima Zavinfce7a472011-04-19 22:30:36 -0700206
Eric Laurent93575202011-01-18 18:39:02 -0800207 Mutex::Autolock _l(mLock);
208
Dima Zavin799a70e2011-04-18 16:57:27 -0700209 /* TODO: move all this work into an Init() function */
John Grossman4ff14ba2012-02-08 16:37:41 -0800210 char val_str[PROPERTY_VALUE_MAX] = { 0 };
211 if (property_get("ro.audio.flinger_standbytime_ms", val_str, NULL) >= 0) {
212 uint32_t int_val;
213 if (1 == sscanf(val_str, "%u", &int_val)) {
214 mStandbyTimeInNsecs = milliseconds(int_val);
215 ALOGI("Using %u mSec as standby time.", int_val);
216 } else {
217 mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs;
218 ALOGI("Using default %u mSec as standby time.",
219 (uint32_t)(mStandbyTimeInNsecs / 1000000));
220 }
221 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700222
Eric Laurent1c333e22014-05-20 10:48:17 -0700223 mPatchPanel = new PatchPanel(this);
224
Eric Laurenta4c5a552012-03-29 10:12:40 -0700225 mMode = AUDIO_MODE_NORMAL;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700226}
227
228AudioFlinger::~AudioFlinger()
229{
230 while (!mRecordThreads.isEmpty()) {
Glenn Kastenc3ae93f2012-07-30 10:59:30 -0700231 // closeInput_nonvirtual() will remove specified entry from mRecordThreads
Glenn Kastend96c5722012-04-25 13:44:49 -0700232 closeInput_nonvirtual(mRecordThreads.keyAt(0));
Mathias Agopian65ab4712010-07-14 17:59:35 -0700233 }
234 while (!mPlaybackThreads.isEmpty()) {
Glenn Kastenc3ae93f2012-07-30 10:59:30 -0700235 // closeOutput_nonvirtual() will remove specified entry from mPlaybackThreads
Glenn Kastend96c5722012-04-25 13:44:49 -0700236 closeOutput_nonvirtual(mPlaybackThreads.keyAt(0));
Mathias Agopian65ab4712010-07-14 17:59:35 -0700237 }
Dima Zavin799a70e2011-04-18 16:57:27 -0700238
Glenn Kasten2b213bc2012-02-02 14:05:20 -0800239 for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
240 // no mHardwareLock needed, as there are no other references to this
Eric Laurenta4c5a552012-03-29 10:12:40 -0700241 audio_hw_device_close(mAudioHwDevs.valueAt(i)->hwDevice());
242 delete mAudioHwDevs.valueAt(i);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700243 }
Glenn Kasten481fb672013-09-30 14:39:28 -0700244
245 // Tell media.log service about any old writers that still need to be unregistered
246 sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log"));
247 if (binder != 0) {
248 sp<IMediaLogService> mediaLogService(interface_cast<IMediaLogService>(binder));
249 for (size_t count = mUnregisteredWriters.size(); count > 0; count--) {
250 sp<IMemory> iMemory(mUnregisteredWriters.top()->getIMemory());
251 mUnregisteredWriters.pop();
252 mediaLogService->unregisterWriter(iMemory);
253 }
254 }
255
Mathias Agopian65ab4712010-07-14 17:59:35 -0700256}
257
Eric Laurenta4c5a552012-03-29 10:12:40 -0700258static const char * const audio_interfaces[] = {
259 AUDIO_HARDWARE_MODULE_ID_PRIMARY,
260 AUDIO_HARDWARE_MODULE_ID_A2DP,
261 AUDIO_HARDWARE_MODULE_ID_USB,
262};
263#define ARRAY_SIZE(x) (sizeof((x))/sizeof(((x)[0])))
264
John Grossmanee578c02012-07-23 17:05:46 -0700265AudioFlinger::AudioHwDevice* AudioFlinger::findSuitableHwDev_l(
266 audio_module_handle_t module,
267 audio_devices_t devices)
Dima Zavin799a70e2011-04-18 16:57:27 -0700268{
Eric Laurenta4c5a552012-03-29 10:12:40 -0700269 // if module is 0, the request comes from an old policy manager and we should load
270 // well known modules
271 if (module == 0) {
272 ALOGW("findSuitableHwDev_l() loading well know audio hw modules");
273 for (size_t i = 0; i < ARRAY_SIZE(audio_interfaces); i++) {
274 loadHwModule_l(audio_interfaces[i]);
275 }
Eric Laurentf1c04f92012-08-28 14:26:53 -0700276 // then try to find a module supporting the requested device.
277 for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
278 AudioHwDevice *audioHwDevice = mAudioHwDevs.valueAt(i);
279 audio_hw_device_t *dev = audioHwDevice->hwDevice();
280 if ((dev->get_supported_devices != NULL) &&
281 (dev->get_supported_devices(dev) & devices) == devices)
282 return audioHwDevice;
283 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700284 } else {
285 // check a match for the requested module handle
John Grossmanee578c02012-07-23 17:05:46 -0700286 AudioHwDevice *audioHwDevice = mAudioHwDevs.valueFor(module);
287 if (audioHwDevice != NULL) {
288 return audioHwDevice;
Eric Laurenta4c5a552012-03-29 10:12:40 -0700289 }
290 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700291
Dima Zavin799a70e2011-04-18 16:57:27 -0700292 return NULL;
293}
Mathias Agopian65ab4712010-07-14 17:59:35 -0700294
Glenn Kasten0f11b512014-01-31 16:18:54 -0800295void AudioFlinger::dumpClients(int fd, const Vector<String16>& args __unused)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700296{
297 const size_t SIZE = 256;
298 char buffer[SIZE];
299 String8 result;
300
301 result.append("Clients:\n");
302 for (size_t i = 0; i < mClients.size(); ++i) {
Glenn Kasten77c11192012-01-25 14:27:41 -0800303 sp<Client> client = mClients.valueAt(i).promote();
304 if (client != 0) {
305 snprintf(buffer, SIZE, " pid: %d\n", client->pid());
306 result.append(buffer);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700307 }
308 }
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700309
Eric Laurentd1b28d42013-09-18 18:47:13 -0700310 result.append("Notification Clients:\n");
311 for (size_t i = 0; i < mNotificationClients.size(); ++i) {
312 snprintf(buffer, SIZE, " pid: %d\n", mNotificationClients.keyAt(i));
313 result.append(buffer);
314 }
315
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700316 result.append("Global session refs:\n");
Marco Nelissenb2208842014-02-07 14:00:50 -0800317 result.append(" session pid count\n");
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700318 for (size_t i = 0; i < mAudioSessionRefs.size(); i++) {
319 AudioSessionRef *r = mAudioSessionRefs[i];
Marco Nelissenb2208842014-02-07 14:00:50 -0800320 snprintf(buffer, SIZE, " %7d %5d %5d\n", r->mSessionid, r->mPid, r->mCnt);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700321 result.append(buffer);
322 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700323 write(fd, result.string(), result.size());
Mathias Agopian65ab4712010-07-14 17:59:35 -0700324}
325
326
Glenn Kasten0f11b512014-01-31 16:18:54 -0800327void AudioFlinger::dumpInternals(int fd, const Vector<String16>& args __unused)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700328{
329 const size_t SIZE = 256;
330 char buffer[SIZE];
331 String8 result;
Glenn Kastena4454b42012-01-04 11:02:33 -0800332 hardware_call_state hardwareStatus = mHardwareStatus;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700333
John Grossman4ff14ba2012-02-08 16:37:41 -0800334 snprintf(buffer, SIZE, "Hardware status: %d\n"
335 "Standby Time mSec: %u\n",
336 hardwareStatus,
337 (uint32_t)(mStandbyTimeInNsecs / 1000000));
Mathias Agopian65ab4712010-07-14 17:59:35 -0700338 result.append(buffer);
339 write(fd, result.string(), result.size());
Mathias Agopian65ab4712010-07-14 17:59:35 -0700340}
341
Glenn Kasten0f11b512014-01-31 16:18:54 -0800342void AudioFlinger::dumpPermissionDenial(int fd, const Vector<String16>& args __unused)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700343{
344 const size_t SIZE = 256;
345 char buffer[SIZE];
346 String8 result;
347 snprintf(buffer, SIZE, "Permission Denial: "
348 "can't dump AudioFlinger from pid=%d, uid=%d\n",
349 IPCThreadState::self()->getCallingPid(),
350 IPCThreadState::self()->getCallingUid());
351 result.append(buffer);
352 write(fd, result.string(), result.size());
Mathias Agopian65ab4712010-07-14 17:59:35 -0700353}
354
Eric Laurent81784c32012-11-19 14:55:58 -0800355bool AudioFlinger::dumpTryLock(Mutex& mutex)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700356{
357 bool locked = false;
358 for (int i = 0; i < kDumpLockRetries; ++i) {
359 if (mutex.tryLock() == NO_ERROR) {
360 locked = true;
361 break;
362 }
Glenn Kasten7dede872011-12-13 11:04:14 -0800363 usleep(kDumpLockSleepUs);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700364 }
365 return locked;
366}
367
368status_t AudioFlinger::dump(int fd, const Vector<String16>& args)
369{
Glenn Kasten44deb052012-02-05 18:09:08 -0800370 if (!dumpAllowed()) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700371 dumpPermissionDenial(fd, args);
372 } else {
373 // get state of hardware lock
Eric Laurent81784c32012-11-19 14:55:58 -0800374 bool hardwareLocked = dumpTryLock(mHardwareLock);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700375 if (!hardwareLocked) {
376 String8 result(kHardwareLockedString);
377 write(fd, result.string(), result.size());
378 } else {
379 mHardwareLock.unlock();
380 }
381
Eric Laurent81784c32012-11-19 14:55:58 -0800382 bool locked = dumpTryLock(mLock);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700383
384 // failed to lock - AudioFlinger is probably deadlocked
385 if (!locked) {
386 String8 result(kDeadlockedString);
387 write(fd, result.string(), result.size());
388 }
389
Eric Laurent021cf962014-05-13 10:18:14 -0700390 bool clientLocked = dumpTryLock(mClientLock);
391 if (!clientLocked) {
392 String8 result(kClientLockedString);
393 write(fd, result.string(), result.size());
394 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700395 dumpClients(fd, args);
Eric Laurent021cf962014-05-13 10:18:14 -0700396 if (clientLocked) {
397 mClientLock.unlock();
398 }
399
Mathias Agopian65ab4712010-07-14 17:59:35 -0700400 dumpInternals(fd, args);
401
402 // dump playback threads
403 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
404 mPlaybackThreads.valueAt(i)->dump(fd, args);
405 }
406
407 // dump record threads
408 for (size_t i = 0; i < mRecordThreads.size(); i++) {
409 mRecordThreads.valueAt(i)->dump(fd, args);
410 }
411
Dima Zavin799a70e2011-04-18 16:57:27 -0700412 // dump all hardware devs
413 for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
Eric Laurenta4c5a552012-03-29 10:12:40 -0700414 audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice();
Dima Zavin799a70e2011-04-18 16:57:27 -0700415 dev->dump(dev, fd);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700416 }
Glenn Kastend06785b2012-09-30 12:29:28 -0700417
Glenn Kasten46909e72013-02-26 09:20:22 -0800418#ifdef TEE_SINK
Glenn Kastend06785b2012-09-30 12:29:28 -0700419 // dump the serially shared record tee sink
420 if (mRecordTeeSource != 0) {
421 dumpTee(fd, mRecordTeeSource);
422 }
Glenn Kasten46909e72013-02-26 09:20:22 -0800423#endif
Glenn Kastend06785b2012-09-30 12:29:28 -0700424
Glenn Kastend65d73c2012-06-22 17:21:07 -0700425 if (locked) {
426 mLock.unlock();
427 }
Glenn Kasten9e58b552013-01-18 15:09:48 -0800428
429 // append a copy of media.log here by forwarding fd to it, but don't attempt
430 // to lookup the service if it's not running, as it will block for a second
431 if (mLogMemoryDealer != 0) {
432 sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log"));
433 if (binder != 0) {
Elliott Hughes8b5f6422014-05-22 01:22:06 -0700434 dprintf(fd, "\nmedia.log:\n");
Glenn Kasten9e58b552013-01-18 15:09:48 -0800435 Vector<String16> args;
436 binder->dump(fd, args);
437 }
438 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700439 }
440 return NO_ERROR;
441}
442
Eric Laurent021cf962014-05-13 10:18:14 -0700443sp<AudioFlinger::Client> AudioFlinger::registerPid(pid_t pid)
Glenn Kasten98ec94c2012-01-25 14:28:29 -0800444{
Eric Laurent021cf962014-05-13 10:18:14 -0700445 Mutex::Autolock _cl(mClientLock);
Glenn Kasten98ec94c2012-01-25 14:28:29 -0800446 // If pid is already in the mClients wp<> map, then use that entry
447 // (for which promote() is always != 0), otherwise create a new entry and Client.
448 sp<Client> client = mClients.valueFor(pid).promote();
449 if (client == 0) {
450 client = new Client(this, pid);
451 mClients.add(pid, client);
452 }
453
454 return client;
455}
Mathias Agopian65ab4712010-07-14 17:59:35 -0700456
Glenn Kasten9e58b552013-01-18 15:09:48 -0800457sp<NBLog::Writer> AudioFlinger::newWriter_l(size_t size, const char *name)
458{
Glenn Kasten481fb672013-09-30 14:39:28 -0700459 // If there is no memory allocated for logs, return a dummy writer that does nothing
Glenn Kasten9e58b552013-01-18 15:09:48 -0800460 if (mLogMemoryDealer == 0) {
461 return new NBLog::Writer();
462 }
Glenn Kasten9e58b552013-01-18 15:09:48 -0800463 sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log"));
Glenn Kasten481fb672013-09-30 14:39:28 -0700464 // Similarly if we can't contact the media.log service, also return a dummy writer
465 if (binder == 0) {
466 return new NBLog::Writer();
Glenn Kasten9e58b552013-01-18 15:09:48 -0800467 }
Glenn Kasten481fb672013-09-30 14:39:28 -0700468 sp<IMediaLogService> mediaLogService(interface_cast<IMediaLogService>(binder));
469 sp<IMemory> shared = mLogMemoryDealer->allocate(NBLog::Timeline::sharedSize(size));
470 // If allocation fails, consult the vector of previously unregistered writers
471 // and garbage-collect one or more them until an allocation succeeds
472 if (shared == 0) {
473 Mutex::Autolock _l(mUnregisteredWritersLock);
474 for (size_t count = mUnregisteredWriters.size(); count > 0; count--) {
475 {
476 // Pick the oldest stale writer to garbage-collect
477 sp<IMemory> iMemory(mUnregisteredWriters[0]->getIMemory());
478 mUnregisteredWriters.removeAt(0);
479 mediaLogService->unregisterWriter(iMemory);
480 // Now the media.log remote reference to IMemory is gone. When our last local
481 // reference to IMemory also drops to zero at end of this block,
482 // the IMemory destructor will deallocate the region from mLogMemoryDealer.
483 }
484 // Re-attempt the allocation
485 shared = mLogMemoryDealer->allocate(NBLog::Timeline::sharedSize(size));
486 if (shared != 0) {
487 goto success;
488 }
489 }
490 // Even after garbage-collecting all old writers, there is still not enough memory,
491 // so return a dummy writer
492 return new NBLog::Writer();
493 }
494success:
495 mediaLogService->registerWriter(shared, size, name);
496 return new NBLog::Writer(size, shared);
Glenn Kasten9e58b552013-01-18 15:09:48 -0800497}
498
499void AudioFlinger::unregisterWriter(const sp<NBLog::Writer>& writer)
500{
Glenn Kasten685ef092013-02-04 08:15:34 -0800501 if (writer == 0) {
502 return;
503 }
Glenn Kasten9e58b552013-01-18 15:09:48 -0800504 sp<IMemory> iMemory(writer->getIMemory());
505 if (iMemory == 0) {
506 return;
507 }
Glenn Kasten481fb672013-09-30 14:39:28 -0700508 // Rather than removing the writer immediately, append it to a queue of old writers to
509 // be garbage-collected later. This allows us to continue to view old logs for a while.
510 Mutex::Autolock _l(mUnregisteredWritersLock);
511 mUnregisteredWriters.push(writer);
Glenn Kasten9e58b552013-01-18 15:09:48 -0800512}
513
Mathias Agopian65ab4712010-07-14 17:59:35 -0700514// IAudioFlinger interface
515
516
517sp<IAudioTrack> AudioFlinger::createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -0800518 audio_stream_type_t streamType,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700519 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800520 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700521 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800522 size_t *frameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -0800523 IAudioFlinger::track_flags_t *flags,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700524 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800525 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -0800526 pid_t tid,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700527 int *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800528 int clientUid,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700529 status_t *status)
530{
531 sp<PlaybackThread::Track> track;
532 sp<TrackHandle> trackHandle;
533 sp<Client> client;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700534 status_t lStatus;
535 int lSessionId;
536
Glenn Kasten263709e2012-01-06 08:40:01 -0800537 // client AudioTrack::set already implements AUDIO_STREAM_DEFAULT => AUDIO_STREAM_MUSIC,
538 // but if someone uses binder directly they could bypass that and cause us to crash
539 if (uint32_t(streamType) >= AUDIO_STREAM_CNT) {
Steve Block29357bc2012-01-06 19:20:56 +0000540 ALOGE("createTrack() invalid stream type %d", streamType);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700541 lStatus = BAD_VALUE;
542 goto Exit;
543 }
544
Glenn Kasten53b5d092014-02-05 10:00:23 -0800545 // further sample rate checks are performed by createTrack_l() depending on the thread type
546 if (sampleRate == 0) {
547 ALOGE("createTrack() invalid sample rate %u", sampleRate);
548 lStatus = BAD_VALUE;
549 goto Exit;
550 }
551
552 // further channel mask checks are performed by createTrack_l() depending on the thread type
553 if (!audio_is_output_channel(channelMask)) {
554 ALOGE("createTrack() invalid channel mask %#x", channelMask);
555 lStatus = BAD_VALUE;
556 goto Exit;
557 }
558
Glenn Kastenc4b88a82014-04-30 16:54:30 -0700559 // further format checks are performed by createTrack_l() depending on the thread type
560 if (!audio_is_valid_format(format)) {
Glenn Kastencac3daa2014-02-07 09:47:14 -0800561 ALOGE("createTrack() invalid format %#x", format);
Glenn Kasten60a83922012-06-21 12:56:37 -0700562 lStatus = BAD_VALUE;
563 goto Exit;
564 }
565
Glenn Kasten663c2242013-09-24 11:52:37 -0700566 if (sharedBuffer != 0 && sharedBuffer->pointer() == NULL) {
567 ALOGE("createTrack() sharedBuffer is non-0 but has NULL pointer()");
568 lStatus = BAD_VALUE;
569 goto Exit;
570 }
571
Mathias Agopian65ab4712010-07-14 17:59:35 -0700572 {
573 Mutex::Autolock _l(mLock);
574 PlaybackThread *thread = checkPlaybackThread_l(output);
575 if (thread == NULL) {
Glenn Kastenc9b2e202013-02-26 11:32:32 -0800576 ALOGE("no playback thread found for output handle %d", output);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700577 lStatus = BAD_VALUE;
578 goto Exit;
579 }
580
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800581 pid_t pid = IPCThreadState::self()->getCallingPid();
Eric Laurent021cf962014-05-13 10:18:14 -0700582 client = registerPid(pid);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700583
Glenn Kastene848bd92014-03-13 15:00:32 -0700584 PlaybackThread *effectThread = NULL;
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700585 if (sessionId != NULL && *sessionId != AUDIO_SESSION_ALLOCATE) {
Glenn Kasten570f6332014-03-13 15:01:06 -0700586 lSessionId = *sessionId;
Eric Laurentf436fdc2012-05-24 11:07:14 -0700587 // check if an effect chain with the same session ID is present on another
588 // output thread and move it here.
Eric Laurentde070132010-07-13 04:45:46 -0700589 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
Eric Laurent39e94f82010-07-28 01:32:47 -0700590 sp<PlaybackThread> t = mPlaybackThreads.valueAt(i);
591 if (mPlaybackThreads.keyAt(i) != output) {
Glenn Kasten570f6332014-03-13 15:01:06 -0700592 uint32_t sessions = t->hasAudioSession(lSessionId);
Eric Laurent39e94f82010-07-28 01:32:47 -0700593 if (sessions & PlaybackThread::EFFECT_SESSION) {
594 effectThread = t.get();
Eric Laurentf436fdc2012-05-24 11:07:14 -0700595 break;
Eric Laurent39e94f82010-07-28 01:32:47 -0700596 }
Eric Laurentde070132010-07-13 04:45:46 -0700597 }
598 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700599 } else {
Eric Laurentde070132010-07-13 04:45:46 -0700600 // if no audio session id is provided, create one here
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700601 lSessionId = nextUniqueId();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700602 if (sessionId != NULL) {
603 *sessionId = lSessionId;
604 }
605 }
Steve Block3856b092011-10-20 11:56:00 +0100606 ALOGV("createTrack() lSessionId: %d", lSessionId);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700607
608 track = thread->createTrack_l(client, streamType, sampleRate, format,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800609 channelMask, frameCount, sharedBuffer, lSessionId, flags, tid, clientUid, &lStatus);
Haynes Mathew George03e9e832013-12-13 15:40:13 -0800610 LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (track == 0));
Glenn Kasten2fc14732013-08-05 14:58:14 -0700611 // we don't abort yet if lStatus != NO_ERROR; there is still work to be done regardless
Eric Laurent39e94f82010-07-28 01:32:47 -0700612
613 // move effect chain to this output thread if an effect on same session was waiting
614 // for a track to be created
615 if (lStatus == NO_ERROR && effectThread != NULL) {
Glenn Kasten2fc14732013-08-05 14:58:14 -0700616 // no risk of deadlock because AudioFlinger::mLock is held
Eric Laurent39e94f82010-07-28 01:32:47 -0700617 Mutex::Autolock _dl(thread->mLock);
618 Mutex::Autolock _sl(effectThread->mLock);
619 moveEffectChain_l(lSessionId, effectThread, thread, true);
620 }
Eric Laurenta011e352012-03-29 15:51:43 -0700621
622 // Look for sync events awaiting for a session to be used.
Mark Salyzyn3ab368e2014-04-15 14:55:53 -0700623 for (size_t i = 0; i < mPendingSyncEvents.size(); i++) {
Eric Laurenta011e352012-03-29 15:51:43 -0700624 if (mPendingSyncEvents[i]->triggerSession() == lSessionId) {
625 if (thread->isValidSyncEvent(mPendingSyncEvents[i])) {
Eric Laurent29864602012-05-08 18:57:51 -0700626 if (lStatus == NO_ERROR) {
Glenn Kastend23eedc2012-08-02 13:35:47 -0700627 (void) track->setSyncEvent(mPendingSyncEvents[i]);
Eric Laurent29864602012-05-08 18:57:51 -0700628 } else {
629 mPendingSyncEvents[i]->cancel();
630 }
Eric Laurenta011e352012-03-29 15:51:43 -0700631 mPendingSyncEvents.removeAt(i);
632 i--;
633 }
634 }
635 }
Glenn Kastene198c362013-08-13 09:13:36 -0700636
Mathias Agopian65ab4712010-07-14 17:59:35 -0700637 }
Glenn Kastene198c362013-08-13 09:13:36 -0700638
Glenn Kasten3ef14ef2014-03-13 15:08:51 -0700639 if (lStatus != NO_ERROR) {
640 // remove local strong reference to Client before deleting the Track so that the
Eric Laurent021cf962014-05-13 10:18:14 -0700641 // Client destructor is called by the TrackBase destructor with mClientLock held
Eric Laurentfe1a94e2014-05-26 16:03:08 -0700642 // Don't hold mClientLock when releasing the reference on the track as the
643 // destructor will acquire it.
644 {
645 Mutex::Autolock _cl(mClientLock);
646 client.clear();
647 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700648 track.clear();
Glenn Kasten3ef14ef2014-03-13 15:08:51 -0700649 goto Exit;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700650 }
651
Glenn Kasten3ef14ef2014-03-13 15:08:51 -0700652 // return handle to client
653 trackHandle = new TrackHandle(track);
654
Mathias Agopian65ab4712010-07-14 17:59:35 -0700655Exit:
Glenn Kasten9156ef32013-08-06 15:39:08 -0700656 *status = lStatus;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700657 return trackHandle;
658}
659
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800660uint32_t AudioFlinger::sampleRate(audio_io_handle_t output) const
Mathias Agopian65ab4712010-07-14 17:59:35 -0700661{
662 Mutex::Autolock _l(mLock);
663 PlaybackThread *thread = checkPlaybackThread_l(output);
664 if (thread == NULL) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000665 ALOGW("sampleRate() unknown thread %d", output);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700666 return 0;
667 }
668 return thread->sampleRate();
669}
670
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800671audio_format_t AudioFlinger::format(audio_io_handle_t output) const
Mathias Agopian65ab4712010-07-14 17:59:35 -0700672{
673 Mutex::Autolock _l(mLock);
674 PlaybackThread *thread = checkPlaybackThread_l(output);
675 if (thread == NULL) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000676 ALOGW("format() unknown thread %d", output);
Glenn Kasten58f30212012-01-12 12:27:51 -0800677 return AUDIO_FORMAT_INVALID;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700678 }
679 return thread->format();
680}
681
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800682size_t AudioFlinger::frameCount(audio_io_handle_t output) const
Mathias Agopian65ab4712010-07-14 17:59:35 -0700683{
684 Mutex::Autolock _l(mLock);
685 PlaybackThread *thread = checkPlaybackThread_l(output);
686 if (thread == NULL) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000687 ALOGW("frameCount() unknown thread %d", output);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700688 return 0;
689 }
Glenn Kasten58912562012-04-03 10:45:00 -0700690 // FIXME currently returns the normal mixer's frame count to avoid confusing legacy callers;
691 // should examine all callers and fix them to handle smaller counts
Mathias Agopian65ab4712010-07-14 17:59:35 -0700692 return thread->frameCount();
693}
694
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800695uint32_t AudioFlinger::latency(audio_io_handle_t output) const
Mathias Agopian65ab4712010-07-14 17:59:35 -0700696{
697 Mutex::Autolock _l(mLock);
698 PlaybackThread *thread = checkPlaybackThread_l(output);
699 if (thread == NULL) {
Glenn Kastenc9b2e202013-02-26 11:32:32 -0800700 ALOGW("latency(): no playback thread found for output handle %d", output);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700701 return 0;
702 }
703 return thread->latency();
704}
705
706status_t AudioFlinger::setMasterVolume(float value)
707{
Eric Laurenta1884f92011-08-23 08:25:03 -0700708 status_t ret = initCheck();
709 if (ret != NO_ERROR) {
710 return ret;
711 }
712
Mathias Agopian65ab4712010-07-14 17:59:35 -0700713 // check calling permissions
714 if (!settingsAllowed()) {
715 return PERMISSION_DENIED;
716 }
717
Eric Laurenta4c5a552012-03-29 10:12:40 -0700718 Mutex::Autolock _l(mLock);
John Grossmanee578c02012-07-23 17:05:46 -0700719 mMasterVolume = value;
Eric Laurenta4c5a552012-03-29 10:12:40 -0700720
John Grossmanee578c02012-07-23 17:05:46 -0700721 // Set master volume in the HALs which support it.
722 for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
723 AutoMutex lock(mHardwareLock);
724 AudioHwDevice *dev = mAudioHwDevs.valueAt(i);
John Grossman4ff14ba2012-02-08 16:37:41 -0800725
John Grossmanee578c02012-07-23 17:05:46 -0700726 mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME;
727 if (dev->canSetMasterVolume()) {
728 dev->hwDevice()->set_master_volume(dev->hwDevice(), value);
Eric Laurent93575202011-01-18 18:39:02 -0800729 }
John Grossmanee578c02012-07-23 17:05:46 -0700730 mHardwareStatus = AUDIO_HW_IDLE;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700731 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700732
John Grossmanee578c02012-07-23 17:05:46 -0700733 // Now set the master volume in each playback thread. Playback threads
734 // assigned to HALs which do not have master volume support will apply
735 // master volume during the mix operation. Threads with HALs which do
736 // support master volume will simply ignore the setting.
Glenn Kasten8d6a2442012-02-08 14:04:28 -0800737 for (size_t i = 0; i < mPlaybackThreads.size(); i++)
John Grossmanee578c02012-07-23 17:05:46 -0700738 mPlaybackThreads.valueAt(i)->setMasterVolume(value);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700739
740 return NO_ERROR;
741}
742
Glenn Kastenf78aee72012-01-04 11:00:47 -0800743status_t AudioFlinger::setMode(audio_mode_t mode)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700744{
Eric Laurenta1884f92011-08-23 08:25:03 -0700745 status_t ret = initCheck();
746 if (ret != NO_ERROR) {
747 return ret;
748 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700749
750 // check calling permissions
751 if (!settingsAllowed()) {
752 return PERMISSION_DENIED;
753 }
Glenn Kasten930f4ca2012-01-06 16:47:31 -0800754 if (uint32_t(mode) >= AUDIO_MODE_CNT) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000755 ALOGW("Illegal value: setMode(%d)", mode);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700756 return BAD_VALUE;
757 }
758
759 { // scope for the lock
760 AutoMutex lock(mHardwareLock);
John Grossmanee578c02012-07-23 17:05:46 -0700761 audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700762 mHardwareStatus = AUDIO_HW_SET_MODE;
John Grossmanee578c02012-07-23 17:05:46 -0700763 ret = dev->set_mode(dev, mode);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700764 mHardwareStatus = AUDIO_HW_IDLE;
765 }
766
767 if (NO_ERROR == ret) {
768 Mutex::Autolock _l(mLock);
769 mMode = mode;
Glenn Kasten8d6a2442012-02-08 14:04:28 -0800770 for (size_t i = 0; i < mPlaybackThreads.size(); i++)
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700771 mPlaybackThreads.valueAt(i)->setMode(mode);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700772 }
773
774 return ret;
775}
776
777status_t AudioFlinger::setMicMute(bool state)
778{
Eric Laurenta1884f92011-08-23 08:25:03 -0700779 status_t ret = initCheck();
780 if (ret != NO_ERROR) {
781 return ret;
782 }
783
Mathias Agopian65ab4712010-07-14 17:59:35 -0700784 // check calling permissions
785 if (!settingsAllowed()) {
786 return PERMISSION_DENIED;
787 }
788
789 AutoMutex lock(mHardwareLock);
John Grossmanee578c02012-07-23 17:05:46 -0700790 audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700791 mHardwareStatus = AUDIO_HW_SET_MIC_MUTE;
John Grossmanee578c02012-07-23 17:05:46 -0700792 ret = dev->set_mic_mute(dev, state);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700793 mHardwareStatus = AUDIO_HW_IDLE;
794 return ret;
795}
796
797bool AudioFlinger::getMicMute() const
798{
Eric Laurenta1884f92011-08-23 08:25:03 -0700799 status_t ret = initCheck();
800 if (ret != NO_ERROR) {
801 return false;
802 }
803
Dima Zavinfce7a472011-04-19 22:30:36 -0700804 bool state = AUDIO_MODE_INVALID;
Glenn Kasten2b213bc2012-02-02 14:05:20 -0800805 AutoMutex lock(mHardwareLock);
John Grossmanee578c02012-07-23 17:05:46 -0700806 audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700807 mHardwareStatus = AUDIO_HW_GET_MIC_MUTE;
John Grossmanee578c02012-07-23 17:05:46 -0700808 dev->get_mic_mute(dev, &state);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700809 mHardwareStatus = AUDIO_HW_IDLE;
810 return state;
811}
812
813status_t AudioFlinger::setMasterMute(bool muted)
814{
John Grossmand8f178d2012-07-20 14:51:35 -0700815 status_t ret = initCheck();
816 if (ret != NO_ERROR) {
817 return ret;
818 }
819
Mathias Agopian65ab4712010-07-14 17:59:35 -0700820 // check calling permissions
821 if (!settingsAllowed()) {
822 return PERMISSION_DENIED;
823 }
824
John Grossmanee578c02012-07-23 17:05:46 -0700825 Mutex::Autolock _l(mLock);
826 mMasterMute = muted;
John Grossmand8f178d2012-07-20 14:51:35 -0700827
John Grossmanee578c02012-07-23 17:05:46 -0700828 // Set master mute in the HALs which support it.
829 for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
830 AutoMutex lock(mHardwareLock);
831 AudioHwDevice *dev = mAudioHwDevs.valueAt(i);
John Grossmand8f178d2012-07-20 14:51:35 -0700832
John Grossmanee578c02012-07-23 17:05:46 -0700833 mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE;
834 if (dev->canSetMasterMute()) {
835 dev->hwDevice()->set_master_mute(dev->hwDevice(), muted);
John Grossmand8f178d2012-07-20 14:51:35 -0700836 }
John Grossmanee578c02012-07-23 17:05:46 -0700837 mHardwareStatus = AUDIO_HW_IDLE;
John Grossmand8f178d2012-07-20 14:51:35 -0700838 }
839
John Grossmanee578c02012-07-23 17:05:46 -0700840 // Now set the master mute in each playback thread. Playback threads
841 // assigned to HALs which do not have master mute support will apply master
842 // mute during the mix operation. Threads with HALs which do support master
843 // mute will simply ignore the setting.
Glenn Kasten8d6a2442012-02-08 14:04:28 -0800844 for (size_t i = 0; i < mPlaybackThreads.size(); i++)
John Grossmanee578c02012-07-23 17:05:46 -0700845 mPlaybackThreads.valueAt(i)->setMasterMute(muted);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700846
847 return NO_ERROR;
848}
849
850float AudioFlinger::masterVolume() const
851{
Glenn Kasten98067102011-12-13 11:47:54 -0800852 Mutex::Autolock _l(mLock);
853 return masterVolume_l();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700854}
855
856bool AudioFlinger::masterMute() const
857{
Glenn Kasten98067102011-12-13 11:47:54 -0800858 Mutex::Autolock _l(mLock);
859 return masterMute_l();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700860}
861
John Grossman4ff14ba2012-02-08 16:37:41 -0800862float AudioFlinger::masterVolume_l() const
863{
John Grossman4ff14ba2012-02-08 16:37:41 -0800864 return mMasterVolume;
865}
866
John Grossmand8f178d2012-07-20 14:51:35 -0700867bool AudioFlinger::masterMute_l() const
868{
John Grossmanee578c02012-07-23 17:05:46 -0700869 return mMasterMute;
John Grossmand8f178d2012-07-20 14:51:35 -0700870}
871
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800872status_t AudioFlinger::setStreamVolume(audio_stream_type_t stream, float value,
873 audio_io_handle_t output)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700874{
875 // check calling permissions
876 if (!settingsAllowed()) {
877 return PERMISSION_DENIED;
878 }
879
Glenn Kasten263709e2012-01-06 08:40:01 -0800880 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
Steve Block29357bc2012-01-06 19:20:56 +0000881 ALOGE("setStreamVolume() invalid stream %d", stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700882 return BAD_VALUE;
883 }
884
885 AutoMutex lock(mLock);
886 PlaybackThread *thread = NULL;
Glenn Kasten142f5192014-03-25 17:44:59 -0700887 if (output != AUDIO_IO_HANDLE_NONE) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700888 thread = checkPlaybackThread_l(output);
889 if (thread == NULL) {
890 return BAD_VALUE;
891 }
892 }
893
894 mStreamTypes[stream].volume = value;
895
896 if (thread == NULL) {
Glenn Kasten8d6a2442012-02-08 14:04:28 -0800897 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700898 mPlaybackThreads.valueAt(i)->setStreamVolume(stream, value);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700899 }
900 } else {
901 thread->setStreamVolume(stream, value);
902 }
903
904 return NO_ERROR;
905}
906
Glenn Kastenfff6d712012-01-12 16:38:12 -0800907status_t AudioFlinger::setStreamMute(audio_stream_type_t stream, bool muted)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700908{
909 // check calling permissions
910 if (!settingsAllowed()) {
911 return PERMISSION_DENIED;
912 }
913
Glenn Kasten263709e2012-01-06 08:40:01 -0800914 if (uint32_t(stream) >= AUDIO_STREAM_CNT ||
Dima Zavinfce7a472011-04-19 22:30:36 -0700915 uint32_t(stream) == AUDIO_STREAM_ENFORCED_AUDIBLE) {
Steve Block29357bc2012-01-06 19:20:56 +0000916 ALOGE("setStreamMute() invalid stream %d", stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700917 return BAD_VALUE;
918 }
919
Eric Laurent93575202011-01-18 18:39:02 -0800920 AutoMutex lock(mLock);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700921 mStreamTypes[stream].mute = muted;
Mark Salyzyn3ab368e2014-04-15 14:55:53 -0700922 for (size_t i = 0; i < mPlaybackThreads.size(); i++)
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700923 mPlaybackThreads.valueAt(i)->setStreamMute(stream, muted);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700924
925 return NO_ERROR;
926}
927
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800928float AudioFlinger::streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
Mathias Agopian65ab4712010-07-14 17:59:35 -0700929{
Glenn Kasten263709e2012-01-06 08:40:01 -0800930 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700931 return 0.0f;
932 }
933
934 AutoMutex lock(mLock);
935 float volume;
Glenn Kasten142f5192014-03-25 17:44:59 -0700936 if (output != AUDIO_IO_HANDLE_NONE) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700937 PlaybackThread *thread = checkPlaybackThread_l(output);
938 if (thread == NULL) {
939 return 0.0f;
940 }
941 volume = thread->streamVolume(stream);
942 } else {
Glenn Kasten6637baa2012-01-09 09:40:36 -0800943 volume = streamVolume_l(stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700944 }
945
946 return volume;
947}
948
Glenn Kastenfff6d712012-01-12 16:38:12 -0800949bool AudioFlinger::streamMute(audio_stream_type_t stream) const
Mathias Agopian65ab4712010-07-14 17:59:35 -0700950{
Glenn Kasten263709e2012-01-06 08:40:01 -0800951 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700952 return true;
953 }
954
Glenn Kasten6637baa2012-01-09 09:40:36 -0800955 AutoMutex lock(mLock);
956 return streamMute_l(stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700957}
958
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800959status_t AudioFlinger::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700960{
Glenn Kasten827e5f12012-11-02 10:00:06 -0700961 ALOGV("setParameters(): io %d, keyvalue %s, calling pid %d",
962 ioHandle, keyValuePairs.string(), IPCThreadState::self()->getCallingPid());
Eric Laurent81784c32012-11-19 14:55:58 -0800963
Mathias Agopian65ab4712010-07-14 17:59:35 -0700964 // check calling permissions
965 if (!settingsAllowed()) {
966 return PERMISSION_DENIED;
967 }
968
Glenn Kasten142f5192014-03-25 17:44:59 -0700969 // AUDIO_IO_HANDLE_NONE means the parameters are global to the audio hardware interface
970 if (ioHandle == AUDIO_IO_HANDLE_NONE) {
Eric Laurenta4c5a552012-03-29 10:12:40 -0700971 Mutex::Autolock _l(mLock);
Dima Zavin799a70e2011-04-18 16:57:27 -0700972 status_t final_result = NO_ERROR;
Glenn Kasten8abf44d2012-02-02 14:16:03 -0800973 {
Eric Laurenta4c5a552012-03-29 10:12:40 -0700974 AutoMutex lock(mHardwareLock);
975 mHardwareStatus = AUDIO_HW_SET_PARAMETER;
976 for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
977 audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice();
978 status_t result = dev->set_parameters(dev, keyValuePairs.string());
979 final_result = result ?: final_result;
980 }
981 mHardwareStatus = AUDIO_HW_IDLE;
Glenn Kasten8abf44d2012-02-02 14:16:03 -0800982 }
Eric Laurent59bd0da2011-08-01 09:52:20 -0700983 // disable AEC and NS if the device is a BT SCO headset supporting those pre processings
984 AudioParameter param = AudioParameter(keyValuePairs);
985 String8 value;
986 if (param.get(String8(AUDIO_PARAMETER_KEY_BT_NREC), value) == NO_ERROR) {
Eric Laurentbee53372011-08-29 12:42:48 -0700987 bool btNrecIsOff = (value == AUDIO_PARAMETER_VALUE_OFF);
988 if (mBtNrecIsOff != btNrecIsOff) {
Eric Laurent59bd0da2011-08-01 09:52:20 -0700989 for (size_t i = 0; i < mRecordThreads.size(); i++) {
990 sp<RecordThread> thread = mRecordThreads.valueAt(i);
Eric Laurentf1c04f92012-08-28 14:26:53 -0700991 audio_devices_t device = thread->inDevice();
Glenn Kasten510a3d62012-07-16 14:24:34 -0700992 bool suspend = audio_is_bluetooth_sco_device(device) && btNrecIsOff;
993 // collect all of the thread's session IDs
994 KeyedVector<int, bool> ids = thread->sessionIds();
995 // suspend effects associated with those session IDs
996 for (size_t j = 0; j < ids.size(); ++j) {
997 int sessionId = ids.keyAt(j);
Eric Laurent59bd0da2011-08-01 09:52:20 -0700998 thread->setEffectSuspended(FX_IID_AEC,
999 suspend,
Glenn Kasten510a3d62012-07-16 14:24:34 -07001000 sessionId);
Eric Laurent59bd0da2011-08-01 09:52:20 -07001001 thread->setEffectSuspended(FX_IID_NS,
1002 suspend,
Glenn Kasten510a3d62012-07-16 14:24:34 -07001003 sessionId);
Eric Laurent59bd0da2011-08-01 09:52:20 -07001004 }
1005 }
Eric Laurentbee53372011-08-29 12:42:48 -07001006 mBtNrecIsOff = btNrecIsOff;
Eric Laurent59bd0da2011-08-01 09:52:20 -07001007 }
1008 }
Glenn Kasten28ed2f92012-06-07 10:17:54 -07001009 String8 screenState;
1010 if (param.get(String8(AudioParameter::keyScreenState), screenState) == NO_ERROR) {
1011 bool isOff = screenState == "off";
Eric Laurent81784c32012-11-19 14:55:58 -08001012 if (isOff != (AudioFlinger::mScreenState & 1)) {
1013 AudioFlinger::mScreenState = ((AudioFlinger::mScreenState & ~1) + 2) | isOff;
Glenn Kasten28ed2f92012-06-07 10:17:54 -07001014 }
1015 }
Dima Zavin799a70e2011-04-18 16:57:27 -07001016 return final_result;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001017 }
1018
1019 // hold a strong ref on thread in case closeOutput() or closeInput() is called
1020 // and the thread is exited once the lock is released
1021 sp<ThreadBase> thread;
1022 {
1023 Mutex::Autolock _l(mLock);
1024 thread = checkPlaybackThread_l(ioHandle);
Glenn Kastend5903ec2012-03-18 10:33:27 -07001025 if (thread == 0) {
Mathias Agopian65ab4712010-07-14 17:59:35 -07001026 thread = checkRecordThread_l(ioHandle);
Glenn Kasten7fc9a6f2012-01-10 10:46:34 -08001027 } else if (thread == primaryPlaybackThread_l()) {
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001028 // indicate output device change to all input threads for pre processing
1029 AudioParameter param = AudioParameter(keyValuePairs);
1030 int value;
Eric Laurent89d94e72012-03-16 20:37:59 -07001031 if ((param.getInt(String8(AudioParameter::keyRouting), value) == NO_ERROR) &&
1032 (value != 0)) {
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001033 for (size_t i = 0; i < mRecordThreads.size(); i++) {
1034 mRecordThreads.valueAt(i)->setParameters(keyValuePairs);
1035 }
1036 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07001037 }
1038 }
Glenn Kasten7378ca52012-01-20 13:44:40 -08001039 if (thread != 0) {
1040 return thread->setParameters(keyValuePairs);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001041 }
1042 return BAD_VALUE;
1043}
1044
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001045String8 AudioFlinger::getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07001046{
Glenn Kasten827e5f12012-11-02 10:00:06 -07001047 ALOGVV("getParameters() io %d, keys %s, calling pid %d",
1048 ioHandle, keys.string(), IPCThreadState::self()->getCallingPid());
Mathias Agopian65ab4712010-07-14 17:59:35 -07001049
Eric Laurenta4c5a552012-03-29 10:12:40 -07001050 Mutex::Autolock _l(mLock);
1051
Glenn Kasten142f5192014-03-25 17:44:59 -07001052 if (ioHandle == AUDIO_IO_HANDLE_NONE) {
Dima Zavinfce7a472011-04-19 22:30:36 -07001053 String8 out_s8;
1054
Dima Zavin799a70e2011-04-18 16:57:27 -07001055 for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
Glenn Kasten8abf44d2012-02-02 14:16:03 -08001056 char *s;
1057 {
1058 AutoMutex lock(mHardwareLock);
1059 mHardwareStatus = AUDIO_HW_GET_PARAMETER;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001060 audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice();
Glenn Kasten8abf44d2012-02-02 14:16:03 -08001061 s = dev->get_parameters(dev, keys.string());
1062 mHardwareStatus = AUDIO_HW_IDLE;
1063 }
John Grossmanef7740b2012-02-09 11:28:36 -08001064 out_s8 += String8(s ? s : "");
Dima Zavin799a70e2011-04-18 16:57:27 -07001065 free(s);
1066 }
Dima Zavinfce7a472011-04-19 22:30:36 -07001067 return out_s8;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001068 }
1069
Mathias Agopian65ab4712010-07-14 17:59:35 -07001070 PlaybackThread *playbackThread = checkPlaybackThread_l(ioHandle);
1071 if (playbackThread != NULL) {
1072 return playbackThread->getParameters(keys);
1073 }
1074 RecordThread *recordThread = checkRecordThread_l(ioHandle);
1075 if (recordThread != NULL) {
1076 return recordThread->getParameters(keys);
1077 }
1078 return String8("");
1079}
1080
Glenn Kastendd8104c2012-07-02 12:42:44 -07001081size_t AudioFlinger::getInputBufferSize(uint32_t sampleRate, audio_format_t format,
1082 audio_channel_mask_t channelMask) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07001083{
Eric Laurenta1884f92011-08-23 08:25:03 -07001084 status_t ret = initCheck();
1085 if (ret != NO_ERROR) {
1086 return 0;
1087 }
1088
Glenn Kasten2b213bc2012-02-02 14:05:20 -08001089 AutoMutex lock(mHardwareLock);
1090 mHardwareStatus = AUDIO_HW_GET_INPUT_BUFFER_SIZE;
Richard Fitzgeraldad3af332013-03-25 16:54:37 +00001091 struct audio_config config;
1092 memset(&config, 0, sizeof(config));
1093 config.sample_rate = sampleRate;
1094 config.channel_mask = channelMask;
1095 config.format = format;
1096
John Grossmanee578c02012-07-23 17:05:46 -07001097 audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice();
1098 size_t size = dev->get_input_buffer_size(dev, &config);
Glenn Kasten2b213bc2012-02-02 14:05:20 -08001099 mHardwareStatus = AUDIO_HW_IDLE;
1100 return size;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001101}
1102
Glenn Kasten5f972c02014-01-13 09:59:31 -08001103uint32_t AudioFlinger::getInputFramesLost(audio_io_handle_t ioHandle) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07001104{
Mathias Agopian65ab4712010-07-14 17:59:35 -07001105 Mutex::Autolock _l(mLock);
1106
1107 RecordThread *recordThread = checkRecordThread_l(ioHandle);
1108 if (recordThread != NULL) {
1109 return recordThread->getInputFramesLost();
1110 }
1111 return 0;
1112}
1113
1114status_t AudioFlinger::setVoiceVolume(float value)
1115{
Eric Laurenta1884f92011-08-23 08:25:03 -07001116 status_t ret = initCheck();
1117 if (ret != NO_ERROR) {
1118 return ret;
1119 }
1120
Mathias Agopian65ab4712010-07-14 17:59:35 -07001121 // check calling permissions
1122 if (!settingsAllowed()) {
1123 return PERMISSION_DENIED;
1124 }
1125
1126 AutoMutex lock(mHardwareLock);
John Grossmanee578c02012-07-23 17:05:46 -07001127 audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice();
Glenn Kasten8abf44d2012-02-02 14:16:03 -08001128 mHardwareStatus = AUDIO_HW_SET_VOICE_VOLUME;
John Grossmanee578c02012-07-23 17:05:46 -07001129 ret = dev->set_voice_volume(dev, value);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001130 mHardwareStatus = AUDIO_HW_IDLE;
1131
1132 return ret;
1133}
1134
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001135status_t AudioFlinger::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001136 audio_io_handle_t output) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07001137{
1138 status_t status;
1139
1140 Mutex::Autolock _l(mLock);
1141
1142 PlaybackThread *playbackThread = checkPlaybackThread_l(output);
1143 if (playbackThread != NULL) {
1144 return playbackThread->getRenderPosition(halFrames, dspFrames);
1145 }
1146
1147 return BAD_VALUE;
1148}
1149
1150void AudioFlinger::registerClient(const sp<IAudioFlingerClient>& client)
1151{
Mathias Agopian65ab4712010-07-14 17:59:35 -07001152 Mutex::Autolock _l(mLock);
Eric Laurent021cf962014-05-13 10:18:14 -07001153 bool clientAdded = false;
1154 {
1155 Mutex::Autolock _cl(mClientLock);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001156
Eric Laurent021cf962014-05-13 10:18:14 -07001157 pid_t pid = IPCThreadState::self()->getCallingPid();
1158 if (mNotificationClients.indexOfKey(pid) < 0) {
1159 sp<NotificationClient> notificationClient = new NotificationClient(this,
1160 client,
1161 pid);
1162 ALOGV("registerClient() client %p, pid %d", notificationClient.get(), pid);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001163
Eric Laurent021cf962014-05-13 10:18:14 -07001164 mNotificationClients.add(pid, notificationClient);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001165
Eric Laurent021cf962014-05-13 10:18:14 -07001166 sp<IBinder> binder = client->asBinder();
1167 binder->linkToDeath(notificationClient);
1168 clientAdded = true;
1169 }
1170 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07001171
Eric Laurent021cf962014-05-13 10:18:14 -07001172 // mClientLock should not be held here because ThreadBase::sendIoConfigEvent() will lock the
Eric Laurentfe1a94e2014-05-26 16:03:08 -07001173 // ThreadBase mutex and the locking order is ThreadBase::mLock then AudioFlinger::mClientLock.
Eric Laurent021cf962014-05-13 10:18:14 -07001174 if (clientAdded) {
Mathias Agopian65ab4712010-07-14 17:59:35 -07001175 // the config change is always sent from playback or record threads to avoid deadlock
1176 // with AudioSystem::gLock
1177 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
Eric Laurent896adcd2012-09-13 11:18:23 -07001178 mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AudioSystem::OUTPUT_OPENED);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001179 }
1180
1181 for (size_t i = 0; i < mRecordThreads.size(); i++) {
Eric Laurent896adcd2012-09-13 11:18:23 -07001182 mRecordThreads.valueAt(i)->sendIoConfigEvent(AudioSystem::INPUT_OPENED);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001183 }
1184 }
1185}
1186
1187void AudioFlinger::removeNotificationClient(pid_t pid)
1188{
1189 Mutex::Autolock _l(mLock);
Eric Laurent021cf962014-05-13 10:18:14 -07001190 {
1191 Mutex::Autolock _cl(mClientLock);
1192 mNotificationClients.removeItem(pid);
1193 }
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001194
Steve Block3856b092011-10-20 11:56:00 +01001195 ALOGV("%d died, releasing its sessions", pid);
Glenn Kasten8d6a2442012-02-08 14:04:28 -08001196 size_t num = mAudioSessionRefs.size();
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001197 bool removed = false;
Glenn Kasten8d6a2442012-02-08 14:04:28 -08001198 for (size_t i = 0; i< num; ) {
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001199 AudioSessionRef *ref = mAudioSessionRefs.itemAt(i);
Glenn Kasten012ca6b2012-03-06 11:22:01 -08001200 ALOGV(" pid %d @ %d", ref->mPid, i);
1201 if (ref->mPid == pid) {
1202 ALOGV(" removing entry for pid %d session %d", pid, ref->mSessionid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001203 mAudioSessionRefs.removeAt(i);
1204 delete ref;
1205 removed = true;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001206 num--;
Glenn Kasten8d6a2442012-02-08 14:04:28 -08001207 } else {
1208 i++;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001209 }
1210 }
1211 if (removed) {
1212 purgeStaleEffects_l();
1213 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07001214}
1215
Eric Laurent021cf962014-05-13 10:18:14 -07001216void AudioFlinger::audioConfigChanged(int event, audio_io_handle_t ioHandle, const void *param2)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001217{
Eric Laurent021cf962014-05-13 10:18:14 -07001218 Mutex::Autolock _l(mClientLock);
1219 size_t size = mNotificationClients.size();
Mathias Agopian65ab4712010-07-14 17:59:35 -07001220 for (size_t i = 0; i < size; i++) {
Eric Laurent021cf962014-05-13 10:18:14 -07001221 mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event,
Eric Laurent10351942014-05-08 18:49:52 -07001222 ioHandle,
1223 param2);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001224 }
1225}
1226
Eric Laurent021cf962014-05-13 10:18:14 -07001227// removeClient_l() must be called with AudioFlinger::mClientLock held
Mathias Agopian65ab4712010-07-14 17:59:35 -07001228void AudioFlinger::removeClient_l(pid_t pid)
1229{
Glenn Kasten827e5f12012-11-02 10:00:06 -07001230 ALOGV("removeClient_l() pid %d, calling pid %d", pid,
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001231 IPCThreadState::self()->getCallingPid());
Mathias Agopian65ab4712010-07-14 17:59:35 -07001232 mClients.removeItem(pid);
1233}
1234
Eric Laurent717e1282012-06-29 16:36:52 -07001235// getEffectThread_l() must be called with AudioFlinger::mLock held
1236sp<AudioFlinger::PlaybackThread> AudioFlinger::getEffectThread_l(int sessionId, int EffectId)
1237{
1238 sp<PlaybackThread> thread;
1239
1240 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
1241 if (mPlaybackThreads.valueAt(i)->getEffect(sessionId, EffectId) != 0) {
1242 ALOG_ASSERT(thread == 0);
1243 thread = mPlaybackThreads.valueAt(i);
1244 }
1245 }
1246
1247 return thread;
1248}
Mathias Agopian65ab4712010-07-14 17:59:35 -07001249
Mathias Agopian65ab4712010-07-14 17:59:35 -07001250
Mathias Agopian65ab4712010-07-14 17:59:35 -07001251
1252// ----------------------------------------------------------------------------
1253
1254AudioFlinger::Client::Client(const sp<AudioFlinger>& audioFlinger, pid_t pid)
1255 : RefBase(),
1256 mAudioFlinger(audioFlinger),
Glenn Kasten99e53b82012-01-19 08:59:58 -08001257 // FIXME should be a "k" constant not hard-coded, in .h or ro. property, see 4 lines below
Mathias Agopian65ab4712010-07-14 17:59:35 -07001258 mMemoryDealer(new MemoryDealer(1024*1024, "AudioFlinger::Client")),
John Grossman4ff14ba2012-02-08 16:37:41 -08001259 mPid(pid),
1260 mTimedTrackCount(0)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001261{
1262 // 1 MB of address space is good for 32 tracks, 8 buffers each, 4 KB/buffer
1263}
1264
Eric Laurent021cf962014-05-13 10:18:14 -07001265// Client destructor must be called with AudioFlinger::mClientLock held
Mathias Agopian65ab4712010-07-14 17:59:35 -07001266AudioFlinger::Client::~Client()
1267{
1268 mAudioFlinger->removeClient_l(mPid);
1269}
1270
Glenn Kasten435dbe62012-01-30 10:15:48 -08001271sp<MemoryDealer> AudioFlinger::Client::heap() const
Mathias Agopian65ab4712010-07-14 17:59:35 -07001272{
1273 return mMemoryDealer;
1274}
1275
John Grossman4ff14ba2012-02-08 16:37:41 -08001276// Reserve one of the limited slots for a timed audio track associated
1277// with this client
1278bool AudioFlinger::Client::reserveTimedTrack()
1279{
1280 const int kMaxTimedTracksPerClient = 4;
1281
1282 Mutex::Autolock _l(mTimedTrackLock);
1283
1284 if (mTimedTrackCount >= kMaxTimedTracksPerClient) {
1285 ALOGW("can not create timed track - pid %d has exceeded the limit",
1286 mPid);
1287 return false;
1288 }
1289
1290 mTimedTrackCount++;
1291 return true;
1292}
1293
1294// Release a slot for a timed audio track
1295void AudioFlinger::Client::releaseTimedTrack()
1296{
1297 Mutex::Autolock _l(mTimedTrackLock);
1298 mTimedTrackCount--;
1299}
1300
Mathias Agopian65ab4712010-07-14 17:59:35 -07001301// ----------------------------------------------------------------------------
1302
1303AudioFlinger::NotificationClient::NotificationClient(const sp<AudioFlinger>& audioFlinger,
1304 const sp<IAudioFlingerClient>& client,
1305 pid_t pid)
Glenn Kasten84afa3b2012-01-25 15:28:08 -08001306 : mAudioFlinger(audioFlinger), mPid(pid), mAudioFlingerClient(client)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001307{
1308}
1309
1310AudioFlinger::NotificationClient::~NotificationClient()
1311{
Mathias Agopian65ab4712010-07-14 17:59:35 -07001312}
1313
Glenn Kasten0f11b512014-01-31 16:18:54 -08001314void AudioFlinger::NotificationClient::binderDied(const wp<IBinder>& who __unused)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001315{
1316 sp<NotificationClient> keep(this);
Glenn Kastena1117922012-01-26 10:53:32 -08001317 mAudioFlinger->removeNotificationClient(mPid);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001318}
1319
Mathias Agopian65ab4712010-07-14 17:59:35 -07001320
1321// ----------------------------------------------------------------------------
1322
Jeff Brown893a5642013-08-16 20:19:26 -07001323static bool deviceRequiresCaptureAudioOutputPermission(audio_devices_t inDevice) {
1324 return audio_is_remote_submix_device(inDevice);
1325}
1326
Mathias Agopian65ab4712010-07-14 17:59:35 -07001327sp<IAudioRecord> AudioFlinger::openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001328 audio_io_handle_t input,
Mathias Agopian65ab4712010-07-14 17:59:35 -07001329 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -08001330 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -07001331 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -08001332 size_t *frameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -07001333 IAudioFlinger::track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -07001334 pid_t tid,
Mathias Agopian65ab4712010-07-14 17:59:35 -07001335 int *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -07001336 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -07001337 sp<IMemory>& cblk,
1338 sp<IMemory>& buffers,
Mathias Agopian65ab4712010-07-14 17:59:35 -07001339 status_t *status)
1340{
1341 sp<RecordThread::RecordTrack> recordTrack;
1342 sp<RecordHandle> recordHandle;
1343 sp<Client> client;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001344 status_t lStatus;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001345 int lSessionId;
1346
Glenn Kastend776ac62014-05-07 09:16:09 -07001347 cblk.clear();
1348 buffers.clear();
1349
Mathias Agopian65ab4712010-07-14 17:59:35 -07001350 // check calling permissions
1351 if (!recordingAllowed()) {
Glenn Kastene93cf2c2013-09-24 11:52:37 -07001352 ALOGE("openRecord() permission denied: recording not allowed");
Mathias Agopian65ab4712010-07-14 17:59:35 -07001353 lStatus = PERMISSION_DENIED;
1354 goto Exit;
1355 }
1356
Glenn Kasten53b5d092014-02-05 10:00:23 -08001357 // further sample rate checks are performed by createRecordTrack_l()
1358 if (sampleRate == 0) {
1359 ALOGE("openRecord() invalid sample rate %u", sampleRate);
1360 lStatus = BAD_VALUE;
1361 goto Exit;
1362 }
1363
Glenn Kasten0e0e8462014-03-13 15:02:40 -07001364 // we don't yet support anything other than 16-bit PCM
1365 if (!(audio_is_valid_format(format) &&
1366 audio_is_linear_pcm(format) && format == AUDIO_FORMAT_PCM_16_BIT)) {
Glenn Kastencac3daa2014-02-07 09:47:14 -08001367 ALOGE("openRecord() invalid format %#x", format);
Glenn Kasten291bb6d2013-07-16 17:23:39 -07001368 lStatus = BAD_VALUE;
1369 goto Exit;
1370 }
1371
Glenn Kasten53b5d092014-02-05 10:00:23 -08001372 // further channel mask checks are performed by createRecordTrack_l()
1373 if (!audio_is_input_channel(channelMask)) {
1374 ALOGE("openRecord() invalid channel mask %#x", channelMask);
1375 lStatus = BAD_VALUE;
1376 goto Exit;
1377 }
1378
Glenn Kasten05997e22014-03-13 15:08:33 -07001379 {
Mathias Agopian65ab4712010-07-14 17:59:35 -07001380 Mutex::Autolock _l(mLock);
Glenn Kastene848bd92014-03-13 15:00:32 -07001381 RecordThread *thread = checkRecordThread_l(input);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001382 if (thread == NULL) {
Glenn Kastene93cf2c2013-09-24 11:52:37 -07001383 ALOGE("openRecord() checkRecordThread_l failed");
Mathias Agopian65ab4712010-07-14 17:59:35 -07001384 lStatus = BAD_VALUE;
1385 goto Exit;
1386 }
1387
Jeff Brown893a5642013-08-16 20:19:26 -07001388 if (deviceRequiresCaptureAudioOutputPermission(thread->inDevice())
1389 && !captureAudioOutputAllowed()) {
Glenn Kastene93cf2c2013-09-24 11:52:37 -07001390 ALOGE("openRecord() permission denied: capture not allowed");
Jeff Brown893a5642013-08-16 20:19:26 -07001391 lStatus = PERMISSION_DENIED;
1392 goto Exit;
1393 }
1394
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001395 pid_t pid = IPCThreadState::self()->getCallingPid();
Eric Laurent021cf962014-05-13 10:18:14 -07001396 client = registerPid(pid);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001397
Glenn Kastenaea7ea02013-06-26 09:25:47 -07001398 if (sessionId != NULL && *sessionId != AUDIO_SESSION_ALLOCATE) {
Mathias Agopian65ab4712010-07-14 17:59:35 -07001399 lSessionId = *sessionId;
1400 } else {
Glenn Kasten570f6332014-03-13 15:01:06 -07001401 // if no audio session id is provided, create one here
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001402 lSessionId = nextUniqueId();
Mathias Agopian65ab4712010-07-14 17:59:35 -07001403 if (sessionId != NULL) {
1404 *sessionId = lSessionId;
1405 }
1406 }
Glenn Kasten570f6332014-03-13 15:01:06 -07001407 ALOGV("openRecord() lSessionId: %d", lSessionId);
1408
Marco Nelissen462fd2f2013-01-14 14:12:05 -08001409 // TODO: the uid should be passed in as a parameter to openRecord
Glenn Kasten1879fff2012-07-11 15:36:59 -07001410 recordTrack = thread->createRecordTrack_l(client, sampleRate, format, channelMask,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -07001411 frameCount, lSessionId, notificationFrames,
Marco Nelissen462fd2f2013-01-14 14:12:05 -08001412 IPCThreadState::self()->getCallingUid(),
1413 flags, tid, &lStatus);
Haynes Mathew George03e9e832013-12-13 15:40:13 -08001414 LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (recordTrack == 0));
Mathias Agopian65ab4712010-07-14 17:59:35 -07001415 }
Glenn Kastene198c362013-08-13 09:13:36 -07001416
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001417 if (lStatus != NO_ERROR) {
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001418 // remove local strong reference to Client before deleting the RecordTrack so that the
Eric Laurent021cf962014-05-13 10:18:14 -07001419 // Client destructor is called by the TrackBase destructor with mClientLock held
Eric Laurentfe1a94e2014-05-26 16:03:08 -07001420 // Don't hold mClientLock when releasing the reference on the track as the
1421 // destructor will acquire it.
1422 {
1423 Mutex::Autolock _cl(mClientLock);
1424 client.clear();
1425 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07001426 recordTrack.clear();
Mathias Agopian65ab4712010-07-14 17:59:35 -07001427 goto Exit;
1428 }
1429
Glenn Kastend776ac62014-05-07 09:16:09 -07001430 cblk = recordTrack->getCblk();
1431 buffers = recordTrack->getBuffers();
1432
Glenn Kasten2fc14732013-08-05 14:58:14 -07001433 // return handle to client
Mathias Agopian65ab4712010-07-14 17:59:35 -07001434 recordHandle = new RecordHandle(recordTrack);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001435
1436Exit:
Glenn Kasten9156ef32013-08-06 15:39:08 -07001437 *status = lStatus;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001438 return recordHandle;
1439}
1440
Eric Laurentb8ba0a92011-08-07 16:32:26 -07001441
1442
Mathias Agopian65ab4712010-07-14 17:59:35 -07001443// ----------------------------------------------------------------------------
1444
Eric Laurenta4c5a552012-03-29 10:12:40 -07001445audio_module_handle_t AudioFlinger::loadHwModule(const char *name)
1446{
1447 if (!settingsAllowed()) {
1448 return 0;
1449 }
1450 Mutex::Autolock _l(mLock);
1451 return loadHwModule_l(name);
1452}
1453
1454// loadHwModule_l() must be called with AudioFlinger::mLock held
1455audio_module_handle_t AudioFlinger::loadHwModule_l(const char *name)
1456{
1457 for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
1458 if (strncmp(mAudioHwDevs.valueAt(i)->moduleName(), name, strlen(name)) == 0) {
1459 ALOGW("loadHwModule() module %s already loaded", name);
1460 return mAudioHwDevs.keyAt(i);
1461 }
1462 }
1463
Eric Laurenta4c5a552012-03-29 10:12:40 -07001464 audio_hw_device_t *dev;
1465
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001466 int rc = load_audio_interface(name, &dev);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001467 if (rc) {
1468 ALOGI("loadHwModule() error %d loading module %s ", rc, name);
1469 return 0;
1470 }
1471
1472 mHardwareStatus = AUDIO_HW_INIT;
1473 rc = dev->init_check(dev);
1474 mHardwareStatus = AUDIO_HW_IDLE;
1475 if (rc) {
1476 ALOGI("loadHwModule() init check error %d for module %s ", rc, name);
1477 return 0;
1478 }
1479
John Grossmanee578c02012-07-23 17:05:46 -07001480 // Check and cache this HAL's level of support for master mute and master
1481 // volume. If this is the first HAL opened, and it supports the get
1482 // methods, use the initial values provided by the HAL as the current
1483 // master mute and volume settings.
1484
1485 AudioHwDevice::Flags flags = static_cast<AudioHwDevice::Flags>(0);
1486 { // scope for auto-lock pattern
Eric Laurenta4c5a552012-03-29 10:12:40 -07001487 AutoMutex lock(mHardwareLock);
John Grossmanee578c02012-07-23 17:05:46 -07001488
1489 if (0 == mAudioHwDevs.size()) {
1490 mHardwareStatus = AUDIO_HW_GET_MASTER_VOLUME;
1491 if (NULL != dev->get_master_volume) {
1492 float mv;
1493 if (OK == dev->get_master_volume(dev, &mv)) {
1494 mMasterVolume = mv;
1495 }
1496 }
1497
1498 mHardwareStatus = AUDIO_HW_GET_MASTER_MUTE;
1499 if (NULL != dev->get_master_mute) {
1500 bool mm;
1501 if (OK == dev->get_master_mute(dev, &mm)) {
1502 mMasterMute = mm;
1503 }
1504 }
1505 }
1506
Eric Laurenta4c5a552012-03-29 10:12:40 -07001507 mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME;
John Grossmanee578c02012-07-23 17:05:46 -07001508 if ((NULL != dev->set_master_volume) &&
1509 (OK == dev->set_master_volume(dev, mMasterVolume))) {
1510 flags = static_cast<AudioHwDevice::Flags>(flags |
1511 AudioHwDevice::AHWD_CAN_SET_MASTER_VOLUME);
1512 }
1513
1514 mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE;
1515 if ((NULL != dev->set_master_mute) &&
1516 (OK == dev->set_master_mute(dev, mMasterMute))) {
1517 flags = static_cast<AudioHwDevice::Flags>(flags |
1518 AudioHwDevice::AHWD_CAN_SET_MASTER_MUTE);
1519 }
1520
Eric Laurenta4c5a552012-03-29 10:12:40 -07001521 mHardwareStatus = AUDIO_HW_IDLE;
1522 }
1523
1524 audio_module_handle_t handle = nextUniqueId();
John Grossmanee578c02012-07-23 17:05:46 -07001525 mAudioHwDevs.add(handle, new AudioHwDevice(name, dev, flags));
Eric Laurenta4c5a552012-03-29 10:12:40 -07001526
1527 ALOGI("loadHwModule() Loaded %s audio interface from %s (%s) handle %d",
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001528 name, dev->common.module->name, dev->common.module->id, handle);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001529
1530 return handle;
1531
1532}
1533
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001534// ----------------------------------------------------------------------------
1535
Glenn Kasten3b16c762012-11-14 08:44:39 -08001536uint32_t AudioFlinger::getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001537{
1538 Mutex::Autolock _l(mLock);
1539 PlaybackThread *thread = primaryPlaybackThread_l();
1540 return thread != NULL ? thread->sampleRate() : 0;
1541}
1542
Glenn Kastene33054e2012-11-14 12:54:39 -08001543size_t AudioFlinger::getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001544{
1545 Mutex::Autolock _l(mLock);
1546 PlaybackThread *thread = primaryPlaybackThread_l();
1547 return thread != NULL ? thread->frameCountHAL() : 0;
1548}
1549
1550// ----------------------------------------------------------------------------
1551
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001552status_t AudioFlinger::setLowRamDevice(bool isLowRamDevice)
1553{
1554 uid_t uid = IPCThreadState::self()->getCallingUid();
1555 if (uid != AID_SYSTEM) {
1556 return PERMISSION_DENIED;
1557 }
1558 Mutex::Autolock _l(mLock);
1559 if (mIsDeviceTypeKnown) {
1560 return INVALID_OPERATION;
1561 }
1562 mIsLowRamDevice = isLowRamDevice;
1563 mIsDeviceTypeKnown = true;
1564 return NO_ERROR;
1565}
1566
1567// ----------------------------------------------------------------------------
1568
Eric Laurenta4c5a552012-03-29 10:12:40 -07001569audio_io_handle_t AudioFlinger::openOutput(audio_module_handle_t module,
1570 audio_devices_t *pDevices,
1571 uint32_t *pSamplingRate,
1572 audio_format_t *pFormat,
1573 audio_channel_mask_t *pChannelMask,
1574 uint32_t *pLatencyMs,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +00001575 audio_output_flags_t flags,
1576 const audio_offload_info_t *offloadInfo)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001577{
Richard Fitzgeraldad3af332013-03-25 16:54:37 +00001578 struct audio_config config;
Glenn Kastenfb872cc2013-08-06 10:45:39 -07001579 memset(&config, 0, sizeof(config));
Richard Fitzgeraldad3af332013-03-25 16:54:37 +00001580 config.sample_rate = (pSamplingRate != NULL) ? *pSamplingRate : 0;
1581 config.channel_mask = (pChannelMask != NULL) ? *pChannelMask : 0;
1582 config.format = (pFormat != NULL) ? *pFormat : AUDIO_FORMAT_DEFAULT;
Glenn Kasten937098b2013-06-26 11:19:36 -07001583 if (offloadInfo != NULL) {
Richard Fitzgeraldad3af332013-03-25 16:54:37 +00001584 config.offload_info = *offloadInfo;
1585 }
1586
Eric Laurentbfb1b832013-01-07 09:53:42 -08001587 ALOGV("openOutput(), module %d Device %x, SamplingRate %d, Format %#08x, Channels %x, flags %x",
Eric Laurenta4c5a552012-03-29 10:12:40 -07001588 module,
Glenn Kastenbb4350d2012-07-03 15:56:38 -07001589 (pDevices != NULL) ? *pDevices : 0,
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001590 config.sample_rate,
1591 config.format,
1592 config.channel_mask,
Eric Laurenta4c5a552012-03-29 10:12:40 -07001593 flags);
Eric Laurentbfb1b832013-01-07 09:53:42 -08001594 ALOGV("openOutput(), offloadInfo %p version 0x%04x",
Glenn Kastene198c362013-08-13 09:13:36 -07001595 offloadInfo, offloadInfo == NULL ? -1 : offloadInfo->version);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001596
Glenn Kasten45faf7e2014-01-17 10:23:01 -08001597 if (pDevices == NULL || *pDevices == AUDIO_DEVICE_NONE) {
Glenn Kasten142f5192014-03-25 17:44:59 -07001598 return AUDIO_IO_HANDLE_NONE;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001599 }
Dima Zavin799a70e2011-04-18 16:57:27 -07001600
Mathias Agopian65ab4712010-07-14 17:59:35 -07001601 Mutex::Autolock _l(mLock);
1602
Glenn Kasten32550952013-08-06 10:45:10 -07001603 AudioHwDevice *outHwDev = findSuitableHwDev_l(module, *pDevices);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001604 if (outHwDev == NULL) {
Glenn Kasten142f5192014-03-25 17:44:59 -07001605 return AUDIO_IO_HANDLE_NONE;
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001606 }
Dima Zavin799a70e2011-04-18 16:57:27 -07001607
John Grossmanee578c02012-07-23 17:05:46 -07001608 audio_hw_device_t *hwDevHal = outHwDev->hwDevice();
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001609 audio_io_handle_t id = nextUniqueId();
1610
Glenn Kasten8abf44d2012-02-02 14:16:03 -08001611 mHardwareStatus = AUDIO_HW_OUTPUT_OPEN;
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001612
Glenn Kasten32550952013-08-06 10:45:10 -07001613 audio_stream_out_t *outStream = NULL;
Andy Hung6146c082014-03-18 11:56:15 -07001614
1615 // FOR TESTING ONLY:
1616 // Enable increased sink precision for mixing mode if kEnableExtendedPrecision is true.
1617 if (kEnableExtendedPrecision && // Check only for Normal Mixing mode
1618 !(flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT))) {
1619 // Update format
1620 //config.format = AUDIO_FORMAT_PCM_FLOAT;
1621 //config.format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
1622 //config.format = AUDIO_FORMAT_PCM_32_BIT;
1623 //config.format = AUDIO_FORMAT_PCM_8_24_BIT;
1624 // ALOGV("openOutput() upgrading format to %#08x", config.format);
1625 }
1626
Glenn Kasten34542ac2013-06-26 11:29:02 -07001627 status_t status = hwDevHal->open_output_stream(hwDevHal,
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001628 id,
1629 *pDevices,
1630 (audio_output_flags_t)flags,
1631 &config,
1632 &outStream);
1633
Glenn Kasten8abf44d2012-02-02 14:16:03 -08001634 mHardwareStatus = AUDIO_HW_IDLE;
Eric Laurentbfb1b832013-01-07 09:53:42 -08001635 ALOGV("openOutput() openOutputStream returned output %p, SamplingRate %d, Format %#08x, "
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001636 "Channels %x, status %d",
Dima Zavin799a70e2011-04-18 16:57:27 -07001637 outStream,
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001638 config.sample_rate,
1639 config.format,
1640 config.channel_mask,
Mathias Agopian65ab4712010-07-14 17:59:35 -07001641 status);
1642
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001643 if (status == NO_ERROR && outStream != NULL) {
Eric Laurentbfb1b832013-01-07 09:53:42 -08001644 AudioStreamOut *output = new AudioStreamOut(outHwDev, outStream, flags);
Dima Zavin799a70e2011-04-18 16:57:27 -07001645
Glenn Kasten32550952013-08-06 10:45:10 -07001646 PlaybackThread *thread;
Eric Laurentbfb1b832013-01-07 09:53:42 -08001647 if (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
1648 thread = new OffloadThread(this, output, id, *pDevices);
1649 ALOGV("openOutput() created offload output: ID %d thread %p", id, thread);
Andy Hung6146c082014-03-18 11:56:15 -07001650 } else if ((flags & AUDIO_OUTPUT_FLAG_DIRECT)
1651 || !isValidPcmSinkFormat(config.format)
1652 || (config.channel_mask != AUDIO_CHANNEL_OUT_STEREO)) {
Mathias Agopian65ab4712010-07-14 17:59:35 -07001653 thread = new DirectOutputThread(this, output, id, *pDevices);
Steve Block3856b092011-10-20 11:56:00 +01001654 ALOGV("openOutput() created direct output: ID %d thread %p", id, thread);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001655 } else {
1656 thread = new MixerThread(this, output, id, *pDevices);
Steve Block3856b092011-10-20 11:56:00 +01001657 ALOGV("openOutput() created mixer output: ID %d thread %p", id, thread);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001658 }
1659 mPlaybackThreads.add(id, thread);
1660
Glenn Kasten7c027242012-12-26 14:43:16 -08001661 if (pSamplingRate != NULL) {
1662 *pSamplingRate = config.sample_rate;
1663 }
1664 if (pFormat != NULL) {
1665 *pFormat = config.format;
1666 }
1667 if (pChannelMask != NULL) {
1668 *pChannelMask = config.channel_mask;
1669 }
1670 if (pLatencyMs != NULL) {
1671 *pLatencyMs = thread->latency();
1672 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07001673
1674 // notify client processes of the new output creation
Eric Laurent021cf962014-05-13 10:18:14 -07001675 thread->audioConfigChanged(AudioSystem::OUTPUT_OPENED);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001676
1677 // the first primary output opened designates the primary hw device
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001678 if ((mPrimaryHardwareDev == NULL) && (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) {
Eric Laurenta4c5a552012-03-29 10:12:40 -07001679 ALOGI("Using module %d has the primary audio interface", module);
1680 mPrimaryHardwareDev = outHwDev;
1681
1682 AutoMutex lock(mHardwareLock);
1683 mHardwareStatus = AUDIO_HW_SET_MODE;
John Grossmanee578c02012-07-23 17:05:46 -07001684 hwDevHal->set_mode(hwDevHal, mMode);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001685 mHardwareStatus = AUDIO_HW_IDLE;
Glenn Kasten4ea00a22014-06-02 08:29:22 -07001686
1687 mPrimaryOutputSampleRate = config.sample_rate;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001688 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07001689 return id;
1690 }
1691
Glenn Kasten142f5192014-03-25 17:44:59 -07001692 return AUDIO_IO_HANDLE_NONE;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001693}
1694
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001695audio_io_handle_t AudioFlinger::openDuplicateOutput(audio_io_handle_t output1,
1696 audio_io_handle_t output2)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001697{
1698 Mutex::Autolock _l(mLock);
1699 MixerThread *thread1 = checkMixerThread_l(output1);
1700 MixerThread *thread2 = checkMixerThread_l(output2);
1701
1702 if (thread1 == NULL || thread2 == NULL) {
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001703 ALOGW("openDuplicateOutput() wrong output mixer type for output %d or %d", output1,
1704 output2);
Glenn Kasten142f5192014-03-25 17:44:59 -07001705 return AUDIO_IO_HANDLE_NONE;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001706 }
1707
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001708 audio_io_handle_t id = nextUniqueId();
Mathias Agopian65ab4712010-07-14 17:59:35 -07001709 DuplicatingThread *thread = new DuplicatingThread(this, thread1, id);
1710 thread->addOutputTrack(thread2);
1711 mPlaybackThreads.add(id, thread);
1712 // notify client processes of the new output creation
Eric Laurent021cf962014-05-13 10:18:14 -07001713 thread->audioConfigChanged(AudioSystem::OUTPUT_OPENED);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001714 return id;
1715}
1716
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001717status_t AudioFlinger::closeOutput(audio_io_handle_t output)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001718{
Glenn Kastend96c5722012-04-25 13:44:49 -07001719 return closeOutput_nonvirtual(output);
1720}
1721
1722status_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output)
1723{
Mathias Agopian65ab4712010-07-14 17:59:35 -07001724 // keep strong reference on the playback thread so that
1725 // it is not destroyed while exit() is executed
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001726 sp<PlaybackThread> thread;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001727 {
1728 Mutex::Autolock _l(mLock);
1729 thread = checkPlaybackThread_l(output);
1730 if (thread == NULL) {
1731 return BAD_VALUE;
1732 }
1733
Steve Block3856b092011-10-20 11:56:00 +01001734 ALOGV("closeOutput() %d", output);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001735
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001736 if (thread->type() == ThreadBase::MIXER) {
Mathias Agopian65ab4712010-07-14 17:59:35 -07001737 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001738 if (mPlaybackThreads.valueAt(i)->type() == ThreadBase::DUPLICATING) {
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001739 DuplicatingThread *dupThread =
1740 (DuplicatingThread *)mPlaybackThreads.valueAt(i).get();
Mathias Agopian65ab4712010-07-14 17:59:35 -07001741 dupThread->removeOutputTrack((MixerThread *)thread.get());
Eric Laurentbfb1b832013-01-07 09:53:42 -08001742
1743 }
1744 }
1745 }
1746
1747
1748 mPlaybackThreads.removeItem(output);
1749 // save all effects to the default thread
1750 if (mPlaybackThreads.size()) {
1751 PlaybackThread *dstThread = checkPlaybackThread_l(mPlaybackThreads.keyAt(0));
1752 if (dstThread != NULL) {
1753 // audioflinger lock is held here so the acquisition order of thread locks does not
1754 // matter
1755 Mutex::Autolock _dl(dstThread->mLock);
1756 Mutex::Autolock _sl(thread->mLock);
1757 Vector< sp<EffectChain> > effectChains = thread->getEffectChains_l();
1758 for (size_t i = 0; i < effectChains.size(); i ++) {
1759 moveEffectChain_l(effectChains[i]->sessionId(), thread.get(), dstThread, true);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001760 }
1761 }
1762 }
Eric Laurent021cf962014-05-13 10:18:14 -07001763 audioConfigChanged(AudioSystem::OUTPUT_CLOSED, output, NULL);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001764 }
1765 thread->exit();
Glenn Kastenb28686f2012-01-06 08:39:38 -08001766 // The thread entity (active unit of execution) is no longer running here,
1767 // but the ThreadBase container still exists.
Mathias Agopian65ab4712010-07-14 17:59:35 -07001768
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001769 if (thread->type() != ThreadBase::DUPLICATING) {
Eric Laurentb8ba0a92011-08-07 16:32:26 -07001770 AudioStreamOut *out = thread->clearOutput();
Glenn Kasten5798d4e2012-03-08 12:18:35 -08001771 ALOG_ASSERT(out != NULL, "out shouldn't be NULL");
Eric Laurentb8ba0a92011-08-07 16:32:26 -07001772 // from now on thread->mOutput is NULL
John Grossmanee578c02012-07-23 17:05:46 -07001773 out->hwDev()->close_output_stream(out->hwDev(), out->stream);
Dima Zavin799a70e2011-04-18 16:57:27 -07001774 delete out;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001775 }
1776 return NO_ERROR;
1777}
1778
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001779status_t AudioFlinger::suspendOutput(audio_io_handle_t output)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001780{
1781 Mutex::Autolock _l(mLock);
1782 PlaybackThread *thread = checkPlaybackThread_l(output);
1783
1784 if (thread == NULL) {
1785 return BAD_VALUE;
1786 }
1787
Steve Block3856b092011-10-20 11:56:00 +01001788 ALOGV("suspendOutput() %d", output);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001789 thread->suspend();
1790
1791 return NO_ERROR;
1792}
1793
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001794status_t AudioFlinger::restoreOutput(audio_io_handle_t output)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001795{
1796 Mutex::Autolock _l(mLock);
1797 PlaybackThread *thread = checkPlaybackThread_l(output);
1798
1799 if (thread == NULL) {
1800 return BAD_VALUE;
1801 }
1802
Steve Block3856b092011-10-20 11:56:00 +01001803 ALOGV("restoreOutput() %d", output);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001804
1805 thread->restore();
1806
1807 return NO_ERROR;
1808}
1809
Eric Laurenta4c5a552012-03-29 10:12:40 -07001810audio_io_handle_t AudioFlinger::openInput(audio_module_handle_t module,
1811 audio_devices_t *pDevices,
1812 uint32_t *pSamplingRate,
1813 audio_format_t *pFormat,
Glenn Kasten254af182012-07-03 14:59:05 -07001814 audio_channel_mask_t *pChannelMask)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001815{
Richard Fitzgeraldad3af332013-03-25 16:54:37 +00001816 struct audio_config config;
Glenn Kastenfb872cc2013-08-06 10:45:39 -07001817 memset(&config, 0, sizeof(config));
Richard Fitzgeraldad3af332013-03-25 16:54:37 +00001818 config.sample_rate = (pSamplingRate != NULL) ? *pSamplingRate : 0;
1819 config.channel_mask = (pChannelMask != NULL) ? *pChannelMask : 0;
1820 config.format = (pFormat != NULL) ? *pFormat : AUDIO_FORMAT_DEFAULT;
1821
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001822 uint32_t reqSamplingRate = config.sample_rate;
1823 audio_format_t reqFormat = config.format;
Glenn Kastenf506e942013-08-06 10:49:43 -07001824 audio_channel_mask_t reqChannelMask = config.channel_mask;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001825
Glenn Kasten45faf7e2014-01-17 10:23:01 -08001826 if (pDevices == NULL || *pDevices == AUDIO_DEVICE_NONE) {
Mathias Agopian65ab4712010-07-14 17:59:35 -07001827 return 0;
1828 }
Dima Zavin799a70e2011-04-18 16:57:27 -07001829
Mathias Agopian65ab4712010-07-14 17:59:35 -07001830 Mutex::Autolock _l(mLock);
1831
Glenn Kasten32550952013-08-06 10:45:10 -07001832 AudioHwDevice *inHwDev = findSuitableHwDev_l(module, *pDevices);
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001833 if (inHwDev == NULL) {
Dima Zavin799a70e2011-04-18 16:57:27 -07001834 return 0;
Glenn Kasten6e2ebe92013-08-13 09:14:51 -07001835 }
Dima Zavin799a70e2011-04-18 16:57:27 -07001836
John Grossmanee578c02012-07-23 17:05:46 -07001837 audio_hw_device_t *inHwHal = inHwDev->hwDevice();
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001838 audio_io_handle_t id = nextUniqueId();
1839
Glenn Kasten32550952013-08-06 10:45:10 -07001840 audio_stream_in_t *inStream = NULL;
1841 status_t status = inHwHal->open_input_stream(inHwHal, id, *pDevices, &config,
Dima Zavin799a70e2011-04-18 16:57:27 -07001842 &inStream);
Glenn Kastencac3daa2014-02-07 09:47:14 -08001843 ALOGV("openInput() openInputStream returned input %p, SamplingRate %d, Format %#x, Channels %x, "
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001844 "status %d",
Dima Zavin799a70e2011-04-18 16:57:27 -07001845 inStream,
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001846 config.sample_rate,
1847 config.format,
1848 config.channel_mask,
Mathias Agopian65ab4712010-07-14 17:59:35 -07001849 status);
1850
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001851 // If the input could not be opened with the requested parameters and we can handle the
1852 // conversion internally, try to open again with the proposed parameters. The AudioFlinger can
1853 // resample the input and do mono to stereo or stereo to mono conversions on 16 bit PCM inputs.
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001854 if (status == BAD_VALUE &&
1855 reqFormat == config.format && config.format == AUDIO_FORMAT_PCM_16_BIT &&
1856 (config.sample_rate <= 2 * reqSamplingRate) &&
Andy Hunge5412692014-05-16 11:25:07 -07001857 (audio_channel_count_from_in_mask(config.channel_mask) <= FCC_2) &&
1858 (audio_channel_count_from_in_mask(reqChannelMask) <= FCC_2)) {
Glenn Kasten85948432013-08-19 12:09:05 -07001859 // FIXME describe the change proposed by HAL (save old values so we can log them here)
Glenn Kasten254af182012-07-03 14:59:05 -07001860 ALOGV("openInput() reopening with proposed sampling rate and channel mask");
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001861 inStream = NULL;
John Grossmanee578c02012-07-23 17:05:46 -07001862 status = inHwHal->open_input_stream(inHwHal, id, *pDevices, &config, &inStream);
Glenn Kasten85948432013-08-19 12:09:05 -07001863 // FIXME log this new status; HAL should not propose any further changes
Mathias Agopian65ab4712010-07-14 17:59:35 -07001864 }
1865
Eric Laurentf7ffb8b2012-04-14 09:06:57 -07001866 if (status == NO_ERROR && inStream != NULL) {
Glenn Kastend06785b2012-09-30 12:29:28 -07001867
Glenn Kasten46909e72013-02-26 09:20:22 -08001868#ifdef TEE_SINK
Glenn Kastend06785b2012-09-30 12:29:28 -07001869 // Try to re-use most recently used Pipe to archive a copy of input for dumpsys,
1870 // or (re-)create if current Pipe is idle and does not match the new format
1871 sp<NBAIO_Sink> teeSink;
Glenn Kastend06785b2012-09-30 12:29:28 -07001872 enum {
1873 TEE_SINK_NO, // don't copy input
1874 TEE_SINK_NEW, // copy input using a new pipe
1875 TEE_SINK_OLD, // copy input using an existing pipe
1876 } kind;
1877 NBAIO_Format format = Format_from_SR_C(inStream->common.get_sample_rate(&inStream->common),
Andy Hunge5412692014-05-16 11:25:07 -07001878 audio_channel_count_from_in_mask(
1879 inStream->common.get_channels(&inStream->common)));
Glenn Kastenda6ef132013-01-10 12:31:01 -08001880 if (!mTeeSinkInputEnabled) {
1881 kind = TEE_SINK_NO;
Glenn Kasten6e0d67d2014-01-31 09:41:08 -08001882 } else if (!Format_isValid(format)) {
Glenn Kastend06785b2012-09-30 12:29:28 -07001883 kind = TEE_SINK_NO;
1884 } else if (mRecordTeeSink == 0) {
1885 kind = TEE_SINK_NEW;
1886 } else if (mRecordTeeSink->getStrongCount() != 1) {
1887 kind = TEE_SINK_NO;
Glenn Kastenf66b4222014-02-20 10:23:28 -08001888 } else if (Format_isEqual(format, mRecordTeeSink->format())) {
Glenn Kastend06785b2012-09-30 12:29:28 -07001889 kind = TEE_SINK_OLD;
1890 } else {
1891 kind = TEE_SINK_NEW;
1892 }
1893 switch (kind) {
1894 case TEE_SINK_NEW: {
Glenn Kastenda6ef132013-01-10 12:31:01 -08001895 Pipe *pipe = new Pipe(mTeeSinkInputFrames, format);
Glenn Kastend06785b2012-09-30 12:29:28 -07001896 size_t numCounterOffers = 0;
1897 const NBAIO_Format offers[1] = {format};
1898 ssize_t index = pipe->negotiate(offers, 1, NULL, numCounterOffers);
1899 ALOG_ASSERT(index == 0);
1900 PipeReader *pipeReader = new PipeReader(*pipe);
1901 numCounterOffers = 0;
1902 index = pipeReader->negotiate(offers, 1, NULL, numCounterOffers);
1903 ALOG_ASSERT(index == 0);
1904 mRecordTeeSink = pipe;
1905 mRecordTeeSource = pipeReader;
1906 teeSink = pipe;
1907 }
1908 break;
1909 case TEE_SINK_OLD:
1910 teeSink = mRecordTeeSink;
1911 break;
1912 case TEE_SINK_NO:
1913 default:
1914 break;
1915 }
Glenn Kasten46909e72013-02-26 09:20:22 -08001916#endif
Glenn Kastenda6ef132013-01-10 12:31:01 -08001917
Dima Zavin799a70e2011-04-18 16:57:27 -07001918 AudioStreamIn *input = new AudioStreamIn(inHwDev, inStream);
1919
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001920 // Start record thread
Glenn Kasten34af0262013-07-30 11:52:39 -07001921 // RecordThread requires both input and output device indication to forward to audio
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001922 // pre processing modules
Glenn Kasten32550952013-08-06 10:45:10 -07001923 RecordThread *thread = new RecordThread(this,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001924 input,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001925 id,
Eric Laurentd3922f72013-02-01 17:57:04 -08001926 primaryOutputDevice_l(),
Glenn Kasten46909e72013-02-26 09:20:22 -08001927 *pDevices
1928#ifdef TEE_SINK
1929 , teeSink
1930#endif
1931 );
Mathias Agopian65ab4712010-07-14 17:59:35 -07001932 mRecordThreads.add(id, thread);
Steve Block3856b092011-10-20 11:56:00 +01001933 ALOGV("openInput() created record thread: ID %d thread %p", id, thread);
Glenn Kasten7c027242012-12-26 14:43:16 -08001934 if (pSamplingRate != NULL) {
1935 *pSamplingRate = reqSamplingRate;
1936 }
1937 if (pFormat != NULL) {
1938 *pFormat = config.format;
1939 }
1940 if (pChannelMask != NULL) {
Glenn Kastenf506e942013-08-06 10:49:43 -07001941 *pChannelMask = reqChannelMask;
Glenn Kasten7c027242012-12-26 14:43:16 -08001942 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07001943
Mathias Agopian65ab4712010-07-14 17:59:35 -07001944 // notify client processes of the new input creation
Eric Laurent021cf962014-05-13 10:18:14 -07001945 thread->audioConfigChanged(AudioSystem::INPUT_OPENED);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001946 return id;
1947 }
1948
1949 return 0;
1950}
1951
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001952status_t AudioFlinger::closeInput(audio_io_handle_t input)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001953{
Glenn Kastend96c5722012-04-25 13:44:49 -07001954 return closeInput_nonvirtual(input);
1955}
1956
1957status_t AudioFlinger::closeInput_nonvirtual(audio_io_handle_t input)
1958{
Mathias Agopian65ab4712010-07-14 17:59:35 -07001959 // keep strong reference on the record thread so that
1960 // it is not destroyed while exit() is executed
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001961 sp<RecordThread> thread;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001962 {
1963 Mutex::Autolock _l(mLock);
1964 thread = checkRecordThread_l(input);
Glenn Kastend5903ec2012-03-18 10:33:27 -07001965 if (thread == 0) {
Mathias Agopian65ab4712010-07-14 17:59:35 -07001966 return BAD_VALUE;
1967 }
1968
Steve Block3856b092011-10-20 11:56:00 +01001969 ALOGV("closeInput() %d", input);
Eric Laurent021cf962014-05-13 10:18:14 -07001970 audioConfigChanged(AudioSystem::INPUT_CLOSED, input, NULL);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001971 mRecordThreads.removeItem(input);
1972 }
1973 thread->exit();
Glenn Kastenb28686f2012-01-06 08:39:38 -08001974 // The thread entity (active unit of execution) is no longer running here,
1975 // but the ThreadBase container still exists.
Mathias Agopian65ab4712010-07-14 17:59:35 -07001976
Eric Laurentb8ba0a92011-08-07 16:32:26 -07001977 AudioStreamIn *in = thread->clearInput();
Glenn Kasten5798d4e2012-03-08 12:18:35 -08001978 ALOG_ASSERT(in != NULL, "in shouldn't be NULL");
Eric Laurentb8ba0a92011-08-07 16:32:26 -07001979 // from now on thread->mInput is NULL
John Grossmanee578c02012-07-23 17:05:46 -07001980 in->hwDev()->close_input_stream(in->hwDev(), in->stream);
Dima Zavin799a70e2011-04-18 16:57:27 -07001981 delete in;
Mathias Agopian65ab4712010-07-14 17:59:35 -07001982
1983 return NO_ERROR;
1984}
1985
Glenn Kastend2304db2014-02-03 07:40:31 -08001986status_t AudioFlinger::invalidateStream(audio_stream_type_t stream)
Mathias Agopian65ab4712010-07-14 17:59:35 -07001987{
1988 Mutex::Autolock _l(mLock);
Glenn Kastend2304db2014-02-03 07:40:31 -08001989 ALOGV("invalidateStream() stream %d", stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -07001990
1991 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
1992 PlaybackThread *thread = mPlaybackThreads.valueAt(i).get();
Eric Laurent22167852012-06-20 12:26:32 -07001993 thread->invalidateTracks(stream);
Eric Laurentde070132010-07-13 04:45:46 -07001994 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07001995
1996 return NO_ERROR;
1997}
1998
1999
2000int AudioFlinger::newAudioSessionId()
2001{
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002002 return nextUniqueId();
Mathias Agopian65ab4712010-07-14 17:59:35 -07002003}
2004
Marco Nelissend457c972014-02-11 08:47:07 -08002005void AudioFlinger::acquireAudioSessionId(int audioSession, pid_t pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002006{
2007 Mutex::Autolock _l(mLock);
Glenn Kastenbb001922012-02-03 11:10:26 -08002008 pid_t caller = IPCThreadState::self()->getCallingPid();
Marco Nelissend457c972014-02-11 08:47:07 -08002009 ALOGV("acquiring %d from %d, for %d", audioSession, caller, pid);
2010 if (pid != -1 && (caller == getpid_cached)) {
2011 caller = pid;
2012 }
Eric Laurentd1b28d42013-09-18 18:47:13 -07002013
Eric Laurent021cf962014-05-13 10:18:14 -07002014 {
2015 Mutex::Autolock _cl(mClientLock);
2016 // Ignore requests received from processes not known as notification client. The request
2017 // is likely proxied by mediaserver (e.g CameraService) and releaseAudioSessionId() can be
2018 // called from a different pid leaving a stale session reference. Also we don't know how
2019 // to clear this reference if the client process dies.
2020 if (mNotificationClients.indexOfKey(caller) < 0) {
2021 ALOGW("acquireAudioSessionId() unknown client %d for session %d", caller, audioSession);
2022 return;
2023 }
Eric Laurentd1b28d42013-09-18 18:47:13 -07002024 }
2025
Glenn Kasten8d6a2442012-02-08 14:04:28 -08002026 size_t num = mAudioSessionRefs.size();
2027 for (size_t i = 0; i< num; i++) {
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002028 AudioSessionRef *ref = mAudioSessionRefs.editItemAt(i);
Glenn Kasten012ca6b2012-03-06 11:22:01 -08002029 if (ref->mSessionid == audioSession && ref->mPid == caller) {
2030 ref->mCnt++;
2031 ALOGV(" incremented refcount to %d", ref->mCnt);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002032 return;
2033 }
2034 }
Glenn Kasten84afa3b2012-01-25 15:28:08 -08002035 mAudioSessionRefs.push(new AudioSessionRef(audioSession, caller));
2036 ALOGV(" added new entry for %d", audioSession);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002037}
2038
Marco Nelissend457c972014-02-11 08:47:07 -08002039void AudioFlinger::releaseAudioSessionId(int audioSession, pid_t pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002040{
2041 Mutex::Autolock _l(mLock);
Glenn Kastenbb001922012-02-03 11:10:26 -08002042 pid_t caller = IPCThreadState::self()->getCallingPid();
Marco Nelissend457c972014-02-11 08:47:07 -08002043 ALOGV("releasing %d from %d for %d", audioSession, caller, pid);
2044 if (pid != -1 && (caller == getpid_cached)) {
2045 caller = pid;
2046 }
Glenn Kasten8d6a2442012-02-08 14:04:28 -08002047 size_t num = mAudioSessionRefs.size();
2048 for (size_t i = 0; i< num; i++) {
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002049 AudioSessionRef *ref = mAudioSessionRefs.itemAt(i);
Glenn Kasten012ca6b2012-03-06 11:22:01 -08002050 if (ref->mSessionid == audioSession && ref->mPid == caller) {
2051 ref->mCnt--;
2052 ALOGV(" decremented refcount to %d", ref->mCnt);
2053 if (ref->mCnt == 0) {
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002054 mAudioSessionRefs.removeAt(i);
2055 delete ref;
2056 purgeStaleEffects_l();
2057 }
2058 return;
2059 }
2060 }
Eric Laurentd1b28d42013-09-18 18:47:13 -07002061 // If the caller is mediaserver it is likely that the session being released was acquired
2062 // on behalf of a process not in notification clients and we ignore the warning.
2063 ALOGW_IF(caller != getpid_cached, "session id %d not found for pid %d", audioSession, caller);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002064}
2065
2066void AudioFlinger::purgeStaleEffects_l() {
2067
Steve Block3856b092011-10-20 11:56:00 +01002068 ALOGV("purging stale effects");
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002069
2070 Vector< sp<EffectChain> > chains;
2071
2072 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
2073 sp<PlaybackThread> t = mPlaybackThreads.valueAt(i);
2074 for (size_t j = 0; j < t->mEffectChains.size(); j++) {
2075 sp<EffectChain> ec = t->mEffectChains[j];
Marco Nelissen0270b182011-08-12 14:14:39 -07002076 if (ec->sessionId() > AUDIO_SESSION_OUTPUT_MIX) {
2077 chains.push(ec);
2078 }
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002079 }
2080 }
2081 for (size_t i = 0; i < mRecordThreads.size(); i++) {
2082 sp<RecordThread> t = mRecordThreads.valueAt(i);
2083 for (size_t j = 0; j < t->mEffectChains.size(); j++) {
2084 sp<EffectChain> ec = t->mEffectChains[j];
2085 chains.push(ec);
2086 }
2087 }
2088
2089 for (size_t i = 0; i < chains.size(); i++) {
2090 sp<EffectChain> ec = chains[i];
2091 int sessionid = ec->sessionId();
2092 sp<ThreadBase> t = ec->mThread.promote();
2093 if (t == 0) {
2094 continue;
2095 }
2096 size_t numsessionrefs = mAudioSessionRefs.size();
2097 bool found = false;
2098 for (size_t k = 0; k < numsessionrefs; k++) {
2099 AudioSessionRef *ref = mAudioSessionRefs.itemAt(k);
Glenn Kasten012ca6b2012-03-06 11:22:01 -08002100 if (ref->mSessionid == sessionid) {
Steve Block3856b092011-10-20 11:56:00 +01002101 ALOGV(" session %d still exists for %d with %d refs",
Glenn Kastene53b9ea2012-03-12 16:29:55 -07002102 sessionid, ref->mPid, ref->mCnt);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002103 found = true;
2104 break;
2105 }
2106 }
2107 if (!found) {
Glenn Kastene198c362013-08-13 09:13:36 -07002108 Mutex::Autolock _l(t->mLock);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002109 // remove all effects from the chain
2110 while (ec->mEffects.size()) {
2111 sp<EffectModule> effect = ec->mEffects[0];
2112 effect->unPin();
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002113 t->removeEffect_l(effect);
Eric Laurenta5f44eb2012-06-25 11:38:29 -07002114 if (effect->purgeHandles()) {
2115 t->checkSuspendOnEffectEnabled_l(effect, false, effect->sessionId());
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002116 }
2117 AudioSystem::unregisterEffect(effect->id());
2118 }
2119 }
2120 }
2121 return;
2122}
2123
Mathias Agopian65ab4712010-07-14 17:59:35 -07002124// checkPlaybackThread_l() must be called with AudioFlinger::mLock held
Glenn Kasten72ef00d2012-01-17 11:09:42 -08002125AudioFlinger::PlaybackThread *AudioFlinger::checkPlaybackThread_l(audio_io_handle_t output) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07002126{
Glenn Kastena1117922012-01-26 10:53:32 -08002127 return mPlaybackThreads.valueFor(output).get();
Mathias Agopian65ab4712010-07-14 17:59:35 -07002128}
2129
2130// checkMixerThread_l() must be called with AudioFlinger::mLock held
Glenn Kasten72ef00d2012-01-17 11:09:42 -08002131AudioFlinger::MixerThread *AudioFlinger::checkMixerThread_l(audio_io_handle_t output) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07002132{
2133 PlaybackThread *thread = checkPlaybackThread_l(output);
Glenn Kastena1117922012-01-26 10:53:32 -08002134 return thread != NULL && thread->type() != ThreadBase::DIRECT ? (MixerThread *) thread : NULL;
Mathias Agopian65ab4712010-07-14 17:59:35 -07002135}
2136
2137// checkRecordThread_l() must be called with AudioFlinger::mLock held
Glenn Kasten72ef00d2012-01-17 11:09:42 -08002138AudioFlinger::RecordThread *AudioFlinger::checkRecordThread_l(audio_io_handle_t input) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07002139{
Glenn Kastena1117922012-01-26 10:53:32 -08002140 return mRecordThreads.valueFor(input).get();
Mathias Agopian65ab4712010-07-14 17:59:35 -07002141}
2142
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002143uint32_t AudioFlinger::nextUniqueId()
Mathias Agopian65ab4712010-07-14 17:59:35 -07002144{
Glenn Kastenbcefec32014-01-17 12:09:05 -08002145 return (uint32_t) android_atomic_inc(&mNextUniqueId);
Mathias Agopian65ab4712010-07-14 17:59:35 -07002146}
2147
Glenn Kasten02fe1bf2012-02-24 15:42:17 -08002148AudioFlinger::PlaybackThread *AudioFlinger::primaryPlaybackThread_l() const
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002149{
2150 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
2151 PlaybackThread *thread = mPlaybackThreads.valueAt(i).get();
Eric Laurentb8ba0a92011-08-07 16:32:26 -07002152 AudioStreamOut *output = thread->getOutput();
John Grossmanee578c02012-07-23 17:05:46 -07002153 if (output != NULL && output->audioHwDev == mPrimaryHardwareDev) {
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002154 return thread;
2155 }
2156 }
2157 return NULL;
2158}
2159
Glenn Kastenbb4350d2012-07-03 15:56:38 -07002160audio_devices_t AudioFlinger::primaryOutputDevice_l() const
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002161{
2162 PlaybackThread *thread = primaryPlaybackThread_l();
2163
2164 if (thread == NULL) {
2165 return 0;
2166 }
2167
Eric Laurentf1c04f92012-08-28 14:26:53 -07002168 return thread->outDevice();
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002169}
2170
Eric Laurenta011e352012-03-29 15:51:43 -07002171sp<AudioFlinger::SyncEvent> AudioFlinger::createSyncEvent(AudioSystem::sync_event_t type,
2172 int triggerSession,
2173 int listenerSession,
2174 sync_event_callback_t callBack,
Eric Laurent8ea16e42014-02-20 16:26:11 -08002175 wp<RefBase> cookie)
Eric Laurenta011e352012-03-29 15:51:43 -07002176{
2177 Mutex::Autolock _l(mLock);
2178
2179 sp<SyncEvent> event = new SyncEvent(type, triggerSession, listenerSession, callBack, cookie);
2180 status_t playStatus = NAME_NOT_FOUND;
2181 status_t recStatus = NAME_NOT_FOUND;
2182 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
2183 playStatus = mPlaybackThreads.valueAt(i)->setSyncEvent(event);
2184 if (playStatus == NO_ERROR) {
2185 return event;
2186 }
2187 }
2188 for (size_t i = 0; i < mRecordThreads.size(); i++) {
2189 recStatus = mRecordThreads.valueAt(i)->setSyncEvent(event);
2190 if (recStatus == NO_ERROR) {
2191 return event;
2192 }
2193 }
2194 if (playStatus == NAME_NOT_FOUND || recStatus == NAME_NOT_FOUND) {
2195 mPendingSyncEvents.add(event);
2196 } else {
2197 ALOGV("createSyncEvent() invalid event %d", event->type());
2198 event.clear();
2199 }
2200 return event;
2201}
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002202
Mathias Agopian65ab4712010-07-14 17:59:35 -07002203// ----------------------------------------------------------------------------
2204// Effect management
2205// ----------------------------------------------------------------------------
2206
2207
Glenn Kastenf587ba52012-01-26 16:25:10 -08002208status_t AudioFlinger::queryNumberEffects(uint32_t *numEffects) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07002209{
2210 Mutex::Autolock _l(mLock);
2211 return EffectQueryNumberEffects(numEffects);
2212}
2213
Glenn Kastenf587ba52012-01-26 16:25:10 -08002214status_t AudioFlinger::queryEffect(uint32_t index, effect_descriptor_t *descriptor) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07002215{
2216 Mutex::Autolock _l(mLock);
2217 return EffectQueryEffect(index, descriptor);
2218}
2219
Glenn Kasten5e92a782012-01-30 07:40:52 -08002220status_t AudioFlinger::getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -08002221 effect_descriptor_t *descriptor) const
Mathias Agopian65ab4712010-07-14 17:59:35 -07002222{
2223 Mutex::Autolock _l(mLock);
2224 return EffectGetDescriptor(pUuid, descriptor);
2225}
2226
2227
Glenn Kasten8d6cc842012-02-03 11:06:53 -08002228sp<IEffect> AudioFlinger::createEffect(
Mathias Agopian65ab4712010-07-14 17:59:35 -07002229 effect_descriptor_t *pDesc,
2230 const sp<IEffectClient>& effectClient,
2231 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -08002232 audio_io_handle_t io,
Mathias Agopian65ab4712010-07-14 17:59:35 -07002233 int sessionId,
2234 status_t *status,
2235 int *id,
2236 int *enabled)
2237{
2238 status_t lStatus = NO_ERROR;
2239 sp<EffectHandle> handle;
Mathias Agopian65ab4712010-07-14 17:59:35 -07002240 effect_descriptor_t desc;
Mathias Agopian65ab4712010-07-14 17:59:35 -07002241
Glenn Kasten8d6cc842012-02-03 11:06:53 -08002242 pid_t pid = IPCThreadState::self()->getCallingPid();
Glenn Kasten98ec94c2012-01-25 14:28:29 -08002243 ALOGV("createEffect pid %d, effectClient %p, priority %d, sessionId %d, io %d",
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002244 pid, effectClient.get(), priority, sessionId, io);
Mathias Agopian65ab4712010-07-14 17:59:35 -07002245
2246 if (pDesc == NULL) {
2247 lStatus = BAD_VALUE;
2248 goto Exit;
2249 }
2250
Eric Laurent84e9a102010-09-23 16:10:16 -07002251 // check audio settings permission for global effects
Dima Zavinfce7a472011-04-19 22:30:36 -07002252 if (sessionId == AUDIO_SESSION_OUTPUT_MIX && !settingsAllowed()) {
Eric Laurent84e9a102010-09-23 16:10:16 -07002253 lStatus = PERMISSION_DENIED;
2254 goto Exit;
2255 }
2256
Dima Zavinfce7a472011-04-19 22:30:36 -07002257 // Session AUDIO_SESSION_OUTPUT_STAGE is reserved for output stage effects
Eric Laurent84e9a102010-09-23 16:10:16 -07002258 // that can only be created by audio policy manager (running in same process)
Glenn Kasten44deb052012-02-05 18:09:08 -08002259 if (sessionId == AUDIO_SESSION_OUTPUT_STAGE && getpid_cached != pid) {
Eric Laurent84e9a102010-09-23 16:10:16 -07002260 lStatus = PERMISSION_DENIED;
2261 goto Exit;
2262 }
2263
Mathias Agopian65ab4712010-07-14 17:59:35 -07002264 {
Mathias Agopian65ab4712010-07-14 17:59:35 -07002265 if (!EffectIsNullUuid(&pDesc->uuid)) {
2266 // if uuid is specified, request effect descriptor
2267 lStatus = EffectGetDescriptor(&pDesc->uuid, &desc);
2268 if (lStatus < 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +00002269 ALOGW("createEffect() error %d from EffectGetDescriptor", lStatus);
Mathias Agopian65ab4712010-07-14 17:59:35 -07002270 goto Exit;
2271 }
2272 } else {
2273 // if uuid is not specified, look for an available implementation
2274 // of the required type in effect factory
2275 if (EffectIsNullUuid(&pDesc->type)) {
Steve Block5ff1dd52012-01-05 23:22:43 +00002276 ALOGW("createEffect() no effect type");
Mathias Agopian65ab4712010-07-14 17:59:35 -07002277 lStatus = BAD_VALUE;
2278 goto Exit;
2279 }
2280 uint32_t numEffects = 0;
2281 effect_descriptor_t d;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002282 d.flags = 0; // prevent compiler warning
Mathias Agopian65ab4712010-07-14 17:59:35 -07002283 bool found = false;
2284
2285 lStatus = EffectQueryNumberEffects(&numEffects);
2286 if (lStatus < 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +00002287 ALOGW("createEffect() error %d from EffectQueryNumberEffects", lStatus);
Mathias Agopian65ab4712010-07-14 17:59:35 -07002288 goto Exit;
2289 }
2290 for (uint32_t i = 0; i < numEffects; i++) {
2291 lStatus = EffectQueryEffect(i, &desc);
2292 if (lStatus < 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +00002293 ALOGW("createEffect() error %d from EffectQueryEffect", lStatus);
Mathias Agopian65ab4712010-07-14 17:59:35 -07002294 continue;
2295 }
2296 if (memcmp(&desc.type, &pDesc->type, sizeof(effect_uuid_t)) == 0) {
2297 // If matching type found save effect descriptor. If the session is
2298 // 0 and the effect is not auxiliary, continue enumeration in case
2299 // an auxiliary version of this effect type is available
2300 found = true;
Glenn Kastena189a682012-02-20 12:16:30 -08002301 d = desc;
Dima Zavinfce7a472011-04-19 22:30:36 -07002302 if (sessionId != AUDIO_SESSION_OUTPUT_MIX ||
Mathias Agopian65ab4712010-07-14 17:59:35 -07002303 (desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
2304 break;
2305 }
2306 }
2307 }
2308 if (!found) {
2309 lStatus = BAD_VALUE;
Steve Block5ff1dd52012-01-05 23:22:43 +00002310 ALOGW("createEffect() effect not found");
Mathias Agopian65ab4712010-07-14 17:59:35 -07002311 goto Exit;
2312 }
2313 // For same effect type, chose auxiliary version over insert version if
2314 // connect to output mix (Compliance to OpenSL ES)
Dima Zavinfce7a472011-04-19 22:30:36 -07002315 if (sessionId == AUDIO_SESSION_OUTPUT_MIX &&
Mathias Agopian65ab4712010-07-14 17:59:35 -07002316 (d.flags & EFFECT_FLAG_TYPE_MASK) != EFFECT_FLAG_TYPE_AUXILIARY) {
Glenn Kastena189a682012-02-20 12:16:30 -08002317 desc = d;
Mathias Agopian65ab4712010-07-14 17:59:35 -07002318 }
2319 }
2320
2321 // Do not allow auxiliary effects on a session different from 0 (output mix)
Dima Zavinfce7a472011-04-19 22:30:36 -07002322 if (sessionId != AUDIO_SESSION_OUTPUT_MIX &&
Mathias Agopian65ab4712010-07-14 17:59:35 -07002323 (desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
2324 lStatus = INVALID_OPERATION;
2325 goto Exit;
2326 }
2327
Eric Laurent59255e42011-07-27 19:49:51 -07002328 // check recording permission for visualizer
2329 if ((memcmp(&desc.type, SL_IID_VISUALIZATION, sizeof(effect_uuid_t)) == 0) &&
2330 !recordingAllowed()) {
2331 lStatus = PERMISSION_DENIED;
2332 goto Exit;
2333 }
2334
Mathias Agopian65ab4712010-07-14 17:59:35 -07002335 // return effect descriptor
Glenn Kastena189a682012-02-20 12:16:30 -08002336 *pDesc = desc;
Glenn Kasten142f5192014-03-25 17:44:59 -07002337 if (io == AUDIO_IO_HANDLE_NONE && sessionId == AUDIO_SESSION_OUTPUT_MIX) {
Eric Laurenteb3c3372013-09-25 12:25:29 -07002338 // if the output returned by getOutputForEffect() is removed before we lock the
2339 // mutex below, the call to checkPlaybackThread_l(io) below will detect it
2340 // and we will exit safely
2341 io = AudioSystem::getOutputForEffect(&desc);
2342 ALOGV("createEffect got output %d", io);
2343 }
2344
2345 Mutex::Autolock _l(mLock);
Mathias Agopian65ab4712010-07-14 17:59:35 -07002346
2347 // If output is not specified try to find a matching audio session ID in one of the
2348 // output threads.
Eric Laurent84e9a102010-09-23 16:10:16 -07002349 // If output is 0 here, sessionId is neither SESSION_OUTPUT_STAGE nor SESSION_OUTPUT_MIX
2350 // because of code checking output when entering the function.
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002351 // Note: io is never 0 when creating an effect on an input
Glenn Kasten142f5192014-03-25 17:44:59 -07002352 if (io == AUDIO_IO_HANDLE_NONE) {
Eric Laurent5baf2af2013-09-12 17:37:00 -07002353 if (sessionId == AUDIO_SESSION_OUTPUT_STAGE) {
2354 // output must be specified by AudioPolicyManager when using session
2355 // AUDIO_SESSION_OUTPUT_STAGE
2356 lStatus = BAD_VALUE;
2357 goto Exit;
2358 }
Eric Laurenteb3c3372013-09-25 12:25:29 -07002359 // look for the thread where the specified audio session is present
2360 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
2361 if (mPlaybackThreads.valueAt(i)->hasAudioSession(sessionId) != 0) {
2362 io = mPlaybackThreads.keyAt(i);
2363 break;
2364 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07002365 }
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002366 if (io == 0) {
Eric Laurenteb3c3372013-09-25 12:25:29 -07002367 for (size_t i = 0; i < mRecordThreads.size(); i++) {
2368 if (mRecordThreads.valueAt(i)->hasAudioSession(sessionId) != 0) {
2369 io = mRecordThreads.keyAt(i);
Glenn Kastene53b9ea2012-03-12 16:29:55 -07002370 break;
2371 }
2372 }
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002373 }
Eric Laurent84e9a102010-09-23 16:10:16 -07002374 // If no output thread contains the requested session ID, default to
2375 // first output. The effect chain will be moved to the correct output
2376 // thread when a track with the same session ID is created
Glenn Kasten142f5192014-03-25 17:44:59 -07002377 if (io == AUDIO_IO_HANDLE_NONE && mPlaybackThreads.size() > 0) {
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002378 io = mPlaybackThreads.keyAt(0);
2379 }
Steve Block3856b092011-10-20 11:56:00 +01002380 ALOGV("createEffect() got io %d for effect %s", io, desc.name);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002381 }
2382 ThreadBase *thread = checkRecordThread_l(io);
2383 if (thread == NULL) {
2384 thread = checkPlaybackThread_l(io);
2385 if (thread == NULL) {
Steve Block29357bc2012-01-06 19:20:56 +00002386 ALOGE("createEffect() unknown output thread");
Eric Laurent7c7f10b2011-06-17 21:29:58 -07002387 lStatus = BAD_VALUE;
2388 goto Exit;
Eric Laurent84e9a102010-09-23 16:10:16 -07002389 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07002390 }
Eric Laurent84e9a102010-09-23 16:10:16 -07002391
Eric Laurent021cf962014-05-13 10:18:14 -07002392 sp<Client> client = registerPid(pid);
Mathias Agopian65ab4712010-07-14 17:59:35 -07002393
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002394 // create effect on selected output thread
Eric Laurentde070132010-07-13 04:45:46 -07002395 handle = thread->createEffect_l(client, effectClient, priority, sessionId,
2396 &desc, enabled, &lStatus);
Mathias Agopian65ab4712010-07-14 17:59:35 -07002397 if (handle != 0 && id != NULL) {
2398 *id = handle->id();
2399 }
Eric Laurentfe1a94e2014-05-26 16:03:08 -07002400 if (handle == 0) {
2401 // remove local strong reference to Client with mClientLock held
2402 Mutex::Autolock _cl(mClientLock);
2403 client.clear();
2404 }
Mathias Agopian65ab4712010-07-14 17:59:35 -07002405 }
2406
2407Exit:
Glenn Kasten9156ef32013-08-06 15:39:08 -07002408 *status = lStatus;
Mathias Agopian65ab4712010-07-14 17:59:35 -07002409 return handle;
2410}
2411
Glenn Kasten72ef00d2012-01-17 11:09:42 -08002412status_t AudioFlinger::moveEffects(int sessionId, audio_io_handle_t srcOutput,
2413 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -07002414{
Steve Block3856b092011-10-20 11:56:00 +01002415 ALOGV("moveEffects() session %d, srcOutput %d, dstOutput %d",
Eric Laurent59255e42011-07-27 19:49:51 -07002416 sessionId, srcOutput, dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -07002417 Mutex::Autolock _l(mLock);
2418 if (srcOutput == dstOutput) {
Steve Block5ff1dd52012-01-05 23:22:43 +00002419 ALOGW("moveEffects() same dst and src outputs %d", dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -07002420 return NO_ERROR;
Mathias Agopian65ab4712010-07-14 17:59:35 -07002421 }
Eric Laurentde070132010-07-13 04:45:46 -07002422 PlaybackThread *srcThread = checkPlaybackThread_l(srcOutput);
2423 if (srcThread == NULL) {
Steve Block5ff1dd52012-01-05 23:22:43 +00002424 ALOGW("moveEffects() bad srcOutput %d", srcOutput);
Eric Laurentde070132010-07-13 04:45:46 -07002425 return BAD_VALUE;
Mathias Agopian65ab4712010-07-14 17:59:35 -07002426 }
Eric Laurentde070132010-07-13 04:45:46 -07002427 PlaybackThread *dstThread = checkPlaybackThread_l(dstOutput);
2428 if (dstThread == NULL) {
Steve Block5ff1dd52012-01-05 23:22:43 +00002429 ALOGW("moveEffects() bad dstOutput %d", dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -07002430 return BAD_VALUE;
2431 }
2432
2433 Mutex::Autolock _dl(dstThread->mLock);
2434 Mutex::Autolock _sl(srcThread->mLock);
Eric Laurent5baf2af2013-09-12 17:37:00 -07002435 return moveEffectChain_l(sessionId, srcThread, dstThread, false);
Mathias Agopian65ab4712010-07-14 17:59:35 -07002436}
2437
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002438// moveEffectChain_l must be called with both srcThread and dstThread mLocks held
Eric Laurent59255e42011-07-27 19:49:51 -07002439status_t AudioFlinger::moveEffectChain_l(int sessionId,
Eric Laurentde070132010-07-13 04:45:46 -07002440 AudioFlinger::PlaybackThread *srcThread,
Eric Laurent39e94f82010-07-28 01:32:47 -07002441 AudioFlinger::PlaybackThread *dstThread,
2442 bool reRegister)
Eric Laurentde070132010-07-13 04:45:46 -07002443{
Steve Block3856b092011-10-20 11:56:00 +01002444 ALOGV("moveEffectChain_l() session %d from thread %p to thread %p",
Eric Laurent59255e42011-07-27 19:49:51 -07002445 sessionId, srcThread, dstThread);
Eric Laurentde070132010-07-13 04:45:46 -07002446
Eric Laurent59255e42011-07-27 19:49:51 -07002447 sp<EffectChain> chain = srcThread->getEffectChain_l(sessionId);
Eric Laurentde070132010-07-13 04:45:46 -07002448 if (chain == 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +00002449 ALOGW("moveEffectChain_l() effect chain for session %d not on source thread %p",
Eric Laurent59255e42011-07-27 19:49:51 -07002450 sessionId, srcThread);
Eric Laurentde070132010-07-13 04:45:46 -07002451 return INVALID_OPERATION;
2452 }
2453
Eric Laurent39e94f82010-07-28 01:32:47 -07002454 // remove chain first. This is useful only if reconfiguring effect chain on same output thread,
Eric Laurentde070132010-07-13 04:45:46 -07002455 // so that a new chain is created with correct parameters when first effect is added. This is
Eric Laurentec35a142011-10-05 17:42:25 -07002456 // otherwise unnecessary as removeEffect_l() will remove the chain when last effect is
Eric Laurentde070132010-07-13 04:45:46 -07002457 // removed.
2458 srcThread->removeEffectChain_l(chain);
2459
2460 // transfer all effects one by one so that new effect chain is created on new thread with
2461 // correct buffer sizes and audio parameters and effect engines reconfigured accordingly
Eric Laurent39e94f82010-07-28 01:32:47 -07002462 sp<EffectChain> dstChain;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07002463 uint32_t strategy = 0; // prevent compiler warning
Eric Laurentde070132010-07-13 04:45:46 -07002464 sp<EffectModule> effect = chain->getEffectFromId_l(0);
Eric Laurent5baf2af2013-09-12 17:37:00 -07002465 Vector< sp<EffectModule> > removed;
2466 status_t status = NO_ERROR;
Eric Laurentde070132010-07-13 04:45:46 -07002467 while (effect != 0) {
2468 srcThread->removeEffect_l(effect);
Eric Laurent5baf2af2013-09-12 17:37:00 -07002469 removed.add(effect);
2470 status = dstThread->addEffect_l(effect);
2471 if (status != NO_ERROR) {
2472 break;
2473 }
Eric Laurentec35a142011-10-05 17:42:25 -07002474 // removeEffect_l() has stopped the effect if it was active so it must be restarted
2475 if (effect->state() == EffectModule::ACTIVE ||
2476 effect->state() == EffectModule::STOPPING) {
2477 effect->start();
2478 }
Eric Laurent39e94f82010-07-28 01:32:47 -07002479 // if the move request is not received from audio policy manager, the effect must be
2480 // re-registered with the new strategy and output
2481 if (dstChain == 0) {
2482 dstChain = effect->chain().promote();
2483 if (dstChain == 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +00002484 ALOGW("moveEffectChain_l() cannot get chain from effect %p", effect.get());
Eric Laurent5baf2af2013-09-12 17:37:00 -07002485 status = NO_INIT;
2486 break;
Eric Laurent39e94f82010-07-28 01:32:47 -07002487 }
2488 strategy = dstChain->strategy();
2489 }
2490 if (reRegister) {
2491 AudioSystem::unregisterEffect(effect->id());
2492 AudioSystem::registerEffect(&effect->desc(),
Eric Laurent5baf2af2013-09-12 17:37:00 -07002493 dstThread->id(),
Eric Laurent39e94f82010-07-28 01:32:47 -07002494 strategy,
Eric Laurent59255e42011-07-27 19:49:51 -07002495 sessionId,
Eric Laurent39e94f82010-07-28 01:32:47 -07002496 effect->id());
Eric Laurentd72b7c02013-10-12 16:17:46 -07002497 AudioSystem::setEffectEnabled(effect->id(), effect->isEnabled());
Eric Laurent39e94f82010-07-28 01:32:47 -07002498 }
Eric Laurentde070132010-07-13 04:45:46 -07002499 effect = chain->getEffectFromId_l(0);
2500 }
2501
Eric Laurent5baf2af2013-09-12 17:37:00 -07002502 if (status != NO_ERROR) {
2503 for (size_t i = 0; i < removed.size(); i++) {
2504 srcThread->addEffect_l(removed[i]);
2505 if (dstChain != 0 && reRegister) {
2506 AudioSystem::unregisterEffect(removed[i]->id());
2507 AudioSystem::registerEffect(&removed[i]->desc(),
2508 srcThread->id(),
2509 strategy,
2510 sessionId,
2511 removed[i]->id());
Eric Laurentd72b7c02013-10-12 16:17:46 -07002512 AudioSystem::setEffectEnabled(effect->id(), effect->isEnabled());
Eric Laurent5baf2af2013-09-12 17:37:00 -07002513 }
2514 }
2515 }
2516
2517 return status;
Mathias Agopian65ab4712010-07-14 17:59:35 -07002518}
2519
Eric Laurent5baf2af2013-09-12 17:37:00 -07002520bool AudioFlinger::isNonOffloadableGlobalEffectEnabled_l()
Eric Laurent813e2a72013-08-31 12:59:48 -07002521{
2522 if (mGlobalEffectEnableTime != 0 &&
2523 ((systemTime() - mGlobalEffectEnableTime) < kMinGlobalEffectEnabletimeNs)) {
2524 return true;
2525 }
2526
2527 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
2528 sp<EffectChain> ec =
2529 mPlaybackThreads.valueAt(i)->getEffectChain_l(AUDIO_SESSION_OUTPUT_MIX);
Eric Laurent5baf2af2013-09-12 17:37:00 -07002530 if (ec != 0 && ec->isNonOffloadableEnabled()) {
Eric Laurent813e2a72013-08-31 12:59:48 -07002531 return true;
2532 }
2533 }
2534 return false;
2535}
2536
Eric Laurent5baf2af2013-09-12 17:37:00 -07002537void AudioFlinger::onNonOffloadableGlobalEffectEnable()
Eric Laurent813e2a72013-08-31 12:59:48 -07002538{
2539 Mutex::Autolock _l(mLock);
2540
2541 mGlobalEffectEnableTime = systemTime();
2542
2543 for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
2544 sp<PlaybackThread> t = mPlaybackThreads.valueAt(i);
2545 if (t->mType == ThreadBase::OFFLOAD) {
2546 t->invalidateTracks(AUDIO_STREAM_MUSIC);
2547 }
2548 }
2549
2550}
2551
Glenn Kastenda6ef132013-01-10 12:31:01 -08002552struct Entry {
2553#define MAX_NAME 32 // %Y%m%d%H%M%S_%d.wav
2554 char mName[MAX_NAME];
2555};
2556
2557int comparEntry(const void *p1, const void *p2)
2558{
2559 return strcmp(((const Entry *) p1)->mName, ((const Entry *) p2)->mName);
2560}
2561
Glenn Kasten46909e72013-02-26 09:20:22 -08002562#ifdef TEE_SINK
Eric Laurent81784c32012-11-19 14:55:58 -08002563void AudioFlinger::dumpTee(int fd, const sp<NBAIO_Source>& source, audio_io_handle_t id)
Mathias Agopian65ab4712010-07-14 17:59:35 -07002564{
Eric Laurent81784c32012-11-19 14:55:58 -08002565 NBAIO_Source *teeSource = source.get();
2566 if (teeSource != NULL) {
Glenn Kastenda6ef132013-01-10 12:31:01 -08002567 // .wav rotation
2568 // There is a benign race condition if 2 threads call this simultaneously.
2569 // They would both traverse the directory, but the result would simply be
2570 // failures at unlink() which are ignored. It's also unlikely since
2571 // normally dumpsys is only done by bugreport or from the command line.
2572 char teePath[32+256];
2573 strcpy(teePath, "/data/misc/media");
2574 size_t teePathLen = strlen(teePath);
2575 DIR *dir = opendir(teePath);
2576 teePath[teePathLen++] = '/';
2577 if (dir != NULL) {
2578#define MAX_SORT 20 // number of entries to sort
2579#define MAX_KEEP 10 // number of entries to keep
2580 struct Entry entries[MAX_SORT];
2581 size_t entryCount = 0;
2582 while (entryCount < MAX_SORT) {
2583 struct dirent de;
2584 struct dirent *result = NULL;
2585 int rc = readdir_r(dir, &de, &result);
2586 if (rc != 0) {
2587 ALOGW("readdir_r failed %d", rc);
2588 break;
2589 }
2590 if (result == NULL) {
2591 break;
2592 }
2593 if (result != &de) {
2594 ALOGW("readdir_r returned unexpected result %p != %p", result, &de);
2595 break;
2596 }
2597 // ignore non .wav file entries
2598 size_t nameLen = strlen(de.d_name);
2599 if (nameLen <= 4 || nameLen >= MAX_NAME ||
2600 strcmp(&de.d_name[nameLen - 4], ".wav")) {
2601 continue;
2602 }
2603 strcpy(entries[entryCount++].mName, de.d_name);
2604 }
2605 (void) closedir(dir);
2606 if (entryCount > MAX_KEEP) {
2607 qsort(entries, entryCount, sizeof(Entry), comparEntry);
2608 for (size_t i = 0; i < entryCount - MAX_KEEP; ++i) {
2609 strcpy(&teePath[teePathLen], entries[i].mName);
2610 (void) unlink(teePath);
2611 }
2612 }
2613 } else {
2614 if (fd >= 0) {
Elliott Hughes8b5f6422014-05-22 01:22:06 -07002615 dprintf(fd, "unable to rotate tees in %s: %s\n", teePath, strerror(errno));
Glenn Kastenda6ef132013-01-10 12:31:01 -08002616 }
2617 }
Eric Laurent81784c32012-11-19 14:55:58 -08002618 char teeTime[16];
2619 struct timeval tv;
2620 gettimeofday(&tv, NULL);
2621 struct tm tm;
2622 localtime_r(&tv.tv_sec, &tm);
Glenn Kastenda6ef132013-01-10 12:31:01 -08002623 strftime(teeTime, sizeof(teeTime), "%Y%m%d%H%M%S", &tm);
2624 snprintf(&teePath[teePathLen], sizeof(teePath) - teePathLen, "%s_%d.wav", teeTime, id);
2625 // if 2 dumpsys are done within 1 second, and rotation didn't work, then discard 2nd
2626 int teeFd = open(teePath, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, S_IRUSR | S_IWUSR);
Eric Laurent81784c32012-11-19 14:55:58 -08002627 if (teeFd >= 0) {
2628 char wavHeader[44];
2629 memcpy(wavHeader,
2630 "RIFF\0\0\0\0WAVEfmt \20\0\0\0\1\0\2\0\104\254\0\0\0\0\0\0\4\0\20\0data\0\0\0\0",
2631 sizeof(wavHeader));
2632 NBAIO_Format format = teeSource->format();
2633 unsigned channelCount = Format_channelCount(format);
2634 ALOG_ASSERT(channelCount <= FCC_2);
2635 uint32_t sampleRate = Format_sampleRate(format);
2636 wavHeader[22] = channelCount; // number of channels
2637 wavHeader[24] = sampleRate; // sample rate
2638 wavHeader[25] = sampleRate >> 8;
2639 wavHeader[32] = channelCount * 2; // block alignment
2640 write(teeFd, wavHeader, sizeof(wavHeader));
2641 size_t total = 0;
2642 bool firstRead = true;
2643 for (;;) {
2644#define TEE_SINK_READ 1024
2645 short buffer[TEE_SINK_READ * FCC_2];
2646 size_t count = TEE_SINK_READ;
2647 ssize_t actual = teeSource->read(buffer, count,
2648 AudioBufferProvider::kInvalidPTS);
2649 bool wasFirstRead = firstRead;
2650 firstRead = false;
2651 if (actual <= 0) {
2652 if (actual == (ssize_t) OVERRUN && wasFirstRead) {
2653 continue;
Eric Laurent59255e42011-07-27 19:49:51 -07002654 }
Eric Laurent81784c32012-11-19 14:55:58 -08002655 break;
Eric Laurent59255e42011-07-27 19:49:51 -07002656 }
Eric Laurent81784c32012-11-19 14:55:58 -08002657 ALOG_ASSERT(actual <= (ssize_t)count);
2658 write(teeFd, buffer, actual * channelCount * sizeof(short));
2659 total += actual;
Eric Laurent59255e42011-07-27 19:49:51 -07002660 }
Eric Laurent81784c32012-11-19 14:55:58 -08002661 lseek(teeFd, (off_t) 4, SEEK_SET);
2662 uint32_t temp = 44 + total * channelCount * sizeof(short) - 8;
2663 write(teeFd, &temp, sizeof(temp));
2664 lseek(teeFd, (off_t) 40, SEEK_SET);
2665 temp = total * channelCount * sizeof(short);
2666 write(teeFd, &temp, sizeof(temp));
2667 close(teeFd);
Glenn Kastenda6ef132013-01-10 12:31:01 -08002668 if (fd >= 0) {
Elliott Hughes8b5f6422014-05-22 01:22:06 -07002669 dprintf(fd, "tee copied to %s\n", teePath);
Glenn Kastenda6ef132013-01-10 12:31:01 -08002670 }
Eric Laurent59255e42011-07-27 19:49:51 -07002671 } else {
Glenn Kastenda6ef132013-01-10 12:31:01 -08002672 if (fd >= 0) {
Elliott Hughes8b5f6422014-05-22 01:22:06 -07002673 dprintf(fd, "unable to create tee %s: %s\n", teePath, strerror(errno));
Glenn Kastenda6ef132013-01-10 12:31:01 -08002674 }
Eric Laurent59255e42011-07-27 19:49:51 -07002675 }
2676 }
2677}
Glenn Kasten46909e72013-02-26 09:20:22 -08002678#endif
Eric Laurent59255e42011-07-27 19:49:51 -07002679
Mathias Agopian65ab4712010-07-14 17:59:35 -07002680// ----------------------------------------------------------------------------
2681
2682status_t AudioFlinger::onTransact(
2683 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
2684{
2685 return BnAudioFlinger::onTransact(code, data, reply, flags);
2686}
2687
Mathias Agopian65ab4712010-07-14 17:59:35 -07002688}; // namespace android