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

Commit 87a728e7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 8887b4f5 5b8fc129
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