Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added playing a background fseq file when FPP is not sending anything. #832

Merged
merged 7 commits into from
Feb 24, 2025
9 changes: 8 additions & 1 deletion include/input/InputFPPRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "InputCommon.hpp"
#include "WebMgr.hpp"
#include "service/FPPDiscovery.h"
#include "InputFPPRemotePlayItem.hpp"

class c_InputFPPRemote : public c_InputCommon
Expand All @@ -44,6 +43,14 @@ class c_InputFPPRemote : public c_InputCommon
void ProcessButtonActions(c_ExternalInput::InputValue_t value);
void SetOperationalState (bool ActiveFlag);

void FppStartRemoteFilePlay (String & FileName, uint32_t ElapsedTimeSec);
void FppStopRemoteFilePlay ();
void FppSyncRemoteFilePlay (String & FileName, uint32_t ElapsedTimeMS);
void GetFppRemotePlayStatus (JsonObject& jsonStatus);
bool IsIdle();
bool AllowedToPlayRemoteFile();
void SetBackgroundFile ();

protected:

c_InputFPPRemotePlayItem * pInputFPPRemotePlayItem = nullptr;
Expand Down
8 changes: 6 additions & 2 deletions include/input/InputFPPRemotePlayItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
class c_InputFPPRemotePlayItem
{
protected:
time_t PlayDurationSec = 0;
bool SendFppSync = false;
time_t PlayDurationSec = 0;
bool SendFppSync = false;
String BackgroundFileName = emptyString;

#if defined(ARDUINO_ARCH_ESP8266)
const uint64_t LocalIntensityBufferSize = 512;
#else
Expand Down Expand Up @@ -76,6 +78,8 @@ const uint64_t LocalIntensityBufferSize = 2048;
c_InputMgr::e_InputChannelIds GetInputChannelId () { return InputChannelId; }
bool InputIsPaused () { return InputPaused; }
void SetOperationalState (bool ActiveFlag) {InputPaused = !ActiveFlag;}
void SetBackgroundFileName(String & FileName) {BackgroundFileName = FileName;}
void ClearFileNames ();

}; // c_InputFPPRemotePlayItem
extern byte *LocalIntensityBuffer;
18 changes: 9 additions & 9 deletions include/service/FPPDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "ESPixelStick.h"
#include "input/InputMgr.hpp"
#include "input/InputFPPRemotePlayFile.hpp"
#include "input/InputFPPRemote.h"

#ifdef ESP32
# include <WiFi.h>
Expand Down Expand Up @@ -55,15 +55,15 @@ class c_FPPDiscovery
String ConfiguredFileToPlay;
String UploadFileName;
IPAddress FppRemoteIp = IPAddress (uint32_t(0));
c_InputFPPRemotePlayFile * InputFPPRemotePlayFile = nullptr;
c_InputFPPRemote * InputFPPRemote = nullptr;
const IPAddress MulticastAddress = IPAddress (239, 70, 80, 80);

void GetStatusJSON (JsonObject& jsonResponse, bool advanced);
void BuildFseqResponse (String fname, c_FileMgr::FileId fseq, String & resp);
void StopPlaying (bool wait = true);
void StartPlaying (String & FileName, float SecondsElapsed);
bool AllowedToRemotePlayFiles ();
void GetDriverName (String & Name) { Name = "FPPD"; }
void GetStatusJSON (JsonObject& jsonResponse, bool advanced);
void BuildFseqResponse (String fname, c_FileMgr::FileId fseq, String & resp);
void StopPlaying ();
void StartPlaying (String & FileName, float SecondsElapsed);
bool AllowedToPlayRemoteFile ();
void GetDriverName (String & Name) { Name = "FPPD"; }

struct MultiSyncStats_t
{
Expand Down Expand Up @@ -133,7 +133,7 @@ SystemDebugStats_t SystemDebugStats;
bool SetConfig (JsonObject& jsonConfig);
void GetConfig (JsonObject& jsonConfig);

void SetInputFPPRemotePlayFile (c_InputFPPRemotePlayFile * value);
void SetInputFPPRemotePlayFile (c_InputFPPRemote * value);
void ForgetInputFPPRemotePlayFile ();
void GenerateFppSyncMsg (uint8_t Action, const String & FileName, uint32_t CurrentFrame, const float & ElpsedTime);
void GetSysInfoJSON (JsonObject& jsonResponse);
Expand Down
155 changes: 135 additions & 20 deletions src/input/InputFPPRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ c_InputFPPRemote::~c_InputFPPRemote ()
{
// DEBUG_V();
StopPlaying ();
FPPDiscovery.ForgetInputFPPRemotePlayFile ();
FPPDiscovery.Disable();
}

} // ~c_InputFPPRemote
Expand Down Expand Up @@ -269,6 +271,7 @@ bool c_InputFPPRemote::SetConfig (JsonObject& jsonConfig)
{
pInputFPPRemotePlayItem->SetSyncOffsetMS (SyncOffsetMS);
pInputFPPRemotePlayItem->SetSendFppSync (SendFppSync);
SetBackgroundFile();
}

