Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc80405a authored by Kriti Dang's avatar Kriti Dang Committed by Android (Google) Code Review
Browse files

Merge "Split getSurroundSound method in 2 methods." into sc-dev

parents c94fb650 01924238
Loading
Loading
Loading
Loading
+56 −12
Original line number Diff line number Diff line
@@ -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},
+7 −10
Original line number Diff line number Diff line
@@ -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;
    }
+4 −2
Original line number Diff line number Diff line
@@ -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