From 2206fd71b38e970fd8e245b0e7a9f8999ae0934f Mon Sep 17 00:00:00 2001 From: Johanness Date: Sat, 30 May 2026 22:12:47 +0300 Subject: [PATCH] some fixes --- nodes/decklink-in/src/decklink_in_node.cpp | 35 ++++++++++++++++---- nodes/decklink-in/src/decklink_in_node.hpp | 1 + nodes/decklink-out/src/decklink_out_node.cpp | 34 +++++++++++++++++-- nodes/decklink-out/src/decklink_out_node.hpp | 1 + 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/nodes/decklink-in/src/decklink_in_node.cpp b/nodes/decklink-in/src/decklink_in_node.cpp index 5bb0cba..bf5593e 100644 --- a/nodes/decklink-in/src/decklink_in_node.cpp +++ b/nodes/decklink-in/src/decklink_in_node.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include #include @@ -32,6 +34,18 @@ void DeckLinkInNode::configure(const nlohmann::json& params) { spdlog::warn("DeckLink-in: unknown mode '{}', defaulting to 1080i50", mode_str); } } + if (params.contains("input_connection")) { + auto conn_str = params["input_connection"].get(); + if (conn_str == "sdi") input_connection_ = bmdVideoConnectionSDI; + else if (conn_str == "hdmi") input_connection_ = bmdVideoConnectionHDMI; + else if (conn_str == "optical_sdi") input_connection_ = bmdVideoConnectionOpticalSDI; + else if (conn_str == "component") input_connection_ = bmdVideoConnectionComponent; + else if (conn_str == "composite") input_connection_ = bmdVideoConnectionComposite; + else if (conn_str == "svideo") input_connection_ = bmdVideoConnectionSVideo; + else { + spdlog::warn("DeckLink-in: unknown input_connection '{}', defaulting to auto", conn_str); + } + } if (!open_device()) { spdlog::error("DeckLink-in: failed to open device during configure"); @@ -90,6 +104,18 @@ bool DeckLinkInNode::open_device() { device->GetModelName(&model_name); spdlog::info("DeckLink-in: opened device '{}'", model_name ? model_name : "unknown"); + if (input_connection_ != bmdVideoConnectionUnspecified) { + IDeckLinkConfiguration* config = nullptr; + if (device->QueryInterface(IID_IDeckLinkConfiguration, (void**)&config) == S_OK && config) { + if (config->SetInt(bmdDeckLinkConfigVideoInputConnection, input_connection_) != S_OK) { + spdlog::warn("DeckLink-in: failed to set input connection"); + } else { + spdlog::info("DeckLink-in: input connection configured"); + } + config->Release(); + } + } + if (device->QueryInterface(IID_IDeckLinkInput, (void**)&input_) != S_OK) { spdlog::error("DeckLink-in: device has no input interface"); device->Release(); @@ -119,13 +145,8 @@ bool DeckLinkInNode::open_device() { is_interlaced_ = (display_mode_ == bmdModeHD1080i50 || display_mode_ == bmdModeHD1080i5994); - if (is_interlaced_) { - grain_rate_.numerator = static_cast(2 * scale); - grain_rate_.denominator = static_cast(duration); - } else { - grain_rate_.numerator = static_cast(scale); - grain_rate_.denominator = static_cast(duration); - } + grain_rate_.numerator = static_cast(scale); + grain_rate_.denominator = static_cast(duration); auto g = std::__gcd(grain_rate_.numerator, grain_rate_.denominator); grain_rate_.numerator /= g; diff --git a/nodes/decklink-in/src/decklink_in_node.hpp b/nodes/decklink-in/src/decklink_in_node.hpp index 3cc47a5..60b1cf5 100644 --- a/nodes/decklink-in/src/decklink_in_node.hpp +++ b/nodes/decklink-in/src/decklink_in_node.hpp @@ -46,6 +46,7 @@ private: int device_index_ = 0; BMDDisplayMode display_mode_ = bmdModeHD1080i50; + BMDVideoConnection input_connection_ = bmdVideoConnectionUnspecified; IDeckLink* decklink_ = nullptr; IDeckLinkInput* input_ = nullptr; diff --git a/nodes/decklink-out/src/decklink_out_node.cpp b/nodes/decklink-out/src/decklink_out_node.cpp index b54127a..a437666 100644 --- a/nodes/decklink-out/src/decklink_out_node.cpp +++ b/nodes/decklink-out/src/decklink_out_node.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include #include @@ -32,6 +34,18 @@ void DeckLinkOutNode::configure(const nlohmann::json& params) { spdlog::warn("DeckLink-out: unknown mode '{}', defaulting to 1080i50", mode_str); } } + if (params.contains("output_connection")) { + auto conn_str = params["output_connection"].get(); + if (conn_str == "sdi") output_connection_ = bmdVideoConnectionSDI; + else if (conn_str == "hdmi") output_connection_ = bmdVideoConnectionHDMI; + else if (conn_str == "optical_sdi") output_connection_ = bmdVideoConnectionOpticalSDI; + else if (conn_str == "component") output_connection_ = bmdVideoConnectionComponent; + else if (conn_str == "composite") output_connection_ = bmdVideoConnectionComposite; + else if (conn_str == "svideo") output_connection_ = bmdVideoConnectionSVideo; + else { + spdlog::warn("DeckLink-out: unknown output_connection '{}', defaulting to auto", conn_str); + } + } } void DeckLinkOutNode::on_add_reader(const std::string& port_id, mxlFlowReader reader) { @@ -95,6 +109,20 @@ bool DeckLinkOutNode::open_device() { decklink_ = device; + if (output_connection_ != bmdVideoConnectionUnspecified) { + IDeckLinkConfiguration* config = nullptr; + if (decklink_->QueryInterface(IID_IDeckLinkConfiguration, (void**)&config) == S_OK && config) { + if (config->SetInt(bmdDeckLinkConfigVideoOutputConnection, output_connection_) != S_OK) { + spdlog::warn("DeckLink-out: failed to set output connection"); + } else { + spdlog::info("DeckLink-out: set output connection configured"); + } + config->Release(); + } else { + spdlog::warn("DeckLink-out: IDeckLinkConfiguration not available"); + } + } + callback_ = std::make_unique(*this); output_->SetScheduledFrameCompletionCallback(callback_.get()); @@ -143,12 +171,14 @@ void DeckLinkOutNode::schedule_frame(void* mxl_payload, long width, long height, if (!output_) return; int32_t out_row_bytes = 0; - output_->RowBytesForPixelFormat(bmdFormat10BitYUV, width, &out_row_bytes); + if (output_->RowBytesForPixelFormat(bmdFormat10BitYUV, width, &out_row_bytes) != S_OK || out_row_bytes <= 0) { + out_row_bytes = ((width + 5) / 6) * 16; + } IDeckLinkMutableVideoFrame* frame = nullptr; if (output_->CreateVideoFrame(width, height, out_row_bytes, bmdFormat10BitYUV, bmdFrameFlagDefault, &frame) != S_OK) { - spdlog::warn("DeckLink-out: failed to create output frame"); + spdlog::warn("DeckLink-out: failed to create output frame {}x{}", width, height); return; } diff --git a/nodes/decklink-out/src/decklink_out_node.hpp b/nodes/decklink-out/src/decklink_out_node.hpp index 027fce5..5807088 100644 --- a/nodes/decklink-out/src/decklink_out_node.hpp +++ b/nodes/decklink-out/src/decklink_out_node.hpp @@ -47,6 +47,7 @@ private: int device_index_ = 0; BMDDisplayMode display_mode_ = bmdModeHD1080i50; + BMDVideoConnection output_connection_ = bmdVideoConnectionUnspecified; IDeckLink* decklink_ = nullptr; IDeckLinkOutput* output_ = nullptr;