blob: abb8f2f34c298074693bf5f32c87761f6e2ff113 [file] [log] [blame]
Andy Hung440901d2023-06-29 21:19:25 -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 Hungc6f227f2023-07-18 18:31:50 -070019#include <android/media/IAudioTrackCallback.h>
20#include <android/media/IEffectClient.h>
21#include <audiomanager/IAudioManager.h>
Andy Hung56ce2ed2024-06-12 16:03:16 -070022#include <audio_utils/DeferredExecutor.h>
Andy Hungc6f227f2023-07-18 18:31:50 -070023#include <audio_utils/MelProcessor.h>
Andy Hung56ce2ed2024-06-12 16:03:16 -070024#include <audio_utils/mutex.h>
Andy Hungc6f227f2023-07-18 18:31:50 -070025#include <binder/MemoryDealer.h>
26#include <datapath/AudioStreamIn.h>
27#include <datapath/AudioStreamOut.h>
28#include <datapath/VolumeInterface.h>
Andy Hung6b137d12024-08-27 22:35:17 +000029#include <datapath/VolumePortInterface.h>
Andy Hungc6f227f2023-07-18 18:31:50 -070030#include <fastpath/FastMixerDumpState.h>
31#include <media/DeviceDescriptorBase.h>
32#include <media/MmapStreamInterface.h>
33#include <media/audiohal/StreamHalInterface.h>
34#include <media/nblog/NBLog.h>
35#include <timing/SyncEvent.h>
Andy Hungc6f227f2023-07-18 18:31:50 -070036#include <utils/RefBase.h>
37#include <vibrator/ExternalVibration.h>
38
39#include <optional>
Andy Hung440901d2023-06-29 21:19:25 -070040
Atneya Nair5997a652024-06-14 17:24:45 -070041namespace com::android::media::permission {
42 class IPermissionProvider;
43}
44
Andy Hung440901d2023-06-29 21:19:25 -070045namespace android {
46
Andy Hung87c693c2023-07-06 20:56:16 -070047class IAfDirectOutputThread;
48class IAfDuplicatingThread;
Andy Hung7aa7d102023-07-07 15:58:48 -070049class IAfMmapCaptureThread;
50class IAfMmapPlaybackThread;
Andy Hung87c693c2023-07-06 20:56:16 -070051class IAfPlaybackThread;
52class IAfRecordThread;
Andy Hungc6f227f2023-07-18 18:31:50 -070053
54class IAfEffectChain;
55class IAfEffectHandle;
56class IAfEffectModule;
57class IAfPatchPanel;
58class IAfPatchRecord;
59class IAfPatchTrack;
60class IAfRecordTrack;
61class IAfTrack;
62class IAfTrackBase;
63class Client;
Andy Hung583043b2023-07-17 17:05:00 -070064class MelReporter;
65
Andy Hung25a80ac2023-07-19 12:47:35 -070066// Used internally for Threads.cpp and AudioFlinger.cpp
67struct stream_type_t {
68 float volume = 1.f;
69 bool mute = false;
70};
71
Andy Hung583043b2023-07-17 17:05:00 -070072// Note this is exposed through IAfThreadBase::afThreadCallback()
73// and hence may be used by the Effect / Track framework.
74class IAfThreadCallback : public virtual RefBase {
75public:
Andy Hung972bec12023-08-31 16:13:39 -070076 virtual audio_utils::mutex& mutex() const
77 RETURN_CAPABILITY(audio_utils::AudioFlinger_Mutex) = 0;
78 virtual bool isNonOffloadableGlobalEffectEnabled_l() const
Andy Hungab65b182023-09-06 19:41:47 -070079 REQUIRES(mutex()) EXCLUDES_ThreadBase_Mutex = 0; // Tracks
Andy Hung583043b2023-07-17 17:05:00 -070080 virtual audio_unique_id_t nextUniqueId(audio_unique_id_use_t use) = 0;
81 virtual bool btNrecIsOff() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -070082 virtual float masterVolume_l() const
83 REQUIRES(mutex()) = 0;
84 virtual bool masterMute_l() const
85 REQUIRES(mutex()) = 0;
86 virtual float getMasterBalance_l() const
87 REQUIRES(mutex()) = 0;
88 virtual bool streamMute_l(audio_stream_type_t stream) const
89 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -070090 virtual audio_mode_t getMode() const = 0;
91 virtual bool isLowRamDevice() const = 0;
92 virtual bool isAudioPolicyReady() const = 0; // Effects
Andy Hung1d2d2aea2023-07-19 16:22:58 -070093 virtual uint32_t getScreenState() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -070094 virtual std::optional<media::AudioVibratorInfo> getDefaultVibratorInfo_l() const
95 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -070096 virtual const sp<IAfPatchPanel>& getPatchPanel() const = 0;
97 virtual const sp<MelReporter>& getMelReporter() const = 0;
98 virtual const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() const = 0;
99 virtual sp<IAudioManager> getOrCreateAudioManager() = 0; // Tracks
100
Andy Hung972bec12023-08-31 16:13:39 -0700101 virtual bool updateOrphanEffectChains(const sp<IAfEffectModule>& effect)
102 EXCLUDES_AudioFlinger_Mutex = 0;
103 virtual status_t moveEffectChain_ll(audio_session_t sessionId,
Shunkai Yao517fc2a2024-03-19 04:31:47 +0000104 IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread,
105 IAfEffectChain* srcChain = nullptr)
Andy Hung972bec12023-08-31 16:13:39 -0700106 REQUIRES(mutex(), audio_utils::ThreadBase_Mutex) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700107
108 virtual void requestLogMerge() = 0;
Andy Hung972bec12023-08-31 16:13:39 -0700109 virtual sp<NBLog::Writer> newWriter_l(size_t size, const char *name)
110 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700111 virtual void unregisterWriter(const sp<NBLog::Writer>& writer) = 0;
112
113 virtual sp<audioflinger::SyncEvent> createSyncEvent(AudioSystem::sync_event_t type,
114 audio_session_t triggerSession,
115 audio_session_t listenerSession,
116 const audioflinger::SyncEventCallback& callBack,
Andy Hung972bec12023-08-31 16:13:39 -0700117 const wp<IAfTrackBase>& cookie)
118 EXCLUDES_AudioFlinger_Mutex = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700119
Andy Hungab65b182023-09-06 19:41:47 -0700120 // Hold either AudioFlinger::mutex or ThreadBase::mutex
121 virtual void ioConfigChanged_l(audio_io_config_event_t event,
Andy Hung583043b2023-07-17 17:05:00 -0700122 const sp<AudioIoDescriptor>& ioDesc,
Andy Hung972bec12023-08-31 16:13:39 -0700123 pid_t pid = 0) EXCLUDES_AudioFlinger_ClientMutex = 0;
124 virtual void onNonOffloadableGlobalEffectEnable() EXCLUDES_AudioFlinger_Mutex = 0;
Mikhail Naganovbf203ce2024-05-23 16:27:59 -0700125 virtual void onSupportedLatencyModesChanged(audio_io_handle_t output,
126 const std::vector<audio_latency_mode_t>& modes)
Andy Hung972bec12023-08-31 16:13:39 -0700127 EXCLUDES_AudioFlinger_ClientMutex = 0;
Mikhail Naganovbf203ce2024-05-23 16:27:59 -0700128
129 virtual void onHardError(std::set<audio_port_handle_t>& trackPortIds) = 0;
Atneya Nair5997a652024-06-14 17:24:45 -0700130
131 virtual const ::com::android::media::permission::IPermissionProvider&
132 getPermissionProvider() = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700133};
Andy Hung87c693c2023-07-06 20:56:16 -0700134
Andy Hung440901d2023-06-29 21:19:25 -0700135class IAfThreadBase : public virtual RefBase {
136public:
137 enum type_t {
138 MIXER, // Thread class is MixerThread
139 DIRECT, // Thread class is DirectOutputThread
140 DUPLICATING, // Thread class is DuplicatingThread
141 RECORD, // Thread class is RecordThread
142 OFFLOAD, // Thread class is OffloadThread
143 MMAP_PLAYBACK, // Thread class for MMAP playback stream
144 MMAP_CAPTURE, // Thread class for MMAP capture stream
145 SPATIALIZER, //
146 BIT_PERFECT, // Thread class for BitPerfectThread
147 // When adding a value, also update IAfThreadBase::threadTypeToString()
148 };
149
150 static const char* threadTypeToString(type_t type);
Andy Hung25a80ac2023-07-19 12:47:35 -0700151 static std::string formatToString(audio_format_t format); // compliant for MediaMetrics
Andy Hung81994d62023-07-20 21:44:14 -0700152 static bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask);
153 static bool isValidPcmSinkFormat(audio_format_t format);
154
Andy Hung440901d2023-06-29 21:19:25 -0700155 virtual status_t readyToRun() = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700156 virtual void clearPowerManager() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700157 virtual status_t initCheck() const = 0;
158 virtual type_t type() const = 0;
159 virtual bool isDuplicating() const = 0;
160 virtual audio_io_handle_t id() const = 0;
161 virtual uint32_t sampleRate() const = 0;
162 virtual audio_channel_mask_t channelMask() const = 0;
163 virtual audio_channel_mask_t mixerChannelMask() const = 0;
164 virtual audio_format_t format() const = 0;
165 virtual uint32_t channelCount() const = 0;
166
167 // Called by AudioFlinger::frameCount(audio_io_handle_t output) and effects,
168 // and returns the [normal mix] buffer's frame count.
169 virtual size_t frameCount() const = 0;
170 virtual audio_channel_mask_t hapticChannelMask() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700171 virtual uint32_t hapticChannelCount() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700172 virtual uint32_t latency_l() const = 0; // NO_THREAD_SAFETY_ANALYSIS
173 virtual void setVolumeForOutput_l(float left, float right) const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700174
175 // Return's the HAL's frame count i.e. fast mixer buffer size.
176 virtual size_t frameCountHAL() const = 0;
177 virtual size_t frameSize() const = 0;
178 // Should be "virtual status_t requestExitAndWait()" and override same
179 // method in Thread, but Thread::requestExitAndWait() is not yet virtual.
Andy Hungab65b182023-09-06 19:41:47 -0700180 virtual void exit() EXCLUDES_ThreadBase_Mutex = 0;
181 virtual bool checkForNewParameter_l(const String8& keyValuePair, status_t& status)
182 REQUIRES(mutex()) = 0;
183 virtual status_t setParameters(const String8& keyValuePairs) EXCLUDES_ThreadBase_Mutex = 0;
184 virtual String8 getParameters(const String8& keys) EXCLUDES_ThreadBase_Mutex = 0;
185 virtual void ioConfigChanged_l(
Andy Hung440901d2023-06-29 21:19:25 -0700186 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700187 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE)
188 /* holds either AF::mutex or TB::mutex */ = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700189
190 // sendConfigEvent_l() must be called with ThreadBase::mLock held
191 // Can temporarily release the lock if waiting for a reply from
192 // processConfigEvents_l().
193 // status_t sendConfigEvent_l(sp<ConfigEvent>& event);
194 virtual void sendIoConfigEvent(
195 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700196 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700197 virtual void sendIoConfigEvent_l(
198 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700199 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) REQUIRES(mutex()) = 0;
200 virtual void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp)
201 EXCLUDES_ThreadBase_Mutex = 0;
202 virtual void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio, bool forApp)
203 REQUIRES(mutex()) = 0;
204 virtual status_t sendSetParameterConfigEvent_l(const String8& keyValuePair)
205 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700206 virtual status_t sendCreateAudioPatchConfigEvent(
Andy Hungab65b182023-09-06 19:41:47 -0700207 const struct audio_patch* patch, audio_patch_handle_t* handle)
208 EXCLUDES_ThreadBase_Mutex = 0;
209 virtual status_t sendReleaseAudioPatchConfigEvent(audio_patch_handle_t handle)
210 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700211 virtual status_t sendUpdateOutDeviceConfigEvent(
Andy Hungab65b182023-09-06 19:41:47 -0700212 const DeviceDescriptorBaseVector& outDevices) EXCLUDES_ThreadBase_Mutex = 0;
213 virtual void sendResizeBufferConfigEvent_l(int32_t maxSharedAudioHistoryMs)
214 REQUIRES(mutex()) = 0;
215 virtual void sendCheckOutputStageEffectsEvent() EXCLUDES_ThreadBase_Mutex = 0;
216 virtual void sendCheckOutputStageEffectsEvent_l()
217 REQUIRES(mutex()) = 0;
218 virtual void sendHalLatencyModesChangedEvent_l()
219 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700220
Andy Hungab65b182023-09-06 19:41:47 -0700221 virtual void processConfigEvents_l()
222 REQUIRES(mutex()) = 0;
223 virtual void setCheckOutputStageEffects() = 0; // no mutex needed
224 virtual void cacheParameters_l()
225 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700226 virtual status_t createAudioPatch_l(
Andy Hungab65b182023-09-06 19:41:47 -0700227 const struct audio_patch* patch, audio_patch_handle_t* handle)
228 REQUIRES(mutex()) = 0;
229 virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle)
230 REQUIRES(mutex()) = 0;
231 virtual void updateOutDevices(const DeviceDescriptorBaseVector& outDevices)
232 EXCLUDES_ThreadBase_Mutex = 0;
233 virtual void toAudioPortConfig(struct audio_port_config* config)
234 EXCLUDES_ThreadBase_Mutex = 0;
235 virtual void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs)
236 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700237
238 // see note at declaration of mStandby, mOutDevice and mInDevice
239 virtual bool inStandby() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700240 virtual const DeviceTypeSet outDeviceTypes_l() const REQUIRES(mutex()) = 0;
241 virtual audio_devices_t inDeviceType_l() const REQUIRES(mutex()) = 0;
242 virtual DeviceTypeSet getDeviceTypes_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700243 virtual const AudioDeviceTypeAddrVector& outDeviceTypeAddrs() const = 0;
244 virtual const AudioDeviceTypeAddr& inDeviceTypeAddr() const = 0;
245 virtual bool isOutput() const = 0;
246 virtual bool isOffloadOrMmap() const = 0;
247 virtual sp<StreamHalInterface> stream() const = 0;
248 virtual sp<IAfEffectHandle> createEffect_l(
249 const sp<Client>& client,
250 const sp<media::IEffectClient>& effectClient,
251 int32_t priority,
252 audio_session_t sessionId,
253 effect_descriptor_t* desc,
254 int* enabled,
255 status_t* status /*non-NULL*/,
256 bool pinned,
257 bool probe,
Andy Hung972bec12023-08-31 16:13:39 -0700258 bool notifyFramesProcessed)
Andy Hungab65b182023-09-06 19:41:47 -0700259 REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700260
261 // return values for hasAudioSession (bit field)
262 enum effect_state {
263 EFFECT_SESSION = 0x1, // the audio session corresponds to at least one
264 // effect
265 TRACK_SESSION = 0x2, // the audio session corresponds to at least one
266 // track
267 FAST_SESSION = 0x4, // the audio session corresponds to at least one
268 // fast track
269 SPATIALIZED_SESSION = 0x8, // the audio session corresponds to at least one
270 // spatialized track
271 BIT_PERFECT_SESSION = 0x10 // the audio session corresponds to at least one
272 // bit-perfect track
273 };
274
275 // get effect chain corresponding to session Id.
Andy Hungab65b182023-09-06 19:41:47 -0700276 virtual sp<IAfEffectChain> getEffectChain(audio_session_t sessionId) const
277 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700278 // same as getEffectChain() but must be called with ThreadBase mutex locked
Andy Hungab65b182023-09-06 19:41:47 -0700279 virtual sp<IAfEffectChain> getEffectChain_l(audio_session_t sessionId) const
280 REQUIRES(mutex()) = 0;
281 virtual std::vector<int> getEffectIds_l(audio_session_t sessionId) const
282 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700283 // add an effect chain to the chain list (mEffectChains)
Andy Hungab65b182023-09-06 19:41:47 -0700284 virtual status_t addEffectChain_l(const sp<IAfEffectChain>& chain)
285 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700286 // remove an effect chain from the chain list (mEffectChains)
Andy Hungab65b182023-09-06 19:41:47 -0700287 virtual size_t removeEffectChain_l(const sp<IAfEffectChain>& chain)
288 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700289 // lock all effect chains Mutexes. Must be called before releasing the
290 // ThreadBase mutex before processing the mixer and effects. This guarantees the
291 // integrity of the chains during the process.
292 // Also sets the parameter 'effectChains' to current value of mEffectChains.
Andy Hungab65b182023-09-06 19:41:47 -0700293 virtual void lockEffectChains_l(Vector<sp<IAfEffectChain>>& effectChains)
Shunkai Yaod125e402024-01-20 03:19:06 +0000294 REQUIRES(mutex()) EXCLUDES_EffectChain_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700295 // unlock effect chains after process
Andy Hungab65b182023-09-06 19:41:47 -0700296 virtual void unlockEffectChains(const Vector<sp<IAfEffectChain>>& effectChains)
297 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700298 // get a copy of mEffectChains vector
Andy Hungab65b182023-09-06 19:41:47 -0700299 virtual Vector<sp<IAfEffectChain>> getEffectChains_l() const
300 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700301 // set audio mode to all effect chains
Andy Hungab65b182023-09-06 19:41:47 -0700302 virtual void setMode(audio_mode_t mode)
303 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700304 // get effect module with corresponding ID on specified audio session
Andy Hungab65b182023-09-06 19:41:47 -0700305 virtual sp<IAfEffectModule> getEffect(audio_session_t sessionId, int effectId) const
306 EXCLUDES_ThreadBase_Mutex = 0;
307 virtual sp<IAfEffectModule> getEffect_l(audio_session_t sessionId, int effectId) const
308 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700309 // add and effect module. Also creates the effect chain is none exists for
310 // the effects audio session. Only called in a context of moving an effect
311 // from one thread to another
Andy Hung972bec12023-08-31 16:13:39 -0700312 virtual status_t addEffect_ll(const sp<IAfEffectModule>& effect)
313 REQUIRES(audio_utils::AudioFlinger_Mutex, mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700314 // remove and effect module. Also removes the effect chain is this was the last
315 // effect
Andy Hungab65b182023-09-06 19:41:47 -0700316 virtual void removeEffect_l(const sp<IAfEffectModule>& effect, bool release = false)
317 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700318 // disconnect an effect handle from module and destroy module if last handle
Andy Hungab65b182023-09-06 19:41:47 -0700319 virtual void disconnectEffectHandle(IAfEffectHandle* handle, bool unpinIfLast)
320 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700321 // detach all tracks connected to an auxiliary effect
Andy Hungab65b182023-09-06 19:41:47 -0700322 virtual void detachAuxEffect_l(int effectId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700323 // returns a combination of:
324 // - EFFECT_SESSION if effects on this audio session exist in one chain
325 // - TRACK_SESSION if tracks on this audio session exist
326 // - FAST_SESSION if fast tracks on this audio session exist
327 // - SPATIALIZED_SESSION if spatialized tracks on this audio session exist
Andy Hungab65b182023-09-06 19:41:47 -0700328 virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const REQUIRES(mutex()) = 0;
329 virtual uint32_t hasAudioSession(audio_session_t sessionId) const
330 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700331
332 // the value returned by default implementation is not important as the
333 // strategy is only meaningful for PlaybackThread which implements this method
Andy Hungab65b182023-09-06 19:41:47 -0700334 virtual product_strategy_t getStrategyForSession_l(audio_session_t sessionId) const
335 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700336
337 // check if some effects must be suspended/restored when an effect is enabled
338 // or disabled
339 virtual void checkSuspendOnEffectEnabled(
Andy Hungab65b182023-09-06 19:41:47 -0700340 bool enabled, audio_session_t sessionId, bool threadLocked)
341 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700342
Andy Hungab65b182023-09-06 19:41:47 -0700343 virtual status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event)
344 EXCLUDES_ThreadBase_Mutex = 0;
345 // internally static, perhaps make static member.
Andy Hung440901d2023-06-29 21:19:25 -0700346 virtual bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const = 0;
347
348 // Return a reference to a per-thread heap which can be used to allocate IMemory
349 // objects that will be read-only to client processes, read/write to mediaserver,
350 // and shared by all client processes of the thread.
351 // The heap is per-thread rather than common across all threads, because
352 // clients can't be trusted not to modify the offset of the IMemory they receive.
353 // If a thread does not have such a heap, this method returns 0.
354 virtual sp<MemoryDealer> readOnlyHeap() const = 0;
355
356 virtual sp<IMemory> pipeMemory() const = 0;
357
Andy Hungab65b182023-09-06 19:41:47 -0700358 virtual void systemReady() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700359
360 // checkEffectCompatibility_l() must be called with ThreadBase::mLock held
361 virtual status_t checkEffectCompatibility_l(
Andy Hungab65b182023-09-06 19:41:47 -0700362 const effect_descriptor_t* desc, audio_session_t sessionId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700363
Andy Hungab65b182023-09-06 19:41:47 -0700364 virtual void broadcast_l() REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700365
Andy Hungab65b182023-09-06 19:41:47 -0700366 virtual bool isTimestampCorrectionEnabled_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700367
368 virtual bool isMsdDevice() const = 0;
369
Andy Hungab65b182023-09-06 19:41:47 -0700370 virtual void dump(int fd, const Vector<String16>& args) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700371
372 // deliver stats to mediametrics.
Andy Hungab65b182023-09-06 19:41:47 -0700373 virtual void sendStatistics(bool force) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700374
Andy Hung972bec12023-08-31 16:13:39 -0700375 virtual audio_utils::mutex& mutex() const
376 RETURN_CAPABILITY(audio_utils::ThreadBase_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700377
Andy Hungab65b182023-09-06 19:41:47 -0700378 virtual void onEffectEnable(const sp<IAfEffectModule>& effect) EXCLUDES_ThreadBase_Mutex = 0;
379 virtual void onEffectDisable() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700380
381 // invalidateTracksForAudioSession_l must be called with holding mLock.
Andy Hungab65b182023-09-06 19:41:47 -0700382 virtual void invalidateTracksForAudioSession_l(audio_session_t sessionId) const
383 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700384 // Invalidate all the tracks with the given audio session.
Andy Hungab65b182023-09-06 19:41:47 -0700385 virtual void invalidateTracksForAudioSession(audio_session_t sessionId) const
386 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700387
388 virtual bool isStreamInitialized() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -0700389 virtual void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor)
390 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
391 virtual void stopMelComputation_l()
392 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700393
Andy Hungab65b182023-09-06 19:41:47 -0700394 virtual product_strategy_t getStrategyForStream(audio_stream_type_t stream) const
395 EXCLUDES_AUDIO_ALL = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700396
397 virtual void setEffectSuspended_l(
Andy Hungab65b182023-09-06 19:41:47 -0700398 const effect_uuid_t* type, bool suspend, audio_session_t sessionId)
399 REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700400
Andy Hung6c498e92023-12-05 17:28:17 -0800401 // Wait while the Thread is busy. This is done to ensure that
402 // the Thread is not busy releasing the Tracks, during which the Thread mutex
403 // may be temporarily unlocked. Some Track methods will use this method to
404 // avoid races.
Andy Hungf462c6c2024-09-23 18:42:26 -0700405 virtual void waitWhileThreadBusy_l(audio_utils::unique_lock<audio_utils::mutex>& ul)
Andy Hung6c498e92023-12-05 17:28:17 -0800406 REQUIRES(mutex()) = 0;
Andy Hung56ce2ed2024-06-12 16:03:16 -0700407
408 // The ThreadloopExecutor is used to defer functors or dtors
409 // to when the Threadloop does not hold any mutexes (at the end of the
410 // processing period cycle).
411 virtual audio_utils::DeferredExecutor& getThreadloopExecutor() = 0;
412
Andy Hung87c693c2023-07-06 20:56:16 -0700413 // Dynamic cast to derived interface
414 virtual sp<IAfDirectOutputThread> asIAfDirectOutputThread() { return nullptr; }
415 virtual sp<IAfDuplicatingThread> asIAfDuplicatingThread() { return nullptr; }
416 virtual sp<IAfPlaybackThread> asIAfPlaybackThread() { return nullptr; }
417 virtual sp<IAfRecordThread> asIAfRecordThread() { return nullptr; }
Andy Hung583043b2023-07-17 17:05:00 -0700418 virtual IAfThreadCallback* afThreadCallback() const = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700419};
420
Andy Hung87c693c2023-07-06 20:56:16 -0700421class IAfPlaybackThread : public virtual IAfThreadBase, public virtual VolumeInterface {
Andy Hung440901d2023-06-29 21:19:25 -0700422public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700423 static sp<IAfPlaybackThread> createBitPerfectThread(
Andy Hung583043b2023-07-17 17:05:00 -0700424 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
425 audio_io_handle_t id, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700426
427 static sp<IAfPlaybackThread> createDirectOutputThread(
Andy Hung583043b2023-07-17 17:05:00 -0700428 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
429 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700430
431 static sp<IAfPlaybackThread> createMixerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700432 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
433 audio_io_handle_t id, bool systemReady, type_t type = MIXER,
434 audio_config_base_t* mixerConfig = nullptr);
Andy Hungee58e4a2023-07-07 13:47:37 -0700435
436 static sp<IAfPlaybackThread> createOffloadThread(
Andy Hung583043b2023-07-17 17:05:00 -0700437 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
438 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700439
440 static sp<IAfPlaybackThread> createSpatializerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700441 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
442 audio_io_handle_t id, bool systemReady, audio_config_base_t* mixerConfig);
Andy Hungee58e4a2023-07-07 13:47:37 -0700443
Andy Hung87c693c2023-07-06 20:56:16 -0700444 static constexpr int8_t kMaxTrackStopRetriesOffload = 2;
445
Andy Hung440901d2023-06-29 21:19:25 -0700446 enum mixer_state {
447 MIXER_IDLE, // no active tracks
448 MIXER_TRACKS_ENABLED, // at least one active track, but no track has any data ready
449 MIXER_TRACKS_READY, // at least one active track, and at least one track has data
450 MIXER_DRAIN_TRACK, // drain currently playing track
451 MIXER_DRAIN_ALL, // fully drain the hardware
452 // standby mode does not have an enum value
453 // suspend by audio policy manager is orthogonal to mixer state
454 };
455
456 // return estimated latency in milliseconds, as reported by HAL
457 virtual uint32_t latency() const = 0; // should be in IAfThreadBase?
458
Andy Hungab65b182023-09-06 19:41:47 -0700459 virtual uint32_t& fastTrackAvailMask_l() REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700460
Andy Hung440901d2023-06-29 21:19:25 -0700461 virtual sp<IAfTrack> createTrack_l(
462 const sp<Client>& client,
463 audio_stream_type_t streamType,
464 const audio_attributes_t& attr,
465 uint32_t* sampleRate,
466 audio_format_t format,
467 audio_channel_mask_t channelMask,
468 size_t* pFrameCount,
469 size_t* pNotificationFrameCount,
470 uint32_t notificationsPerBuffer,
471 float speed,
472 const sp<IMemory>& sharedBuffer,
473 audio_session_t sessionId,
474 audio_output_flags_t* flags,
475 pid_t creatorPid,
476 const AttributionSourceState& attributionSource,
477 pid_t tid,
478 status_t* status /*non-NULL*/,
479 audio_port_handle_t portId,
480 const sp<media::IAudioTrackCallback>& callback,
481 bool isSpatialized,
jiabin94ed47c2023-07-27 23:34:20 +0000482 bool isBitPerfect,
Andy Hung6b137d12024-08-27 22:35:17 +0000483 audio_output_flags_t* afTrackFlags,
484 float volume)
Andy Hung972bec12023-08-31 16:13:39 -0700485 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700486
Andy Hungab65b182023-09-06 19:41:47 -0700487 virtual status_t addTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
488 virtual bool destroyTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
489 virtual bool isTrackActive(const sp<IAfTrack>& track) const REQUIRES(mutex()) = 0;
490 virtual void addOutputTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700491
Andy Hungab65b182023-09-06 19:41:47 -0700492 virtual AudioStreamOut* getOutput_l() const REQUIRES(mutex()) = 0;
Andy Hung8d672e02023-09-15 18:19:28 -0700493 virtual AudioStreamOut* getOutput() const EXCLUDES_ThreadBase_Mutex = 0;
494 virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700495
496 // a very large number of suspend() will eventually wraparound, but unlikely
497 virtual void suspend() = 0;
498 virtual void restore() = 0;
499 virtual bool isSuspended() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700500 virtual status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames) const
501 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700502 // Consider also removing and passing an explicit mMainBuffer initialization
503 // parameter to AF::IAfTrack::Track().
504 virtual float* sinkBuffer() const = 0;
505
Andy Hungab65b182023-09-06 19:41:47 -0700506 virtual status_t attachAuxEffect(const sp<IAfTrack>& track, int EffectId)
507 EXCLUDES_ThreadBase_Mutex = 0;
508 virtual status_t attachAuxEffect_l(const sp<IAfTrack>& track, int EffectId)
509 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700510
511 // called with AudioFlinger lock held
Andy Hungab65b182023-09-06 19:41:47 -0700512 virtual bool invalidateTracks_l(audio_stream_type_t streamType) REQUIRES(mutex()) = 0;
513 virtual bool invalidateTracks_l(std::set<audio_port_handle_t>& portIds) REQUIRES(mutex()) = 0;
514 virtual void invalidateTracks(audio_stream_type_t streamType)
515 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700516 // Invalidate tracks by a set of port ids. The port id will be removed from
517 // the given set if the corresponding track is found and invalidated.
Andy Hungab65b182023-09-06 19:41:47 -0700518 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
519 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700520
Andy Hungab65b182023-09-06 19:41:47 -0700521 virtual status_t getTimestamp_l(AudioTimestamp& timestamp) REQUIRES(mutex()) = 0;
522 virtual void addPatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;
523 virtual void deletePatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700524
525 // Return the asynchronous signal wait time.
Andy Hungab65b182023-09-06 19:41:47 -0700526 virtual int64_t computeWaitTimeNs_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700527 // returns true if the track is allowed to be added to the thread.
528 virtual bool isTrackAllowed_l(
529 audio_channel_mask_t channelMask, audio_format_t format, audio_session_t sessionId,
Andy Hungab65b182023-09-06 19:41:47 -0700530 uid_t uid) const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700531
532 virtual bool supportsHapticPlayback() const = 0;
533
Andy Hungab65b182023-09-06 19:41:47 -0700534 virtual void setDownStreamPatch(const struct audio_patch* patch)
535 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700536
Andy Hungab65b182023-09-06 19:41:47 -0700537 virtual IAfTrack* getTrackById_l(audio_port_handle_t trackId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700538
539 virtual bool hasMixer() const = 0;
540
541 virtual status_t setRequestedLatencyMode(audio_latency_mode_t mode) = 0;
542
Andy Hungab65b182023-09-06 19:41:47 -0700543 virtual status_t getSupportedLatencyModes(std::vector<audio_latency_mode_t>* modes)
544 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700545
546 virtual status_t setBluetoothVariableLatencyEnabled(bool enabled) = 0;
547
Andy Hungab65b182023-09-06 19:41:47 -0700548 virtual void setStandby() EXCLUDES_ThreadBase_Mutex = 0;
549 virtual void setStandby_l() REQUIRES(mutex()) = 0;
550 virtual bool waitForHalStart() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700551
552 virtual bool hasFastMixer() const = 0;
553 virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const = 0;
554 virtual const std::atomic<int64_t>& framesWritten() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700555
556 virtual bool usesHwAvSync() const = 0;
jiabin220eea12024-05-17 17:55:20 +0000557
558 virtual void setTracksInternalMute(std::map<audio_port_handle_t, bool>* tracksInternalMute)
559 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung6b137d12024-08-27 22:35:17 +0000560
561 virtual status_t setPortsVolume(const std::vector<audio_port_handle_t>& portIds, float volume)
562 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700563};
564
565class IAfDirectOutputThread : public virtual IAfPlaybackThread {
566public:
567 virtual status_t selectPresentation(int presentationId, int programId) = 0;
568};
569
570class IAfDuplicatingThread : public virtual IAfPlaybackThread {
571public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700572 static sp<IAfDuplicatingThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700573 const sp<IAfThreadCallback>& afThreadCallback, IAfPlaybackThread* mainThread,
Andy Hungee58e4a2023-07-07 13:47:37 -0700574 audio_io_handle_t id, bool systemReady);
575
Andy Hungab65b182023-09-06 19:41:47 -0700576 virtual void addOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700577 virtual uint32_t waitTimeMs() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700578 virtual void removeOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700579};
580
581class IAfRecordThread : public virtual IAfThreadBase {
582public:
583 static sp<IAfRecordThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700584 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamIn* input,
585 audio_io_handle_t id, bool systemReady);
Andy Hung87c693c2023-07-06 20:56:16 -0700586
587 virtual sp<IAfRecordTrack> createRecordTrack_l(
588 const sp<Client>& client,
589 const audio_attributes_t& attr,
590 uint32_t* pSampleRate,
591 audio_format_t format,
592 audio_channel_mask_t channelMask,
593 size_t* pFrameCount,
594 audio_session_t sessionId,
595 size_t* pNotificationFrameCount,
596 pid_t creatorPid,
597 const AttributionSourceState& attributionSource,
598 audio_input_flags_t* flags,
599 pid_t tid,
600 status_t* status /*non-NULL*/,
601 audio_port_handle_t portId,
Andy Hung972bec12023-08-31 16:13:39 -0700602 int32_t maxSharedAudioHistoryMs)
Andy Hungab65b182023-09-06 19:41:47 -0700603 REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;
604 virtual void destroyTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;
605 virtual void removeTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700606
607 virtual status_t start(
608 IAfRecordTrack* recordTrack, AudioSystem::sync_event_t event,
Andy Hungab65b182023-09-06 19:41:47 -0700609 audio_session_t triggerSession) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700610
611 // ask the thread to stop the specified track, and
612 // return true if the caller should then do it's part of the stopping process
Andy Hungab65b182023-09-06 19:41:47 -0700613 virtual bool stop(IAfRecordTrack* recordTrack) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700614
Andy Hungab65b182023-09-06 19:41:47 -0700615 // NO_THREAD_SAFETY_ANALYSIS: consider atomics
Andy Hung87c693c2023-07-06 20:56:16 -0700616 virtual AudioStreamIn* getInput() const = 0;
617 virtual AudioStreamIn* clearInput() = 0;
618
619 virtual status_t getActiveMicrophones(
Andy Hungab65b182023-09-06 19:41:47 -0700620 std::vector<media::MicrophoneInfoFw>* activeMicrophones)
621 const EXCLUDES_ThreadBase_Mutex = 0;
622 virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction)
623 EXCLUDES_ThreadBase_Mutex = 0;
624 virtual status_t setPreferredMicrophoneFieldDimension(float zoom)
625 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700626
Andy Hungab65b182023-09-06 19:41:47 -0700627 virtual void addPatchTrack(const sp<IAfPatchRecord>& record)
628 EXCLUDES_ThreadBase_Mutex = 0;
629 virtual void deletePatchTrack(const sp<IAfPatchRecord>& record)
630 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700631 virtual bool fastTrackAvailable() const = 0;
632 virtual void setFastTrackAvailable(bool available) = 0;
633
Andy Hungab65b182023-09-06 19:41:47 -0700634 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
635 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700636 virtual bool hasFastCapture() const = 0;
637
Andy Hung3f49ebb2023-09-19 14:48:41 -0700638 virtual void checkBtNrec() EXCLUDES_ThreadBase_Mutex = 0;
639 virtual uint32_t getInputFramesLost() const EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700640
641 virtual status_t shareAudioHistory(
642 const std::string& sharedAudioPackageName,
643 audio_session_t sharedSessionId = AUDIO_SESSION_NONE,
Andy Hungab65b182023-09-06 19:41:47 -0700644 int64_t sharedAudioStartMs = -1) EXCLUDES_ThreadBase_Mutex = 0;
645 virtual void resetAudioHistory_l() REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700646};
647
Andy Hung7aa7d102023-07-07 15:58:48 -0700648class IAfMmapThread : public virtual IAfThreadBase {
649public:
650 // createIAudioTrackAdapter() is a static constructor which creates an
651 // MmapStreamInterface AIDL interface adapter from the MmapThread object that
652 // may be passed back to the client.
653 //
654 // Only one AIDL MmapStreamInterface interface adapter should be created per MmapThread.
655 static sp<MmapStreamInterface> createMmapStreamInterfaceAdapter(
656 const sp<IAfMmapThread>& mmapThread);
657
658 virtual void configure(
659 const audio_attributes_t* attr,
660 audio_stream_type_t streamType,
661 audio_session_t sessionId,
662 const sp<MmapStreamCallback>& callback,
663 audio_port_handle_t deviceId,
Andy Hung3f49ebb2023-09-19 14:48:41 -0700664 audio_port_handle_t portId) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700665 virtual void disconnect() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700666
667 // MmapStreamInterface handling (see adapter)
668 virtual status_t createMmapBuffer(
Andy Hung3f49ebb2023-09-19 14:48:41 -0700669 int32_t minSizeFrames, struct audio_mmap_buffer_info* info)
670 EXCLUDES_ThreadBase_Mutex = 0;
671 virtual status_t getMmapPosition(struct audio_mmap_position* position) const
672 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700673 virtual status_t start(
674 const AudioClient& client, const audio_attributes_t* attr,
Andy Hung3f49ebb2023-09-19 14:48:41 -0700675 audio_port_handle_t* handle) EXCLUDES_ThreadBase_Mutex = 0;
676 virtual status_t stop(audio_port_handle_t handle) EXCLUDES_ThreadBase_Mutex = 0;
677 virtual status_t standby() EXCLUDES_ThreadBase_Mutex = 0;
678 virtual status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const
679 EXCLUDES_ThreadBase_Mutex = 0;
680 virtual status_t reportData(const void* buffer, size_t frameCount)
681 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700682
Andy Hung99b1ba62023-07-14 11:00:08 -0700683 // TODO(b/291317898) move to IAfThreadBase?
Andy Hungab65b182023-09-06 19:41:47 -0700684 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
685 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700686
Andy Hung99b1ba62023-07-14 11:00:08 -0700687 // Sets the UID records silence - TODO(b/291317898) move to IAfMmapCaptureThread
Andy Hungab65b182023-09-06 19:41:47 -0700688 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
689 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700690
691 virtual sp<IAfMmapPlaybackThread> asIAfMmapPlaybackThread() { return nullptr; }
692 virtual sp<IAfMmapCaptureThread> asIAfMmapCaptureThread() { return nullptr; }
693};
694
695class IAfMmapPlaybackThread : public virtual IAfMmapThread, public virtual VolumeInterface {
696public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700697 static sp<IAfMmapPlaybackThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700698 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
699 AudioHwDevice* hwDev, AudioStreamOut* output, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700700
Andy Hungab65b182023-09-06 19:41:47 -0700701 virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung6b137d12024-08-27 22:35:17 +0000702
703 virtual status_t setPortsVolume(const std::vector<audio_port_handle_t>& portIds, float volume)
704 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700705};
706
707class IAfMmapCaptureThread : public virtual IAfMmapThread {
708public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700709 static sp<IAfMmapCaptureThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700710 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
711 AudioHwDevice* hwDev, AudioStreamIn* input, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700712
Andy Hungab65b182023-09-06 19:41:47 -0700713 virtual AudioStreamIn* clearInput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700714};
715
Andy Hung440901d2023-06-29 21:19:25 -0700716} // namespace android