blob: 96d9f9710413856075c1d4fd1149dee21b3ee88a [file] [log] [blame]
Eric Laurentca7cc822012-11-19 14:55:58 -08001/*
2**
3** Copyright 2012, 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"
Eric Laurentca7cc822012-11-19 14:55:58 -080023#include <utils/Log.h>
Eric Laurentca7cc822012-11-19 14:55:58 -080024#include <audio_utils/primitives.h>
25#include <private/media/AudioEffectShared.h>
Mikhail Naganova0c91332016-09-19 10:01:12 -070026#include <media/audiohal/EffectHalInterface.h>
27#include <media/audiohal/EffectsFactoryHalInterface.h>
Mikhail Naganov9fe94012016-10-14 14:57:40 -070028#include <system/audio_effects/effect_visualizer.h>
Eric Laurentca7cc822012-11-19 14:55:58 -080029
30#include "AudioFlinger.h"
31#include "ServiceUtilities.h"
32
33// ----------------------------------------------------------------------------
34
35// Note: the following macro is used for extremely verbose logging message. In
36// order to run with ALOG_ASSERT turned on, we need to have LOG_NDEBUG set to
37// 0; but one side effect of this is to turn all LOGV's as well. Some messages
38// are so verbose that we want to suppress them even when we have ALOG_ASSERT
39// turned on. Do not uncomment the #def below unless you really know what you
40// are doing and want to see all of the extremely verbose messages.
41//#define VERY_VERY_VERBOSE_LOGGING
42#ifdef VERY_VERY_VERBOSE_LOGGING
43#define ALOGVV ALOGV
44#else
45#define ALOGVV(a...) do { } while(0)
46#endif
47
Ricardo Garcia726b6a72014-08-11 12:04:54 -070048#define min(a, b) ((a) < (b) ? (a) : (b))
49
Eric Laurentca7cc822012-11-19 14:55:58 -080050namespace android {
51
52// ----------------------------------------------------------------------------
53// EffectModule implementation
54// ----------------------------------------------------------------------------
55
56#undef LOG_TAG
57#define LOG_TAG "AudioFlinger::EffectModule"
58
59AudioFlinger::EffectModule::EffectModule(ThreadBase *thread,
60 const wp<AudioFlinger::EffectChain>& chain,
61 effect_descriptor_t *desc,
62 int id,
Glenn Kastend848eb42016-03-08 13:42:11 -080063 audio_session_t sessionId)
Eric Laurentca7cc822012-11-19 14:55:58 -080064 : mPinned(sessionId > AUDIO_SESSION_OUTPUT_MIX),
65 mThread(thread), mChain(chain), mId(id), mSessionId(sessionId),
66 mDescriptor(*desc),
67 // mConfig is set by configure() and not used before then
Eric Laurentca7cc822012-11-19 14:55:58 -080068 mStatus(NO_INIT), mState(IDLE),
69 // mMaxDisableWaitCnt is set by configure() and not used before then
70 // mDisableWaitCnt is set by process() and updateState() and not used before then
Eric Laurentaaa44472014-09-12 17:41:50 -070071 mSuspended(false),
72 mAudioFlinger(thread->mAudioFlinger)
Eric Laurentca7cc822012-11-19 14:55:58 -080073{
74 ALOGV("Constructor %p", this);
75 int lStatus;
76
77 // create effect engine from effect factory
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -070078 mStatus = -ENODEV;
79 sp<AudioFlinger> audioFlinger = mAudioFlinger.promote();
Mikhail Naganov1dc98672016-08-18 17:50:29 -070080 if (audioFlinger != 0) {
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -070081 sp<EffectsFactoryHalInterface> effectsFactory = audioFlinger->getEffectsFactory();
Mikhail Naganov1dc98672016-08-18 17:50:29 -070082 if (effectsFactory != 0) {
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -070083 mStatus = effectsFactory->createEffect(
84 &desc->uuid, sessionId, thread->id(), &mEffectInterface);
85 }
86 }
Eric Laurentca7cc822012-11-19 14:55:58 -080087
88 if (mStatus != NO_ERROR) {
89 return;
90 }
91 lStatus = init();
92 if (lStatus < 0) {
93 mStatus = lStatus;
94 goto Error;
95 }
96
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -070097 ALOGV("Constructor success name %s, Interface %p", mDescriptor.name, mEffectInterface.get());
Eric Laurentca7cc822012-11-19 14:55:58 -080098 return;
99Error:
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700100 mEffectInterface.clear();
Eric Laurentca7cc822012-11-19 14:55:58 -0800101 ALOGV("Constructor Error %d", mStatus);
102}
103
104AudioFlinger::EffectModule::~EffectModule()
105{
106 ALOGV("Destructor %p", this);
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700107 if (mEffectInterface != 0) {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800108 remove_effect_from_hal_l();
Eric Laurentca7cc822012-11-19 14:55:58 -0800109 // release effect engine
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700110 mEffectInterface.clear();
Eric Laurentca7cc822012-11-19 14:55:58 -0800111 }
112}
113
114status_t AudioFlinger::EffectModule::addHandle(EffectHandle *handle)
115{
116 status_t status;
117
118 Mutex::Autolock _l(mLock);
119 int priority = handle->priority();
120 size_t size = mHandles.size();
121 EffectHandle *controlHandle = NULL;
122 size_t i;
123 for (i = 0; i < size; i++) {
124 EffectHandle *h = mHandles[i];
125 if (h == NULL || h->destroyed_l()) {
126 continue;
127 }
128 // first non destroyed handle is considered in control
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700129 if (controlHandle == NULL) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800130 controlHandle = h;
Glenn Kasten6e2ebe92013-08-13 09:14:51 -0700131 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800132 if (h->priority() <= priority) {
133 break;
134 }
135 }
136 // if inserted in first place, move effect control from previous owner to this handle
137 if (i == 0) {
138 bool enabled = false;
139 if (controlHandle != NULL) {
140 enabled = controlHandle->enabled();
141 controlHandle->setControl(false/*hasControl*/, true /*signal*/, enabled /*enabled*/);
142 }
143 handle->setControl(true /*hasControl*/, false /*signal*/, enabled /*enabled*/);
144 status = NO_ERROR;
145 } else {
146 status = ALREADY_EXISTS;
147 }
Glenn Kastenc42e9b42016-03-21 11:35:03 -0700148 ALOGV("addHandle() %p added handle %p in position %zu", this, handle, i);
Eric Laurentca7cc822012-11-19 14:55:58 -0800149 mHandles.insertAt(handle, i);
150 return status;
151}
152
153size_t AudioFlinger::EffectModule::removeHandle(EffectHandle *handle)
154{
155 Mutex::Autolock _l(mLock);
156 size_t size = mHandles.size();
157 size_t i;
158 for (i = 0; i < size; i++) {
159 if (mHandles[i] == handle) {
160 break;
161 }
162 }
163 if (i == size) {
164 return size;
165 }
Glenn Kastenc42e9b42016-03-21 11:35:03 -0700166 ALOGV("removeHandle() %p removed handle %p in position %zu", this, handle, i);
Eric Laurentca7cc822012-11-19 14:55:58 -0800167
168 mHandles.removeAt(i);
169 // if removed from first place, move effect control from this handle to next in line
170 if (i == 0) {
171 EffectHandle *h = controlHandle_l();
172 if (h != NULL) {
173 h->setControl(true /*hasControl*/, true /*signal*/ , handle->enabled() /*enabled*/);
174 }
175 }
176
177 // Prevent calls to process() and other functions on effect interface from now on.
178 // The effect engine will be released by the destructor when the last strong reference on
179 // this object is released which can happen after next process is called.
180 if (mHandles.size() == 0 && !mPinned) {
181 mState = DESTROYED;
182 }
183
184 return mHandles.size();
185}
186
187// must be called with EffectModule::mLock held
188AudioFlinger::EffectHandle *AudioFlinger::EffectModule::controlHandle_l()
189{
190 // the first valid handle in the list has control over the module
191 for (size_t i = 0; i < mHandles.size(); i++) {
192 EffectHandle *h = mHandles[i];
193 if (h != NULL && !h->destroyed_l()) {
194 return h;
195 }
196 }
197
198 return NULL;
199}
200
201size_t AudioFlinger::EffectModule::disconnect(EffectHandle *handle, bool unpinIfLast)
202{
203 ALOGV("disconnect() %p handle %p", this, handle);
204 // keep a strong reference on this EffectModule to avoid calling the
205 // destructor before we exit
206 sp<EffectModule> keep(this);
207 {
Eric Laurentaaa44472014-09-12 17:41:50 -0700208 if (removeHandle(handle) == 0) {
209 if (!isPinned() || unpinIfLast) {
210 sp<ThreadBase> thread = mThread.promote();
211 if (thread != 0) {
212 Mutex::Autolock _l(thread->mLock);
213 thread->removeEffect_l(this);
214 }
215 sp<AudioFlinger> af = mAudioFlinger.promote();
216 if (af != 0) {
217 af->updateOrphanEffectChains(this);
218 }
219 AudioSystem::unregisterEffect(mId);
220 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800221 }
222 }
223 return mHandles.size();
224}
225
Eric Laurentfa1e1232016-08-02 19:01:49 -0700226bool AudioFlinger::EffectModule::updateState() {
Eric Laurentca7cc822012-11-19 14:55:58 -0800227 Mutex::Autolock _l(mLock);
228
Eric Laurentfa1e1232016-08-02 19:01:49 -0700229 bool started = false;
Eric Laurentca7cc822012-11-19 14:55:58 -0800230 switch (mState) {
231 case RESTART:
232 reset_l();
233 // FALL THROUGH
234
235 case STARTING:
236 // clear auxiliary effect input buffer for next accumulation
237 if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
238 memset(mConfig.inputCfg.buffer.raw,
239 0,
240 mConfig.inputCfg.buffer.frameCount*sizeof(int32_t));
241 }
Eric Laurentd0ebb532013-04-02 16:41:41 -0700242 if (start_l() == NO_ERROR) {
243 mState = ACTIVE;
Eric Laurentfa1e1232016-08-02 19:01:49 -0700244 started = true;
Eric Laurentd0ebb532013-04-02 16:41:41 -0700245 } else {
246 mState = IDLE;
247 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800248 break;
249 case STOPPING:
Eric Laurentd0ebb532013-04-02 16:41:41 -0700250 if (stop_l() == NO_ERROR) {
251 mDisableWaitCnt = mMaxDisableWaitCnt;
252 } else {
253 mDisableWaitCnt = 1; // will cause immediate transition to IDLE
254 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800255 mState = STOPPED;
256 break;
257 case STOPPED:
258 // mDisableWaitCnt is forced to 1 by process() when the engine indicates the end of the
259 // turn off sequence.
260 if (--mDisableWaitCnt == 0) {
261 reset_l();
262 mState = IDLE;
263 }
264 break;
265 default: //IDLE , ACTIVE, DESTROYED
266 break;
267 }
Eric Laurentfa1e1232016-08-02 19:01:49 -0700268
269 return started;
Eric Laurentca7cc822012-11-19 14:55:58 -0800270}
271
272void AudioFlinger::EffectModule::process()
273{
274 Mutex::Autolock _l(mLock);
275
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700276 if (mState == DESTROYED || mEffectInterface == 0 ||
Eric Laurentca7cc822012-11-19 14:55:58 -0800277 mConfig.inputCfg.buffer.raw == NULL ||
278 mConfig.outputCfg.buffer.raw == NULL) {
279 return;
280 }
281
282 if (isProcessEnabled()) {
283 // do 32 bit to 16 bit conversion for auxiliary effect input buffer
284 if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
285 ditherAndClamp(mConfig.inputCfg.buffer.s32,
286 mConfig.inputCfg.buffer.s32,
287 mConfig.inputCfg.buffer.frameCount/2);
288 }
Eric Laurent6dd0fd92016-09-15 12:44:53 -0700289 int ret;
290 if (isProcessImplemented()) {
291 // do the actual processing in the effect engine
Eric Laurentdb0fd692016-09-16 10:26:09 -0700292 ret = mEffectInterface->process(&mConfig.inputCfg.buffer, &mConfig.outputCfg.buffer);
Eric Laurent6dd0fd92016-09-15 12:44:53 -0700293 } else {
294 if (mConfig.inputCfg.buffer.raw != mConfig.outputCfg.buffer.raw) {
295 size_t frameCnt = mConfig.inputCfg.buffer.frameCount * FCC_2; //always stereo here
296 int16_t *in = mConfig.inputCfg.buffer.s16;
297 int16_t *out = mConfig.outputCfg.buffer.s16;
Eric Laurentca7cc822012-11-19 14:55:58 -0800298
Eric Laurent6dd0fd92016-09-15 12:44:53 -0700299 if (mConfig.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) {
300 for (size_t i = 0; i < frameCnt; i++) {
301 out[i] = clamp16((int32_t)out[i] + (int32_t)in[i]);
302 }
303 } else {
304 memcpy(mConfig.outputCfg.buffer.raw, mConfig.inputCfg.buffer.raw,
305 frameCnt * sizeof(int16_t));
306 }
307 }
308 ret = -ENODATA;
309 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800310 // force transition to IDLE state when engine is ready
311 if (mState == STOPPED && ret == -ENODATA) {
312 mDisableWaitCnt = 1;
313 }
314
315 // clear auxiliary effect input buffer for next accumulation
316 if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
317 memset(mConfig.inputCfg.buffer.raw, 0,
318 mConfig.inputCfg.buffer.frameCount*sizeof(int32_t));
319 }
320 } else if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_INSERT &&
321 mConfig.inputCfg.buffer.raw != mConfig.outputCfg.buffer.raw) {
322 // If an insert effect is idle and input buffer is different from output buffer,
323 // accumulate input onto output
324 sp<EffectChain> chain = mChain.promote();
325 if (chain != 0 && chain->activeTrackCnt() != 0) {
Eric Laurent6dd0fd92016-09-15 12:44:53 -0700326 size_t frameCnt = mConfig.inputCfg.buffer.frameCount * FCC_2; //always stereo here
Eric Laurentca7cc822012-11-19 14:55:58 -0800327 int16_t *in = mConfig.inputCfg.buffer.s16;
328 int16_t *out = mConfig.outputCfg.buffer.s16;
329 for (size_t i = 0; i < frameCnt; i++) {
330 out[i] = clamp16((int32_t)out[i] + (int32_t)in[i]);
331 }
332 }
333 }
334}
335
336void AudioFlinger::EffectModule::reset_l()
337{
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700338 if (mStatus != NO_ERROR || mEffectInterface == 0) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800339 return;
340 }
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700341 mEffectInterface->command(EFFECT_CMD_RESET, 0, NULL, 0, NULL);
Eric Laurentca7cc822012-11-19 14:55:58 -0800342}
343
344status_t AudioFlinger::EffectModule::configure()
345{
Eric Laurentd0ebb532013-04-02 16:41:41 -0700346 status_t status;
347 sp<ThreadBase> thread;
348 uint32_t size;
349 audio_channel_mask_t channelMask;
350
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700351 if (mEffectInterface == 0) {
Eric Laurentd0ebb532013-04-02 16:41:41 -0700352 status = NO_INIT;
353 goto exit;
Eric Laurentca7cc822012-11-19 14:55:58 -0800354 }
355
Eric Laurentd0ebb532013-04-02 16:41:41 -0700356 thread = mThread.promote();
Eric Laurentca7cc822012-11-19 14:55:58 -0800357 if (thread == 0) {
Eric Laurentd0ebb532013-04-02 16:41:41 -0700358 status = DEAD_OBJECT;
359 goto exit;
Eric Laurentca7cc822012-11-19 14:55:58 -0800360 }
361
362 // TODO: handle configuration of effects replacing track process
Eric Laurentd0ebb532013-04-02 16:41:41 -0700363 channelMask = thread->channelMask();
Ricardo Garciad11da702015-05-28 12:14:12 -0700364 mConfig.outputCfg.channels = channelMask;
Eric Laurentca7cc822012-11-19 14:55:58 -0800365
366 if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
367 mConfig.inputCfg.channels = AUDIO_CHANNEL_OUT_MONO;
368 } else {
369 mConfig.inputCfg.channels = channelMask;
Ricardo Garciad11da702015-05-28 12:14:12 -0700370 // TODO: Update this logic when multichannel effects are implemented.
371 // For offloaded tracks consider mono output as stereo for proper effect initialization
372 if (channelMask == AUDIO_CHANNEL_OUT_MONO) {
373 mConfig.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
374 mConfig.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
375 ALOGV("Overriding effect input and output as STEREO");
376 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800377 }
Ricardo Garciad11da702015-05-28 12:14:12 -0700378
Eric Laurentca7cc822012-11-19 14:55:58 -0800379 mConfig.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
380 mConfig.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
381 mConfig.inputCfg.samplingRate = thread->sampleRate();
382 mConfig.outputCfg.samplingRate = mConfig.inputCfg.samplingRate;
383 mConfig.inputCfg.bufferProvider.cookie = NULL;
384 mConfig.inputCfg.bufferProvider.getBuffer = NULL;
385 mConfig.inputCfg.bufferProvider.releaseBuffer = NULL;
386 mConfig.outputCfg.bufferProvider.cookie = NULL;
387 mConfig.outputCfg.bufferProvider.getBuffer = NULL;
388 mConfig.outputCfg.bufferProvider.releaseBuffer = NULL;
389 mConfig.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
390 // Insert effect:
391 // - in session AUDIO_SESSION_OUTPUT_MIX or AUDIO_SESSION_OUTPUT_STAGE,
392 // always overwrites output buffer: input buffer == output buffer
393 // - in other sessions:
394 // last effect in the chain accumulates in output buffer: input buffer != output buffer
395 // other effect: overwrites output buffer: input buffer == output buffer
396 // Auxiliary effect:
397 // accumulates in output buffer: input buffer != output buffer
398 // Therefore: accumulate <=> input buffer != output buffer
399 if (mConfig.inputCfg.buffer.raw != mConfig.outputCfg.buffer.raw) {
400 mConfig.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
401 } else {
402 mConfig.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_WRITE;
403 }
404 mConfig.inputCfg.mask = EFFECT_CONFIG_ALL;
405 mConfig.outputCfg.mask = EFFECT_CONFIG_ALL;
406 mConfig.inputCfg.buffer.frameCount = thread->frameCount();
407 mConfig.outputCfg.buffer.frameCount = mConfig.inputCfg.buffer.frameCount;
408
Glenn Kastenc42e9b42016-03-21 11:35:03 -0700409 ALOGV("configure() %p thread %p buffer %p framecount %zu",
Eric Laurentca7cc822012-11-19 14:55:58 -0800410 this, thread.get(), mConfig.inputCfg.buffer.raw, mConfig.inputCfg.buffer.frameCount);
411
412 status_t cmdStatus;
Eric Laurentd0ebb532013-04-02 16:41:41 -0700413 size = sizeof(int);
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700414 status = mEffectInterface->command(EFFECT_CMD_SET_CONFIG,
415 sizeof(effect_config_t),
416 &mConfig,
417 &size,
418 &cmdStatus);
Eric Laurentca7cc822012-11-19 14:55:58 -0800419 if (status == 0) {
420 status = cmdStatus;
421 }
422
423 if (status == 0 &&
424 (memcmp(&mDescriptor.type, SL_IID_VISUALIZATION, sizeof(effect_uuid_t)) == 0)) {
425 uint32_t buf32[sizeof(effect_param_t) / sizeof(uint32_t) + 2];
426 effect_param_t *p = (effect_param_t *)buf32;
427
428 p->psize = sizeof(uint32_t);
429 p->vsize = sizeof(uint32_t);
430 size = sizeof(int);
431 *(int32_t *)p->data = VISUALIZER_PARAM_LATENCY;
432
433 uint32_t latency = 0;
434 PlaybackThread *pbt = thread->mAudioFlinger->checkPlaybackThread_l(thread->mId);
435 if (pbt != NULL) {
436 latency = pbt->latency_l();
437 }
438
439 *((int32_t *)p->data + 1)= latency;
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700440 mEffectInterface->command(EFFECT_CMD_SET_PARAM,
441 sizeof(effect_param_t) + 8,
442 &buf32,
443 &size,
444 &cmdStatus);
Eric Laurentca7cc822012-11-19 14:55:58 -0800445 }
446
447 mMaxDisableWaitCnt = (MAX_DISABLE_TIME_MS * mConfig.outputCfg.samplingRate) /
448 (1000 * mConfig.outputCfg.buffer.frameCount);
449
Eric Laurentd0ebb532013-04-02 16:41:41 -0700450exit:
451 mStatus = status;
Eric Laurentca7cc822012-11-19 14:55:58 -0800452 return status;
453}
454
455status_t AudioFlinger::EffectModule::init()
456{
457 Mutex::Autolock _l(mLock);
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700458 if (mEffectInterface == 0) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800459 return NO_INIT;
460 }
461 status_t cmdStatus;
462 uint32_t size = sizeof(status_t);
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700463 status_t status = mEffectInterface->command(EFFECT_CMD_INIT,
464 0,
465 NULL,
466 &size,
467 &cmdStatus);
Eric Laurentca7cc822012-11-19 14:55:58 -0800468 if (status == 0) {
469 status = cmdStatus;
470 }
471 return status;
472}
473
Eric Laurent1b928682014-10-02 19:41:47 -0700474void AudioFlinger::EffectModule::addEffectToHal_l()
475{
476 if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC ||
477 (mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_POST_PROC) {
478 sp<ThreadBase> thread = mThread.promote();
479 if (thread != 0) {
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700480 sp<StreamHalInterface> stream = thread->stream();
481 if (stream != 0) {
482 status_t result = stream->addEffect(mEffectInterface);
483 ALOGE_IF(result != OK, "Error when adding effect: %d", result);
Eric Laurent1b928682014-10-02 19:41:47 -0700484 }
485 }
486 }
487}
488
Eric Laurentfa1e1232016-08-02 19:01:49 -0700489// start() must be called with PlaybackThread::mLock or EffectChain::mLock held
Eric Laurentca7cc822012-11-19 14:55:58 -0800490status_t AudioFlinger::EffectModule::start()
491{
Eric Laurentfa1e1232016-08-02 19:01:49 -0700492 sp<EffectChain> chain;
493 status_t status;
494 {
495 Mutex::Autolock _l(mLock);
496 status = start_l();
497 if (status == NO_ERROR) {
498 chain = mChain.promote();
499 }
500 }
501 if (chain != 0) {
502 chain->resetVolume_l();
503 }
504 return status;
Eric Laurentca7cc822012-11-19 14:55:58 -0800505}
506
507status_t AudioFlinger::EffectModule::start_l()
508{
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700509 if (mEffectInterface == 0) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800510 return NO_INIT;
511 }
Eric Laurentd0ebb532013-04-02 16:41:41 -0700512 if (mStatus != NO_ERROR) {
513 return mStatus;
514 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800515 status_t cmdStatus;
516 uint32_t size = sizeof(status_t);
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700517 status_t status = mEffectInterface->command(EFFECT_CMD_ENABLE,
518 0,
519 NULL,
520 &size,
521 &cmdStatus);
Eric Laurentca7cc822012-11-19 14:55:58 -0800522 if (status == 0) {
523 status = cmdStatus;
524 }
Eric Laurentcb4b6e92014-10-01 14:26:10 -0700525 if (status == 0) {
Eric Laurent1b928682014-10-02 19:41:47 -0700526 addEffectToHal_l();
Eric Laurentca7cc822012-11-19 14:55:58 -0800527 }
528 return status;
529}
530
531status_t AudioFlinger::EffectModule::stop()
532{
533 Mutex::Autolock _l(mLock);
534 return stop_l();
535}
536
537status_t AudioFlinger::EffectModule::stop_l()
538{
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700539 if (mEffectInterface == 0) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800540 return NO_INIT;
541 }
Eric Laurentd0ebb532013-04-02 16:41:41 -0700542 if (mStatus != NO_ERROR) {
543 return mStatus;
544 }
Eric Laurentbfb1b832013-01-07 09:53:42 -0800545 status_t cmdStatus = NO_ERROR;
Eric Laurentca7cc822012-11-19 14:55:58 -0800546 uint32_t size = sizeof(status_t);
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700547 status_t status = mEffectInterface->command(EFFECT_CMD_DISABLE,
548 0,
549 NULL,
550 &size,
551 &cmdStatus);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800552 if (status == NO_ERROR) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800553 status = cmdStatus;
554 }
Eric Laurentbfb1b832013-01-07 09:53:42 -0800555 if (status == NO_ERROR) {
556 status = remove_effect_from_hal_l();
557 }
558 return status;
559}
560
561status_t AudioFlinger::EffectModule::remove_effect_from_hal_l()
562{
563 if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC ||
564 (mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_POST_PROC) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800565 sp<ThreadBase> thread = mThread.promote();
566 if (thread != 0) {
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700567 sp<StreamHalInterface> stream = thread->stream();
568 if (stream != 0) {
569 status_t result = stream->removeEffect(mEffectInterface);
570 ALOGE_IF(result != OK, "Error when removing effect: %d", result);
Eric Laurentca7cc822012-11-19 14:55:58 -0800571 }
572 }
573 }
Eric Laurentbfb1b832013-01-07 09:53:42 -0800574 return NO_ERROR;
Eric Laurentca7cc822012-11-19 14:55:58 -0800575}
576
Andy Hunge4a1d912016-08-17 14:11:13 -0700577// round up delta valid if value and divisor are positive.
578template <typename T>
579static T roundUpDelta(const T &value, const T &divisor) {
580 T remainder = value % divisor;
581 return remainder == 0 ? 0 : divisor - remainder;
582}
583
Eric Laurentca7cc822012-11-19 14:55:58 -0800584status_t AudioFlinger::EffectModule::command(uint32_t cmdCode,
585 uint32_t cmdSize,
586 void *pCmdData,
587 uint32_t *replySize,
588 void *pReplyData)
589{
590 Mutex::Autolock _l(mLock);
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700591 ALOGVV("command(), cmdCode: %d, mEffectInterface: %p", cmdCode, mEffectInterface.get());
Eric Laurentca7cc822012-11-19 14:55:58 -0800592
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700593 if (mState == DESTROYED || mEffectInterface == 0) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800594 return NO_INIT;
595 }
Eric Laurentd0ebb532013-04-02 16:41:41 -0700596 if (mStatus != NO_ERROR) {
597 return mStatus;
598 }
Andy Hung110bc952016-06-20 15:22:52 -0700599 if (cmdCode == EFFECT_CMD_GET_PARAM &&
600 (*replySize < sizeof(effect_param_t) ||
601 ((effect_param_t *)pCmdData)->psize > *replySize - sizeof(effect_param_t))) {
602 android_errorWriteLog(0x534e4554, "29251553");
603 return -EINVAL;
604 }
Andy Hunge4a1d912016-08-17 14:11:13 -0700605 if ((cmdCode == EFFECT_CMD_SET_PARAM
606 || cmdCode == EFFECT_CMD_SET_PARAM_DEFERRED) && // DEFERRED not generally used
607 (sizeof(effect_param_t) > cmdSize
608 || ((effect_param_t *)pCmdData)->psize > cmdSize
609 - sizeof(effect_param_t)
610 || ((effect_param_t *)pCmdData)->vsize > cmdSize
611 - sizeof(effect_param_t)
612 - ((effect_param_t *)pCmdData)->psize
613 || roundUpDelta(((effect_param_t *)pCmdData)->psize, (uint32_t)sizeof(int)) >
614 cmdSize
615 - sizeof(effect_param_t)
616 - ((effect_param_t *)pCmdData)->psize
617 - ((effect_param_t *)pCmdData)->vsize)) {
618 android_errorWriteLog(0x534e4554, "30204301");
619 return -EINVAL;
620 }
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700621 status_t status = mEffectInterface->command(cmdCode,
622 cmdSize,
623 pCmdData,
624 replySize,
625 pReplyData);
Eric Laurentca7cc822012-11-19 14:55:58 -0800626 if (cmdCode != EFFECT_CMD_GET_PARAM && status == NO_ERROR) {
627 uint32_t size = (replySize == NULL) ? 0 : *replySize;
628 for (size_t i = 1; i < mHandles.size(); i++) {
629 EffectHandle *h = mHandles[i];
630 if (h != NULL && !h->destroyed_l()) {
631 h->commandExecuted(cmdCode, cmdSize, pCmdData, size, pReplyData);
632 }
633 }
634 }
635 return status;
636}
637
638status_t AudioFlinger::EffectModule::setEnabled(bool enabled)
639{
640 Mutex::Autolock _l(mLock);
641 return setEnabled_l(enabled);
642}
643
644// must be called with EffectModule::mLock held
645status_t AudioFlinger::EffectModule::setEnabled_l(bool enabled)
646{
647
648 ALOGV("setEnabled %p enabled %d", this, enabled);
649
650 if (enabled != isEnabled()) {
651 status_t status = AudioSystem::setEffectEnabled(mId, enabled);
652 if (enabled && status != NO_ERROR) {
653 return status;
654 }
655
656 switch (mState) {
657 // going from disabled to enabled
658 case IDLE:
659 mState = STARTING;
660 break;
661 case STOPPED:
662 mState = RESTART;
663 break;
664 case STOPPING:
665 mState = ACTIVE;
666 break;
667
668 // going from enabled to disabled
669 case RESTART:
670 mState = STOPPED;
671 break;
672 case STARTING:
673 mState = IDLE;
674 break;
675 case ACTIVE:
676 mState = STOPPING;
677 break;
678 case DESTROYED:
679 return NO_ERROR; // simply ignore as we are being destroyed
680 }
681 for (size_t i = 1; i < mHandles.size(); i++) {
682 EffectHandle *h = mHandles[i];
683 if (h != NULL && !h->destroyed_l()) {
684 h->setEnabled(enabled);
685 }
686 }
687 }
688 return NO_ERROR;
689}
690
691bool AudioFlinger::EffectModule::isEnabled() const
692{
693 switch (mState) {
694 case RESTART:
695 case STARTING:
696 case ACTIVE:
697 return true;
698 case IDLE:
699 case STOPPING:
700 case STOPPED:
701 case DESTROYED:
702 default:
703 return false;
704 }
705}
706
707bool AudioFlinger::EffectModule::isProcessEnabled() const
708{
Eric Laurentd0ebb532013-04-02 16:41:41 -0700709 if (mStatus != NO_ERROR) {
710 return false;
711 }
712
Eric Laurentca7cc822012-11-19 14:55:58 -0800713 switch (mState) {
714 case RESTART:
715 case ACTIVE:
716 case STOPPING:
717 case STOPPED:
718 return true;
719 case IDLE:
720 case STARTING:
721 case DESTROYED:
722 default:
723 return false;
724 }
725}
726
727status_t AudioFlinger::EffectModule::setVolume(uint32_t *left, uint32_t *right, bool controller)
728{
729 Mutex::Autolock _l(mLock);
Eric Laurentd0ebb532013-04-02 16:41:41 -0700730 if (mStatus != NO_ERROR) {
731 return mStatus;
732 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800733 status_t status = NO_ERROR;
Eric Laurentca7cc822012-11-19 14:55:58 -0800734 // Send volume indication if EFFECT_FLAG_VOLUME_IND is set and read back altered volume
735 // if controller flag is set (Note that controller == TRUE => EFFECT_FLAG_VOLUME_CTRL set)
736 if (isProcessEnabled() &&
737 ((mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL ||
738 (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_IND)) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800739 uint32_t volume[2];
740 uint32_t *pVolume = NULL;
741 uint32_t size = sizeof(volume);
742 volume[0] = *left;
743 volume[1] = *right;
744 if (controller) {
745 pVolume = volume;
746 }
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700747 status = mEffectInterface->command(EFFECT_CMD_SET_VOLUME,
748 size,
749 volume,
750 &size,
751 pVolume);
Eric Laurentca7cc822012-11-19 14:55:58 -0800752 if (controller && status == NO_ERROR && size == sizeof(volume)) {
753 *left = volume[0];
754 *right = volume[1];
755 }
756 }
757 return status;
758}
759
760status_t AudioFlinger::EffectModule::setDevice(audio_devices_t device)
761{
762 if (device == AUDIO_DEVICE_NONE) {
763 return NO_ERROR;
764 }
765
766 Mutex::Autolock _l(mLock);
Eric Laurentd0ebb532013-04-02 16:41:41 -0700767 if (mStatus != NO_ERROR) {
768 return mStatus;
769 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800770 status_t status = NO_ERROR;
Eric Laurent7e1139c2013-06-06 18:29:01 -0700771 if ((mDescriptor.flags & EFFECT_FLAG_DEVICE_MASK) == EFFECT_FLAG_DEVICE_IND) {
Eric Laurentca7cc822012-11-19 14:55:58 -0800772 status_t cmdStatus;
773 uint32_t size = sizeof(status_t);
774 uint32_t cmd = audio_is_output_devices(device) ? EFFECT_CMD_SET_DEVICE :
775 EFFECT_CMD_SET_INPUT_DEVICE;
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700776 status = mEffectInterface->command(cmd,
777 sizeof(uint32_t),
778 &device,
779 &size,
780 &cmdStatus);
Eric Laurentca7cc822012-11-19 14:55:58 -0800781 }
782 return status;
783}
784
785status_t AudioFlinger::EffectModule::setMode(audio_mode_t mode)
786{
787 Mutex::Autolock _l(mLock);
Eric Laurentd0ebb532013-04-02 16:41:41 -0700788 if (mStatus != NO_ERROR) {
789 return mStatus;
790 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800791 status_t status = NO_ERROR;
792 if ((mDescriptor.flags & EFFECT_FLAG_AUDIO_MODE_MASK) == EFFECT_FLAG_AUDIO_MODE_IND) {
793 status_t cmdStatus;
794 uint32_t size = sizeof(status_t);
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700795 status = mEffectInterface->command(EFFECT_CMD_SET_AUDIO_MODE,
796 sizeof(audio_mode_t),
797 &mode,
798 &size,
799 &cmdStatus);
Eric Laurentca7cc822012-11-19 14:55:58 -0800800 if (status == NO_ERROR) {
801 status = cmdStatus;
802 }
803 }
804 return status;
805}
806
807status_t AudioFlinger::EffectModule::setAudioSource(audio_source_t source)
808{
809 Mutex::Autolock _l(mLock);
Eric Laurentd0ebb532013-04-02 16:41:41 -0700810 if (mStatus != NO_ERROR) {
811 return mStatus;
812 }
Eric Laurentca7cc822012-11-19 14:55:58 -0800813 status_t status = NO_ERROR;
814 if ((mDescriptor.flags & EFFECT_FLAG_AUDIO_SOURCE_MASK) == EFFECT_FLAG_AUDIO_SOURCE_IND) {
815 uint32_t size = 0;
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700816 status = mEffectInterface->command(EFFECT_CMD_SET_AUDIO_SOURCE,
817 sizeof(audio_source_t),
818 &source,
819 &size,
820 NULL);
Eric Laurentca7cc822012-11-19 14:55:58 -0800821 }
822 return status;
823}
824
825void AudioFlinger::EffectModule::setSuspended(bool suspended)
826{
827 Mutex::Autolock _l(mLock);
828 mSuspended = suspended;
829}
830
831bool AudioFlinger::EffectModule::suspended() const
832{
833 Mutex::Autolock _l(mLock);
834 return mSuspended;
835}
836
837bool AudioFlinger::EffectModule::purgeHandles()
838{
839 bool enabled = false;
840 Mutex::Autolock _l(mLock);
841 for (size_t i = 0; i < mHandles.size(); i++) {
842 EffectHandle *handle = mHandles[i];
843 if (handle != NULL && !handle->destroyed_l()) {
844 handle->effect().clear();
845 if (handle->hasControl()) {
846 enabled = handle->enabled();
847 }
848 }
849 }
850 return enabled;
851}
852
Eric Laurent5baf2af2013-09-12 17:37:00 -0700853status_t AudioFlinger::EffectModule::setOffloaded(bool offloaded, audio_io_handle_t io)
854{
855 Mutex::Autolock _l(mLock);
856 if (mStatus != NO_ERROR) {
857 return mStatus;
858 }
859 status_t status = NO_ERROR;
860 if ((mDescriptor.flags & EFFECT_FLAG_OFFLOAD_SUPPORTED) != 0) {
861 status_t cmdStatus;
862 uint32_t size = sizeof(status_t);
863 effect_offload_param_t cmd;
864
865 cmd.isOffload = offloaded;
866 cmd.ioHandle = io;
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700867 status = mEffectInterface->command(EFFECT_CMD_OFFLOAD,
868 sizeof(effect_offload_param_t),
869 &cmd,
870 &size,
871 &cmdStatus);
Eric Laurent5baf2af2013-09-12 17:37:00 -0700872 if (status == NO_ERROR) {
873 status = cmdStatus;
874 }
875 mOffloaded = (status == NO_ERROR) ? offloaded : false;
876 } else {
877 if (offloaded) {
878 status = INVALID_OPERATION;
879 }
880 mOffloaded = false;
881 }
882 ALOGV("setOffloaded() offloaded %d io %d status %d", offloaded, io, status);
883 return status;
884}
885
886bool AudioFlinger::EffectModule::isOffloaded() const
887{
888 Mutex::Autolock _l(mLock);
889 return mOffloaded;
890}
891
Marco Nelissenb2208842014-02-07 14:00:50 -0800892String8 effectFlagsToString(uint32_t flags) {
893 String8 s;
894
895 s.append("conn. mode: ");
896 switch (flags & EFFECT_FLAG_TYPE_MASK) {
897 case EFFECT_FLAG_TYPE_INSERT: s.append("insert"); break;
898 case EFFECT_FLAG_TYPE_AUXILIARY: s.append("auxiliary"); break;
899 case EFFECT_FLAG_TYPE_REPLACE: s.append("replace"); break;
900 case EFFECT_FLAG_TYPE_PRE_PROC: s.append("preproc"); break;
901 case EFFECT_FLAG_TYPE_POST_PROC: s.append("postproc"); break;
902 default: s.append("unknown/reserved"); break;
903 }
904 s.append(", ");
905
906 s.append("insert pref: ");
907 switch (flags & EFFECT_FLAG_INSERT_MASK) {
908 case EFFECT_FLAG_INSERT_ANY: s.append("any"); break;
909 case EFFECT_FLAG_INSERT_FIRST: s.append("first"); break;
910 case EFFECT_FLAG_INSERT_LAST: s.append("last"); break;
911 case EFFECT_FLAG_INSERT_EXCLUSIVE: s.append("exclusive"); break;
912 default: s.append("unknown/reserved"); break;
913 }
914 s.append(", ");
915
916 s.append("volume mgmt: ");
917 switch (flags & EFFECT_FLAG_VOLUME_MASK) {
918 case EFFECT_FLAG_VOLUME_NONE: s.append("none"); break;
919 case EFFECT_FLAG_VOLUME_CTRL: s.append("implements control"); break;
920 case EFFECT_FLAG_VOLUME_IND: s.append("requires indication"); break;
921 default: s.append("unknown/reserved"); break;
922 }
923 s.append(", ");
924
925 uint32_t devind = flags & EFFECT_FLAG_DEVICE_MASK;
926 if (devind) {
927 s.append("device indication: ");
928 switch (devind) {
929 case EFFECT_FLAG_DEVICE_IND: s.append("requires updates"); break;
930 default: s.append("unknown/reserved"); break;
931 }
932 s.append(", ");
933 }
934
935 s.append("input mode: ");
936 switch (flags & EFFECT_FLAG_INPUT_MASK) {
937 case EFFECT_FLAG_INPUT_DIRECT: s.append("direct"); break;
938 case EFFECT_FLAG_INPUT_PROVIDER: s.append("provider"); break;
939 case EFFECT_FLAG_INPUT_BOTH: s.append("direct+provider"); break;
940 default: s.append("not set"); break;
941 }
942 s.append(", ");
943
944 s.append("output mode: ");
945 switch (flags & EFFECT_FLAG_OUTPUT_MASK) {
946 case EFFECT_FLAG_OUTPUT_DIRECT: s.append("direct"); break;
947 case EFFECT_FLAG_OUTPUT_PROVIDER: s.append("provider"); break;
948 case EFFECT_FLAG_OUTPUT_BOTH: s.append("direct+provider"); break;
949 default: s.append("not set"); break;
950 }
951 s.append(", ");
952
953 uint32_t accel = flags & EFFECT_FLAG_HW_ACC_MASK;
954 if (accel) {
955 s.append("hardware acceleration: ");
956 switch (accel) {
957 case EFFECT_FLAG_HW_ACC_SIMPLE: s.append("non-tunneled"); break;
958 case EFFECT_FLAG_HW_ACC_TUNNEL: s.append("tunneled"); break;
959 default: s.append("unknown/reserved"); break;
960 }
961 s.append(", ");
962 }
963
964 uint32_t modeind = flags & EFFECT_FLAG_AUDIO_MODE_MASK;
965 if (modeind) {
966 s.append("mode indication: ");
967 switch (modeind) {
968 case EFFECT_FLAG_AUDIO_MODE_IND: s.append("required"); break;
969 default: s.append("unknown/reserved"); break;
970 }
971 s.append(", ");
972 }
973
974 uint32_t srcind = flags & EFFECT_FLAG_AUDIO_SOURCE_MASK;
975 if (srcind) {
976 s.append("source indication: ");
977 switch (srcind) {
978 case EFFECT_FLAG_AUDIO_SOURCE_IND: s.append("required"); break;
979 default: s.append("unknown/reserved"); break;
980 }
981 s.append(", ");
982 }
983
984 if (flags & EFFECT_FLAG_OFFLOAD_MASK) {
985 s.append("offloadable, ");
986 }
987
988 int len = s.length();
989 if (s.length() > 2) {
Glenn Kasten57c4e6f2016-03-18 14:54:07 -0700990 (void) s.lockBuffer(len);
Marco Nelissenb2208842014-02-07 14:00:50 -0800991 s.unlockBuffer(len - 2);
992 }
993 return s;
994}
995
996
Glenn Kasten0f11b512014-01-31 16:18:54 -0800997void AudioFlinger::EffectModule::dump(int fd, const Vector<String16>& args __unused)
Eric Laurentca7cc822012-11-19 14:55:58 -0800998{
999 const size_t SIZE = 256;
1000 char buffer[SIZE];
1001 String8 result;
1002
1003 snprintf(buffer, SIZE, "\tEffect ID %d:\n", mId);
1004 result.append(buffer);
1005
1006 bool locked = AudioFlinger::dumpTryLock(mLock);
1007 // failed to lock - AudioFlinger is probably deadlocked
1008 if (!locked) {
1009 result.append("\t\tCould not lock Fx mutex:\n");
1010 }
1011
1012 result.append("\t\tSession Status State Engine:\n");
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001013 snprintf(buffer, SIZE, "\t\t%05d %03d %03d %p\n",
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -07001014 mSessionId, mStatus, mState, mEffectInterface.get());
Eric Laurentca7cc822012-11-19 14:55:58 -08001015 result.append(buffer);
1016
1017 result.append("\t\tDescriptor:\n");
1018 snprintf(buffer, SIZE, "\t\t- UUID: %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n",
1019 mDescriptor.uuid.timeLow, mDescriptor.uuid.timeMid, mDescriptor.uuid.timeHiAndVersion,
1020 mDescriptor.uuid.clockSeq, mDescriptor.uuid.node[0], mDescriptor.uuid.node[1],
1021 mDescriptor.uuid.node[2],
1022 mDescriptor.uuid.node[3],mDescriptor.uuid.node[4],mDescriptor.uuid.node[5]);
1023 result.append(buffer);
1024 snprintf(buffer, SIZE, "\t\t- TYPE: %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n",
1025 mDescriptor.type.timeLow, mDescriptor.type.timeMid,
1026 mDescriptor.type.timeHiAndVersion,
1027 mDescriptor.type.clockSeq, mDescriptor.type.node[0], mDescriptor.type.node[1],
1028 mDescriptor.type.node[2],
1029 mDescriptor.type.node[3],mDescriptor.type.node[4],mDescriptor.type.node[5]);
1030 result.append(buffer);
Marco Nelissenb2208842014-02-07 14:00:50 -08001031 snprintf(buffer, SIZE, "\t\t- apiVersion: %08X\n\t\t- flags: %08X (%s)\n",
Eric Laurentca7cc822012-11-19 14:55:58 -08001032 mDescriptor.apiVersion,
Marco Nelissenb2208842014-02-07 14:00:50 -08001033 mDescriptor.flags,
1034 effectFlagsToString(mDescriptor.flags).string());
Eric Laurentca7cc822012-11-19 14:55:58 -08001035 result.append(buffer);
1036 snprintf(buffer, SIZE, "\t\t- name: %s\n",
1037 mDescriptor.name);
1038 result.append(buffer);
1039 snprintf(buffer, SIZE, "\t\t- implementor: %s\n",
1040 mDescriptor.implementor);
1041 result.append(buffer);
1042
1043 result.append("\t\t- Input configuration:\n");
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001044 result.append("\t\t\tFrames Smp rate Channels Format Buffer\n");
Narayan Kamath1d6fa7a2014-02-11 13:47:53 +00001045 snprintf(buffer, SIZE, "\t\t\t%05zu %05d %08x %6d (%s) %p\n",
Eric Laurentca7cc822012-11-19 14:55:58 -08001046 mConfig.inputCfg.buffer.frameCount,
1047 mConfig.inputCfg.samplingRate,
1048 mConfig.inputCfg.channels,
Marco Nelissenb2208842014-02-07 14:00:50 -08001049 mConfig.inputCfg.format,
Narayan Kamath1d6fa7a2014-02-11 13:47:53 +00001050 formatToString((audio_format_t)mConfig.inputCfg.format),
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001051 mConfig.inputCfg.buffer.raw);
Eric Laurentca7cc822012-11-19 14:55:58 -08001052 result.append(buffer);
1053
1054 result.append("\t\t- Output configuration:\n");
1055 result.append("\t\t\tBuffer Frames Smp rate Channels Format\n");
Narayan Kamath1d6fa7a2014-02-11 13:47:53 +00001056 snprintf(buffer, SIZE, "\t\t\t%p %05zu %05d %08x %d (%s)\n",
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001057 mConfig.outputCfg.buffer.raw,
Eric Laurentca7cc822012-11-19 14:55:58 -08001058 mConfig.outputCfg.buffer.frameCount,
1059 mConfig.outputCfg.samplingRate,
1060 mConfig.outputCfg.channels,
Marco Nelissenb2208842014-02-07 14:00:50 -08001061 mConfig.outputCfg.format,
1062 formatToString((audio_format_t)mConfig.outputCfg.format));
Eric Laurentca7cc822012-11-19 14:55:58 -08001063 result.append(buffer);
1064
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001065 snprintf(buffer, SIZE, "\t\t%zu Clients:\n", mHandles.size());
Eric Laurentca7cc822012-11-19 14:55:58 -08001066 result.append(buffer);
Marco Nelissenb2208842014-02-07 14:00:50 -08001067 result.append("\t\t\t Pid Priority Ctrl Locked client server\n");
Eric Laurentca7cc822012-11-19 14:55:58 -08001068 for (size_t i = 0; i < mHandles.size(); ++i) {
1069 EffectHandle *handle = mHandles[i];
1070 if (handle != NULL && !handle->destroyed_l()) {
Glenn Kasten01d3acb2014-02-06 08:24:07 -08001071 handle->dumpToBuffer(buffer, SIZE);
Eric Laurentca7cc822012-11-19 14:55:58 -08001072 result.append(buffer);
1073 }
1074 }
1075
Eric Laurentca7cc822012-11-19 14:55:58 -08001076 write(fd, result.string(), result.length());
1077
1078 if (locked) {
1079 mLock.unlock();
1080 }
1081}
1082
1083// ----------------------------------------------------------------------------
1084// EffectHandle implementation
1085// ----------------------------------------------------------------------------
1086
1087#undef LOG_TAG
1088#define LOG_TAG "AudioFlinger::EffectHandle"
1089
1090AudioFlinger::EffectHandle::EffectHandle(const sp<EffectModule>& effect,
1091 const sp<AudioFlinger::Client>& client,
1092 const sp<IEffectClient>& effectClient,
1093 int32_t priority)
1094 : BnEffect(),
1095 mEffect(effect), mEffectClient(effectClient), mClient(client), mCblk(NULL),
1096 mPriority(priority), mHasControl(false), mEnabled(false), mDestroyed(false)
1097{
1098 ALOGV("constructor %p", this);
1099
1100 if (client == 0) {
1101 return;
1102 }
1103 int bufOffset = ((sizeof(effect_param_cblk_t) - 1) / sizeof(int) + 1) * sizeof(int);
1104 mCblkMemory = client->heap()->allocate(EFFECT_PARAM_BUFFER_SIZE + bufOffset);
Glenn Kastene75da402013-11-20 13:54:52 -08001105 if (mCblkMemory == 0 ||
1106 (mCblk = static_cast<effect_param_cblk_t *>(mCblkMemory->pointer())) == NULL) {
Glenn Kastenc42e9b42016-03-21 11:35:03 -07001107 ALOGE("not enough memory for Effect size=%zu", EFFECT_PARAM_BUFFER_SIZE +
Eric Laurentca7cc822012-11-19 14:55:58 -08001108 sizeof(effect_param_cblk_t));
Glenn Kastene75da402013-11-20 13:54:52 -08001109 mCblkMemory.clear();
Eric Laurentca7cc822012-11-19 14:55:58 -08001110 return;
1111 }
Glenn Kastene75da402013-11-20 13:54:52 -08001112 new(mCblk) effect_param_cblk_t();
1113 mBuffer = (uint8_t *)mCblk + bufOffset;
Eric Laurentca7cc822012-11-19 14:55:58 -08001114}
1115
1116AudioFlinger::EffectHandle::~EffectHandle()
1117{
1118 ALOGV("Destructor %p", this);
1119
1120 if (mEffect == 0) {
1121 mDestroyed = true;
1122 return;
1123 }
1124 mEffect->lock();
1125 mDestroyed = true;
1126 mEffect->unlock();
1127 disconnect(false);
1128}
1129
Glenn Kastene75da402013-11-20 13:54:52 -08001130status_t AudioFlinger::EffectHandle::initCheck()
1131{
1132 return mClient == 0 || mCblkMemory != 0 ? OK : NO_MEMORY;
1133}
1134
Eric Laurentca7cc822012-11-19 14:55:58 -08001135status_t AudioFlinger::EffectHandle::enable()
1136{
1137 ALOGV("enable %p", this);
1138 if (!mHasControl) {
1139 return INVALID_OPERATION;
1140 }
1141 if (mEffect == 0) {
1142 return DEAD_OBJECT;
1143 }
1144
1145 if (mEnabled) {
1146 return NO_ERROR;
1147 }
1148
1149 mEnabled = true;
1150
1151 sp<ThreadBase> thread = mEffect->thread().promote();
1152 if (thread != 0) {
1153 thread->checkSuspendOnEffectEnabled(mEffect, true, mEffect->sessionId());
1154 }
1155
1156 // checkSuspendOnEffectEnabled() can suspend this same effect when enabled
1157 if (mEffect->suspended()) {
1158 return NO_ERROR;
1159 }
1160
1161 status_t status = mEffect->setEnabled(true);
1162 if (status != NO_ERROR) {
1163 if (thread != 0) {
1164 thread->checkSuspendOnEffectEnabled(mEffect, false, mEffect->sessionId());
1165 }
1166 mEnabled = false;
Eric Laurent813e2a72013-08-31 12:59:48 -07001167 } else {
Eric Laurent59fe0102013-09-27 18:48:26 -07001168 if (thread != 0) {
1169 if (thread->type() == ThreadBase::OFFLOAD) {
Eric Laurent813e2a72013-08-31 12:59:48 -07001170 PlaybackThread *t = (PlaybackThread *)thread.get();
Eric Laurent59fe0102013-09-27 18:48:26 -07001171 Mutex::Autolock _l(t->mLock);
1172 t->broadcast_l();
Eric Laurent813e2a72013-08-31 12:59:48 -07001173 }
Eric Laurent59fe0102013-09-27 18:48:26 -07001174 if (!mEffect->isOffloadable()) {
1175 if (thread->type() == ThreadBase::OFFLOAD) {
1176 PlaybackThread *t = (PlaybackThread *)thread.get();
1177 t->invalidateTracks(AUDIO_STREAM_MUSIC);
1178 }
1179 if (mEffect->sessionId() == AUDIO_SESSION_OUTPUT_MIX) {
1180 thread->mAudioFlinger->onNonOffloadableGlobalEffectEnable();
1181 }
Eric Laurent813e2a72013-08-31 12:59:48 -07001182 }
1183 }
Eric Laurentca7cc822012-11-19 14:55:58 -08001184 }
1185 return status;
1186}
1187
1188status_t AudioFlinger::EffectHandle::disable()
1189{
1190 ALOGV("disable %p", this);
1191 if (!mHasControl) {
1192 return INVALID_OPERATION;
1193 }
1194 if (mEffect == 0) {
1195 return DEAD_OBJECT;
1196 }
1197
1198 if (!mEnabled) {
1199 return NO_ERROR;
1200 }
1201 mEnabled = false;
1202
1203 if (mEffect->suspended()) {
1204 return NO_ERROR;
1205 }
1206
1207 status_t status = mEffect->setEnabled(false);
1208
1209 sp<ThreadBase> thread = mEffect->thread().promote();
1210 if (thread != 0) {
1211 thread->checkSuspendOnEffectEnabled(mEffect, false, mEffect->sessionId());
Eric Laurent59fe0102013-09-27 18:48:26 -07001212 if (thread->type() == ThreadBase::OFFLOAD) {
1213 PlaybackThread *t = (PlaybackThread *)thread.get();
1214 Mutex::Autolock _l(t->mLock);
1215 t->broadcast_l();
1216 }
Eric Laurentca7cc822012-11-19 14:55:58 -08001217 }
1218
1219 return status;
1220}
1221
1222void AudioFlinger::EffectHandle::disconnect()
1223{
1224 disconnect(true);
1225}
1226
1227void AudioFlinger::EffectHandle::disconnect(bool unpinIfLast)
1228{
1229 ALOGV("disconnect(%s)", unpinIfLast ? "true" : "false");
1230 if (mEffect == 0) {
1231 return;
1232 }
1233 // restore suspended effects if the disconnected handle was enabled and the last one.
1234 if ((mEffect->disconnect(this, unpinIfLast) == 0) && mEnabled) {
1235 sp<ThreadBase> thread = mEffect->thread().promote();
1236 if (thread != 0) {
1237 thread->checkSuspendOnEffectEnabled(mEffect, false, mEffect->sessionId());
1238 }
1239 }
1240
1241 // release sp on module => module destructor can be called now
1242 mEffect.clear();
1243 if (mClient != 0) {
1244 if (mCblk != NULL) {
1245 // unlike ~TrackBase(), mCblk is never a local new, so don't delete
1246 mCblk->~effect_param_cblk_t(); // destroy our shared-structure.
1247 }
1248 mCblkMemory.clear(); // free the shared memory before releasing the heap it belongs to
Eric Laurent021cf962014-05-13 10:18:14 -07001249 // Client destructor must run with AudioFlinger client mutex locked
1250 Mutex::Autolock _l(mClient->audioFlinger()->mClientLock);
Eric Laurentca7cc822012-11-19 14:55:58 -08001251 mClient.clear();
1252 }
1253}
1254
1255status_t AudioFlinger::EffectHandle::command(uint32_t cmdCode,
1256 uint32_t cmdSize,
1257 void *pCmdData,
1258 uint32_t *replySize,
1259 void *pReplyData)
1260{
1261 ALOGVV("command(), cmdCode: %d, mHasControl: %d, mEffect: %p",
1262 cmdCode, mHasControl, (mEffect == 0) ? 0 : mEffect.get());
1263
1264 // only get parameter command is permitted for applications not controlling the effect
1265 if (!mHasControl && cmdCode != EFFECT_CMD_GET_PARAM) {
1266 return INVALID_OPERATION;
1267 }
1268 if (mEffect == 0) {
1269 return DEAD_OBJECT;
1270 }
1271 if (mClient == 0) {
1272 return INVALID_OPERATION;
1273 }
1274
1275 // handle commands that are not forwarded transparently to effect engine
1276 if (cmdCode == EFFECT_CMD_SET_PARAM_COMMIT) {
1277 // No need to trylock() here as this function is executed in the binder thread serving a
1278 // particular client process: no risk to block the whole media server process or mixer
1279 // threads if we are stuck here
1280 Mutex::Autolock _l(mCblk->lock);
1281 if (mCblk->clientIndex > EFFECT_PARAM_BUFFER_SIZE ||
1282 mCblk->serverIndex > EFFECT_PARAM_BUFFER_SIZE) {
1283 mCblk->serverIndex = 0;
1284 mCblk->clientIndex = 0;
1285 return BAD_VALUE;
1286 }
1287 status_t status = NO_ERROR;
1288 while (mCblk->serverIndex < mCblk->clientIndex) {
1289 int reply;
1290 uint32_t rsize = sizeof(int);
1291 int *p = (int *)(mBuffer + mCblk->serverIndex);
1292 int size = *p++;
1293 if (((uint8_t *)p + size) > mBuffer + mCblk->clientIndex) {
1294 ALOGW("command(): invalid parameter block size");
1295 break;
1296 }
1297 effect_param_t *param = (effect_param_t *)p;
1298 if (param->psize == 0 || param->vsize == 0) {
1299 ALOGW("command(): null parameter or value size");
1300 mCblk->serverIndex += size;
1301 continue;
1302 }
1303 uint32_t psize = sizeof(effect_param_t) +
1304 ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) +
1305 param->vsize;
1306 status_t ret = mEffect->command(EFFECT_CMD_SET_PARAM,
1307 psize,
1308 p,
1309 &rsize,
1310 &reply);
1311 // stop at first error encountered
1312 if (ret != NO_ERROR) {
1313 status = ret;
1314 *(int *)pReplyData = reply;
1315 break;
1316 } else if (reply != NO_ERROR) {
1317 *(int *)pReplyData = reply;
1318 break;
1319 }
1320 mCblk->serverIndex += size;
1321 }
1322 mCblk->serverIndex = 0;
1323 mCblk->clientIndex = 0;
1324 return status;
1325 } else if (cmdCode == EFFECT_CMD_ENABLE) {
1326 *(int *)pReplyData = NO_ERROR;
1327 return enable();
1328 } else if (cmdCode == EFFECT_CMD_DISABLE) {
1329 *(int *)pReplyData = NO_ERROR;
1330 return disable();
1331 }
1332
1333 return mEffect->command(cmdCode, cmdSize, pCmdData, replySize, pReplyData);
1334}
1335
1336void AudioFlinger::EffectHandle::setControl(bool hasControl, bool signal, bool enabled)
1337{
1338 ALOGV("setControl %p control %d", this, hasControl);
1339
1340 mHasControl = hasControl;
1341 mEnabled = enabled;
1342
1343 if (signal && mEffectClient != 0) {
1344 mEffectClient->controlStatusChanged(hasControl);
1345 }
1346}
1347
1348void AudioFlinger::EffectHandle::commandExecuted(uint32_t cmdCode,
1349 uint32_t cmdSize,
1350 void *pCmdData,
1351 uint32_t replySize,
1352 void *pReplyData)
1353{
1354 if (mEffectClient != 0) {
1355 mEffectClient->commandExecuted(cmdCode, cmdSize, pCmdData, replySize, pReplyData);
1356 }
1357}
1358
1359
1360
1361void AudioFlinger::EffectHandle::setEnabled(bool enabled)
1362{
1363 if (mEffectClient != 0) {
1364 mEffectClient->enableStatusChanged(enabled);
1365 }
1366}
1367
1368status_t AudioFlinger::EffectHandle::onTransact(
1369 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1370{
1371 return BnEffect::onTransact(code, data, reply, flags);
1372}
1373
1374
Glenn Kasten01d3acb2014-02-06 08:24:07 -08001375void AudioFlinger::EffectHandle::dumpToBuffer(char* buffer, size_t size)
Eric Laurentca7cc822012-11-19 14:55:58 -08001376{
1377 bool locked = mCblk != NULL && AudioFlinger::dumpTryLock(mCblk->lock);
1378
Marco Nelissenb2208842014-02-07 14:00:50 -08001379 snprintf(buffer, size, "\t\t\t%5d %5d %3s %3s %5u %5u\n",
Eric Laurentca7cc822012-11-19 14:55:58 -08001380 (mClient == 0) ? getpid_cached : mClient->pid(),
1381 mPriority,
Marco Nelissenb2208842014-02-07 14:00:50 -08001382 mHasControl ? "yes" : "no",
1383 locked ? "yes" : "no",
Eric Laurentca7cc822012-11-19 14:55:58 -08001384 mCblk ? mCblk->clientIndex : 0,
1385 mCblk ? mCblk->serverIndex : 0
1386 );
1387
1388 if (locked) {
1389 mCblk->lock.unlock();
1390 }
1391}
1392
1393#undef LOG_TAG
1394#define LOG_TAG "AudioFlinger::EffectChain"
1395
1396AudioFlinger::EffectChain::EffectChain(ThreadBase *thread,
Glenn Kastend848eb42016-03-08 13:42:11 -08001397 audio_session_t sessionId)
Eric Laurentca7cc822012-11-19 14:55:58 -08001398 : mThread(thread), mSessionId(sessionId), mActiveTrackCnt(0), mTrackCnt(0), mTailBufferCount(0),
1399 mOwnInBuffer(false), mVolumeCtrlIdx(-1), mLeftVolume(UINT_MAX), mRightVolume(UINT_MAX),
Eric Laurentfa1e1232016-08-02 19:01:49 -07001400 mNewLeftVolume(UINT_MAX), mNewRightVolume(UINT_MAX)
Eric Laurentca7cc822012-11-19 14:55:58 -08001401{
1402 mStrategy = AudioSystem::getStrategyForStream(AUDIO_STREAM_MUSIC);
1403 if (thread == NULL) {
1404 return;
1405 }
1406 mMaxTailBuffers = ((kProcessTailDurationMs * thread->sampleRate()) / 1000) /
1407 thread->frameCount();
1408}
1409
1410AudioFlinger::EffectChain::~EffectChain()
1411{
1412 if (mOwnInBuffer) {
1413 delete mInBuffer;
1414 }
1415
1416}
1417
1418// getEffectFromDesc_l() must be called with ThreadBase::mLock held
1419sp<AudioFlinger::EffectModule> AudioFlinger::EffectChain::getEffectFromDesc_l(
1420 effect_descriptor_t *descriptor)
1421{
1422 size_t size = mEffects.size();
1423
1424 for (size_t i = 0; i < size; i++) {
1425 if (memcmp(&mEffects[i]->desc().uuid, &descriptor->uuid, sizeof(effect_uuid_t)) == 0) {
1426 return mEffects[i];
1427 }
1428 }
1429 return 0;
1430}
1431
1432// getEffectFromId_l() must be called with ThreadBase::mLock held
1433sp<AudioFlinger::EffectModule> AudioFlinger::EffectChain::getEffectFromId_l(int id)
1434{
1435 size_t size = mEffects.size();
1436
1437 for (size_t i = 0; i < size; i++) {
1438 // by convention, return first effect if id provided is 0 (0 is never a valid id)
1439 if (id == 0 || mEffects[i]->id() == id) {
1440 return mEffects[i];
1441 }
1442 }
1443 return 0;
1444}
1445
1446// getEffectFromType_l() must be called with ThreadBase::mLock held
1447sp<AudioFlinger::EffectModule> AudioFlinger::EffectChain::getEffectFromType_l(
1448 const effect_uuid_t *type)
1449{
1450 size_t size = mEffects.size();
1451
1452 for (size_t i = 0; i < size; i++) {
1453 if (memcmp(&mEffects[i]->desc().type, type, sizeof(effect_uuid_t)) == 0) {
1454 return mEffects[i];
1455 }
1456 }
1457 return 0;
1458}
1459
1460void AudioFlinger::EffectChain::clearInputBuffer()
1461{
1462 Mutex::Autolock _l(mLock);
1463 sp<ThreadBase> thread = mThread.promote();
1464 if (thread == 0) {
1465 ALOGW("clearInputBuffer(): cannot promote mixer thread");
1466 return;
1467 }
1468 clearInputBuffer_l(thread);
1469}
1470
1471// Must be called with EffectChain::mLock locked
Chih-Hung Hsieh36d0ca12016-08-09 14:31:32 -07001472void AudioFlinger::EffectChain::clearInputBuffer_l(const sp<ThreadBase>& thread)
Eric Laurentca7cc822012-11-19 14:55:58 -08001473{
Ricardo Garcia322bab22014-08-06 11:43:46 -07001474 // TODO: This will change in the future, depending on multichannel
1475 // and sample format changes for effects.
1476 // Currently effects processing is only available for stereo, AUDIO_FORMAT_PCM_16_BIT
1477 // (4 bytes frame size)
Ricardo Garcia726b6a72014-08-11 12:04:54 -07001478 const size_t frameSize =
1479 audio_bytes_per_sample(AUDIO_FORMAT_PCM_16_BIT) * min(FCC_2, thread->channelCount());
Ricardo Garcia322bab22014-08-06 11:43:46 -07001480 memset(mInBuffer, 0, thread->frameCount() * frameSize);
Eric Laurentca7cc822012-11-19 14:55:58 -08001481}
1482
1483// Must be called with EffectChain::mLock locked
1484void AudioFlinger::EffectChain::process_l()
1485{
1486 sp<ThreadBase> thread = mThread.promote();
1487 if (thread == 0) {
1488 ALOGW("process_l(): cannot promote mixer thread");
1489 return;
1490 }
1491 bool isGlobalSession = (mSessionId == AUDIO_SESSION_OUTPUT_MIX) ||
1492 (mSessionId == AUDIO_SESSION_OUTPUT_STAGE);
Jean-Michel Trivifed62922013-09-25 18:50:33 -07001493 // never process effects when:
1494 // - on an OFFLOAD thread
1495 // - no more tracks are on the session and the effect tail has been rendered
1496 bool doProcess = (thread->type() != ThreadBase::OFFLOAD);
Eric Laurentca7cc822012-11-19 14:55:58 -08001497 if (!isGlobalSession) {
1498 bool tracksOnSession = (trackCnt() != 0);
1499
1500 if (!tracksOnSession && mTailBufferCount == 0) {
1501 doProcess = false;
1502 }
1503
1504 if (activeTrackCnt() == 0) {
1505 // if no track is active and the effect tail has not been rendered,
1506 // the input buffer must be cleared here as the mixer process will not do it
1507 if (tracksOnSession || mTailBufferCount > 0) {
1508 clearInputBuffer_l(thread);
1509 if (mTailBufferCount > 0) {
1510 mTailBufferCount--;
1511 }
1512 }
1513 }
1514 }
1515
1516 size_t size = mEffects.size();
1517 if (doProcess) {
1518 for (size_t i = 0; i < size; i++) {
1519 mEffects[i]->process();
1520 }
1521 }
Eric Laurentfa1e1232016-08-02 19:01:49 -07001522 bool doResetVolume = false;
Eric Laurentca7cc822012-11-19 14:55:58 -08001523 for (size_t i = 0; i < size; i++) {
Eric Laurentfa1e1232016-08-02 19:01:49 -07001524 doResetVolume = mEffects[i]->updateState() || doResetVolume;
1525 }
1526 if (doResetVolume) {
1527 resetVolume_l();
Eric Laurentca7cc822012-11-19 14:55:58 -08001528 }
1529}
1530
1531// addEffect_l() must be called with PlaybackThread::mLock held
1532status_t AudioFlinger::EffectChain::addEffect_l(const sp<EffectModule>& effect)
1533{
1534 effect_descriptor_t desc = effect->desc();
1535 uint32_t insertPref = desc.flags & EFFECT_FLAG_INSERT_MASK;
1536
1537 Mutex::Autolock _l(mLock);
1538 effect->setChain(this);
1539 sp<ThreadBase> thread = mThread.promote();
1540 if (thread == 0) {
1541 return NO_INIT;
1542 }
1543 effect->setThread(thread);
1544
1545 if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
1546 // Auxiliary effects are inserted at the beginning of mEffects vector as
1547 // they are processed first and accumulated in chain input buffer
1548 mEffects.insertAt(effect, 0);
1549
1550 // the input buffer for auxiliary effect contains mono samples in
1551 // 32 bit format. This is to avoid saturation in AudoMixer
1552 // accumulation stage. Saturation is done in EffectModule::process() before
1553 // calling the process in effect engine
1554 size_t numSamples = thread->frameCount();
1555 int32_t *buffer = new int32_t[numSamples];
1556 memset(buffer, 0, numSamples * sizeof(int32_t));
1557 effect->setInBuffer((int16_t *)buffer);
1558 // auxiliary effects output samples to chain input buffer for further processing
1559 // by insert effects
1560 effect->setOutBuffer(mInBuffer);
1561 } else {
1562 // Insert effects are inserted at the end of mEffects vector as they are processed
1563 // after track and auxiliary effects.
1564 // Insert effect order as a function of indicated preference:
1565 // if EFFECT_FLAG_INSERT_EXCLUSIVE, insert in first position or reject if
1566 // another effect is present
1567 // else if EFFECT_FLAG_INSERT_FIRST, insert in first position or after the
1568 // last effect claiming first position
1569 // else if EFFECT_FLAG_INSERT_LAST, insert in last position or before the
1570 // first effect claiming last position
1571 // else if EFFECT_FLAG_INSERT_ANY insert after first or before last
1572 // Reject insertion if an effect with EFFECT_FLAG_INSERT_EXCLUSIVE is
1573 // already present
1574
1575 size_t size = mEffects.size();
1576 size_t idx_insert = size;
1577 ssize_t idx_insert_first = -1;
1578 ssize_t idx_insert_last = -1;
1579
1580 for (size_t i = 0; i < size; i++) {
1581 effect_descriptor_t d = mEffects[i]->desc();
1582 uint32_t iMode = d.flags & EFFECT_FLAG_TYPE_MASK;
1583 uint32_t iPref = d.flags & EFFECT_FLAG_INSERT_MASK;
1584 if (iMode == EFFECT_FLAG_TYPE_INSERT) {
1585 // check invalid effect chaining combinations
1586 if (insertPref == EFFECT_FLAG_INSERT_EXCLUSIVE ||
1587 iPref == EFFECT_FLAG_INSERT_EXCLUSIVE) {
1588 ALOGW("addEffect_l() could not insert effect %s: exclusive conflict with %s",
1589 desc.name, d.name);
1590 return INVALID_OPERATION;
1591 }
1592 // remember position of first insert effect and by default
1593 // select this as insert position for new effect
1594 if (idx_insert == size) {
1595 idx_insert = i;
1596 }
1597 // remember position of last insert effect claiming
1598 // first position
1599 if (iPref == EFFECT_FLAG_INSERT_FIRST) {
1600 idx_insert_first = i;
1601 }
1602 // remember position of first insert effect claiming
1603 // last position
1604 if (iPref == EFFECT_FLAG_INSERT_LAST &&
1605 idx_insert_last == -1) {
1606 idx_insert_last = i;
1607 }
1608 }
1609 }
1610
1611 // modify idx_insert from first position if needed
1612 if (insertPref == EFFECT_FLAG_INSERT_LAST) {
1613 if (idx_insert_last != -1) {
1614 idx_insert = idx_insert_last;
1615 } else {
1616 idx_insert = size;
1617 }
1618 } else {
1619 if (idx_insert_first != -1) {
1620 idx_insert = idx_insert_first + 1;
1621 }
1622 }
1623
1624 // always read samples from chain input buffer
1625 effect->setInBuffer(mInBuffer);
1626
1627 // if last effect in the chain, output samples to chain
1628 // output buffer, otherwise to chain input buffer
1629 if (idx_insert == size) {
1630 if (idx_insert != 0) {
1631 mEffects[idx_insert-1]->setOutBuffer(mInBuffer);
1632 mEffects[idx_insert-1]->configure();
1633 }
1634 effect->setOutBuffer(mOutBuffer);
1635 } else {
1636 effect->setOutBuffer(mInBuffer);
1637 }
1638 mEffects.insertAt(effect, idx_insert);
1639
Glenn Kastenc42e9b42016-03-21 11:35:03 -07001640 ALOGV("addEffect_l() effect %p, added in chain %p at rank %zu", effect.get(), this,
Eric Laurentca7cc822012-11-19 14:55:58 -08001641 idx_insert);
1642 }
1643 effect->configure();
1644 return NO_ERROR;
1645}
1646
1647// removeEffect_l() must be called with PlaybackThread::mLock held
1648size_t AudioFlinger::EffectChain::removeEffect_l(const sp<EffectModule>& effect)
1649{
1650 Mutex::Autolock _l(mLock);
1651 size_t size = mEffects.size();
1652 uint32_t type = effect->desc().flags & EFFECT_FLAG_TYPE_MASK;
1653
1654 for (size_t i = 0; i < size; i++) {
1655 if (effect == mEffects[i]) {
1656 // calling stop here will remove pre-processing effect from the audio HAL.
1657 // This is safe as we hold the EffectChain mutex which guarantees that we are not in
1658 // the middle of a read from audio HAL
1659 if (mEffects[i]->state() == EffectModule::ACTIVE ||
1660 mEffects[i]->state() == EffectModule::STOPPING) {
1661 mEffects[i]->stop();
1662 }
1663 if (type == EFFECT_FLAG_TYPE_AUXILIARY) {
1664 delete[] effect->inBuffer();
1665 } else {
1666 if (i == size - 1 && i != 0) {
1667 mEffects[i - 1]->setOutBuffer(mOutBuffer);
1668 mEffects[i - 1]->configure();
1669 }
1670 }
1671 mEffects.removeAt(i);
Glenn Kastenc42e9b42016-03-21 11:35:03 -07001672 ALOGV("removeEffect_l() effect %p, removed from chain %p at rank %zu", effect.get(),
Eric Laurentca7cc822012-11-19 14:55:58 -08001673 this, i);
1674 break;
1675 }
1676 }
1677
1678 return mEffects.size();
1679}
1680
1681// setDevice_l() must be called with PlaybackThread::mLock held
1682void AudioFlinger::EffectChain::setDevice_l(audio_devices_t device)
1683{
1684 size_t size = mEffects.size();
1685 for (size_t i = 0; i < size; i++) {
1686 mEffects[i]->setDevice(device);
1687 }
1688}
1689
1690// setMode_l() must be called with PlaybackThread::mLock held
1691void AudioFlinger::EffectChain::setMode_l(audio_mode_t mode)
1692{
1693 size_t size = mEffects.size();
1694 for (size_t i = 0; i < size; i++) {
1695 mEffects[i]->setMode(mode);
1696 }
1697}
1698
1699// setAudioSource_l() must be called with PlaybackThread::mLock held
1700void AudioFlinger::EffectChain::setAudioSource_l(audio_source_t source)
1701{
1702 size_t size = mEffects.size();
1703 for (size_t i = 0; i < size; i++) {
1704 mEffects[i]->setAudioSource(source);
1705 }
1706}
1707
Eric Laurentfa1e1232016-08-02 19:01:49 -07001708// setVolume_l() must be called with PlaybackThread::mLock or EffectChain::mLock held
1709bool AudioFlinger::EffectChain::setVolume_l(uint32_t *left, uint32_t *right, bool force)
Eric Laurentca7cc822012-11-19 14:55:58 -08001710{
1711 uint32_t newLeft = *left;
1712 uint32_t newRight = *right;
1713 bool hasControl = false;
1714 int ctrlIdx = -1;
1715 size_t size = mEffects.size();
1716
1717 // first update volume controller
1718 for (size_t i = size; i > 0; i--) {
1719 if (mEffects[i - 1]->isProcessEnabled() &&
1720 (mEffects[i - 1]->desc().flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL) {
1721 ctrlIdx = i - 1;
1722 hasControl = true;
1723 break;
1724 }
1725 }
1726
Eric Laurentfa1e1232016-08-02 19:01:49 -07001727 if (!force && ctrlIdx == mVolumeCtrlIdx &&
Eric Laurentcb4b6e92014-10-01 14:26:10 -07001728 *left == mLeftVolume && *right == mRightVolume) {
Eric Laurentca7cc822012-11-19 14:55:58 -08001729 if (hasControl) {
1730 *left = mNewLeftVolume;
1731 *right = mNewRightVolume;
1732 }
1733 return hasControl;
1734 }
1735
1736 mVolumeCtrlIdx = ctrlIdx;
1737 mLeftVolume = newLeft;
1738 mRightVolume = newRight;
1739
1740 // second get volume update from volume controller
1741 if (ctrlIdx >= 0) {
1742 mEffects[ctrlIdx]->setVolume(&newLeft, &newRight, true);
1743 mNewLeftVolume = newLeft;
1744 mNewRightVolume = newRight;
1745 }
1746 // then indicate volume to all other effects in chain.
1747 // Pass altered volume to effects before volume controller
1748 // and requested volume to effects after controller
1749 uint32_t lVol = newLeft;
1750 uint32_t rVol = newRight;
1751
1752 for (size_t i = 0; i < size; i++) {
1753 if ((int)i == ctrlIdx) {
1754 continue;
1755 }
1756 // this also works for ctrlIdx == -1 when there is no volume controller
1757 if ((int)i > ctrlIdx) {
1758 lVol = *left;
1759 rVol = *right;
1760 }
1761 mEffects[i]->setVolume(&lVol, &rVol, false);
1762 }
1763 *left = newLeft;
1764 *right = newRight;
1765
1766 return hasControl;
1767}
1768
Eric Laurentfa1e1232016-08-02 19:01:49 -07001769// resetVolume_l() must be called with PlaybackThread::mLock or EffectChain::mLock held
1770void AudioFlinger::EffectChain::resetVolume_l()
1771{
Eric Laurente7449bf2016-08-03 18:44:07 -07001772 if ((mLeftVolume != UINT_MAX) && (mRightVolume != UINT_MAX)) {
1773 uint32_t left = mLeftVolume;
1774 uint32_t right = mRightVolume;
1775 (void)setVolume_l(&left, &right, true);
1776 }
Eric Laurentfa1e1232016-08-02 19:01:49 -07001777}
1778
Eric Laurent1b928682014-10-02 19:41:47 -07001779void AudioFlinger::EffectChain::syncHalEffectsState()
1780{
1781 Mutex::Autolock _l(mLock);
1782 for (size_t i = 0; i < mEffects.size(); i++) {
1783 if (mEffects[i]->state() == EffectModule::ACTIVE ||
1784 mEffects[i]->state() == EffectModule::STOPPING) {
1785 mEffects[i]->addEffectToHal_l();
1786 }
1787 }
1788}
1789
Eric Laurentca7cc822012-11-19 14:55:58 -08001790void AudioFlinger::EffectChain::dump(int fd, const Vector<String16>& args)
1791{
1792 const size_t SIZE = 256;
1793 char buffer[SIZE];
1794 String8 result;
1795
Marco Nelissenb2208842014-02-07 14:00:50 -08001796 size_t numEffects = mEffects.size();
Glenn Kastenc42e9b42016-03-21 11:35:03 -07001797 snprintf(buffer, SIZE, " %zu effects for session %d\n", numEffects, mSessionId);
Eric Laurentca7cc822012-11-19 14:55:58 -08001798 result.append(buffer);
1799
Marco Nelissenb2208842014-02-07 14:00:50 -08001800 if (numEffects) {
1801 bool locked = AudioFlinger::dumpTryLock(mLock);
1802 // failed to lock - AudioFlinger is probably deadlocked
1803 if (!locked) {
1804 result.append("\tCould not lock mutex:\n");
Eric Laurentca7cc822012-11-19 14:55:58 -08001805 }
Eric Laurentca7cc822012-11-19 14:55:58 -08001806
Marco Nelissenb2208842014-02-07 14:00:50 -08001807 result.append("\tIn buffer Out buffer Active tracks:\n");
Narayan Kamath1d6fa7a2014-02-11 13:47:53 +00001808 snprintf(buffer, SIZE, "\t%p %p %d\n",
1809 mInBuffer,
1810 mOutBuffer,
Marco Nelissenb2208842014-02-07 14:00:50 -08001811 mActiveTrackCnt);
1812 result.append(buffer);
1813 write(fd, result.string(), result.size());
1814
1815 for (size_t i = 0; i < numEffects; ++i) {
1816 sp<EffectModule> effect = mEffects[i];
1817 if (effect != 0) {
1818 effect->dump(fd, args);
1819 }
1820 }
1821
1822 if (locked) {
1823 mLock.unlock();
1824 }
Eric Laurentca7cc822012-11-19 14:55:58 -08001825 }
1826}
1827
1828// must be called with ThreadBase::mLock held
1829void AudioFlinger::EffectChain::setEffectSuspended_l(
1830 const effect_uuid_t *type, bool suspend)
1831{
1832 sp<SuspendedEffectDesc> desc;
1833 // use effect type UUID timelow as key as there is no real risk of identical
1834 // timeLow fields among effect type UUIDs.
1835 ssize_t index = mSuspendedEffects.indexOfKey(type->timeLow);
1836 if (suspend) {
1837 if (index >= 0) {
1838 desc = mSuspendedEffects.valueAt(index);
1839 } else {
1840 desc = new SuspendedEffectDesc();
1841 desc->mType = *type;
1842 mSuspendedEffects.add(type->timeLow, desc);
1843 ALOGV("setEffectSuspended_l() add entry for %08x", type->timeLow);
1844 }
1845 if (desc->mRefCount++ == 0) {
1846 sp<EffectModule> effect = getEffectIfEnabled(type);
1847 if (effect != 0) {
1848 desc->mEffect = effect;
1849 effect->setSuspended(true);
1850 effect->setEnabled(false);
1851 }
1852 }
1853 } else {
1854 if (index < 0) {
1855 return;
1856 }
1857 desc = mSuspendedEffects.valueAt(index);
1858 if (desc->mRefCount <= 0) {
1859 ALOGW("setEffectSuspended_l() restore refcount should not be 0 %d", desc->mRefCount);
1860 desc->mRefCount = 1;
1861 }
1862 if (--desc->mRefCount == 0) {
1863 ALOGV("setEffectSuspended_l() remove entry for %08x", mSuspendedEffects.keyAt(index));
1864 if (desc->mEffect != 0) {
1865 sp<EffectModule> effect = desc->mEffect.promote();
1866 if (effect != 0) {
1867 effect->setSuspended(false);
1868 effect->lock();
1869 EffectHandle *handle = effect->controlHandle_l();
1870 if (handle != NULL && !handle->destroyed_l()) {
1871 effect->setEnabled_l(handle->enabled());
1872 }
1873 effect->unlock();
1874 }
1875 desc->mEffect.clear();
1876 }
1877 mSuspendedEffects.removeItemsAt(index);
1878 }
1879 }
1880}
1881
1882// must be called with ThreadBase::mLock held
1883void AudioFlinger::EffectChain::setEffectSuspendedAll_l(bool suspend)
1884{
1885 sp<SuspendedEffectDesc> desc;
1886
1887 ssize_t index = mSuspendedEffects.indexOfKey((int)kKeyForSuspendAll);
1888 if (suspend) {
1889 if (index >= 0) {
1890 desc = mSuspendedEffects.valueAt(index);
1891 } else {
1892 desc = new SuspendedEffectDesc();
1893 mSuspendedEffects.add((int)kKeyForSuspendAll, desc);
1894 ALOGV("setEffectSuspendedAll_l() add entry for 0");
1895 }
1896 if (desc->mRefCount++ == 0) {
1897 Vector< sp<EffectModule> > effects;
1898 getSuspendEligibleEffects(effects);
1899 for (size_t i = 0; i < effects.size(); i++) {
1900 setEffectSuspended_l(&effects[i]->desc().type, true);
1901 }
1902 }
1903 } else {
1904 if (index < 0) {
1905 return;
1906 }
1907 desc = mSuspendedEffects.valueAt(index);
1908 if (desc->mRefCount <= 0) {
1909 ALOGW("setEffectSuspendedAll_l() restore refcount should not be 0 %d", desc->mRefCount);
1910 desc->mRefCount = 1;
1911 }
1912 if (--desc->mRefCount == 0) {
1913 Vector<const effect_uuid_t *> types;
1914 for (size_t i = 0; i < mSuspendedEffects.size(); i++) {
1915 if (mSuspendedEffects.keyAt(i) == (int)kKeyForSuspendAll) {
1916 continue;
1917 }
1918 types.add(&mSuspendedEffects.valueAt(i)->mType);
1919 }
1920 for (size_t i = 0; i < types.size(); i++) {
1921 setEffectSuspended_l(types[i], false);
1922 }
1923 ALOGV("setEffectSuspendedAll_l() remove entry for %08x",
1924 mSuspendedEffects.keyAt(index));
1925 mSuspendedEffects.removeItem((int)kKeyForSuspendAll);
1926 }
1927 }
1928}
1929
1930
1931// The volume effect is used for automated tests only
1932#ifndef OPENSL_ES_H_
1933static const effect_uuid_t SL_IID_VOLUME_ = { 0x09e8ede0, 0xddde, 0x11db, 0xb4f6,
1934 { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
1935const effect_uuid_t * const SL_IID_VOLUME = &SL_IID_VOLUME_;
1936#endif //OPENSL_ES_H_
1937
1938bool AudioFlinger::EffectChain::isEffectEligibleForSuspend(const effect_descriptor_t& desc)
1939{
1940 // auxiliary effects and visualizer are never suspended on output mix
1941 if ((mSessionId == AUDIO_SESSION_OUTPUT_MIX) &&
1942 (((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) ||
1943 (memcmp(&desc.type, SL_IID_VISUALIZATION, sizeof(effect_uuid_t)) == 0) ||
1944 (memcmp(&desc.type, SL_IID_VOLUME, sizeof(effect_uuid_t)) == 0))) {
1945 return false;
1946 }
1947 return true;
1948}
1949
1950void AudioFlinger::EffectChain::getSuspendEligibleEffects(
1951 Vector< sp<AudioFlinger::EffectModule> > &effects)
1952{
1953 effects.clear();
1954 for (size_t i = 0; i < mEffects.size(); i++) {
1955 if (isEffectEligibleForSuspend(mEffects[i]->desc())) {
1956 effects.add(mEffects[i]);
1957 }
1958 }
1959}
1960
1961sp<AudioFlinger::EffectModule> AudioFlinger::EffectChain::getEffectIfEnabled(
1962 const effect_uuid_t *type)
1963{
1964 sp<EffectModule> effect = getEffectFromType_l(type);
1965 return effect != 0 && effect->isEnabled() ? effect : 0;
1966}
1967
1968void AudioFlinger::EffectChain::checkSuspendOnEffectEnabled(const sp<EffectModule>& effect,
1969 bool enabled)
1970{
1971 ssize_t index = mSuspendedEffects.indexOfKey(effect->desc().type.timeLow);
1972 if (enabled) {
1973 if (index < 0) {
1974 // if the effect is not suspend check if all effects are suspended
1975 index = mSuspendedEffects.indexOfKey((int)kKeyForSuspendAll);
1976 if (index < 0) {
1977 return;
1978 }
1979 if (!isEffectEligibleForSuspend(effect->desc())) {
1980 return;
1981 }
1982 setEffectSuspended_l(&effect->desc().type, enabled);
1983 index = mSuspendedEffects.indexOfKey(effect->desc().type.timeLow);
1984 if (index < 0) {
1985 ALOGW("checkSuspendOnEffectEnabled() Fx should be suspended here!");
1986 return;
1987 }
1988 }
1989 ALOGV("checkSuspendOnEffectEnabled() enable suspending fx %08x",
1990 effect->desc().type.timeLow);
1991 sp<SuspendedEffectDesc> desc = mSuspendedEffects.valueAt(index);
1992 // if effect is requested to suspended but was not yet enabled, supend it now.
1993 if (desc->mEffect == 0) {
1994 desc->mEffect = effect;
1995 effect->setEnabled(false);
1996 effect->setSuspended(true);
1997 }
1998 } else {
1999 if (index < 0) {
2000 return;
2001 }
2002 ALOGV("checkSuspendOnEffectEnabled() disable restoring fx %08x",
2003 effect->desc().type.timeLow);
2004 sp<SuspendedEffectDesc> desc = mSuspendedEffects.valueAt(index);
2005 desc->mEffect.clear();
2006 effect->setSuspended(false);
2007 }
2008}
2009
Eric Laurent5baf2af2013-09-12 17:37:00 -07002010bool AudioFlinger::EffectChain::isNonOffloadableEnabled()
Eric Laurent813e2a72013-08-31 12:59:48 -07002011{
2012 Mutex::Autolock _l(mLock);
2013 size_t size = mEffects.size();
2014 for (size_t i = 0; i < size; i++) {
Eric Laurent5baf2af2013-09-12 17:37:00 -07002015 if (mEffects[i]->isEnabled() && !mEffects[i]->isOffloadable()) {
Eric Laurent813e2a72013-08-31 12:59:48 -07002016 return true;
2017 }
2018 }
2019 return false;
2020}
2021
Eric Laurentaaa44472014-09-12 17:41:50 -07002022void AudioFlinger::EffectChain::setThread(const sp<ThreadBase>& thread)
2023{
2024 Mutex::Autolock _l(mLock);
2025 mThread = thread;
2026 for (size_t i = 0; i < mEffects.size(); i++) {
2027 mEffects[i]->setThread(thread);
2028 }
2029}
2030
Andy Hungd3bb0ad2016-10-11 17:16:43 -07002031void AudioFlinger::EffectChain::checkOutputFlagCompatibility(audio_output_flags_t *flags) const
2032{
2033 if ((*flags & AUDIO_OUTPUT_FLAG_RAW) != 0 && !isRawCompatible()) {
2034 *flags = (audio_output_flags_t)(*flags & ~AUDIO_OUTPUT_FLAG_RAW);
2035 }
2036 if ((*flags & AUDIO_OUTPUT_FLAG_FAST) != 0 && !isFastCompatible()) {
2037 *flags = (audio_output_flags_t)(*flags & ~AUDIO_OUTPUT_FLAG_FAST);
2038 }
2039}
2040
2041void AudioFlinger::EffectChain::checkInputFlagCompatibility(audio_input_flags_t *flags) const
2042{
2043 if ((*flags & AUDIO_INPUT_FLAG_RAW) != 0 && !isRawCompatible()) {
2044 *flags = (audio_input_flags_t)(*flags & ~AUDIO_INPUT_FLAG_RAW);
2045 }
2046 if ((*flags & AUDIO_INPUT_FLAG_FAST) != 0 && !isFastCompatible()) {
2047 *flags = (audio_input_flags_t)(*flags & ~AUDIO_INPUT_FLAG_FAST);
2048 }
2049}
2050
2051bool AudioFlinger::EffectChain::isRawCompatible() const
Eric Laurent4c415062016-06-17 16:14:16 -07002052{
2053 Mutex::Autolock _l(mLock);
Andy Hungd3bb0ad2016-10-11 17:16:43 -07002054 for (const auto &effect : mEffects) {
2055 if (effect->isProcessImplemented()) {
2056 return false;
Eric Laurent4c415062016-06-17 16:14:16 -07002057 }
2058 }
Andy Hungd3bb0ad2016-10-11 17:16:43 -07002059 // Allow effects without processing.
2060 return true;
2061}
2062
2063bool AudioFlinger::EffectChain::isFastCompatible() const
2064{
2065 Mutex::Autolock _l(mLock);
2066 for (const auto &effect : mEffects) {
2067 if (effect->isProcessImplemented()
2068 && effect->isImplementationSoftware()) {
2069 return false;
2070 }
2071 }
2072 // Allow effects without processing or hw accelerated effects.
2073 return true;
Eric Laurent4c415062016-06-17 16:14:16 -07002074}
2075
2076// isCompatibleWithThread_l() must be called with thread->mLock held
2077bool AudioFlinger::EffectChain::isCompatibleWithThread_l(const sp<ThreadBase>& thread) const
2078{
2079 Mutex::Autolock _l(mLock);
2080 for (size_t i = 0; i < mEffects.size(); i++) {
2081 if (thread->checkEffectCompatibility_l(&(mEffects[i]->desc()), mSessionId) != NO_ERROR) {
2082 return false;
2083 }
2084 }
2085 return true;
2086}
2087
Glenn Kasten63238ef2015-03-02 15:50:29 -08002088} // namespace android