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