Support query microphones information.
Get list of all/currently active microphones from hal.
Bug: 64038649
Test: Manual Testing and Cts test
Change-Id: Id39cae38ba040f9bc91571e713487f87c2eb67b0
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index ea06b6c..32ed0bb 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1962,39 +1962,10 @@
status_t AudioFlinger::getMicrophones(std::vector<media::MicrophoneInfo> *microphones)
{
- // Fake data
- size_t fakeNum = 2;
- audio_devices_t fakeTypes[] = { AUDIO_DEVICE_IN_BUILTIN_MIC, AUDIO_DEVICE_IN_BACK_MIC };
- for (size_t i = 0; i < fakeNum; i++) {
- struct audio_microphone_characteristic_t characteristics;
- sprintf(characteristics.device_id, "microphone:%zu", i);
- characteristics.device = fakeTypes[i];
- sprintf(characteristics.address, "");
- characteristics.location = AUDIO_MICROPHONE_LOCATION_MAINBODY;
- characteristics.group = 0;
- characteristics.index_in_the_group = i;
- characteristics.sensitivity = 1.0f;
- characteristics.max_spl = 100.0f;
- characteristics.min_spl = 0.0f;
- characteristics.directionality = AUDIO_MICROPHONE_DIRECTIONALITY_OMNI;
- characteristics.num_frequency_responses = 5 - i;
- for (size_t j = 0; j < characteristics.num_frequency_responses; j++) {
- characteristics.frequency_responses[0][j] = 100.0f - j;
- characteristics.frequency_responses[1][j] = 100.0f + j;
- }
- for (size_t j = 0; j < AUDIO_CHANNEL_COUNT_MAX; j++) {
- characteristics.channel_mapping[j] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
- }
- characteristics.geometric_location.x = 0.1f;
- characteristics.geometric_location.y = 0.2f;
- characteristics.geometric_location.z = 0.3f;
- characteristics.orientation.x = 0.0f;
- characteristics.orientation.y = 1.0f;
- characteristics.orientation.z = 0.0f;
- media::MicrophoneInfo microphoneInfo = media::MicrophoneInfo(characteristics);
- microphones->push_back(microphoneInfo);
- }
- return NO_ERROR;
+ AutoMutex lock(mHardwareLock);
+ sp<DeviceHalInterface> dev = mPrimaryHardwareDev->hwDevice();
+ status_t status = dev->getMicrophones(microphones);
+ return status;
}
// setAudioHwSyncForSession_l() must be called with AudioFlinger::mLock held
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 62e9fe7..875b55f 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -7129,42 +7129,8 @@
{
ALOGV("RecordThread::getActiveMicrophones");
AutoMutex _l(mLock);
- // Fake data
- struct audio_microphone_characteristic_t characteristic;
- sprintf(characteristic.device_id, "builtin_mic");
- characteristic.device = AUDIO_DEVICE_IN_BUILTIN_MIC;
- sprintf(characteristic.address, "");
- characteristic.location = AUDIO_MICROPHONE_LOCATION_MAINBODY;
- characteristic.group = 0;
- characteristic.index_in_the_group = 0;
- characteristic.sensitivity = 1.0f;
- characteristic.max_spl = 100.0f;
- characteristic.min_spl = 0.0f;
- characteristic.directionality = AUDIO_MICROPHONE_DIRECTIONALITY_OMNI;
- characteristic.num_frequency_responses = 5;
- for (size_t i = 0; i < characteristic.num_frequency_responses; i++) {
- characteristic.frequency_responses[0][i] = 100.0f - i;
- characteristic.frequency_responses[1][i] = 100.0f + i;
- }
- for (size_t i = 0; i < AUDIO_CHANNEL_COUNT_MAX; i++) {
- characteristic.channel_mapping[i] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
- }
- audio_microphone_channel_mapping_t channel_mappings[] = {
- AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT,
- AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED,
- };
- for (size_t i = 0; i < mChannelCount; i++) {
- characteristic.channel_mapping[i] = channel_mappings[i % 2];
- }
- characteristic.geometric_location.x = 0.1f;
- characteristic.geometric_location.y = 0.2f;
- characteristic.geometric_location.z = 0.3f;
- characteristic.orientation.x = 0.0f;
- characteristic.orientation.y = 1.0f;
- characteristic.orientation.z = 0.0f;
- media::MicrophoneInfo microphoneInfo = media::MicrophoneInfo(characteristic);
- activeMicrophones->push_back(microphoneInfo);
- return NO_ERROR;
+ status_t status = mInput->stream->getActiveMicrophones(activeMicrophones);
+ return status;
}
// destroyTrack_l() must be called with ThreadBase::mLock held
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 73d92ac..126da1e 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -3777,6 +3777,16 @@
ALOGE("Default device %08x is unreachable", mDefaultOutputDevice->type());
status = NO_INIT;
}
+ // If microphones address is empty, set it according to device type
+ for (size_t i = 0; i < mAvailableInputDevices.size(); i++) {
+ if (mAvailableInputDevices[i]->mAddress.isEmpty()) {
+ if (mAvailableInputDevices[i]->type() == AUDIO_DEVICE_IN_BUILTIN_MIC) {
+ mAvailableInputDevices[i]->mAddress = String8(AUDIO_BOTTOM_MICROPHONE_ADDRESS);
+ } else if (mAvailableInputDevices[i]->type() == AUDIO_DEVICE_IN_BACK_MIC) {
+ mAvailableInputDevices[i]->mAddress = String8(AUDIO_BACK_MICROPHONE_ADDRESS);
+ }
+ }
+ }
if (mPrimaryOutput == 0) {
ALOGE("Failed to open primary output");