]> git.sesse.net Git - nageru/blobdiff - decklink_capture.cpp
Fix an issue where the mixer lagging too much behind CEF would cause us to display...
[nageru] / decklink_capture.cpp
index 33bb73daa219fa51c31d1ebdd23a3f72709858d5..6dba068fca51108fcbfc3a55050efcc1223880ee 100644 (file)
@@ -319,6 +319,14 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived(
                char thread_name[16];
                snprintf(thread_name, sizeof(thread_name), "DeckLink_C_%d", card_index);
                pthread_setname_np(pthread_self(), thread_name);
+
+               sched_param param;
+               memset(&param, 0, sizeof(param));
+               param.sched_priority = 1;
+               if (sched_setscheduler(0, SCHED_RR, &param) == -1) {
+                       printf("couldn't set realtime priority for DeckLink thread: %s\n", strerror(errno));
+               }
+
                if (has_dequeue_callbacks) {
                        dequeue_init_callback();
                }
@@ -340,8 +348,8 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived(
        if (video_frame) {
                video_format.has_signal = !(video_frame->GetFlags() & bmdFrameHasNoInputSource);
 
-               int width = video_frame->GetWidth();
-               int height = video_frame->GetHeight();
+               const int width = video_frame->GetWidth();
+               const int height = video_frame->GetHeight();
                const int stride = video_frame->GetRowBytes();
                const BMDPixelFormat format = video_frame->GetPixelFormat();
                assert(format == pixel_format_to_bmd(current_pixel_format));
@@ -473,20 +481,24 @@ void DeckLinkCapture::stop_dequeue_thread()
 
 void DeckLinkCapture::set_video_mode(uint32_t video_mode_id)
 {
-       if (input->PauseStreams() != S_OK) {
-               fprintf(stderr, "PauseStreams failed\n");
-               exit(1);
-       }
-       if (input->FlushStreams() != S_OK) {
-               fprintf(stderr, "FlushStreams failed\n");
-               exit(1);
+       if (running) {
+               if (input->PauseStreams() != S_OK) {
+                       fprintf(stderr, "PauseStreams failed\n");
+                       exit(1);
+               }
+               if (input->FlushStreams() != S_OK) {
+                       fprintf(stderr, "FlushStreams failed\n");
+                       exit(1);
+               }
        }
 
        set_video_mode_no_restart(video_mode_id);
 
-       if (input->StartStreams() != S_OK) {
-               fprintf(stderr, "StartStreams failed\n");
-               exit(1);
+       if (running) {
+               if (input->StartStreams() != S_OK) {
+                       fprintf(stderr, "StartStreams failed\n");
+                       exit(1);
+               }
        }
 }