GCC Code Coverage Report


Directory: ./
File: playlist/PlaylistEntryPause.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 83 87 95.4%
Functions: 13 13 100.0%
Branches: 39 64 60.9%

Line Branch Exec Source
1 /*
2 * This file is part of the Falcon Player (FPP) and is Copyright (C)
3 * 2013-2022 by the Falcon Player Developers.
4 *
5 * The Falcon Player (FPP) is free software, and is covered under
6 * multiple Open Source licenses. Please see the included 'LICENSES'
7 * file for descriptions of what files are covered by each license.
8 *
9 * This source file is covered under the LGPL v2.1 as described in the
10 * included LICENSE.LGPL file.
11 */
12
13 #include "fpp-pch.h"
14
15 #include "fpp-json.h"
16
17 #include "../common.h"
18 #include "../log.h"
19
20 #include "PlaylistEntryPause.h"
21
22 /*
23 *
24 */
25 1081 PlaylistEntryPause::PlaylistEntryPause(Playlist* playlist, PlaylistEntryBase* parent) :
26 PlaylistEntryBase(playlist, parent),
27 1081 m_duration(0.0f),
28 1081 m_startTime(0),
29 1081 m_endTime(0),
30 1081 m_pausedRemaining(0) {
31
1/2
✓ Branch 0 taken 1081 times.
✗ Branch 1 not taken.
1081 LogDebug(VB_PLAYLIST, "PlaylistEntryPause::PlaylistEntryPause()\n");
32
33
1/2
✓ Branch 0 taken 1081 times.
✗ Branch 1 not taken.
1081 m_type = "pause";
34 1081 }
35
36 /*
37 *
38 */
39 4032 PlaylistEntryPause::~PlaylistEntryPause() {
40 4032 }
41
42 /*
43 *
44 */
45 1081 int PlaylistEntryPause::Init(Json::Value& config) {
46 1081 LogDebug(VB_PLAYLIST, "PlaylistEntryPause::Init()\n");
47
48 1081 m_duration = config["duration"].asFloat();
49 1081 m_endTime = 0;
50 1081 m_finishTime = 0;
51 1081 m_pausedRemaining = 0;
52 1081 return PlaylistEntryBase::Init(config);
53 }
54
55 /*
56 *
57 */
58 25038 int PlaylistEntryPause::StartPlaying(void) {
59 25038 LogDebug(VB_PLAYLIST, "PlaylistEntryPause::StartPlaying()\n");
60
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25038 times.
25038 if (!CanPlay()) {
62 ✗ FinishPlay();
63 ✗ return 0;
64 }
65 25038 m_pausedRemaining = 0;
66 // Calculate end time as m_duation number of seconds from now
67 25038 m_startTime = GetMonotonicTimeMS();
68
69 25038 double tmp = m_duration;
70 25038 tmp *= 1000.0;
71 25038 m_endTime = m_startTime + tmp;
72
73 25038 return PlaylistEntryBase::StartPlaying();
74 }
75
76 /*
77 *
78 */
79 39812 int PlaylistEntryPause::Process(void) {
80
3/6
✓ Branch 0 taken 39812 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39812 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 39812 times.
39812 if (!m_isStarted || !m_isPlaying || m_isFinished) {
81 ✗ return 0;
82 }
83
84 39812 long long now = GetMonotonicTimeMS();
85
4/6
✓ Branch 0 taken 39812 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39812 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 118 times.
✓ Branch 5 taken 39694 times.
39812 if (m_isStarted && m_isPlaying && (now >= m_endTime)) {
86 118 m_finishTime = GetMonotonicTimeMS();
87 118 FinishPlay();
88 }
89
90 39812 return PlaylistEntryBase::Process();
91 }
92
93 /*
94 *
95 */
96 24884 int PlaylistEntryPause::Stop(void) {
97 24884 LogDebug(VB_PLAYLIST, "PlaylistEntryPause::Stop()\n");
98
99 24884 m_finishTime = GetMonotonicTimeMS();
100 24884 FinishPlay();
101 24884 m_pausedRemaining = 0;
102 24884 return PlaylistEntryBase::Stop();
103 }
104
105 80984 uint64_t PlaylistEntryPause::GetLengthInMS() {
106 80984 float f = m_duration; //duration is in seconds
107 80984 f *= 1000;
108 80984 return f;
109 }
110 143365 uint64_t PlaylistEntryPause::GetElapsedMS() {
111 143365 long long now = GetMonotonicTimeMS();
112
3/4
✓ Branch 0 taken 143365 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 143017 times.
✓ Branch 3 taken 348 times.
143365 if (m_isStarted && m_isPlaying) {
113 143017 return now - m_startTime;
114 }
115 348 return 0;
116 }
117
118 /*
119 *
120 */
121 4 void PlaylistEntryPause::Dump(void) {
122 4 PlaylistEntryBase::Dump();
123
124 4 LogDebug(VB_PLAYLIST, "Duration: %f\n", m_duration);
125 4 LogDebug(VB_PLAYLIST, "Cur Time: %lld\n", GetMonotonicTimeMS());
126 4 LogDebug(VB_PLAYLIST, "Start Time: %lld\n", m_startTime);
127 4 LogDebug(VB_PLAYLIST, "End Time: %lld\n", m_endTime);
128 4 LogDebug(VB_PLAYLIST, "Finish Time: %lld\n", m_finishTime);
129 4 }
130
131 /*
132 *
133 */
134 60047 Json::Value PlaylistEntryPause::GetConfig(void) {
135 60047 Json::Value result = PlaylistEntryBase::GetConfig();
136
137
1/2
✓ Branch 0 taken 60047 times.
✗ Branch 1 not taken.
60047 long long now = GetMonotonicTimeMS();
138
3/4
✓ Branch 0 taken 60047 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5196 times.
✓ Branch 3 taken 54851 times.
60047 if (IsPaused()) {
139 5196 m_endTime = now + m_pausedRemaining;
140 5196 float d = m_duration * 1000;
141 5196 m_startTime = m_endTime - d;
142 }
143
144 // The timers run on the monotonic clock (a wall-clock step used to stall
145 // a pause for as long as the clock jumped back -- years, for an unset RTC
146 // stepping to 2000). Report them as wall-clock times, as before.
147
1/2
✓ Branch 0 taken 60047 times.
✗ Branch 1 not taken.
60047 long long toWall = GetTimeMS() - now;
148
2/4
✓ Branch 0 taken 60047 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60047 times.
✗ Branch 3 not taken.
60047 result["duration"] = m_duration;
149
4/6
✓ Branch 0 taken 59993 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 60047 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 60047 times.
✗ Branch 5 not taken.
60047 result["startTime"] = (Json::UInt64)(m_startTime ? m_startTime + toWall : 0);
150
4/6
✓ Branch 0 taken 59993 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 60047 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 60047 times.
✗ Branch 5 not taken.
60047 result["endTime"] = (Json::UInt64)(m_endTime ? m_endTime + toWall : 0);
151
4/6
✓ Branch 0 taken 24501 times.
✓ Branch 1 taken 35546 times.
✓ Branch 2 taken 60047 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 60047 times.
✗ Branch 5 not taken.
60047 result["finishTime"] = (Json::UInt64)(m_finishTime ? m_finishTime + toWall : 0);
152
153
3/4
✓ Branch 0 taken 35523 times.
✓ Branch 1 taken 24524 times.
✓ Branch 2 taken 35523 times.
✗ Branch 3 not taken.
60047 if (m_isPlaying && (m_endTime > now))
154
2/4
✓ Branch 0 taken 35523 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35523 times.
✗ Branch 3 not taken.
35523 result["remaining"] = (Json::UInt64)((m_endTime - now) / 1000);
155 else
156
2/4
✓ Branch 0 taken 24524 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24524 times.
✗ Branch 3 not taken.
24524 result["remaining"] = (Json::UInt64)0;
157
158 60047 return result;
159 ✗ }
160
161 373 void PlaylistEntryPause::Pause() {
162 373 long long now = GetMonotonicTimeMS();
163 373 m_pausedRemaining = m_endTime - now;
164 373 }
165 144557 bool PlaylistEntryPause::IsPaused() {
166 144557 return m_pausedRemaining != 0;
167 }
168 298 void PlaylistEntryPause::Resume() {
169 298 long long now = GetMonotonicTimeMS();
170 298 m_endTime = now + m_pausedRemaining;
171 298 m_pausedRemaining = 0;
172 298 }
173