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