blob: 9ecf89e7183c422da35f48c0489bfc1318f1b2a1 [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
Andy Hung5fd10da2023-07-19 11:31:15 -070018#pragma once
19
20#include "DeviceEffectManager.h"
21#include "IAfEffect.h"
22
23#include <android-base/macros.h> // DISALLOW_COPY_AND_ASSIGN
24#include <mediautils/Synchronization.h>
25#include <private/media/AudioEffectShared.h>
26
27#include <map> // avoid transitive dependency
jiabin8b627fa2024-03-19 19:05:38 +000028#include <optional>
29#include <vector>
Andy Hung5fd10da2023-07-19 11:31:15 -070030
Andy Hung6ac17eb2023-06-20 18:56:17 -070031namespace android {
Eric Laurent81784c32012-11-19 14:55:58 -080032
33//--- Audio Effect Management
34
Eric Laurent41709552019-12-16 19:34:05 -080035// EffectBase(EffectModule) and EffectChain classes both have their own mutex to protect
Eric Laurent81784c32012-11-19 14:55:58 -080036// state changes or resource modifications. Always respect the following order
37// if multiple mutexes must be acquired to avoid cross deadlock:
Eric Laurent41709552019-12-16 19:34:05 -080038// AudioFlinger -> ThreadBase -> EffectChain -> EffectBase(EffectModule)
39// AudioHandle -> ThreadBase -> EffectChain -> EffectBase(EffectModule)
Eric Laurent6b446ce2019-12-13 10:56:31 -080040
41// NOTE: When implementing the EffectCallbackInterface, in an EffectChain or other, it is important
42// to pay attention to this locking order as some callback methods can be called from a state where
43// EffectModule and/or EffectChain mutexes are held.
44
Eric Laurenteb3c3372013-09-25 12:25:29 -070045// In addition, methods that lock the AudioPolicyService mutex (getOutputForEffect(),
Eric Laurent3bc859b2016-12-05 11:07:22 -080046// startOutput(), getInputForAttr(), releaseInput()...) should never be called with AudioFlinger or
47// Threadbase mutex locked to avoid cross deadlock with other clients calling AudioPolicyService
48// methods that in turn call AudioFlinger thus locking the same mutexes in the reverse order.
Eric Laurent81784c32012-11-19 14:55:58 -080049
Eric Laurent41709552019-12-16 19:34:05 -080050
51// The EffectBase class contains common properties, state and behavior for and EffectModule or
52// other derived classes managing an audio effect instance within the effect framework.
53// It also contains the class mutex (see comment on locking order above).
Andy Hung6ac17eb2023-06-20 18:56:17 -070054class EffectBase : public virtual IAfEffectBase {
Eric Laurent81784c32012-11-19 14:55:58 -080055public:
Eric Laurent41709552019-12-16 19:34:05 -080056 EffectBase(const sp<EffectCallbackInterface>& callback,
57 effect_descriptor_t *desc,
58 int id,
59 audio_session_t sessionId,
60 bool pinned);
61
Andy Hung6ac17eb2023-06-20 18:56:17 -070062 int id() const final { return mId; }
63 effect_state state() const final {
Eric Laurent81784c32012-11-19 14:55:58 -080064 return mState;
65 }
Andy Hung6ac17eb2023-06-20 18:56:17 -070066 audio_session_t sessionId() const final {
Eric Laurent81784c32012-11-19 14:55:58 -080067 return mSessionId;
68 }
Andy Hung6ac17eb2023-06-20 18:56:17 -070069 const effect_descriptor_t& desc() const final { return mDescriptor; }
70 bool isOffloadable() const final
Eric Laurent5baf2af2013-09-12 17:37:00 -070071 { return (mDescriptor.flags & EFFECT_FLAG_OFFLOAD_SUPPORTED) != 0; }
Andy Hung6ac17eb2023-06-20 18:56:17 -070072 bool isImplementationSoftware() const final
Eric Laurent4c415062016-06-17 16:14:16 -070073 { return (mDescriptor.flags & EFFECT_FLAG_HW_ACC_MASK) == 0; }
Andy Hung6ac17eb2023-06-20 18:56:17 -070074 bool isProcessImplemented() const final
Eric Laurent6dd0fd92016-09-15 12:44:53 -070075 { return (mDescriptor.flags & EFFECT_FLAG_NO_PROCESS) == 0; }
Andy Hung6ac17eb2023-06-20 18:56:17 -070076 bool isVolumeControl() const
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +090077 { return (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK)
78 == EFFECT_FLAG_VOLUME_CTRL; }
Andy Hung6ac17eb2023-06-20 18:56:17 -070079 bool isVolumeMonitor() const final
Jasmine Cha934ecfb2019-01-23 18:19:14 +080080 { return (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK)
81 == EFFECT_FLAG_VOLUME_MONITOR; }
Eric Laurent41709552019-12-16 19:34:05 -080082
Shunkai Yaod125e402024-01-20 03:19:06 +000083 status_t setEnabled(bool enabled, bool fromHandle) override EXCLUDES_EffectBase_Mutex;
84 status_t setEnabled_l(bool enabled) final REQUIRES(audio_utils::EffectBase_Mutex);
Andy Hung6ac17eb2023-06-20 18:56:17 -070085 bool isEnabled() const final;
Shunkai Yaod125e402024-01-20 03:19:06 +000086 void setSuspended(bool suspended) final EXCLUDES_EffectBase_Mutex;
87 bool suspended() const final EXCLUDES_EffectBase_Mutex;
Eric Laurent41709552019-12-16 19:34:05 -080088
Andy Hung6ac17eb2023-06-20 18:56:17 -070089 status_t command(int32_t __unused,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -070090 const std::vector<uint8_t>& __unused,
91 int32_t __unused,
Andy Hung6ac17eb2023-06-20 18:56:17 -070092 std::vector<uint8_t>* __unused) override {
93 return NO_ERROR;
94 }
Eric Laurent41709552019-12-16 19:34:05 -080095
Andy Hungfda44002021-06-03 17:23:16 -070096 // mCallback is atomic so this can be lock-free.
Andy Hung6ac17eb2023-06-20 18:56:17 -070097 void setCallback(const sp<EffectCallbackInterface>& callback) final {
98 mCallback = callback;
99 }
100 sp<EffectCallbackInterface> getCallback() const final {
101 return mCallback.load();
102 }
Eric Laurent41709552019-12-16 19:34:05 -0800103
Shunkai Yaod125e402024-01-20 03:19:06 +0000104 status_t addHandle(IAfEffectHandle* handle) final EXCLUDES_EffectBase_Mutex;
105 ssize_t disconnectHandle(IAfEffectHandle* handle,
106 bool unpinIfLast) final EXCLUDES_EffectBase_Mutex;
107 ssize_t removeHandle(IAfEffectHandle* handle) final EXCLUDES_EffectBase_Mutex;
108 ssize_t removeHandle_l(IAfEffectHandle* handle) final REQUIRES(audio_utils::EffectBase_Mutex);
109 IAfEffectHandle* controlHandle_l() final REQUIRES(audio_utils::EffectBase_Mutex);
110 bool purgeHandles() final EXCLUDES_EffectBase_Mutex;
Eric Laurent41709552019-12-16 19:34:05 -0800111
Shunkai Yaod125e402024-01-20 03:19:06 +0000112 void checkSuspendOnEffectEnabled(bool enabled, bool threadLocked) final;
Eric Laurent41709552019-12-16 19:34:05 -0800113
Shunkai Yaod125e402024-01-20 03:19:06 +0000114 bool isPinned() const final { return mPinned; }
115 void unPin() final { mPinned = false; }
Eric Laurent41709552019-12-16 19:34:05 -0800116
Shunkai Yaod125e402024-01-20 03:19:06 +0000117 audio_utils::mutex& mutex() const final
118 RETURN_CAPABILITY(android::audio_utils::EffectBase_Mutex) {
119 return mMutex;
120 }
Eric Laurent81784c32012-11-19 14:55:58 -0800121
Shunkai Yaod125e402024-01-20 03:19:06 +0000122 status_t updatePolicyState() final EXCLUDES_EffectBase_Mutex;
Eric Laurent41709552019-12-16 19:34:05 -0800123
Andy Hung6ac17eb2023-06-20 18:56:17 -0700124 sp<IAfEffectModule> asEffectModule() override { return nullptr; }
125 sp<IAfDeviceEffectProxy> asDeviceEffectProxy() override { return nullptr; }
Eric Laurent6c796322019-04-09 14:13:17 -0700126
Shunkai Yaod125e402024-01-20 03:19:06 +0000127 void dump(int fd, const Vector<String16>& args) const override;
Eric Laurent81784c32012-11-19 14:55:58 -0800128
Eric Laurentd66d7a12021-07-13 13:35:32 +0200129protected:
Shunkai Yaod125e402024-01-20 03:19:06 +0000130 bool isInternal_l() const REQUIRES(audio_utils::EffectBase_Mutex) {
131 for (auto handle : mHandles) {
132 if (handle->client() != nullptr) {
133 return false;
134 }
135 }
136 return true;
137 }
Eric Laurentd66d7a12021-07-13 13:35:32 +0200138
Eric Laurent41709552019-12-16 19:34:05 -0800139 bool mPinned = false;
140
141 DISALLOW_COPY_AND_ASSIGN(EffectBase);
142
Andy Hungf65f5a72023-08-29 12:19:17 -0700143 // mutex for process, commands and handles list protection
Andy Hunga6f1cbb2023-10-12 18:18:13 -0700144 mutable audio_utils::mutex mMutex{audio_utils::MutexOrder::kEffectBase_Mutex};
Andy Hungfda44002021-06-03 17:23:16 -0700145 mediautils::atomic_sp<EffectCallbackInterface> mCallback; // parent effect chain
Eric Laurent41709552019-12-16 19:34:05 -0800146 const int mId; // this instance unique ID
147 const audio_session_t mSessionId; // audio session ID
148 const effect_descriptor_t mDescriptor;// effect descriptor received from effect engine
149 effect_state mState = IDLE; // current activation state
Eric Laurentd9eb4962019-12-19 09:20:49 -0800150 // effect is suspended: temporarily disabled by framework
151 bool mSuspended = false;
Eric Laurent41709552019-12-16 19:34:05 -0800152
Andy Hung6ac17eb2023-06-20 18:56:17 -0700153 Vector<IAfEffectHandle *> mHandles; // list of client handles
Eric Laurent41709552019-12-16 19:34:05 -0800154 // First handle in mHandles has highest priority and controls the effect module
155
156 // Audio policy effect state management
Andy Hungf65f5a72023-08-29 12:19:17 -0700157 // Mutex protecting transactions with audio policy manager as mutex() cannot
Eric Laurent41709552019-12-16 19:34:05 -0800158 // be held to avoid cross deadlocks with audio policy mutex
Shunkai Yaod125e402024-01-20 03:19:06 +0000159 audio_utils::mutex& policyMutex() const
160 RETURN_CAPABILITY(android::audio_utils::EffectBase_PolicyMutex) {
161 return mPolicyMutex;
162 }
Andy Hunga6f1cbb2023-10-12 18:18:13 -0700163 mutable audio_utils::mutex mPolicyMutex{audio_utils::MutexOrder::kEffectBase_PolicyMutex};
Eric Laurent41709552019-12-16 19:34:05 -0800164 // Effect is registered in APM or not
165 bool mPolicyRegistered = false;
166 // Effect enabled state communicated to APM. Enabled state corresponds to
167 // state requested by the EffectHandle with control
168 bool mPolicyEnabled = false;
169};
170
171// The EffectModule class is a wrapper object controlling the effect engine implementation
172// in the effect library. It prevents concurrent calls to process() and command() functions
173// from different client threads. It keeps a list of EffectHandle objects corresponding
174// to all client applications using this effect and notifies applications of effect state,
175// control or parameter changes. It manages the activation state machine to send appropriate
176// reset, enable, disable commands to effect engine and provide volume
177// ramping when effects are activated/deactivated.
178// When controlling an auxiliary effect, the EffectModule also provides an input buffer used by
179// the attached track(s) to accumulate their auxiliary channel.
Andy Hung6ac17eb2023-06-20 18:56:17 -0700180class EffectModule : public IAfEffectModule, public EffectBase {
Eric Laurent41709552019-12-16 19:34:05 -0800181public:
François Gaffiec944aa32024-03-13 17:08:52 +0100182 EffectModule(const sp<EffectCallbackInterface>& callback,
Eric Laurent41709552019-12-16 19:34:05 -0800183 effect_descriptor_t *desc,
184 int id,
185 audio_session_t sessionId,
Eric Laurentb82e6b72019-11-22 17:25:04 -0800186 bool pinned,
Shunkai Yaod125e402024-01-20 03:19:06 +0000187 audio_port_handle_t deviceId) REQUIRES(audio_utils::EffectChain_Mutex);
188 ~EffectModule() override REQUIRES(audio_utils::EffectChain_Mutex);
Eric Laurent41709552019-12-16 19:34:05 -0800189
Shunkai Yaod125e402024-01-20 03:19:06 +0000190 void process() final EXCLUDES_EffectBase_Mutex;
191 bool updateState_l() final REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex;
192 status_t command(int32_t cmdCode, const std::vector<uint8_t>& cmdData, int32_t maxReplySize,
193 std::vector<uint8_t>* reply) final EXCLUDES_EffectBase_Mutex;
Eric Laurent41709552019-12-16 19:34:05 -0800194
Shunkai Yaod125e402024-01-20 03:19:06 +0000195 void reset_l() final REQUIRES(audio_utils::EffectBase_Mutex);
196 status_t configure_l() final REQUIRES(audio_utils::EffectChain_Mutex);
197 status_t init_l() final REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700198 uint32_t status() const final {
Eric Laurent41709552019-12-16 19:34:05 -0800199 return mStatus;
200 }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700201 bool isProcessEnabled() const final;
Shunkai Yaod125e402024-01-20 03:19:06 +0000202 bool isOffloadedOrDirect_l() const final REQUIRES(audio_utils::EffectChain_Mutex);
203 bool isVolumeControlEnabled_l() const final REQUIRES(audio_utils::EffectChain_Mutex);
Andy Hung6ac17eb2023-06-20 18:56:17 -0700204 void setInBuffer(const sp<EffectBufferHalInterface>& buffer) final;
205 int16_t *inBuffer() const final {
Eric Laurent41709552019-12-16 19:34:05 -0800206 return mInBuffer != 0 ? reinterpret_cast<int16_t*>(mInBuffer->ptr()) : NULL;
207 }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700208 void setOutBuffer(const sp<EffectBufferHalInterface>& buffer) final;
209 int16_t *outBuffer() const final {
Eric Laurent41709552019-12-16 19:34:05 -0800210 return mOutBuffer != 0 ? reinterpret_cast<int16_t*>(mOutBuffer->ptr()) : NULL;
211 }
Andy Hung799c8d02021-10-28 17:05:40 -0700212 // Updates the access mode if it is out of date. May issue a new effect configure.
Shunkai Yaod125e402024-01-20 03:19:06 +0000213 void updateAccessMode_l() final REQUIRES(audio_utils::EffectChain_Mutex) {
214 if (requiredEffectBufferAccessMode() != mConfig.outputCfg.accessMode) {
215 configure_l();
216 }
217 }
218 status_t setDevices(const AudioDeviceTypeAddrVector& devices) final EXCLUDES_EffectBase_Mutex;
219 status_t setInputDevice(const AudioDeviceTypeAddr& device) final EXCLUDES_EffectBase_Mutex;
Shunkai Yao44778ce2024-06-08 00:54:32 +0000220 status_t setVolume_l(uint32_t* left, uint32_t* right, bool controller, bool force) final
221 REQUIRES(audio_utils::EffectChain_Mutex);
Shunkai Yaod125e402024-01-20 03:19:06 +0000222 status_t setMode(audio_mode_t mode) final EXCLUDES_EffectBase_Mutex;
223 status_t setAudioSource(audio_source_t source) final EXCLUDES_EffectBase_Mutex;
224 status_t start_l() final REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex;
225 status_t stop_l() final REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex;
Andy Hung799c8d02021-10-28 17:05:40 -0700226
Shunkai Yaod125e402024-01-20 03:19:06 +0000227 status_t setOffloaded_l(bool offloaded, audio_io_handle_t io) final
228 REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex;
229 bool isOffloaded_l() const final
230 REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex;
François Gaffiec944aa32024-03-13 17:08:52 +0100231 void addEffectToHal_l() override REQUIRES(audio_utils::EffectChain_Mutex);
Shunkai Yao4fa10092024-04-04 17:30:48 +0000232 void release_l(const std::string& from = "") final REQUIRES(audio_utils::EffectChain_Mutex);
Eric Laurent41709552019-12-16 19:34:05 -0800233
Andy Hung6ac17eb2023-06-20 18:56:17 -0700234 sp<IAfEffectModule> asEffectModule() final { return this; }
Eric Laurent41709552019-12-16 19:34:05 -0800235
Andy Hung6ac17eb2023-06-20 18:56:17 -0700236 bool isHapticGenerator() const final;
Eric Laurent4eb45d02023-12-20 12:07:17 +0100237 bool isSpatializer() const final;
Eric Laurent41709552019-12-16 19:34:05 -0800238
Ahmad Khalil229466a2024-02-05 12:15:30 +0000239 status_t setHapticScale_l(int id, os::HapticScale hapticScale) final
Shunkai Yao29d10572024-03-19 04:31:47 +0000240 REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex;
Shunkai Yaod125e402024-01-20 03:19:06 +0000241 status_t setVibratorInfo_l(const media::AudioVibratorInfo& vibratorInfo) final
Shunkai Yao29d10572024-03-19 04:31:47 +0000242 REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex;
Shunkai Yaod125e402024-01-20 03:19:06 +0000243 status_t sendMetadata_ll(const std::vector<playback_track_metadata_v7_t>& metadata) final
244 REQUIRES(audio_utils::ThreadBase_Mutex,
245 audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex;
jiabineb3bda02020-06-30 14:07:03 -0700246
Shunkai Yaod125e402024-01-20 03:19:06 +0000247 status_t getConfigs_l(audio_config_base_t* inputCfg, audio_config_base_t* outputCfg,
248 bool* isOutput) const final
249 REQUIRES(audio_utils::EffectHandle_Mutex) EXCLUDES_EffectBase_Mutex;
Mikhail Naganov8d7da002022-04-19 21:21:23 +0000250
Andy Hung6ac17eb2023-06-20 18:56:17 -0700251 void dump(int fd, const Vector<String16>& args) const final;
Eric Laurent41709552019-12-16 19:34:05 -0800252
François Gaffiec944aa32024-03-13 17:08:52 +0100253protected:
254 sp<EffectHalInterface> mEffectInterface; // Effect module HAL
255
Eric Laurent41709552019-12-16 19:34:05 -0800256private:
Eric Laurent81784c32012-11-19 14:55:58 -0800257
258 // Maximum time allocated to effect engines to complete the turn off sequence
259 static const uint32_t MAX_DISABLE_TIME_MS = 10000;
260
Mikhail Naganovbf493082017-04-17 17:37:12 -0700261 DISALLOW_COPY_AND_ASSIGN(EffectModule);
Eric Laurent81784c32012-11-19 14:55:58 -0800262
Shunkai Yaod125e402024-01-20 03:19:06 +0000263 status_t start_ll() REQUIRES(audio_utils::EffectChain_Mutex, audio_utils::EffectBase_Mutex);
264 status_t stop_ll() REQUIRES(audio_utils::EffectChain_Mutex, audio_utils::EffectBase_Mutex);
François Gaffiec944aa32024-03-13 17:08:52 +0100265 status_t removeEffectFromHal_l() override REQUIRES(audio_utils::EffectChain_Mutex);
jiabin8f278ee2019-11-11 12:16:27 -0800266 status_t sendSetAudioDevicesCommand(const AudioDeviceTypeAddrVector &devices, uint32_t cmdCode);
Andy Hung799c8d02021-10-28 17:05:40 -0700267 effect_buffer_access_e requiredEffectBufferAccessMode() const {
268 return mConfig.inputCfg.buffer.raw == mConfig.outputCfg.buffer.raw
269 ? EFFECT_BUFFER_ACCESS_WRITE : EFFECT_BUFFER_ACCESS_ACCUMULATE;
270 }
271
Shunkai Yao12629832024-07-12 21:21:42 +0000272 status_t setVolumeInternal_ll(uint32_t* left, uint32_t* right,
273 bool controller /* the volume controller effect of the chain */)
274 REQUIRES(audio_utils::EffectChain_Mutex, audio_utils::EffectBase_Mutex);
Eric Laurent81784c32012-11-19 14:55:58 -0800275
Eric Laurent81784c32012-11-19 14:55:58 -0800276 effect_config_t mConfig; // input and output audio configuration
Mikhail Naganov022b9952017-01-04 16:36:51 -0800277 sp<EffectBufferHalInterface> mInBuffer; // Buffers for interacting with HAL
278 sp<EffectBufferHalInterface> mOutBuffer;
Eric Laurent81784c32012-11-19 14:55:58 -0800279 status_t mStatus; // initialization status
Eric Laurent81784c32012-11-19 14:55:58 -0800280 // First handle in mHandles has highest priority and controls the effect module
281 uint32_t mMaxDisableWaitCnt; // maximum grace period before forcing an effect off after
282 // sending disable command.
283 uint32_t mDisableWaitCnt; // current process() calls count during disable period.
Eric Laurent5baf2af2013-09-12 17:37:00 -0700284 bool mOffloaded; // effect is currently offloaded to the audio DSP
Shunkai Yaof80f58f2024-07-03 18:21:30 +0000285 // effect has been added to this HAL input stream
286 audio_io_handle_t mCurrentHalStream = AUDIO_IO_HANDLE_NONE;
Mikhail Naganov8d7da002022-04-19 21:21:23 +0000287 bool mIsOutput; // direction of the AF thread
rago94a1ee82017-07-21 15:11:02 -0700288
rago94a1ee82017-07-21 15:11:02 -0700289 bool mSupportsFloat; // effect supports float processing
Andy Hungbded9c82017-11-30 18:47:35 -0800290 sp<EffectBufferHalInterface> mInConversionBuffer; // Buffers for HAL conversion if needed.
291 sp<EffectBufferHalInterface> mOutConversionBuffer;
Andy Hung9aad48c2017-11-29 10:29:19 -0800292 uint32_t mInChannelCountRequested;
293 uint32_t mOutChannelCountRequested;
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900294
Andy Hungf65f5a72023-08-29 12:19:17 -0700295 template <typename MUTEX>
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900296 class AutoLockReentrant {
297 public:
Shunkai Yao12629832024-07-12 21:21:42 +0000298 AutoLockReentrant(MUTEX& mutex, pid_t allowedTid) ACQUIRE(audio_utils::EffectBase_Mutex)
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900299 : mMutex(gettid() == allowedTid ? nullptr : &mutex)
300 {
301 if (mMutex != nullptr) mMutex->lock();
302 }
Shunkai Yao12629832024-07-12 21:21:42 +0000303 ~AutoLockReentrant() RELEASE(audio_utils::EffectBase_Mutex) {
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900304 if (mMutex != nullptr) mMutex->unlock();
305 }
306 private:
Andy Hungf65f5a72023-08-29 12:19:17 -0700307 MUTEX * const mMutex;
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900308 };
309
310 static constexpr pid_t INVALID_PID = (pid_t)-1;
311 // this tid is allowed to call setVolume() without acquiring the mutex.
312 pid_t mSetVolumeReentrantTid = INVALID_PID;
jiabin8b627fa2024-03-19 19:05:38 +0000313
jiabin59c27cb2024-04-17 20:44:20 +0000314 // Cache the volume that has been set successfully.
jiabin8b627fa2024-03-19 19:05:38 +0000315 std::optional<std::vector<uint32_t>> mVolume;
jiabin59c27cb2024-04-17 20:44:20 +0000316 // Cache the volume that returned from the effect when setting volume successfully. The value
317 // here is used to indicate the volume to apply before this effect.
318 std::optional<std::vector<uint32_t>> mReturnedVolume;
Shunkai Yao4fa10092024-04-04 17:30:48 +0000319 // TODO: b/315995877, remove this debugging string after root cause
Shunkai Yao12629832024-07-12 21:21:42 +0000320 std::string mEffectInterfaceDebug GUARDED_BY(audio_utils::EffectChain_Mutex);
Eric Laurent81784c32012-11-19 14:55:58 -0800321};
322
François Gaffiec944aa32024-03-13 17:08:52 +0100323class HwAccDeviceEffectModule : public EffectModule {
324public:
325 HwAccDeviceEffectModule(const sp<EffectCallbackInterface>& callback, effect_descriptor_t *desc,
326 int id, audio_port_handle_t deviceId) :
327 EffectModule(callback, desc, id, AUDIO_SESSION_DEVICE, /* pinned */ false, deviceId) {}
328 void addEffectToHal_l() final REQUIRES(audio_utils::EffectChain_Mutex);
329
330private:
331 status_t removeEffectFromHal_l() final REQUIRES(audio_utils::EffectChain_Mutex);
332 bool mAddedToHal = false;
333};
334
Eric Laurent81784c32012-11-19 14:55:58 -0800335// The EffectHandle class implements the IEffect interface. It provides resources
336// to receive parameter updates, keeps track of effect control
337// ownership and state and has a pointer to the EffectModule object it is controlling.
338// There is one EffectHandle object for each application controlling (or using)
339// an effect module.
340// The EffectHandle is obtained by calling AudioFlinger::createEffect().
Andy Hung6ac17eb2023-06-20 18:56:17 -0700341class EffectHandle: public IAfEffectHandle, public android::media::BnEffect {
Eric Laurent81784c32012-11-19 14:55:58 -0800342public:
343
Andy Hung6ac17eb2023-06-20 18:56:17 -0700344 EffectHandle(const sp<IAfEffectBase>& effect,
Andy Hung59867e42023-06-27 17:05:02 -0700345 const sp<Client>& client,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700346 const sp<media::IEffectClient>& effectClient,
François Gaffiefce3b6c2024-05-23 13:52:23 +0200347 int32_t priority, bool notifyFramesProcessed, bool isInternal = false,
348 audio_utils::MutexOrder mutexOrder = audio_utils::MutexOrder::kEffectHandle_Mutex);
Andy Hung6ac17eb2023-06-20 18:56:17 -0700349 ~EffectHandle() override;
Andy Hungc747c532022-03-07 21:41:14 -0800350 status_t onTransact(
Andy Hung6ac17eb2023-06-20 18:56:17 -0700351 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) final;
352 status_t initCheck() const final;
Eric Laurent81784c32012-11-19 14:55:58 -0800353
354 // IEffect
Andy Hung6ac17eb2023-06-20 18:56:17 -0700355 android::binder::Status enable(int32_t* _aidl_return) final;
356 android::binder::Status disable(int32_t* _aidl_return) final;
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700357 android::binder::Status command(int32_t cmdCode,
358 const std::vector<uint8_t>& cmdData,
359 int32_t maxResponseSize,
360 std::vector<uint8_t>* response,
Andy Hung6ac17eb2023-06-20 18:56:17 -0700361 int32_t* _aidl_return) final;
362 android::binder::Status disconnect() final;
363 android::binder::Status getCblk(media::SharedFileRegion* _aidl_return) final;
Mikhail Naganov8d7da002022-04-19 21:21:23 +0000364 android::binder::Status getConfig(media::EffectConfig* _config,
Andy Hung6ac17eb2023-06-20 18:56:17 -0700365 int32_t* _aidl_return) final;
Eric Laurent81784c32012-11-19 14:55:58 -0800366
Andy Hung59867e42023-06-27 17:05:02 -0700367 const sp<Client>& client() const final { return mClient; }
François Gaffiefce3b6c2024-05-23 13:52:23 +0200368 /**
369 * Checks if the handle is internal, aka created by AudioFlinger for internal needs (e.g.
370 * device effect HAL handle or device effect thread handle).
371 */
372 virtual bool isInternal() const { return mIsInternal; }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700373
374 sp<android::media::IEffect> asIEffect() final {
375 return sp<android::media::IEffect>::fromExisting(this);
376 }
Eric Laurentd66d7a12021-07-13 13:35:32 +0200377
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700378private:
379 void disconnect(bool unpinIfLast);
Eric Laurent81784c32012-11-19 14:55:58 -0800380
381 // Give or take control of effect module
382 // - hasControl: true if control is given, false if removed
383 // - signal: true client app should be signaled of change, false otherwise
384 // - enabled: state of the effect when control is passed
Andy Hung6ac17eb2023-06-20 18:56:17 -0700385 void setControl(bool hasControl, bool signal, bool enabled) final;
Eric Laurent81784c32012-11-19 14:55:58 -0800386 void commandExecuted(uint32_t cmdCode,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700387 const std::vector<uint8_t>& cmdData,
Andy Hung6ac17eb2023-06-20 18:56:17 -0700388 const std::vector<uint8_t>& replyData) final;
389 bool enabled() const final { return mEnabled; }
390 void setEnabled(bool enabled) final;
391 void framesProcessed(int32_t frames) const final;
Eric Laurent81784c32012-11-19 14:55:58 -0800392
Andy Hung6ac17eb2023-06-20 18:56:17 -0700393public:
Eric Laurent81784c32012-11-19 14:55:58 -0800394 // Getters
Andy Hung6ac17eb2023-06-20 18:56:17 -0700395 wp<IAfEffectBase> effect() const final { return mEffect; }
396 int id() const final {
397 sp<IAfEffectBase> effect = mEffect.promote();
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800398 if (effect == 0) {
399 return 0;
400 }
401 return effect->id();
402 }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700403private:
404 int priority() const final { return mPriority; }
405 bool hasControl() const final { return mHasControl; }
406 bool disconnected() const final { return mDisconnected; }
Eric Laurent81784c32012-11-19 14:55:58 -0800407
Andy Hung6ac17eb2023-06-20 18:56:17 -0700408 void dumpToBuffer(char* buffer, size_t size) const final;
409
François Gaffiefce3b6c2024-05-23 13:52:23 +0200410protected:
411 // protects IEffect method calls
412 mutable audio_utils::mutex mMutex;
Eric Laurent81784c32012-11-19 14:55:58 -0800413
Mikhail Naganovbf493082017-04-17 17:37:12 -0700414private:
Mikhail Naganovbf493082017-04-17 17:37:12 -0700415 DISALLOW_COPY_AND_ASSIGN(EffectHandle);
Eric Laurent81784c32012-11-19 14:55:58 -0800416
François Gaffiefce3b6c2024-05-23 13:52:23 +0200417 virtual audio_utils::mutex& mutex() const
418 RETURN_CAPABILITY(android::audio_utils::EffectHandle_Mutex) {
Shunkai Yaod125e402024-01-20 03:19:06 +0000419 return mMutex;
420 }
François Gaffiefce3b6c2024-05-23 13:52:23 +0200421
Andy Hung6ac17eb2023-06-20 18:56:17 -0700422 const wp<IAfEffectBase> mEffect; // pointer to controlled EffectModule
Andy Hung318e0242020-12-21 10:33:49 -0800423 const sp<media::IEffectClient> mEffectClient; // callback interface for client notifications
Andy Hung59867e42023-06-27 17:05:02 -0700424 /*const*/ sp<Client> mClient; // client for shared memory allocation, see
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700425 // disconnect()
426 sp<IMemory> mCblkMemory; // shared memory for control block
427 effect_param_cblk_t* mCblk; // control block for deferred parameter setting via
428 // shared memory
429 uint8_t* mBuffer; // pointer to parameter area in shared memory
430 int mPriority; // client application priority to control the effect
431 bool mHasControl; // true if this handle is controlling the effect
432 bool mEnabled; // cached enable state: needed when the effect is
433 // restored after being suspended
434 bool mDisconnected; // Set to true by disconnect()
Eric Laurentde8caf42021-08-11 17:19:25 +0200435 const bool mNotifyFramesProcessed; // true if the client callback event
436 // EVENT_FRAMES_PROCESSED must be generated
François Gaffiefce3b6c2024-05-23 13:52:23 +0200437 const bool mIsInternal;
438};
439
440/**
441 * There are 2 types of effects:
442 * -Session Effect: handle is directly called from the client, without AudioFlinger lock.
443 * -Device Effect: a device effect proxy is aggregating a collection of internal effect handles that
444 * controls the same effect added on all audio patches involving the device effect selected port
445 * requested either by a client or by AudioPolicyEffects. These internal effect handles do not have
446 * client. Sequence flow implies a different locking order, hence the lock is specialied.
447 */
448class InternalEffectHandle : public EffectHandle {
449public:
450 InternalEffectHandle(const sp<IAfEffectBase>& effect, bool notifyFramesProcessed) :
451 EffectHandle(effect, /* client= */ nullptr, /* effectClient= */ nullptr,
452 /* priority= */ 0, notifyFramesProcessed, /* isInternal */ true,
453 audio_utils::MutexOrder::kDeviceEffectHandle_Mutex) {}
454
455 virtual audio_utils::mutex& mutex() const
456 RETURN_CAPABILITY(android::audio_utils::DeviceEffectHandle_Mutex) {
457 return mMutex;
458 }
Eric Laurent81784c32012-11-19 14:55:58 -0800459};
460
461// the EffectChain class represents a group of effects associated to one audio session.
462// There can be any number of EffectChain objects per output mixer thread (PlaybackThread).
Glenn Kastend848eb42016-03-08 13:42:11 -0800463// The EffectChain with session ID AUDIO_SESSION_OUTPUT_MIX contains global effects applied
464// to the output mix.
Eric Laurent81784c32012-11-19 14:55:58 -0800465// Effects in this chain can be insert or auxiliary. Effects in other chains (attached to
466// tracks) are insert only. The EffectChain maintains an ordered list of effect module, the
Glenn Kastend848eb42016-03-08 13:42:11 -0800467// order corresponding in the effect process order. When attached to a track (session ID !=
468// AUDIO_SESSION_OUTPUT_MIX),
Eric Laurent81784c32012-11-19 14:55:58 -0800469// it also provide it's own input buffer used by the track as accumulation buffer.
Andy Hung6ac17eb2023-06-20 18:56:17 -0700470class EffectChain : public IAfEffectChain {
Eric Laurent81784c32012-11-19 14:55:58 -0800471public:
Shunkai Yao29d10572024-03-19 04:31:47 +0000472 EffectChain(const sp<IAfThreadBase>& thread,
473 audio_session_t sessionId,
474 const sp<IAfThreadCallback>& afThreadCallback);
Eric Laurent81784c32012-11-19 14:55:58 -0800475
Shunkai Yaof4847652024-01-12 00:25:20 +0000476 void process_l() final REQUIRES(audio_utils::EffectChain_Mutex);
Eric Laurent81784c32012-11-19 14:55:58 -0800477
Shunkai Yaof4847652024-01-12 00:25:20 +0000478 audio_utils::mutex& mutex() const final RETURN_CAPABILITY(audio_utils::EffectChain_Mutex) {
479 return mMutex;
480 }
Andy Hungf65f5a72023-08-29 12:19:17 -0700481
Shunkai Yao29d10572024-03-19 04:31:47 +0000482 status_t createEffect(sp<IAfEffectModule>& effect, effect_descriptor_t* desc, int id,
Shunkai Yaod125e402024-01-20 03:19:06 +0000483 audio_session_t sessionId, bool pinned) final
Shunkai Yao29d10572024-03-19 04:31:47 +0000484 EXCLUDES_EffectChain_Mutex;
485 status_t addEffect(const sp<IAfEffectModule>& handle) final
486 EXCLUDES_EffectChain_Mutex;
Shunkai Yaod125e402024-01-20 03:19:06 +0000487 status_t addEffect_l(const sp<IAfEffectModule>& handle) final
Shunkai Yao29d10572024-03-19 04:31:47 +0000488 REQUIRES(audio_utils::EffectChain_Mutex);
489 size_t removeEffect(const sp<IAfEffectModule>& handle, bool release = false) final
490 EXCLUDES_EffectChain_Mutex;
Eric Laurent81784c32012-11-19 14:55:58 -0800491
Andy Hung6ac17eb2023-06-20 18:56:17 -0700492 audio_session_t sessionId() const final { return mSessionId; }
493 void setSessionId(audio_session_t sessionId) final { mSessionId = sessionId; }
Eric Laurent81784c32012-11-19 14:55:58 -0800494
Shunkai Yao29d10572024-03-19 04:31:47 +0000495 sp<IAfEffectModule> getEffectFromDesc(effect_descriptor_t* descriptor) const final
496 EXCLUDES_EffectChain_Mutex;
Shunkai Yaod125e402024-01-20 03:19:06 +0000497 sp<IAfEffectModule> getEffectFromId_l(int id) const final
Shunkai Yao29d10572024-03-19 04:31:47 +0000498 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex;
Shunkai Yaod125e402024-01-20 03:19:06 +0000499 sp<IAfEffectModule> getEffectFromType_l(const effect_uuid_t* type) const final
Shunkai Yao29d10572024-03-19 04:31:47 +0000500 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex;
Shunkai Yaod125e402024-01-20 03:19:06 +0000501 std::vector<int> getEffectIds_l() const final REQUIRES(audio_utils::ThreadBase_Mutex);
Glenn Kastenc56f3422014-03-21 17:53:17 -0700502 // FIXME use float to improve the dynamic range
Eric Laurent81784c32012-11-19 14:55:58 -0800503
Shunkai Yaof4847652024-01-12 00:25:20 +0000504 bool setVolume(uint32_t* left, uint32_t* right,
505 bool force = false) final EXCLUDES_EffectChain_Mutex;
506 void resetVolume_l() final REQUIRES(audio_utils::EffectChain_Mutex);
Shunkai Yaod125e402024-01-20 03:19:06 +0000507 void setDevices_l(const AudioDeviceTypeAddrVector& devices) final
Shunkai Yao29d10572024-03-19 04:31:47 +0000508 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex;
Shunkai Yaod125e402024-01-20 03:19:06 +0000509 void setInputDevice_l(const AudioDeviceTypeAddr& device) final
Shunkai Yao29d10572024-03-19 04:31:47 +0000510 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex;
511 void setMode_l(audio_mode_t mode) final
512 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex;
513 void setAudioSource_l(audio_source_t source) final
514 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700515
516 void setInBuffer(const sp<EffectBufferHalInterface>& buffer) final {
Eric Laurent81784c32012-11-19 14:55:58 -0800517 mInBuffer = buffer;
Eric Laurent81784c32012-11-19 14:55:58 -0800518 }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700519 float *inBuffer() const final {
Andy Hung181d96f2023-05-23 14:01:03 -0700520 return mInBuffer != 0 ? reinterpret_cast<float*>(mInBuffer->ptr()) : NULL;
Eric Laurent81784c32012-11-19 14:55:58 -0800521 }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700522 void setOutBuffer(const sp<EffectBufferHalInterface>& buffer) final {
Eric Laurent81784c32012-11-19 14:55:58 -0800523 mOutBuffer = buffer;
524 }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700525 float *outBuffer() const final {
Andy Hung181d96f2023-05-23 14:01:03 -0700526 return mOutBuffer != 0 ? reinterpret_cast<float*>(mOutBuffer->ptr()) : NULL;
Eric Laurent81784c32012-11-19 14:55:58 -0800527 }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700528 void incTrackCnt() final { android_atomic_inc(&mTrackCnt); }
529 void decTrackCnt() final { android_atomic_dec(&mTrackCnt); }
530 int32_t trackCnt() const final { return android_atomic_acquire_load(&mTrackCnt); }
Eric Laurent81784c32012-11-19 14:55:58 -0800531
Andy Hung6ac17eb2023-06-20 18:56:17 -0700532 void incActiveTrackCnt() final { android_atomic_inc(&mActiveTrackCnt);
Eric Laurent81784c32012-11-19 14:55:58 -0800533 mTailBufferCount = mMaxTailBuffers; }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700534 void decActiveTrackCnt() final { android_atomic_dec(&mActiveTrackCnt); }
535 int32_t activeTrackCnt() const final {
536 return android_atomic_acquire_load(&mActiveTrackCnt);
537 }
Eric Laurent81784c32012-11-19 14:55:58 -0800538
Andy Hung6ac17eb2023-06-20 18:56:17 -0700539 product_strategy_t strategy() const final { return mStrategy; }
540 void setStrategy(product_strategy_t strategy) final
Eric Laurent81784c32012-11-19 14:55:58 -0800541 { mStrategy = strategy; }
542
Eric Laurentd8365c52017-07-16 15:27:05 -0700543 // suspend or restore effects of the specified type. The number of suspend requests is counted
544 // and restore occurs once all suspend requests are cancelled.
Shunkai Yaod125e402024-01-20 03:19:06 +0000545 void setEffectSuspended_l(const effect_uuid_t* type, bool suspend) final
546 REQUIRES(audio_utils::ThreadBase_Mutex);
Eric Laurent81784c32012-11-19 14:55:58 -0800547 // suspend all eligible effects
Shunkai Yaod125e402024-01-20 03:19:06 +0000548 void setEffectSuspendedAll_l(bool suspend) final REQUIRES(audio_utils::ThreadBase_Mutex);
Eric Laurent6b446ce2019-12-13 10:56:31 -0800549 // check if effects should be suspended or restored when a given effect is enable or disabled
Shunkai Yaod125e402024-01-20 03:19:06 +0000550 void checkSuspendOnEffectEnabled_l(const sp<IAfEffectModule>& effect, bool enabled) final
551 REQUIRES(audio_utils::ThreadBase_Mutex);
Eric Laurent81784c32012-11-19 14:55:58 -0800552
Shunkai Yaod125e402024-01-20 03:19:06 +0000553 void clearInputBuffer() final EXCLUDES_EffectChain_Mutex;
Eric Laurent81784c32012-11-19 14:55:58 -0800554
Eric Laurent5baf2af2013-09-12 17:37:00 -0700555 // At least one non offloadable effect in the chain is enabled
Shunkai Yaod125e402024-01-20 03:19:06 +0000556 bool isNonOffloadableEnabled() const final EXCLUDES_EffectChain_Mutex;
557 bool isNonOffloadableEnabled_l() const final REQUIRES(audio_utils::EffectChain_Mutex);
Eric Laurent813e2a72013-08-31 12:59:48 -0700558
Shunkai Yaod125e402024-01-20 03:19:06 +0000559 void syncHalEffectsState_l()
560 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex final;
Eric Laurent1b928682014-10-02 19:41:47 -0700561
Andy Hungd3bb0ad2016-10-11 17:16:43 -0700562 // flags is an ORed set of audio_output_flags_t which is updated on return.
Andy Hung6ac17eb2023-06-20 18:56:17 -0700563 void checkOutputFlagCompatibility(audio_output_flags_t *flags) const final;
Andy Hungd3bb0ad2016-10-11 17:16:43 -0700564
565 // flags is an ORed set of audio_input_flags_t which is updated on return.
Andy Hung6ac17eb2023-06-20 18:56:17 -0700566 void checkInputFlagCompatibility(audio_input_flags_t *flags) const final;
Andy Hungd3bb0ad2016-10-11 17:16:43 -0700567
568 // Is this EffectChain compatible with the RAW audio flag.
Andy Hung6ac17eb2023-06-20 18:56:17 -0700569 bool isRawCompatible() const final;
Andy Hungd3bb0ad2016-10-11 17:16:43 -0700570
571 // Is this EffectChain compatible with the FAST audio flag.
Andy Hung6ac17eb2023-06-20 18:56:17 -0700572 bool isFastCompatible() const final;
Eric Laurent4c415062016-06-17 16:14:16 -0700573
jiabinc658e452022-10-21 20:52:21 +0000574 // Is this EffectChain compatible with the bit-perfect audio flag.
Andy Hung6ac17eb2023-06-20 18:56:17 -0700575 bool isBitPerfectCompatible() const final;
jiabinc658e452022-10-21 20:52:21 +0000576
Andy Hungf65f5a72023-08-29 12:19:17 -0700577 // isCompatibleWithThread_l() must be called with thread->mutex() held
Andy Hungab65b182023-09-06 19:41:47 -0700578 bool isCompatibleWithThread_l(const sp<IAfThreadBase>& thread) const final
Shunkai Yaod125e402024-01-20 03:19:06 +0000579 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex;
jiabineb3bda02020-06-30 14:07:03 -0700580
Shunkai Yao29d10572024-03-19 04:31:47 +0000581 bool containsHapticGeneratingEffect() final
582 EXCLUDES_EffectChain_Mutex;
583
584 bool containsHapticGeneratingEffect_l() final
585 REQUIRES(audio_utils::EffectChain_Mutex);
jiabine70bc7f2020-06-30 22:07:55 -0700586
Ahmad Khalil229466a2024-02-05 12:15:30 +0000587 void setHapticScale_l(int id, os::HapticScale hapticScale) final
Shunkai Yaod125e402024-01-20 03:19:06 +0000588 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800589
Andy Hung6ac17eb2023-06-20 18:56:17 -0700590 sp<EffectCallbackInterface> effectCallback() const final { return mEffectCallback; }
Eric Laurentf1f22e72021-07-13 14:04:14 +0200591
Andy Hung87c693c2023-07-06 20:56:16 -0700592 wp<IAfThreadBase> thread() const final { return mEffectCallback->thread(); }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700593
Shunkai Yao29d10572024-03-19 04:31:47 +0000594 bool isFirstEffect_l(int id) const final REQUIRES(audio_utils::EffectChain_Mutex) {
Andy Hung6ac17eb2023-06-20 18:56:17 -0700595 return !mEffects.isEmpty() && id == mEffects[0]->id();
596 }
597
598 void dump(int fd, const Vector<String16>& args) const final;
599
Shunkai Yao29d10572024-03-19 04:31:47 +0000600 size_t numberOfEffects() const final {
601 audio_utils::lock_guard _l(mutex());
602 return mEffects.size();
603 }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700604
605 sp<IAfEffectModule> getEffectModule(size_t index) const final {
Shunkai Yao29d10572024-03-19 04:31:47 +0000606 audio_utils::lock_guard _l(mutex());
Andy Hung6ac17eb2023-06-20 18:56:17 -0700607 return mEffects[index];
608 }
609
Eric Laurent4eb45d02023-12-20 12:07:17 +0100610 void sendMetadata_l(const std::vector<playback_track_metadata_v7_t>& allMetadata,
611 const std::optional<const std::vector<playback_track_metadata_v7_t>> spatializedMetadata)
612 final REQUIRES(audio_utils::ThreadBase_Mutex);
613
Shunkai Yaod125e402024-01-20 03:19:06 +0000614 void setThread(const sp<IAfThreadBase>& thread) final EXCLUDES_EffectChain_Mutex;
Eric Laurent81784c32012-11-19 14:55:58 -0800615
Shunkai Yaof4847652024-01-12 00:25:20 +0000616 private:
617 bool setVolume_l(uint32_t* left, uint32_t* right, bool force = false)
618 REQUIRES(audio_utils::EffectChain_Mutex);
Eric Laurent6b446ce2019-12-13 10:56:31 -0800619
Andy Hung328d6772021-01-12 12:32:21 -0800620 // For transaction consistency, please consider holding the EffectChain lock before
621 // calling the EffectChain::EffectCallback methods, excepting
622 // createEffectHal and allocateHalBuffer.
623 //
624 // This prevents migration of the EffectChain to another PlaybackThread
625 // for the purposes of the EffectCallback.
Eric Laurent6b446ce2019-12-13 10:56:31 -0800626 class EffectCallback : public EffectCallbackInterface {
627 public:
Ytai Ben-Tsvi4f043362020-01-28 12:39:23 -0800628 // Note: ctors taking a weak pointer to their owner must not promote it
629 // during construction (but may keep a reference for later promotion).
630 EffectCallback(const wp<EffectChain>& owner,
Shunkai Yao29d10572024-03-19 04:31:47 +0000631 const sp<IAfThreadBase>& thread,
632 const sp<IAfThreadCallback>& afThreadCallback) // we take a sp<> but store a wp<>.
Andy Hung6626a012021-01-12 13:38:00 -0800633 : mChain(owner)
Shunkai Yao29d10572024-03-19 04:31:47 +0000634 , mThread(thread), mAfThreadCallback(afThreadCallback) {
635 if (thread != nullptr) {
636 mThreadType = thread->type();
637 }
Ytai Ben-Tsvi3de1bbf2020-01-21 16:41:17 -0800638 }
Eric Laurent6b446ce2019-12-13 10:56:31 -0800639
640 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
641 int32_t sessionId, int32_t deviceId, sp<EffectHalInterface> *effect) override;
642 status_t allocateHalBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) override;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700643 bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect) override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800644
645 audio_io_handle_t io() const override;
646 bool isOutput() const override;
647 bool isOffload() const override;
648 bool isOffloadOrDirect() const override;
649 bool isOffloadOrMmap() const override;
Eric Laurent0dccd2e2021-10-26 17:40:18 +0200650 bool isSpatializer() const override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800651
652 uint32_t sampleRate() const override;
Eric Laurentf1f22e72021-07-13 14:04:14 +0200653 audio_channel_mask_t inChannelMask(int id) const override;
654 uint32_t inChannelCount(int id) const override;
655 audio_channel_mask_t outChannelMask() const override;
656 uint32_t outChannelCount() const override;
jiabineb3bda02020-06-30 14:07:03 -0700657 audio_channel_mask_t hapticChannelMask() const override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800658 size_t frameCount() const override;
659 uint32_t latency() const override;
660
Andy Hung920f6572022-10-06 12:09:49 -0700661 status_t addEffectToHal(const sp<EffectHalInterface>& effect) override;
662 status_t removeEffectFromHal(const sp<EffectHalInterface>& effect) override;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700663 bool disconnectEffectHandle(IAfEffectHandle *handle, bool unpinIfLast) override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800664 void setVolumeForOutput(float left, float right) const override;
665
666 // check if effects should be suspended/restored when a given effect is enable/disabled
Shunkai Yaod125e402024-01-20 03:19:06 +0000667 void checkSuspendOnEffectEnabled(const sp<IAfEffectBase>& effect, bool enabled,
668 bool threadLocked) override;
669 void resetVolume_l() override
670 REQUIRES(audio_utils::ThreadBase_Mutex, audio_utils::EffectChain_Mutex);
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800671 product_strategy_t strategy() const override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800672 int32_t activeTrackCnt() const override;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700673 void onEffectEnable(const sp<IAfEffectBase>& effect) override;
674 void onEffectDisable(const sp<IAfEffectBase>& effect) override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800675
Andy Hung6ac17eb2023-06-20 18:56:17 -0700676 wp<IAfEffectChain> chain() const final { return mChain; }
Eric Laurent6b446ce2019-12-13 10:56:31 -0800677
Andy Hung6ac17eb2023-06-20 18:56:17 -0700678 bool isAudioPolicyReady() const final {
Shunkai Yao29d10572024-03-19 04:31:47 +0000679 if (mAfThreadCallback == nullptr) {
680 return false;
681 }
Andy Hung583043b2023-07-17 17:05:00 -0700682 return mAfThreadCallback->isAudioPolicyReady();
Eric Laurentd66d7a12021-07-13 13:35:32 +0200683 }
684
Andy Hung87c693c2023-07-06 20:56:16 -0700685 wp<IAfThreadBase> thread() const { return mThread.load(); }
Ytai Ben-Tsvi3de1bbf2020-01-21 16:41:17 -0800686
Andy Hung87c693c2023-07-06 20:56:16 -0700687 void setThread(const sp<IAfThreadBase>& thread) {
Ytai Ben-Tsvi3de1bbf2020-01-21 16:41:17 -0800688 mThread = thread;
Shunkai Yao29d10572024-03-19 04:31:47 +0000689 if (thread != nullptr) {
690 mThreadType = thread->type();
691 mAfThreadCallback = thread->afThreadCallback();
692 }
Ytai Ben-Tsvi3de1bbf2020-01-21 16:41:17 -0800693 }
Shunkai Yao517fc2a2024-03-19 04:31:47 +0000694 bool hasThreadAttached() const {
695 return thread().promote() != nullptr;
696 }
Eric Laurent6b446ce2019-12-13 10:56:31 -0800697 private:
Andy Hung6ac17eb2023-06-20 18:56:17 -0700698 const wp<IAfEffectChain> mChain;
Andy Hung87c693c2023-07-06 20:56:16 -0700699 mediautils::atomic_wp<IAfThreadBase> mThread;
Andy Hung583043b2023-07-17 17:05:00 -0700700 sp<IAfThreadCallback> mAfThreadCallback;
Shunkai Yao29d10572024-03-19 04:31:47 +0000701 IAfThreadBase::type_t mThreadType = IAfThreadBase::MIXER;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800702 };
703
Mikhail Naganovbf493082017-04-17 17:37:12 -0700704 DISALLOW_COPY_AND_ASSIGN(EffectChain);
Eric Laurent81784c32012-11-19 14:55:58 -0800705
706 class SuspendedEffectDesc : public RefBase {
707 public:
708 SuspendedEffectDesc() : mRefCount(0) {}
709
Eric Laurentd8365c52017-07-16 15:27:05 -0700710 int mRefCount; // > 0 when suspended
Eric Laurent81784c32012-11-19 14:55:58 -0800711 effect_uuid_t mType;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700712 wp<IAfEffectModule> mEffect;
Eric Laurent81784c32012-11-19 14:55:58 -0800713 };
714
715 // get a list of effect modules to suspend when an effect of the type
716 // passed is enabled.
Shunkai Yao29d10572024-03-19 04:31:47 +0000717 void getSuspendEligibleEffects(Vector<sp<IAfEffectModule>>& effects)
718 EXCLUDES_EffectChain_Mutex;
Eric Laurent81784c32012-11-19 14:55:58 -0800719
720 // get an effect module if it is currently enable
Shunkai Yaod125e402024-01-20 03:19:06 +0000721 sp<IAfEffectModule> getEffectIfEnabled_l(const effect_uuid_t* type)
722 REQUIRES(audio_utils::ThreadBase_Mutex);
Eric Laurent81784c32012-11-19 14:55:58 -0800723 // true if the effect whose descriptor is passed can be suspended
724 // OEMs can modify the rules implemented in this method to exclude specific effect
725 // types or implementations from the suspend/restore mechanism.
Shunkai Yao29d10572024-03-19 04:31:47 +0000726 bool isEffectEligibleForSuspend(const effect_descriptor_t& desc);
Eric Laurent81784c32012-11-19 14:55:58 -0800727
Shunkai Yaod125e402024-01-20 03:19:06 +0000728 static bool isEffectEligibleForBtNrecSuspend_l(const effect_uuid_t* type)
729 REQUIRES(audio_utils::ThreadBase_Mutex);
Eric Laurentd8365c52017-07-16 15:27:05 -0700730
Shunkai Yaod125e402024-01-20 03:19:06 +0000731 void clearInputBuffer_l() REQUIRES(audio_utils::EffectChain_Mutex);
Eric Laurent81784c32012-11-19 14:55:58 -0800732
Zhou Songd505c642020-02-20 16:35:37 +0800733 // true if any effect module within the chain has volume control
Shunkai Yaod125e402024-01-20 03:19:06 +0000734 bool hasVolumeControlEnabled_l() const REQUIRES(audio_utils::EffectChain_Mutex);
Zhou Songd505c642020-02-20 16:35:37 +0800735
Shunkai Yaod125e402024-01-20 03:19:06 +0000736 void setVolumeForOutput_l(uint32_t left, uint32_t right)
737 REQUIRES(audio_utils::EffectChain_Mutex);
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900738
Shunkai Yao29d10572024-03-19 04:31:47 +0000739 ssize_t getInsertIndex_l(const effect_descriptor_t& desc)
740 REQUIRES(audio_utils::EffectChain_Mutex);
Eric Laurent0dccd2e2021-10-26 17:40:18 +0200741
Shunkai Yaod125e402024-01-20 03:19:06 +0000742 std::optional<size_t> findVolumeControl_l(size_t from, size_t to) const
743 REQUIRES(audio_utils::EffectChain_Mutex);
jiabinbd18c8e2023-08-24 21:10:44 +0000744
Andy Hunga6f1cbb2023-10-12 18:18:13 -0700745 // mutex protecting effect list
746 mutable audio_utils::mutex mMutex{audio_utils::MutexOrder::kEffectChain_Mutex};
Shunkai Yao29d10572024-03-19 04:31:47 +0000747 Vector<sp<IAfEffectModule>> mEffects GUARDED_BY(mutex()); // list of effect modules
Eric Laurent4c415062016-06-17 16:14:16 -0700748 audio_session_t mSessionId; // audio session ID
Mikhail Naganov022b9952017-01-04 16:36:51 -0800749 sp<EffectBufferHalInterface> mInBuffer; // chain input buffer
750 sp<EffectBufferHalInterface> mOutBuffer; // chain output buffer
Eric Laurent81784c32012-11-19 14:55:58 -0800751
752 // 'volatile' here means these are accessed with atomic operations instead of mutex
753 volatile int32_t mActiveTrackCnt; // number of active tracks connected
754 volatile int32_t mTrackCnt; // number of tracks connected
755
Eric Laurent4c415062016-06-17 16:14:16 -0700756 int32_t mTailBufferCount; // current effect tail buffer count
757 int32_t mMaxTailBuffers; // maximum effect tail buffers
Eric Laurent4c415062016-06-17 16:14:16 -0700758 uint32_t mLeftVolume; // previous volume on left channel
759 uint32_t mRightVolume; // previous volume on right channel
760 uint32_t mNewLeftVolume; // new volume on left channel
761 uint32_t mNewRightVolume; // new volume on right channel
Jaideep Sharmad4270b92024-07-10 14:56:42 +0530762 product_strategy_t mStrategy = PRODUCT_STRATEGY_NONE; // strategy for this effect chain
Eric Laurent4c415062016-06-17 16:14:16 -0700763 // mSuspendedEffects lists all effects currently suspended in the chain.
764 // Use effect type UUID timelow field as key. There is no real risk of identical
765 // timeLow fields among effect type UUIDs.
Eric Laurentd8365c52017-07-16 15:27:05 -0700766 // Updated by setEffectSuspended_l() and setEffectSuspendedAll_l() only.
Eric Laurent4c415062016-06-17 16:14:16 -0700767 KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800768
769 const sp<EffectCallback> mEffectCallback;
jiabinbd18c8e2023-08-24 21:10:44 +0000770
771 wp<IAfEffectModule> mVolumeControlEffect;
Eric Laurent81784c32012-11-19 14:55:58 -0800772};
Eric Laurentb82e6b72019-11-22 17:25:04 -0800773
Andy Hung6ac17eb2023-06-20 18:56:17 -0700774class DeviceEffectProxy : public IAfDeviceEffectProxy, public EffectBase {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800775public:
Andy Hung6ac17eb2023-06-20 18:56:17 -0700776 DeviceEffectProxy(const AudioDeviceTypeAddr& device,
Andy Hung55a74fd2023-07-13 19:54:47 -0700777 const sp<DeviceEffectManagerCallback>& callback,
Eric Laurentde8caf42021-08-11 17:19:25 +0200778 effect_descriptor_t *desc, int id, bool notifyFramesProcessed)
Eric Laurentb82e6b72019-11-22 17:25:04 -0800779 : EffectBase(callback, desc, id, AUDIO_SESSION_DEVICE, false),
780 mDevice(device), mManagerCallback(callback),
Eric Laurentde8caf42021-08-11 17:19:25 +0200781 mMyCallback(new ProxyCallback(wp<DeviceEffectProxy>(this), callback)),
782 mNotifyFramesProcessed(notifyFramesProcessed) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -0800783
Andy Hung6ac17eb2023-06-20 18:56:17 -0700784 status_t setEnabled(bool enabled, bool fromHandle) final;
785 sp<IAfDeviceEffectProxy> asDeviceEffectProxy() final { return this; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800786
Shunkai Yaod125e402024-01-20 03:19:06 +0000787 status_t init_l(const std::map<audio_patch_handle_t, IAfPatchPanel::Patch>& patches) final
788 REQUIRES(audio_utils::DeviceEffectManager_Mutex) EXCLUDES_EffectBase_Mutex;
Andy Hung8e6b62a2023-07-13 18:11:33 -0700789
Andy Hung6ac17eb2023-06-20 18:56:17 -0700790 status_t onCreatePatch(audio_patch_handle_t patchHandle,
Shunkai Yaod125e402024-01-20 03:19:06 +0000791 const IAfPatchPanel::Patch& patch) final;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800792
François Gaffie58e73af2023-02-15 11:47:24 +0100793 status_t onUpdatePatch(audio_patch_handle_t oldPatchHandle, audio_patch_handle_t newPatchHandle,
Andy Hung8e6b62a2023-07-13 18:11:33 -0700794 const IAfPatchPanel::Patch& patch) final;
François Gaffie58e73af2023-02-15 11:47:24 +0100795
François Gaffiefce3b6c2024-05-23 13:52:23 +0200796 sp<IAfEffectHandle> onReleasePatch(audio_patch_handle_t patchHandle) final;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800797
Andy Hung6ac17eb2023-06-20 18:56:17 -0700798 size_t removeEffect(const sp<IAfEffectModule>& effect) final;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800799
Andy Hung6ac17eb2023-06-20 18:56:17 -0700800 status_t addEffectToHal(const sp<EffectHalInterface>& effect) final;
801 status_t removeEffectFromHal(const sp<EffectHalInterface>& effect) final;
802
803 const AudioDeviceTypeAddr& device() const final { return mDevice; };
804 bool isOutput() const final;
805 uint32_t sampleRate() const final;
806 audio_channel_mask_t channelMask() const final;
807 uint32_t channelCount() const final;
808
Shunkai Yaod125e402024-01-20 03:19:06 +0000809 status_t command(int32_t cmdCode, const std::vector<uint8_t>& cmdData, int32_t maxReplySize,
810 std::vector<uint8_t>* reply) final EXCLUDES_DeviceEffectProxy_ProxyMutex;
François Gaffiea2e985b2023-06-09 14:37:56 +0200811
Andy Hung6ac17eb2023-06-20 18:56:17 -0700812 void dump2(int fd, int spaces) const final;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800813
814private:
815
816 class ProxyCallback : public EffectCallbackInterface {
817 public:
Ytai Ben-Tsvi4f043362020-01-28 12:39:23 -0800818 // Note: ctors taking a weak pointer to their owner must not promote it
819 // during construction (but may keep a reference for later promotion).
820 ProxyCallback(const wp<DeviceEffectProxy>& owner,
Andy Hung55a74fd2023-07-13 19:54:47 -0700821 const sp<DeviceEffectManagerCallback>& callback)
Ytai Ben-Tsvi4f043362020-01-28 12:39:23 -0800822 : mProxy(owner), mManagerCallback(callback) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -0800823
824 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
825 int32_t sessionId, int32_t deviceId, sp<EffectHalInterface> *effect) override;
826 status_t allocateHalBuffer(size_t size __unused,
827 sp<EffectBufferHalInterface>* buffer __unused) override { return NO_ERROR; }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700828 bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect __unused) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800829 return false;
830 }
831
832 audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; }
833 bool isOutput() const override;
834 bool isOffload() const override { return false; }
835 bool isOffloadOrDirect() const override { return false; }
836 bool isOffloadOrMmap() const override { return false; }
Eric Laurent0dccd2e2021-10-26 17:40:18 +0200837 bool isSpatializer() const override { return false; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800838
839 uint32_t sampleRate() const override;
Eric Laurentf1f22e72021-07-13 14:04:14 +0200840 audio_channel_mask_t inChannelMask(int id) const override;
841 uint32_t inChannelCount(int id) const override;
842 audio_channel_mask_t outChannelMask() const override;
843 uint32_t outChannelCount() const override;
jiabineb3bda02020-06-30 14:07:03 -0700844 audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; }
François Gaffie9b5cbdb2024-05-31 10:36:39 +0200845 /**
846 * frameCount cannot be zero.
847 */
848 size_t frameCount() const override { return 1; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800849 uint32_t latency() const override { return 0; }
850
Andy Hung920f6572022-10-06 12:09:49 -0700851 status_t addEffectToHal(const sp<EffectHalInterface>& effect) override;
852 status_t removeEffectFromHal(const sp<EffectHalInterface>& effect) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800853
Andy Hung6ac17eb2023-06-20 18:56:17 -0700854 bool disconnectEffectHandle(IAfEffectHandle *handle, bool unpinIfLast) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800855 void setVolumeForOutput(float left __unused, float right __unused) const override {}
856
Andy Hung6ac17eb2023-06-20 18:56:17 -0700857 void checkSuspendOnEffectEnabled(const sp<IAfEffectBase>& effect __unused,
Eric Laurentb82e6b72019-11-22 17:25:04 -0800858 bool enabled __unused, bool threadLocked __unused) override {}
Shunkai Yaod125e402024-01-20 03:19:06 +0000859 void resetVolume_l() override REQUIRES(audio_utils::EffectChain_Mutex) {}
Jaideep Sharmad4270b92024-07-10 14:56:42 +0530860 product_strategy_t strategy() const override { return PRODUCT_STRATEGY_NONE; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800861 int32_t activeTrackCnt() const override { return 0; }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700862 void onEffectEnable(const sp<IAfEffectBase>& effect __unused) override;
863 void onEffectDisable(const sp<IAfEffectBase>& effect __unused) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800864
Andy Hung6ac17eb2023-06-20 18:56:17 -0700865 wp<IAfEffectChain> chain() const override { return nullptr; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800866
Eric Laurentd66d7a12021-07-13 13:35:32 +0200867 bool isAudioPolicyReady() const override {
868 return mManagerCallback->isAudioPolicyReady();
869 }
870
Eric Laurentb82e6b72019-11-22 17:25:04 -0800871 int newEffectId();
872
873 private:
874 const wp<DeviceEffectProxy> mProxy;
Andy Hung55a74fd2023-07-13 19:54:47 -0700875 const sp<DeviceEffectManagerCallback> mManagerCallback;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800876 };
877
Andy Hung8e6b62a2023-07-13 18:11:33 -0700878 status_t checkPort(const IAfPatchPanel::Patch& patch,
Shunkai Yaod125e402024-01-20 03:19:06 +0000879 const struct audio_port_config* port, sp<IAfEffectHandle>* handle);
Eric Laurentb82e6b72019-11-22 17:25:04 -0800880
881 const AudioDeviceTypeAddr mDevice;
Andy Hung55a74fd2023-07-13 19:54:47 -0700882 const sp<DeviceEffectManagerCallback> mManagerCallback;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800883 const sp<ProxyCallback> mMyCallback;
884
Shunkai Yaod125e402024-01-20 03:19:06 +0000885 audio_utils::mutex& proxyMutex() const
886 RETURN_CAPABILITY(android::audio_utils::DeviceEffectProxy_ProxyMutex) {
887 return mProxyMutex;
888 }
Andy Hunga6f1cbb2023-10-12 18:18:13 -0700889 mutable audio_utils::mutex mProxyMutex{
890 audio_utils::MutexOrder::kDeviceEffectProxy_ProxyMutex};
Andy Hungf65f5a72023-08-29 12:19:17 -0700891 std::map<audio_patch_handle_t, sp<IAfEffectHandle>> mEffectHandles; // protected by mProxyMutex
892 sp<IAfEffectModule> mHalEffect; // protected by mProxyMutex
Eric Laurentb82e6b72019-11-22 17:25:04 -0800893 struct audio_port_config mDevicePort = { .id = AUDIO_PORT_HANDLE_NONE };
Eric Laurentde8caf42021-08-11 17:19:25 +0200894 const bool mNotifyFramesProcessed;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800895};
Andy Hung6ac17eb2023-06-20 18:56:17 -0700896
897} // namespace android