AudioTrack: Add getUnderrunCount()
This allows an app to detect application-level output glitches.
Underrun counts survive track recreation.
Change-Id: I8eb14e92f6fc1007718a29b0666ab51ace30cdb8
Bug: 25641253
Signed-off-by: Phil Burk <philburk@google.com>
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 5e14940..31e88c3 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -493,6 +493,7 @@
mPreviousTimestampValid = false;
mTimestampStartupGlitchReported = false;
mRetrogradeMotionReported = false;
+ mUnderrunCountOffset = 0;
return NO_ERROR;
}
@@ -2112,6 +2113,9 @@
return DEAD_OBJECT;
}
+ // Save so we can return count since creation.
+ mUnderrunCountOffset = getUnderrunCount_l();
+
// save the old static buffer position
size_t bufferPosition = 0;
int loopCount = 0;
@@ -2427,6 +2431,17 @@
return NO_ERROR;
}
+uint32_t AudioTrack::getUnderrunCount() const
+{
+ AutoMutex lock(mLock);
+ return getUnderrunCount_l();
+}
+
+uint32_t AudioTrack::getUnderrunCount_l() const
+{
+ return mProxy->getUnderrunCount() + mUnderrunCountOffset;
+}
+
uint32_t AudioTrack::getUnderrunFrames() const
{
AutoMutex lock(mLock);