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

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

Change-Id: I09371fff110b28d8bb68bc2d1839672c1d1fdc8a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Eric Laurent
2023-04-11 09:20:59 +00:00
committed by Automerger Merge Worker

View File

@@ -2382,36 +2382,31 @@ static jint android_media_AudioSystem_getSurroundFormats(JNIEnv *env, jobject th
if (jSurroundFormats == nullptr) { if (jSurroundFormats == nullptr) {
ALOGE("jSurroundFormats is NULL"); ALOGE("jSurroundFormats is NULL");
return (jint)AUDIO_JAVA_BAD_VALUE; return static_cast<jint>(AUDIO_JAVA_BAD_VALUE);
} }
if (!env->IsInstanceOf(jSurroundFormats, gMapClass)) { if (!env->IsInstanceOf(jSurroundFormats, gMapClass)) {
ALOGE("getSurroundFormats not a map"); ALOGE("getSurroundFormats not a map");
return (jint)AUDIO_JAVA_BAD_VALUE; return static_cast<jint>(AUDIO_JAVA_BAD_VALUE);
} }
jint jStatus; jint jStatus;
unsigned int numSurroundFormats = 0; unsigned int numSurroundFormats = 0;
audio_format_t *surroundFormats = nullptr; status_t status = AudioSystem::getSurroundFormats(&numSurroundFormats, nullptr, nullptr);
bool *surroundFormatsEnabled = nullptr;
status_t status = AudioSystem::getSurroundFormats(&numSurroundFormats, surroundFormats,
surroundFormatsEnabled);
if (status != NO_ERROR) { if (status != NO_ERROR) {
ALOGE_IF(status != NO_ERROR, "AudioSystem::getSurroundFormats error %d", status); ALOGE_IF(status != NO_ERROR, "AudioSystem::getSurroundFormats error %d", status);
jStatus = nativeToJavaStatus(status); return nativeToJavaStatus(status);
goto exit;
} }
if (numSurroundFormats == 0) { if (numSurroundFormats == 0) {
jStatus = (jint)AUDIO_JAVA_SUCCESS; return static_cast<jint>(AUDIO_JAVA_SUCCESS);
goto exit;
} }
surroundFormats = (audio_format_t *)calloc(numSurroundFormats, sizeof(audio_format_t)); auto surroundFormats = std::make_unique<audio_format_t[]>(numSurroundFormats);
surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool)); auto surroundFormatsEnabled = std::make_unique<bool[]>(numSurroundFormats);
status = AudioSystem::getSurroundFormats(&numSurroundFormats, surroundFormats, status = AudioSystem::getSurroundFormats(&numSurroundFormats, &surroundFormats[0],
surroundFormatsEnabled); &surroundFormatsEnabled[0]);
jStatus = nativeToJavaStatus(status); jStatus = nativeToJavaStatus(status);
if (status != NO_ERROR) { if (status != NO_ERROR) {
ALOGE_IF(status != NO_ERROR, "AudioSystem::getSurroundFormats error %d", status); ALOGE_IF(status != NO_ERROR, "AudioSystem::getSurroundFormats error %d", status);
goto exit; return jStatus;
} }
for (size_t i = 0; i < numSurroundFormats; i++) { for (size_t i = 0; i < numSurroundFormats; i++) {
int audioFormat = audioFormatFromNative(surroundFormats[i]); int audioFormat = audioFormatFromNative(surroundFormats[i]);
@@ -2427,9 +2422,6 @@ static jint android_media_AudioSystem_getSurroundFormats(JNIEnv *env, jobject th
env->DeleteLocalRef(enabled); env->DeleteLocalRef(enabled);
} }
exit:
free(surroundFormats);
free(surroundFormatsEnabled);
return jStatus; return jStatus;
} }
@@ -2439,31 +2431,28 @@ static jint android_media_AudioSystem_getReportedSurroundFormats(JNIEnv *env, jo
if (jSurroundFormats == nullptr) { if (jSurroundFormats == nullptr) {
ALOGE("jSurroundFormats is NULL"); ALOGE("jSurroundFormats is NULL");
return (jint)AUDIO_JAVA_BAD_VALUE; return static_cast<jint>(AUDIO_JAVA_BAD_VALUE);
} }
if (!env->IsInstanceOf(jSurroundFormats, gArrayListClass)) { if (!env->IsInstanceOf(jSurroundFormats, gArrayListClass)) {
ALOGE("jSurroundFormats not an arraylist"); ALOGE("jSurroundFormats not an arraylist");
return (jint)AUDIO_JAVA_BAD_VALUE; return static_cast<jint>(AUDIO_JAVA_BAD_VALUE);
} }
jint jStatus; jint jStatus;
unsigned int numSurroundFormats = 0; unsigned int numSurroundFormats = 0;
audio_format_t *surroundFormats = nullptr; status_t status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, nullptr);
status_t status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, surroundFormats);
if (status != NO_ERROR) { if (status != NO_ERROR) {
ALOGE_IF(status != NO_ERROR, "AudioSystem::getReportedSurroundFormats error %d", status); ALOGE_IF(status != NO_ERROR, "AudioSystem::getReportedSurroundFormats error %d", status);
jStatus = nativeToJavaStatus(status); return nativeToJavaStatus(status);
goto exit;
} }
if (numSurroundFormats == 0) { if (numSurroundFormats == 0) {
jStatus = (jint)AUDIO_JAVA_SUCCESS; return static_cast<jint>(AUDIO_JAVA_SUCCESS);
goto exit;
} }
surroundFormats = (audio_format_t *)calloc(numSurroundFormats, sizeof(audio_format_t)); auto surroundFormats = std::make_unique<audio_format_t[]>(numSurroundFormats);
status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, surroundFormats); status = AudioSystem::getReportedSurroundFormats(&numSurroundFormats, &surroundFormats[0]);
jStatus = nativeToJavaStatus(status); jStatus = nativeToJavaStatus(status);
if (status != NO_ERROR) { if (status != NO_ERROR) {
ALOGE_IF(status != NO_ERROR, "AudioSystem::getReportedSurroundFormats error %d", status); ALOGE_IF(status != NO_ERROR, "AudioSystem::getReportedSurroundFormats error %d", status);
goto exit; return jStatus;
} }
for (size_t i = 0; i < numSurroundFormats; i++) { for (size_t i = 0; i < numSurroundFormats; i++) {
int audioFormat = audioFormatFromNative(surroundFormats[i]); int audioFormat = audioFormatFromNative(surroundFormats[i]);
@@ -2477,8 +2466,6 @@ static jint android_media_AudioSystem_getReportedSurroundFormats(JNIEnv *env, jo
env->DeleteLocalRef(surroundFormat); env->DeleteLocalRef(surroundFormat);
} }
exit:
free(surroundFormats);
return jStatus; return jStatus;
} }