Merge "Expose latency methods through AudioManager and AudioTrack." into jb-mr2-dev

This commit is contained in:
Oliver Woodman
2013-07-02 08:11:13 +00:00
committed by Android (Google) Code Review
5 changed files with 52 additions and 0 deletions

View File

@@ -271,6 +271,17 @@ android_media_AudioSystem_getPrimaryOutputFrameCount(JNIEnv *env, jobject clazz)
return (jint) AudioSystem::getPrimaryOutputFrameCount();
}
static jint
android_media_AudioSystem_getOutputLatency(JNIEnv *env, jobject clazz, jint stream)
{
uint32_t afLatency;
if (AudioSystem::getOutputLatency(&afLatency, static_cast <audio_stream_type_t>(stream))
!= NO_ERROR) {
afLatency = -1;
}
return (jint) afLatency;
}
// ----------------------------------------------------------------------------
static JNINativeMethod gMethods[] = {
@@ -296,6 +307,7 @@ static JNINativeMethod gMethods[] = {
{"getDevicesForStream", "(I)I", (void *)android_media_AudioSystem_getDevicesForStream},
{"getPrimaryOutputSamplingRate", "()I", (void *)android_media_AudioSystem_getPrimaryOutputSamplingRate},
{"getPrimaryOutputFrameCount", "()I", (void *)android_media_AudioSystem_getPrimaryOutputFrameCount},
{"getOutputLatency", "(I)I", (void *)android_media_AudioSystem_getOutputLatency},
};
int register_android_media_AudioSystem(JNIEnv *env)

View File

@@ -727,6 +727,19 @@ static jint android_media_AudioTrack_get_position(JNIEnv *env, jobject thiz) {
}
// ----------------------------------------------------------------------------
static jint android_media_AudioTrack_get_latency(JNIEnv *env, jobject thiz) {
sp<AudioTrack> lpTrack = getAudioTrack(env, thiz);
if (lpTrack == NULL) {
jniThrowException(env, "java/lang/IllegalStateException",
"Unable to retrieve AudioTrack pointer for latency()");
return AUDIOTRACK_ERROR;
}
return (jint)lpTrack->latency();
}
// ----------------------------------------------------------------------------
static jint android_media_AudioTrack_set_loop(JNIEnv *env, jobject thiz,
jint loopStart, jint loopEnd, jint loopCount) {
@@ -854,6 +867,7 @@ static JNINativeMethod gMethods[] = {
"()I", (void *)android_media_AudioTrack_get_pos_update_period},
{"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_set_loop", "(III)I", (void *)android_media_AudioTrack_set_loop},
{"native_reload_static", "()I", (void *)android_media_AudioTrack_reload},
{"native_get_output_sample_rate",

View File

@@ -2553,4 +2553,15 @@ public class AudioManager {
}
}
/**
* Returns the estimated latency for the given stream type in milliseconds.
*
* DO NOT UNHIDE. The existing approach for doing A/V sync has too many problems. We need
* a better solution.
* @hide
*/
public int getOutputLatency(int streamType) {
return AudioSystem.getOutputLatency(streamType);
}
}

View File

@@ -401,5 +401,6 @@ public class AudioSystem
// helpers for android.media.AudioManager.getProperty(), see description there for meaning
public static native int getPrimaryOutputSamplingRate();
public static native int getPrimaryOutputFrameCount();
public static native int getOutputLatency(int stream);
}

View File

@@ -627,6 +627,18 @@ public class AudioTrack
return native_get_position();
}
/**
* Returns this track's estimated latency in milliseconds. This includes the latency due
* to AudioTrack buffer size, AudioMixer (if any) and audio hardware driver.
*
* DO NOT UNHIDE. The existing approach for doing A/V sync has too many problems. We need
* a better solution.
* @hide
*/
public int getLatency() {
return native_get_latency();
}
/**
* Returns the hardware output sample rate
*/
@@ -1256,6 +1268,8 @@ public class AudioTrack
private native final int native_set_position(int position);
private native final int native_get_position();
private native final int native_get_latency();
private native final int native_set_loop(int start, int end, int loopCount);
static private native final int native_get_output_sample_rate(int streamType);