summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Phil Burk <philburk@google.com> 2016-01-18 03:47:39 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-01-18 03:47:39 +0000
commit8c2dd1f7e7771c61e5aeb4570e097e258d18cdef (patch)
treebd278e757e9ae028d983edaebe0ebf3eee264b1c
parent9fe16a479a40034e1dac899a6bf8cff6b4e345e1 (diff)
parent03f61bbb2e7293592ad4a304b0f0b8e6ee8e6aac (diff)
Merge "Revert "Revert "AudioTrack: Add getUnderrunCount()"""
-rw-r--r--core/jni/android_media_AudioTrack.cpp12
-rw-r--r--media/java/android/media/AudioTrack.java22
2 files changed, 33 insertions, 1 deletions
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index 6ef97e6a1cae..61f185e10f4c 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -898,6 +898,17 @@ static jint android_media_AudioTrack_get_latency(JNIEnv *env, jobject thiz) {
return (jint)lpTrack->latency();
}
+// ----------------------------------------------------------------------------
+static jint android_media_AudioTrack_get_underrun_count(JNIEnv *env, jobject thiz) {
+ sp<AudioTrack> lpTrack = getAudioTrack(env, thiz);
+
+ if (lpTrack == NULL) {
+ jniThrowException(env, "java/lang/IllegalStateException",
+ "Unable to retrieve AudioTrack pointer for getUnderrunCount()");
+ return (jint)AUDIO_JAVA_ERROR;
+ }
+ return (jint)lpTrack->getUnderrunCount();
+}
// ----------------------------------------------------------------------------
static jint android_media_AudioTrack_get_timestamp(JNIEnv *env, jobject thiz, jlongArray jTimestamp) {
@@ -1139,6 +1150,7 @@ static const JNINativeMethod gMethods[] = {
{"native_set_position", "(I)I", (void *)android_media_AudioTrack_set_position},
{"native_get_position", "()I", (void *)android_media_AudioTrack_get_position},
{"native_get_latency", "()I", (void *)android_media_AudioTrack_get_latency},
+ {"native_get_underrun_count", "()I", (void *)android_media_AudioTrack_get_underrun_count},
{"native_get_timestamp", "([J)I", (void *)android_media_AudioTrack_get_timestamp},
{"native_set_loop", "(III)I", (void *)android_media_AudioTrack_set_loop},
{"native_reload_static", "()I", (void *)android_media_AudioTrack_reload},
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index 846922ea46d7..431984081405 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -42,7 +42,6 @@ import android.util.Log;
import com.android.internal.app.IAppOpsService;
-
/**
* The AudioTrack class manages and plays a single audio resource for Java applications.
* It allows streaming of PCM audio buffers to the audio sink for playback. This is
@@ -1193,6 +1192,25 @@ public class AudioTrack implements AudioRouting
}
/**
+ * Returns the number of underrun occurrences in the application-level write buffer
+ * since the AudioTrack was created.
+ * An underrun occurs if the application does not write audio
+ * data quickly enough, causing the buffer to underflow
+ * and a potential audio glitch or pop.
+ * Underruns are less likely when buffer sizes are large.
+ * <p> Though the "int" type is signed 32-bits, the value should be reinterpreted
+ * as if it is unsigned 32-bits.
+ * That is, the next position after 0x7FFFFFFF is (int) 0x80000000.
+ * This is a continuously advancing counter. It can wrap around to zero
+ * if there are too many underruns. If there were, for example, 68 underruns per
+ * second then the counter would wrap in 2 years.
+ * @hide
+ */
+ public int getUnderrunCount() {
+ return native_get_underrun_count();
+ }
+
+ /**
* Returns the output sample rate in Hz for the specified stream type.
*/
static public int getNativeOutputSampleRate(int streamType) {
@@ -2785,6 +2803,8 @@ public class AudioTrack implements AudioRouting
private native final int native_get_latency();
+ private native final int native_get_underrun_count();
+
// longArray must be a non-null array of length >= 2
// [0] is assigned the frame position
// [1] is assigned the time in CLOCK_MONOTONIC nanoseconds