summaryrefslogtreecommitdiffstats
path: root/core/jni/android_media_AudioTrack.cpp
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2012-01-16 14:37:12 -0800
committerGlenn Kasten <gkasten@google.com>2012-01-17 15:33:20 -0800
commit29a0909c5f777230b9f34ef0703fed3cd4633833 (patch)
treeb4f944cd3fffaa5f4d770b514a60147c3cbe0cfd /core/jni/android_media_AudioTrack.cpp
parent73d27c3d46ce9a19c0cc358d0b2788f1f51706d7 (diff)
downloadframeworks_base-29a0909c5f777230b9f34ef0703fed3cd4633833.zip
frameworks_base-29a0909c5f777230b9f34ef0703fed3cd4633833.tar.gz
frameworks_base-29a0909c5f777230b9f34ef0703fed3cd4633833.tar.bz2
Replace run-time stream types by compile-time
Use the AUDIO_STREAM_* constants defined in <system/audio.h> instead of dynamically looking up stream types from AudioManager. Replace a series of "if" statements by a switch. Change-Id: I6d015bc151c9ab97a02492e84c63298b1f6f31ac
Diffstat (limited to 'core/jni/android_media_AudioTrack.cpp')
-rw-r--r--core/jni/android_media_AudioTrack.cpp102
1 files changed, 25 insertions, 77 deletions
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index 4aa49f4..36d28c2 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -49,14 +49,6 @@ struct fields_t {
jmethodID postNativeEventInJava; //... event post callback method
int PCM16; //... format constants
int PCM8; //... format constants
- int STREAM_VOICE_CALL; //... stream type constants
- int STREAM_SYSTEM; //... stream type constants
- int STREAM_RING; //... stream type constants
- int STREAM_MUSIC; //... stream type constants
- int STREAM_ALARM; //... stream type constants
- int STREAM_NOTIFICATION; //... stream type constants
- int STREAM_BLUETOOTH_SCO; //... stream type constants
- int STREAM_DTMF; //... stream type constants
int MODE_STREAM; //... memory mode
int MODE_STATIC; //... memory mode
jfieldID nativeTrackInJavaObj; // stores in Java the native AudioTrack object
@@ -197,23 +189,18 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
// check the stream type
audio_stream_type_t atStreamType;
- if (streamType == javaAudioTrackFields.STREAM_VOICE_CALL) {
- atStreamType = AUDIO_STREAM_VOICE_CALL;
- } else if (streamType == javaAudioTrackFields.STREAM_SYSTEM) {
- atStreamType = AUDIO_STREAM_SYSTEM;
- } else if (streamType == javaAudioTrackFields.STREAM_RING) {
- atStreamType = AUDIO_STREAM_RING;
- } else if (streamType == javaAudioTrackFields.STREAM_MUSIC) {
- atStreamType = AUDIO_STREAM_MUSIC;
- } else if (streamType == javaAudioTrackFields.STREAM_ALARM) {
- atStreamType = AUDIO_STREAM_ALARM;
- } else if (streamType == javaAudioTrackFields.STREAM_NOTIFICATION) {
- atStreamType = AUDIO_STREAM_NOTIFICATION;
- } else if (streamType == javaAudioTrackFields.STREAM_BLUETOOTH_SCO) {
- atStreamType = AUDIO_STREAM_BLUETOOTH_SCO;
- } else if (streamType == javaAudioTrackFields.STREAM_DTMF) {
- atStreamType = AUDIO_STREAM_DTMF;
- } else {
+ switch (streamType) {
+ case AUDIO_STREAM_VOICE_CALL:
+ case AUDIO_STREAM_SYSTEM:
+ case AUDIO_STREAM_RING:
+ case AUDIO_STREAM_MUSIC:
+ case AUDIO_STREAM_ALARM:
+ case AUDIO_STREAM_NOTIFICATION:
+ case AUDIO_STREAM_BLUETOOTH_SCO:
+ case AUDIO_STREAM_DTMF:
+ atStreamType = (audio_stream_type_t) streamType;
+ break;
+ default:
ALOGE("Error creating AudioTrack: unknown stream type.");
return AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
}
@@ -764,24 +751,20 @@ static jint android_media_AudioTrack_get_output_sample_rate(JNIEnv *env, jobjec
// convert the stream type from Java to native value
// FIXME: code duplication with android_media_AudioTrack_native_setup()
audio_stream_type_t nativeStreamType;
- if (javaStreamType == javaAudioTrackFields.STREAM_VOICE_CALL) {
- nativeStreamType = AUDIO_STREAM_VOICE_CALL;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_SYSTEM) {
- nativeStreamType = AUDIO_STREAM_SYSTEM;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_RING) {
- nativeStreamType = AUDIO_STREAM_RING;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_MUSIC) {
- nativeStreamType = AUDIO_STREAM_MUSIC;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_ALARM) {
- nativeStreamType = AUDIO_STREAM_ALARM;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_NOTIFICATION) {
- nativeStreamType = AUDIO_STREAM_NOTIFICATION;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_BLUETOOTH_SCO) {
- nativeStreamType = AUDIO_STREAM_BLUETOOTH_SCO;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_DTMF) {
- nativeStreamType = AUDIO_STREAM_DTMF;
- } else {
+ switch (javaStreamType) {
+ case AUDIO_STREAM_VOICE_CALL:
+ case AUDIO_STREAM_SYSTEM:
+ case AUDIO_STREAM_RING:
+ case AUDIO_STREAM_MUSIC:
+ case AUDIO_STREAM_ALARM:
+ case AUDIO_STREAM_NOTIFICATION:
+ case AUDIO_STREAM_BLUETOOTH_SCO:
+ case AUDIO_STREAM_DTMF:
+ nativeStreamType = (audio_stream_type_t) javaStreamType;
+ break;
+ default:
nativeStreamType = AUDIO_STREAM_DEFAULT;
+ break;
}
if (AudioSystem::getOutputSamplingRate(&afSamplingRate, nativeStreamType) != NO_ERROR) {
@@ -987,41 +970,6 @@ int register_android_media_AudioTrack(JNIEnv *env)
return -1;
}
- // Get the stream types from the AudioManager class
- jclass audioManagerClass = NULL;
- audioManagerClass = env->FindClass(JAVA_AUDIOMANAGER_CLASS_NAME);
- if (audioManagerClass == NULL) {
- ALOGE("Can't find %s", JAVA_AUDIOMANAGER_CLASS_NAME);
- return -1;
- }
- if ( !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_VOICE_CALL_NAME, &(javaAudioTrackFields.STREAM_VOICE_CALL))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_MUSIC_NAME, &(javaAudioTrackFields.STREAM_MUSIC))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_SYSTEM_NAME, &(javaAudioTrackFields.STREAM_SYSTEM))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_RING_NAME, &(javaAudioTrackFields.STREAM_RING))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_ALARM_NAME, &(javaAudioTrackFields.STREAM_ALARM))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_NOTIFICATION_NAME, &(javaAudioTrackFields.STREAM_NOTIFICATION))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_BLUETOOTH_SCO_NAME, &(javaAudioTrackFields.STREAM_BLUETOOTH_SCO))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_DTMF_NAME, &(javaAudioTrackFields.STREAM_DTMF))) {
- // error log performed in android_media_getIntConstantFromClass()
- return -1;
- }
-
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
}