blob: 7ed9e19e8f75a23bef065e98613b7b432211995f [file] [log] [blame]
Andy Hung6ac17eb2023-06-20 18:56:17 -07001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
Andy Hung0a51b5c2023-07-18 20:54:44 -070019#include "IAfPatchPanel.h" // full class Patch definition needed
20
21#include <android/media/AudioVibratorInfo.h>
22#include <android/media/BnEffect.h>
23#include <android/media/BnEffectClient.h>
Andy Hungf65f5a72023-08-29 12:19:17 -070024#include <audio_utils/mutex.h>
Andy Hung0a51b5c2023-07-18 20:54:44 -070025#include <media/AudioCommonTypes.h> // product_strategy_t
26#include <media/AudioDeviceTypeAddr.h>
27#include <media/audiohal/EffectHalInterface.h>
28#include <utils/RefBase.h>
29#include <vibrator/ExternalVibration.h>
30
Andy Hung6ac17eb2023-06-20 18:56:17 -070031namespace android {
32
Andy Hung0a51b5c2023-07-18 20:54:44 -070033class Client;
Andy Hung55a74fd2023-07-13 19:54:47 -070034class DeviceEffectManagerCallback;
Andy Hung0a51b5c2023-07-18 20:54:44 -070035
Andy Hung6ac17eb2023-06-20 18:56:17 -070036class IAfDeviceEffectProxy;
37class IAfEffectBase;
38class IAfEffectChain;
39class IAfEffectHandle;
40class IAfEffectModule;
Andy Hung87c693c2023-07-06 20:56:16 -070041class IAfThreadBase;
Andy Hung6ac17eb2023-06-20 18:56:17 -070042
43// Interface implemented by the EffectModule parent or owner (e.g an EffectChain) to abstract
44// interactions between the EffectModule and the reset of the audio framework.
45class EffectCallbackInterface : public RefBase {
46public:
47 // Trivial methods usually implemented with help from ThreadBase
48 virtual audio_io_handle_t io() const = 0;
François Gaffie2e10aa82024-03-13 17:08:52 +010049 virtual bool shouldDispatchAddRemoveToHal(bool isAdded) const = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -070050 virtual bool isOutput() const = 0;
51 virtual bool isOffload() const = 0;
52 virtual bool isOffloadOrDirect() const = 0;
53 virtual bool isOffloadOrMmap() const = 0;
54 virtual bool isSpatializer() const = 0;
55 virtual uint32_t sampleRate() const = 0;
56 virtual audio_channel_mask_t inChannelMask(int id) const = 0;
57 virtual uint32_t inChannelCount(int id) const = 0;
58 virtual audio_channel_mask_t outChannelMask() const = 0;
59 virtual uint32_t outChannelCount() const = 0;
60 virtual audio_channel_mask_t hapticChannelMask() const = 0;
61 virtual size_t frameCount() const = 0;
62
63 // Non trivial methods usually implemented with help from ThreadBase:
64 // pay attention to mutex locking order
65 virtual uint32_t latency() const { return 0; }
66 virtual status_t addEffectToHal(const sp<EffectHalInterface>& effect) = 0;
67 virtual status_t removeEffectFromHal(const sp<EffectHalInterface>& effect) = 0;
68 virtual void setVolumeForOutput(float left, float right) const = 0;
69 virtual bool disconnectEffectHandle(IAfEffectHandle *handle, bool unpinIfLast) = 0;
70 virtual void checkSuspendOnEffectEnabled(
71 const sp<IAfEffectBase>& effect, bool enabled, bool threadLocked) = 0;
72 virtual void onEffectEnable(const sp<IAfEffectBase>& effect) = 0;
73 virtual void onEffectDisable(const sp<IAfEffectBase>& effect) = 0;
74
75 // Methods usually implemented with help from AudioFlinger: pay attention to mutex locking order
76 virtual status_t createEffectHal(const effect_uuid_t *pEffectUuid,
77 int32_t sessionId, int32_t deviceId, sp<EffectHalInterface> *effect) = 0;
78 virtual status_t allocateHalBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) = 0;
79 virtual bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect) = 0;
80
81 // Methods usually implemented with help from EffectChain: pay attention to mutex locking order
82 virtual product_strategy_t strategy() const = 0;
83 virtual int32_t activeTrackCnt() const = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +000084 virtual void resetVolume_l() REQUIRES(audio_utils::EffectChain_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -070085 virtual wp<IAfEffectChain> chain() const = 0;
86 virtual bool isAudioPolicyReady() const = 0;
87};
88
89class IAfEffectBase : public virtual RefBase {
90 friend class EffectChain;
91 friend class EffectHandle;
92
93public:
94 enum effect_state {
95 IDLE,
96 RESTART,
97 STARTING,
98 ACTIVE,
99 STOPPING,
100 STOPPED,
101 DESTROYED
102 };
103 virtual int id() const = 0;
104 virtual effect_state state() const = 0;
105 virtual audio_session_t sessionId() const = 0;
106 virtual const effect_descriptor_t& desc() const = 0;
107 virtual bool isOffloadable() const = 0;
108 virtual bool isImplementationSoftware() const = 0;
109 virtual bool isProcessImplemented() const = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000110 virtual bool isVolumeControl() const REQUIRES(audio_utils::EffectChain_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700111 virtual bool isVolumeMonitor() const = 0;
112 virtual bool isEnabled() const = 0;
113 virtual bool isPinned() const = 0;
114 virtual void unPin() = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000115 virtual status_t updatePolicyState() EXCLUDES_EffectBase_Mutex = 0;
116 virtual bool purgeHandles() EXCLUDES_EffectBase_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700117 virtual void checkSuspendOnEffectEnabled(bool enabled, bool threadLocked) = 0;
118
119 // mCallback is atomic so this can be lock-free.
120 virtual void setCallback(const sp<EffectCallbackInterface>& callback) = 0;
121 virtual sp<EffectCallbackInterface> getCallback() const = 0;
122
Shunkai Yaod125e402024-01-20 03:19:06 +0000123 virtual status_t addHandle(IAfEffectHandle* handle) EXCLUDES_EffectBase_Mutex = 0;
124 virtual ssize_t removeHandle(IAfEffectHandle* handle) EXCLUDES_EffectBase_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700125
126 virtual sp<IAfEffectModule> asEffectModule() = 0;
127 virtual sp<IAfDeviceEffectProxy> asDeviceEffectProxy() = 0;
128
Shunkai Yaod125e402024-01-20 03:19:06 +0000129 virtual status_t command(int32_t cmdCode, const std::vector<uint8_t>& cmdData,
130 int32_t maxReplySize, std::vector<uint8_t>* reply)
131 EXCLUDES(audio_utils::EffectBase_Mutex) = 0;
François Gaffiea2e985b2023-06-09 14:37:56 +0200132
Andy Hung6ac17eb2023-06-20 18:56:17 -0700133 virtual void dump(int fd, const Vector<String16>& args) const = 0;
134
135private:
Shunkai Yaod125e402024-01-20 03:19:06 +0000136 virtual status_t setEnabled(bool enabled, bool fromHandle) EXCLUDES_EffectBase_Mutex = 0;
137 virtual status_t setEnabled_l(bool enabled) REQUIRES(audio_utils::EffectBase_Mutex) = 0;
138 virtual void setSuspended(bool suspended) EXCLUDES_EffectBase_Mutex = 0;
139 virtual bool suspended() const EXCLUDES_EffectBase_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700140
Shunkai Yaod125e402024-01-20 03:19:06 +0000141 virtual ssize_t disconnectHandle(IAfEffectHandle* handle,
142 bool unpinIfLast) EXCLUDES_EffectBase_Mutex = 0;
143 virtual ssize_t removeHandle_l(IAfEffectHandle* handle)
144 REQUIRES(audio_utils::EffectBase_Mutex) = 0;
145 virtual IAfEffectHandle* controlHandle_l() REQUIRES(audio_utils::EffectBase_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700146
Shunkai Yaod125e402024-01-20 03:19:06 +0000147 virtual audio_utils::mutex& mutex() const
148 RETURN_CAPABILITY(android::audio_utils::EffectBase_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700149};
150
151class IAfEffectModule : public virtual IAfEffectBase {
152 friend class DeviceEffectProxy;
153 friend class EffectChain;
154
155public:
156 static sp<IAfEffectModule> create(
157 const sp<EffectCallbackInterface>& callabck,
158 effect_descriptor_t *desc,
159 int id,
160 audio_session_t sessionId,
161 bool pinned,
162 audio_port_handle_t deviceId);
163
164 virtual int16_t *inBuffer() const = 0;
165 virtual status_t setDevices(const AudioDeviceTypeAddrVector &devices) = 0;
166 virtual status_t setInputDevice(const AudioDeviceTypeAddr &device) = 0;
Shunkai Yao44778ce2024-06-08 00:54:32 +0000167 virtual status_t setVolume_l(uint32_t* left, uint32_t* right,
168 bool controller /* effect controlling chain volume */,
169 bool force = false) REQUIRES(audio_utils::EffectChain_Mutex) = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000170 virtual status_t setOffloaded_l(bool offloaded, audio_io_handle_t io) = 0;
171 virtual bool isOffloaded_l() const = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700172
173 virtual status_t setAudioSource(audio_source_t source) = 0;
174 virtual status_t setMode(audio_mode_t mode) = 0;
175
Shunkai Yaod125e402024-01-20 03:19:06 +0000176 virtual status_t start_l() = 0;
177 virtual status_t getConfigs_l(audio_config_base_t* inputCfg, audio_config_base_t* outputCfg,
178 bool* isOutput) const
179 REQUIRES(audio_utils::EffectHandle_Mutex) EXCLUDES_EffectBase_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700180
181 static bool isHapticGenerator(const effect_uuid_t* type);
182 virtual bool isHapticGenerator() const = 0;
Eric Laurent4eb45d02023-12-20 12:07:17 +0100183 static bool isSpatializer(const effect_uuid_t* type);
184 virtual bool isSpatializer() const = 0;
185
Ahmad Khalil229466a2024-02-05 12:15:30 +0000186 virtual status_t setHapticScale_l(int id, os::HapticScale hapticScale)
Shunkai Yao29d10572024-03-19 04:31:47 +0000187 REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000188 virtual status_t setVibratorInfo_l(const media::AudioVibratorInfo& vibratorInfo)
Shunkai Yao29d10572024-03-19 04:31:47 +0000189 REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000190 virtual status_t sendMetadata_ll(const std::vector<playback_track_metadata_v7_t>& metadata)
191 REQUIRES(audio_utils::ThreadBase_Mutex,
192 audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex = 0;
Shunkai Yaof62fbce2024-06-26 21:53:51 +0000193 // return true if there was a state change from STARTING to ACTIVE, or STOPPED to IDLE, effect
194 // chain will do a volume reset in these two cases
195 virtual bool updateState_l()
196 REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700197
198private:
199 virtual void process() = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000200 virtual void reset_l() REQUIRES(audio_utils::EffectChain_Mutex) = 0;
201 virtual status_t configure_l() REQUIRES(audio_utils::EffectChain_Mutex) = 0;
202 virtual status_t init_l()
203 REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700204 virtual uint32_t status() const = 0;
205 virtual bool isProcessEnabled() const = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000206 virtual bool isOffloadedOrDirect_l() const REQUIRES(audio_utils::EffectChain_Mutex) = 0;
207 virtual bool isVolumeControlEnabled_l() const REQUIRES(audio_utils::EffectChain_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700208
209 virtual void setInBuffer(const sp<EffectBufferHalInterface>& buffer) = 0;
210 virtual void setOutBuffer(const sp<EffectBufferHalInterface>& buffer) = 0;
211 virtual int16_t *outBuffer() const = 0;
212
213 // Updates the access mode if it is out of date. May issue a new effect configure.
Shunkai Yaod125e402024-01-20 03:19:06 +0000214 virtual void updateAccessMode_l() = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700215
Shunkai Yaod125e402024-01-20 03:19:06 +0000216 virtual status_t stop_l() = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700217 virtual void addEffectToHal_l() = 0;
Shunkai Yao4fa10092024-04-04 17:30:48 +0000218 virtual void release_l(const std::string& from) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700219};
220
221class IAfEffectChain : public RefBase {
222 // Most of these methods are accessed from AudioFlinger::Thread
223public:
224 static sp<IAfEffectChain> create(
Andy Hung583043b2023-07-17 17:05:00 -0700225 const sp<IAfThreadBase>& thread,
Shunkai Yao29d10572024-03-19 04:31:47 +0000226 audio_session_t sessionId,
227 const sp<IAfThreadCallback>& afThreadCallback);
Andy Hung6ac17eb2023-06-20 18:56:17 -0700228
229 // special key used for an entry in mSuspendedEffects keyed vector
230 // corresponding to a suspend all request.
231 static constexpr int kKeyForSuspendAll = 0;
232
233 // minimum duration during which we force calling effect process when last track on
234 // a session is stopped or removed to allow effect tail to be rendered
235 static constexpr int kProcessTailDurationMs = 1000;
236
Shunkai Yaod125e402024-01-20 03:19:06 +0000237 virtual void process_l() REQUIRES(audio_utils::EffectChain_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700238
Shunkai Yaod125e402024-01-20 03:19:06 +0000239 virtual audio_utils::mutex& mutex() const RETURN_CAPABILITY(audio_utils::EffectChain_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700240
Shunkai Yao29d10572024-03-19 04:31:47 +0000241 virtual status_t createEffect(sp<IAfEffectModule>& effect, effect_descriptor_t* desc, int id,
Shunkai Yaod125e402024-01-20 03:19:06 +0000242 audio_session_t sessionId, bool pinned)
Shunkai Yao29d10572024-03-19 04:31:47 +0000243 EXCLUDES_EffectChain_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700244
Shunkai Yao29d10572024-03-19 04:31:47 +0000245 virtual status_t addEffect(const sp<IAfEffectModule>& handle)
246 EXCLUDES_EffectChain_Mutex = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000247 virtual status_t addEffect_l(const sp<IAfEffectModule>& handle)
Shunkai Yao29d10572024-03-19 04:31:47 +0000248 REQUIRES(audio_utils::EffectChain_Mutex) = 0;
249 virtual size_t removeEffect(const sp<IAfEffectModule>& handle,
Shunkai Yaod125e402024-01-20 03:19:06 +0000250 bool release = false) EXCLUDES_EffectChain_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700251
252 virtual audio_session_t sessionId() const = 0;
253 virtual void setSessionId(audio_session_t sessionId) = 0;
254
Shunkai Yao29d10572024-03-19 04:31:47 +0000255 virtual sp<IAfEffectModule> getEffectFromDesc(effect_descriptor_t* descriptor) const
256 EXCLUDES_EffectChain_Mutex = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000257 virtual sp<IAfEffectModule> getEffectFromId_l(int id) const
Shunkai Yao29d10572024-03-19 04:31:47 +0000258 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000259 virtual sp<IAfEffectModule> getEffectFromType_l(const effect_uuid_t* type) const
Shunkai Yao29d10572024-03-19 04:31:47 +0000260 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000261 virtual std::vector<int> getEffectIds_l() const = 0;
Shunkai Yaof4847652024-01-12 00:25:20 +0000262 virtual bool setVolume(uint32_t* left, uint32_t* right,
263 bool force = false) EXCLUDES_EffectChain_Mutex = 0;
264 virtual void resetVolume_l() REQUIRES(audio_utils::EffectChain_Mutex) = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000265 virtual void setDevices_l(const AudioDeviceTypeAddrVector& devices)
Shunkai Yao29d10572024-03-19 04:31:47 +0000266 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000267 virtual void setInputDevice_l(const AudioDeviceTypeAddr& device)
Shunkai Yao29d10572024-03-19 04:31:47 +0000268 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex = 0;
269 virtual void setMode_l(audio_mode_t mode)
270 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000271 virtual void setAudioSource_l(audio_source_t source)
272 REQUIRES(audio_utils::ThreadBase_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700273
274 virtual void setInBuffer(const sp<EffectBufferHalInterface>& buffer) = 0;
275 virtual float *inBuffer() const = 0;
276 virtual void setOutBuffer(const sp<EffectBufferHalInterface>& buffer) = 0;
277 virtual float *outBuffer() const = 0;
278
279 virtual void incTrackCnt() = 0;
280 virtual void decTrackCnt() = 0;
281 virtual int32_t trackCnt() const = 0;
282
283 virtual void incActiveTrackCnt() = 0;
284 virtual void decActiveTrackCnt() = 0;
285 virtual int32_t activeTrackCnt() const = 0;
286
287 virtual product_strategy_t strategy() const = 0;
288 virtual void setStrategy(product_strategy_t strategy) = 0;
289
290 // suspend or restore effects of the specified type. The number of suspend requests is counted
291 // and restore occurs once all suspend requests are cancelled.
Shunkai Yaod125e402024-01-20 03:19:06 +0000292 virtual void setEffectSuspended_l(const effect_uuid_t* type, bool suspend) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700293 // suspend all eligible effects
294 virtual void setEffectSuspendedAll_l(bool suspend) = 0;
295 // check if effects should be suspended or restored when a given effect is enable or disabled
Shunkai Yaod125e402024-01-20 03:19:06 +0000296 virtual void checkSuspendOnEffectEnabled_l(const sp<IAfEffectModule>& effect, bool enabled)
297 REQUIRES(audio_utils::ThreadBase_Mutex) REQUIRES(audio_utils::ThreadBase_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700298
Shunkai Yaod125e402024-01-20 03:19:06 +0000299 virtual void clearInputBuffer() EXCLUDES_EffectChain_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700300
301 // At least one non offloadable effect in the chain is enabled
Shunkai Yaod125e402024-01-20 03:19:06 +0000302 virtual bool isNonOffloadableEnabled() const EXCLUDES_EffectChain_Mutex = 0;
303 virtual bool isNonOffloadableEnabled_l() const REQUIRES(audio_utils::EffectChain_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700304
Shunkai Yaod125e402024-01-20 03:19:06 +0000305 virtual void syncHalEffectsState_l()
306 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700307
308 // flags is an ORed set of audio_output_flags_t which is updated on return.
309 virtual void checkOutputFlagCompatibility(audio_output_flags_t *flags) const = 0;
310
311 // flags is an ORed set of audio_input_flags_t which is updated on return.
312 virtual void checkInputFlagCompatibility(audio_input_flags_t *flags) const = 0;
313
314 // Is this EffectChain compatible with the RAW audio flag.
315 virtual bool isRawCompatible() const = 0;
316
317 // Is this EffectChain compatible with the FAST audio flag.
318 virtual bool isFastCompatible() const = 0;
319
320 // Is this EffectChain compatible with the bit-perfect audio flag.
321 virtual bool isBitPerfectCompatible() const = 0;
322
323 // isCompatibleWithThread_l() must be called with thread->mLock held
Shunkai Yaod125e402024-01-20 03:19:06 +0000324 virtual bool isCompatibleWithThread_l(const sp<IAfThreadBase>& thread) const
325 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700326
Shunkai Yao29d10572024-03-19 04:31:47 +0000327 virtual bool containsHapticGeneratingEffect()
328 EXCLUDES_EffectChain_Mutex = 0;
329
330 virtual bool containsHapticGeneratingEffect_l()
331 REQUIRES(audio_utils::EffectChain_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700332
Ahmad Khalil229466a2024-02-05 12:15:30 +0000333 virtual void setHapticScale_l(int id, os::HapticScale hapticScale)
Shunkai Yaod125e402024-01-20 03:19:06 +0000334 REQUIRES(audio_utils::ThreadBase_Mutex) EXCLUDES_EffectChain_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700335
336 virtual sp<EffectCallbackInterface> effectCallback() const = 0;
337
Andy Hung87c693c2023-07-06 20:56:16 -0700338 virtual wp<IAfThreadBase> thread() const = 0;
Shunkai Yaod125e402024-01-20 03:19:06 +0000339 virtual void setThread(const sp<IAfThreadBase>& thread) EXCLUDES_EffectChain_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700340
Shunkai Yao29d10572024-03-19 04:31:47 +0000341 virtual bool isFirstEffect_l(int id) const REQUIRES(audio_utils::EffectChain_Mutex) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700342
343 virtual size_t numberOfEffects() const = 0;
344 virtual sp<IAfEffectModule> getEffectModule(size_t index) const = 0;
345
Eric Laurent4eb45d02023-12-20 12:07:17 +0100346 // sendMetadata_l() must be called with thread->mLock held
347 virtual void sendMetadata_l(const std::vector<playback_track_metadata_v7_t>& allMetadata,
348 const std::optional<const std::vector<playback_track_metadata_v7_t>> spatializedMetadata);
349
Andy Hung6ac17eb2023-06-20 18:56:17 -0700350 virtual void dump(int fd, const Vector<String16>& args) const = 0;
351};
352
353class IAfEffectHandle : public virtual RefBase {
354 friend class EffectBase;
355 friend class EffectChain;
356 friend class EffectModule;
357
358public:
359 static sp<IAfEffectHandle> create(
360 const sp<IAfEffectBase>& effect,
Andy Hung59867e42023-06-27 17:05:02 -0700361 const sp<Client>& client,
Andy Hung6ac17eb2023-06-20 18:56:17 -0700362 const sp<media::IEffectClient>& effectClient,
363 int32_t priority, bool notifyFramesProcessed);
364
365 virtual status_t initCheck() const = 0;
366 virtual bool enabled() const = 0;
367 virtual int id() const = 0;
368 virtual wp<IAfEffectBase> effect() const = 0;
369 virtual sp<android::media::IEffect> asIEffect() = 0;
Andy Hung59867e42023-06-27 17:05:02 -0700370 virtual const sp<Client>& client() const = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700371
372private:
373 virtual void setControl(bool hasControl, bool signal, bool enabled) = 0;
374 virtual bool hasControl() const = 0;
375 virtual void setEnabled(bool enabled) = 0;
376 virtual bool disconnected() const = 0;
377 virtual int priority() const = 0;
378
379 virtual void commandExecuted(uint32_t cmdCode,
380 const std::vector<uint8_t>& cmdData,
381 const std::vector<uint8_t>& replyData) = 0;
382 virtual void framesProcessed(int32_t frames) const = 0;
383
384 virtual void dumpToBuffer(char* buffer, size_t size) const = 0;
385};
386
387class IAfDeviceEffectProxy : public virtual IAfEffectBase {
388public:
Andy Hung6ac17eb2023-06-20 18:56:17 -0700389 static sp<IAfDeviceEffectProxy> create(const AudioDeviceTypeAddr& device,
Andy Hung55a74fd2023-07-13 19:54:47 -0700390 const sp<DeviceEffectManagerCallback>& callback,
Andy Hung6ac17eb2023-06-20 18:56:17 -0700391 effect_descriptor_t *desc, int id, bool notifyFramesProcessed);
392
Shunkai Yaod125e402024-01-20 03:19:06 +0000393 virtual status_t init_l(const std::map<audio_patch_handle_t, IAfPatchPanel::Patch>& patches)
394 REQUIRES(audio_utils::DeviceEffectManager_Mutex) EXCLUDES_EffectBase_Mutex = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700395 virtual const AudioDeviceTypeAddr& device() const = 0;
396
397 virtual status_t onCreatePatch(
398 audio_patch_handle_t patchHandle,
Andy Hung8e6b62a2023-07-13 18:11:33 -0700399 const IAfPatchPanel::Patch& patch) = 0;
François Gaffie58e73af2023-02-15 11:47:24 +0100400 virtual status_t onUpdatePatch(audio_patch_handle_t oldPatchHandle,
401 audio_patch_handle_t newPatchHandle,
Andy Hung8e6b62a2023-07-13 18:11:33 -0700402 const IAfPatchPanel::Patch& patch) = 0;
Andy Hung6ac17eb2023-06-20 18:56:17 -0700403 virtual void onReleasePatch(audio_patch_handle_t patchHandle) = 0;
404
Andy Hung99b1ba62023-07-14 11:00:08 -0700405 virtual void dump2(int fd, int spaces) const = 0; // TODO(b/291319101) naming?
Andy Hung6ac17eb2023-06-20 18:56:17 -0700406
407private:
408 // used by DeviceEffectProxy
409 virtual bool isOutput() const = 0;
410 virtual uint32_t sampleRate() const = 0;
411 virtual audio_channel_mask_t channelMask() const = 0;
412 virtual uint32_t channelCount() const = 0;
413
414 virtual size_t removeEffect(const sp<IAfEffectModule>& effect) = 0;
415 virtual status_t addEffectToHal(const sp<EffectHalInterface>& effect) = 0;
416 virtual status_t removeEffectFromHal(const sp<EffectHalInterface>& effect) = 0;
417};
418
Andy Hungee58e4a2023-07-07 13:47:37 -0700419} // namespace android