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