blob: 78788dfbe13e749f79bd7ac699d364afa977eb3f [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
Eric Laurent6b446ce2019-12-13 10:56:31 -080024// Interface implemented by the EffectModule parent or owner (e.g an EffectChain) to abstract
25// interactions between the EffectModule and the reset of the audio framework.
26class EffectCallbackInterface : public RefBase {
27public:
28 ~EffectCallbackInterface() override = default;
29
30 // Trivial methods usually implemented with help from ThreadBase
31 virtual audio_io_handle_t io() const = 0;
32 virtual bool isOutput() const = 0;
33 virtual bool isOffload() const = 0;
34 virtual bool isOffloadOrDirect() const = 0;
35 virtual bool isOffloadOrMmap() const = 0;
Eric Laurent0dccd2e2021-10-26 17:40:18 +020036 virtual bool isSpatializer() const = 0;
Eric Laurentb82e6b72019-11-22 17:25:04 -080037 virtual uint32_t sampleRate() const = 0;
Eric Laurentf1f22e72021-07-13 14:04:14 +020038 virtual audio_channel_mask_t inChannelMask(int id) const = 0;
39 virtual uint32_t inChannelCount(int id) const = 0;
40 virtual audio_channel_mask_t outChannelMask() const = 0;
41 virtual uint32_t outChannelCount() const = 0;
jiabineb3bda02020-06-30 14:07:03 -070042 virtual audio_channel_mask_t hapticChannelMask() const = 0;
Eric Laurent6b446ce2019-12-13 10:56:31 -080043 virtual size_t frameCount() const = 0;
44
45 // Non trivial methods usually implemented with help from ThreadBase:
46 // pay attention to mutex locking order
47 virtual uint32_t latency() const { return 0; }
48 virtual status_t addEffectToHal(sp<EffectHalInterface> effect) = 0;
49 virtual status_t removeEffectFromHal(sp<EffectHalInterface> effect) = 0;
50 virtual void setVolumeForOutput(float left, float right) const = 0;
51 virtual bool disconnectEffectHandle(EffectHandle *handle, bool unpinIfLast) = 0;
Eric Laurent41709552019-12-16 19:34:05 -080052 virtual void checkSuspendOnEffectEnabled(const sp<EffectBase>& effect,
Eric Laurent6b446ce2019-12-13 10:56:31 -080053 bool enabled,
54 bool threadLocked) = 0;
Eric Laurent41709552019-12-16 19:34:05 -080055 virtual void onEffectEnable(const sp<EffectBase>& effect) = 0;
56 virtual void onEffectDisable(const sp<EffectBase>& effect) = 0;
Eric Laurent6b446ce2019-12-13 10:56:31 -080057
58 // Methods usually implemented with help from AudioFlinger: pay attention to mutex locking order
59 virtual status_t createEffectHal(const effect_uuid_t *pEffectUuid,
60 int32_t sessionId, int32_t deviceId, sp<EffectHalInterface> *effect) = 0;
61 virtual status_t allocateHalBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) = 0;
Eric Laurent41709552019-12-16 19:34:05 -080062 virtual bool updateOrphanEffectChains(const sp<EffectBase>& effect) = 0;
Eric Laurent6b446ce2019-12-13 10:56:31 -080063
64 // Methods usually implemented with help from EffectChain: pay attention to mutex locking order
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080065 virtual product_strategy_t strategy() const = 0;
Eric Laurent6b446ce2019-12-13 10:56:31 -080066 virtual int32_t activeTrackCnt() const = 0;
67 virtual void resetVolume() = 0;
68
69 virtual wp<EffectChain> chain() const = 0;
Eric Laurentd66d7a12021-07-13 13:35:32 +020070
71 virtual bool isAudioPolicyReady() const = 0;
Eric Laurent6b446ce2019-12-13 10:56:31 -080072};
73
Eric Laurent41709552019-12-16 19:34:05 -080074// EffectBase(EffectModule) and EffectChain classes both have their own mutex to protect
Eric Laurent81784c32012-11-19 14:55:58 -080075// state changes or resource modifications. Always respect the following order
76// if multiple mutexes must be acquired to avoid cross deadlock:
Eric Laurent41709552019-12-16 19:34:05 -080077// AudioFlinger -> ThreadBase -> EffectChain -> EffectBase(EffectModule)
78// AudioHandle -> ThreadBase -> EffectChain -> EffectBase(EffectModule)
Eric Laurent6b446ce2019-12-13 10:56:31 -080079
80// NOTE: When implementing the EffectCallbackInterface, in an EffectChain or other, it is important
81// to pay attention to this locking order as some callback methods can be called from a state where
82// EffectModule and/or EffectChain mutexes are held.
83
Eric Laurenteb3c3372013-09-25 12:25:29 -070084// In addition, methods that lock the AudioPolicyService mutex (getOutputForEffect(),
Eric Laurent3bc859b2016-12-05 11:07:22 -080085// startOutput(), getInputForAttr(), releaseInput()...) should never be called with AudioFlinger or
86// Threadbase mutex locked to avoid cross deadlock with other clients calling AudioPolicyService
87// methods that in turn call AudioFlinger thus locking the same mutexes in the reverse order.
Eric Laurent81784c32012-11-19 14:55:58 -080088
Eric Laurent41709552019-12-16 19:34:05 -080089
90// The EffectBase class contains common properties, state and behavior for and EffectModule or
91// other derived classes managing an audio effect instance within the effect framework.
92// It also contains the class mutex (see comment on locking order above).
93class EffectBase : public RefBase {
Eric Laurent81784c32012-11-19 14:55:58 -080094public:
Eric Laurent41709552019-12-16 19:34:05 -080095 EffectBase(const sp<EffectCallbackInterface>& callback,
96 effect_descriptor_t *desc,
97 int id,
98 audio_session_t sessionId,
99 bool pinned);
100
101 ~EffectBase() override = default;
Eric Laurent81784c32012-11-19 14:55:58 -0800102
103 enum effect_state {
104 IDLE,
105 RESTART,
106 STARTING,
107 ACTIVE,
108 STOPPING,
109 STOPPED,
110 DESTROYED
111 };
112
Eric Laurent41709552019-12-16 19:34:05 -0800113 int id() const { return mId; }
Eric Laurent81784c32012-11-19 14:55:58 -0800114 effect_state state() const {
115 return mState;
116 }
Glenn Kastend848eb42016-03-08 13:42:11 -0800117 audio_session_t sessionId() const {
Eric Laurent81784c32012-11-19 14:55:58 -0800118 return mSessionId;
119 }
Eric Laurent81784c32012-11-19 14:55:58 -0800120 const effect_descriptor_t& desc() const { return mDescriptor; }
Eric Laurent5baf2af2013-09-12 17:37:00 -0700121 bool isOffloadable() const
122 { return (mDescriptor.flags & EFFECT_FLAG_OFFLOAD_SUPPORTED) != 0; }
Eric Laurent4c415062016-06-17 16:14:16 -0700123 bool isImplementationSoftware() const
124 { return (mDescriptor.flags & EFFECT_FLAG_HW_ACC_MASK) == 0; }
Eric Laurent6dd0fd92016-09-15 12:44:53 -0700125 bool isProcessImplemented() const
126 { return (mDescriptor.flags & EFFECT_FLAG_NO_PROCESS) == 0; }
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900127 bool isVolumeControl() const
128 { return (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK)
129 == EFFECT_FLAG_VOLUME_CTRL; }
Jasmine Cha934ecfb2019-01-23 18:19:14 +0800130 bool isVolumeMonitor() const
131 { return (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK)
132 == EFFECT_FLAG_VOLUME_MONITOR; }
Eric Laurent41709552019-12-16 19:34:05 -0800133
134 virtual status_t setEnabled(bool enabled, bool fromHandle);
135 status_t setEnabled_l(bool enabled);
136 bool isEnabled() const;
137
138 void setSuspended(bool suspended);
139 bool suspended() const;
140
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700141 virtual status_t command(int32_t __unused,
142 const std::vector<uint8_t>& __unused,
143 int32_t __unused,
144 std::vector<uint8_t>* __unused) { return NO_ERROR; };
Eric Laurent41709552019-12-16 19:34:05 -0800145
Andy Hungfda44002021-06-03 17:23:16 -0700146 // mCallback is atomic so this can be lock-free.
Eric Laurent41709552019-12-16 19:34:05 -0800147 void setCallback(const sp<EffectCallbackInterface>& callback) { mCallback = callback; }
Andy Hungfda44002021-06-03 17:23:16 -0700148 sp<EffectCallbackInterface> getCallback() const { return mCallback.load(); }
Eric Laurent41709552019-12-16 19:34:05 -0800149
150 status_t addHandle(EffectHandle *handle);
151 ssize_t disconnectHandle(EffectHandle *handle, bool unpinIfLast);
152 ssize_t removeHandle(EffectHandle *handle);
Jaideep Sharmaed8688022020-08-07 14:09:16 +0530153 ssize_t removeHandle_l(EffectHandle *handle);
Eric Laurent41709552019-12-16 19:34:05 -0800154 EffectHandle* controlHandle_l();
155 bool purgeHandles();
156
157 void checkSuspendOnEffectEnabled(bool enabled, bool threadLocked);
158
159 bool isPinned() const { return mPinned; }
160 void unPin() { mPinned = false; }
161
162 void lock() { mLock.lock(); }
163 void unlock() { mLock.unlock(); }
Eric Laurent81784c32012-11-19 14:55:58 -0800164
Eric Laurent6c796322019-04-09 14:13:17 -0700165 status_t updatePolicyState();
Eric Laurent41709552019-12-16 19:34:05 -0800166
167 virtual sp<EffectModule> asEffectModule() { return nullptr; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800168 virtual sp<DeviceEffectProxy> asDeviceEffectProxy() { return nullptr; }
Eric Laurent6c796322019-04-09 14:13:17 -0700169
Eric Laurent81784c32012-11-19 14:55:58 -0800170 void dump(int fd, const Vector<String16>& args);
171
Eric Laurentd66d7a12021-07-13 13:35:32 +0200172protected:
173 bool isInternal_l() const {
174 for (auto handle : mHandles) {
175 if (handle->client() != nullptr) {
176 return false;
177 }
178 }
179 return true;
180 }
181
Mikhail Naganovbf493082017-04-17 17:37:12 -0700182private:
Eric Laurent81784c32012-11-19 14:55:58 -0800183 friend class AudioFlinger; // for mHandles
Eric Laurent41709552019-12-16 19:34:05 -0800184 bool mPinned = false;
185
186 DISALLOW_COPY_AND_ASSIGN(EffectBase);
187
188mutable Mutex mLock; // mutex for process, commands and handles list protection
Andy Hungfda44002021-06-03 17:23:16 -0700189 mediautils::atomic_sp<EffectCallbackInterface> mCallback; // parent effect chain
Eric Laurent41709552019-12-16 19:34:05 -0800190 const int mId; // this instance unique ID
191 const audio_session_t mSessionId; // audio session ID
192 const effect_descriptor_t mDescriptor;// effect descriptor received from effect engine
193 effect_state mState = IDLE; // current activation state
Eric Laurentd9eb4962019-12-19 09:20:49 -0800194 // effect is suspended: temporarily disabled by framework
195 bool mSuspended = false;
Eric Laurent41709552019-12-16 19:34:05 -0800196
197 Vector<EffectHandle *> mHandles; // list of client handles
198 // First handle in mHandles has highest priority and controls the effect module
199
200 // Audio policy effect state management
201 // Mutex protecting transactions with audio policy manager as mLock cannot
202 // be held to avoid cross deadlocks with audio policy mutex
203 Mutex mPolicyLock;
204 // Effect is registered in APM or not
205 bool mPolicyRegistered = false;
206 // Effect enabled state communicated to APM. Enabled state corresponds to
207 // state requested by the EffectHandle with control
208 bool mPolicyEnabled = false;
209};
210
211// The EffectModule class is a wrapper object controlling the effect engine implementation
212// in the effect library. It prevents concurrent calls to process() and command() functions
213// from different client threads. It keeps a list of EffectHandle objects corresponding
214// to all client applications using this effect and notifies applications of effect state,
215// control or parameter changes. It manages the activation state machine to send appropriate
216// reset, enable, disable commands to effect engine and provide volume
217// ramping when effects are activated/deactivated.
218// When controlling an auxiliary effect, the EffectModule also provides an input buffer used by
219// the attached track(s) to accumulate their auxiliary channel.
220class EffectModule : public EffectBase {
221public:
222 EffectModule(const sp<EffectCallbackInterface>& callabck,
223 effect_descriptor_t *desc,
224 int id,
225 audio_session_t sessionId,
Eric Laurentb82e6b72019-11-22 17:25:04 -0800226 bool pinned,
227 audio_port_handle_t deviceId);
Eric Laurent41709552019-12-16 19:34:05 -0800228 virtual ~EffectModule();
229
230 void process();
231 bool updateState();
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700232 status_t command(int32_t cmdCode,
233 const std::vector<uint8_t>& cmdData,
234 int32_t maxReplySize,
235 std::vector<uint8_t>* reply) override;
Eric Laurent41709552019-12-16 19:34:05 -0800236
237 void reset_l();
238 status_t configure();
239 status_t init();
240
241 uint32_t status() {
242 return mStatus;
243 }
244
245 bool isProcessEnabled() const;
246 bool isOffloadedOrDirect() const;
247 bool isVolumeControlEnabled() const;
248
249 void setInBuffer(const sp<EffectBufferHalInterface>& buffer);
250 int16_t *inBuffer() const {
251 return mInBuffer != 0 ? reinterpret_cast<int16_t*>(mInBuffer->ptr()) : NULL;
252 }
253 void setOutBuffer(const sp<EffectBufferHalInterface>& buffer);
254 int16_t *outBuffer() const {
255 return mOutBuffer != 0 ? reinterpret_cast<int16_t*>(mOutBuffer->ptr()) : NULL;
256 }
257
Andy Hung799c8d02021-10-28 17:05:40 -0700258 // Updates the access mode if it is out of date. May issue a new effect configure.
259 void updateAccessMode() {
260 if (requiredEffectBufferAccessMode() != mConfig.outputCfg.accessMode) {
261 configure();
262 }
263 }
264
Eric Laurent41709552019-12-16 19:34:05 -0800265 status_t setDevices(const AudioDeviceTypeAddrVector &devices);
266 status_t setInputDevice(const AudioDeviceTypeAddr &device);
267 status_t setVolume(uint32_t *left, uint32_t *right, bool controller);
268 status_t setMode(audio_mode_t mode);
269 status_t setAudioSource(audio_source_t source);
270 status_t start();
271 status_t stop();
272
273 status_t setOffloaded(bool offloaded, audio_io_handle_t io);
274 bool isOffloaded() const;
275 void addEffectToHal_l();
276 void release_l();
277
278 sp<EffectModule> asEffectModule() override { return this; }
279
jiabineb3bda02020-06-30 14:07:03 -0700280 static bool isHapticGenerator(const effect_uuid_t* type);
281 bool isHapticGenerator() const;
282
jiabine70bc7f2020-06-30 22:07:55 -0700283 status_t setHapticIntensity(int id, int intensity);
Lais Andradebc3f37a2021-07-02 00:13:19 +0100284 status_t setVibratorInfo(const media::AudioVibratorInfo& vibratorInfo);
jiabine70bc7f2020-06-30 22:07:55 -0700285
Mikhail Naganov8d7da002022-04-19 21:21:23 +0000286 status_t getConfigs(audio_config_base_t* inputCfg,
287 audio_config_base_t* outputCfg,
288 bool* isOutput) const;
289
Eric Laurent41709552019-12-16 19:34:05 -0800290 void dump(int fd, const Vector<String16>& args);
291
292private:
293 friend class AudioFlinger; // for mHandles
Eric Laurent81784c32012-11-19 14:55:58 -0800294
295 // Maximum time allocated to effect engines to complete the turn off sequence
296 static const uint32_t MAX_DISABLE_TIME_MS = 10000;
297
Mikhail Naganovbf493082017-04-17 17:37:12 -0700298 DISALLOW_COPY_AND_ASSIGN(EffectModule);
Eric Laurent81784c32012-11-19 14:55:58 -0800299
300 status_t start_l();
301 status_t stop_l();
Eric Laurent6b446ce2019-12-13 10:56:31 -0800302 status_t removeEffectFromHal_l();
jiabin8f278ee2019-11-11 12:16:27 -0800303 status_t sendSetAudioDevicesCommand(const AudioDeviceTypeAddrVector &devices, uint32_t cmdCode);
Andy Hung799c8d02021-10-28 17:05:40 -0700304 effect_buffer_access_e requiredEffectBufferAccessMode() const {
305 return mConfig.inputCfg.buffer.raw == mConfig.outputCfg.buffer.raw
306 ? EFFECT_BUFFER_ACCESS_WRITE : EFFECT_BUFFER_ACCESS_ACCUMULATE;
307 }
308
jiabin4e246532022-08-23 16:37:30 -0700309 status_t setVolumeInternal(uint32_t *left, uint32_t *right, bool controller);
310
Eric Laurent81784c32012-11-19 14:55:58 -0800311
Eric Laurent81784c32012-11-19 14:55:58 -0800312 effect_config_t mConfig; // input and output audio configuration
Mikhail Naganov4a3d5c22016-08-15 13:47:42 -0700313 sp<EffectHalInterface> mEffectInterface; // Effect module HAL
Mikhail Naganov022b9952017-01-04 16:36:51 -0800314 sp<EffectBufferHalInterface> mInBuffer; // Buffers for interacting with HAL
315 sp<EffectBufferHalInterface> mOutBuffer;
Eric Laurent81784c32012-11-19 14:55:58 -0800316 status_t mStatus; // initialization status
Eric Laurent81784c32012-11-19 14:55:58 -0800317 // First handle in mHandles has highest priority and controls the effect module
318 uint32_t mMaxDisableWaitCnt; // maximum grace period before forcing an effect off after
319 // sending disable command.
320 uint32_t mDisableWaitCnt; // current process() calls count during disable period.
Eric Laurent5baf2af2013-09-12 17:37:00 -0700321 bool mOffloaded; // effect is currently offloaded to the audio DSP
David Li6c8ac4b2021-06-22 22:17:52 +0800322 bool mAddedToHal; // effect has been added to the audio HAL
Mikhail Naganov8d7da002022-04-19 21:21:23 +0000323 bool mIsOutput; // direction of the AF thread
rago94a1ee82017-07-21 15:11:02 -0700324
325#ifdef FLOAT_EFFECT_CHAIN
326 bool mSupportsFloat; // effect supports float processing
Andy Hungbded9c82017-11-30 18:47:35 -0800327 sp<EffectBufferHalInterface> mInConversionBuffer; // Buffers for HAL conversion if needed.
328 sp<EffectBufferHalInterface> mOutConversionBuffer;
Andy Hung9aad48c2017-11-29 10:29:19 -0800329 uint32_t mInChannelCountRequested;
330 uint32_t mOutChannelCountRequested;
rago94a1ee82017-07-21 15:11:02 -0700331#endif
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900332
333 class AutoLockReentrant {
334 public:
335 AutoLockReentrant(Mutex& mutex, pid_t allowedTid)
336 : mMutex(gettid() == allowedTid ? nullptr : &mutex)
337 {
338 if (mMutex != nullptr) mMutex->lock();
339 }
340 ~AutoLockReentrant() {
341 if (mMutex != nullptr) mMutex->unlock();
342 }
343 private:
344 Mutex * const mMutex;
345 };
346
347 static constexpr pid_t INVALID_PID = (pid_t)-1;
348 // this tid is allowed to call setVolume() without acquiring the mutex.
349 pid_t mSetVolumeReentrantTid = INVALID_PID;
Eric Laurent81784c32012-11-19 14:55:58 -0800350};
351
352// The EffectHandle class implements the IEffect interface. It provides resources
353// to receive parameter updates, keeps track of effect control
354// ownership and state and has a pointer to the EffectModule object it is controlling.
355// There is one EffectHandle object for each application controlling (or using)
356// an effect module.
357// The EffectHandle is obtained by calling AudioFlinger::createEffect().
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700358class EffectHandle: public android::media::BnEffect {
Eric Laurent81784c32012-11-19 14:55:58 -0800359public:
360
Eric Laurent41709552019-12-16 19:34:05 -0800361 EffectHandle(const sp<EffectBase>& effect,
Eric Laurent81784c32012-11-19 14:55:58 -0800362 const sp<AudioFlinger::Client>& client,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700363 const sp<media::IEffectClient>& effectClient,
Eric Laurentde8caf42021-08-11 17:19:25 +0200364 int32_t priority, bool notifyFramesProcessed);
Eric Laurent81784c32012-11-19 14:55:58 -0800365 virtual ~EffectHandle();
Andy Hungc747c532022-03-07 21:41:14 -0800366 status_t onTransact(
367 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) override;
Glenn Kastene75da402013-11-20 13:54:52 -0800368 virtual status_t initCheck();
Eric Laurent81784c32012-11-19 14:55:58 -0800369
370 // IEffect
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700371 android::binder::Status enable(int32_t* _aidl_return) override;
372 android::binder::Status disable(int32_t* _aidl_return) override;
373 android::binder::Status command(int32_t cmdCode,
374 const std::vector<uint8_t>& cmdData,
375 int32_t maxResponseSize,
376 std::vector<uint8_t>* response,
377 int32_t* _aidl_return) override;
378 android::binder::Status disconnect() override;
379 android::binder::Status getCblk(media::SharedFileRegion* _aidl_return) override;
Mikhail Naganov8d7da002022-04-19 21:21:23 +0000380 android::binder::Status getConfig(media::EffectConfig* _config,
381 int32_t* _aidl_return) override;
Eric Laurent81784c32012-11-19 14:55:58 -0800382
Eric Laurentd66d7a12021-07-13 13:35:32 +0200383 sp<Client> client() const { return mClient; }
384
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700385private:
386 void disconnect(bool unpinIfLast);
Eric Laurent81784c32012-11-19 14:55:58 -0800387
388 // Give or take control of effect module
389 // - hasControl: true if control is given, false if removed
390 // - signal: true client app should be signaled of change, false otherwise
391 // - enabled: state of the effect when control is passed
392 void setControl(bool hasControl, bool signal, bool enabled);
393 void commandExecuted(uint32_t cmdCode,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700394 const std::vector<uint8_t>& cmdData,
395 const std::vector<uint8_t>& replyData);
Eric Laurent81784c32012-11-19 14:55:58 -0800396 void setEnabled(bool enabled);
397 bool enabled() const { return mEnabled; }
398
Eric Laurentde8caf42021-08-11 17:19:25 +0200399 void framesProcessed(int32_t frames) const;
400
Eric Laurent81784c32012-11-19 14:55:58 -0800401 // Getters
Eric Laurent41709552019-12-16 19:34:05 -0800402 wp<EffectBase> effect() const { return mEffect; }
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800403 int id() const {
Eric Laurent41709552019-12-16 19:34:05 -0800404 sp<EffectBase> effect = mEffect.promote();
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800405 if (effect == 0) {
406 return 0;
407 }
408 return effect->id();
409 }
Eric Laurent81784c32012-11-19 14:55:58 -0800410 int priority() const { return mPriority; }
411 bool hasControl() const { return mHasControl; }
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800412 bool disconnected() const { return mDisconnected; }
Eric Laurent81784c32012-11-19 14:55:58 -0800413
Glenn Kasten01d3acb2014-02-06 08:24:07 -0800414 void dumpToBuffer(char* buffer, size_t size);
Eric Laurent81784c32012-11-19 14:55:58 -0800415
Mikhail Naganovbf493082017-04-17 17:37:12 -0700416private:
Eric Laurent81784c32012-11-19 14:55:58 -0800417 friend class AudioFlinger; // for mEffect, mHasControl, mEnabled
Mikhail Naganovbf493082017-04-17 17:37:12 -0700418 DISALLOW_COPY_AND_ASSIGN(EffectHandle);
Eric Laurent81784c32012-11-19 14:55:58 -0800419
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700420 Mutex mLock; // protects IEffect method calls
Andy Hung318e0242020-12-21 10:33:49 -0800421 const wp<EffectBase> mEffect; // pointer to controlled EffectModule
422 const sp<media::IEffectClient> mEffectClient; // callback interface for client notifications
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700423 /*const*/ sp<Client> mClient; // client for shared memory allocation, see
424 // disconnect()
425 sp<IMemory> mCblkMemory; // shared memory for control block
426 effect_param_cblk_t* mCblk; // control block for deferred parameter setting via
427 // shared memory
428 uint8_t* mBuffer; // pointer to parameter area in shared memory
429 int mPriority; // client application priority to control the effect
430 bool mHasControl; // true if this handle is controlling the effect
431 bool mEnabled; // cached enable state: needed when the effect is
432 // restored after being suspended
433 bool mDisconnected; // Set to true by disconnect()
Eric Laurentde8caf42021-08-11 17:19:25 +0200434 const bool mNotifyFramesProcessed; // true if the client callback event
435 // EVENT_FRAMES_PROCESSED must be generated
Eric Laurent81784c32012-11-19 14:55:58 -0800436};
437
438// the EffectChain class represents a group of effects associated to one audio session.
439// There can be any number of EffectChain objects per output mixer thread (PlaybackThread).
Glenn Kastend848eb42016-03-08 13:42:11 -0800440// The EffectChain with session ID AUDIO_SESSION_OUTPUT_MIX contains global effects applied
441// to the output mix.
Eric Laurent81784c32012-11-19 14:55:58 -0800442// Effects in this chain can be insert or auxiliary. Effects in other chains (attached to
443// tracks) are insert only. The EffectChain maintains an ordered list of effect module, the
Glenn Kastend848eb42016-03-08 13:42:11 -0800444// order corresponding in the effect process order. When attached to a track (session ID !=
445// AUDIO_SESSION_OUTPUT_MIX),
Eric Laurent81784c32012-11-19 14:55:58 -0800446// it also provide it's own input buffer used by the track as accumulation buffer.
447class EffectChain : public RefBase {
448public:
Glenn Kastend848eb42016-03-08 13:42:11 -0800449 EffectChain(const wp<ThreadBase>& wThread, audio_session_t sessionId);
Eric Laurent81784c32012-11-19 14:55:58 -0800450 virtual ~EffectChain();
451
452 // special key used for an entry in mSuspendedEffects keyed vector
453 // corresponding to a suspend all request.
454 static const int kKeyForSuspendAll = 0;
455
456 // minimum duration during which we force calling effect process when last track on
457 // a session is stopped or removed to allow effect tail to be rendered
458 static const int kProcessTailDurationMs = 1000;
459
460 void process_l();
461
462 void lock() {
463 mLock.lock();
464 }
465 void unlock() {
466 mLock.unlock();
467 }
468
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800469 status_t createEffect_l(sp<EffectModule>& effect,
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800470 effect_descriptor_t *desc,
471 int id,
472 audio_session_t sessionId,
473 bool pinned);
Eric Laurent81784c32012-11-19 14:55:58 -0800474 status_t addEffect_l(const sp<EffectModule>& handle);
Eric Laurent0d5a2ed2016-12-01 15:28:29 -0800475 status_t addEffect_ll(const sp<EffectModule>& handle);
476 size_t removeEffect_l(const sp<EffectModule>& handle, bool release = false);
Eric Laurent81784c32012-11-19 14:55:58 -0800477
Glenn Kastend848eb42016-03-08 13:42:11 -0800478 audio_session_t sessionId() const { return mSessionId; }
479 void setSessionId(audio_session_t sessionId) { mSessionId = sessionId; }
Eric Laurent81784c32012-11-19 14:55:58 -0800480
481 sp<EffectModule> getEffectFromDesc_l(effect_descriptor_t *descriptor);
482 sp<EffectModule> getEffectFromId_l(int id);
483 sp<EffectModule> getEffectFromType_l(const effect_uuid_t *type);
Eric Laurent6c796322019-04-09 14:13:17 -0700484 std::vector<int> getEffectIds();
Glenn Kastenc56f3422014-03-21 17:53:17 -0700485 // FIXME use float to improve the dynamic range
Eric Laurentfa1e1232016-08-02 19:01:49 -0700486 bool setVolume_l(uint32_t *left, uint32_t *right, bool force = false);
487 void resetVolume_l();
jiabin8f278ee2019-11-11 12:16:27 -0800488 void setDevices_l(const AudioDeviceTypeAddrVector &devices);
489 void setInputDevice_l(const AudioDeviceTypeAddr &device);
Eric Laurent81784c32012-11-19 14:55:58 -0800490 void setMode_l(audio_mode_t mode);
491 void setAudioSource_l(audio_source_t source);
492
Mikhail Naganov022b9952017-01-04 16:36:51 -0800493 void setInBuffer(const sp<EffectBufferHalInterface>& buffer) {
Eric Laurent81784c32012-11-19 14:55:58 -0800494 mInBuffer = buffer;
Eric Laurent81784c32012-11-19 14:55:58 -0800495 }
rago94a1ee82017-07-21 15:11:02 -0700496 effect_buffer_t *inBuffer() const {
497 return mInBuffer != 0 ? reinterpret_cast<effect_buffer_t*>(mInBuffer->ptr()) : NULL;
Eric Laurent81784c32012-11-19 14:55:58 -0800498 }
Mikhail Naganov022b9952017-01-04 16:36:51 -0800499 void setOutBuffer(const sp<EffectBufferHalInterface>& buffer) {
Eric Laurent81784c32012-11-19 14:55:58 -0800500 mOutBuffer = buffer;
501 }
rago94a1ee82017-07-21 15:11:02 -0700502 effect_buffer_t *outBuffer() const {
503 return mOutBuffer != 0 ? reinterpret_cast<effect_buffer_t*>(mOutBuffer->ptr()) : NULL;
Eric Laurent81784c32012-11-19 14:55:58 -0800504 }
505
506 void incTrackCnt() { android_atomic_inc(&mTrackCnt); }
507 void decTrackCnt() { android_atomic_dec(&mTrackCnt); }
508 int32_t trackCnt() const { return android_atomic_acquire_load(&mTrackCnt); }
509
510 void incActiveTrackCnt() { android_atomic_inc(&mActiveTrackCnt);
511 mTailBufferCount = mMaxTailBuffers; }
512 void decActiveTrackCnt() { android_atomic_dec(&mActiveTrackCnt); }
513 int32_t activeTrackCnt() const { return android_atomic_acquire_load(&mActiveTrackCnt); }
514
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800515 product_strategy_t strategy() const { return mStrategy; }
516 void setStrategy(product_strategy_t strategy)
Eric Laurent81784c32012-11-19 14:55:58 -0800517 { mStrategy = strategy; }
518
Eric Laurentd8365c52017-07-16 15:27:05 -0700519 // suspend or restore effects of the specified type. The number of suspend requests is counted
520 // and restore occurs once all suspend requests are cancelled.
Eric Laurent81784c32012-11-19 14:55:58 -0800521 void setEffectSuspended_l(const effect_uuid_t *type,
522 bool suspend);
523 // suspend all eligible effects
524 void setEffectSuspendedAll_l(bool suspend);
Eric Laurent6b446ce2019-12-13 10:56:31 -0800525 // check if effects should be suspended or restored when a given effect is enable or disabled
526 void checkSuspendOnEffectEnabled(const sp<EffectModule>& effect, bool enabled);
Eric Laurent81784c32012-11-19 14:55:58 -0800527
528 void clearInputBuffer();
529
Eric Laurent5baf2af2013-09-12 17:37:00 -0700530 // At least one non offloadable effect in the chain is enabled
531 bool isNonOffloadableEnabled();
Shingo Kitajima1f8df9a2018-05-29 11:35:06 +0900532 bool isNonOffloadableEnabled_l();
Eric Laurent813e2a72013-08-31 12:59:48 -0700533
Eric Laurent1b928682014-10-02 19:41:47 -0700534 void syncHalEffectsState();
535
Andy Hungd3bb0ad2016-10-11 17:16:43 -0700536 // flags is an ORed set of audio_output_flags_t which is updated on return.
537 void checkOutputFlagCompatibility(audio_output_flags_t *flags) const;
538
539 // flags is an ORed set of audio_input_flags_t which is updated on return.
540 void checkInputFlagCompatibility(audio_input_flags_t *flags) const;
541
542 // Is this EffectChain compatible with the RAW audio flag.
543 bool isRawCompatible() const;
544
545 // Is this EffectChain compatible with the FAST audio flag.
546 bool isFastCompatible() const;
Eric Laurent4c415062016-06-17 16:14:16 -0700547
548 // isCompatibleWithThread_l() must be called with thread->mLock held
549 bool isCompatibleWithThread_l(const sp<ThreadBase>& thread) const;
550
jiabineb3bda02020-06-30 14:07:03 -0700551 bool containsHapticGeneratingEffect_l();
552
jiabine70bc7f2020-06-30 22:07:55 -0700553 void setHapticIntensity_l(int id, int intensity);
554
Eric Laurent6b446ce2019-12-13 10:56:31 -0800555 sp<EffectCallbackInterface> effectCallback() const { return mEffectCallback; }
556 wp<ThreadBase> thread() const { return mEffectCallback->thread(); }
557
Eric Laurentf1f22e72021-07-13 14:04:14 +0200558 bool isFirstEffect(int id) const { return !mEffects.isEmpty() && id == mEffects[0]->id(); }
559
Eric Laurent81784c32012-11-19 14:55:58 -0800560 void dump(int fd, const Vector<String16>& args);
561
Mikhail Naganovbf493082017-04-17 17:37:12 -0700562private:
Eric Laurent6b446ce2019-12-13 10:56:31 -0800563
Andy Hung328d6772021-01-12 12:32:21 -0800564 // For transaction consistency, please consider holding the EffectChain lock before
565 // calling the EffectChain::EffectCallback methods, excepting
566 // createEffectHal and allocateHalBuffer.
567 //
568 // This prevents migration of the EffectChain to another PlaybackThread
569 // for the purposes of the EffectCallback.
Eric Laurent6b446ce2019-12-13 10:56:31 -0800570 class EffectCallback : public EffectCallbackInterface {
571 public:
Ytai Ben-Tsvi4f043362020-01-28 12:39:23 -0800572 // Note: ctors taking a weak pointer to their owner must not promote it
573 // during construction (but may keep a reference for later promotion).
574 EffectCallback(const wp<EffectChain>& owner,
Ytai Ben-Tsvi3de1bbf2020-01-21 16:41:17 -0800575 const wp<ThreadBase>& thread)
Andy Hung6626a012021-01-12 13:38:00 -0800576 : mChain(owner)
577 , mThread(thread)
578 , mAudioFlinger(*gAudioFlinger) {
Greg Kaiseree71ebd2021-11-09 07:37:38 -0800579 sp<ThreadBase> base = thread.promote();
580 if (base != nullptr) {
581 mThreadType = base->type();
582 } else {
583 mThreadType = ThreadBase::MIXER; // assure a consistent value.
584 }
Ytai Ben-Tsvi3de1bbf2020-01-21 16:41:17 -0800585 }
Eric Laurent6b446ce2019-12-13 10:56:31 -0800586
587 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
588 int32_t sessionId, int32_t deviceId, sp<EffectHalInterface> *effect) override;
589 status_t allocateHalBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) override;
Eric Laurent41709552019-12-16 19:34:05 -0800590 bool updateOrphanEffectChains(const sp<EffectBase>& effect) override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800591
592 audio_io_handle_t io() const override;
593 bool isOutput() const override;
594 bool isOffload() const override;
595 bool isOffloadOrDirect() const override;
596 bool isOffloadOrMmap() const override;
Eric Laurent0dccd2e2021-10-26 17:40:18 +0200597 bool isSpatializer() const override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800598
599 uint32_t sampleRate() const override;
Eric Laurentf1f22e72021-07-13 14:04:14 +0200600 audio_channel_mask_t inChannelMask(int id) const override;
601 uint32_t inChannelCount(int id) const override;
602 audio_channel_mask_t outChannelMask() const override;
603 uint32_t outChannelCount() const override;
jiabineb3bda02020-06-30 14:07:03 -0700604 audio_channel_mask_t hapticChannelMask() const override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800605 size_t frameCount() const override;
606 uint32_t latency() const override;
607
608 status_t addEffectToHal(sp<EffectHalInterface> effect) override;
609 status_t removeEffectFromHal(sp<EffectHalInterface> effect) override;
610 bool disconnectEffectHandle(EffectHandle *handle, bool unpinIfLast) override;
611 void setVolumeForOutput(float left, float right) const override;
612
613 // check if effects should be suspended/restored when a given effect is enable/disabled
Eric Laurent41709552019-12-16 19:34:05 -0800614 void checkSuspendOnEffectEnabled(const sp<EffectBase>& effect,
Eric Laurent6b446ce2019-12-13 10:56:31 -0800615 bool enabled, bool threadLocked) override;
616 void resetVolume() override;
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800617 product_strategy_t strategy() const override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800618 int32_t activeTrackCnt() const override;
Eric Laurent41709552019-12-16 19:34:05 -0800619 void onEffectEnable(const sp<EffectBase>& effect) override;
620 void onEffectDisable(const sp<EffectBase>& effect) override;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800621
622 wp<EffectChain> chain() const override { return mChain; }
623
Eric Laurentd66d7a12021-07-13 13:35:32 +0200624 bool isAudioPolicyReady() const override {
625 return mAudioFlinger.isAudioPolicyReady();
626 }
627
Andy Hung328d6772021-01-12 12:32:21 -0800628 wp<ThreadBase> thread() const { return mThread.load(); }
Ytai Ben-Tsvi3de1bbf2020-01-21 16:41:17 -0800629
Eric Laurent0dccd2e2021-10-26 17:40:18 +0200630 void setThread(const sp<ThreadBase>& thread) {
Ytai Ben-Tsvi3de1bbf2020-01-21 16:41:17 -0800631 mThread = thread;
Eric Laurent0dccd2e2021-10-26 17:40:18 +0200632 mThreadType = thread->type();
Ytai Ben-Tsvi3de1bbf2020-01-21 16:41:17 -0800633 }
Eric Laurent6b446ce2019-12-13 10:56:31 -0800634
635 private:
Andy Hung318e0242020-12-21 10:33:49 -0800636 const wp<EffectChain> mChain;
Andy Hung328d6772021-01-12 12:32:21 -0800637 mediautils::atomic_wp<ThreadBase> mThread;
Andy Hung6626a012021-01-12 13:38:00 -0800638 AudioFlinger &mAudioFlinger; // implementation detail: outer instance always exists.
Eric Laurent0dccd2e2021-10-26 17:40:18 +0200639 ThreadBase::type_t mThreadType;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800640 };
641
Eric Laurent81784c32012-11-19 14:55:58 -0800642 friend class AudioFlinger; // for mThread, mEffects
Mikhail Naganovbf493082017-04-17 17:37:12 -0700643 DISALLOW_COPY_AND_ASSIGN(EffectChain);
Eric Laurent81784c32012-11-19 14:55:58 -0800644
645 class SuspendedEffectDesc : public RefBase {
646 public:
647 SuspendedEffectDesc() : mRefCount(0) {}
648
Eric Laurentd8365c52017-07-16 15:27:05 -0700649 int mRefCount; // > 0 when suspended
Eric Laurent81784c32012-11-19 14:55:58 -0800650 effect_uuid_t mType;
651 wp<EffectModule> mEffect;
652 };
653
654 // get a list of effect modules to suspend when an effect of the type
655 // passed is enabled.
656 void getSuspendEligibleEffects(Vector< sp<EffectModule> > &effects);
657
658 // get an effect module if it is currently enable
659 sp<EffectModule> getEffectIfEnabled(const effect_uuid_t *type);
660 // true if the effect whose descriptor is passed can be suspended
661 // OEMs can modify the rules implemented in this method to exclude specific effect
662 // types or implementations from the suspend/restore mechanism.
663 bool isEffectEligibleForSuspend(const effect_descriptor_t& desc);
664
Eric Laurentd8365c52017-07-16 15:27:05 -0700665 static bool isEffectEligibleForBtNrecSuspend(const effect_uuid_t *type);
666
Eric Laurent6b446ce2019-12-13 10:56:31 -0800667 void clearInputBuffer_l();
Eric Laurent81784c32012-11-19 14:55:58 -0800668
Eric Laurentaaa44472014-09-12 17:41:50 -0700669 void setThread(const sp<ThreadBase>& thread);
670
Zhou Songd505c642020-02-20 16:35:37 +0800671 // true if any effect module within the chain has volume control
672 bool hasVolumeControlEnabled_l() const;
673
Tomoharu Kasahara1990bd42014-12-12 14:04:11 +0900674 void setVolumeForOutput_l(uint32_t left, uint32_t right);
675
Eric Laurent0dccd2e2021-10-26 17:40:18 +0200676 ssize_t getInsertIndex(const effect_descriptor_t& desc);
677
Eric Laurent4c415062016-06-17 16:14:16 -0700678 mutable Mutex mLock; // mutex protecting effect list
679 Vector< sp<EffectModule> > mEffects; // list of effect modules
680 audio_session_t mSessionId; // audio session ID
Mikhail Naganov022b9952017-01-04 16:36:51 -0800681 sp<EffectBufferHalInterface> mInBuffer; // chain input buffer
682 sp<EffectBufferHalInterface> mOutBuffer; // chain output buffer
Eric Laurent81784c32012-11-19 14:55:58 -0800683
684 // 'volatile' here means these are accessed with atomic operations instead of mutex
685 volatile int32_t mActiveTrackCnt; // number of active tracks connected
686 volatile int32_t mTrackCnt; // number of tracks connected
687
Eric Laurent4c415062016-06-17 16:14:16 -0700688 int32_t mTailBufferCount; // current effect tail buffer count
689 int32_t mMaxTailBuffers; // maximum effect tail buffers
Eric Laurent4c415062016-06-17 16:14:16 -0700690 int mVolumeCtrlIdx; // index of insert effect having control over volume
691 uint32_t mLeftVolume; // previous volume on left channel
692 uint32_t mRightVolume; // previous volume on right channel
693 uint32_t mNewLeftVolume; // new volume on left channel
694 uint32_t mNewRightVolume; // new volume on right channel
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800695 product_strategy_t mStrategy; // strategy for this effect chain
Eric Laurent4c415062016-06-17 16:14:16 -0700696 // mSuspendedEffects lists all effects currently suspended in the chain.
697 // Use effect type UUID timelow field as key. There is no real risk of identical
698 // timeLow fields among effect type UUIDs.
Eric Laurentd8365c52017-07-16 15:27:05 -0700699 // Updated by setEffectSuspended_l() and setEffectSuspendedAll_l() only.
Eric Laurent4c415062016-06-17 16:14:16 -0700700 KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects;
Eric Laurent6b446ce2019-12-13 10:56:31 -0800701
702 const sp<EffectCallback> mEffectCallback;
Eric Laurent81784c32012-11-19 14:55:58 -0800703};
Eric Laurentb82e6b72019-11-22 17:25:04 -0800704
705class DeviceEffectProxy : public EffectBase {
706public:
707 DeviceEffectProxy (const AudioDeviceTypeAddr& device,
708 const sp<DeviceEffectManagerCallback>& callback,
Eric Laurentde8caf42021-08-11 17:19:25 +0200709 effect_descriptor_t *desc, int id, bool notifyFramesProcessed)
Eric Laurentb82e6b72019-11-22 17:25:04 -0800710 : EffectBase(callback, desc, id, AUDIO_SESSION_DEVICE, false),
711 mDevice(device), mManagerCallback(callback),
Eric Laurentde8caf42021-08-11 17:19:25 +0200712 mMyCallback(new ProxyCallback(wp<DeviceEffectProxy>(this), callback)),
713 mNotifyFramesProcessed(notifyFramesProcessed) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -0800714
715 status_t setEnabled(bool enabled, bool fromHandle) override;
716 sp<DeviceEffectProxy> asDeviceEffectProxy() override { return this; }
717
718 status_t init(const std::map<audio_patch_handle_t, PatchPanel::Patch>& patches);
719 status_t onCreatePatch(audio_patch_handle_t patchHandle, const PatchPanel::Patch& patch);
720 void onReleasePatch(audio_patch_handle_t patchHandle);
721
722 size_t removeEffect(const sp<EffectModule>& effect);
723
724 status_t addEffectToHal(sp<EffectHalInterface> effect);
725 status_t removeEffectFromHal(sp<EffectHalInterface> effect);
726
727 const AudioDeviceTypeAddr& device() { return mDevice; };
728 bool isOutput() const;
729 uint32_t sampleRate() const;
730 audio_channel_mask_t channelMask() const;
731 uint32_t channelCount() const;
732
733 void dump(int fd, int spaces);
734
735private:
736
737 class ProxyCallback : public EffectCallbackInterface {
738 public:
Ytai Ben-Tsvi4f043362020-01-28 12:39:23 -0800739 // Note: ctors taking a weak pointer to their owner must not promote it
740 // during construction (but may keep a reference for later promotion).
741 ProxyCallback(const wp<DeviceEffectProxy>& owner,
742 const sp<DeviceEffectManagerCallback>& callback)
743 : mProxy(owner), mManagerCallback(callback) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -0800744
745 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
746 int32_t sessionId, int32_t deviceId, sp<EffectHalInterface> *effect) override;
747 status_t allocateHalBuffer(size_t size __unused,
748 sp<EffectBufferHalInterface>* buffer __unused) override { return NO_ERROR; }
749 bool updateOrphanEffectChains(const sp<EffectBase>& effect __unused) override {
750 return false;
751 }
752
753 audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; }
754 bool isOutput() const override;
755 bool isOffload() const override { return false; }
756 bool isOffloadOrDirect() const override { return false; }
757 bool isOffloadOrMmap() const override { return false; }
Eric Laurent0dccd2e2021-10-26 17:40:18 +0200758 bool isSpatializer() const override { return false; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800759
760 uint32_t sampleRate() const override;
Eric Laurentf1f22e72021-07-13 14:04:14 +0200761 audio_channel_mask_t inChannelMask(int id) const override;
762 uint32_t inChannelCount(int id) const override;
763 audio_channel_mask_t outChannelMask() const override;
764 uint32_t outChannelCount() const override;
jiabineb3bda02020-06-30 14:07:03 -0700765 audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800766 size_t frameCount() const override { return 0; }
767 uint32_t latency() const override { return 0; }
768
769 status_t addEffectToHal(sp<EffectHalInterface> effect) override;
770 status_t removeEffectFromHal(sp<EffectHalInterface> effect) override;
771
772 bool disconnectEffectHandle(EffectHandle *handle, bool unpinIfLast) override;
773 void setVolumeForOutput(float left __unused, float right __unused) const override {}
774
775 void checkSuspendOnEffectEnabled(const sp<EffectBase>& effect __unused,
776 bool enabled __unused, bool threadLocked __unused) override {}
777 void resetVolume() override {}
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800778 product_strategy_t strategy() const override { return static_cast<product_strategy_t>(0); }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800779 int32_t activeTrackCnt() const override { return 0; }
Eric Laurent76c89f32021-12-03 17:13:23 +0100780 void onEffectEnable(const sp<EffectBase>& effect __unused) override;
781 void onEffectDisable(const sp<EffectBase>& effect __unused) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800782
783 wp<EffectChain> chain() const override { return nullptr; }
784
Eric Laurentd66d7a12021-07-13 13:35:32 +0200785 bool isAudioPolicyReady() const override {
786 return mManagerCallback->isAudioPolicyReady();
787 }
788
Eric Laurentb82e6b72019-11-22 17:25:04 -0800789 int newEffectId();
790
791 private:
792 const wp<DeviceEffectProxy> mProxy;
793 const sp<DeviceEffectManagerCallback> mManagerCallback;
794 };
795
796 status_t checkPort(const PatchPanel::Patch& patch, const struct audio_port_config *port,
797 sp<EffectHandle> *handle);
798
799 const AudioDeviceTypeAddr mDevice;
800 const sp<DeviceEffectManagerCallback> mManagerCallback;
801 const sp<ProxyCallback> mMyCallback;
802
803 Mutex mProxyLock;
804 std::map<audio_patch_handle_t, sp<EffectHandle>> mEffectHandles; // protected by mProxyLock
805 sp<EffectModule> mHalEffect; // protected by mProxyLock
806 struct audio_port_config mDevicePort = { .id = AUDIO_PORT_HANDLE_NONE };
Eric Laurentde8caf42021-08-11 17:19:25 +0200807 const bool mNotifyFramesProcessed;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800808};