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
This commit is contained in:
parent
0a5932d7cd
commit
b5ecdf7060
3 changed files with 13 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue