Skip to content

Commit

Permalink
Merge pull request #672 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Fixed a small memory leak
  • Loading branch information
forkineye authored Oct 3, 2023
2 parents 3a559c2 + 00adb33 commit 43f361d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 46 deletions.
43 changes: 13 additions & 30 deletions ESPixelStick/src/input/InputFPPRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = "";

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -502,19 +515,21 @@ 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

//-----------------------------------------------------------------------------
void fsm_PlayFile_state_Stopping::Stop (void)
{
// DEBUG_START;
// DEBUG_V("State:Stopping");

// DEBUG_END;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 ())
{
Expand All @@ -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);

Expand All @@ -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 ())
{
Expand Down
58 changes: 46 additions & 12 deletions ESPixelStick/src/service/FPPDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -400,6 +406,7 @@ void c_FPPDiscovery::ProcessBlankPacket ()
{
// DEBUG_START;

StopPlaying ();
if (IsEnabled)
{
memset (OutputMgr.GetBufferAddress(), 0x0, OutputMgr.GetBufferUsedSize ());
Expand Down Expand Up @@ -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;
4 changes: 2 additions & 2 deletions ESPixelStick/src/service/FPPDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 43f361d

Please sign in to comment.