summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorPaul McLean <pmclean@google.com>2015-06-16 21:41:21 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-16 21:41:23 +0000
commit8ff232c7be5e075b6b0e10b8f40b556c97b79651 (patch)
tree07acfc89cd4bcff171247a2b922e07d6008243c3 /core/jni
parentb259a9036bab78222ea72f45b909d76361da4783 (diff)
parentf29e5f34b39a5688925ca4654be0eab11277b1cc (diff)
downloadframeworks_base-8ff232c7be5e075b6b0e10b8f40b556c97b79651.zip
frameworks_base-8ff232c7be5e075b6b0e10b8f40b556c97b79651.tar.gz
frameworks_base-8ff232c7be5e075b6b0e10b8f40b556c97b79651.tar.bz2
Merge "Implement channel index masks in AudioDeviceInfo." into mnc-dev
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_media_AudioSystem.cpp66
1 files changed, 47 insertions, 19 deletions
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 1cd07d1..ac00532 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -677,13 +677,14 @@ static jint convertAudioPortConfigFromNative(JNIEnv *env,
// constructed by java code with correct class type (device, mix etc...)
// and reference to AudioPort instance in this client
jAudioPort = env->NewObject(gAudioPortClass, gAudioPortCstor,
- jHandle,
- 0,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL);
+ jHandle, // handle
+ 0, // role
+ NULL, // name
+ NULL, // samplingRates
+ NULL, // channelMasks
+ NULL, // channelIndexMasks
+ NULL, // formats
+ NULL); // gains
env->DeleteLocalRef(jHandle);
if (jAudioPort == NULL) {
return (jint)AUDIO_JAVA_ERROR;
@@ -837,11 +838,14 @@ static jint convertAudioPortFromNative(JNIEnv *env,
jint jStatus = (jint)AUDIO_JAVA_SUCCESS;
jintArray jSamplingRates = NULL;
jintArray jChannelMasks = NULL;
+ jintArray jChannelIndexMasks = NULL;
jintArray jFormats = NULL;
jobjectArray jGains = NULL;
jobject jHandle = NULL;
jstring jDeviceName = NULL;
bool useInMask;
+ size_t numPositionMasks = 0;
+ size_t numIndexMasks = 0;
ALOGV("convertAudioPortFromNative id %d role %d type %d name %s",
nAudioPort->id, nAudioPort->role, nAudioPort->type, nAudioPort->name);
@@ -856,23 +860,43 @@ static jint convertAudioPortFromNative(JNIEnv *env,
(jint *)nAudioPort->sample_rates);
}
- jChannelMasks = env->NewIntArray(nAudioPort->num_channel_masks);
+ // count up how many masks are positional and indexed
+ for(size_t index = 0; index < nAudioPort->num_channel_masks; index++) {
+ const audio_channel_mask_t mask = nAudioPort->channel_masks[index];
+ if (audio_channel_mask_get_representation(mask) == AUDIO_CHANNEL_REPRESENTATION_INDEX) {
+ numIndexMasks++;
+ } else {
+ numPositionMasks++;
+ }
+ }
+
+ jChannelMasks = env->NewIntArray(numPositionMasks);
if (jChannelMasks == NULL) {
jStatus = (jint)AUDIO_JAVA_ERROR;
goto exit;
}
+ jChannelIndexMasks = env->NewIntArray(numIndexMasks);
+ if (jChannelIndexMasks == NULL) {
+ jStatus = (jint)AUDIO_JAVA_ERROR;
+ goto exit;
+ }
useInMask = useInChannelMask(nAudioPort->type, nAudioPort->role);
- jint jMask;
- for (size_t j = 0; j < nAudioPort->num_channel_masks; j++) {
- if (useInMask) {
- jMask = inChannelMaskFromNative(nAudioPort->channel_masks[j]);
+ // put the masks in the output arrays
+ for (size_t maskIndex = 0, posMaskIndex = 0, indexedMaskIndex = 0;
+ maskIndex < nAudioPort->num_channel_masks; maskIndex++) {
+ const audio_channel_mask_t mask = nAudioPort->channel_masks[maskIndex];
+ if (audio_channel_mask_get_representation(mask) == AUDIO_CHANNEL_REPRESENTATION_INDEX) {
+ jint jMask = audio_channel_mask_get_bits(mask);
+ env->SetIntArrayRegion(jChannelIndexMasks, indexedMaskIndex++, 1, &jMask);
} else {
- jMask = outChannelMaskFromNative(nAudioPort->channel_masks[j]);
+ jint jMask = useInMask ? inChannelMaskFromNative(mask)
+ : outChannelMaskFromNative(mask);
+ env->SetIntArrayRegion(jChannelMasks, posMaskIndex++, 1, &jMask);
}
- env->SetIntArrayRegion(jChannelMasks, j, 1, &jMask);
}
+ // formats
jFormats = env->NewIntArray(nAudioPort->num_formats);
if (jFormats == NULL) {
jStatus = (jint)AUDIO_JAVA_ERROR;
@@ -883,14 +907,17 @@ static jint convertAudioPortFromNative(JNIEnv *env,
env->SetIntArrayRegion(jFormats, j, 1, &jFormat);
}
+ // gains
jGains = env->NewObjectArray(nAudioPort->num_gains,
gAudioGainClass, NULL);
if (jGains == NULL) {
jStatus = (jint)AUDIO_JAVA_ERROR;
goto exit;
}
+
for (size_t j = 0; j < nAudioPort->num_gains; j++) {
audio_channel_mask_t nMask = nAudioPort->gains[j].channel_mask;
+ jint jMask;
if (useInMask) {
jMask = inChannelMaskFromNative(nMask);
ALOGV("convertAudioPortConfigFromNative IN mask java %x native %x", jMask, nMask);
@@ -931,7 +958,8 @@ static jint convertAudioPortFromNative(JNIEnv *env,
jstring jAddress = env->NewStringUTF(nAudioPort->ext.device.address);
*jAudioPort = env->NewObject(gAudioDevicePortClass, gAudioDevicePortCstor,
jHandle, jDeviceName,
- jSamplingRates, jChannelMasks, jFormats, jGains,
+ jSamplingRates, jChannelMasks, jChannelIndexMasks,
+ jFormats, jGains,
nAudioPort->ext.device.type, jAddress);
env->DeleteLocalRef(jAddress);
} else if (nAudioPort->type == AUDIO_PORT_TYPE_MIX) {
@@ -939,7 +967,7 @@ static jint convertAudioPortFromNative(JNIEnv *env,
*jAudioPort = env->NewObject(gAudioMixPortClass, gAudioMixPortCstor,
jHandle, nAudioPort->ext.mix.handle,
nAudioPort->role, jDeviceName,
- jSamplingRates, jChannelMasks,
+ jSamplingRates, jChannelMasks, jChannelIndexMasks,
jFormats, jGains);
} else {
ALOGE("convertAudioPortFromNative unknown nAudioPort type %d", nAudioPort->type);
@@ -1634,7 +1662,7 @@ int register_android_media_AudioSystem(JNIEnv *env)
jclass audioPortClass = FindClassOrDie(env, "android/media/AudioPort");
gAudioPortClass = MakeGlobalRefOrDie(env, audioPortClass);
gAudioPortCstor = GetMethodIDOrDie(env, audioPortClass, "<init>",
- "(Landroid/media/AudioHandle;ILjava/lang/String;[I[I[I[Landroid/media/AudioGain;)V");
+ "(Landroid/media/AudioHandle;ILjava/lang/String;[I[I[I[I[Landroid/media/AudioGain;)V");
gAudioPortFields.mHandle = GetFieldIDOrDie(env, audioPortClass, "mHandle",
"Landroid/media/AudioHandle;");
gAudioPortFields.mRole = GetFieldIDOrDie(env, audioPortClass, "mRole", "I");
@@ -1672,12 +1700,12 @@ int register_android_media_AudioSystem(JNIEnv *env)
jclass audioDevicePortClass = FindClassOrDie(env, "android/media/AudioDevicePort");
gAudioDevicePortClass = MakeGlobalRefOrDie(env, audioDevicePortClass);
gAudioDevicePortCstor = GetMethodIDOrDie(env, audioDevicePortClass, "<init>",
- "(Landroid/media/AudioHandle;Ljava/lang/String;[I[I[I[Landroid/media/AudioGain;ILjava/lang/String;)V");
+ "(Landroid/media/AudioHandle;Ljava/lang/String;[I[I[I[I[Landroid/media/AudioGain;ILjava/lang/String;)V");
jclass audioMixPortClass = FindClassOrDie(env, "android/media/AudioMixPort");
gAudioMixPortClass = MakeGlobalRefOrDie(env, audioMixPortClass);
gAudioMixPortCstor = GetMethodIDOrDie(env, audioMixPortClass, "<init>",
- "(Landroid/media/AudioHandle;IILjava/lang/String;[I[I[I[Landroid/media/AudioGain;)V");
+ "(Landroid/media/AudioHandle;IILjava/lang/String;[I[I[I[I[Landroid/media/AudioGain;)V");
jclass audioGainClass = FindClassOrDie(env, "android/media/AudioGain");
gAudioGainClass = MakeGlobalRefOrDie(env, audioGainClass);