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

Commit 5b8fc129 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audio: Run VTS tests for streams of non-primary modules for HAL V6

Implement parsing of AudioPolicyManager config for finding
out supported format configurations of streams. This only applies
when running tests for HAL V6. Previously format configurations
mandated by CDD were used for testing, this does not work well
for non-primary modules.

Fix the following issues found while running the tests
for "r_submix" and "msd" modules:

- IStream::getSupportedFormats must return a status
  to indicate that this capability is not supported by HAL;

- it is allowed for IStream::setDevices to return
  NOT_SUPPORTED status.

Other changes:

- Factor out helper functions for generating format
  configurations;

- Fix generation of the channel mask component in the names
  of tests that use AudioConfig, add sampling rate to test
  names.

Bug: 141989952
Bug: 141847510
Test: atest VtsHalAudioV5_0TargetTest
      atest VtsHalAudioV6_0TargetTest
            also, run modified V5_0 test using generators for V6_0

Change-Id: If0d330881901908e546baab89f63d3333003e355
parent c8a6fd93
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -123,9 +123,11 @@ interface IStream {
     * equivalent to getting AUDIO_PARAMETER_STREAM_SUP_FORMATS on the legacy
     * HAL.
     *
     * @return retval operation completion status.
     * @return formats supported audio formats.
     *                 Must be non empty if retval is OK.
     */
    getSupportedFormats() generates (vec<AudioFormat> formats);
    getSupportedFormats() generates (Result retval, vec<AudioFormat> formats);

    /**
     * Sets the audio format of the stream. Calling this method is equivalent to
+9 −0
Original line number Diff line number Diff line
@@ -175,8 +175,17 @@ Return<void> Stream::getSupportedFormats(getSupportedFormats_cb _hidl_cb) {
        for (size_t i = 0; i < halFormats.size(); ++i) {
            formats[i] = AudioFormat(halFormats[i]);
        }
        // Legacy get_parameter does not return a status_t, thus can not advertise of failure.
        // Note that the method must not return an empty list if this capability is supported.
        if (formats.size() == 0) {
            result = Result::NOT_SUPPORTED;
        }
    }
#if MAJOR_VERSION <= 5
    _hidl_cb(formats);
#elif MAJOR_VERSION >= 6
    _hidl_cb(result, formats);
#endif
    return Void();
}

+3 −2
Original line number Diff line number Diff line
@@ -172,9 +172,10 @@ static void testSetDevices(IStream* stream, const DeviceAddress& address) {
    DeviceAddress otherAddress = address;
    otherAddress.device = (address.device & AudioDevice::BIT_IN) == 0 ? AudioDevice::OUT_SPEAKER
                                                                      : AudioDevice::IN_BUILTIN_MIC;
    EXPECT_OK(stream->setDevices({otherAddress}));
    EXPECT_RESULT(okOrNotSupported, stream->setDevices({otherAddress}));

    ASSERT_OK(stream->setDevices({address}));  // Go back to the original value
    ASSERT_RESULT(okOrNotSupported,
                  stream->setDevices({address}));  // Go back to the original value
}

TEST_IO_STREAM(SetDevices, "Check that the stream can be rerouted to SPEAKER or BUILTIN_MIC",
+8 −1
Original line number Diff line number Diff line
@@ -75,11 +75,18 @@ struct GetSupported {
        return res;
    }

#if MAJOR_VERSION <= 5
    static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
        EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
        // TODO: this should be an optional function
        return Result::OK;
    }
#elif MAJOR_VERSION >= 6
    static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
        Result res;
        EXPECT_OK(stream->getSupportedFormats(returnIn(res, capabilities)));
        return res;
    }
#endif
};

template <class T>
+74 −0
Original line number Diff line number Diff line
@@ -64,3 +64,77 @@ const std::vector<DeviceParameter>& getDeviceParameters() {
    }();
    return parameters;
}

const std::vector<DeviceConfigParameter>& getOutputDeviceConfigParameters() {
    static std::vector<DeviceConfigParameter> parameters = [] {
        std::vector<DeviceConfigParameter> result;
        for (const auto& device : getDeviceParameters()) {
            auto module =
                    getCachedPolicyConfig().getModuleFromName(std::get<PARAM_DEVICE_NAME>(device));
            for (const auto& ioProfile : module->getOutputProfiles()) {
                for (const auto& profile : ioProfile->getAudioProfiles()) {
                    auto configs = ConfigHelper::combineAudioConfig(profile->getChannels(),
                                                                    profile->getSampleRates(),
                                                                    profile->getFormat());
                    auto flags = ioProfile->getFlags();
                    for (auto& config : configs) {
                        // Some combinations of flags declared in the config file require special
                        // treatment.
                        bool special = false;
                        if (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
                            config.offloadInfo.sampleRateHz = config.sampleRateHz;
                            config.offloadInfo.channelMask = config.channelMask;
                            config.offloadInfo.format = config.format;
                            config.offloadInfo.streamType = AudioStreamType::MUSIC;
                            config.offloadInfo.bitRatePerSecond = 320;
                            config.offloadInfo.durationMicroseconds = -1;
                            config.offloadInfo.bitWidth = 16;
                            config.offloadInfo.bufferSize = 256;  // arbitrary value
                            config.offloadInfo.usage = AudioUsage::MEDIA;
                            result.emplace_back(
                                    device, config,
                                    AudioOutputFlag(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD));
                            special = true;
                        }
                        if ((flags & AUDIO_OUTPUT_FLAG_DIRECT) &&
                            !(flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC)) {
                            result.emplace_back(device, config,
                                                AudioOutputFlag(AUDIO_OUTPUT_FLAG_DIRECT));
                            special = true;
                        }
                        if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) {  // ignore the flag
                            flags &= ~AUDIO_OUTPUT_FLAG_PRIMARY;
                        }
                        if (!special) {
                            result.emplace_back(device, config, AudioOutputFlag(flags));
                        }
                    }
                }
            }
        }
        return result;
    }();
    return parameters;
}

const std::vector<DeviceConfigParameter>& getInputDeviceConfigParameters() {
    static std::vector<DeviceConfigParameter> parameters = [] {
        std::vector<DeviceConfigParameter> result;
        for (const auto& device : getDeviceParameters()) {
            auto module =
                    getCachedPolicyConfig().getModuleFromName(std::get<PARAM_DEVICE_NAME>(device));
            for (const auto& ioProfile : module->getInputProfiles()) {
                for (const auto& profile : ioProfile->getAudioProfiles()) {
                    auto configs = ConfigHelper::combineAudioConfig(profile->getChannels(),
                                                                    profile->getSampleRates(),
                                                                    profile->getFormat());
                    for (const auto& config : configs) {
                        result.emplace_back(device, config, AudioInputFlag(ioProfile->getFlags()));
                    }
                }
            }
        }
        return result;
    }();
    return parameters;
}
Loading