diff options
author | Andy Hung <hunga@google.com> | 2015-04-30 00:16:16 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-04-30 00:16:16 +0000 |
commit | edcf5e1e05b7c258665476a75af8440b12050ace (patch) | |
tree | 741e860e53d45517cb64738d5daa9cec88cbb85c | |
parent | 8fa0eecc4fa569fe89273ddb3234f03bf1c567ec (diff) | |
parent | f17dd0b48c894fda00b1d2068ef54b05221b1d7a (diff) | |
download | frameworks_base-edcf5e1e05b7c258665476a75af8440b12050ace.zip frameworks_base-edcf5e1e05b7c258665476a75af8440b12050ace.tar.gz frameworks_base-edcf5e1e05b7c258665476a75af8440b12050ace.tar.bz2 |
am f17dd0b4: am 1afdbe3b: Merge "Pass PlaybackSettings as class object for AudioTrack JNI" into mnc-dev
* commit 'f17dd0b48c894fda00b1d2068ef54b05221b1d7a':
Pass PlaybackSettings as class object for AudioTrack JNI
-rw-r--r-- | core/jni/Android.mk | 1 | ||||
-rw-r--r-- | core/jni/android_media_AudioTrack.cpp | 72 | ||||
-rw-r--r-- | media/java/android/media/AudioTrack.java | 34 |
3 files changed, 41 insertions, 66 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk index cd117eb1..bbdd860 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -176,6 +176,7 @@ LOCAL_C_INCLUDES += \ $(call include-path-for, libhardware)/hardware \ $(call include-path-for, libhardware_legacy)/hardware_legacy \ $(TOP)/frameworks/av/include \ + $(TOP)/frameworks/base/media/jni \ $(TOP)/system/media/camera/include \ $(TOP)/system/netd/include \ external/pdfium/core/include/fpdfapi \ diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp index 2f6a69c..26b82c5 100644 --- a/core/jni/android_media_AudioTrack.cpp +++ b/core/jni/android_media_AudioTrack.cpp @@ -35,6 +35,7 @@ #include "android_media_AudioFormat.h" #include "android_media_AudioErrors.h" +#include "android_media_PlaybackSettings.h" // ---------------------------------------------------------------------------- @@ -59,6 +60,7 @@ struct audio_attributes_fields_t { }; static audio_track_fields_t javaAudioTrackFields; static audio_attributes_fields_t javaAudioAttrFields; +static PlaybackSettings::fields_t gPlaybackSettingsFields; struct audiotrack_callback_cookie { jclass audioTrack_class; @@ -690,7 +692,7 @@ static jint android_media_AudioTrack_get_playback_rate(JNIEnv *env, jobject thi // ---------------------------------------------------------------------------- static void android_media_AudioTrack_set_playback_settings(JNIEnv *env, jobject thiz, - jfloatArray floatArray, jintArray intArray) { + jobject settings) { sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); if (lpTrack == NULL) { jniThrowException(env, "java/lang/IllegalStateException", @@ -698,50 +700,39 @@ static void android_media_AudioTrack_set_playback_settings(JNIEnv *env, jobject return; } - // NOTE: Get<Primitive>ArrayRegion throws ArrayIndexOutOfBoundsException if not valid. - // TODO: consider the actual occupancy. - float farray[2]; - int iarray[2]; - if ((env->GetFloatArrayRegion(floatArray, 0, 2, farray), env->ExceptionCheck()) == JNI_FALSE - && - (env->GetIntArrayRegion(intArray, 0, 2, iarray), env->ExceptionCheck()) == JNI_FALSE) { - // arrays retrieved OK - AudioPlaybackRate playbackRate; - playbackRate.mSpeed = farray[0]; - playbackRate.mPitch = farray[1]; - playbackRate.mFallbackMode = (AudioTimestretchFallbackMode)iarray[0]; - playbackRate.mStretchMode = (AudioTimestretchStretchMode)iarray[1]; - if (lpTrack->setPlaybackRate(playbackRate) != OK) { - jniThrowException(env, "java/lang/IllegalArgumentException", - "arguments out of range"); - } + PlaybackSettings pbs; + pbs.fillFromJobject(env, gPlaybackSettingsFields, settings); + + ALOGV("setPlaybackSettings: %d:%f %d:%f %d:%u %d:%u", + pbs.speedSet, pbs.audioRate.mSpeed, + pbs.pitchSet, pbs.audioRate.mPitch, + pbs.audioFallbackModeSet, pbs.audioRate.mFallbackMode, + pbs.audioStretchModeSet, pbs.audioRate.mStretchMode); + + if (lpTrack->setPlaybackRate(pbs.audioRate) != OK) { + jniThrowException(env, "java/lang/IllegalArgumentException", + "arguments out of range"); } } // ---------------------------------------------------------------------------- -static void android_media_AudioTrack_get_playback_settings(JNIEnv *env, jobject thiz, - jfloatArray floatArray, jintArray intArray) { +static jobject android_media_AudioTrack_get_playback_settings(JNIEnv *env, jobject thiz, + jobject settings) { sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); if (lpTrack == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "AudioTrack not initialized"); - return; + return NULL; } - AudioPlaybackRate playbackRate = lpTrack->getPlaybackRate(); - - float farray[2] = { - playbackRate.mSpeed, - playbackRate.mPitch, - }; - int iarray[2] = { - playbackRate.mFallbackMode, - playbackRate.mStretchMode, - }; - // NOTE: Set<Primitive>ArrayRegion throws ArrayIndexOutOfBoundsException if not valid. - env->SetFloatArrayRegion(floatArray, 0, 2, farray); - env->SetIntArrayRegion(intArray, 0, 2, iarray); + PlaybackSettings pbs; + pbs.audioRate = lpTrack->getPlaybackRate(); + pbs.speedSet = true; + pbs.pitchSet = true; + pbs.audioFallbackModeSet = true; + pbs.audioStretchModeSet = true; + return pbs.asJobject(env, gPlaybackSettingsFields); } @@ -1012,9 +1003,11 @@ static JNINativeMethod gMethods[] = { {"native_get_playback_rate", "()I", (void *)android_media_AudioTrack_get_playback_rate}, {"native_set_playback_settings", - "([F[I)V", (void *)android_media_AudioTrack_set_playback_settings}, + "(Landroid/media/PlaybackSettings;)V", + (void *)android_media_AudioTrack_set_playback_settings}, {"native_get_playback_settings", - "([F[I)V", (void *)android_media_AudioTrack_get_playback_settings}, + "()Landroid/media/PlaybackSettings;", + (void *)android_media_AudioTrack_get_playback_settings}, {"native_set_marker_pos","(I)I", (void *)android_media_AudioTrack_set_marker_pos}, {"native_get_marker_pos","()I", (void *)android_media_AudioTrack_get_marker_pos}, {"native_set_pos_update_period", @@ -1088,6 +1081,8 @@ int register_android_media_AudioTrack(JNIEnv *env) javaAudioTrackFields.fieldStreamType = GetFieldIDOrDie(env, audioTrackClass, JAVA_STREAMTYPE_FIELD_NAME, "I"); + env->DeleteLocalRef(audioTrackClass); + // Get the AudioAttributes class and fields jclass audioAttrClass = FindClassOrDie(env, kAudioAttributesClassPathName); javaAudioAttrFields.fieldUsage = GetFieldIDOrDie(env, audioAttrClass, "mUsage", "I"); @@ -1097,6 +1092,11 @@ int register_android_media_AudioTrack(JNIEnv *env) javaAudioAttrFields.fieldFormattedTags = GetFieldIDOrDie(env, audioAttrClass, "mFormattedTags", "Ljava/lang/String;"); + env->DeleteLocalRef(audioAttrClass); + + // initialize PlaybackSettings field info + gPlaybackSettingsFields.init(env); + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java index 6f1fd24..cb05cc5 100644 --- a/media/java/android/media/AudioTrack.java +++ b/media/java/android/media/AudioTrack.java @@ -920,13 +920,7 @@ public class AudioTrack * @throws IllegalStateException if track is not initialized. */ public @NonNull PlaybackSettings getPlaybackSettings() { - float[] floatArray = new float[2]; - int[] intArray = new int[2]; - native_get_playback_settings(floatArray, intArray); - return new PlaybackSettings() - .setSpeed(floatArray[0]) - .setPitch(floatArray[1]) - .setAudioFallbackMode(intArray[0]); + return native_get_playback_settings(); } /** @@ -1340,21 +1334,7 @@ public class AudioTrack if (settings == null) { throw new IllegalArgumentException("settings is null"); } - float[] floatArray; - int[] intArray; - try { - floatArray = new float[] { - settings.getSpeed(), - settings.getPitch(), - }; - intArray = new int[] { - settings.getAudioFallbackMode(), - PlaybackSettings.AUDIO_STRETCH_MODE_DEFAULT, - }; - } catch (IllegalStateException e) { - throw new IllegalArgumentException(e); - } - native_set_playback_settings(floatArray, intArray); + native_set_playback_settings(settings); } @@ -2353,14 +2333,8 @@ public class AudioTrack private native final int native_set_playback_rate(int sampleRateInHz); private native final int native_get_playback_rate(); - // floatArray must be a non-null array of length >= 2 - // [0] is speed - // [1] is pitch - // intArray must be a non-null array of length >= 2 - // [0] is audio fallback mode - // [1] is audio stretch mode - private native final void native_set_playback_settings(float[] floatArray, int[] intArray); - private native final void native_get_playback_settings(float[] floatArray, int[] intArray); + private native final void native_set_playback_settings(@NonNull PlaybackSettings settings); + private native final @NonNull PlaybackSettings native_get_playback_settings(); private native final int native_set_marker_pos(int marker); private native final int native_get_marker_pos(); |