Skip to content

Commit e3fd0eb

Browse files
[EGD-4176] Audio state notifications (#937)
1 parent 47bcf28 commit e3fd0eb

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* `[gui]` Add "ButtonOnOff" widget.
99
* `[cellular]` Add support for modem reset
1010
* `[cellular]` Obtain time zone through network
11+
* `[audio]` Add state notifications
1112
* `[antenna]` Service-antenna enabled.
1213

1314
### Changed

module-services/service-audio/ServiceAudio.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,20 @@ auto ServiceAudio::HandleKeyPressed(const int step) -> std::unique_ptr<AudioKeyP
440440
return std::make_unique<AudioKeyPressedResponse>(audio::RetCode::Success, newVolume, muted, context);
441441
}
442442

443+
bool ServiceAudio::IsBusy()
444+
{
445+
for (auto &input : audioMux.GetAllInputs()) {
446+
if (input.audio->GetCurrentState() != Audio::State::Idle) {
447+
return true;
448+
}
449+
}
450+
return false;
451+
}
452+
443453
sys::Message_t ServiceAudio::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
444454
{
445455
sys::Message_t responseMsg;
456+
bool isBusy = IsBusy();
446457

447458
auto &msgType = typeid(*msgl);
448459
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
509520
LOG_DEBUG("Unhandled message");
510521
}
511522

523+
auto curIsBusy = IsBusy();
524+
if (isBusy != curIsBusy) {
525+
auto broadMsg = std::make_shared<AudioNotificationMessage>(
526+
curIsBusy ? AudioNotificationMessage::Type::ServiceWakeUp : AudioNotificationMessage::Type::ServiceSleep);
527+
sys::Bus::SendMulticast(broadMsg, sys::BusChannels::ServiceAudioNotifications, this);
528+
}
529+
512530
if (responseMsg) {
513531
return responseMsg;
514532
}

module-services/service-audio/ServiceAudio.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ServiceAudio : public sys::Service
7777
auto IsOperationEnabled(const audio::PlaybackType &plType, const audio::Operation::Type &opType) -> bool;
7878
constexpr auto IsResumable(const audio::PlaybackType &type) const -> bool;
7979
constexpr auto ShouldLoop(const std::optional<audio::PlaybackType> &type) const -> bool;
80+
auto IsBusy() -> bool;
8081

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

module-services/service-audio/messages/AudioMessage.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ class AudioNotificationMessage : public AudioMessage
4646
enum class Type
4747
{
4848
EndOfFile,
49-
Stop
49+
Stop,
50+
ServiceWakeUp,
51+
ServiceSleep,
5052
};
5153

52-
explicit AudioNotificationMessage(Type type, audio::Token token) : type(type), token(token)
54+
explicit AudioNotificationMessage(Type type, audio::Token token = audio::Token()) : type(type), token(token)
5355
{}
5456

5557
const Type type;

0 commit comments

Comments
 (0)