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) {
{"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},
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
}
/**
+ * 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) {
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