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

Commit 9dac2b95 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "audio: Allow specifying "default" stream type in V7"

parents 9b2940db 5fd0c77c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ struct Uuid {
 * Audio stream type describing the intended use case of a stream.
 * See 'audioStreamType' in audio_policy_configuration.xsd for the
 * list of allowed values.
 *
 * An empty string is used to specify the "default" stream type.
 */
typedef string AudioStreamType;

+19 −9
Original line number Diff line number Diff line
@@ -335,25 +335,35 @@ status_t HidlUtils::audioSourceToHal(const AudioSource& source, audio_source_t*
    return BAD_VALUE;
}

// The "default" value of audio_stream_type_t is represented by an empty string.
status_t HidlUtils::audioStreamTypeFromHal(audio_stream_type_t halStreamType,
                                           AudioStreamType* streamType) {
    if (halStreamType != AUDIO_STREAM_DEFAULT) {
        *streamType = audio_stream_type_to_string(halStreamType);
        if (!streamType->empty() && !xsd::isUnknownAudioStreamType(*streamType)) {
            return NO_ERROR;
        }
        ALOGE("Unknown audio stream type value 0x%X", halStreamType);
        return BAD_VALUE;
    } else {
        *streamType = "";
        return NO_ERROR;
    }
}

status_t HidlUtils::audioStreamTypeToHal(const AudioStreamType& streamType,
                                         audio_stream_type_t* halStreamType) {
    if (!streamType.empty()) {
        if (!xsd::isUnknownAudioStreamType(streamType) &&
            audio_stream_type_from_string(streamType.c_str(), halStreamType)) {
            return NO_ERROR;
        }
        ALOGE("Unknown audio stream type \"%s\"", streamType.c_str());
    *halStreamType = AUDIO_STREAM_DEFAULT;
        return BAD_VALUE;
    } else {
        *halStreamType = AUDIO_STREAM_DEFAULT;
        return NO_ERROR;
    }
}

status_t HidlUtils::audioConfigFromHal(const audio_config_t& halConfig, bool isInput,
+11 −3
Original line number Diff line number Diff line
@@ -44,8 +44,8 @@ static constexpr audio_gain_mode_t kInvalidHalGainMode =
        static_cast<audio_gain_mode_t>(0xFFFFFFFFU);
// AUDIO_SOURCE_INVALID is framework-only.
static constexpr audio_source_t kInvalidHalSource = static_cast<audio_source_t>(-1);
static constexpr audio_stream_type_t kInvalidHalStreamType =
        static_cast<audio_stream_type_t>(0xFFFFFFFFU);
// AUDIO_STREAM_DEFAULT is framework-only
static constexpr audio_stream_type_t kInvalidHalStreamType = static_cast<audio_stream_type_t>(-2);
static constexpr audio_usage_t kInvalidHalUsage = static_cast<audio_usage_t>(0xFFFFFFFFU);

TEST(HidlUtils, ConvertInvalidChannelMask) {
@@ -660,10 +660,18 @@ TEST(HidlUtils, ConvertInvalidStreamType) {
    AudioStreamType invalid;
    EXPECT_EQ(BAD_VALUE, HidlUtils::audioStreamTypeFromHal(kInvalidHalStreamType, &invalid));
    audio_stream_type_t halInvalid;
    EXPECT_EQ(BAD_VALUE, HidlUtils::audioStreamTypeToHal("", &halInvalid));
    EXPECT_EQ(BAD_VALUE, HidlUtils::audioStreamTypeToHal("random string", &halInvalid));
}

TEST(HidlUtils, ConvertDefaultStreamType) {
    AudioStreamType streamDefault = "";
    audio_stream_type_t halStreamDefault;
    EXPECT_EQ(NO_ERROR, HidlUtils::audioStreamTypeToHal(streamDefault, &halStreamDefault));
    AudioStreamType streamDefaultBack;
    EXPECT_EQ(NO_ERROR, HidlUtils::audioStreamTypeFromHal(halStreamDefault, &streamDefaultBack));
    EXPECT_EQ(streamDefault, streamDefaultBack);
}

TEST(HidlUtils, ConvertStreamType) {
    for (const auto enumVal : xsdc_enum_range<xsd::AudioStreamType>{}) {
        const AudioStreamType streamType = toString(enumVal);