]> git.sesse.net Git - nageru/blobdiff - decklink_output.cpp
When switching output cards, do it from the mixer thread.
[nageru] / decklink_output.cpp
index 7fa689e547610c0fb14696349a87f3e445e42422..b3c4c85457dedef75fd1a115fa9b82689ac27599 100644 (file)
@@ -1,6 +1,7 @@
 #include <movit/effect_util.h>
 #include <movit/util.h>
 #include <movit/resource_pool.h>  // Must be above the Xlib includes.
+#include <pthread.h>
 
 #include <epoxy/egl.h>
 
@@ -63,8 +64,10 @@ void DeckLinkOutput::set_device(IDeckLink *decklink)
 void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts)
 {
        assert(output);
+       assert(!playback_initiated);
 
        should_quit = false;
+       playback_initiated = true;
        playback_started = false;
        this->base_pts = base_pts;
 
@@ -153,9 +156,14 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts)
 
 void DeckLinkOutput::end_output()
 {
+       if (!playback_initiated) {
+               return;
+       }
+
        should_quit = true;
        frame_queues_changed.notify_all();
        present_thread.join();
+       playback_initiated = false;
 
        output->StopScheduledPlayback(0, nullptr, 0);
        output->DisableVideoOutput();
@@ -173,6 +181,8 @@ void DeckLinkOutput::end_output()
 
 void DeckLinkOutput::send_frame(GLuint y_tex, GLuint cbcr_tex, const vector<RefCountedFrame> &input_frames, int64_t pts, int64_t duration)
 {
+       assert(!should_quit);
+
        unique_ptr<Frame> frame = move(get_frame());
        chroma_subsampler->create_uyvy(y_tex, cbcr_tex, width, height, frame->uyvy_tex);
 
@@ -234,6 +244,8 @@ void DeckLinkOutput::send_audio(int64_t pts, const std::vector<float> &samples)
 
 void DeckLinkOutput::wait_for_frame(int64_t pts, int *dropped_frames, int64_t *frame_duration)
 {
+       assert(!should_quit);
+
        *dropped_frames = 0;
        *frame_duration = this->frame_duration;
 
@@ -354,6 +366,7 @@ unique_ptr<DeckLinkOutput::Frame> DeckLinkOutput::get_frame()
 
 void DeckLinkOutput::present_thread_func()
 {
+       pthread_setname_np(pthread_self(), "DeckLinkOutput");
        for ( ;; ) {
                unique_ptr<Frame> frame;
                {