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
+22 -12
View File
@@ -1,3 +1,4 @@
#include <chrono>
#include <string>
#include <mxl/flow.h>
#include <mxl/time.h>
@@ -38,12 +39,12 @@ class NDIOutNode : public dmf::NodeBase {
const mxlRational rate = {fps_num, fps_den};
uint64_t index = mxlGetCurrentIndex(&rate);
uint64_t frame_count = 0;
uint64_t invalid_count = 0;
uint64_t late_count = 0;
auto wall_start = std::chrono::steady_clock::now();
auto last_log_time = wall_start;
uint64_t index = mxlGetCurrentIndex(&rate);
uint64_t frame_count = 0;
uint64_t invalid_count = 0;
uint64_t late_count = 0;
auto wall_start = std::chrono::steady_clock::now();
auto last_log_time = wall_start;
// NDI part
if (!NDIlib_initialize()) {
@@ -73,9 +74,10 @@ class NDIOutNode : public dmf::NodeBase {
NDI_video_frame_10bit.p_data = (uint8_t*)malloc(NDI_video_frame_10bit.line_stride_in_bytes * NDI_video_frame_10bit.yres);
NDIlib_video_frame_v2_t NDI_video_frame_16bit;
NDI_video_frame_16bit.xres = NDI_video_frame_10bit.xres;
NDI_video_frame_16bit.yres = NDI_video_frame_10bit.yres;
NDI_video_frame_16bit.xres = NDI_video_frame_10bit.xres;
NDI_video_frame_16bit.yres = NDI_video_frame_10bit.yres;
NDI_video_frame_16bit.frame_rate_N = fps_num;
NDI_video_frame_16bit.frame_rate_D = fps_den;
NDI_video_frame_16bit.line_stride_in_bytes = NDI_video_frame_16bit.xres * sizeof(uint16_t);
NDI_video_frame_16bit.p_data = (uint8_t*)malloc(NDI_video_frame_16bit.line_stride_in_bytes * 2 * NDI_video_frame_16bit.yres);
//
@@ -98,9 +100,8 @@ class NDIOutNode : public dmf::NodeBase {
NDIlib_util_V210_to_P216(&NDI_video_frame_10bit, &NDI_video_frame_16bit);
NDIlib_send_send_video_v2(pNDI_send, &NDI_video_frame_16bit);
ndi_frame_counter++;
if (ndi_frame_counter == 1) {
log("NDI reciever got feed");
}
if (ndi_frame_counter == 1)
log("NDI receiver connected");
} else if (st == MXL_ERR_OUT_OF_RANGE_TOO_EARLY) {
mxlSleepForNs(1'000'000); // 1 ms poll
@@ -114,6 +115,15 @@ class NDIOutNode : public dmf::NodeBase {
log("unexpected status=%d on index=%llu", st, index);
break;
}
auto now = std::chrono::steady_clock::now();
if (std::chrono::duration<double>(now - last_log_time).count() >= 1.0) {
const double elapsed = std::chrono::duration<double>(now - wall_start).count();
log("frames=%llu invalid=%llu late=%llu avg=%.2f fps",
frame_count, invalid_count, late_count,
static_cast<double>(frame_count) / elapsed);
last_log_time = now;
}
}
log("stopped — total frames=%llu invalid=%llu late=%llu",