Limit cached timestamp use if HW fails to provide them
On some devices, if the HDMI cable is disconnected during use,
cached timestamp info can become very old.
Bug: 29423451
Change-Id: Ieecf5e98bad14d00b4f5f14b032c2cf66ae94ceb
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 1963da3..e8da341 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -2374,9 +2374,14 @@
if (location == ExtendedTimestamp::LOCATION_SERVER) {
ALOGW_IF(mPreviousLocation == ExtendedTimestamp::LOCATION_KERNEL,
"getTimestamp() location moved from kernel to server");
+ // check that the last kernel OK time info exists and the positions
+ // are valid (if they predate the current track, the positions may
+ // be zero or negative).
const int64_t frames =
(ets.mTimeNs[ExtendedTimestamp::LOCATION_SERVER_LASTKERNELOK] < 0 ||
- ets.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL_LASTKERNELOK] < 0)
+ ets.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL_LASTKERNELOK] < 0 ||
+ ets.mPosition[ExtendedTimestamp::LOCATION_SERVER_LASTKERNELOK] <= 0 ||
+ ets.mPosition[ExtendedTimestamp::LOCATION_KERNEL_LASTKERNELOK] <= 0)
?
int64_t((double)mAfLatency * mSampleRate * mPlaybackRate.mSpeed
/ 1000)