~aleteoryx/muditaos

fb6922458416b4517dbe3e0a312c38de579b6817 — Hubert Chrzaniuk 5 years ago 10e5542
[EGD-4176] Audio state notifications (#937)

M changelog.md => changelog.md +1 -0
@@ 8,6 8,7 @@
* `[gui]` Add "ButtonOnOff" widget.
* `[cellular]` Add support for modem reset
* `[cellular]` Obtain time zone through network
* `[audio]` Add state notifications
* `[antenna]` Service-antenna enabled.

### Changed

M module-services/service-audio/ServiceAudio.cpp => module-services/service-audio/ServiceAudio.cpp +18 -0
@@ 440,9 440,20 @@ auto ServiceAudio::HandleKeyPressed(const int step) -> std::unique_ptr<AudioKeyP
    return std::make_unique<AudioKeyPressedResponse>(audio::RetCode::Success, newVolume, muted, context);
}

bool ServiceAudio::IsBusy()
{
    for (auto &input : audioMux.GetAllInputs()) {
        if (input.audio->GetCurrentState() != Audio::State::Idle) {
            return true;
        }
    }
    return false;
}

sys::Message_t ServiceAudio::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
{
    sys::Message_t responseMsg;
    bool isBusy = IsBusy();

    auto &msgType = typeid(*msgl);
    LOG_DEBUG("msgType %d %s", static_cast<int>(msgl->messageType), msgType.name());


@@ 509,6 520,13 @@ sys::Message_t ServiceAudio::DataReceivedHandler(sys::DataMessage *msgl, sys::Re
        LOG_DEBUG("Unhandled message");
    }

    auto curIsBusy = IsBusy();
    if (isBusy != curIsBusy) {
        auto broadMsg = std::make_shared<AudioNotificationMessage>(
            curIsBusy ? AudioNotificationMessage::Type::ServiceWakeUp : AudioNotificationMessage::Type::ServiceSleep);
        sys::Bus::SendMulticast(broadMsg, sys::BusChannels::ServiceAudioNotifications, this);
    }

    if (responseMsg) {
        return responseMsg;
    }

M module-services/service-audio/ServiceAudio.hpp => module-services/service-audio/ServiceAudio.hpp +1 -0
@@ 77,6 77,7 @@ class ServiceAudio : public sys::Service
    auto IsOperationEnabled(const audio::PlaybackType &plType, const audio::Operation::Type &opType) -> bool;
    constexpr auto IsResumable(const audio::PlaybackType &type) const -> bool;
    constexpr auto ShouldLoop(const std::optional<audio::PlaybackType> &type) const -> bool;
    auto IsBusy() -> bool;

    void addOrIgnoreEntry(const std::string &profilePath, const std::string &defaultValue);


M module-services/service-audio/messages/AudioMessage.hpp => module-services/service-audio/messages/AudioMessage.hpp +4 -2
@@ 46,10 46,12 @@ class AudioNotificationMessage : public AudioMessage
    enum class Type
    {
        EndOfFile,
        Stop
        Stop,
        ServiceWakeUp,
        ServiceSleep,
    };

    explicit AudioNotificationMessage(Type type, audio::Token token) : type(type), token(token)
    explicit AudioNotificationMessage(Type type, audio::Token token = audio::Token()) : type(type), token(token)
    {}

    const Type type;