summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2011-07-25 12:58:14 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2011-07-25 17:06:22 -0700
commitd9ae1c573e37e245c7f4f0480a8fa925e57bd49d (patch)
tree2d61028f503d38aef825ad2029909e3747862012 /core/jni
parentb243d5bc7db88396f0da304553687e7a0bccfa3d (diff)
downloadframeworks_base-d9ae1c573e37e245c7f4f0480a8fa925e57bd49d.zip
frameworks_base-d9ae1c573e37e245c7f4f0480a8fa925e57bd49d.tar.gz
frameworks_base-d9ae1c573e37e245c7f4f0480a8fa925e57bd49d.tar.bz2
Fix bug 4319552 Java to native channel mask translation
When creating a new AudioTrack instance, translate from a Java channel mask as defined in android.media.AudioFormat to one as defined in audio.h which matches industry-standard channel mask definitions. Change-Id: I7eeece8ec2a437977c31f6e82590f9591158144b
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_media_AudioTrack.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index bd70dad..2929056 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -167,11 +167,11 @@ static void audioCallback(int event, void* user, void *info) {
// ----------------------------------------------------------------------------
static int
android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
- jint streamType, jint sampleRateInHertz, jint channels,
+ jint streamType, jint sampleRateInHertz, jint javaChannelMask,
jint audioFormat, jint buffSizeInBytes, jint memoryMode, jintArray jSession)
{
- LOGV("sampleRate=%d, audioFormat(from Java)=%d, channels=%x, buffSize=%d",
- sampleRateInHertz, audioFormat, channels, buffSizeInBytes);
+ LOGV("sampleRate=%d, audioFormat(from Java)=%d, channel mask=%x, buffSize=%d",
+ sampleRateInHertz, audioFormat, javaChannelMask, buffSizeInBytes);
int afSampleRate;
int afFrameCount;
@@ -184,11 +184,16 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
}
- if (!audio_is_output_channel(channels)) {
+ // Java channel masks don't map directly to the native definition, but it's a simple shift
+ // to skip the two deprecated channel configurations "default" and "mono".
+ uint32_t nativeChannelMask = ((uint32_t)javaChannelMask) >> 2;
+
+ if (!audio_is_output_channel(nativeChannelMask)) {
LOGE("Error creating AudioTrack: invalid channel mask.");
return AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK;
}
- int nbChannels = popcount(channels);
+
+ int nbChannels = popcount(nativeChannelMask);
// check the stream type
audio_stream_type_t atStreamType;
@@ -285,7 +290,7 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
atStreamType,// stream type
sampleRateInHertz,
format,// word length, PCM
- channels,
+ nativeChannelMask,
frameCount,
0,// flags
audioCallback, &(lpJniStorage->mCallbackData),//callback, callback data (user)
@@ -306,7 +311,7 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
atStreamType,// stream type
sampleRateInHertz,
format,// word length, PCM
- channels,
+ nativeChannelMask,
frameCount,
0,// flags
audioCallback, &(lpJniStorage->mCallbackData),//callback, callback data (user));