]> git.sesse.net Git - nageru/blobdiff - nageru/decklink_output.cpp
Fix a bug; 60.00 fps would never be autoselected for output. (Then again, 59.97 shoul...
[nageru] / nageru / decklink_output.cpp
index c9cd481c4d49e411dcdeb69028408bb3d20bcc18..3dd5243c5998b5a8c2b5efb747366d4dc9652ce4 100644 (file)
@@ -84,6 +84,9 @@ DeckLinkOutput::DeckLinkOutput(ResourcePool *resource_pool, QSurface *surface, u
 
 bool DeckLinkOutput::set_device(IDeckLink *decklink)
 {
+       if (decklink->QueryInterface(IID_IDeckLinkInput, (void**)&input) != S_OK) {
+               input = nullptr;
+       }
        if (decklink->QueryInterface(IID_IDeckLinkOutput, (void**)&output) != S_OK) {
                fprintf(stderr, "Warning: Card %u has no outputs\n", card_index);
                return false;
@@ -151,7 +154,7 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts)
                fprintf(stderr, "Failed to set video output connection for card %u\n", card_index);
                abort();
        }
-       if (config->SetFlag(bmdDeckLinkConfigUse1080pNotPsF, true) != S_OK) {
+       if (config->SetFlag(bmdDeckLinkConfigOutput1080pAsPsF, true) != S_OK) {
                fprintf(stderr, "Failed to set PsF flag for card\n");
                abort();
        }
@@ -193,6 +196,15 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts)
 
        display_mode->Release();
 
+       if (input != nullptr) {
+               if (input->DisableVideoInput() != S_OK) {
+                       fprintf(stderr, "Warning: Failed to disable video input for card %d\n", card_index);
+               }
+               if (input->DisableAudioInput() != S_OK) {
+                       fprintf(stderr, "Warning: Failed to disable audio input for card %d\n", card_index);
+               }
+       }
+
        HRESULT result = output->EnableVideoOutput(mode, bmdVideoOutputFlagDefault);
        if (result != S_OK) {
                fprintf(stderr, "Couldn't enable output with error 0x%x\n", result);
@@ -248,6 +260,15 @@ void DeckLinkOutput::end_output()
                        frame_freelist.pop();
                }
        }
+
+       if (input != nullptr) {
+               input->Release();
+               input = nullptr;
+       }
+       if (output != nullptr) {
+               output->Release();
+               output = nullptr;
+       }
 }
 
 void DeckLinkOutput::send_frame(GLuint y_tex, GLuint cbcr_tex, YCbCrLumaCoefficients output_ycbcr_coefficients, const vector<RefCountedFrame> &input_frames, int64_t pts, int64_t duration)
@@ -418,7 +439,7 @@ uint32_t DeckLinkOutput::pick_video_mode(uint32_t mode) const
        }
 
        // Prioritize 59.94 > 60 > 29.97. If none of those are found, then pick the highest one.
-       for (const pair<int, int> &desired : vector<pair<int, int>>{ { 60000, 1001 }, { 60, 0 }, { 30000, 1001 } }) {
+       for (const pair<int, int> &desired : vector<pair<int, int>>{ { 60000, 1001 }, { 60, 1 }, { 30000, 1001 } }) {
                for (const auto &it : video_modes) {
                        if (it.second.frame_rate_num * desired.second == desired.first * it.second.frame_rate_den) {
                                return it.first;