| 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 | 4149 | PlaylistEntryBase::PlaylistEntryBase(Playlist* playlist, PlaylistEntryBase* parent) : | |
| 26 | 4149 | m_enabled(1), | |
| 27 | 4149 | m_isStarted(0), | |
| 28 | 4149 | m_isPlaying(0), | |
| 29 | 4149 | m_isFinished(0), | |
| 30 | 4149 | m_playOnce(0), | |
| 31 | 4149 | m_playCount(0), | |
| 32 | 4149 | m_isPrepped(0), | |
| 33 | 4149 | m_deprecated(0), | |
| 34 | 4149 | m_parent(parent), | |
| 35 | 4149 | m_parentPlaylist(playlist), | |
| 36 |
1/2✓ Branch 0 taken 4149 times.
✗ Branch 1 not taken.
|
4149 | m_playlistPosition(-1) { |
| 37 |
1/2✓ Branch 0 taken 4149 times.
✗ Branch 1 not taken.
|
4149 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::PlaylistEntryBase()\n"); |
| 38 |
1/2✓ Branch 0 taken 4149 times.
✗ Branch 1 not taken.
|
4149 | m_type = "base"; |
| 39 | 4149 | } | |
| 40 | |||
| 41 | /* | ||
| 42 | * | ||
| 43 | */ | ||
| 44 | 7372 | PlaylistEntryBase::~PlaylistEntryBase() { | |
| 45 | 7372 | } | |
| 46 | |||
| 47 | /* | ||
| 48 | * | ||
| 49 | */ | ||
| 50 | 4148 | int PlaylistEntryBase::Init(Json::Value& config) { | |
| 51 |
3/6✓ Branch 0 taken 4148 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4148 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4148 times.
✗ Branch 5 not taken.
|
4148 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::Init(): '%s'\n", |
| 52 | config["type"].asString().c_str()); | ||
| 53 | |||
| 54 |
1/2✓ Branch 0 taken 4148 times.
✗ Branch 1 not taken.
|
4148 | if (config.isMember("enabled")) |
| 55 | 4148 | m_enabled = config["enabled"].asInt(); | |
| 56 | |||
| 57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4146 times.
|
4146 | if (config.isMember("note")) |
| 58 | ✗ | m_note = config["note"].asString(); | |
| 59 | |||
| 60 | 4146 | m_isStarted = 0; | |
| 61 | 4146 | m_isPlaying = 0; | |
| 62 | 4146 | m_isFinished = 0; | |
| 63 | 4146 | m_config = config; | |
| 64 | |||
| 65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4146 times.
|
4146 | if (config.isMember("timecode")) { |
| 66 | ✗ | std::string v = config["timecode"].asString(); | |
| 67 | ✗ | if (v == "Default") { | |
| 68 | ✗ | m_timeCode = -1; | |
| 69 | } else { | ||
| 70 | try { | ||
| 71 | ✗ | std::vector<std::string> sparts = split(v, ':'); | |
| 72 | ✗ | if (sparts.size() == 2) { | |
| 73 | ✗ | m_timeCode = std::stoi(sparts[0]) * 60 * 60; | |
| 74 | ✗ | m_timeCode += std::stoi(sparts[1]) * 60; | |
| 75 | ✗ | } else if (sparts.size() == 3) { | |
| 76 | ✗ | m_timeCode = std::stoi(sparts[0]) * 60 * 60; | |
| 77 | ✗ | m_timeCode += std::stoi(sparts[1]) * 60; | |
| 78 | ✗ | m_timeCode += std::stoi(sparts[2]); | |
| 79 | } | ||
| 80 | ✗ | m_timeCode *= 1000; // seconds -> milliseconds | |
| 81 | ✗ | } catch (...) { | |
| 82 | ✗ | LogWarn(VB_PLAYLIST, "%s not a valid time code\n", v.c_str()); | |
| 83 | ✗ | m_timeCode = -1; | |
| 84 | ✗ | } | |
| 85 | } | ||
| 86 | ✗ | } | |
| 87 | 4146 | return 1; | |
| 88 | } | ||
| 89 | |||
| 90 | /* | ||
| 91 | * | ||
| 92 | */ | ||
| 93 | 32668 | int PlaylistEntryBase::CanPlay(void) { | |
| 94 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 32668 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
32668 | 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 32664 times.
|
32668 | if (!m_enabled) { |
| 100 | 4 | LogDebug(VB_PLAYLIST, "%s item disabled\n", m_type.c_str()); | |
| 101 | 4 | return 0; | |
| 102 | } | ||
| 103 | |||
| 104 | 32664 | return 1; | |
| 105 | } | ||
| 106 | |||
| 107 | /* | ||
| 108 | * | ||
| 109 | */ | ||
| 110 | 32653 | int PlaylistEntryBase::StartPlaying(void) { | |
| 111 | 32653 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::StartPlaying()\n"); | |
| 112 | |||
| 113 | 32653 | m_isStarted = 1; | |
| 114 | 32653 | m_isPlaying = 1; | |
| 115 | 32653 | m_isFinished = 0; | |
| 116 | 32653 | m_playCount++; | |
| 117 | |||
| 118 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 32649 times.
|
32653 | if (WillLog(LOG_DEBUG, VB_PLAYLIST)) |
| 119 | 4 | Dump(); | |
| 120 | |||
| 121 | 32653 | return 1; | |
| 122 | } | ||
| 123 | |||
| 124 | 32575 | int PlaylistEntryBase::StartPlayingOrFinish(void) { | |
| 125 | 32575 | int result = StartPlaying(); | |
| 126 |
6/6✓ Branch 0 taken 60 times.
✓ Branch 1 taken 32515 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 32574 times.
|
32575 | 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 | 32575 | return result; | |
| 131 | } | ||
| 132 | |||
| 133 | 46 | void PlaylistEntryBase::ResetPlayState(void) { | |
| 134 | 46 | m_isStarted = 0; | |
| 135 | 46 | m_isPlaying = 0; | |
| 136 | 46 | m_isFinished = 0; | |
| 137 | 46 | } | |
| 138 | |||
| 139 | /* | ||
| 140 | * | ||
| 141 | */ | ||
| 142 | 60218 | void PlaylistEntryBase::FinishPlay(void) { | |
| 143 | 60218 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::FinishPlay()\n"); | |
| 144 | |||
| 145 | 60218 | m_isStarted = 1; | |
| 146 | 60218 | m_isPlaying = 0; | |
| 147 | 60218 | m_isFinished = 1; | |
| 148 | 60218 | } | |
| 149 | |||
| 150 | /* | ||
| 151 | * | ||
| 152 | */ | ||
| 153 | 123404 | int PlaylistEntryBase::IsStarted(void) { | |
| 154 | 123404 | return m_isStarted; | |
| 155 | } | ||
| 156 | |||
| 157 | /* | ||
| 158 | * | ||
| 159 | */ | ||
| 160 | 352776 | int PlaylistEntryBase::IsPlaying(void) { | |
| 161 |
4/4✓ Branch 0 taken 352623 times.
✓ Branch 1 taken 153 times.
✓ Branch 2 taken 352469 times.
✓ Branch 3 taken 154 times.
|
352776 | if (m_isStarted && m_isPlaying) |
| 162 | 352469 | return 1; | |
| 163 | |||
| 164 | 307 | return 0; | |
| 165 | } | ||
| 166 | |||
| 167 | /* | ||
| 168 | * | ||
| 169 | */ | ||
| 170 | 538276 | int PlaylistEntryBase::IsFinished(void) { | |
| 171 |
5/6✓ Branch 0 taken 537510 times.
✓ Branch 1 taken 766 times.
✓ Branch 2 taken 4388 times.
✓ Branch 3 taken 533122 times.
✓ Branch 4 taken 4388 times.
✗ Branch 5 not taken.
|
538276 | if (m_isStarted && !m_isPlaying && m_isFinished) |
| 172 | 4388 | return 1; | |
| 173 | |||
| 174 | 533888 | 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 | 534355 | int PlaylistEntryBase::Process(void) { | |
| 190 | 534355 | return 1; | |
| 191 | } | ||
| 192 | |||
| 193 | /* | ||
| 194 | * | ||
| 195 | */ | ||
| 196 | 28168 | int PlaylistEntryBase::Stop(void) { | |
| 197 | 28168 | LogDebug(VB_PLAYLIST, "PlaylistEntryBase::Stop()\n"); | |
| 198 | |||
| 199 | 28168 | FinishPlay(); | |
| 200 | |||
| 201 | 28168 | 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 | 87236 | Json::Value PlaylistEntryBase::GetConfig(void) { | |
| 225 | 87236 | Json::Value result = m_config; | |
| 226 | |||
| 227 |
2/4✓ Branch 0 taken 87236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87236 times.
✗ Branch 3 not taken.
|
87236 | result["type"] = m_type; |
| 228 |
2/4✓ Branch 0 taken 87236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87236 times.
✗ Branch 3 not taken.
|
87236 | result["note"] = m_note; |
| 229 |
2/4✓ Branch 0 taken 87236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87236 times.
✗ Branch 3 not taken.
|
87236 | result["enabled"] = m_enabled; |
| 230 |
2/4✓ Branch 0 taken 87236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87236 times.
✗ Branch 3 not taken.
|
87236 | result["isStarted"] = m_isStarted; |
| 231 |
2/4✓ Branch 0 taken 87236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87236 times.
✗ Branch 3 not taken.
|
87236 | result["isPlaying"] = m_isPlaying; |
| 232 |
2/4✓ Branch 0 taken 87236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87236 times.
✗ Branch 3 not taken.
|
87236 | result["isFinished"] = m_isFinished; |
| 233 |
2/4✓ Branch 0 taken 87236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87236 times.
✗ Branch 3 not taken.
|
87236 | result["playOnce"] = m_playOnce; |
| 234 |
2/4✓ Branch 0 taken 87236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87236 times.
✗ Branch 3 not taken.
|
87236 | result["playCount"] = m_playCount; |
| 235 |
2/4✓ Branch 0 taken 87236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87236 times.
✗ Branch 3 not taken.
|
87236 | result["deprecated"] = m_deprecated; |
| 236 | |||
| 237 | 87236 | 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 |