diff options
author | Andy Hung <hunga@google.com> | 2021-03-16 11:30:01 -0700 |
---|---|---|
committer | Andy Hung <hunga@google.com> | 2021-03-19 00:25:31 -0700 |
commit | 59df55f8ccf3c0bd03cfc3b37ac48a16c99f08ca (patch) | |
tree | 90280814078026e00c0f423c84d54f2cd606ed15 /core | |
parent | 47157e77113e9362e9a511c9c0be99639cc5139a (diff) |
AudioTrack: get/setStartThresholdInFrames
setStartThresholdInFrames is used to set the start threshold
in frames for streaming AudioTrack playback.
Normally this is the entire buffer capacity in frames
but may be reduced for low latency playback,
compressed formats, and direct tracks.
See CTS test AudioTrackTest#testStartThresholdInFrames
for example calling details and behavior.
Test: atest AudioTrackTest#testStartThresholdInFrames
Test: atest AudioTrackTest#testStartThresholdInFramesExceptions
Bug: 183003720
Merged-In: I5064d04961e48b530c49071ff84c2e0d2065f41b
Change-Id: I5064d04961e48b530c49071ff84c2e0d2065f41b
Diffstat (limited to 'core')
-rw-r--r-- | core/api/current.txt | 2 | ||||
-rw-r--r-- | core/jni/android_media_AudioTrack.cpp | 40 |
2 files changed, 42 insertions, 0 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 2b5075dfae95..0b1fa771cba4 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -19852,6 +19852,7 @@ package android.media { method public android.media.AudioDeviceInfo getPreferredDevice(); method public android.media.AudioDeviceInfo getRoutedDevice(); method public int getSampleRate(); + method @IntRange(from=1) public int getStartThresholdInFrames(); method public int getState(); method public int getStreamType(); method public boolean getTimestamp(android.media.AudioTimestamp); @@ -19882,6 +19883,7 @@ package android.media { method public int setPositionNotificationPeriod(int); method public boolean setPreferredDevice(android.media.AudioDeviceInfo); method public int setPresentation(@NonNull android.media.AudioPresentation); + method @IntRange(from=1) public int setStartThresholdInFrames(@IntRange(from=1) int); method @Deprecated protected void setState(int); method @Deprecated public int setStereoVolume(float, float); method public int setVolume(float); diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp index 065c79b8601f..452f55a0ba97 100644 --- a/core/jni/android_media_AudioTrack.cpp +++ b/core/jni/android_media_AudioTrack.cpp @@ -1419,6 +1419,42 @@ static jint android_media_AudioTrack_getDualMonoMode(JNIEnv *env, jobject thiz, return nativeToJavaStatus(status); } +static jint android_media_AudioTrack_getStartThresholdInFrames(JNIEnv *env, jobject thiz) { + sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); + if (lpTrack == nullptr) { + jniThrowException(env, "java/lang/IllegalStateException", + "Unable to retrieve AudioTrack pointer for getStartThresholdInFrames()"); + return (jint)AUDIO_JAVA_ERROR; + } + const ssize_t result = lpTrack->getStartThresholdInFrames(); + if (result <= 0) { + jniThrowExceptionFmt(env, "java/lang/IllegalStateException", + "Internal error detected in getStartThresholdInFrames() = %zd", + result); + return (jint)AUDIO_JAVA_ERROR; + } + return (jint)result; // this should be a positive value. +} + +static jint android_media_AudioTrack_setStartThresholdInFrames(JNIEnv *env, jobject thiz, + jint startThresholdInFrames) { + sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); + if (lpTrack == nullptr) { + jniThrowException(env, "java/lang/IllegalStateException", + "Unable to retrieve AudioTrack pointer for setStartThresholdInFrames()"); + return (jint)AUDIO_JAVA_ERROR; + } + // non-positive values of startThresholdInFrames are not allowed by the Java layer. + const ssize_t result = lpTrack->setStartThresholdInFrames(startThresholdInFrames); + if (result <= 0) { + jniThrowExceptionFmt(env, "java/lang/IllegalStateException", + "Internal error detected in setStartThresholdInFrames() = %zd", + result); + return (jint)AUDIO_JAVA_ERROR; + } + return (jint)result; // this should be a positive value. +} + // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- static const JNINativeMethod gMethods[] = { @@ -1496,6 +1532,10 @@ static const JNINativeMethod gMethods[] = { (void *)android_media_AudioTrack_getAudioDescriptionMixLeveldB}, {"native_set_dual_mono_mode", "(I)I", (void *)android_media_AudioTrack_setDualMonoMode}, {"native_get_dual_mono_mode", "([I)I", (void *)android_media_AudioTrack_getDualMonoMode}, + {"native_setStartThresholdInFrames", "(I)I", + (void *)android_media_AudioTrack_setStartThresholdInFrames}, + {"native_getStartThresholdInFrames", "()I", + (void *)android_media_AudioTrack_getStartThresholdInFrames}, }; // field names found in android/media/AudioTrack.java |