summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorPaul McLean <pmclean@google.com>2015-06-18 22:00:24 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-18 22:00:33 +0000
commit2d5f41e4c1733ff3e606390a433a6a52be6e862a (patch)
treee23bc5ada01d9eccda0b3c18d88b76365a5433b9 /core/jni
parentb0ff3a6cb37aa45add4b0c5135bd978442fcc441 (diff)
parent2db94372749c4fcc9bd715f41e0b5c4045ee7c84 (diff)
downloadframeworks_base-2d5f41e4c1733ff3e606390a433a6a52be6e862a.zip
frameworks_base-2d5f41e4c1733ff3e606390a433a6a52be6e862a.tar.gz
frameworks_base-2d5f41e4c1733ff3e606390a433a6a52be6e862a.tar.bz2
Merge "Better handling of 0-length format conversions in convertAudioPortFromNative()." into mnc-dev
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_media_AudioSystem.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 9f2181f..91b3278 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -856,7 +856,8 @@ static jint convertAudioPortFromNative(JNIEnv *env,
bool useInMask;
size_t numPositionMasks = 0;
size_t numIndexMasks = 0;
- size_t numUniqueFormats;
+ size_t numUniqueFormats = 0;
+
ALOGV("convertAudioPortFromNative id %d role %d type %d name %s",
nAudioPort->id, nAudioPort->role, nAudioPort->type, nAudioPort->name);
@@ -907,12 +908,13 @@ static jint convertAudioPortFromNative(JNIEnv *env,
}
// formats
- cFormats = new int[nAudioPort->num_formats];
- numUniqueFormats = 0;
- for (size_t index = 0; index < nAudioPort->num_formats; index++) {
- int format = audioFormatFromNative(nAudioPort->formats[index]);
- if (!hasFormat(cFormats, numUniqueFormats, format)) {
- cFormats[numUniqueFormats++] = format;
+ if (nAudioPort->num_formats != 0) {
+ cFormats = new int[nAudioPort->num_formats];
+ for (size_t index = 0; index < nAudioPort->num_formats; index++) {
+ int format = audioFormatFromNative(nAudioPort->formats[index]);
+ if (!hasFormat(cFormats, numUniqueFormats, format)) {
+ cFormats[numUniqueFormats++] = format;
+ }
}
}
jFormats = env->NewIntArray(numUniqueFormats);
@@ -920,7 +922,9 @@ static jint convertAudioPortFromNative(JNIEnv *env,
jStatus = (jint)AUDIO_JAVA_ERROR;
goto exit;
}
- env->SetIntArrayRegion(jFormats, 0, numUniqueFormats, cFormats);
+ if (numUniqueFormats != 0) {
+ env->SetIntArrayRegion(jFormats, 0, numUniqueFormats, cFormats);
+ }
// gains
jGains = env->NewObjectArray(nAudioPort->num_gains,