fifo: non-throttling reader doesn't see data already written
Test: see the multi-reader interactive test
Change-Id: I0663a8e90efc094fef09401c6e2ecd3391100efa
diff --git a/audio_utils/fifo.cpp b/audio_utils/fifo.cpp
index 8f89318..ee36cbd 100644
--- a/audio_utils/fifo.cpp
+++ b/audio_utils/fifo.cpp
@@ -397,7 +397,16 @@
////////////////////////////////////////////////////////////////////////////////
audio_utils_fifo_reader::audio_utils_fifo_reader(audio_utils_fifo& fifo, bool throttlesWriter) :
- audio_utils_fifo_provider(fifo), mLocalFront(0),
+ audio_utils_fifo_provider(fifo),
+
+ // If we throttle the writer, then initialize our front index to zero so that we see all data
+ // currently in the buffer.
+ // Otherwise, ignore everything currently in the buffer by initializing our front index to the
+ // current value of writer's rear. This avoids an immediate -EOVERFLOW (overrun) in the case
+ // where reader starts out more than one buffer behind writer. The initial catch-up does not
+ // contribute towards the totalLost, totalFlushed, or totalReleased counters.
+ mLocalFront(throttlesWriter ? 0 : mFifo.mWriterRear.loadConsume()),
+
mThrottleFront(throttlesWriter ? mFifo.mThrottleFront : NULL),
mArmLevel(-1), mTriggerLevel(mFifo.mFrameCount),
mIsArmed(true), // because initial fill level of zero is > mArmLevel