~aleteoryx/muditaos

4ad16d7ae27854c47ba7c11040d81cc2fbcc03df — Hubert Chrzaniuk 5 years ago e340788
[EGD-4125] Cumulative set of minor fixes for audio (#861)

* fixed choice of input for recording
* fixed vibration setting getter
* fixed response messages from a HandleStop
* improved style of using AudioMux APIs
M changelog.md => changelog.md +2 -0
@@ 8,7 8,9 @@
* `[cellular]` Handling incoming calls and sms in sleep mode

### Fixed

* `[audio]` Fix headphones autodetection.
* `[audio]` Cumulative set of minor fixes and improvements

## [0.42.2 2020-10-16]


M module-audio/Audio/AudioMux.cpp => module-audio/Audio/AudioMux.cpp +0 -8
@@ 37,14 37,6 @@ namespace audio
        return std::nullopt;
    }

    std::optional<AudioMux::Input *> AudioMux::GetRecordingInput()
    {
        if (auto input = GetInput({Audio::State::Recording, Audio::State::Routing})) {
            return input;
        }
        return std::nullopt;
    }

    std::optional<AudioMux::Input *> AudioMux::GetPlaybackInput(const audio::PlaybackType &playbackType)
    {
        // if routing or recording we cannot continue

M module-audio/Audio/AudioMux.hpp => module-audio/Audio/AudioMux.hpp +0 -5
@@ 89,11 89,6 @@ namespace audio
         */
        auto GetRoutingInput(bool force = false) -> std::optional<Input *>;
        /**
         * Gets input for recording
         * @return nullopt if input not found
         */
        auto GetRecordingInput() -> std::optional<Input *>;
        /**
         * Gets input for playback
         * @param playbackType Playback type to compare
         * @return nullopt if input not found

M module-services/service-audio/ServiceAudio.cpp => module-services/service-audio/ServiceAudio.cpp +18 -24
@@ 159,14 159,12 @@ static void ExtVibrationStop()

bool ServiceAudio::IsVibrationEnabled(const audio::PlaybackType &type)
{
    auto isEnabled = utils::getValue<audio::Vibrate>(
        getSetting(Setting::EnableVibration, Profile::Type::Idle, PlaybackType::Multimedia));
    auto isEnabled = utils::getValue<audio::Vibrate>(getSetting(Setting::EnableVibration, Profile::Type::Idle, type));
    return isEnabled;
}
bool ServiceAudio::IsPlaybackEnabled(const audio::PlaybackType &type)
{
    auto isEnabled = utils::getValue<audio::EnableSound>(
        getSetting(Setting::EnableSound, Profile::Type::Idle, PlaybackType::Multimedia));
    auto isEnabled = utils::getValue<audio::EnableSound>(getSetting(Setting::EnableSound, Profile::Type::Idle, type));
    return isEnabled;
}



@@ 291,13 289,7 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStart(const Operation:
            for (auto &audioInput : audioMux.GetAllInputs()) {
                HandlePause(&audioInput);
            }
            if (opType == Operation::Type::Recorder) {
                // since recording works on the same audio as routing
                retToken = input.value()->token;
            }
            else {
                retToken = audioMux.ResetInput(input);
            }
            retToken = audioMux.ResetInput(input);

            if (IsPlaybackEnabled(playbackType)) {
                retCode = (*input)->audio->Start(opType, retToken, fileName.c_str(), playbackType);


@@ 316,7 308,7 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStart(const Operation:
        return std::make_unique<AudioStartPlaybackResponse>(retCode, retToken);
    }
    else if (opType == Operation::Type::Recorder) {
        auto input = audioMux.GetRecordingInput();
        auto input = audioMux.GetIdleInput();
        AudioStart(input);
        return std::make_unique<AudioStartRecorderResponse>(retCode, retToken);
    }


@@ 340,7 332,7 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector
                                                               const Token &token,
                                                               bool &muted)
{
    std::vector<audio::RetCode> retCodes = {audio::RetCode::Success};
    std::vector<std::pair<Token, audio::RetCode>> retCodes;

    auto stopInput = [this](auto inp) {
        if (inp->audio->GetCurrentState() == Audio::State::Idle) {


@@ 356,10 348,10 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector

    // stop by token
    if (auto tokenInput = audioMux.GetInput(token); token.IsValid() && tokenInput) {
        retCodes.emplace_back(stopInput(tokenInput.value()));
        retCodes.emplace_back(std::make_pair(token, stopInput(tokenInput.value())));
    }
    else if (token.IsValid()) {
        return std::make_unique<AudioPauseResponse>(RetCode::TokenNotFound, Token::MakeBadToken());
        return std::make_unique<AudioStopResponse>(RetCode::TokenNotFound, Token::MakeBadToken());
    }
    // stop with vector of playback types
    else if (!stopTypes.empty()) {


@@ 367,25 359,28 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector
            const auto &currentOperation = input.audio->GetCurrentOperation();
            if (std::find(stopTypes.begin(), stopTypes.end(), currentOperation.GetPlaybackType()) != stopTypes.end()) {
                muted = true;
                retCodes.emplace_back(stopInput(&input));
                auto t = input.token;
                retCodes.emplace_back(t, stopInput(&input));
            }
        }
    }
    // stop all audio
    else if (token.IsUninitialized()) {
        for (auto &input : audioMux.GetAllInputs()) {
            retCodes.emplace_back(stopInput(&input));
            auto t = input.token;
            retCodes.emplace_back(t, stopInput(&input));
        }
    }

    // on failure return first false code
    auto it = std::find_if_not(retCodes.begin(), retCodes.end(), [](auto p) { return p == audio::RetCode::Success; });
    auto it =
        std::find_if_not(retCodes.begin(), retCodes.end(), [](auto p) { return p.second == audio::RetCode::Success; });
    if (it != retCodes.end()) {
        return std::make_unique<AudioResponseMessage>(*it);
        return std::make_unique<AudioStopResponse>(it->second, it->first);
    }

    VibrationUpdate();
    return std::make_unique<AudioResponseMessage>(audio::RetCode::Success);
    return std::make_unique<AudioStopResponse>(audio::RetCode::Success, token);
}

std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector<audio::PlaybackType> &stopTypes,


@@ 533,8 528,8 @@ std::string ServiceAudio::getSetting(const Setting &setting,
            targetProfile  = currentProfile;
            targetPlayback = currentPlaybackType;
        }
        else if (setting == Setting::Volume) {
            auto input    = audioMux.GetIdleInput();
        else if (auto input = audioMux.GetIdleInput(); input && (setting == Setting::Volume)) {

            targetProfile = ((*input)->audio->GetHeadphonesInserted()) ? Profile::Type::PlaybackHeadphones
                                                                       : Profile::Type::PlaybackLoudspeaker;
            targetPlayback = PlaybackType::CallRingtone;


@@ 570,8 565,7 @@ void ServiceAudio::setSetting(const Setting &setting,
            updatedProfile               = currentOperation.GetProfile()->GetType();
            updatedPlayback              = (*activeInput)->audio->GetCurrentOperationPlaybackType();
        }
        else if (setting == audio::Setting::Volume) {
            auto input     = audioMux.GetIdleInput();
        else if (auto input = audioMux.GetIdleInput(); input && (setting == audio::Setting::Volume)) {
            updatedProfile = (*input)->audio->GetHeadphonesInserted() ? Profile::Type::PlaybackHeadphones
                                                                      : Profile::Type::PlaybackLoudspeaker;
            updatedPlayback = PlaybackType::CallRingtone;