Add interface to query the mmap support.
Currently, the mmap support is defined in system property. But the
system property only indicates if the mmap is supported or not. It
doesn't indicate on which device mmap is supported. In that case, adding
an interface to query the mmap support can help make things clear.
Test: atest AAudioTests
Test: Run OboeTester TEST OUTPUT
Test: Verify that MMAP is showed as enabled if supported
Test: Try toggling MMAP on and off when opening streams
Bug: 193275465
Change-Id: Iac289c1a02e6e2ab4076ab6f2b5045efecad97ac
diff --git a/services/audioflinger/Android.bp b/services/audioflinger/Android.bp
index ea85d04..f401fff 100644
--- a/services/audioflinger/Android.bp
+++ b/services/audioflinger/Android.bp
@@ -41,6 +41,7 @@
"FastThreadState.cpp",
"NBAIO_Tee.cpp",
"PatchPanel.cpp",
+ "PropertyUtils.cpp",
"SpdifStreamOut.cpp",
"StateQueue.cpp",
"Threads.cpp",
@@ -92,6 +93,7 @@
],
header_libs: [
+ "libaaudio_headers",
"libaudioclient_headers",
"libaudiohal_headers",
"libmedia_headers",
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 1bfacd5..c8d753b 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -57,6 +57,7 @@
#include "AudioFlinger.h"
#include "NBAIO_Tee.h"
+#include "PropertyUtils.h"
#include <media/AudioResamplerPublic.h>
@@ -335,6 +336,36 @@
return NO_ERROR;
}
+#define MAX_MMAP_PROPERTY_DEVICE_HAL_VERSION 7.0
+
+status_t AudioFlinger::getMmapPolicyInfos(
+ media::AudioMMapPolicyType policyType,
+ std::vector<media::AudioMMapPolicyInfo> *policyInfos) {
+ if (const auto it = mPolicyInfos.find(policyType); it != mPolicyInfos.end()) {
+ *policyInfos = it->second;
+ return NO_ERROR;
+ }
+ if (mDevicesFactoryHal->getHalVersion() > MAX_MMAP_PROPERTY_DEVICE_HAL_VERSION) {
+ AutoMutex lock(mHardwareLock);
+ for (size_t i = 0; i < mAudioHwDevs.size(); ++i) {
+ AudioHwDevice *dev = mAudioHwDevs.valueAt(i);
+ std::vector<media::AudioMMapPolicyInfo> infos;
+ status_t status = dev->getMmapPolicyInfos(policyType, &infos);
+ if (status != NO_ERROR) {
+ ALOGE("Failed to query mmap policy info of %d, error %d",
+ mAudioHwDevs.keyAt(i), status);
+ continue;
+ }
+ policyInfos->insert(policyInfos->end(), infos.begin(), infos.end());
+ }
+ mPolicyInfos[policyType] = *policyInfos;
+ } else {
+ getMmapPolicyInfosFromSystemProperty(policyType, policyInfos);
+ mPolicyInfos[policyType] = *policyInfos;
+ }
+ return NO_ERROR;
+}
+
// getDefaultVibratorInfo_l must be called with AudioFlinger lock held.
std::optional<media::AudioVibratorInfo> AudioFlinger::getDefaultVibratorInfo_l() {
if (mAudioVibratorInfos.empty()) {
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index d6bf0ae..b5d587b 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -282,6 +282,10 @@
virtual status_t updateSecondaryOutputs(
const TrackSecondaryOutputsMap& trackSecondaryOutputs);
+ virtual status_t getMmapPolicyInfos(
+ media::AudioMMapPolicyType policyType,
+ std::vector<media::AudioMMapPolicyInfo> *policyInfos);
+
status_t onTransactWrapper(TransactionCode code, const Parcel& data, uint32_t flags,
const std::function<status_t()>& delegate) override;
@@ -1004,6 +1008,8 @@
// Keep in sync with java definition in media/java/android/media/AudioRecord.java
static constexpr int32_t kMaxSharedAudioHistoryMs = 5000;
+
+ std::map<media::AudioMMapPolicyType, std::vector<media::AudioMMapPolicyInfo>> mPolicyInfos;
};
#undef INCLUDING_FROM_AUDIOFLINGER_H
diff --git a/services/audioflinger/AudioHwDevice.cpp b/services/audioflinger/AudioHwDevice.cpp
index 16b25f6..b996c6c9 100644
--- a/services/audioflinger/AudioHwDevice.cpp
+++ b/services/audioflinger/AudioHwDevice.cpp
@@ -103,4 +103,12 @@
}
+
+status_t AudioHwDevice::getMmapPolicyInfos(
+ media::AudioMMapPolicyType policyType,
+ std::vector<media::AudioMMapPolicyInfo> *policyInfos) const {
+ return mHwDevice->getMmapPolicyInfos(policyType, policyInfos);
+}
+
+
}; // namespace android
diff --git a/services/audioflinger/AudioHwDevice.h b/services/audioflinger/AudioHwDevice.h
index fc2c693..b72072f 100644
--- a/services/audioflinger/AudioHwDevice.h
+++ b/services/audioflinger/AudioHwDevice.h
@@ -85,6 +85,10 @@
status_t getAudioPort(struct audio_port_v7 *port) const;
+ status_t getMmapPolicyInfos(
+ media::AudioMMapPolicyType policyType,
+ std::vector<media::AudioMMapPolicyInfo> *policyInfos) const;
+
private:
const audio_module_handle_t mHandle;
const char * const mModuleName;
diff --git a/services/audioflinger/PropertyUtils.cpp b/services/audioflinger/PropertyUtils.cpp
new file mode 100644
index 0000000..b8abb8e
--- /dev/null
+++ b/services/audioflinger/PropertyUtils.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <aaudio/AAudio.h>
+#include <aaudio/AAudioTesting.h>
+#include <android/media/AudioMMapPolicy.h>
+#include <cutils/properties.h>
+
+#include "PropertyUtils.h"
+
+namespace android {
+
+std::string getMmapPolicyProperty(media::AudioMMapPolicyType policyType) {
+ switch (policyType) {
+ case media::AudioMMapPolicyType::DEFAULT:
+ return "aaudio.mmap_policy";
+ case media::AudioMMapPolicyType::EXCLUSIVE:
+ return "aaudio.mmap_exclusive_policy";
+ default:
+ return "";
+ }
+}
+
+int getDefaultPolicyFromType(media::AudioMMapPolicyType policyType) {
+ switch (policyType) {
+ case media::AudioMMapPolicyType::EXCLUSIVE:
+ return AAUDIO_UNSPECIFIED;
+ case media::AudioMMapPolicyType::DEFAULT:
+ default:
+ return AAUDIO_POLICY_NEVER;
+ }
+}
+
+media::AudioMMapPolicy legacy2aidl_aaudio_policy_t_AudioMMapPolicy(aaudio_policy_t legacy) {
+ switch (legacy) {
+ case AAUDIO_POLICY_NEVER:
+ return media::AudioMMapPolicy::NEVER;
+ case AAUDIO_POLICY_AUTO:
+ return media::AudioMMapPolicy::AUTO;
+ case AAUDIO_POLICY_ALWAYS:
+ return media::AudioMMapPolicy::ALWAYS;
+ case AAUDIO_UNSPECIFIED:
+ return media::AudioMMapPolicy::UNSPECIFIED;
+ default:
+ ALOGE("%s unknown aaudio policy: %d", __func__, legacy);
+ return media::AudioMMapPolicy::UNSPECIFIED;
+ }
+}
+
+status_t getMmapPolicyInfosFromSystemProperty(
+ media::AudioMMapPolicyType policyType,
+ std::vector<media::AudioMMapPolicyInfo> *policyInfos) {
+ media::AudioMMapPolicyInfo policyInfo;
+ const std::string propertyStr = getMmapPolicyProperty(policyType);
+ if (propertyStr.empty()) {
+ return BAD_VALUE;
+ }
+ policyInfo.mmapPolicy = legacy2aidl_aaudio_policy_t_AudioMMapPolicy(
+ property_get_int32(propertyStr.c_str(), getDefaultPolicyFromType(policyType)));
+ policyInfos->push_back(policyInfo);
+ return NO_ERROR;
+}
+
+} // namespace android
diff --git a/services/audioflinger/PropertyUtils.h b/services/audioflinger/PropertyUtils.h
new file mode 100644
index 0000000..38cbf92
--- /dev/null
+++ b/services/audioflinger/PropertyUtils.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <android/media/AudioMMapPolicyType.h>
+#include <android/media/AudioMMapPolicyInfo.h>
+
+namespace android {
+
+status_t getMmapPolicyInfosFromSystemProperty(
+ media::AudioMMapPolicyType policyType,
+ std::vector<media::AudioMMapPolicyInfo> *policyInfos);
+
+} // namespace android