From 817da7d0be9e4339bca67421940ef50b89ad72e3 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 8 Mar 2023 17:40:35 -0800 Subject: [PATCH] audio: Add vendor tags handling for AIDL Vendor tags are used in audio attributes and in source/sink metadata. The definition for vendor tag syntax is the same as it used to be in HIDL. Bug: 205884982 Bug: 272188499 Test: m Change-Id: Iffab15edaec10f0dfccff2512bbff9dff557725a --- audio/aidl/common/include/Utils.h | 13 +++++++++++++ audio/common/all-versions/default/HidlUtils.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/audio/aidl/common/include/Utils.h b/audio/aidl/common/include/Utils.h index d87bbd4934..32c36b85f2 100644 --- a/audio/aidl/common/include/Utils.h +++ b/audio/aidl/common/include/Utils.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -133,6 +134,18 @@ constexpr bool isValidAudioMode(::aidl::android::media::audio::common::AudioMode kValidAudioModes.end(); } +static inline bool maybeVendorExtension(const std::string& s) { + // Only checks whether the string starts with the "vendor prefix". + static const std::string vendorPrefix = "VX_"; + return s.size() > vendorPrefix.size() && s.substr(0, vendorPrefix.size()) == vendorPrefix; +} + +static inline bool isVendorExtension(const std::string& s) { + // Must be the same as defined in {Playback|Record}TrackMetadata.aidl + static const std::regex vendorExtension("VX_[A-Z0-9]{3,}_[_A-Z0-9]+"); + return std::regex_match(s.begin(), s.end(), vendorExtension); +} + // The helper functions defined below are only applicable to the case when an enum type // specifies zero-based bit positions, not bit masks themselves. This is why instantiation // is restricted to certain enum types. diff --git a/audio/common/all-versions/default/HidlUtils.h b/audio/common/all-versions/default/HidlUtils.h index ad9dee22c1..844a65117c 100644 --- a/audio/common/all-versions/default/HidlUtils.h +++ b/audio/common/all-versions/default/HidlUtils.h @@ -81,7 +81,7 @@ struct HidlUtils { #endif #if MAJOR_VERSION >= 7 - static constexpr char sAudioTagSeparator = ';'; + static constexpr char sAudioTagSeparator = AUDIO_ATTRIBUTES_TAGS_SEPARATOR; static status_t audioChannelMaskFromHal(audio_channel_mask_t halChannelMask, bool isInput, AudioChannelMask* channelMask);