Read info about source from source/flow_def

This commit is contained in:
JohannesItten
2026-07-09 12:43:10 +03:00
parent d3ef011319
commit d2095d14d3
8 changed files with 172 additions and 54 deletions
+33
View File
@@ -121,6 +121,39 @@ public:
int channel_stride = 0; // floats between channel planes (NDI planar layout)
};
// Waits for the first audio packet and returns its format.
// Call after probe(). Audio packets are typically already queued at that point.
// Discards any video frames encountered while searching. Respects g_running.
AudioInfo probe_audio(uint32_t timeout_ms = 5000) {
const auto deadline = std::chrono::steady_clock::now()
+ std::chrono::milliseconds(timeout_ms);
while (dmf::g_running.load(std::memory_order_relaxed) &&
std::chrono::steady_clock::now() < deadline) {
NDIlib_video_frame_v2_t video_frame{};
NDIlib_audio_frame_v3_t audio_frame{};
auto type = NDIlib_recv_capture_v3(recv_, &video_frame, &audio_frame, nullptr, 100);
if (type == NDIlib_frame_type_error)
throw std::runtime_error("NDI source lost during audio probe");
if (type == NDIlib_frame_type_video) {
NDIlib_recv_free_video_v2(recv_, &video_frame);
continue;
}
if (type == NDIlib_frame_type_audio) {
const bool is_fltp = (audio_frame.FourCC == NDIlib_FourCC_audio_type_FLTP);
AudioInfo info;
if (is_fltp) {
info.sample_rate = audio_frame.sample_rate;
info.channels = audio_frame.no_channels;
info.samples = audio_frame.no_samples;
info.channel_stride = audio_frame.channel_stride_in_bytes / sizeof(float);
}
NDIlib_recv_free_audio_v3(recv_, &audio_frame);
if (is_fltp) return info;
}
}
throw std::runtime_error("Timeout waiting for first audio packet");
}
// Receives one NDI frame. On video: converts to V210 in frame_buffer/frame_stride.
// On audio: copies float32 planar samples into audio_out and fills audio_info.
// Returns FrameKind::None on timeout or non-A/V frames.