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

Function dataRequestFunction

src/test/test_databuffer_multi_port.cpp:79–117  ·  view source on GitHub ↗

--- DATA REQUEST FUNCTION --- This function can be signalled with the condition variable to request data from the client.

Source from the content-addressed store, hash-verified

77// --- DATA REQUEST FUNCTION ---
78// This function can be signalled with the condition variable to request data from the client.
79void dataRequestFunction() {
80 // Create and share condition variable with DataBuffer class.
81 DataBuffer::setDataRequestCondition(&dataRequestCv);
82
83 while (running) {
84 // Wait for the condition to be signalled.
85 std::unique_lock<std::mutex> lk(dataRequestMtx);
86 using namespace std::chrono_literals;
87 dataRequestCv.wait(lk);
88
89 if (!running) {
90 std::cout << "Shutting down data request function..." << std::endl;
91 break;
92 }
93
94 // Set data request as pending.
95 DataBuffer::dataRequestPending = true;
96
97 //std::cout << "Asking for data..." << std::endl;
98
99 // Write into buffer after a brief delay.
100 std::this_thread::sleep_for(std::chrono::milliseconds(1));
101
102 // Create fresh chunk using counter.
103 for (uint32_t i = 0; i < chunk_size; ++i) {
104 chunk[i] = writeCnt++;
105 }
106
107 DataBuffer::write(chunk, chunk_size);
108
109 if (!playerRunning) {
110 // Start playback locally.
111 ffplay.playTrack();
112 playerRunning = true;
113
114 DataBuffer::startBufferAhead();
115 }
116 }
117}
118
119
120// --- SEEKING HANDLER ---

Callers

nothing calls this directly

Calls 2

waitMethod · 0.80
playTrackMethod · 0.45

Tested by

no test coverage detected