MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / run

Method run

src/server/ffplaydummy.cpp:271–331  ·  view source on GitHub ↗

--- RUN ---

Source from the content-addressed store, hash-verified

269
270// --- RUN ---
271void FfplayDummy::run() {
272 buf = (uint8_t*) malloc(buf_size);
273
274 read_size = start_size;
275
276 // Start main loop.
277 // This loop waits until it is triggered, at which point there should either be a URL to
278 // stream from, or a file to stream via the DataBuffer.
279 running = true;
280 playerStarted = false;
281 std::mutex playbackMtx;
282 while (running) {
283 // Wait in condition variable until triggered. Ensure an event is waiting to deal with
284 // spurious wake-ups.
285 std::unique_lock<std::mutex> lk(playbackMtx);
286 using namespace std::chrono_literals;
287 dumbplaybackCv.wait(lk);
288
289 if (!running) {
290 std::cout << "Terminating AV thread..." << std::endl;
291 break;
292 }
293
294 // Intercept spurious wake-ups.
295 if (!playingTrack && !castingUrl) { continue; }
296
297 // Start playback.
298 playerStarted = true;
299
300 // Update clients with status update.
301 sendGlobalStatusUpdate();
302
303 // Start dummy playback:
304 // - Request a 32 kB data block every N milliseconds.
305 // - Once EOF is returned, wait N milliseconds, then quit.
306 ct.setCallback(FfplayDummy::triggerRead, 0);
307 ct.setStopCallback(FfplayDummy::cleanUp);
308 ct.start(50); // Trigger time in milliseconds.
309
310 // Wait here until playback has finished.
311 // The read thread in StreamHandler will signal this condition variable.
312 dummyMutex.lock();
313 dummyCon.wait(dummyMutex);
314 dummyMutex.unlock();
315
316 ct.stop();
317
318 DataBuffer::reset(); // Clears the data buffer (file data buffer).
319 finishPlayback(); // Calls handler for post-playback steps.
320
321 // Clean up.
322 free(buf);
323
324 playerStarted = false;
325 playingTrack = false;
326 castingUrl = false;
327
328 // Update clients with status update.

Callers

nothing calls this directly

Calls 9

waitMethod · 0.80
setCallbackMethod · 0.80
setStopCallbackMethod · 0.80
lockMethod · 0.80
unlockMethod · 0.80
sendGlobalStatusUpdateFunction · 0.70
finishPlaybackFunction · 0.70
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected