diff options
| author | 2021-03-02 13:51:09 +0100 | |
|---|---|---|
| committer | 2021-03-05 14:09:14 +0100 | |
| commit | 01924238457e3abe0225a9de080934deedc51608 (patch) | |
| tree | d226a5eaa6dee6032601c13cc0c2d9c859eebde0 | |
| parent | ac754912cab6a51accd96012774a31323aa89513 (diff) | |
Split getSurroundSound method in 2 methods.
Split getSurroundSound in:
getSurroundSound for formats supported by source android device
getReportedSurroundSound for formats reported by any connected sound
device like soundbar etc.
Bug: 177990551
Test: Tested manually
Change-Id: I8687c2f827ce09df49d19c6f553a81dfd6caffe4
| -rw-r--r-- | core/jni/android_media_AudioSystem.cpp | 68 | ||||
| -rw-r--r-- | media/java/android/media/AudioManager.java | 17 | ||||
| -rw-r--r-- | media/java/android/media/AudioSystem.java | 6 |
3 files changed, 67 insertions, 24 deletions
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp index 94bd28a59e7c..f102edc79e7f 100644 --- a/core/jni/android_media_AudioSystem.cpp +++ b/core/jni/android_media_AudioSystem.cpp @@ -2204,13 +2204,11 @@ android_media_AudioSystem_getHwOffloadEncodingFormatsSupportedForA2DP( return jStatus; } -static jint -android_media_AudioSystem_getSurroundFormats(JNIEnv *env, jobject thiz, - jobject jSurroundFormats, jboolean reported) -{ +static jint android_media_AudioSystem_getSurroundFormats(JNIEnv *env, jobject thiz, + jobject jSurroundFormats) { ALOGV("getSurroundFormats"); - if (jSurroundFormats == NULL) { + if (jSurroundFormats == nullptr) { ALOGE("jSurroundFormats is NULL"); return (jint)AUDIO_JAVA_BAD_VALUE; } @@ -2221,10 +2219,10 @@ android_media_AudioSystem_getSurroundFormats(JNIEnv *env, jobject thiz, jint jStatus; unsigned int numSurroundFormats = 0; - audio_format_t *surroundFormats = NULL; - bool *surroundFormatsEnabled = NULL; - status_t status = AudioSystem::getSurroundFormats( - &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported); + audio_format_t *surroundFormats = nullptr; + bool *surroundFormatsEnabled = nullptr; + status_t status = AudioSystem::getSurroundFormats(&numSurroundFormats, surroundFormats, + surroundFormatsEnabled); if (status != NO_ERROR) { ALOGE_IF(status != NO_ERROR, "AudioSystem::getSurroundFormats error %d", status); jStatus = nativeToJavaStatus(status); @@ -2236,8 +2234,8 @@ android_media_AudioSystem_getSurroundFormats(JNIEnv *env, jobject thiz, } surroundFormats = (audio_format_t *)calloc(numSurroundFormats, sizeof(audio_format_t)); surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool)); - status = AudioSystem::getSurroundFormats( - &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported); + status = AudioSystem::getSurroundFormats(&numSurroundFormats, surroundFormats, + surroundFormatsEnabled); jStatus = nativeToJavaStatus(status); if (status != NO_ERROR) { ALOGE_IF(status != NO_ERROR, "AudioSystem::getSurroundFormats error %d", status); @@ -2258,6 +2256,50 @@ exit: return jStatus; } +static jint android_media_AudioSystem_getReportedSurroundFormats(JNIEnv *env, jobject thiz, + jobject jSurroundFormats) { + ALOGV("getReportedSurroundFormats"); + + if (jSurroundFormats == nullptr) { + ALOGE("jSurroundFormats is NULL"); + return (jint)AUDIO_JAVA_BAD_VALUE; + } + if (!env->IsInstanceOf(jSurroundFormats, gArrayListClass)) { + ALOGE("jSurroundFormats not an arraylist"); + return (jint)AUDIO_JAVA_BAD_VALUE; + } + jint jStatus; + unsigned int numSurroundFormats = 0; + audio_format_t *surroundFormats = nullptr; + status_t status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, surroundFormats); + if (status != NO_ERROR) { + ALOGE_IF(status != NO_ERROR, "AudioSystem::getReportedSurroundFormats error %d", status); + jStatus = nativeToJavaStatus(status); + goto exit; + } + if (numSurroundFormats == 0) { + jStatus = (jint)AUDIO_JAVA_SUCCESS; + goto exit; + } + surroundFormats = (audio_format_t *)calloc(numSurroundFormats, sizeof(audio_format_t)); + status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, surroundFormats); + jStatus = nativeToJavaStatus(status); + if (status != NO_ERROR) { + ALOGE_IF(status != NO_ERROR, "AudioSystem::getReportedSurroundFormats error %d", status); + goto exit; + } + for (size_t i = 0; i < numSurroundFormats; i++) { + jobject surroundFormat = env->NewObject(gIntegerClass, gIntegerCstor, + audioFormatFromNative(surroundFormats[i])); + env->CallObjectMethod(jSurroundFormats, gArrayListMethods.add, surroundFormat); + env->DeleteLocalRef(surroundFormat); + } + +exit: + free(surroundFormats); + return jStatus; +} + static jint android_media_AudioSystem_setSurroundFormatEnabled(JNIEnv *env, jobject thiz, jint audioFormat, jboolean enabled) @@ -2619,8 +2661,10 @@ static const JNINativeMethod gMethods[] = (void *)android_media_AudioSystem_getOffloadSupport}, {"getMicrophones", "(Ljava/util/ArrayList;)I", (void *)android_media_AudioSystem_getMicrophones}, - {"getSurroundFormats", "(Ljava/util/Map;Z)I", + {"getSurroundFormats", "(Ljava/util/Map;)I", (void *)android_media_AudioSystem_getSurroundFormats}, + {"getReportedSurroundFormats", "(Ljava/util/ArrayList;)I", + (void *)android_media_AudioSystem_getReportedSurroundFormats}, {"setSurroundFormatEnabled", "(IZ)I", (void *)android_media_AudioSystem_setSurroundFormatEnabled}, {"setAssistantUid", "(I)I", (void *)android_media_AudioSystem_setAssistantUid}, diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index b2de49deefca..bf99b2328de9 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -6729,7 +6729,7 @@ public class AudioManager { */ public Map<Integer, Boolean> getSurroundFormats() { Map<Integer, Boolean> surroundFormats = new HashMap<>(); - int status = AudioSystem.getSurroundFormats(surroundFormats, false); + int status = AudioSystem.getSurroundFormats(surroundFormats); if (status != AudioManager.SUCCESS) { // fail and bail! Log.e(TAG, "getSurroundFormats failed:" + status); @@ -6762,20 +6762,17 @@ public class AudioManager { /** * @hide * Returns all surround formats that are reported by the connected HDMI device. - * The keys are not affected by calling setSurroundFormatEnabled(), and the values - * are not affected by calling setSurroundFormatEnabled() when in AUTO mode. - * This information can used to show the AUTO setting for SurroundSound. + * The return values are not affected by calling setSurroundFormatEnabled. * - * @return a map where the key is a surround format and - * the value indicates the surround format is enabled or not + * @return a list of surround formats */ - public Map<Integer, Boolean> getReportedSurroundFormats() { - Map<Integer, Boolean> reportedSurroundFormats = new HashMap<>(); - int status = AudioSystem.getSurroundFormats(reportedSurroundFormats, true); + public ArrayList<Integer> getReportedSurroundFormats() { + ArrayList<Integer> reportedSurroundFormats = new ArrayList<>(); + int status = AudioSystem.getReportedSurroundFormats(reportedSurroundFormats); if (status != AudioManager.SUCCESS) { // fail and bail! Log.e(TAG, "getReportedSurroundFormats failed:" + status); - return new HashMap<Integer, Boolean>(); // Always return a map. + return new ArrayList<Integer>(); // Always return a list. } return reportedSurroundFormats; } diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index f1f6cb1f42be..8134d6f8352d 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -1699,8 +1699,10 @@ public class AudioSystem public static native int getMicrophones(ArrayList<MicrophoneInfo> microphonesInfo); /** @hide */ - public static native int getSurroundFormats(Map<Integer, Boolean> surroundFormats, - boolean reported); + public static native int getSurroundFormats(Map<Integer, Boolean> surroundFormats); + + /** @hide */ + public static native int getReportedSurroundFormats(ArrayList<Integer> surroundFormats); /** * @hide |