MCPcopy Create free account
hub / github.com/MaartenBaert/ssr / InputThread

Method InputThread

src/AV/Input/GLInjectInput.cpp:287–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287void GLInjectInput::InputThread() {
288 try {
289
290 Logger::LogInfo("[GLInjectInput::InputThread] " + Logger::tr("Input thread started."));
291
292 // deal with pre-existing streams
293 {
294 SharedLock lock(&m_shared_data);
295 auto &streams = lock->m_stream_watcher->GetStreams();
296 for(size_t i = streams.size(); i > 0; ) {
297 --i;
298 if(SwitchStream(lock.get(), streams[i]))
299 break;
300 }
301 }
302
303 int64_t next_watcher_update = hrt_time_micro();
304
305 while(!m_should_stop) {
306
307 // try to get a frame
308 int64_t timestamp;
309 unsigned int width, height;
310 int stride;
311 void *data;
312 {
313 SharedLock lock(&m_shared_data);
314
315 // update stream watcher
316 if(hrt_time_micro() >= next_watcher_update) {
317 lock->m_stream_watcher->HandleChanges(&StreamAddCallback, &StreamRemoveCallback, this);
318 next_watcher_update = hrt_time_micro() + 200000;
319 }
320
321 // do we have a stream reader?
322 if(lock->m_stream_reader == NULL) {
323 PushVideoPing(hrt_time_micro() - MAX_COMMUNICATION_LATENCY);
324 lock.lock().unlock(); // release lock before sleep
325 usleep(20000);
326 continue;
327 }
328
329 // is a frame ready?
330 data = lock->m_stream_reader->GetFrame(&timestamp, &width, &height, &stride);
331 if(data == NULL) {
332 PushVideoPing(hrt_time_micro() - MAX_COMMUNICATION_LATENCY);
333 lock.lock().unlock(); // release lock before sleep
334 usleep(20000);
335 continue;
336 }
337
338 }
339
340 // if the stride is negative, change the pointer
341 // this is needed because OpenGL stores frames upside-down
342 if(stride < 0) {
343 data = (char*) data + (size_t) (-stride) * (size_t) (height - 1);
344 }

Callers

nothing calls this directly

Calls 6

getMethod · 0.80
HandleChangesMethod · 0.80
hrt_time_microFunction · 0.50
GetFrameMethod · 0.45
NextFrameMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected