blob: 4d26aa04536cf19d228c557040657fa0440e6b10 [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>
29#include <fastpath/FastMixerDumpState.h>
30#include <media/DeviceDescriptorBase.h>
31#include <media/MmapStreamInterface.h>
32#include <media/audiohal/StreamHalInterface.h>
33#include <media/nblog/NBLog.h>
34#include <timing/SyncEvent.h>
Andy Hungc6f227f2023-07-18 18:31:50 -070035#include <utils/RefBase.h>
36#include <vibrator/ExternalVibration.h>
37
38#include <optional>
Andy Hung440901d2023-06-29 21:19:25 -070039
Atneya Nair5997a652024-06-14 17:24:45 -070040namespace com::android::media::permission {
41 class IPermissionProvider;
42}
43
Andy Hung440901d2023-06-29 21:19:25 -070044namespace android {
45
Andy Hung87c693c2023-07-06 20:56:16 -070046class IAfDirectOutputThread;
47class IAfDuplicatingThread;
Andy Hung7aa7d102023-07-07 15:58:48 -070048class IAfMmapCaptureThread;
49class IAfMmapPlaybackThread;
Andy Hung87c693c2023-07-06 20:56:16 -070050class IAfPlaybackThread;
51class IAfRecordThread;
Andy Hungc6f227f2023-07-18 18:31:50 -070052
53class IAfEffectChain;
54class IAfEffectHandle;
55class IAfEffectModule;
56class IAfPatchPanel;
57class IAfPatchRecord;
58class IAfPatchTrack;
59class IAfRecordTrack;
60class IAfTrack;
61class IAfTrackBase;
62class Client;
Andy Hung583043b2023-07-17 17:05:00 -070063class MelReporter;
64
Andy Hung25a80ac2023-07-19 12:47:35 -070065// Used internally for Threads.cpp and AudioFlinger.cpp
66struct stream_type_t {
67 float volume = 1.f;
68 bool mute = false;
69};
70
Andy Hung583043b2023-07-17 17:05:00 -070071// Note this is exposed through IAfThreadBase::afThreadCallback()
72// and hence may be used by the Effect / Track framework.
73class IAfThreadCallback : public virtual RefBase {
74public:
Andy Hung972bec12023-08-31 16:13:39 -070075 virtual audio_utils::mutex& mutex() const
76 RETURN_CAPABILITY(audio_utils::AudioFlinger_Mutex) = 0;
77 virtual bool isNonOffloadableGlobalEffectEnabled_l() const
Andy Hungab65b182023-09-06 19:41:47 -070078 REQUIRES(mutex()) EXCLUDES_ThreadBase_Mutex = 0; // Tracks
Andy Hung583043b2023-07-17 17:05:00 -070079 virtual audio_unique_id_t nextUniqueId(audio_unique_id_use_t use) = 0;
80 virtual bool btNrecIsOff() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -070081 virtual float masterVolume_l() const
82 REQUIRES(mutex()) = 0;
83 virtual bool masterMute_l() const
84 REQUIRES(mutex()) = 0;
85 virtual float getMasterBalance_l() const
86 REQUIRES(mutex()) = 0;
87 virtual bool streamMute_l(audio_stream_type_t stream) const
88 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -070089 virtual audio_mode_t getMode() const = 0;
90 virtual bool isLowRamDevice() const = 0;
91 virtual bool isAudioPolicyReady() const = 0; // Effects
Andy Hung1d2d2aea2023-07-19 16:22:58 -070092 virtual uint32_t getScreenState() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -070093 virtual std::optional<media::AudioVibratorInfo> getDefaultVibratorInfo_l() const
94 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -070095 virtual const sp<IAfPatchPanel>& getPatchPanel() const = 0;
96 virtual const sp<MelReporter>& getMelReporter() const = 0;
97 virtual const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() const = 0;
98 virtual sp<IAudioManager> getOrCreateAudioManager() = 0; // Tracks
99
Andy Hung972bec12023-08-31 16:13:39 -0700100 virtual bool updateOrphanEffectChains(const sp<IAfEffectModule>& effect)
101 EXCLUDES_AudioFlinger_Mutex = 0;
102 virtual status_t moveEffectChain_ll(audio_session_t sessionId,
Shunkai Yao517fc2a2024-03-19 04:31:47 +0000103 IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread,
104 IAfEffectChain* srcChain = nullptr)
Andy Hung972bec12023-08-31 16:13:39 -0700105 REQUIRES(mutex(), audio_utils::ThreadBase_Mutex) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700106
107 virtual void requestLogMerge() = 0;
Andy Hung972bec12023-08-31 16:13:39 -0700108 virtual sp<NBLog::Writer> newWriter_l(size_t size, const char *name)
109 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700110 virtual void unregisterWriter(const sp<NBLog::Writer>& writer) = 0;
111
112 virtual sp<audioflinger::SyncEvent> createSyncEvent(AudioSystem::sync_event_t type,
113 audio_session_t triggerSession,
114 audio_session_t listenerSession,
115 const audioflinger::SyncEventCallback& callBack,
Andy Hung972bec12023-08-31 16:13:39 -0700116 const wp<IAfTrackBase>& cookie)
117 EXCLUDES_AudioFlinger_Mutex = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700118
Andy Hungab65b182023-09-06 19:41:47 -0700119 // Hold either AudioFlinger::mutex or ThreadBase::mutex
120 virtual void ioConfigChanged_l(audio_io_config_event_t event,
Andy Hung583043b2023-07-17 17:05:00 -0700121 const sp<AudioIoDescriptor>& ioDesc,
Andy Hung972bec12023-08-31 16:13:39 -0700122 pid_t pid = 0) EXCLUDES_AudioFlinger_ClientMutex = 0;
123 virtual void onNonOffloadableGlobalEffectEnable() EXCLUDES_AudioFlinger_Mutex = 0;
Mikhail Naganovbf203ce2024-05-23 16:27:59 -0700124 virtual void onSupportedLatencyModesChanged(audio_io_handle_t output,
125 const std::vector<audio_latency_mode_t>& modes)
Andy Hung972bec12023-08-31 16:13:39 -0700126 EXCLUDES_AudioFlinger_ClientMutex = 0;
Mikhail Naganovbf203ce2024-05-23 16:27:59 -0700127
128 virtual void onHardError(std::set<audio_port_handle_t>& trackPortIds) = 0;
Atneya Nair5997a652024-06-14 17:24:45 -0700129
130 virtual const ::com::android::media::permission::IPermissionProvider&
131 getPermissionProvider() = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700132};
Andy Hung87c693c2023-07-06 20:56:16 -0700133
Andy Hung440901d2023-06-29 21:19:25 -0700134class IAfThreadBase : public virtual RefBase {
135public:
136 enum type_t {
137 MIXER, // Thread class is MixerThread
138 DIRECT, // Thread class is DirectOutputThread
139 DUPLICATING, // Thread class is DuplicatingThread
140 RECORD, // Thread class is RecordThread
141 OFFLOAD, // Thread class is OffloadThread
142 MMAP_PLAYBACK, // Thread class for MMAP playback stream
143 MMAP_CAPTURE, // Thread class for MMAP capture stream
144 SPATIALIZER, //
145 BIT_PERFECT, // Thread class for BitPerfectThread
146 // When adding a value, also update IAfThreadBase::threadTypeToString()
147 };
148
149 static const char* threadTypeToString(type_t type);
Andy Hung25a80ac2023-07-19 12:47:35 -0700150 static std::string formatToString(audio_format_t format); // compliant for MediaMetrics
Andy Hung81994d62023-07-20 21:44:14 -0700151 static bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask);
152 static bool isValidPcmSinkFormat(audio_format_t format);
153
Andy Hung440901d2023-06-29 21:19:25 -0700154 virtual status_t readyToRun() = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700155 virtual void clearPowerManager() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700156 virtual status_t initCheck() const = 0;
157 virtual type_t type() const = 0;
158 virtual bool isDuplicating() const = 0;
159 virtual audio_io_handle_t id() const = 0;
160 virtual uint32_t sampleRate() const = 0;
161 virtual audio_channel_mask_t channelMask() const = 0;
162 virtual audio_channel_mask_t mixerChannelMask() const = 0;
163 virtual audio_format_t format() const = 0;
164 virtual uint32_t channelCount() const = 0;
165
166 // Called by AudioFlinger::frameCount(audio_io_handle_t output) and effects,
167 // and returns the [normal mix] buffer's frame count.
168 virtual size_t frameCount() const = 0;
169 virtual audio_channel_mask_t hapticChannelMask() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700170 virtual uint32_t hapticChannelCount() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700171 virtual uint32_t latency_l() const = 0; // NO_THREAD_SAFETY_ANALYSIS
172 virtual void setVolumeForOutput_l(float left, float right) const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700173
174 // Return's the HAL's frame count i.e. fast mixer buffer size.
175 virtual size_t frameCountHAL() const = 0;
176 virtual size_t frameSize() const = 0;
177 // Should be "virtual status_t requestExitAndWait()" and override same
178 // method in Thread, but Thread::requestExitAndWait() is not yet virtual.
Andy Hungab65b182023-09-06 19:41:47 -0700179 virtual void exit() EXCLUDES_ThreadBase_Mutex = 0;
180 virtual bool checkForNewParameter_l(const String8& keyValuePair, status_t& status)
181 REQUIRES(mutex()) = 0;
182 virtual status_t setParameters(const String8& keyValuePairs) EXCLUDES_ThreadBase_Mutex = 0;
183 virtual String8 getParameters(const String8& keys) EXCLUDES_ThreadBase_Mutex = 0;
184 virtual void ioConfigChanged_l(
Andy Hung440901d2023-06-29 21:19:25 -0700185 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700186 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE)
187 /* holds either AF::mutex or TB::mutex */ = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700188
189 // sendConfigEvent_l() must be called with ThreadBase::mLock held
190 // Can temporarily release the lock if waiting for a reply from
191 // processConfigEvents_l().
192 // status_t sendConfigEvent_l(sp<ConfigEvent>& event);
193 virtual void sendIoConfigEvent(
194 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700195 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700196 virtual void sendIoConfigEvent_l(
197 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700198 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) REQUIRES(mutex()) = 0;
199 virtual void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp)
200 EXCLUDES_ThreadBase_Mutex = 0;
201 virtual void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio, bool forApp)
202 REQUIRES(mutex()) = 0;
203 virtual status_t sendSetParameterConfigEvent_l(const String8& keyValuePair)
204 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700205 virtual status_t sendCreateAudioPatchConfigEvent(
Andy Hungab65b182023-09-06 19:41:47 -0700206 const struct audio_patch* patch, audio_patch_handle_t* handle)
207 EXCLUDES_ThreadBase_Mutex = 0;
208 virtual status_t sendReleaseAudioPatchConfigEvent(audio_patch_handle_t handle)
209 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700210 virtual status_t sendUpdateOutDeviceConfigEvent(
Andy Hungab65b182023-09-06 19:41:47 -0700211 const DeviceDescriptorBaseVector& outDevices) EXCLUDES_ThreadBase_Mutex = 0;
212 virtual void sendResizeBufferConfigEvent_l(int32_t maxSharedAudioHistoryMs)
213 REQUIRES(mutex()) = 0;
214 virtual void sendCheckOutputStageEffectsEvent() EXCLUDES_ThreadBase_Mutex = 0;
215 virtual void sendCheckOutputStageEffectsEvent_l()
216 REQUIRES(mutex()) = 0;
217 virtual void sendHalLatencyModesChangedEvent_l()
218 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700219
Andy Hungab65b182023-09-06 19:41:47 -0700220 virtual void processConfigEvents_l()
221 REQUIRES(mutex()) = 0;
222 virtual void setCheckOutputStageEffects() = 0; // no mutex needed
223 virtual void cacheParameters_l()
224 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700225 virtual status_t createAudioPatch_l(
Andy Hungab65b182023-09-06 19:41:47 -0700226 const struct audio_patch* patch, audio_patch_handle_t* handle)
227 REQUIRES(mutex()) = 0;
228 virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle)
229 REQUIRES(mutex()) = 0;
230 virtual void updateOutDevices(const DeviceDescriptorBaseVector& outDevices)
231 EXCLUDES_ThreadBase_Mutex = 0;
232 virtual void toAudioPortConfig(struct audio_port_config* config)
233 EXCLUDES_ThreadBase_Mutex = 0;
234 virtual void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs)
235 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700236
237 // see note at declaration of mStandby, mOutDevice and mInDevice
238 virtual bool inStandby() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700239 virtual const DeviceTypeSet outDeviceTypes_l() const REQUIRES(mutex()) = 0;
240 virtual audio_devices_t inDeviceType_l() const REQUIRES(mutex()) = 0;
241 virtual DeviceTypeSet getDeviceTypes_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700242 virtual const AudioDeviceTypeAddrVector& outDeviceTypeAddrs() const = 0;
243 virtual const AudioDeviceTypeAddr& inDeviceTypeAddr() const = 0;
244 virtual bool isOutput() const = 0;
245 virtual bool isOffloadOrMmap() const = 0;
246 virtual sp<StreamHalInterface> stream() const = 0;
247 virtual sp<IAfEffectHandle> createEffect_l(
248 const sp<Client>& client,
249 const sp<media::IEffectClient>& effectClient,
250 int32_t priority,
251 audio_session_t sessionId,
252 effect_descriptor_t* desc,
253 int* enabled,
254 status_t* status /*non-NULL*/,
255 bool pinned,
256 bool probe,
Andy Hung972bec12023-08-31 16:13:39 -0700257 bool notifyFramesProcessed)
Andy Hungab65b182023-09-06 19:41:47 -0700258 REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700259
260 // return values for hasAudioSession (bit field)
261 enum effect_state {
262 EFFECT_SESSION = 0x1, // the audio session corresponds to at least one
263 // effect
264 TRACK_SESSION = 0x2, // the audio session corresponds to at least one
265 // track
266 FAST_SESSION = 0x4, // the audio session corresponds to at least one
267 // fast track
268 SPATIALIZED_SESSION = 0x8, // the audio session corresponds to at least one
269 // spatialized track
270 BIT_PERFECT_SESSION = 0x10 // the audio session corresponds to at least one
271 // bit-perfect track
272 };
273
274 // get effect chain corresponding to session Id.
Andy Hungab65b182023-09-06 19:41:47 -0700275 virtual sp<IAfEffectChain> getEffectChain(audio_session_t sessionId) const
276 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700277 // same as getEffectChain() but must be called with ThreadBase mutex locked
Andy Hungab65b182023-09-06 19:41:47 -0700278 virtual sp<IAfEffectChain> getEffectChain_l(audio_session_t sessionId) const
279 REQUIRES(mutex()) = 0;
280 virtual std::vector<int> getEffectIds_l(audio_session_t sessionId) const
281 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700282 // add an effect chain to the chain list (mEffectChains)
Andy Hungab65b182023-09-06 19:41:47 -0700283 virtual status_t addEffectChain_l(const sp<IAfEffectChain>& chain)
284 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700285 // remove an effect chain from the chain list (mEffectChains)
Andy Hungab65b182023-09-06 19:41:47 -0700286 virtual size_t removeEffectChain_l(const sp<IAfEffectChain>& chain)
287 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700288 // lock all effect chains Mutexes. Must be called before releasing the
289 // ThreadBase mutex before processing the mixer and effects. This guarantees the
290 // integrity of the chains during the process.
291 // Also sets the parameter 'effectChains' to current value of mEffectChains.
Andy Hungab65b182023-09-06 19:41:47 -0700292 virtual void lockEffectChains_l(Vector<sp<IAfEffectChain>>& effectChains)
Shunkai Yaod125e402024-01-20 03:19:06 +0000293 REQUIRES(mutex()) EXCLUDES_EffectChain_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700294 // unlock effect chains after process
Andy Hungab65b182023-09-06 19:41:47 -0700295 virtual void unlockEffectChains(const Vector<sp<IAfEffectChain>>& effectChains)
296 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700297 // get a copy of mEffectChains vector
Andy Hungab65b182023-09-06 19:41:47 -0700298 virtual Vector<sp<IAfEffectChain>> getEffectChains_l() const
299 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700300 // set audio mode to all effect chains
Andy Hungab65b182023-09-06 19:41:47 -0700301 virtual void setMode(audio_mode_t mode)
302 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700303 // get effect module with corresponding ID on specified audio session
Andy Hungab65b182023-09-06 19:41:47 -0700304 virtual sp<IAfEffectModule> getEffect(audio_session_t sessionId, int effectId) const
305 EXCLUDES_ThreadBase_Mutex = 0;
306 virtual sp<IAfEffectModule> getEffect_l(audio_session_t sessionId, int effectId) const
307 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700308 // add and effect module. Also creates the effect chain is none exists for
309 // the effects audio session. Only called in a context of moving an effect
310 // from one thread to another
Andy Hung972bec12023-08-31 16:13:39 -0700311 virtual status_t addEffect_ll(const sp<IAfEffectModule>& effect)
312 REQUIRES(audio_utils::AudioFlinger_Mutex, mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700313 // remove and effect module. Also removes the effect chain is this was the last
314 // effect
Andy Hungab65b182023-09-06 19:41:47 -0700315 virtual void removeEffect_l(const sp<IAfEffectModule>& effect, bool release = false)
316 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700317 // disconnect an effect handle from module and destroy module if last handle
Andy Hungab65b182023-09-06 19:41:47 -0700318 virtual void disconnectEffectHandle(IAfEffectHandle* handle, bool unpinIfLast)
319 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700320 // detach all tracks connected to an auxiliary effect
Andy Hungab65b182023-09-06 19:41:47 -0700321 virtual void detachAuxEffect_l(int effectId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700322 // returns a combination of:
323 // - EFFECT_SESSION if effects on this audio session exist in one chain
324 // - TRACK_SESSION if tracks on this audio session exist
325 // - FAST_SESSION if fast tracks on this audio session exist
326 // - SPATIALIZED_SESSION if spatialized tracks on this audio session exist
Andy Hungab65b182023-09-06 19:41:47 -0700327 virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const REQUIRES(mutex()) = 0;
328 virtual uint32_t hasAudioSession(audio_session_t sessionId) const
329 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700330
331 // the value returned by default implementation is not important as the
332 // strategy is only meaningful for PlaybackThread which implements this method
Andy Hungab65b182023-09-06 19:41:47 -0700333 virtual product_strategy_t getStrategyForSession_l(audio_session_t sessionId) const
334 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700335
336 // check if some effects must be suspended/restored when an effect is enabled
337 // or disabled
338 virtual void checkSuspendOnEffectEnabled(
Andy Hungab65b182023-09-06 19:41:47 -0700339 bool enabled, audio_session_t sessionId, bool threadLocked)
340 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700341
Andy Hungab65b182023-09-06 19:41:47 -0700342 virtual status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event)
343 EXCLUDES_ThreadBase_Mutex = 0;
344 // internally static, perhaps make static member.
Andy Hung440901d2023-06-29 21:19:25 -0700345 virtual bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const = 0;
346
347 // Return a reference to a per-thread heap which can be used to allocate IMemory
348 // objects that will be read-only to client processes, read/write to mediaserver,
349 // and shared by all client processes of the thread.
350 // The heap is per-thread rather than common across all threads, because
351 // clients can't be trusted not to modify the offset of the IMemory they receive.
352 // If a thread does not have such a heap, this method returns 0.
353 virtual sp<MemoryDealer> readOnlyHeap() const = 0;
354
355 virtual sp<IMemory> pipeMemory() const = 0;
356
Andy Hungab65b182023-09-06 19:41:47 -0700357 virtual void systemReady() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700358
359 // checkEffectCompatibility_l() must be called with ThreadBase::mLock held
360 virtual status_t checkEffectCompatibility_l(
Andy Hungab65b182023-09-06 19:41:47 -0700361 const effect_descriptor_t* desc, audio_session_t sessionId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700362
Andy Hungab65b182023-09-06 19:41:47 -0700363 virtual void broadcast_l() REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700364
Andy Hungab65b182023-09-06 19:41:47 -0700365 virtual bool isTimestampCorrectionEnabled_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700366
367 virtual bool isMsdDevice() const = 0;
368
Andy Hungab65b182023-09-06 19:41:47 -0700369 virtual void dump(int fd, const Vector<String16>& args) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700370
371 // deliver stats to mediametrics.
Andy Hungab65b182023-09-06 19:41:47 -0700372 virtual void sendStatistics(bool force) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700373
Andy Hung972bec12023-08-31 16:13:39 -0700374 virtual audio_utils::mutex& mutex() const
375 RETURN_CAPABILITY(audio_utils::ThreadBase_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700376
Andy Hungab65b182023-09-06 19:41:47 -0700377 virtual void onEffectEnable(const sp<IAfEffectModule>& effect) EXCLUDES_ThreadBase_Mutex = 0;
378 virtual void onEffectDisable() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700379
380 // invalidateTracksForAudioSession_l must be called with holding mLock.
Andy Hungab65b182023-09-06 19:41:47 -0700381 virtual void invalidateTracksForAudioSession_l(audio_session_t sessionId) const
382 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700383 // Invalidate all the tracks with the given audio session.
Andy Hungab65b182023-09-06 19:41:47 -0700384 virtual void invalidateTracksForAudioSession(audio_session_t sessionId) const
385 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700386
387 virtual bool isStreamInitialized() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -0700388 virtual void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor)
389 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
390 virtual void stopMelComputation_l()
391 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700392
Andy Hungab65b182023-09-06 19:41:47 -0700393 virtual product_strategy_t getStrategyForStream(audio_stream_type_t stream) const
394 EXCLUDES_AUDIO_ALL = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700395
396 virtual void setEffectSuspended_l(
Andy Hungab65b182023-09-06 19:41:47 -0700397 const effect_uuid_t* type, bool suspend, audio_session_t sessionId)
398 REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700399
Andy Hung6c498e92023-12-05 17:28:17 -0800400 // Wait while the Thread is busy. This is done to ensure that
401 // the Thread is not busy releasing the Tracks, during which the Thread mutex
402 // may be temporarily unlocked. Some Track methods will use this method to
403 // avoid races.
404 virtual void waitWhileThreadBusy_l(audio_utils::unique_lock& ul)
405 REQUIRES(mutex()) = 0;
Andy Hung56ce2ed2024-06-12 16:03:16 -0700406
407 // The ThreadloopExecutor is used to defer functors or dtors
408 // to when the Threadloop does not hold any mutexes (at the end of the
409 // processing period cycle).
410 virtual audio_utils::DeferredExecutor& getThreadloopExecutor() = 0;
411
Andy Hung87c693c2023-07-06 20:56:16 -0700412 // Dynamic cast to derived interface
413 virtual sp<IAfDirectOutputThread> asIAfDirectOutputThread() { return nullptr; }
414 virtual sp<IAfDuplicatingThread> asIAfDuplicatingThread() { return nullptr; }
415 virtual sp<IAfPlaybackThread> asIAfPlaybackThread() { return nullptr; }
416 virtual sp<IAfRecordThread> asIAfRecordThread() { return nullptr; }
Andy Hung583043b2023-07-17 17:05:00 -0700417 virtual IAfThreadCallback* afThreadCallback() const = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700418};
419
Andy Hung87c693c2023-07-06 20:56:16 -0700420class IAfPlaybackThread : public virtual IAfThreadBase, public virtual VolumeInterface {
Andy Hung440901d2023-06-29 21:19:25 -0700421public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700422 static sp<IAfPlaybackThread> createBitPerfectThread(
Andy Hung583043b2023-07-17 17:05:00 -0700423 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
424 audio_io_handle_t id, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700425
426 static sp<IAfPlaybackThread> createDirectOutputThread(
Andy Hung583043b2023-07-17 17:05:00 -0700427 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
428 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700429
430 static sp<IAfPlaybackThread> createMixerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700431 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
432 audio_io_handle_t id, bool systemReady, type_t type = MIXER,
433 audio_config_base_t* mixerConfig = nullptr);
Andy Hungee58e4a2023-07-07 13:47:37 -0700434
435 static sp<IAfPlaybackThread> createOffloadThread(
Andy Hung583043b2023-07-17 17:05:00 -0700436 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
437 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700438
439 static sp<IAfPlaybackThread> createSpatializerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700440 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
441 audio_io_handle_t id, bool systemReady, audio_config_base_t* mixerConfig);
Andy Hungee58e4a2023-07-07 13:47:37 -0700442
Andy Hung87c693c2023-07-06 20:56:16 -0700443 static constexpr int8_t kMaxTrackStopRetriesOffload = 2;
444
Andy Hung440901d2023-06-29 21:19:25 -0700445 enum mixer_state {
446 MIXER_IDLE, // no active tracks
447 MIXER_TRACKS_ENABLED, // at least one active track, but no track has any data ready
448 MIXER_TRACKS_READY, // at least one active track, and at least one track has data
449 MIXER_DRAIN_TRACK, // drain currently playing track
450 MIXER_DRAIN_ALL, // fully drain the hardware
451 // standby mode does not have an enum value
452 // suspend by audio policy manager is orthogonal to mixer state
453 };
454
455 // return estimated latency in milliseconds, as reported by HAL
456 virtual uint32_t latency() const = 0; // should be in IAfThreadBase?
457
Andy Hungab65b182023-09-06 19:41:47 -0700458 virtual uint32_t& fastTrackAvailMask_l() REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700459
Andy Hung440901d2023-06-29 21:19:25 -0700460 virtual sp<IAfTrack> createTrack_l(
461 const sp<Client>& client,
462 audio_stream_type_t streamType,
463 const audio_attributes_t& attr,
464 uint32_t* sampleRate,
465 audio_format_t format,
466 audio_channel_mask_t channelMask,
467 size_t* pFrameCount,
468 size_t* pNotificationFrameCount,
469 uint32_t notificationsPerBuffer,
470 float speed,
471 const sp<IMemory>& sharedBuffer,
472 audio_session_t sessionId,
473 audio_output_flags_t* flags,
474 pid_t creatorPid,
475 const AttributionSourceState& attributionSource,
476 pid_t tid,
477 status_t* status /*non-NULL*/,
478 audio_port_handle_t portId,
479 const sp<media::IAudioTrackCallback>& callback,
480 bool isSpatialized,
jiabin94ed47c2023-07-27 23:34:20 +0000481 bool isBitPerfect,
Pechetty Sravani (xWF)2e077f02024-08-27 01:46:20 +0000482 audio_output_flags_t* afTrackFlags)
Andy Hung972bec12023-08-31 16:13:39 -0700483 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700484
Andy Hungab65b182023-09-06 19:41:47 -0700485 virtual status_t addTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
486 virtual bool destroyTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
487 virtual bool isTrackActive(const sp<IAfTrack>& track) const REQUIRES(mutex()) = 0;
488 virtual void addOutputTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700489
Andy Hungab65b182023-09-06 19:41:47 -0700490 virtual AudioStreamOut* getOutput_l() const REQUIRES(mutex()) = 0;
Andy Hung8d672e02023-09-15 18:19:28 -0700491 virtual AudioStreamOut* getOutput() const EXCLUDES_ThreadBase_Mutex = 0;
492 virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700493
494 // a very large number of suspend() will eventually wraparound, but unlikely
495 virtual void suspend() = 0;
496 virtual void restore() = 0;
497 virtual bool isSuspended() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700498 virtual status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames) const
499 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700500 // Consider also removing and passing an explicit mMainBuffer initialization
501 // parameter to AF::IAfTrack::Track().
502 virtual float* sinkBuffer() const = 0;
503
Andy Hungab65b182023-09-06 19:41:47 -0700504 virtual status_t attachAuxEffect(const sp<IAfTrack>& track, int EffectId)
505 EXCLUDES_ThreadBase_Mutex = 0;
506 virtual status_t attachAuxEffect_l(const sp<IAfTrack>& track, int EffectId)
507 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700508
509 // called with AudioFlinger lock held
Andy Hungab65b182023-09-06 19:41:47 -0700510 virtual bool invalidateTracks_l(audio_stream_type_t streamType) REQUIRES(mutex()) = 0;
511 virtual bool invalidateTracks_l(std::set<audio_port_handle_t>& portIds) REQUIRES(mutex()) = 0;
512 virtual void invalidateTracks(audio_stream_type_t streamType)
513 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700514 // Invalidate tracks by a set of port ids. The port id will be removed from
515 // the given set if the corresponding track is found and invalidated.
Andy Hungab65b182023-09-06 19:41:47 -0700516 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
517 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700518
Andy Hungab65b182023-09-06 19:41:47 -0700519 virtual status_t getTimestamp_l(AudioTimestamp& timestamp) REQUIRES(mutex()) = 0;
520 virtual void addPatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;
521 virtual void deletePatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700522
523 // Return the asynchronous signal wait time.
Andy Hungab65b182023-09-06 19:41:47 -0700524 virtual int64_t computeWaitTimeNs_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700525 // returns true if the track is allowed to be added to the thread.
526 virtual bool isTrackAllowed_l(
527 audio_channel_mask_t channelMask, audio_format_t format, audio_session_t sessionId,
Andy Hungab65b182023-09-06 19:41:47 -0700528 uid_t uid) const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700529
530 virtual bool supportsHapticPlayback() const = 0;
531
Andy Hungab65b182023-09-06 19:41:47 -0700532 virtual void setDownStreamPatch(const struct audio_patch* patch)
533 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700534
Andy Hungab65b182023-09-06 19:41:47 -0700535 virtual IAfTrack* getTrackById_l(audio_port_handle_t trackId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700536
537 virtual bool hasMixer() const = 0;
538
539 virtual status_t setRequestedLatencyMode(audio_latency_mode_t mode) = 0;
540
Andy Hungab65b182023-09-06 19:41:47 -0700541 virtual status_t getSupportedLatencyModes(std::vector<audio_latency_mode_t>* modes)
542 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700543
544 virtual status_t setBluetoothVariableLatencyEnabled(bool enabled) = 0;
545
Andy Hungab65b182023-09-06 19:41:47 -0700546 virtual void setStandby() EXCLUDES_ThreadBase_Mutex = 0;
547 virtual void setStandby_l() REQUIRES(mutex()) = 0;
548 virtual bool waitForHalStart() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700549
550 virtual bool hasFastMixer() const = 0;
551 virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const = 0;
552 virtual const std::atomic<int64_t>& framesWritten() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700553
554 virtual bool usesHwAvSync() const = 0;
jiabin220eea12024-05-17 17:55:20 +0000555
556 virtual void setTracksInternalMute(std::map<audio_port_handle_t, bool>* tracksInternalMute)
557 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700558};
559
560class IAfDirectOutputThread : public virtual IAfPlaybackThread {
561public:
562 virtual status_t selectPresentation(int presentationId, int programId) = 0;
563};
564
565class IAfDuplicatingThread : public virtual IAfPlaybackThread {
566public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700567 static sp<IAfDuplicatingThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700568 const sp<IAfThreadCallback>& afThreadCallback, IAfPlaybackThread* mainThread,
Andy Hungee58e4a2023-07-07 13:47:37 -0700569 audio_io_handle_t id, bool systemReady);
570
Andy Hungab65b182023-09-06 19:41:47 -0700571 virtual void addOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700572 virtual uint32_t waitTimeMs() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700573 virtual void removeOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700574};
575
576class IAfRecordThread : public virtual IAfThreadBase {
577public:
578 static sp<IAfRecordThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700579 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamIn* input,
580 audio_io_handle_t id, bool systemReady);
Andy Hung87c693c2023-07-06 20:56:16 -0700581
582 virtual sp<IAfRecordTrack> createRecordTrack_l(
583 const sp<Client>& client,
584 const audio_attributes_t& attr,
585 uint32_t* pSampleRate,
586 audio_format_t format,
587 audio_channel_mask_t channelMask,
588 size_t* pFrameCount,
589 audio_session_t sessionId,
590 size_t* pNotificationFrameCount,
591 pid_t creatorPid,
592 const AttributionSourceState& attributionSource,
593 audio_input_flags_t* flags,
594 pid_t tid,
595 status_t* status /*non-NULL*/,
596 audio_port_handle_t portId,
Andy Hung972bec12023-08-31 16:13:39 -0700597 int32_t maxSharedAudioHistoryMs)
Andy Hungab65b182023-09-06 19:41:47 -0700598 REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;
599 virtual void destroyTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;
600 virtual void removeTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700601
602 virtual status_t start(
603 IAfRecordTrack* recordTrack, AudioSystem::sync_event_t event,
Andy Hungab65b182023-09-06 19:41:47 -0700604 audio_session_t triggerSession) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700605
606 // ask the thread to stop the specified track, and
607 // return true if the caller should then do it's part of the stopping process
Andy Hungab65b182023-09-06 19:41:47 -0700608 virtual bool stop(IAfRecordTrack* recordTrack) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700609
Andy Hungab65b182023-09-06 19:41:47 -0700610 // NO_THREAD_SAFETY_ANALYSIS: consider atomics
Andy Hung87c693c2023-07-06 20:56:16 -0700611 virtual AudioStreamIn* getInput() const = 0;
612 virtual AudioStreamIn* clearInput() = 0;
613
614 virtual status_t getActiveMicrophones(
Andy Hungab65b182023-09-06 19:41:47 -0700615 std::vector<media::MicrophoneInfoFw>* activeMicrophones)
616 const EXCLUDES_ThreadBase_Mutex = 0;
617 virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction)
618 EXCLUDES_ThreadBase_Mutex = 0;
619 virtual status_t setPreferredMicrophoneFieldDimension(float zoom)
620 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700621
Andy Hungab65b182023-09-06 19:41:47 -0700622 virtual void addPatchTrack(const sp<IAfPatchRecord>& record)
623 EXCLUDES_ThreadBase_Mutex = 0;
624 virtual void deletePatchTrack(const sp<IAfPatchRecord>& record)
625 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700626 virtual bool fastTrackAvailable() const = 0;
627 virtual void setFastTrackAvailable(bool available) = 0;
628
Andy Hungab65b182023-09-06 19:41:47 -0700629 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
630 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700631 virtual bool hasFastCapture() const = 0;
632
Andy Hung3f49ebb2023-09-19 14:48:41 -0700633 virtual void checkBtNrec() EXCLUDES_ThreadBase_Mutex = 0;
634 virtual uint32_t getInputFramesLost() const EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700635
636 virtual status_t shareAudioHistory(
637 const std::string& sharedAudioPackageName,
638 audio_session_t sharedSessionId = AUDIO_SESSION_NONE,
Andy Hungab65b182023-09-06 19:41:47 -0700639 int64_t sharedAudioStartMs = -1) EXCLUDES_ThreadBase_Mutex = 0;
640 virtual void resetAudioHistory_l() REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700641};
642
Andy Hung7aa7d102023-07-07 15:58:48 -0700643class IAfMmapThread : public virtual IAfThreadBase {
644public:
645 // createIAudioTrackAdapter() is a static constructor which creates an
646 // MmapStreamInterface AIDL interface adapter from the MmapThread object that
647 // may be passed back to the client.
648 //
649 // Only one AIDL MmapStreamInterface interface adapter should be created per MmapThread.
650 static sp<MmapStreamInterface> createMmapStreamInterfaceAdapter(
651 const sp<IAfMmapThread>& mmapThread);
652
653 virtual void configure(
654 const audio_attributes_t* attr,
655 audio_stream_type_t streamType,
656 audio_session_t sessionId,
657 const sp<MmapStreamCallback>& callback,
658 audio_port_handle_t deviceId,
Andy Hung3f49ebb2023-09-19 14:48:41 -0700659 audio_port_handle_t portId) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700660 virtual void disconnect() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700661
662 // MmapStreamInterface handling (see adapter)
663 virtual status_t createMmapBuffer(
Andy Hung3f49ebb2023-09-19 14:48:41 -0700664 int32_t minSizeFrames, struct audio_mmap_buffer_info* info)
665 EXCLUDES_ThreadBase_Mutex = 0;
666 virtual status_t getMmapPosition(struct audio_mmap_position* position) const
667 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700668 virtual status_t start(
669 const AudioClient& client, const audio_attributes_t* attr,
Andy Hung3f49ebb2023-09-19 14:48:41 -0700670 audio_port_handle_t* handle) EXCLUDES_ThreadBase_Mutex = 0;
671 virtual status_t stop(audio_port_handle_t handle) EXCLUDES_ThreadBase_Mutex = 0;
672 virtual status_t standby() EXCLUDES_ThreadBase_Mutex = 0;
673 virtual status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const
674 EXCLUDES_ThreadBase_Mutex = 0;
675 virtual status_t reportData(const void* buffer, size_t frameCount)
676 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700677
Andy Hung99b1ba62023-07-14 11:00:08 -0700678 // TODO(b/291317898) move to IAfThreadBase?
Andy Hungab65b182023-09-06 19:41:47 -0700679 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
680 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700681
Andy Hung99b1ba62023-07-14 11:00:08 -0700682 // Sets the UID records silence - TODO(b/291317898) move to IAfMmapCaptureThread
Andy Hungab65b182023-09-06 19:41:47 -0700683 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
684 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700685
686 virtual sp<IAfMmapPlaybackThread> asIAfMmapPlaybackThread() { return nullptr; }
687 virtual sp<IAfMmapCaptureThread> asIAfMmapCaptureThread() { return nullptr; }
688};
689
690class IAfMmapPlaybackThread : public virtual IAfMmapThread, public virtual VolumeInterface {
691public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700692 static sp<IAfMmapPlaybackThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700693 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
694 AudioHwDevice* hwDev, AudioStreamOut* output, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700695
Andy Hungab65b182023-09-06 19:41:47 -0700696 virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700697};
698
699class IAfMmapCaptureThread : public virtual IAfMmapThread {
700public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700701 static sp<IAfMmapCaptureThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700702 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
703 AudioHwDevice* hwDev, AudioStreamIn* input, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700704
Andy Hungab65b182023-09-06 19:41:47 -0700705 virtual AudioStreamIn* clearInput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700706};
707
Andy Hung440901d2023-06-29 21:19:25 -0700708} // namespace android