fix ndi->decklinkout slowdown
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -96,19 +97,23 @@ class NDIInNode : public dmf::NodeBase {
|
||||
dmf::NDIReceiver::AudioInfo audio_info;
|
||||
|
||||
while (dmf::g_running.load(std::memory_order_relaxed)) {
|
||||
// Drain all queued NDI frames before writing one MXL grain.
|
||||
// Drain available NDI frames before writing one MXL grain.
|
||||
// With audio enabled, many audio packets may be queued ahead of a video frame.
|
||||
// Calling capture() once per grain window would starve video reception.
|
||||
// Strategy: blocking first call (5ms), then non-blocking drain of remainder.
|
||||
// Budget: drain for at most half a frame period so the grain clock stays on time
|
||||
// even when catching up from a startup audio backlog.
|
||||
try {
|
||||
const auto drain_deadline =
|
||||
std::chrono::steady_clock::now() + std::chrono::milliseconds(20);
|
||||
bool first = true;
|
||||
while (dmf::g_running.load(std::memory_order_relaxed)) {
|
||||
while (dmf::g_running.load(std::memory_order_relaxed) &&
|
||||
std::chrono::steady_clock::now() < drain_deadline) {
|
||||
auto kind = ndi.capture(latest_video.data(), video_stride,
|
||||
audio_buf, audio_info, has_audio,
|
||||
first ? 5 : 0);
|
||||
first = false;
|
||||
if (kind == dmf::NDIReceiver::FrameKind::Video) {
|
||||
have_video = true;
|
||||
break; // got video — write grain now, remaining audio deferred to next window
|
||||
} else if (kind == dmf::NDIReceiver::FrameKind::Audio && has_audio) {
|
||||
mxlMutableWrappedMultiBufferSlice slice{};
|
||||
if (mxlFlowWriterOpenSamples(audio_writer, audio_index,
|
||||
|
||||
Reference in New Issue
Block a user