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