Skip to content

Commit

Permalink
Allow a plugin to get notification when a playlist is inserted so it …
Browse files Browse the repository at this point in the history
…can prepare
  • Loading branch information
dkulp committed Dec 7, 2024
1 parent 02d5935 commit 32244ca
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace FPPPlugins
virtual void eventCallback(const char* id, const char* impetus) {}
virtual void mediaCallback(const Json::Value& playlist, const MediaDetails& mediaDetails) {}
virtual void playlistCallback(const Json::Value& playlist, const std::string& action, const std::string& section, int item) {}
virtual void playlistInserted(const std::string& playlist, const int position, int endPosition, bool immediate) {}
};

class ChannelDataPlugin {
Expand Down
9 changes: 7 additions & 2 deletions src/Plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ FPPPlugins::Plugin* PluginManager::loadUserPlugin(const std::string& name) {
}
delete spl;
mLoadedUserPlugins.emplace(name);
auto *p = loadSHLIBPlugin(shlibName);
auto* p = loadSHLIBPlugin(shlibName);
if (p == nullptr) {
WarningHolder::AddWarning(5, "Could not load plugin " + name);
}
Expand All @@ -488,7 +488,7 @@ FPPPlugins::Plugin* PluginManager::loadSHLIBPlugin(const std::string& shlibName)
if (!FileExists(shlibName) && !FileExists(getFPPDDir("/" + shlibName))) {
LogErr(VB_PLUGIN, "Failed to find shlib %s\n", shlibName.c_str());
}
char *er = dlerror();
char* er = dlerror();
LogErr(VB_PLUGIN, "Failed to load shlib: %s\n", er);
return nullptr;
}
Expand Down Expand Up @@ -574,6 +574,11 @@ void PluginManager::playlistCallback(const Json::Value& playlist, const std::str
a->playlistCallback(playlist, action, section, item);
}
}
void PluginManager::playlistInserted(const std::string& playlist, const int position, int endPosition, bool immediate) {
for (auto a : mPlaylistPlugins) {
a->playlistInserted(playlist, position, endPosition, immediate);
}
}

// blocking
void MediaCallback::run(const Json::Value& playlist, const MediaDetails& mediaDetails) {
Expand Down
1 change: 1 addition & 0 deletions src/Plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PluginManager {

void mediaCallback(const Json::Value& playlist, const MediaDetails& mediaDetails);
void playlistCallback(const Json::Value& playlist, const std::string& action, const std::string& section, int item);
void playlistInserted(const std::string& filename, const int position, int endPosition, bool immediate);
void multiSyncData(const std::string& pn, uint8_t* data, int len);

void registerApis(httpserver::webserver* m_ws);
Expand Down
2 changes: 2 additions & 0 deletions src/playlist/Playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ int Playlist::Cleanup(void) {

void Playlist::InsertPlaylistAsNext(const std::string& filename, const int position, int endPosition) {
std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
PluginManager::INSTANCE.playlistInserted(filename, position, endPosition, false);
if (m_status == FPP_STATUS_IDLE) {
Play(filename, position, 0, m_scheduleEntry, endPosition);
} else {
Expand All @@ -1106,6 +1107,7 @@ void Playlist::InsertPlaylistAsNext(const std::string& filename, const int posit
}
void Playlist::InsertPlaylistImmediate(const std::string& filename, const int position, int endPosition) {
std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
PluginManager::INSTANCE.playlistInserted(filename, position, endPosition, true);
if (m_status == FPP_STATUS_IDLE) {
Play(filename, position, 0, m_scheduleEntry, endPosition);
} else {
Expand Down

0 comments on commit 32244ca

Please sign in to comment.