blob: a7da658305f0918ff1a3de8c93ba418c499dce51 [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
40namespace android {
41
Andy Hung87c693c2023-07-06 20:56:16 -070042class IAfDirectOutputThread;
43class IAfDuplicatingThread;
Andy Hung7aa7d102023-07-07 15:58:48 -070044class IAfMmapCaptureThread;
45class IAfMmapPlaybackThread;
Andy Hung87c693c2023-07-06 20:56:16 -070046class IAfPlaybackThread;
47class IAfRecordThread;
Andy Hungc6f227f2023-07-18 18:31:50 -070048
49class IAfEffectChain;
50class IAfEffectHandle;
51class IAfEffectModule;
52class IAfPatchPanel;
53class IAfPatchRecord;
54class IAfPatchTrack;
55class IAfRecordTrack;
56class IAfTrack;
57class IAfTrackBase;
58class Client;
Andy Hung583043b2023-07-17 17:05:00 -070059class MelReporter;
60
Andy Hung25a80ac2023-07-19 12:47:35 -070061// Used internally for Threads.cpp and AudioFlinger.cpp
62struct stream_type_t {
63 float volume = 1.f;
64 bool mute = false;
65};
66
Andy Hung583043b2023-07-17 17:05:00 -070067// Note this is exposed through IAfThreadBase::afThreadCallback()
68// and hence may be used by the Effect / Track framework.
69class IAfThreadCallback : public virtual RefBase {
70public:
Andy Hung972bec12023-08-31 16:13:39 -070071 virtual audio_utils::mutex& mutex() const
72 RETURN_CAPABILITY(audio_utils::AudioFlinger_Mutex) = 0;
73 virtual bool isNonOffloadableGlobalEffectEnabled_l() const
Andy Hungab65b182023-09-06 19:41:47 -070074 REQUIRES(mutex()) EXCLUDES_ThreadBase_Mutex = 0; // Tracks
Andy Hung583043b2023-07-17 17:05:00 -070075 virtual audio_unique_id_t nextUniqueId(audio_unique_id_use_t use) = 0;
76 virtual bool btNrecIsOff() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -070077 virtual float masterVolume_l() const
78 REQUIRES(mutex()) = 0;
79 virtual bool masterMute_l() const
80 REQUIRES(mutex()) = 0;
81 virtual float getMasterBalance_l() const
82 REQUIRES(mutex()) = 0;
83 virtual bool streamMute_l(audio_stream_type_t stream) const
84 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -070085 virtual audio_mode_t getMode() const = 0;
86 virtual bool isLowRamDevice() const = 0;
87 virtual bool isAudioPolicyReady() const = 0; // Effects
Andy Hung1d2d2aea2023-07-19 16:22:58 -070088 virtual uint32_t getScreenState() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -070089 virtual std::optional<media::AudioVibratorInfo> getDefaultVibratorInfo_l() const
90 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -070091 virtual const sp<IAfPatchPanel>& getPatchPanel() const = 0;
92 virtual const sp<MelReporter>& getMelReporter() const = 0;
93 virtual const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() const = 0;
94 virtual sp<IAudioManager> getOrCreateAudioManager() = 0; // Tracks
95
Andy Hung972bec12023-08-31 16:13:39 -070096 virtual bool updateOrphanEffectChains(const sp<IAfEffectModule>& effect)
97 EXCLUDES_AudioFlinger_Mutex = 0;
98 virtual status_t moveEffectChain_ll(audio_session_t sessionId,
Shunkai Yao517fc2a2024-03-19 04:31:47 +000099 IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread,
100 IAfEffectChain* srcChain = nullptr)
Andy Hung972bec12023-08-31 16:13:39 -0700101 REQUIRES(mutex(), audio_utils::ThreadBase_Mutex) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700102
103 virtual void requestLogMerge() = 0;
Andy Hung972bec12023-08-31 16:13:39 -0700104 virtual sp<NBLog::Writer> newWriter_l(size_t size, const char *name)
105 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700106 virtual void unregisterWriter(const sp<NBLog::Writer>& writer) = 0;
107
108 virtual sp<audioflinger::SyncEvent> createSyncEvent(AudioSystem::sync_event_t type,
109 audio_session_t triggerSession,
110 audio_session_t listenerSession,
111 const audioflinger::SyncEventCallback& callBack,
Andy Hung972bec12023-08-31 16:13:39 -0700112 const wp<IAfTrackBase>& cookie)
113 EXCLUDES_AudioFlinger_Mutex = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700114
Andy Hungab65b182023-09-06 19:41:47 -0700115 // Hold either AudioFlinger::mutex or ThreadBase::mutex
116 virtual void ioConfigChanged_l(audio_io_config_event_t event,
Andy Hung583043b2023-07-17 17:05:00 -0700117 const sp<AudioIoDescriptor>& ioDesc,
Andy Hung972bec12023-08-31 16:13:39 -0700118 pid_t pid = 0) EXCLUDES_AudioFlinger_ClientMutex = 0;
119 virtual void onNonOffloadableGlobalEffectEnable() EXCLUDES_AudioFlinger_Mutex = 0;
Mikhail Naganovbf203ce2024-05-23 16:27:59 -0700120 virtual void onSupportedLatencyModesChanged(audio_io_handle_t output,
121 const std::vector<audio_latency_mode_t>& modes)
Andy Hung972bec12023-08-31 16:13:39 -0700122 EXCLUDES_AudioFlinger_ClientMutex = 0;
Mikhail Naganovbf203ce2024-05-23 16:27:59 -0700123
124 virtual void onHardError(std::set<audio_port_handle_t>& trackPortIds) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700125};
Andy Hung87c693c2023-07-06 20:56:16 -0700126
Andy Hung440901d2023-06-29 21:19:25 -0700127class IAfThreadBase : public virtual RefBase {
128public:
129 enum type_t {
130 MIXER, // Thread class is MixerThread
131 DIRECT, // Thread class is DirectOutputThread
132 DUPLICATING, // Thread class is DuplicatingThread
133 RECORD, // Thread class is RecordThread
134 OFFLOAD, // Thread class is OffloadThread
135 MMAP_PLAYBACK, // Thread class for MMAP playback stream
136 MMAP_CAPTURE, // Thread class for MMAP capture stream
137 SPATIALIZER, //
138 BIT_PERFECT, // Thread class for BitPerfectThread
139 // When adding a value, also update IAfThreadBase::threadTypeToString()
140 };
141
142 static const char* threadTypeToString(type_t type);
Andy Hung25a80ac2023-07-19 12:47:35 -0700143 static std::string formatToString(audio_format_t format); // compliant for MediaMetrics
Andy Hung81994d62023-07-20 21:44:14 -0700144 static bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask);
145 static bool isValidPcmSinkFormat(audio_format_t format);
146
Andy Hung440901d2023-06-29 21:19:25 -0700147 virtual status_t readyToRun() = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700148 virtual void clearPowerManager() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700149 virtual status_t initCheck() const = 0;
150 virtual type_t type() const = 0;
151 virtual bool isDuplicating() const = 0;
152 virtual audio_io_handle_t id() const = 0;
153 virtual uint32_t sampleRate() const = 0;
154 virtual audio_channel_mask_t channelMask() const = 0;
155 virtual audio_channel_mask_t mixerChannelMask() const = 0;
156 virtual audio_format_t format() const = 0;
157 virtual uint32_t channelCount() const = 0;
158
159 // Called by AudioFlinger::frameCount(audio_io_handle_t output) and effects,
160 // and returns the [normal mix] buffer's frame count.
161 virtual size_t frameCount() const = 0;
162 virtual audio_channel_mask_t hapticChannelMask() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700163 virtual uint32_t hapticChannelCount() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700164 virtual uint32_t latency_l() const = 0; // NO_THREAD_SAFETY_ANALYSIS
165 virtual void setVolumeForOutput_l(float left, float right) const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700166
167 // Return's the HAL's frame count i.e. fast mixer buffer size.
168 virtual size_t frameCountHAL() const = 0;
169 virtual size_t frameSize() const = 0;
170 // Should be "virtual status_t requestExitAndWait()" and override same
171 // method in Thread, but Thread::requestExitAndWait() is not yet virtual.
Andy Hungab65b182023-09-06 19:41:47 -0700172 virtual void exit() EXCLUDES_ThreadBase_Mutex = 0;
173 virtual bool checkForNewParameter_l(const String8& keyValuePair, status_t& status)
174 REQUIRES(mutex()) = 0;
175 virtual status_t setParameters(const String8& keyValuePairs) EXCLUDES_ThreadBase_Mutex = 0;
176 virtual String8 getParameters(const String8& keys) EXCLUDES_ThreadBase_Mutex = 0;
177 virtual void ioConfigChanged_l(
Andy Hung440901d2023-06-29 21:19:25 -0700178 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700179 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE)
180 /* holds either AF::mutex or TB::mutex */ = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700181
182 // sendConfigEvent_l() must be called with ThreadBase::mLock held
183 // Can temporarily release the lock if waiting for a reply from
184 // processConfigEvents_l().
185 // status_t sendConfigEvent_l(sp<ConfigEvent>& event);
186 virtual void sendIoConfigEvent(
187 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700188 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700189 virtual void sendIoConfigEvent_l(
190 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700191 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) REQUIRES(mutex()) = 0;
192 virtual void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp)
193 EXCLUDES_ThreadBase_Mutex = 0;
194 virtual void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio, bool forApp)
195 REQUIRES(mutex()) = 0;
196 virtual status_t sendSetParameterConfigEvent_l(const String8& keyValuePair)
197 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700198 virtual status_t sendCreateAudioPatchConfigEvent(
Andy Hungab65b182023-09-06 19:41:47 -0700199 const struct audio_patch* patch, audio_patch_handle_t* handle)
200 EXCLUDES_ThreadBase_Mutex = 0;
201 virtual status_t sendReleaseAudioPatchConfigEvent(audio_patch_handle_t handle)
202 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700203 virtual status_t sendUpdateOutDeviceConfigEvent(
Andy Hungab65b182023-09-06 19:41:47 -0700204 const DeviceDescriptorBaseVector& outDevices) EXCLUDES_ThreadBase_Mutex = 0;
205 virtual void sendResizeBufferConfigEvent_l(int32_t maxSharedAudioHistoryMs)
206 REQUIRES(mutex()) = 0;
207 virtual void sendCheckOutputStageEffectsEvent() EXCLUDES_ThreadBase_Mutex = 0;
208 virtual void sendCheckOutputStageEffectsEvent_l()
209 REQUIRES(mutex()) = 0;
210 virtual void sendHalLatencyModesChangedEvent_l()
211 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700212
Andy Hungab65b182023-09-06 19:41:47 -0700213 virtual void processConfigEvents_l()
214 REQUIRES(mutex()) = 0;
215 virtual void setCheckOutputStageEffects() = 0; // no mutex needed
216 virtual void cacheParameters_l()
217 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700218 virtual status_t createAudioPatch_l(
Andy Hungab65b182023-09-06 19:41:47 -0700219 const struct audio_patch* patch, audio_patch_handle_t* handle)
220 REQUIRES(mutex()) = 0;
221 virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle)
222 REQUIRES(mutex()) = 0;
223 virtual void updateOutDevices(const DeviceDescriptorBaseVector& outDevices)
224 EXCLUDES_ThreadBase_Mutex = 0;
225 virtual void toAudioPortConfig(struct audio_port_config* config)
226 EXCLUDES_ThreadBase_Mutex = 0;
227 virtual void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs)
228 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700229
230 // see note at declaration of mStandby, mOutDevice and mInDevice
231 virtual bool inStandby() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700232 virtual const DeviceTypeSet outDeviceTypes_l() const REQUIRES(mutex()) = 0;
233 virtual audio_devices_t inDeviceType_l() const REQUIRES(mutex()) = 0;
234 virtual DeviceTypeSet getDeviceTypes_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700235 virtual const AudioDeviceTypeAddrVector& outDeviceTypeAddrs() const = 0;
236 virtual const AudioDeviceTypeAddr& inDeviceTypeAddr() const = 0;
237 virtual bool isOutput() const = 0;
238 virtual bool isOffloadOrMmap() const = 0;
239 virtual sp<StreamHalInterface> stream() const = 0;
240 virtual sp<IAfEffectHandle> createEffect_l(
241 const sp<Client>& client,
242 const sp<media::IEffectClient>& effectClient,
243 int32_t priority,
244 audio_session_t sessionId,
245 effect_descriptor_t* desc,
246 int* enabled,
247 status_t* status /*non-NULL*/,
248 bool pinned,
249 bool probe,
Andy Hung972bec12023-08-31 16:13:39 -0700250 bool notifyFramesProcessed)
Andy Hungab65b182023-09-06 19:41:47 -0700251 REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700252
253 // return values for hasAudioSession (bit field)
254 enum effect_state {
255 EFFECT_SESSION = 0x1, // the audio session corresponds to at least one
256 // effect
257 TRACK_SESSION = 0x2, // the audio session corresponds to at least one
258 // track
259 FAST_SESSION = 0x4, // the audio session corresponds to at least one
260 // fast track
261 SPATIALIZED_SESSION = 0x8, // the audio session corresponds to at least one
262 // spatialized track
263 BIT_PERFECT_SESSION = 0x10 // the audio session corresponds to at least one
264 // bit-perfect track
265 };
266
267 // get effect chain corresponding to session Id.
Andy Hungab65b182023-09-06 19:41:47 -0700268 virtual sp<IAfEffectChain> getEffectChain(audio_session_t sessionId) const
269 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700270 // same as getEffectChain() but must be called with ThreadBase mutex locked
Andy Hungab65b182023-09-06 19:41:47 -0700271 virtual sp<IAfEffectChain> getEffectChain_l(audio_session_t sessionId) const
272 REQUIRES(mutex()) = 0;
273 virtual std::vector<int> getEffectIds_l(audio_session_t sessionId) const
274 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700275 // add an effect chain to the chain list (mEffectChains)
Andy Hungab65b182023-09-06 19:41:47 -0700276 virtual status_t addEffectChain_l(const sp<IAfEffectChain>& chain)
277 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700278 // remove an effect chain from the chain list (mEffectChains)
Andy Hungab65b182023-09-06 19:41:47 -0700279 virtual size_t removeEffectChain_l(const sp<IAfEffectChain>& chain)
280 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700281 // lock all effect chains Mutexes. Must be called before releasing the
282 // ThreadBase mutex before processing the mixer and effects. This guarantees the
283 // integrity of the chains during the process.
284 // Also sets the parameter 'effectChains' to current value of mEffectChains.
Andy Hungab65b182023-09-06 19:41:47 -0700285 virtual void lockEffectChains_l(Vector<sp<IAfEffectChain>>& effectChains)
Shunkai Yaod125e402024-01-20 03:19:06 +0000286 REQUIRES(mutex()) EXCLUDES_EffectChain_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700287 // unlock effect chains after process
Andy Hungab65b182023-09-06 19:41:47 -0700288 virtual void unlockEffectChains(const Vector<sp<IAfEffectChain>>& effectChains)
289 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700290 // get a copy of mEffectChains vector
Andy Hungab65b182023-09-06 19:41:47 -0700291 virtual Vector<sp<IAfEffectChain>> getEffectChains_l() const
292 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700293 // set audio mode to all effect chains
Andy Hungab65b182023-09-06 19:41:47 -0700294 virtual void setMode(audio_mode_t mode)
295 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700296 // get effect module with corresponding ID on specified audio session
Andy Hungab65b182023-09-06 19:41:47 -0700297 virtual sp<IAfEffectModule> getEffect(audio_session_t sessionId, int effectId) const
298 EXCLUDES_ThreadBase_Mutex = 0;
299 virtual sp<IAfEffectModule> getEffect_l(audio_session_t sessionId, int effectId) const
300 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700301 // add and effect module. Also creates the effect chain is none exists for
302 // the effects audio session. Only called in a context of moving an effect
303 // from one thread to another
Andy Hung972bec12023-08-31 16:13:39 -0700304 virtual status_t addEffect_ll(const sp<IAfEffectModule>& effect)
305 REQUIRES(audio_utils::AudioFlinger_Mutex, mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700306 // remove and effect module. Also removes the effect chain is this was the last
307 // effect
Andy Hungab65b182023-09-06 19:41:47 -0700308 virtual void removeEffect_l(const sp<IAfEffectModule>& effect, bool release = false)
309 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700310 // disconnect an effect handle from module and destroy module if last handle
Andy Hungab65b182023-09-06 19:41:47 -0700311 virtual void disconnectEffectHandle(IAfEffectHandle* handle, bool unpinIfLast)
312 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700313 // detach all tracks connected to an auxiliary effect
Andy Hungab65b182023-09-06 19:41:47 -0700314 virtual void detachAuxEffect_l(int effectId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700315 // returns a combination of:
316 // - EFFECT_SESSION if effects on this audio session exist in one chain
317 // - TRACK_SESSION if tracks on this audio session exist
318 // - FAST_SESSION if fast tracks on this audio session exist
319 // - SPATIALIZED_SESSION if spatialized tracks on this audio session exist
Andy Hungab65b182023-09-06 19:41:47 -0700320 virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const REQUIRES(mutex()) = 0;
321 virtual uint32_t hasAudioSession(audio_session_t sessionId) const
322 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700323
324 // the value returned by default implementation is not important as the
325 // strategy is only meaningful for PlaybackThread which implements this method
Andy Hungab65b182023-09-06 19:41:47 -0700326 virtual product_strategy_t getStrategyForSession_l(audio_session_t sessionId) const
327 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700328
329 // check if some effects must be suspended/restored when an effect is enabled
330 // or disabled
331 virtual void checkSuspendOnEffectEnabled(
Andy Hungab65b182023-09-06 19:41:47 -0700332 bool enabled, audio_session_t sessionId, bool threadLocked)
333 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700334
Andy Hungab65b182023-09-06 19:41:47 -0700335 virtual status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event)
336 EXCLUDES_ThreadBase_Mutex = 0;
337 // internally static, perhaps make static member.
Andy Hung440901d2023-06-29 21:19:25 -0700338 virtual bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const = 0;
339
340 // Return a reference to a per-thread heap which can be used to allocate IMemory
341 // objects that will be read-only to client processes, read/write to mediaserver,
342 // and shared by all client processes of the thread.
343 // The heap is per-thread rather than common across all threads, because
344 // clients can't be trusted not to modify the offset of the IMemory they receive.
345 // If a thread does not have such a heap, this method returns 0.
346 virtual sp<MemoryDealer> readOnlyHeap() const = 0;
347
348 virtual sp<IMemory> pipeMemory() const = 0;
349
Andy Hungab65b182023-09-06 19:41:47 -0700350 virtual void systemReady() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700351
352 // checkEffectCompatibility_l() must be called with ThreadBase::mLock held
353 virtual status_t checkEffectCompatibility_l(
Andy Hungab65b182023-09-06 19:41:47 -0700354 const effect_descriptor_t* desc, audio_session_t sessionId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700355
Andy Hungab65b182023-09-06 19:41:47 -0700356 virtual void broadcast_l() REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700357
Andy Hungab65b182023-09-06 19:41:47 -0700358 virtual bool isTimestampCorrectionEnabled_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700359
360 virtual bool isMsdDevice() const = 0;
361
Andy Hungab65b182023-09-06 19:41:47 -0700362 virtual void dump(int fd, const Vector<String16>& args) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700363
364 // deliver stats to mediametrics.
Andy Hungab65b182023-09-06 19:41:47 -0700365 virtual void sendStatistics(bool force) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700366
Andy Hung972bec12023-08-31 16:13:39 -0700367 virtual audio_utils::mutex& mutex() const
368 RETURN_CAPABILITY(audio_utils::ThreadBase_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700369
Andy Hungab65b182023-09-06 19:41:47 -0700370 virtual void onEffectEnable(const sp<IAfEffectModule>& effect) EXCLUDES_ThreadBase_Mutex = 0;
371 virtual void onEffectDisable() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700372
373 // invalidateTracksForAudioSession_l must be called with holding mLock.
Andy Hungab65b182023-09-06 19:41:47 -0700374 virtual void invalidateTracksForAudioSession_l(audio_session_t sessionId) const
375 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700376 // Invalidate all the tracks with the given audio session.
Andy Hungab65b182023-09-06 19:41:47 -0700377 virtual void invalidateTracksForAudioSession(audio_session_t sessionId) const
378 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700379
380 virtual bool isStreamInitialized() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -0700381 virtual void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor)
382 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
383 virtual void stopMelComputation_l()
384 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700385
Andy Hungab65b182023-09-06 19:41:47 -0700386 virtual product_strategy_t getStrategyForStream(audio_stream_type_t stream) const
387 EXCLUDES_AUDIO_ALL = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700388
389 virtual void setEffectSuspended_l(
Andy Hungab65b182023-09-06 19:41:47 -0700390 const effect_uuid_t* type, bool suspend, audio_session_t sessionId)
391 REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700392
Andy Hung6c498e92023-12-05 17:28:17 -0800393 // Wait while the Thread is busy. This is done to ensure that
394 // the Thread is not busy releasing the Tracks, during which the Thread mutex
395 // may be temporarily unlocked. Some Track methods will use this method to
396 // avoid races.
397 virtual void waitWhileThreadBusy_l(audio_utils::unique_lock& ul)
398 REQUIRES(mutex()) = 0;
Andy Hung56ce2ed2024-06-12 16:03:16 -0700399
400 // The ThreadloopExecutor is used to defer functors or dtors
401 // to when the Threadloop does not hold any mutexes (at the end of the
402 // processing period cycle).
403 virtual audio_utils::DeferredExecutor& getThreadloopExecutor() = 0;
404
Andy Hung87c693c2023-07-06 20:56:16 -0700405 // Dynamic cast to derived interface
406 virtual sp<IAfDirectOutputThread> asIAfDirectOutputThread() { return nullptr; }
407 virtual sp<IAfDuplicatingThread> asIAfDuplicatingThread() { return nullptr; }
408 virtual sp<IAfPlaybackThread> asIAfPlaybackThread() { return nullptr; }
409 virtual sp<IAfRecordThread> asIAfRecordThread() { return nullptr; }
Andy Hung583043b2023-07-17 17:05:00 -0700410 virtual IAfThreadCallback* afThreadCallback() const = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700411};
412
Andy Hung87c693c2023-07-06 20:56:16 -0700413class IAfPlaybackThread : public virtual IAfThreadBase, public virtual VolumeInterface {
Andy Hung440901d2023-06-29 21:19:25 -0700414public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700415 static sp<IAfPlaybackThread> createBitPerfectThread(
Andy Hung583043b2023-07-17 17:05:00 -0700416 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
417 audio_io_handle_t id, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700418
419 static sp<IAfPlaybackThread> createDirectOutputThread(
Andy Hung583043b2023-07-17 17:05:00 -0700420 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
421 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700422
423 static sp<IAfPlaybackThread> createMixerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700424 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
425 audio_io_handle_t id, bool systemReady, type_t type = MIXER,
426 audio_config_base_t* mixerConfig = nullptr);
Andy Hungee58e4a2023-07-07 13:47:37 -0700427
428 static sp<IAfPlaybackThread> createOffloadThread(
Andy Hung583043b2023-07-17 17:05:00 -0700429 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
430 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700431
432 static sp<IAfPlaybackThread> createSpatializerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700433 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
434 audio_io_handle_t id, bool systemReady, audio_config_base_t* mixerConfig);
Andy Hungee58e4a2023-07-07 13:47:37 -0700435
Andy Hung87c693c2023-07-06 20:56:16 -0700436 static constexpr int8_t kMaxTrackStopRetriesOffload = 2;
437
Andy Hung440901d2023-06-29 21:19:25 -0700438 enum mixer_state {
439 MIXER_IDLE, // no active tracks
440 MIXER_TRACKS_ENABLED, // at least one active track, but no track has any data ready
441 MIXER_TRACKS_READY, // at least one active track, and at least one track has data
442 MIXER_DRAIN_TRACK, // drain currently playing track
443 MIXER_DRAIN_ALL, // fully drain the hardware
444 // standby mode does not have an enum value
445 // suspend by audio policy manager is orthogonal to mixer state
446 };
447
448 // return estimated latency in milliseconds, as reported by HAL
449 virtual uint32_t latency() const = 0; // should be in IAfThreadBase?
450
Andy Hungab65b182023-09-06 19:41:47 -0700451 virtual uint32_t& fastTrackAvailMask_l() REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700452
Andy Hung440901d2023-06-29 21:19:25 -0700453 virtual sp<IAfTrack> createTrack_l(
454 const sp<Client>& client,
455 audio_stream_type_t streamType,
456 const audio_attributes_t& attr,
457 uint32_t* sampleRate,
458 audio_format_t format,
459 audio_channel_mask_t channelMask,
460 size_t* pFrameCount,
461 size_t* pNotificationFrameCount,
462 uint32_t notificationsPerBuffer,
463 float speed,
464 const sp<IMemory>& sharedBuffer,
465 audio_session_t sessionId,
466 audio_output_flags_t* flags,
467 pid_t creatorPid,
468 const AttributionSourceState& attributionSource,
469 pid_t tid,
470 status_t* status /*non-NULL*/,
471 audio_port_handle_t portId,
472 const sp<media::IAudioTrackCallback>& callback,
473 bool isSpatialized,
jiabin94ed47c2023-07-27 23:34:20 +0000474 bool isBitPerfect,
Andy Hung972bec12023-08-31 16:13:39 -0700475 audio_output_flags_t* afTrackFlags)
476 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700477
Andy Hungab65b182023-09-06 19:41:47 -0700478 virtual status_t addTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
479 virtual bool destroyTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
480 virtual bool isTrackActive(const sp<IAfTrack>& track) const REQUIRES(mutex()) = 0;
481 virtual void addOutputTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700482
Andy Hungab65b182023-09-06 19:41:47 -0700483 virtual AudioStreamOut* getOutput_l() const REQUIRES(mutex()) = 0;
Andy Hung8d672e02023-09-15 18:19:28 -0700484 virtual AudioStreamOut* getOutput() const EXCLUDES_ThreadBase_Mutex = 0;
485 virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700486
487 // a very large number of suspend() will eventually wraparound, but unlikely
488 virtual void suspend() = 0;
489 virtual void restore() = 0;
490 virtual bool isSuspended() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700491 virtual status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames) const
492 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700493 // Consider also removing and passing an explicit mMainBuffer initialization
494 // parameter to AF::IAfTrack::Track().
495 virtual float* sinkBuffer() const = 0;
496
Andy Hungab65b182023-09-06 19:41:47 -0700497 virtual status_t attachAuxEffect(const sp<IAfTrack>& track, int EffectId)
498 EXCLUDES_ThreadBase_Mutex = 0;
499 virtual status_t attachAuxEffect_l(const sp<IAfTrack>& track, int EffectId)
500 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700501
502 // called with AudioFlinger lock held
Andy Hungab65b182023-09-06 19:41:47 -0700503 virtual bool invalidateTracks_l(audio_stream_type_t streamType) REQUIRES(mutex()) = 0;
504 virtual bool invalidateTracks_l(std::set<audio_port_handle_t>& portIds) REQUIRES(mutex()) = 0;
505 virtual void invalidateTracks(audio_stream_type_t streamType)
506 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700507 // Invalidate tracks by a set of port ids. The port id will be removed from
508 // the given set if the corresponding track is found and invalidated.
Andy Hungab65b182023-09-06 19:41:47 -0700509 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
510 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700511
Andy Hungab65b182023-09-06 19:41:47 -0700512 virtual status_t getTimestamp_l(AudioTimestamp& timestamp) REQUIRES(mutex()) = 0;
513 virtual void addPatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;
514 virtual void deletePatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700515
516 // Return the asynchronous signal wait time.
Andy Hungab65b182023-09-06 19:41:47 -0700517 virtual int64_t computeWaitTimeNs_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700518 // returns true if the track is allowed to be added to the thread.
519 virtual bool isTrackAllowed_l(
520 audio_channel_mask_t channelMask, audio_format_t format, audio_session_t sessionId,
Andy Hungab65b182023-09-06 19:41:47 -0700521 uid_t uid) const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700522
523 virtual bool supportsHapticPlayback() const = 0;
524
Andy Hungab65b182023-09-06 19:41:47 -0700525 virtual void setDownStreamPatch(const struct audio_patch* patch)
526 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700527
Andy Hungab65b182023-09-06 19:41:47 -0700528 virtual IAfTrack* getTrackById_l(audio_port_handle_t trackId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700529
530 virtual bool hasMixer() const = 0;
531
532 virtual status_t setRequestedLatencyMode(audio_latency_mode_t mode) = 0;
533
Andy Hungab65b182023-09-06 19:41:47 -0700534 virtual status_t getSupportedLatencyModes(std::vector<audio_latency_mode_t>* modes)
535 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700536
537 virtual status_t setBluetoothVariableLatencyEnabled(bool enabled) = 0;
538
Andy Hungab65b182023-09-06 19:41:47 -0700539 virtual void setStandby() EXCLUDES_ThreadBase_Mutex = 0;
540 virtual void setStandby_l() REQUIRES(mutex()) = 0;
541 virtual bool waitForHalStart() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700542
543 virtual bool hasFastMixer() const = 0;
544 virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const = 0;
545 virtual const std::atomic<int64_t>& framesWritten() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700546
547 virtual bool usesHwAvSync() const = 0;
jiabin220eea12024-05-17 17:55:20 +0000548
549 virtual void setTracksInternalMute(std::map<audio_port_handle_t, bool>* tracksInternalMute)
550 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700551};
552
553class IAfDirectOutputThread : public virtual IAfPlaybackThread {
554public:
555 virtual status_t selectPresentation(int presentationId, int programId) = 0;
556};
557
558class IAfDuplicatingThread : public virtual IAfPlaybackThread {
559public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700560 static sp<IAfDuplicatingThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700561 const sp<IAfThreadCallback>& afThreadCallback, IAfPlaybackThread* mainThread,
Andy Hungee58e4a2023-07-07 13:47:37 -0700562 audio_io_handle_t id, bool systemReady);
563
Andy Hungab65b182023-09-06 19:41:47 -0700564 virtual void addOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700565 virtual uint32_t waitTimeMs() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700566 virtual void removeOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700567};
568
569class IAfRecordThread : public virtual IAfThreadBase {
570public:
571 static sp<IAfRecordThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700572 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamIn* input,
573 audio_io_handle_t id, bool systemReady);
Andy Hung87c693c2023-07-06 20:56:16 -0700574
575 virtual sp<IAfRecordTrack> createRecordTrack_l(
576 const sp<Client>& client,
577 const audio_attributes_t& attr,
578 uint32_t* pSampleRate,
579 audio_format_t format,
580 audio_channel_mask_t channelMask,
581 size_t* pFrameCount,
582 audio_session_t sessionId,
583 size_t* pNotificationFrameCount,
584 pid_t creatorPid,
585 const AttributionSourceState& attributionSource,
586 audio_input_flags_t* flags,
587 pid_t tid,
588 status_t* status /*non-NULL*/,
589 audio_port_handle_t portId,
Andy Hung972bec12023-08-31 16:13:39 -0700590 int32_t maxSharedAudioHistoryMs)
Andy Hungab65b182023-09-06 19:41:47 -0700591 REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;
592 virtual void destroyTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;
593 virtual void removeTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700594
595 virtual status_t start(
596 IAfRecordTrack* recordTrack, AudioSystem::sync_event_t event,
Andy Hungab65b182023-09-06 19:41:47 -0700597 audio_session_t triggerSession) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700598
599 // ask the thread to stop the specified track, and
600 // return true if the caller should then do it's part of the stopping process
Andy Hungab65b182023-09-06 19:41:47 -0700601 virtual bool stop(IAfRecordTrack* recordTrack) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700602
Andy Hungab65b182023-09-06 19:41:47 -0700603 // NO_THREAD_SAFETY_ANALYSIS: consider atomics
Andy Hung87c693c2023-07-06 20:56:16 -0700604 virtual AudioStreamIn* getInput() const = 0;
605 virtual AudioStreamIn* clearInput() = 0;
606
607 virtual status_t getActiveMicrophones(
Andy Hungab65b182023-09-06 19:41:47 -0700608 std::vector<media::MicrophoneInfoFw>* activeMicrophones)
609 const EXCLUDES_ThreadBase_Mutex = 0;
610 virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction)
611 EXCLUDES_ThreadBase_Mutex = 0;
612 virtual status_t setPreferredMicrophoneFieldDimension(float zoom)
613 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700614
Andy Hungab65b182023-09-06 19:41:47 -0700615 virtual void addPatchTrack(const sp<IAfPatchRecord>& record)
616 EXCLUDES_ThreadBase_Mutex = 0;
617 virtual void deletePatchTrack(const sp<IAfPatchRecord>& record)
618 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700619 virtual bool fastTrackAvailable() const = 0;
620 virtual void setFastTrackAvailable(bool available) = 0;
621
Andy Hungab65b182023-09-06 19:41:47 -0700622 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
623 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700624 virtual bool hasFastCapture() const = 0;
625
Andy Hung3f49ebb2023-09-19 14:48:41 -0700626 virtual void checkBtNrec() EXCLUDES_ThreadBase_Mutex = 0;
627 virtual uint32_t getInputFramesLost() const EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700628
629 virtual status_t shareAudioHistory(
630 const std::string& sharedAudioPackageName,
631 audio_session_t sharedSessionId = AUDIO_SESSION_NONE,
Andy Hungab65b182023-09-06 19:41:47 -0700632 int64_t sharedAudioStartMs = -1) EXCLUDES_ThreadBase_Mutex = 0;
633 virtual void resetAudioHistory_l() REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700634};
635
Andy Hung7aa7d102023-07-07 15:58:48 -0700636class IAfMmapThread : public virtual IAfThreadBase {
637public:
638 // createIAudioTrackAdapter() is a static constructor which creates an
639 // MmapStreamInterface AIDL interface adapter from the MmapThread object that
640 // may be passed back to the client.
641 //
642 // Only one AIDL MmapStreamInterface interface adapter should be created per MmapThread.
643 static sp<MmapStreamInterface> createMmapStreamInterfaceAdapter(
644 const sp<IAfMmapThread>& mmapThread);
645
646 virtual void configure(
647 const audio_attributes_t* attr,
648 audio_stream_type_t streamType,
649 audio_session_t sessionId,
650 const sp<MmapStreamCallback>& callback,
651 audio_port_handle_t deviceId,
Andy Hung3f49ebb2023-09-19 14:48:41 -0700652 audio_port_handle_t portId) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700653 virtual void disconnect() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700654
655 // MmapStreamInterface handling (see adapter)
656 virtual status_t createMmapBuffer(
Andy Hung3f49ebb2023-09-19 14:48:41 -0700657 int32_t minSizeFrames, struct audio_mmap_buffer_info* info)
658 EXCLUDES_ThreadBase_Mutex = 0;
659 virtual status_t getMmapPosition(struct audio_mmap_position* position) const
660 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700661 virtual status_t start(
662 const AudioClient& client, const audio_attributes_t* attr,
Andy Hung3f49ebb2023-09-19 14:48:41 -0700663 audio_port_handle_t* handle) EXCLUDES_ThreadBase_Mutex = 0;
664 virtual status_t stop(audio_port_handle_t handle) EXCLUDES_ThreadBase_Mutex = 0;
665 virtual status_t standby() EXCLUDES_ThreadBase_Mutex = 0;
666 virtual status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const
667 EXCLUDES_ThreadBase_Mutex = 0;
668 virtual status_t reportData(const void* buffer, size_t frameCount)
669 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700670
Andy Hung99b1ba62023-07-14 11:00:08 -0700671 // TODO(b/291317898) move to IAfThreadBase?
Andy Hungab65b182023-09-06 19:41:47 -0700672 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
673 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700674
Andy Hung99b1ba62023-07-14 11:00:08 -0700675 // Sets the UID records silence - TODO(b/291317898) move to IAfMmapCaptureThread
Andy Hungab65b182023-09-06 19:41:47 -0700676 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
677 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700678
679 virtual sp<IAfMmapPlaybackThread> asIAfMmapPlaybackThread() { return nullptr; }
680 virtual sp<IAfMmapCaptureThread> asIAfMmapCaptureThread() { return nullptr; }
681};
682
683class IAfMmapPlaybackThread : public virtual IAfMmapThread, public virtual VolumeInterface {
684public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700685 static sp<IAfMmapPlaybackThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700686 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
687 AudioHwDevice* hwDev, AudioStreamOut* output, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700688
Andy Hungab65b182023-09-06 19:41:47 -0700689 virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700690};
691
692class IAfMmapCaptureThread : public virtual IAfMmapThread {
693public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700694 static sp<IAfMmapCaptureThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700695 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
696 AudioHwDevice* hwDev, AudioStreamIn* input, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700697
Andy Hungab65b182023-09-06 19:41:47 -0700698 virtual AudioStreamIn* clearInput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700699};
700
Andy Hung440901d2023-06-29 21:19:25 -0700701} // namespace android