blob: c7444ad17627874ecf80141e50a8dd884f79995f [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 Hung954b9712023-08-28 18:36:53 -070022#include <audio_utils/mutex.h>
Andy Hungc6f227f2023-07-18 18:31:50 -070023#include <audio_utils/MelProcessor.h>
24#include <binder/MemoryDealer.h>
25#include <datapath/AudioStreamIn.h>
26#include <datapath/AudioStreamOut.h>
27#include <datapath/VolumeInterface.h>
28#include <fastpath/FastMixerDumpState.h>
29#include <media/DeviceDescriptorBase.h>
30#include <media/MmapStreamInterface.h>
31#include <media/audiohal/StreamHalInterface.h>
32#include <media/nblog/NBLog.h>
33#include <timing/SyncEvent.h>
Andy Hungc6f227f2023-07-18 18:31:50 -070034#include <utils/RefBase.h>
35#include <vibrator/ExternalVibration.h>
36
37#include <optional>
Andy Hung440901d2023-06-29 21:19:25 -070038
39namespace android {
40
Andy Hung87c693c2023-07-06 20:56:16 -070041class IAfDirectOutputThread;
42class IAfDuplicatingThread;
Andy Hung7aa7d102023-07-07 15:58:48 -070043class IAfMmapCaptureThread;
44class IAfMmapPlaybackThread;
Andy Hung87c693c2023-07-06 20:56:16 -070045class IAfPlaybackThread;
46class IAfRecordThread;
Andy Hungc6f227f2023-07-18 18:31:50 -070047
48class IAfEffectChain;
49class IAfEffectHandle;
50class IAfEffectModule;
51class IAfPatchPanel;
52class IAfPatchRecord;
53class IAfPatchTrack;
54class IAfRecordTrack;
55class IAfTrack;
56class IAfTrackBase;
57class Client;
Andy Hung583043b2023-07-17 17:05:00 -070058class MelReporter;
59
Andy Hung25a80ac2023-07-19 12:47:35 -070060// Used internally for Threads.cpp and AudioFlinger.cpp
61struct stream_type_t {
62 float volume = 1.f;
63 bool mute = false;
64};
65
Andy Hung583043b2023-07-17 17:05:00 -070066// Note this is exposed through IAfThreadBase::afThreadCallback()
67// and hence may be used by the Effect / Track framework.
68class IAfThreadCallback : public virtual RefBase {
69public:
Andy Hung972bec12023-08-31 16:13:39 -070070 virtual audio_utils::mutex& mutex() const
71 RETURN_CAPABILITY(audio_utils::AudioFlinger_Mutex) = 0;
72 virtual bool isNonOffloadableGlobalEffectEnabled_l() const
Andy Hungab65b182023-09-06 19:41:47 -070073 REQUIRES(mutex()) EXCLUDES_ThreadBase_Mutex = 0; // Tracks
Andy Hung583043b2023-07-17 17:05:00 -070074 virtual audio_unique_id_t nextUniqueId(audio_unique_id_use_t use) = 0;
75 virtual bool btNrecIsOff() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -070076 virtual float masterVolume_l() const
77 REQUIRES(mutex()) = 0;
78 virtual bool masterMute_l() const
79 REQUIRES(mutex()) = 0;
80 virtual float getMasterBalance_l() const
81 REQUIRES(mutex()) = 0;
82 virtual bool streamMute_l(audio_stream_type_t stream) const
83 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -070084 virtual audio_mode_t getMode() const = 0;
85 virtual bool isLowRamDevice() const = 0;
86 virtual bool isAudioPolicyReady() const = 0; // Effects
Andy Hung1d2d2aea2023-07-19 16:22:58 -070087 virtual uint32_t getScreenState() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -070088 virtual std::optional<media::AudioVibratorInfo> getDefaultVibratorInfo_l() const
89 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -070090 virtual const sp<IAfPatchPanel>& getPatchPanel() const = 0;
91 virtual const sp<MelReporter>& getMelReporter() const = 0;
92 virtual const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() const = 0;
93 virtual sp<IAudioManager> getOrCreateAudioManager() = 0; // Tracks
94
Andy Hung972bec12023-08-31 16:13:39 -070095 virtual bool updateOrphanEffectChains(const sp<IAfEffectModule>& effect)
96 EXCLUDES_AudioFlinger_Mutex = 0;
97 virtual status_t moveEffectChain_ll(audio_session_t sessionId,
Francois Gaffie2b229cd2021-11-22 18:20:16 +010098 IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread,
99 IAfEffectChain* srcChain = nullptr)
Andy Hung972bec12023-08-31 16:13:39 -0700100 REQUIRES(mutex(), audio_utils::ThreadBase_Mutex) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700101
102 virtual void requestLogMerge() = 0;
Andy Hung972bec12023-08-31 16:13:39 -0700103 virtual sp<NBLog::Writer> newWriter_l(size_t size, const char *name)
104 REQUIRES(mutex()) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700105 virtual void unregisterWriter(const sp<NBLog::Writer>& writer) = 0;
106
107 virtual sp<audioflinger::SyncEvent> createSyncEvent(AudioSystem::sync_event_t type,
108 audio_session_t triggerSession,
109 audio_session_t listenerSession,
110 const audioflinger::SyncEventCallback& callBack,
Andy Hung972bec12023-08-31 16:13:39 -0700111 const wp<IAfTrackBase>& cookie)
112 EXCLUDES_AudioFlinger_Mutex = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700113
Andy Hungab65b182023-09-06 19:41:47 -0700114 // Hold either AudioFlinger::mutex or ThreadBase::mutex
115 virtual void ioConfigChanged_l(audio_io_config_event_t event,
Andy Hung583043b2023-07-17 17:05:00 -0700116 const sp<AudioIoDescriptor>& ioDesc,
Andy Hung972bec12023-08-31 16:13:39 -0700117 pid_t pid = 0) EXCLUDES_AudioFlinger_ClientMutex = 0;
118 virtual void onNonOffloadableGlobalEffectEnable() EXCLUDES_AudioFlinger_Mutex = 0;
Mikhail Naganovbf203ce2024-05-23 16:27:59 -0700119 virtual void onSupportedLatencyModesChanged(audio_io_handle_t output,
120 const std::vector<audio_latency_mode_t>& modes)
Andy Hung972bec12023-08-31 16:13:39 -0700121 EXCLUDES_AudioFlinger_ClientMutex = 0;
Mikhail Naganovbf203ce2024-05-23 16:27:59 -0700122
123 virtual void onHardError(std::set<audio_port_handle_t>& trackPortIds) = 0;
Andy Hung583043b2023-07-17 17:05:00 -0700124};
Andy Hung87c693c2023-07-06 20:56:16 -0700125
Andy Hung440901d2023-06-29 21:19:25 -0700126class IAfThreadBase : public virtual RefBase {
127public:
128 enum type_t {
129 MIXER, // Thread class is MixerThread
130 DIRECT, // Thread class is DirectOutputThread
131 DUPLICATING, // Thread class is DuplicatingThread
132 RECORD, // Thread class is RecordThread
133 OFFLOAD, // Thread class is OffloadThread
134 MMAP_PLAYBACK, // Thread class for MMAP playback stream
135 MMAP_CAPTURE, // Thread class for MMAP capture stream
136 SPATIALIZER, //
137 BIT_PERFECT, // Thread class for BitPerfectThread
138 // When adding a value, also update IAfThreadBase::threadTypeToString()
139 };
140
141 static const char* threadTypeToString(type_t type);
Andy Hung25a80ac2023-07-19 12:47:35 -0700142 static std::string formatToString(audio_format_t format); // compliant for MediaMetrics
Andy Hung81994d62023-07-20 21:44:14 -0700143 static bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask);
144 static bool isValidPcmSinkFormat(audio_format_t format);
145
Andy Hung440901d2023-06-29 21:19:25 -0700146 virtual status_t readyToRun() = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700147 virtual void clearPowerManager() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700148 virtual status_t initCheck() const = 0;
149 virtual type_t type() const = 0;
150 virtual bool isDuplicating() const = 0;
151 virtual audio_io_handle_t id() const = 0;
152 virtual uint32_t sampleRate() const = 0;
153 virtual audio_channel_mask_t channelMask() const = 0;
154 virtual audio_channel_mask_t mixerChannelMask() const = 0;
155 virtual audio_format_t format() const = 0;
156 virtual uint32_t channelCount() const = 0;
157
158 // Called by AudioFlinger::frameCount(audio_io_handle_t output) and effects,
159 // and returns the [normal mix] buffer's frame count.
160 virtual size_t frameCount() const = 0;
161 virtual audio_channel_mask_t hapticChannelMask() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700162 virtual uint32_t hapticChannelCount() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700163 virtual uint32_t latency_l() const = 0; // NO_THREAD_SAFETY_ANALYSIS
164 virtual void setVolumeForOutput_l(float left, float right) const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700165
166 // Return's the HAL's frame count i.e. fast mixer buffer size.
167 virtual size_t frameCountHAL() const = 0;
168 virtual size_t frameSize() const = 0;
169 // Should be "virtual status_t requestExitAndWait()" and override same
170 // method in Thread, but Thread::requestExitAndWait() is not yet virtual.
Andy Hungab65b182023-09-06 19:41:47 -0700171 virtual void exit() EXCLUDES_ThreadBase_Mutex = 0;
172 virtual bool checkForNewParameter_l(const String8& keyValuePair, status_t& status)
173 REQUIRES(mutex()) = 0;
174 virtual status_t setParameters(const String8& keyValuePairs) EXCLUDES_ThreadBase_Mutex = 0;
175 virtual String8 getParameters(const String8& keys) EXCLUDES_ThreadBase_Mutex = 0;
176 virtual void ioConfigChanged_l(
Andy Hung440901d2023-06-29 21:19:25 -0700177 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700178 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE)
179 /* holds either AF::mutex or TB::mutex */ = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700180
181 // sendConfigEvent_l() must be called with ThreadBase::mLock held
182 // Can temporarily release the lock if waiting for a reply from
183 // processConfigEvents_l().
184 // status_t sendConfigEvent_l(sp<ConfigEvent>& event);
185 virtual void sendIoConfigEvent(
186 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) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700188 virtual void sendIoConfigEvent_l(
189 audio_io_config_event_t event, pid_t pid = 0,
Andy Hungab65b182023-09-06 19:41:47 -0700190 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) REQUIRES(mutex()) = 0;
191 virtual void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp)
192 EXCLUDES_ThreadBase_Mutex = 0;
193 virtual void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio, bool forApp)
194 REQUIRES(mutex()) = 0;
195 virtual status_t sendSetParameterConfigEvent_l(const String8& keyValuePair)
196 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700197 virtual status_t sendCreateAudioPatchConfigEvent(
Andy Hungab65b182023-09-06 19:41:47 -0700198 const struct audio_patch* patch, audio_patch_handle_t* handle)
199 EXCLUDES_ThreadBase_Mutex = 0;
200 virtual status_t sendReleaseAudioPatchConfigEvent(audio_patch_handle_t handle)
201 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700202 virtual status_t sendUpdateOutDeviceConfigEvent(
Andy Hungab65b182023-09-06 19:41:47 -0700203 const DeviceDescriptorBaseVector& outDevices) EXCLUDES_ThreadBase_Mutex = 0;
204 virtual void sendResizeBufferConfigEvent_l(int32_t maxSharedAudioHistoryMs)
205 REQUIRES(mutex()) = 0;
206 virtual void sendCheckOutputStageEffectsEvent() EXCLUDES_ThreadBase_Mutex = 0;
207 virtual void sendCheckOutputStageEffectsEvent_l()
208 REQUIRES(mutex()) = 0;
209 virtual void sendHalLatencyModesChangedEvent_l()
210 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700211
Andy Hungab65b182023-09-06 19:41:47 -0700212 virtual void processConfigEvents_l()
213 REQUIRES(mutex()) = 0;
214 virtual void setCheckOutputStageEffects() = 0; // no mutex needed
215 virtual void cacheParameters_l()
216 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700217 virtual status_t createAudioPatch_l(
Andy Hungab65b182023-09-06 19:41:47 -0700218 const struct audio_patch* patch, audio_patch_handle_t* handle)
219 REQUIRES(mutex()) = 0;
220 virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle)
221 REQUIRES(mutex()) = 0;
222 virtual void updateOutDevices(const DeviceDescriptorBaseVector& outDevices)
223 EXCLUDES_ThreadBase_Mutex = 0;
224 virtual void toAudioPortConfig(struct audio_port_config* config)
225 EXCLUDES_ThreadBase_Mutex = 0;
226 virtual void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs)
227 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700228
229 // see note at declaration of mStandby, mOutDevice and mInDevice
230 virtual bool inStandby() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700231 virtual const DeviceTypeSet outDeviceTypes_l() const REQUIRES(mutex()) = 0;
232 virtual audio_devices_t inDeviceType_l() const REQUIRES(mutex()) = 0;
233 virtual DeviceTypeSet getDeviceTypes_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700234 virtual const AudioDeviceTypeAddrVector& outDeviceTypeAddrs() const = 0;
235 virtual const AudioDeviceTypeAddr& inDeviceTypeAddr() const = 0;
236 virtual bool isOutput() const = 0;
237 virtual bool isOffloadOrMmap() const = 0;
238 virtual sp<StreamHalInterface> stream() const = 0;
239 virtual sp<IAfEffectHandle> createEffect_l(
240 const sp<Client>& client,
241 const sp<media::IEffectClient>& effectClient,
242 int32_t priority,
243 audio_session_t sessionId,
244 effect_descriptor_t* desc,
245 int* enabled,
246 status_t* status /*non-NULL*/,
247 bool pinned,
248 bool probe,
Andy Hung972bec12023-08-31 16:13:39 -0700249 bool notifyFramesProcessed)
Andy Hungab65b182023-09-06 19:41:47 -0700250 REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700251
252 // return values for hasAudioSession (bit field)
253 enum effect_state {
254 EFFECT_SESSION = 0x1, // the audio session corresponds to at least one
255 // effect
256 TRACK_SESSION = 0x2, // the audio session corresponds to at least one
257 // track
258 FAST_SESSION = 0x4, // the audio session corresponds to at least one
259 // fast track
260 SPATIALIZED_SESSION = 0x8, // the audio session corresponds to at least one
261 // spatialized track
262 BIT_PERFECT_SESSION = 0x10 // the audio session corresponds to at least one
263 // bit-perfect track
264 };
265
266 // get effect chain corresponding to session Id.
Andy Hungab65b182023-09-06 19:41:47 -0700267 virtual sp<IAfEffectChain> getEffectChain(audio_session_t sessionId) const
268 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700269 // same as getEffectChain() but must be called with ThreadBase mutex locked
Andy Hungab65b182023-09-06 19:41:47 -0700270 virtual sp<IAfEffectChain> getEffectChain_l(audio_session_t sessionId) const
271 REQUIRES(mutex()) = 0;
272 virtual std::vector<int> getEffectIds_l(audio_session_t sessionId) const
273 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700274 // add an effect chain to the chain list (mEffectChains)
Andy Hungab65b182023-09-06 19:41:47 -0700275 virtual status_t addEffectChain_l(const sp<IAfEffectChain>& chain)
276 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700277 // remove an effect chain from the chain list (mEffectChains)
Andy Hungab65b182023-09-06 19:41:47 -0700278 virtual size_t removeEffectChain_l(const sp<IAfEffectChain>& chain)
279 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700280 // lock all effect chains Mutexes. Must be called before releasing the
281 // ThreadBase mutex before processing the mixer and effects. This guarantees the
282 // integrity of the chains during the process.
283 // Also sets the parameter 'effectChains' to current value of mEffectChains.
Andy Hungab65b182023-09-06 19:41:47 -0700284 virtual void lockEffectChains_l(Vector<sp<IAfEffectChain>>& effectChains)
Shunkai Yaod125e402024-01-20 03:19:06 +0000285 REQUIRES(mutex()) EXCLUDES_EffectChain_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700286 // unlock effect chains after process
Andy Hungab65b182023-09-06 19:41:47 -0700287 virtual void unlockEffectChains(const Vector<sp<IAfEffectChain>>& effectChains)
288 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700289 // get a copy of mEffectChains vector
Andy Hungab65b182023-09-06 19:41:47 -0700290 virtual Vector<sp<IAfEffectChain>> getEffectChains_l() const
291 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700292 // set audio mode to all effect chains
Andy Hungab65b182023-09-06 19:41:47 -0700293 virtual void setMode(audio_mode_t mode)
294 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700295 // get effect module with corresponding ID on specified audio session
Andy Hungab65b182023-09-06 19:41:47 -0700296 virtual sp<IAfEffectModule> getEffect(audio_session_t sessionId, int effectId) const
297 EXCLUDES_ThreadBase_Mutex = 0;
298 virtual sp<IAfEffectModule> getEffect_l(audio_session_t sessionId, int effectId) const
299 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700300 // add and effect module. Also creates the effect chain is none exists for
301 // the effects audio session. Only called in a context of moving an effect
302 // from one thread to another
Andy Hung972bec12023-08-31 16:13:39 -0700303 virtual status_t addEffect_ll(const sp<IAfEffectModule>& effect)
304 REQUIRES(audio_utils::AudioFlinger_Mutex, mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700305 // remove and effect module. Also removes the effect chain is this was the last
306 // effect
Andy Hungab65b182023-09-06 19:41:47 -0700307 virtual void removeEffect_l(const sp<IAfEffectModule>& effect, bool release = false)
308 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700309 // disconnect an effect handle from module and destroy module if last handle
Andy Hungab65b182023-09-06 19:41:47 -0700310 virtual void disconnectEffectHandle(IAfEffectHandle* handle, bool unpinIfLast)
311 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700312 // detach all tracks connected to an auxiliary effect
Andy Hungab65b182023-09-06 19:41:47 -0700313 virtual void detachAuxEffect_l(int effectId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700314 // returns a combination of:
315 // - EFFECT_SESSION if effects on this audio session exist in one chain
316 // - TRACK_SESSION if tracks on this audio session exist
317 // - FAST_SESSION if fast tracks on this audio session exist
318 // - SPATIALIZED_SESSION if spatialized tracks on this audio session exist
Andy Hungab65b182023-09-06 19:41:47 -0700319 virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const REQUIRES(mutex()) = 0;
320 virtual uint32_t hasAudioSession(audio_session_t sessionId) const
321 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700322
323 // the value returned by default implementation is not important as the
324 // strategy is only meaningful for PlaybackThread which implements this method
Andy Hungab65b182023-09-06 19:41:47 -0700325 virtual product_strategy_t getStrategyForSession_l(audio_session_t sessionId) const
326 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700327
328 // check if some effects must be suspended/restored when an effect is enabled
329 // or disabled
330 virtual void checkSuspendOnEffectEnabled(
Andy Hungab65b182023-09-06 19:41:47 -0700331 bool enabled, audio_session_t sessionId, bool threadLocked)
332 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700333
Andy Hungab65b182023-09-06 19:41:47 -0700334 virtual status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event)
335 EXCLUDES_ThreadBase_Mutex = 0;
336 // internally static, perhaps make static member.
Andy Hung440901d2023-06-29 21:19:25 -0700337 virtual bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const = 0;
338
339 // Return a reference to a per-thread heap which can be used to allocate IMemory
340 // objects that will be read-only to client processes, read/write to mediaserver,
341 // and shared by all client processes of the thread.
342 // The heap is per-thread rather than common across all threads, because
343 // clients can't be trusted not to modify the offset of the IMemory they receive.
344 // If a thread does not have such a heap, this method returns 0.
345 virtual sp<MemoryDealer> readOnlyHeap() const = 0;
346
347 virtual sp<IMemory> pipeMemory() const = 0;
348
Andy Hungab65b182023-09-06 19:41:47 -0700349 virtual void systemReady() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700350
351 // checkEffectCompatibility_l() must be called with ThreadBase::mLock held
352 virtual status_t checkEffectCompatibility_l(
Andy Hungab65b182023-09-06 19:41:47 -0700353 const effect_descriptor_t* desc, audio_session_t sessionId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700354
Andy Hungab65b182023-09-06 19:41:47 -0700355 virtual void broadcast_l() REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700356
Andy Hungab65b182023-09-06 19:41:47 -0700357 virtual bool isTimestampCorrectionEnabled_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700358
359 virtual bool isMsdDevice() const = 0;
360
Andy Hungab65b182023-09-06 19:41:47 -0700361 virtual void dump(int fd, const Vector<String16>& args) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700362
363 // deliver stats to mediametrics.
Andy Hungab65b182023-09-06 19:41:47 -0700364 virtual void sendStatistics(bool force) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700365
Andy Hung972bec12023-08-31 16:13:39 -0700366 virtual audio_utils::mutex& mutex() const
367 RETURN_CAPABILITY(audio_utils::ThreadBase_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700368
Andy Hungab65b182023-09-06 19:41:47 -0700369 virtual void onEffectEnable(const sp<IAfEffectModule>& effect) EXCLUDES_ThreadBase_Mutex = 0;
370 virtual void onEffectDisable() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700371
372 // invalidateTracksForAudioSession_l must be called with holding mLock.
Andy Hungab65b182023-09-06 19:41:47 -0700373 virtual void invalidateTracksForAudioSession_l(audio_session_t sessionId) const
374 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700375 // Invalidate all the tracks with the given audio session.
Andy Hungab65b182023-09-06 19:41:47 -0700376 virtual void invalidateTracksForAudioSession(audio_session_t sessionId) const
377 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700378
379 virtual bool isStreamInitialized() const = 0;
Andy Hung972bec12023-08-31 16:13:39 -0700380 virtual void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor)
381 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
382 virtual void stopMelComputation_l()
383 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700384
Andy Hungab65b182023-09-06 19:41:47 -0700385 virtual product_strategy_t getStrategyForStream(audio_stream_type_t stream) const
386 EXCLUDES_AUDIO_ALL = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700387
388 virtual void setEffectSuspended_l(
Andy Hungab65b182023-09-06 19:41:47 -0700389 const effect_uuid_t* type, bool suspend, audio_session_t sessionId)
390 REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700391
Andy Hung6c498e92023-12-05 17:28:17 -0800392 // Wait while the Thread is busy. This is done to ensure that
393 // the Thread is not busy releasing the Tracks, during which the Thread mutex
394 // may be temporarily unlocked. Some Track methods will use this method to
395 // avoid races.
396 virtual void waitWhileThreadBusy_l(audio_utils::unique_lock& ul)
397 REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700398 // Dynamic cast to derived interface
399 virtual sp<IAfDirectOutputThread> asIAfDirectOutputThread() { return nullptr; }
400 virtual sp<IAfDuplicatingThread> asIAfDuplicatingThread() { return nullptr; }
401 virtual sp<IAfPlaybackThread> asIAfPlaybackThread() { return nullptr; }
402 virtual sp<IAfRecordThread> asIAfRecordThread() { return nullptr; }
Andy Hung583043b2023-07-17 17:05:00 -0700403 virtual IAfThreadCallback* afThreadCallback() const = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700404};
405
Andy Hung87c693c2023-07-06 20:56:16 -0700406class IAfPlaybackThread : public virtual IAfThreadBase, public virtual VolumeInterface {
Andy Hung440901d2023-06-29 21:19:25 -0700407public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700408 static sp<IAfPlaybackThread> createBitPerfectThread(
Andy Hung583043b2023-07-17 17:05:00 -0700409 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
410 audio_io_handle_t id, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700411
412 static sp<IAfPlaybackThread> createDirectOutputThread(
Andy Hung583043b2023-07-17 17:05:00 -0700413 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
414 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700415
416 static sp<IAfPlaybackThread> createMixerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700417 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
418 audio_io_handle_t id, bool systemReady, type_t type = MIXER,
419 audio_config_base_t* mixerConfig = nullptr);
Andy Hungee58e4a2023-07-07 13:47:37 -0700420
421 static sp<IAfPlaybackThread> createOffloadThread(
Andy Hung583043b2023-07-17 17:05:00 -0700422 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
423 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700424
425 static sp<IAfPlaybackThread> createSpatializerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700426 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
427 audio_io_handle_t id, bool systemReady, audio_config_base_t* mixerConfig);
Andy Hungee58e4a2023-07-07 13:47:37 -0700428
Andy Hung87c693c2023-07-06 20:56:16 -0700429 static constexpr int8_t kMaxTrackStopRetriesOffload = 2;
430
Andy Hung440901d2023-06-29 21:19:25 -0700431 enum mixer_state {
432 MIXER_IDLE, // no active tracks
433 MIXER_TRACKS_ENABLED, // at least one active track, but no track has any data ready
434 MIXER_TRACKS_READY, // at least one active track, and at least one track has data
435 MIXER_DRAIN_TRACK, // drain currently playing track
436 MIXER_DRAIN_ALL, // fully drain the hardware
437 // standby mode does not have an enum value
438 // suspend by audio policy manager is orthogonal to mixer state
439 };
440
441 // return estimated latency in milliseconds, as reported by HAL
442 virtual uint32_t latency() const = 0; // should be in IAfThreadBase?
443
Andy Hungab65b182023-09-06 19:41:47 -0700444 virtual uint32_t& fastTrackAvailMask_l() REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700445
Andy Hung440901d2023-06-29 21:19:25 -0700446 virtual sp<IAfTrack> createTrack_l(
447 const sp<Client>& client,
448 audio_stream_type_t streamType,
449 const audio_attributes_t& attr,
450 uint32_t* sampleRate,
451 audio_format_t format,
452 audio_channel_mask_t channelMask,
453 size_t* pFrameCount,
454 size_t* pNotificationFrameCount,
455 uint32_t notificationsPerBuffer,
456 float speed,
457 const sp<IMemory>& sharedBuffer,
458 audio_session_t sessionId,
459 audio_output_flags_t* flags,
460 pid_t creatorPid,
461 const AttributionSourceState& attributionSource,
462 pid_t tid,
463 status_t* status /*non-NULL*/,
464 audio_port_handle_t portId,
465 const sp<media::IAudioTrackCallback>& callback,
466 bool isSpatialized,
jiabin94ed47c2023-07-27 23:34:20 +0000467 bool isBitPerfect,
Andy Hung972bec12023-08-31 16:13:39 -0700468 audio_output_flags_t* afTrackFlags)
469 REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700470
Andy Hungab65b182023-09-06 19:41:47 -0700471 virtual status_t addTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
472 virtual bool destroyTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
473 virtual bool isTrackActive(const sp<IAfTrack>& track) const REQUIRES(mutex()) = 0;
474 virtual void addOutputTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700475
Andy Hungab65b182023-09-06 19:41:47 -0700476 virtual AudioStreamOut* getOutput_l() const REQUIRES(mutex()) = 0;
Andy Hung8d672e02023-09-15 18:19:28 -0700477 virtual AudioStreamOut* getOutput() const EXCLUDES_ThreadBase_Mutex = 0;
478 virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700479
480 // a very large number of suspend() will eventually wraparound, but unlikely
481 virtual void suspend() = 0;
482 virtual void restore() = 0;
483 virtual bool isSuspended() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700484 virtual status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames) const
485 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700486 // Consider also removing and passing an explicit mMainBuffer initialization
487 // parameter to AF::IAfTrack::Track().
488 virtual float* sinkBuffer() const = 0;
489
Andy Hungab65b182023-09-06 19:41:47 -0700490 virtual status_t attachAuxEffect(const sp<IAfTrack>& track, int EffectId)
491 EXCLUDES_ThreadBase_Mutex = 0;
492 virtual status_t attachAuxEffect_l(const sp<IAfTrack>& track, int EffectId)
493 REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700494
495 // called with AudioFlinger lock held
Andy Hungab65b182023-09-06 19:41:47 -0700496 virtual bool invalidateTracks_l(audio_stream_type_t streamType) REQUIRES(mutex()) = 0;
497 virtual bool invalidateTracks_l(std::set<audio_port_handle_t>& portIds) REQUIRES(mutex()) = 0;
498 virtual void invalidateTracks(audio_stream_type_t streamType)
499 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700500 // Invalidate tracks by a set of port ids. The port id will be removed from
501 // the given set if the corresponding track is found and invalidated.
Andy Hungab65b182023-09-06 19:41:47 -0700502 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
503 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700504
Andy Hungab65b182023-09-06 19:41:47 -0700505 virtual status_t getTimestamp_l(AudioTimestamp& timestamp) REQUIRES(mutex()) = 0;
506 virtual void addPatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;
507 virtual void deletePatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700508
509 // Return the asynchronous signal wait time.
Andy Hungab65b182023-09-06 19:41:47 -0700510 virtual int64_t computeWaitTimeNs_l() const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700511 // returns true if the track is allowed to be added to the thread.
512 virtual bool isTrackAllowed_l(
513 audio_channel_mask_t channelMask, audio_format_t format, audio_session_t sessionId,
Andy Hungab65b182023-09-06 19:41:47 -0700514 uid_t uid) const REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700515
516 virtual bool supportsHapticPlayback() const = 0;
517
Andy Hungab65b182023-09-06 19:41:47 -0700518 virtual void setDownStreamPatch(const struct audio_patch* patch)
519 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700520
Andy Hungab65b182023-09-06 19:41:47 -0700521 virtual IAfTrack* getTrackById_l(audio_port_handle_t trackId) REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700522
523 virtual bool hasMixer() const = 0;
524
525 virtual status_t setRequestedLatencyMode(audio_latency_mode_t mode) = 0;
526
Andy Hungab65b182023-09-06 19:41:47 -0700527 virtual status_t getSupportedLatencyModes(std::vector<audio_latency_mode_t>* modes)
528 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700529
530 virtual status_t setBluetoothVariableLatencyEnabled(bool enabled) = 0;
531
Andy Hungab65b182023-09-06 19:41:47 -0700532 virtual void setStandby() EXCLUDES_ThreadBase_Mutex = 0;
533 virtual void setStandby_l() REQUIRES(mutex()) = 0;
534 virtual bool waitForHalStart() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700535
536 virtual bool hasFastMixer() const = 0;
537 virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const = 0;
538 virtual const std::atomic<int64_t>& framesWritten() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700539
540 virtual bool usesHwAvSync() const = 0;
541};
542
543class IAfDirectOutputThread : public virtual IAfPlaybackThread {
544public:
545 virtual status_t selectPresentation(int presentationId, int programId) = 0;
546};
547
548class IAfDuplicatingThread : public virtual IAfPlaybackThread {
549public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700550 static sp<IAfDuplicatingThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700551 const sp<IAfThreadCallback>& afThreadCallback, IAfPlaybackThread* mainThread,
Andy Hungee58e4a2023-07-07 13:47:37 -0700552 audio_io_handle_t id, bool systemReady);
553
Andy Hungab65b182023-09-06 19:41:47 -0700554 virtual void addOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700555 virtual uint32_t waitTimeMs() const = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700556 virtual void removeOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700557};
558
559class IAfRecordThread : public virtual IAfThreadBase {
560public:
561 static sp<IAfRecordThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700562 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamIn* input,
563 audio_io_handle_t id, bool systemReady);
Andy Hung87c693c2023-07-06 20:56:16 -0700564
565 virtual sp<IAfRecordTrack> createRecordTrack_l(
566 const sp<Client>& client,
567 const audio_attributes_t& attr,
568 uint32_t* pSampleRate,
569 audio_format_t format,
570 audio_channel_mask_t channelMask,
571 size_t* pFrameCount,
572 audio_session_t sessionId,
573 size_t* pNotificationFrameCount,
574 pid_t creatorPid,
575 const AttributionSourceState& attributionSource,
576 audio_input_flags_t* flags,
577 pid_t tid,
578 status_t* status /*non-NULL*/,
579 audio_port_handle_t portId,
Andy Hung972bec12023-08-31 16:13:39 -0700580 int32_t maxSharedAudioHistoryMs)
Andy Hungab65b182023-09-06 19:41:47 -0700581 REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;
582 virtual void destroyTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;
583 virtual void removeTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700584
585 virtual status_t start(
586 IAfRecordTrack* recordTrack, AudioSystem::sync_event_t event,
Andy Hungab65b182023-09-06 19:41:47 -0700587 audio_session_t triggerSession) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700588
589 // ask the thread to stop the specified track, and
590 // return true if the caller should then do it's part of the stopping process
Andy Hungab65b182023-09-06 19:41:47 -0700591 virtual bool stop(IAfRecordTrack* recordTrack) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700592
Andy Hungab65b182023-09-06 19:41:47 -0700593 // NO_THREAD_SAFETY_ANALYSIS: consider atomics
Andy Hung87c693c2023-07-06 20:56:16 -0700594 virtual AudioStreamIn* getInput() const = 0;
595 virtual AudioStreamIn* clearInput() = 0;
596
597 virtual status_t getActiveMicrophones(
Andy Hungab65b182023-09-06 19:41:47 -0700598 std::vector<media::MicrophoneInfoFw>* activeMicrophones)
599 const EXCLUDES_ThreadBase_Mutex = 0;
600 virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction)
601 EXCLUDES_ThreadBase_Mutex = 0;
602 virtual status_t setPreferredMicrophoneFieldDimension(float zoom)
603 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700604
Andy Hungab65b182023-09-06 19:41:47 -0700605 virtual void addPatchTrack(const sp<IAfPatchRecord>& record)
606 EXCLUDES_ThreadBase_Mutex = 0;
607 virtual void deletePatchTrack(const sp<IAfPatchRecord>& record)
608 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700609 virtual bool fastTrackAvailable() const = 0;
610 virtual void setFastTrackAvailable(bool available) = 0;
611
Andy Hungab65b182023-09-06 19:41:47 -0700612 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
613 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700614 virtual bool hasFastCapture() const = 0;
615
Andy Hung3f49ebb2023-09-19 14:48:41 -0700616 virtual void checkBtNrec() EXCLUDES_ThreadBase_Mutex = 0;
617 virtual uint32_t getInputFramesLost() const EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700618
619 virtual status_t shareAudioHistory(
620 const std::string& sharedAudioPackageName,
621 audio_session_t sharedSessionId = AUDIO_SESSION_NONE,
Andy Hungab65b182023-09-06 19:41:47 -0700622 int64_t sharedAudioStartMs = -1) EXCLUDES_ThreadBase_Mutex = 0;
623 virtual void resetAudioHistory_l() REQUIRES(mutex()) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700624};
625
Andy Hung7aa7d102023-07-07 15:58:48 -0700626class IAfMmapThread : public virtual IAfThreadBase {
627public:
628 // createIAudioTrackAdapter() is a static constructor which creates an
629 // MmapStreamInterface AIDL interface adapter from the MmapThread object that
630 // may be passed back to the client.
631 //
632 // Only one AIDL MmapStreamInterface interface adapter should be created per MmapThread.
633 static sp<MmapStreamInterface> createMmapStreamInterfaceAdapter(
634 const sp<IAfMmapThread>& mmapThread);
635
636 virtual void configure(
637 const audio_attributes_t* attr,
638 audio_stream_type_t streamType,
639 audio_session_t sessionId,
640 const sp<MmapStreamCallback>& callback,
641 audio_port_handle_t deviceId,
Andy Hung3f49ebb2023-09-19 14:48:41 -0700642 audio_port_handle_t portId) EXCLUDES_ThreadBase_Mutex = 0;
Andy Hungab65b182023-09-06 19:41:47 -0700643 virtual void disconnect() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700644
645 // MmapStreamInterface handling (see adapter)
646 virtual status_t createMmapBuffer(
Andy Hung3f49ebb2023-09-19 14:48:41 -0700647 int32_t minSizeFrames, struct audio_mmap_buffer_info* info)
648 EXCLUDES_ThreadBase_Mutex = 0;
649 virtual status_t getMmapPosition(struct audio_mmap_position* position) const
650 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700651 virtual status_t start(
652 const AudioClient& client, const audio_attributes_t* attr,
Andy Hung3f49ebb2023-09-19 14:48:41 -0700653 audio_port_handle_t* handle) EXCLUDES_ThreadBase_Mutex = 0;
654 virtual status_t stop(audio_port_handle_t handle) EXCLUDES_ThreadBase_Mutex = 0;
655 virtual status_t standby() EXCLUDES_ThreadBase_Mutex = 0;
656 virtual status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const
657 EXCLUDES_ThreadBase_Mutex = 0;
658 virtual status_t reportData(const void* buffer, size_t frameCount)
659 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700660
Andy Hung99b1ba62023-07-14 11:00:08 -0700661 // TODO(b/291317898) move to IAfThreadBase?
Andy Hungab65b182023-09-06 19:41:47 -0700662 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
663 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700664
Andy Hung99b1ba62023-07-14 11:00:08 -0700665 // Sets the UID records silence - TODO(b/291317898) move to IAfMmapCaptureThread
Andy Hungab65b182023-09-06 19:41:47 -0700666 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
667 EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700668
669 virtual sp<IAfMmapPlaybackThread> asIAfMmapPlaybackThread() { return nullptr; }
670 virtual sp<IAfMmapCaptureThread> asIAfMmapCaptureThread() { return nullptr; }
671};
672
673class IAfMmapPlaybackThread : public virtual IAfMmapThread, public virtual VolumeInterface {
674public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700675 static sp<IAfMmapPlaybackThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700676 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
677 AudioHwDevice* hwDev, AudioStreamOut* output, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700678
Andy Hungab65b182023-09-06 19:41:47 -0700679 virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700680};
681
682class IAfMmapCaptureThread : public virtual IAfMmapThread {
683public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700684 static sp<IAfMmapCaptureThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700685 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
686 AudioHwDevice* hwDev, AudioStreamIn* input, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700687
Andy Hungab65b182023-09-06 19:41:47 -0700688 virtual AudioStreamIn* clearInput() EXCLUDES_ThreadBase_Mutex = 0;
Andy Hung7aa7d102023-07-07 15:58:48 -0700689};
690
Andy Hung440901d2023-06-29 21:19:25 -0700691} // namespace android