| 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 | #include "fpphttp.h" // drogon/HTTP helpers used here; no longer pulled transitively (see fpphttp_types.h) | ||
| 17 | |||
| 18 | #include <atomic> | ||
| 19 | #include <chrono> | ||
| 20 | #include <cstdlib> | ||
| 21 | #include <ctime> | ||
| 22 | #include <functional> | ||
| 23 | #include <string> | ||
| 24 | #include <vector> | ||
| 25 | |||
| 26 | #include "Events.h" | ||
| 27 | #include "common.h" | ||
| 28 | #include "log.h" | ||
| 29 | #include "commands/Commands.h" | ||
| 30 | |||
| 31 | #include "Player.h" | ||
| 32 | |||
| 33 | // Playlists retired by the main loop are destroyed HERE, on the main thread, | ||
| 34 | // never by whichever thread happened to drop the last snapshot: ~Playlist runs | ||
| 35 | // Cleanup(), which parks every entry on Playlist.cpp's PL_ENTRY_CLEANUPS — an | ||
| 36 | // unsynchronized list that only the main thread drains. So the shared_ptr | ||
| 37 | // deleter does not delete; it parks the raw pointer here, and | ||
| 38 | // Playlist::Process() calls DrainRetiredPlaylists() at exactly the point in the | ||
| 39 | // frame where the old drain ran `delete p`. | ||
| 40 | // | ||
| 41 | // Declared ahead of Player::INSTANCE so it is constructed first and therefore | ||
| 42 | // destroyed last — ~Player drains it during static destruction. | ||
| 43 | static std::mutex s_retiredPlaylistLock; | ||
| 44 | static std::vector<Playlist*> s_retiredPlaylists; | ||
| 45 | |||
| 46 | 569 | static void RetirePlaylist(Playlist* p) { | |
| 47 |
1/2✓ Branch 0 taken 569 times.
✗ Branch 1 not taken.
|
569 | std::lock_guard<std::mutex> lk(s_retiredPlaylistLock); |
| 48 |
1/2✓ Branch 0 taken 569 times.
✗ Branch 1 not taken.
|
569 | s_retiredPlaylists.push_back(p); |
| 49 | 569 | } | |
| 50 | |||
| 51 | Player Player::INSTANCE; | ||
| 52 | |||
| 53 | // A count: a command holds one around StartPlaylist(), whose PlayImpl() holds | ||
| 54 | // its own. | ||
| 55 | static std::atomic<int> s_switchesInFlight{ 0 }; | ||
| 56 | // When the count last left 0. A command's scope also covers the presets and | ||
| 57 | // plugin callbacks its stop and start fire, and a script plugin's callback is | ||
| 58 | // waited for with no timeout: past this long, the switch no longer holds the | ||
| 59 | // scheduler back. | ||
| 60 | static std::atomic<int64_t> s_switchSinceMs{ 0 }; | ||
| 61 | static std::atomic<bool> s_switchOverdueLogged{ false }; | ||
| 62 | static constexpr int64_t MAX_SWITCH_MS = 5000; | ||
| 63 | |||
| 64 | 4261 | static int64_t SteadyMs() { | |
| 65 |
1/2✓ Branch 0 taken 4261 times.
✗ Branch 1 not taken.
|
4261 | return std::chrono::duration_cast<std::chrono::milliseconds>( |
| 66 | 8522 | std::chrono::steady_clock::now().time_since_epoch()) | |
| 67 | 8522 | .count(); | |
| 68 | } | ||
| 69 | |||
| 70 | 3794 | Player::SwitchScope::SwitchScope() { | |
| 71 |
2/2✓ Branch 0 taken 2033 times.
✓ Branch 1 taken 1761 times.
|
3794 | if (s_switchesInFlight++ == 0) { |
| 72 | 2033 | s_switchSinceMs = SteadyMs(); | |
| 73 | 2033 | s_switchOverdueLogged = false; | |
| 74 | } | ||
| 75 | 3794 | } | |
| 76 | |||
| 77 | 3794 | Player::SwitchScope::~SwitchScope() { | |
| 78 | 3794 | s_switchesInFlight--; | |
| 79 | 3794 | } | |
| 80 | |||
| 81 | 7054 | bool Player::Switching() { | |
| 82 |
2/2✓ Branch 0 taken 4826 times.
✓ Branch 1 taken 2228 times.
|
7054 | if (s_switchesInFlight == 0) |
| 83 | 4826 | return false; | |
| 84 | 2228 | int64_t ms = SteadyMs() - s_switchSinceMs; | |
| 85 |
2/2✓ Branch 0 taken 2223 times.
✓ Branch 1 taken 5 times.
|
2228 | if (ms < MAX_SWITCH_MS) |
| 86 | 2223 | return true; | |
| 87 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
|
5 | if (!s_switchOverdueLogged.exchange(true)) |
| 88 | 1 | LogWarn(VB_PLAYLIST, "A playlist switch is still running after %lld ms (a slow PLAYLIST_STOPPED/STARTED preset or plugin callback?); the scheduler carries on\n", (long long)ms); | |
| 89 | 5 | return false; | |
| 90 | } | ||
| 91 | |||
| 92 | 3252 | Player::Player() : | |
| 93 | 3252 | lastCheckTime(std::time(nullptr)), | |
| 94 | 3252 | origStartTime(0), | |
| 95 | 3252 | origStopTime(0), | |
| 96 | 3252 | startTime(0), | |
| 97 | 3252 | stopTime(0), | |
| 98 | 3252 | stopMethod(0), | |
| 99 | 3252 | priority(1000), | |
| 100 | 3252 | allowScheduleOverride(true), | |
| 101 | 6504 | forceStopped(false) { | |
| 102 | 3252 | } | |
| 103 | |||
| 104 | 600 | Player::~Player() { | |
| 105 | // Static destruction: nothing will call Process() again, so drop the owning | ||
| 106 | // references and run the deferred deletes inline. The entries those | ||
| 107 | // destructors park on PL_ENTRY_CLEANUPS are left for the process to | ||
| 108 | // reclaim, exactly as the old `delete playlist` did. | ||
| 109 | 600 | m_playlist.store(nullptr); | |
| 110 | 600 | std::vector<std::shared_ptr<Playlist>> owned; | |
| 111 | { | ||
| 112 | 600 | std::lock_guard<std::mutex> lk(m_ownedPlaylistsLock); | |
| 113 | 600 | owned.swap(m_ownedPlaylists); | |
| 114 | 600 | } | |
| 115 | 600 | owned.clear(); | |
| 116 | 600 | DrainRetiredPlaylists(); | |
| 117 | 600 | } | |
| 118 | |||
| 119 | 3223 | std::shared_ptr<Playlist> Player::CreatePlaylist(std::shared_ptr<Playlist> parent) { | |
| 120 |
4/10✓ Branch 0 taken 3223 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3223 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3223 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3223 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
3223 | std::shared_ptr<Playlist> pl(new Playlist(std::move(parent)), RetirePlaylist); |
| 121 |
1/2✓ Branch 0 taken 3223 times.
✗ Branch 1 not taken.
|
3223 | std::lock_guard<std::mutex> lk(m_ownedPlaylistsLock); |
| 122 |
1/2✓ Branch 0 taken 3223 times.
✗ Branch 1 not taken.
|
3223 | m_ownedPlaylists.push_back(pl); |
| 123 | 3223 | return pl; | |
| 124 | 3223 | } | |
| 125 | |||
| 126 | 3635 | void Player::SetCurrentPlaylist(Playlist* p) { | |
| 127 | 3635 | std::shared_ptr<Playlist> owned; | |
| 128 | { | ||
| 129 |
1/2✓ Branch 0 taken 3635 times.
✗ Branch 1 not taken.
|
3635 | std::lock_guard<std::mutex> lk(m_ownedPlaylistsLock); |
| 130 |
1/2✓ Branch 0 taken 4474 times.
✗ Branch 1 not taken.
|
4474 | for (auto& sp : m_ownedPlaylists) { |
| 131 |
2/2✓ Branch 0 taken 3635 times.
✓ Branch 1 taken 839 times.
|
4474 | if (sp.get() == p) { |
| 132 | 3635 | owned = sp; | |
| 133 | 3635 | break; | |
| 134 | } | ||
| 135 | } | ||
| 136 | 3635 | } | |
| 137 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3635 times.
|
3635 | if (!owned) { |
| 138 | // Invariant: only an instance this player created and has not yet | ||
| 139 | // released can become current. Getting here means a raw Playlist* | ||
| 140 | // outlived its ownership — publishing it (or publishing null) would | ||
| 141 | // hand every reader a dangling or absent playlist, so keep the current | ||
| 142 | // one and make the breakage visible instead. | ||
| 143 | ✗ | LogErr(VB_PLAYLIST, "Player::SetCurrentPlaylist() called with an unowned Playlist %p — keeping the current playlist\n", | |
| 144 | (void*)p); | ||
| 145 | ✗ | return; | |
| 146 | } | ||
| 147 |
1/2✓ Branch 0 taken 3635 times.
✗ Branch 1 not taken.
|
3635 | m_playlist.store(std::move(owned)); |
| 148 |
1/2✓ Branch 0 taken 3635 times.
✗ Branch 1 not taken.
|
3635 | } |
| 149 | |||
| 150 | 569 | void Player::ReleasePlaylist(Playlist* p) { | |
| 151 | // Declared before the lock so the reference is dropped — and the deleter | ||
| 152 | // run, if this was the last one — after m_ownedPlaylistsLock is released. | ||
| 153 | 569 | std::shared_ptr<Playlist> dropped; | |
| 154 | { | ||
| 155 |
1/2✓ Branch 0 taken 569 times.
✗ Branch 1 not taken.
|
569 | std::lock_guard<std::mutex> lk(m_ownedPlaylistsLock); |
| 156 |
1/2✓ Branch 0 taken 1183 times.
✗ Branch 1 not taken.
|
1183 | for (auto it = m_ownedPlaylists.begin(); it != m_ownedPlaylists.end(); ++it) { |
| 157 |
2/2✓ Branch 0 taken 569 times.
✓ Branch 1 taken 614 times.
|
1183 | if (it->get() == p) { |
| 158 | 569 | dropped = std::move(*it); | |
| 159 |
1/2✓ Branch 0 taken 569 times.
✗ Branch 1 not taken.
|
569 | m_ownedPlaylists.erase(it); |
| 160 | 569 | break; | |
| 161 | } | ||
| 162 | } | ||
| 163 | 569 | } | |
| 164 | 569 | } | |
| 165 | |||
| 166 | 573270 | void Player::DrainRetiredPlaylists() { | |
| 167 | while (true) { | ||
| 168 | 573270 | Playlist* p = nullptr; | |
| 169 | { | ||
| 170 |
1/2✓ Branch 0 taken 573270 times.
✗ Branch 1 not taken.
|
573270 | std::lock_guard<std::mutex> lk(s_retiredPlaylistLock); |
| 171 |
2/2✓ Branch 0 taken 572701 times.
✓ Branch 1 taken 569 times.
|
573270 | if (s_retiredPlaylists.empty()) |
| 172 | 1145402 | return; | |
| 173 | 569 | p = s_retiredPlaylists.back(); | |
| 174 | 569 | s_retiredPlaylists.pop_back(); | |
| 175 |
2/2✓ Branch 0 taken 569 times.
✓ Branch 1 taken 572701 times.
|
573270 | } |
| 176 | // Deliberately unlocked: ~Playlist runs arbitrary entry destructors. | ||
| 177 |
1/2✓ Branch 0 taken 569 times.
✗ Branch 1 not taken.
|
569 | delete p; |
| 178 | 569 | } | |
| 179 | } | ||
| 180 | |||
| 181 | 2651 | void Player::Init() { | |
| 182 | /* | ||
| 183 | * Start Playlist Callback | ||
| 184 | */ | ||
| 185 | std::function<void(const std::string&, const std::string&)> | ||
| 186 | 2651 | playlist_callback = [](const std::string& topic_in, | |
| 187 | const std::string& payload) { | ||
| 188 | 115 | std::string emptyStr; | |
| 189 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | std::string topic = topic_in; |
| 190 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | topic.replace(0, 14, emptyStr); // Replace until /# |
| 191 | |||
| 192 | 115 | int pos = topic.find("/"); | |
| 193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
|
115 | if (pos == std::string::npos) { |
| 194 | ✗ | LogWarn(VB_PLAYLIST, "Ignoring Invalid playlist topic: playlist/%s\n", | |
| 195 | topic.c_str()); | ||
| 196 | ✗ | return; | |
| 197 | } | ||
| 198 | |||
| 199 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | std::string newPlaylistName = topic.substr(0, pos); |
| 200 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | std::string topicEnd = topic.substr(pos); |
| 201 | |||
| 202 |
3/4✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 58 times.
|
115 | if (topicEnd == "/start") { |
| 203 | 57 | pos = 0; | |
| 204 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 10 times.
|
57 | if (!payload.empty()) { |
| 205 | 47 | pos = std::atoi(payload.c_str()); | |
| 206 | } | ||
| 207 | |||
| 208 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | LogDebug(VB_CONTROL, "Starting Playlist '%s' with message '%s'\n", |
| 209 | newPlaylistName.c_str(), payload.c_str()); | ||
| 210 | // Stop the running playlist first, as Start Playlist does. | ||
| 211 | // Stopped inside the start instead, its PLAYLIST_STOPPED | ||
| 212 | // preset and plugin "stop" callback are deferred and run | ||
| 213 | // after the new playlist has started, undoing its lead-in. | ||
| 214 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | Player::SwitchScope switching; |
| 215 |
3/4✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 27 times.
|
57 | if (Player::INSTANCE.GetStatus() != FPP_STATUS_IDLE) { |
| 216 |
1/2✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
|
30 | Player::INSTANCE.StopNowAllLevels(1); |
| 217 | } | ||
| 218 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | Player::INSTANCE.StartPlaylist(newPlaylistName, -1, pos); |
| 219 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | LogDebug(VB_CONTROL, "Call to Player::INSTANCE.StartPlaylist complete\n"); |
| 220 | 57 | } else { | |
| 221 | // Runs on the MQTT thread; the snapshot pins the instance for | ||
| 222 | // the call. | ||
| 223 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | std::shared_ptr<Playlist> pl = Player::INSTANCE.PlaylistSnapshot(); |
| 224 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | if (pl) |
| 225 |
3/6✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 58 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 56 times.
✗ Branch 5 not taken.
|
58 | pl->MQTTHandler(topic, payload); |
| 226 | 56 | }; | |
| 227 | |||
| 228 |
1/2✓ Branch 0 taken 113 times.
✗ Branch 1 not taken.
|
113 | LogDebug(VB_CONTROL, "exit playlist_callback (MQTT)\n"); |
| 229 |
2/4✓ Branch 0 taken 113 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 113 times.
✗ Branch 3 not taken.
|
2764 | }; |
| 230 |
2/4✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2651 times.
✗ Branch 3 not taken.
|
2651 | Events::AddCallback("/set/playlist/#", playlist_callback); |
| 231 | |||
| 232 |
3/4✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✓ Branch 3 taken 2590 times.
|
2651 | if (Events::HasEventHandlers()) { |
| 233 | // Deprecated topics. Registered here, once, rather than per Playlist | ||
| 234 | // instance: a per-instance callback captured that instance, outlived | ||
| 235 | // it, and was re-added (growing the handler's topic list) by every | ||
| 236 | // inserted playlist. Same snapshot dispatch as /set/playlist/#. | ||
| 237 | std::function<void(const std::string&, const std::string&)> legacy_callback = | ||
| 238 | 61 | [](const std::string& t, const std::string& payload) { | |
| 239 |
1/2✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
|
86 | LogDebug(VB_CONTROL, "Received deprecated MQTT Topic: '%s' \n", t.c_str()); |
| 240 |
1/2✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
|
86 | std::string topic = t; |
| 241 |
1/2✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
|
86 | topic.replace(0, 10, ""); // strip "/playlist/" |
| 242 |
1/2✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
|
86 | std::shared_ptr<Playlist> pl = Player::INSTANCE.PlaylistSnapshot(); |
| 243 |
1/2✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
|
86 | if (pl) |
| 244 |
3/6✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 86 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 86 times.
✗ Branch 5 not taken.
|
86 | pl->MQTTHandler(topic, payload); |
| 245 | 147 | }; | |
| 246 |
2/4✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✗ Branch 3 not taken.
|
122 | Events::AddCallback("/playlist/name/set", legacy_callback); |
| 247 |
2/4✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✗ Branch 3 not taken.
|
122 | Events::AddCallback("/playlist/repeat/set", legacy_callback); |
| 248 |
2/4✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✗ Branch 3 not taken.
|
61 | Events::AddCallback("/playlist/sectionPosition/set", legacy_callback); |
| 249 | 61 | } | |
| 250 | |||
| 251 | // The resident playlist. Created here rather than in the constructor | ||
| 252 | // because Playlist's own constructor reaches for Events, PluginManager and | ||
| 253 | // CommandManager, which are not yet built during static initialization. | ||
| 254 | // From this point on PlaylistSnapshot() never returns null: the resident | ||
| 255 | // instance is only ever replaced (SwitchToInsertedPlaylist, SetIdle's walk | ||
| 256 | // back up the parent chain), never cleared. | ||
| 257 |
1/2✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
|
2651 | std::shared_ptr<Playlist> pl = CreatePlaylist(nullptr); |
| 258 |
1/2✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
|
2651 | SetCurrentPlaylist(pl.get()); |
| 259 | 2651 | } | |
| 260 | |||
| 261 | 1488 | int Player::StartPlaylist(const std::string& name, const int repeat, | |
| 262 | const int startPosition, const int endPosition, const int manualPriority, | ||
| 263 | const bool allowScheduleOverride) { | ||
| 264 | { | ||
| 265 |
1/2✓ Branch 0 taken 1488 times.
✗ Branch 1 not taken.
|
1488 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 266 |
5/6✓ Branch 0 taken 1488 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49 times.
✓ Branch 3 taken 1439 times.
✓ Branch 4 taken 1441 times.
✓ Branch 5 taken 47 times.
|
1537 | if ((GetStatus() == FPP_STATUS_IDLE) || |
| 267 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 47 times.
|
49 | (name != playlistName)) { |
| 268 |
1/2✓ Branch 0 taken 1441 times.
✗ Branch 1 not taken.
|
1441 | playlistName = name; |
| 269 | 1441 | startTime = std::time(nullptr); | |
| 270 | 1441 | stopTime = 0; | |
| 271 | 1441 | origStopTime = 0; | |
| 272 | 1441 | stopMethod = 0; | |
| 273 | 1441 | priority = manualPriority; | |
| 274 | 1441 | this->allowScheduleOverride = allowScheduleOverride; | |
| 275 | } | ||
| 276 | |||
| 277 | 1488 | forceStopped = false; | |
| 278 |
1/2✓ Branch 0 taken 1488 times.
✗ Branch 1 not taken.
|
1488 | forceStoppedPlaylist = ""; |
| 279 | 1488 | } | |
| 280 | |||
| 281 |
1/2✓ Branch 0 taken 1488 times.
✗ Branch 1 not taken.
|
1488 | std::shared_ptr<Playlist> pl = PlaylistSnapshot(); |
| 282 |
5/6✓ Branch 0 taken 57 times.
✓ Branch 1 taken 1431 times.
✓ Branch 2 taken 284 times.
✓ Branch 3 taken 1204 times.
✓ Branch 4 taken 1488 times.
✗ Branch 5 not taken.
|
1488 | LogDebug(VB_PLAYLIST, "Manually starting %srepeating playlist '%s'\n", |
| 283 | (repeat == -1 ? pl->GetRepeat() : repeat) ? "" : "non-", | ||
| 284 | name.c_str()); | ||
| 285 | |||
| 286 |
1/2✓ Branch 0 taken 1488 times.
✗ Branch 1 not taken.
|
2976 | return pl->Play(name, startPosition, repeat, -1, endPosition); |
| 287 | 1488 | } | |
| 288 | |||
| 289 | 111 | int Player::StartScheduledPlaylist(const std::string& name, const int position, | |
| 290 | const int repeat, const int scheduleEntry, const int scheduledPriority, | ||
| 291 | const time_t sTime, const time_t eTime, const int method) { | ||
| 292 | { | ||
| 293 |
1/2✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
|
111 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 294 |
1/2✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
|
111 | playlistName = name; |
| 295 | 111 | origStartTime = sTime; | |
| 296 | 111 | origStopTime = eTime; | |
| 297 | 111 | startTime = std::time(nullptr); | |
| 298 | 111 | stopTime = eTime; | |
| 299 | 111 | stopMethod = method; | |
| 300 | 111 | priority = scheduledPriority; | |
| 301 | 111 | forceStopped = false; | |
| 302 |
1/2✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
|
111 | forceStoppedPlaylist = ""; |
| 303 | 111 | } | |
| 304 | |||
| 305 |
7/8✓ Branch 0 taken 26 times.
✓ Branch 1 taken 85 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 23 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 94 times.
✓ Branch 7 taken 17 times.
|
111 | LogDebug(VB_PLAYLIST, "Starting %srepeating playlist '%s' with scheduled '%s' in %d seconds\n", |
| 306 | repeat ? "" : "non-", | ||
| 307 | name.c_str(), | ||
| 308 | method == 0 ? "Graceful Stop" : method == 1 ? "Hard Stop" | ||
| 309 | : method == 2 ? "Graceful Stop After Loop" | ||
| 310 | : "", | ||
| 311 | (int)(eTime - std::time(nullptr))); | ||
| 312 | |||
| 313 |
2/4✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 111 times.
✗ Branch 3 not taken.
|
111 | return PlaylistSnapshot()->Play(name, position, repeat, scheduleEntry); |
| 314 | } | ||
| 315 | |||
| 316 | 9 | int Player::AdjustPlaylistStopTime(const int seconds) { | |
| 317 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if ((GetStatus() != FPP_STATUS_PLAYLIST_PLAYING) && |
| 318 |
2/8✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9 times.
|
9 | (GetStatus() != FPP_STATUS_STOPPING_GRACEFULLY) && |
| 319 | ✗ | (GetStatus() != FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP)) { | |
| 320 | ✗ | LogInfo(VB_SCHEDULE, "Tried to extend a running playlist, but there is no playlist running.\n"); | |
| 321 | ✗ | return 0; | |
| 322 | } | ||
| 323 | |||
| 324 |
2/4✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
|
9 | if (!WasScheduled()) { |
| 325 | ✗ | LogInfo(VB_SCHEDULE, "Tried to extend running playlist, but it was manually started.\n"); | |
| 326 | ✗ | return 0; | |
| 327 | } | ||
| 328 | |||
| 329 | // UI should catch this, but also check here | ||
| 330 |
2/4✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
|
9 | if ((seconds > (12 * 60 * 60)) || |
| 331 | (seconds < (-3 * 60 * 60))) { | ||
| 332 | ✗ | return 0; | |
| 333 | } | ||
| 334 | |||
| 335 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 336 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | if (seconds >= 0) { |
| 337 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | LogDebug(VB_PLAYLIST, "Extending scheduled playlist '%s' by %d seconds\n", |
| 338 | playlistName.c_str(), seconds); | ||
| 339 | } else { | ||
| 340 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | LogDebug(VB_PLAYLIST, "Shortening scheduled playlist '%s' by %d seconds\n", |
| 341 | playlistName.c_str(), seconds); | ||
| 342 | } | ||
| 343 | |||
| 344 | 9 | stopTime += seconds; | |
| 345 | |||
| 346 | char timeBuf[32]; | ||
| 347 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | LogDebug(VB_PLAYLIST, "New end time is now: %s", ctime_r(&stopTime, timeBuf)); |
| 348 | |||
| 349 | 9 | return 1; | |
| 350 | 9 | } | |
| 351 | |||
| 352 | 39 | void Player::InsertPlaylistAsNext(const std::string& filename, const int startPosition, const int endPos) { | |
| 353 |
2/4✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
|
39 | PlaylistSnapshot()->InsertPlaylistAsNext(filename, startPosition, endPos); |
| 354 | 39 | } | |
| 355 | |||
| 356 | 659 | void Player::InsertPlaylistImmediate(const std::string& filename, const int startPosition, const int endPos) { | |
| 357 |
2/4✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 659 times.
✗ Branch 3 not taken.
|
659 | PlaylistSnapshot()->InsertPlaylistImmediate(filename, startPosition, endPos); |
| 358 | 659 | } | |
| 359 | |||
| 360 | 1055 | void Player::RecordForceStop(int forceStop) { | |
| 361 |
1/2✓ Branch 0 taken 1055 times.
✗ Branch 1 not taken.
|
1055 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 362 | 1055 | forceStopped = (bool)forceStop; | |
| 363 |
2/2✓ Branch 0 taken 1042 times.
✓ Branch 1 taken 13 times.
|
1055 | if (forceStopped) |
| 364 |
1/2✓ Branch 0 taken 1042 times.
✗ Branch 1 not taken.
|
1042 | forceStoppedPlaylist = playlistName; |
| 365 | else | ||
| 366 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | forceStoppedPlaylist = ""; |
| 367 | 1055 | } | |
| 368 | |||
| 369 | 840 | int Player::StopNow(int forceStop) { | |
| 370 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 839 times.
|
840 | if (InHandedBackStoppedPreset()) { |
| 371 | 1 | LogInfo(VB_PLAYLIST, "Ignoring Stop Now from the PLAYLIST_STOPPED preset of an inserted playlist: it has already stopped, and the playlist it interrupted carries on\n"); | |
| 372 | 1 | return 1; | |
| 373 | } | ||
| 374 | 839 | RecordForceStop(forceStop); | |
| 375 |
2/4✓ Branch 0 taken 839 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 837 times.
✗ Branch 3 not taken.
|
839 | return PlaylistSnapshot()->StopNow(forceStop); |
| 376 | } | ||
| 377 | |||
| 378 | 18 | int Player::StopGracefully(int forceStop, int afterCurrentLoop) { | |
| 379 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (InHandedBackStoppedPreset()) { |
| 380 | ✗ | LogInfo(VB_PLAYLIST, "Ignoring Stop Gracefully from the PLAYLIST_STOPPED preset of an inserted playlist: it has already stopped, and the playlist it interrupted carries on\n"); | |
| 381 | ✗ | return 1; | |
| 382 | } | ||
| 383 | 18 | RecordForceStop(forceStop); | |
| 384 |
2/4✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
18 | return PlaylistSnapshot()->StopGracefully(forceStop, afterCurrentLoop); |
| 385 | } | ||
| 386 | |||
| 387 | 198 | void Player::StopNowAllLevels(int forceStop) { | |
| 388 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
|
198 | if (InHandedBackStoppedPreset()) { |
| 389 | ✗ | LogInfo(VB_PLAYLIST, "Ignoring Stop Now from the PLAYLIST_STOPPED preset of an inserted playlist: it has already stopped, and the playlist it interrupted carries on\n"); | |
| 390 | ✗ | return; | |
| 391 | } | ||
| 392 | 198 | RecordForceStop(forceStop); | |
| 393 | 198 | Playlist::StopNowAllLevels(forceStop); | |
| 394 | } | ||
| 395 | |||
| 396 | 5313 | std::time_t Player::GetOrigStartTime() { | |
| 397 |
1/2✓ Branch 0 taken 5313 times.
✗ Branch 1 not taken.
|
5313 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 398 | 5313 | return origStartTime; | |
| 399 | 5313 | } | |
| 400 | 3099 | std::time_t Player::GetOrigStopTime() { | |
| 401 |
1/2✓ Branch 0 taken 3099 times.
✗ Branch 1 not taken.
|
3099 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 402 | 3099 | return origStopTime; | |
| 403 | 3099 | } | |
| 404 | 3104 | std::time_t Player::GetStartTime() { | |
| 405 |
1/2✓ Branch 0 taken 3104 times.
✗ Branch 1 not taken.
|
3104 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 406 | 3104 | return startTime; | |
| 407 | 3104 | } | |
| 408 | 5283 | std::time_t Player::GetStopTime() { | |
| 409 |
1/2✓ Branch 0 taken 5283 times.
✗ Branch 1 not taken.
|
5283 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 410 | 5283 | return stopTime; | |
| 411 | 5283 | } | |
| 412 | 153 | void Player::ClearForceStopped() { | |
| 413 |
1/2✓ Branch 0 taken 153 times.
✗ Branch 1 not taken.
|
153 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 414 | 153 | forceStopped = false; | |
| 415 | 153 | } | |
| 416 | 1238 | bool Player::GetForceStopped() { | |
| 417 |
1/2✓ Branch 0 taken 1238 times.
✗ Branch 1 not taken.
|
1238 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 418 | 1238 | return forceStopped; | |
| 419 | 1238 | } | |
| 420 | 32 | std::string Player::GetForceStoppedPlaylist() { | |
| 421 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 422 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
64 | return forceStoppedPlaylist; |
| 423 | 32 | } | |
| 424 | 2338 | int Player::GetPriority() { | |
| 425 |
1/2✓ Branch 0 taken 2338 times.
✗ Branch 1 not taken.
|
2338 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 426 | 2338 | return priority; | |
| 427 | 2338 | } | |
| 428 | 20 | bool Player::GetAllowScheduleOverride() { | |
| 429 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 430 | 20 | return allowScheduleOverride; | |
| 431 | 20 | } | |
| 432 | |||
| 433 | 391469 | int Player::Process() { | |
| 434 | 391469 | std::time_t procTime = std::time(nullptr); | |
| 435 |
2/4✓ Branch 0 taken 391469 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 391469 times.
✗ Branch 3 not taken.
|
391469 | PlaylistStatus status = PlaylistSnapshot()->getPlaylistStatus(); |
| 436 | |||
| 437 | // See if we need to stop a scheduled playlist. A paused one counts: it | ||
| 438 | // used to be skipped, so a playlist paused during its window never | ||
| 439 | // stopped, and as the scheduler waits for idle, every later scheduled show | ||
| 440 | // was skipped too. | ||
| 441 | 391469 | bool check = false; | |
| 442 | 391469 | std::time_t stop = 0; | |
| 443 | 391469 | std::time_t origStop = 0; | |
| 444 | 391469 | int method = 0; | |
| 445 | 391469 | std::string name; | |
| 446 | { | ||
| 447 |
1/2✓ Branch 0 taken 391469 times.
✗ Branch 1 not taken.
|
391469 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 448 |
4/4✓ Branch 0 taken 8822 times.
✓ Branch 1 taken 382647 times.
✓ Branch 2 taken 3439 times.
✓ Branch 3 taken 5383 times.
|
391469 | if (((status == FPP_STATUS_PLAYLIST_PLAYING) || (status == FPP_STATUS_PLAYLIST_PAUSED)) && |
| 449 |
2/2✓ Branch 0 taken 39884 times.
✓ Branch 1 taken 346202 times.
|
386086 | (stopTime) && |
| 450 |
2/2✓ Branch 0 taken 433 times.
✓ Branch 1 taken 39451 times.
|
39884 | (lastCheckTime != procTime)) { |
| 451 | 433 | lastCheckTime = procTime; | |
| 452 | 433 | check = true; | |
| 453 | 433 | stop = stopTime; | |
| 454 | 433 | origStop = origStopTime; | |
| 455 | 433 | method = stopMethod; | |
| 456 |
1/2✓ Branch 0 taken 433 times.
✗ Branch 1 not taken.
|
433 | name = playlistName; |
| 457 | } | ||
| 458 | 391469 | } | |
| 459 | |||
| 460 |
2/2✓ Branch 0 taken 433 times.
✓ Branch 1 taken 391036 times.
|
391469 | if (check) { |
| 461 |
2/2✓ Branch 0 taken 420 times.
✓ Branch 1 taken 13 times.
|
433 | if (stop > procTime) { |
| 462 | 420 | bool logSwitch = false; | |
| 463 | 420 | int diff = stop - procTime; | |
| 464 | |||
| 465 | // Print the countdown more frequently as we get closer | ||
| 466 |
6/6✓ Branch 0 taken 177 times.
✓ Branch 1 taken 243 times.
✓ Branch 2 taken 174 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 237 times.
|
420 | if (((diff > 300) && ((diff % 300) == 0)) || |
| 467 |
6/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 174 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 293 times.
✓ Branch 5 taken 123 times.
|
417 | ((diff > 60) && (diff <= 300) && ((diff % 60) == 0)) || |
| 468 |
6/6✓ Branch 0 taken 114 times.
✓ Branch 1 taken 179 times.
✓ Branch 2 taken 108 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 123 times.
✓ Branch 5 taken 287 times.
|
416 | ((diff > 10) && (diff <= 60) && ((diff % 10) == 0)) || |
| 469 | ((diff <= 10))) { | ||
| 470 | 133 | logSwitch = true; | |
| 471 | } | ||
| 472 | |||
| 473 |
2/2✓ Branch 0 taken 133 times.
✓ Branch 1 taken 287 times.
|
420 | if (logSwitch) { |
| 474 |
8/10✓ Branch 0 taken 13 times.
✓ Branch 1 taken 120 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 43 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 78 times.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 133 times.
✗ Branch 9 not taken.
|
133 | LogDebug(VB_PLAYLIST, "Playlist '%s' will switch to '%s' in %d second%s\n", |
| 475 | name.c_str(), | ||
| 476 | method == 0 ? "Stopping Gracefully" : method == 1 ? "Hard Stop" | ||
| 477 | : method == 2 ? "Stopping Gracefully After Loop" | ||
| 478 | : "", | ||
| 479 | diff, | ||
| 480 | diff == 1 ? "" : "s"); | ||
| 481 | } | ||
| 482 | } | ||
| 483 | |||
| 484 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 420 times.
|
433 | if (stop <= procTime) { |
| 485 | // if user shortened the scheduled end time mark as force stopped | ||
| 486 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10 times.
|
13 | int forceStop = (stop < origStop) ? 1 : 0; |
| 487 | |||
| 488 | // A paused playlist just stops at the end of its window: a | ||
| 489 | // graceful stop would first resume it, bringing the show back on | ||
| 490 | // after its time to finish the interrupted entry. | ||
| 491 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 12 times.
|
13 | if (status == FPP_STATUS_PLAYLIST_PAUSED) |
| 492 | 1 | method = 1; | |
| 493 | |||
| 494 |
3/3✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
|
13 | switch (method) { |
| 495 | 3 | case 0: // Gracefully | |
| 496 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | StopGracefully(forceStop); |
| 497 | 3 | break; | |
| 498 | 1 | case 2: // After Loop | |
| 499 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | StopGracefully(forceStop, 1); |
| 500 | 1 | break; | |
| 501 | 9 | case 1: // Hard Stop | |
| 502 | default: | ||
| 503 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | StopNowAllLevels(forceStop); |
| 504 | 9 | break; | |
| 505 | } | ||
| 506 | } | ||
| 507 | } | ||
| 508 | |||
| 509 | // Deliberately a second snapshot rather than one hoisted to the top of the | ||
| 510 | // method: the stop handling above can legitimately change which playlist is | ||
| 511 | // current (a hard stop of an inserted playlist unwinds one level and hands | ||
| 512 | // the player back to the parent), and this tick must process whichever one | ||
| 513 | // is current now — which is what the raw global did. | ||
| 514 |
2/4✓ Branch 0 taken 391469 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 391469 times.
✗ Branch 3 not taken.
|
782938 | return PlaylistSnapshot()->Process(); |
| 515 | 391469 | } | |
| 516 | |||
| 517 | 14085 | void Player::ProcessMedia() { | |
| 518 |
2/4✓ Branch 0 taken 14085 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14085 times.
✗ Branch 3 not taken.
|
14085 | PlaylistSnapshot()->ProcessMedia(); |
| 519 | 14085 | } | |
| 520 | |||
| 521 | 1735523 | int Player::IsPlaying() { | |
| 522 |
2/4✓ Branch 0 taken 1735523 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1735523 times.
✗ Branch 3 not taken.
|
1735523 | return PlaylistSnapshot()->IsPlaying(); |
| 523 | } | ||
| 524 | |||
| 525 | 478939 | std::string Player::GetPlaylistName() { | |
| 526 |
2/4✓ Branch 0 taken 478939 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 478939 times.
✗ Branch 3 not taken.
|
478939 | return PlaylistSnapshot()->GetPlaylistName(); |
| 527 | } | ||
| 528 | |||
| 529 | 1670993 | PlaylistStatus Player::GetStatus() { | |
| 530 |
2/4✓ Branch 0 taken 1670993 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1670993 times.
✗ Branch 3 not taken.
|
1670993 | return PlaylistSnapshot()->getPlaylistStatus(); |
| 531 | } | ||
| 532 | |||
| 533 | 382665 | int Player::GetRepeat() { | |
| 534 |
1/2✓ Branch 0 taken 382665 times.
✗ Branch 1 not taken.
|
382665 | return PlaylistSnapshot()->GetRepeat(); |
| 535 | } | ||
| 536 | |||
| 537 | 3 | void Player::SetRepeat(int repeat) { | |
| 538 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | PlaylistSnapshot()->SetRepeat(repeat); |
| 539 | 3 | } | |
| 540 | |||
| 541 | 3099 | int Player::GetStopMethod() { | |
| 542 |
1/2✓ Branch 0 taken 3099 times.
✗ Branch 1 not taken.
|
3099 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 543 | 3099 | return stopMethod; | |
| 544 | 3099 | } | |
| 545 | |||
| 546 | 382654 | int Player::GetPosition() { | |
| 547 |
2/4✓ Branch 0 taken 382654 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 382654 times.
✗ Branch 3 not taken.
|
382654 | return PlaylistSnapshot()->GetPosition(); |
| 548 | } | ||
| 549 | |||
| 550 | 8 | int Player::GetResumePosition() { | |
| 551 |
2/4✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 | return PlaylistSnapshot()->GetResumePosition(); |
| 552 | } | ||
| 553 | |||
| 554 | 25 | Json::Value Player::GetInfo(void) { | |
| 555 |
2/4✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
|
25 | return PlaylistSnapshot()->GetInfo(); |
| 556 | } | ||
| 557 | |||
| 558 | 2720 | int Player::GetScheduleEntry() { | |
| 559 |
1/2✓ Branch 0 taken 2720 times.
✗ Branch 1 not taken.
|
2720 | return PlaylistSnapshot()->GetScheduleEntry(); |
| 560 | } | ||
| 561 | |||
| 562 | 5 | uint64_t Player::GetFileTime() { | |
| 563 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | return PlaylistSnapshot()->GetFileTime(); |
| 564 | } | ||
| 565 | |||
| 566 | 7 | Json::Value Player::GetConfig() { | |
| 567 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
7 | return PlaylistSnapshot()->GetConfig(); |
| 568 | } | ||
| 569 | |||
| 570 | 6 | Json::Value Player::GetMqttStatusJSON() { | |
| 571 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | return PlaylistSnapshot()->GetMqttStatusJSON(); |
| 572 | } | ||
| 573 | |||
| 574 | 570323 | int Player::WasScheduled() { | |
| 575 |
2/4✓ Branch 0 taken 570323 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 570323 times.
✗ Branch 3 not taken.
|
570323 | return PlaylistSnapshot()->WasScheduled(); |
| 576 | } | ||
| 577 | |||
| 578 | 9 | int Player::FindPosForMS(uint64_t& ms, bool itemDefinedOnly) { | |
| 579 |
2/4✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | return PlaylistSnapshot()->FindPosForMS(ms, itemDefinedOnly); |
| 580 | } | ||
| 581 | |||
| 582 | 17 | void Player::GetFilenamesForPos(int pos, std::string& seq, std::string& med) { | |
| 583 |
2/4✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
|
17 | PlaylistSnapshot()->GetFilenamesForPos(pos, seq, med); |
| 584 | 17 | } | |
| 585 | |||
| 586 | 11 | int Player::Load(const std::string filename) { | |
| 587 |
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.
|
33 | return PlaylistSnapshot()->Load(filename.c_str()); |
| 588 | } | ||
| 589 | |||
| 590 | ✗ | int Player::Start() { | |
| 591 | ✗ | return PlaylistSnapshot()->Start(); | |
| 592 | } | ||
| 593 | |||
| 594 | 8146 | void Player::RestartItem() { | |
| 595 |
2/4✓ Branch 0 taken 8146 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8146 times.
✗ Branch 3 not taken.
|
8146 | PlaylistSnapshot()->RestartItem(); |
| 596 | 8146 | } | |
| 597 | |||
| 598 | 8187 | void Player::NextItem() { | |
| 599 |
2/4✓ Branch 0 taken 8187 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8187 times.
✗ Branch 3 not taken.
|
8187 | PlaylistSnapshot()->NextItem(); |
| 600 | 8187 | } | |
| 601 | |||
| 602 | 8177 | void Player::PrevItem() { | |
| 603 |
2/4✓ Branch 0 taken 8177 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8177 times.
✗ Branch 3 not taken.
|
8177 | PlaylistSnapshot()->PrevItem(); |
| 604 | 8177 | } | |
| 605 | |||
| 606 | 19 | void Player::Pause() { | |
| 607 |
2/4✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
|
19 | PlaylistSnapshot()->Pause(); |
| 608 | 19 | } | |
| 609 | |||
| 610 | 16 | void Player::Resume() { | |
| 611 |
2/4✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 | PlaylistSnapshot()->Resume(); |
| 612 | 16 | } | |
| 613 | |||
| 614 | 906 | int Player::Cleanup(void) { | |
| 615 | // The main loop calls this after an unlocked "now idle" read. A start from | ||
| 616 | // another thread can land between that read and here, so only clean up a | ||
| 617 | // playlist that is still idle under its lock; SetIdle() has already run | ||
| 618 | // Cleanup() on every transition to idle. | ||
| 619 |
2/4✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 906 times.
✗ Branch 3 not taken.
|
906 | return PlaylistSnapshot()->CleanupIfIdle(); |
| 620 | } | ||
| 621 | |||
| 622 | 223040 | void Player::GetCurrentStatus(Json::Value& result) { | |
| 623 |
2/4✓ Branch 0 taken 223040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 223040 times.
✗ Branch 3 not taken.
|
223040 | PlaylistSnapshot()->GetCurrentStatus(result); |
| 624 | 223040 | } | |
| 625 | |||
| 626 | 19611 | Json::Value Player::GetStatusJSON() { | |
| 627 |
1/2✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
|
19611 | Json::Value result; |
| 628 |
1/2✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
|
19611 | Json::Value playlists(Json::arrayValue); |
| 629 |
1/2✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
|
19611 | Json::Value pl; |
| 630 | |||
| 631 | // One snapshot for the whole object: six separate loads could straddle a | ||
| 632 | // playlist switch and report a mix of two playlists in one status blob. | ||
| 633 |
1/2✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
|
19611 | std::shared_ptr<Playlist> cur = PlaylistSnapshot(); |
| 634 |
1/2✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
|
19611 | pl = cur->GetInfo(); |
| 635 |
2/4✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
|
19611 | pl["details"] = cur->GetConfig(); |
| 636 |
3/6✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19611 times.
✗ Branch 5 not taken.
|
19611 | pl["status"] = (int)cur->getPlaylistStatus(); |
| 637 |
3/6✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19611 times.
✗ Branch 5 not taken.
|
19611 | pl["scheduled"] = cur->WasScheduled() ? true : false; |
| 638 |
3/6✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19611 times.
✗ Branch 5 not taken.
|
19611 | pl["position"] = cur->GetPosition(); |
| 639 |
2/4✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
|
19611 | pl["lastModified"] = (Json::UInt64)cur->GetFileTime(); |
| 640 | |||
| 641 | // things we store locally that would need to be in an array if we can | ||
| 642 | // play multiple playlists concurrently | ||
| 643 |
1/2✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
|
19611 | std::lock_guard<std::mutex> lk(m_stateLock); |
| 644 |
2/4✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
|
19611 | pl["origStartTime"] = (Json::UInt64)origStartTime; |
| 645 |
2/4✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
|
19611 | pl["origStopTime"] = (Json::UInt64)origStopTime; |
| 646 |
2/4✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
|
19611 | pl["startTime"] = (Json::UInt64)startTime; |
| 647 |
2/4✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
|
19611 | pl["stopTime"] = (Json::UInt64)stopTime; |
| 648 |
2/4✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
|
19611 | pl["stopMethod"] = stopMethod; |
| 649 |
2/4✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
|
19611 | pl["priority"] = priority; |
| 650 | |||
| 651 |
1/2✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
|
19611 | playlists.append(pl); |
| 652 | |||
| 653 |
2/4✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
|
19611 | result["playlists"] = playlists; |
| 654 | |||
| 655 | 19611 | return result; | |
| 656 | 19611 | } | |
| 657 | |||
| 658 | // -------------------------------------------------------------------------- | ||
| 659 | // OpenAPI docs for the /player/* endpoints handled below. | ||
| 660 | // -------------------------------------------------------------------------- | ||
| 661 | |||
| 662 | /** | ||
| 663 | * Get the player status. Equivalent to /api/player/status. | ||
| 664 | * | ||
| 665 | * @route GET /api/player | ||
| 666 | * @response 200 Player status JSON. | ||
| 667 | */ | ||
| 668 | |||
| 669 | /** | ||
| 670 | * Get the player status (playlist, sequence, timing, mode, etc.). | ||
| 671 | * | ||
| 672 | * @route GET /api/player/status | ||
| 673 | * @response 200 Player status JSON. | ||
| 674 | */ | ||
| 675 | |||
| 676 | /** | ||
| 677 | * Get information about the currently playing playlist. | ||
| 678 | * | ||
| 679 | * @route GET /api/player/current | ||
| 680 | * @response 200 Object with a `playlist` member describing the current playlist. | ||
| 681 | */ | ||
| 682 | 32885 | HttpResponsePtr Player::render_GET(const HttpRequestPtr& req) { | |
| 683 |
2/4✓ Branch 0 taken 32885 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32885 times.
✗ Branch 3 not taken.
|
32885 | auto pieces = getPathPieces(req->path()); |
| 684 | 32885 | int plen = pieces.size(); | |
| 685 | |||
| 686 |
1/2✓ Branch 0 taken 32885 times.
✗ Branch 1 not taken.
|
32885 | Json::Value result; |
| 687 | |||
| 688 |
8/10✓ Branch 0 taken 32879 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 32879 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32879 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 19605 times.
✓ Branch 7 taken 13274 times.
✓ Branch 8 taken 19611 times.
✓ Branch 9 taken 13274 times.
|
32885 | if ((plen == 1) || ((plen == 2) && (pieces[1] == "status"))) { |
| 689 |
1/2✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
|
19611 | result = GetStatusJSON(); |
| 690 |
4/8✓ Branch 0 taken 19611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19611 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19611 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 19611 times.
✗ Branch 7 not taken.
|
78444 | return makeStringResponse(SaveJsonToString(result, " "), 200, "application/json"); |
| 691 |
6/8✓ Branch 0 taken 13274 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13274 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13273 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 13273 times.
✓ Branch 7 taken 1 times.
|
13274 | } else if ((plen == 2) && (pieces[1] == "current")) { |
| 692 |
1/2✓ Branch 0 taken 13273 times.
✗ Branch 1 not taken.
|
13273 | Json::Value result; |
| 693 |
1/2✓ Branch 0 taken 13273 times.
✗ Branch 1 not taken.
|
13273 | Json::Value pl; |
| 694 |
2/4✓ Branch 0 taken 13273 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13273 times.
✗ Branch 3 not taken.
|
13273 | pl = PlaylistSnapshot()->GetInfo(); |
| 695 |
2/4✓ Branch 0 taken 13273 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13273 times.
✗ Branch 3 not taken.
|
13273 | result["playlist"] = pl; |
| 696 |
4/8✓ Branch 0 taken 13273 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13273 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13273 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13273 times.
✗ Branch 7 not taken.
|
39819 | return makeStringResponse(SaveJsonToString(result, " "), 200, "application/json"); |
| 697 | 13273 | } | |
| 698 | |||
| 699 |
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.
|
4 | return makeStringResponse("Not Found", 404, "text/plain"); |
| 700 | 32885 | } | |
| 701 | |||
| 702 | ✗ | HttpResponsePtr Player::render_POST(const HttpRequestPtr& req) { | |
| 703 | ✗ | auto pieces = getPathPieces(req->path()); | |
| 704 | ✗ | int plen = pieces.size(); | |
| 705 | |||
| 706 | ✗ | return makeStringResponse("Not Found", 404, "text/plain"); | |
| 707 | ✗ | } | |
| 708 | |||
| 709 | ✗ | HttpResponsePtr Player::render_PUT(const HttpRequestPtr& req) { | |
| 710 | ✗ | auto pieces = getPathPieces(req->path()); | |
| 711 | ✗ | int plen = pieces.size(); | |
| 712 | |||
| 713 | ✗ | return makeStringResponse("Not Found", 404, "text/plain"); | |
| 714 | ✗ | } | |
| 715 |