Revert "Move EffectsConfig loading in AudioPolicyEffects to libAudioHal"
This reverts commit e3e403d4598c5460baffeba766f469eceafd91e5.
Reason for revert: fixes b/279127394 validated by http://go/abtd-run/L71300000960106239 and b/279108570
Change-Id: I58054d98365a6bf10b4dab2f347d4ee78205440c
diff --git a/services/audiopolicy/service/AudioPolicyEffects.cpp b/services/audiopolicy/service/AudioPolicyEffects.cpp
index b0eb3b7..c7a60c2 100644
--- a/services/audiopolicy/service/AudioPolicyEffects.cpp
+++ b/services/audiopolicy/service/AudioPolicyEffects.cpp
@@ -41,25 +41,26 @@
// AudioPolicyEffects Implementation
// ----------------------------------------------------------------------------
-AudioPolicyEffects::AudioPolicyEffects(const sp<EffectsFactoryHalInterface>& effectsFactoryHal) {
- // load xml config with effectsFactoryHal
- status_t loadResult = loadAudioEffectConfig(effectsFactoryHal);
+AudioPolicyEffects::AudioPolicyEffects()
+{
+ status_t loadResult = loadAudioEffectXmlConfig();
if (loadResult == NO_ERROR) {
- mDefaultDeviceEffectFuture =
- std::async(std::launch::async, &AudioPolicyEffects::initDefaultDeviceEffects, this);
+ mDefaultDeviceEffectFuture = std::async(
+ std::launch::async, &AudioPolicyEffects::initDefaultDeviceEffects, this);
} else if (loadResult < 0) {
- ALOGW("Failed to query effect configuration, fallback to load .conf");
+ ALOGW("Failed to load XML effect configuration, fallback to .conf");
// load automatic audio effect modules
if (access(AUDIO_EFFECT_VENDOR_CONFIG_FILE, R_OK) == 0) {
- loadAudioEffectConfigLegacy(AUDIO_EFFECT_VENDOR_CONFIG_FILE);
+ loadAudioEffectConfig(AUDIO_EFFECT_VENDOR_CONFIG_FILE);
} else if (access(AUDIO_EFFECT_DEFAULT_CONFIG_FILE, R_OK) == 0) {
- loadAudioEffectConfigLegacy(AUDIO_EFFECT_DEFAULT_CONFIG_FILE);
+ loadAudioEffectConfig(AUDIO_EFFECT_DEFAULT_CONFIG_FILE);
}
} else if (loadResult > 0) {
ALOGE("Effect config is partially invalid, skipped %d elements", loadResult);
}
}
+
AudioPolicyEffects::~AudioPolicyEffects()
{
size_t i = 0;
@@ -906,16 +907,12 @@
return NO_ERROR;
}
-status_t AudioPolicyEffects::loadAudioEffectConfig(
- const sp<EffectsFactoryHalInterface>& effectsFactoryHal) {
- if (!effectsFactoryHal) {
- ALOGE("%s Null EffectsFactoryHalInterface", __func__);
- return UNEXPECTED_NULL;
+status_t AudioPolicyEffects::loadAudioEffectXmlConfig() {
+ auto result = effectsConfig::parse();
+ if (result.parsedConfig == nullptr) {
+ return -ENOENT;
}
- const auto& processings = effectsFactoryHal->getProcessings();
- const auto& skippedElements = VALUE_OR_RETURN_STATUS(processings.result);
-
auto loadProcessingChain = [](auto& processingChain, auto& streams) {
for (auto& stream : processingChain) {
auto effectDescs = std::make_unique<EffectDescVector>();
@@ -927,8 +924,9 @@
}
};
- auto loadDeviceProcessingChain = [](auto& processingChain, auto& devicesEffects) {
+ auto loadDeviceProcessingChain = [](auto &processingChain, auto& devicesEffects) {
for (auto& deviceProcess : processingChain) {
+
auto effectDescs = std::make_unique<EffectDescVector>();
for (auto& effect : deviceProcess.effects) {
effectDescs->mEffects.add(
@@ -940,18 +938,17 @@
}
};
- loadProcessingChain(processings.preprocess, mInputSources);
- loadProcessingChain(processings.postprocess, mOutputStreams);
-
+ loadProcessingChain(result.parsedConfig->preprocess, mInputSources);
+ loadProcessingChain(result.parsedConfig->postprocess, mOutputStreams);
{
Mutex::Autolock _l(mLock);
- loadDeviceProcessingChain(processings.deviceprocess, mDeviceEffects);
+ loadDeviceProcessingChain(result.parsedConfig->deviceprocess, mDeviceEffects);
}
-
- return skippedElements;
+ // Casting from ssize_t to status_t is probably safe, there should not be more than 2^31 errors
+ return result.nbSkippedElement;
}
-status_t AudioPolicyEffects::loadAudioEffectConfigLegacy(const char *path)
+status_t AudioPolicyEffects::loadAudioEffectConfig(const char *path)
{
cnode *root;
char *data;
diff --git a/services/audiopolicy/service/AudioPolicyEffects.h b/services/audiopolicy/service/AudioPolicyEffects.h
index 6ed11f1..13d5d0c 100644
--- a/services/audiopolicy/service/AudioPolicyEffects.h
+++ b/services/audiopolicy/service/AudioPolicyEffects.h
@@ -20,33 +20,22 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <future>
-
-#include <android-base/thread_annotations.h>
#include <cutils/misc.h>
#include <media/AudioEffect.h>
-#include <media/audiohal/EffectsFactoryHalInterface.h>
#include <system/audio.h>
#include <utils/Vector.h>
#include <utils/SortedVector.h>
+#include <android-base/thread_annotations.h>
+
+#include <future>
namespace android {
// ----------------------------------------------------------------------------
-/**
- * AudioPolicyEffects class.
- *
- * This class manages all effects attached to input and output streams in AudioPolicyService.
- * The effect configurations caa be queried in several ways:
- *
- * With HIDL HAL, the configuration file `audio_effects.xml` will be loaded by libAudioHal. If this
- * file does not exist, AudioPolicyEffects class will fallback to load configuration from
- * `/vendor/etc/audio_effects.conf` (AUDIO_EFFECT_VENDOR_CONFIG_FILE). If this file also does not
- * exist, the configuration will be loaded from the file `/system/etc/audio_effects.conf`.
- *
- * With AIDL HAL, the configuration will be queried with the method `IFactory::queryProcessing()`.
- */
+// AudioPolicyEffects class
+// This class will manage all effects attached to input and output streams in
+// AudioPolicyService as configured in audio_effects.conf.
class AudioPolicyEffects : public RefBase
{
@@ -55,7 +44,7 @@
// The constructor will parse audio_effects.conf
// First it will look whether vendor specific file exists,
// otherwise it will parse the system default file.
- AudioPolicyEffects(const sp<EffectsFactoryHalInterface>& effectsFactoryHal);
+ AudioPolicyEffects();
virtual ~AudioPolicyEffects();
// NOTE: methods on AudioPolicyEffects should never be called with the AudioPolicyService
@@ -229,6 +218,7 @@
};
+
static const char * const kInputSourceNames[AUDIO_SOURCE_CNT -1];
static audio_source_t inputSourceNameToEnum(const char *name);
@@ -236,8 +226,8 @@
audio_stream_type_t streamNameToEnum(const char *name);
// Parse audio_effects.conf
- status_t loadAudioEffectConfigLegacy(const char *path);
- status_t loadAudioEffectConfig(const sp<EffectsFactoryHalInterface>& effectsFactoryHal);
+ status_t loadAudioEffectConfig(const char *path); // TODO: add legacy in the name
+ status_t loadAudioEffectXmlConfig(); // TODO: remove "Xml" in the name
// Load all effects descriptors in configuration file
status_t loadEffects(cnode *root, Vector <EffectDesc *>& effects);
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index 0df3962..f34427c 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -460,14 +460,14 @@
}
ALOGV("startOutput()");
sp<AudioPlaybackClient> client;
- sp<AudioPolicyEffects> audioPolicyEffects;
+ sp<AudioPolicyEffects>audioPolicyEffects;
getPlaybackClientAndEffects(portId, client, audioPolicyEffects, __func__);
if (audioPolicyEffects != 0) {
// create audio processors according to stream
- status_t status = audioPolicyEffects->addOutputSessionEffects(client->io, client->stream,
- client->session);
+ status_t status = audioPolicyEffects->addOutputSessionEffects(
+ client->io, client->stream, client->session);
if (status != NO_ERROR && status != ALREADY_EXISTS) {
ALOGW("Failed to add effects on session %d", client->session);
}
diff --git a/services/audiopolicy/service/AudioPolicyService.cpp b/services/audiopolicy/service/AudioPolicyService.cpp
index 040f869..281785e 100644
--- a/services/audiopolicy/service/AudioPolicyService.cpp
+++ b/services/audiopolicy/service/AudioPolicyService.cpp
@@ -252,8 +252,7 @@
}
// load audio processing modules
- const sp<EffectsFactoryHalInterface> effectsFactoryHal = EffectsFactoryHalInterface::create();
- sp<AudioPolicyEffects> audioPolicyEffects = new AudioPolicyEffects(effectsFactoryHal);
+ sp<AudioPolicyEffects> audioPolicyEffects = new AudioPolicyEffects();
sp<UidPolicy> uidPolicy = new UidPolicy(this);
sp<SensorPrivacyPolicy> sensorPrivacyPolicy = new SensorPrivacyPolicy(this);
{
@@ -272,7 +271,7 @@
AudioDeviceTypeAddrVector devices;
bool hasSpatializer = mAudioPolicyManager->canBeSpatialized(&attr, nullptr, devices);
if (hasSpatializer) {
- mSpatializer = Spatializer::create(this, effectsFactoryHal);
+ mSpatializer = Spatializer::create(this);
}
if (mSpatializer == nullptr) {
// No spatializer created, signal the reason: NO_INIT a failure, OK means intended.
diff --git a/services/audiopolicy/service/Spatializer.cpp b/services/audiopolicy/service/Spatializer.cpp
index f0d5274..5db82f7 100644
--- a/services/audiopolicy/service/Spatializer.cpp
+++ b/services/audiopolicy/service/Spatializer.cpp
@@ -30,6 +30,7 @@
#include <audio_utils/fixedfft.h>
#include <cutils/bitops.h>
#include <hardware/sensors.h>
+#include <media/audiohal/EffectsFactoryHalInterface.h>
#include <media/stagefright/foundation/AHandler.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/MediaMetricsItem.h>
@@ -214,17 +215,18 @@
};
// ---------------------------------------------------------------------------
-sp<Spatializer> Spatializer::create(SpatializerPolicyCallback* callback,
- const sp<EffectsFactoryHalInterface>& effectsFactoryHal) {
+sp<Spatializer> Spatializer::create(SpatializerPolicyCallback *callback) {
sp<Spatializer> spatializer;
+ sp<EffectsFactoryHalInterface> effectsFactoryHal = EffectsFactoryHalInterface::create();
if (effectsFactoryHal == nullptr) {
ALOGW("%s failed to create effect factory interface", __func__);
return spatializer;
}
std::vector<effect_descriptor_t> descriptors;
- status_t status = effectsFactoryHal->getDescriptors(FX_IID_SPATIALIZER, &descriptors);
+ status_t status =
+ effectsFactoryHal->getDescriptors(FX_IID_SPATIALIZER, &descriptors);
if (status != NO_ERROR) {
ALOGW("%s failed to get spatializer descriptor, error %d", __func__, status);
return spatializer;
diff --git a/services/audiopolicy/service/Spatializer.h b/services/audiopolicy/service/Spatializer.h
index a657b7f..60030bd 100644
--- a/services/audiopolicy/service/Spatializer.h
+++ b/services/audiopolicy/service/Spatializer.h
@@ -27,7 +27,6 @@
#include <audio_utils/SimpleLog.h>
#include <math.h>
#include <media/AudioEffect.h>
-#include <media/audiohal/EffectsFactoryHalInterface.h>
#include <media/VectorRecorder.h>
#include <media/audiohal/EffectHalInterface.h>
#include <media/stagefright/foundation/ALooper.h>
@@ -95,8 +94,7 @@
private SpatializerPoseController::Listener,
public virtual AudioSystem::SupportedLatencyModesCallback {
public:
- static sp<Spatializer> create(SpatializerPolicyCallback* callback,
- const sp<EffectsFactoryHalInterface>& effectsFactoryHal);
+ static sp<Spatializer> create(SpatializerPolicyCallback *callback);
~Spatializer() override;