Skip to content

Commit

Permalink
Keep filename as a std::string when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Dec 4, 2024
1 parent ec480f0 commit 29fa807
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
26 changes: 13 additions & 13 deletions src/playlist/Playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int Playlist::LoadJSONIntoPlaylist(std::vector<PlaylistEntryBase*>& 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"))
Expand Down Expand Up @@ -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;
}
Expand All @@ -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));

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::recursive_mutex> lck(m_playlistMutex);

Expand Down
8 changes: 4 additions & 4 deletions src/playlist/Playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlaylistEntryBase*>& playlistPart, const Json::Value& entries, int startPos, int& maxEntries);

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

0 comments on commit 29fa807

Please sign in to comment.