blob: 8b87ed7dc22e6bb140637551592bd3b1211b0d56 [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,
316 bool isBitPerfect) = 0;
317
Andy Hung87c693c2023-07-06 20:56:16 -0700318 virtual status_t addTrack_l(const sp<IAfTrack>& track) = 0;
319 virtual bool destroyTrack_l(const sp<IAfTrack>& track) = 0;
320 virtual bool isTrackActive(const sp<IAfTrack>& track) const = 0;
321 virtual void addOutputTrack_l(const sp<IAfTrack>& track) = 0;
322
323 virtual AudioStreamOut* getOutput_l() const = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700324 virtual AudioStreamOut* getOutput() const = 0;
325 virtual AudioStreamOut* clearOutput() = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700326
327 // a very large number of suspend() will eventually wraparound, but unlikely
328 virtual void suspend() = 0;
329 virtual void restore() = 0;
330 virtual bool isSuspended() const = 0;
331 virtual status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames) const = 0;
332 // Consider also removing and passing an explicit mMainBuffer initialization
333 // parameter to AF::IAfTrack::Track().
334 virtual float* sinkBuffer() const = 0;
335
336 virtual status_t attachAuxEffect(const sp<IAfTrack>& track, int EffectId) = 0;
337 virtual status_t attachAuxEffect_l(const sp<IAfTrack>& track, int EffectId) = 0;
338
339 // called with AudioFlinger lock held
340 virtual bool invalidateTracks_l(audio_stream_type_t streamType) = 0;
341 virtual bool invalidateTracks_l(std::set<audio_port_handle_t>& portIds) = 0;
342 virtual void invalidateTracks(audio_stream_type_t streamType) = 0;
343 // Invalidate tracks by a set of port ids. The port id will be removed from
344 // the given set if the corresponding track is found and invalidated.
345 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds) = 0;
346
347 virtual status_t getTimestamp_l(AudioTimestamp& timestamp) = 0;
348 virtual void addPatchTrack(const sp<IAfPatchTrack>& track) = 0;
349 virtual void deletePatchTrack(const sp<IAfPatchTrack>& track) = 0;
350
351 // Return the asynchronous signal wait time.
352 virtual int64_t computeWaitTimeNs_l() const = 0;
353 // returns true if the track is allowed to be added to the thread.
354 virtual bool isTrackAllowed_l(
355 audio_channel_mask_t channelMask, audio_format_t format, audio_session_t sessionId,
356 uid_t uid) const = 0;
357
358 virtual bool supportsHapticPlayback() const = 0;
359
360 virtual void setDownStreamPatch(const struct audio_patch* patch) = 0;
361
362 virtual IAfTrack* getTrackById_l(audio_port_handle_t trackId) = 0;
363
364 virtual bool hasMixer() const = 0;
365
366 virtual status_t setRequestedLatencyMode(audio_latency_mode_t mode) = 0;
367
368 virtual status_t getSupportedLatencyModes(std::vector<audio_latency_mode_t>* modes) = 0;
369
370 virtual status_t setBluetoothVariableLatencyEnabled(bool enabled) = 0;
371
372 virtual void setStandby() = 0;
373 virtual void setStandby_l() = 0;
374 virtual bool waitForHalStart() = 0;
375
376 virtual bool hasFastMixer() const = 0;
377 virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const = 0;
378 virtual const std::atomic<int64_t>& framesWritten() const = 0;
Andy Hung87c693c2023-07-06 20:56:16 -0700379
380 virtual bool usesHwAvSync() const = 0;
381};
382
383class IAfDirectOutputThread : public virtual IAfPlaybackThread {
384public:
385 virtual status_t selectPresentation(int presentationId, int programId) = 0;
386};
387
388class IAfDuplicatingThread : public virtual IAfPlaybackThread {
389public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700390 static sp<IAfDuplicatingThread> create(
391 const sp<AudioFlinger>& audioFlinger, IAfPlaybackThread* mainThread,
392 audio_io_handle_t id, bool systemReady);
393
Andy Hung87c693c2023-07-06 20:56:16 -0700394 virtual void addOutputTrack(IAfPlaybackThread* thread) = 0;
395 virtual uint32_t waitTimeMs() const = 0;
396 virtual void removeOutputTrack(IAfPlaybackThread* thread) = 0;
397};
398
399class IAfRecordThread : public virtual IAfThreadBase {
400public:
401 static sp<IAfRecordThread> create(
402 const sp<AudioFlinger>& audioFlinger, AudioStreamIn* input, audio_io_handle_t id,
403 bool systemReady);
404
405 virtual sp<IAfRecordTrack> createRecordTrack_l(
406 const sp<Client>& client,
407 const audio_attributes_t& attr,
408 uint32_t* pSampleRate,
409 audio_format_t format,
410 audio_channel_mask_t channelMask,
411 size_t* pFrameCount,
412 audio_session_t sessionId,
413 size_t* pNotificationFrameCount,
414 pid_t creatorPid,
415 const AttributionSourceState& attributionSource,
416 audio_input_flags_t* flags,
417 pid_t tid,
418 status_t* status /*non-NULL*/,
419 audio_port_handle_t portId,
420 int32_t maxSharedAudioHistoryMs) = 0;
421 virtual void destroyTrack_l(const sp<IAfRecordTrack>& track) = 0;
422 virtual void removeTrack_l(const sp<IAfRecordTrack>& track) = 0;
423
424 virtual status_t start(
425 IAfRecordTrack* recordTrack, AudioSystem::sync_event_t event,
426 audio_session_t triggerSession) = 0;
427
428 // ask the thread to stop the specified track, and
429 // return true if the caller should then do it's part of the stopping process
430 virtual bool stop(IAfRecordTrack* recordTrack) = 0;
431
432 virtual AudioStreamIn* getInput() const = 0;
433 virtual AudioStreamIn* clearInput() = 0;
434
435 virtual status_t getActiveMicrophones(
436 std::vector<media::MicrophoneInfoFw>* activeMicrophones) const = 0;
437 virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction) = 0;
438 virtual status_t setPreferredMicrophoneFieldDimension(float zoom) = 0;
439
440 virtual void addPatchTrack(const sp<IAfPatchRecord>& record) = 0;
441 virtual void deletePatchTrack(const sp<IAfPatchRecord>& record) = 0;
442 virtual bool fastTrackAvailable() const = 0;
443 virtual void setFastTrackAvailable(bool available) = 0;
444
445 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced) = 0;
446 virtual bool hasFastCapture() const = 0;
447
448 virtual void checkBtNrec() = 0;
449 virtual uint32_t getInputFramesLost() const = 0;
450
451 virtual status_t shareAudioHistory(
452 const std::string& sharedAudioPackageName,
453 audio_session_t sharedSessionId = AUDIO_SESSION_NONE,
454 int64_t sharedAudioStartMs = -1) = 0;
455 virtual void resetAudioHistory_l() = 0;
Andy Hung440901d2023-06-29 21:19:25 -0700456};
457
Andy Hung7aa7d102023-07-07 15:58:48 -0700458class IAfMmapThread : public virtual IAfThreadBase {
459public:
460 // createIAudioTrackAdapter() is a static constructor which creates an
461 // MmapStreamInterface AIDL interface adapter from the MmapThread object that
462 // may be passed back to the client.
463 //
464 // Only one AIDL MmapStreamInterface interface adapter should be created per MmapThread.
465 static sp<MmapStreamInterface> createMmapStreamInterfaceAdapter(
466 const sp<IAfMmapThread>& mmapThread);
467
468 virtual void configure(
469 const audio_attributes_t* attr,
470 audio_stream_type_t streamType,
471 audio_session_t sessionId,
472 const sp<MmapStreamCallback>& callback,
473 audio_port_handle_t deviceId,
474 audio_port_handle_t portId) = 0;
475 virtual void disconnect() = 0;
476
477 // MmapStreamInterface handling (see adapter)
478 virtual status_t createMmapBuffer(
479 int32_t minSizeFrames, struct audio_mmap_buffer_info* info) = 0;
480 virtual status_t getMmapPosition(struct audio_mmap_position* position) const = 0;
481 virtual status_t start(
482 const AudioClient& client, const audio_attributes_t* attr,
483 audio_port_handle_t* handle) = 0;
484 virtual status_t stop(audio_port_handle_t handle) = 0;
485 virtual status_t standby() = 0;
486 virtual status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const = 0;
487 virtual status_t reportData(const void* buffer, size_t frameCount) = 0;
488
489 // TODO(b/288339104) move to IAfThreadBase?
490 virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds) = 0;
491
492 // Sets the UID records silence - TODO(b/288339104) move to IAfMmapCaptureThread
493 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced) = 0;
494
495 virtual sp<IAfMmapPlaybackThread> asIAfMmapPlaybackThread() { return nullptr; }
496 virtual sp<IAfMmapCaptureThread> asIAfMmapCaptureThread() { return nullptr; }
497};
498
499class IAfMmapPlaybackThread : public virtual IAfMmapThread, public virtual VolumeInterface {
500public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700501 static sp<IAfMmapPlaybackThread> create(
502 const sp<AudioFlinger>& audioFlinger, audio_io_handle_t id, AudioHwDevice* hwDev,
503 AudioStreamOut* output, bool systemReady);
504
Andy Hung7aa7d102023-07-07 15:58:48 -0700505 virtual AudioStreamOut* clearOutput() = 0;
506};
507
508class IAfMmapCaptureThread : public virtual IAfMmapThread {
509public:
Andy Hungee58e4a2023-07-07 13:47:37 -0700510 static sp<IAfMmapCaptureThread> create(
511 const sp<AudioFlinger>& audioFlinger, audio_io_handle_t id, AudioHwDevice* hwDev,
512 AudioStreamIn* input, bool systemReady);
513
Andy Hung7aa7d102023-07-07 15:58:48 -0700514 virtual AudioStreamIn* clearInput() = 0;
515};
516
Andy Hung440901d2023-06-29 21:19:25 -0700517} // namespace android