Implement AIDL effect IFacotry::queryProcessing
Bug: 281572768
Test: atest --test-mapping hardware/interfaces/audio/aidl/vts:presubmit
Change-Id: I0166786d531437ef52690b92067766879b043a1d
Merged-In: I0166786d531437ef52690b92067766879b043a1d
diff --git a/audio/aidl/default/EffectConfig.cpp b/audio/aidl/default/EffectConfig.cpp
index 5a83fef..71d111b 100644
--- a/audio/aidl/default/EffectConfig.cpp
+++ b/audio/aidl/default/EffectConfig.cpp
@@ -14,12 +14,17 @@
* limitations under the License.
*/
+#include <optional>
+#include <string>
#define LOG_TAG "AHAL_EffectConfig"
#include <android-base/logging.h>
+#include <system/audio_effects/audio_effects_conf.h>
#include <system/audio_effects/effect_uuid.h>
#include "effectFactory-impl/EffectConfig.h"
+using aidl::android::media::audio::common::AudioSource;
+using aidl::android::media::audio::common::AudioStreamType;
using aidl::android::media::audio::common::AudioUuid;
namespace aidl::android::hardware::audio::effect {
@@ -55,14 +60,16 @@
// Parse pre processing chains
for (auto& xmlPreprocess : getChildren(xmlConfig, "preprocess")) {
for (auto& xmlStream : getChildren(xmlPreprocess, "stream")) {
- registerFailure(parseStream(xmlStream));
+ // AudioSource
+ registerFailure(parseProcessing(Processing::Type::source, xmlStream));
}
}
// Parse post processing chains
for (auto& xmlPostprocess : getChildren(xmlConfig, "postprocess")) {
for (auto& xmlStream : getChildren(xmlPostprocess, "stream")) {
- registerFailure(parseStream(xmlStream));
+ // AudioStreamType
+ registerFailure(parseProcessing(Processing::Type::streamType, xmlStream));
}
}
}
@@ -140,21 +147,6 @@
return true;
}
-bool EffectConfig::parseStream(const tinyxml2::XMLElement& xml) {
- LOG(DEBUG) << __func__ << dump(xml);
- const char* type = xml.Attribute("type");
- RETURN_VALUE_IF(!type, false, "noTypeInProcess");
- RETURN_VALUE_IF(0 != mProcessingMap.count(type), false, "duplicateType");
-
- for (auto& apply : getChildren(xml, "apply")) {
- const char* name = apply.get().Attribute("effect");
- RETURN_VALUE_IF(!name, false, "noEffectAttribute");
- mProcessingMap[type].push_back(name);
- LOG(DEBUG) << __func__ << " " << type << " : " << name;
- }
- return true;
-}
-
bool EffectConfig::parseLibraryUuid(const tinyxml2::XMLElement& xml,
struct LibraryUuid& libraryUuid, bool isProxy) {
// Retrieve library name only if not effectProxy element
@@ -174,6 +166,80 @@
return true;
}
+std::optional<Processing::Type> EffectConfig::stringToProcessingType(Processing::Type::Tag typeTag,
+ const std::string& type) {
+ // see list of audio stream types in audio_stream_type_t:
+ // system/media/audio/include/system/audio_effects/audio_effects_conf.h
+ // AUDIO_STREAM_DEFAULT_TAG is not listed here because according to SYS_RESERVED_DEFAULT in
+ // AudioStreamType.aidl: "Value reserved for system use only. HALs must never return this value
+ // to the system or accept it from the system".
+ static const std::map<const std::string, AudioStreamType> sAudioStreamTypeTable = {
+ {AUDIO_STREAM_VOICE_CALL_TAG, AudioStreamType::VOICE_CALL},
+ {AUDIO_STREAM_SYSTEM_TAG, AudioStreamType::SYSTEM},
+ {AUDIO_STREAM_RING_TAG, AudioStreamType::RING},
+ {AUDIO_STREAM_MUSIC_TAG, AudioStreamType::MUSIC},
+ {AUDIO_STREAM_ALARM_TAG, AudioStreamType::ALARM},
+ {AUDIO_STREAM_NOTIFICATION_TAG, AudioStreamType::NOTIFICATION},
+ {AUDIO_STREAM_BLUETOOTH_SCO_TAG, AudioStreamType::BLUETOOTH_SCO},
+ {AUDIO_STREAM_ENFORCED_AUDIBLE_TAG, AudioStreamType::ENFORCED_AUDIBLE},
+ {AUDIO_STREAM_DTMF_TAG, AudioStreamType::DTMF},
+ {AUDIO_STREAM_TTS_TAG, AudioStreamType::TTS},
+ {AUDIO_STREAM_ASSISTANT_TAG, AudioStreamType::ASSISTANT}};
+
+ // see list of audio sources in audio_source_t:
+ // system/media/audio/include/system/audio_effects/audio_effects_conf.h
+ static const std::map<const std::string, AudioSource> sAudioSourceTable = {
+ {MIC_SRC_TAG, AudioSource::VOICE_CALL},
+ {VOICE_UL_SRC_TAG, AudioSource::VOICE_CALL},
+ {VOICE_DL_SRC_TAG, AudioSource::VOICE_CALL},
+ {VOICE_CALL_SRC_TAG, AudioSource::VOICE_CALL},
+ {CAMCORDER_SRC_TAG, AudioSource::VOICE_CALL},
+ {VOICE_REC_SRC_TAG, AudioSource::VOICE_CALL},
+ {VOICE_COMM_SRC_TAG, AudioSource::VOICE_CALL},
+ {REMOTE_SUBMIX_SRC_TAG, AudioSource::VOICE_CALL},
+ {UNPROCESSED_SRC_TAG, AudioSource::VOICE_CALL},
+ {VOICE_PERFORMANCE_SRC_TAG, AudioSource::VOICE_CALL}};
+
+ if (typeTag == Processing::Type::streamType) {
+ auto typeIter = sAudioStreamTypeTable.find(type);
+ if (typeIter != sAudioStreamTypeTable.end()) {
+ return typeIter->second;
+ }
+ } else if (typeTag == Processing::Type::source) {
+ auto typeIter = sAudioSourceTable.find(type);
+ if (typeIter != sAudioSourceTable.end()) {
+ return typeIter->second;
+ }
+ }
+
+ return std::nullopt;
+}
+
+bool EffectConfig::parseProcessing(Processing::Type::Tag typeTag, const tinyxml2::XMLElement& xml) {
+ LOG(DEBUG) << __func__ << dump(xml);
+ const char* typeStr = xml.Attribute("type");
+ auto aidlType = stringToProcessingType(typeTag, typeStr);
+ RETURN_VALUE_IF(!aidlType.has_value(), false, "illegalStreamType");
+ RETURN_VALUE_IF(0 != mProcessingMap.count(aidlType.value()), false, "duplicateStreamType");
+
+ for (auto& apply : getChildren(xml, "apply")) {
+ const char* name = apply.get().Attribute("effect");
+ if (mEffectsMap.find(name) == mEffectsMap.end()) {
+ LOG(ERROR) << __func__ << " effect " << name << " doesn't exist, skipping";
+ continue;
+ }
+ RETURN_VALUE_IF(!name, false, "noEffectAttribute");
+ mProcessingMap[aidlType.value()].emplace_back(mEffectsMap[name]);
+ LOG(WARNING) << __func__ << " " << typeStr << " : " << name;
+ }
+ return true;
+}
+
+const std::map<Processing::Type, std::vector<EffectConfig::EffectLibraries>>&
+EffectConfig::getProcessingMap() const {
+ return mProcessingMap;
+}
+
bool EffectConfig::findUuid(const std::string& xmlEffectName, AudioUuid* uuid) {
// Difference from EFFECT_TYPE_LIST_DEF, there could be multiple name mapping to same Effect Type
#define EFFECT_XML_TYPE_LIST_DEF(V) \