blob: 541be0a70e6d978ab77c54494bc09da562c92f03 [file] [log] [blame]
Andy Hungd29af632023-06-23 19:27:19 -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
19namespace android {
20
21// Common interface to all Playback and Record tracks.
22class IAfTrackBase : public virtual RefBase {
23public:
24 enum track_state : int32_t {
25 IDLE,
26 FLUSHED, // for PlaybackTracks only
27 STOPPED,
28 // next 2 states are currently used for fast tracks
29 // and offloaded tracks only
30 STOPPING_1, // waiting for first underrun
31 STOPPING_2, // waiting for presentation complete
32 RESUMING, // for PlaybackTracks only
33 ACTIVE,
34 PAUSING,
35 PAUSED,
36 STARTING_1, // for RecordTrack only
37 STARTING_2, // for RecordTrack only
38 };
39
40 // where to allocate the data buffer
41 enum alloc_type {
42 ALLOC_CBLK, // allocate immediately after control block
43 ALLOC_READONLY, // allocate from a separate read-only heap per thread
44 ALLOC_PIPE, // do not allocate; use the pipe buffer
45 ALLOC_LOCAL, // allocate a local buffer
46 ALLOC_NONE, // do not allocate:use the buffer passed to TrackBase constructor
47 };
48
49 enum track_type {
50 TYPE_DEFAULT,
51 TYPE_OUTPUT,
52 TYPE_PATCH,
53 };
54
55 virtual status_t initCheck() const = 0;
56 virtual status_t start(
57 AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE,
58 audio_session_t triggerSession = AUDIO_SESSION_NONE) = 0;
59 virtual void stop() = 0;
60 virtual sp<IMemory> getCblk() const = 0;
61 virtual audio_track_cblk_t* cblk() const = 0;
62 virtual audio_session_t sessionId() const = 0;
63 virtual uid_t uid() const = 0;
64 virtual pid_t creatorPid() const = 0;
65 virtual uint32_t sampleRate() const = 0;
66 virtual size_t frameSize() const = 0;
67 virtual audio_port_handle_t portId() const = 0;
68 virtual status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event) = 0;
69 virtual track_state state() const = 0;
70 virtual void setState(track_state state) = 0;
71 virtual sp<IMemory> getBuffers() const = 0;
72 virtual void* buffer() const = 0;
73 virtual size_t bufferSize() const = 0;
74 virtual bool isFastTrack() const = 0;
75 virtual bool isDirect() const = 0;
76 virtual bool isOutputTrack() const = 0;
77 virtual bool isPatchTrack() const = 0;
78 virtual bool isExternalTrack() const = 0;
79
80 virtual void invalidate() = 0;
81 virtual bool isInvalid() const = 0;
82
83 virtual void terminate() = 0;
84 virtual bool isTerminated() const = 0;
85
86 virtual audio_attributes_t attributes() const = 0;
87 virtual bool isSpatialized() const = 0;
88 virtual bool isBitPerfect() const = 0;
89
90 // not currently implemented in TrackBase, but overridden.
91 virtual void destroy() {}; // MmapTrack doesn't implement.
92 virtual void appendDumpHeader(String8& result) const = 0;
93 virtual void appendDump(String8& result, bool active) const = 0;
94
95 // Dup with AudioBufferProvider interface
96 virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0;
97 virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer) = 0;
98
99 // Added for RecordTrack and OutputTrack
100 // TODO(b/288339104) type
101 virtual wp<Thread> thread() const = 0;
102 virtual const sp<ServerProxy>& serverProxy() const = 0;
103
104 // TEE_SINK
105 virtual void dumpTee(int fd __unused, const std::string& reason __unused) const {};
106
107 /** returns the buffer contents size converted to time in milliseconds
108 * for PCM Playback or Record streaming tracks. The return value is zero for
109 * PCM static tracks and not defined for non-PCM tracks.
110 *
111 * This may be called without the thread lock.
112 */
113 virtual double bufferLatencyMs() const = 0;
114
115 /** returns whether the track supports server latency computation.
116 * This is set in the constructor and constant throughout the track lifetime.
117 */
118 virtual bool isServerLatencySupported() const = 0;
119
120 /** computes the server latency for PCM Playback or Record track
121 * to the device sink/source. This is the time for the next frame in the track buffer
122 * written or read from the server thread to the device source or sink.
123 *
124 * This may be called without the thread lock, but latencyMs and fromTrack
125 * may be not be synchronized. For example PatchPanel may not obtain the
126 * thread lock before calling.
127 *
128 * \param latencyMs on success is set to the latency in milliseconds of the
129 * next frame written/read by the server thread to/from the track buffer
130 * from the device source/sink.
131 * \param fromTrack on success is set to true if latency was computed directly
132 * from the track timestamp; otherwise set to false if latency was
133 * estimated from the server timestamp.
134 * fromTrack may be nullptr or omitted if not required.
135 *
136 * \returns OK or INVALID_OPERATION on failure.
137 */
138 virtual status_t getServerLatencyMs(double* latencyMs, bool* fromTrack = nullptr) const = 0;
139
140 /** computes the total client latency for PCM Playback or Record tracks
141 * for the next client app access to the device sink/source; i.e. the
142 * server latency plus the buffer latency.
143 *
144 * This may be called without the thread lock, but latencyMs and fromTrack
145 * may be not be synchronized. For example PatchPanel may not obtain the
146 * thread lock before calling.
147 *
148 * \param latencyMs on success is set to the latency in milliseconds of the
149 * next frame written/read by the client app to/from the track buffer
150 * from the device sink/source.
151 * \param fromTrack on success is set to true if latency was computed directly
152 * from the track timestamp; otherwise set to false if latency was
153 * estimated from the server timestamp.
154 * fromTrack may be nullptr or omitted if not required.
155 *
156 * \returns OK or INVALID_OPERATION on failure.
157 */
158 virtual status_t getTrackLatencyMs(double* latencyMs, bool* fromTrack = nullptr) const = 0;
159
160 // TODO: Consider making this external.
161 struct FrameTime {
162 int64_t frames;
163 int64_t timeNs;
164 };
165
166 // KernelFrameTime is updated per "mix" period even for non-pcm tracks.
167 virtual void getKernelFrameTime(FrameTime* ft) const = 0;
168
169 virtual audio_format_t format() const = 0;
170 virtual int id() const = 0;
171
172 virtual const char* getTrackStateAsString() const = 0;
173
174 // Called by the PlaybackThread to indicate that the track is becoming active
175 // and a new interval should start with a given device list.
176 virtual void logBeginInterval(const std::string& devices) = 0;
177
178 // Called by the PlaybackThread to indicate the track is no longer active.
179 virtual void logEndInterval() = 0;
180
181 // Called to tally underrun frames in playback.
182 virtual void tallyUnderrunFrames(size_t frames) = 0;
183
184 virtual audio_channel_mask_t channelMask() const = 0;
185
186 /** @return true if the track has changed (metadata or volume) since
187 * the last time this function was called,
188 * true if this function was never called since the track creation,
189 * false otherwise.
190 * Thread safe.
191 */
192 virtual bool readAndClearHasChanged() = 0;
193
194 /** Set that a metadata has changed and needs to be notified to backend. Thread safe. */
195 virtual void setMetadataHasChanged() = 0;
196
197 /**
198 * Called when a track moves to active state to record its contribution to battery usage.
199 * Track state transitions should eventually be handled within the track class.
200 */
201 virtual void beginBatteryAttribution() = 0;
202
203 /**
204 * Called when a track moves out of the active state to record its contribution
205 * to battery usage.
206 */
207 virtual void endBatteryAttribution() = 0;
208
209 /**
210 * For RecordTrack
211 * TODO(b/288339104) either use this or add asRecordTrack or asTrack etc.
212 */
213 virtual void handleSyncStartEvent(const sp<audioflinger::SyncEvent>& event __unused){};
214
215 // For Thread use, fast tracks and offloaded tracks only
216 // TODO(b/288339104) rearrange to IAfTrack.
217 virtual bool isStopped() const = 0;
218 virtual bool isStopping() const = 0;
219 virtual bool isStopping_1() const = 0;
220 virtual bool isStopping_2() const = 0;
221};
222
223// Common interface for Playback tracks.
224class IAfTrack : public virtual IAfTrackBase {
225public:
Andy Hung8d31fd22023-06-26 19:20:57 -0700226 // FillingStatus is used for suppressing volume ramp at begin of playing
227 enum FillingStatus { FS_INVALID, FS_FILLING, FS_FILLED, FS_ACTIVE };
228
Andy Hungd29af632023-06-23 19:27:19 -0700229 // createIAudioTrackAdapter() is a static constructor which creates an
230 // IAudioTrack AIDL interface adapter from the Track object that
231 // may be passed back to the client (if needed).
232 //
233 // Only one AIDL IAudioTrack interface adapter should be created per Track.
234 static sp<media::IAudioTrack> createIAudioTrackAdapter(const sp<IAfTrack>& track);
235
Andy Hung8d31fd22023-06-26 19:20:57 -0700236 static sp<IAfTrack> create( // TODO(b/288339104) void*
237 void* /* AudioFlinger::PlaybackThread */ thread,
238 const sp<Client>& client,
239 audio_stream_type_t streamType,
240 const audio_attributes_t& attr,
241 uint32_t sampleRate,
242 audio_format_t format,
243 audio_channel_mask_t channelMask,
244 size_t frameCount,
245 void* buffer,
246 size_t bufferSize,
247 const sp<IMemory>& sharedBuffer,
248 audio_session_t sessionId,
249 pid_t creatorPid,
250 const AttributionSourceState& attributionSource,
251 audio_output_flags_t flags,
252 track_type type,
253 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE,
254 /** default behaviour is to start when there are as many frames
255 * ready as possible (aka. Buffer is full). */
256 size_t frameCountToBeReady = SIZE_MAX,
257 float speed = 1.0f,
258 bool isSpatialized = false,
259 bool isBitPerfect = false);
260
Andy Hungd29af632023-06-23 19:27:19 -0700261 virtual void pause() = 0;
262 virtual void flush() = 0;
263 virtual audio_stream_type_t streamType() const = 0;
264 virtual bool isOffloaded() const = 0;
265 virtual bool isOffloadedOrDirect() const = 0;
266 virtual bool isStatic() const = 0;
267 virtual status_t setParameters(const String8& keyValuePairs) = 0;
268 virtual status_t selectPresentation(int presentationId, int programId) = 0;
269 virtual status_t attachAuxEffect(int EffectId) = 0;
270 virtual void setAuxBuffer(int EffectId, int32_t* buffer) = 0;
271 virtual int32_t* auxBuffer() const = 0;
272 virtual void setMainBuffer(float* buffer) = 0;
273 virtual float* mainBuffer() const = 0;
274 virtual int auxEffectId() const = 0;
275 virtual status_t getTimestamp(AudioTimestamp& timestamp) = 0;
276 virtual void signal() = 0;
277 virtual status_t getDualMonoMode(audio_dual_mono_mode_t* mode) const = 0;
278 virtual status_t setDualMonoMode(audio_dual_mono_mode_t mode) = 0;
279 virtual status_t getAudioDescriptionMixLevel(float* leveldB) const = 0;
280 virtual status_t setAudioDescriptionMixLevel(float leveldB) = 0;
281 virtual status_t getPlaybackRateParameters(audio_playback_rate_t* playbackRate) const = 0;
282 virtual status_t setPlaybackRateParameters(const audio_playback_rate_t& playbackRate) = 0;
283
284 // implement FastMixerState::VolumeProvider interface
285 virtual gain_minifloat_packed_t getVolumeLR() const = 0;
286
287 // implement volume handling.
288 virtual media::VolumeShaper::Status applyVolumeShaper(
289 const sp<media::VolumeShaper::Configuration>& configuration,
290 const sp<media::VolumeShaper::Operation>& operation) = 0;
291 virtual sp<media::VolumeShaper::State> getVolumeShaperState(int id) const = 0;
292 virtual sp<media::VolumeHandler> getVolumeHandler() const = 0;
293 /** Set the computed normalized final volume of the track.
294 * !masterMute * masterVolume * streamVolume * averageLRVolume */
295 virtual void setFinalVolume(float volumeLeft, float volumeRight) = 0;
296 virtual float getFinalVolume() const = 0;
297 virtual void getFinalVolume(float* left, float* right) const = 0;
298
299 using SourceMetadatas = std::vector<playback_track_metadata_v7_t>;
300 using MetadataInserter = std::back_insert_iterator<SourceMetadatas>;
301 /** Copy the track metadata in the provided iterator. Thread safe. */
302 virtual void copyMetadataTo(MetadataInserter& backInserter) const = 0;
303
304 /** Return haptic playback of the track is enabled or not, used in mixer. */
305 virtual bool getHapticPlaybackEnabled() const = 0;
306 /** Set haptic playback of the track is enabled or not, should be
307 * set after query or get callback from vibrator service */
308 virtual void setHapticPlaybackEnabled(bool hapticPlaybackEnabled) = 0;
309 /** Return at what intensity to play haptics, used in mixer. */
310 virtual os::HapticScale getHapticIntensity() const = 0;
311 /** Return the maximum amplitude allowed for haptics data, used in mixer. */
312 virtual float getHapticMaxAmplitude() const = 0;
313 /** Set intensity of haptic playback, should be set after querying vibrator service. */
314 virtual void setHapticIntensity(os::HapticScale hapticIntensity) = 0;
315 /** Set maximum amplitude allowed for haptic data, should be set after querying
316 * vibrator service.
317 */
318 virtual void setHapticMaxAmplitude(float maxAmplitude) = 0;
319 virtual sp<os::ExternalVibration> getExternalVibration() const = 0;
320
321 // This function should be called with holding thread lock.
322 virtual void updateTeePatches_l() = 0;
323
324 // TODO(b/288339104) type
325 virtual void setTeePatchesToUpdate_l(
326 const void* teePatchesToUpdate /* TeePatches& teePatchesToUpdate */) = 0;
327
328 static bool checkServerLatencySupported(audio_format_t format, audio_output_flags_t flags) {
329 return audio_is_linear_pcm(format) && (flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) == 0;
330 }
331
332 virtual audio_output_flags_t getOutputFlags() const = 0;
333 virtual float getSpeed() const = 0;
334
335 /**
336 * Updates the mute state and notifies the audio service. Call this only when holding player
337 * thread lock.
338 */
339 virtual void processMuteEvent_l(
340 const sp<IAudioManager>& audioManager, mute_state_t muteState) = 0;
341
342 virtual void triggerEvents(AudioSystem::sync_event_t type) = 0;
343
344 virtual void disable() = 0;
345 virtual int& fastIndex() = 0;
346 virtual bool isPlaybackRestricted() const = 0;
Andy Hung8d31fd22023-06-26 19:20:57 -0700347
348 // Used by thread only
349
350 virtual bool isPausing() const = 0;
351 virtual bool isPaused() const = 0;
352 virtual bool isResuming() const = 0;
353 virtual bool isReady() const = 0;
354 virtual void setPaused() = 0;
355 virtual void reset() = 0;
356 virtual bool isFlushPending() const = 0;
357 virtual void flushAck() = 0;
358 virtual bool isResumePending() const = 0;
359 virtual void resumeAck() = 0;
360 // For direct or offloaded tracks ensure that the pause state is acknowledged
361 // by the playback thread in case of an immediate flush.
362 virtual bool isPausePending() const = 0;
363 virtual void pauseAck() = 0;
364 virtual void updateTrackFrameInfo(
365 int64_t trackFramesReleased, int64_t sinkFramesWritten, uint32_t halSampleRate,
366 const ExtendedTimestamp& timeStamp) = 0;
367 virtual sp<IMemory> sharedBuffer() const = 0;
368
369 // Dup with ExtendedAudioBufferProvider
370 virtual size_t framesReady() const = 0;
371
372 // presentationComplete checked by frames. (Mixed Tracks).
373 // framesWritten is cumulative, never reset, and is shared all tracks
374 // audioHalFrames is derived from output latency
375 virtual bool presentationComplete(int64_t framesWritten, size_t audioHalFrames) = 0;
376
377 // presentationComplete checked by time. (Direct Tracks).
378 virtual bool presentationComplete(uint32_t latencyMs) = 0;
379
380 virtual void resetPresentationComplete() = 0;
381
382 virtual bool hasVolumeController() const = 0;
383 virtual void setHasVolumeController(bool hasVolumeController) = 0;
384 virtual const sp<AudioTrackServerProxy>& audioTrackServerProxy() const = 0;
385 virtual void setCachedVolume(float volume) = 0;
386 virtual void setResetDone(bool resetDone) = 0;
387
388 virtual ExtendedAudioBufferProvider* asExtendedAudioBufferProvider() = 0;
389 virtual VolumeProvider* asVolumeProvider() = 0;
390
391 // TODO(b/288339104) split into getter/setter
392 virtual FillingStatus& fillingStatus() = 0;
393 virtual int8_t& retryCount() = 0;
394 virtual FastTrackUnderruns& fastTrackUnderruns() = 0;
Andy Hungd29af632023-06-23 19:27:19 -0700395};
396
397// playback track, used by DuplicatingThread
398class IAfOutputTrack : public virtual IAfTrack {
399public:
Andy Hung8d31fd22023-06-26 19:20:57 -0700400 // TODO(b/288339104) void*
401 static sp<IAfOutputTrack> create(
402 void* /* AudioFlinger::PlaybackThread */ playbackThread,
403 void* /* AudioFlinger::DuplicatingThread */ sourceThread, uint32_t sampleRate,
404 audio_format_t format, audio_channel_mask_t channelMask, size_t frameCount,
405 const AttributionSourceState& attributionSource);
406
Andy Hungd29af632023-06-23 19:27:19 -0700407 virtual ssize_t write(void* data, uint32_t frames) = 0;
408 virtual bool bufferQueueEmpty() const = 0;
409 virtual bool isActive() const = 0;
410
411 /** Set the metadatas of the upstream tracks. Thread safe. */
412 virtual void setMetadatas(const SourceMetadatas& metadatas) = 0;
413 /** returns client timestamp to the upstream duplicating thread. */
414 virtual ExtendedTimestamp getClientProxyTimestamp() const = 0;
415};
416
417class IAfMmapTrack : public virtual IAfTrackBase {
418public:
Andy Hung8d31fd22023-06-26 19:20:57 -0700419 // TODO(b/288339104) void*
420 static sp<IAfMmapTrack> create(void* /*AudioFlinger::ThreadBase */ thread,
421 const audio_attributes_t& attr,
422 uint32_t sampleRate,
423 audio_format_t format,
424 audio_channel_mask_t channelMask,
425 audio_session_t sessionId,
426 bool isOut,
427 const android::content::AttributionSourceState& attributionSource,
428 pid_t creatorPid,
429 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
430
Andy Hungd29af632023-06-23 19:27:19 -0700431 // protected by MMapThread::mLock
432 virtual void setSilenced_l(bool silenced) = 0;
433 // protected by MMapThread::mLock
434 virtual bool isSilenced_l() const = 0;
435 // protected by MMapThread::mLock
436 virtual bool getAndSetSilencedNotified_l() = 0;
437
438 /**
439 * Updates the mute state and notifies the audio service. Call this only when holding player
440 * thread lock.
441 */
442 virtual void processMuteEvent_l( // see IAfTrack
443 const sp<IAudioManager>& audioManager, mute_state_t muteState) = 0;
444};
445
Andy Hung8d31fd22023-06-26 19:20:57 -0700446class RecordBufferConverter;
447
Andy Hungd29af632023-06-23 19:27:19 -0700448class IAfRecordTrack : public virtual IAfTrackBase {
449public:
450 // createIAudioRecordAdapter() is a static constructor which creates an
451 // IAudioRecord AIDL interface adapter from the RecordTrack object that
452 // may be passed back to the client (if needed).
453 //
454 // Only one AIDL IAudioRecord interface adapter should be created per RecordTrack.
455 static sp<media::IAudioRecord> createIAudioRecordAdapter(const sp<IAfRecordTrack>& recordTrack);
456
Andy Hung8d31fd22023-06-26 19:20:57 -0700457 // TODO(b/288339104) void*
458 static sp<IAfRecordTrack> create(void* /* AudioFlinger::RecordThread */ thread,
459 const sp<Client>& client,
460 const audio_attributes_t& attr,
461 uint32_t sampleRate,
462 audio_format_t format,
463 audio_channel_mask_t channelMask,
464 size_t frameCount,
465 void* buffer,
466 size_t bufferSize,
467 audio_session_t sessionId,
468 pid_t creatorPid,
469 const AttributionSourceState& attributionSource,
470 audio_input_flags_t flags,
471 track_type type,
472 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE,
473 int32_t startFrames = -1);
474
Andy Hungd29af632023-06-23 19:27:19 -0700475 // clear the buffer overflow flag
476 virtual void clearOverflow() = 0;
477 // set the buffer overflow flag and return previous value
478 virtual bool setOverflow() = 0;
479
480 // TODO(b/288339104) handleSyncStartEvent in IAfTrackBase should move here.
481 virtual void clearSyncStartEvent() = 0;
482 virtual void updateTrackFrameInfo(
483 int64_t trackFramesReleased, int64_t sourceFramesRead, uint32_t halSampleRate,
484 const ExtendedTimestamp& timestamp) = 0;
485
486 virtual void setSilenced(bool silenced) = 0;
487 virtual bool isSilenced() const = 0;
488 virtual status_t getActiveMicrophones(
489 std::vector<media::MicrophoneInfoFw>* activeMicrophones) const = 0;
490
491 virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction) = 0;
492 virtual status_t setPreferredMicrophoneFieldDimension(float zoom) = 0;
493 virtual status_t shareAudioHistory(
494 const std::string& sharedAudioPackageName, int64_t sharedAudioStartMs) = 0;
495 virtual int32_t startFrames() const = 0;
496
497 static bool checkServerLatencySupported(audio_format_t format, audio_input_flags_t flags) {
498 return audio_is_linear_pcm(format) && (flags & AUDIO_INPUT_FLAG_HW_AV_SYNC) == 0;
499 }
500
501 using SinkMetadatas = std::vector<record_track_metadata_v7_t>;
502 using MetadataInserter = std::back_insert_iterator<SinkMetadatas>;
503 virtual void copyMetadataTo(MetadataInserter& backInserter) const = 0; // see IAfTrack
Andy Hung8d31fd22023-06-26 19:20:57 -0700504
505 // private to Threads
506 virtual AudioBufferProvider::Buffer& sinkBuffer() = 0;
507 virtual audioflinger::SynchronizedRecordState& synchronizedRecordState() = 0;
508 virtual RecordBufferConverter* recordBufferConverter() const = 0;
509 virtual ResamplerBufferProvider* resamplerBufferProvider() const = 0;
Andy Hungd29af632023-06-23 19:27:19 -0700510};
511
Andy Hungca9be052023-06-26 19:20:57 -0700512// PatchProxyBufferProvider interface is implemented by PatchTrack and PatchRecord.
513// it provides buffer access methods that map those of a ClientProxy (see AudioTrackShared.h)
514class PatchProxyBufferProvider {
515public:
516 virtual ~PatchProxyBufferProvider() = default;
517 virtual bool producesBufferOnDemand() const = 0;
518 virtual status_t obtainBuffer(
519 Proxy::Buffer* buffer, const struct timespec* requested = nullptr) = 0;
520 virtual void releaseBuffer(Proxy::Buffer* buffer) = 0;
521};
522
523class IAfPatchTrackBase : public virtual RefBase {
524public:
Andy Hung8d31fd22023-06-26 19:20:57 -0700525 using Timeout = std::optional<std::chrono::nanoseconds>;
526
Andy Hungca9be052023-06-26 19:20:57 -0700527 virtual void setPeerTimeout(std::chrono::nanoseconds timeout) = 0;
528 virtual void setPeerProxy(const sp<IAfPatchTrackBase>& proxy, bool holdReference) = 0;
529 virtual void clearPeerProxy() = 0;
530 virtual PatchProxyBufferProvider* asPatchProxyBufferProvider() = 0;
531};
532
Andy Hung8d31fd22023-06-26 19:20:57 -0700533class IAfPatchTrack : public virtual IAfTrack, public virtual IAfPatchTrackBase {
534public:
535 static sp<IAfPatchTrack> create(
536 void * /* PlaybackThread */ playbackThread, // TODO(b/288339104)
537 audio_stream_type_t streamType,
538 uint32_t sampleRate,
539 audio_channel_mask_t channelMask,
540 audio_format_t format,
541 size_t frameCount,
542 void *buffer,
543 size_t bufferSize,
544 audio_output_flags_t flags,
545 const Timeout& timeout = {},
546 size_t frameCountToBeReady = 1 /** Default behaviour is to start
547 * as soon as possible to have
548 * the lowest possible latency
549 * even if it might glitch. */);
550};
Andy Hungca9be052023-06-26 19:20:57 -0700551
552// Abstraction for the Audio Source for the RecordThread (HAL or PassthruPatchRecord).
553struct Source {
554 virtual ~Source() = default;
555 // The following methods have the same signatures as in StreamHalInterface.
556 virtual status_t read(void* buffer, size_t bytes, size_t* read) = 0;
557 virtual status_t getCapturePosition(int64_t* frames, int64_t* time) = 0;
558 virtual status_t standby() = 0;
559};
560
561class IAfPatchRecord : public virtual IAfRecordTrack, public virtual IAfPatchTrackBase {
562public:
Andy Hung8d31fd22023-06-26 19:20:57 -0700563 static sp<IAfPatchRecord> create(
564 void* /* RecordThread */ recordThread, // TODO(b/288339104)
565 uint32_t sampleRate,
566 audio_channel_mask_t channelMask,
567 audio_format_t format,
568 size_t frameCount,
569 void* buffer,
570 size_t bufferSize,
571 audio_input_flags_t flags,
572 const Timeout& timeout = {},
573 audio_source_t source = AUDIO_SOURCE_DEFAULT);
574
575 static sp<IAfPatchRecord> createPassThru(
576 void* /* RecordThread */ recordThread, // TODO(b/288339104)
577 uint32_t sampleRate,
578 audio_channel_mask_t channelMask,
579 audio_format_t format,
580 size_t frameCount,
581 audio_input_flags_t flags,
582 audio_source_t source = AUDIO_SOURCE_DEFAULT);
583
Andy Hungca9be052023-06-26 19:20:57 -0700584 virtual Source* getSource() = 0;
585 virtual size_t writeFrames(const void* src, size_t frameCount, size_t frameSize) = 0;
586};
587
Andy Hungd29af632023-06-23 19:27:19 -0700588} // namespace android