Merge "Filter unsuported native audio formats in getDirectProfilesForAttributes" into tm-dev am: a3f6dae96f

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

Change-Id: I0efe9e79265007fda4de4000316847d85ba0ef4d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-05-09 17:41:10 +00:00
committed by Automerger Merge Worker

View File

@@ -1264,6 +1264,12 @@ static jint convertAudioProfileFromNative(JNIEnv *env, jobject *jAudioProfile,
size_t numPositionMasks = 0; size_t numPositionMasks = 0;
size_t numIndexMasks = 0; size_t numIndexMasks = 0;
int audioFormat = audioFormatFromNative(nAudioProfile->format);
if (audioFormat == ENCODING_INVALID) {
ALOGW("Unknown native audio format for JAVA API: %u", nAudioProfile->format);
return AUDIO_JAVA_BAD_VALUE;
}
// count up how many masks are positional and indexed // count up how many masks are positional and indexed
for (size_t index = 0; index < nAudioProfile->num_channel_masks; index++) { for (size_t index = 0; index < nAudioProfile->num_channel_masks; index++) {
const audio_channel_mask_t mask = nAudioProfile->channel_masks[index]; const audio_channel_mask_t mask = nAudioProfile->channel_masks[index];
@@ -1306,10 +1312,9 @@ static jint convertAudioProfileFromNative(JNIEnv *env, jobject *jAudioProfile,
ALOGW("Unknown encapsulation type for JAVA API: %u", nAudioProfile->encapsulation_type); ALOGW("Unknown encapsulation type for JAVA API: %u", nAudioProfile->encapsulation_type);
} }
*jAudioProfile = *jAudioProfile = env->NewObject(gAudioProfileClass, gAudioProfileCstor, audioFormat,
env->NewObject(gAudioProfileClass, gAudioProfileCstor, jSamplingRates.get(), jChannelMasks.get(),
audioFormatFromNative(nAudioProfile->format), jSamplingRates.get(), jChannelIndexMasks.get(), encapsulationType);
jChannelMasks.get(), jChannelIndexMasks.get(), encapsulationType);
if (*jAudioProfile == nullptr) { if (*jAudioProfile == nullptr) {
return AUDIO_JAVA_ERROR; return AUDIO_JAVA_ERROR;
@@ -1368,6 +1373,10 @@ static jint convertAudioPortFromNative(JNIEnv *env, jobject *jAudioPort,
jobject jAudioProfile = nullptr; jobject jAudioProfile = nullptr;
jStatus = convertAudioProfileFromNative(env, &jAudioProfile, &nAudioPort->audio_profiles[i], jStatus = convertAudioProfileFromNative(env, &jAudioProfile, &nAudioPort->audio_profiles[i],
useInMask); useInMask);
if (jStatus == AUDIO_JAVA_BAD_VALUE) {
// skipping Java layer unsupported audio formats
continue;
}
if (jStatus != NO_ERROR) { if (jStatus != NO_ERROR) {
jStatus = (jint)AUDIO_JAVA_ERROR; jStatus = (jint)AUDIO_JAVA_ERROR;
goto exit; goto exit;
@@ -2406,8 +2415,13 @@ static jint android_media_AudioSystem_getSurroundFormats(JNIEnv *env, jobject th
goto exit; goto exit;
} }
for (size_t i = 0; i < numSurroundFormats; i++) { for (size_t i = 0; i < numSurroundFormats; i++) {
jobject surroundFormat = env->NewObject(gIntegerClass, gIntegerCstor, int audioFormat = audioFormatFromNative(surroundFormats[i]);
audioFormatFromNative(surroundFormats[i])); if (audioFormat == ENCODING_INVALID) {
// skipping Java layer unsupported audio formats
ALOGW("Unknown surround native audio format for JAVA API: %u", surroundFormats[i]);
continue;
}
jobject surroundFormat = env->NewObject(gIntegerClass, gIntegerCstor, audioFormat);
jobject enabled = env->NewObject(gBooleanClass, gBooleanCstor, surroundFormatsEnabled[i]); jobject enabled = env->NewObject(gBooleanClass, gBooleanCstor, surroundFormatsEnabled[i]);
env->CallObjectMethod(jSurroundFormats, gMapPut, surroundFormat, enabled); env->CallObjectMethod(jSurroundFormats, gMapPut, surroundFormat, enabled);
env->DeleteLocalRef(surroundFormat); env->DeleteLocalRef(surroundFormat);
@@ -2453,8 +2467,13 @@ static jint android_media_AudioSystem_getReportedSurroundFormats(JNIEnv *env, jo
goto exit; goto exit;
} }
for (size_t i = 0; i < numSurroundFormats; i++) { for (size_t i = 0; i < numSurroundFormats; i++) {
jobject surroundFormat = env->NewObject(gIntegerClass, gIntegerCstor, int audioFormat = audioFormatFromNative(surroundFormats[i]);
audioFormatFromNative(surroundFormats[i])); if (audioFormat == ENCODING_INVALID) {
// skipping Java layer unsupported audio formats
ALOGW("Unknown surround native audio format for JAVA API: %u", surroundFormats[i]);
continue;
}
jobject surroundFormat = env->NewObject(gIntegerClass, gIntegerCstor, audioFormat);
env->CallObjectMethod(jSurroundFormats, gArrayListMethods.add, surroundFormat); env->CallObjectMethod(jSurroundFormats, gArrayListMethods.add, surroundFormat);
env->DeleteLocalRef(surroundFormat); env->DeleteLocalRef(surroundFormat);
} }
@@ -2919,6 +2938,10 @@ static jint android_media_AudioSystem_getDirectProfilesForAttributes(JNIEnv *env
for (const auto &audioProfile : audioProfiles) { for (const auto &audioProfile : audioProfiles) {
jobject jAudioProfile; jobject jAudioProfile;
jStatus = convertAudioProfileFromNative(env, &jAudioProfile, &audioProfile, false); jStatus = convertAudioProfileFromNative(env, &jAudioProfile, &audioProfile, false);
if (jStatus == AUDIO_JAVA_BAD_VALUE) {
// skipping Java layer unsupported audio formats
continue;
}
if (jStatus != AUDIO_JAVA_SUCCESS) { if (jStatus != AUDIO_JAVA_SUCCESS) {
return jStatus; return jStatus;
} }