| 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 | #ifndef PLATFORM_OSX | ||
| 16 | #include <asm-generic/hugetlb_encode.h> | ||
| 17 | #endif | ||
| 18 | #include <sys/mman.h> | ||
| 19 | |||
| 20 | #include <algorithm> | ||
| 21 | #include <atomic> | ||
| 22 | #include <chrono> | ||
| 23 | #include <cstdint> | ||
| 24 | #include <list> | ||
| 25 | #include <map> | ||
| 26 | #include <mutex> | ||
| 27 | #include <set> | ||
| 28 | #include <stdio.h> | ||
| 29 | #include <stdlib.h> | ||
| 30 | #include <string.h> | ||
| 31 | #include <string> | ||
| 32 | #include <thread> | ||
| 33 | #include <utility> | ||
| 34 | #include <vector> | ||
| 35 | |||
| 36 | #include "MultiSync.h" | ||
| 37 | #include "Player.h" | ||
| 38 | #include "Timers.h" | ||
| 39 | #include "Plugins.h" | ||
| 40 | #include "Warnings.h" | ||
| 41 | #include "common.h" | ||
| 42 | #include "effects.h" | ||
| 43 | #include "log.h" | ||
| 44 | #include "settings.h" | ||
| 45 | #include "channeloutput/ChannelOutputSetup.h" | ||
| 46 | #include "channeloutput/channeloutputthread.h" | ||
| 47 | #include "channeltester/ChannelTester.h" | ||
| 48 | #include "commands/Commands.h" | ||
| 49 | #include "mediaoutput/GStreamerOut.h" | ||
| 50 | #include "overlays/PixelOverlay.h" | ||
| 51 | #include "playlist/Playlist.h" | ||
| 52 | |||
| 53 | #include "Sequence.h" | ||
| 54 | |||
| 55 | using namespace std::literals; | ||
| 56 | using namespace std::chrono_literals; | ||
| 57 | using namespace std::literals::chrono_literals; | ||
| 58 | |||
| 59 | #define SEQUENCE_CACHE_FRAMECOUNT 40 | ||
| 60 | |||
| 61 | Sequence* sequence = NULL; | ||
| 62 | // The pause and single-step flags are set by commands on the main loop and | ||
| 63 | // read by the output thread. atomic_ref rather than atomic members: this | ||
| 64 | // class's layout is compiled into plugins (see Sequence.h). | ||
| 65 | 110890 | static std::atomic_ref<int> seqFlag(int& flag) { | |
| 66 | 110890 | return std::atomic_ref<int>(flag); | |
| 67 | } | ||
| 68 | |||
| 69 | 2652 | Sequence::Sequence() : | |
| 70 | 2652 | m_seqMSDuration(0), | |
| 71 | 2652 | m_seqMSElapsed(0), | |
| 72 | 2652 | m_seqMSRemaining(0), | |
| 73 | 2652 | m_seqFile(nullptr), | |
| 74 | 2652 | m_seqStarting(0), | |
| 75 | 2652 | m_seqPaused(0), | |
| 76 | 2652 | m_seqStepTime(50), | |
| 77 | 2652 | m_seqSingleStep(0), | |
| 78 | 2652 | m_seqSingleStepBack(0), | |
| 79 | 2652 | m_seqRefreshRate(20), | |
| 80 | 2652 | m_remoteBlankCount(0), | |
| 81 | 2652 | m_numSeek(0), | |
| 82 | 2652 | m_readThread(nullptr), | |
| 83 | 2652 | m_lastFrameRead(-1), | |
| 84 | 2652 | m_doneRead(false), | |
| 85 | 2652 | m_shuttingDown(false), | |
| 86 | 2652 | m_lastFrameData(nullptr), | |
| 87 | 2652 | m_dataProcessed(false), | |
| 88 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | m_seqFilename(""), |
| 89 | // Allocated here, not on the first bridged packet: the receive thread | ||
| 90 | // allocating it while the output thread tested the pointer was a race. | ||
| 91 | // calloc'd pages cost nothing until something is written to them. | ||
| 92 | 2652 | m_bridgeData((uint8_t*)calloc(1, FPPD_MAX_CHANNEL_NUM)), | |
| 93 | 13260 | m_seqData(nullptr) { | |
| 94 | #ifndef PLATFORM_OSX | ||
| 95 | 2652 | m_seqData = (char*)mmap(NULL, FPPD_MAX_CHANNEL_NUM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | HUGETLB_FLAG_ENCODE_2MB, -1, 0); | |
| 96 | #endif | ||
| 97 |
3/4✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2536 times.
✓ Branch 3 taken 116 times.
|
2652 | if (m_seqData == nullptr || m_seqData == MAP_FAILED) { |
| 98 | 2536 | m_seqData = (char*)mmap(NULL, FPPD_MAX_CHANNEL_NUM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
| 99 |
1/2✓ Branch 0 taken 2536 times.
✗ Branch 1 not taken.
|
2536 | LogDebug(VB_SEQUENCE, "Not using Huge Pages for Sequence Data %p\n", m_seqData); |
| 100 | } else { | ||
| 101 |
1/2✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
|
116 | LogDebug(VB_SEQUENCE, "Using Huge Pages for Sequence Data %p\n", m_seqData); |
| 102 | } | ||
| 103 | 2652 | memset(m_seqData, 0, FPPD_MAX_CHANNEL_NUM); | |
| 104 |
2/2✓ Branch 0 taken 10608 times.
✓ Branch 1 taken 2652 times.
|
13260 | for (int x = 0; x < 4; x++) { |
| 105 | 10608 | m_seqData[FPPD_OFF_CHANNEL + x] = 0; | |
| 106 | 10608 | m_seqData[FPPD_WHITE_CHANNEL] = 0xFF; | |
| 107 | } | ||
| 108 | |||
| 109 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | m_blankBetweenSequences = getSettingInt("blankBetweenSequences"); |
| 110 |
2/4✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
|
2652 | setBridgePrioritySetting(getSetting("bridgeDataPriority", "Warn If Sequence Running")); |
| 111 | |||
| 112 |
3/6✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
|
10903 | registerSettingsListener("sequence", "blankBetweenSequences", |
| 113 | 2947 | [this](const std::string& value) { | |
| 114 | 1 | m_blankBetweenSequences = getSettingInt("blankBetweenSequences"); | |
| 115 | 1 | }); | |
| 116 |
3/6✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
|
10608 | registerSettingsListener("sequence", "bridgeDataPriority", |
| 117 | 2947 | [this](const std::string& value) { | |
| 118 | 1 | setBridgePrioritySetting(value); | |
| 119 | 1 | }); | |
| 120 | 2652 | } | |
| 121 | |||
| 122 | 2620 | Sequence::~Sequence() { | |
| 123 | 2620 | m_shuttingDown = true; | |
| 124 | 2620 | frameLoadSignal.notify_all(); | |
| 125 |
2/2✓ Branch 0 taken 448 times.
✓ Branch 1 taken 2172 times.
|
2620 | if (m_readThread) { |
| 126 | 448 | m_readThread->join(); | |
| 127 |
1/2✓ Branch 0 taken 448 times.
✗ Branch 1 not taken.
|
448 | delete m_readThread; |
| 128 | } | ||
| 129 | 2620 | SetLastFrameData(nullptr); | |
| 130 | 2620 | clearCaches(); | |
| 131 | 2620 | setSeqFile(nullptr); | |
| 132 |
1/2✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
|
2620 | if (m_bridgeData) { |
| 133 | 2620 | free(m_bridgeData); | |
| 134 | } | ||
| 135 | 2620 | munmap(m_seqData, FPPD_MAX_CHANNEL_NUM); // the size mmap()ed in the constructor | |
| 136 | 2620 | } | |
| 137 | |||
| 138 | 2653 | void Sequence::setBridgePrioritySetting(const std::string& value) { | |
| 139 | 2653 | m_prioritize_sequence_over_bridge = false; | |
| 140 | 2653 | m_warn_if_bridging = false; | |
| 141 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2652 times.
|
2653 | if (value == "Prioritize Sequence") { |
| 142 | 1 | m_prioritize_sequence_over_bridge = true; | |
| 143 |
2/2✓ Branch 0 taken 2650 times.
✓ Branch 1 taken 2 times.
|
2652 | } else if (value == "Warn If Sequence Running") { |
| 144 | 2650 | m_prioritize_sequence_over_bridge = true; | |
| 145 | 2650 | m_warn_if_bridging = true; | |
| 146 | } | ||
| 147 | 2653 | } | |
| 148 | |||
| 149 | 6669 | void Sequence::clearCaches() { | |
| 150 |
2/2✓ Branch 0 taken 14897 times.
✓ Branch 1 taken 6669 times.
|
21566 | while (!frameCache.empty()) { |
| 151 |
1/2✓ Branch 0 taken 14897 times.
✗ Branch 1 not taken.
|
14897 | if (frameCache.front() != m_lastFrameData) |
| 152 |
1/2✓ Branch 0 taken 14897 times.
✗ Branch 1 not taken.
|
14897 | delete frameCache.front(); |
| 153 | 14897 | frameCache.pop_front(); | |
| 154 | } | ||
| 155 |
2/2✓ Branch 0 taken 13955 times.
✓ Branch 1 taken 6669 times.
|
20624 | while (!pastFrameCache.empty()) { |
| 156 |
2/2✓ Branch 0 taken 12417 times.
✓ Branch 1 taken 1538 times.
|
13955 | if (pastFrameCache.front() != m_lastFrameData) |
| 157 |
1/2✓ Branch 0 taken 12417 times.
✗ Branch 1 not taken.
|
12417 | delete pastFrameCache.front(); |
| 158 | 13955 | pastFrameCache.pop_front(); | |
| 159 | } | ||
| 160 | 6669 | } | |
| 161 | |||
| 162 | 187264 | void Sequence::SetLastFrameData(FSEQFile::FrameData* data) { | |
| 163 |
2/2✓ Branch 0 taken 100001 times.
✓ Branch 1 taken 87263 times.
|
187264 | if (m_lastFrameData == data) |
| 164 | 100001 | return; | |
| 165 | |||
| 166 |
2/2✓ Branch 0 taken 86394 times.
✓ Branch 1 taken 869 times.
|
87263 | if (m_lastFrameData) { |
| 167 | 86394 | bool found = false; | |
| 168 |
2/2✓ Branch 0 taken 1639405 times.
✓ Branch 1 taken 86394 times.
|
1725799 | for (auto const& i : pastFrameCache) { |
| 169 |
2/2✓ Branch 0 taken 84824 times.
✓ Branch 1 taken 1554581 times.
|
1639405 | if (i == m_lastFrameData) |
| 170 | 84824 | found = true; | |
| 171 | } | ||
| 172 | |||
| 173 |
2/2✓ Branch 0 taken 1570 times.
✓ Branch 1 taken 84824 times.
|
86394 | if (!found) { |
| 174 |
2/2✓ Branch 0 taken 593 times.
✓ Branch 1 taken 1570 times.
|
2163 | for (auto const& i : frameCache) { |
| 175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 593 times.
|
593 | if (i == m_lastFrameData) |
| 176 | ✗ | found = true; | |
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 |
2/2✓ Branch 0 taken 1570 times.
✓ Branch 1 taken 84824 times.
|
86394 | if (!found) |
| 181 |
1/2✓ Branch 0 taken 1570 times.
✗ Branch 1 not taken.
|
1570 | delete m_lastFrameData; |
| 182 | } | ||
| 183 | |||
| 184 | 87263 | m_lastFrameData = data; | |
| 185 |
2/2✓ Branch 0 taken 86396 times.
✓ Branch 1 taken 867 times.
|
87263 | m_lastFrameNumber = data ? (int64_t)data->frame : -1; |
| 186 | } | ||
| 187 | |||
| 188 | /* | ||
| 189 | * | ||
| 190 | */ | ||
| 191 | |||
| 192 | 450 | void ReadSequenceDataThread(Sequence* sequence) { | |
| 193 | 450 | sequence->ReadFramesLoop(); | |
| 194 | 448 | } | |
| 195 | 450 | void Sequence::ReadFramesLoop() { | |
| 196 |
2/4✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 450 times.
✗ Branch 3 not taken.
|
450 | SetThreadName("FPP-ReadFrames"); |
| 197 |
1/2✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
|
450 | std::unique_lock<std::mutex> lock(frameCacheLock); |
| 198 | while (true) { | ||
| 199 |
2/2✓ Branch 0 taken 448 times.
✓ Branch 1 taken 278835 times.
|
279283 | if (m_shuttingDown) { |
| 200 | 448 | return; | |
| 201 | } | ||
| 202 | 278835 | int cacheSize = frameCache.size(); | |
| 203 |
1/2✓ Branch 0 taken 278835 times.
✗ Branch 1 not taken.
|
278835 | std::shared_ptr<FSEQFile> seqFilePtr = m_seqFile.load(); |
| 204 |
10/10✓ Branch 0 taken 149606 times.
✓ Branch 1 taken 129229 times.
✓ Branch 2 taken 148940 times.
✓ Branch 3 taken 666 times.
✓ Branch 4 taken 128303 times.
✓ Branch 5 taken 20637 times.
✓ Branch 6 taken 103168 times.
✓ Branch 7 taken 25135 times.
✓ Branch 8 taken 103168 times.
✓ Branch 9 taken 175667 times.
|
278835 | if (frameCache.size() < SEQUENCE_CACHE_FRAMECOUNT && m_seqStarting < 2 && seqFilePtr && !m_doneRead) { |
| 205 | 103168 | uint32_t frame = (m_lastFrameRead + 1); | |
| 206 |
2/2✓ Branch 0 taken 101833 times.
✓ Branch 1 taken 1335 times.
|
103168 | if (frame < seqFilePtr->getNumFrames()) { |
| 207 |
1/2✓ Branch 0 taken 101833 times.
✗ Branch 1 not taken.
|
101833 | lock.unlock(); |
| 208 | |||
| 209 |
1/2✓ Branch 0 taken 101833 times.
✗ Branch 1 not taken.
|
101833 | long long start = GetTimeMS(); |
| 210 |
1/2✓ Branch 0 taken 101833 times.
✗ Branch 1 not taken.
|
101833 | std::unique_lock<std::mutex> readlock(readFileLock); |
| 211 |
1/2✓ Branch 0 taken 101833 times.
✗ Branch 1 not taken.
|
101833 | long long lockt = GetTimeMS(); |
| 212 |
1/2✓ Branch 0 taken 101833 times.
✗ Branch 1 not taken.
|
101833 | std::shared_ptr<FSEQFile> file = m_seqFile.load(); |
| 213 | 101833 | FSEQFile::FrameData* fd = nullptr; | |
| 214 |
5/6✓ Branch 0 taken 101826 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 101826 times.
✓ Branch 4 taken 101826 times.
✓ Branch 5 taken 7 times.
|
101833 | if (m_doneRead || file == nullptr) { |
| 215 | // memset(fd->data, 0, maxChanToRead); | ||
| 216 | } else { | ||
| 217 |
1/2✓ Branch 0 taken 101826 times.
✗ Branch 1 not taken.
|
101826 | fd = file->getFrame(frame); |
| 218 | } | ||
| 219 |
1/2✓ Branch 0 taken 101833 times.
✗ Branch 1 not taken.
|
101833 | long long unlock = GetTimeMS(); |
| 220 |
1/2✓ Branch 0 taken 101833 times.
✗ Branch 1 not taken.
|
101833 | readlock.unlock(); |
| 221 |
1/2✓ Branch 0 taken 101833 times.
✗ Branch 1 not taken.
|
101833 | long long end = GetTimeMS(); |
| 222 | 101833 | long long total = end - start; | |
| 223 |
4/4✓ Branch 0 taken 101832 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 101825 times.
|
101833 | if (total > 20 || fd == nullptr) { |
| 224 | 8 | uint32_t lfr = m_lastFrameRead; | |
| 225 | 8 | int lt = lockt - start; | |
| 226 | 8 | int ul = end - unlock; | |
| 227 | 8 | int gf = unlock - lockt; | |
| 228 | |||
| 229 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | LogDebug(VB_SEQUENCE, "Problem reading frame %d: %X Time: %d ms Last: %d Lock: %d GetFrame: %d Unlock: %d\n", |
| 230 | frame, fd, ((int)total), lfr, lt, gf, ul); | ||
| 231 | } | ||
| 232 | |||
| 233 |
1/2✓ Branch 0 taken 101833 times.
✗ Branch 1 not taken.
|
101833 | lock.lock(); |
| 234 |
2/2✓ Branch 0 taken 101826 times.
✓ Branch 1 taken 7 times.
|
101833 | if (fd) { |
| 235 |
2/2✓ Branch 0 taken 101800 times.
✓ Branch 1 taken 26 times.
|
101826 | if (m_lastFrameRead == (frame - 1)) { |
| 236 | 101800 | m_lastFrameRead = frame; | |
| 237 |
1/2✓ Branch 0 taken 101800 times.
✗ Branch 1 not taken.
|
101800 | frameCache.push_back(fd); |
| 238 | |||
| 239 |
1/2✓ Branch 0 taken 101800 times.
✗ Branch 1 not taken.
|
101800 | lock.unlock(); |
| 240 | 101800 | frameLoadedSignal.notify_all(); | |
| 241 |
2/4✓ Branch 0 taken 101800 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101800 times.
✗ Branch 3 not taken.
|
101800 | std::this_thread::sleep_for(1ms); |
| 242 |
1/2✓ Branch 0 taken 101800 times.
✗ Branch 1 not taken.
|
101800 | lock.lock(); |
| 243 | } else { | ||
| 244 | // a skip is in progress, we don't need this frame anymore | ||
| 245 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | delete fd; |
| 246 | } | ||
| 247 | } | ||
| 248 | 101833 | } else { | |
| 249 | 1335 | m_doneRead = true; | |
| 250 |
1/2✓ Branch 0 taken 1335 times.
✗ Branch 1 not taken.
|
1335 | lock.unlock(); |
| 251 | 1335 | frameLoadedSignal.notify_all(); | |
| 252 |
2/4✓ Branch 0 taken 1335 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1335 times.
✗ Branch 3 not taken.
|
1335 | std::this_thread::sleep_for(1ms); |
| 253 |
1/2✓ Branch 0 taken 1335 times.
✗ Branch 1 not taken.
|
1335 | lock.lock(); |
| 254 | } | ||
| 255 | } else { | ||
| 256 |
2/4✓ Branch 0 taken 175667 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 175665 times.
✗ Branch 3 not taken.
|
175667 | frameLoadSignal.wait_for(lock, 25ms); |
| 257 | } | ||
| 258 | 557666 | } | |
| 259 | 448 | } | |
| 260 | |||
| 261 | 3985 | inline void checkForReplacementFile(const std::string &fname) { | |
| 262 |
1/2✓ Branch 0 taken 3985 times.
✗ Branch 1 not taken.
|
3985 | std::string replaceFileName = fname + ".replace"; |
| 263 |
2/4✓ Branch 0 taken 3985 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3985 times.
|
3985 | if (FileExists(replaceFileName)) { |
| 264 | ✗ | unlink(fname.c_str()); | |
| 265 | ✗ | rename(replaceFileName.c_str(), fname.c_str()); | |
| 266 | } | ||
| 267 | 3985 | } | |
| 268 | |||
| 269 | // Warning ID / lifetime for "sequence file does not exist". The warning is | ||
| 270 | // re-armed on every sync packet for the missing file, so this is the grace | ||
| 271 | // period after the player goes quiet (or after it sends a stop, which closes | ||
| 272 | // the sequence and clears the warning outright), not the total display time. | ||
| 273 | static constexpr int MISSING_SEQUENCE_WARNING_ID = 25; | ||
| 274 | static constexpr int MISSING_SEQUENCE_WARNING_TIMEOUT = 30; | ||
| 275 | |||
| 276 | // Sequence names already reported missing or invalid, so a playlist that keeps | ||
| 277 | // coming round to them (or a master that keeps naming one in sync packets) | ||
| 278 | // logs each once instead of every time: a repeating playlist of missing | ||
| 279 | // sequences wrote some 150 KB of log every 5 s. A name leaves the set when | ||
| 280 | // it opens. File-static (guarded by m_sequenceLock) because Sequence is | ||
| 281 | // plugin-visible. | ||
| 282 | static std::set<std::string> reportedMissingSequences; | ||
| 283 | |||
| 284 | 752 | static bool FirstReportOfMissing(const std::string& name) { | |
| 285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 752 times.
|
752 | if (reportedMissingSequences.size() > 256) { |
| 286 | ✗ | reportedMissingSequences.clear(); | |
| 287 | } | ||
| 288 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
752 | return reportedMissingSequences.insert(name).second; |
| 289 | } | ||
| 290 | |||
| 291 | 763 | void Sequence::SetMissingSequenceWarning(const std::string& filename, const std::string& warning) { | |
| 292 | 763 | ClearMissingSequenceWarning(); | |
| 293 | 763 | m_missingSeqFilename = filename; | |
| 294 | 763 | m_missingSeqWarning = warning; | |
| 295 |
2/4✓ Branch 0 taken 763 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 763 times.
✗ Branch 3 not taken.
|
763 | WarningHolder::AddWarningTimeout(MISSING_SEQUENCE_WARNING_TIMEOUT, MISSING_SEQUENCE_WARNING_ID, warning); |
| 296 | 763 | } | |
| 297 | |||
| 298 | 165 | void Sequence::RefreshMissingSequenceWarning() { | |
| 299 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 165 times.
|
165 | if (m_missingSeqWarning.empty()) { |
| 300 | ✗ | return; | |
| 301 | } | ||
| 302 | // AddWarningTimeout only ever pushes an existing warning's timeout later, | ||
| 303 | // so this keeps it up for as long as the sync packets keep arriving. | ||
| 304 |
2/4✓ Branch 0 taken 165 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 165 times.
✗ Branch 3 not taken.
|
330 | WarningHolder::AddWarningTimeout(MISSING_SEQUENCE_WARNING_TIMEOUT, MISSING_SEQUENCE_WARNING_ID, m_missingSeqWarning); |
| 305 | } | ||
| 306 | |||
| 307 | 4112 | void Sequence::ClearMissingSequenceWarning() { | |
| 308 |
2/2✓ Branch 0 taken 3355 times.
✓ Branch 1 taken 757 times.
|
4112 | if (m_missingSeqWarning.empty()) { |
| 309 | 3355 | return; | |
| 310 | } | ||
| 311 |
2/4✓ Branch 0 taken 757 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 757 times.
✗ Branch 3 not taken.
|
757 | WarningHolder::RemoveWarning(MISSING_SEQUENCE_WARNING_ID, m_missingSeqWarning); |
| 312 | 757 | m_missingSeqWarning.clear(); | |
| 313 | 757 | m_missingSeqFilename.clear(); | |
| 314 | } | ||
| 315 | |||
| 316 | 2511 | int Sequence::OpenSequenceFile(const std::string& filename, int startFrame, int startSecond) { | |
| 317 |
1/2✓ Branch 0 taken 2511 times.
✗ Branch 1 not taken.
|
2511 | LogDebug(VB_SEQUENCE, "OpenSequenceFile(%s, %d, %d)\n", filename.c_str(), startFrame, startSecond); |
| 318 | |||
| 319 |
2/4✓ Branch 0 taken 2511 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2511 times.
|
2511 | if (filename == "") { |
| 320 | ✗ | LogErr(VB_SEQUENCE, "Empty Sequence Filename!\n", filename.c_str()); | |
| 321 | ✗ | return 0; | |
| 322 | } | ||
| 323 | |||
| 324 | // Sequence names are flat files inside the sequences directory -- they | ||
| 325 | // arrive from playlists, play commands, and multisync sync packets, so a | ||
| 326 | // rogue remote or crafted playlist must not escape via ../ (which would | ||
| 327 | // reach checkForReplacementFile()'s unlink/rename below), pick absolute | ||
| 328 | // paths, or smuggle NULs past the c_str() calls. Reject up front, before | ||
| 329 | // any teardown, the same way empty names are rejected. | ||
| 330 |
2/2✓ Branch 0 taken 2447 times.
✓ Branch 1 taken 60 times.
|
5018 | if (filename.find_first_of("/\\") != std::string::npos || |
| 331 |
5/6✓ Branch 0 taken 2507 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2447 times.
✓ Branch 4 taken 64 times.
✓ Branch 5 taken 2447 times.
|
5018 | filename.find("..") != std::string::npos || |
| 332 | 2447 | filename.find('\0') != std::string::npos) { | |
| 333 | // The missing-sequence warning state is guarded by m_sequenceLock. | ||
| 334 | // Leave m_seqStarting alone: a sequence that is open but not yet | ||
| 335 | // started must not be flipped to "running" by a rejected request. | ||
| 336 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 337 |
3/4✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 59 times.
|
64 | if (FirstReportOfMissing(filename)) { |
| 338 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | LogErr(VB_SEQUENCE, "Invalid Sequence Filename '%s'\n", filename.c_str()); |
| 339 | } else { | ||
| 340 |
1/2✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
|
59 | LogDebug(VB_SEQUENCE, "Invalid Sequence Filename '%s'\n", filename.c_str()); |
| 341 | } | ||
| 342 |
3/6✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
|
64 | SetMissingSequenceWarning(filename, "Invalid sequence filename " + filename + "\n"); |
| 343 | 64 | return 0; | |
| 344 | 64 | } | |
| 345 | |||
| 346 | 2447 | size_t bytesRead = 0; | |
| 347 |
1/2✓ Branch 0 taken 2447 times.
✗ Branch 1 not taken.
|
2447 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 348 | // Only opening the same file again forgets that it ended or was stopped: | ||
| 349 | // the master opens the next item right after stopping this one, and a sync | ||
| 350 | // packet for this one still in flight must not find the record gone. | ||
| 351 |
2/2✓ Branch 0 taken 966 times.
✓ Branch 1 taken 1481 times.
|
2447 | if (m_endedSeqFilename == filename) { |
| 352 | 966 | m_endedSeqFilename.clear(); | |
| 353 | } | ||
| 354 | 2447 | const uint64_t openGeneration = ++m_openGeneration; | |
| 355 | // A pending frame skip counts from the old file's position (see | ||
| 356 | // SkipFrames()). | ||
| 357 |
1/2✓ Branch 0 taken 2447 times.
✗ Branch 1 not taken.
|
2447 | CancelFrameSkip(); |
| 358 | |||
| 359 |
3/4✓ Branch 0 taken 2447 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 2439 times.
|
2447 | if (m_seqFile.load()) { |
| 360 |
6/6✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7 times.
|
8 | if (m_seqFilename == filename && m_seqStarting) { |
| 361 | // same filename AND we haven't started yet, we can continue | ||
| 362 | 1 | return 1; | |
| 363 | } | ||
| 364 | } | ||
| 365 | |||
| 366 |
3/4✓ Branch 0 taken 2446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 2440 times.
|
2446 | if (IsSequenceRunning()) |
| 367 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | CloseSequenceFile(); |
| 368 | |||
| 369 | // Tear down any existing m_seqFile. m_seqFile is an atomic<shared_ptr<FSEQFile>>, so | ||
| 370 | // resetting it here cannot free the file out from under an in-flight getFrame() in the | ||
| 371 | // ReadFramesLoop thread: that thread holds its own shared_ptr copy and the FSEQFile is | ||
| 372 | // only destroyed once the last holder releases it. | ||
| 373 |
1/2✓ Branch 0 taken 2446 times.
✗ Branch 1 not taken.
|
2446 | std::unique_lock<std::mutex> readLock(readFileLock); |
| 374 |
1/2✓ Branch 0 taken 2446 times.
✗ Branch 1 not taken.
|
2446 | std::unique_lock<std::mutex> lock(frameCacheLock); |
| 375 |
3/4✓ Branch 0 taken 2446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2445 times.
|
2446 | if (std::shared_ptr<FSEQFile> old = m_seqFile.load()) { |
| 376 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::string fn = old->getFilename(); |
| 377 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | setSeqFile(nullptr); |
| 378 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ForgetTriggers(); |
| 379 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | checkForReplacementFile(fn); |
| 380 | 2447 | } | |
| 381 | |||
| 382 | 2446 | m_seqStarting = 2; | |
| 383 | 2446 | m_doneRead = false; | |
| 384 | 2446 | m_lastFrameRead = -1; | |
| 385 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2436 times.
|
2446 | if (startFrame) { |
| 386 | 10 | m_lastFrameRead = startFrame - 1; | |
| 387 | } | ||
| 388 |
1/2✓ Branch 0 taken 2446 times.
✗ Branch 1 not taken.
|
2446 | clearCaches(); |
| 389 |
1/2✓ Branch 0 taken 2446 times.
✗ Branch 1 not taken.
|
2446 | lock.unlock(); |
| 390 |
1/2✓ Branch 0 taken 2446 times.
✗ Branch 1 not taken.
|
2446 | readLock.unlock(); |
| 391 | |||
| 392 | 2446 | seqFlag(m_seqPaused).store(0); | |
| 393 | 2446 | m_seqMSDuration = 0; | |
| 394 | 2446 | m_seqMSElapsed = 0; | |
| 395 | 2446 | m_seqMSRemaining = 0; | |
| 396 |
1/2✓ Branch 0 taken 2446 times.
✗ Branch 1 not taken.
|
2446 | SetChannelOutputFrameNumber(m_lastFrameRead + 1); |
| 397 |
2/2✓ Branch 0 taken 451 times.
✓ Branch 1 taken 1995 times.
|
2446 | if (m_readThread == nullptr) { |
| 398 | // Started by the first open fppd makes, which can come long after | ||
| 399 | // start: on a remote, the first sync packet. A process already out of | ||
| 400 | // threads or (32 bit) address space by then - dozens of FSEQ effects | ||
| 401 | // running - makes the constructor throw; fail this open, as a missing | ||
| 402 | // file does, rather than abort, and let the next open try again. | ||
| 403 | try { | ||
| 404 |
5/8✓ Branch 0 taken 451 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 450 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 450 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
451 | m_readThread = new std::thread(ReadSequenceDataThread, this); |
| 405 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } catch (const std::system_error& e) { |
| 406 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogErr(VB_SEQUENCE, "Could not start the sequence read thread (%s), not opening %s\n", e.what(), filename.c_str()); |
| 407 | 1 | m_readThread = nullptr; | |
| 408 | 1 | m_seqStarting = 0; | |
| 409 | 1 | return 0; | |
| 410 | 1 | } | |
| 411 | } | ||
| 412 | |||
| 413 | { | ||
| 414 |
1/2✓ Branch 0 taken 2445 times.
✗ Branch 1 not taken.
|
2445 | std::unique_lock<std::mutex> nameLock(m_seqFilenameLock); |
| 415 |
1/2✓ Branch 0 taken 2445 times.
✗ Branch 1 not taken.
|
2445 | m_seqFilename = filename; |
| 416 | 2445 | } | |
| 417 |
1/2✓ Branch 0 taken 2445 times.
✗ Branch 1 not taken.
|
2445 | m_seqSyncName = filename; |
| 418 | |||
| 419 | char tmpFilename[2048]; | ||
| 420 | unsigned char tmpData[2048]; | ||
| 421 |
4/8✓ Branch 0 taken 2445 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2445 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2445 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2445 times.
✗ Branch 7 not taken.
|
2445 | std::string fullPath = FPP_DIR_SEQUENCE("/" + filename); |
| 422 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2444 times.
|
2445 | if (fullPath.size() >= sizeof(tmpFilename)) { |
| 423 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogErr(VB_SEQUENCE, "Sequence Filename too long (%u chars)\n", (unsigned)fullPath.size()); |
| 424 |
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 | SetMissingSequenceWarning(filename, "Invalid sequence filename " + filename + "\n"); |
| 425 | 1 | m_seqStarting = 0; | |
| 426 | 1 | return 0; | |
| 427 | } | ||
| 428 | 2444 | memcpy(tmpFilename, fullPath.c_str(), fullPath.size() + 1); | |
| 429 | |||
| 430 |
3/4✓ Branch 0 taken 2444 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 2401 times.
|
2444 | if (getFPPmode() == REMOTE_MODE) |
| 431 |
2/4✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✗ Branch 3 not taken.
|
43 | CheckForHostSpecificFile(getSetting("HostName").c_str(), tmpFilename); |
| 432 | |||
| 433 |
2/4✓ Branch 0 taken 2444 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2444 times.
✗ Branch 3 not taken.
|
2444 | checkForReplacementFile(std::string(tmpFilename)); |
| 434 | |||
| 435 |
3/4✓ Branch 0 taken 2444 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 699 times.
✓ Branch 3 taken 1745 times.
|
2444 | if (!FileExists(tmpFilename)) { |
| 436 |
1/2✓ Branch 0 taken 699 times.
✗ Branch 1 not taken.
|
699 | std::string warning = "Sequence file "; |
| 437 |
1/2✓ Branch 0 taken 699 times.
✗ Branch 1 not taken.
|
699 | warning += tmpFilename; |
| 438 |
1/2✓ Branch 0 taken 699 times.
✗ Branch 1 not taken.
|
699 | warning += " does not exist\n"; |
| 439 | |||
| 440 |
3/4✓ Branch 0 taken 699 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 688 times.
|
699 | if (getFPPmode() == REMOTE_MODE) { |
| 441 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | LogDebug(VB_SEQUENCE, "Sequence file %s does not exist\n", tmpFilename); |
| 442 | |||
| 443 | // Look for fallback.fseq instead | ||
| 444 |
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 | strcpy(tmpFilename, FPP_DIR_SEQUENCE("/fallback.fseq").c_str()); |
| 445 | |||
| 446 |
3/4✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 1 times.
|
11 | if (!FileExists(tmpFilename)) { |
| 447 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | LogDebug(VB_SEQUENCE, "Fallback Sequence file %s does not exist\n", tmpFilename); |
| 448 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | SetMissingSequenceWarning(filename, warning); |
| 449 | 10 | m_seqStarting = 0; | |
| 450 | 10 | return 0; | |
| 451 | |||
| 452 | } else { | ||
| 453 | { | ||
| 454 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::unique_lock<std::mutex> nameLock(m_seqFilenameLock); |
| 455 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | m_seqFilename = "fallback.fseq"; |
| 456 | 1 | } | |
| 457 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogDebug(VB_SEQUENCE, "Playing Fallback Sequence file %s\n", tmpFilename); |
| 458 | } | ||
| 459 | |||
| 460 | } else { | ||
| 461 |
3/4✓ Branch 0 taken 688 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 680 times.
|
688 | if (FirstReportOfMissing(filename)) { |
| 462 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | LogErr(VB_SEQUENCE, "Sequence file %s does not exist\n", tmpFilename); |
| 463 | } else { | ||
| 464 |
1/2✓ Branch 0 taken 680 times.
✗ Branch 1 not taken.
|
680 | LogDebug(VB_SEQUENCE, "Sequence file %s does not exist\n", tmpFilename); |
| 465 | } | ||
| 466 |
1/2✓ Branch 0 taken 688 times.
✗ Branch 1 not taken.
|
688 | SetMissingSequenceWarning(filename, warning); |
| 467 | 688 | m_seqStarting = 0; | |
| 468 | 688 | return 0; | |
| 469 | } | ||
| 470 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 698 times.
|
699 | } |
| 471 | |||
| 472 | // We have a file to play (the requested one, or the fallback) | ||
| 473 |
1/2✓ Branch 0 taken 1746 times.
✗ Branch 1 not taken.
|
1746 | ClearMissingSequenceWarning(); |
| 474 |
1/2✓ Branch 0 taken 1746 times.
✗ Branch 1 not taken.
|
1746 | reportedMissingSequences.erase(filename); |
| 475 | |||
| 476 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 1708 times.
|
1746 | if (multiSync->isMultiSyncEnabled()) { |
| 477 |
1/2✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
|
38 | seqLock.unlock(); |
| 478 |
1/2✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
|
38 | multiSync->SendSeqOpenPacket(filename); |
| 479 |
1/2✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
|
38 | seqLock.lock(); |
| 480 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 37 times.
|
38 | if (openGeneration != m_openGeneration) { |
| 481 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogDebug(VB_SEQUENCE, "Open of %s superseded by a later open while sending the open packet\n", filename.c_str()); |
| 482 | 1 | return 0; | |
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 |
1/2✓ Branch 0 taken 1745 times.
✗ Branch 1 not taken.
|
1745 | setSeqFile(nullptr); |
| 487 |
2/4✓ Branch 0 taken 1745 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1745 times.
✗ Branch 3 not taken.
|
1745 | FSEQFile* seqFile = FSEQFile::openFSEQFile(tmpFilename); |
| 488 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1744 times.
|
1745 | if (seqFile == NULL) { |
| 489 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogErr(VB_SEQUENCE, "Error opening sequence file: %s. FSEQFile::openFSEQFile returned NULL\n", |
| 490 | tmpFilename); | ||
| 491 | 1 | m_seqStarting = 0; | |
| 492 | 1 | return 0; | |
| 493 | } | ||
| 494 | |||
| 495 | 1744 | m_seqStepTime = seqFile->getStepTime(); | |
| 496 | 1744 | m_seqRefreshRate = 1000.0f / m_seqStepTime; | |
| 497 | |||
| 498 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1727 times.
|
1744 | if (startSecond >= 0) { |
| 499 | 17 | int frame = startSecond * 1000; | |
| 500 | 17 | frame /= seqFile->getStepTime(); | |
| 501 | 17 | m_lastFrameRead = frame - 1; | |
| 502 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if (m_lastFrameRead < -1) |
| 503 | ✗ | m_lastFrameRead = -1; | |
| 504 | } | ||
| 505 | |||
| 506 | // prepareRead() copies the ranges into its own member before returning, so | ||
| 507 | // it's safe to pass the temporary snapshot directly -- it lives through the | ||
| 508 | // full expression. | ||
| 509 |
2/4✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1744 times.
✗ Branch 3 not taken.
|
1744 | seqFile->prepareRead(*GetOutputRangesSnapshot(), startFrame < 0 ? 0 : startFrame); |
| 510 | // Calculate duration | ||
| 511 | 1744 | m_seqMSRemaining = seqFile->getNumFrames() * seqFile->getStepTime(); | |
| 512 | 3488 | m_seqMSDuration = m_seqMSRemaining.load(); | |
| 513 | 1744 | m_seqMSElapsed = 0; | |
| 514 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | SetChannelOutputRefreshRate(m_seqRefreshRate); |
| 515 | |||
| 516 | // start reading frames | ||
| 517 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | lock.lock(); |
| 518 |
2/4✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1744 times.
✗ Branch 3 not taken.
|
1744 | setSeqFile(std::shared_ptr<FSEQFile>(seqFile)); |
| 519 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | lock.unlock(); |
| 520 | 1744 | m_seqStarting = 1; // beyond header, read loop can start reading frames | |
| 521 | 1744 | frameLoadSignal.notify_all(); | |
| 522 | 1744 | seqFlag(m_seqPaused).store(0); | |
| 523 | 1744 | seqFlag(m_seqSingleStep).store(0); | |
| 524 | 1744 | seqFlag(m_seqSingleStepBack).store(0); | |
| 525 | 1744 | m_dataProcessed = false; | |
| 526 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | ProcessVariableHeaders(); |
| 527 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | ReadSequenceData(true); |
| 528 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | seqLock.unlock(); |
| 529 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | StartChannelOutputThread(); |
| 530 | |||
| 531 | 1744 | m_numSeek = 0; | |
| 532 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | LogDebug(VB_SEQUENCE, "seqRefreshRate : %f\n", m_seqRefreshRate); |
| 533 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
3488 | LogDebug(VB_SEQUENCE, "seqMSDuration : %d\n", m_seqMSDuration.load()); |
| 534 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
3488 | LogDebug(VB_SEQUENCE, "seqMSRemaining : %d\n", m_seqMSRemaining.load()); |
| 535 | 1744 | return 1; | |
| 536 | 2447 | } | |
| 537 | 1744 | void Sequence::ProcessVariableHeaders() { | |
| 538 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | std::shared_ptr<FSEQFile> seqFile = m_seqFile.load(); |
| 539 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1744 times.
|
1744 | if (!seqFile) { |
| 540 | ✗ | return; | |
| 541 | } | ||
| 542 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | auto trig = std::make_shared<Triggers>(); |
| 543 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 1744 times.
|
1787 | for (auto& vh : seqFile->getVariableHeaders()) { |
| 544 |
5/6✓ Branch 0 taken 10 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
43 | if (vh.code[0] != 'F' || (vh.code[1] != 'C' && vh.code[1] != 'E')) { |
| 545 | 36 | continue; | |
| 546 | } | ||
| 547 | // This walks a blob that came straight out of a file, so every read is | ||
| 548 | // bounds-checked against its end. It used to trust the block's own | ||
| 549 | // fields: the entry count and range count were read (unaligned) with no | ||
| 550 | // size check and the command/IP strings with a bare std::string(char*), | ||
| 551 | // so one truncated or non-v1 FC/FE block ran strlen() off the end of the | ||
| 552 | // vector and killed fppd while opening the sequence, before a single | ||
| 553 | // frame played. Nothing here is worth crashing a show over - a header | ||
| 554 | // that does not parse is dropped and the sequence still runs. | ||
| 555 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | const std::vector<uint8_t>& vhd = vh.getData(); |
| 556 | 10 | const uint8_t* data = vhd.data(); | |
| 557 | 10 | const uint8_t* const end = data + vhd.size(); | |
| 558 | |||
| 559 | 10029 | auto readU32 = [&data, end](uint32_t& out) { | |
| 560 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10026 times.
|
10029 | if ((size_t)(end - data) < sizeof(out)) { |
| 561 | 3 | return false; | |
| 562 | } | ||
| 563 | 10026 | memcpy(&out, data, sizeof(out)); // also drops the unaligned cast | |
| 564 | 10026 | data += sizeof(out); | |
| 565 | 10026 | return true; | |
| 566 | 10 | }; | |
| 567 | 16 | auto readStr = [&data, end](std::string& out) { | |
| 568 | 16 | const uint8_t* nul = (const uint8_t*)memchr(data, 0, end - data); | |
| 569 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
|
16 | if (nul == nullptr) { |
| 570 | 2 | return false; | |
| 571 | } | ||
| 572 | 14 | out.assign((const char*)data, nul - data); | |
| 573 | 14 | data = nul + 1; | |
| 574 | 14 | return true; | |
| 575 | 10 | }; | |
| 576 | |||
| 577 | 10 | uint32_t count = 0; | |
| 578 | 10 | std::string ips; | |
| 579 | // version flag, only understand v1 right now | ||
| 580 |
9/12✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 7 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 7 times.
|
10 | if (data == end || *data++ != 1 || !readU32(count) || !readStr(ips)) { |
| 581 | 3 | continue; | |
| 582 | } | ||
| 583 | // TODO - process ips to see if we are actually supposed to run these commands/effects | ||
| 584 | // Not supported in xLights yet | ||
| 585 | |||
| 586 | 7 | bool truncated = false; | |
| 587 |
3/4✓ Branch 0 taken 8 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
14 | for (uint32_t x = 0; x < count && !truncated; x++) { |
| 588 | 8 | std::string cmd; | |
| 589 | 8 | uint32_t cc = 0; | |
| 590 |
6/8✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 7 times.
|
8 | if (!readStr(cmd) || !readU32(cc)) { |
| 591 | 1 | truncated = true; | |
| 592 | 1 | break; | |
| 593 | } | ||
| 594 | // The name is stored once (an _END twin for commands) and each | ||
| 595 | // range records only its index; see Triggers. | ||
| 596 | 7 | const uint32_t idx = (uint32_t)trig->names.size(); | |
| 597 |
2/2✓ Branch 0 taken 5006 times.
✓ Branch 1 taken 6 times.
|
5012 | for (uint32_t cc1 = 0; cc1 < cc; cc1++) { |
| 598 | 5006 | uint32_t start = 0; | |
| 599 | 5006 | uint32_t stop = 0; | |
| 600 |
5/6✓ Branch 0 taken 5006 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5005 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 5005 times.
|
5006 | if (!readU32(start) || !readU32(stop)) { |
| 601 | 1 | truncated = true; | |
| 602 | 1 | break; | |
| 603 | } | ||
| 604 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4999 times.
|
5005 | if (cc1 == 0) { |
| 605 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | trig->names.push_back(cmd); |
| 606 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | if (vh.code[1] == 'C') { |
| 607 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | trig->names.push_back(cmd + "_END"); |
| 608 | } | ||
| 609 | } | ||
| 610 |
2/2✓ Branch 0 taken 5003 times.
✓ Branch 1 taken 2 times.
|
5005 | if (vh.code[1] == 'C') { |
| 611 |
2/4✓ Branch 0 taken 5003 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5003 times.
✗ Branch 3 not taken.
|
5003 | trig->commandPresets[start].push_back(idx); |
| 612 |
2/4✓ Branch 0 taken 5003 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5003 times.
✗ Branch 3 not taken.
|
5003 | trig->commandPresets[stop].push_back(idx + 1); |
| 613 | } else { | ||
| 614 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | trig->effectsOn[start].push_back(idx); |
| 615 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | trig->effectsOff[stop].push_back(idx); |
| 616 | } | ||
| 617 | } | ||
| 618 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | } |
| 619 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
|
7 | if (truncated) { |
| 620 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogWarn(VB_SEQUENCE, "Truncated '%c%c' variable header in %s, ignoring the rest of it\n", |
| 621 | vh.code[0], vh.code[1], m_seqFilename.c_str()); | ||
| 622 | } | ||
| 623 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
|
10 | } |
| 624 |
7/8✓ Branch 0 taken 1741 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1739 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1739 times.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 1739 times.
|
1744 | if (!trig->commandPresets.empty() || !trig->effectsOn.empty() || !trig->effectsOff.empty()) { |
| 625 | 5 | m_lastTriggeredFrame = -1; | |
| 626 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | setTriggers(trig); |
| 627 | } | ||
| 628 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | } |
| 629 | |||
| 630 | // Drop the current file's triggers (open/close). Effects the file started | ||
| 631 | // are stopped from the main loop: this runs under m_sequenceLock, and on the | ||
| 632 | // output thread when a sequence reaches its end, and StopEffect() can blank | ||
| 633 | // the outputs. | ||
| 634 | 1541 | void Sequence::ForgetTriggers() { | |
| 635 |
1/2✓ Branch 0 taken 1541 times.
✗ Branch 1 not taken.
|
1541 | setTriggers(nullptr); |
| 636 | 1541 | m_lastTriggeredFrame = -1; | |
| 637 | 1541 | std::vector<std::string> running; | |
| 638 | { | ||
| 639 | // Clearing the owner in the same critical section as the swap is what | ||
| 640 | // closes the window for an effect FireFrameTriggers() is starting | ||
| 641 | // right now: it either lands in `running` or sees the table closed. | ||
| 642 |
1/2✓ Branch 0 taken 1541 times.
✗ Branch 1 not taken.
|
1541 | std::unique_lock<std::mutex> l(m_triggerEffectsLock); |
| 643 | 1541 | m_triggerEffectsOwner = nullptr; | |
| 644 | 1541 | running.swap(m_triggerEffects); | |
| 645 | 1541 | } | |
| 646 |
2/2✓ Branch 0 taken 1540 times.
✓ Branch 1 taken 1 times.
|
1541 | if (running.empty()) |
| 647 | 1540 | return; | |
| 648 | { | ||
| 649 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::unique_lock<std::mutex> l(m_pendingPresetsLock); |
| 650 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | m_pendingEffectStops.insert(m_pendingEffectStops.end(), running.begin(), running.end()); |
| 651 | 1 | } | |
| 652 |
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.
|
3 | Timers::INSTANCE.addTimer("SequencePresets", GetTimeMS(), [this]() { |
| 653 | 1 | drainPendingPresets(); | |
| 654 | 1 | }); | |
| 655 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1540 times.
|
1541 | } |
| 656 | |||
| 657 | 3287 | void Sequence::queuePreset(const std::string& preset, std::map<std::string, std::string>&& keywords) { | |
| 658 |
2/2✓ Branch 0 taken 3247 times.
✓ Branch 1 taken 40 times.
|
3287 | if (!CommandManager::INSTANCE.HasPreset(preset)) { |
| 659 | 3247 | return; | |
| 660 | } | ||
| 661 | { | ||
| 662 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | std::unique_lock<std::mutex> l(m_pendingPresetsLock); |
| 663 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | m_pendingPresets.emplace_back(preset, std::move(keywords)); |
| 664 | 40 | } | |
| 665 | // One shared timer name: a queue while an entry is already armed just | ||
| 666 | // refreshes it, and the drain empties the whole FIFO, so nothing is lost | ||
| 667 | // to the replace-same-name semantics. The drain runs on the main loop | ||
| 668 | // with no sequence locks held; a preset that re-enters the sequence (or | ||
| 669 | // queues further presets) is therefore safe. | ||
| 670 |
3/6✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
|
120 | Timers::INSTANCE.addTimer("SequencePresets", GetTimeMS(), [this]() { |
| 671 | 36 | drainPendingPresets(); | |
| 672 | 36 | }); | |
| 673 | } | ||
| 674 | |||
| 675 | 2657 | void Sequence::drainPendingPresets() { | |
| 676 |
1/2✓ Branch 0 taken 2657 times.
✗ Branch 1 not taken.
|
2657 | std::unique_lock<std::mutex> l(m_pendingPresetsLock); |
| 677 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2657 times.
|
2658 | while (!m_pendingEffectStops.empty()) { |
| 678 | 1 | std::string eff = std::move(m_pendingEffectStops.front()); | |
| 679 | 1 | m_pendingEffectStops.pop_front(); | |
| 680 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | l.unlock(); |
| 681 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | StopEffect(eff); |
| 682 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | l.lock(); |
| 683 | 1 | } | |
| 684 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 2657 times.
|
2697 | while (!m_pendingPresets.empty()) { |
| 685 | 40 | auto p = std::move(m_pendingPresets.front()); | |
| 686 | 40 | m_pendingPresets.pop_front(); | |
| 687 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | l.unlock(); |
| 688 |
2/4✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
40 | CommandManager::INSTANCE.TriggerPreset(p.first, p.second); |
| 689 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | l.lock(); |
| 690 | 40 | } | |
| 691 | 2657 | } | |
| 692 | |||
| 693 | 2599 | void Sequence::StartSequence() { | |
| 694 | // Callers reach this without m_sequenceLock (the command handler and the | ||
| 695 | // playlist), so the name has to be snapshotted rather than read raw. | ||
| 696 |
1/2✓ Branch 0 taken 2599 times.
✗ Branch 1 not taken.
|
2599 | std::string seqName = GetSeqFilenameCopy(); |
| 697 |
8/14✓ Branch 0 taken 2599 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2599 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2599 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1740 times.
✓ Branch 7 taken 859 times.
✓ Branch 8 taken 2599 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1740 times.
✓ Branch 11 taken 859 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
2599 | if (!IsSequenceRunning() && m_seqFile.load()) { |
| 698 |
2/2✓ Branch 0 taken 37 times.
✓ Branch 1 taken 1703 times.
|
1740 | if (multiSync->isMultiSyncEnabled()) { |
| 699 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | ResetChannelOutputFrameNumber(); |
| 700 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | multiSync->SendSeqSyncStartPacket(seqName); |
| 701 | } | ||
| 702 | 1740 | m_seqStarting = 0; | |
| 703 |
1/2✓ Branch 0 taken 1740 times.
✗ Branch 1 not taken.
|
1740 | SetChannelOutputRefreshRate(m_seqRefreshRate); |
| 704 |
1/2✓ Branch 0 taken 1740 times.
✗ Branch 1 not taken.
|
1740 | StartChannelOutputThread(); |
| 705 | |||
| 706 | // Only on an actual start. It used to be queued on every call, and a | ||
| 707 | // remote whose copy of the sequence is missing calls this for every | ||
| 708 | // sync packet: the user's SEQUENCE_STARTED preset ran several times a | ||
| 709 | // second for the whole song, with no matching SEQUENCE_STOPPED. | ||
| 710 | // | ||
| 711 | // Deferred to the main loop: callers can hold m_sequenceLock | ||
| 712 | // (recursively, via StartSequence(filename, frame)), and a preset that | ||
| 713 | // starts/stops a playlist takes m_playlistMutex - the reverse of the | ||
| 714 | // playlist thread's m_playlistMutex -> m_sequenceLock order. | ||
| 715 |
5/10✓ Branch 0 taken 1740 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1740 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1740 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1740 times.
✓ Branch 7 taken 1740 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
8700 | queuePreset("SEQUENCE_STARTED", { { "SEQUENCE_NAME", seqName } }); |
| 716 | } | ||
| 717 |
1/6✓ Branch 0 taken 1740 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
4339 | } |
| 718 | |||
| 719 | 264 | void Sequence::StartSequence(const std::string& filename, int frameNumber) { | |
| 720 |
1/2✓ Branch 0 taken 264 times.
✗ Branch 1 not taken.
|
264 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 721 |
8/8✓ Branch 0 taken 215 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 200 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 250 times.
|
264 | if ((frameNumber > 0) && (filename == m_endedSeqFilename) && (frameNumber >= m_endedSeqIgnoreFrom)) { |
| 722 | // A sync packet for a sequence that already played to its end here | ||
| 723 | // (see m_endedSeqFilename). A start (frame 0) or an open replays it, | ||
| 724 | // and so does a sync packet for a frame before the last two seconds | ||
| 725 | // (see m_endedSeqIgnoreFrom). | ||
| 726 | 14 | return; | |
| 727 | } | ||
| 728 |
6/6✓ Branch 0 taken 55 times.
✓ Branch 1 taken 195 times.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 54 times.
✓ Branch 5 taken 196 times.
|
250 | if ((sequence->m_seqFilename != filename) && (m_seqSyncName != filename)) { |
| 729 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | CloseSequenceFile(); |
| 730 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | OpenSequenceFile(filename, frameNumber); |
| 731 |
7/12✓ Branch 0 taken 196 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 165 times.
✓ Branch 3 taken 31 times.
✓ Branch 4 taken 165 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 196 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 165 times.
✓ Branch 9 taken 31 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
196 | } else if (!m_seqFile.load() && m_missingSeqFilename == filename) { |
| 732 | // The file is still missing and the player is still syncing to it, so | ||
| 733 | // keep the warning up instead of letting it time out mid-sequence. | ||
| 734 |
1/2✓ Branch 0 taken 165 times.
✗ Branch 1 not taken.
|
165 | RefreshMissingSequenceWarning(); |
| 735 | } | ||
| 736 |
7/8✓ Branch 0 taken 48 times.
✓ Branch 1 taken 202 times.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 47 times.
✓ Branch 6 taken 203 times.
✓ Branch 7 taken 47 times.
|
250 | if ((sequence->m_seqFilename == filename) || (sequence->m_seqFilename == "fallback.fseq")) { |
| 737 |
1/2✓ Branch 0 taken 203 times.
✗ Branch 1 not taken.
|
203 | StartSequence(); |
| 738 |
2/2✓ Branch 0 taken 170 times.
✓ Branch 1 taken 33 times.
|
203 | if (frameNumber != 0) { |
| 739 |
1/2✓ Branch 0 taken 170 times.
✗ Branch 1 not taken.
|
170 | SeekSequenceFile(frameNumber); |
| 740 | } | ||
| 741 | } | ||
| 742 |
2/2✓ Branch 0 taken 250 times.
✓ Branch 1 taken 14 times.
|
264 | } |
| 743 | |||
| 744 | 15646 | void Sequence::SeekSequenceFile(int frameNumber) { | |
| 745 |
1/2✓ Branch 0 taken 15646 times.
✗ Branch 1 not taken.
|
15646 | LogDebug(VB_SEQUENCE, "SeekSequenceFile(%d)\n", frameNumber); |
| 746 | |||
| 747 |
1/2✓ Branch 0 taken 15646 times.
✗ Branch 1 not taken.
|
15646 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 748 |
3/4✓ Branch 0 taken 15646 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 162 times.
✓ Branch 3 taken 15484 times.
|
15646 | if (!IsSequenceRunning()) { |
| 749 |
1/2✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
|
162 | LogDebug(VB_SEQUENCE, "No sequence is running\n"); |
| 750 | 162 | return; | |
| 751 | } | ||
| 752 |
1/2✓ Branch 0 taken 15484 times.
✗ Branch 1 not taken.
|
15484 | seqLock.unlock(); |
| 753 | |||
| 754 |
1/2✓ Branch 0 taken 15484 times.
✗ Branch 1 not taken.
|
15484 | std::unique_lock<std::mutex> lock(frameCacheLock); |
| 755 |
5/6✓ Branch 0 taken 16062 times.
✓ Branch 1 taken 15484 times.
✓ Branch 2 taken 16062 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16062 times.
✓ Branch 5 taken 15484 times.
|
31546 | while (!pastFrameCache.empty() && frameNumber >= pastFrameCache.back()->frame) { |
| 756 | // Going backwords but frame is cached, we'll push the old frames | ||
| 757 |
1/2✓ Branch 0 taken 16062 times.
✗ Branch 1 not taken.
|
16062 | frameCache.push_front(pastFrameCache.back()); |
| 758 | 16062 | pastFrameCache.pop_back(); | |
| 759 | } | ||
| 760 |
6/6✓ Branch 0 taken 16560 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1092 times.
✓ Branch 3 taken 15468 times.
✓ Branch 4 taken 1092 times.
✓ Branch 5 taken 15484 times.
|
16576 | while (!frameCache.empty() && frameCache.front()->frame < frameNumber) { |
| 761 |
2/2✓ Branch 0 taken 1060 times.
✓ Branch 1 taken 32 times.
|
1092 | if (frameCache.front() != m_lastFrameData) |
| 762 |
1/2✓ Branch 0 taken 1060 times.
✗ Branch 1 not taken.
|
1060 | delete frameCache.front(); |
| 763 | 1092 | frameCache.pop_front(); | |
| 764 | } | ||
| 765 |
4/6✓ Branch 0 taken 15468 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 15468 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 15484 times.
|
15484 | if (!frameCache.empty() && frameNumber < frameCache.front()->frame) { |
| 766 | ✗ | clearCaches(); | |
| 767 | } | ||
| 768 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 15468 times.
|
15484 | if (frameCache.empty()) { |
| 769 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | LogDebug(VB_SEQUENCE, "Seeking to %d. Last read is %d\n", frameNumber, (int)m_lastFrameRead); |
| 770 | 16 | m_lastFrameRead = frameNumber - 1; | |
| 771 | 16 | frameLoadSignal.notify_all(); | |
| 772 | |||
| 773 |
7/8✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 8 times.
|
16 | if ((frameNumber < 100) && (getFPPmode() == REMOTE_MODE)) { |
| 774 | 8 | m_numSeek++; | |
| 775 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
|
8 | if (m_numSeek > 6) { |
| 776 | // Timed: it is re-raised while the skipping continues and | ||
| 777 | // otherwise ages out, rather than staying up until a restart. | ||
| 778 |
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.
|
8 | WarningHolder::AddWarningTimeout(600, 17, "Multiple Frame Skips During Playback - Likely Slow Network"); |
| 779 | } | ||
| 780 | } | ||
| 781 | } | ||
| 782 |
1/2✓ Branch 0 taken 15484 times.
✗ Branch 1 not taken.
|
15484 | lock.unlock(); |
| 783 | 15484 | frameLoadSignal.notify_all(); | |
| 784 |
2/2✓ Branch 0 taken 15484 times.
✓ Branch 1 taken 162 times.
|
15646 | } |
| 785 | |||
| 786 | 15476 | void Sequence::SkipFrames(std::atomic_int& skip) { | |
| 787 |
1/2✓ Branch 0 taken 15476 times.
✗ Branch 1 not taken.
|
15476 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 788 |
1/2✓ Branch 0 taken 15476 times.
✗ Branch 1 not taken.
|
30952 | if (int frames = skip.exchange(0, std::memory_order_relaxed)) { |
| 789 |
1/2✓ Branch 0 taken 15476 times.
✗ Branch 1 not taken.
|
15476 | SeekSequenceFile(channelOutputFrame.load(std::memory_order_relaxed) + frames + 1); |
| 790 | } | ||
| 791 | 15476 | } | |
| 792 | |||
| 793 | 28824 | std::string Sequence::GetSeqFilenameCopy() const { | |
| 794 |
1/2✓ Branch 0 taken 28824 times.
✗ Branch 1 not taken.
|
28824 | std::unique_lock<std::mutex> nameLock(m_seqFilenameLock); |
| 795 |
1/2✓ Branch 0 taken 28824 times.
✗ Branch 1 not taken.
|
57648 | return m_seqFilename; |
| 796 | 28824 | } | |
| 797 | |||
| 798 | // The flag is set after its pointer is stored and cleared before the pointer | ||
| 799 | // is dropped, so a reader that sees it set finds the pointer set too, as far | ||
| 800 | // as any unlocked check can promise that. | ||
| 801 | 7650 | void Sequence::setSeqFile(std::shared_ptr<FSEQFile> f) { | |
| 802 |
2/2✓ Branch 0 taken 1744 times.
✓ Branch 1 taken 5906 times.
|
7650 | if (f) { |
| 803 |
1/2✓ Branch 0 taken 1744 times.
✗ Branch 1 not taken.
|
1744 | m_seqFile.store(std::move(f)); |
| 804 | 1744 | m_haveSeqFile.store(true, std::memory_order_release); | |
| 805 | } else { | ||
| 806 | 5906 | m_haveSeqFile.store(false, std::memory_order_release); | |
| 807 |
1/2✓ Branch 0 taken 5906 times.
✗ Branch 1 not taken.
|
5906 | m_seqFile.store(nullptr); |
| 808 | } | ||
| 809 | 7650 | } | |
| 810 | |||
| 811 | 1546 | void Sequence::setTriggers(std::shared_ptr<Triggers> t) { | |
| 812 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1541 times.
|
1546 | if (t) { |
| 813 | { | ||
| 814 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | std::unique_lock<std::mutex> l(m_triggerEffectsLock); |
| 815 | 5 | m_triggerEffectsOwner = t.get(); | |
| 816 | 5 | } | |
| 817 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | m_triggers.store(std::move(t)); |
| 818 | 5 | m_haveTriggers.store(true, std::memory_order_release); | |
| 819 | } else { | ||
| 820 | 1541 | m_haveTriggers.store(false, std::memory_order_release); | |
| 821 |
1/2✓ Branch 0 taken 1541 times.
✗ Branch 1 not taken.
|
1541 | m_triggers.store(nullptr); |
| 822 | } | ||
| 823 | 1546 | } | |
| 824 | |||
| 825 | 2848815 | int Sequence::IsSequenceRunning(void) { | |
| 826 |
6/6✓ Branch 0 taken 1665725 times.
✓ Branch 1 taken 1183090 times.
✓ Branch 2 taken 1660224 times.
✓ Branch 3 taken 5501 times.
✓ Branch 4 taken 1660224 times.
✓ Branch 5 taken 1188591 times.
|
4514540 | if (m_haveSeqFile.load(std::memory_order_acquire) && !m_seqStarting.load(std::memory_order_acquire)) |
| 827 | 1660224 | return 1; | |
| 828 | |||
| 829 | 1188591 | return 0; | |
| 830 | } | ||
| 831 | |||
| 832 | 2171 | int Sequence::IsSequenceRunning(const std::string& filename) { | |
| 833 | 2171 | int result = 0; | |
| 834 | |||
| 835 |
1/2✓ Branch 0 taken 2171 times.
✗ Branch 1 not taken.
|
2171 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 836 |
7/8✓ Branch 0 taken 402 times.
✓ Branch 1 taken 1769 times.
✓ Branch 2 taken 402 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✓ Branch 5 taken 377 times.
✓ Branch 6 taken 1794 times.
✓ Branch 7 taken 377 times.
|
2171 | if ((sequence->m_seqFilename == filename) || (!filename.empty() && (sequence->m_seqSyncName == filename))) |
| 837 |
1/2✓ Branch 0 taken 1794 times.
✗ Branch 1 not taken.
|
1794 | result = sequence->IsSequenceRunning(); |
| 838 | |||
| 839 | 2171 | return result; | |
| 840 | 2171 | } | |
| 841 | |||
| 842 | 82850 | void Sequence::BlankSequenceData(bool clearBridge) { | |
| 843 |
1/2✓ Branch 0 taken 82850 times.
✗ Branch 1 not taken.
|
82850 | LogExcess(VB_SEQUENCE, "BlankSequenceData()\n"); |
| 844 |
1/2✓ Branch 0 taken 82850 times.
✗ Branch 1 not taken.
|
82850 | auto ranges = GetOutputRangesSnapshot(); |
| 845 |
2/2✓ Branch 0 taken 82910 times.
✓ Branch 1 taken 82850 times.
|
165760 | for (auto& a : *ranges) { |
| 846 | 82910 | memset(&m_seqData[a.first], 0, a.second); | |
| 847 | } | ||
| 848 |
3/4✓ Branch 0 taken 82850 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5190 times.
✓ Branch 3 taken 77660 times.
|
82850 | if (m_bridgeData && clearBridge) { |
| 849 |
1/2✓ Branch 0 taken 5190 times.
✗ Branch 1 not taken.
|
5190 | std::unique_lock<std::mutex> lock(m_bridgeRangesLock); |
| 850 |
2/2✓ Branch 0 taken 5206 times.
✓ Branch 1 taken 5190 times.
|
10396 | for (auto& a : *ranges) { |
| 851 | 5206 | memset(&m_bridgeData[a.first], 0, a.second); | |
| 852 | } | ||
| 853 | 5190 | m_bridgeRanges.clear(); | |
| 854 | 5190 | m_hasBridgeRanges.store(false, std::memory_order_relaxed); | |
| 855 | 5190 | } | |
| 856 | |||
| 857 | 82850 | m_dataProcessed = false; | |
| 858 | |||
| 859 |
1/2✓ Branch 0 taken 82850 times.
✗ Branch 1 not taken.
|
82850 | std::unique_lock<std::mutex> lock(frameCacheLock); |
| 860 |
1/2✓ Branch 0 taken 82850 times.
✗ Branch 1 not taken.
|
82850 | SetLastFrameData(nullptr); |
| 861 | 82850 | } | |
| 862 | |||
| 863 | 32 | int Sequence::SequenceIsPaused(void) { | |
| 864 | 32 | return seqFlag(m_seqPaused).load(); | |
| 865 | } | ||
| 866 | |||
| 867 | 23 | void Sequence::ToggleSequencePause(void) { | |
| 868 | 23 | seqFlag(m_seqPaused).fetch_xor(1); | |
| 869 | 23 | } | |
| 870 | |||
| 871 | 32 | void Sequence::SingleStepSequence(void) { | |
| 872 | 32 | seqFlag(m_seqSingleStep).store(1); | |
| 873 | 32 | } | |
| 874 | |||
| 875 | // Broken per issue #986 | ||
| 876 | ✗ | void Sequence::SingleStepSequenceBack(void) { | |
| 877 | ✗ | seqFlag(m_seqSingleStepBack).store(1); | |
| 878 | ✗ | } | |
| 879 | |||
| 880 | 182946 | void Sequence::ReadSequenceData(bool forceFirstFrame) { | |
| 881 |
1/2✓ Branch 0 taken 182946 times.
✗ Branch 1 not taken.
|
182946 | LogExcess(VB_SEQUENCE, "ReadSequenceData()\n"); |
| 882 |
1/2✓ Branch 0 taken 182946 times.
✗ Branch 1 not taken.
|
182946 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 883 |
6/6✓ Branch 0 taken 181202 times.
✓ Branch 1 taken 1744 times.
✓ Branch 2 taken 81 times.
✓ Branch 3 taken 181121 times.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 182865 times.
|
182946 | if (!forceFirstFrame && m_seqStarting) { |
| 884 | 81 | return; | |
| 885 | } | ||
| 886 | |||
| 887 |
7/8✓ Branch 0 taken 182865 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101299 times.
✓ Branch 3 taken 81566 times.
✓ Branch 4 taken 122 times.
✓ Branch 5 taken 101177 times.
✓ Branch 6 taken 122 times.
✓ Branch 7 taken 182743 times.
|
182865 | if ((IsSequenceRunning()) && seqFlag(m_seqPaused).load(std::memory_order_relaxed)) { |
| 888 |
2/2✓ Branch 0 taken 101 times.
✓ Branch 1 taken 21 times.
|
122 | if (seqFlag(m_seqSingleStep).exchange(0)) { |
| 889 | // one frame forward: read it as if playing | ||
| 890 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 101 times.
|
101 | } else if (seqFlag(m_seqSingleStepBack).exchange(0)) { |
| 891 | ✗ | std::unique_lock<std::mutex> lock(frameCacheLock); | |
| 892 | ✗ | if (!pastFrameCache.empty()) { | |
| 893 | ✗ | frameCache.push_front(pastFrameCache.back()); | |
| 894 | ✗ | pastFrameCache.pop_back(); | |
| 895 | ✗ | } else if (frameCache.empty()) { | |
| 896 | ✗ | m_lastFrameRead = -1; | |
| 897 | ✗ | frameLoadSignal.notify_all(); | |
| 898 | } else { | ||
| 899 | ✗ | int f = frameCache.front()->frame - 1; | |
| 900 | ✗ | m_lastFrameRead = f - 1; | |
| 901 | ✗ | if (m_lastFrameRead < -1) { | |
| 902 | ✗ | m_lastFrameRead = -1; | |
| 903 | } | ||
| 904 | ✗ | clearCaches(); | |
| 905 | ✗ | frameLoadSignal.notify_all(); | |
| 906 | } | ||
| 907 | ✗ | } else { | |
| 908 | 101 | return; | |
| 909 | } | ||
| 910 | } | ||
| 911 | |||
| 912 |
7/8✓ Branch 0 taken 181020 times.
✓ Branch 1 taken 1744 times.
✓ Branch 2 taken 181020 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 101198 times.
✓ Branch 5 taken 79822 times.
✓ Branch 6 taken 102942 times.
✓ Branch 7 taken 79822 times.
|
182764 | if (forceFirstFrame || IsSequenceRunning()) { |
| 913 | 102942 | m_remoteBlankCount = 0; | |
| 914 | |||
| 915 |
1/2✓ Branch 0 taken 102942 times.
✗ Branch 1 not taken.
|
102942 | std::unique_lock<std::mutex> lock(frameCacheLock); |
| 916 |
6/6✓ Branch 0 taken 4411 times.
✓ Branch 1 taken 98531 times.
✓ Branch 2 taken 3306 times.
✓ Branch 3 taken 1105 times.
✓ Branch 4 taken 3306 times.
✓ Branch 5 taken 99636 times.
|
102942 | if (frameCache.empty() && !m_doneRead) { |
| 917 | // wait up to the step time, if we don't have the frame, bail | ||
| 918 | 3306 | frameLoadSignal.notify_all(); | |
| 919 |
1/2✓ Branch 0 taken 3306 times.
✗ Branch 1 not taken.
|
3306 | frameLoadedSignal.wait_for(lock, std::chrono::milliseconds(m_seqStepTime - 1)); |
| 920 | } | ||
| 921 |
2/2✓ Branch 0 taken 101793 times.
✓ Branch 1 taken 1149 times.
|
102942 | if (!frameCache.empty()) { |
| 922 | 101793 | FSEQFile::FrameData* data = frameCache.front(); | |
| 923 | 101793 | frameCache.pop_front(); | |
| 924 |
2/2✓ Branch 0 taken 71734 times.
✓ Branch 1 taken 30059 times.
|
101793 | if (pastFrameCache.size() > 20) { |
| 925 |
1/2✓ Branch 0 taken 71734 times.
✗ Branch 1 not taken.
|
71734 | if (pastFrameCache.front() != m_lastFrameData) |
| 926 |
1/2✓ Branch 0 taken 71734 times.
✗ Branch 1 not taken.
|
71734 | delete pastFrameCache.front(); |
| 927 | 71734 | pastFrameCache.pop_front(); | |
| 928 | } | ||
| 929 |
1/2✓ Branch 0 taken 101793 times.
✗ Branch 1 not taken.
|
101793 | pastFrameCache.push_back(data); |
| 930 |
1/2✓ Branch 0 taken 101793 times.
✗ Branch 1 not taken.
|
101793 | SetLastFrameData(data); |
| 931 |
1/2✓ Branch 0 taken 101793 times.
✗ Branch 1 not taken.
|
101793 | lock.unlock(); |
| 932 | 101793 | frameLoadSignal.notify_all(); | |
| 933 | |||
| 934 |
1/2✓ Branch 0 taken 101793 times.
✗ Branch 1 not taken.
|
101793 | data->readFrame((uint8_t*)m_seqData, FPPD_MAX_CHANNELS); |
| 935 |
1/2✓ Branch 0 taken 101793 times.
✗ Branch 1 not taken.
|
101793 | SetChannelOutputFrameNumber(data->frame); |
| 936 | // Values for status and the playlist; nothing is published | ||
| 937 | // through them, so no ordering is needed. | ||
| 938 | 101793 | const int elapsed = data->frame * m_seqStepTime; | |
| 939 | 101793 | m_seqMSElapsed.store(elapsed, std::memory_order_relaxed); | |
| 940 | 203586 | m_seqMSRemaining.store(m_seqMSDuration.load(std::memory_order_relaxed) - elapsed, std::memory_order_relaxed); | |
| 941 | 101793 | m_dataProcessed.store(false, std::memory_order_release); | |
| 942 |
2/2✓ Branch 0 taken 1105 times.
✓ Branch 1 taken 44 times.
|
1149 | } else if (m_doneRead) { |
| 943 |
1/2✓ Branch 0 taken 1105 times.
✗ Branch 1 not taken.
|
1105 | lock.unlock(); |
| 944 | 2210 | m_seqMSElapsed = m_seqMSDuration.load(); | |
| 945 | 1105 | m_seqMSRemaining = 0; | |
| 946 | // Remember it by the name sync packets use (see m_seqSyncName). | ||
| 947 | 1105 | std::string ended; | |
| 948 | 1105 | int ignoreFrom = 0; | |
| 949 | { | ||
| 950 |
1/2✓ Branch 0 taken 1105 times.
✗ Branch 1 not taken.
|
1105 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 951 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1105 times.
✓ Branch 2 taken 1105 times.
✗ Branch 3 not taken.
|
1105 | ended = m_seqSyncName.empty() ? m_seqFilename : m_seqSyncName; |
| 952 |
1/2✓ Branch 0 taken 1105 times.
✗ Branch 1 not taken.
|
1105 | if (m_seqStepTime > 0) { |
| 953 | 2210 | ignoreFrom = std::max(0, (m_seqMSDuration.load() - 2000) / m_seqStepTime); | |
| 954 | } | ||
| 955 | 1105 | } | |
| 956 |
1/2✓ Branch 0 taken 1105 times.
✗ Branch 1 not taken.
|
1105 | CloseSequenceFile(); |
| 957 |
1/2✓ Branch 0 taken 1105 times.
✗ Branch 1 not taken.
|
1105 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 958 |
1/2✓ Branch 0 taken 1105 times.
✗ Branch 1 not taken.
|
1105 | m_endedSeqFilename = ended; |
| 959 | 1105 | m_endedSeqIgnoreFrom = ignoreFrom; | |
| 960 | 1105 | } else { | |
| 961 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 2 times.
|
44 | if (m_lastFrameRead > 0) { |
| 962 | // we'll have the read thread discard the frame | ||
| 963 | 42 | m_lastFrameRead++; | |
| 964 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 41 times.
|
42 | if (!pastFrameCache.empty()) { |
| 965 | // and copy the last frame data | ||
| 966 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | SetLastFrameData(pastFrameCache.back()); |
| 967 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | pastFrameCache.back()->readFrame((uint8_t*)m_seqData, FPPD_MAX_CHANNELS); |
| 968 | 1 | m_dataProcessed = false; | |
| 969 | } | ||
| 970 | } | ||
| 971 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | lock.unlock(); |
| 972 | 44 | frameLoadSignal.notify_all(); | |
| 973 | } | ||
| 974 | 102942 | } else { | |
| 975 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 79822 times.
|
79822 | if (m_blankBetweenSequences) { |
| 976 | ✗ | BlankSequenceData(); | |
| 977 |
3/4✓ Branch 0 taken 79822 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 764 times.
✓ Branch 3 taken 79058 times.
|
79822 | } else if (getFPPmode() == REMOTE_MODE) { |
| 978 | // on a remote, we will get a "stop" and then a "start" a short time later | ||
| 979 | // we don't want to blank immediately (unless the master tells us to) | ||
| 980 | // so we don't get black blinks on the remote. We'll wait the equivalent | ||
| 981 | // of 5 frames to then blank | ||
| 982 |
2/2✓ Branch 0 taken 683 times.
✓ Branch 1 taken 81 times.
|
764 | if (m_remoteBlankCount > 5) { |
| 983 |
1/2✓ Branch 0 taken 683 times.
✗ Branch 1 not taken.
|
683 | BlankSequenceData(); |
| 984 | } else { | ||
| 985 | 81 | m_remoteBlankCount++; | |
| 986 | } | ||
| 987 |
7/10✓ Branch 0 taken 79058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76977 times.
✓ Branch 3 taken 2081 times.
✓ Branch 4 taken 76977 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 76977 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 76977 times.
✓ Branch 9 taken 2081 times.
|
79058 | } else if (!Player::INSTANCE.IsPlaying() && (getFPPmode() & PLAYER_MODE)) { |
| 988 | // Player, but not playlist running (so not between sequences) | ||
| 989 | // yet we are likely outputting something (overlay, etc...) Need to blank | ||
| 990 |
1/2✓ Branch 0 taken 76977 times.
✗ Branch 1 not taken.
|
76977 | BlankSequenceData(); |
| 991 | } | ||
| 992 | } | ||
| 993 |
2/2✓ Branch 0 taken 182764 times.
✓ Branch 1 taken 182 times.
|
182946 | } |
| 994 | |||
| 995 | 196890 | void Sequence::ProcessSequenceData(int ms) { | |
| 996 |
2/2✓ Branch 0 taken 9912 times.
✓ Branch 1 taken 186978 times.
|
196890 | if (m_dataProcessed.load(std::memory_order_acquire)) { |
| 997 | // we shouldn't normally be reprocessing the same data, so | ||
| 998 | // if we are then see if we can start with a pristine copy | ||
| 999 |
1/2✓ Branch 0 taken 9912 times.
✗ Branch 1 not taken.
|
9912 | std::unique_lock<std::mutex> lock(frameCacheLock); |
| 1000 |
2/2✓ Branch 0 taken 1354 times.
✓ Branch 1 taken 8558 times.
|
9912 | if (m_lastFrameData) |
| 1001 |
1/2✓ Branch 0 taken 1354 times.
✗ Branch 1 not taken.
|
1354 | m_lastFrameData->readFrame((uint8_t*)m_seqData, FPPD_MAX_CHANNELS); |
| 1002 | 9912 | } | |
| 1003 | |||
| 1004 |
5/6✓ Branch 0 taken 196890 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6548 times.
✓ Branch 3 taken 190342 times.
✓ Branch 4 taken 6548 times.
✓ Branch 5 taken 190342 times.
|
196890 | if (m_bridgeData && hasBridgeData()) { |
| 1005 | // Prune expired ranges and merge the live ones, all under the lock. | ||
| 1006 | // m_bridgeRanges is keyed by startChannel so the scratch vector comes | ||
| 1007 | // out sorted. WriteBridgeData() copies each packet in under the same | ||
| 1008 | // lock, so a packet can no longer land halfway through this copy and | ||
| 1009 | // send a universe half old, half new; the receive path waits at most | ||
| 1010 | // for one merge's memcpys. | ||
| 1011 |
1/2✓ Branch 0 taken 6548 times.
✗ Branch 1 not taken.
|
6548 | uint64_t nt = GetMonotonicTimeMS(); // expiries are monotonic (CommitBridgeRanges) |
| 1012 | // The scratch vector is shared by every caller (the output thread and | ||
| 1013 | // the inline SendBlankingData path), so it is cleared, filled and read | ||
| 1014 | // only under the lock: a clear() racing another caller's emplace_back | ||
| 1015 | // or iteration corrupts the vector. | ||
| 1016 |
1/2✓ Branch 0 taken 6548 times.
✗ Branch 1 not taken.
|
6548 | std::unique_lock<std::mutex> bridgesLock(m_bridgeRangesLock); |
| 1017 | 6548 | m_bridgeRangeScratch.clear(); | |
| 1018 | 6548 | auto rit = m_bridgeRanges.begin(); | |
| 1019 |
2/2✓ Branch 0 taken 19043 times.
✓ Branch 1 taken 6548 times.
|
25591 | while (rit != m_bridgeRanges.end()) { |
| 1020 | 19043 | BridgeRangeData& rd = rit->second; | |
| 1021 | 19043 | uint32_t len = 0; | |
| 1022 | 19043 | auto it = rd.expires.begin(); | |
| 1023 |
2/2✓ Branch 0 taken 19045 times.
✓ Branch 1 taken 19043 times.
|
38088 | while (it != rd.expires.end()) { |
| 1024 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 19031 times.
|
19045 | if (it->second < nt) { |
| 1025 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | it = rd.expires.erase(it); |
| 1026 | } else { | ||
| 1027 | 19031 | len = std::max(len, it->first); | |
| 1028 | 19031 | ++it; | |
| 1029 | } | ||
| 1030 | } | ||
| 1031 |
2/2✓ Branch 0 taken 19031 times.
✓ Branch 1 taken 12 times.
|
19043 | if (len > 0) { |
| 1032 |
1/2✓ Branch 0 taken 19031 times.
✗ Branch 1 not taken.
|
19031 | m_bridgeRangeScratch.emplace_back(rd.startChannel, len); |
| 1033 | 19031 | ++rit; | |
| 1034 | } else { | ||
| 1035 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | rit = m_bridgeRanges.erase(rit); |
| 1036 | } | ||
| 1037 | } | ||
| 1038 | 6548 | m_hasBridgeRanges.store(!m_bridgeRanges.empty(), std::memory_order_relaxed); | |
| 1039 | |||
| 1040 | // copy the latest bridge data to the sequence data | ||
| 1041 | 6548 | uint32_t curStart = 0xFFFFFFFF; | |
| 1042 | 6548 | uint32_t nextStart = 0xFFFFFFFF; | |
| 1043 |
2/2✓ Branch 0 taken 19031 times.
✓ Branch 1 taken 6548 times.
|
25579 | for (auto& a : m_bridgeRangeScratch) { |
| 1044 |
2/2✓ Branch 0 taken 6538 times.
✓ Branch 1 taken 12493 times.
|
19031 | if (curStart == 0xFFFFFFFF) { |
| 1045 | 6538 | curStart = a.first; | |
| 1046 | 6538 | nextStart = a.first + a.second; | |
| 1047 |
2/2✓ Branch 0 taken 4415 times.
✓ Branch 1 taken 8078 times.
|
12493 | } else if (a.first > nextStart) { |
| 1048 | 4415 | memcpy(&m_seqData[curStart], &m_bridgeData[curStart], nextStart - curStart); | |
| 1049 | 4415 | curStart = a.first; | |
| 1050 | 4415 | nextStart = a.first + a.second; | |
| 1051 | } else { | ||
| 1052 | // Adjacent or overlapping: extend the run, but never shrink it. | ||
| 1053 | // This used to set it to the end of 'a', which cut the run | ||
| 1054 | // short when 'a' lay entirely inside it (one input's universe | ||
| 1055 | // inside another's range), dropping the earlier range's tail. | ||
| 1056 | 8078 | nextStart = std::max(nextStart, a.first + a.second); | |
| 1057 | } | ||
| 1058 | } | ||
| 1059 |
2/2✓ Branch 0 taken 6538 times.
✓ Branch 1 taken 10 times.
|
6548 | if (curStart != 0xFFFFFFFF) { |
| 1060 | 6538 | memcpy(&m_seqData[curStart], &m_bridgeData[curStart], nextStart - curStart); | |
| 1061 | } | ||
| 1062 |
1/2✓ Branch 0 taken 6548 times.
✗ Branch 1 not taken.
|
6548 | bridgesLock.unlock(); |
| 1063 | 6548 | } | |
| 1064 | 196890 | PluginManager::INSTANCE.modifySequenceData(ms, (uint8_t*)m_seqData); | |
| 1065 | |||
| 1066 |
2/2✓ Branch 0 taken 1759 times.
✓ Branch 1 taken 195131 times.
|
196890 | if (IsEffectRunning()) |
| 1067 | 1759 | OverlayEffects(m_seqData); | |
| 1068 | |||
| 1069 | 196890 | if ( | |
| 1070 | #ifdef HAS_GSTREAMER | ||
| 1071 |
2/2✓ Branch 0 taken 1319 times.
✓ Branch 1 taken 195571 times.
|
196890 | GStreamerOutput::IsOverlayingVideo() |
| 1072 | #else | ||
| 1073 | false | ||
| 1074 | #endif | ||
| 1075 | ) { | ||
| 1076 | #ifdef HAS_GSTREAMER | ||
| 1077 | 1319 | GStreamerOutput::ProcessVideoOverlay(ms); | |
| 1078 | #endif | ||
| 1079 | } | ||
| 1080 |
2/2✓ Branch 0 taken 27947 times.
✓ Branch 1 taken 168943 times.
|
196890 | if (PixelOverlayManager::INSTANCE.hasActiveOverlays()) { |
| 1081 | 27947 | PixelOverlayManager::INSTANCE.doOverlays((uint8_t*)m_seqData); | |
| 1082 | } | ||
| 1083 | |||
| 1084 |
2/2✓ Branch 0 taken 41616 times.
✓ Branch 1 taken 155274 times.
|
196890 | if (ChannelTester::INSTANCE.Testing()) |
| 1085 | 41616 | ChannelTester::INSTANCE.OverlayTestData(m_seqData); | |
| 1086 | |||
| 1087 | 196890 | PluginManager::INSTANCE.modifyChannelData(ms, (uint8_t*)m_seqData); | |
| 1088 | |||
| 1089 | 196890 | PrepareChannelData(m_seqData); | |
| 1090 | 196890 | m_dataProcessed.store(true, std::memory_order_release); | |
| 1091 | 196890 | } | |
| 1092 | |||
| 1093 | 187425 | void Sequence::FireFrameTriggers() { | |
| 1094 | // Triggers belong to frames, not to sends. This runs on every output | ||
| 1095 | // send, and used to fire whatever frame was current: the first frame's | ||
| 1096 | // triggers went off two or three times (it is sent before the sequence | ||
| 1097 | // starts, and a remote resends it until the start packet arrives), a held | ||
| 1098 | // or paused frame re-fired every send, and a frame skipped by a catch-up | ||
| 1099 | // jump -- often the one carrying an _END preset -- never fired. Fire each | ||
| 1100 | // frame's triggers once, only once the sequence has started, including the | ||
| 1101 | // frames a small jump skipped; a large jump is a seek (a remote joining | ||
| 1102 | // mid-song) and fires only the frame it lands on. | ||
| 1103 | // Most files have no triggers: skip the locked load on every frame. | ||
| 1104 |
2/2✓ Branch 0 taken 187261 times.
✓ Branch 1 taken 164 times.
|
187425 | if (!m_haveTriggers.load(std::memory_order_acquire)) |
| 1105 | 187262 | return; | |
| 1106 |
1/2✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
|
164 | std::shared_ptr<Triggers> trig = m_triggers.load(); |
| 1107 | 164 | int64_t frame = m_lastFrameNumber.load(); | |
| 1108 |
6/8✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 164 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 163 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 163 times.
|
164 | if (!trig || (frame < 0) || m_seqStarting) |
| 1109 | 1 | return; | |
| 1110 | 163 | int64_t last = m_lastTriggeredFrame.load(); | |
| 1111 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 163 times.
|
163 | if (frame == last) |
| 1112 | ✗ | return; | |
| 1113 |
1/2✓ Branch 0 taken 163 times.
✗ Branch 1 not taken.
|
163 | int64_t maxCatchup = (m_seqStepTime > 0) ? (2000 / m_seqStepTime) : 40; |
| 1114 |
2/4✓ Branch 0 taken 163 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 163 times.
✗ Branch 3 not taken.
|
163 | int64_t from = ((frame < last) || ((frame - last) > maxCatchup)) ? frame : last + 1; |
| 1115 | 163 | m_lastTriggeredFrame = frame; | |
| 1116 | |||
| 1117 |
1/2✓ Branch 0 taken 163 times.
✗ Branch 1 not taken.
|
163 | for (auto p = trig->commandPresets.lower_bound((uint32_t)from); |
| 1118 |
6/6✓ Branch 0 taken 86 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 80 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 163 times.
|
169 | (p != trig->commandPresets.end()) && (p->first <= (uint64_t)frame); ++p) { |
| 1119 | // This runs on the channel output thread while the open/close | ||
| 1120 | // paths can be reassigning the name on another thread. | ||
| 1121 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | std::string seqName = GetSeqFilenameCopy(); |
| 1122 |
2/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
12 | std::map<std::string, std::string> keywords({ { "SEQUENCE_NAME", seqName } }); |
| 1123 | 6 | uint32_t elapsedMS = p->first * (uint32_t)m_seqStepTime; | |
| 1124 | 6 | uint32_t totalSeconds = elapsedMS / 1000; | |
| 1125 | char timeBuf[16]; | ||
| 1126 | 6 | snprintf(timeBuf, sizeof(timeBuf), "%02u:%02u.%03u", | |
| 1127 | totalSeconds / 60, totalSeconds % 60, elapsedMS % 1000); | ||
| 1128 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | for (uint32_t idx : p->second) { |
| 1129 | 6 | const std::string& cmd = trig->names[idx]; | |
| 1130 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | LogDebug(VB_COMMAND, "Sequence \"%s\" @ %s triggering preset \"%s\"\n", seqName.c_str(), timeBuf, cmd.c_str()); |
| 1131 | // Deferred to the main loop: this thread holds | ||
| 1132 | // outputThreadLock for the whole frame, so running a | ||
| 1133 | // command here couples the output thread to every lock | ||
| 1134 | // any command can take (playlist, scheduler via | ||
| 1135 | // %VAR:fpp_*%, media...). The preset fires on the next | ||
| 1136 | // main-loop tick, a few ms after the frame it was | ||
| 1137 | // authored on. | ||
| 1138 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | queuePreset(cmd, std::map<std::string, std::string>(keywords)); |
| 1139 | } | ||
| 1140 | 6 | } | |
| 1141 |
1/2✓ Branch 0 taken 163 times.
✗ Branch 1 not taken.
|
163 | for (auto e = trig->effectsOn.lower_bound((uint32_t)from); |
| 1142 |
6/6✓ Branch 0 taken 5 times.
✓ Branch 1 taken 160 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 163 times.
|
165 | (e != trig->effectsOn.end()) && (e->first <= (uint64_t)frame); ++e) { |
| 1143 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | for (uint32_t idx : e->second) { |
| 1144 | 2 | const std::string& eff = trig->names[idx]; | |
| 1145 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | StartEffect(eff, 0, 1); |
| 1146 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::unique_lock<std::mutex> l(m_triggerEffectsLock); |
| 1147 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (m_triggerEffectsOwner == trig.get()) { |
| 1148 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | m_triggerEffects.push_back(eff); |
| 1149 | } else { | ||
| 1150 | // The file closed (ForgetTriggers) while this frame was | ||
| 1151 | // firing, after it took the running list: nothing else will | ||
| 1152 | // stop this effect, so stop it here, as effectsOff does. | ||
| 1153 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | l.unlock(); |
| 1154 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | StopEffect(eff); |
| 1155 | } | ||
| 1156 | 2 | } | |
| 1157 | } | ||
| 1158 |
1/2✓ Branch 0 taken 163 times.
✗ Branch 1 not taken.
|
163 | for (auto e = trig->effectsOff.lower_bound((uint32_t)from); |
| 1159 |
4/6✓ Branch 0 taken 42 times.
✓ Branch 1 taken 121 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 42 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 163 times.
|
163 | (e != trig->effectsOff.end()) && (e->first <= (uint64_t)frame); ++e) { |
| 1160 | ✗ | for (uint32_t idx : e->second) { | |
| 1161 | ✗ | const std::string& eff = trig->names[idx]; | |
| 1162 | ✗ | StopEffect(eff); | |
| 1163 | ✗ | std::unique_lock<std::mutex> l(m_triggerEffectsLock); | |
| 1164 | ✗ | auto it = std::find(m_triggerEffects.begin(), m_triggerEffects.end(), eff); | |
| 1165 | ✗ | if (it != m_triggerEffects.end()) | |
| 1166 | ✗ | m_triggerEffects.erase(it); | |
| 1167 | ✗ | } | |
| 1168 | } | ||
| 1169 |
4/10✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 163 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
170 | } |
| 1170 | |||
| 1171 | 187425 | void Sequence::SendSequenceData() { | |
| 1172 | 187425 | FireFrameTriggers(); | |
| 1173 | 187425 | SendChannelData(m_seqData); | |
| 1174 | 187425 | } | |
| 1175 | |||
| 1176 | 5190 | void Sequence::SendBlankingData(void) { | |
| 1177 |
1/2✓ Branch 0 taken 5190 times.
✗ Branch 1 not taken.
|
5190 | LogDebug(VB_SEQUENCE, "SendBlankingData()\n"); |
| 1178 |
2/4✓ Branch 0 taken 5190 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5190 times.
✗ Branch 3 not taken.
|
5190 | std::this_thread::sleep_for(5ms); |
| 1179 | |||
| 1180 |
2/2✓ Branch 0 taken 86 times.
✓ Branch 1 taken 5104 times.
|
5190 | if (multiSync->isMultiSyncEnabled()) |
| 1181 |
1/2✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
|
86 | multiSync->SendBlankingDataPacket(); |
| 1182 | |||
| 1183 |
1/2✓ Branch 0 taken 5190 times.
✗ Branch 1 not taken.
|
5190 | BlankSequenceData(true); |
| 1184 | |||
| 1185 | // Normally the output thread sends it. With output disabled (the outputs | ||
| 1186 | // API's "disable") that thread keeps running and preparing every frame on | ||
| 1187 | // the same buffers, so it is asked to send this one anyway rather than | ||
| 1188 | // having this thread prepare and send alongside it. Waiting for its lock | ||
| 1189 | // instead deadlocked: callers hold m_sequenceLock (CloseSequenceFile(), | ||
| 1190 | // and the open/start paths that close), which the output thread takes in | ||
| 1191 | // ReadSequenceData() while holding outputThreadLock. | ||
| 1192 |
7/10✓ Branch 0 taken 5190 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5010 times.
✓ Branch 3 taken 180 times.
✓ Branch 4 taken 5010 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 180 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4530 times.
✓ Branch 9 taken 660 times.
|
5190 | if (ChannelOutputThreadIsEnabled() ? ForceChannelOutputNow() : ForceChannelOutputSendNow()) { |
| 1193 | 4530 | return; | |
| 1194 | } | ||
| 1195 | |||
| 1196 | // The output thread isn't running, or is on its way out and no longer | ||
| 1197 | // preparing frames: drive the outputs from this thread. Hold off a | ||
| 1198 | // replacement output thread from starting mid-send, but never wait on its | ||
| 1199 | // lock: an exiting thread holds it while its OUTPUTS_DISABLED presets run, | ||
| 1200 | // and those can stop a playlist, which needs m_sequenceLock -- held by our | ||
| 1201 | // caller. Not on the output thread itself, which already holds it, nor | ||
| 1202 | // when this send re-enters itself through OverlayEffects() on the same | ||
| 1203 | // thread: the lock is a plain mutex. Then hold off an output reload's | ||
| 1204 | // teardown, which would otherwise free an output mid-send. | ||
| 1205 | static thread_local int inlineSendDepth = 0; | ||
| 1206 | 660 | std::unique_lock<std::mutex> threadLock(outputThreadLock, std::defer_lock); | |
| 1207 |
4/8✓ Branch 0 taken 660 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 660 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 660 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 660 times.
✗ Branch 7 not taken.
|
660 | if (inlineSendDepth == 0 && !IsChannelOutputThread()) { |
| 1208 |
7/8✓ Branch 0 taken 12010 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11361 times.
✓ Branch 3 taken 649 times.
✓ Branch 4 taken 11350 times.
✓ Branch 5 taken 11 times.
✓ Branch 6 taken 11350 times.
✓ Branch 7 taken 660 times.
|
12010 | for (int tries = 0; !threadLock.try_lock() && tries < 50; ++tries) { |
| 1209 |
4/10✓ Branch 0 taken 11350 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11350 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11350 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 11350 times.
|
11350 | if (ChannelOutputThreadIsEnabled() ? ForceChannelOutputNow() : ForceChannelOutputSendNow()) { |
| 1210 | ✗ | return; // a replacement came up; it sends the blank | |
| 1211 | } | ||
| 1212 |
2/4✓ Branch 0 taken 11350 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11350 times.
✗ Branch 3 not taken.
|
11350 | std::this_thread::sleep_for(1ms); |
| 1213 | } | ||
| 1214 | } | ||
| 1215 |
1/2✓ Branch 0 taken 660 times.
✗ Branch 1 not taken.
|
660 | std::unique_lock<std::recursive_mutex> inlineLock(inlineOutputLock); |
| 1216 | struct Depth { | ||
| 1217 | 660 | Depth() { inlineSendDepth++; } | |
| 1218 | 660 | ~Depth() { inlineSendDepth--; } | |
| 1219 | 660 | } depth; | |
| 1220 |
1/2✓ Branch 0 taken 660 times.
✗ Branch 1 not taken.
|
660 | ProcessSequenceData(0); |
| 1221 |
1/2✓ Branch 0 taken 660 times.
✗ Branch 1 not taken.
|
660 | SendSequenceData(); |
| 1222 |
1/2✓ Branch 0 taken 660 times.
✗ Branch 1 not taken.
|
660 | } |
| 1223 | |||
| 1224 | 33 | void Sequence::CloseIfOpen(const std::string& filename) { | |
| 1225 |
1/2✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 1226 |
6/6✓ Branch 0 taken 4 times.
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 30 times.
✓ Branch 5 taken 3 times.
|
33 | if ((m_seqFilename == filename) || (m_seqSyncName == filename)) { |
| 1227 | // The master has stopped this sequence. A sync packet for it that was | ||
| 1228 | // already in flight arrives after the close; without a record it looks | ||
| 1229 | // like a join mid-stream and reopens what was just stopped (or closes | ||
| 1230 | // the next sequence to make room). Ignore syncs from about a second | ||
| 1231 | // before where we stopped: a repeat's syncs start near frame 0. | ||
| 1232 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
|
30 | std::string stopped = m_seqSyncName.empty() ? m_seqFilename : m_seqSyncName; |
| 1233 | 30 | int stepTime = m_seqStepTime; | |
| 1234 | 30 | int ignoreFrom = 0; | |
| 1235 |
7/12✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 30 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 24 times.
✓ Branch 9 taken 6 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
30 | if (stepTime > 0 && m_seqFile.load()) { |
| 1236 | 48 | ignoreFrom = std::max(1, m_seqMSElapsed.load() / stepTime - 1000 / stepTime); | |
| 1237 | } | ||
| 1238 |
1/2✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
|
30 | CloseSequenceFile(); |
| 1239 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
|
30 | if (ignoreFrom > 0) { |
| 1240 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | m_endedSeqFilename = stopped; |
| 1241 | 24 | m_endedSeqIgnoreFrom = ignoreFrom; | |
| 1242 | } | ||
| 1243 | 30 | } | |
| 1244 | 33 | } | |
| 1245 | |||
| 1246 | 53 | uint64_t Sequence::OpenGeneration() { | |
| 1247 |
1/2✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
|
53 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 1248 | 53 | return m_openGeneration; | |
| 1249 | 53 | } | |
| 1250 | |||
| 1251 | 53 | void Sequence::CloseSequenceFileIfStill(uint64_t generation) { | |
| 1252 | { | ||
| 1253 |
1/2✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
|
53 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 1254 |
9/12✓ Branch 0 taken 46 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 44 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 46 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 51 times.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
53 | if (generation != m_openGeneration || !m_seqFile.load()) { |
| 1255 | 51 | return; | |
| 1256 | } | ||
| 1257 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 51 times.
|
53 | } |
| 1258 | // Outside the lock, as every other caller: CloseSequenceFile() sends the | ||
| 1259 | // MultiSync stop before it takes it. The only opener that could slip in | ||
| 1260 | // between is another thread's Start Sequence, and callers of this run on | ||
| 1261 | // the main loop with the playlist. | ||
| 1262 | 2 | CloseSequenceFile(); | |
| 1263 | } | ||
| 1264 | |||
| 1265 | 1603 | void Sequence::CloseSequenceFile(void) { | |
| 1266 | // These two reads happen before m_sequenceLock is taken below, so they need | ||
| 1267 | // the snapshot; callers arrive here from the playlist, MultiSync and the | ||
| 1268 | // API threads. | ||
| 1269 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | std::string seqName = GetSeqFilenameCopy(); |
| 1270 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | LogDebug(VB_SEQUENCE, "CloseSequenceFile() %s\n", seqName.c_str()); |
| 1271 | |||
| 1272 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 1581 times.
|
1603 | if (multiSync->isMultiSyncEnabled()) |
| 1273 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | multiSync->SendSeqSyncStopPacket(seqName); |
| 1274 | |||
| 1275 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | std::unique_lock<std::recursive_mutex> seqLock(m_sequenceLock); |
| 1276 | |||
| 1277 | // The player told us to stop (or we're moving on); a file that never | ||
| 1278 | // opened is no longer worth warning about. | ||
| 1279 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | ClearMissingSequenceWarning(); |
| 1280 | |||
| 1281 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | std::unique_lock<std::mutex> readLock(readFileLock); |
| 1282 |
3/4✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1540 times.
✓ Branch 3 taken 63 times.
|
1603 | if (std::shared_ptr<FSEQFile> old = m_seqFile.load()) { |
| 1283 |
1/2✓ Branch 0 taken 1540 times.
✗ Branch 1 not taken.
|
1540 | std::string fn = old->getFilename(); |
| 1284 |
1/2✓ Branch 0 taken 1540 times.
✗ Branch 1 not taken.
|
1540 | std::unique_lock<std::mutex> fclock(frameCacheLock); |
| 1285 |
1/2✓ Branch 0 taken 1540 times.
✗ Branch 1 not taken.
|
1540 | setSeqFile(nullptr); |
| 1286 |
1/2✓ Branch 0 taken 1540 times.
✗ Branch 1 not taken.
|
1540 | fclock.unlock(); |
| 1287 |
1/2✓ Branch 0 taken 1540 times.
✗ Branch 1 not taken.
|
1540 | checkForReplacementFile(fn); |
| 1288 | |||
| 1289 | // Deferred to the main loop: this runs under m_sequenceLock + | ||
| 1290 | // readFileLock (and on the channel output thread when the sequence | ||
| 1291 | // ends via ReadSequenceData), so firing the preset here inverts | ||
| 1292 | // against the playlist thread's m_playlistMutex -> m_sequenceLock. | ||
| 1293 |
2/2✓ Branch 0 taken 1538 times.
✓ Branch 1 taken 2 times.
|
1540 | if (!m_seqStarting) { |
| 1294 | // Only for a sequence that started, to pair with SEQUENCE_STARTED | ||
| 1295 | // (which fires only on an actual start). Closing one that was | ||
| 1296 | // opened and never started -- the next playlist entry prepared, | ||
| 1297 | // then a stop -- used to fire a STOPPED with no STARTED. | ||
| 1298 |
5/10✓ Branch 0 taken 1538 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1538 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1538 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1538 times.
✓ Branch 7 taken 1538 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
7690 | queuePreset("SEQUENCE_STOPPED", { { "SEQUENCE_NAME", m_seqFilename } }); |
| 1299 | } | ||
| 1300 |
1/2✓ Branch 0 taken 1540 times.
✗ Branch 1 not taken.
|
1540 | ForgetTriggers(); |
| 1301 | 3143 | } | |
| 1302 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | readLock.unlock(); |
| 1303 | |||
| 1304 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | std::unique_lock<std::mutex> lock(frameCacheLock); |
| 1305 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | clearCaches(); |
| 1306 | 1603 | m_doneRead = true; | |
| 1307 | 1603 | m_lastFrameRead = -1; | |
| 1308 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | lock.unlock(); |
| 1309 | 1603 | frameLoadedSignal.notify_all(); | |
| 1310 | |||
| 1311 | { | ||
| 1312 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | std::unique_lock<std::mutex> nameLock(m_seqFilenameLock); |
| 1313 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | m_seqFilename = ""; |
| 1314 | 1603 | } | |
| 1315 | 1603 | m_seqSyncName.clear(); | |
| 1316 | 1603 | seqFlag(m_seqPaused).store(0); | |
| 1317 | |||
| 1318 |
1/2✓ Branch 0 taken 1603 times.
✗ Branch 1 not taken.
|
1603 | if ((!IsEffectRunning()) && |
| 1319 |
3/4✓ Branch 0 taken 1602 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1515 times.
✓ Branch 3 taken 87 times.
|
1602 | ((getFPPmode() != REMOTE_MODE) && |
| 1320 |
7/8✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1515 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1084 times.
✓ Branch 5 taken 431 times.
✓ Branch 6 taken 431 times.
✓ Branch 7 taken 1172 times.
|
4290 | (Player::INSTANCE.GetStatus() != FPP_STATUS_PLAYLIST_PLAYING)) || |
| 1321 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | (m_blankBetweenSequences)) { |
| 1322 |
1/2✓ Branch 0 taken 431 times.
✗ Branch 1 not taken.
|
431 | SendBlankingData(); |
| 1323 | } | ||
| 1324 |
1/6✓ Branch 0 taken 1538 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
3141 | } |
| 1325 | |||
| 1326 | 68628 | bool Sequence::WriteBridgeData(uint8_t* data, int startChannel, int len) { | |
| 1327 |
3/4✓ Branch 0 taken 68628 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17190 times.
✓ Branch 3 taken 51438 times.
|
68628 | if (this->IsSequenceRunning()) { |
| 1328 |
2/2✓ Branch 0 taken 17158 times.
✓ Branch 1 taken 32 times.
|
17190 | if (m_warn_if_bridging) { |
| 1329 | // Called for every bridged packet, so refresh the warning at most | ||
| 1330 | // once a second rather than taking the warnings lock (and logging) | ||
| 1331 | // hundreds of times a second. The 60s timeout still tracks the | ||
| 1332 | // last packet to within a second. | ||
| 1333 | static std::atomic<long long> lastWarnMS{ 0 }; | ||
| 1334 |
1/2✓ Branch 0 taken 17158 times.
✗ Branch 1 not taken.
|
17158 | long long now = GetMonotonicTimeMS(); |
| 1335 | 17158 | long long last = lastWarnMS.load(std::memory_order_relaxed); | |
| 1336 |
5/6✓ Branch 0 taken 17 times.
✓ Branch 1 taken 17141 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✓ Branch 5 taken 17141 times.
|
17175 | if (now - last >= 1000 && lastWarnMS.compare_exchange_strong(last, now, std::memory_order_relaxed)) { |
| 1337 |
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.
|
68 | WarningHolder::AddWarningTimeout(60, 11, "Received bridging data while sequence is running."); |
| 1338 | } | ||
| 1339 | } | ||
| 1340 |
2/2✓ Branch 0 taken 17188 times.
✓ Branch 1 taken 2 times.
|
17190 | if (m_prioritize_sequence_over_bridge) { |
| 1341 | 17188 | return false; | |
| 1342 | } | ||
| 1343 | } | ||
| 1344 | |||
| 1345 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51440 times.
|
51440 | if (!m_bridgeData) { |
| 1346 | ✗ | return false; | |
| 1347 | } | ||
| 1348 | // Guard against out-of-range bridging data. The bound is the real | ||
| 1349 | // channels, FPPD_MAX_CHANNELS: the bytes after them are the reserved OFF | ||
| 1350 | // and WHITE channels, which outputs read as "always 0" for null pixels and | ||
| 1351 | // smart-receiver lead-in/out, and bridged data merged into them turned | ||
| 1352 | // those on. Unsigned arithmetic avoids overflow. | ||
| 1353 |
2/4✓ Branch 0 taken 51440 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51440 times.
✗ Branch 3 not taken.
|
51440 | if (startChannel < 0 || len < 0 || |
| 1354 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51440 times.
|
51440 | ((unsigned long long)startChannel + (unsigned long long)len) > (unsigned long long)FPPD_MAX_CHANNELS) { |
| 1355 | ✗ | return false; | |
| 1356 | } | ||
| 1357 | // Under the ranges lock, which ProcessSequenceData() holds while it | ||
| 1358 | // copies the bridge buffer out: a packet landing mid-copy sent a universe | ||
| 1359 | // half old, half new. | ||
| 1360 |
1/2✓ Branch 0 taken 51440 times.
✗ Branch 1 not taken.
|
51440 | std::unique_lock<std::mutex> lock(m_bridgeRangesLock); |
| 1361 | 51440 | memcpy(&m_bridgeData[startChannel], data, len); | |
| 1362 | 51440 | return true; | |
| 1363 | 51440 | } | |
| 1364 | |||
| 1365 | 18912 | void Sequence::CommitBridgeRanges(const std::vector<std::pair<uint32_t, uint32_t>>& ranges, uint64_t expireMS) { | |
| 1366 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18912 times.
|
18912 | if (ranges.empty()) { |
| 1367 | ✗ | return; | |
| 1368 | } | ||
| 1369 |
1/2✓ Branch 0 taken 18912 times.
✗ Branch 1 not taken.
|
18912 | std::unique_lock<std::mutex> lock(m_bridgeRangesLock); |
| 1370 |
2/2✓ Branch 0 taken 51440 times.
✓ Branch 1 taken 18912 times.
|
70352 | for (auto& r : ranges) { |
| 1371 |
1/2✓ Branch 0 taken 51440 times.
✗ Branch 1 not taken.
|
51440 | auto& a = m_bridgeRanges[r.first]; |
| 1372 | 51440 | a.startChannel = r.first; | |
| 1373 |
1/2✓ Branch 0 taken 51440 times.
✗ Branch 1 not taken.
|
51440 | a.expires[r.second] = expireMS; |
| 1374 | } | ||
| 1375 | 18912 | m_hasBridgeRanges.store(true, std::memory_order_relaxed); | |
| 1376 |
1/2✓ Branch 0 taken 18912 times.
✗ Branch 1 not taken.
|
18912 | lock.unlock(); |
| 1377 | |||
| 1378 | 18912 | setDataNotProcessed(); | |
| 1379 | 18912 | } | |
| 1380 | |||
| 1381 | ✗ | void Sequence::SetBridgeData(uint8_t* data, int startChannel, int len, uint64_t expireMS) { | |
| 1382 | ✗ | if (!WriteBridgeData(data, startChannel, len)) { | |
| 1383 | ✗ | return; | |
| 1384 | } | ||
| 1385 | ✗ | std::unique_lock<std::mutex> lock(m_bridgeRangesLock); | |
| 1386 | ✗ | auto& a = m_bridgeRanges[startChannel]; | |
| 1387 | ✗ | a.startChannel = startChannel; | |
| 1388 | ✗ | a.expires[len] = expireMS; | |
| 1389 | ✗ | m_hasBridgeRanges.store(true, std::memory_order_relaxed); | |
| 1390 | ✗ | lock.unlock(); | |
| 1391 | |||
| 1392 | ✗ | setDataNotProcessed(); | |
| 1393 | ✗ | } | |
| 1394 | |||
| 1395 | 914211 | bool Sequence::hasBridgeData() { | |
| 1396 | 914211 | return m_hasBridgeRanges.load(std::memory_order_relaxed); | |
| 1397 | } | ||
| 1398 |