Merge "audio: Allow specifying "default" stream type in V7" am: 9dac2b95fc

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1582322

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I911d2b7f5b607de9576c02fd9ff4c100b0e01d1a
This commit is contained in:
Treehugger Robot 2021-02-10 20:11:28 +00:00 committed by Automerger Merge Worker
commit 61a4a2a00d
3 changed files with 32 additions and 12 deletions

View file

@ -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;

View file

@ -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) {
*streamType = audio_stream_type_to_string(halStreamType);
if (!streamType->empty() && !xsd::isUnknownAudioStreamType(*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;
}
ALOGE("Unknown audio stream type value 0x%X", halStreamType);
return BAD_VALUE;
}
status_t HidlUtils::audioStreamTypeToHal(const AudioStreamType& streamType,
audio_stream_type_t* halStreamType) {
if (!xsd::isUnknownAudioStreamType(streamType) &&
audio_stream_type_from_string(streamType.c_str(), 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());
return BAD_VALUE;
} else {
*halStreamType = AUDIO_STREAM_DEFAULT;
return NO_ERROR;
}
ALOGE("Unknown audio stream type \"%s\"", streamType.c_str());
*halStreamType = AUDIO_STREAM_DEFAULT;
return BAD_VALUE;
}
status_t HidlUtils::audioConfigFromHal(const audio_config_t& halConfig, bool isInput,

View file

@ -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);