fix: MXL_ERR_FLOW_INVALID reconnect, nullptr→"" options, null guards
Readers (ndiout, fakesink) now handle MXL_ERR_FLOW_INVALID by releasing and recreating the flow reader, then realigning the index to current time. This lets consumer nodes survive a producer restart without exiting. All mxlCreateInstance/FlowWriter/FlowReader options args changed from nullptr to "" to match MXL reference implementation style. mxlReleaseFlowReader calls guarded with null checks so cleanup is safe when a mid-run reconnect attempt fails. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+27
-5
@@ -64,7 +64,7 @@ class NDIOutNode : public dmf::NodeBase {
|
||||
log("flow active — starting read");
|
||||
|
||||
mxlFlowConfigInfo video_cfg{};
|
||||
mxlStatus vst = mxlCreateFlowReader(instance(), flow_id.c_str(), nullptr, &video_reader);
|
||||
mxlStatus vst = mxlCreateFlowReader(instance(), flow_id.c_str(), "", &video_reader);
|
||||
if (vst != MXL_STATUS_OK) { log("video mxlCreateFlowReader failed (%s)", dmf::mxl_status_str(vst)); return; }
|
||||
mxlFlowReaderGetConfigInfo(video_reader, &video_cfg);
|
||||
video_stride = video_cfg.discrete.sliceSizes[0];
|
||||
@@ -77,10 +77,11 @@ class NDIOutNode : public dmf::NodeBase {
|
||||
int channels = 0;
|
||||
int samples_per_frame = 0;
|
||||
bool has_audio = config().contains("audio_flow_id");
|
||||
std::string audio_flow_id;
|
||||
|
||||
if (has_audio) {
|
||||
const auto audio_flow_info = config().at("audio_flow_id");
|
||||
const auto audio_flow_id = audio_flow_info.at("id").get<std::string>();
|
||||
audio_flow_id = audio_flow_info.at("id").get<std::string>();
|
||||
sample_rate = audio_flow_info.value("sample_rate", 48000);
|
||||
channels = audio_flow_info.value("channels", 2);
|
||||
samples_per_frame = sample_rate * fps_den / fps_num;
|
||||
@@ -88,7 +89,7 @@ class NDIOutNode : public dmf::NodeBase {
|
||||
log("audio flow=%s %d Hz %dch %d samples/frame",
|
||||
audio_flow_id.c_str(), sample_rate, channels, samples_per_frame);
|
||||
|
||||
mxlStatus ast = mxlCreateFlowReader(instance(), audio_flow_id.c_str(), nullptr, &audio_reader);
|
||||
mxlStatus ast = mxlCreateFlowReader(instance(), audio_flow_id.c_str(), "", &audio_reader);
|
||||
if (ast != MXL_STATUS_OK) {
|
||||
log("audio mxlCreateFlowReader failed (%s) — continuing without audio", dmf::mxl_status_str(ast));
|
||||
has_audio = false;
|
||||
@@ -188,6 +189,16 @@ class NDIOutNode : public dmf::NodeBase {
|
||||
mxlFlowRuntimeInfo ari{};
|
||||
mxlFlowReaderGetRuntimeInfo(audio_reader, &ari);
|
||||
audio_index = ari.headIndex;
|
||||
} else if (ast == MXL_ERR_FLOW_INVALID) {
|
||||
log("audio flow invalidated — reconnecting...");
|
||||
mxlReleaseFlowReader(instance(), audio_reader);
|
||||
audio_reader = nullptr;
|
||||
mxlSleepForNs(100'000'000);
|
||||
if (mxlCreateFlowReader(instance(), audio_flow_id.c_str(), "", &audio_reader) == MXL_STATUS_OK) {
|
||||
log("audio flow reconnected");
|
||||
const mxlRational r = {sample_rate, 1};
|
||||
audio_index = mxlGetCurrentIndex(&r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,6 +234,17 @@ class NDIOutNode : public dmf::NodeBase {
|
||||
mxlFlowReaderGetRuntimeInfo(video_reader, &ri);
|
||||
video_index = ri.headIndex;
|
||||
|
||||
} else if (vst == MXL_ERR_FLOW_INVALID) {
|
||||
log("video flow invalidated — reconnecting...");
|
||||
mxlReleaseFlowReader(instance(), video_reader);
|
||||
video_reader = nullptr;
|
||||
mxlSleepForNs(100'000'000);
|
||||
if (mxlCreateFlowReader(instance(), flow_id.c_str(), "", &video_reader) == MXL_STATUS_OK) {
|
||||
log("video flow reconnected");
|
||||
const mxlRational r = {fps_num, fps_den};
|
||||
video_index = mxlGetCurrentIndex(&r);
|
||||
}
|
||||
|
||||
} else {
|
||||
log("unexpected video status (%s) on index=%llu", dmf::mxl_status_str(vst), video_index);
|
||||
break;
|
||||
@@ -248,8 +270,8 @@ class NDIOutNode : public dmf::NodeBase {
|
||||
else
|
||||
log("stopped");
|
||||
|
||||
if (has_video) mxlReleaseFlowReader(instance(), video_reader);
|
||||
if (has_audio) mxlReleaseFlowReader(instance(), audio_reader);
|
||||
if (has_video && video_reader) mxlReleaseFlowReader(instance(), video_reader);
|
||||
if (has_audio && audio_reader) mxlReleaseFlowReader(instance(), audio_reader);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user