From b434c61b86e6c8ce733476371639fa0aeb5f80b2 Mon Sep 17 00:00:00 2001 From: Johanness Date: Sat, 30 May 2026 23:24:54 +0300 Subject: [PATCH] decklink-out: non-blocking frame pool, skip late frames instead of realign, 5 preroll frames --- nodes/decklink-out/src/decklink_out_node.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/nodes/decklink-out/src/decklink_out_node.cpp b/nodes/decklink-out/src/decklink_out_node.cpp index 2f6ed87..e770e10 100644 --- a/nodes/decklink-out/src/decklink_out_node.cpp +++ b/nodes/decklink-out/src/decklink_out_node.cpp @@ -157,7 +157,7 @@ bool DeckLinkOutNode::open_device() { is_interlaced_); } - preroll_frames_ = 3; + preroll_frames_ = 5; for (int i = 0; i < preroll_frames_; ++i) { IDeckLinkMutableVideoFrame* frame = nullptr; int32_t out_row_bytes = out_width_ * 16 / 6; @@ -239,8 +239,8 @@ void DeckLinkOutNode::schedule_frame(void* mxl_payload, long width, long height, IDeckLinkMutableVideoFrame* frame = nullptr; { - std::unique_lock lock(frame_pool_mutex_); - if (frame_pool_cv_.wait_for(lock, std::chrono::milliseconds(100), [this] { return !frame_pool_.empty(); })) { + std::lock_guard lock(frame_pool_mutex_); + if (!frame_pool_.empty()) { frame = frame_pool_.back(); frame_pool_.pop_back(); } @@ -295,16 +295,18 @@ void DeckLinkOutNode::process() { uint8_t* payload = nullptr; auto status = mxlFlowReaderGetGrain(*reader_, source_index, 5000000ULL, &grain_info, &payload); if (status != MXL_STATUS_OK) { - if (status == MXL_ERR_OUT_OF_RANGE_TOO_LATE || status == MXL_ERR_OUT_OF_RANGE_TOO_EARLY) { + if (status == MXL_ERR_OUT_OF_RANGE_TOO_LATE) { auto now = mxlGetTime(); auto current_index = mxlTimestampToIndex(&flow_rate_, now); - spdlog::warn("DeckLink-out: realigned from {} to {}", source_index, current_index - 2); + spdlog::warn("DeckLink-out: grain too late, skipping to index {}", current_index - 2); source_index = current_index - 2; - status = mxlFlowReaderGetGrain(*reader_, source_index, 5000000ULL, &grain_info, &payload); if (status != MXL_STATUS_OK) { + grains_read_++; return; } + } else if (status == MXL_ERR_OUT_OF_RANGE_TOO_EARLY) { + return; } else { return; } @@ -320,7 +322,6 @@ void DeckLinkOutNode::process() { schedule_frame(payload, src_width, src_height, src_row_bytes); - read_index_ = source_index + 1; grains_read_++; if (grains_read_ == 1) {