| 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 | 773 | PlaylistEntryPause::PlaylistEntryPause(Playlist* playlist, PlaylistEntryBase* parent) : | |
| 26 | PlaylistEntryBase(playlist, parent), | ||
| 27 | 773 | m_duration(0.0f), | |
| 28 | 773 | m_startTime(0), | |
| 29 | 773 | m_endTime(0), | |
| 30 | 773 | m_pausedRemaining(0) { | |
| 31 |
1/2✓ Branch 0 taken 773 times.
✗ Branch 1 not taken.
|
773 | LogDebug(VB_PLAYLIST, "PlaylistEntryPause::PlaylistEntryPause()\n"); |
| 32 | |||
| 33 |
1/2✓ Branch 0 taken 773 times.
✗ Branch 1 not taken.
|
773 | m_type = "pause"; |
| 34 | 773 | } | |
| 35 | |||
| 36 | /* | ||
| 37 | * | ||
| 38 | */ | ||
| 39 | 2884 | PlaylistEntryPause::~PlaylistEntryPause() { | |
| 40 | 2884 | } | |
| 41 | |||
| 42 | /* | ||
| 43 | * | ||
| 44 | */ | ||
| 45 | 773 | int PlaylistEntryPause::Init(Json::Value& config) { | |
| 46 | 773 | LogDebug(VB_PLAYLIST, "PlaylistEntryPause::Init()\n"); | |
| 47 | |||
| 48 | 773 | m_duration = config["duration"].asFloat(); | |
| 49 | 773 | m_endTime = 0; | |
| 50 | 773 | m_finishTime = 0; | |
| 51 | 773 | m_pausedRemaining = 0; | |
| 52 | 773 | return PlaylistEntryBase::Init(config); | |
| 53 | } | ||
| 54 | |||
| 55 | /* | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | 27489 | int PlaylistEntryPause::StartPlaying(void) { | |
| 59 | 27489 | LogDebug(VB_PLAYLIST, "PlaylistEntryPause::StartPlaying()\n"); | |
| 60 | |||
| 61 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27489 times.
|
27489 | if (!CanPlay()) { |
| 62 | ✗ | FinishPlay(); | |
| 63 | ✗ | return 0; | |
| 64 | } | ||
| 65 | 27489 | m_pausedRemaining = 0; | |
| 66 | // Calculate end time as m_duation number of seconds from now | ||
| 67 | 27489 | m_startTime = GetMonotonicTimeMS(); | |
| 68 | |||
| 69 | 27489 | double tmp = m_duration; | |
| 70 | 27489 | tmp *= 1000.0; | |
| 71 | 27489 | m_endTime = m_startTime + tmp; | |
| 72 | |||
| 73 | 27489 | return PlaylistEntryBase::StartPlaying(); | |
| 74 | } | ||
| 75 | |||
| 76 | /* | ||
| 77 | * | ||
| 78 | */ | ||
| 79 | 25202 | int PlaylistEntryPause::Process(void) { | |
| 80 |
3/6✓ Branch 0 taken 25202 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25202 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 25202 times.
|
25202 | if (!m_isStarted || !m_isPlaying || m_isFinished) { |
| 81 | ✗ | return 0; | |
| 82 | } | ||
| 83 | |||
| 84 | 25202 | long long now = GetMonotonicTimeMS(); | |
| 85 |
4/6✓ Branch 0 taken 25202 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25202 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 97 times.
✓ Branch 5 taken 25105 times.
|
25202 | if (m_isStarted && m_isPlaying && (now >= m_endTime)) { |
| 86 | 97 | m_finishTime = GetMonotonicTimeMS(); | |
| 87 | 97 | FinishPlay(); | |
| 88 | } | ||
| 89 | |||
| 90 | 25202 | return PlaylistEntryBase::Process(); | |
| 91 | } | ||
| 92 | |||
| 93 | /* | ||
| 94 | * | ||
| 95 | */ | ||
| 96 | 27369 | int PlaylistEntryPause::Stop(void) { | |
| 97 | 27369 | LogDebug(VB_PLAYLIST, "PlaylistEntryPause::Stop()\n"); | |
| 98 | |||
| 99 | 27369 | m_finishTime = GetMonotonicTimeMS(); | |
| 100 | 27369 | FinishPlay(); | |
| 101 | 27369 | m_pausedRemaining = 0; | |
| 102 | 27369 | return PlaylistEntryBase::Stop(); | |
| 103 | } | ||
| 104 | |||
| 105 | 42507 | uint64_t PlaylistEntryPause::GetLengthInMS() { | |
| 106 | 42507 | float f = m_duration; //duration is in seconds | |
| 107 | 42507 | f *= 1000; | |
| 108 | 42507 | return f; | |
| 109 | } | ||
| 110 | 85014 | uint64_t PlaylistEntryPause::GetElapsedMS() { | |
| 111 | 85014 | long long now = GetMonotonicTimeMS(); | |
| 112 |
3/4✓ Branch 0 taken 85014 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84784 times.
✓ Branch 3 taken 230 times.
|
85014 | if (m_isStarted && m_isPlaying) { |
| 113 | 84784 | return now - m_startTime; | |
| 114 | } | ||
| 115 | 230 | 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 | 66986 | Json::Value PlaylistEntryPause::GetConfig(void) { | |
| 135 | 66986 | Json::Value result = PlaylistEntryBase::GetConfig(); | |
| 136 | |||
| 137 |
1/2✓ Branch 0 taken 66986 times.
✗ Branch 1 not taken.
|
66986 | long long now = GetMonotonicTimeMS(); |
| 138 |
3/4✓ Branch 0 taken 66986 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5591 times.
✓ Branch 3 taken 61395 times.
|
66986 | if (IsPaused()) { |
| 139 | 5591 | m_endTime = now + m_pausedRemaining; | |
| 140 | 5591 | float d = m_duration * 1000; | |
| 141 | 5591 | 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 66986 times.
✗ Branch 1 not taken.
|
66986 | long long toWall = GetTimeMS() - now; |
| 148 |
2/4✓ Branch 0 taken 66986 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66986 times.
✗ Branch 3 not taken.
|
66986 | result["duration"] = m_duration; |
| 149 |
4/6✓ Branch 0 taken 66958 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 66986 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 66986 times.
✗ Branch 5 not taken.
|
66986 | result["startTime"] = (Json::UInt64)(m_startTime ? m_startTime + toWall : 0); |
| 150 |
4/6✓ Branch 0 taken 66958 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 66986 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 66986 times.
✗ Branch 5 not taken.
|
66986 | result["endTime"] = (Json::UInt64)(m_endTime ? m_endTime + toWall : 0); |
| 151 |
4/6✓ Branch 0 taken 27216 times.
✓ Branch 1 taken 39770 times.
✓ Branch 2 taken 66986 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 66986 times.
✗ Branch 5 not taken.
|
66986 | result["finishTime"] = (Json::UInt64)(m_finishTime ? m_finishTime + toWall : 0); |
| 152 | |||
| 153 |
3/4✓ Branch 0 taken 39773 times.
✓ Branch 1 taken 27213 times.
✓ Branch 2 taken 39773 times.
✗ Branch 3 not taken.
|
66986 | if (m_isPlaying && (m_endTime > now)) |
| 154 |
2/4✓ Branch 0 taken 39773 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39773 times.
✗ Branch 3 not taken.
|
39773 | result["remaining"] = (Json::UInt64)((m_endTime - now) / 1000); |
| 155 | else | ||
| 156 |
2/4✓ Branch 0 taken 27213 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27213 times.
✗ Branch 3 not taken.
|
27213 | result["remaining"] = (Json::UInt64)0; |
| 157 | |||
| 158 | 66986 | return result; | |
| 159 | ✗ | } | |
| 160 | |||
| 161 | 328 | void PlaylistEntryPause::Pause() { | |
| 162 | 328 | long long now = GetMonotonicTimeMS(); | |
| 163 | 328 | m_pausedRemaining = m_endTime - now; | |
| 164 | 328 | } | |
| 165 | 123155 | bool PlaylistEntryPause::IsPaused() { | |
| 166 | 123155 | return m_pausedRemaining != 0; | |
| 167 | } | ||
| 168 | 324 | void PlaylistEntryPause::Resume() { | |
| 169 | 324 | long long now = GetMonotonicTimeMS(); | |
| 170 | 324 | m_endTime = now + m_pausedRemaining; | |
| 171 | 324 | m_pausedRemaining = 0; | |
| 172 | 324 | } | |
| 173 |