AudioFlinger: remove float and multichannel shim for AIDL
Test: Validate AudioEffects with AIDL mode on and off.
Test: atest android.media.audio.cts.AudioEffectTest \
android.media.audio.cts.AudioPreProcessingTest \
android.media.audio.cts.BassBoostTest \
android.media.audio.cts.EnvReverbTest \
android.media.audio.cts.EqualizerTest \
android.media.audio.cts.LoudnessEnhancerTest \
android.media.audio.cts.PresetReverbTest \
android.media.audio.cts.VirtualizerTest \
android.media.audio.cts.VisualizerTest
Bug: 282066693
Change-Id: I08ab707f56d4e7c445306dc1532e887bbbb276c7
diff --git a/media/libaudiohal/include/media/audiohal/AudioHalVersionInfo.h b/media/libaudiohal/include/media/audiohal/AudioHalVersionInfo.h
index 6e09463..2323ed6 100644
--- a/media/libaudiohal/include/media/audiohal/AudioHalVersionInfo.h
+++ b/media/libaudiohal/include/media/audiohal/AudioHalVersionInfo.h
@@ -30,6 +30,8 @@
minor = halMinor;
}
+ bool isHidl() const { return type == Type::HIDL; }
+
Type getType() const { return type; }
int getMajorVersion() const { return major; }
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index ab197f8..5fcc302 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -58,6 +58,7 @@
#include <audiomanager/IAudioManager.h>
#include "AudioFlinger.h"
+#include "EffectConfiguration.h"
#include "NBAIO_Tee.h"
#include "PropertyUtils.h"
@@ -372,7 +373,7 @@
BatteryNotifier::getInstance().noteResetAudio();
mDevicesFactoryHal = DevicesFactoryHalInterface::create();
- mEffectsFactoryHal = EffectsFactoryHalInterface::create();
+ mEffectsFactoryHal = audioflinger::EffectConfiguration::getEffectsFactoryHal();
mMediaLogNotifier->run("MediaLogNotifier");
std::vector<pid_t> halPids;
diff --git a/services/audioflinger/DeviceEffectManager.cpp b/services/audioflinger/DeviceEffectManager.cpp
index 2f61a01..4fb6138 100644
--- a/services/audioflinger/DeviceEffectManager.cpp
+++ b/services/audioflinger/DeviceEffectManager.cpp
@@ -23,6 +23,7 @@
#include <audio_utils/primitives.h>
#include "AudioFlinger.h"
+#include "EffectConfiguration.h"
#include <media/audiohal/EffectsFactoryHalInterface.h>
// ----------------------------------------------------------------------------
@@ -111,14 +112,16 @@
status_t AudioFlinger::DeviceEffectManager::checkEffectCompatibility(
const effect_descriptor_t *desc) {
- sp<EffectsFactoryHalInterface> effectsFactory = mAudioFlinger.getEffectsFactory();
+ const sp<EffectsFactoryHalInterface> effectsFactory =
+ audioflinger::EffectConfiguration::getEffectsFactoryHal();
if (effectsFactory == nullptr) {
return BAD_VALUE;
}
- static AudioHalVersionInfo sMinDeviceEffectHalVersion =
+ static const AudioHalVersionInfo sMinDeviceEffectHalVersion =
AudioHalVersionInfo(AudioHalVersionInfo::Type::HIDL, 6, 0);
- AudioHalVersionInfo halVersion = effectsFactory->getHalVersion();
+ static const AudioHalVersionInfo halVersion =
+ audioflinger::EffectConfiguration::getAudioHalVersionInfo();
// We can trust AIDL generated AudioHalVersionInfo comparison operator (based on std::tie) as
// long as the type, major and minor sequence doesn't change in the definition.
@@ -137,7 +140,8 @@
const effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t deviceId,
sp<EffectHalInterface> *effect) {
status_t status = NO_INIT;
- sp<EffectsFactoryHalInterface> effectsFactory = mAudioFlinger.getEffectsFactory();
+ const sp<EffectsFactoryHalInterface> effectsFactory =
+ audioflinger::EffectConfiguration::getEffectsFactoryHal();
if (effectsFactory != 0) {
status = effectsFactory->createEffect(
pEffectUuid, sessionId, AUDIO_IO_HANDLE_NONE, deviceId, effect);
diff --git a/services/audioflinger/EffectConfiguration.h b/services/audioflinger/EffectConfiguration.h
new file mode 100644
index 0000000..2f07fa2
--- /dev/null
+++ b/services/audioflinger/EffectConfiguration.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2023 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 <media/audiohal/EffectsFactoryHalInterface.h>
+
+namespace android::audioflinger {
+
+/**
+ * Effect Configuration abstraction and helper class.
+ */
+class EffectConfiguration {
+public:
+ static bool isHidl() {
+ static const bool isHidl = getAudioHalVersionInfo().isHidl();
+ return isHidl;
+ }
+
+ static const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() {
+ static const auto effectsFactoryHal = EffectsFactoryHalInterface::create();
+ return effectsFactoryHal;
+ }
+
+ static const detail::AudioHalVersionInfo& getAudioHalVersionInfo() {
+ static const auto audioHalVersionInfo = getEffectsFactoryHal() ?
+ getEffectsFactoryHal()->getHalVersion() : detail::AudioHalVersionInfo{
+ detail::AudioHalVersionInfo::Type::HIDL, 0 /* major */, 0 /* minor */ };
+ return audioHalVersionInfo;
+ }
+};
+
+} // namespace android::audioflinger
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index f324408..39feec4 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -44,6 +44,7 @@
#include <mediautils/TimeCheck.h>
#include "AudioFlinger.h"
+#include "EffectConfiguration.h"
// ----------------------------------------------------------------------------
@@ -65,6 +66,7 @@
namespace android {
using aidl_utils::statusTFromBinderStatus;
+using audioflinger::EffectConfiguration;
using binder::Status;
namespace {
@@ -982,6 +984,7 @@
#ifdef MULTICHANNEL_EFFECT_CHAIN
if (status != NO_ERROR &&
+ EffectConfiguration::isHidl() && // only HIDL effects support channel conversion
mIsOutput &&
(mConfig.inputCfg.channels != AUDIO_CHANNEL_OUT_STEREO
|| mConfig.outputCfg.channels != AUDIO_CHANNEL_OUT_STEREO)) {
@@ -1012,7 +1015,8 @@
mSupportsFloat = true;
}
- if (status != NO_ERROR) {
+ // only HIDL effects support integer conversion.
+ if (status != NO_ERROR && EffectConfiguration::isHidl()) {
ALOGV("EFFECT_CMD_SET_CONFIG failed with float format, retry with int16_t.");
mConfig.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
mConfig.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
@@ -3032,7 +3036,8 @@
const effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t deviceId,
sp<EffectHalInterface> *effect) {
status_t status = NO_INIT;
- sp<EffectsFactoryHalInterface> effectsFactory = mAudioFlinger.getEffectsFactory();
+ const sp<EffectsFactoryHalInterface> effectsFactory =
+ EffectConfiguration::getEffectsFactoryHal();
if (effectsFactory != 0) {
status = effectsFactory->createEffect(pEffectUuid, sessionId, io(), deviceId, effect);
}