diff --git a/ESPixelStick/src/input/InputFPPRemote.cpp b/ESPixelStick/src/input/InputFPPRemote.cpp index 96fb965f9..2a8323e15 100644 --- a/ESPixelStick/src/input/InputFPPRemote.cpp +++ b/ESPixelStick/src/input/InputFPPRemote.cpp @@ -257,7 +257,7 @@ bool c_InputFPPRemote::SetConfig (JsonObject& jsonConfig) setFromJSON (SyncOffsetMS, jsonConfig, CN_SyncOffset); setFromJSON (SendFppSync, jsonConfig, CN_SendFppSync); - if (pInputFPPRemotePlayItem) + if (PlayingFile()) { pInputFPPRemotePlayItem->SetSyncOffsetMS (SyncOffsetMS); pInputFPPRemotePlayItem->SetSendFppSync (SendFppSync); @@ -289,16 +289,19 @@ void c_InputFPPRemote::StopPlaying () FPPDiscovery.Disable (); FPPDiscovery.ForgetInputFPPRemotePlayFile (); - pInputFPPRemotePlayItem->Stop (); - - while (!pInputFPPRemotePlayItem->IsIdle ()) + if(PlayingFile()) { - pInputFPPRemotePlayItem->Poll (); pInputFPPRemotePlayItem->Stop (); - } - delete pInputFPPRemotePlayItem; - pInputFPPRemotePlayItem = nullptr; + while (!pInputFPPRemotePlayItem->IsIdle ()) + { + pInputFPPRemotePlayItem->Poll (); + pInputFPPRemotePlayItem->Stop (); + } + + delete pInputFPPRemotePlayItem; + pInputFPPRemotePlayItem = nullptr; + } FileBeingPlayed = ""; @@ -346,28 +349,8 @@ void c_InputFPPRemote::StartPlayingLocalFile (String& FileName) do // once { - if (PlayingRemoteFile ()) - { - StopPlaying (); - } - - // are we already playing a local file? - if (PlayingFile ()) - { - // DEBUG_V ("PlayingFile"); - // has the file changed? - if (FileBeingPlayed != FileName) - { - // DEBUG_V ("StopPlaying"); - StopPlaying (); - } - else - { - // DEBUG_V ("Play It Again"); - pInputFPPRemotePlayItem->Start (FileName, 0, 1); - break; - } - } + // make sure we are stopped (clears pInputFPPRemotePlayItem) + StopPlaying(); // DEBUG_V ("Start A New File"); int Last_dot_pl_Position = FileName.lastIndexOf(CN_Dotpl); diff --git a/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp b/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp index d2e40ff9d..4e53908da 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp @@ -121,7 +121,12 @@ void c_InputFPPRemotePlayFile::Stop () { // DEBUG_START; - pCurrentFsmState->Stop (); + while (pCurrentFsmState != &fsm_PlayFile_state_Idle_imp) + { + pCurrentFsmState->Stop (); + pCurrentFsmState->Poll (); + pCurrentFsmState->TimerPoll (); + } // DEBUG_END; } // Stop diff --git a/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp b/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp index 1908b3bd0..c735dd531 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp @@ -45,6 +45,7 @@ IRAM_ATTR void fsm_PlayFile_state_Idle::TimerPoll () void fsm_PlayFile_state_Idle::Init (c_InputFPPRemotePlayFile* Parent) { // DEBUG_START; + // DEBUG_V("State:Idle"); // DEBUG_V (String (" Parent: 0x") + String ((uint32_t)Parent, HEX)); p_Parent = Parent; @@ -59,6 +60,7 @@ void fsm_PlayFile_state_Idle::Init (c_InputFPPRemotePlayFile* Parent) void fsm_PlayFile_state_Idle::Start (String& FileName, float ElapsedSeconds, uint32_t RemainingPlayCount) { // DEBUG_START; + // DEBUG_V("State:Idle"); // DEBUG_V (String ("FileName: ") + FileName); @@ -80,6 +82,7 @@ void fsm_PlayFile_state_Idle::Start (String& FileName, float ElapsedSeconds, uin void fsm_PlayFile_state_Idle::Stop (void) { // DEBUG_START; + // DEBUG_V("State:Idle"); // Do nothing @@ -91,6 +94,7 @@ void fsm_PlayFile_state_Idle::Stop (void) bool fsm_PlayFile_state_Idle::Sync (String& FileName, float ElapsedSeconds) { // DEBUG_START; + // DEBUG_V("State: Idle"); Start (FileName, ElapsedSeconds, 1); @@ -126,6 +130,7 @@ IRAM_ATTR void fsm_PlayFile_state_Starting::TimerPoll () void fsm_PlayFile_state_Starting::Init (c_InputFPPRemotePlayFile* Parent) { // DEBUG_START; + // DEBUG_V("State:Starting"); p_Parent = Parent; Parent->pCurrentFsmState = &(Parent->fsm_PlayFile_state_Starting_imp); @@ -143,6 +148,7 @@ void fsm_PlayFile_state_Starting::Init (c_InputFPPRemotePlayFile* Parent) void fsm_PlayFile_state_Starting::Start (String& FileName, float ElapsedSeconds, uint32_t RemainingPlayCount) { // DEBUG_START; + // DEBUG_V("State:Starting"); // DEBUG_V (String ("FileName: ") + FileName); p_Parent->PlayItemName = FileName; @@ -158,6 +164,7 @@ void fsm_PlayFile_state_Starting::Start (String& FileName, float ElapsedSeconds, void fsm_PlayFile_state_Starting::Stop (void) { // DEBUG_START; + // DEBUG_V("State:Starting"); p_Parent->RemainingPlayCount = 0; p_Parent->fsm_PlayFile_state_Idle_imp.Init (p_Parent); @@ -170,6 +177,8 @@ void fsm_PlayFile_state_Starting::Stop (void) bool fsm_PlayFile_state_Starting::Sync (String& FileName, float ElapsedSeconds) { // DEBUG_START; + // DEBUG_V("State:Starting"); + bool response = false; Start (FileName, ElapsedSeconds, 1); @@ -304,6 +313,7 @@ IRAM_ATTR void fsm_PlayFile_state_PlayingFile::TimerPoll () void fsm_PlayFile_state_PlayingFile::Init (c_InputFPPRemotePlayFile* Parent) { // DEBUG_START; + // DEBUG_V("State:PlayingFile"); p_Parent = Parent; @@ -349,6 +359,7 @@ void fsm_PlayFile_state_PlayingFile::Init (c_InputFPPRemotePlayFile* Parent) void fsm_PlayFile_state_PlayingFile::Start (String& FileName, float ElapsedSeconds, uint32_t PlayCount) { // DEBUG_START; + // DEBUG_V("State:PlayingFile"); // DEBUG_V (String (" FileName: ") + FileName); // DEBUG_V (String (" LastPlayedFrameId: ") + String (p_Parent->LastPlayedFrameId)); @@ -366,6 +377,7 @@ void fsm_PlayFile_state_PlayingFile::Start (String& FileName, float ElapsedSecon void fsm_PlayFile_state_PlayingFile::Stop (void) { // DEBUG_START; + // DEBUG_V("State:PlayingFile"); // DEBUG_V (String (F ("Stop Playing:: FileName: '")) + p_Parent->PlayItemName + "'"); // DEBUG_V (String (" LastPlayedFrameId: ") + String (p_Parent->LastPlayedFrameId)); @@ -478,6 +490,7 @@ IRAM_ATTR void fsm_PlayFile_state_Stopping::TimerPoll () void fsm_PlayFile_state_Stopping::Init (c_InputFPPRemotePlayFile* Parent) { // DEBUG_START; + // DEBUG_V("State:Stopping"); FileName = ""; StartingElapsedTime = 0.0; @@ -502,12 +515,13 @@ void fsm_PlayFile_state_Stopping::Init (c_InputFPPRemotePlayFile* Parent) void fsm_PlayFile_state_Stopping::Start (String& _FileName, float ElapsedTime, uint32_t _PlayCount) { // DEBUG_START; + // DEBUG_V("State:Stopping"); FileName = _FileName; StartingElapsedTime = ElapsedTime; PlayCount = _PlayCount; - // DEBUG_END + // DEBUG_END; } // fsm_PlayFile_state_Stopping::Start @@ -515,6 +529,7 @@ void fsm_PlayFile_state_Stopping::Start (String& _FileName, float ElapsedTime, u void fsm_PlayFile_state_Stopping::Stop (void) { // DEBUG_START; + // DEBUG_V("State:Stopping"); // DEBUG_END; @@ -524,6 +539,7 @@ void fsm_PlayFile_state_Stopping::Stop (void) bool fsm_PlayFile_state_Stopping::Sync (String&, float) { // DEBUG_START; + // DEBUG_V("State:Stopping"); // DEBUG_END; return false; @@ -563,6 +579,7 @@ IRAM_ATTR void fsm_PlayFile_state_Error::TimerPoll () void fsm_PlayFile_state_Error::Init (c_InputFPPRemotePlayFile* Parent) { // DEBUG_START; + // DEBUG_V("State:Error"); p_Parent = Parent; Parent->pCurrentFsmState = &(Parent->fsm_PlayFile_state_Error_imp); @@ -579,6 +596,7 @@ void fsm_PlayFile_state_Error::Init (c_InputFPPRemotePlayFile* Parent) void fsm_PlayFile_state_Error::Start (String& FileName, float ElapsedSeconds, uint32_t PlayCount) { // DEBUG_START; + // DEBUG_V("State:Error"); if (FileName != p_Parent->GetFileName ()) { @@ -593,6 +611,7 @@ void fsm_PlayFile_state_Error::Start (String& FileName, float ElapsedSeconds, ui void fsm_PlayFile_state_Error::Stop (void) { // DEBUG_START; + // DEBUG_V("State:Error"); p_Parent->fsm_PlayFile_state_Idle_imp.Init (p_Parent); @@ -604,6 +623,7 @@ void fsm_PlayFile_state_Error::Stop (void) bool fsm_PlayFile_state_Error::Sync (String& FileName, float ElapsedSeconds) { // DEBUG_START; + // DEBUG_V("State:Error"); if (FileName != p_Parent->GetFileName ()) { diff --git a/ESPixelStick/src/service/FPPDiscovery.cpp b/ESPixelStick/src/service/FPPDiscovery.cpp index 2033840f2..cdefaac33 100644 --- a/ESPixelStick/src/service/FPPDiscovery.cpp +++ b/ESPixelStick/src/service/FPPDiscovery.cpp @@ -78,27 +78,34 @@ void c_FPPDiscovery::NetworkStateChanged (bool NewNetworkState) // DEBUG_V (); - bool fail = false; - // Try to listen to the broadcast port + bool Failed = true; if (!udp.listen (FPP_DISCOVERY_PORT)) { logcon (String (F ("FAILED to subscribed to broadcast messages"))); - fail = true; - break; } - //logcon (String (F ("FPPDiscovery subscribed to broadcast"))); + else + { + Failed = false; + logcon (String (F ("FPPDiscovery subscribed to broadcast messages on port: ")) + String(FPP_DISCOVERY_PORT)); + } if (!udp.listenMulticast (MulticastAddress, FPP_DISCOVERY_PORT)) { logcon (String (F ("FAILED to subscribed to multicast messages"))); - fail = true; - break; } - //logcon (String (F ("FPPDiscovery subscribed to multicast: ")) + address.toString ()); + else + { + Failed = false; + logcon (String (F ("FPPDiscovery subscribed to multicast: ")) + MulticastAddress.toString () + F(":") + String(FPP_DISCOVERY_PORT)); + } - if (!fail) - logcon (String (F ("Listening on port ")) + String(FPP_DISCOVERY_PORT)); + // did at least one binding work? + if(Failed) + { + // no active bindings + break; + } udp.onPacket (std::bind (&c_FPPDiscovery::ProcessReceivedUdpPacket, this, std::placeholders::_1)); @@ -178,7 +185,7 @@ void c_FPPDiscovery::ProcessReceivedUdpPacket (AsyncUDPPacket UDPpacket) // We're in an upload, can't be bothered if (inFileUpload) { - // DEBUG_V ("") + // DEBUG_V ("In Upload, Ignore message"); break; } @@ -244,7 +251,6 @@ void c_FPPDiscovery::ProcessReceivedUdpPacket (AsyncUDPPacket UDPpacket) case CTRL_PKT_BLANK: { // DEBUG_V (String (F ("FPP Blank packet"))); - // StopPlaying (); MultiSyncStats.pktBlank++; ProcessBlankPacket (); break; @@ -400,6 +406,7 @@ void c_FPPDiscovery::ProcessBlankPacket () { // DEBUG_START; + StopPlaying (); if (IsEnabled) { memset (OutputMgr.GetBufferAddress(), 0x0, OutputMgr.GetBufferUsedSize ()); @@ -1153,4 +1160,31 @@ void c_FPPDiscovery::GenerateFppSyncMsg(uint8_t Action, const String & FileName, // DEBUG_END; } // GenerateFppSyncMsg +//----------------------------------------------------------------------------- +void c_FPPDiscovery::SetInputFPPRemotePlayFile (c_InputFPPRemotePlayFile * value) +{ + // DEBUG_START; + + InputFPPRemotePlayFile = value; + + // DEBUG_END; + +} // SetInputFPPRemotePlayFile + +//----------------------------------------------------------------------------- +void c_FPPDiscovery::ForgetInputFPPRemotePlayFile () +{ + // DEBUG_START; + + if(nullptr != InputFPPRemotePlayFile) + { + delete InputFPPRemotePlayFile; + InputFPPRemotePlayFile = nullptr; + } + + // DEBUG_END; + +} // SetInputFPPRemotePlayFile + + c_FPPDiscovery FPPDiscovery; diff --git a/ESPixelStick/src/service/FPPDiscovery.h b/ESPixelStick/src/service/FPPDiscovery.h index 1c4f30cd5..532d07d61 100644 --- a/ESPixelStick/src/service/FPPDiscovery.h +++ b/ESPixelStick/src/service/FPPDiscovery.h @@ -118,8 +118,8 @@ class c_FPPDiscovery void GetStatus (JsonObject& jsonStatus); void NetworkStateChanged (bool NewNetworkState); - void SetInputFPPRemotePlayFile (c_InputFPPRemotePlayFile * value) { InputFPPRemotePlayFile = value; } - void ForgetInputFPPRemotePlayFile () { InputFPPRemotePlayFile = nullptr; } + void SetInputFPPRemotePlayFile (c_InputFPPRemotePlayFile * value); + void ForgetInputFPPRemotePlayFile (); void GenerateFppSyncMsg (uint8_t Action, const String & FileName, uint32_t CurrentFrame, const float & ElpsedTime); # define SYNC_PKT_START 0