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