// DEBUG_V ("Config Processing");
Expand Down Expand Up @@ -317,23 +320,10 @@ void c_InputFPPRemote::StopPlaying ()
}
Stopping = true;

// DEBUG_V ("Disable FPP Discovery");
// FPPDiscovery.Disable ();
FPPDiscovery.ForgetInputFPPRemotePlayFile ();

if(PlayingFile())
{
// DEBUG_V();
// DEBUG_V(String("pInputFPPRemotePlayItem: 0x") + String(uint32_t(pInputFPPRemotePlayItem), HEX));
pInputFPPRemotePlayItem->Stop ();

// DEBUG_V();
while (!pInputFPPRemotePlayItem->IsIdle ())
{
pInputFPPRemotePlayItem->Poll ();
// DEBUG_V();
pInputFPPRemotePlayItem->Stop ();
}
// DEBUG_V("Tell player to stop");
FppStopRemoteFilePlay();

// DEBUG_V("Delete current playing file");
delete pInputFPPRemotePlayItem;
Expand Down Expand Up @@ -370,7 +360,7 @@ void c_InputFPPRemote::StartPlaying (String& FileName)
break;
}

if (FileName.equals(CN_No_LocalFileToPlay))
if (FppSyncOverride || FileName.equals(CN_No_LocalFileToPlay))
{
StartPlayingRemoteFile (FileName);
}
Expand Down Expand Up @@ -438,6 +428,7 @@ void c_InputFPPRemote::StartPlayingLocalFile (String& FileName)
}

// DEBUG_V (String ("Start Playing FileName: '") + FileName + "'");
pInputFPPRemotePlayItem->ClearFileNames();
pInputFPPRemotePlayItem->SetSyncOffsetMS (SyncOffsetMS);
pInputFPPRemotePlayItem->SetSendFppSync (SendFppSync);
pInputFPPRemotePlayItem->Start (FileName, 0, 1);
Expand Down Expand Up @@ -469,26 +460,30 @@ void c_InputFPPRemote::StartPlayingRemoteFile (String& FileName)
if(pInputFPPRemotePlayItem)
{
// DEBUG_V ("Delete existing play item");
delete pInputFPPRemotePlayItem;
c_InputFPPRemotePlayItem * temp = pInputFPPRemotePlayItem;
pInputFPPRemotePlayItem = nullptr;
delete temp;
// DEBUG_V(String("pInputFPPRemotePlayItem: 0x") + String(uint32_t(pInputFPPRemotePlayItem), HEX));
}
// DEBUG_V ("Start Local FSEQ file player");
pInputFPPRemotePlayItem = new c_InputFPPRemotePlayFile (GetInputChannelId ());
// DEBUG_V(String("pInputFPPRemotePlayItem: 0x") + String(uint32_t(pInputFPPRemotePlayItem), HEX));
pInputFPPRemotePlayItem->SetSyncOffsetMS (SyncOffsetMS);
pInputFPPRemotePlayItem->SetSendFppSync (SendFppSync);

SetBackgroundFile();

StatusType = CN_File;
FileBeingPlayed = FileName;

FPPDiscovery.SetInputFPPRemotePlayFile ((c_InputFPPRemotePlayFile *) pInputFPPRemotePlayItem);
FPPDiscovery.SetInputFPPRemotePlayFile (this);
FPPDiscovery.Enable ();

} while (false);

// DEBUG_END;

} // StartPlaying
} // StartPlayingRemoteFile

//-----------------------------------------------------------------------------
void c_InputFPPRemote::validateConfiguration ()
Expand Down Expand Up @@ -518,7 +513,7 @@ bool c_InputFPPRemote::PlayingRemoteFile ()
break;
}

if (!FileBeingPlayed.equals(CN_No_LocalFileToPlay))
if (!FppSyncOverride && !FileBeingPlayed.equals(CN_No_LocalFileToPlay))
{
break;
}
Expand All @@ -531,3 +526,123 @@ bool c_InputFPPRemote::PlayingRemoteFile ()
return response;

} // PlayingRemoteFile

//-----------------------------------------------------------------------------
void c_InputFPPRemote::FppStartRemoteFilePlay (String & FileName, uint32_t ElapsedTimeSec)
{
// DEBUG_START;

if (AllowedToPlayRemoteFile())
{
// DEBUG_V ("Ask FSM to start playing");
pInputFPPRemotePlayItem->Start (FileName, ElapsedTimeSec, 1);
}

// DEBUG_END;
} // FppStartRemoteFilePlay

//-----------------------------------------------------------------------------
void c_InputFPPRemote::FppStopRemoteFilePlay ()
{
// DEBUG_START;

// only process if the pointer is valid
while (AllowedToPlayRemoteFile())
{
// DEBUG_V("Pointer is valid");
if(pInputFPPRemotePlayItem->IsIdle())
{
// DEBUG_V("Play item is Idle.");
break;
}

// DEBUG_V("try to stop");
pInputFPPRemotePlayItem->ClearFileNames();
pInputFPPRemotePlayItem->Stop ();
pInputFPPRemotePlayItem->Poll ();

FeedWDT();
delay(5);
}

// DEBUG_END;
} // FppStopRemoteFilePlay

