From b5ecdf7060ea608433d828ea43d1385a8ffc0421 Mon Sep 17 00:00:00 2001 From: Bob Date: Sun, 21 May 2023 21:00:17 +0200 Subject: [PATCH] consider kodi playing the same as a sound trigger, so that the off command is not executed when kodi is paused for longer than the timeout --- src/ampswitch.cpp | 15 ++++++--------- src/ampswitch.h | 4 ++-- src/kodiclient.cpp | 9 +++++---- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/ampswitch.cpp b/src/ampswitch.cpp index 38a1f3e..07ba998 100644 --- a/src/ampswitch.cpp +++ b/src/ampswitch.cpp @@ -52,7 +52,7 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[]) m_switchedon = false; m_samplecounter = 0; m_usekodi = false; - m_playstart = false; + m_playing = false; struct option longoptions[] = { @@ -323,12 +323,9 @@ int CAmpSwitch::PJackProcessCallback(jack_nframes_t nframes) //if the absolute sample value is higher than the trigger level, set the switch state to on and reset the sample counter bool trigger = fabsf(*(in++)) > m_triggerlevel; - //Consider a playback start as a trigger. - if (m_playstart) - { + //Consider kodi playing as a trigger + if (m_playing) trigger = true; - m_playstart = false; - } if (trigger) { @@ -390,8 +387,8 @@ void CAmpSwitch::SignalHandler(int signum) g_stop = true; } -void CAmpSwitch::SignalPlayStart() +void CAmpSwitch::SetPlayingState(bool playing) { - //Signal the jack client thread that playback has started. - m_playstart = true; + //Inform the switch thread about the play state of kodi + m_playing = playing; } diff --git a/src/ampswitch.h b/src/ampswitch.h index 88a972f..3851e53 100644 --- a/src/ampswitch.h +++ b/src/ampswitch.h @@ -32,7 +32,7 @@ class CAmpSwitch void Process(); void Cleanup(); - void SignalPlayStart(); + void SetPlayingState(bool playing); private: void PrintHelpMessage(); @@ -70,7 +70,7 @@ class CAmpSwitch bool m_usekodi; CKodiClient m_kodiclient; - bool m_playstart; + bool m_playing; }; #endif //AMPSWITCH_H diff --git a/src/kodiclient.cpp b/src/kodiclient.cpp index 09be578..81f570d 100644 --- a/src/kodiclient.cpp +++ b/src/kodiclient.cpp @@ -76,6 +76,7 @@ void CKodiClient::Process() } catch(boost::system::system_error& error) { + m_ampswitch->SetPlayingState(false); printf("ERROR: unable to connect to Kodi JSONRPC: %s\n", error.what()); printf("Retrying in 10 seconds\n"); sleep(10); @@ -155,12 +156,12 @@ void CKodiClient::Parse(const std::string& jsonstr) if (method == "Player.OnPlay") { printf("Player started\n"); - m_ampswitch->SignalPlayStart(); + m_ampswitch->SetPlayingState(true); } - else if (method == "Player.OnResume") + else if (method == "Player.OnStop") { - printf("Player unpaused\n"); - m_ampswitch->SignalPlayStart(); + printf("Player stopped\n"); + m_ampswitch->SetPlayingState(false); } } }