diff options
author | Mikhail Naganov <mnaganov@google.com> | 2021-01-15 19:05:04 +0000 |
---|---|---|
committer | Mikhail Naganov <mnaganov@google.com> | 2021-02-02 18:17:26 +0000 |
commit | 5ec48c2d4d7a8ccdea489ad4b34a7cf75480ffcc (patch) | |
tree | e1458ca90fba3abd0f427da2f65fc0d52ecc5d35 /audio/common/all-versions/default/7.0/HidlUtils.cpp | |
parent | 4f5cb710b92fd58338630e2f54f03cac0468b3f8 (diff) |
audio: Create libraries for data types in core and effect
Add 'CoreUtils' library similar to 'HidlUtils' for the types
specific to the core HAL. Add 'EffectUtils' library similar to
'HidlUtils' for the types specific to the effects HAL. Move into
them and de-duplicate code previously scattered across the
default HAL implementation and libaudiohal. Add unit tests.
Removed 'AUDIO_{INPUT|OUTPUT}_FLAG_NONE' from the list of
values in the XSD file to avoid additional complexity due to
equivalence of this value to an empty list of flags.
Bug: 142480271
Test: m android.hardware.audio@X.0-impl
Test: m android.hardware.audio.effect@X.0-impl
Test: atest android.hardware.audio@7.0-util_tests
Test: atest android.hardware.audio.common@7.0-util_tests
Test: atest android.hardware.audio.effect@7.0-util_tests
Change-Id: I71a95cbe07fcc162dc6d74ff9665747a17ce5a80
Diffstat (limited to 'audio/common/all-versions/default/7.0/HidlUtils.cpp')
-rw-r--r-- | audio/common/all-versions/default/7.0/HidlUtils.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/audio/common/all-versions/default/7.0/HidlUtils.cpp b/audio/common/all-versions/default/7.0/HidlUtils.cpp index f09db5ed98..bb3a5968b5 100644 --- a/audio/common/all-versions/default/7.0/HidlUtils.cpp +++ b/audio/common/all-versions/default/7.0/HidlUtils.cpp @@ -16,6 +16,7 @@ #include <stdio.h> #include <string.h> +#include <algorithm> #define LOG_TAG "HidlUtils" #include <log/log.h> @@ -281,7 +282,7 @@ status_t HidlUtils::audioGainModeMaskFromHal(audio_gain_mode_t halGainModeMask, hidl_vec<AudioGainMode>* gainModeMask) { status_t status = NO_ERROR; std::vector<AudioGainMode> result; - for (uint32_t bit = 0; bit < sizeof(audio_gain_mode_t) * 8; ++bit) { + for (uint32_t bit = 0; halGainModeMask != 0 && bit < sizeof(audio_gain_mode_t) * 8; ++bit) { audio_gain_mode_t flag = static_cast<audio_gain_mode_t>(1u << bit); if ((flag & halGainModeMask) == flag) { AudioGainMode flagStr = audio_gain_mode_to_string(flag); @@ -291,6 +292,7 @@ status_t HidlUtils::audioGainModeMaskFromHal(audio_gain_mode_t halGainModeMask, ALOGE("Unknown audio gain mode value 0x%X", flag); status = BAD_VALUE; } + halGainModeMask = static_cast<audio_gain_mode_t>(halGainModeMask & ~flag); } } *gainModeMask = result; @@ -858,15 +860,17 @@ status_t HidlUtils::audioProfileToHal(const AudioProfile& profile, return result; } -status_t HidlUtils::audioTagsFromHal(const char* halTags, hidl_vec<AudioTag>* tags) { - std::vector<std::string> strTags = utils::splitString(halTags, sAudioTagSeparator); +status_t HidlUtils::audioTagsFromHal(const std::vector<std::string>& strTags, + hidl_vec<AudioTag>* tags) { status_t result = NO_ERROR; tags->resize(strTags.size()); size_t to = 0; for (size_t from = 0; from < strTags.size(); ++from) { - if (xsd::isVendorExtension(strTags[from])) { - (*tags)[to++] = strTags[from]; + const auto& tag = strTags[from]; + if (xsd::isVendorExtension(tag)) { + (*tags)[to++] = tag; } else { + ALOGE("Vendor extension tag is ill-formed: \"%s\"", tag.c_str()); result = BAD_VALUE; } } @@ -889,6 +893,7 @@ status_t HidlUtils::audioTagsToHal(const hidl_vec<AudioTag>& tags, char* halTags halTagsBuffer << tag; hasValue = true; } else { + ALOGE("Vendor extension tag is ill-formed: \"%s\"", tag.c_str()); result = BAD_VALUE; } } @@ -899,6 +904,31 @@ status_t HidlUtils::audioTagsToHal(const hidl_vec<AudioTag>& tags, char* halTags return result; } +hidl_vec<AudioTag> HidlUtils::filterOutNonVendorTags(const hidl_vec<AudioTag>& tags) { + hidl_vec<AudioTag> result; + result.resize(tags.size()); + size_t resultIdx = 0; + for (const auto& tag : tags) { + if (xsd::maybeVendorExtension(tag)) { + result[resultIdx++] = tag; + } + } + if (resultIdx != result.size()) { + result.resize(resultIdx); + } + return result; +} + +std::vector<std::string> HidlUtils::filterOutNonVendorTags(const std::vector<std::string>& tags) { + std::vector<std::string> result; + std::copy_if(tags.begin(), tags.end(), std::back_inserter(result), xsd::maybeVendorExtension); + return result; +} + +std::vector<std::string> HidlUtils::splitAudioTags(const char* halTags) { + return utils::splitString(halTags, sAudioTagSeparator); +} + status_t HidlUtils::deviceAddressFromHal(audio_devices_t halDeviceType, const char* halDeviceAddress, DeviceAddress* device) { status_t result = NO_ERROR; |