24#include "oboe/Definitions.h"
25#include "oboe/ResultWithValue.h"
26#include "oboe/AudioStreamBuilder.h"
27#include "oboe/AudioStreamBase.h"
37constexpr int64_t kDefaultTimeoutNanos = (2000 * kNanosPerMillisecond);
89 return Result::ErrorUnimplemented;
101 virtual Result
start(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
107 virtual Result
pause(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
113 virtual Result
flush(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
119 virtual Result
stop(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
184 StreamState *nextState,
185 int64_t timeoutNanoseconds) = 0;
207 return Result::ErrorUnimplemented;
328 return Result::ErrorUnimplemented;
482 return mErrorCallbackResult;
486 int32_t getDelayBeforeCloseMillis()
const {
487 return mDelayBeforeCloseMillis;
532 mPerformanceHintEnabled =
enabled;
542 return mPerformanceHintEnabled;
572 return oboe::Result::ErrorUnimplemented;
587 return mErrorCallbackCalled.exchange(
true);
608 return DataCallbackResult::Stop;
625 return mDataCallbackEnabled;
633 mDataCallbackEnabled =
enabled;
646 if (mDelayBeforeCloseMillis > 0) {
647 usleep(mDelayBeforeCloseMillis * 1000);
671 void setWeakThis(std::shared_ptr<oboe::AudioStream> &
sharedStream) {
678 std::shared_ptr<oboe::AudioStream> lockWeakThis() {
679 return mWeakThis.lock();
682 std::weak_ptr<AudioStream> mWeakThis;
702 oboe::Result mErrorCallbackResult = oboe::Result::OK;
712 static constexpr int kMinDelayBeforeCloseMillis = 10;
713 int32_t mDelayBeforeCloseMillis = kMinDelayBeforeCloseMillis;
718 void checkScheduler();
719 int mPreviousScheduler = -1;
721 std::atomic<bool> mDataCallbackEnabled{
false};
722 std::atomic<bool> mErrorCallbackCalled{
false};
724 std::atomic<bool> mPerformanceHintEnabled{
false};
Definition AudioStreamBase.h:30
int32_t mChannelCount
Definition AudioStreamBase.h:250
AudioStreamDataCallback * mDataCallback
Definition AudioStreamBase.h:240
AudioStreamErrorCallback * mErrorCallback
Definition AudioStreamBase.h:244
Definition AudioStreamBuilder.h:34
Definition AudioStreamCallback.h:34
Definition AudioStreamCallback.h:102
Definition AudioStream.h:42
int32_t mFramesPerBurst
Definition AudioStream.h:708
virtual Result pause(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
std::atomic< int64_t > mFramesRead
Definition AudioStream.h:698
virtual Result waitForStateChange(StreamState inputState, StreamState *nextState, int64_t timeoutNanoseconds)=0
virtual DataCallbackResult onDefaultCallback(void *, int)
Definition AudioStream.h:607
void setDataCallbackEnabled(bool enabled)
Definition AudioStream.h:632
bool usesAAudio() const
Definition AudioStream.h:402
virtual AudioApi getAudioApi() const =0
int32_t getFramesPerBurst() const
Definition AudioStream.h:236
virtual Result flush(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
virtual Result requestStart()=0
virtual ResultWithValue< double > calculateLatencyMillis()
Definition AudioStream.h:300
virtual ResultWithValue< int32_t > read(void *, int32_t, int64_t)
Definition AudioStream.h:384
virtual bool isXRunCountSupported() const =0
int32_t getBytesPerSample() const
virtual ResultWithValue< int32_t > getXRunCount()
Definition AudioStream.h:222
virtual void updateFramesRead()=0
virtual StreamState getState()=0
virtual Result release()
Definition AudioStream.h:88
virtual void closePerformanceHint()
Definition AudioStream.h:665
int32_t getBytesPerFrame() const
Definition AudioStream.h:247
void sleepBeforeClose()
Definition AudioStream.h:645
virtual void updateFramesWritten()=0
virtual Result open()
Definition AudioStream.h:65
virtual void beginPerformanceHintInCallback()
Definition AudioStream.h:654
virtual Result requestFlush()=0
virtual void endPerformanceHintInCallback(int32_t)
Definition AudioStream.h:660
virtual Result requestPause()=0
virtual Result requestStop()=0
std::atomic< int64_t > mFramesWritten
Definition AudioStream.h:690
virtual Result waitForStateTransition(StreamState startingState, StreamState endingState, int64_t timeoutNanoseconds)
virtual void * getUnderlyingStream() const
Definition AudioStream.h:414
AudioStream(const AudioStreamBuilder &builder)
virtual oboe::Result getLastErrorCallbackResult() const
Definition AudioStream.h:481
virtual oboe::Result reportWorkload(int32_t appWorkload)
Definition AudioStream.h:571
bool isPerformanceHintEnabled()
Definition AudioStream.h:541
bool wasErrorCallbackCalled()
Definition AudioStream.h:586
ResultWithValue< int32_t > getAvailableFrames()
virtual ResultWithValue< int32_t > setBufferSizeInFrames(int32_t)
Definition AudioStream.h:206
virtual int64_t getFramesWritten()
DataCallbackResult fireDataCallback(void *audioData, int numFrames)
ResultWithValue< int32_t > waitForAvailableFrames(int32_t numFrames, int64_t timeoutNanoseconds)
virtual Result getTimestamp(clockid_t, int64_t *, int64_t *)
Definition AudioStream.h:325
virtual ResultWithValue< int32_t > write(const void *, int32_t, int64_t)
Definition AudioStream.h:366
void setPerformanceHintEnabled(bool enabled)
Definition AudioStream.h:531
bool isDataCallbackEnabled()
Definition AudioStream.h:624
virtual Result stop(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
virtual int64_t getFramesRead()
void calculateDefaultDelayBeforeCloseMillis()
virtual Result start(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
void setDelayBeforeCloseMillis(int32_t delayBeforeCloseMillis)
Definition AudioStream.h:504
virtual ResultWithValue< FrameTimestamp > getTimestamp(clockid_t)
Definition ResultWithValue.h:47
Definition AudioStream.h:731