]> git.sesse.net Git - nageru/blobdiff - decklink_output.cpp
Write video to disk on a background thread; reduces mutex contention a fair bit when...
[nageru] / decklink_output.cpp
index 544e2edd333017d080b989a859004ba0f04bd6e4..d68467703103966942ce730076ab25875008ad5b 100644 (file)
@@ -2,6 +2,7 @@
 #include <movit/util.h>
 #include <movit/resource_pool.h>  // Must be above the Xlib includes.
 #include <pthread.h>
+#include <unistd.h>
 
 #include <mutex>
 
@@ -262,7 +263,7 @@ void DeckLinkOutput::send_frame(GLuint y_tex, GLuint cbcr_tex, YCbCrLumaCoeffici
                last_frame_had_mode_mismatch = false;
        }
 
-       unique_ptr<Frame> frame = move(get_frame());
+       unique_ptr<Frame> frame = get_frame();
        if (global_flags.ten_bit_output) {
                chroma_subsampler->create_v210(y_tex, cbcr_tex, width, height, frame->uyvy_tex);
        } else {
@@ -543,7 +544,15 @@ void DeckLinkOutput::present_thread_func()
                        ++metric_decklink_output_inflight_frames;
                }
 
-               glClientWaitSync(frame->fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED);
+               for ( ;; ) {
+                       int err = glClientWaitSync(frame->fence.get(), /*flags=*/0, 0);
+                       if (err == GL_TIMEOUT_EXPIRED) {
+                               // NVIDIA likes to busy-wait; yield instead.
+                               this_thread::sleep_for(milliseconds(1));
+                       } else {
+                               break;
+                       }
+               }
                check_error();
                frame->fence.reset();