| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 10 | * included LICENSE.LGPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #include "Warnings.h" // WarningHolder -- needed directly for NOPCH builds | ||
| 18 | |||
| 19 | #include <filesystem> | ||
| 20 | #include <thread> | ||
| 21 | using namespace std::filesystem; | ||
| 22 | |||
| 23 | #include <sys/wait.h> | ||
| 24 | |||
| 25 | #include "../Events.h" | ||
| 26 | #include "../MultiSync.h" | ||
| 27 | #include "../commands/Commands.h" | ||
| 28 | #include "../Plugins.h" | ||
| 29 | #include "../channeloutput/ChannelOutputSetup.h" | ||
| 30 | #include "../common.h" | ||
| 31 | #include "../log.h" | ||
| 32 | #include "../mediadetails.h" | ||
| 33 | |||
| 34 | #include "Playlist.h" | ||
| 35 | #include "PlaylistEntryMedia.h" | ||
| 36 | |||
| 37 | int PlaylistEntryMedia::m_openStartDelay = -1; | ||
| 38 | |||
| 39 | /* | ||
| 40 | * | ||
| 41 | */ | ||
| 42 | 207 | PlaylistEntryMedia::PlaylistEntryMedia(Playlist* playlist, PlaylistEntryBase* parent) : | |
| 43 | PlaylistEntryBase(playlist, parent), | ||
| 44 | 207 | m_status(0), | |
| 45 | 207 | m_mediaOutput(NULL), | |
| 46 |
1/2✓ Branch 0 taken 207 times.
✗ Branch 1 not taken.
|
414 | m_videoOutput("--Default--"), |
| 47 | 207 | m_streamSlot(1), | |
| 48 | 207 | m_slotStatus(&mediaOutputStatus), | |
| 49 | 207 | m_openTime(0), | |
| 50 |
1/2✓ Branch 0 taken 207 times.
✗ Branch 1 not taken.
|
414 | m_fileMode("single"), |
| 51 | 207 | m_duration(0), | |
| 52 | 621 | m_pausedTime(-1) { | |
| 53 |
1/2✓ Branch 0 taken 207 times.
✗ Branch 1 not taken.
|
207 | LogDebug(VB_PLAYLIST, "PlaylistEntryMedia::PlaylistEntryMedia()\n"); |
| 54 |
2/2✓ Branch 0 taken 105 times.
✓ Branch 1 taken 102 times.
|
207 | if (m_openStartDelay == -1) { |
| 55 |
1/2✓ Branch 0 taken 105 times.
✗ Branch 1 not taken.
|
105 | m_openStartDelay = getSettingInt("openStartDelay"); |
| 56 | } | ||
| 57 |
1/2✓ Branch 0 taken 207 times.
✗ Branch 1 not taken.
|
207 | m_type = "media"; |
| 58 | // entries made in the same second must not draw the same "random" file | ||
| 59 | 207 | m_fileSeed = (unsigned int)(time(NULL) + ((long long)this & 0xFFFFFFFF)); | |
| 60 | 207 | } | |
| 61 | |||
| 62 | /* | ||
| 63 | * | ||
| 64 | */ | ||
| 65 | 644 | PlaylistEntryMedia::~PlaylistEntryMedia() { | |
| 66 | // Companion streams belong to this entry; deleting a playing entry | ||
| 67 | // (Playlist::Cleanup() doesn't Stop() first) left them playing. | ||
| 68 | 322 | StopExtraMedia(); | |
| 69 | |||
| 70 | // Playlist::Cleanup() deletes entries without calling Stop() first — if | ||
| 71 | // media was still open the output object (and its live GStreamer | ||
| 72 | // pipeline) leaked. Swap under the lock, tear down outside it, same | ||
| 73 | // discipline as CloseMediaOutput(). | ||
| 74 | 322 | MediaOutputBase* out = nullptr; | |
| 75 | { | ||
| 76 | 322 | std::lock_guard<std::mutex> lock(m_mediaOutputLock); | |
| 77 | 322 | out = m_mediaOutput; | |
| 78 | 322 | m_mediaOutput = nullptr; | |
| 79 | 322 | } | |
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 161 times.
|
322 | delete out; |
| 81 | 644 | } | |
| 82 | |||
| 83 | /* | ||
| 84 | * | ||
| 85 | */ | ||
| 86 | 207 | int PlaylistEntryMedia::Init(Json::Value& config) { | |
| 87 | 207 | LogDebug(VB_PLAYLIST, "PlaylistEntryMedia::Init()\n"); | |
| 88 | |||
| 89 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 161 times.
|
207 | if (config.isMember("fileMode")) { |
| 90 |
2/4✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
|
46 | m_fileMode = config["fileMode"].asString(); |
| 91 | } | ||
| 92 | |||
| 93 |
2/2✓ Branch 0 taken 161 times.
✓ Branch 1 taken 46 times.
|
207 | if (m_fileMode == "single") { |
| 94 |
1/2✓ Branch 0 taken 161 times.
✗ Branch 1 not taken.
|
161 | if (config.isMember("mediaName")) { |
| 95 |
2/4✓ Branch 0 taken 161 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 161 times.
✗ Branch 3 not taken.
|
161 | m_mediaFilename = config["mediaName"].asString(); |
| 96 | } else { | ||
| 97 | ✗ | LogErr(VB_PLAYLIST, "Missing mediaName entry\n"); | |
| 98 | ✗ | return 0; | |
| 99 | } | ||
| 100 | } else { | ||
| 101 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 34 times.
|
46 | if (config.isMember("mediaPrefix")) { |
| 102 |
2/4✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
12 | m_mediaPrefix = config["mediaPrefix"].asString(); |
| 103 | } | ||
| 104 |
2/2✓ Branch 0 taken 45 times.
✓ Branch 1 taken 1 times.
|
46 | if (GetFileList()) { |
| 105 |
1/2✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
|
45 | m_mediaFilename = GetNextRandomFile(); |
| 106 | } else { | ||
| 107 | 1 | LogErr(VB_PLAYLIST, "Error, no files found when trying to play random file in %s mode\n", | |
| 108 | m_fileMode.c_str()); | ||
| 109 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | WarningHolder::AddWarningTimeout(60, 30, "No media files found to play in '" + m_fileMode + "' mode"); |
| 110 | 1 | return 0; | |
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 158 times.
|
206 | if (config.isMember("videoOut")) { |
| 115 |
2/4✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | m_videoOutput = config["videoOut"].asString(); |
| 116 | } | ||
| 117 | |||
| 118 | // Companion streams to run alongside this entry (see ExtraMedia). | ||
| 119 | 206 | m_extraMedia.clear(); | |
| 120 |
5/6✓ Branch 0 taken 3 times.
✓ Branch 1 taken 203 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 203 times.
|
206 | if (config.isMember("extraMedia") && config["extraMedia"].isArray()) { |
| 121 |
8/14✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✓ Branch 13 taken 3 times.
|
6 | for (const auto& e : config["extraMedia"]) { |
| 122 | 3 | ExtraMedia em; | |
| 123 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | em.mediaName = e.get("mediaName", "").asString(); |
| 124 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (em.mediaName.empty()) |
| 125 | ✗ | continue; | |
| 126 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | em.slot = e.get("slot", 2).asInt(); |
| 127 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | if (em.slot < 2 || em.slot > StreamSlotManager::MAX_SLOTS) { |
| 128 | ✗ | LogWarn(VB_PLAYLIST, "Media entry: extraMedia '%s' has slot %d; must be 2-%d (slot 1 is this entry's own media), skipping\n", | |
| 129 | em.mediaName.c_str(), em.slot, StreamSlotManager::MAX_SLOTS); | ||
| 130 | ✗ | continue; | |
| 131 | } | ||
| 132 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | em.videoOut = e.get("videoOut", "").asString(); |
| 133 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | em.sync = e.get("sync", false).asBool(); |
| 134 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | m_extraMedia.push_back(em); |
| 135 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | } |
| 136 | } | ||
| 137 | // Flat single-companion form, which is what the playlist editor writes -- | ||
| 138 | // the editor rebuilds an entry from the fields it knows about, so a | ||
| 139 | // hand-authored "extraMedia" array survives fppd but not a round trip | ||
| 140 | // through the UI. One companion covers both things this was asked for (a | ||
| 141 | // second audio feed on another device, a second video on another HDMI), so | ||
| 142 | // that case gets real fields and the array stays the advanced escape hatch. | ||
| 143 |
10/16✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 204 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 204 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 204 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
206 | if (config.isMember("extraMediaName") && !config["extraMediaName"].asString().empty()) { |
| 144 | 2 | ExtraMedia em; | |
| 145 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | em.mediaName = config["extraMediaName"].asString(); |
| 146 | // The slot is the output route -- which audio device a companion lands | ||
| 147 | // on is set per slot in the PipeWire audio groups, not per entry. The | ||
| 148 | // editor writes this as a string; hand-authored playlists may use an | ||
| 149 | // int, and asInt() on a string throws, so handle both. | ||
| 150 | 2 | em.slot = 2; | |
| 151 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | if (config.isMember("extraMediaSlot")) { |
| 152 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | const Json::Value& sv = config["extraMediaSlot"]; |
| 153 |
6/16✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
2 | int s = sv.isString() ? atoi(sv.asString().c_str()) : (sv.isIntegral() ? sv.asInt() : 0); |
| 154 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | if (s >= 2 && s <= StreamSlotManager::MAX_SLOTS) { |
| 155 | 2 | em.slot = s; | |
| 156 | ✗ | } else if (s != 0) { | |
| 157 | ✗ | LogWarn(VB_PLAYLIST, "Media entry: extraMediaSlot %d out of range, using slot 2\n", s); | |
| 158 | } | ||
| 159 | } | ||
| 160 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | em.videoOut = config.get("extraMediaOut", "").asString(); |
| 161 | 2 | em.sync = true; // it belongs to the show; sync is only a repair path | |
| 162 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | m_extraMedia.push_back(em); |
| 163 | 2 | } | |
| 164 | |||
| 165 | // Stream slot (1-5), default 1. Slot > 1 plays on a separate PipeWire stream. | ||
| 166 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 205 times.
|
206 | if (config.isMember("streamSlot")) { |
| 167 | 1 | m_streamSlot = config["streamSlot"].asInt(); | |
| 168 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (m_streamSlot < 1) m_streamSlot = 1; |
| 169 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (m_streamSlot > StreamSlotManager::MAX_SLOTS) m_streamSlot = StreamSlotManager::MAX_SLOTS; |
| 170 | } | ||
| 171 | 206 | m_slotStatus = StreamSlotManager::Instance().GetStatus(m_streamSlot); | |
| 172 | |||
| 173 | 206 | m_pausedTime = -1; | |
| 174 | 206 | return PlaylistEntryBase::Init(config); | |
| 175 | } | ||
| 176 | |||
| 177 | 242 | int PlaylistEntryMedia::PreparePlay() { | |
| 178 | 242 | LogDebug(VB_PLAYLIST, "PlaylistEntryMedia::PreparePlay()\n"); | |
| 179 | |||
| 180 |
4/6✓ Branch 0 taken 230 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 230 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 242 times.
|
242 | if (!m_resuming && !CanPlay()) { |
| 181 | ✗ | FinishPlay(); | |
| 182 | ✗ | return 0; | |
| 183 | } | ||
| 184 | { | ||
| 185 | // mediaSeconds too: it still holds where the previous media on this | ||
| 186 | // slot ended, and StartPlaying() takes it as a lower bound for | ||
| 187 | // m_duration -- a longer clip before this one became this entry's | ||
| 188 | // length. A resume restores the whole slot status after this. | ||
| 189 |
1/2✓ Branch 0 taken 242 times.
✗ Branch 1 not taken.
|
242 | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); |
| 190 | 242 | m_slotStatus->minutesTotal = 0; | |
| 191 | 242 | m_slotStatus->secondsTotal = 0; | |
| 192 | 242 | m_slotStatus->secondsElapsed = 0; | |
| 193 | 242 | m_slotStatus->subSecondsElapsed = 0; | |
| 194 | 242 | m_slotStatus->mediaSeconds = 0.0; | |
| 195 | 242 | } | |
| 196 | |||
| 197 |
8/8✓ Branch 0 taken 48 times.
✓ Branch 1 taken 194 times.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 29 times.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 226 times.
|
242 | if ((m_fileMode != "single") && !m_resuming && !m_preparedFile.empty()) { |
| 198 | // Drawn when this entry was prepared, and its media made ready. | ||
| 199 | 16 | m_mediaFilename = m_preparedFile; | |
| 200 | 16 | m_preparedFile.clear(); | |
| 201 |
6/6✓ Branch 0 taken 32 times.
✓ Branch 1 taken 194 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 29 times.
✓ Branch 5 taken 197 times.
|
226 | } else if ((m_fileMode != "single") && !m_resuming) { |
| 202 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 3 times.
|
29 | if (m_files.size()) { |
| 203 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | m_mediaFilename = GetNextRandomFile(); |
| 204 | } else { | ||
| 205 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (GetFileList()) { |
| 206 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | m_mediaFilename = GetNextRandomFile(); |
| 207 | } else { | ||
| 208 | 1 | LogErr(VB_PLAYLIST, "Error, no files found when trying to play random file in %s mode\n", | |
| 209 | m_fileMode.c_str()); | ||
| 210 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | WarningHolder::AddWarningTimeout(60, 30, "No media files found to play in '" + m_fileMode + "' mode"); |
| 211 | 1 | return 0; | |
| 212 | } | ||
| 213 | } | ||
| 214 | } | ||
| 215 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 241 times.
|
241 | if (!OpenMediaOutput()) { |
| 216 | ✗ | FinishPlay(); | |
| 217 | ✗ | return 0; | |
| 218 | } | ||
| 219 | |||
| 220 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 228 times.
|
241 | if (multiSync->isMultiSyncEnabled()) { |
| 221 | 13 | multiSync->SendMediaOpenPacket(m_mediaFilename); | |
| 222 | } | ||
| 223 | |||
| 224 | 241 | m_openTime = GetMonotonicTimeMS(); | |
| 225 |
2/4✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 241 times.
✗ Branch 3 not taken.
|
664 | Events::Publish("playlist/media/status", m_mediaFilename); |
| 226 |
2/4✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 241 times.
✗ Branch 3 not taken.
|
482 | Events::Publish("playlist/media/title", MediaDetails::INSTANCE.title); |
| 227 |
2/4✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 241 times.
✗ Branch 3 not taken.
|
241 | Events::Publish("playlist/media/artist", MediaDetails::INSTANCE.artist); |
| 228 | 241 | return 1; | |
| 229 | } | ||
| 230 | |||
| 231 | 91 | void PlaylistEntryMedia::PrepareAhead() { | |
| 232 |
2/4✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 91 times.
|
91 | if (!CanPlay()) { |
| 233 | 1 | return; | |
| 234 | } | ||
| 235 |
1/2✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
|
91 | std::string file = m_mediaFilename; |
| 236 |
3/4✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 74 times.
|
91 | if (m_fileMode != "single") { |
| 237 | // Draw the random file now, and keep it for PreparePlay(). | ||
| 238 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | if (m_preparedFile.empty()) { |
| 239 |
7/8✓ Branch 0 taken 8 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 16 times.
|
17 | if (m_files.empty() && !GetFileList()) { |
| 240 | 1 | return; | |
| 241 | } | ||
| 242 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | m_preparedFile = GetNextRandomFile(); |
| 243 | } | ||
| 244 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | file = m_preparedFile; |
| 245 | } | ||
| 246 |
2/4✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✗ Branch 3 not taken.
|
90 | PrepareMediaOutput(file, ResolveVideoOutput(m_videoOutput), m_streamSlot); |
| 247 | // Remotes too, whatever this plays here: a remote may show a video of the | ||
| 248 | // same name for a song. The same name its Open will carry (PreparePlay()). | ||
| 249 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 89 times.
|
90 | if (multiSync->isMultiSyncEnabled()) { |
| 250 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | multiSync->SendMediaPreparePacket(file); |
| 251 | } | ||
| 252 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 1 times.
|
91 | } |
| 253 | |||
| 254 | /* | ||
| 255 | * | ||
| 256 | */ | ||
| 257 | 230 | int PlaylistEntryMedia::StartPlaying(void) { | |
| 258 |
1/2✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
|
230 | LogDebug(VB_PLAYLIST, "PlaylistEntryMedia::StartPlaying()\n"); |
| 259 | |||
| 260 |
6/6✓ Branch 0 taken 13 times.
✓ Branch 1 taken 217 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 225 times.
|
230 | if (multiSync->isMultiSyncEnabled() && m_openTime) { |
| 261 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | long long st = GetMonotonicTimeMS() - m_openTime; |
| 262 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (st < m_openStartDelay) { |
| 263 | ✗ | std::this_thread::sleep_for(std::chrono::milliseconds(m_openStartDelay - st)); | |
| 264 | } | ||
| 265 | } | ||
| 266 | |||
| 267 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 78 times.
|
230 | if (m_mediaOutput == nullptr) { |
| 268 |
3/4✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 151 times.
|
152 | if (PreparePlay() == 0) { |
| 269 | 1 | return 0; | |
| 270 | } | ||
| 271 | } | ||
| 272 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
|
229 | if (m_mediaOutput == nullptr) { |
| 273 | ✗ | return 0; | |
| 274 | } | ||
| 275 | |||
| 276 | // The status is written by the output's Process() under FieldsLock(); | ||
| 277 | // copy it under the same lock before using it here on the playlist thread. | ||
| 278 | 229 | MediaOutputStatus status; | |
| 279 | { | ||
| 280 |
1/2✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
|
229 | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); |
| 281 |
1/2✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
|
229 | status = *m_slotStatus; |
| 282 | 229 | } | |
| 283 | 229 | float f = status.mediaSeconds * 1000; | |
| 284 | 229 | uint64_t duration = m_duration.load(); | |
| 285 |
2/2✓ Branch 0 taken 202 times.
✓ Branch 1 taken 27 times.
|
229 | if (duration == 0) { |
| 286 | 202 | float total = status.minutesTotal * 60 + status.secondsTotal; | |
| 287 | 202 | total *= 1000; | |
| 288 | 202 | duration = total; | |
| 289 | 202 | m_duration.store(duration); | |
| 290 | } | ||
| 291 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
|
229 | if (f > duration) { |
| 292 | ✗ | duration = f; | |
| 293 | ✗ | m_duration.store(duration); | |
| 294 | } | ||
| 295 |
1/2✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
|
229 | std::unique_lock<std::mutex> lock(m_mediaOutputLock); |
| 296 | |||
| 297 |
6/6✓ Branch 0 taken 219 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 207 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 217 times.
|
229 | if (m_mediaOutput->getMediaOffsetMS() <= 0 && multiSync->isMultiSyncEnabled()) { |
| 298 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | multiSync->SendMediaSyncStartPacket(m_mediaFilename); |
| 299 | } | ||
| 300 | |||
| 301 |
1/2✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
|
229 | ResetChannelOutputFrameNumber(); |
| 302 |
3/4✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 227 times.
|
229 | if (!m_mediaOutput->Start()) { |
| 303 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogErr(VB_MEDIAOUT, "Could not start media %s\n", m_mediaOutput->m_mediaFilename.c_str()); |
| 304 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | WarningHolder::AddWarningTimeout(60, 30, "Could not start media " + m_mediaOutput->m_mediaFilename); |
| 305 | // Swap-unlock-delete: the delete runs the full GStreamer teardown | ||
| 306 | // (sleeps plus a state change that can block indefinitely on a | ||
| 307 | // wedged decoder) — doing that under m_mediaOutputLock wedges any | ||
| 308 | // thread touching this entry, including HTTP status threads that | ||
| 309 | // are holding m_playlistMutex. Same rationale as CloseMediaOutput. | ||
| 310 | 2 | MediaOutputBase* failed = m_mediaOutput; | |
| 311 | 2 | m_mediaOutput = 0; | |
| 312 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | lock.unlock(); |
| 313 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | delete failed; |
| 314 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | FinishPlay(); |
| 315 | 2 | return 0; | |
| 316 | } | ||
| 317 | |||
| 318 |
1/2✓ Branch 0 taken 227 times.
✗ Branch 1 not taken.
|
227 | lock.unlock(); |
| 319 |
1/2✓ Branch 0 taken 227 times.
✗ Branch 1 not taken.
|
227 | m_startTime = GetMonotonicTimeMS(); |
| 320 | 227 | m_soundEndMs = 0; | |
| 321 | 227 | m_syncStartSent = false; | |
| 322 |
1/2✓ Branch 0 taken 227 times.
✗ Branch 1 not taken.
|
227 | StartExtraMedia(); |
| 323 |
1/2✓ Branch 0 taken 227 times.
✗ Branch 1 not taken.
|
227 | return PlaylistEntryBase::StartPlaying(); |
| 324 | 229 | } | |
| 325 | |||
| 326 | /* | ||
| 327 | * | ||
| 328 | */ | ||
| 329 | 167804 | int PlaylistEntryMedia::Process(void) { | |
| 330 |
1/2✓ Branch 0 taken 167804 times.
✗ Branch 1 not taken.
|
167804 | std::unique_lock<std::mutex> lock(m_mediaOutputLock); |
| 331 | |||
| 332 |
1/2✓ Branch 0 taken 167804 times.
✗ Branch 1 not taken.
|
167804 | if (m_mediaOutput) { |
| 333 |
8/8✓ Branch 0 taken 163406 times.
✓ Branch 1 taken 4398 times.
✓ Branch 2 taken 1546 times.
✓ Branch 3 taken 161860 times.
✓ Branch 4 taken 21 times.
✓ Branch 5 taken 1525 times.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 167783 times.
|
167804 | if (!m_syncStartSent && m_mediaOutput->getMediaOffsetMS() > 0 && multiSync->isMultiSyncEnabled()) { |
| 334 |
1/2✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
|
21 | long long ct = GetMonotonicTimeMS() - m_startTime; |
| 335 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
|
21 | if (ct > (m_mediaOutput->getMediaOffsetMS() - 20)) { |
| 336 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | multiSync->SendMediaSyncStartPacket(m_mediaFilename); |
| 337 | 1 | m_syncStartSent = true; | |
| 338 | } | ||
| 339 | } | ||
| 340 | |||
| 341 |
1/2✓ Branch 0 taken 167804 times.
✗ Branch 1 not taken.
|
167804 | m_mediaOutput->Process(); |
| 342 |
3/4✓ Branch 0 taken 167804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✓ Branch 3 taken 167636 times.
|
167804 | if (!m_mediaOutput->IsPlaying()) { |
| 343 |
1/2✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
|
168 | m_soundEndMs = m_mediaOutput->SoundEndMS(); |
| 344 |
1/2✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
|
168 | FinishPlay(); |
| 345 |
1/2✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
|
168 | lock.unlock(); |
| 346 | // Companions are tied to this entry's lifetime, so they stop when | ||
| 347 | // the media ends naturally too -- not only on an explicit Stop(). | ||
| 348 |
1/2✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
|
168 | StopExtraMedia(); |
| 349 |
1/2✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
|
168 | CloseMediaOutput(); |
| 350 |
1/2✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
|
168 | lock.lock(); |
| 351 | } | ||
| 352 | } else { | ||
| 353 | ✗ | FinishPlay(); | |
| 354 | } | ||
| 355 | |||
| 356 |
1/2✓ Branch 0 taken 167804 times.
✗ Branch 1 not taken.
|
167804 | lock.unlock(); |
| 357 |
1/2✓ Branch 0 taken 167804 times.
✗ Branch 1 not taken.
|
335608 | return PlaylistEntryBase::Process(); |
| 358 | 167804 | } | |
| 359 | |||
| 360 | 58 | bool PlaylistEntryMedia::HasExtraAtEnd() { | |
| 361 | // m_mediaOutput can be deleted concurrently by CloseMediaOutput() (e.g. | ||
| 362 | // the HTTP status thread calling this while the playlist thread tears | ||
| 363 | // down media), so the pointer must not be dereferenced without the lock. | ||
| 364 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | std::lock_guard<std::mutex> lock(m_mediaOutputLock); |
| 365 | 58 | bool result = false; | |
| 366 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 54 times.
|
58 | if (m_mediaOutput) { |
| 367 | 4 | result = m_mediaOutput->getMediaOffsetMS() < 0; | |
| 368 | } | ||
| 369 | 58 | return result; | |
| 370 | 58 | } | |
| 371 | 874 | bool PlaylistEntryMedia::IsAudible() { | |
| 372 |
1/2✓ Branch 0 taken 874 times.
✗ Branch 1 not taken.
|
874 | std::lock_guard<std::mutex> lock(m_mediaOutputLock); |
| 373 |
4/6✓ Branch 0 taken 874 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 874 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 65 times.
✓ Branch 5 taken 809 times.
|
1748 | return !m_mediaOutput || m_mediaOutput->IsAudible(); |
| 374 | 874 | } | |
| 375 | 130875 | int32_t PlaylistEntryMedia::GetMediaOffsetMS() { | |
| 376 |
1/2✓ Branch 0 taken 130875 times.
✗ Branch 1 not taken.
|
130875 | std::lock_guard<std::mutex> lock(m_mediaOutputLock); |
| 377 | 130875 | int32_t result = 0; | |
| 378 |
2/2✓ Branch 0 taken 130821 times.
✓ Branch 1 taken 54 times.
|
130875 | if (m_mediaOutput) { |
| 379 | 130821 | result = m_mediaOutput->getMediaOffsetMS(); | |
| 380 | } | ||
| 381 | 130875 | return result; | |
| 382 | 130875 | } | |
| 383 | |||
| 384 | 190834 | uint64_t PlaylistEntryMedia::GetLengthInMS() { | |
| 385 | 190834 | uint64_t duration = m_duration.load(); | |
| 386 |
2/2✓ Branch 0 taken 1698 times.
✓ Branch 1 taken 189136 times.
|
190834 | if (duration == 0) { |
| 387 |
1/2✓ Branch 0 taken 1698 times.
✗ Branch 1 not taken.
|
1698 | MediaDetails details; |
| 388 |
1/2✓ Branch 0 taken 1698 times.
✗ Branch 1 not taken.
|
1698 | details.ParseMedia(m_mediaFilename.c_str()); |
| 389 | 1698 | duration = details.lengthMS; | |
| 390 | 1698 | m_duration.store(duration); | |
| 391 | 1698 | } | |
| 392 | // Always try to refine from the running media output status. | ||
| 393 | // Some backends (e.g. GStreamer) may not have the duration available | ||
| 394 | // immediately at Start(), so minutesTotal/secondsTotal get populated | ||
| 395 | // asynchronously. Re-checking here prevents GetElapsedMS()'s | ||
| 396 | // "if (f > m_duration)" guard from permanently caching a wrong value | ||
| 397 | // (i.e., the elapsed time) before the real duration was known. | ||
| 398 | // FieldsLock() is a leaf: copy the fields, then release it before any | ||
| 399 | // other lock or a call into MediaDetails. | ||
| 400 | 190834 | MediaOutputStatus status; | |
| 401 | { | ||
| 402 |
1/2✓ Branch 0 taken 190834 times.
✗ Branch 1 not taken.
|
190834 | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); |
| 403 |
1/2✓ Branch 0 taken 190834 times.
✗ Branch 1 not taken.
|
190834 | status = *m_slotStatus; |
| 404 | 190834 | } | |
| 405 |
4/4✓ Branch 0 taken 108714 times.
✓ Branch 1 taken 82120 times.
✓ Branch 2 taken 105057 times.
✓ Branch 3 taken 3657 times.
|
190834 | if (status.minutesTotal > 0 || status.secondsTotal > 0) { |
| 406 | 187177 | uint64_t d = ((uint64_t)status.minutesTotal * 60 + status.secondsTotal) * 1000; | |
| 407 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 187129 times.
|
187177 | if (d > duration) { |
| 408 | 48 | duration = d; | |
| 409 | 48 | m_duration.store(duration); | |
| 410 | } | ||
| 411 | } | ||
| 412 | 190834 | return duration; | |
| 413 | 190834 | } | |
| 414 | 213876 | uint64_t PlaylistEntryMedia::GetElapsedMS() { | |
| 415 | // Before m_mediaOutput: Pause() closes the media output. | ||
| 416 | 213876 | int paused = m_pausedTime.load(); | |
| 417 |
2/2✓ Branch 0 taken 8634 times.
✓ Branch 1 taken 205242 times.
|
213876 | if (paused >= 0) { |
| 418 | 8634 | return paused; | |
| 419 | } | ||
| 420 | // The output can be deleted by CloseMediaOutput() on another thread, so | ||
| 421 | // only test the pointer under its lock -- the fields come from the status | ||
| 422 | // snapshot below, exactly as GetConfig() does. | ||
| 423 | bool hasMediaOutput; | ||
| 424 | { | ||
| 425 |
1/2✓ Branch 0 taken 205242 times.
✗ Branch 1 not taken.
|
205242 | std::lock_guard<std::mutex> lock(m_mediaOutputLock); |
| 426 | 205242 | hasMediaOutput = (m_mediaOutput != nullptr); | |
| 427 | 205242 | } | |
| 428 |
2/2✓ Branch 0 taken 174 times.
✓ Branch 1 taken 205068 times.
|
205242 | if (!hasMediaOutput) { |
| 429 | 174 | return 0; | |
| 430 | } | ||
| 431 | 205068 | MediaOutputStatus status; | |
| 432 | { | ||
| 433 |
1/2✓ Branch 0 taken 205068 times.
✗ Branch 1 not taken.
|
205068 | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); |
| 434 |
1/2✓ Branch 0 taken 205068 times.
✗ Branch 1 not taken.
|
205068 | status = *m_slotStatus; |
| 435 | 205068 | } | |
| 436 | 205068 | float f = status.secondsElapsed * 1000; | |
| 437 | 205068 | f += status.subSecondsElapsed * 10; // subSec is in 1/100th second | |
| 438 | 205068 | uint64_t duration = m_duration.load(); | |
| 439 |
2/2✓ Branch 0 taken 1578 times.
✓ Branch 1 taken 203490 times.
|
205068 | if (duration == 0) { |
| 440 | 1578 | float d = status.minutesTotal * 60 + status.secondsTotal; | |
| 441 | 1578 | d *= 1000; | |
| 442 | 1578 | duration = d; | |
| 443 | 1578 | m_duration.store(duration); | |
| 444 | } | ||
| 445 |
2/2✓ Branch 0 taken 379 times.
✓ Branch 1 taken 204689 times.
|
205068 | if (f > duration) { |
| 446 | 379 | duration = f; | |
| 447 | 379 | m_duration.store(duration); | |
| 448 | } | ||
| 449 | 205068 | return f; | |
| 450 | 205068 | } | |
| 451 | |||
| 452 | /* | ||
| 453 | * | ||
| 454 | */ | ||
| 455 | // Start/stop are delegated to the existing Play Media / Stop Media Slot | ||
| 456 | // commands rather than reimplementing slot setup here: those already handle | ||
| 457 | // registration, teardown and the sync flag, and reusing them keeps one code | ||
| 458 | // path for "play something on a slot". | ||
| 459 | 239 | void PlaylistEntryMedia::StartExtraMedia(int startMS) { | |
| 460 |
5/6✓ Branch 0 taken 7 times.
✓ Branch 1 taken 232 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 232 times.
✓ Branch 5 taken 7 times.
|
239 | if (m_extraMedia.empty() || m_extraMediaStarted) |
| 461 | 232 | return; | |
| 462 | 7 | m_extraMediaStarted = true; | |
| 463 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
14 | for (const auto& em : m_extraMedia) { |
| 464 | std::vector<std::string> args = { | ||
| 465 | 7 | em.mediaName, | |
| 466 | "1", // play once; it is stopped with the entry | ||
| 467 | "0", // no volume adjustment | ||
| 468 | 7 | std::to_string(em.slot), | |
| 469 | 7 | em.videoOut, | |
| 470 | 7 | em.sync ? "true" : "false" | |
| 471 |
3/6✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
56 | }; |
| 472 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
7 | LogDebug(VB_PLAYLIST, "Media entry: starting extra media '%s' on slot %d (videoOut='%s'%s)\n", |
| 473 | em.mediaName.c_str(), em.slot, em.videoOut.c_str(), | ||
| 474 | em.sync ? ", synced" : ""); | ||
| 475 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
7 | CommandManager::INSTANCE.run("Play Media", args); |
| 476 | |||
| 477 | // Resuming mid-entry: "Play Media" always starts at zero, so put the | ||
| 478 | // companion back on the entry's timeline explicitly. Waiting for the | ||
| 479 | // sync repair path is not enough -- it only acts past MAX_DRIFT_SEC, | ||
| 480 | // and only for companions that opted into sync at all. | ||
| 481 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
|
7 | if (startMS > 0) { |
| 482 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | StreamSlotManager::Instance().SeekSlot(em.slot, startMS / 1000.0f); |
| 483 | } | ||
| 484 | 7 | } | |
| 485 |
7/16✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
14 | } |
| 486 | |||
| 487 | 429 | void PlaylistEntryMedia::StopExtraMedia(void) { | |
| 488 |
2/2✓ Branch 0 taken 423 times.
✓ Branch 1 taken 6 times.
|
429 | if (!m_extraMediaStarted) |
| 489 | 423 | return; | |
| 490 | 6 | m_extraMediaStarted = false; | |
| 491 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | for (const auto& em : m_extraMedia) { |
| 492 |
3/6✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
18 | std::vector<std::string> args = { std::to_string(em.slot) }; |
| 493 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | LogDebug(VB_COMMAND, "Media entry: stopping extra media '%s', running \"Stop Media Slot\" on slot %d\n", em.mediaName.c_str(), em.slot); |
| 494 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | CommandManager::INSTANCE.run("Stop Media Slot", args); |
| 495 | 6 | } | |
| 496 |
0/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6 | } |
| 497 | |||
| 498 | 88 | int PlaylistEntryMedia::Stop(void) { | |
| 499 | 88 | LogDebug(VB_PLAYLIST, "PlaylistEntryMedia::Stop()\n"); | |
| 500 | |||
| 501 | 88 | StopExtraMedia(); | |
| 502 | 88 | CloseMediaOutput(); | |
| 503 | |||
| 504 |
3/6✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88 times.
✗ Branch 5 not taken.
|
352 | Events::Publish("playlist/media/status", ""); |
| 505 |
3/6✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88 times.
✗ Branch 5 not taken.
|
352 | Events::Publish("playlist/media/title", ""); |
| 506 |
3/6✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88 times.
✗ Branch 5 not taken.
|
264 | Events::Publish("playlist/media/artist", ""); |
| 507 | |||
| 508 | { | ||
| 509 |
1/2✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
|
88 | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); |
| 510 | 88 | m_slotStatus->minutesTotal = 0; | |
| 511 | 88 | m_slotStatus->secondsTotal = 0; | |
| 512 | 88 | m_slotStatus->secondsElapsed = 0; | |
| 513 | 88 | m_slotStatus->subSecondsElapsed = 0; | |
| 514 | 88 | m_slotStatus->mediaSeconds = 0.0; | |
| 515 | 88 | } | |
| 516 | |||
| 517 | 88 | return PlaylistEntryBase::Stop(); | |
| 518 | } | ||
| 519 | |||
| 520 | /* | ||
| 521 | * | ||
| 522 | */ | ||
| 523 | ✗ | void PlaylistEntryMedia::Dump(void) { | |
| 524 | ✗ | PlaylistEntryBase::Dump(); | |
| 525 | |||
| 526 | ✗ | LogDebug(VB_PLAYLIST, "Media Filename: %s\n", m_mediaFilename.c_str()); | |
| 527 | ✗ | } | |
| 528 | |||
| 529 | /* | ||
| 530 | * | ||
| 531 | */ | ||
| 532 | 241 | int PlaylistEntryMedia::OpenMediaOutput(void) { | |
| 533 |
1/2✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
|
241 | LogDebug(VB_PLAYLIST, "PlaylistEntryMedia::OpenMediaOutput() - Starting\n"); |
| 534 | |||
| 535 | { | ||
| 536 |
1/2✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
|
241 | std::unique_lock<std::mutex> lock(m_mediaOutputLock); |
| 537 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 241 times.
|
241 | if (m_mediaOutput) { |
| 538 | ✗ | lock.unlock(); | |
| 539 | ✗ | CloseMediaOutput(); | |
| 540 | } | ||
| 541 | 241 | } | |
| 542 | |||
| 543 |
1/2✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
|
241 | std::string tmpFile = m_mediaFilename; |
| 544 | 241 | std::size_t found = tmpFile.find_last_of("."); | |
| 545 | |||
| 546 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 241 times.
|
241 | if (found == std::string::npos) { |
| 547 | ✗ | LogWarn(VB_MEDIAOUT, "Unable to determine extension of media file %s\n", | |
| 548 | m_mediaFilename.c_str()); | ||
| 549 | ✗ | return 0; | |
| 550 | } | ||
| 551 | |||
| 552 |
2/4✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 241 times.
✗ Branch 3 not taken.
|
241 | std::string ext = toLowerCopy(tmpFile.substr(found + 1)); |
| 553 | |||
| 554 |
1/2✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
|
241 | LogDebug(VB_PLAYLIST, "PlaylistEntryMedia - Starting %s\n", tmpFile.c_str()); |
| 555 | |||
| 556 | // m_mediaOutputLock must NOT be held here: mediaCallback() re-enters this | ||
| 557 | // entry on the same thread via Playlist::GetInfo() -> GetCurrentEntry() -> | ||
| 558 | // GetConfig(), which takes m_mediaOutputLock. Holding it across the | ||
| 559 | // callback self-deadlocks the playlist thread (fppd hang on every media | ||
| 560 | // start). Nothing below touches m_mediaOutput until the assignment at | ||
| 561 | // the end, so the pointer needs no protection in between — only the | ||
| 562 | // final store is done under the lock. | ||
| 563 |
1/2✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
|
241 | MediaDetails::INSTANCE.ParseMedia(m_mediaFilename.c_str()); |
| 564 |
2/4✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 241 times.
✗ Branch 3 not taken.
|
241 | PluginManager::INSTANCE.mediaCallback(m_parentPlaylist->GetInfo(), MediaDetails::INSTANCE); |
| 565 | |||
| 566 |
1/2✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
|
241 | std::string vOut = ResolveVideoOutput(m_videoOutput); |
| 567 | |||
| 568 | // Ready already if it was guessed to play next (Playlist::PrepareNextIfDue()). | ||
| 569 |
1/2✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
|
241 | MediaOutputBase* out = ClaimPreparedMediaOutput(tmpFile, vOut, m_streamSlot); |
| 570 |
2/2✓ Branch 0 taken 162 times.
✓ Branch 1 taken 79 times.
|
241 | if (!out) { |
| 571 |
1/2✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
|
162 | out = CreateMediaOutput(tmpFile, vOut, m_streamSlot); |
| 572 | } | ||
| 573 | |||
| 574 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 241 times.
|
241 | if (!out) { |
| 575 | ✗ | LogDebug(VB_MEDIAOUT, "No Media Output handler for %s\n", tmpFile.c_str()); | |
| 576 | ✗ | return 0; | |
| 577 | } | ||
| 578 | |||
| 579 | { | ||
| 580 |
1/2✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
|
241 | std::lock_guard<std::mutex> lock(m_mediaOutputLock); |
| 581 | 241 | m_mediaOutput = out; | |
| 582 | 241 | } | |
| 583 | |||
| 584 |
1/2✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
|
241 | LogDebug(VB_PLAYLIST, "PlaylistEntryMedia::OpenMediaOutput() - Complete\n"); |
| 585 | |||
| 586 | 241 | return 1; | |
| 587 | 241 | } | |
| 588 | |||
| 589 | /* | ||
| 590 | * | ||
| 591 | */ | ||
| 592 | 268 | int PlaylistEntryMedia::CloseMediaOutput(void) { | |
| 593 |
1/2✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
|
268 | LogDebug(VB_PLAYLIST, "PlaylistEntryMedia::CloseMediaOutput()\n"); |
| 594 | |||
| 595 | 268 | m_slotStatus->status = MEDIAOUTPUTSTATUS_IDLE; | |
| 596 | |||
| 597 |
1/2✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
|
268 | std::unique_lock<std::mutex> lock(m_mediaOutputLock); |
| 598 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 213 times.
|
268 | if (!m_mediaOutput) { |
| 599 | 55 | return 0; | |
| 600 | } | ||
| 601 | |||
| 602 | // Swap the member into a local and null it out while still holding the | ||
| 603 | // lock, then release the lock before the blocking teardown below. | ||
| 604 | // ~GStreamerOutput() (via delete) runs GStreamerOutput::Stop(), which | ||
| 605 | // has 250ms + 150ms sleeps and a gst_element_set_state(NULL) that can | ||
| 606 | // block indefinitely if the Pi's V4L2 decoder wedges (issue #2695). | ||
| 607 | // Holding m_mediaOutputLock across that would stall any other thread | ||
| 608 | // touching this entry (HTTP status thread, Process(), etc.) for the | ||
| 609 | // same duration. | ||
| 610 | 213 | MediaOutputBase* out = m_mediaOutput; | |
| 611 | 213 | m_mediaOutput = NULL; | |
| 612 |
1/2✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
|
213 | lock.unlock(); |
| 613 | |||
| 614 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 200 times.
|
213 | if (multiSync->isMultiSyncEnabled()) |
| 615 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | multiSync->SendMediaSyncStopPacket(m_mediaFilename); |
| 616 | |||
| 617 |
1/2✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
|
213 | delete out; |
| 618 | |||
| 619 | 213 | return 1; | |
| 620 | 268 | } | |
| 621 | |||
| 622 | /* | ||
| 623 | * | ||
| 624 | */ | ||
| 625 | 57 | int PlaylistEntryMedia::GetFileList(void) { | |
| 626 | 57 | std::string dir; | |
| 627 | |||
| 628 | 57 | m_files.clear(); | |
| 629 | |||
| 630 |
2/4✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
|
57 | if (m_fileMode == "randomVideo") |
| 631 | ✗ | dir = FPP_DIR_VIDEO(""); | |
| 632 |
2/4✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
|
57 | else if (m_fileMode == "randomAudio") |
| 633 |
3/6✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
|
114 | dir = FPP_DIR_MUSIC(""); |
| 634 | |||
| 635 | // Only media files of the kind this entry plays: without a prefix every | ||
| 636 | // directory entry went in, subdirectories included, and one picked as | ||
| 637 | // "random media" failed to play. Names are kept relative to the folder, | ||
| 638 | // as a single-file entry's are, rather than as this box's full path -- | ||
| 639 | // they go out in MultiSync packets, and a remote looks them up in its own | ||
| 640 | // folder. A folder that can't be read is reported, not thrown. | ||
| 641 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | bool video = (m_fileMode == "randomVideo"); |
| 642 | 57 | std::error_code ec; | |
| 643 |
2/4✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
|
57 | for (recursive_directory_iterator it(dir, directory_options::skip_permission_denied, ec), end; |
| 644 |
6/8✓ Branch 0 taken 361 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 361 times.
✓ Branch 5 taken 57 times.
✓ Branch 6 taken 361 times.
✓ Branch 7 taken 57 times.
|
418 | !ec && it != end; it.increment(ec)) { |
| 645 | 361 | std::error_code fec; | |
| 646 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 325 times.
|
361 | if (!it->is_regular_file(fec)) { |
| 647 | 180 | continue; | |
| 648 | } | ||
| 649 |
2/4✓ Branch 0 taken 325 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 325 times.
✗ Branch 3 not taken.
|
325 | std::string ext = it->path().extension().string(); |
| 650 |
1/2✓ Branch 0 taken 325 times.
✗ Branch 1 not taken.
|
325 | if (!ext.empty()) { |
| 651 |
1/2✓ Branch 0 taken 325 times.
✗ Branch 1 not taken.
|
325 | ext.erase(0, 1); |
| 652 | } | ||
| 653 |
4/8✗ Branch 0 not taken.
✓ Branch 1 taken 325 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 325 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96 times.
✓ Branch 7 taken 229 times.
|
325 | if (video ? !IsExtensionVideo(ext) : !IsExtensionAudio(ext)) { |
| 654 | 96 | continue; | |
| 655 | } | ||
| 656 |
12/18✓ Branch 0 taken 72 times.
✓ Branch 1 taken 157 times.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 48 times.
✓ Branch 7 taken 24 times.
✓ Branch 8 taken 72 times.
✓ Branch 9 taken 157 times.
✓ Branch 10 taken 72 times.
✓ Branch 11 taken 157 times.
✓ Branch 12 taken 48 times.
✓ Branch 13 taken 181 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
229 | if (!m_mediaPrefix.empty() && it->path().stem().string().find(m_mediaPrefix) != 0) { |
| 657 | 48 | continue; | |
| 658 | } | ||
| 659 |
1/2✓ Branch 0 taken 181 times.
✗ Branch 1 not taken.
|
181 | LogDebug(VB_PLAYLIST, "match: %s\n", it->path().c_str()); |
| 660 |
4/8✓ Branch 0 taken 181 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 181 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 181 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 181 times.
✗ Branch 7 not taken.
|
181 | m_files.push_back(it->path().lexically_relative(dir).string()); |
| 661 |
2/2✓ Branch 0 taken 181 times.
✓ Branch 1 taken 144 times.
|
382 | } |
| 662 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
|
57 | if (ec) { |
| 663 | ✗ | LogWarn(VB_PLAYLIST, "Could not list %s for random media: %s\n", dir.c_str(), ec.message().c_str()); | |
| 664 | } | ||
| 665 | |||
| 666 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | LogDebug(VB_PLAYLIST, "%d files in %s directory\n", m_files.size(), dir.c_str()); |
| 667 | |||
| 668 | 114 | return m_files.size(); | |
| 669 | 57 | } | |
| 670 | |||
| 671 | /* | ||
| 672 | * | ||
| 673 | */ | ||
| 674 | 89 | std::string PlaylistEntryMedia::GetNextRandomFile(void) { | |
| 675 | 89 | std::string filename; | |
| 676 | |||
| 677 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 89 times.
|
89 | if (!m_files.size()) |
| 678 | ✗ | GetFileList(); | |
| 679 | |||
| 680 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 89 times.
|
89 | if (!m_files.size()) { |
| 681 | ✗ | LogWarn(VB_PLAYLIST, "No files found in GetNextRandomFile()\n"); | |
| 682 | ✗ | return filename; | |
| 683 | } | ||
| 684 | |||
| 685 | 89 | int i = rand_r(&m_fileSeed) % m_files.size(); | |
| 686 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | filename = m_files[i]; |
| 687 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | m_files.erase(m_files.begin() + i); |
| 688 | |||
| 689 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | LogDebug(VB_PLAYLIST, "GetNextRandomFile() = %s\n", filename.c_str()); |
| 690 | |||
| 691 | 89 | return filename; | |
| 692 | ✗ | } | |
| 693 | |||
| 694 | /* | ||
| 695 | * | ||
| 696 | */ | ||
| 697 | 659 | Json::Value PlaylistEntryMedia::GetConfig(void) { | |
| 698 |
1/2✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
|
659 | Json::Value result = PlaylistEntryBase::GetConfig(); |
| 699 | 659 | MediaOutputStatus status; | |
| 700 | { | ||
| 701 |
1/2✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
|
659 | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); |
| 702 |
4/6✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 647 times.
✓ Branch 4 taken 659 times.
✗ Branch 5 not taken.
|
659 | status = IsPaused() ? m_pausedStatus : *m_slotStatus; |
| 703 | 659 | } | |
| 704 |
2/4✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 659 times.
✗ Branch 3 not taken.
|
659 | result["mediaFilename"] = m_mediaFilename; |
| 705 |
2/4✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 659 times.
✗ Branch 3 not taken.
|
659 | result["streamSlot"] = m_streamSlot; |
| 706 | |||
| 707 | // Only need the pointer's non-null-ness here (the actual fields come | ||
| 708 | // from the already-copied "status" above), but the pointer itself can | ||
| 709 | // be deleted concurrently by CloseMediaOutput(), so check it under the | ||
| 710 | // lock rather than dereferencing/testing it unguarded. | ||
| 711 | bool hasMediaOutput; | ||
| 712 | { | ||
| 713 |
1/2✓ Branch 0 taken 659 times.
✗ Branch 1 not taken.
|
659 | std::lock_guard<std::mutex> lock(m_mediaOutputLock); |
| 714 | 659 | hasMediaOutput = (m_mediaOutput != nullptr); | |
| 715 | 659 | } | |
| 716 | |||
| 717 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 553 times.
|
659 | if (hasMediaOutput) { |
| 718 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["status"] = status.status.load(); |
| 719 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["secondsElapsed"] = status.secondsElapsed; |
| 720 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["subSecondsElapsed"] = status.subSecondsElapsed; |
| 721 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["secondsRemaining"] = status.secondsRemaining; |
| 722 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["subSecondsRemaining"] = status.subSecondsRemaining; |
| 723 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["minutesTotal"] = status.minutesTotal; |
| 724 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["secondsTotal"] = status.secondsTotal; |
| 725 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["mediaSeconds"] = status.mediaSeconds; |
| 726 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["mediaSeconds"] = status.mediaSeconds; |
| 727 |
2/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | result["millisecondsElapsed"] = status.secondsElapsed * 1000 + status.subSecondsElapsed * 10; |
| 728 | } | ||
| 729 | |||
| 730 | 659 | return result; | |
| 731 | 659 | } | |
| 732 | |||
| 733 | ✗ | Json::Value PlaylistEntryMedia::GetMqttStatus(void) { | |
| 734 | ✗ | Json::Value result = PlaylistEntryBase::GetMqttStatus(); | |
| 735 | ✗ | MediaOutputStatus status; | |
| 736 | { | ||
| 737 | ✗ | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); | |
| 738 | ✗ | status = IsPaused() ? m_pausedStatus : *m_slotStatus; | |
| 739 | ✗ | } | |
| 740 | ✗ | result["secondsElapsed"] = status.secondsElapsed; | |
| 741 | ✗ | result["millisecondsElapsed"] = status.secondsElapsed * 1000 + status.subSecondsElapsed * 10; | |
| 742 | ✗ | result["secondsRemaining"] = status.secondsRemaining; | |
| 743 | ✗ | result["secondsTotal"] = status.minutesTotal * 60 + status.secondsTotal; | |
| 744 | ✗ | result["mediaName"] = m_mediaFilename; | |
| 745 | ✗ | result["mediaTitle"] = MediaDetails::INSTANCE.title; | |
| 746 | ✗ | result["mediaArtist"] = MediaDetails::INSTANCE.artist; | |
| 747 | |||
| 748 | ✗ | return result; | |
| 749 | ✗ | } | |
| 750 | |||
| 751 | 12 | void PlaylistEntryMedia::Pause() { | |
| 752 | { | ||
| 753 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); |
| 754 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | m_pausedStatus = *m_slotStatus; |
| 755 | 12 | } | |
| 756 | 12 | m_pausedTime = GetElapsedMS(); | |
| 757 | // Pausing a media entry tears the output down rather than pausing the | ||
| 758 | // pipeline, so companions are stopped and rebuilt the same way; Resume() | ||
| 759 | // restarts them at m_pausedTime. | ||
| 760 | 12 | StopExtraMedia(); | |
| 761 | 12 | CloseMediaOutput(); | |
| 762 |
3/6✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
|
48 | Events::Publish("playlist/media/status", ""); |
| 763 |
3/6✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
|
48 | Events::Publish("playlist/media/title", ""); |
| 764 |
3/6✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
|
36 | Events::Publish("playlist/media/artist", ""); |
| 765 | 12 | } | |
| 766 | 336999 | bool PlaylistEntryMedia::IsPaused() { | |
| 767 | 336999 | return m_pausedTime >= 0; | |
| 768 | } | ||
| 769 | 12 | void PlaylistEntryMedia::Resume() { | |
| 770 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (m_pausedTime >= 0) { |
| 771 | // Captured before the block below clears m_pausedTime, and used to put | ||
| 772 | // the companions back at the same offset as this entry's own media. | ||
| 773 | 12 | int resumeMS = m_pausedTime; | |
| 774 | // PreparePlay()'s return is intentionally not treated as fatal here; | ||
| 775 | // if it failed, m_mediaOutput will be left null and is handled below | ||
| 776 | // instead of blindly dereferencing it. | ||
| 777 | 12 | m_resuming = true; | |
| 778 | 12 | PreparePlay(); | |
| 779 | 12 | m_resuming = false; | |
| 780 | |||
| 781 | // If Start() fails, the failed output is swapped out under the lock | ||
| 782 | // and deleted after it's released — its destructor runs the blocking | ||
| 783 | // GStreamer teardown (see CloseMediaOutput rationale). | ||
| 784 | 12 | MediaOutputBase* failed = nullptr; | |
| 785 | { | ||
| 786 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | std::lock_guard<std::mutex> lock(m_mediaOutputLock); |
| 787 | |||
| 788 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (!m_mediaOutput) { |
| 789 | // PreparePlay() couldn't (re)create the media output (e.g. file | ||
| 790 | // missing/unsupported). Nothing to resume -- still clear the | ||
| 791 | // paused state so the entry doesn't stay wedged reporting | ||
| 792 | // itself as paused forever. | ||
| 793 | ✗ | LogErr(VB_MEDIAOUT, "Could not resume media %s, no media output available\n", m_mediaFilename.c_str()); | |
| 794 | ✗ | m_pausedTime = -1; | |
| 795 | { | ||
| 796 | ✗ | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); | |
| 797 | ✗ | *m_slotStatus = m_pausedStatus; | |
| 798 | ✗ | } | |
| 799 | ✗ | return; | |
| 800 | } | ||
| 801 | |||
| 802 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (multiSync->isMultiSyncEnabled()) |
| 803 | ✗ | multiSync->SendMediaSyncStartPacket(m_mediaFilename); | |
| 804 | 12 | m_syncStartSent = true; // sent just above, offset or not | |
| 805 | |||
| 806 |
2/4✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
|
12 | if (!m_mediaOutput->Start(m_pausedTime)) { |
| 807 | ✗ | LogErr(VB_MEDIAOUT, "Could not start media %s\n", m_mediaOutput->m_mediaFilename.c_str()); | |
| 808 | ✗ | WarningHolder::AddWarningTimeout(60, 30, "Could not start media " + m_mediaOutput->m_mediaFilename); | |
| 809 | ✗ | failed = m_mediaOutput; | |
| 810 | ✗ | m_mediaOutput = nullptr; | |
| 811 | } | ||
| 812 | |||
| 813 | // Whether Start() above succeeded or failed, the pause is over: | ||
| 814 | // clear m_pausedTime so the entry doesn't stay wedged reporting | ||
| 815 | // itself as paused, and restore the last known status snapshot. | ||
| 816 | // The lock (RAII) is released exactly once here on every path, | ||
| 817 | // when it goes out of scope. | ||
| 818 | 12 | m_pausedTime = -1; | |
| 819 | { | ||
| 820 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | std::lock_guard<std::mutex> lock(MediaOutputStatus::FieldsLock()); |
| 821 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | *m_slotStatus = m_pausedStatus; |
| 822 | 12 | } | |
| 823 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | } |
| 824 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | delete failed; |
| 825 | |||
| 826 | // Outside the media output lock: this dispatches commands, and holding | ||
| 827 | // the lock across that is how deadlocks get built. | ||
| 828 | 12 | StartExtraMedia(resumeMS); | |
| 829 | } | ||
| 830 | } | ||
| 831 |