GCC Code Coverage Report


Directory: ./
File: playlist/Playlist.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 1803 2011 89.7%
Functions: 101 110 91.8%
Branches: 2302 4055 56.8%

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 <sys/wait.h>
18
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 #include <algorithm>
22 #include <cstring> // strnlen -- needed directly for NOPCH builds
23 #include <functional>
24 #include <time.h>
25
26 #include "../Events.h"
27 #include "../Sequence.h"
28 #include "../Warnings.h"
29 #include "../common.h"
30 #include "../log.h"
31 #include "../settings.h"
32
33 #include "../fseq/FSEQFile.h"
34
35 #include "../MultiSync.h"
36 #include "../Player.h"
37 #include "Playlist.h"
38 #include "Plugins.h"
39 #include "fpp.h"
40
41 #include "PlaylistEntryBoth.h"
42 #include "PlaylistEntryBranch.h"
43 #include "PlaylistEntryCommand.h"
44 #include "PlaylistEntryDynamic.h"
45 #include "PlaylistEntryImage.h"
46 #include "PlaylistEntryMedia.h"
47 #include "PlaylistEntryPause.h"
48 #include "PlaylistEntryPlaylist.h"
49 #include "PlaylistEntryRemap.h"
50 #include "PlaylistEntryScript.h"
51 #include "PlaylistEntrySequence.h"
52 #include "PlaylistEntryURL.h"
53 #include "../mediaoutput/StreamSlotManager.h"
54 #include "../util/RegExCache.h"
55
56 // Playlists the player is done with. Retiring is still a two-step deferral:
57 // pushed here at the moment the instance stops being current, and only at the
58 // top of Process() — after the stack has unwound — handed back to the owner.
59 // What changed in stage 2 is the second step: the drain drops the player's
60 // owning reference instead of calling delete, so an instance a reader thread is
61 // still holding a snapshot of survives until that reader is done with it.
62 // Between push and drain the instance is fully alive, which is what SetIdle's
63 // "is this parent condemned" walk below relies on.
64 // Both lists are reached from command threads as well as the main loop --
65 // SetIdle/SwitchToInsertedPlaylist condemn instances from whatever thread runs
66 // the transition, and a Load() on a command thread parks replaced entries -- so
67 // every access holds PL_CLEANUPS_LOCK. Deletes never run under it.
68 static std::mutex PL_CLEANUPS_LOCK;
69 static std::list<Playlist*> PL_CLEANUPS;
70 // Entries deleted while one of their own methods may still be on the
71 // call stack (e.g. a "Start Playlist" command entry that reloads this
72 // playlist from inside StartPlaying) are parked here and freed at the
73 // top of Process(), after the stack has unwound. Mirrors PL_CLEANUPS.
74 static std::list<PlaylistEntryBase*> PL_ENTRY_CLEANUPS;
75
76 // See the façade's comment in Playlist.h. Stateless, so no static
77 // initialization order concerns of its own; the snapshot it hands out comes
78 // from Player::INSTANCE.
79 PlaylistRef playlist;
80
81 ✗ PlaylistHandle PlaylistRef::operator->() const {
82 ✗ return PlaylistHandle{ Player::INSTANCE.PlaylistSnapshot() };
83 }
84
85 ✗ PlaylistRef::operator bool() const {
86 ✗ return Player::INSTANCE.PlaylistSnapshot() != nullptr;
87 }
88
89 // ──────────────────────────────────────────────────────────────────────────
90 // Crash snapshot
91 //
92 // What was playing, and where, at the moment fppd died. The crash handler
93 // already records the sequence file and elapsed ms; the playlist half is the
94 // part that explains *why* a given entry was being started -- most usefully
95 // the three section sizes, since an empty section that a caller believed was
96 // non-empty is the shape of a whole class of bug here.
97 //
98 // Deliberately plain scalars in file statics, never the live Playlist: see
99 // PlaylistDumpCrashState in the header for why the handler cannot lock or
100 // walk containers. Torn reads are accepted.
101 // ──────────────────────────────────────────────────────────────────────────
102 namespace {
103 // A playlist file's "random" field, as the UI and older files write it: a
104 // number, a bool, or a number in a string. Anything else is 0 (in order).
105 116 int PlaylistRandomSetting(const Json::Value& v) {
106
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 5 times.
116 if (v.isNumeric()) {
107 111 return v.asInt();
108 }
109
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 if (v.isBool()) {
110
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 return v.asBool() ? 1 : 0;
111 }
112
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (v.isString()) {
113
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 return std::atoi(v.asString().c_str());
114 }
115 ✗ return 0;
116 }
117
118 struct CrashSnapshot {
119 char playlistName[128];
120 char section[24];
121 int sectionPosition;
122 int leadInSize;
123 int mainSize;
124 int leadOutSize;
125 int status;
126 bool everSet;
127 };
128 CrashSnapshot s_crashSnapshot{};
129
130 786922 void copyFixed(char* dst, size_t dstSize, const std::string& src) {
131
1/2
✓ Branch 0 taken 786922 times.
✗ Branch 1 not taken.
786922 size_t n = src.size() < dstSize - 1 ? src.size() : dstSize - 1;
132 786922 memcpy(dst, src.data(), n);
133 786922 dst[n] = '\0';
134 786922 }
135 } // namespace
136
137 393461 void Playlist::UpdateCrashSnapshot(void) {
138 393461 CrashSnapshot& s = s_crashSnapshot;
139 393461 copyFixed(s.playlistName, sizeof(s.playlistName), m_name);
140 393461 copyFixed(s.section, sizeof(s.section), m_currentSectionStr);
141 393461 s.sectionPosition = m_sectionPosition;
142 393461 s.leadInSize = (int)m_leadIn.size();
143 393461 s.mainSize = (int)m_mainPlaylist.size();
144 393461 s.leadOutSize = (int)m_leadOut.size();
145 393461 s.status = (int)m_status;
146 393461 s.everSet = true;
147 393461 }
148
149 32 void PlaylistDumpCrashState(int fd) {
150 32 const CrashSnapshot& s = s_crashSnapshot;
151 char buf[512];
152 int n;
153
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 3 times.
32 if (!s.everSet) {
154 29 n = snprintf(buf, sizeof(buf), "Playlist state: none (no playlist has run)\n");
155 } else {
156 3 n = snprintf(buf, sizeof(buf),
157 "Playlist state: name='%.127s' section=%.23s pos=%d status=%d "
158 "sizes(leadIn=%d main=%d leadOut=%d)\n",
159 3 s.playlistName, s.section, s.sectionPosition, s.status,
160 3 s.leadInSize, s.mainSize, s.leadOutSize);
161 }
162
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (n > 0) {
163
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 (void)!write(fd, buf, (size_t)(n < (int)sizeof(buf) ? n : (int)sizeof(buf) - 1));
164 }
165 32 }
166
167 // ──────────────────────────────────────────────────────────────────────────
168 // Deferred notifications and deferred re-entrant starts.
169 //
170 // TriggerPreset() and PluginManager::playlistCallback() run arbitrary code
171 // INLINE on the calling thread: preset commands can start/stop playlists,
172 // native plugins can call any FPP API, and script plugins fork and block in
173 // waitpid. Historically these fired from inside Play()/Start()/StopNow()/
174 // SetIdle()/Process() while m_playlistMutex (recursive) was held and while
175 // this playlist's state was mid-transition. The recursion "worked", but:
176 // - PLAYLIST_STARTED presets that start another playlist re-entered
177 // Play() on the same stack; chains (A starts B, B starts A) recursed
178 // without bound until stack overflow.
179 // - Presets/plugins observed and mutated half-updated playlist state
180 // (the PL_CLEANUPS / PL_ENTRY_CLEANUPS / deferred-start machinery is
181 // scar tissue from exactly this).
182 // - The mutex stayed held across fork/waitpid script runs, stalling the
183 // status API.
184 //
185 // The invariant now: a state transition COMPLETES before any preset or
186 // playlist callback runs. Notification sites queue a snapshot-capturing
187 // closure via QueuePlaylistNotification(); every public transition method
188 // holds a PlaylistTransitionGuard, and when the OUTERMOST guard on this
189 // thread unwinds (mutex already released — the guard is declared before
190 // the lock), the queue is drained iteratively. A Play() triggered by a
191 // drained notification runs inline at depth 1 and appends its own
192 // notifications to the same queue, so chains flatten into iteration
193 // instead of recursion; runaway chains hit MAX_NOTIFICATION_CASCADE and
194 // stop with a warning instead of a stack overflow.
195 //
196 // Re-entrant Play() (depth > 1, e.g. a "Start Playlist" COMMAND ENTRY
197 // executing inside its own StartPlaying() frame) is recorded in
198 // s_pendingStart* and replayed by the same drain. This generalizes the
199 // old PlaylistEntryCommand/PlaylistEntryScript dynamic_cast special-case
200 // in Play() to every re-entrant caller.
201 // ──────────────────────────────────────────────────────────────────────────
202 static thread_local int tl_transitionDepth = 0;
203 static thread_local bool tl_drainingNotifications = false;
204 // Set while StopNowAllLevelsImpl() unwinds an inserted-playlist stack: each
205 // level's SetIdle() still hands the player back to its parent, but doesn't
206 // resume it, because the parent is stopped next.
207 static thread_local bool tl_stoppingAllLevels = false;
208 static thread_local std::vector<std::function<void()>> tl_pendingNotifications;
209 // One drain may legitimately fire a handful of chained events (playlist A's
210 // STOPPED preset starts B, etc.). Each start/stop cycle queues ~4-5
211 // notifications, so 20 allows ~4 chained playlist switches — anything past
212 // that is a preset loop (PLAYLIST_STARTED → Start Playlist → ...).
213 static constexpr int MAX_NOTIFICATION_CASCADE = 20;
214
215 // Pending re-entrant start request. File-scope (not per-Playlist members)
216 // because the active Playlist object can be swapped/queued for cleanup
217 // between the defer and the drain (inserted playlists, SetIdle-to-parent) —
218 // the request belongs to "the player", not to one instance.
219 static std::mutex s_pendingStartMutex;
220 static std::string s_pendingStartFilename;
221 static int s_pendingStartPosition = 0;
222 static int s_pendingStartRepeat = 0;
223 static int s_pendingStartScheduleEntry = 0;
224 static int s_pendingStartEndPosition = 0;
225
226 // Set while a PLAYLIST_STOPPED preset runs for an inserted playlist that has
227 // handed the player back to the playlist it interrupted. That playlist has
228 // already stopped; the preset runs after the transition (above), by which
229 // time the parent has resumed, so a Stop in it would stop the parent -- a
230 // show went dark after every Remote Falcon request (#3114). FPP 9 ran the
231 // preset while the inserted playlist was still current, where a Stop did
232 // nothing; Player's stops do nothing here for the same reason.
233 static thread_local int tl_handedBackStoppedPreset = 0;
234
235 1056 bool InHandedBackStoppedPreset() {
236 1056 return tl_handedBackStoppedPreset > 0;
237 }
238
239 namespace {
240 struct HandedBackStoppedPresetScope {
241 bool on;
242 12 explicit HandedBackStoppedPresetScope(bool b) :
243 12 on(b) {
244
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
12 if (on)
245 1 tl_handedBackStoppedPreset++;
246 12 }
247 12 ~HandedBackStoppedPresetScope() {
248
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
12 if (on)
249 1 tl_handedBackStoppedPreset--;
250 12 }
251 };
252 }
253
254 36540 static void QueuePlaylistNotification(std::function<void()>&& fn) {
255
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36540 times.
36540 if (tl_transitionDepth == 0) {
256 // Not inside a transition (shouldn't happen — all queue sites are in
257 // guarded methods) — fire directly rather than parking it on this
258 // thread's queue where it would only drain on some later transition.
259 ✗ fn();
260 ✗ return;
261 }
262 36540 tl_pendingNotifications.push_back(std::move(fn));
263 }
264
265 namespace {
266 class PlaylistTransitionGuard {
267 public:
268 453326 PlaylistTransitionGuard() { tl_transitionDepth++; }
269 453326 ~PlaylistTransitionGuard() {
270
6/6
✓ Branch 0 taken 421962 times.
✓ Branch 1 taken 31364 times.
✓ Branch 2 taken 244 times.
✓ Branch 3 taken 421718 times.
✓ Branch 4 taken 31608 times.
✓ Branch 5 taken 421718 times.
453326 if (--tl_transitionDepth > 0 || tl_drainingNotifications) {
271 // Inner frame, or a frame created by the drain itself — the
272 // outermost/draining frame owns the queue.
273 31608 return;
274 }
275 421718 tl_drainingNotifications = true;
276 421718 int fired = 0;
277 while (true) {
278
2/2
✓ Branch 0 taken 36531 times.
✓ Branch 1 taken 421789 times.
458320 if (!tl_pendingNotifications.empty()) {
279
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 36517 times.
36531 if (++fired > MAX_NOTIFICATION_CASCADE) {
280 14 LogErr(VB_PLAYLIST, "Playlist notification cascade exceeded %d events — presets/plugins are starting playlists in a loop (e.g. PLAYLIST_STARTED -> Start Playlist -> PLAYLIST_STARTED), or a playlist command entry keeps restarting its own playlist item. Dropping %d pending notifications.\n",
281 MAX_NOTIFICATION_CASCADE, (int)tl_pendingNotifications.size());
282 42 WarningHolder::AddWarningTimeout(300, 36, "Playlist loop detected: a playlist preset (e.g. PLAYLIST_STARTED) starts a playlist which re-triggers the preset, or a playlist command entry (Restart/Next/Prev Playlist Item) keeps landing on itself. Fix the preset or playlist.");
283 14 tl_pendingNotifications.clear();
284 14 std::lock_guard<std::mutex> l(s_pendingStartMutex);
285 14 s_pendingStartFilename.clear();
286 14 break;
287 14 }
288 36517 std::function<void()> fn = std::move(tl_pendingNotifications.front());
289 36517 tl_pendingNotifications.erase(tl_pendingNotifications.begin());
290 36517 fn();
291 36515 continue;
292 36515 }
293 // Replay a deferred re-entrant start, if one was recorded.
294 421789 std::string nm;
295 int pos, rep, sched, endPos;
296 {
297 421789 std::lock_guard<std::mutex> l(s_pendingStartMutex);
298
2/2
✓ Branch 0 taken 421702 times.
✓ Branch 1 taken 87 times.
421789 if (s_pendingStartFilename.empty())
299 421702 break;
300 87 nm = s_pendingStartFilename;
301 87 s_pendingStartFilename.clear();
302 87 pos = s_pendingStartPosition;
303 87 rep = s_pendingStartRepeat;
304 87 sched = s_pendingStartScheduleEntry;
305 87 endPos = s_pendingStartEndPosition;
306
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 421702 times.
421789 }
307 87 std::shared_ptr<Playlist> cur = Player::INSTANCE.PlaylistSnapshot();
308
1/2
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
87 if (cur) {
309 // Runs at depth 0 → executes inline; its notifications land
310 // back on this queue and the loop continues.
311 87 cur->Play(nm, pos, rep, sched, endPos);
312 }
313
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 421702 times.
458391 }
314 421716 tl_drainingNotifications = false;
315 88 }
316 };
317 } // namespace
318 // The atomic members replaced plain ones in place; a plugin's inline getter
319 // built against the old header must still find the same bytes.
320 static_assert(sizeof(std::atomic<int>) == sizeof(int) && alignof(std::atomic<int>) == alignof(int));
321 static_assert(sizeof(std::atomic<time_t>) == sizeof(time_t) && alignof(std::atomic<time_t>) == alignof(time_t));
322
323 /*
324 *
325 */
326 3223 Playlist::Playlist(std::shared_ptr<Playlist> parent) :
327 3223 m_parent(parent),
328 3223 m_repeat(0),
329 3223 m_loop(0),
330 3223 m_loopCount(0),
331 3223 m_random(0),
332 3223 m_blankAtEnd(1),
333 3223 m_startTime(0),
334 3223 m_subPlaylistDepth(0),
335 3223 m_scheduleEntry(-1),
336 3223 m_forceStop(0),
337 3223 m_stopAtPos(-1),
338 3223 m_loadStartPos(-1),
339 3223 m_loadEndPos(-1),
340 3223 m_fileTime(0),
341 3223 m_configTime(0),
342 3223 m_currentSection(nullptr),
343
1/2
✓ Branch 0 taken 3223 times.
✗ Branch 1 not taken.
6446 m_currentSectionStr("New"),
344 3223 m_sectionPosition(0),
345 3223 m_startPosition(0),
346 3223 m_globalPauseBetweenSequencesMS(0),
347 3223 m_isInGlobalPause(false),
348 3223 m_shouldStartGlobalPause(false),
349 3223 m_globalPauseStartTime(0),
350
2/4
✓ Branch 0 taken 3223 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3223 times.
✗ Branch 3 not taken.
12892 m_status(FPP_STATUS_IDLE) {
351
2/2
✓ Branch 0 taken 2651 times.
✓ Branch 1 taken 572 times.
3223 if (!parent) {
352 // The resident playlist announces the player's idle state at startup.
353 // An inserted playlist must not: it is constructed mid-show, and this
354 // published status=idle and repeat=0 over MQTT and sent plugins a
355 // "stop" while the parent was still playing.
356
1/2
✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
2651 SetIdle(false);
357
1/2
✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
2651 SetRepeat(0);
358 }
359
360 // The legacy /playlist/*/set MQTT topics are registered once, in
361 // Player::Init(), and dispatched to whichever playlist is current. They
362 // used to be registered here with [this]: every inserted playlist
363 // overwrote the callback with a pointer to itself and never removed it,
364 // so once that playlist finished and was freed, the next message on those
365 // topics called into freed memory.
366 3223 }
367
368 /*
369 *
370 */
371 569 Playlist::~Playlist() {
372 569 Cleanup();
373 569 }
374
375 2082900 PlaylistStatus Playlist::getPlaylistStatus() {
376 2082900 return m_status;
377 }
378
379 // Maps each status to the exact camelCase string the code has always used for
380 // the "status"/"currentState" fields and the "status" event, plus the "paused"
381 // value the paused state never had. This is the ONLY place m_status becomes a
382 // string, which is what keeps the two from drifting. (The space-separated
383 // human names "stopping gracefully" etc. are a separate representation built
384 // from the same enum in httpAPI.cpp's status_name / Variables.cpp; those are
385 // unaffected.) FPP_STATUS_STOPPING_NOW never had a string mirror -- SetIdle()
386 // overwrites the status within the same lock hold in StopNowImpl(), so no
387 // reader observes it -- "stoppingNow" simply completes the mapping.
388 122238 const char* Playlist::PlaylistStatusToString(PlaylistStatus status) {
389
5/7
✓ Branch 0 taken 15807 times.
✓ Branch 1 taken 102425 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3984 times.
✗ Branch 6 not taken.
122238 switch (status) {
390 15807 case FPP_STATUS_IDLE:
391 15807 return "idle";
392 102425 case FPP_STATUS_PLAYLIST_PLAYING:
393 102425 return "playing";
394 16 case FPP_STATUS_STOPPING_GRACEFULLY:
395 16 return "stoppingGracefully";
396 6 case FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP:
397 6 return "stoppingAfterLoop";
398 ✗ case FPP_STATUS_STOPPING_NOW:
399 ✗ return "stoppingNow";
400 3984 case FPP_STATUS_PLAYLIST_PAUSED:
401 3984 return "paused";
402 }
403 ✗ return "idle";
404 }
405
406 /*
407 *
408 */
409 18 int Playlist::LoadJSONIntoPlaylist(std::vector<PlaylistEntryBase*>& playlistPart, const Json::Value& entries, int startPos, int& maxEntries) {
410 18 return LoadSection(playlistPart, entries, startPos, maxEntries, nullptr);
411 }
412
413 3193 int Playlist::LoadSection(std::vector<PlaylistEntryBase*>& playlistPart, const Json::Value& entries, int startPos,
414 int& maxEntries, std::vector<int>* rowStart) {
415 3193 PlaylistEntryBase* plEntry = NULL;
416
417
2/2
✓ Branch 0 taken 3175 times.
✓ Branch 1 taken 18 times.
3193 if (rowStart)
418
2/4
✓ Branch 0 taken 3175 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3175 times.
✗ Branch 3 not taken.
3175 rowStart->assign(entries.size(), -1);
419
420 3193 int c = startPos;
421
7/8
✓ Branch 0 taken 8935 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5773 times.
✓ Branch 3 taken 3162 times.
✓ Branch 4 taken 5742 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 5742 times.
✓ Branch 7 taken 3193 times.
8935 for (; (c < entries.size()) && (maxEntries > 0); c++) {
422
2/2
✓ Branch 0 taken 5725 times.
✓ Branch 1 taken 17 times.
5742 if (rowStart)
423 5725 (*rowStart)[c] = playlistPart.size();
424 // Long-term handle sub-playlists on-demand instead of at load time
425
6/10
✓ Branch 0 taken 5742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5742 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5742 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5742 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7 times.
✓ Branch 9 taken 5735 times.
5742 if (entries[c]["type"].asString() == "playlist") {
426 7 m_subPlaylistDepth++;
427
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (m_subPlaylistDepth < 5) {
428
8/16
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
18 std::string filename = FPP_DIR_PLAYLIST("/" + entries[c]["name"].asString() + ".json");
429
430
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 Json::Value subPlaylist = LoadJSON(filename);
431 6 int tmpMax = 999999;
432
433
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (subPlaylist.isMember("leadIn"))
434
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 LoadJSONIntoPlaylist(playlistPart, subPlaylist["leadIn"], 0, tmpMax);
435
436
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (subPlaylist.isMember("mainPlaylist"))
437
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 LoadJSONIntoPlaylist(playlistPart, subPlaylist["mainPlaylist"], 0, tmpMax);
438
439
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (subPlaylist.isMember("leadOut"))
440
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 LoadJSONIntoPlaylist(playlistPart, subPlaylist["leadOut"], 0, tmpMax);
441 6 } else {
442
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 LogErr(VB_PLAYLIST, "Error, recursive playlist. Sub-playlist depth exceeded 5 trying to include '%s'\n", entries[c]["name"].asString().c_str());
443
7/14
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
2 WarningHolder::AddWarningTimeout(60, 24, "Recursive playlist: sub-playlist depth exceeded trying to include '" + entries[c]["name"].asString() + "'");
444 }
445
446 7 m_subPlaylistDepth--;
447 } else {
448
3/6
✓ Branch 0 taken 5735 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5735 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5735 times.
✗ Branch 5 not taken.
5735 plEntry = LoadPlaylistEntry(entries[c]);
449
2/2
✓ Branch 0 taken 5731 times.
✓ Branch 1 taken 4 times.
5735 if (plEntry) {
450
1/2
✓ Branch 0 taken 5731 times.
✗ Branch 1 not taken.
5731 playlistPart.push_back(plEntry);
451 }
452 }
453 // An end position counts rows of the file: a sub-playlist row used not
454 // to count at all, and an entry that failed to load let one more in.
455 5742 maxEntries--;
456 }
457
2/2
✓ Branch 0 taken 3175 times.
✓ Branch 1 taken 18 times.
3193 if (rowStart) {
458 // Rows past an end position start where the section ends.
459
3/4
✓ Branch 0 taken 3281 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✓ Branch 3 taken 3175 times.
3281 for (; c < entries.size(); c++)
460 106 (*rowStart)[c] = playlistPart.size();
461 }
462
463 3193 return 1;
464 }
465
466 /*
467 *
468 */
469 2267 int Playlist::Load(Json::Value& config) {
470
1/2
✓ Branch 0 taken 2267 times.
✗ Branch 1 not taken.
2267 LogDebug(VB_PLAYLIST, "Playlist::Load(JSON)\n");
471
472 // Everything is parsed into locals and only committed once the whole
473 // config has been read. jsoncpp throws on a wrong-typed value ("repeat":
474 // "1", a section that is an object, ...), and this runs from Process()
475 // when a playing playlist's file is edited (ReloadIfNeeded) with nothing
476 // above it to catch -- that terminated fppd mid-show. Cleaning up first,
477 // as this used to, also meant any failure left a half-loaded playlist in
478 // place of the running one.
479 2267 std::string name;
480 2267 std::string desc;
481 2267 int repeat = 0;
482 2267 int loopCount = 0;
483 2267 int globalPauseMS = 0;
484 2267 int random = 0;
485
1/2
✓ Branch 0 taken 2267 times.
✗ Branch 1 not taken.
2267 Json::Value playlistInfo;
486 2267 std::vector<PlaylistEntryBase*> leadIn;
487 2267 std::vector<PlaylistEntryBase*> mainPlaylist;
488 2267 std::vector<PlaylistEntryBase*> leadOut;
489 2267 std::vector<int> leadInRows;
490 2267 std::vector<int> mainRows;
491 2267 std::vector<int> leadOutRows;
492
493 try {
494
3/4
✓ Branch 0 taken 2267 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2261 times.
✓ Branch 3 taken 6 times.
2267 if (config.isMember("name"))
495
2/4
✓ Branch 0 taken 2261 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2261 times.
✗ Branch 3 not taken.
2261 name = config["name"].asString();
496
497
3/4
✓ Branch 0 taken 2267 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2264 times.
2267 if (config.isMember("desc"))
498
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 desc = config["desc"].asString();
499
500
3/4
✓ Branch 0 taken 2267 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2265 times.
✓ Branch 3 taken 2 times.
2267 repeat = config["repeat"].asInt();
501
2/4
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2265 times.
✗ Branch 3 not taken.
2265 loopCount = config["loopCount"].asInt();
502 2265 m_subPlaylistDepth = 0;
503
504 // Load global pause between sequences configuration
505
3/4
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2260 times.
2265 if (config.isMember("globalPauseBetweenSequencesMS"))
506
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 globalPauseMS = config["globalPauseBetweenSequencesMS"].asInt();
507
508
2/4
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2265 times.
✗ Branch 3 not taken.
2265 playlistInfo = config["playlistInfo"];
509
510 2265 int startPos = 0;
511 2265 int maxEntries = 999999;
512 2265 int origEntryCount = 0;
513
514
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 2227 times.
2265 if (m_loadEndPos >= 0) {
515 38 maxEntries = m_loadEndPos + 1 - ((m_loadStartPos >= 0) ? m_loadStartPos : 0);
516 }
517
518 // Start -2 / end 0 asks for one random main-playlist item (Insert
519 // Random Item From Playlist). The lead-in and lead-out are not part of
520 // the pick: the lead-in used to load first and take the single slot, so
521 // a playlist with a lead-in always "randomly" played its first lead-in
522 // item.
523
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2247 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
2265 bool randomSingle = (m_loadStartPos == -2) && (m_loadEndPos == 0);
524
525
11/14
✓ Branch 0 taken 2247 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 2247 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2216 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 2216 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2216 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 901 times.
✓ Branch 11 taken 1315 times.
✓ Branch 12 taken 901 times.
✓ Branch 13 taken 1364 times.
2265 if (!randomSingle && config.isMember("leadIn") && config["leadIn"].size()) {
526
1/2
✓ Branch 0 taken 901 times.
✗ Branch 1 not taken.
901 LogDebug(VB_PLAYLIST, "Loading LeadIn:\n");
527
2/4
✓ Branch 0 taken 901 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 901 times.
✗ Branch 3 not taken.
901 const Json::Value leadInCfg = config["leadIn"];
528
529
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 883 times.
901 if (m_loadStartPos >= 0)
530 18 startPos = m_loadStartPos;
531 else
532 883 startPos = 0;
533
534
2/4
✓ Branch 0 taken 901 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 901 times.
✗ Branch 3 not taken.
901 leadInRows.assign(leadInCfg.size(), -1);
535
2/4
✓ Branch 0 taken 901 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 901 times.
✗ Branch 3 not taken.
901 if (startPos < leadInCfg.size())
536
1/2
✓ Branch 0 taken 901 times.
✗ Branch 1 not taken.
901 LoadSection(leadIn, leadInCfg, startPos, maxEntries, &leadInRows);
537
538
1/2
✓ Branch 0 taken 901 times.
✗ Branch 1 not taken.
901 origEntryCount += leadInCfg.size();
539 901 }
540
541
9/12
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2259 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 2259 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2259 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2254 times.
✓ Branch 9 taken 5 times.
✓ Branch 10 taken 2254 times.
✓ Branch 11 taken 11 times.
2265 if (config.isMember("mainPlaylist") && config["mainPlaylist"].size()) {
542
1/2
✓ Branch 0 taken 2254 times.
✗ Branch 1 not taken.
2254 LogDebug(VB_PLAYLIST, "Loading MainPlaylist:\n");
543
2/4
✓ Branch 0 taken 2254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2254 times.
✗ Branch 3 not taken.
2254 const Json::Value playlist = config["mainPlaylist"];
544
545
4/4
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 2078 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 173 times.
2254 if ((m_loadStartPos >= 0) && (m_loadStartPos > origEntryCount)) {
546 3 startPos = m_loadStartPos - origEntryCount;
547
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2233 times.
2251 } else if (randomSingle) {
548 // random single item
549
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 int l = playlist.size();
550
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 times.
18 if (l > 1) {
551
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 startPos = FPPrand() % l;
552 17 maxEntries = 1;
553 }
554 } else {
555 2233 startPos = 0;
556 }
557
558
2/4
✓ Branch 0 taken 2254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2254 times.
✗ Branch 3 not taken.
2254 mainRows.assign(playlist.size(), -1);
559
2/4
✓ Branch 0 taken 2254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2254 times.
✗ Branch 3 not taken.
2254 if (startPos < playlist.size()) {
560
1/2
✓ Branch 0 taken 2254 times.
✗ Branch 1 not taken.
2254 LoadSection(mainPlaylist, playlist, startPos, maxEntries, &mainRows);
561 }
562
563
1/2
✓ Branch 0 taken 2254 times.
✗ Branch 1 not taken.
2254 origEntryCount += playlist.size();
564 2254 }
565
566
11/14
✓ Branch 0 taken 2247 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 2247 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2216 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 2216 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2216 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 20 times.
✓ Branch 11 taken 2196 times.
✓ Branch 12 taken 20 times.
✓ Branch 13 taken 2245 times.
2265 if (!randomSingle && config.isMember("leadOut") && config["leadOut"].size()) {
567
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 LogDebug(VB_PLAYLIST, "Loading LeadOut:\n");
568
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 const Json::Value leadOutCfg = config["leadOut"];
569
570
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
20 if ((m_loadStartPos >= 0) && (m_loadStartPos > origEntryCount))
571 ✗ startPos = m_loadStartPos - origEntryCount;
572 else
573 20 startPos = 0;
574
575
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 leadOutRows.assign(leadOutCfg.size(), -1);
576
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 if (startPos < leadOutCfg.size())
577
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 LoadSection(leadOut, leadOutCfg, startPos, maxEntries, &leadOutRows);
578 20 }
579
580 // Sections skipped above still count their rows.
581
7/8
✓ Branch 0 taken 1364 times.
✓ Branch 1 taken 901 times.
✓ Branch 2 taken 1364 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1333 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 1333 times.
✓ Branch 7 taken 932 times.
2265 if (leadInRows.empty() && config.isMember("leadIn"))
582
3/6
✓ Branch 0 taken 1333 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1333 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1333 times.
✗ Branch 5 not taken.
1333 leadInRows.assign(config["leadIn"].size(), -1);
583
7/8
✓ Branch 0 taken 2245 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 2245 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2214 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 2214 times.
✓ Branch 7 taken 51 times.
2265 if (leadOutRows.empty() && config.isMember("leadOut"))
584
3/6
✓ Branch 0 taken 2214 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2214 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2214 times.
✗ Branch 5 not taken.
2214 leadOutRows.assign(config["leadOut"].size(), -1);
585
586
3/4
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✓ Branch 3 taken 2159 times.
2265 if (config.isMember("random")) {
587
2/4
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
106 random = PlaylistRandomSetting(config["random"]);
588 }
589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } catch (const std::exception& ex) {
590
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
2 std::string warn = "Playlist " + (name.empty() ? m_filename : name) + " is invalid: " + ex.what();
591
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogErr(VB_PLAYLIST, "%s\n", warn.c_str());
592
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 WarningHolder::AddWarningTimeout(60, 24, warn);
593 // Entries built before the throw were never published; retire them
594 // the same way Cleanup() does (destroyed on the main thread).
595
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
596
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (auto* section : { &leadIn, &mainPlaylist, &leadOut }) {
597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 for (auto* e : *section) {
598 ✗ PL_ENTRY_CLEANUPS.push_back(e);
599 }
600 }
601 2 return 0;
602 2 }
603
604
1/2
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
2265 Cleanup();
605
606 {
607
1/2
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
2265 std::lock_guard<std::mutex> nl(m_nameLock);
608
1/2
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
2265 m_name = name;
609 2265 }
610
1/2
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
2265 m_desc = desc;
611 2265 m_repeat = repeat;
612 2265 m_loopCount = loopCount;
613 2265 m_globalPauseBetweenSequencesMS = globalPauseMS;
614
1/2
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
2265 m_playlistInfo = playlistInfo;
615 2265 m_random = random;
616 2265 m_leadIn.swap(leadIn);
617 2265 m_mainPlaylist.swap(mainPlaylist);
618 2265 m_leadOut.swap(leadOut);
619 2265 m_leadInRows.swap(leadInRows);
620 2265 m_mainRows.swap(mainRows);
621 2265 m_leadOutRows.swap(leadOutRows);
622
623 // set the positions prior to any randomizations
624 2265 int curPos = 0;
625
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 2265 times.
3176 for (auto& a : m_leadIn) {
626 911 a->SetPositionInPlaylist(curPos);
627 911 ++curPos;
628 }
629
2/2
✓ Branch 0 taken 4798 times.
✓ Branch 1 taken 2265 times.
7063 for (auto& a : m_mainPlaylist) {
630 4798 a->SetPositionInPlaylist(curPos);
631 4798 ++curPos;
632 }
633
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2265 times.
2287 for (auto& a : m_leadOut) {
634 22 a->SetPositionInPlaylist(curPos);
635 22 ++curPos;
636 }
637
638 2265 m_sectionPosition = 0;
639 2265 m_currentSection = nullptr;
640
641
3/4
✓ Branch 0 taken 2265 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2263 times.
2265 if (WillLog(LOG_DEBUG, VB_PLAYLIST))
642
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Dump();
643
644 2265 return 1;
645 2267 }
646
647 /*
648 *
649 */
650 2262 Json::Value Playlist::LoadJSON(const std::string& filename) {
651
1/2
✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
2262 LogDebug(VB_PLAYLIST, "Playlist::LoadJSON(%s)\n", filename.c_str());
652
653
1/2
✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
2262 Json::Value root;
654
655
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2262 times.
2262 if (filename.empty()) {
656 ✗ LogErr(VB_PLAYLIST, "Playlist::LoadJSON() called with empty filename\n");
657 ✗ return root;
658 }
659
660
3/4
✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 2254 times.
2262 if (!LoadJsonFromFile(filename, root, JsonRoot::Object)) {
661
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 std::string warn = "Could not load playlist ";
662
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 warn += filename;
663
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 WarningHolder::AddWarningTimeout(30, 24, warn);
664
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 LogErr(VB_PLAYLIST, "Error loading %s\n", filename.c_str());
665 // Signal load failure with a null root. LoadJsonFromFile normalizes a
666 // failure to an empty object, which is indistinguishable from a valid
667 // but empty playlist -- returning null instead lets ReloadPlaylist tell
668 // "file missing / half-written / unparseable" (null) apart from "a real
669 // playlist that happens to be empty" (a parsed object), so a transient
670 // read failure can't Cleanup() a playing show. Callers that treat this
671 // as an empty playlist (isMember checks, Load()) behave as before: a
672 // null Json::Value reports no members and loads nothing.
673
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 return Json::Value();
674 8 }
675
676
2/2
✓ Branch 0 taken 2242 times.
✓ Branch 1 taken 12 times.
2254 if (m_filename == filename) {
677 // stat() can fail (the file replaced between the read and here); its
678 // st_mtime is then uninitialized, so leave m_fileTime as it was rather
679 // than copying garbage into the reload check.
680 struct stat attr;
681
2/2
✓ Branch 0 taken 2240 times.
✓ Branch 1 taken 2 times.
2242 if (stat(filename.c_str(), &attr) == 0) {
682 char timeBuf[32];
683
1/2
✓ Branch 0 taken 2240 times.
✗ Branch 1 not taken.
2240 LogDebug(VB_PLAYLIST, "Playlist Last Modified: %s\n", ctime_r(&attr.st_mtime, timeBuf));
684
685 2240 m_fileTime = attr.st_mtime;
686 }
687 }
688
689 2254 return root;
690 2262 }
691
692 3 std::string sanitizeMediaName(std::string mediaName) {
693
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 LogDebug(VB_PLAYLIST, "Searching for Media File (%s)\n", mediaName.c_str());
694 // Same regex as PHP's sanitizeFilename
695
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 RegExCache rec("([^\\w\\s\\d\\-_~,;\\[\\]\\(\\).])");
696 // Check raw format for older Music uploads
697
4/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 std::string tmpMedia = FPP_DIR_MUSIC("/" + mediaName);
698
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 std::string tmpMedialClean = std::regex_replace(mediaName, *rec.regex, "");
699
700
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 LogDebug(VB_PLAYLIST, "SanitizeMedia: Checking Raw Music (%s)\n", tmpMedia.c_str());
701
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if (FileExists(tmpMedia)) {
702 1 return mediaName;
703 }
704
705 // Try Cleaned Music
706
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
2 tmpMedia = FPP_DIR_MUSIC("/" + tmpMedialClean);
707
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogDebug(VB_PLAYLIST, "SanitizeMedia: Checking Cleaned Music (%s)\n", tmpMedia.c_str());
708
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if (FileExists(tmpMedia)) {
709 1 return tmpMedialClean;
710 }
711
712 // Try Older (orginal) Video upload
713
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 tmpMedia = FPP_DIR_VIDEO("/" + mediaName);
714
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogDebug(VB_PLAYLIST, "SanitizeMedia: Checking Raw Video (%s)\n", tmpMedia.c_str());
715
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (FileExists(tmpMedia)) {
716 ✗ return mediaName;
717 }
718
719 // Try cleaned video file
720
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 tmpMedia = FPP_DIR_VIDEO("/" + tmpMedialClean);
721
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogDebug(VB_PLAYLIST, "SanitizeMedia: Checking Clean Video (%s)\n", tmpMedia.c_str());
722
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (FileExists(tmpMedia)) {
723 ✗ return tmpMedialClean;
724 }
725
726
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogWarn(VB_PLAYLIST, "SanitizeMedia: Unable to find Media: (%s)\n", mediaName.c_str());
727
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 tmpMedia = "";
728 1 return tmpMedia;
729 3 }
730
731 /*
732 *
733 */
734 2256 int Playlist::Load(const std::string& filename) {
735 2256 LogDebug(VB_PLAYLIST, "Playlist::Load(%s)\n", filename.c_str());
736
737
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2256 times.
2256 if (filename.empty()) {
738 ✗ LogErr(VB_PLAYLIST, "Playlist::Load() called with empty filename\n");
739 ✗ return 0;
740 }
741
742
2/4
✓ Branch 0 taken 2256 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2256 times.
✗ Branch 3 not taken.
2256 Events::Publish("playlist/name/status", filename);
743
744 try {
745
1/2
✓ Branch 0 taken 2256 times.
✗ Branch 1 not taken.
2256 Json::Value root;
746
1/2
✓ Branch 0 taken 2256 times.
✗ Branch 1 not taken.
2256 std::string tmpFilename = filename;
747
748
1/2
✓ Branch 0 taken 2256 times.
✗ Branch 1 not taken.
2256 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
749
750 // Whether this load synthesizes a one-entry playlist from a bare
751 // media file rather than loading a saved .json playlist. Captured
752 // here from the branch taken (a saved playlist could itself be named
753 // "something.fseq", so the filename alone cannot decide below).
754 2256 bool generated = false;
755
4/6
✓ Branch 0 taken 2256 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2256 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 2238 times.
4512 if (endsWith(tmpFilename, ".fseq")) {
756 18 generated = true;
757
4/8
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
18 m_filename = FPP_DIR_SEQUENCE("/" + tmpFilename);
758
759
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 root["name"] = tmpFilename;
760
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 root["repeat"] = 0;
761
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 root["loopCount"] = 0;
762
763 18 std::string mediaName;
764
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 FSEQFile* src = FSEQFile::openFSEQFile(m_filename);
765
6/6
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 5 times.
18 if (src && !src->getVariableHeaders().empty()) {
766
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 13 times.
33 for (auto& head : src->getVariableHeaders()) {
767
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
20 if ((head.code[0] == 'm') && (head.code[1] == 'f')) {
768
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 const auto& data = head.getData();
769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (data.empty()) {
770 ✗ continue;
771 }
772 3 const char* d = (const char*)data.data();
773 3 size_t len = strnlen(d, data.size());
774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (len == 0) {
775 ✗ continue;
776 }
777
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 std::string raw(d, len);
778 3 size_t pos = raw.find_last_of("/\\");
779
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (pos == std::string::npos) {
780
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 mediaName = raw;
781 } else {
782
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 mediaName = raw.substr(pos + 1);
783 }
784
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::string tmpMedia = sanitizeMediaName(mediaName);
785
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if (tmpMedia == "") {
786
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 std::string warn = "fseq \"" + tmpFilename + "\" lists a media file of \"" + mediaName + "\" but it can not be found";
787
788
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 WarningHolder::AddWarningTimeout(60, 24, warn);
789
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogDebug(VB_PLAYLIST, "%s\n", warn.c_str());
790
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 mediaName = "";
791 1 }
792 // Set the Media to the correct name
793
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 mediaName = tmpMedia;
794 3 }
795 }
796 }
797
798
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 times.
18 if (src)
799
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 delete src;
800
801
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 Json::Value mp(Json::arrayValue);
802
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 Json::Value pe;
803
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 if (mediaName.empty()) {
804
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 pe["type"] = "sequence";
805
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 LogDebug(VB_PLAYLIST, "Generated an on-the-fly playlist for %s\n", tmpFilename.c_str());
806 } else {
807
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 pe["type"] = "both";
808
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 pe["mediaName"] = mediaName;
809
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogDebug(VB_PLAYLIST, "Generated an on-the-fly playlist for %s/%s\n", tmpFilename.c_str(), mediaName.c_str());
810 }
811
812
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 pe["enabled"] = 1;
813
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 pe["playOnce"] = 0;
814
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 pe["sequenceName"] = tmpFilename;
815
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 pe["videoOut"] = "--Default--";
816
817
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 mp.append(pe);
818
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 root["mainPlaylist"] = mp;
819
820 18 } else {
821
13/22
✓ Branch 0 taken 2238 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2238 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2234 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 2234 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2234 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 2233 times.
✓ Branch 12 taken 2234 times.
✓ Branch 13 taken 4 times.
✓ Branch 14 taken 2238 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5 times.
✓ Branch 17 taken 2233 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
2238 if (IsExtensionAudio(GetFileExtension(tmpFilename)) || IsExtensionVideo(GetFileExtension(tmpFilename))) {
822 5 generated = true;
823
4/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 1 times.
5 if (IsExtensionAudio(GetFileExtension(tmpFilename)))
824
4/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
8 m_filename = FPP_DIR_MUSIC("/" + filename);
825 else
826
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
2 m_filename = FPP_DIR_VIDEO("/" + filename);
827
828
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 root["name"] = tmpFilename;
829
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 root["repeat"] = 0;
830
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 root["loopCount"] = 0;
831
832
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 Json::Value mp(Json::arrayValue);
833
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 Json::Value pe;
834
835
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 pe["type"] = "media";
836
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 pe["mediaName"] = tmpFilename;
837
838
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 LogDebug(VB_PLAYLIST, "Generated an on-the-fly playlist for %s\n", tmpFilename.c_str());
839
840
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 pe["enabled"] = 1;
841
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 pe["playOnce"] = 0;
842
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 pe["videoOut"] = "--Default--";
843
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 mp.append(pe);
844
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 root["mainPlaylist"] = mp;
845
846 5 } else {
847
5/10
✓ Branch 0 taken 2233 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2233 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2233 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2233 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2233 times.
✗ Branch 9 not taken.
2233 m_filename = FPP_DIR_PLAYLIST("/" + filename + ".json");
848
1/2
✓ Branch 0 taken 2233 times.
✗ Branch 1 not taken.
2233 root = LoadJSON(m_filename);
849 }
850 }
851
1/2
✓ Branch 0 taken 2256 times.
✗ Branch 1 not taken.
2256 int rc = Load(root);
852 // NB: Load(Json) runs Cleanup() first, which resets
853 // m_generatedOnTheFly, so the flag captured from the branch above
854 // has to be (re)asserted here, after the load.
855 2256 m_generatedOnTheFly = generated;
856 2256 return rc;
857
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2256 } catch (std::exception& er) {
858 ✗ std::string warn = "Playlist " + GetPlaylistName() + " is invalid: " + er.what();
859 ✗ LogWarn(VB_PLAYLIST, "%s\n", warn.c_str());
860 ✗ WarningHolder::AddWarningTimeout(60, 24, warn);
861 ✗ return 0;
862 ✗ }
863 }
864
865 /*
866 *
867 */
868 5735 PlaylistEntryBase* Playlist::LoadPlaylistEntry(Json::Value entry) {
869 5735 PlaylistEntryBase* result = NULL;
870
871 // jsoncpp throws on a wrong-typed value ("enabled":"1", an entry that is
872 // not an object, ...). Contain it here, the one place every entry is
873 // built: nothing above this catches on the reload-from-Process() path, so
874 // an escaped exception terminated fppd mid-show.
875 try {
876
2/4
✓ Branch 0 taken 5735 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5735 times.
✗ Branch 3 not taken.
5735 std::string type = entry["type"].asString();
877
3/4
✓ Branch 0 taken 5735 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 5663 times.
5735 if (type == "both")
878
3/8
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 72 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
72 result = new PlaylistEntryBoth(this);
879
3/4
✓ Branch 0 taken 5663 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 5636 times.
5663 else if (type == "branch")
880
3/8
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 27 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
27 result = new PlaylistEntryBranch(this);
881
3/4
✓ Branch 0 taken 5636 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 5610 times.
5636 else if (type == "dynamic")
882
3/8
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
26 result = new PlaylistEntryDynamic(this);
883
3/4
✓ Branch 0 taken 5610 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 352 times.
✓ Branch 3 taken 5258 times.
5610 else if (type == "image")
884
3/8
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 352 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 352 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
352 result = new PlaylistEntryImage(this);
885
3/4
✓ Branch 0 taken 5258 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135 times.
✓ Branch 3 taken 5123 times.
5258 else if (type == "media")
886
3/8
✓ Branch 0 taken 135 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 135 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
135 result = new PlaylistEntryMedia(this);
887
3/4
✓ Branch 0 taken 5123 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1079 times.
✓ Branch 3 taken 4044 times.
5123 else if (type == "pause")
888
3/8
✓ Branch 0 taken 1079 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1079 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1079 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1079 result = new PlaylistEntryPause(this);
889
2/4
✓ Branch 0 taken 4044 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4044 times.
4044 else if (type == "playlist")
890 ✗ result = new PlaylistEntryPlaylist(this);
891
3/4
✓ Branch 0 taken 4044 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4040 times.
4044 else if (type == "remap")
892
3/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
4 result = new PlaylistEntryRemap(this);
893
3/4
✓ Branch 0 taken 4040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 4015 times.
4040 else if (type == "script")
894
3/8
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 25 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
25 result = new PlaylistEntryScript(this);
895
3/4
✓ Branch 0 taken 4015 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 685 times.
✓ Branch 3 taken 3330 times.
4015 else if (type == "sequence")
896
3/8
✓ Branch 0 taken 685 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 685 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 685 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
685 result = new PlaylistEntrySequence(this);
897
3/4
✓ Branch 0 taken 3330 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 3310 times.
3330 else if (type == "url")
898
3/8
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
20 result = new PlaylistEntryURL(this);
899
3/4
✓ Branch 0 taken 3310 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3308 times.
✓ Branch 3 taken 2 times.
3310 else if (type == "command")
900
3/8
✓ Branch 0 taken 3308 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3308 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3308 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3308 result = new PlaylistEntryCommand(this);
901 else {
902
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogErr(VB_PLAYLIST, "Unknown Playlist Entry Type: %s\n", type.c_str());
903
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 WarningHolder::AddWarningTimeout(60, 24, "Unknown playlist entry type: " + type);
904 2 return NULL;
905 }
906
907
4/4
✓ Branch 0 taken 5732 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5731 times.
✓ Branch 3 taken 1 times.
5733 if (result->Init(entry))
908 5731 return result;
909
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5733 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
5736 } catch (const std::exception& ex) {
910
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogErr(VB_PLAYLIST, "Invalid playlist entry, skipping it: %s\n", ex.what());
911
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
3 WarningHolder::AddWarningTimeout(60, 24, std::string("Invalid playlist entry skipped: ") + ex.what());
912 1 }
913
914 // Init failed or threw: the entry was never handed to a caller, so this is
915 // its only owner and it must be destroyed here rather than leaked.
916
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 delete result;
917 2 return NULL;
918 }
919
920 /*
921 *
922 */
923 12 int Playlist::ReloadPlaylist(void) {
924
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 LogDebug(VB_PLAYLIST, "Playlist::ReloadPlaylist()\n");
925
926
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if (m_filename == "") {
927 ✗ LogErr(VB_PLAYLIST, "Playlist::ReloadPlaylist() called but m_filename is empty\n");
928 ✗ return 0;
929 }
930
931
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
932
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 std::string currentSectionStr = m_currentSectionStr;
933 12 int repeat = m_repeat;
934 12 int loopCount = m_loopCount;
935 12 long long startTime = m_startTime;
936
937
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 Json::Value root = LoadJSON(m_filename);
938
939 // Invariant: a reload must never replace a playing playlist with nothing.
940 // LoadJSON returns a null root when the file is missing, half-written, or
941 // unparseable (a non-atomic UI save leaves a brief window where a reload
942 // was already triggered). Load() would Cleanup() the running playlist and
943 // then load an empty one, silently stopping the show. Bail here instead so
944 // ReloadIfNeeded takes its "continuing with existing copy" path and keeps
945 // the current playlist. A genuinely empty playlist still parses to an
946 // object (not null), so a real reload -- even to an empty playlist -- works.
947
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11 times.
12 if (root.isNull()) {
948
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogErr(VB_PLAYLIST, "Playlist::ReloadPlaylist() got no usable playlist from %s; keeping the running playlist\n", m_filename.c_str());
949 1 return 0;
950 }
951
952
3/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9 times.
11 if (!Load(root))
953 2 return 0;
954
955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (m_random > 0) {
956 ✗ RandomizeMainPlaylist();
957 }
958
959 9 m_repeat = repeat;
960 9 m_loopCount = loopCount;
961 9 m_startTime = startTime;
962 9 m_sectionPosition = 0;
963
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 m_currentSectionStr = "MainPlaylist";
964 9 m_currentSection = &m_mainPlaylist;
965
966 9 return 1;
967 12 }
968
969 /*
970 *
971 */
972 2014 void Playlist::ReloadIfNeeded(void) {
973
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2002 times.
2014 if (FileHasBeenModified()) {
974 12 m_nextShuffle.clear();
975 12 LogDebug(VB_PLAYLIST, "Playlist .json file has been modified, reloading playlist\n");
976
977
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
12 if (!ReloadPlaylist())
978 3 LogErr(VB_PLAYLIST, "Error reloading playlist, continuing with existing copy.");
979 }
980 2014 }
981
982 /*
983 *
984 */
985 1993 void Playlist::SwitchToMainPlaylist(void) {
986
1/2
✓ Branch 0 taken 1993 times.
✗ Branch 1 not taken.
1993 LogDebug(VB_PLAYLIST, "Switching to MainPlaylist\n");
987
988
1/2
✓ Branch 0 taken 1993 times.
✗ Branch 1 not taken.
1993 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
989
1/2
✓ Branch 0 taken 1993 times.
✗ Branch 1 not taken.
1993 UpdateCrashSnapshot();
990
991 // A caller's "does this section have entries" test can be invalidated
992 // before we get here: ReloadIfNeeded() runs Cleanup(), which pops every
993 // entry into PL_ENTRY_CLEANUPS and then reloads from the file, so a
994 // playlist edited mid-play can come back without this section. The
995 // vector is empty but keeps its capacity, so [0] hands back a stale
996 // pointer to an entry that Process() is about to delete -- the vtable is
997 // still mapped, the virtual call dispatches, and the fault lands inside
998 // StartPlaying(). Check here, at the one place the section is indexed,
999 // rather than at each call site.
1000
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1992 times.
1993 if (m_mainPlaylist.empty()) {
1001
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogDebug(VB_PLAYLIST, "MainPlaylist is empty, switching to idle.\n");
1002
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 SetIdle();
1003 1 return;
1004 }
1005
1006
1/2
✓ Branch 0 taken 1992 times.
✗ Branch 1 not taken.
1992 m_currentSectionStr = "MainPlaylist";
1007 1992 m_currentSection = &m_mainPlaylist;
1008 1992 m_sectionPosition = 0;
1009
6/8
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 1963 times.
✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 29 times.
✓ Branch 7 taken 1963 times.
1992 if (m_loopHoldUntilMS && GetMonotonicTimeMS() < m_loopHoldUntilMS) {
1010 // Process() starts it when the hold runs out.
1011 29 return;
1012 }
1013 1963 m_loopHoldUntilMS = 0;
1014
1/2
✓ Branch 0 taken 1963 times.
✗ Branch 1 not taken.
1963 m_loopStartMS = GetMonotonicTimeMS();
1015
1/2
✓ Branch 0 taken 1963 times.
✗ Branch 1 not taken.
1963 StartPlayingWithGlobalPause(m_mainPlaylist[0]);
1016
2/2
✓ Branch 0 taken 1963 times.
✓ Branch 1 taken 30 times.
1993 }
1017
1018 /*
1019 *
1020 */
1021 10 void Playlist::SwitchToLeadOut(void) {
1022
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 LogDebug(VB_PLAYLIST, "Switching to LeadOut\n");
1023
1024
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1025
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 UpdateCrashSnapshot();
1026
1027 // See SwitchToMainPlaylist() -- a reload between the caller's size check
1028 // and here can leave this section empty.
1029
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if (m_leadOut.empty()) {
1030
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogDebug(VB_PLAYLIST, "LeadOut is empty, switching to idle.\n");
1031
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 SetIdle();
1032 2 return;
1033 }
1034
1035
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 m_currentSectionStr = "LeadOut";
1036 8 m_currentSection = &m_leadOut;
1037 8 m_sectionPosition = 0;
1038 // A hold is for the next main pass only; one still set here would
1039 // restart this lead-out entry when it ran out.
1040 8 m_loopHoldUntilMS = 0;
1041
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 StartPlayingWithGlobalPause(m_leadOut[0]);
1042
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
10 }
1043
1044 /*
1045 *
1046 */
1047 26783 int Playlist::Start(void) {
1048 // Name it here rather than leaving that to the per-entry Init() lines
1049 // below: this is the line the crash-time log ring is read from first, and
1050 // "which playlist" is the question it is read to answer.
1051
2/4
✓ Branch 0 taken 26783 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26783 times.
✗ Branch 3 not taken.
26783 LogDebug(VB_PLAYLIST, "Playlist::Start(%s)\n", GetPlaylistName().c_str());
1052
1053 26783 PlaylistTransitionGuard guard;
1054
1/2
✓ Branch 0 taken 26783 times.
✗ Branch 1 not taken.
26783 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1055
1056
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1483 times.
28274 if ((!m_leadIn.size()) &&
1057
5/6
✓ Branch 0 taken 1491 times.
✓ Branch 1 taken 25292 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 26775 times.
28274 (!m_mainPlaylist.size()) &&
1058 8 (!m_leadOut.size())) {
1059
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
8 std::string warn = "Playlist " + GetPlaylistName() + " is empty. Nothing to play.";
1060
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 WarningHolder::AddWarningTimeout(30, 24, warn);
1061
1062
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 SetIdle();
1063 8 return 0;
1064 8 }
1065
1066 // Capture the pre-start status before we flip to PLAYING: the callback
1067 // below distinguishes a fresh start from a restart of an already-playing
1068 // playlist.
1069 26775 PlaylistStatus origStatus = m_status;
1070 26775 m_status = FPP_STATUS_PLAYLIST_PLAYING;
1071
1072
1/2
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
26775 m_startTime = GetTime();
1073 26775 m_loop = 0;
1074 26775 m_forceStop = 0;
1075 // Also cleared by Cleanup(); repeated for the restart-in-place path,
1076 // which starts again without cleaning up.
1077 26775 m_isInGlobalPause = false;
1078 26775 m_shouldStartGlobalPause = false;
1079 26775 m_loopHoldUntilMS = 0;
1080
1081
1/2
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
26775 LogDebug(VB_PLAYLIST, "============================================================================\n");
1082
1083
2/2
✓ Branch 0 taken 24435 times.
✓ Branch 1 taken 2340 times.
26775 if (m_startPosition > 0) {
1084
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24435 times.
24435 if (m_startPosition >= (m_leadIn.size() + m_mainPlaylist.size() + m_leadOut.size()))
1085 ✗ m_startPosition = 0;
1086
1087
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24434 times.
24435 if (m_startPosition >= (m_leadIn.size() + m_mainPlaylist.size())) {
1088 1 m_sectionPosition = m_startPosition - (m_leadIn.size() + m_mainPlaylist.size());
1089
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 m_currentSectionStr = "LeadOut";
1090 1 m_currentSection = &m_leadOut;
1091
1/2
✓ Branch 0 taken 24434 times.
✗ Branch 1 not taken.
24434 } else if (m_startPosition >= m_leadIn.size()) {
1092 24434 m_sectionPosition = m_startPosition - m_leadIn.size();
1093
1/2
✓ Branch 0 taken 24434 times.
✗ Branch 1 not taken.
24434 m_currentSectionStr = "MainPlaylist";
1094 24434 m_currentSection = &m_mainPlaylist;
1095 } else {
1096 ✗ m_sectionPosition = m_startPosition;
1097 ✗ m_currentSectionStr = "LeadIn";
1098 ✗ m_currentSection = &m_leadIn;
1099 }
1100 } else {
1101
2/2
✓ Branch 0 taken 861 times.
✓ Branch 1 taken 1479 times.
2340 if (m_leadIn.size()) {
1102
1/2
✓ Branch 0 taken 861 times.
✗ Branch 1 not taken.
861 m_currentSectionStr = "LeadIn";
1103 861 m_currentSection = &m_leadIn;
1104
1/2
✓ Branch 0 taken 1479 times.
✗ Branch 1 not taken.
1479 } else if (m_mainPlaylist.size()) {
1105
1/2
✓ Branch 0 taken 1479 times.
✗ Branch 1 not taken.
1479 m_currentSectionStr = "MainPlaylist";
1106 1479 m_currentSection = &m_mainPlaylist;
1107 } else { // must be only lead Out
1108 ✗ m_currentSectionStr = "LeadOut";
1109 ✗ m_currentSection = &m_leadOut;
1110 }
1111
1112 2340 m_sectionPosition = 0;
1113 }
1114
1115 {
1116 // Deferred — plugin callbacks run arbitrary code inline; snapshot the
1117 // state now, deliver after the transition completes (see
1118 // PlaylistTransitionGuard).
1119
1/2
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
26775 Json::Value info = GetInfo();
1120
3/4
✓ Branch 0 taken 24538 times.
✓ Branch 1 taken 2237 times.
✓ Branch 2 taken 26775 times.
✗ Branch 3 not taken.
26813 std::string action = (origStatus == FPP_STATUS_PLAYLIST_PLAYING) ? "playing" : "start";
1121
1/2
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
26775 std::string sec = m_currentSectionStr;
1122 26775 int pos = m_sectionPosition;
1123
5/16
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26775 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 26775 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 26775 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 26775 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
26775 QueuePlaylistNotification([info, action, sec, pos]() {
1124 26767 PluginManager::INSTANCE.playlistCallback(info, action, sec, pos);
1125
2/2
✓ Branch 0 taken 2236 times.
✓ Branch 1 taken 24531 times.
26767 if (action == "start") {
1126 // "playing" is sent as each subsequent item begins, so without
1127 // this the first item is the only one never announced that way
1128 // - and a plugin listening for "playing" waits until item two,
1129 // or forever on a single-item playlist. The two are not
1130 // alternatives: "start" means the playlist began, "playing"
1131 // means an item is playing, and at item zero both are true.
1132
2/4
✓ Branch 0 taken 2236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2236 times.
✗ Branch 3 not taken.
6708 PluginManager::INSTANCE.playlistCallback(info, "playing", sec, pos);
1133 }
1134 26767 });
1135 26775 }
1136
4/8
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26775 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 26775 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 26775 times.
✗ Branch 7 not taken.
80363 Events::Publish("status", PlaylistStatusToString(m_status));
1137
2/4
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26775 times.
✗ Branch 3 not taken.
53550 Events::Publish("playlist/section/status", m_currentSectionStr);
1138
2/4
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26775 times.
✗ Branch 3 not taken.
53512 Events::Publish("playlist/sectionPosition/status", m_sectionPosition);
1139
1140
2/4
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26775 times.
✗ Branch 3 not taken.
26775 m_currentSection->at(m_sectionPosition)->StartPlayingOrFinish();
1141
1142
1/2
✓ Branch 0 taken 26775 times.
✗ Branch 1 not taken.
26775 LogDebug(VB_PLAYLIST, "Exiting Playlist::Start()\n");
1143 26775 return 1;
1144 26783 }
1145
1146 /*
1147 *
1148 */
1149 841 int Playlist::StopNow(int forceStop) {
1150 841 PlaylistTransitionGuard guard;
1151
1/2
✓ Branch 0 taken 841 times.
✗ Branch 1 not taken.
841 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1152
3/4
✓ Branch 0 taken 841 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 839 times.
841 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
1153
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 lck.unlock();
1154
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 return cur->StopNow(forceStop);
1155
2/2
✓ Branch 0 taken 839 times.
✓ Branch 1 taken 2 times.
841 }
1156
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 754 times.
839 if (m_status == FPP_STATUS_IDLE) {
1157 85 return 1;
1158 }
1159
1160
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 747 times.
754 if (tl_transitionDepth > 1) {
1161 // Re-entrant stop — e.g. a "Stop Now" (or "Start Playlist At Item",
1162 // which pre-stops) command executing from inside a playlist entry's
1163 // own StartPlaying frame. Running inline would tear the playlist
1164 // stack out from under the frames above us: with inserted (nested)
1165 // playlists, SetIdle() switches the player's current playlist to the
1166 // parent and condemns levels to PL_CLEANUPS while
1167 // SwitchToInsertedPlaylist/Start frames still reference them. Queue
1168 // it; the outermost transition drains it (before any deferred start —
1169 // queue order is preserved), targeting whatever playlist is current at
1170 // that point.
1171
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 LogDebug(VB_PLAYLIST, "Playlist::StopNow(%d) re-entrant (depth %d) — deferring until current transition completes\n",
1172 forceStop, tl_transitionDepth);
1173
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 QueuePlaylistNotification([forceStop]() {
1174
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 std::shared_ptr<Playlist> cur = Player::INSTANCE.PlaylistSnapshot();
1175
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (cur) {
1176
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 cur->StopNowImpl(forceStop);
1177 }
1178 7 });
1179 7 return 1;
1180 }
1181
1/2
✓ Branch 0 taken 747 times.
✗ Branch 1 not taken.
747 return StopNowImpl(forceStop);
1182 841 }
1183
1184 // The body of StopNow(). Called from StopNow() (non-re-entrant), from the
1185 // deferred-stop drain closure, and directly by internal orchestration
1186 // (PlayImpl's stop-before-load, Process()'s invalid-section bail-out) that
1187 // must stop inline as part of its own transition.
1188 1130 int Playlist::StopNowImpl(int forceStop) {
1189
1/2
✓ Branch 0 taken 1130 times.
✗ Branch 1 not taken.
1130 LogDebug(VB_PLAYLIST, "Playlist::StopNow(%d)\n", forceStop);
1190
1191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1130 times.
1130 if (m_status == FPP_STATUS_IDLE) {
1192 ✗ return 1;
1193 }
1194
1195 1130 PlaylistTransitionGuard guard;
1196
1197 // Stop background stream slots (2-5). Slot 1 is stopped by the current
1198 // entry's Stop() below, which sends the MultiSync media stop packet
1199 // BEFORE the (slow) pipeline teardown — stopping slot 1 here first would
1200 // delay that packet by ~0.5s and make remotes stop late (issue #2676).
1201
2/4
✓ Branch 0 taken 1130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1130 times.
✗ Branch 3 not taken.
1130 StreamSlotManager::Instance().StopBackgroundSlots();
1202
1203 1130 std::map<std::string, std::string> keywords;
1204
3/6
✓ Branch 0 taken 1130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1130 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1130 times.
✗ Branch 5 not taken.
3390 keywords["PLAYLIST_NAME"] = GetPlaylistName();
1205
4/6
✓ Branch 0 taken 1130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1130 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1129 times.
2260 if (CommandManager::INSTANCE.HasPreset("PLAYLIST_STOPPING_NOW")) {
1206 // Deferred — preset commands run inline and can re-enter the
1207 // playlist; fired after this stop completes (PlaylistTransitionGuard).
1208
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 QueuePlaylistNotification([keywords]() mutable {
1209
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 CommandManager::INSTANCE.TriggerPreset("PLAYLIST_STOPPING_NOW", keywords);
1210 1 });
1211 }
1212
1213
1/2
✓ Branch 0 taken 1130 times.
✗ Branch 1 not taken.
1130 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1214 1130 m_status = FPP_STATUS_STOPPING_NOW;
1215
1216
1/2
✓ Branch 0 taken 1130 times.
✗ Branch 1 not taken.
1130 PlaylistEntryBase* entry = CurrentEntry();
1217
7/8
✓ Branch 0 taken 1125 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1125 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1074 times.
✓ Branch 5 taken 51 times.
✓ Branch 6 taken 1074 times.
✓ Branch 7 taken 56 times.
1130 if (entry && entry->IsPlaying())
1218
1/2
✓ Branch 0 taken 1074 times.
✗ Branch 1 not taken.
1074 entry->Stop();
1219
1220 1130 m_forceStop = forceStop;
1221
1/2
✓ Branch 0 taken 1130 times.
✗ Branch 1 not taken.
1130 SetIdle();
1222
1223 1130 return 1;
1224 1130 }
1225
1226 198 void Playlist::StopNowAllLevels(int forceStop) {
1227 198 PlaylistTransitionGuard guard;
1228
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 194 times.
198 if (tl_transitionDepth > 1) {
1229 // Re-entrant, as in StopNow(): the outermost transition drains it.
1230
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 QueuePlaylistNotification([forceStop]() {
1231 4 StopNowAllLevelsImpl(forceStop);
1232 4 });
1233 4 return;
1234 }
1235
1/2
✓ Branch 0 taken 194 times.
✗ Branch 1 not taken.
194 StopNowAllLevelsImpl(forceStop);
1236
2/2
✓ Branch 0 taken 194 times.
✓ Branch 1 taken 4 times.
198 }
1237
1238 // Stopping the levels one StopNow() at a time handed back to each parent
1239 // between them: SetIdle() resumed the parent's paused entry and published
1240 // it as playing, and only the next StopNow() stopped it, so a hard stop of
1241 // an inserted playlist briefly restarted the playlist it was inserted
1242 // into. Here the levels stop inside one transition, no parent is resumed,
1243 // and the presets and callbacks of every level run once the stack is idle.
1244 282 void Playlist::StopNowAllLevelsImpl(int forceStop) {
1245 282 PlaylistTransitionGuard guard;
1246 282 bool wasStopping = tl_stoppingAllLevels;
1247 282 tl_stoppingAllLevels = true;
1248
1/2
✓ Branch 0 taken 282 times.
✗ Branch 1 not taken.
282 std::shared_ptr<Playlist> cur = Player::INSTANCE.PlaylistSnapshot();
1249
2/4
✓ Branch 0 taken 282 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 282 times.
✗ Branch 3 not taken.
282 int levels = cur ? cur->GetLevelCount() : 0;
1250
8/10
✓ Branch 0 taken 377 times.
✓ Branch 1 taken 281 times.
✓ Branch 2 taken 377 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 377 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 376 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 376 times.
✓ Branch 9 taken 282 times.
658 for (int i = 0; i < levels && cur && cur->getPlaylistStatus() != FPP_STATUS_IDLE; i++) {
1251
1/2
✓ Branch 0 taken 376 times.
✗ Branch 1 not taken.
376 cur->StopNowImpl(forceStop);
1252
1/2
✓ Branch 0 taken 376 times.
✗ Branch 1 not taken.
376 cur = Player::INSTANCE.PlaylistSnapshot();
1253 }
1254 282 tl_stoppingAllLevels = wasStopping;
1255 282 }
1256
1257 /*
1258 *
1259 */
1260 18 int Playlist::StopGracefully(int forceStop, int afterCurrentLoop) {
1261
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 LogDebug(VB_PLAYLIST, "Playlist::StopGracefully(%d, %d)\n", forceStop, afterCurrentLoop);
1262
1263 18 PlaylistTransitionGuard guard;
1264
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1265
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
1266 ✗ lck.unlock();
1267 ✗ return cur->StopGracefully(forceStop, afterCurrentLoop);
1268
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 }
1269 // Nothing to stop. Going on would set a stopping status on an idle
1270 // playlist, which nothing then clears: fppd reported "stopping
1271 // gracefully" with nothing playing.
1272
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if (m_status == FPP_STATUS_IDLE) {
1273 2 return 1;
1274 }
1275
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 return StopGracefullyImpl(forceStop, afterCurrentLoop);
1276 18 }
1277
1278 // The body of StopGracefully(), minus the is-this-current check: it walks up
1279 // the m_parent chain, and the parents of an inserted playlist are never the
1280 // current one.
1281 17 int Playlist::StopGracefullyImpl(int forceStop, int afterCurrentLoop) {
1282 17 PlaylistTransitionGuard guard;
1283
7/12
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 17 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
17 if (m_status == FPP_STATUS_PLAYLIST_PAUSED && this == Player::INSTANCE.PlaylistSnapshot().get()) {
1284 ✗ Resume();
1285 }
1286
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1287
1288 17 std::map<std::string, std::string> keywords;
1289
3/6
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✗ Branch 5 not taken.
34 keywords["PLAYLIST_NAME"] = m_name;
1290
1291
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12 times.
17 if (afterCurrentLoop) {
1292
4/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 4 times.
10 if (CommandManager::INSTANCE.HasPreset("PLAYLIST_STOPPING_AFTER_LOOP")) {
1293
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 QueuePlaylistNotification([keywords]() mutable {
1294
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 CommandManager::INSTANCE.TriggerPreset("PLAYLIST_STOPPING_AFTER_LOOP", keywords);
1295 1 });
1296 }
1297 5 m_status = FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP;
1298 } else {
1299
4/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 11 times.
24 if (CommandManager::INSTANCE.HasPreset("PLAYLIST_STOPPING_GRACEFULLY")) {
1300
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 QueuePlaylistNotification([keywords]() mutable {
1301
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 CommandManager::INSTANCE.TriggerPreset("PLAYLIST_STOPPING_GRACEFULLY", keywords);
1302 1 });
1303 }
1304 12 m_status = FPP_STATUS_STOPPING_GRACEFULLY;
1305 }
1306 17 m_forceStop = forceStop;
1307
3/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 16 times.
17 if (std::shared_ptr<Playlist> par = m_parent.load()) {
1308
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 par->StopGracefullyImpl(forceStop, afterCurrentLoop);
1309 17 }
1310
1311 17 return 1;
1312 17 }
1313
1314 607 void Playlist::Pause() {
1315
2/4
✓ Branch 0 taken 607 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 607 times.
✗ Branch 3 not taken.
607 LogDebug(VB_PLAYLIST, "Playlist::Pause called on %s\n", GetPlaylistName().c_str());
1316 607 PlaylistTransitionGuard guard;
1317
1/2
✓ Branch 0 taken 607 times.
✗ Branch 1 not taken.
607 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1318
2/4
✓ Branch 0 taken 607 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 607 times.
607 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
1319 ✗ lck.unlock();
1320 ✗ return cur->Pause();
1321
1/2
✓ Branch 0 taken 607 times.
✗ Branch 1 not taken.
607 }
1322
3/4
✓ Branch 0 taken 607 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 606 times.
✓ Branch 3 taken 1 times.
607 if (IsPlaying()) {
1323
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 PlaylistEntryBase* entry = CurrentEntry();
1324
7/8
✓ Branch 0 taken 605 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 605 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 451 times.
✓ Branch 5 taken 154 times.
✓ Branch 6 taken 451 times.
✓ Branch 7 taken 155 times.
606 if (entry && entry->IsPlaying()) {
1325
1/2
✓ Branch 0 taken 451 times.
✗ Branch 1 not taken.
451 entry->Pause();
1326
6/8
✓ Branch 0 taken 451 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 386 times.
✓ Branch 3 taken 65 times.
✓ Branch 4 taken 386 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 386 times.
✓ Branch 7 taken 65 times.
451 if (entry->IsPaused() && m_status != FPP_STATUS_PLAYLIST_PAUSED) {
1327 386 m_statusBeforePause = m_status;
1328 386 m_status = FPP_STATUS_PLAYLIST_PAUSED;
1329 }
1330 }
1331 }
1332
2/4
✓ Branch 0 taken 607 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 607 times.
✗ Branch 3 not taken.
607 }
1333 344 void Playlist::Resume() {
1334
2/4
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 344 times.
✗ Branch 3 not taken.
344 LogDebug(VB_PLAYLIST, "Playlist::Resume called on %s\n", GetPlaylistName().c_str());
1335 344 PlaylistTransitionGuard guard;
1336
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1337
2/4
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 344 times.
344 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
1338 ✗ lck.unlock();
1339 ✗ return cur->Resume();
1340
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 }
1341
3/4
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 343 times.
✓ Branch 3 taken 1 times.
344 if (IsPlaying()) {
1342 // Two ways to be paused: the playlist status, or -- for a parent that
1343 // was told to stop gracefully while paused under an "insert
1344 // immediate" child -- a STOPPING_* status over an entry that is still
1345 // paused. The second used to be unresumable: the parent sat on its
1346 // paused entry forever, never finishing the stop.
1347
1/2
✓ Branch 0 taken 343 times.
✗ Branch 1 not taken.
343 PlaylistEntryBase* entry = CurrentEntry();
1348 343 bool statusPaused = (m_status == FPP_STATUS_PLAYLIST_PAUSED);
1349
8/10
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 310 times.
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 32 times.
✓ Branch 8 taken 311 times.
✓ Branch 9 taken 32 times.
343 if (statusPaused || (entry && entry->IsPaused())) {
1350
1/2
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
311 if (entry) {
1351
1/2
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
311 entry->Resume();
1352 }
1353
2/2
✓ Branch 0 taken 310 times.
✓ Branch 1 taken 1 times.
311 if (statusPaused) {
1354 // Back to what Pause() interrupted, which may be a stop.
1355 310 m_status = m_statusBeforePause;
1356 }
1357
1358 // Notify of current playlists because was likely changed when Paused.
1359
2/4
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 311 times.
✗ Branch 3 not taken.
931 Events::Publish("playlist/name/status", m_name);
1360
4/8
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 311 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 311 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 311 times.
✗ Branch 7 not taken.
935 Events::Publish("status", PlaylistStatusToString(m_status));
1361
2/4
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 311 times.
✗ Branch 3 not taken.
622 Events::Publish("playlist/section/status", m_currentSectionStr);
1362
2/4
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 311 times.
✗ Branch 3 not taken.
620 Events::Publish("playlist/sectionPosition/status", m_sectionPosition);
1363 {
1364
1/2
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
311 Json::Value info = GetInfo();
1365
1/2
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
311 std::string sec = m_currentSectionStr;
1366 311 int pos = m_sectionPosition;
1367
4/12
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 311 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 311 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 311 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
311 QueuePlaylistNotification([info, sec, pos]() {
1368
2/4
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 311 times.
✗ Branch 3 not taken.
622 PluginManager::INSTANCE.playlistCallback(info, "playing", sec, pos);
1369 311 });
1370 311 }
1371 }
1372 }
1373
2/4
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 344 times.
✗ Branch 3 not taken.
344 }
1374
1375 /*
1376 *
1377 */
1378 1737369 int Playlist::IsPlaying(void) {
1379
2/2
✓ Branch 0 taken 471683 times.
✓ Branch 1 taken 11438 times.
2220490 if ((m_status == FPP_STATUS_PLAYLIST_PLAYING) ||
1380
2/2
✓ Branch 0 taken 466895 times.
✓ Branch 1 taken 4788 times.
954804 (m_status == FPP_STATUS_STOPPING_GRACEFULLY) ||
1381
6/6
✓ Branch 0 taken 483121 times.
✓ Branch 1 taken 1254248 times.
✓ Branch 2 taken 20075 times.
✓ Branch 3 taken 446820 times.
✓ Branch 4 taken 1290549 times.
✓ Branch 5 taken 446820 times.
2692173 (m_status == FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP) ||
1382 466895 (m_status == FPP_STATUS_PLAYLIST_PAUSED)) // paused is technically still "running"
1383 1290549 return 1;
1384
1385 446820 return 0;
1386 }
1387
1388 /*
1389 *
1390 */
1391 2014 int Playlist::FileHasBeenModified(void) {
1392
4/10
✓ Branch 0 taken 2014 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2014 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2013 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
6042 if ((endsWith(m_filename, ".fseq")) ||
1393
7/14
✓ Branch 0 taken 2014 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2014 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2014 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2014 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2013 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 2014 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
8055 (IsExtensionAudio(GetFileExtension(m_filename))) ||
1394
6/12
✓ Branch 0 taken 2013 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2013 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2013 times.
✓ Branch 6 taken 2013 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 2014 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
4027 (IsExtensionVideo(GetFileExtension(m_filename)))) {
1395 1 return 0;
1396 }
1397
1398 struct stat attr;
1399
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2013 times.
2013 if (stat(m_filename.c_str(), &attr) != 0) {
1400 // The file is momentarily unstat-able -- a non-atomic UI save (write a
1401 // temp then rename, or a slow write) makes it briefly absent. attr is
1402 // uninitialized on failure, so comparing attr.st_mtime would read stack
1403 // garbage and fabricate a spurious "modified", triggering a reload that
1404 // wipes the running playlist. A file we can't stat right now is not a
1405 // reason to reload: report unmodified and let the next tick retry.
1406 ✗ return 0;
1407 }
1408
1409 char timeBuf[32];
1410
1/2
✓ Branch 0 taken 2013 times.
✗ Branch 1 not taken.
2013 LogDebug(VB_PLAYLIST, "Playlist Last Modified: %s\n", ctime_r(&attr.st_mtime, timeBuf));
1411
1412
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2001 times.
2013 if (attr.st_mtime > m_fileTime)
1413 12 return 1;
1414
1415 2001 return 0;
1416 }
1417
1418 // Process() used to re-enter itself on this thread: after switching to an
1419 // inserted playlist it tail-called `return pl->Process()` while the outer frame
1420 // still held its own m_playlistMutex -- and that outer instance may already be
1421 // on PL_CLEANUPS. It no longer does (see the switch sites), but draining only
1422 // in the outermost frame is what makes the PL_CLEANUPS/PL_ENTRY_CLEANUPS
1423 // promise ("freed after the stack has unwound") true, so the depth guard stays
1424 // for any path that still nests.
1425 static thread_local int tl_processDepth = 0;
1426 namespace {
1427 class ProcessDepthGuard {
1428 public:
1429 391469 ProcessDepthGuard() { tl_processDepth++; }
1430 391469 ~ProcessDepthGuard() { tl_processDepth--; }
1431 };
1432 } // namespace
1433
1434 // Release playlists condemned to PL_CLEANUPS, run the destructors the
1435 // shared_ptr deleter deferred, then free retired entries. Main thread only,
1436 // and never with a Process() frame on the stack. Process() does this at its
1437 // outermost depth; the main loop also calls it while the player is idle,
1438 // because Process() only runs while something plays -- a stop used to leave
1439 // the stopped playlist's entries (an image entry's prep thread, a media
1440 // entry's state) alive until the next show started.
1441 572101 void Playlist::ReleaseRetired(void) {
1442 {
1443 // Held across the whole condemned pass (not swap-and-release) so
1444 // SetIdle's condemned-parent walk on another thread sees either the
1445 // full pre-drain list or the post-release state, never a moment
1446 // where a condemned instance has left the list but still looks
1447 // current-able. ReleasePlaylist only nests the owner's registry
1448 // lock inside; nothing takes these two in the other order.
1449
1/2
✓ Branch 0 taken 572101 times.
✗ Branch 1 not taken.
572101 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
1450
2/2
✓ Branch 0 taken 549 times.
✓ Branch 1 taken 571552 times.
572101 if (!PL_CLEANUPS.empty()) {
1451
1/2
✓ Branch 0 taken 549 times.
✗ Branch 1 not taken.
549 PL_CLEANUPS.sort();
1452 549 PL_CLEANUPS.unique();
1453
2/2
✓ Branch 0 taken 569 times.
✓ Branch 1 taken 549 times.
1118 while (!PL_CLEANUPS.empty()) {
1454 569 Playlist* p = PL_CLEANUPS.front();
1455 // Drops the player's owning reference rather than deleting.
1456 // If a reader thread still holds a snapshot of p, the
1457 // instance stays alive until that snapshot releases; its
1458 // destructor then runs on this thread in a later
1459 // DrainRetiredPlaylists().
1460
1/2
✓ Branch 0 taken 569 times.
✗ Branch 1 not taken.
569 Player::INSTANCE.ReleasePlaylist(p);
1461 569 PL_CLEANUPS.pop_front();
1462 }
1463 }
1464 572101 }
1465 // Runs the destructors the shared_ptr deleter deferred — here, between
1466 // the two lists, because ~Playlist parks its entries on
1467 // PL_ENTRY_CLEANUPS and those must be freed in the same tick, exactly
1468 // as when the drain above did the delete itself. Not under the lock:
1469 // those destructors push onto PL_ENTRY_CLEANUPS themselves.
1470 572101 Player::INSTANCE.DrainRetiredPlaylists();
1471 // Entry destructors can park further entries (nested sub-entries), so
1472 // swap-and-delete until a pass drains nothing.
1473 while (true) {
1474 573882 std::list<PlaylistEntryBase*> entries;
1475 {
1476
1/2
✓ Branch 0 taken 573882 times.
✗ Branch 1 not taken.
573882 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
1477 573882 entries.swap(PL_ENTRY_CLEANUPS);
1478 573882 }
1479
2/2
✓ Branch 0 taken 572101 times.
✓ Branch 1 taken 1781 times.
573882 if (entries.empty())
1480 572101 break;
1481
2/2
✓ Branch 0 taken 5207 times.
✓ Branch 1 taken 1781 times.
6988 for (auto* e : entries) {
1482
1/2
✓ Branch 0 taken 5207 times.
✗ Branch 1 not taken.
5207 delete e;
1483 }
1484
2/2
✓ Branch 0 taken 1781 times.
✓ Branch 1 taken 572101 times.
575663 }
1485 572101 }
1486
1487 /*
1488 *
1489 */
1490 391469 int Playlist::Process(void) {
1491
3/4
✓ Branch 0 taken 613 times.
✓ Branch 1 taken 390856 times.
✓ Branch 2 taken 613 times.
✗ Branch 3 not taken.
391469 static time_t lastCheckTime = time(nullptr);
1492 391469 time_t procTime = time(nullptr);
1493
1494 391469 PlaylistTransitionGuard guard;
1495 391469 ProcessDepthGuard depthGuard;
1496
1497 // Process any background stream slots (2-5) — fire-and-forget media on secondary streams
1498
2/4
✓ Branch 0 taken 391469 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 391469 times.
✗ Branch 3 not taken.
391469 StreamSlotManager::Instance().ProcessBackgroundSlots();
1499
1500 // Pull sync-enabled slots toward the primary media's position so extra
1501 // streams (a second language on another audio output, a second display)
1502 // stay locked to the show rather than free-running. Hooked here rather
1503 // than in ProcessMedia(), which the main loop only calls in REMOTE_MODE.
1504 float mediaSecs;
1505 {
1506 // A resume on a command thread rewrites these (PlaylistEntryMedia).
1507
1/2
✓ Branch 0 taken 391469 times.
✗ Branch 1 not taken.
391469 std::lock_guard<std::mutex> fieldsLock(MediaOutputStatus::FieldsLock());
1508 391469 mediaSecs = mediaOutputStatus.mediaSeconds;
1509 391469 }
1510
6/6
✓ Branch 0 taken 167162 times.
✓ Branch 1 taken 224307 times.
✓ Branch 2 taken 159779 times.
✓ Branch 3 taken 7383 times.
✓ Branch 4 taken 159779 times.
✓ Branch 5 taken 231690 times.
391469 if (mediaOutputStatus.status == MEDIAOUTPUTSTATUS_PLAYING && mediaSecs > 0.0f) {
1511
2/4
✓ Branch 0 taken 159779 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 159779 times.
✗ Branch 3 not taken.
159779 StreamSlotManager::Instance().SyncSlotsToMaster(mediaSecs);
1512 }
1513
1514 // LogExcess(VB_PLAYLIST, "Playlist::Process: %s, section %s, position: %d\n", m_name.c_str(), m_currentSectionStr.c_str(), m_sectionPosition);
1515
1516
1/2
✓ Branch 0 taken 391469 times.
✗ Branch 1 not taken.
391469 if (tl_processDepth == 1) {
1517
1/2
✓ Branch 0 taken 391469 times.
✗ Branch 1 not taken.
391469 ReleaseRetired();
1518 }
1519
1/2
✓ Branch 0 taken 391469 times.
✗ Branch 1 not taken.
391469 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1520
3/4
✓ Branch 0 taken 391469 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 391458 times.
391469 if (m_currentSectionStr == "New") {
1521 11 return 0;
1522 }
1523
1524
1/2
✓ Branch 0 taken 391458 times.
✗ Branch 1 not taken.
391458 UpdateCrashSnapshot();
1525
1526
3/6
✓ Branch 0 taken 391458 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 391458 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 391458 times.
391458 if (m_currentSection == nullptr || m_sectionPosition >= m_currentSection->size()) {
1527 ✗ LogErr(VB_PLAYLIST, "Section position %d is outside of section %s\n",
1528 m_sectionPosition, m_currentSectionStr.c_str());
1529 ✗ StopNowImpl();
1530 ✗ return 0;
1531 }
1532
1533 // Holding off the next pass of an instant-only repeating playlist.
1534
2/2
✓ Branch 0 taken 2602 times.
✓ Branch 1 taken 388856 times.
391458 if (m_loopHoldUntilMS) {
1535
3/4
✓ Branch 0 taken 2602 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2581 times.
✓ Branch 3 taken 21 times.
2602 if (GetMonotonicTimeMS() < m_loopHoldUntilMS) {
1536 2581 return 1;
1537 }
1538 21 m_loopHoldUntilMS = 0;
1539
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 m_loopStartMS = GetMonotonicTimeMS();
1540
3/6
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 if (m_currentSection && m_sectionPosition < m_currentSection->size()) {
1541
2/4
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
21 StartPlayingWithGlobalPause(m_currentSection->at(m_sectionPosition));
1542 }
1543 21 return 1;
1544 }
1545
1546 // Handle global pause between sequences
1547
2/2
✓ Branch 0 taken 1004 times.
✓ Branch 1 taken 387852 times.
388856 if (m_isInGlobalPause) {
1548
1/2
✓ Branch 0 taken 1004 times.
✗ Branch 1 not taken.
1004 long long currentTime = GetMonotonicTimeMS();
1549
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 999 times.
1004 if ((currentTime - m_globalPauseStartTime) >= m_globalPauseBetweenSequencesMS) {
1550
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 LogDebug(VB_PLAYLIST, "Global pause between sequences completed, starting next item\n");
1551 5 m_isInGlobalPause = false;
1552 // Start the current item (which was delayed by the pause)
1553
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 if (m_currentSection && m_sectionPosition < m_currentSection->size()) {
1554
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 m_currentSection->at(m_sectionPosition)->StartPlayingOrFinish();
1555 }
1556 } else {
1557 // Still in pause period, don't process anything
1558 999 return 1;
1559 }
1560 }
1561
1562
10/14
✓ Branch 0 taken 387857 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 387857 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 384417 times.
✓ Branch 5 taken 3440 times.
✓ Branch 6 taken 384417 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 384417 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 384342 times.
✓ Branch 11 taken 75 times.
✓ Branch 12 taken 384342 times.
✓ Branch 13 taken 3515 times.
387857 if (!m_currentSection->at(m_sectionPosition)->IsPaused() && m_currentSection->at(m_sectionPosition)->IsPlaying()) {
1563
2/4
✓ Branch 0 taken 384342 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 384342 times.
✗ Branch 3 not taken.
384342 m_currentSection->at(m_sectionPosition)->Process();
1564
1/2
✓ Branch 0 taken 384342 times.
✗ Branch 1 not taken.
384342 PrepareNextIfDue();
1565 }
1566
1567 387857 Playlist* pl = nullptr;
1568
8/10
✓ Branch 0 taken 387857 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 387857 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3440 times.
✓ Branch 5 taken 384417 times.
✓ Branch 6 taken 364 times.
✓ Branch 7 taken 3076 times.
✓ Branch 8 taken 364 times.
✓ Branch 9 taken 387493 times.
387857 if (m_currentSection->at(m_sectionPosition)->IsPaused() && !m_insertedPlaylist.empty()) {
1569
3/4
✓ Branch 0 taken 364 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 359 times.
364 if ((pl = SwitchToInsertedPlaylist()) == nullptr) {
1570 // The insert was refused (nesting limit) or failed to start. A
1571 // failed start already resumed us from the child's SetIdle; a
1572 // refusal didn't, and we'd sit paused under nothing. Resume() is a
1573 // no-op if we're not paused.
1574
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (Player::INSTANCE.PlaylistSnapshot().get() == this) {
1575
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 Resume();
1576 }
1577 5 return 1;
1578 }
1579 // SwitchToInsertedPlaylist() already started pl (via PlayImpl) and made
1580 // it current; the next tick processes it. Never process the child from
1581 // here: this frame holds our lock, and a thread stopping the child
1582 // takes the child's lock and then ours (StopGracefully forwards to
1583 // m_parent, SetIdle resumes it) -- taking pl's lock here deadlocked
1584 // against that. Processing it inline also recursed once per level of
1585 // a playlist that inserts itself.
1586 359 return 1;
1587 }
1588
1589
4/6
✓ Branch 0 taken 387493 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 387493 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5695 times.
✓ Branch 5 taken 381798 times.
387493 if (m_currentSection->at(m_sectionPosition)->IsFinished()) {
1590
1/2
✓ Branch 0 taken 5695 times.
✗ Branch 1 not taken.
5695 LogDebug(VB_PLAYLIST, "Playlist entry finished\n");
1591
3/4
✓ Branch 0 taken 5695 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 5693 times.
5695 if (WillLog(LOG_DEBUG, VB_PLAYLIST))
1592
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 m_currentSection->at(m_sectionPosition)->Dump();
1593
1594
1/2
✓ Branch 0 taken 5695 times.
✗ Branch 1 not taken.
5695 LogDebug(VB_PLAYLIST, "============================================================================\n");
1595
1596 // Check if we should start a global pause before the next item
1597
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 5686 times.
5695 if (m_globalPauseBetweenSequencesMS > 0) {
1598
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
18 bool isStoppingGracefully = (m_status == FPP_STATUS_STOPPING_GRACEFULLY ||
1599 9 m_status == FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP);
1600
1601
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (!isStoppingGracefully) {
1602
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 LogDebug(VB_PLAYLIST, "Marking for global pause between sequences for %d ms\n", m_globalPauseBetweenSequencesMS);
1603 9 m_shouldStartGlobalPause = true;
1604 }
1605 }
1606
1607 // "query_next" stays SYNCHRONOUS by design: it is the decision-point
1608 // hook plugins use to insert the next item (InsertPlaylistAsNext)
1609 // before the SwitchToInsertedPlaylist checks just below — deferring
1610 // it would make the insertion miss this cycle. Re-entrant Play()
1611 // from the callback is safe now (Play() defers it), which was the
1612 // only hazard of calling it inline.
1613
3/6
✓ Branch 0 taken 5695 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5695 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5695 times.
✗ Branch 5 not taken.
11456 PluginManager::INSTANCE.playlistCallback(GetInfo(), "query_next", m_currentSectionStr, m_sectionPosition);
1614
1615
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5682 times.
5695 if (m_status == FPP_STATUS_STOPPING_GRACEFULLY) {
1616
4/6
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 2 times.
26 if ((m_currentSectionStr == "LeadIn") ||
1617
3/4
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 2 times.
13 (m_currentSectionStr == "MainPlaylist")) {
1618
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 ReloadIfNeeded();
1619
1620
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
11 if (m_leadOut.size()) {
1621
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogDebug(VB_PLAYLIST, "Stopping Gracefully\n");
1622
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 SwitchToLeadOut();
1623 } else {
1624
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 SetIdle();
1625 }
1626 11 return 1;
1627 }
1628 }
1629
6/8
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 5647 times.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 37 times.
✓ Branch 7 taken 5647 times.
5684 if (m_stopAtPos != -1 && m_stopAtPos <= (GetPosition() - 1)) {
1630
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
37 if ((pl = SwitchToInsertedPlaylist(true)) != nullptr) {
1631 ✗ return 1; // next tick processes pl; see the paused case above
1632 }
1633
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
37 if (Player::INSTANCE.PlaylistSnapshot().get() != this) {
1634 // The insert failed to start and handed the player back to our
1635 // parent, condemning us; nothing here is ours to run any more.
1636 ✗ return 1;
1637 }
1638
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 LogDebug(VB_PLAYLIST, "Stopping after end position\n");
1639
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 SetIdle();
1640 37 return 1;
1641 }
1642
4/6
✓ Branch 0 taken 5647 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5647 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 207 times.
✓ Branch 5 taken 5440 times.
5647 if ((pl = SwitchToInsertedPlaylist(WillStopAfterCurrent())) != nullptr) {
1643 207 return 1; // next tick processes pl; see the paused case above
1644 }
1645
2/4
✓ Branch 0 taken 5440 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5440 times.
5440 if (Player::INSTANCE.PlaylistSnapshot().get() != this) {
1646 ✗ return 1; // condemned by a failed insert; see above
1647 }
1648
1649
1/2
✓ Branch 0 taken 5440 times.
✗ Branch 1 not taken.
5440 auto currentEntry = m_currentSection->at(m_sectionPosition);
1650
3/4
✓ Branch 0 taken 5440 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 5429 times.
5440 if (currentEntry->GetNextBranchType() == PlaylistEntryBase::PlaylistBranchType::Index) {
1651
3/6
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
11 if (currentEntry->GetNextSection() != "") {
1652
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 LogDebug(VB_PLAYLIST, "Attempting Switch to %s section.\n",
1653 currentEntry->GetNextSection().c_str());
1654
1655
3/6
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11 times.
11 if (currentEntry->GetNextSection() == "leadIn") {
1656 ✗ m_currentSectionStr = "LeadIn";
1657 ✗ m_currentSection = &m_leadIn;
1658
3/6
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11 times.
11 } else if (currentEntry->GetNextSection() == "leadOut") {
1659 ✗ m_currentSectionStr = "LeadOut";
1660 ✗ m_currentSection = &m_leadOut;
1661 } else {
1662
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 m_currentSectionStr = "MainPlaylist";
1663 11 m_currentSection = &m_mainPlaylist;
1664 }
1665
1666 // A Branch's item number is a row of the playlist as the
1667 // editor shows it; map it through the row table, as a
1668 // sub-playlist row expands to several entries.
1669
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 const std::vector<int>& rows = CurrentSectionRows();
1670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 int rowCount = rows.empty() ? (int)m_currentSection->size() : (int)rows.size();
1671
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 int item = currentEntry->GetNextItem();
1672
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 if ((item >= 0) && (item < rowCount)) {
1673
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 m_sectionPosition = RowToSectionPosition(rows, item, m_currentSection->size());
1674 } else {
1675 ✗ m_sectionPosition = 0;
1676 }
1677 ✗ } else if (currentEntry->GetNextItem() != -1) {
1678 ✗ m_sectionPosition = RowToSectionPosition(CurrentSectionRows(), currentEntry->GetNextItem(), m_currentSection->size());
1679 } else {
1680 ✗ m_sectionPosition++;
1681 }
1682
3/4
✓ Branch 0 taken 5429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 5426 times.
5429 } else if (currentEntry->GetNextBranchType() == PlaylistEntryBase::PlaylistBranchType::Offset) {
1683 // Offsets count rows too (see the Index case above).
1684
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 const std::vector<int>& rows = CurrentSectionRows();
1685
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 int nextRow = SectionPositionToRow(rows, m_sectionPosition) + currentEntry->GetNextItem();
1686
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 LogDebug(VB_PLAYLIST, "Attempting Offset Branch to section row %d\n", nextRow);
1687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (nextRow < 0) {
1688 ✗ LogDebug(VB_PLAYLIST, "New position negative, branching to first position in section\n");
1689 ✗ m_sectionPosition = 0;
1690 } else {
1691
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 m_sectionPosition = RowToSectionPosition(rows, nextRow, m_currentSection->size());
1692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (m_sectionPosition >= m_currentSection->size())
1693 ✗ LogDebug(VB_PLAYLIST, "Offset outside current section, ending section\n");
1694 }
1695
3/4
✓ Branch 0 taken 5426 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 5415 times.
5426 } else if (currentEntry->GetNextBranchType() == PlaylistEntryBase::PlaylistBranchType::Playlist) {
1696 // handled internally to PlaylistEntryBranch
1697 11 m_sectionPosition++;
1698 } else {
1699 5415 m_sectionPosition++;
1700 }
1701
1702
2/2
✓ Branch 0 taken 2653 times.
✓ Branch 1 taken 2787 times.
5440 if (m_sectionPosition >= m_currentSection->size()) {
1703
3/4
✓ Branch 0 taken 2653 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 758 times.
✓ Branch 3 taken 1895 times.
2653 if (m_currentSectionStr == "LeadIn") {
1704
1/2
✓ Branch 0 taken 758 times.
✗ Branch 1 not taken.
758 LogDebug(VB_PLAYLIST, "At end of leadIn.\n");
1705
1706
1/2
✓ Branch 0 taken 758 times.
✗ Branch 1 not taken.
758 ReloadIfNeeded();
1707
1708
2/2
✓ Branch 0 taken 756 times.
✓ Branch 1 taken 2 times.
758 if (m_mainPlaylist.size()) {
1709
1/2
✓ Branch 0 taken 756 times.
✗ Branch 1 not taken.
756 SwitchToMainPlaylist();
1710
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 } else if (m_leadOut.size()) {
1711
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 SwitchToLeadOut();
1712 } else {
1713
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogDebug(VB_PLAYLIST, "No more playlist entries, switching to idle.\n");
1714
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 SetIdle();
1715 }
1716
3/4
✓ Branch 0 taken 1895 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1886 times.
✓ Branch 3 taken 9 times.
1895 } else if (m_currentSectionStr == "MainPlaylist") {
1717 1886 m_loop++;
1718
1/2
✓ Branch 0 taken 1886 times.
✗ Branch 1 not taken.
3772 LogDebug(VB_PLAYLIST, "mainPlaylist loop now: %d\n", m_loop.load());
1719
8/8
✓ Branch 0 taken 1249 times.
✓ Branch 1 taken 637 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 1217 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 1239 times.
✓ Branch 7 taken 647 times.
1886 if ((m_repeat) && (!m_loopCount || (m_loop < m_loopCount))) {
1720
1/2
✓ Branch 0 taken 1239 times.
✗ Branch 1 not taken.
1239 ReloadIfNeeded();
1721
1722
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1237 times.
1239 if (m_status == FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP) {
1723
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (m_leadOut.size()) {
1724
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogDebug(VB_PLAYLIST, "Stopping Gracefully after loop\n");
1725
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 SwitchToLeadOut();
1726 } else {
1727
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogDebug(VB_PLAYLIST, "Stopping Gracefully after loop. Empty leadOut, setting to Idle state\n");
1728
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 SetIdle();
1729 }
1730
1731 2 return 1;
1732 }
1733
1734
2/2
✓ Branch 0 taken 1215 times.
✓ Branch 1 taken 22 times.
1237 if (!m_loopCount)
1735
1/2
✓ Branch 0 taken 1215 times.
✗ Branch 1 not taken.
1215 LogDebug(VB_PLAYLIST, "mainPlaylist repeating for another loop, loopCount == 0\n");
1736 else
1737
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
44 LogDebug(VB_PLAYLIST, "mainPlaylist repeating for another loop, %d <= %d\n", m_loop.load(), m_loopCount);
1738
1739 // A pass this short has nothing in it that takes time;
1740 // repeated as-is it would spin the main loop. Hold the next
1741 // pass until a second after this one began. Any pass with a
1742 // real entry in it (a sequence, a pause, media) is far
1743 // longer and unaffected. Only here, where another pass
1744 // starts: Process() restarts whatever entry is current when
1745 // the hold runs out, so a hold left set on the way to the
1746 // lead-out played its first entry twice.
1747 static constexpr long long MIN_INSTANT_PASS_MS = 50;
1748 static constexpr long long INSTANT_PASS_PERIOD_MS = 1000;
1749
1/2
✓ Branch 0 taken 1237 times.
✗ Branch 1 not taken.
1237 long long passMS = GetMonotonicTimeMS() - m_loopStartMS;
1750
4/4
✓ Branch 0 taken 1195 times.
✓ Branch 1 taken 42 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 1166 times.
1237 if (m_loopStartMS && passMS < MIN_INSTANT_PASS_MS) {
1751 29 m_loopHoldUntilMS = m_loopStartMS + INSTANT_PASS_PERIOD_MS;
1752
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 21 times.
29 if (!m_warnedInstantLoop) {
1753 8 m_warnedInstantLoop = true;
1754
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 LogWarn(VB_PLAYLIST, "Playlist '%s' repeats with nothing in it that takes time; limiting it to one pass a second\n",
1755 m_name.c_str());
1756 }
1757 }
1758
1759
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1233 times.
1237 if (m_random == 2) {
1760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (m_nextShuffle.size() == m_mainPlaylist.size()) {
1761 // Drawn when this pass's first entry was prepared.
1762 ✗ m_mainPlaylist = m_nextShuffle;
1763 } else {
1764
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 RandomizeMainPlaylist();
1765 }
1766 }
1767 1237 m_nextShuffle.clear();
1768
1769 // Goes through SwitchToMainPlaylist() for its empty-section
1770 // guard; we are already in the MainPlaylist section, so the
1771 // section/position it sets are the values this branch wants.
1772 // ReloadIfNeeded() above may have emptied the section.
1773
1/2
✓ Branch 0 taken 1237 times.
✗ Branch 1 not taken.
1237 SwitchToMainPlaylist();
1774
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 641 times.
647 } else if (m_leadOut.size()) {
1775
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 ReloadIfNeeded();
1776
1777
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 SwitchToLeadOut();
1778 } else {
1779
1/2
✓ Branch 0 taken 641 times.
✗ Branch 1 not taken.
641 LogDebug(VB_PLAYLIST, "No more playlist entries, switching to idle.\n");
1780
1/2
✓ Branch 0 taken 641 times.
✗ Branch 1 not taken.
641 SetIdle();
1781 }
1782 } else {
1783
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 LogDebug(VB_PLAYLIST, "No more playlist entries, switching to idle.\n");
1784
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 SetIdle();
1785 }
1786 } else {
1787 // Start the next item in the current section
1788
2/4
✓ Branch 0 taken 2787 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2787 times.
✗ Branch 3 not taken.
2787 StartPlayingWithGlobalPause(m_currentSection->at(m_sectionPosition));
1789 }
1790
1791 // NOTE: deferred "Start Playlist" requests recorded by re-entrant
1792 // Play() calls are replayed by the outermost PlaylistTransitionGuard
1793 // when this Process() frame unwinds — the drain loop that used to
1794 // live here moved there so it also covers requests deferred during
1795 // idle transitions (Process() stops running once the player goes
1796 // idle, so a drain only here could strand them).
1797
1798 // Only if we are still playing. Several of the branches above end the
1799 // playlist via SetIdle(), which queues the "stop" callback and resets
1800 // the section to "New" - falling through to here then told every plugin
1801 // "playing" immediately after "stop", for a section that isn't running.
1802 // Plugins that key powering hardware up off "playing" turned it right
1803 // back on at the end of a show.
1804
2/2
✓ Branch 0 taken 4784 times.
✓ Branch 1 taken 654 times.
5438 if (m_status != FPP_STATUS_IDLE) {
1805 {
1806
1/2
✓ Branch 0 taken 4784 times.
✗ Branch 1 not taken.
4784 Json::Value info = GetInfo();
1807
1/2
✓ Branch 0 taken 4784 times.
✗ Branch 1 not taken.
4784 std::string sec = m_currentSectionStr;
1808 4784 int pos = m_sectionPosition;
1809
4/12
✓ Branch 0 taken 4784 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4784 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4784 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4784 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
4784 QueuePlaylistNotification([info, sec, pos]() {
1810
2/4
✓ Branch 0 taken 4784 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4784 times.
✗ Branch 3 not taken.
9568 PluginManager::INSTANCE.playlistCallback(info, "playing", sec, pos);
1811 4784 });
1812 4784 }
1813
2/4
✓ Branch 0 taken 4784 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4784 times.
✗ Branch 3 not taken.
9568 Events::Publish("playlist/section/status", m_currentSectionStr);
1814
2/4
✓ Branch 0 taken 4784 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4784 times.
✗ Branch 3 not taken.
14313 Events::Publish("playlist/sectionPosition/status", m_sectionPosition);
1815 }
1816 }
1817
1818 387236 return 1;
1819 391469 }
1820
1821 // How long before the current entry ends the next one's media is prepared:
1822 // enough for a pipeline to build and decode its first frame on a slow board,
1823 // little enough that a guess overtaken by an insert costs little.
1824 static constexpr uint64_t PREPARE_NEXT_LEAD_MS = 1500;
1825
1826 384342 void Playlist::PrepareNextIfDue() {
1827
1/2
✓ Branch 0 taken 384342 times.
✗ Branch 1 not taken.
384342 PlaylistEntryBase* cur = m_currentSection->at(m_sectionPosition);
1828
1/2
✓ Branch 0 taken 384342 times.
✗ Branch 1 not taken.
384342 uint64_t length = cur->GetLengthInMS();
1829
1/2
✓ Branch 0 taken 384342 times.
✗ Branch 1 not taken.
384342 uint64_t elapsed = cur->GetElapsedMS();
1830
4/4
✓ Branch 0 taken 377218 times.
✓ Branch 1 taken 7124 times.
✓ Branch 2 taken 301711 times.
✓ Branch 3 taken 75507 times.
384342 if (!length || elapsed + PREPARE_NEXT_LEAD_MS < length) {
1831 // Not due, so the next time it is, it is a new pass -- the same
1832 // entry comes round again when a playlist of one entry repeats.
1833 308835 m_preparedAfter = nullptr;
1834 382829 return;
1835 }
1836
2/2
✓ Branch 0 taken 73994 times.
✓ Branch 1 taken 1513 times.
75507 if (cur == m_preparedAfter) {
1837 73994 return; // done for this pass
1838 }
1839 1513 m_preparedAfter = cur;
1840 1513 bool ends = false;
1841
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1501 times.
1513 if (!m_insertedPlaylist.empty()) {
1842
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 PrepareInsertedPlaylist();
1843
3/4
✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1195 times.
✓ Branch 3 taken 306 times.
1501 } else if (PlaylistEntryBase* next = PeekNextEntry(&ends)) {
1844
1/2
✓ Branch 0 taken 1195 times.
✗ Branch 1 not taken.
1195 next->PrepareAhead();
1845
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 10 times.
306 } else if (ends) {
1846
1/2
✓ Branch 0 taken 296 times.
✗ Branch 1 not taken.
296 PrepareParentsNext();
1847 }
1848 }
1849
1850 297 void Playlist::PrepareParentsNext() {
1851 // The level SetIdle() would hand back to: condemned levels are skipped.
1852
1/2
✓ Branch 0 taken 297 times.
✗ Branch 1 not taken.
297 std::shared_ptr<Playlist> par = m_parent.load();
1853 {
1854
1/2
✓ Branch 0 taken 297 times.
✗ Branch 1 not taken.
297 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
1855
5/8
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 230 times.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 67 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 297 times.
297 while (par && std::find(PL_CLEANUPS.begin(), PL_CLEANUPS.end(), par.get()) != PL_CLEANUPS.end()) {
1856 ✗ par = par->m_parent.load();
1857 }
1858 297 }
1859
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 230 times.
297 if (par) {
1860 // Child before parent: the order StopGracefully takes the locks in.
1861
1/2
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
67 par->PrepareNextOnResume();
1862 }
1863 297 }
1864
1865 67 void Playlist::PrepareNextOnResume() {
1866
1/2
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
67 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
1867
7/10
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 66 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 66 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 66 times.
67 if (m_currentSectionStr == "New" || !m_currentSection || m_sectionPosition >= m_currentSection->size()) {
1868 1 return;
1869 }
1870 // Inserted after the current entry, which has finished: once resumed it
1871 // moves on, exactly as if the insert had never been. Inserted
1872 // immediately, the current entry is paused and resumes instead.
1873
4/6
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 40 times.
✓ Branch 5 taken 26 times.
66 if (!m_currentSection->at(m_sectionPosition)->IsFinished()) {
1874 40 return;
1875 }
1876 26 bool ends = false;
1877
3/4
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 1 times.
26 if (PlaylistEntryBase* next = PeekNextEntry(&ends)) {
1878
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 next->PrepareAhead();
1879
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 } else if (ends) {
1880
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 PrepareParentsNext();
1881 }
1882
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 41 times.
67 }
1883
1884 // An insert (Insert Playlist After Current: Remote Falcon's requests) plays
1885 // next. Its entries aren't loaded until it starts, so its first media is
1886 // read from its file -- where that is certain: from the top, unshuffled, a
1887 // plain media entry first.
1888 12 void Playlist::PrepareInsertedPlaylist() {
1889
6/8
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 11 times.
23 if (m_insertedPlaylistPosition > 0 || m_status == FPP_STATUS_STOPPING_GRACEFULLY ||
1890 11 m_status == FPP_STATUS_STOPPING_NOW) {
1891 7 return;
1892 }
1893
6/12
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
22 Json::Value root = LoadJSON(FPP_DIR_PLAYLIST("/" + m_insertedPlaylist + ".json"));
1894
13/22
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 10 times.
✓ Branch 12 taken 10 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 10 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 10 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
11 if (!root.isObject() || PlaylistRandomSetting(root.get("random", 0)) > 0) {
1895 1 return;
1896 }
1897 10 std::string media;
1898 10 std::string videoOut;
1899 10 int slot = 1;
1900 // The file is read unchecked, and jsoncpp's as*() throw on a field of the
1901 // wrong type ("random": "0" did, aborting fppd). Preparing is only a head
1902 // start, so an entry that doesn't read cleanly is left for the insert to
1903 // load (and report) when it starts.
1904 try {
1905
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 const Json::Value& leadIn = root["leadIn"];
1906
6/10
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 9 times.
✗ Branch 9 not taken.
10 const Json::Value& entries = leadIn.isArray() && leadIn.size() ? leadIn : root["mainPlaylist"];
1907
8/16
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 10 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 10 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 10 times.
10 if (!entries.isArray() || !entries.size() || !entries[0].isObject()) {
1908 5 return;
1909 }
1910
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 const Json::Value& e = entries[0];
1911
3/6
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 std::string type = e.get("type", "").asString();
1912
10/20
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 14 taken 5 times.
✓ Branch 15 taken 5 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
20 if ((type != "media" && type != "both") || !e.get("enabled", 1).asBool() ||
1913
26/48
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5 times.
✓ Branch 22 taken 5 times.
✓ Branch 23 taken 5 times.
✓ Branch 24 taken 5 times.
✓ Branch 25 taken 5 times.
✓ Branch 26 taken 5 times.
✓ Branch 27 taken 5 times.
✓ Branch 28 taken 5 times.
✓ Branch 29 taken 5 times.
✓ Branch 30 taken 5 times.
✓ Branch 31 taken 5 times.
✓ Branch 32 taken 5 times.
✓ Branch 33 taken 5 times.
✓ Branch 34 taken 5 times.
✓ Branch 35 taken 5 times.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
20 e.get("fileMode", "single").asString() != "single" || !e.get("mediaPrefix", "").asString().empty()) {
1914 5 return;
1915 }
1916
4/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
5 slot = std::clamp(e.get("streamSlot", 1).asInt(), 1, StreamSlotManager::MAX_SLOTS);
1917
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 media = e.get("mediaName", "").asString();
1918
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 videoOut = e.get("videoOut", "").asString();
1919
2/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10 } catch (const std::exception& ex) {
1920 ✗ LogWarn(VB_PLAYLIST, "Not preparing inserted playlist %s: %s\n", m_insertedPlaylist.c_str(), ex.what());
1921 ✗ return;
1922 ✗ }
1923
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 PrepareMediaOutput(media, ResolveVideoOutput(videoOut), slot);
1924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (multiSync->isMultiSyncEnabled()) {
1925 ✗ multiSync->SendMediaPreparePacket(media);
1926 }
1927
6/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 6 times.
21 }
1928
1929 // The same decisions Process() makes once the current entry has finished,
1930 // as far as they can be made now; nullptr wherever they can't.
1931 1527 PlaylistEntryBase* Playlist::PeekNextEntry(bool* ends) {
1932 1527 bool endsHere = false;
1933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1527 times.
1527 if (!ends) {
1934 ✗ ends = &endsHere;
1935 }
1936 1527 *ends = false;
1937
4/4
✓ Branch 0 taken 1526 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1517 times.
✓ Branch 3 taken 9 times.
4580 if (!m_insertedPlaylist.empty() || m_globalPauseBetweenSequencesMS > 0 ||
1938
4/6
✓ Branch 0 taken 1527 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1517 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 1517 times.
4580 m_status == FPP_STATUS_STOPPING_GRACEFULLY || m_status == FPP_STATUS_STOPPING_NOW) {
1939 10 return nullptr;
1940 }
1941
1/2
✓ Branch 0 taken 1517 times.
✗ Branch 1 not taken.
1517 PlaylistEntryBase* cur = m_currentSection->at(m_sectionPosition);
1942
2/4
✓ Branch 0 taken 1517 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1517 times.
1517 if (cur->GetNextBranchType() != PlaylistEntryBase::PlaylistBranchType::NoBranch) {
1943 ✗ return nullptr;
1944 }
1945
6/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1515 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1515 times.
1517 if (m_stopAtPos != -1 && m_stopAtPos <= (GetPosition() - 1)) {
1946 2 *ends = true; // the end position Process() stops at
1947 2 return nullptr;
1948 }
1949
2/2
✓ Branch 0 taken 667 times.
✓ Branch 1 taken 848 times.
1515 if (m_sectionPosition + 1 < m_currentSection->size()) {
1950
1/2
✓ Branch 0 taken 667 times.
✗ Branch 1 not taken.
667 return m_currentSection->at(m_sectionPosition + 1);
1951 }
1952
3/4
✓ Branch 0 taken 848 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 827 times.
848 if (m_currentSectionStr == "LeadIn") {
1953
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if (!m_mainPlaylist.empty()) {
1954 21 return m_mainPlaylist[0]; // already shuffled, when it is, by Start()
1955 }
1956 ✗ if (m_leadOut.empty()) {
1957 ✗ *ends = true;
1958 ✗ return nullptr;
1959 }
1960 ✗ return m_leadOut[0];
1961 }
1962
2/4
✓ Branch 0 taken 827 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 827 times.
827 if (m_currentSectionStr != "MainPlaylist") {
1963 ✗ *ends = m_currentSectionStr == "LeadOut";
1964 ✗ return nullptr;
1965 }
1966
8/8
✓ Branch 0 taken 533 times.
✓ Branch 1 taken 294 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 527 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 530 times.
✓ Branch 7 taken 1 times.
1358 bool loopsAgain = m_repeat && (!m_loopCount || (m_loop + 1) < m_loopCount) &&
1967 531 m_status != FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP;
1968
2/2
✓ Branch 0 taken 297 times.
✓ Branch 1 taken 530 times.
827 if (!loopsAgain) {
1969
2/2
✓ Branch 0 taken 295 times.
✓ Branch 1 taken 2 times.
297 if (m_leadOut.empty()) {
1970 295 *ends = true;
1971 295 return nullptr;
1972 }
1973 2 return m_leadOut[0];
1974 }
1975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 530 times.
530 if (m_random == 2) {
1976 // Reshuffled at the wrap: draw that shuffle now and keep it.
1977 ✗ if (m_nextShuffle.size() != m_mainPlaylist.size()) {
1978 ✗ m_nextShuffle = ShuffledMainPlaylist();
1979 }
1980 ✗ return m_nextShuffle.empty() ? nullptr : m_nextShuffle[0];
1981 }
1982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 530 times.
530 return m_mainPlaylist.empty() ? nullptr : m_mainPlaylist[0];
1983 }
1984
1985 // Deepest stack of inserted playlists SwitchToInsertedPlaylist will build,
1986 // counting the resident playlist at the bottom.
1987 static constexpr int MAX_INSERTED_PLAYLIST_DEPTH = 10;
1988
1989 // True when this playlist ends once the current entry finishes -- i.e. an
1990 // inserted playlist can take our place instead of nesting under us. Both
1991 // section branches used to be inverted (true exactly when more was left to
1992 // play): an insert queued near the end of a nested playlist dropped its
1993 // remaining sections, while a playlist that really was ending nested the
1994 // insert one level deeper every time -- without bound for a playlist that
1995 // branches back to itself.
1996 5647 bool Playlist::WillStopAfterCurrent() {
1997
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 2831 times.
5647 if ((m_sectionPosition + 1) < m_currentSection->size()) {
1998 2816 return false;
1999 }
2000 2831 PlaylistEntryBase* entry = CurrentEntry();
2001
3/6
✓ Branch 0 taken 2831 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2831 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2831 times.
5662 if (entry && (entry->GetNextBranchType() == PlaylistEntryBase::PlaylistBranchType::Index ||
2002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2831 times.
2831 entry->GetNextBranchType() == PlaylistEntryBase::PlaylistBranchType::Offset)) {
2003 // A last-entry branch can jump back into the playlist.
2004 ✗ return false;
2005 }
2006
2/2
✓ Branch 0 taken 781 times.
✓ Branch 1 taken 2050 times.
2831 if (m_currentSectionStr == "LeadIn") {
2007
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 779 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
781 return m_mainPlaylist.empty() && m_leadOut.empty();
2008
2/2
✓ Branch 0 taken 2041 times.
✓ Branch 1 taken 9 times.
2050 } else if (m_currentSectionStr == "MainPlaylist") {
2009 // Same test Process() applies once m_loop has been incremented.
2010
8/8
✓ Branch 0 taken 1249 times.
✓ Branch 1 taken 792 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 1217 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 1237 times.
✓ Branch 7 taken 2 times.
3280 bool loopsAgain = m_repeat && (!m_loopCount || ((m_loop + 1) < m_loopCount)) &&
2011 1239 (m_status != FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP);
2012
4/4
✓ Branch 0 taken 804 times.
✓ Branch 1 taken 1237 times.
✓ Branch 2 taken 796 times.
✓ Branch 3 taken 8 times.
2041 return !loopsAgain && m_leadOut.empty();
2013 }
2014 9 return true;
2015 }
2016
2017 6048 Playlist* Playlist::SwitchToInsertedPlaylist(bool isStopping) {
2018
2/2
✓ Branch 0 taken 573 times.
✓ Branch 1 taken 5475 times.
6048 if (m_insertedPlaylist != "") {
2019 // We are exiting, so there is no point wasting our memory on the stack
2020 // of playlists: the new playlist takes our place by inheriting our
2021 // parent, and we clean ourselves up once it is known to be running.
2022
7/10
✓ Branch 0 taken 154 times.
✓ Branch 1 taken 419 times.
✓ Branch 2 taken 154 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 151 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 154 times.
✓ Branch 7 taken 419 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
573 bool replaceSelf = isStopping && (m_parent.load() != nullptr);
2023 // The new playlist's parent: ours if it replaces us, else us.
2024
5/8
✓ Branch 0 taken 151 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 151 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 422 times.
✓ Branch 5 taken 151 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
573 std::shared_ptr<Playlist> newParent = replaceSelf ? m_parent.load() : weak_from_this().lock();
2025
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 573 times.
573 if (!newParent) {
2026 // Only an instance the player owns is processed, so this can't
2027 // happen; without an owning reference to link to, don't insert.
2028 ✗ LogErr(VB_PLAYLIST, "Not inserting playlist '%s': the playlist it interrupts is not owned by the player\n",
2029 m_insertedPlaylist.c_str());
2030 ✗ m_insertedPlaylist = "";
2031 ✗ return nullptr;
2032 }
2033
2034 // Bound the stack of inserted playlists. Inline sub-playlists stop at
2035 // 5 levels in LoadJSONIntoPlaylist, but inserts (Insert Playlist
2036 // commands, Branch-to-playlist) had no limit: a playlist that branches
2037 // to itself, or A -> B -> A, nested one level per pass until memory or
2038 // the stack ran out.
2039 573 int depth = 1;
2040
3/4
✓ Branch 0 taken 643 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 643 times.
✓ Branch 3 taken 573 times.
1216 for (std::shared_ptr<Playlist> p = newParent; p; p = p->m_parent.load()) {
2041 643 depth++;
2042 573 }
2043
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 572 times.
573 if (depth > MAX_INSERTED_PLAYLIST_DEPTH) {
2044
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogErr(VB_PLAYLIST, "Not inserting playlist '%s': inserted playlists are already nested %d deep (does a playlist insert or branch to itself?)\n",
2045 m_insertedPlaylist.c_str(), depth - 1);
2046
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 WarningHolder::AddWarningTimeout(60, 24, "Recursive playlist: too many nested inserts trying to start '" + m_insertedPlaylist + "'");
2047
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 m_insertedPlaylist = "";
2048 1 return nullptr;
2049 }
2050
2051 // The player owns the new instance from birth; plRef only keeps it
2052 // alive across the start attempt below, before it is published.
2053
1/2
✓ Branch 0 taken 572 times.
✗ Branch 1 not taken.
572 std::shared_ptr<Playlist> plRef = Player::INSTANCE.CreatePlaylist(newParent);
2054 572 Playlist* pl = plRef.get();
2055
1/2
✓ Branch 0 taken 572 times.
✗ Branch 1 not taken.
572 std::string plname = m_insertedPlaylist;
2056 // PlayImpl, not Play: this runs inside the parent's transition
2057 // (depth > 1) and the child MUST start inline as part of the switch —
2058 // the public Play() would defer it.
2059
2/4
✓ Branch 0 taken 572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 572 times.
✗ Branch 3 not taken.
1144 pl->PlayImpl(m_insertedPlaylist.c_str(), m_insertedPlaylistPosition, 0, m_scheduleEntry, m_insertedPlaylistEndPosition);
2060
1/2
✓ Branch 0 taken 572 times.
✗ Branch 1 not taken.
572 m_insertedPlaylist = "";
2061 // An instance is condemned to PL_CLEANUPS only once it is no longer
2062 // the current playlist — the drain drops the owning reference
2063 // unconditionally, so condemning the instance the player is still
2064 // running would leave nothing owning it. That is why the cleanup of
2065 // `this` waits until the replacement is known to be playing.
2066
3/4
✓ Branch 0 taken 572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 566 times.
✓ Branch 3 taken 6 times.
572 if (pl->IsPlaying()) {
2067
1/2
✓ Branch 0 taken 566 times.
✗ Branch 1 not taken.
566 LogDebug(VB_PLAYLIST, "Switching to inserted playlist '%s'\n", plname.c_str());
2068
1/2
✓ Branch 0 taken 566 times.
✗ Branch 1 not taken.
566 Player::INSTANCE.SetCurrentPlaylist(pl);
2069
2/2
✓ Branch 0 taken 151 times.
✓ Branch 1 taken 415 times.
566 if (replaceSelf) {
2070
1/2
✓ Branch 0 taken 151 times.
✗ Branch 1 not taken.
151 m_parent = nullptr;
2071
1/2
✓ Branch 0 taken 151 times.
✗ Branch 1 not taken.
151 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
2072
1/2
✓ Branch 0 taken 151 times.
✗ Branch 1 not taken.
151 PL_CLEANUPS.push_back(this);
2073 151 }
2074 566 return pl;
2075 }
2076 {
2077
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
2078
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 PL_CLEANUPS.push_back(pl);
2079 6 }
2080
3/12
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
6 if (replaceSelf && Player::INSTANCE.PlaylistSnapshot().get() != this) {
2081 // pl failed to start and its own SetIdle() already handed the
2082 // player on to our parent, so nothing will process us again.
2083 ✗ m_parent = nullptr;
2084 ✗ std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
2085 ✗ PL_CLEANUPS.push_back(this);
2086 ✗ }
2087
6/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 566 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 566 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 567 times.
1705 }
2088 5481 return nullptr;
2089 }
2090
2091 /*
2092 *
2093 */
2094 14085 void Playlist::ProcessMedia(void) {
2095
1/2
✓ Branch 0 taken 14085 times.
✗ Branch 1 not taken.
14085 std::unique_lock<std::mutex> lock(mediaOutputLock);
2096
1/2
✓ Branch 0 taken 14085 times.
✗ Branch 1 not taken.
14085 if (mediaOutput) {
2097
1/2
✓ Branch 0 taken 14085 times.
✗ Branch 1 not taken.
14085 mediaOutput->Process();
2098 }
2099 14085 }
2100
2101 /*
2102 *
2103 */
2104 4490 void Playlist::SetIdle(bool exit) {
2105 4490 PlaylistTransitionGuard guard;
2106 4490 m_status = FPP_STATUS_IDLE;
2107
2108 4490 std::map<std::string, std::string> keywords;
2109
3/4
✓ Branch 0 taken 4490 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1830 times.
✓ Branch 3 taken 2660 times.
4490 if (m_name != "") {
2110
3/6
✓ Branch 0 taken 1830 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1830 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1830 times.
✗ Branch 5 not taken.
5490 keywords["PLAYLIST_NAME"] = m_name;
2111 }
2112
1/2
✓ Branch 0 taken 4490 times.
✗ Branch 1 not taken.
4490 Cleanup();
2113 // An insert still waiting for the current item to end goes with the
2114 // playlist it was for. Not in Cleanup(), which a reload also runs.
2115
1/2
✓ Branch 0 taken 4490 times.
✗ Branch 1 not taken.
4490 m_insertedPlaylist = "";
2116
2117 4490 bool publishIdle = true;
2118 // Walk up past parents that are already condemned to PL_CLEANUPS — making
2119 // one current again would resurrect an object the next Process() tick
2120 // releases (leaving the player pointing at a corpse), or double-play it. A
2121 // parent can be condemned while we're exiting when a re-entrant stop tore
2122 // down an intermediate level of an inserted-playlist stack.
2123 // par is held, not borrowed: another thread can condemn it once the walk
2124 // lets go of the lock (a second Start Playlist that already sees it as
2125 // current), and the main loop then releases it while this hand-back is
2126 // still resuming it and reading its status.
2127
1/2
✓ Branch 0 taken 4490 times.
✗ Branch 1 not taken.
4490 std::shared_ptr<Playlist> par = m_parent.load();
2128 {
2129
1/2
✓ Branch 0 taken 4490 times.
✗ Branch 1 not taken.
4490 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
2130
5/8
✓ Branch 0 taken 418 times.
✓ Branch 1 taken 4072 times.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 418 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4490 times.
4490 while (par && std::find(PL_CLEANUPS.begin(), PL_CLEANUPS.end(), par.get()) != PL_CLEANUPS.end()) {
2131 ✗ par = par->m_parent.load();
2132 }
2133 4490 }
2134
3/4
✓ Branch 0 taken 418 times.
✓ Branch 1 taken 4072 times.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
4490 bool handingBack = par && exit;
2135 // A stop of every level hands back without resuming: the parent is the
2136 // next level to stop, not a playlist that carries on.
2137
4/4
✓ Branch 0 taken 418 times.
✓ Branch 1 taken 4072 times.
✓ Branch 2 taken 323 times.
✓ Branch 3 taken 95 times.
4490 bool resumeParent = handingBack && !tl_stoppingAllLevels;
2138 // Media prepared for what would have played next holds a decoder and
2139 // keeps the display up behind it, so it goes -- unless this is an insert
2140 // ending and the media is the resumed playlist's next entry
2141 // (PrepareParentsNext()). That claims it, or discards it on a mismatch.
2142
2/2
✓ Branch 0 taken 4167 times.
✓ Branch 1 taken 323 times.
4490 if (!resumeParent) {
2143
1/2
✓ Branch 0 taken 4167 times.
✗ Branch 1 not taken.
4167 DiscardPreparedMediaOutput();
2144 }
2145
2146 // Both deferred (see PlaylistTransitionGuard): a PLAYLIST_STOPPED preset
2147 // that starts another playlist used to run here, mid-SetIdle — the rest
2148 // of this function then continued tearing down state the preset's Play()
2149 // had just replaced, and the trailing "idle" publishes lied about the
2150 // actual (playing) state. The "stop" callback snapshot keeps the OLD
2151 // playlist's info, which is what the plugin is being told stopped.
2152
2/2
✓ Branch 0 taken 1830 times.
✓ Branch 1 taken 2660 times.
4490 if (!keywords.empty()) {
2153
4/6
✓ Branch 0 taken 1830 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1830 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 1818 times.
3660 if (CommandManager::INSTANCE.HasPreset("PLAYLIST_STOPPED")) {
2154
3/8
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
12 QueuePlaylistNotification([keywords, resumeParent]() mutable {
2155 12 HandedBackStoppedPresetScope scope(resumeParent);
2156
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
24 CommandManager::INSTANCE.TriggerPreset("PLAYLIST_STOPPED", keywords);
2157 12 });
2158 }
2159 }
2160
2161 {
2162
1/2
✓ Branch 0 taken 4490 times.
✗ Branch 1 not taken.
4490 Json::Value info = GetInfo();
2163
1/2
✓ Branch 0 taken 4490 times.
✗ Branch 1 not taken.
4490 std::string sec = m_currentSectionStr;
2164 4490 int pos = m_sectionPosition;
2165
4/12
✓ Branch 0 taken 4490 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4490 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4490 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4490 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
4490 QueuePlaylistNotification([info, sec, pos]() {
2166
2/4
✓ Branch 0 taken 4489 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4487 times.
✗ Branch 3 not taken.
8978 PluginManager::INSTANCE.playlistCallback(info, "stop", sec, pos);
2167 4487 });
2168 4490 }
2169
2170
2/2
✓ Branch 0 taken 418 times.
✓ Branch 1 taken 4072 times.
4490 if (handingBack) {
2171 // par is still owned: it is on the parent chain and not condemned, so
2172 // the player has never released it.
2173
1/2
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
418 Player::INSTANCE.SetCurrentPlaylist(par.get());
2174
2/2
✓ Branch 0 taken 323 times.
✓ Branch 1 taken 95 times.
418 if (resumeParent) {
2175 // Unconditional: Resume() is a no-op unless par is paused, and par
2176 // may be STOPPING_* over a paused entry (stopped while we played).
2177
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 par->Resume();
2178 // Resume() only republishes when par was paused (Insert Immediate).
2179 // After an Insert After Current par never paused, so the MQTT name and
2180 // status topics would still describe the finished insert.
2181
2/4
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 323 times.
✗ Branch 3 not taken.
323 if (par->IsPlaying()) {
2182
2/4
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 323 times.
✗ Branch 3 not taken.
967 Events::Publish("playlist/name/status", par->m_name);
2183
4/8
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 323 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 323 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 323 times.
✗ Branch 7 not taken.
971 Events::Publish("status", PlaylistStatusToString(par->m_status));
2184
2/4
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 323 times.
✗ Branch 3 not taken.
646 Events::Publish("playlist/section/status", par->m_currentSectionStr);
2185
2/4
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 323 times.
✗ Branch 3 not taken.
967 Events::Publish("playlist/sectionPosition/status", par->m_sectionPosition);
2186 }
2187 }
2188 {
2189
1/2
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
418 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
2190
1/2
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
418 PL_CLEANUPS.push_back(this);
2191 418 }
2192 // Retired: a thread still holding a snapshot of this level must not
2193 // reach the parent (released on a later tick) through us.
2194
1/2
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
418 m_parent = nullptr;
2195
2196
3/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 417 times.
✓ Branch 3 taken 1 times.
418 if (par->getPlaylistStatus() != FPP_STATUS_IDLE)
2197 417 publishIdle = false;
2198
2/2
✓ Branch 0 taken 1421 times.
✓ Branch 1 taken 2651 times.
4072 } else if (exit) {
2199
2/4
✓ Branch 0 taken 1421 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1421 times.
1421 if (m_parent.load()) {
2200 // Whole remaining chain was condemned — we are still the current
2201 // playlist, so we must NOT be condemned too (the PL_CLEANUPS drain
2202 // releases unconditionally, and the player's own reference is the
2203 // only thing that would be left holding us). We become the
2204 // resident idle playlist, like any top-level SetIdle; just drop
2205 // the dangling pointer into the condemned chain.
2206 ✗ m_parent = nullptr;
2207 }
2208
1/2
✓ Branch 0 taken 1421 times.
✗ Branch 1 not taken.
1421 sequence->SendBlankingData();
2209 }
2210
2211
2/2
✓ Branch 0 taken 4073 times.
✓ Branch 1 taken 417 times.
4490 if (publishIdle) {
2212
3/6
✓ Branch 0 taken 4073 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4073 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4073 times.
✗ Branch 5 not taken.
16292 Events::Publish("status", "idle");
2213
3/6
✓ Branch 0 taken 4073 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4073 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4073 times.
✗ Branch 5 not taken.
16292 Events::Publish("playlist/name/status", "");
2214
3/6
✓ Branch 0 taken 4073 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4073 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4073 times.
✗ Branch 5 not taken.
16292 Events::Publish("playlist/section/status", "");
2215
2/4
✓ Branch 0 taken 4073 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4073 times.
✗ Branch 3 not taken.
8146 Events::Publish("playlist/sectionPosition/status", 0);
2216
2/4
✓ Branch 0 taken 4073 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4073 times.
✗ Branch 3 not taken.
8146 Events::Publish("playlist/repeat/status", 0);
2217 }
2218 4490 }
2219
2220 /*
2221 *
2222 */
2223 906 int Playlist::CleanupIfIdle(void) {
2224
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2225
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 905 times.
906 if (m_status != FPP_STATUS_IDLE)
2226 1 return 0;
2227
1/2
✓ Branch 0 taken 905 times.
✗ Branch 1 not taken.
905 return Cleanup();
2228 906 }
2229
2230 8229 int Playlist::Cleanup(void) {
2231
1/2
✓ Branch 0 taken 8229 times.
✗ Branch 1 not taken.
8229 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2232
2233 {
2234
1/2
✓ Branch 0 taken 8229 times.
✗ Branch 1 not taken.
8229 std::lock_guard<std::mutex> nl(m_nameLock);
2235
1/2
✓ Branch 0 taken 8229 times.
✗ Branch 1 not taken.
8229 m_name = "";
2236 8229 }
2237
1/2
✓ Branch 0 taken 8229 times.
✗ Branch 1 not taken.
8229 m_desc = "";
2238 8229 m_generatedOnTheFly = false;
2239
1/2
✓ Branch 0 taken 8229 times.
✗ Branch 1 not taken.
8229 m_currentSectionStr = "New";
2240 8229 m_currentSection = nullptr;
2241 8229 m_startPosition = 0;
2242 8229 m_sectionPosition = 0;
2243 8229 m_repeat = 0;
2244 8229 m_loopCount = 0;
2245 8229 m_startTime = 0;
2246 // A stop during the gap between sequences left these set, and the next
2247 // playlist's first Process() "ended the pause" by starting its first
2248 // entry a second time (media restarted, command entries ran twice).
2249 8229 m_isInGlobalPause = false;
2250 8229 m_shouldStartGlobalPause = false;
2251 8229 m_loopHoldUntilMS = 0;
2252 // Here, not in Start(): navigation restarts in place through Start().
2253 8229 m_warnedInstantLoop = false;
2254 8229 m_leadInRows.clear();
2255 8229 m_mainRows.clear();
2256 8229 m_leadOutRows.clear();
2257 8229 m_nextShuffle.clear();
2258 8229 m_preparedAfter = nullptr;
2259
2260
2/2
✓ Branch 0 taken 891 times.
✓ Branch 1 taken 8229 times.
9120 while (m_leadIn.size()) {
2261 891 PlaylistEntryBase* entry = m_leadIn.back();
2262 891 m_leadIn.pop_back();
2263 {
2264
1/2
✓ Branch 0 taken 891 times.
✗ Branch 1 not taken.
891 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
2265
1/2
✓ Branch 0 taken 891 times.
✗ Branch 1 not taken.
891 PL_ENTRY_CLEANUPS.push_back(entry);
2266 891 }
2267 }
2268
2269
2/2
✓ Branch 0 taken 4423 times.
✓ Branch 1 taken 8229 times.
12652 while (m_mainPlaylist.size()) {
2270 4423 PlaylistEntryBase* entry = m_mainPlaylist.back();
2271 4423 m_mainPlaylist.pop_back();
2272 {
2273
1/2
✓ Branch 0 taken 4423 times.
✗ Branch 1 not taken.
4423 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
2274
1/2
✓ Branch 0 taken 4423 times.
✗ Branch 1 not taken.
4423 PL_ENTRY_CLEANUPS.push_back(entry);
2275 4423 }
2276 }
2277
2278
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8229 times.
8247 while (m_leadOut.size()) {
2279 18 PlaylistEntryBase* entry = m_leadOut.back();
2280 18 m_leadOut.pop_back();
2281 {
2282
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 std::lock_guard<std::mutex> lk(PL_CLEANUPS_LOCK);
2283
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 PL_ENTRY_CLEANUPS.push_back(entry);
2284 18 }
2285 }
2286 8229 return 1;
2287 8229 }
2288
2289 39 void Playlist::InsertPlaylistAsNext(const std::string& filename, const int position, int endPosition) {
2290 // Guard before the lock, like every transition: when idle the Play()
2291 // below is then deferred and run after the lock is released, instead of
2292 // draining its presets and plugin callbacks while holding it.
2293 39 PlaylistTransitionGuard guard;
2294
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2295
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 39 times.
39 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
2296 ✗ lck.unlock();
2297 ✗ cur->InsertPlaylistAsNext(filename, position, endPosition);
2298 ✗ return;
2299
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 }
2300
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 PluginManager::INSTANCE.playlistInserted(filename, position, endPosition, false);
2301
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 30 times.
39 if (m_status == FPP_STATUS_IDLE) {
2302
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 Play(filename, position, 0, m_scheduleEntry, endPosition);
2303 } else {
2304
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 m_insertedPlaylist = filename;
2305 30 m_insertedPlaylistPosition = position;
2306 30 m_insertedPlaylistEndPosition = endPosition;
2307 // What was prepared is no longer what plays next: prepare again (at
2308 // once, if the current entry is already in its last moments).
2309 30 m_preparedAfter = nullptr;
2310 }
2311
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
39 }
2312 659 void Playlist::InsertPlaylistImmediate(const std::string& filename, const int position, int endPosition) {
2313 // Guard before the lock, like every transition: when idle the Play()
2314 // below is then deferred and run after the lock is released, instead of
2315 // draining its presets and plugin callbacks while holding it.
2316 659 PlaylistTransitionGuard guard;
2317
1/2
✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
659 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2318
2/4
✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 659 times.
659 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
2319 ✗ lck.unlock();
2320 ✗ cur->InsertPlaylistImmediate(filename, position, endPosition);
2321 ✗ return;
2322
1/2
✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
659 }
2323
1/2
✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
659 PluginManager::INSTANCE.playlistInserted(filename, position, endPosition, true);
2324
2/2
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 588 times.
659 if (m_status == FPP_STATUS_IDLE) {
2325
1/2
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
71 Play(filename, position, 0, m_scheduleEntry, endPosition);
2326 } else {
2327
1/2
✓ Branch 0 taken 588 times.
✗ Branch 1 not taken.
588 Pause();
2328
1/2
✓ Branch 0 taken 588 times.
✗ Branch 1 not taken.
588 m_insertedPlaylist = filename;
2329 588 m_insertedPlaylistPosition = position;
2330 588 m_insertedPlaylistEndPosition = endPosition;
2331 }
2332
2/4
✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 659 times.
✗ Branch 3 not taken.
659 }
2333
2334 1809 int Playlist::Play(const std::string& filename, const int position, const int repeat, const int scheduleEntry, const int endPosition) {
2335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1809 times.
1809 if (filename.empty())
2336 ✗ return 0;
2337
2338 1809 PlaylistTransitionGuard guard;
2339
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 1722 times.
1809 if (tl_transitionDepth > 1) {
2340 // Re-entrant call: another transition on THIS thread is still on the
2341 // stack — e.g. a "Start Playlist" command entry executing inside its
2342 // own StartPlaying() frame, or a native plugin callback. Executing
2343 // inline would reload/clobber playlist state that the outer frames
2344 // still reference (m_currentSection, positions), so record the
2345 // request; the outermost PlaylistTransitionGuard replays it after
2346 // the stack unwinds. This replaces (and generalizes) the old
2347 // PlaylistEntryCommand/PlaylistEntryScript dynamic_cast check that
2348 // deferred via the startNewPlaylistFilename members.
2349
1/2
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
87 LogDebug(VB_PLAYLIST, "Playlist::Play('%s') re-entrant (depth %d) — deferring until current transition completes\n",
2350 filename.c_str(), tl_transitionDepth);
2351
1/2
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
87 std::lock_guard<std::mutex> l(s_pendingStartMutex);
2352
1/2
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
87 s_pendingStartFilename = filename;
2353 87 s_pendingStartPosition = position;
2354 87 s_pendingStartRepeat = repeat;
2355 87 s_pendingStartScheduleEntry = scheduleEntry;
2356 87 s_pendingStartEndPosition = endPosition;
2357 87 return 1;
2358 87 }
2359
1/2
✓ Branch 0 taken 1722 times.
✗ Branch 1 not taken.
1722 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2360
3/4
✓ Branch 0 taken 1722 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1719 times.
1722 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
2361 // An idle, condemned level would otherwise load and start the new
2362 // playlist itself, where nothing processes it.
2363
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 lck.unlock();
2364
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 return cur->Play(filename, position, repeat, scheduleEntry, endPosition);
2365
2/2
✓ Branch 0 taken 1719 times.
✓ Branch 1 taken 3 times.
1722 }
2366
1/2
✓ Branch 0 taken 1719 times.
✗ Branch 1 not taken.
1719 return PlayImpl(filename, position, repeat, scheduleEntry, endPosition);
2367 1809 }
2368
2369 // The body of Play(). Called only from Play() (guarded, non-re-entrant) and
2370 // from SwitchToInsertedPlaylist(), which must start the inserted child
2371 // playlist inline as part of the parent's own transition.
2372 2308 int Playlist::PlayImpl(const std::string& filename, const int position, const int repeat, const int scheduleEntry, const int endPosition) {
2373
1/2
✓ Branch 0 taken 2308 times.
✗ Branch 1 not taken.
2308 LogDebug(VB_PLAYLIST, "Playlist::Play('%s', %d, %d, %d, %d)\n",
2374 filename.c_str(), position, repeat, scheduleEntry, endPosition);
2375
2376 // From before the stop below until the new playlist has started, and no
2377 // longer: the deferred presets and plugin callbacks run after this.
2378
1/2
✓ Branch 0 taken 2308 times.
✗ Branch 1 not taken.
2308 Player::SwitchScope switching;
2379
1/2
✓ Branch 0 taken 2308 times.
✗ Branch 1 not taken.
2308 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2380
2381 // Paused counts as running: it used to fall through to the load below,
2382 // which replaced the paused entry without stopping it -- no stop
2383 // callback, no PLAYLIST_STOPPED preset, and an inserted level loaded in
2384 // place instead of handing back to its parent.
2385
2/2
✓ Branch 0 taken 2177 times.
✓ Branch 1 taken 2 times.
4487 if ((m_status == FPP_STATUS_PLAYLIST_PLAYING) ||
2386
1/2
✓ Branch 0 taken 2177 times.
✗ Branch 1 not taken.
4356 (m_status == FPP_STATUS_PLAYLIST_PAUSED) ||
2387
5/6
✓ Branch 0 taken 2179 times.
✓ Branch 1 taken 129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2177 times.
✓ Branch 4 taken 131 times.
✓ Branch 5 taken 2177 times.
6664 (m_status == FPP_STATUS_STOPPING_GRACEFULLY) ||
2388 2177 (m_status == FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP)) {
2389 // Running but not current: a playlist was inserted under us since
2390 // Play() looked (or we were reached by the delegation below, after a
2391 // stop). Everything past here locks the current level while holding
2392 // ours -- parent before child, the reverse of SetIdle() resuming its
2393 // parent under the child's lock -- so hand the start to the current
2394 // level, as Play() does. Under our lock no child can be inserted, so
2395 // once this check passes it holds. A level SwitchToInsertedPlaylist()
2396 // is starting is idle and never gets here.
2397
3/4
✓ Branch 0 taken 131 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 130 times.
131 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
2398
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 lck.unlock();
2399
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 return cur->PlayImpl(filename, position, repeat, scheduleEntry, endPosition);
2400
2/2
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 1 times.
131 }
2401
5/10
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 130 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 130 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 130 times.
✗ Branch 9 not taken.
130 std::string fullfilename = FPP_DIR_PLAYLIST("/" + filename + ".json");
2402
2403 // Only a fully loaded copy can be jumped within: SetPosition() indexes
2404 // the loaded entries, and a copy Load() trimmed (given a start and
2405 // end item) no longer lines up with the playlist's positions.
2406
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 129 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 130 times.
✗ Branch 5 not taken.
130 bool loadedWhole = ((m_loadStartPos == -1) || (m_loadStartPos == 0)) && (m_loadEndPos < 0);
2407
6/8
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 46 times.
✗ Branch 7 not taken.
212 if ((m_filename == fullfilename) && (repeat == m_repeat) && m_currentSection && position >= 0 &&
2408
5/6
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46 times.
✓ Branch 5 taken 84 times.
212 loadedWhole && (endPosition < 0)) {
2409 // the requested playlist is already running and loaded, we can jump right to the index
2410
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 PlaylistEntryBase* entry = CurrentEntry();
2411
4/8
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 46 times.
✗ Branch 7 not taken.
46 if (entry && entry->IsPlaying()) {
2412
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 entry->Stop();
2413 }
2414
2415 46 m_sectionPosition = 0;
2416 // position is a row of the playlist file; the loaded copy counts
2417 // a sub-playlist row's entries separately.
2418
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 int p = FileRowToPosition(position);
2419 46 int mainPos = p - (int)m_leadIn.size();
2420
6/8
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 41 times.
46 if ((m_random > 0) && (mainPos >= 0) && (mainPos < (int)m_mainPlaylist.size())) {
2421 // The row maps to where the entry was loaded, and the main
2422 // playlist is shuffled by now: as when starting part-way in
2423 // below, play that entry next and the rest in a fresh shuffle.
2424
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 p = ShuffleMainPlaylistFrom(p);
2425 }
2426
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 SetPosition(p);
2427 // Deliberate here, unlike the call at the end of this function:
2428 // this branch is a jump inside a playlist that is already running
2429 // (possibly stopping gracefully), so normalising to PLAYING is what
2430 // makes Start() report "playing" rather than "start".
2431 46 m_status = FPP_STATUS_PLAYLIST_PLAYING;
2432
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 Start();
2433 46 return 1;
2434
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 } else if (m_currentSection) {
2435 // Re-entrant callers (command/script entries, plugin callbacks)
2436 // never reach here — Play() deferred them — so it is safe to
2437 // stop the current playlist and load the new one directly. Every
2438 // level: stopped one at a time, each parent resumed in between,
2439 // for the 100 ms below, before the next pass stopped it.
2440
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 StopNowAllLevelsImpl(1);
2441
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2442
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 std::shared_ptr<Playlist> cur = Player::INSTANCE.PlaylistSnapshot();
2443
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 68 times.
84 if (cur.get() != this) {
2444 // This was an inserted (nested) playlist: the stop unwound the
2445 // stack -- the current playlist is now the outermost one (idle),
2446 // and `this` is already queued on PL_CLEANUPS.
2447 // Loading the new playlist into `this` would start it on a
2448 // condemned object the player never processes and the next
2449 // Process() tick releases (the historical "started a playlist
2450 // from inside nested playlists and it blipped and vanished
2451 // while the outer playlist resumed" bug). Delegate to the
2452 // now-active level instead, which performs the load. Not
2453 // under our lock: `this` is done with, and holding it while
2454 // the next level locks itself would order the two locks.
2455
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 lck.unlock();
2456
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 return cur->PlayImpl(filename, position, repeat, scheduleEntry, endPosition);
2457 }
2458
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 16 times.
84 }
2459
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 62 times.
130 }
2460 2245 m_scheduleEntry = scheduleEntry;
2461 2245 m_forceStop = 0;
2462
2463 2245 int tmpStartPos = position;
2464 2245 int tmpEndPos = endPosition;
2465
2466
3/4
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 2207 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 38 times.
2245 if ((tmpEndPos >= 0) && (tmpEndPos < tmpStartPos)) {
2467 ✗ LogWarn(VB_PLAYLIST, "Playlist::Play() called with end position less than start position: Play('%s', %d, %d, %d, %d)\n",
2468 filename.c_str(), position, repeat, scheduleEntry, endPosition);
2469 ✗ tmpEndPos = -1;
2470 }
2471
2472 // Only a range (a start AND an end, as Insert Playlist sends to play one
2473 // item) trims the loaded copy. A start alone -- Start Playlist At Item, or
2474 // the resume after an fppd restart -- loads every entry and starts part-way
2475 // in. Trimming those left the status page, and every later reload of the
2476 // file, showing only the entries from the start point on: a show resumed
2477 // after a restart came back with part of its playlist missing.
2478 2245 int startRow = -1;
2479
4/4
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 2201 times.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 3 times.
2245 if ((tmpStartPos > 0) && (tmpEndPos < 0)) {
2480 41 startRow = tmpStartPos;
2481 41 tmpStartPos = -1;
2482 }
2483
2484 2245 m_loadStartPos = tmpStartPos;
2485 2245 m_loadEndPos = tmpEndPos;
2486
2487
1/2
✓ Branch 0 taken 2245 times.
✗ Branch 1 not taken.
2245 Load(filename);
2488
2489
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 2069 times.
2245 if (tmpStartPos >= 0) {
2490 // Load() would have trimmed our internal copy of the playlist, so adjust our values
2491
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 173 times.
176 if (tmpEndPos >= 0)
2492 3 tmpEndPos -= tmpStartPos;
2493
2494 176 tmpStartPos = 0;
2495 }
2496
2497 2245 int p = tmpStartPos;
2498
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 2204 times.
2245 if (startRow > 0) {
2499 // A row past the end maps to the end, which Start() wraps to the start.
2500
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 p = FileRowToPosition(startRow);
2501 }
2502
2503
6/6
✓ Branch 0 taken 2069 times.
✓ Branch 1 taken 176 times.
✓ Branch 2 taken 2051 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 105 times.
✓ Branch 5 taken 2122 times.
2245 if ((tmpStartPos == 0 || tmpStartPos == -1) && (m_random > 0)) {
2504 105 int mainPos = p - (int)m_leadIn.size();
2505
6/8
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 78 times.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 27 times.
✓ Branch 7 taken 78 times.
105 if ((startRow > 0) && (mainPos >= 0) && (mainPos < (int)m_mainPlaylist.size())) {
2506
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 p = ShuffleMainPlaylistFrom(p);
2507 } else {
2508
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 RandomizeMainPlaylist();
2509 }
2510 }
2511
2512
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2227 times.
2245 if (p == -2) {
2513 // random
2514 18 int l = m_mainPlaylist.size();
2515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (l > 1) {
2516 ✗ p = FPPrand() % l;
2517 ✗ p = p + m_leadIn.size();
2518 }
2519 }
2520
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 2028 times.
2245 if (p >= 0)
2521
1/2
✓ Branch 0 taken 217 times.
✗ Branch 1 not taken.
217 SetPosition(p);
2522
2523
2/2
✓ Branch 0 taken 2188 times.
✓ Branch 1 taken 57 times.
2245 if (repeat >= 0)
2524
1/2
✓ Branch 0 taken 2188 times.
✗ Branch 1 not taken.
2188 SetRepeat(repeat);
2525
2526 2245 m_stopAtPos = tmpEndPos;
2527
2528 // Deliberately not setting m_status here. Start() tells a fresh start from
2529 // a restart by reading m_status before it flips to PLAYING, and it sets
2530 // PLAYING itself a few lines in. Setting it first made that read always say
2531 // PLAYING, so the playlist callback reported "playing" even when the player
2532 // had been idle - which made "start" unreachable in player mode, the only
2533 // other site that sends it being the remote-mode fake in mediaoutput.cpp.
2534 // Plugins that key on the documented "start" action therefore never ran.
2535 // This call is made holding m_playlistMutex, so no other thread can observe
2536 // the window before Start() sets the status.
2537
1/2
✓ Branch 0 taken 2245 times.
✗ Branch 1 not taken.
2245 int result = Start();
2538
2539
2/2
✓ Branch 0 taken 2237 times.
✓ Branch 1 taken 8 times.
2245 if (result == 1) {
2540 2237 std::map<std::string, std::string> keywords;
2541
3/6
✓ Branch 0 taken 2237 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2237 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2237 times.
✗ Branch 5 not taken.
6711 keywords["PLAYLIST_NAME"] = m_name;
2542
4/6
✓ Branch 0 taken 2237 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2237 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 2226 times.
4474 if (CommandManager::INSTANCE.HasPreset("PLAYLIST_STARTED")) {
2543 // Deferred: preset commands run arbitrary code inline (including
2544 // "Start Playlist", which used to recurse into Play() under the
2545 // lock). Fires after this transition completes and the mutex is
2546 // released — see PlaylistTransitionGuard.
2547
3/6
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
11 QueuePlaylistNotification([keywords]() mutable {
2548
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
20 CommandManager::INSTANCE.TriggerPreset("PLAYLIST_STARTED", keywords);
2549 10 });
2550 }
2551 2237 }
2552
2553 2245 return result;
2554 2308 }
2555
2556 /*
2557 *
2558 */
2559 305 void Playlist::SetPosition(int position) {
2560 // The MQTT position topics call this from the MQTT thread, while the
2561 // playlist thread reads m_startPosition in Start() under the lock.
2562
1/2
✓ Branch 0 taken 305 times.
✗ Branch 1 not taken.
305 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2563 305 m_startPosition = position;
2564
2565
2/4
✓ Branch 0 taken 305 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 305 times.
✗ Branch 3 not taken.
305 Events::Publish("playlist/position/status", position);
2566 305 }
2567
2568 /*
2569 *
2570 */
2571 4846 void Playlist::SetRepeat(int repeat) {
2572 4846 m_repeat = repeat;
2573
2574
2/4
✓ Branch 0 taken 4846 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4846 times.
✗ Branch 3 not taken.
4846 Events::Publish("playlist/repeat/status", repeat);
2575 4846 }
2576
2577 114 void Playlist::RandomizeMainPlaylist() {
2578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
114 if (m_random == 0) {
2579 ✗ return;
2580 }
2581
2582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
114 if (m_mainPlaylist.empty()) {
2583 ✗ return;
2584 }
2585
2586
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 m_mainPlaylist = ShuffledMainPlaylist();
2587 }
2588
2589 114 std::vector<PlaylistEntryBase*> Playlist::ShuffledMainPlaylist() const {
2590
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 std::vector<PlaylistEntryBase*> tmpPlaylist = m_mainPlaylist;
2591 114 std::vector<PlaylistEntryBase*> shuffled;
2592 114 int origSize = tmpPlaylist.size();
2593
2594
2/2
✓ Branch 0 taken 491 times.
✓ Branch 1 taken 114 times.
605 while (tmpPlaylist.size()) {
2595 491 int l = tmpPlaylist.size();
2596
2/2
✓ Branch 0 taken 377 times.
✓ Branch 1 taken 114 times.
491 if (l > 1) {
2597
1/2
✓ Branch 0 taken 377 times.
✗ Branch 1 not taken.
377 int p = FPPrand() % l;
2598
2599 // If this is the first item found and it is the last
2600 // item in the previous list then try again unless our playlist is only 2 items long
2601
8/8
✓ Branch 0 taken 134 times.
✓ Branch 1 taken 243 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 110 times.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 20 times.
✓ Branch 7 taken 357 times.
377 if ((!shuffled.size()) && (p == (origSize - 1)) && origSize > 2)
2602 20 continue;
2603
2604
1/2
✓ Branch 0 taken 357 times.
✗ Branch 1 not taken.
357 shuffled.push_back(tmpPlaylist[p]);
2605
1/2
✓ Branch 0 taken 357 times.
✗ Branch 1 not taken.
357 tmpPlaylist.erase(tmpPlaylist.begin() + p);
2606 } else {
2607
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 shuffled.push_back(tmpPlaylist.back());
2608 114 tmpPlaylist.pop_back();
2609 }
2610 }
2611 114 return shuffled;
2612 114 }
2613
2614 // Starting part-way into a shuffled main playlist: the entry loaded at
2615 // position (counted across the whole playlist, as loaded) plays first, then
2616 // the rest in a fresh shuffle -- its row says nothing about which of the
2617 // others have played. The entry is found by its load position, not by
2618 // index, since the main playlist may already be shuffled. Returns the
2619 // position it now starts at.
2620 32 int Playlist::ShuffleMainPlaylistFrom(int position) {
2621 32 PlaylistEntryBase* first = nullptr;
2622
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 for (auto* e : m_mainPlaylist) {
2623
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 82 times.
114 if (e->GetPositionInPlaylist() == position) {
2624 32 first = e;
2625 32 break;
2626 }
2627 }
2628
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 RandomizeMainPlaylist();
2629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (!first) {
2630 ✗ return position;
2631 }
2632
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
32 m_mainPlaylist.erase(std::find(m_mainPlaylist.begin(), m_mainPlaylist.end(), first));
2633
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 m_mainPlaylist.insert(m_mainPlaylist.begin(), first);
2634 32 return m_leadIn.size();
2635 }
2636
2637 /*
2638 *
2639 */
2640 2 void Playlist::Dump(void) {
2641 2 LogDebug(VB_PLAYLIST, "Playlist: %s\n", m_name.c_str());
2642
2643 2 LogDebug(VB_PLAYLIST, " Description : %s\n", m_desc.c_str());
2644 4 LogDebug(VB_PLAYLIST, " Repeat : %d\n", m_repeat.load());
2645 2 LogDebug(VB_PLAYLIST, " Loop Count : %d\n", m_loopCount);
2646 2 LogDebug(VB_PLAYLIST, " Current Section : %s\n", m_currentSectionStr.c_str());
2647 2 LogDebug(VB_PLAYLIST, " Section Position : %d\n", m_sectionPosition);
2648
2649
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (m_leadIn.size()) {
2650 1 LogDebug(VB_PLAYLIST, " Lead In:\n");
2651
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (int c = 0; c < m_leadIn.size(); c++)
2652 1 m_leadIn[c]->Dump();
2653 } else {
2654 1 LogDebug(VB_PLAYLIST, " Lead In : (No Lead In)\n");
2655 }
2656
2657
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (m_mainPlaylist.size()) {
2658 2 LogDebug(VB_PLAYLIST, " Main Playlist:\n");
2659
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 for (int c = 0; c < m_mainPlaylist.size(); c++)
2660 3 m_mainPlaylist[c]->Dump();
2661 } else {
2662 ✗ LogDebug(VB_PLAYLIST, " Main Playlist : (No Main Playlist)\n");
2663 }
2664
2665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (m_leadOut.size()) {
2666 ✗ LogDebug(VB_PLAYLIST, " Lead Out:\n");
2667 ✗ for (int c = 0; c < m_leadOut.size(); c++)
2668 ✗ m_leadOut[c]->Dump();
2669 } else {
2670 2 LogDebug(VB_PLAYLIST, " Lead Out : (No Lead Out)\n");
2671 }
2672 2 }
2673
2674 545953 std::string Playlist::GetPlaylistName(void) {
2675
1/2
✓ Branch 0 taken 545953 times.
✗ Branch 1 not taken.
545953 std::lock_guard<std::mutex> nl(m_nameLock);
2676
1/2
✓ Branch 0 taken 545953 times.
✗ Branch 1 not taken.
1091906 return m_name;
2677 545953 }
2678
2679 22 const std::vector<int>& Playlist::CurrentSectionRows() const {
2680
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
22 static const std::vector<int> none;
2681
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (m_currentSection == &m_leadIn)
2682 ✗ return m_leadInRows;
2683
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (m_currentSection == &m_mainPlaylist)
2684 22 return m_mainRows;
2685 ✗ if (m_currentSection == &m_leadOut)
2686 ✗ return m_leadOutRows;
2687 ✗ return none;
2688 }
2689
2690 // File row (0-based, within a section) to a position in the loaded section.
2691 // A row that wasn't loaded (before a start position) maps to the section's
2692 // start; one past the last row, to its end. With no row table (nothing
2693 // loaded from a file) rows and positions are the same.
2694 101 int Playlist::RowToSectionPosition(const std::vector<int>& rows, int row, int sectionSize) {
2695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 101 times.
101 if (row < 0)
2696 ✗ return 0;
2697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 101 times.
101 if (rows.empty())
2698 ✗ return std::min(row, sectionSize);
2699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 101 times.
101 if (row >= (int)rows.size())
2700 ✗ return sectionSize;
2701 101 return std::max(rows[row], 0);
2702 }
2703
2704 // The file row a loaded position came from.
2705 11 int Playlist::SectionPositionToRow(const std::vector<int>& rows, int pos) {
2706
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (rows.empty())
2707 ✗ return pos;
2708 11 int row = 0;
2709
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 11 times.
60 for (int r = 0; r < (int)rows.size(); r++) {
2710
5/6
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 38 times.
✓ Branch 5 taken 11 times.
49 if ((rows[r] >= 0) && (rows[r] <= pos))
2711 38 row = r;
2712 }
2713 11 return row;
2714 }
2715
2716 // File row counted across the whole playlist (lead-in, then main, then
2717 // lead-out) to an overall loaded position.
2718 87 int Playlist::FileRowToPosition(int row) {
2719
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 83 times.
87 int li = m_leadInRows.empty() ? (int)m_leadIn.size() : (int)m_leadInRows.size();
2720
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
87 int mi = m_mainRows.empty() ? (int)m_mainPlaylist.size() : (int)m_mainRows.size();
2721
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 77 times.
87 if (row < li)
2722 10 return RowToSectionPosition(m_leadInRows, row, m_leadIn.size());
2723
1/2
✓ Branch 0 taken 77 times.
✗ Branch 1 not taken.
77 if (row < li + mi)
2724 77 return m_leadIn.size() + RowToSectionPosition(m_mainRows, row - li, m_mainPlaylist.size());
2725 ✗ return m_leadIn.size() + m_mainPlaylist.size() + RowToSectionPosition(m_leadOutRows, row - li - mi, m_leadOut.size());
2726 }
2727
2728 28858 std::shared_ptr<Playlist> Playlist::CurrentIfNotThis(void) {
2729
1/2
✓ Branch 0 taken 28858 times.
✗ Branch 1 not taken.
28858 std::shared_ptr<Playlist> cur = Player::INSTANCE.PlaylistSnapshot();
2730
5/6
✓ Branch 0 taken 28858 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 28852 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 28852 times.
28858 if (cur && cur.get() != this)
2731 6 return cur;
2732 28852 return nullptr;
2733 28858 }
2734
2735 // Re-entrant Restart/Next/Prev Item: a command entry for one of them runs
2736 // inside its own StartPlaying() frame (Start()/Process() are on the stack).
2737 // Inline, RestartItem() restarted that same command entry, which ran
2738 // RestartItem() again, until the main thread's stack overflowed; Next and Prev
2739 // did the same whenever they landed back on the entry itself (the only entry
2740 // of a repeating playlist, Prev on the first). Defer like StopNow(): the
2741 // outermost guard replays it against whatever playlist is current then, so an
2742 // entry that restarts itself is a drain cascade, which
2743 // MAX_NOTIFICATION_CASCADE bounds, rather than recursion.
2744 24640 static bool DeferIfReentrant(const char* what, void (Playlist::*fn)(void)) {
2745
2/2
✓ Branch 0 taken 24497 times.
✓ Branch 1 taken 143 times.
24640 if (tl_transitionDepth <= 1) {
2746 24497 return false;
2747 }
2748 143 LogDebug(VB_PLAYLIST, "Playlist::%s() re-entrant (depth %d) — deferring until current transition completes\n",
2749 what, tl_transitionDepth);
2750
1/2
✓ Branch 0 taken 143 times.
✗ Branch 1 not taken.
143 QueuePlaylistNotification([fn]() {
2751
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 std::shared_ptr<Playlist> cur = Player::INSTANCE.PlaylistSnapshot();
2752
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (cur) {
2753
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 ((*cur).*fn)();
2754 }
2755 130 });
2756 143 return true;
2757 }
2758
2759 8196 void Playlist::RestartItem(void) {
2760
2/4
✓ Branch 0 taken 8196 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8196 times.
✗ Branch 3 not taken.
8196 LogDebug(VB_PLAYLIST, "RestartItem called for '%s'\n", GetPlaylistName().c_str());
2761 8196 PlaylistTransitionGuard guard;
2762
3/4
✓ Branch 0 taken 8196 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 8141 times.
8196 if (DeferIfReentrant("RestartItem", &Playlist::RestartItem)) {
2763 55 return;
2764 }
2765
1/2
✓ Branch 0 taken 8141 times.
✗ Branch 1 not taken.
8141 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2766
2/4
✓ Branch 0 taken 8141 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8141 times.
8141 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
2767 ✗ lck.unlock();
2768 ✗ return cur->RestartItem();
2769
1/2
✓ Branch 0 taken 8141 times.
✗ Branch 1 not taken.
8141 }
2770
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8140 times.
8141 if (m_status == FPP_STATUS_IDLE) {
2771 1 return;
2772 }
2773
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8140 times.
8140 if (m_status != FPP_STATUS_PLAYLIST_PLAYING) {
2774 ✗ return;
2775 }
2776
2777 // Clear global pause state when manually navigating
2778 8140 m_shouldStartGlobalPause = false;
2779 8140 m_isInGlobalPause = false;
2780 8140 m_loopHoldUntilMS = 0;
2781
2782
1/2
✓ Branch 0 taken 8140 times.
✗ Branch 1 not taken.
8140 int pos = GetPosition() - 1;
2783
1/2
✓ Branch 0 taken 8140 times.
✗ Branch 1 not taken.
8140 PlaylistEntryBase* entry = CurrentEntry();
2784
6/8
✓ Branch 0 taken 8139 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8139 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8139 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8139 times.
✓ Branch 7 taken 1 times.
8140 if (entry && entry->IsPlaying())
2785
1/2
✓ Branch 0 taken 8139 times.
✗ Branch 1 not taken.
8139 entry->Stop();
2786
2787 8140 m_sectionPosition = 0;
2788 8140 m_startPosition = pos;
2789
1/2
✓ Branch 0 taken 8140 times.
✗ Branch 1 not taken.
8140 Start();
2790
4/4
✓ Branch 0 taken 8140 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8140 times.
✓ Branch 3 taken 56 times.
8197 }
2791 8227 void Playlist::NextItem(void) {
2792
2/4
✓ Branch 0 taken 8227 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8227 times.
✗ Branch 3 not taken.
8227 LogDebug(VB_PLAYLIST, "NextItem called for '%s'\n", GetPlaylistName().c_str());
2793 8227 PlaylistTransitionGuard guard;
2794
3/4
✓ Branch 0 taken 8227 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 8183 times.
8227 if (DeferIfReentrant("NextItem", &Playlist::NextItem)) {
2795 44 return;
2796 }
2797
1/2
✓ Branch 0 taken 8183 times.
✗ Branch 1 not taken.
8183 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2798
2/4
✓ Branch 0 taken 8183 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8183 times.
8183 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
2799 ✗ lck.unlock();
2800 ✗ return cur->NextItem();
2801
1/2
✓ Branch 0 taken 8183 times.
✗ Branch 1 not taken.
8183 }
2802
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8182 times.
8183 if (m_status == FPP_STATUS_IDLE) {
2803 1 return;
2804 }
2805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8182 times.
8182 if (m_status != FPP_STATUS_PLAYLIST_PLAYING) {
2806 ✗ return;
2807 }
2808
2809 // Clear global pause state when manually navigating
2810 8182 m_shouldStartGlobalPause = false;
2811 8182 m_isInGlobalPause = false;
2812 8182 m_loopHoldUntilMS = 0;
2813 8182 bool somewhereToGo = true;
2814
1/2
✓ Branch 0 taken 8182 times.
✗ Branch 1 not taken.
8182 int pos = GetPosition();
2815
3/4
✓ Branch 0 taken 8182 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8180 times.
8182 if (m_currentSectionStr == "LeadIn") {
2816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 if ((pos < m_leadIn.size()) ||
2817
2/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 (m_mainPlaylist.size()) ||
2818 ✗ (m_leadOut.size())) {
2819 // as long as we have somewhere to go then go to next
2820 2 pos++;
2821 } else {
2822 // nowhere to go, stop playlist
2823 ✗ somewhereToGo = false;
2824 }
2825
3/4
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8178 times.
✓ Branch 3 taken 2 times.
8180 } else if (m_currentSectionStr == "MainPlaylist") {
2826
2/2
✓ Branch 0 taken 5359 times.
✓ Branch 1 taken 2819 times.
8178 if (pos < (m_leadIn.size() + m_mainPlaylist.size())) {
2827 // if not at end of main go to next item
2828 5359 pos++;
2829
2/2
✓ Branch 0 taken 2818 times.
✓ Branch 1 taken 1 times.
2819 } else if (m_repeat) {
2830 // if at end of main and repeating, go to first item in main
2831 2818 pos = m_leadIn.size() + 1;
2832
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 } else if (m_leadOut.size()) {
2833 // if at end of main and non-repeating, go to first in LeadOut
2834 1 pos++;
2835 } else {
2836 // nowhere to go, stop playlist
2837 ✗ somewhereToGo = false;
2838 }
2839
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 } else if (m_currentSectionStr == "LeadOut") {
2840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (pos < (m_leadIn.size() + m_mainPlaylist.size() + m_leadOut.size())) {
2841 // more in leadOut so go to next
2842 ✗ pos++;
2843 } else {
2844 // nowhere to go, stop playlist
2845 1 somewhereToGo = false;
2846 }
2847 } else {
2848 1 return;
2849 }
2850
2851
1/2
✓ Branch 0 taken 8181 times.
✗ Branch 1 not taken.
8181 PlaylistEntryBase* entry = CurrentEntry();
2852
6/8
✓ Branch 0 taken 8181 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8181 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8178 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 8178 times.
✓ Branch 7 taken 3 times.
8181 if (entry && entry->IsPlaying())
2853
1/2
✓ Branch 0 taken 8178 times.
✗ Branch 1 not taken.
8178 entry->Stop();
2854
2855
2/2
✓ Branch 0 taken 8180 times.
✓ Branch 1 taken 1 times.
8181 if (somewhereToGo) {
2856 8180 pos--;
2857 8180 m_sectionPosition = 0;
2858 8180 m_startPosition = pos;
2859
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 Start();
2860 }
2861
4/4
✓ Branch 0 taken 8181 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8181 times.
✓ Branch 3 taken 46 times.
8229 }
2862
2863 /*
2864 *
2865 */
2866 8217 void Playlist::PrevItem(void) {
2867
2/4
✓ Branch 0 taken 8217 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8217 times.
✗ Branch 3 not taken.
8217 LogDebug(VB_PLAYLIST, "PrevItem called for '%s'\n", GetPlaylistName().c_str());
2868 8217 PlaylistTransitionGuard guard;
2869
3/4
✓ Branch 0 taken 8217 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 8173 times.
8217 if (DeferIfReentrant("PrevItem", &Playlist::PrevItem)) {
2870 44 return;
2871 }
2872
1/2
✓ Branch 0 taken 8173 times.
✗ Branch 1 not taken.
8173 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2873
2/4
✓ Branch 0 taken 8173 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8173 times.
8173 if (std::shared_ptr<Playlist> cur = CurrentIfNotThis()) {
2874 ✗ lck.unlock();
2875 ✗ return cur->PrevItem();
2876
1/2
✓ Branch 0 taken 8173 times.
✗ Branch 1 not taken.
8173 }
2877
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8172 times.
8173 if (m_status == FPP_STATUS_IDLE) {
2878 1 return;
2879 }
2880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8172 times.
8172 if (m_status != FPP_STATUS_PLAYLIST_PLAYING) {
2881 ✗ return;
2882 }
2883
2884 // Clear global pause state when manually navigating
2885 8172 m_shouldStartGlobalPause = false;
2886 8172 m_isInGlobalPause = false;
2887 8172 m_loopHoldUntilMS = 0;
2888
2889
1/2
✓ Branch 0 taken 8172 times.
✗ Branch 1 not taken.
8172 int pos = GetPosition();
2890
5/6
✓ Branch 0 taken 8172 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8171 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 8171 times.
16343 if ((m_currentSectionStr == "LeadIn") ||
2891
2/4
✓ Branch 0 taken 8171 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8171 times.
8171 (m_currentSectionStr == "LeadOut")) {
2892 // No repeat on LeadIn/Out so just go to previous item
2893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (pos > 1)
2894 ✗ pos--;
2895
3/4
✓ Branch 0 taken 8171 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8170 times.
✓ Branch 3 taken 1 times.
8171 } else if (m_currentSectionStr == "MainPlaylist") {
2896
2/2
✓ Branch 0 taken 5352 times.
✓ Branch 1 taken 2818 times.
8170 if (pos > (m_leadIn.size() + 1)) {
2897 // If not first item in Main, go to prev item
2898 5352 pos--;
2899
1/2
✓ Branch 0 taken 2818 times.
✗ Branch 1 not taken.
2818 } else if (m_repeat) {
2900 // if first item in main and repeating, go to end of main
2901 2818 pos = m_leadIn.size() + m_mainPlaylist.size();
2902 ✗ } else if (m_leadIn.size()) {
2903 // if first item in main and non-repeating go to end of LeadIn
2904 ✗ pos = m_leadIn.size();
2905 }
2906 }
2907
2908
1/2
✓ Branch 0 taken 8172 times.
✗ Branch 1 not taken.
8172 PlaylistEntryBase* entry = CurrentEntry();
2909
6/8
✓ Branch 0 taken 8171 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8171 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8171 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8171 times.
✓ Branch 7 taken 1 times.
8172 if (entry && entry->IsPlaying())
2910
1/2
✓ Branch 0 taken 8171 times.
✗ Branch 1 not taken.
8171 entry->Stop();
2911
2912 8172 m_sectionPosition = 0;
2913 8172 m_startPosition = pos - 1;
2914
1/2
✓ Branch 0 taken 8172 times.
✗ Branch 1 not taken.
8172 Start();
2915
4/4
✓ Branch 0 taken 8172 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8172 times.
✓ Branch 3 taken 45 times.
8218 }
2916
2917 342109 PlaylistEntryBase* Playlist::CurrentEntry(void) {
2918
5/6
✓ Branch 0 taken 342101 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 342101 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 342101 times.
342109 if (m_currentSection == nullptr || m_sectionPosition >= (int)m_currentSection->size())
2919 8 return nullptr;
2920
2921 342101 return m_currentSection->at(m_sectionPosition);
2922 }
2923
2924 /*
2925 *
2926 */
2927 608385 int Playlist::GetPosition(void) {
2928 // Read from status, restart and sync paths on other threads; the sections
2929 // and m_currentSectionStr change under this lock.
2930
1/2
✓ Branch 0 taken 608385 times.
✗ Branch 1 not taken.
608385 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2931 608385 int result = 0;
2932
2933
2/2
✓ Branch 0 taken 5652 times.
✓ Branch 1 taken 602733 times.
608385 if (m_status == FPP_STATUS_IDLE)
2934 5652 return result;
2935
2936
3/4
✓ Branch 0 taken 602733 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4731 times.
✓ Branch 3 taken 598002 times.
602733 if (m_currentSectionStr == "LeadIn")
2937 4731 return m_sectionPosition + 1;
2938
2939
3/4
✓ Branch 0 taken 598002 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 597751 times.
✓ Branch 3 taken 251 times.
598002 if (m_currentSectionStr == "MainPlaylist")
2940 597751 return m_leadIn.size() + m_sectionPosition + 1;
2941
2942
3/4
✓ Branch 0 taken 251 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 248 times.
✓ Branch 3 taken 3 times.
251 if (m_currentSectionStr == "LeadOut")
2943 248 return m_leadIn.size() + m_mainPlaylist.size() + m_sectionPosition + 1;
2944
2945 3 return result;
2946 608385 }
2947
2948 /*
2949 * 0-based position a restart should resume this playlist at: the current
2950 * entry if it still has work left, the one after it if it does not.
2951 *
2952 * Resuming AT an entry that has already done its work replays it. For a
2953 * command entry that is the command that asked for the restart ("Restart
2954 * FPPD", "Switch To Player Mode"), so the new fppd runs it again and restarts
2955 * in a loop for the rest of the schedule window. That entry is not yet marked
2956 * finished -- Process() only does that on the next main-loop pass, and the
2957 * restart ends the loop first -- so a completed command counts as finished
2958 * here too.
2959 *
2960 * The position is counted in the playlist FILE, which is what the restarted
2961 * fppd loads. A playlist that was itself given a start and end item (an
2962 * Insert Playlist range) was loaded with every entry before the start trimmed
2963 * off (see Load()), so GetPosition() counts from the trimmed start; add the
2964 * trimmed entries back or a second restart resumes too early.
2965 *
2966 * A position past the end is wrapped back to the start by Start().
2967 */
2968 8 int Playlist::GetResumePosition(void) {
2969
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
2970
2971 8 bool done = false;
2972
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 PlaylistEntryBase* entry = CurrentEntry();
2973
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (entry) {
2974
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 PlaylistEntryCommand* cmdEntry = dynamic_cast<PlaylistEntryCommand*>(entry);
2975
8/12
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 6 times.
8 if (entry->IsFinished() || (cmdEntry && cmdEntry->CommandDone())) {
2976 2 done = true;
2977 }
2978 }
2979
2980
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 const std::vector<int>& rows = CurrentSectionRows();
2981
4/8
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 8 times.
8 if (rows.empty() || !m_currentSection || (m_status == FPP_STATUS_IDLE)) {
2982 // No row table (not loaded from a playlist file): positions are rows.
2983 ✗ int pos = GetPosition() - 1;
2984 ✗ if (m_loadStartPos > 0) {
2985 ✗ pos += m_loadStartPos;
2986 }
2987 ✗ return done ? pos + 1 : pos;
2988 }
2989
2990 // The row of the file this entry came from, counted across the whole
2991 // playlist. It used to be the loaded position plus the trimmed rows,
2992 // which mixed the two once a sub-playlist row had expanded into several
2993 // entries. Resuming inside a sub-playlist restarts that sub-playlist: a
2994 // row is as fine as a position in the file can be.
2995
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 int pos = m_sectionPosition + (done ? 1 : 0);
2996 8 int base = 0;
2997 8 int loadedBase = 0;
2998
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (m_currentSection == &m_mainPlaylist) {
2999 8 base = m_leadInRows.size();
3000 8 loadedBase = m_leadIn.size();
3001 ✗ } else if (m_currentSection == &m_leadOut) {
3002 ✗ base = m_leadInRows.size() + m_mainRows.size();
3003 ✗ loadedBase = m_leadIn.size() + m_mainPlaylist.size();
3004 }
3005 8 int row = (int)rows.size();
3006
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (pos < (int)m_currentSection->size()) {
3007 // The row table is in load order, and a random playlist's main
3008 // section is shuffled: go by where the entry was loaded, not by its
3009 // index, or the resume lands on whichever entry was loaded at that
3010 // index -- one that may already have played.
3011 8 int loadedPos = (*m_currentSection)[pos]->GetPositionInPlaylist() - loadedBase;
3012
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 row = SectionPositionToRow(rows, loadedPos);
3013 }
3014 8 return base + row;
3015 8 }
3016
3017 /*
3018 *
3019 */
3020 260606 int Playlist::GetSize(void) {
3021
1/2
✓ Branch 0 taken 260606 times.
✗ Branch 1 not taken.
260606 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3022
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 260606 times.
260606 if (m_status == FPP_STATUS_IDLE)
3023 ✗ return 0;
3024
3025 260606 return m_leadIn.size() + m_mainPlaylist.size() + m_leadOut.size();
3026 260606 }
3027
3028 /*
3029 *
3030 */
3031 94823 Json::Value Playlist::GetCurrentEntry(void) {
3032 94823 Json::Value result;
3033
3034
2/2
✓ Branch 0 taken 15804 times.
✓ Branch 1 taken 79019 times.
94823 if (m_status == FPP_STATUS_IDLE)
3035 15804 return result;
3036
3037
1/2
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
79019 PlaylistEntryBase* entry = CurrentEntry();
3038
1/2
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
79019 if (entry)
3039
1/2
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
79019 result = entry->GetConfig();
3040
3041 79019 return result;
3042 ✗ }
3043 17 static void GetFilenames(PlaylistEntryBase* entry, std::string& seq, std::string& med) {
3044
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 PlaylistEntrySequence* se = dynamic_cast<PlaylistEntrySequence*>(entry);
3045
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 PlaylistEntryMedia* me = dynamic_cast<PlaylistEntryMedia*>(entry);
3046
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 PlaylistEntryBoth* be = dynamic_cast<PlaylistEntryBoth*>(entry);
3047
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 10 times.
17 if (se) {
3048 7 seq = se->GetSequenceName();
3049 }
3050
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 14 times.
17 if (me) {
3051
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 med = me->GetMediaName();
3052 }
3053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (be) {
3054 ✗ seq = be->GetSequenceName();
3055 ✗ med = be->GetMediaName();
3056 }
3057 17 }
3058
3059 17 void Playlist::GetFilenamesForPos(int pos, std::string& seq, std::string& med) {
3060
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3061
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 12 times.
26 for (auto& a : m_leadIn) {
3062
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 9 times.
14 if (a->GetPositionInPlaylist() == pos) {
3063
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 GetFilenames(a, seq, med);
3064 5 return;
3065 }
3066 }
3067
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 for (auto& a : m_mainPlaylist) {
3068
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 10 times.
22 if (a->GetPositionInPlaylist() == pos) {
3069
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 GetFilenames(a, seq, med);
3070 12 return;
3071 }
3072 }
3073 ✗ for (auto& a : m_leadOut) {
3074 ✗ if (a->GetPositionInPlaylist() == pos) {
3075 ✗ GetFilenames(a, seq, med);
3076 ✗ return;
3077 }
3078 }
3079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 }
3080
3081 9 int Playlist::FindPosForMS(uint64_t& t, bool itemDefinedOnly) {
3082
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3083
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
9 if (itemDefinedOnly) {
3084 2 PlaylistEntryBase* bestOption = nullptr;
3085 2 uint64_t diff = 0xFFFFFFFFFFL;
3086
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (auto& a : m_leadIn) {
3087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (a->GetTimeCode() < t) {
3088 ✗ uint64_t d2 = t - a->GetTimeCode();
3089 ✗ if (d2 < diff) {
3090 ✗ diff = d2;
3091 ✗ bestOption = a;
3092 }
3093 }
3094 }
3095
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
10 for (auto& a : m_mainPlaylist) {
3096
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
8 if (a->GetTimeCode() < t) {
3097 3 uint64_t d2 = t - a->GetTimeCode();
3098
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (d2 < diff) {
3099 3 diff = d2;
3100 3 bestOption = a;
3101 }
3102 }
3103 }
3104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 for (auto& a : m_leadOut) {
3105 ✗ if (a->GetTimeCode() < t) {
3106 ✗ uint64_t d2 = t - a->GetTimeCode();
3107 ✗ if (d2 < diff) {
3108 ✗ diff = d2;
3109 ✗ bestOption = a;
3110 }
3111 }
3112 }
3113
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (bestOption) {
3114 2 t -= bestOption->GetTimeCode();
3115 2 return bestOption->GetPositionInPlaylist();
3116 }
3117 } else {
3118
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 for (auto& a : m_leadIn) {
3119
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 uint64_t i = a->GetLengthInMS();
3120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (t < i) {
3121 ✗ return a->GetPositionInPlaylist();
3122 }
3123 7 t -= i;
3124 }
3125
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2 times.
20 for (auto& a : m_mainPlaylist) {
3126
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 uint64_t i = a->GetLengthInMS();
3127
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 13 times.
18 if (t < i) {
3128 5 return a->GetPositionInPlaylist();
3129 }
3130 13 t -= i;
3131 }
3132
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (auto& a : m_leadOut) {
3133
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 uint64_t i = a->GetLengthInMS();
3134
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (t < i) {
3135 1 return a->GetPositionInPlaylist();
3136 }
3137 1 t -= i;
3138 }
3139 }
3140 1 t = 0;
3141 1 return -1;
3142 9 }
3143
3144 ✗ uint64_t Playlist::GetCurrentPosInMS() {
3145 ✗ int pos = 0;
3146 uint64_t posms;
3147 ✗ return GetCurrentPosInMS(pos, posms, false);
3148 }
3149 54338 uint64_t Playlist::GetCurrentPosInMS(int& position, uint64_t& posms, bool itemDefinedOnly) {
3150
1/2
✓ Branch 0 taken 54338 times.
✗ Branch 1 not taken.
54338 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3151
3152 54338 position = -1;
3153 54338 posms = 0;
3154
2/2
✓ Branch 0 taken 2295 times.
✓ Branch 1 taken 52043 times.
54338 if (m_status == FPP_STATUS_IDLE) {
3155 2295 return 0;
3156 }
3157
1/2
✓ Branch 0 taken 52043 times.
✗ Branch 1 not taken.
52043 PlaylistEntryBase* entry = CurrentEntry();
3158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52043 times.
52043 if (entry == nullptr) {
3159 ✗ return 0;
3160 }
3161 52043 position = entry->GetPositionInPlaylist();
3162
1/2
✓ Branch 0 taken 52043 times.
✗ Branch 1 not taken.
52043 posms = entry->GetElapsedMS();
3163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52043 times.
52043 if (itemDefinedOnly) {
3164 ✗ int pos = entry->GetTimeCode();
3165 ✗ if (pos >= 0) {
3166 ✗ return pos + posms;
3167 } else {
3168 ✗ posms = 0;
3169 ✗ return 0;
3170 }
3171 }
3172
3173 52043 uint64_t pos = 0;
3174
2/2
✓ Branch 0 taken 20631 times.
✓ Branch 1 taken 52043 times.
72674 for (int x = 0; x < m_sectionPosition; x++) {
3175
2/4
✓ Branch 0 taken 20631 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20631 times.
✗ Branch 3 not taken.
20631 pos += m_currentSection->at(x)->GetLengthInMS();
3176 }
3177 52043 pos += posms;
3178 // if we aren't in the LeadIn, add the time of the LeadIn
3179
3/4
✓ Branch 0 taken 52043 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26121 times.
✓ Branch 3 taken 25922 times.
52043 if (m_currentSectionStr != "LeadIn") {
3180
2/2
✓ Branch 0 taken 26121 times.
✓ Branch 1 taken 26121 times.
52242 for (auto& a : m_leadIn) {
3181
1/2
✓ Branch 0 taken 26121 times.
✗ Branch 1 not taken.
26121 pos += a->GetLengthInMS();
3182 }
3183 } else {
3184 25922 return pos;
3185 }
3186
2/4
✓ Branch 0 taken 26121 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26121 times.
26121 if (m_currentSectionStr != "MainPlaylist") {
3187 // must be in the leadOut, add the main list length
3188 ✗ for (auto& a : m_mainPlaylist) {
3189 ✗ pos += a->GetLengthInMS();
3190 }
3191 }
3192 26121 return pos;
3193 54338 }
3194 ✗ uint64_t Playlist::GetPosStartInMS(int pos) {
3195 ✗ std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3196 ✗ uint64_t ms = 0;
3197
3198 ✗ for (auto& a : m_leadIn) {
3199 ✗ if (a->GetPositionInPlaylist() == pos) {
3200 ✗ return ms;
3201 }
3202 ✗ ms += a->GetLengthInMS();
3203 }
3204 ✗ for (auto& a : m_mainPlaylist) {
3205 ✗ if (a->GetPositionInPlaylist() == pos) {
3206 ✗ return ms;
3207 }
3208 ✗ ms += a->GetLengthInMS();
3209 }
3210 ✗ for (auto& a : m_leadOut) {
3211 ✗ if (a->GetPositionInPlaylist() == pos) {
3212 ✗ return ms;
3213 }
3214 ✗ ms += a->GetLengthInMS();
3215 }
3216 ✗ return ms;
3217 ✗ }
3218
3219 6 Json::Value Playlist::GetMqttStatusJSON(void) {
3220 // this is called on background thread, need to lock
3221
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3222
3223
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 Json::Value result;
3224
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 result["status"] = PlaylistStatusToString(m_status); // Works because single playlist
3225
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 Json::Value playlistArray = Json::Value(Json::arrayValue);
3226
3227
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 PlaylistEntryBase* entry = (m_status != FPP_STATUS_IDLE) ? CurrentEntry() : nullptr;
3228
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (entry) {
3229
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Json::Value entryArray = Json::Value(Json::arrayValue);
3230
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Json::Value playlist;
3231 // Only one entry right now.
3232
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Json::Value playlistEntry = entry->GetMqttStatus();
3233
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 entryArray.append(playlistEntry);
3234
3235
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 playlist["name"] = m_name;
3236
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 playlist["repeat"] = m_repeat.load();
3237
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 playlist["description"] = m_desc;
3238
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 playlist["currentItems"] = entryArray;
3239
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 playlistArray.append(playlist);
3240 3 }
3241
3242
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 result["activePlaylists"] = playlistArray;
3243 6 return result;
3244 6 }
3245
3246 223040 void Playlist::GetCurrentStatus(Json::Value& result) {
3247
1/2
✓ Branch 0 taken 223040 times.
✗ Branch 1 not taken.
223040 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3248
5/6
✓ Branch 0 taken 181587 times.
✓ Branch 1 taken 41453 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 181587 times.
✓ Branch 4 taken 41453 times.
✓ Branch 5 taken 181587 times.
223040 if (m_status == FPP_STATUS_IDLE || m_currentSection == nullptr) {
3249
2/4
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
41453 result["repeat_mode"] = "0";
3250
3/6
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41453 times.
✗ Branch 5 not taken.
41453 result["current_playlist"]["description"] = "";
3251
3/6
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41453 times.
✗ Branch 5 not taken.
41453 result["current_playlist"]["playlist"] = "";
3252
3/6
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41453 times.
✗ Branch 5 not taken.
41453 result["current_playlist"]["count"] = "0";
3253
3/6
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41453 times.
✗ Branch 5 not taken.
41453 result["current_playlist"]["index"] = "0";
3254
3/6
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41453 times.
✗ Branch 5 not taken.
41453 result["current_playlist"]["type"] = "";
3255
3/6
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41453 times.
✗ Branch 5 not taken.
41453 result["current_playlist"]["generated"] = false;
3256
3257
2/4
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
41453 result["current_sequence"] = "";
3258
2/4
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
41453 result["current_song"] = "";
3259
2/4
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
41453 result["seconds_played"] = "0";
3260
2/4
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
41453 result["seconds_remaining"] = "0";
3261
2/4
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
41453 result["time_elapsed"] = "00:00";
3262
2/4
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
41453 result["time_remaining"] = "00:00";
3263
3264 // Still provide global pause and random info even when idle
3265
3/6
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41453 times.
✗ Branch 5 not taken.
41453 result["global_pause"]["configured"] = m_globalPauseBetweenSequencesMS > 0;
3266
3/6
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41453 times.
✗ Branch 5 not taken.
41453 result["global_pause"]["duration_ms"] = m_globalPauseBetweenSequencesMS;
3267
3/6
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41453 times.
✗ Branch 5 not taken.
41453 result["global_pause"]["active"] = false; // Always false when idle
3268
2/4
✓ Branch 0 taken 41453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41453 times.
✗ Branch 3 not taken.
41453 result["random"] = m_random;
3269 41453 return;
3270 }
3271
3272
1/2
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
181587 std::string plname = m_name;
3273
2/4
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
363174 result["repeat_mode"] = m_repeat.load();
3274
3/6
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181587 times.
✗ Branch 5 not taken.
181587 result["current_playlist"]["description"] = m_desc;
3275
4/8
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181587 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 181587 times.
✗ Branch 7 not taken.
181587 result["current_playlist"]["count"] = std::to_string(GetSize());
3276
4/8
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181587 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 181587 times.
✗ Branch 7 not taken.
181587 result["current_playlist"]["index"] = std::to_string(GetPosition());
3277
3278
2/4
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
181587 result["random"] = m_random;
3279
3280 // Global pause between sequences status
3281
3/6
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181587 times.
✗ Branch 5 not taken.
181587 result["global_pause"]["configured"] = m_globalPauseBetweenSequencesMS > 0;
3282
3/6
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181587 times.
✗ Branch 5 not taken.
181587 result["global_pause"]["duration_ms"] = m_globalPauseBetweenSequencesMS;
3283
3/6
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181587 times.
✗ Branch 5 not taken.
181587 result["global_pause"]["active"] = m_isInGlobalPause;
3284
3/4
✓ Branch 0 taken 3466 times.
✓ Branch 1 taken 178121 times.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
181587 if (m_isInGlobalPause && m_globalPauseBetweenSequencesMS > 0) {
3285
1/2
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
3466 long long elapsed = GetMonotonicTimeMS() - m_globalPauseStartTime;
3286 3466 long long remaining = m_globalPauseBetweenSequencesMS - elapsed;
3287
2/2
✓ Branch 0 taken 652 times.
✓ Branch 1 taken 2814 times.
3466 if (remaining < 0) remaining = 0;
3288
3/6
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3466 times.
✗ Branch 5 not taken.
3466 result["global_pause"]["elapsed_ms"] = static_cast<Json::Int64>(elapsed);
3289
3/6
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3466 times.
✗ Branch 5 not taken.
3466 result["global_pause"]["remaining_ms"] = static_cast<Json::Int64>(remaining);
3290
3/6
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3466 times.
✗ Branch 5 not taken.
3466 result["global_pause"]["remaining_seconds"] = static_cast<Json::Int64>((remaining + 999) / 1000); // Round up
3291 }
3292
3293 // CurrentEntry() returns null while the playlist is between items --
3294 // Process() parks m_sectionPosition at exactly the section size when
3295 // advancing past the end of a section, and checks for that state rather
3296 // than treating it as invalid. Indexing unguarded here would throw
3297 // std::out_of_range out of the /api/fppd/status handler on a drogon I/O
3298 // thread, which aborts fppd; treat "no current entry" as the null case
3299 // the code below already handles.
3300
1/2
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
181587 PlaylistEntryBase* ple = CurrentEntry();
3301 181587 std::string type;
3302
1/2
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
181587 if (ple) {
3303
1/2
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
181587 type = ple->GetType();
3304 }
3305
3306
3/4
✓ Branch 0 taken 182037 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 450 times.
✓ Branch 3 taken 181587 times.
182037 while (type == "dynamic") {
3307
1/2
✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
450 PlaylistEntryDynamic* dyn = dynamic_cast<PlaylistEntryDynamic*>(ple);
3308
1/2
✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
450 ple = dyn->GetCurrentEntry();
3309
2/2
✓ Branch 0 taken 399 times.
✓ Branch 1 taken 51 times.
450 if (ple) {
3310
1/2
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
399 type = ple->GetType();
3311 } else {
3312
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 type = "unknown";
3313 }
3314 }
3315
3316
1/2
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
181587 plname = plname.substr(plname.find_last_of("\\/") + 1);
3317
3/6
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 181587 times.
363174 if (endsWith(plname, ".json")) {
3318 ✗ plname = plname.substr(0, plname.find_last_of("."));
3319 }
3320
3/6
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181587 times.
✗ Branch 5 not taken.
181587 result["current_playlist"]["playlist"] = plname;
3321
3/6
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181587 times.
✗ Branch 5 not taken.
181587 result["current_playlist"]["type"] = type;
3322
3/6
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181587 times.
✗ Branch 5 not taken.
181587 result["current_playlist"]["generated"] = m_generatedOnTheFly;
3323
3324
2/2
✓ Branch 0 taken 181536 times.
✓ Branch 1 taken 51 times.
181587 if (ple) {
3325 // Check if we're currently in a global pause - if so, show pause progress instead of item progress
3326
3/4
✓ Branch 0 taken 3466 times.
✓ Branch 1 taken 178070 times.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
181536 if (m_isInGlobalPause && m_globalPauseBetweenSequencesMS > 0) {
3327 // Show global pause progress
3328
1/2
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
3466 long long elapsed = GetMonotonicTimeMS() - m_globalPauseStartTime;
3329 3466 long long remaining = m_globalPauseBetweenSequencesMS - elapsed;
3330
2/2
✓ Branch 0 taken 652 times.
✓ Branch 1 taken 2814 times.
3466 if (remaining < 0) remaining = 0;
3331
3332 3466 int secsElapsed = (int)(elapsed / 1000);
3333 3466 int secsRemaining = (int)(remaining / 1000);
3334
3335
2/4
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
3466 result["current_sequence"] = "Global Pause";
3336
2/4
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
3466 result["current_song"] = "";
3337
2/4
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
3466 result["seconds_played"] = std::to_string(secsElapsed);
3338
2/4
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
3466 result["seconds_elapsed"] = std::to_string(secsElapsed);
3339
2/4
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
3466 result["milliseconds_elapsed"] = static_cast<Json::Int64>(elapsed);
3340
2/4
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
3466 result["seconds_remaining"] = std::to_string(secsRemaining);
3341
3/6
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3466 times.
✗ Branch 5 not taken.
3466 result["time_elapsed"] = secondsToTime(secsElapsed);
3342
3/6
✓ Branch 0 taken 3466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3466 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3466 times.
✗ Branch 5 not taken.
3466 result["time_remaining"] = secondsToTime(secsRemaining);
3343 3466 } else {
3344 // Normal item progress
3345
1/2
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
178070 int msecs = ple->GetElapsedMS();
3346 178070 int secsElapsed = (int)(msecs / 1000);
3347
2/4
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178070 times.
✗ Branch 3 not taken.
178070 int secsRemaining = (int)((ple->GetLengthInMS() - ple->GetElapsedMS()) / 1000);
3348
3349 178070 std::string currentSeq;
3350 178070 std::string currentSong;
3351
3/4
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21617 times.
✓ Branch 3 taken 156453 times.
178070 if (type == "media") {
3352
1/2
✓ Branch 0 taken 21617 times.
✗ Branch 1 not taken.
21617 PlaylistEntryMedia* med = dynamic_cast<PlaylistEntryMedia*>(ple);
3353
1/2
✓ Branch 0 taken 21617 times.
✗ Branch 1 not taken.
21617 currentSong = med->GetMediaName();
3354
3/4
✓ Branch 0 taken 156453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1435 times.
✓ Branch 3 taken 155018 times.
156453 } else if (type == "both") {
3355
1/2
✓ Branch 0 taken 1435 times.
✗ Branch 1 not taken.
1435 PlaylistEntryBoth* both = dynamic_cast<PlaylistEntryBoth*>(ple);
3356
1/2
✓ Branch 0 taken 1435 times.
✗ Branch 1 not taken.
1435 currentSeq = both->GetSequenceName();
3357
1/2
✓ Branch 0 taken 1435 times.
✗ Branch 1 not taken.
1435 currentSong = both->GetMediaName();
3358
3/4
✓ Branch 0 taken 155018 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11489 times.
✓ Branch 3 taken 143529 times.
155018 } else if (type == "sequence") {
3359
1/2
✓ Branch 0 taken 11489 times.
✗ Branch 1 not taken.
11489 PlaylistEntrySequence* seq = dynamic_cast<PlaylistEntrySequence*>(ple);
3360
1/2
✓ Branch 0 taken 11489 times.
✗ Branch 1 not taken.
11489 currentSeq = seq->GetSequenceName();
3361 11489 secsElapsed = sequence->m_seqMSElapsed / 1000;
3362 11489 secsRemaining = sequence->m_seqMSRemaining / 1000;
3363
3/4
✓ Branch 0 taken 143529 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 143527 times.
143529 } else if (type == "script") {
3364
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 PlaylistEntryScript* scr = dynamic_cast<PlaylistEntryScript*>(ple);
3365
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 currentSeq = scr->GetScriptName();
3366 }
3367
2/4
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178070 times.
✗ Branch 3 not taken.
178070 result["current_sequence"] = currentSeq;
3368
2/4
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178070 times.
✗ Branch 3 not taken.
178070 result["current_song"] = currentSong;
3369
2/4
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178070 times.
✗ Branch 3 not taken.
178070 result["seconds_played"] = std::to_string(secsElapsed);
3370
2/4
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178070 times.
✗ Branch 3 not taken.
178070 result["seconds_elapsed"] = std::to_string(secsElapsed);
3371
2/4
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178070 times.
✗ Branch 3 not taken.
178070 result["milliseconds_elapsed"] = msecs;
3372
2/4
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178070 times.
✗ Branch 3 not taken.
178070 result["seconds_remaining"] = std::to_string(secsRemaining);
3373
3/6
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178070 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 178070 times.
✗ Branch 5 not taken.
178070 result["time_elapsed"] = secondsToTime(secsElapsed);
3374
3/6
✓ Branch 0 taken 178070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178070 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 178070 times.
✗ Branch 5 not taken.
178070 result["time_remaining"] = secondsToTime(secsRemaining);
3375 178070 }
3376 } else {
3377 // No current entry (between items, or a dynamic entry with nothing
3378 // resolved). Emit the same placeholders the idle branch above uses so
3379 // the status JSON keeps a stable shape for API consumers.
3380
2/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
51 result["current_sequence"] = "";
3381
2/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
51 result["current_song"] = "";
3382
2/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
51 result["seconds_played"] = "0";
3383
2/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
51 result["seconds_remaining"] = "0";
3384
2/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
51 result["time_elapsed"] = "00:00";
3385
2/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
51 result["time_remaining"] = "00:00";
3386 }
3387
3388 181587 std::list<std::string> parents;
3389
1/2
✓ Branch 0 taken 181587 times.
✗ Branch 1 not taken.
181587 GetParentPlaylistNames(parents);
3390
2/2
✓ Branch 0 taken 11180 times.
✓ Branch 1 taken 170407 times.
181587 if (!parents.empty()) {
3391
2/2
✓ Branch 0 taken 13358 times.
✓ Branch 1 taken 11180 times.
24538 for (auto& n : parents) {
3392
3/6
✓ Branch 0 taken 13358 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13358 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13358 times.
✗ Branch 5 not taken.
13358 result["breadcrumbs"].append(n);
3393 }
3394 }
3395
2/2
✓ Branch 0 taken 181587 times.
✓ Branch 1 taken 41453 times.
223040 }
3396 282 int Playlist::GetLevelCount() {
3397 282 int levels = 1;
3398
4/6
✓ Branch 0 taken 282 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 95 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 95 times.
✓ Branch 5 taken 282 times.
377 for (std::shared_ptr<Playlist> par = m_parent.load(); par; par = par->m_parent.load()) {
3399 95 levels++;
3400 282 }
3401 282 return levels;
3402 }
3403 194945 void Playlist::GetParentPlaylistNames(std::list<std::string>& names) {
3404
3/4
✓ Branch 0 taken 194945 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13358 times.
✓ Branch 3 taken 181587 times.
194945 if (std::shared_ptr<Playlist> par = m_parent.load()) {
3405
1/2
✓ Branch 0 taken 13358 times.
✗ Branch 1 not taken.
13358 par->GetParentPlaylistNames(names);
3406
2/4
✓ Branch 0 taken 13358 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13358 times.
✗ Branch 3 not taken.
13358 names.push_back(par->GetPlaylistName());
3407 194945 }
3408 194945 }
3409
3410 /*
3411 *
3412 */
3413 75205 Json::Value Playlist::GetInfo(void) {
3414 75205 Json::Value result;
3415
1/2
✓ Branch 0 taken 75205 times.
✗ Branch 1 not taken.
75205 GetInfo(result);
3416 75205 return result;
3417 ✗ }
3418
3419 94823 void Playlist::GetInfo(Json::Value& result) {
3420
1/2
✓ Branch 0 taken 94823 times.
✗ Branch 1 not taken.
94823 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3421
3/6
✓ Branch 0 taken 94823 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 94823 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 94823 times.
✗ Branch 5 not taken.
94823 result["currentState"] = PlaylistStatusToString(m_status);
3422
2/2
✓ Branch 0 taken 15804 times.
✓ Branch 1 taken 79019 times.
94823 if (m_status == FPP_STATUS_IDLE) {
3423
2/4
✓ Branch 0 taken 15804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15804 times.
✗ Branch 3 not taken.
15804 result["name"] = "";
3424
2/4
✓ Branch 0 taken 15804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15804 times.
✗ Branch 3 not taken.
15804 result["desc"] = "";
3425
2/4
✓ Branch 0 taken 15804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15804 times.
✗ Branch 3 not taken.
15804 result["repeat"] = 0;
3426
2/4
✓ Branch 0 taken 15804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15804 times.
✗ Branch 3 not taken.
15804 result["loop"] = 0;
3427
2/4
✓ Branch 0 taken 15804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15804 times.
✗ Branch 3 not taken.
15804 result["loopCount"] = 0;
3428
2/4
✓ Branch 0 taken 15804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15804 times.
✗ Branch 3 not taken.
15804 result["random"] = 0;
3429
2/4
✓ Branch 0 taken 15804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15804 times.
✗ Branch 3 not taken.
15804 result["blankAtEnd"] = 0;
3430
2/4
✓ Branch 0 taken 15804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15804 times.
✗ Branch 3 not taken.
15804 result["size"] = 0;
3431 } else {
3432
2/4
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79019 times.
✗ Branch 3 not taken.
79019 result["name"] = m_name;
3433
2/4
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79019 times.
✗ Branch 3 not taken.
79019 result["desc"] = m_desc;
3434
2/4
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79019 times.
✗ Branch 3 not taken.
158038 result["repeat"] = m_repeat.load();
3435
2/4
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79019 times.
✗ Branch 3 not taken.
158038 result["loop"] = m_loop.load();
3436
2/4
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79019 times.
✗ Branch 3 not taken.
79019 result["loopCount"] = m_loopCount;
3437
2/4
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79019 times.
✗ Branch 3 not taken.
79019 result["random"] = m_random;
3438
2/4
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79019 times.
✗ Branch 3 not taken.
79019 result["blankAtEnd"] = m_blankAtEnd;
3439
3/6
✓ Branch 0 taken 79019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79019 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 79019 times.
✗ Branch 5 not taken.
79019 result["size"] = GetSize();
3440 }
3441
2/4
✓ Branch 0 taken 94823 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 94823 times.
✗ Branch 3 not taken.
94823 result["currentEntry"] = GetCurrentEntry();
3442 94823 }
3443
3444 /*
3445 *
3446 */
3447 ✗ std::string Playlist::GetConfigStr(void) {
3448 ✗ return SaveJsonToString(GetConfig());
3449 }
3450
3451 /*
3452 *
3453 */
3454 19618 Json::Value Playlist::GetConfig(void) {
3455
1/2
✓ Branch 0 taken 19618 times.
✗ Branch 1 not taken.
19618 Json::Value result;
3456
1/2
✓ Branch 0 taken 19618 times.
✗ Branch 1 not taken.
19618 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3457
1/2
✓ Branch 0 taken 19618 times.
✗ Branch 1 not taken.
19618 GetInfo(result);
3458
3459
2/2
✓ Branch 0 taken 8055 times.
✓ Branch 1 taken 11563 times.
19618 if (m_leadIn.size()) {
3460
2/4
✓ Branch 0 taken 8055 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8055 times.
✗ Branch 3 not taken.
8055 result["leadIn"] = Json::Value(Json::arrayValue);
3461
1/2
✓ Branch 0 taken 8055 times.
✗ Branch 1 not taken.
8055 Json::Value& jsonArray = result["leadIn"];
3462
2/2
✓ Branch 0 taken 8055 times.
✓ Branch 1 taken 8055 times.
16110 for (int c = 0; c < m_leadIn.size(); c++) {
3463
2/4
✓ Branch 0 taken 8055 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8055 times.
✗ Branch 3 not taken.
8055 jsonArray.append(m_leadIn[c]->GetConfig());
3464 }
3465 }
3466
3467
2/2
✓ Branch 0 taken 13969 times.
✓ Branch 1 taken 5649 times.
19618 if (m_mainPlaylist.size()) {
3468
2/4
✓ Branch 0 taken 13969 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13969 times.
✗ Branch 3 not taken.
13969 result["mainPlaylist"] = Json::Value(Json::arrayValue);
3469
1/2
✓ Branch 0 taken 13969 times.
✗ Branch 1 not taken.
13969 Json::Value& jsonArray = result["mainPlaylist"];
3470
2/2
✓ Branch 0 taken 22032 times.
✓ Branch 1 taken 13969 times.
36001 for (int c = 0; c < m_mainPlaylist.size(); c++) {
3471
2/4
✓ Branch 0 taken 22032 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22032 times.
✗ Branch 3 not taken.
22032 jsonArray.append(m_mainPlaylist[c]->GetConfig());
3472 }
3473 }
3474
3475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19618 times.
19618 if (m_leadOut.size()) {
3476 ✗ result["leadOut"] = Json::Value(Json::arrayValue);
3477 ✗ Json::Value& jsonArray = result["leadOut"];
3478 ✗ for (int c = 0; c < m_leadOut.size(); c++) {
3479 ✗ jsonArray.append(m_leadOut[c]->GetConfig());
3480 }
3481 }
3482
3483 19618 m_configTime = time(NULL);
3484
2/4
✓ Branch 0 taken 19618 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19618 times.
✗ Branch 3 not taken.
19618 result["configTime"] = (Json::UInt64)m_configTime;
3485
3486
2/4
✓ Branch 0 taken 19618 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19618 times.
✗ Branch 3 not taken.
19618 result["random"] = m_random;
3487
2/4
✓ Branch 0 taken 19618 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19618 times.
✗ Branch 3 not taken.
19618 result["globalPauseBetweenSequencesMS"] = m_globalPauseBetweenSequencesMS;
3488
3489
2/4
✓ Branch 0 taken 19618 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19618 times.
✗ Branch 3 not taken.
19618 result["playlistInfo"] = m_playlistInfo;
3490
1/2
✓ Branch 0 taken 19618 times.
✗ Branch 1 not taken.
19618 m_config = result;
3491
3492 19618 return result;
3493 19618 }
3494
3495 /*
3496 *
3497 */
3498 144 int Playlist::MQTTHandler(std::string topic, std::string msg) {
3499
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144 times.
✗ Branch 3 not taken.
144 LogDebug(VB_PLAYLIST, "Playlist::MQTTHandler('%s', '%s') while playing '%s'\n",
3500 topic.c_str(), msg.c_str(), GetPlaylistName().c_str());
3501
3502 // note the leading /set/playlist will be removed from topic by now
3503
3504 144 int pos = topic.find("/");
3505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 144 times.
144 if (pos == std::string::npos) {
3506 ✗ LogWarn(VB_PLAYLIST, "Ignoring Invalid playlist topic: playlist/%s\n",
3507 topic.c_str());
3508 ✗ return 0;
3509 }
3510
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 std::string newPlaylistName = topic.substr(0, pos);
3511
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 std::string topicEnd = topic.substr(pos);
3512
3513 /*
3514 * NOTE: This because multiple playlist are not supported, the newPlaylistname value
3515 * is only considered when starting a playlist. All other actions will
3516 * apply to the current running playlist even if the names don't match
3517 */
3518
3519 // Stops go through the Player, as the API's and the commands' do, so the
3520 // force-stop is recorded and the scheduler does not start the playlist
3521 // straight back up.
3522 // ALLPLAYLIST should be checked first to avoid name colision.
3523
3/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✓ Branch 3 taken 97 times.
144 if (topic == "ALLPLAYLISTS/stop/now") {
3524
1/2
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
47 Player::INSTANCE.StopNow(1);
3525
3526
2/4
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 97 times.
97 } else if (topic == "ALLPLAYLISTS/stop/graceful") {
3527 ✗ Player::INSTANCE.StopGracefully(1);
3528
3529
2/4
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 97 times.
97 } else if (topic == "ALLPLAYLISTS/stop/afterloop") {
3530 ✗ Player::INSTANCE.StopGracefully(1, 1);
3531
3532
2/4
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 97 times.
97 } else if (topicEnd == "/next") {
3533 ✗ NextItem();
3534
3535
2/4
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 97 times.
97 } else if (topicEnd == "/prev") {
3536 ✗ PrevItem();
3537
3538
2/4
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 97 times.
97 } else if (topicEnd == "/repeat") {
3539 ✗ SetRepeat(atoi(msg.c_str()));
3540
3541
2/4
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 97 times.
97 } else if (topicEnd == "/startPosition") {
3542 ✗ SetPosition(atoi(msg.c_str()));
3543
3544
3/4
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 89 times.
97 } else if (topicEnd == "/stop/now") {
3545
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
8 Player::INSTANCE.StopNow(1);
3546
3547
3/4
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 88 times.
89 } else if (topicEnd == "/stop/graceful") {
3548
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 Player::INSTANCE.StopGracefully(1);
3549
3550
3/4
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 86 times.
88 } else if (topicEnd == "/stop/afterloop") {
3551
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Player::INSTANCE.StopGracefully(1, 1);
3552
3553 // These three are depgrecated and should be removed
3554
3/4
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 46 times.
86 } else if (topic == "name/set") {
3555
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 LogInfo(VB_CONTROL, "playlist/%s is deprecated and will be removed in a future release\n",
3556 topic.c_str());
3557 // On the MQTT thread: the playlist thread moves m_sectionPosition
3558 // under the lock as it advances.
3559 int position;
3560 {
3561
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 std::unique_lock<std::recursive_mutex> lck(m_playlistMutex);
3562 40 position = m_sectionPosition;
3563 40 }
3564
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 Play(msg, position, m_repeat);
3565
3566
3/4
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 42 times.
46 } else if (topic == "repeat/set") {
3567
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 LogInfo(VB_PLAYLIST, "playlist/%s is deprecated and will be removed in a future release\n",
3568 topic.c_str());
3569
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 SetRepeat(atoi(msg.c_str()));
3570
3571
2/4
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
42 } else if (topic == "sectionPosition/set") {
3572
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 LogInfo(VB_PLAYLIST, "playlist/%s is deprecated and will be removed in a future release\n",
3573 topic.c_str());
3574
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 SetPosition(atoi(msg.c_str()));
3575
3576 } else {
3577 ✗ LogWarn(VB_PLAYLIST, "Ignoring Invalid playlist topic: playlist/%s\n", topic.c_str());
3578 ✗ return 0;
3579 }
3580
3581 142 return 1;
3582 142 }
3583
3584 /*
3585 *
3586 */
3587 ✗ std::string Playlist::ReplaceMatches(std::string in) {
3588 ✗ std::string out = in;
3589
3590 ✗ LogDebug(VB_PLAYLIST, "In: '%s'\n", in.c_str());
3591
3592 // FIXME, Playlist
3593
3594 ✗ LogDebug(VB_PLAYLIST, "Out: '%s'\n", out.c_str());
3595
3596 ✗ return out;
3597 ✗ }
3598
3599 /*
3600 * Helper method to start playing an entry, handling global pause between sequences
3601 */
3602 4779 void Playlist::StartPlayingWithGlobalPause(PlaylistEntryBase* entry) {
3603
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4773 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
4779 if (m_shouldStartGlobalPause && m_globalPauseBetweenSequencesMS > 0) {
3604 6 LogDebug(VB_PLAYLIST, "Starting global pause between sequences for %d ms before next item\n", m_globalPauseBetweenSequencesMS);
3605 6 m_shouldStartGlobalPause = false;
3606 6 m_isInGlobalPause = true;
3607 6 m_globalPauseStartTime = GetMonotonicTimeMS();
3608 // Don't start the entry yet, it will be started when the pause completes
3609 } else {
3610 // No global pause needed, start immediately
3611 4773 entry->StartPlayingOrFinish();
3612 }
3613 4779 }
3614