audio: Allow specifying "default" stream type in V7

Despite that AUDIO_STREAM_DEFAULT value of audio_stream_type_t
should only used by the framework, it can still end up being
passed to the HAL in port configs and offload info structures.
This happens in the cases when the stream type is not actually
used by the HAL. It seems natural to use an empty string
as the value of AudioStreamType field in this case.

Bug: 179743630
Test: atest android.hardware.audio.common@7.0-util_tests
Test: make a telephone call on a device with HAL V7
Change-Id: Ia330031fca9d081627746b4f6074162835c4c54b
This commit is contained in:
Mikhail Naganov 2021-02-10 04:20:04 +00:00
parent 7e734892c9
commit 5fd0c77caf
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);