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/Threads.cpp b/services/audioflinger/Threads.cpp
index 9344e20..596ff36 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -6320,9 +6320,13 @@
track->isStopping_2() || track->isPaused()) {
// We have consumed all the buffers of this track.
// Remove it from the list of active tracks.
+ bool presComplete = false;
if (mStandby || !last ||
- track->presentationComplete(latency_l()) ||
+ (presComplete = track->presentationComplete(latency_l())) ||
track->isPaused() || mHwPaused) {
+ if (presComplete) {
+ mOutput->presentationComplete();
+ }
if (track->isStopping_2()) {
track->mState = TrackBase::STOPPED;
}
@@ -6901,7 +6905,8 @@
// Drain has completed or we are in standby, signal presentation complete
if (!(mDrainSequence & 1) || !last || mStandby) {
track->mState = TrackBase::STOPPED;
- track->presentationComplete(latency_l());
+ mOutput->presentationComplete();
+ track->presentationComplete(latency_l()); // always returns true
track->reset();
tracksToRemove->add(track);
// OFFLOADED stop resets frame counts.