Merge "audio: Use auto-generated MicrophoneInfoFw class" am: b28d0c3ed6

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

Change-Id: I5d9c068ef0ff3f76b7980b06f34dceacbe8f4b56
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Mikhail Naganov 2023-02-16 16:47:12 +00:00 committed by Automerger Merge Worker
commit ad0a80281d
5 changed files with 51 additions and 70 deletions

View File

@ -18,29 +18,25 @@
#define LOG_TAG "AudioRecord-JNI" #define LOG_TAG "AudioRecord-JNI"
#include <inttypes.h>
#include <jni.h>
#include <nativehelper/JNIHelp.h>
#include "core_jni_helpers.h"
#include <utils/Log.h>
#include <media/AudioRecord.h>
#include <media/MicrophoneInfo.h>
#include <vector>
#include <android/content/AttributionSourceState.h> #include <android/content/AttributionSourceState.h>
#include <android_os_Parcel.h> #include <android_os_Parcel.h>
#include <inttypes.h>
#include <jni.h>
#include <media/AudioRecord.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/ScopedUtfChars.h> #include <nativehelper/ScopedUtfChars.h>
#include <utils/Log.h>
#include <vector>
#include "android_media_AudioAttributes.h" #include "android_media_AudioAttributes.h"
#include "android_media_AudioFormat.h"
#include "android_media_AudioErrors.h" #include "android_media_AudioErrors.h"
#include "android_media_AudioFormat.h"
#include "android_media_DeviceCallback.h" #include "android_media_DeviceCallback.h"
#include "android_media_JNIUtils.h" #include "android_media_JNIUtils.h"
#include "android_media_MediaMetricsJNI.h" #include "android_media_MediaMetricsJNI.h"
#include "android_media_MicrophoneInfo.h" #include "android_media_MicrophoneInfo.h"
#include "core_jni_helpers.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -721,7 +717,7 @@ static jint android_media_AudioRecord_get_active_microphones(JNIEnv *env,
} }
jint jStatus = AUDIO_JAVA_SUCCESS; jint jStatus = AUDIO_JAVA_SUCCESS;
std::vector<media::MicrophoneInfo> activeMicrophones; std::vector<media::MicrophoneInfoFw> activeMicrophones;
status_t status = lpRecorder->getActiveMicrophones(&activeMicrophones); status_t status = lpRecorder->getActiveMicrophones(&activeMicrophones);
if (status != NO_ERROR) { if (status != NO_ERROR) {
ALOGE_IF(status != NO_ERROR, "AudioRecord::getActiveMicrophones error %d", status); ALOGE_IF(status != NO_ERROR, "AudioRecord::getActiveMicrophones error %d", status);

View File

@ -27,7 +27,6 @@
#include <media/AudioContainers.h> #include <media/AudioContainers.h>
#include <media/AudioPolicy.h> #include <media/AudioPolicy.h>
#include <media/AudioSystem.h> #include <media/AudioSystem.h>
#include <media/MicrophoneInfo.h>
#include <nativehelper/JNIHelp.h> #include <nativehelper/JNIHelp.h>
#include <nativehelper/ScopedLocalRef.h> #include <nativehelper/ScopedLocalRef.h>
#include <system/audio.h> #include <system/audio.h>
@ -2325,7 +2324,7 @@ android_media_AudioSystem_getMicrophones(JNIEnv *env, jobject thiz, jobject jMic
} }
jint jStatus; jint jStatus;
std::vector<media::MicrophoneInfo> microphones; std::vector<media::MicrophoneInfoFw> microphones;
status_t status = AudioSystem::getMicrophones(&microphones); status_t status = AudioSystem::getMicrophones(&microphones);
if (status != NO_ERROR) { if (status != NO_ERROR) {
ALOGE("AudioSystem::getMicrophones error %d", status); ALOGE("AudioSystem::getMicrophones error %d", status);

View File

@ -15,6 +15,9 @@
*/ */
#include "android_media_MicrophoneInfo.h" #include "android_media_MicrophoneInfo.h"
#include <media/AidlConversion.h>
#include "android_media_AudioErrors.h" #include "android_media_AudioErrors.h"
#include "core_jni_helpers.h" #include "core_jni_helpers.h"
@ -46,8 +49,17 @@ static jmethodID gPairCstor;
namespace android { namespace android {
jint convertMicrophoneInfoFromNative(JNIEnv *env, jobject *jMicrophoneInfo, jint convertMicrophoneInfoFromNative(JNIEnv *env, jobject *jMicrophoneInfo,
const media::MicrophoneInfo *microphoneInfo) const media::MicrophoneInfoFw *microphoneInfo) {
{ // The Java object uses the same enum values as the C enum values, which are
// generated from HIDL. Thus, we can use the legacy structure as the source for
// creating the Java object. Once we start removing legacy types, we can add
// direct converters between Java and AIDL, this will eliminate the need
// to have JNI code like this one.
auto conv = aidl2legacy_MicrophoneInfoFw_audio_microphone_characteristic_t(*microphoneInfo);
if (!conv.ok()) {
return nativeToJavaStatus(conv.error());
}
jint jStatus = (jint)AUDIO_JAVA_SUCCESS; jint jStatus = (jint)AUDIO_JAVA_SUCCESS;
jstring jDeviceId = NULL; jstring jDeviceId = NULL;
jstring jAddress = NULL; jstring jAddress = NULL;
@ -56,36 +68,23 @@ jint convertMicrophoneInfoFromNative(JNIEnv *env, jobject *jMicrophoneInfo,
jobject jFrequencyResponses = NULL; jobject jFrequencyResponses = NULL;
jobject jChannelMappings = NULL; jobject jChannelMappings = NULL;
jDeviceId = env->NewStringUTF(microphoneInfo->getDeviceId().c_str()); const auto &micInfo = conv.value();
jAddress = env->NewStringUTF(microphoneInfo->getAddress().c_str()); jDeviceId = env->NewStringUTF(micInfo.device_id);
if (microphoneInfo->getGeometricLocation().size() != 3 || jAddress = env->NewStringUTF(micInfo.address);
microphoneInfo->getOrientation().size() != 3) { jGeometricLocation =
jStatus = nativeToJavaStatus(BAD_VALUE); env->NewObject(gMicrophoneInfoCoordinateClass, gMicrophoneInfoCoordinateCstor,
goto exit; micInfo.geometric_location.x, micInfo.geometric_location.y,
} micInfo.geometric_location.z);
jGeometricLocation = env->NewObject(gMicrophoneInfoCoordinateClass, jOrientation =
gMicrophoneInfoCoordinateCstor, env->NewObject(gMicrophoneInfoCoordinateClass, gMicrophoneInfoCoordinateCstor,
microphoneInfo->getGeometricLocation()[0], micInfo.orientation.x, micInfo.orientation.y, micInfo.orientation.z);
microphoneInfo->getGeometricLocation()[1],
microphoneInfo->getGeometricLocation()[2]);
jOrientation = env->NewObject(gMicrophoneInfoCoordinateClass,
gMicrophoneInfoCoordinateCstor,
microphoneInfo->getOrientation()[0],
microphoneInfo->getOrientation()[1],
microphoneInfo->getOrientation()[2]);
// Create a list of Pair for frequency response. // Create a list of Pair for frequency response.
if (microphoneInfo->getFrequencyResponses().size() != 2 ||
microphoneInfo->getFrequencyResponses()[0].size() !=
microphoneInfo->getFrequencyResponses()[1].size()) {
jStatus = nativeToJavaStatus(BAD_VALUE);
goto exit;
}
jFrequencyResponses = env->NewObject(gArrayListClass, gArrayListCstor); jFrequencyResponses = env->NewObject(gArrayListClass, gArrayListCstor);
for (size_t i = 0; i < microphoneInfo->getFrequencyResponses()[0].size(); i++) { for (size_t i = 0; i < micInfo.num_frequency_responses; i++) {
jobject jFrequency = env->NewObject(gFloatClass, gFloatCstor, jobject jFrequency =
microphoneInfo->getFrequencyResponses()[0][i]); env->NewObject(gFloatClass, gFloatCstor, micInfo.frequency_responses[0][i]);
jobject jResponse = env->NewObject(gFloatClass, gFloatCstor, jobject jResponse =
microphoneInfo->getFrequencyResponses()[1][i]); env->NewObject(gFloatClass, gFloatCstor, micInfo.frequency_responses[1][i]);
jobject jFrequencyResponse = env->NewObject(gPairClass, gPairCstor, jFrequency, jResponse); jobject jFrequencyResponse = env->NewObject(gPairClass, gPairCstor, jFrequency, jResponse);
env->CallBooleanMethod(jFrequencyResponses, gArrayListMethods.add, jFrequencyResponse); env->CallBooleanMethod(jFrequencyResponses, gArrayListMethods.add, jFrequencyResponse);
env->DeleteLocalRef(jFrequency); env->DeleteLocalRef(jFrequency);
@ -93,13 +92,9 @@ jint convertMicrophoneInfoFromNative(JNIEnv *env, jobject *jMicrophoneInfo,
env->DeleteLocalRef(jFrequencyResponse); env->DeleteLocalRef(jFrequencyResponse);
} }
// Create a list of Pair for channel mapping. // Create a list of Pair for channel mapping.
if (microphoneInfo->getChannelMapping().size() != AUDIO_CHANNEL_COUNT_MAX) { const auto &channelMapping = micInfo.channel_mapping;
jStatus = nativeToJavaStatus(BAD_VALUE); for (size_t i = 0; i < std::size(channelMapping); i++) {
goto exit; int channelMappingType = channelMapping[i];
}
jChannelMappings = env->NewObject(gArrayListClass, gArrayListCstor);
for (size_t i = 0; i < microphoneInfo->getChannelMapping().size(); i++) {
int channelMappingType = microphoneInfo->getChannelMapping()[i];
if (channelMappingType != AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED) { if (channelMappingType != AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED) {
jobject jChannelIndex = env->NewObject(gIntegerClass, gIntegerCstor, i); jobject jChannelIndex = env->NewObject(gIntegerClass, gIntegerCstor, i);
jobject jChannelMappingType = env->NewObject(gIntegerClass, gIntegerCstor, jobject jChannelMappingType = env->NewObject(gIntegerClass, gIntegerCstor,
@ -113,18 +108,11 @@ jint convertMicrophoneInfoFromNative(JNIEnv *env, jobject *jMicrophoneInfo,
} }
} }
*jMicrophoneInfo = env->NewObject(gMicrophoneInfoClass, gMicrophoneInfoCstor, jDeviceId, *jMicrophoneInfo = env->NewObject(gMicrophoneInfoClass, gMicrophoneInfoCstor, jDeviceId,
microphoneInfo->getType(), jAddress, micInfo.device, jAddress, micInfo.location, micInfo.group,
microphoneInfo->getDeviceLocation(), micInfo.index_in_the_group, jGeometricLocation, jOrientation,
microphoneInfo->getDeviceGroup(), jFrequencyResponses, jChannelMappings, micInfo.sensitivity,
microphoneInfo->getIndexInTheGroup(), micInfo.max_spl, micInfo.min_spl, micInfo.directionality);
jGeometricLocation, jOrientation,
jFrequencyResponses, jChannelMappings,
microphoneInfo->getSensitivity(),
microphoneInfo->getMaxSpl(),
microphoneInfo->getMinSpl(),
microphoneInfo->getDirectionality());
exit:
if (jDeviceId != NULL) { if (jDeviceId != NULL) {
env->DeleteLocalRef(jDeviceId); env->DeleteLocalRef(jDeviceId);
} }
@ -145,7 +133,6 @@ exit:
} }
return jStatus; return jStatus;
} }
} }
int register_android_media_MicrophoneInfo(JNIEnv *env) int register_android_media_MicrophoneInfo(JNIEnv *env)

View File

@ -17,8 +17,8 @@
#ifndef ANDROID_MEDIA_MICROPHONEINFO_H #ifndef ANDROID_MEDIA_MICROPHONEINFO_H
#define ANDROID_MEDIA_MICROPHONEINFO_H #define ANDROID_MEDIA_MICROPHONEINFO_H
#include <android/media/MicrophoneInfoFw.h>
#include <system/audio.h> #include <system/audio.h>
#include <media/MicrophoneInfo.h>
#include "jni.h" #include "jni.h"
@ -27,7 +27,7 @@ namespace android {
// Conversion from C++ MicrophoneInfo object to Java MicrophoneInfo object // Conversion from C++ MicrophoneInfo object to Java MicrophoneInfo object
extern jint convertMicrophoneInfoFromNative(JNIEnv *env, jobject *jMicrophoneInfo, extern jint convertMicrophoneInfoFromNative(JNIEnv *env, jobject *jMicrophoneInfo,
const media::MicrophoneInfo *microphoneInfo); const media::MicrophoneInfoFw *microphoneInfo);
} // namespace android } // namespace android
#endif #endif

View File

@ -30,7 +30,6 @@
#include <camera/Camera.h> #include <camera/Camera.h>
#include <media/mediarecorder.h> #include <media/mediarecorder.h>
#include <media/MediaMetricsItem.h> #include <media/MediaMetricsItem.h>
#include <media/MicrophoneInfo.h>
#include <media/stagefright/PersistentSurface.h> #include <media/stagefright/PersistentSurface.h>
#include <utils/threads.h> #include <utils/threads.h>
@ -774,7 +773,7 @@ android_media_MediaRecord_getActiveMicrophones(JNIEnv *env,
} }
jint jStatus = AUDIO_JAVA_SUCCESS; jint jStatus = AUDIO_JAVA_SUCCESS;
std::vector<media::MicrophoneInfo> activeMicrophones; std::vector<media::MicrophoneInfoFw> activeMicrophones;
status_t status = mr->getActiveMicrophones(&activeMicrophones); status_t status = mr->getActiveMicrophones(&activeMicrophones);
if (status != NO_ERROR) { if (status != NO_ERROR) {
ALOGE_IF(status != NO_ERROR, "MediaRecorder::getActiveMicrophones error %d", status); ALOGE_IF(status != NO_ERROR, "MediaRecorder::getActiveMicrophones error %d", status);