diff options
author | jiabin <jiabin@google.com> | 2021-03-05 06:42:05 +0000 |
---|---|---|
committer | jiabin <jiabin@google.com> | 2021-03-23 17:22:38 -0700 |
commit | 574a86fa361314024c5e94cd6b0384e809740868 (patch) | |
tree | 0bf49eba766610c9d58e60015236c5153c83dced /audio/common/all-versions/default/tests/hidlutils_tests.cpp | |
parent | 442a08d3ee2b0a38fca873da22d4e317ea5b7e45 (diff) |
Add AudioTransport to replace AudioProfile in AudioPort.
An AudioTransport contains AudioProfile or hardware descriptor to
describe the audio capabilities for an AudioPort and the encapsulation
type to represent the encapsualtion format that must be used when
sending the audio data with the format associated the AudioTransport to
Android.
The hardware descriptor will be used when the format is not recognized
by the platform.
Currently, the short audio descriptor is added as one of the hardware
descriptors. Short audio descriptor is reported from EDID for HDMI.
Bug: 131736540
Bug: 178619392
Test: atest android.hardware.audio.common@7.0-util_tests
Test: atest VtsHalAudioV7_0TargetTest
Change-Id: Ic5ed9ff9b694511fdd7e90cdcda2777bdfa74f65
Diffstat (limited to 'audio/common/all-versions/default/tests/hidlutils_tests.cpp')
-rw-r--r-- | audio/common/all-versions/default/tests/hidlutils_tests.cpp | 81 |
1 files changed, 71 insertions, 10 deletions
diff --git a/audio/common/all-versions/default/tests/hidlutils_tests.cpp b/audio/common/all-versions/default/tests/hidlutils_tests.cpp index e154453e2b..c9e6fac7b2 100644 --- a/audio/common/all-versions/default/tests/hidlutils_tests.cpp +++ b/audio/common/all-versions/default/tests/hidlutils_tests.cpp @@ -47,6 +47,10 @@ static constexpr audio_source_t kInvalidHalSource = static_cast<audio_source_t>( // 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); +static constexpr audio_encapsulation_type_t kInvalidEncapsulationType = + static_cast<audio_encapsulation_type_t>(0xFFFFFFFFU); +static constexpr audio_standard_t kInvalidAudioStandard = + static_cast<audio_standard_t>(0xFFFFFFFFU); TEST(HidlUtils, ConvertInvalidChannelMask) { AudioChannelMask invalid; @@ -950,6 +954,53 @@ TEST(HidlUtils, ConvertAudioPortConfig) { EXPECT_TRUE(audio_port_configs_are_equal(&halConfig, &halConfigBack)); } +TEST(HidlUtils, ConvertInvalidAudioTransports) { + hidl_vec<AudioTransport> invalid; + struct audio_port_v7 halInvalid = {}; + halInvalid.num_audio_profiles = 1; + halInvalid.audio_profiles[0].format = kInvalidHalFormat; + halInvalid.audio_profiles[0].encapsulation_type = kInvalidEncapsulationType; + halInvalid.num_extra_audio_descriptors = 1; + halInvalid.extra_audio_descriptors[0].standard = kInvalidAudioStandard; + halInvalid.extra_audio_descriptors[0].descriptor_length = EXTRA_AUDIO_DESCRIPTOR_SIZE + 1; + EXPECT_EQ(BAD_VALUE, + HidlUtils::audioTransportsFromHal(halInvalid, false /*isInput*/, &invalid)); + invalid.resize(2); + AudioProfile invalidProfile; + invalidProfile.format = "random string"; + invalid[0].audioCapability.profile(invalidProfile); + invalid[0].encapsulationType = "random string"; + invalid[0].audioCapability.edid(hidl_vec<uint8_t>(EXTRA_AUDIO_DESCRIPTOR_SIZE + 1)); + invalid[1].encapsulationType = "random string"; + EXPECT_EQ(BAD_VALUE, HidlUtils::audioTransportsToHal(invalid, &halInvalid)); +} + +TEST(HidlUtils, ConvertAudioTransports) { + hidl_vec<AudioTransport> transports; + transports.resize(2); + AudioProfile profile; + profile.format = toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT); + profile.sampleRates.resize(2); + profile.sampleRates[0] = 44100; + profile.sampleRates[1] = 48000; + profile.channelMasks.resize(2); + profile.channelMasks[0] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_MONO); + profile.channelMasks[1] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO); + transports[0].audioCapability.profile(profile); + hidl_vec<uint8_t> shortAudioDescriptor({0x11, 0x06, 0x01}); + transports[0].encapsulationType = + toString(xsd::AudioEncapsulationType::AUDIO_ENCAPSULATION_TYPE_NONE); + transports[1].audioCapability.edid(std::move(shortAudioDescriptor)); + transports[1].encapsulationType = + toString(xsd::AudioEncapsulationType::AUDIO_ENCAPSULATION_TYPE_IEC61937); + struct audio_port_v7 halPort; + EXPECT_EQ(NO_ERROR, HidlUtils::audioTransportsToHal(transports, &halPort)); + hidl_vec<AudioTransport> transportsBack; + EXPECT_EQ(NO_ERROR, + HidlUtils::audioTransportsFromHal(halPort, false /*isInput*/, &transportsBack)); + EXPECT_EQ(transports, transportsBack); +} + TEST(HidlUtils, ConvertInvalidAudioPort) { AudioPort invalid; struct audio_port_v7 halInvalid = {}; @@ -958,8 +1009,10 @@ TEST(HidlUtils, ConvertInvalidAudioPort) { halInvalid.num_audio_profiles = 1; halInvalid.audio_profiles[0].format = kInvalidHalFormat; EXPECT_EQ(BAD_VALUE, HidlUtils::audioPortFromHal(halInvalid, &invalid)); - invalid.profiles.resize(1); - invalid.profiles[0].format = "random string"; + invalid.transports.resize(1); + AudioProfile invalidProfile; + invalidProfile.format = "random string"; + invalid.transports[0].audioCapability.profile(invalidProfile); EXPECT_EQ(BAD_VALUE, HidlUtils::audioPortToHal(invalid, &halInvalid)); } @@ -967,14 +1020,22 @@ TEST(HidlUtils, ConvertAudioPort) { AudioPort port = {}; port.id = 42; port.name = "test"; - port.profiles.resize(1); - port.profiles[0].format = toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT); - port.profiles[0].sampleRates.resize(2); - port.profiles[0].sampleRates[0] = 44100; - port.profiles[0].sampleRates[1] = 48000; - port.profiles[0].channelMasks.resize(2); - port.profiles[0].channelMasks[0] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_MONO); - port.profiles[0].channelMasks[1] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO); + port.transports.resize(2); + AudioProfile profile; + profile.format = toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT); + profile.sampleRates.resize(2); + profile.sampleRates[0] = 44100; + profile.sampleRates[1] = 48000; + profile.channelMasks.resize(2); + profile.channelMasks[0] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_MONO); + profile.channelMasks[1] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO); + port.transports[0].audioCapability.profile(profile); + port.transports[0].encapsulationType = + toString(xsd::AudioEncapsulationType::AUDIO_ENCAPSULATION_TYPE_NONE); + hidl_vec<uint8_t> shortAudioDescriptor({0x11, 0x06, 0x01}); + port.transports[1].audioCapability.edid(std::move(shortAudioDescriptor)); + port.transports[1].encapsulationType = + toString(xsd::AudioEncapsulationType::AUDIO_ENCAPSULATION_TYPE_IEC61937); port.gains.resize(1); port.gains[0].channelMask = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO); port.ext.device({}); |