aaudio: cleanup code that reads timing model
Only use the clock model for the position when
it is running and when the service is not updating
the FIFO counter.
Bug: 120932593
Bug: 122374244
Test: test_return_stop
Test: test_return_stop -i
Change-Id: I6d6a23b35dca5529b6221e1b3b4a4e6672093bf2
diff --git a/media/libaaudio/src/client/AudioStreamInternalCapture.cpp b/media/libaaudio/src/client/AudioStreamInternalCapture.cpp
index 7dcb620..a6cc45b 100644
--- a/media/libaaudio/src/client/AudioStreamInternalCapture.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternalCapture.cpp
@@ -210,17 +210,12 @@
}
int64_t AudioStreamInternalCapture::getFramesWritten() {
- int64_t framesWrittenHardware;
- if (isActive()) {
- framesWrittenHardware = mClockModel.convertTimeToPosition(AudioClock::getNanoseconds());
- } else {
- framesWrittenHardware = mAudioEndpoint.getDataWriteCounter();
- }
- // Prevent retrograde motion.
+ const int64_t framesWrittenHardware = isClockModelInControl()
+ ? mClockModel.convertTimeToPosition(AudioClock::getNanoseconds())
+ : mAudioEndpoint.getDataWriteCounter();
+ // Add service offset and prevent retrograde motion.
mLastFramesWritten = std::max(mLastFramesWritten,
framesWrittenHardware + mFramesOffsetFromService);
- //ALOGD("getFramesWritten() returns %lld",
- // (long long)mLastFramesWritten);
return mLastFramesWritten;
}