libaaudio: implement callback
Use AudioTrack and AudioRecord TRANSFER_CALLBACK.
Add FixedBlockAdapter to provide fixed size callbacks.
Bug: 36489240
Test: CTS test_aaudio.cpp
Change-Id: Id2034dd640f878dd27fee6b43ad80a01c627dfd6
Signed-off-by: Phil Burk <philburk@google.com>
(cherry picked from commit c8f372c22a0e4c667a3ad3c1ec569032574c1d64)
diff --git a/media/libaaudio/src/client/AudioStreamInternal.h b/media/libaaudio/src/client/AudioStreamInternal.h
index 6f3a7ac..9a15a9b 100644
--- a/media/libaaudio/src/client/AudioStreamInternal.h
+++ b/media/libaaudio/src/client/AudioStreamInternal.h
@@ -53,7 +53,7 @@
int64_t *timeNanoseconds) override;
- virtual aaudio_result_t updateState() override;
+ virtual aaudio_result_t updateStateWhileWaiting() override;
// =========== End ABSTRACT methods ===========================
virtual aaudio_result_t open(const AudioStreamBuilder &builder) override;
@@ -64,10 +64,6 @@
int32_t numFrames,
int64_t timeoutNanoseconds) override;
- virtual aaudio_result_t waitForStateChange(aaudio_stream_state_t currentState,
- aaudio_stream_state_t *nextState,
- int64_t timeoutNanoseconds) override;
-
virtual aaudio_result_t setBufferSize(int32_t requestedFrames) override;
virtual int32_t getBufferSize() const override;
@@ -86,10 +82,17 @@
virtual aaudio_result_t unregisterThread() override;
+ // Called internally from 'C'
+ void *callbackLoop();
+
protected:
aaudio_result_t processCommands();
+ aaudio_result_t requestPauseInternal();
+
+ aaudio_result_t stopCallback();
+
/**
* Low level write that will not block. It will just write as much as it can.
*
@@ -108,17 +111,22 @@
aaudio_result_t onTimestampFromServer(AAudioServiceMessage *message);
+ // Calculate timeout for an operation involving framesPerOperation.
+ int64_t calculateReasonableTimeout(int32_t framesPerOperation);
+
private:
IsochronousClockModel mClockModel;
AudioEndpoint mAudioEndpoint;
aaudio_handle_t mServiceStreamHandle;
EndpointDescriptor mEndpointDescriptor;
+ uint8_t *mCallbackBuffer = nullptr;
+ int32_t mCallbackFrames = 0;
+
// Offset from underlying frame position.
int64_t mFramesOffsetFromService = 0;
int64_t mLastFramesRead = 0;
int32_t mFramesPerBurst;
int32_t mXRunCount = 0;
-
void processTimestamp(uint64_t position, int64_t time);
};