| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 10 | * included LICENSE.LGPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #include "../common.h" | ||
| 18 | #include "../log.h" | ||
| 19 | |||
| 20 | #include "PlaylistEntryBase.h" | ||
| 21 | |||
| 22 | /* | ||
| 23 | * | ||
| 24 | */ | ||
| 25 | 5894 | PlaylistEntryBase::PlaylistEntryBase(Playlist* playlist, PlaylistEntryBase* parent) : | |
| 26 | 5894 | m_enabled(1), | |
| 27 | 5894 | m_isStarted(0), | |
| 28 | 5894 | m_isPlaying(0), | |
| 29 | 5894 | m_isFinished(0), | |
| 30 | 5894 | m_playOnce(0), | |
| 31 | 5894 | m_playCount(0), | |
| 32 | 5894 | m_isPrepped(0), | |
| 33 | 5894 | m_deprecated(0), | |
| 34 | 5894 | m_parent(parent), | |
| 35 | 5894 | m_parentPlaylist(playlist), | |
| 36 |
1/2✓ Branch 0 taken 5894 times.
✗ Branch 1 not taken.
|
5894 | m_playlistPosition(-1) { |
| 37 |
1/2✓ Branch 0 taken 5894 times.
✗ Branch 1 not taken.
|
5894 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::PlaylistEntryBase()\n"); |
| 38 |
1/2✓ Branch 0 taken 5894 times.
✗ Branch 1 not taken.
|
5894 | m_type = "base"; |
| 39 | 5894 | } | |
| 40 | |||
| 41 | /* | ||
| 42 | * | ||
| 43 | */ | ||
| 44 | 10688 | PlaylistEntryBase::~PlaylistEntryBase() { | |
| 45 | 10688 | } | |
| 46 | |||
| 47 | /* | ||
| 48 | * | ||
| 49 | */ | ||
| 50 | 5892 | int PlaylistEntryBase::Init(Json::Value& config) { | |
| 51 |
3/6✓ Branch 0 taken 5892 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5892 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5892 times.
✗ Branch 5 not taken.
|
5892 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::Init(): '%s'\n", |
| 52 | config["type"].asString().c_str()); | ||
| 53 | |||
| 54 |
1/2✓ Branch 0 taken 5892 times.
✗ Branch 1 not taken.
|
5892 | if (config.isMember("enabled")) |
| 55 | 5892 | m_enabled = config["enabled"].asInt(); | |
| 56 | |||
| 57 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5889 times.
|
5890 | if (config.isMember("note")) |
| 58 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | m_note = config["note"].asString(); |
| 59 | |||
| 60 | 5890 | m_isStarted = 0; | |
| 61 | 5890 | m_isPlaying = 0; | |
| 62 | 5890 | m_isFinished = 0; | |
| 63 | 5890 | m_config = config; | |
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5886 times.
|
5890 | if (config.isMember("timecode")) { |
| 66 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | std::string v = config["timecode"].asString(); |
| 67 |
3/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
4 | if (v == "Default") { |
| 68 | 1 | m_timeCode = -1; | |
| 69 | } else { | ||
| 70 | try { | ||
| 71 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | std::vector<std::string> sparts = split(v, ':'); |
| 72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (sparts.size() == 2) { |
| 73 | ✗ | m_timeCode = std::stoi(sparts[0]) * 60 * 60; | |
| 74 | ✗ | m_timeCode += std::stoi(sparts[1]) * 60; | |
| 75 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | } else if (sparts.size() == 3) { |
| 76 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | m_timeCode = std::stoi(sparts[0]) * 60 * 60; |
| 77 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | m_timeCode += std::stoi(sparts[1]) * 60; |
| 78 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | m_timeCode += std::stoi(sparts[2]); |
| 79 | } | ||
| 80 | 3 | m_timeCode *= 1000; // seconds -> milliseconds | |
| 81 | 3 | } catch (...) { | |
| 82 | ✗ | LogWarn(VB_PLAYLIST, "%s not a valid time code\n", v.c_str()); | |
| 83 | ✗ | m_timeCode = -1; | |
| 84 | ✗ | } | |
| 85 | } | ||
| 86 | 4 | } | |
| 87 | 5890 | return 1; | |
| 88 | } | ||
| 89 | |||
| 90 | /* | ||
| 91 | * | ||
| 92 | */ | ||
| 93 | 31854 | int PlaylistEntryBase::CanPlay(void) { | |
| 94 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 31854 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
31854 | if (m_playOnce && (m_playCount > 0)) { |
| 95 | ✗ | LogDebug(VB_PLAYLIST, "%s item exceeds play count\n", m_type.c_str()); | |
| 96 | ✗ | return 0; | |
| 97 | } | ||
| 98 | |||
| 99 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 31850 times.
|
31854 | if (!m_enabled) { |
| 100 | 4 | LogDebug(VB_PLAYLIST, "%s item disabled\n", m_type.c_str()); | |
| 101 | 4 | return 0; | |
| 102 | } | ||
| 103 | |||
| 104 | 31850 | return 1; | |
| 105 | } | ||
| 106 | |||
| 107 | /* | ||
| 108 | * | ||
| 109 | */ | ||
| 110 | 31700 | int PlaylistEntryBase::StartPlaying(void) { | |
| 111 | 31700 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::StartPlaying()\n"); | |
| 112 | |||
| 113 | 31700 | m_isStarted = 1; | |
| 114 | 31700 | m_isPlaying = 1; | |
| 115 | 31700 | m_isFinished = 0; | |
| 116 | 31700 | m_playCount++; | |
| 117 | |||
| 118 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 31696 times.
|
31700 | if (WillLog(LOG_DEBUG, VB_PLAYLIST)) |
| 119 | 4 | Dump(); | |
| 120 | |||
| 121 | 31700 | return 1; | |
| 122 | } | ||
| 123 | |||
| 124 | 31569 | int PlaylistEntryBase::StartPlayingOrFinish(void) { | |
| 125 | 31569 | int result = StartPlaying(); | |
| 126 |
6/6✓ Branch 0 taken 70 times.
✓ Branch 1 taken 31499 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 69 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 31568 times.
|
31569 | if (!IsPlaying() && !IsFinished()) { |
| 127 | 1 | LogWarn(VB_PLAYLIST, "%s entry did not start; skipping it\n", m_type.c_str()); | |
| 128 | 1 | FinishPlay(); | |
| 129 | } | ||
| 130 | 31569 | return result; | |
| 131 | } | ||
| 132 | |||
| 133 | 79 | void PlaylistEntryBase::ResetPlayState(void) { | |
| 134 | 79 | m_isStarted = 0; | |
| 135 | 79 | m_isPlaying = 0; | |
| 136 | 79 | m_isFinished = 0; | |
| 137 | 79 | } | |
| 138 | |||
| 139 | /* | ||
| 140 | * | ||
| 141 | */ | ||
| 142 | 56775 | void PlaylistEntryBase::FinishPlay(void) { | |
| 143 | 56775 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::FinishPlay()\n"); | |
| 144 | |||
| 145 | 56775 | m_isStarted = 1; | |
| 146 | 56775 | m_isPlaying = 0; | |
| 147 | 56775 | m_isFinished = 1; | |
| 148 | 56775 | } | |
| 149 | |||
| 150 | /* | ||
| 151 | * | ||
| 152 | */ | ||
| 153 | 130706 | int PlaylistEntryBase::IsStarted(void) { | |
| 154 | 130706 | return m_isStarted; | |
| 155 | } | ||
| 156 | |||
| 157 | /* | ||
| 158 | * | ||
| 159 | */ | ||
| 160 | 442861 | int PlaylistEntryBase::IsPlaying(void) { | |
| 161 |
4/4✓ Branch 0 taken 442705 times.
✓ Branch 1 taken 156 times.
✓ Branch 2 taken 442507 times.
✓ Branch 3 taken 198 times.
|
442861 | if (m_isStarted && m_isPlaying) |
| 162 | 442507 | return 1; | |
| 163 | |||
| 164 | 354 | return 0; | |
| 165 | } | ||
| 166 | |||
| 167 | /* | ||
| 168 | * | ||
| 169 | */ | ||
| 170 | 646265 | int PlaylistEntryBase::IsFinished(void) { | |
| 171 |
5/6✓ Branch 0 taken 645197 times.
✓ Branch 1 taken 1068 times.
✓ Branch 2 taken 5920 times.
✓ Branch 3 taken 639277 times.
✓ Branch 4 taken 5920 times.
✗ Branch 5 not taken.
|
646265 | if (m_isStarted && !m_isPlaying && m_isFinished) |
| 172 | 5920 | return 1; | |
| 173 | |||
| 174 | 640345 | return 0; | |
| 175 | } | ||
| 176 | |||
| 177 | /* | ||
| 178 | * | ||
| 179 | */ | ||
| 180 | ✗ | int PlaylistEntryBase::Prep(void) { | |
| 181 | ✗ | m_isPrepped = 1; | |
| 182 | |||
| 183 | ✗ | return 1; | |
| 184 | } | ||
| 185 | |||
| 186 | /* | ||
| 187 | * | ||
| 188 | */ | ||
| 189 | 641210 | int PlaylistEntryBase::Process(void) { | |
| 190 | 641210 | return 1; | |
| 191 | } | ||
| 192 | |||
| 193 | /* | ||
| 194 | * | ||
| 195 | */ | ||
| 196 | 25745 | int PlaylistEntryBase::Stop(void) { | |
| 197 | 25745 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::Stop()\n"); | |
| 198 | |||
| 199 | 25745 | FinishPlay(); | |
| 200 | |||
| 201 | 25745 | return 1; | |
| 202 | } | ||
| 203 | |||
| 204 | /* | ||
| 205 | * | ||
| 206 | */ | ||
| 207 | 10 | void PlaylistEntryBase::Dump(void) { | |
| 208 | 10 | LogDebug(VB_PLAYLIST, "---- Playlist Entry ----\n"); | |
| 209 | 10 | LogDebug(VB_PLAYLIST, "Entry Type: %s\n", m_type.c_str()); | |
| 210 | 10 | LogDebug(VB_PLAYLIST, "Entry Note: %s\n", m_note.c_str()); | |
| 211 | 10 | } | |
| 212 | |||
| 213 | /* | ||
| 214 | * | ||
| 215 | */ | ||
| 216 | 3 | Json::Value PlaylistEntryBase::GetMqttStatus(void) { | |
| 217 | 3 | Json::Value result; | |
| 218 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | result["type"] = m_type; |
| 219 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | result["playOnce"] = m_playOnce; |
| 220 | |||
| 221 | 3 | return result; | |
| 222 | ✗ | } | |
| 223 | |||
| 224 | 76486 | Json::Value PlaylistEntryBase::GetConfig(void) { | |
| 225 | 76486 | Json::Value result = m_config; | |
| 226 | |||
| 227 |
2/4✓ Branch 0 taken 76486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76486 times.
✗ Branch 3 not taken.
|
76486 | result["type"] = m_type; |
| 228 |
2/4✓ Branch 0 taken 76486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76486 times.
✗ Branch 3 not taken.
|
76486 | result["note"] = m_note; |
| 229 |
2/4✓ Branch 0 taken 76486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76486 times.
✗ Branch 3 not taken.
|
76486 | result["enabled"] = m_enabled; |
| 230 |
2/4✓ Branch 0 taken 76486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76486 times.
✗ Branch 3 not taken.
|
76486 | result["isStarted"] = m_isStarted; |
| 231 |
2/4✓ Branch 0 taken 76486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76486 times.
✗ Branch 3 not taken.
|
76486 | result["isPlaying"] = m_isPlaying; |
| 232 |
2/4✓ Branch 0 taken 76486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76486 times.
✗ Branch 3 not taken.
|
76486 | result["isFinished"] = m_isFinished; |
| 233 |
2/4✓ Branch 0 taken 76486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76486 times.
✗ Branch 3 not taken.
|
76486 | result["playOnce"] = m_playOnce; |
| 234 |
2/4✓ Branch 0 taken 76486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76486 times.
✗ Branch 3 not taken.
|
76486 | result["playCount"] = m_playCount; |
| 235 |
2/4✓ Branch 0 taken 76486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76486 times.
✗ Branch 3 not taken.
|
76486 | result["deprecated"] = m_deprecated; |
| 236 | |||
| 237 | 76486 | return result; | |
| 238 | ✗ | } | |
| 239 | |||
| 240 | /* | ||
| 241 | * | ||
| 242 | */ | ||
| 243 | 19 | std::string PlaylistEntryBase::ReplaceMatches(std::string in) { | |
| 244 | 19 | std::string out = in; | |
| 245 | |||
| 246 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | LogDebug(VB_PLAYLIST, "In: '%s'\n", in.c_str()); |
| 247 | |||
| 248 |
2/4✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
|
38 | replaceAll(out, "%t", m_type); |
| 249 | |||
| 250 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | LogDebug(VB_PLAYLIST, "Out: '%s'\n", out.c_str()); |
| 251 | |||
| 252 | 19 | return out; | |
| 253 | ✗ | } | |
| 254 |