AudioTrack: fix stall if setBufferSizeInFrames() called before play()
The server was waiting for a full buffer.
But the buffer was only getting partly filled.
So the stream was not starting.
The fix involves having the server look at the adjustable threshold.
Bug: 27505889
Change-Id: I5dbf686413e670dacbbecc9e0f838744e465f44f
Signed-off-by: Phil Burk <philburk@google.com>
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
index ea8a78e..24784ea 100644
--- a/include/private/media/AudioTrackShared.h
+++ b/include/private/media/AudioTrackShared.h
@@ -177,6 +177,10 @@
// server write-only, client read
ExtendedTimestampQueue::Shared mExtendedTimestampQueue;
+ // This is set by AudioTrack.setBufferSizeInFrames().
+ // A write will not fill the buffer above this limit.
+ volatile uint32_t mBufferSizeInFrames; // effective size of the buffer
+
public:
volatile int32_t mFlags; // combinations of CBLK_*
@@ -312,9 +316,9 @@
return mEpoch;
}
- size_t getBufferSizeInFrames() const { return mBufferSizeInFrames; }
- // See documentation for AudioTrack.setBufferSizeInFrames()
- size_t setBufferSizeInFrames(size_t requestedSize);
+ uint32_t getBufferSizeInFrames() const { return mBufferSizeInFrames; }
+ // See documentation for AudioTrack::setBufferSizeInFrames()
+ uint32_t setBufferSizeInFrames(uint32_t requestedSize);
status_t getTimestamp(ExtendedTimestamp *timestamp) {
if (timestamp == nullptr) {
@@ -329,12 +333,10 @@
mTimestamp.clear();
}
-protected:
- // This is set by AudioTrack.setBufferSizeInFrames().
- // A write will not fill the buffer above this limit.
- size_t mBufferSizeInFrames; // effective size of the buffer
-
private:
+ // This is a copy of mCblk->mBufferSizeInFrames
+ uint32_t mBufferSizeInFrames; // effective size of the buffer
+
Modulo<uint32_t> mEpoch;
// The shared buffer contents referred to by the timestamp observer
@@ -518,6 +520,11 @@
mTimestampMutator.push(timestamp);
}
+ // Get dynamic buffer size from the shared control block.
+ uint32_t getBufferSizeInFrames() const {
+ return android_atomic_acquire_load((int32_t *)&mCblk->mBufferSizeInFrames);
+ }
+
protected:
size_t mAvailToClient; // estimated frames available to client prior to releaseBuffer()
int32_t mFlush; // our copy of cblk->u.mStreaming.mFlush, for streaming output only