fix: NDI node correctness and robustness fixes

NDIHelper:
- find_sources: check g_running each attempt to avoid 50s block on shutdown
- getV210_video_frame: fix P216 branch (fall-through + local pointer reassignment bug)
- getV210_video_frame: status_change re-queries source info instead of throwing
- select_source: fix typo "recieve" → "receive"

ndiout:
- set frame_rate_N/frame_rate_D on the NDI send frame (was 0/0)
- add per-second stats logging (matching fakesink pattern)
- add missing <chrono> include
- fix typo "reciever" → "receiver"

ndiin:
- read source_num from NODE_CONFIG (key: "source_num", default 0)
- wrap hot-loop NDI call in try/catch so source-lost terminates cleanly
- pass source_num through to getV210_video_frame

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
JohannesItten
2026-07-01 12:07:45 +03:00
parent 19ea14a61c
commit 7a32fa20af
3 changed files with 60 additions and 34 deletions
+28 -16
View File
@@ -2,6 +2,7 @@
#include <vector>
#include <string>
#include <Processing.NDI.Lib.h>
#include "Signal.hpp"
#include "V210.hpp"
namespace dmf {
@@ -35,6 +36,11 @@ class NDIHelper {
uint32_t sources_amount = 0;
const NDIlib_source_t* p_sources = nullptr;
for (int attempt = 0; !sources_amount && attempt < max_attempts; ++attempt) {
if (!dmf::g_running.load(std::memory_order_relaxed)) {
NDIlib_find_destroy(pNDI_find);
pNDI_find = nullptr;
throw std::runtime_error("Interrupted while searching for NDI sources");
}
NDIlib_find_wait_for_sources(pNDI_find, timeout_ms);
p_sources = NDIlib_find_get_current_sources(pNDI_find, &sources_amount);
}
@@ -68,7 +74,7 @@ class NDIHelper {
pNDI_recv = NDIlib_recv_create_v3();
if (!pNDI_recv) {
throw std::runtime_error("Cannot create NDI recieve instance");
throw std::runtime_error("Cannot create NDI receive instance");
}
NDIlib_recv_connect(pNDI_recv, &cached_sources[source_num]);
}
@@ -154,28 +160,34 @@ class NDIHelper {
NDIlib_video_frame_v2_t video_frame;
NDIlib_frame_type_e frame_type;
frame_type = NDIlib_recv_capture_v3(pNDI_recv, &video_frame, nullptr, nullptr, 5);
switch(frame_type)
{
case NDIlib_frame_type_error:
throw std::runtime_error("NDI source lost");
case NDIlib_frame_type_status_change:
throw std::runtime_error("NDI source resolution or framerate are changed");
}
if (frame_type != NDIlib_frame_type_video) {
if (frame_type == NDIlib_frame_type_error)
throw std::runtime_error("NDI source lost");
if (frame_type == NDIlib_frame_type_status_change) {
// Source changed resolution or framerate — refresh internal info, repeat last frame
get_source_info(source_num);
return false;
}
switch(fourCC)
{
if (frame_type != NDIlib_frame_type_video)
return false;
switch (fourCC) {
case NDIlib_FourCC_type_UYVY:
v210::UYVYtoV210(video_frame.p_data, frame_buffer, xres, yres, stride, frame_stride);
break;
case NDIlib_FourCC_type_P216:
NDIlib_video_frame_v2_t video_frame_10bit;
NDIlib_util_P216_to_V210(&video_frame, &video_frame_10bit);
frame_buffer = video_frame.p_data;
case NDIlib_FourCC_type_P216: {
// P216→V210: write directly into caller's buffer via a wrapper frame
NDIlib_video_frame_v2_t dst{};
dst.p_data = frame_buffer;
dst.line_stride_in_bytes = frame_stride;
NDIlib_util_P216_to_V210(&video_frame, &dst);
break;
}
default:
throw std::runtime_error("Color format is not supported yet");
NDIlib_recv_free_video_v2(pNDI_recv, &video_frame);
throw std::runtime_error("Unsupported NDI color format: " + fourCCtoStr());
}
NDIlib_recv_free_video_v2(pNDI_recv, &video_frame);
return true;