Support query active microphones information in AudioRecord.
This is part of device enumeration. With the new add API, developer
could get the active microphones information for each channel.
Bug: 64038649
Test: Run cts and check the print log.
Change-Id: Ic63d86e533a30e40697da7522a5a81f7cfcea988
diff --git a/media/libaudioclient/AudioRecord.cpp b/media/libaudioclient/AudioRecord.cpp
index 3aebb8a..6b3a8f0 100644
--- a/media/libaudioclient/AudioRecord.cpp
+++ b/media/libaudioclient/AudioRecord.cpp
@@ -1316,6 +1316,14 @@
}
}
+// -------------------------------------------------------------------------
+
+status_t AudioRecord::getActiveMicrophones(std::vector<media::MicrophoneInfo>* activeMicrophones)
+{
+ AutoMutex lock(mLock);
+ return mAudioRecord->getActiveMicrophones(activeMicrophones).transactionError();
+}
+
// =========================================================================
void AudioRecord::DeathNotifier::binderDied(const wp<IBinder>& who __unused)
diff --git a/media/libaudioclient/aidl/android/media/IAudioRecord.aidl b/media/libaudioclient/aidl/android/media/IAudioRecord.aidl
index 7572671..01e0a71 100644
--- a/media/libaudioclient/aidl/android/media/IAudioRecord.aidl
+++ b/media/libaudioclient/aidl/android/media/IAudioRecord.aidl
@@ -16,6 +16,8 @@
package android.media;
+import android.media.MicrophoneInfo;
+
/* Native code must specify namespace media (media::IAudioRecord) when referring to this class */
interface IAudioRecord {
@@ -30,4 +32,8 @@
* will be processed, unless flush() is called.
*/
void stop();
+
+ /* Get a list of current active microphones.
+ */
+ void getActiveMicrophones(out MicrophoneInfo[] activeMicrophones);
}
diff --git a/media/libaudioclient/include/media/AudioRecord.h b/media/libaudioclient/include/media/AudioRecord.h
index caaefce..a82e21e 100644
--- a/media/libaudioclient/include/media/AudioRecord.h
+++ b/media/libaudioclient/include/media/AudioRecord.h
@@ -23,8 +23,10 @@
#include <media/AudioTimestamp.h>
#include <media/MediaAnalyticsItem.h>
#include <media/Modulo.h>
+#include <media/MicrophoneInfo.h>
#include <utils/RefBase.h>
#include <utils/threads.h>
+#include <vector>
#include "android/media/IAudioRecord.h"
@@ -527,6 +529,11 @@
/* Get the flags */
audio_input_flags_t getFlags() const { AutoMutex _l(mLock); return mFlags; }
+ /* Get active microphones. A empty vector of MicrophoneInfo will be passed as a parameter,
+ * the data will be filled when querying the hal.
+ */
+ status_t getActiveMicrophones(std::vector<media::MicrophoneInfo>* activeMicrophones);
+
/*
* Dumps the state of an audio record.
*/
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 83caca7..7c38bcc 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -559,6 +559,8 @@
virtual binder::Status start(int /*AudioSystem::sync_event_t*/ event,
int /*audio_session_t*/ triggerSession);
virtual binder::Status stop();
+ virtual binder::Status getActiveMicrophones(
+ std::vector<media::MicrophoneInfo>* activeMicrophones);
private:
const sp<RecordThread::RecordTrack> mRecordTrack;
diff --git a/services/audioflinger/RecordTracks.h b/services/audioflinger/RecordTracks.h
index 63a3d98..1733ef5 100644
--- a/services/audioflinger/RecordTracks.h
+++ b/services/audioflinger/RecordTracks.h
@@ -66,6 +66,8 @@
void setSilenced(bool silenced) { mSilenced = silenced; }
bool isSilenced() const { return mSilenced; }
+ status_t getActiveMicrophones(std::vector<media::MicrophoneInfo>* activeMicrophones);
+
private:
friend class AudioFlinger; // for mState
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 7bfe802..f8fa094 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -7042,6 +7042,49 @@
#endif
}
+status_t AudioFlinger::RecordThread::getActiveMicrophones(
+ std::vector<media::MicrophoneInfo>* activeMicrophones)
+{
+ ALOGV("RecordThread::getActiveMicrophones");
+ AutoMutex _l(mLock);
+ // Fake data
+ struct audio_microphone_characteristic_t characteristic;
+ sprintf(characteristic.device_id, "builtin_mic");
+ characteristic.type = 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;
+}
+
// destroyTrack_l() must be called with ThreadBase::mLock held
void AudioFlinger::RecordThread::destroyTrack_l(const sp<RecordTrack>& track)
{
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index eb29497..53cb8ad 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -1398,6 +1398,8 @@
// Sets the UID records silence
void setRecordSilenced(uid_t uid, bool silenced);
+ status_t getActiveMicrophones(std::vector<media::MicrophoneInfo>* activeMicrophones);
+
private:
// Enter standby if not already in standby, and set mStandby flag
void standbyIfNotAlreadyInStandby();
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index 06bbf1e..67f27d0 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -1580,6 +1580,13 @@
mRecordTrack->stop();
}
+binder::Status AudioFlinger::RecordHandle::getActiveMicrophones(
+ std::vector<media::MicrophoneInfo>* activeMicrophones) {
+ ALOGV("RecordHandle::getActiveMicrophones()");
+ return binder::Status::fromStatusT(
+ mRecordTrack->getActiveMicrophones(activeMicrophones));
+}
+
// ----------------------------------------------------------------------------
// RecordTrack constructor must be called with AudioFlinger::mLock and ThreadBase::mLock held
@@ -1792,6 +1799,18 @@
mServerProxy->setTimestamp(local);
}
+status_t AudioFlinger::RecordThread::RecordTrack::getActiveMicrophones(
+ std::vector<media::MicrophoneInfo>* activeMicrophones)
+{
+ sp<ThreadBase> thread = mThread.promote();
+ if (thread != 0) {
+ RecordThread *recordThread = (RecordThread *)thread.get();
+ return recordThread->getActiveMicrophones(activeMicrophones);
+ } else {
+ return BAD_VALUE;
+ }
+}
+
AudioFlinger::RecordThread::PatchRecord::PatchRecord(RecordThread *recordThread,
uint32_t sampleRate,
audio_channel_mask_t channelMask,