Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f5305b36 authored by Kevin Rocard's avatar Kevin Rocard
Browse files

Audio HAL: Align V2 and V4 VTS



It was thought that the V2 VTS were not going to be supported after V4
VTS were created. Thus a large portion of the code was copy paste and
modified.

That assumption ended up wrong as a lot of OEM reported bugs that needed
to be fixed in both versions.

As a result align the code of both version VTS as much as possible.
The code will be merged in a follow up patch.

Bug: 118203066
Test: compile
Change-Id: I994232db237b5d7c52e7d796f199ab3c6eec21f4
Signed-off-by: default avatarKevin Rocard <krocard@google.com>
parent 1770b3b4
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ using ::android::hardware::audio::common::AUDIO_HAL_VERSION::AudioSource;
using ::android::hardware::audio::common::AUDIO_HAL_VERSION::AudioStreamType;
using ::android::hardware::audio::common::AUDIO_HAL_VERSION::AudioUsage;

using ::android::hardware::audio::common::utils::mkEnumConverter;
using ::android::hardware::audio::common::utils::EnumBitfield;

namespace android {
namespace hardware {
@@ -43,7 +43,7 @@ namespace AUDIO_HAL_VERSION {

void HidlUtils::audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config) {
    config->sampleRateHz = halConfig.sample_rate;
    config->channelMask = mkEnumConverter<AudioChannelMask>(halConfig.channel_mask);
    config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask);
    config->format = AudioFormat(halConfig.format);
    audioOffloadInfoFromHal(halConfig.offload_info, &config->offloadInfo);
    config->frameCount = halConfig.frame_count;
@@ -61,8 +61,8 @@ void HidlUtils::audioConfigToHal(const AudioConfig& config, audio_config_t* halC
void HidlUtils::audioGainConfigFromHal(const struct audio_gain_config& halConfig,
                                       AudioGainConfig* config) {
    config->index = halConfig.index;
    config->mode = mkEnumConverter<AudioGainMode>(halConfig.mode);
    config->channelMask = mkEnumConverter<AudioChannelMask>(halConfig.channel_mask);
    config->mode = EnumBitfield<AudioGainMode>(halConfig.mode);
    config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask);
    for (size_t i = 0; i < sizeof(audio_channel_mask_t) * 8; ++i) {
        config->values[i] = halConfig.values[i];
    }
@@ -82,8 +82,8 @@ void HidlUtils::audioGainConfigToHal(const AudioGainConfig& config,
}

void HidlUtils::audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain) {
    gain->mode = mkEnumConverter<AudioGainMode>(halGain.mode);
    gain->channelMask = mkEnumConverter<AudioChannelMask>(halGain.channel_mask);
    gain->mode = EnumBitfield<AudioGainMode>(halGain.mode);
    gain->channelMask = EnumBitfield<AudioChannelMask>(halGain.channel_mask);
    gain->minValue = halGain.min_value;
    gain->maxValue = halGain.max_value;
    gain->defaultValue = halGain.default_value;
@@ -122,7 +122,7 @@ audio_usage_t HidlUtils::audioUsageToHal(const AudioUsage usage) {
void HidlUtils::audioOffloadInfoFromHal(const audio_offload_info_t& halOffload,
                                        AudioOffloadInfo* offload) {
    offload->sampleRateHz = halOffload.sample_rate;
    offload->channelMask = mkEnumConverter<AudioChannelMask>(halOffload.channel_mask);
    offload->channelMask = EnumBitfield<AudioChannelMask>(halOffload.channel_mask);
    offload->format = AudioFormat(halOffload.format);
    offload->streamType = AudioStreamType(halOffload.stream_type);
    offload->bitRatePerSecond = halOffload.bit_rate;
@@ -155,9 +155,9 @@ void HidlUtils::audioPortConfigFromHal(const struct audio_port_config& halConfig
    config->id = halConfig.id;
    config->role = AudioPortRole(halConfig.role);
    config->type = AudioPortType(halConfig.type);
    config->configMask = mkEnumConverter<AudioPortConfigMask>(halConfig.config_mask);
    config->configMask = EnumBitfield<AudioPortConfigMask>(halConfig.config_mask);
    config->sampleRateHz = halConfig.sample_rate;
    config->channelMask = mkEnumConverter<AudioChannelMask>(halConfig.channel_mask);
    config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask);
    config->format = AudioFormat(halConfig.format);
    audioGainConfigFromHal(halConfig.gain, &config->gain);
    switch (halConfig.type) {
@@ -257,7 +257,7 @@ void HidlUtils::audioPortFromHal(const struct audio_port& halPort, AudioPort* po
    }
    port->channelMasks.resize(halPort.num_channel_masks);
    for (size_t i = 0; i < halPort.num_channel_masks; ++i) {
        port->channelMasks[i] = mkEnumConverter<AudioChannelMask>(halPort.channel_masks[i]);
        port->channelMasks[i] = EnumBitfield<AudioChannelMask>(halPort.channel_masks[i]);
    }
    port->formats.resize(halPort.num_formats);
    for (size_t i = 0; i < halPort.num_formats; ++i) {
+16 −21
Original line number Diff line number Diff line
@@ -26,36 +26,31 @@ namespace audio {
namespace common {
namespace utils {

/** Similar to static_cast but also casts to hidl_bitfield depending on
 * return type inference (emulated through user-define conversion).
 */
template <class Source, class Destination = Source>
class EnumConverter {
/** Converting between a bitfield or itself. */
template <class Enum>
class EnumBitfield {
   public:
    static_assert(std::is_enum<Source>::value || std::is_enum<Destination>::value,
                  "Source or destination should be an enum");
    using Bitfield = ::android::hardware::hidl_bitfield<Enum>;

    explicit EnumConverter(Source source) : mSource(source) {}
    EnumBitfield(const EnumBitfield&) = default;
    explicit EnumBitfield(Enum value) : mValue(value) {}
    explicit EnumBitfield(Bitfield value) : EnumBitfield(static_cast<Enum>(value)) {}

    operator Destination() const { return static_cast<Destination>(mSource); }
    EnumBitfield& operator=(const EnumBitfield&) = default;
    EnumBitfield& operator=(Enum value) { return *this = EnumBitfield{value}; }
    EnumBitfield& operator=(Bitfield value) { return *this = EnumBitfield{value}; }

    template <class = std::enable_if_t<std::is_enum<Destination>::value>>
    operator ::android::hardware::hidl_bitfield<Destination>() {
        return static_cast<std::underlying_type_t<Destination>>(mSource);
    }
    operator Enum() const { return mValue; }
    operator Bitfield() const { return static_cast<Bitfield>(mValue); }

   private:
    const Source mSource;
    Enum mValue;
};
template <class Destination, class Source>
auto mkEnumConverter(Source source) {
    return EnumConverter<Source, Destination>{source};
}

/** Allows converting an enum to its bitfield or itself. */
/** ATD way to create a EnumBitfield. */
template <class Enum>
EnumConverter<Enum> mkBitfield(Enum value) {
    return EnumConverter<Enum>{value};
EnumBitfield<Enum> mkEnumBitfield(Enum value) {
    return EnumBitfield<Enum>{value};
}

}  // namespace utils
+6 −0
Original line number Diff line number Diff line
@@ -29,5 +29,11 @@ cc_test {
        "libicuuc_stubdata",
        "libxml2",
    ],
    shared_libs: [
        "libfmq",
    ],
    header_libs: [
        "android.hardware.audio.common.util@all-versions",
    ],
    test_suites: ["general-tests"],
}
+195 −120

File changed.

Preview size limit exceeded, changes collapsed.

+9 −2
Original line number Diff line number Diff line
@@ -19,12 +19,19 @@

#include "utility/ValidateXml.h"

// Stringify the argument.
#define QUOTE(x) #x
#define STRINGIFY(x) QUOTE(x)

#define AUDIO_HAL_VERSION V2_0

TEST(CheckConfig, audioPolicyConfigurationValidation) {
    RecordProperty("description",
                   "Verify that the audio policy configuration file "
                   "is valid according to the schema");

    std::vector<const char*> locations = {"/odm/etc", "/vendor/etc", "/system/etc"};
    EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS("audio_policy_configuration.xml", locations,
                                            "/data/local/tmp/audio_policy_configuration.xsd");
    const char* xsd =
        "/data/local/tmp/audio_policy_configuration_" STRINGIFY(AUDIO_HAL_VERSION) ".xsd";
    EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS("audio_policy_configuration.xml", locations, xsd);
}
Loading