//-----------------------------------------------------------------------------
void c_InputFPPRemote::FppSyncRemoteFilePlay (String & FileName, uint32_t ElapsedTimeSec)
{
// DEBUG_START;

if (AllowedToPlayRemoteFile())
{
// DEBUG_V("Send Sync message")
pInputFPPRemotePlayItem->Sync(FileName, ElapsedTimeSec);
}

// DEBUG_END;
} // FppSyncRemoteFilePlay

//-----------------------------------------------------------------------------
void c_InputFPPRemote::GetFppRemotePlayStatus (JsonObject& jsonStatus)
{
// DEBUG_START;

if (pInputFPPRemotePlayItem)
{
// DEBUG_V ("Ask FSM to start playing");
pInputFPPRemotePlayItem->GetStatus (jsonStatus);
}

// DEBUG_END;
} // GetFppRemotePlayStatus

//-----------------------------------------------------------------------------
bool c_InputFPPRemote::IsIdle ()
{
// DEBUG_START;
bool Response = true;
if (pInputFPPRemotePlayItem)
{
// DEBUG_V ("Ask FSM to start playing");
Response = pInputFPPRemotePlayItem->IsIdle ();
}
return Response;
// DEBUG_END;
} // GetFppRemotePlayStatus

//-----------------------------------------------------------------------------
bool c_InputFPPRemote::AllowedToPlayRemoteFile()
{
// DEBUG_START;

bool Response = false;

if (pInputFPPRemotePlayItem &&
(ConfiguredFileToPlay.equals(CN_No_LocalFileToPlay) || FppSyncOverride))
{
// DEBUG_V ("FPP Is allowed to control playing files");
Response = true;
}

// DEBUG_END;
return Response;
} // AllowedToPlayRemoteFile

//-----------------------------------------------------------------------------
void c_InputFPPRemote::SetBackgroundFile ()
{
// DEBUG_START;

if(FppSyncOverride)
{
String Background = ConfiguredFileToPlay.equals(CN_No_LocalFileToPlay) ? emptyString : ConfiguredFileToPlay;
pInputFPPRemotePlayItem->SetBackgroundFileName(Background);
// DEBUG_V(String("Background: ") + Background);
}
else
{
pInputFPPRemotePlayItem->ClearFileNames();
}

// DEBUG_END;
} // SetBackgroundFile
14 changes: 7 additions & 7 deletions src/input/InputFPPRemotePlayFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void c_InputFPPRemotePlayFile::Stop ()
//-----------------------------------------------------------------------------
void c_InputFPPRemotePlayFile::Sync (String & FileName, float SecondsElapsed)
{
// DEBUG_START;
// xDEBUG_START;

if(!InputIsPaused())
{
Expand All @@ -96,7 +96,7 @@ void c_InputFPPRemotePlayFile::Sync (String & FileName, float SecondsElapsed)
}
}

// DEBUG_END;
// xDEBUG_END;

} // Sync

Expand All @@ -108,9 +108,9 @@ bool c_InputFPPRemotePlayFile::Poll ()

if(!InputIsPaused())
{
// DEBUG_V("Poll the FSM: Start");
// xDEBUG_V("Poll the FSM: Start");
Response = pCurrentFsmState->Poll ();
// DEBUG_V("Poll the FSM: Done");
// xDEBUG_V("Poll the FSM: Done");
}

// xDEBUG_END;
Expand Down Expand Up @@ -475,7 +475,7 @@ uint64_t c_InputFPPRemotePlayFile::ReadFile(uint64_t DestinationIntensityId, uin
{
if(c_FileMgr::INVALID_FILE_HANDLE == FileControl[CurrentFile].FileHandleForFileBeingPlayed)
{
// DEBUG_V(String("FileHandleForFileBeingPlayed: ") + String(FileControl[CurrentFile].FileHandleForFileBeingPlayed));
// DEBUG_V("No Valid File Handle");
break;
}

Expand All @@ -492,12 +492,12 @@ uint64_t c_InputFPPRemotePlayFile::ReadFile(uint64_t DestinationIntensityId, uin
}
while (NumBytesRead < NumBytesToRead)
{
// DEBUG_V();
// xDEBUG_V();
uint64_t NumBytesReadThisPass = FileMgr.ReadSdFile(FileControl[CurrentFile].FileHandleForFileBeingPlayed,
LocalIntensityBuffer,
min((NumBytesToRead - NumBytesRead), LocalIntensityBufferSize),
FileOffset);
// DEBUG_V();
// xDEBUG_V();
#ifdef DEBUG_FSEQ
/*
uint32_t nonZeroCount = 0;
Expand Down
Loading