Support effect config parser in effect AIDL
Bug: 255361653
Test: parse an example audio_effects.xml
atest VtsHalAudioEffectFactoryTargetTest
atest VtsHalAudioEffectTargetTest
atest VtsHalEqualizerTargetTest
Change-Id: I086905bcbe113a56767cae45102c84f5250d348e
diff --git a/audio/aidl/default/include/effect-impl/EffectTypes.h b/audio/aidl/default/include/effect-impl/EffectTypes.h
index edce26b..fc6a01d 100644
--- a/audio/aidl/default/include/effect-impl/EffectTypes.h
+++ b/audio/aidl/default/include/effect-impl/EffectTypes.h
@@ -19,6 +19,7 @@
#include <string>
#include <aidl/android/hardware/audio/effect/BnEffect.h>
+#include <android-base/logging.h>
typedef binder_exception_t (*EffectCreateFunctor)(
const ::aidl::android::media::audio::common::AudioUuid*,
@@ -101,4 +102,23 @@
} \
} while (0)
+static inline bool stringToUuid(const char* str,
+ ::aidl::android::media::audio::common::AudioUuid* uuid) {
+ RETURN_VALUE_IF(!uuid || !str, false, "nullPtr");
+
+ uint32_t tmp[10];
+ if (sscanf(str, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", tmp, tmp + 1, tmp + 2, tmp + 3,
+ tmp + 4, tmp + 5, tmp + 6, tmp + 7, tmp + 8, tmp + 9) < 10) {
+ return false;
+ }
+
+ uuid->timeLow = (uint32_t)tmp[0];
+ uuid->timeMid = (uint16_t)tmp[1];
+ uuid->timeHiAndVersion = (uint16_t)tmp[2];
+ uuid->clockSeq = (uint16_t)tmp[3];
+ uuid->node.insert(uuid->node.end(), {(uint8_t)tmp[4], (uint8_t)tmp[5], (uint8_t)tmp[6],
+ (uint8_t)tmp[7], (uint8_t)tmp[8], (uint8_t)tmp[9]});
+ return true;
+}
+
} // namespace aidl::android::hardware::audio::effect
diff --git a/audio/aidl/default/include/effect-impl/EffectUUID.h b/audio/aidl/default/include/effect-impl/EffectUUID.h
index 767cf6c..184a587 100644
--- a/audio/aidl/default/include/effect-impl/EffectUUID.h
+++ b/audio/aidl/default/include/effect-impl/EffectUUID.h
@@ -15,6 +15,8 @@
*/
#pragma once
+#include <map>
+
#include <aidl/android/media/audio/common/AudioUuid.h>
namespace aidl::android::hardware::audio::effect {
@@ -39,14 +41,14 @@
0x8f34,
{0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
-// Equalizer implementation UUID.
+// 0bed4300-847d-11df-bb17-0002a5d5c51b
static const AudioUuid EqualizerSwImplUUID = {static_cast<int32_t>(0x0bed4300),
0x847d,
0x11df,
0xbb17,
{0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
-// Equalizer bundle implementation UUID.
+// ce772f20-847d-11df-bb17-0002a5d5c51b
static const AudioUuid EqualizerBundleImplUUID = {static_cast<int32_t>(0xce772f20),
0x847d,
0x11df,
@@ -166,4 +168,26 @@
0x9b6a,
{0x02, 0x42, 0xac, 0x12, 0x00, 0x02}};
+/**
+ * @brief A map between effect name and effect type UUID.
+ * All <name> attribution in effect/effectProxy of audio_effects.xml should be listed in this map.
+ * We need this map is because existing audio_effects.xml don't have a type UUID defined.
+ */
+static const std::map<const std::string /* effect type */, const AudioUuid&> kUuidNameTypeMap = {
+ {"bassboost", BassBoostTypeUUID},
+ {"downmix", DownmixTypeUUID},
+ {"dynamics_processing", DynamicsProcessingTypeUUID},
+ {"equalizer", EqualizerTypeUUID},
+ {"haptic_generator", HapticGeneratorTypeUUID},
+ {"loudness_enhancer", LoudnessEnhancerTypeUUID},
+ {"reverb", ReverbTypeUUID},
+ {"reverb_env_aux", ReverbTypeUUID},
+ {"reverb_env_ins", ReverbTypeUUID},
+ {"reverb_pre_aux", ReverbTypeUUID},
+ {"reverb_pre_ins", ReverbTypeUUID},
+ {"virtualizer", VirtualizerTypeUUID},
+ {"visualizer", VisualizerTypeUUID},
+ {"volume", VolumeTypeUUID},
+};
+
} // namespace aidl::android::hardware::audio::effect