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

Commit 0c907a97 authored by Eric Laurent's avatar Eric Laurent Committed by Automerger Merge Worker
Browse files

Merge "[RFC media]: refactoring several functions to C++ style" am: 6b602d83...

Merge "[RFC media]: refactoring several functions to C++ style" am: 6b602d83 am: e19fda14 am: 34263f36

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2528799



Change-Id: Ib123f868bf10b5c9215f529142bc0f428b1df098
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents b6ea0ff3 34263f36
Loading
Loading
Loading
Loading
+18 −31
Original line number Diff line number Diff line
@@ -2481,36 +2481,31 @@ static jint android_media_AudioSystem_getSurroundFormats(JNIEnv *env, jobject th

    if (jSurroundFormats == nullptr) {
        ALOGE("jSurroundFormats is NULL");
        return (jint)AUDIO_JAVA_BAD_VALUE;
        return static_cast<jint>(AUDIO_JAVA_BAD_VALUE);
    }
    if (!env->IsInstanceOf(jSurroundFormats, gMapClass)) {
        ALOGE("getSurroundFormats not a map");
        return (jint)AUDIO_JAVA_BAD_VALUE;
        return static_cast<jint>(AUDIO_JAVA_BAD_VALUE);
    }

    jint jStatus;
    unsigned int numSurroundFormats = 0;
    audio_format_t *surroundFormats = nullptr;
    bool *surroundFormatsEnabled = nullptr;
    status_t status = AudioSystem::getSurroundFormats(&numSurroundFormats, surroundFormats,
                                                      surroundFormatsEnabled);
    status_t status = AudioSystem::getSurroundFormats(&numSurroundFormats, nullptr, nullptr);
    if (status != NO_ERROR) {
        ALOGE_IF(status != NO_ERROR, "AudioSystem::getSurroundFormats error %d", status);
        jStatus = nativeToJavaStatus(status);
        goto exit;
        return nativeToJavaStatus(status);
    }
    if (numSurroundFormats == 0) {
        jStatus = (jint)AUDIO_JAVA_SUCCESS;
        goto exit;
        return static_cast<jint>(AUDIO_JAVA_SUCCESS);
    }
    surroundFormats = (audio_format_t *)calloc(numSurroundFormats, sizeof(audio_format_t));
    surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
    status = AudioSystem::getSurroundFormats(&numSurroundFormats, surroundFormats,
                                             surroundFormatsEnabled);
    auto surroundFormats = std::make_unique<audio_format_t[]>(numSurroundFormats);
    auto surroundFormatsEnabled = std::make_unique<bool[]>(numSurroundFormats);
    status = AudioSystem::getSurroundFormats(&numSurroundFormats, &surroundFormats[0],
                                             &surroundFormatsEnabled[0]);
    jStatus = nativeToJavaStatus(status);
    if (status != NO_ERROR) {
        ALOGE_IF(status != NO_ERROR, "AudioSystem::getSurroundFormats error %d", status);
        goto exit;
        return jStatus;
    }
    for (size_t i = 0; i < numSurroundFormats; i++) {
        int audioFormat = audioFormatFromNative(surroundFormats[i]);
@@ -2526,9 +2521,6 @@ static jint android_media_AudioSystem_getSurroundFormats(JNIEnv *env, jobject th
        env->DeleteLocalRef(enabled);
    }

exit:
    free(surroundFormats);
    free(surroundFormatsEnabled);
    return jStatus;
}

@@ -2538,31 +2530,28 @@ static jint android_media_AudioSystem_getReportedSurroundFormats(JNIEnv *env, jo

    if (jSurroundFormats == nullptr) {
        ALOGE("jSurroundFormats is NULL");
        return (jint)AUDIO_JAVA_BAD_VALUE;
        return static_cast<jint>(AUDIO_JAVA_BAD_VALUE);
    }
    if (!env->IsInstanceOf(jSurroundFormats, gArrayListClass)) {
        ALOGE("jSurroundFormats not an arraylist");
        return (jint)AUDIO_JAVA_BAD_VALUE;
        return static_cast<jint>(AUDIO_JAVA_BAD_VALUE);
    }
    jint jStatus;
    unsigned int numSurroundFormats = 0;
    audio_format_t *surroundFormats = nullptr;
    status_t status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, surroundFormats);
    status_t status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, nullptr);
    if (status != NO_ERROR) {
        ALOGE_IF(status != NO_ERROR, "AudioSystem::getReportedSurroundFormats error %d", status);
        jStatus = nativeToJavaStatus(status);
        goto exit;
        return nativeToJavaStatus(status);
    }
    if (numSurroundFormats == 0) {
        jStatus = (jint)AUDIO_JAVA_SUCCESS;
        goto exit;
        return static_cast<jint>(AUDIO_JAVA_SUCCESS);
    }
    surroundFormats = (audio_format_t *)calloc(numSurroundFormats, sizeof(audio_format_t));
    status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, surroundFormats);
    auto surroundFormats = std::make_unique<audio_format_t[]>(numSurroundFormats);
    status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, &surroundFormats[0]);
    jStatus = nativeToJavaStatus(status);
    if (status != NO_ERROR) {
        ALOGE_IF(status != NO_ERROR, "AudioSystem::getReportedSurroundFormats error %d", status);
        goto exit;
        return jStatus;
    }
    for (size_t i = 0; i < numSurroundFormats; i++) {
        int audioFormat = audioFormatFromNative(surroundFormats[i]);
@@ -2576,8 +2565,6 @@ static jint android_media_AudioSystem_getReportedSurroundFormats(JNIEnv *env, jo
        env->DeleteLocalRef(surroundFormat);
    }

exit:
    free(surroundFormats);
    return jStatus;
}