From 29fa8071c472da793198afb4cff74d449cb10f6b Mon Sep 17 00:00:00 2001 From: Daniel Kulp Date: Wed, 4 Dec 2024 14:52:58 -0500 Subject: [PATCH] Keep filename as a std::string when possible --- src/playlist/Playlist.cpp | 26 +++++++++++++------------- src/playlist/Playlist.h | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/playlist/Playlist.cpp b/src/playlist/Playlist.cpp index 4edb00974..50ff9d0e4 100644 --- a/src/playlist/Playlist.cpp +++ b/src/playlist/Playlist.cpp @@ -122,7 +122,7 @@ int Playlist::LoadJSONIntoPlaylist(std::vector& playlistPart if (m_subPlaylistDepth < 5) { std::string filename = FPP_DIR_PLAYLIST("/" + entries[c]["name"].asString() + ".json"); - Json::Value subPlaylist = LoadJSON(filename.c_str()); + Json::Value subPlaylist = LoadJSON(filename); int tmpMax = 999999; if (subPlaylist.isMember("leadIn")) @@ -264,12 +264,12 @@ int Playlist::Load(Json::Value& config) { /* * */ -Json::Value Playlist::LoadJSON(const char* filename) { - LogDebug(VB_PLAYLIST, "Playlist::LoadJSON(%s)\n", filename); +Json::Value Playlist::LoadJSON(const std::string& filename) { + LogDebug(VB_PLAYLIST, "Playlist::LoadJSON(%s)\n", filename.c_str()); Json::Value root; - if (!strlen(filename)) { + if (filename.empty()) { LogErr(VB_PLAYLIST, "Playlist::LoadJSON() called with empty filename\n"); return root; } @@ -284,7 +284,7 @@ Json::Value Playlist::LoadJSON(const char* filename) { if (m_filename == filename) { struct stat attr; - stat(filename, &attr); + stat(filename.c_str(), &attr); LogDebug(VB_PLAYLIST, "Playlist Last Modified: %s\n", ctime(&attr.st_mtime)); @@ -336,10 +336,10 @@ std::string sanitizeMediaName(std::string mediaName) { /* * */ -int Playlist::Load(const char* filename) { - LogDebug(VB_PLAYLIST, "Playlist::Load(%s)\n", filename); +int Playlist::Load(const std::string& filename) { + LogDebug(VB_PLAYLIST, "Playlist::Load(%s)\n", filename.c_str()); - if (!strlen(filename)) { + if (filename.empty()) { LogErr(VB_PLAYLIST, "Playlist::Load() called with empty filename\n"); return 0; } @@ -434,7 +434,7 @@ int Playlist::Load(const char* filename) { } else { m_filename = FPP_DIR_PLAYLIST("/" + filename + ".json"); - root = LoadJSON(m_filename.c_str()); + root = LoadJSON(m_filename); } } return Load(root); @@ -508,7 +508,7 @@ int Playlist::ReloadPlaylist(void) { int loopCount = m_loopCount; long long startTime = m_startTime; - Json::Value root = LoadJSON(m_filename.c_str()); + Json::Value root = LoadJSON(m_filename); if (!Load(root)) return 0; @@ -1116,12 +1116,12 @@ void Playlist::InsertPlaylistImmediate(const std::string& filename, const int po } } -int Playlist::Play(const char* filename, const int position, const int repeat, const int scheduleEntry, const int endPosition) { - if (!strlen(filename)) +int Playlist::Play(const std::string& filename, const int position, const int repeat, const int scheduleEntry, const int endPosition) { + if (filename.empty()) return 0; LogDebug(VB_PLAYLIST, "Playlist::Play('%s', %d, %d, %d, %d)\n", - filename, position, repeat, scheduleEntry, endPosition); + filename.c_str(), position, repeat, scheduleEntry, endPosition); std::unique_lock lck(m_playlistMutex); diff --git a/src/playlist/Playlist.h b/src/playlist/Playlist.h index 92fbdb68c..ef27eaccb 100644 --- a/src/playlist/Playlist.h +++ b/src/playlist/Playlist.h @@ -36,9 +36,9 @@ class Playlist { PlaylistStatus getPlaylistStatus(); // New methods - Json::Value LoadJSON(const char* filename); + Json::Value LoadJSON(const std::string& filename); int Load(Json::Value& config); - int Load(const char* filename); + int Load(const std::string& filename); PlaylistEntryBase* LoadPlaylistEntry(Json::Value entry); int LoadJSONIntoPlaylist(std::vector& playlistPart, const Json::Value& entries, int startPos, int& maxEntries); @@ -56,7 +56,7 @@ class Playlist { void ProcessMedia(void); int Cleanup(void); - int Play(const char* filename, const int position = -1, const int repeat = -1, const int scheduleEntry = -1, const int endPosition = -1); + int Play(const std::string& filename, const int position = -1, const int repeat = -1, const int scheduleEntry = -1, const int endPosition = -1); void InsertPlaylistAsNext(const std::string& filename, const int startPosition = -1, const int endPos = -1); void InsertPlaylistImmediate(const std::string& filename, const int startPosition = -1, const int endPos = -1); @@ -92,7 +92,7 @@ class Playlist { uint64_t GetCurrentPosInMS(); uint64_t GetCurrentPosInMS(int& pos, uint64_t& posms, bool itemDefinedOnly = false); uint64_t GetPosStartInMS(int pos); - int FindPosForMS(uint64_t& ms, bool itemDefinedOnly = false); //ms will be updated with how far into Pos it would be + int FindPosForMS(uint64_t& ms, bool itemDefinedOnly = false); // ms will be updated with how far into Pos it would be void GetFilenamesForPos(int pos, std::string& seq, std::string& med); int MQTTHandler(std::string topic, std::string msg);