blob: 15a26ea75e579dd38acfd33a77873a7d1d89b516 [file] [log] [blame]
Eric Laurent81784c32012-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#ifndef INCLUDING_FROM_AUDIOFLINGER_H
19 #error This header file should only be included from AudioFlinger.h
20#endif
21
22//--- Audio Effect Management
23
24// EffectModule and EffectChain classes both have their own mutex to protect
25// state changes or resource modifications. Always respect the following order
26// if multiple mutexes must be acquired to avoid cross deadlock:
27// AudioFlinger -> ThreadBase -> EffectChain -> EffectModule
Eric Laurent3bc859b2016-12-05 11:07:22 -080028// AudioHandle -> ThreadBase -> EffectChain -> EffectModule
Eric Laurenteb3c3372013-09-25 12:25:29 -070029// In addition, methods that lock the AudioPolicyService mutex (getOutputForEffect(),
Eric Laurent3bc859b2016-12-05 11:07:22 -080030// startOutput(), getInputForAttr(), releaseInput()...) should never be called with AudioFlinger or
31// Threadbase mutex locked to avoid cross deadlock with other clients calling AudioPolicyService
32// methods that in turn call AudioFlinger thus locking the same mutexes in the reverse order.
Eric Laurent81784c32012-11-19 14:55:58 -080033
34// The EffectModule class is a wrapper object controlling the effect engine implementation
35// in the effect library. It prevents concurrent calls to process() and command() functions
36// from different client threads. It keeps a list of EffectHandle objects corresponding
37// to all client applications using this effect and notifies applications of effect state,
38// control or parameter changes. It manages the activation state machine to send appropriate
39// reset, enable, disable commands to effect engine and provide volume
40// ramping when effects are activated/deactivated.
41// When controlling an auxiliary effect, the EffectModule also provides an input buffer used by
42// the attached track(s) to accumulate their auxiliary channel.
43class EffectModule : public RefBase {
44public:
45 EffectModule(ThreadBase *thread,
46 const wp<AudioFlinger::EffectChain>& chain,
47 effect_descriptor_t *desc,
48 int id,
Eric Laurent0d5a2ed2016-12-01 15:28:29 -080049 audio_session_t sessionId,
50 bool pinned);
Eric Laurent81784c32012-11-19 14:55:58 -080051 virtual ~EffectModule();
52
53 enum effect_state {
54 IDLE,
55 RESTART,
56 STARTING,
57 ACTIVE,
58 STOPPING,
59 STOPPED,
60 DESTROYED
61 };
62
63 int id() const { return mId; }
64 void process();
Eric Laurentfa1e1232016-08-02 19:01:49 -070065 bool updateState();
Eric Laurent81784c32012-11-19 14:55:58 -080066 status_t command(uint32_t cmdCode,
67 uint32_t cmdSize,
68 void *pCmdData,
69 uint32_t *replySize,
70 void *pReplyData);
71
72 void reset_l();
73 status_t configure();
74 status_t init();
75 effect_state state() const {
76 return mState;
77 }
78 uint32_t status() {
79 return mStatus;
80 }
Glenn Kastend848eb42016-03-08 13:42:11 -080081 audio_session_t sessionId() const {
Eric Laurent81784c32012-11-19 14:55:58 -080082 return mSessionId;
83 }
84 status_t setEnabled(bool enabled);
85 status_t setEnabled_l(bool enabled);
86 bool isEnabled() const;
87 bool isProcessEnabled() const;
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +090088 bool isOffloadedOrDirect() const;
89 bool isVolumeControlEnabled() const;
Eric Laurent81784c32012-11-19 14:55:58 -080090
Mikhail Naganov022b9952017-01-04 16:36:51 -080091 void setInBuffer(const sp<EffectBufferHalInterface>& buffer);
92 int16_t *inBuffer() const {
93 return mInBuffer != 0 ? reinterpret_cast<int16_t*>(mInBuffer->ptr()) : NULL;
94 }
95 void setOutBuffer(const sp<EffectBufferHalInterface>& buffer);
96 int16_t *outBuffer() const {
97 return mOutBuffer != 0 ? reinterpret_cast<int16_t*>(mOutBuffer->ptr()) : NULL;
98 }
Eric Laurent81784c32012-11-19 14:55:58 -080099 void setChain(const wp<EffectChain>& chain) { mChain = chain; }
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900100 void setThread(const wp<ThreadBase>& thread)
101 { mThread = thread; mThreadType = thread.promote()->type(); }
Eric Laurent81784c32012-11-19 14:55:58 -0800102 const wp<ThreadBase>& thread() { return mThread; }
103
104 status_t addHandle(EffectHandle *handle);
Eric Laurentf10c7092016-12-06 17:09:56 -0800105 ssize_t disconnectHandle(EffectHandle *handle, bool unpinIfLast);
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800106 ssize_t removeHandle(EffectHandle *handle);
107 ssize_t removeHandle_l(EffectHandle *handle);
Eric Laurent81784c32012-11-19 14:55:58 -0800108
109 const effect_descriptor_t& desc() const { return mDescriptor; }
110 wp<EffectChain>& chain() { return mChain; }
111
112 status_t setDevice(audio_devices_t device);
113 status_t setVolume(uint32_t *left, uint32_t *right, bool controller);
114 status_t setMode(audio_mode_t mode);
115 status_t setAudioSource(audio_source_t source);
116 status_t start();
117 status_t stop();
118 void setSuspended(bool suspended);
119 bool suspended() const;
120
121 EffectHandle* controlHandle_l();
122
123 bool isPinned() const { return mPinned; }
124 void unPin() { mPinned = false; }
125 bool purgeHandles();
126 void lock() { mLock.lock(); }
127 void unlock() { mLock.unlock(); }
Eric Laurent5baf2af2013-09-12 17:37:00 -0700128 bool isOffloadable() const
129 { return (mDescriptor.flags & EFFECT_FLAG_OFFLOAD_SUPPORTED) != 0; }
Eric Laurent4c415062016-06-17 16:14:16 -0700130 bool isImplementationSoftware() const
131 { return (mDescriptor.flags & EFFECT_FLAG_HW_ACC_MASK) == 0; }
Eric Laurent6dd0fd92016-09-15 12:44:53 -0700132 bool isProcessImplemented() const
133 { return (mDescriptor.flags & EFFECT_FLAG_NO_PROCESS) == 0; }
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900134 bool isVolumeControl() const
135 { return (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK)
136 == EFFECT_FLAG_VOLUME_CTRL; }
Eric Laurent5baf2af2013-09-12 17:37:00 -0700137 status_t setOffloaded(bool offloaded, audio_io_handle_t io);
138 bool isOffloaded() const;
Eric Laurent1b928682014-10-02 19:41:47 -0700139 void addEffectToHal_l();
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800140 void release_l();
Eric Laurent81784c32012-11-19 14:55:58 -0800141
142 void dump(int fd, const Vector<String16>& args);
143
Mikhail Naganovbf493082017-04-17 17:37:12 -0700144private:
Eric Laurent81784c32012-11-19 14:55:58 -0800145 friend class AudioFlinger; // for mHandles
146 bool mPinned;
147
148 // Maximum time allocated to effect engines to complete the turn off sequence
149 static const uint32_t MAX_DISABLE_TIME_MS = 10000;
150
Mikhail Naganovbf493082017-04-17 17:37:12 -0700151 DISALLOW_COPY_AND_ASSIGN(EffectModule);
Eric Laurent81784c32012-11-19 14:55:58 -0800152
153 status_t start_l();
154 status_t stop_l();
Eric Laurentbfb1b832013-01-07 09:53:42 -0800155 status_t remove_effect_from_hal_l();
Eric Laurent81784c32012-11-19 14:55:58 -0800156
157mutable Mutex mLock; // mutex for process, commands and handles list protection
158 wp<ThreadBase> mThread; // parent thread
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900159 ThreadBase::type_t mThreadType; // parent thread type
Eric Laurent81784c32012-11-19 14:55:58 -0800160 wp<EffectChain> mChain; // parent effect chain
161 const int mId; // this instance unique ID
Glenn Kastend848eb42016-03-08 13:42:11 -0800162 const audio_session_t mSessionId; // audio session ID
Eric Laurent81784c32012-11-19 14:55:58 -0800163 const effect_descriptor_t mDescriptor;// effect descriptor received from effect engine
164 effect_config_t mConfig; // input and output audio configuration
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700165 sp<EffectHalInterface> mEffectInterface; // Effect module HAL
Mikhail Naganov022b9952017-01-04 16:36:51 -0800166 sp<EffectBufferHalInterface> mInBuffer; // Buffers for interacting with HAL
167 sp<EffectBufferHalInterface> mOutBuffer;
Eric Laurent81784c32012-11-19 14:55:58 -0800168 status_t mStatus; // initialization status
169 effect_state mState; // current activation state
170 Vector<EffectHandle *> mHandles; // list of client handles
171 // First handle in mHandles has highest priority and controls the effect module
172 uint32_t mMaxDisableWaitCnt; // maximum grace period before forcing an effect off after
173 // sending disable command.
174 uint32_t mDisableWaitCnt; // current process() calls count during disable period.
175 bool mSuspended; // effect is suspended: temporarily disabled by framework
Eric Laurent5baf2af2013-09-12 17:37:00 -0700176 bool mOffloaded; // effect is currently offloaded to the audio DSP
Eric Laurentaaa44472014-09-12 17:41:50 -0700177 wp<AudioFlinger> mAudioFlinger;
rago94a1ee82017-07-21 15:11:02 -0700178
179#ifdef FLOAT_EFFECT_CHAIN
180 bool mSupportsFloat; // effect supports float processing
Andy Hungbded9c82017-11-30 18:47:35 -0800181 sp<EffectBufferHalInterface> mInConversionBuffer; // Buffers for HAL conversion if needed.
182 sp<EffectBufferHalInterface> mOutConversionBuffer;
Andy Hung9aad48c2017-11-29 10:29:19 -0800183 uint32_t mInChannelCountRequested;
184 uint32_t mOutChannelCountRequested;
rago94a1ee82017-07-21 15:11:02 -0700185#endif
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900186
187 class AutoLockReentrant {
188 public:
189 AutoLockReentrant(Mutex& mutex, pid_t allowedTid)
190 : mMutex(gettid() == allowedTid ? nullptr : &mutex)
191 {
192 if (mMutex != nullptr) mMutex->lock();
193 }
194 ~AutoLockReentrant() {
195 if (mMutex != nullptr) mMutex->unlock();
196 }
197 private:
198 Mutex * const mMutex;
199 };
200
201 static constexpr pid_t INVALID_PID = (pid_t)-1;
202 // this tid is allowed to call setVolume() without acquiring the mutex.
203 pid_t mSetVolumeReentrantTid = INVALID_PID;
Eric Laurent81784c32012-11-19 14:55:58 -0800204};
205
206// The EffectHandle class implements the IEffect interface. It provides resources
207// to receive parameter updates, keeps track of effect control
208// ownership and state and has a pointer to the EffectModule object it is controlling.
209// There is one EffectHandle object for each application controlling (or using)
210// an effect module.
211// The EffectHandle is obtained by calling AudioFlinger::createEffect().
212class EffectHandle: public android::BnEffect {
213public:
214
215 EffectHandle(const sp<EffectModule>& effect,
216 const sp<AudioFlinger::Client>& client,
217 const sp<IEffectClient>& effectClient,
218 int32_t priority);
219 virtual ~EffectHandle();
Glenn Kastene75da402013-11-20 13:54:52 -0800220 virtual status_t initCheck();
Eric Laurent81784c32012-11-19 14:55:58 -0800221
222 // IEffect
223 virtual status_t enable();
224 virtual status_t disable();
225 virtual status_t command(uint32_t cmdCode,
226 uint32_t cmdSize,
227 void *pCmdData,
228 uint32_t *replySize,
229 void *pReplyData);
230 virtual void disconnect();
231private:
232 void disconnect(bool unpinIfLast);
233public:
234 virtual sp<IMemory> getCblk() const { return mCblkMemory; }
235 virtual status_t onTransact(uint32_t code, const Parcel& data,
236 Parcel* reply, uint32_t flags);
237
238
239 // Give or take control of effect module
240 // - hasControl: true if control is given, false if removed
241 // - signal: true client app should be signaled of change, false otherwise
242 // - enabled: state of the effect when control is passed
243 void setControl(bool hasControl, bool signal, bool enabled);
244 void commandExecuted(uint32_t cmdCode,
245 uint32_t cmdSize,
246 void *pCmdData,
247 uint32_t replySize,
248 void *pReplyData);
249 void setEnabled(bool enabled);
250 bool enabled() const { return mEnabled; }
251
252 // Getters
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800253 wp<EffectModule> effect() const { return mEffect; }
254 int id() const {
255 sp<EffectModule> effect = mEffect.promote();
256 if (effect == 0) {
257 return 0;
258 }
259 return effect->id();
260 }
Eric Laurent81784c32012-11-19 14:55:58 -0800261 int priority() const { return mPriority; }
262 bool hasControl() const { return mHasControl; }
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800263 bool disconnected() const { return mDisconnected; }
Eric Laurent81784c32012-11-19 14:55:58 -0800264
Glenn Kasten01d3acb2014-02-06 08:24:07 -0800265 void dumpToBuffer(char* buffer, size_t size);
Eric Laurent81784c32012-11-19 14:55:58 -0800266
Mikhail Naganovbf493082017-04-17 17:37:12 -0700267private:
Eric Laurent81784c32012-11-19 14:55:58 -0800268 friend class AudioFlinger; // for mEffect, mHasControl, mEnabled
Mikhail Naganovbf493082017-04-17 17:37:12 -0700269 DISALLOW_COPY_AND_ASSIGN(EffectHandle);
Eric Laurent81784c32012-11-19 14:55:58 -0800270
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800271 Mutex mLock; // protects IEffect method calls
272 wp<EffectModule> mEffect; // pointer to controlled EffectModule
Eric Laurent81784c32012-11-19 14:55:58 -0800273 sp<IEffectClient> mEffectClient; // callback interface for client notifications
274 /*const*/ sp<Client> mClient; // client for shared memory allocation, see disconnect()
275 sp<IMemory> mCblkMemory; // shared memory for control block
276 effect_param_cblk_t* mCblk; // control block for deferred parameter setting via
277 // shared memory
278 uint8_t* mBuffer; // pointer to parameter area in shared memory
279 int mPriority; // client application priority to control the effect
280 bool mHasControl; // true if this handle is controlling the effect
281 bool mEnabled; // cached enable state: needed when the effect is
282 // restored after being suspended
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800283 bool mDisconnected; // Set to true by disconnect()
Eric Laurent81784c32012-11-19 14:55:58 -0800284};
285
286// the EffectChain class represents a group of effects associated to one audio session.
287// There can be any number of EffectChain objects per output mixer thread (PlaybackThread).
Glenn Kastend848eb42016-03-08 13:42:11 -0800288// The EffectChain with session ID AUDIO_SESSION_OUTPUT_MIX contains global effects applied
289// to the output mix.
Eric Laurent81784c32012-11-19 14:55:58 -0800290// Effects in this chain can be insert or auxiliary. Effects in other chains (attached to
291// tracks) are insert only. The EffectChain maintains an ordered list of effect module, the
Glenn Kastend848eb42016-03-08 13:42:11 -0800292// order corresponding in the effect process order. When attached to a track (session ID !=
293// AUDIO_SESSION_OUTPUT_MIX),
Eric Laurent81784c32012-11-19 14:55:58 -0800294// it also provide it's own input buffer used by the track as accumulation buffer.
295class EffectChain : public RefBase {
296public:
Glenn Kastend848eb42016-03-08 13:42:11 -0800297 EffectChain(const wp<ThreadBase>& wThread, audio_session_t sessionId);
298 EffectChain(ThreadBase *thread, audio_session_t sessionId);
Eric Laurent81784c32012-11-19 14:55:58 -0800299 virtual ~EffectChain();
300
301 // special key used for an entry in mSuspendedEffects keyed vector
302 // corresponding to a suspend all request.
303 static const int kKeyForSuspendAll = 0;
304
305 // minimum duration during which we force calling effect process when last track on
306 // a session is stopped or removed to allow effect tail to be rendered
307 static const int kProcessTailDurationMs = 1000;
308
309 void process_l();
310
311 void lock() {
312 mLock.lock();
313 }
314 void unlock() {
315 mLock.unlock();
316 }
317
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800318 status_t createEffect_l(sp<EffectModule>& effect,
319 ThreadBase *thread,
320 effect_descriptor_t *desc,
321 int id,
322 audio_session_t sessionId,
323 bool pinned);
Eric Laurent81784c32012-11-19 14:55:58 -0800324 status_t addEffect_l(const sp<EffectModule>& handle);
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800325 status_t addEffect_ll(const sp<EffectModule>& handle);
326 size_t removeEffect_l(const sp<EffectModule>& handle, bool release = false);
Eric Laurent81784c32012-11-19 14:55:58 -0800327
Glenn Kastend848eb42016-03-08 13:42:11 -0800328 audio_session_t sessionId() const { return mSessionId; }
329 void setSessionId(audio_session_t sessionId) { mSessionId = sessionId; }
Eric Laurent81784c32012-11-19 14:55:58 -0800330
331 sp<EffectModule> getEffectFromDesc_l(effect_descriptor_t *descriptor);
332 sp<EffectModule> getEffectFromId_l(int id);
333 sp<EffectModule> getEffectFromType_l(const effect_uuid_t *type);
Glenn Kastenc56f3422014-03-21 17:53:17 -0700334 // FIXME use float to improve the dynamic range
Eric Laurentfa1e1232016-08-02 19:01:49 -0700335 bool setVolume_l(uint32_t *left, uint32_t *right, bool force = false);
336 void resetVolume_l();
Eric Laurent81784c32012-11-19 14:55:58 -0800337 void setDevice_l(audio_devices_t device);
338 void setMode_l(audio_mode_t mode);
339 void setAudioSource_l(audio_source_t source);
340
Mikhail Naganov022b9952017-01-04 16:36:51 -0800341 void setInBuffer(const sp<EffectBufferHalInterface>& buffer) {
Eric Laurent81784c32012-11-19 14:55:58 -0800342 mInBuffer = buffer;
Eric Laurent81784c32012-11-19 14:55:58 -0800343 }
rago94a1ee82017-07-21 15:11:02 -0700344 effect_buffer_t *inBuffer() const {
345 return mInBuffer != 0 ? reinterpret_cast<effect_buffer_t*>(mInBuffer->ptr()) : NULL;
Eric Laurent81784c32012-11-19 14:55:58 -0800346 }
Mikhail Naganov022b9952017-01-04 16:36:51 -0800347 void setOutBuffer(const sp<EffectBufferHalInterface>& buffer) {
Eric Laurent81784c32012-11-19 14:55:58 -0800348 mOutBuffer = buffer;
349 }
rago94a1ee82017-07-21 15:11:02 -0700350 effect_buffer_t *outBuffer() const {
351 return mOutBuffer != 0 ? reinterpret_cast<effect_buffer_t*>(mOutBuffer->ptr()) : NULL;
Eric Laurent81784c32012-11-19 14:55:58 -0800352 }
353
354 void incTrackCnt() { android_atomic_inc(&mTrackCnt); }
355 void decTrackCnt() { android_atomic_dec(&mTrackCnt); }
356 int32_t trackCnt() const { return android_atomic_acquire_load(&mTrackCnt); }
357
358 void incActiveTrackCnt() { android_atomic_inc(&mActiveTrackCnt);
359 mTailBufferCount = mMaxTailBuffers; }
360 void decActiveTrackCnt() { android_atomic_dec(&mActiveTrackCnt); }
361 int32_t activeTrackCnt() const { return android_atomic_acquire_load(&mActiveTrackCnt); }
362
363 uint32_t strategy() const { return mStrategy; }
364 void setStrategy(uint32_t strategy)
365 { mStrategy = strategy; }
366
Eric Laurentd8365c52017-07-16 15:27:05 -0700367 // suspend or restore effects of the specified type. The number of suspend requests is counted
368 // and restore occurs once all suspend requests are cancelled.
Eric Laurent81784c32012-11-19 14:55:58 -0800369 void setEffectSuspended_l(const effect_uuid_t *type,
370 bool suspend);
371 // suspend all eligible effects
372 void setEffectSuspendedAll_l(bool suspend);
373 // check if effects should be suspend or restored when a given effect is enable or disabled
374 void checkSuspendOnEffectEnabled(const sp<EffectModule>& effect,
375 bool enabled);
376
377 void clearInputBuffer();
378
Eric Laurent5baf2af2013-09-12 17:37:00 -0700379 // At least one non offloadable effect in the chain is enabled
380 bool isNonOffloadableEnabled();
Shingo Kitajima1f8df9a2018-05-29 11:35:06 +0900381 bool isNonOffloadableEnabled_l();
Eric Laurent813e2a72013-08-31 12:59:48 -0700382
Eric Laurent1b928682014-10-02 19:41:47 -0700383 void syncHalEffectsState();
384
Andy Hungd3bb0ad2016-10-11 17:16:43 -0700385 // flags is an ORed set of audio_output_flags_t which is updated on return.
386 void checkOutputFlagCompatibility(audio_output_flags_t *flags) const;
387
388 // flags is an ORed set of audio_input_flags_t which is updated on return.
389 void checkInputFlagCompatibility(audio_input_flags_t *flags) const;
390
391 // Is this EffectChain compatible with the RAW audio flag.
392 bool isRawCompatible() const;
393
394 // Is this EffectChain compatible with the FAST audio flag.
395 bool isFastCompatible() const;
Eric Laurent4c415062016-06-17 16:14:16 -0700396
397 // isCompatibleWithThread_l() must be called with thread->mLock held
398 bool isCompatibleWithThread_l(const sp<ThreadBase>& thread) const;
399
Eric Laurent81784c32012-11-19 14:55:58 -0800400 void dump(int fd, const Vector<String16>& args);
401
Mikhail Naganovbf493082017-04-17 17:37:12 -0700402private:
Eric Laurent81784c32012-11-19 14:55:58 -0800403 friend class AudioFlinger; // for mThread, mEffects
Mikhail Naganovbf493082017-04-17 17:37:12 -0700404 DISALLOW_COPY_AND_ASSIGN(EffectChain);
Eric Laurent81784c32012-11-19 14:55:58 -0800405
406 class SuspendedEffectDesc : public RefBase {
407 public:
408 SuspendedEffectDesc() : mRefCount(0) {}
409
Eric Laurentd8365c52017-07-16 15:27:05 -0700410 int mRefCount; // > 0 when suspended
Eric Laurent81784c32012-11-19 14:55:58 -0800411 effect_uuid_t mType;
412 wp<EffectModule> mEffect;
413 };
414
415 // get a list of effect modules to suspend when an effect of the type
416 // passed is enabled.
417 void getSuspendEligibleEffects(Vector< sp<EffectModule> > &effects);
418
419 // get an effect module if it is currently enable
420 sp<EffectModule> getEffectIfEnabled(const effect_uuid_t *type);
421 // true if the effect whose descriptor is passed can be suspended
422 // OEMs can modify the rules implemented in this method to exclude specific effect
423 // types or implementations from the suspend/restore mechanism.
424 bool isEffectEligibleForSuspend(const effect_descriptor_t& desc);
425
Eric Laurentd8365c52017-07-16 15:27:05 -0700426 static bool isEffectEligibleForBtNrecSuspend(const effect_uuid_t *type);
427
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700428 void clearInputBuffer_l(const sp<ThreadBase>& thread);
Eric Laurent81784c32012-11-19 14:55:58 -0800429
Eric Laurentaaa44472014-09-12 17:41:50 -0700430 void setThread(const sp<ThreadBase>& thread);
431
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900432 void setVolumeForOutput_l(uint32_t left, uint32_t right);
433
Eric Laurent4c415062016-06-17 16:14:16 -0700434 wp<ThreadBase> mThread; // parent mixer thread
435 mutable Mutex mLock; // mutex protecting effect list
436 Vector< sp<EffectModule> > mEffects; // list of effect modules
437 audio_session_t mSessionId; // audio session ID
Mikhail Naganov022b9952017-01-04 16:36:51 -0800438 sp<EffectBufferHalInterface> mInBuffer; // chain input buffer
439 sp<EffectBufferHalInterface> mOutBuffer; // chain output buffer
Eric Laurent81784c32012-11-19 14:55:58 -0800440
441 // 'volatile' here means these are accessed with atomic operations instead of mutex
442 volatile int32_t mActiveTrackCnt; // number of active tracks connected
443 volatile int32_t mTrackCnt; // number of tracks connected
444
Eric Laurent4c415062016-06-17 16:14:16 -0700445 int32_t mTailBufferCount; // current effect tail buffer count
446 int32_t mMaxTailBuffers; // maximum effect tail buffers
Eric Laurent4c415062016-06-17 16:14:16 -0700447 int mVolumeCtrlIdx; // index of insert effect having control over volume
448 uint32_t mLeftVolume; // previous volume on left channel
449 uint32_t mRightVolume; // previous volume on right channel
450 uint32_t mNewLeftVolume; // new volume on left channel
451 uint32_t mNewRightVolume; // new volume on right channel
452 uint32_t mStrategy; // strategy for this effect chain
453 // mSuspendedEffects lists all effects currently suspended in the chain.
454 // Use effect type UUID timelow field as key. There is no real risk of identical
455 // timeLow fields among effect type UUIDs.
Eric Laurentd8365c52017-07-16 15:27:05 -0700456 // Updated by setEffectSuspended_l() and setEffectSuspendedAll_l() only.
Eric Laurent4c415062016-06-17 16:14:16 -0700457 KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects;
Eric Laurent81784c32012-11-19 14:55:58 -0800458};