~aleteoryx/muditaos

56c60a1ab9d684e6d64012a8e526da31329d3d1c — Jakub Pyszczak 5 years ago 6843142
[EGD-4076] Headphones auto detect fix
M changelog.md => changelog.md +5 -0
@@ 1,5 1,10 @@
# MuditaOS changelog

## Current release

### Fixed
* `[audio]` Fix headphones autodetection.

## [0.42.2 2020-10-16]

### Added

M module-services/service-audio/ServiceAudio.cpp => module-services/service-audio/ServiceAudio.cpp +9 -18
@@ 330,22 330,10 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStart(const Operation:

std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleSendEvent(std::shared_ptr<Event> evt)
{
    auto input = audioMux.GetRoutingInput();
    input      = input ? input : audioMux.GetActiveInput();

    if (!input) {
        return std::make_unique<AudioResponseMessage>(RetCode::OperationNotSet);
    }

    if (evt->getType() == EventType::HeadphonesPlugin) {
        headphonesInserted = true;
    }
    else if (evt->getType() == EventType::HeadphonesUnplug) {
        headphonesInserted = false;
    for (auto &input : audioMux.GetAllInputs()) {
        input.audio->SendEvent(evt);
    }

    auto retVal = input.value()->audio->SendEvent(evt);
    return std::make_unique<AudioEventResponse>(retVal);
    return std::make_unique<AudioEventResponse>(RetCode::Success);
}

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


@@ 546,7 534,9 @@ std::string ServiceAudio::getSetting(const Setting &setting,
            targetPlayback = currentPlaybackType;
        }
        else if (setting == Setting::Volume) {
            targetProfile = headphonesInserted ? Profile::Type::PlaybackHeadphones : Profile::Type::PlaybackLoudspeaker;
            auto input    = audioMux.GetIdleInput();
            targetProfile = ((*input)->audio->GetHeadphonesInserted()) ? Profile::Type::PlaybackHeadphones
                                                                       : Profile::Type::PlaybackLoudspeaker;
            targetPlayback = PlaybackType::CallRingtone;
        }
        else {


@@ 581,8 571,9 @@ void ServiceAudio::setSetting(const Setting &setting,
            updatedPlayback              = (*activeInput)->audio->GetCurrentOperationPlaybackType();
        }
        else if (setting == audio::Setting::Volume) {
            updatedProfile =
                headphonesInserted ? Profile::Type::PlaybackHeadphones : Profile::Type::PlaybackLoudspeaker;
            auto input     = audioMux.GetIdleInput();
            updatedProfile = (*input)->audio->GetHeadphonesInserted() ? Profile::Type::PlaybackHeadphones
                                                                      : Profile::Type::PlaybackLoudspeaker;
            updatedPlayback = PlaybackType::CallRingtone;
            valueToSet      = std::clamp(utils::getValue<audio::Volume>(value), minVolume, maxVolume);
        }

M module-services/service-audio/ServiceAudio.hpp => module-services/service-audio/ServiceAudio.hpp +0 -2
@@ 42,8 42,6 @@ class ServiceAudio : public sys::Service
    audio::AudioMux audioMux;
    audio::AudioMux::VibrationStatus vibrationMotorStatus = audio::AudioMux::VibrationStatus::Off;

    bool headphonesInserted = false;

    auto IsVibrationMotorOn()
    {
        return vibrationMotorStatus == audio::AudioMux::VibrationStatus::On;

M module-services/service-evtmgr/WorkerEvent.cpp => module-services/service-evtmgr/WorkerEvent.cpp +1 -1
@@ 72,7 72,7 @@ bool WorkerEvent::handleMessage(uint32_t queueID)
        if (bsp::headset::Handler(notification) == true) {
            bool state = bsp::headset::IsInserted();
            auto message = std::make_shared<AudioEventRequest>(state ? audio::EventType::HeadphonesPlugin
                                                                     : audio::EventType::CallSpeakerphoneOff);
                                                                     : audio::EventType::HeadphonesUnplug);
            sys::Bus::SendUnicast(message, service::name::evt_manager, this->service);
        }
    }