blob: 5afd7fc4bc019832a3ad0bf3369ce75a55978998 [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>
34#include <utils/Mutex.h>
35#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 Hung954b9712023-08-28 18:36:53 -070071 virtual audio_utils::mutex& mutex() const = 0;
Andy Hung583043b2023-07-17 17:05:00 -070072 virtual bool isNonOffloadableGlobalEffectEnabled_l() const = 0; // Tracks
73 virtual audio_unique_id_t nextUniqueId(audio_unique_id_use_t use) = 0;
74 virtual bool btNrecIsOff() const = 0;
75 virtual float masterVolume_l() const = 0;
76 virtual bool masterMute_l() const = 0;
77 virtual float getMasterBalance_l() const = 0;
78 virtual bool streamMute_l(audio_stream_type_t stream) const = 0;
79 virtual audio_mode_t getMode() const = 0;
80 virtual bool isLowRamDevice() const = 0;
81 virtual bool isAudioPolicyReady() const = 0; // Effects
Andy Hung1d2d2aea2023-07-19 16:22:58 -070082 virtual uint32_t getScreenState() const = 0;
Andy Hung583043b2023-07-17 17:05:00 -070083 virtual std::optional<media::AudioVibratorInfo> getDefaultVibratorInfo_l() const = 0;
84 virtual const sp<IAfPatchPanel>& getPatchPanel() const = 0;
85 virtual const sp<MelReporter>& getMelReporter() const = 0;
86 virtual const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() const = 0;
87 virtual sp<IAudioManager> getOrCreateAudioManager() = 0; // Tracks
88
89 virtual bool updateOrphanEffectChains(const sp<IAfEffectModule>& effect) = 0;
90 virtual status_t moveEffectChain_l(audio_session_t sessionId,
91 IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread) = 0;
92
93 virtual void requestLogMerge() = 0;
94 virtual sp<NBLog::Writer> newWriter_l(size_t size, const char *name) = 0;
95 virtual void unregisterWriter(const sp<NBLog::Writer>& writer) = 0;
96
97 virtual sp<audioflinger::SyncEvent> createSyncEvent(AudioSystem::sync_event_t type,
98 audio_session_t triggerSession,
99 audio_session_t listenerSession,
100 const audioflinger::SyncEventCallback& callBack,
101 const wp<IAfTrackBase>& cookie) = 0;
102
103 virtual void ioConfigChanged(audio_io_config_event_t event,
104 const sp<AudioIoDescriptor>& ioDesc,
105 pid_t pid = 0) = 0;
106 virtual void onNonOffloadableGlobalEffectEnable() = 0;
107 virtual void onSupportedLatencyModesChanged(
108 audio_io_handle_t output, const std::vector<audio_latency_mode_t>& modes) = 0;
109};
Andy Hung87c693c2023-07-06 20:56:16 -0700110
Andy Hung440901d2023-06-29 21:19:25 -0700111class IAfThreadBase : public virtual RefBase {
112public:
113 enum type_t {
114 MIXER, // Thread class is MixerThread
115 DIRECT, // Thread class is DirectOutputThread
116 DUPLICATING, // Thread class is DuplicatingThread
117 RECORD, // Thread class is RecordThread
118 OFFLOAD, // Thread class is OffloadThread
119 MMAP_PLAYBACK, // Thread class for MMAP playback stream
120 MMAP_CAPTURE, // Thread class for MMAP capture stream
121 SPATIALIZER, //
122 BIT_PERFECT, // Thread class for BitPerfectThread
123 // When adding a value, also update IAfThreadBase::threadTypeToString()
124 };
125
126 static const char* threadTypeToString(type_t type);
Andy Hung25a80ac2023-07-19 12:47:35 -0700127 static std::string formatToString(audio_format_t format); // compliant for MediaMetrics
Andy Hung81994d62023-07-20 21:44:14 -0700128 static bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask);
129 static bool isValidPcmSinkFormat(audio_format_t format);
130
Andy Hung440901d2023-06-29 21:19:25 -0700131 virtual status_t readyToRun() = 0;
132 virtual void clearPowerManager() = 0;
133 virtual status_t initCheck() const = 0;
134 virtual type_t type() const = 0;
135 virtual bool isDuplicating() const = 0;
136 virtual audio_io_handle_t id() const = 0;
137 virtual uint32_t sampleRate() const = 0;
138 virtual audio_channel_mask_t channelMask() const = 0;
139 virtual audio_channel_mask_t mixerChannelMask() const = 0;
140 virtual audio_format_t format() const = 0;
141 virtual uint32_t channelCount() const = 0;
142
143 // Called by AudioFlinger::frameCount(audio_io_handle_t output) and effects,
144 // and returns the [normal mix] buffer's frame count.
145 virtual size_t frameCount() const = 0;
146 virtual audio_channel_mask_t hapticChannelMask() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700147 virtual uint32_t hapticChannelCount() const = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700148 virtual uint32_t latency_l() const = 0;
149 virtual void setVolumeForOutput_l(float left, float right) const = 0;
150
151 // Return's the HAL's frame count i.e. fast mixer buffer size.
152 virtual size_t frameCountHAL() const = 0;
153 virtual size_t frameSize() const = 0;
154 // Should be "virtual status_t requestExitAndWait()" and override same
155 // method in Thread, but Thread::requestExitAndWait() is not yet virtual.
156 virtual void exit() = 0;
157 virtual bool checkForNewParameter_l(const String8& keyValuePair, status_t& status) = 0;
158 virtual status_t setParameters(const String8& keyValuePairs) = 0;
159 virtual String8 getParameters(const String8& keys) = 0;
160 virtual void ioConfigChanged(
161 audio_io_config_event_t event, pid_t pid = 0,
162 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) = 0;
163
164 // sendConfigEvent_l() must be called with ThreadBase::mLock held
165 // Can temporarily release the lock if waiting for a reply from
166 // processConfigEvents_l().
167 // status_t sendConfigEvent_l(sp<ConfigEvent>& event);
168 virtual void sendIoConfigEvent(
169 audio_io_config_event_t event, pid_t pid = 0,
170 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) = 0;
171 virtual void sendIoConfigEvent_l(
172 audio_io_config_event_t event, pid_t pid = 0,
173 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) = 0;
174 virtual void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp) = 0;
175 virtual void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio, bool forApp) = 0;
176 virtual status_t sendSetParameterConfigEvent_l(const String8& keyValuePair) = 0;
177 virtual status_t sendCreateAudioPatchConfigEvent(
178 const struct audio_patch* patch, audio_patch_handle_t* handle) = 0;
179 virtual status_t sendReleaseAudioPatchConfigEvent(audio_patch_handle_t handle) = 0;
180 virtual status_t sendUpdateOutDeviceConfigEvent(
181 const DeviceDescriptorBaseVector& outDevices) = 0;
182 virtual void sendResizeBufferConfigEvent_l(int32_t maxSharedAudioHistoryMs) = 0;
183 virtual void sendCheckOutputStageEffectsEvent() = 0;
184 virtual void sendCheckOutputStageEffectsEvent_l() = 0;
185 virtual void sendHalLatencyModesChangedEvent_l() = 0;
186
187 virtual void processConfigEvents_l() = 0;
188 virtual void setCheckOutputStageEffects() = 0;
189 virtual void cacheParameters_l() = 0;
190 virtual status_t createAudioPatch_l(
191 const struct audio_patch* patch, audio_patch_handle_t* handle) = 0;
192 virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle) = 0;
193 virtual void updateOutDevices(const DeviceDescriptorBaseVector& outDevices) = 0;
194 virtual void toAudioPortConfig(struct audio_port_config* config) = 0;
195 virtual void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs) = 0;
196
197 // see note at declaration of mStandby, mOutDevice and mInDevice
198 virtual bool inStandby() const = 0;
199 virtual const DeviceTypeSet outDeviceTypes() const = 0;
200 virtual audio_devices_t inDeviceType() const = 0;
201 virtual DeviceTypeSet getDeviceTypes() const = 0;
202 virtual const AudioDeviceTypeAddrVector& outDeviceTypeAddrs() const = 0;
203 virtual const AudioDeviceTypeAddr& inDeviceTypeAddr() const = 0;
204 virtual bool isOutput() const = 0;
205 virtual bool isOffloadOrMmap() const = 0;
206 virtual sp<StreamHalInterface> stream() const = 0;
207 virtual sp<IAfEffectHandle> createEffect_l(
208 const sp<Client>& client,
209 const sp<media::IEffectClient>& effectClient,
210 int32_t priority,
211 audio_session_t sessionId,
212 effect_descriptor_t* desc,
213 int* enabled,
214 status_t* status /*non-NULL*/,
215 bool pinned,
216 bool probe,
217 bool notifyFramesProcessed) = 0;
218
219 // return values for hasAudioSession (bit field)
220 enum effect_state {
221 EFFECT_SESSION = 0x1, // the audio session corresponds to at least one
222 // effect
223 TRACK_SESSION = 0x2, // the audio session corresponds to at least one
224 // track
225 FAST_SESSION = 0x4, // the audio session corresponds to at least one
226 // fast track
227 SPATIALIZED_SESSION = 0x8, // the audio session corresponds to at least one
228 // spatialized track
229 BIT_PERFECT_SESSION = 0x10 // the audio session corresponds to at least one
230 // bit-perfect track
231 };
232
233 // get effect chain corresponding to session Id.
234 virtual sp<IAfEffectChain> getEffectChain(audio_session_t sessionId) const = 0;
235 // same as getEffectChain() but must be called with ThreadBase mutex locked
236 virtual sp<IAfEffectChain> getEffectChain_l(audio_session_t sessionId) const = 0;
237 virtual std::vector<int> getEffectIds_l(audio_session_t sessionId) const = 0;
238 // add an effect chain to the chain list (mEffectChains)
239 virtual status_t addEffectChain_l(const sp<IAfEffectChain>& chain) = 0;
240 // remove an effect chain from the chain list (mEffectChains)
241 virtual size_t removeEffectChain_l(const sp<IAfEffectChain>& chain) = 0;
242 // lock all effect chains Mutexes. Must be called before releasing the
243 // ThreadBase mutex before processing the mixer and effects. This guarantees the
244 // integrity of the chains during the process.
245 // Also sets the parameter 'effectChains' to current value of mEffectChains.
246 virtual void lockEffectChains_l(Vector<sp<IAfEffectChain>>& effectChains) = 0;
247 // unlock effect chains after process
248 virtual void unlockEffectChains(const Vector<sp<IAfEffectChain>>& effectChains) = 0;
249 // get a copy of mEffectChains vector
250 virtual Vector<sp<IAfEffectChain>> getEffectChains_l() const = 0;
251 // set audio mode to all effect chains
252 virtual void setMode(audio_mode_t mode) = 0;
253 // get effect module with corresponding ID on specified audio session
254 virtual sp<IAfEffectModule> getEffect(audio_session_t sessionId, int effectId) const = 0;
255 virtual sp<IAfEffectModule> getEffect_l(audio_session_t sessionId, int effectId) const = 0;
256 // add and effect module. Also creates the effect chain is none exists for
257 // the effects audio session. Only called in a context of moving an effect
258 // from one thread to another
259 virtual status_t addEffect_l(const sp<IAfEffectModule>& effect) = 0;
260 // remove and effect module. Also removes the effect chain is this was the last
261 // effect
262 virtual void removeEffect_l(const sp<IAfEffectModule>& effect, bool release = false) = 0;
263 // disconnect an effect handle from module and destroy module if last handle
264 virtual void disconnectEffectHandle(IAfEffectHandle* handle, bool unpinIfLast) = 0;
265 // detach all tracks connected to an auxiliary effect
266 virtual void detachAuxEffect_l(int effectId) = 0;
267 // returns a combination of:
268 // - EFFECT_SESSION if effects on this audio session exist in one chain
269 // - TRACK_SESSION if tracks on this audio session exist
270 // - FAST_SESSION if fast tracks on this audio session exist
271 // - SPATIALIZED_SESSION if spatialized tracks on this audio session exist
272 virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const = 0;
273 virtual uint32_t hasAudioSession(audio_session_t sessionId) const = 0;
274
275 // the value returned by default implementation is not important as the
276 // strategy is only meaningful for PlaybackThread which implements this method
277 virtual product_strategy_t getStrategyForSession_l(audio_session_t sessionId) const = 0;
278
279 // check if some effects must be suspended/restored when an effect is enabled
280 // or disabled
281 virtual void checkSuspendOnEffectEnabled(
282 bool enabled, audio_session_t sessionId, bool threadLocked) = 0;
283
284 virtual status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event) = 0;
285 virtual bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const = 0;
286
287 // Return a reference to a per-thread heap which can be used to allocate IMemory
288 // objects that will be read-only to client processes, read/write to mediaserver,
289 // and shared by all client processes of the thread.
290 // The heap is per-thread rather than common across all threads, because
291 // clients can't be trusted not to modify the offset of the IMemory they receive.
292 // If a thread does not have such a heap, this method returns 0.
293 virtual sp<MemoryDealer> readOnlyHeap() const = 0;
294
295 virtual sp<IMemory> pipeMemory() const = 0;
296
297 virtual void systemReady() = 0;
298
299 // checkEffectCompatibility_l() must be called with ThreadBase::mLock held
300 virtual status_t checkEffectCompatibility_l(
301 const effect_descriptor_t* desc, audio_session_t sessionId) = 0;
302
303 virtual void broadcast_l() = 0;
304
305 virtual bool isTimestampCorrectionEnabled() const = 0;
306
307 virtual bool isMsdDevice() const = 0;
308
309 virtual void dump(int fd, const Vector<String16>& args) = 0;
310
311 // deliver stats to mediametrics.
312 virtual void sendStatistics(bool force) = 0;
313
314 virtual Mutex& mutex() const = 0;
315
316 virtual void onEffectEnable(const sp<IAfEffectModule>& effect) = 0;
317 virtual void onEffectDisable() = 0;
318
319 // invalidateTracksForAudioSession_l must be called with holding mLock.
320 virtual void invalidateTracksForAudioSession_l(audio_session_t sessionId) const = 0;
321 // Invalidate all the tracks with the given audio session.
322 virtual void invalidateTracksForAudioSession(audio_session_t sessionId) const = 0;
323
324 virtual bool isStreamInitialized() const = 0;
325 virtual void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor) = 0;
326 virtual void stopMelComputation_l() = 0;
327
328 virtual product_strategy_t getStrategyForStream(audio_stream_type_t stream) const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700329
330 virtual void setEffectSuspended_l(
331 const effect_uuid_t* type, bool suspend, audio_session_t sessionId) = 0;
332
333 // Dynamic cast to derived interface
334 virtual sp<IAfDirectOutputThread> asIAfDirectOutputThread() { return nullptr; }
335 virtual sp<IAfDuplicatingThread> asIAfDuplicatingThread() { return nullptr; }
336 virtual sp<IAfPlaybackThread> asIAfPlaybackThread() { return nullptr; }
337 virtual sp<IAfRecordThread> asIAfRecordThread() { return nullptr; }
Andy Hung583043b2023-07-17 17:05:00 -0700338 virtual IAfThreadCallback* afThreadCallback() const = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700339};
340
Andy Hung87c693c2023-07-06 20:56:16 -0700341class IAfPlaybackThread : public virtual IAfThreadBase, public virtual VolumeInterface {
Andy Hung440901d2023-06-29 21:19:25 -0700342public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700343 static sp<IAfPlaybackThread> createBitPerfectThread(
Andy Hung583043b2023-07-17 17:05:00 -0700344 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
345 audio_io_handle_t id, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700346
347 static sp<IAfPlaybackThread> createDirectOutputThread(
Andy Hung583043b2023-07-17 17:05:00 -0700348 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
349 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700350
351 static sp<IAfPlaybackThread> createMixerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700352 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
353 audio_io_handle_t id, bool systemReady, type_t type = MIXER,
354 audio_config_base_t* mixerConfig = nullptr);
Andy Hungee58e4a2023-07-07 13:47:37 -0700355
356 static sp<IAfPlaybackThread> createOffloadThread(
Andy Hung583043b2023-07-17 17:05:00 -0700357 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
358 audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);
Andy Hungee58e4a2023-07-07 13:47:37 -0700359
360 static sp<IAfPlaybackThread> createSpatializerThread(
Andy Hung583043b2023-07-17 17:05:00 -0700361 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
362 audio_io_handle_t id, bool systemReady, audio_config_base_t* mixerConfig);
Andy Hungee58e4a2023-07-07 13:47:37 -0700363
Andy Hung87c693c2023-07-06 20:56:16 -0700364 static constexpr int8_t kMaxTrackStopRetriesOffload = 2;
365
Andy Hung440901d2023-06-29 21:19:25 -0700366 enum mixer_state {
367 MIXER_IDLE, // no active tracks
368 MIXER_TRACKS_ENABLED, // at least one active track, but no track has any data ready
369 MIXER_TRACKS_READY, // at least one active track, and at least one track has data
370 MIXER_DRAIN_TRACK, // drain currently playing track
371 MIXER_DRAIN_ALL, // fully drain the hardware
372 // standby mode does not have an enum value
373 // suspend by audio policy manager is orthogonal to mixer state
374 };
375
376 // return estimated latency in milliseconds, as reported by HAL
377 virtual uint32_t latency() const = 0; // should be in IAfThreadBase?
378
Andy Hung87c693c2023-07-06 20:56:16 -0700379 virtual uint32_t& fastTrackAvailMask_l() = 0;
380
Andy Hung440901d2023-06-29 21:19:25 -0700381 virtual sp<IAfTrack> createTrack_l(
382 const sp<Client>& client,
383 audio_stream_type_t streamType,
384 const audio_attributes_t& attr,
385 uint32_t* sampleRate,
386 audio_format_t format,
387 audio_channel_mask_t channelMask,
388 size_t* pFrameCount,
389 size_t* pNotificationFrameCount,
390 uint32_t notificationsPerBuffer,
391 float speed,
392 const sp<IMemory>& sharedBuffer,
393 audio_session_t sessionId,
394 audio_output_flags_t* flags,
395 pid_t creatorPid,
396 const AttributionSourceState& attributionSource,
397 pid_t tid,
398 status_t* status /*non-NULL*/,
399 audio_port_handle_t portId,
400 const sp<media::IAudioTrackCallback>& callback,
401 bool isSpatialized,
jiabin94ed47c2023-07-27 23:34:20 +0000402 bool isBitPerfect,
403 audio_output_flags_t* afTrackFlags) = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700404
Andy Hung87c693c2023-07-06 20:56:16 -0700405 virtual status_t addTrack_l(const sp<IAfTrack>& track) = 0;
406 virtual bool destroyTrack_l(const sp<IAfTrack>& track) = 0;
407 virtual bool isTrackActive(const sp<IAfTrack>& track) const = 0;
408 virtual void addOutputTrack_l(const sp<IAfTrack>& track) = 0;
409
410 virtual AudioStreamOut* getOutput_l() const = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700411 virtual AudioStreamOut* getOutput() const = 0;
412 virtual AudioStreamOut* clearOutput() = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700413
414 // a very large number of suspend() will eventually wraparound, but unlikely
415 virtual void suspend() = 0;
416 virtual void restore() = 0;
417 virtual bool isSuspended() const = 0;
418 virtual status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames) const = 0;
419 // Consider also removing and passing an explicit mMainBuffer initialization
420 // parameter to AF::IAfTrack::Track().
421 virtual float* sinkBuffer() const = 0;
422
423 virtual status_t attachAuxEffect(const sp<IAfTrack>& track, int EffectId) = 0;
424 virtual status_t attachAuxEffect_l(const sp<IAfTrack>& track, int EffectId) = 0;
425
426 // called with AudioFlinger lock held
427 virtual bool invalidateTracks_l(audio_stream_type_t streamType) = 0;
428 virtual bool invalidateTracks_l(std::set<audio_port_handle_t>& portIds) = 0;
429 virtual void invalidateTracks(audio_stream_type_t streamType) = 0;
430 // Invalidate tracks by a set of port ids. The port id will be removed from
431 // the given set if the corresponding track is found and invalidated.
432 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds) = 0;
433
434 virtual status_t getTimestamp_l(AudioTimestamp& timestamp) = 0;
435 virtual void addPatchTrack(const sp<IAfPatchTrack>& track) = 0;
436 virtual void deletePatchTrack(const sp<IAfPatchTrack>& track) = 0;
437
438 // Return the asynchronous signal wait time.
439 virtual int64_t computeWaitTimeNs_l() const = 0;
440 // returns true if the track is allowed to be added to the thread.
441 virtual bool isTrackAllowed_l(
442 audio_channel_mask_t channelMask, audio_format_t format, audio_session_t sessionId,
443 uid_t uid) const = 0;
444
445 virtual bool supportsHapticPlayback() const = 0;
446
447 virtual void setDownStreamPatch(const struct audio_patch* patch) = 0;
448
449 virtual IAfTrack* getTrackById_l(audio_port_handle_t trackId) = 0;
450
451 virtual bool hasMixer() const = 0;
452
453 virtual status_t setRequestedLatencyMode(audio_latency_mode_t mode) = 0;
454
455 virtual status_t getSupportedLatencyModes(std::vector<audio_latency_mode_t>* modes) = 0;
456
457 virtual status_t setBluetoothVariableLatencyEnabled(bool enabled) = 0;
458
459 virtual void setStandby() = 0;
460 virtual void setStandby_l() = 0;
461 virtual bool waitForHalStart() = 0;
462
463 virtual bool hasFastMixer() const = 0;
464 virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const = 0;
465 virtual const std::atomic<int64_t>& framesWritten() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700466
467 virtual bool usesHwAvSync() const = 0;
468};
469
470class IAfDirectOutputThread : public virtual IAfPlaybackThread {
471public:
472 virtual status_t selectPresentation(int presentationId, int programId) = 0;
473};
474
475class IAfDuplicatingThread : public virtual IAfPlaybackThread {
476public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700477 static sp<IAfDuplicatingThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700478 const sp<IAfThreadCallback>& afThreadCallback, IAfPlaybackThread* mainThread,
Andy Hungee58e4a2023-07-07 13:47:37 -0700479 audio_io_handle_t id, bool systemReady);
480
Andy Hung87c693c2023-07-06 20:56:16 -0700481 virtual void addOutputTrack(IAfPlaybackThread* thread) = 0;
482 virtual uint32_t waitTimeMs() const = 0;
483 virtual void removeOutputTrack(IAfPlaybackThread* thread) = 0;
484};
485
486class IAfRecordThread : public virtual IAfThreadBase {
487public:
488 static sp<IAfRecordThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700489 const sp<IAfThreadCallback>& afThreadCallback, AudioStreamIn* input,
490 audio_io_handle_t id, bool systemReady);
Andy Hung87c693c2023-07-06 20:56:16 -0700491
492 virtual sp<IAfRecordTrack> createRecordTrack_l(
493 const sp<Client>& client,
494 const audio_attributes_t& attr,
495 uint32_t* pSampleRate,
496 audio_format_t format,
497 audio_channel_mask_t channelMask,
498 size_t* pFrameCount,
499 audio_session_t sessionId,
500 size_t* pNotificationFrameCount,
501 pid_t creatorPid,
502 const AttributionSourceState& attributionSource,
503 audio_input_flags_t* flags,
504 pid_t tid,
505 status_t* status /*non-NULL*/,
506 audio_port_handle_t portId,
507 int32_t maxSharedAudioHistoryMs) = 0;
508 virtual void destroyTrack_l(const sp<IAfRecordTrack>& track) = 0;
509 virtual void removeTrack_l(const sp<IAfRecordTrack>& track) = 0;
510
511 virtual status_t start(
512 IAfRecordTrack* recordTrack, AudioSystem::sync_event_t event,
513 audio_session_t triggerSession) = 0;
514
515 // ask the thread to stop the specified track, and
516 // return true if the caller should then do it's part of the stopping process
517 virtual bool stop(IAfRecordTrack* recordTrack) = 0;
518
519 virtual AudioStreamIn* getInput() const = 0;
520 virtual AudioStreamIn* clearInput() = 0;
521
522 virtual status_t getActiveMicrophones(
523 std::vector<media::MicrophoneInfoFw>* activeMicrophones) const = 0;
524 virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction) = 0;
525 virtual status_t setPreferredMicrophoneFieldDimension(float zoom) = 0;
526
527 virtual void addPatchTrack(const sp<IAfPatchRecord>& record) = 0;
528 virtual void deletePatchTrack(const sp<IAfPatchRecord>& record) = 0;
529 virtual bool fastTrackAvailable() const = 0;
530 virtual void setFastTrackAvailable(bool available) = 0;
531
532 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced) = 0;
533 virtual bool hasFastCapture() const = 0;
534
535 virtual void checkBtNrec() = 0;
536 virtual uint32_t getInputFramesLost() const = 0;
537
538 virtual status_t shareAudioHistory(
539 const std::string& sharedAudioPackageName,
540 audio_session_t sharedSessionId = AUDIO_SESSION_NONE,
541 int64_t sharedAudioStartMs = -1) = 0;
542 virtual void resetAudioHistory_l() = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700543};
544
Andy Hung7aa7d102023-07-07 15:58:48 -0700545class IAfMmapThread : public virtual IAfThreadBase {
546public:
547 // createIAudioTrackAdapter() is a static constructor which creates an
548 // MmapStreamInterface AIDL interface adapter from the MmapThread object that
549 // may be passed back to the client.
550 //
551 // Only one AIDL MmapStreamInterface interface adapter should be created per MmapThread.
552 static sp<MmapStreamInterface> createMmapStreamInterfaceAdapter(
553 const sp<IAfMmapThread>& mmapThread);
554
555 virtual void configure(
556 const audio_attributes_t* attr,
557 audio_stream_type_t streamType,
558 audio_session_t sessionId,
559 const sp<MmapStreamCallback>& callback,
560 audio_port_handle_t deviceId,
561 audio_port_handle_t portId) = 0;
562 virtual void disconnect() = 0;
563
564 // MmapStreamInterface handling (see adapter)
565 virtual status_t createMmapBuffer(
566 int32_t minSizeFrames, struct audio_mmap_buffer_info* info) = 0;
567 virtual status_t getMmapPosition(struct audio_mmap_position* position) const = 0;
568 virtual status_t start(
569 const AudioClient& client, const audio_attributes_t* attr,
570 audio_port_handle_t* handle) = 0;
571 virtual status_t stop(audio_port_handle_t handle) = 0;
572 virtual status_t standby() = 0;
573 virtual status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const = 0;
574 virtual status_t reportData(const void* buffer, size_t frameCount) = 0;
575
Andy Hung99b1ba62023-07-14 11:00:08 -0700576 // TODO(b/291317898) move to IAfThreadBase?
Andy Hung7aa7d102023-07-07 15:58:48 -0700577 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds) = 0;
578
Andy Hung99b1ba62023-07-14 11:00:08 -0700579 // Sets the UID records silence - TODO(b/291317898) move to IAfMmapCaptureThread
Andy Hung7aa7d102023-07-07 15:58:48 -0700580 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced) = 0;
581
582 virtual sp<IAfMmapPlaybackThread> asIAfMmapPlaybackThread() { return nullptr; }
583 virtual sp<IAfMmapCaptureThread> asIAfMmapCaptureThread() { return nullptr; }
584};
585
586class IAfMmapPlaybackThread : public virtual IAfMmapThread, public virtual VolumeInterface {
587public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700588 static sp<IAfMmapPlaybackThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700589 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
590 AudioHwDevice* hwDev, AudioStreamOut* output, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700591
Andy Hung7aa7d102023-07-07 15:58:48 -0700592 virtual AudioStreamOut* clearOutput() = 0;
593};
594
595class IAfMmapCaptureThread : public virtual IAfMmapThread {
596public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700597 static sp<IAfMmapCaptureThread> create(
Andy Hung583043b2023-07-17 17:05:00 -0700598 const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
599 AudioHwDevice* hwDev, AudioStreamIn* input, bool systemReady);
Andy Hungee58e4a2023-07-07 13:47:37 -0700600
Andy Hung7aa7d102023-07-07 15:58:48 -0700601 virtual AudioStreamIn* clearInput() = 0;
602};
603
Andy Hung440901d2023-06-29 21:19:25 -0700604} // namespace android