MCPcopy Create free account
hub / github.com/WarmUpTill/SceneSwitcher / Thread

Method Thread

lib/advanced-scene-switcher.cpp:220–323  ·  view source on GitHub ↗

* Main switcher thread ******************************************************************************/

Source from the content-addressed store, hash-verified

218 * Main switcher thread
219 ******************************************************************************/
220void SwitcherData::Thread()
221{
222 blog(LOG_INFO, "started");
223 int sleep = 0;
224 int linger = 0;
225 std::chrono::milliseconds duration;
226 auto startTime = std::chrono::high_resolution_clock::now();
227 auto endTime = std::chrono::high_resolution_clock::now();
228 switcher->firstIntervalAfterStop = true;
229
230 while (true) {
231 std::unique_lock<std::mutex> lock(m);
232 mainLoopLock = &lock;
233
234 bool match = false;
235 OBSWeakSource scene;
236 OBSWeakSource transition;
237 // The previous scene might have changed during the linger duration,
238 // if a longer transition is used than the configured check interval
239 bool setPrevSceneAfterLinger = false;
240 bool macroMatch = false;
241 endTime = std::chrono::high_resolution_clock::now();
242 auto runTime =
243 std::chrono::duration_cast<std::chrono::milliseconds>(
244 endTime - startTime);
245
246 if (sleep) {
247 duration = std::chrono::milliseconds(sleep);
248 } else {
249 duration = std::chrono::milliseconds(interval) +
250 std::chrono::milliseconds(linger) - runTime;
251 if (duration.count() < 1) {
252 vblog(LOG_INFO,
253 "detected busy loop - refusing to sleep less than 1ms");
254 duration = std::chrono::milliseconds(10);
255 }
256 }
257
258 vblog(LOG_INFO, "try to sleep for %ld",
259 (long int)duration.count());
260 SetWaitScene();
261 cv.wait_for(lock, duration);
262
263 startTime = std::chrono::high_resolution_clock::now();
264 sleep = 0;
265 linger = 0;
266
267 Prune();
268 if (stop) {
269 break;
270 }
271 if (checkPause()) {
272 continue;
273 }
274 SetPreconditions();
275 match = CheckForMatch(scene, transition, linger,
276 setPrevSceneAfterLinger, macroMatch);
277 if (stop) {

Callers 2

runMethod · 0.80
run_helperFunction · 0.80

Calls 5

nowClass · 0.85
RunMacrosFunction · 0.85
SwitchSceneFunction · 0.85
countMethod · 0.80
RunIntervalResetStepsFunction · 0.50

Tested by

no test coverage detected