Allow frame count regress in AudioStreamOut
AudioStreamOut attempts to detect wraparound by assuming that the
HAL frame count is monotonic, which is not true wrt gapless offload
tracks. When a non-monotonic update is detected, we freeze the fw
side framecount, rather than updating. The exception is when we
are notified that framecount will reset (e.g. flush()).
Since the notification that we are transitioning can occur arbitrarily
in advance from the HAL, upon presentationComplete for a offload stream,
we notify AudioStreamOut that we expect an upcoming framecount reset
from the HAL.
Then, we do not suppress the next detected non-monotonic sample, and
appropriately decrease the uint64 mRenderPosition.
Test: offloadAudioTrackPlayer manual test app (exoplayer test in
google3)
Bug: 191950723
Change-Id: I6060d0a9750783c2e2a7b46ce592c042d1405aa0
diff --git a/services/audioflinger/AudioStreamOut.h b/services/audioflinger/AudioStreamOut.h
index 565f43a..82fe238 100644
--- a/services/audioflinger/AudioStreamOut.h
+++ b/services/audioflinger/AudioStreamOut.h
@@ -93,13 +93,21 @@
virtual status_t flush();
virtual status_t standby();
+ // Avoid suppressing retrograde motion in mRenderPosition for gapless offload/direct when
+ // transitioning between tracks.
+ // The HAL resets the frame position without flush/stop being called, but calls back prior to
+ // this event. So, on the next occurrence of retrograde motion, we permit backwards movement of
+ // mRenderPosition.
+ virtual void presentationComplete() { mExpectRetrograde = true; }
+
protected:
uint64_t mFramesWritten; // reset by flush
uint64_t mFramesWrittenAtStandby;
- uint64_t mRenderPosition; // reset by flush or standby
+ uint64_t mRenderPosition; // reset by flush, standby, or presentation complete
int mRateMultiplier;
bool mHalFormatHasProportionalFrames;
size_t mHalFrameSize;
+ bool mExpectRetrograde; // see presentationComplete
};
} // namespace android