feat: NDI in node receives and writes audio flow
- FlowDef.hpp: add make_audio_flow_def (NMOS IS-04 audio/Lnn flow)
- NDIReceiver: replace capture_v210 with capture() — single recv call
dispatches to FrameKind::{Video,Audio,None}; AudioInfo struct carries
sample_rate/channels/samples/channel_stride
- ndiin: optional audio writer when graph wires audio_flow_id; single
loop with 5ms NDI poll; audio grains written immediately on arrival;
video grains written when mxlGetCurrentIndex reaches video_index
- build_graph: rename ndiin video port flow_id → video_flow_id; add
audio_flow_id edge (no sink yet — wired to ndiin only)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+50
-26
@@ -112,12 +112,24 @@ public:
|
||||
throw std::runtime_error("Interrupted during probe");
|
||||
}
|
||||
|
||||
// Captures one video frame and converts it to V210 in frame_buffer.
|
||||
// Returns false if no frame was available this tick (caller should repeat last frame).
|
||||
// Throws on source lost or unsupported format.
|
||||
bool capture_v210(uint8_t* frame_buffer, uint32_t frame_stride) {
|
||||
NDIlib_video_frame_v2_t frame;
|
||||
auto type = NDIlib_recv_capture_v3(recv_, &frame, nullptr, nullptr, 5);
|
||||
enum class FrameKind { None, Video, Audio };
|
||||
|
||||
struct AudioInfo {
|
||||
int sample_rate = 0;
|
||||
int channels = 0;
|
||||
int samples = 0;
|
||||
int channel_stride = 0; // floats between channel planes (NDI planar layout)
|
||||
};
|
||||
|
||||
// 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.
|
||||
// Throws on source lost or video format change.
|
||||
FrameKind capture(uint8_t* frame_buffer, uint32_t frame_stride,
|
||||
std::vector<float>& audio_out, AudioInfo& audio_info) {
|
||||
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, 5);
|
||||
|
||||
if (type == NDIlib_frame_type_error)
|
||||
throw std::runtime_error("NDI source lost");
|
||||
@@ -135,30 +147,42 @@ public:
|
||||
std::to_string(info_.width) + "x" + std::to_string(info_.height) +
|
||||
" @" + std::to_string(info_.fps_num) + "/" + std::to_string(info_.fps_den));
|
||||
}
|
||||
return false;
|
||||
return FrameKind::None;
|
||||
}
|
||||
|
||||
if (type != NDIlib_frame_type_video)
|
||||
return false;
|
||||
|
||||
switch (info_.fourcc) {
|
||||
case NDIlib_FourCC_type_UYVY:
|
||||
v210::UYVYtoV210(frame.p_data, frame_buffer,
|
||||
info_.width, info_.height, info_.stride, frame_stride);
|
||||
break;
|
||||
case NDIlib_FourCC_type_P216: {
|
||||
NDIlib_video_frame_v2_t dst{};
|
||||
dst.p_data = frame_buffer;
|
||||
dst.line_stride_in_bytes = frame_stride;
|
||||
NDIlib_util_P216_to_V210(&frame, &dst);
|
||||
break;
|
||||
if (type == NDIlib_frame_type_video) {
|
||||
switch (info_.fourcc) {
|
||||
case NDIlib_FourCC_type_UYVY:
|
||||
v210::UYVYtoV210(video_frame.p_data, frame_buffer,
|
||||
info_.width, info_.height, info_.stride, frame_stride);
|
||||
break;
|
||||
case NDIlib_FourCC_type_P216: {
|
||||
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:
|
||||
NDIlib_recv_free_video_v2(recv_, &video_frame);
|
||||
throw std::runtime_error("Unsupported NDI color format: " + fourcc_str(info_.fourcc));
|
||||
}
|
||||
default:
|
||||
NDIlib_recv_free_video_v2(recv_, &frame);
|
||||
throw std::runtime_error("Unsupported NDI color format: " + fourcc_str(info_.fourcc));
|
||||
NDIlib_recv_free_video_v2(recv_, &video_frame);
|
||||
return FrameKind::Video;
|
||||
}
|
||||
NDIlib_recv_free_video_v2(recv_, &frame);
|
||||
return true;
|
||||
|
||||
if (type == NDIlib_frame_type_audio) {
|
||||
audio_info.sample_rate = audio_frame.sample_rate;
|
||||
audio_info.channels = audio_frame.no_channels;
|
||||
audio_info.samples = audio_frame.no_samples;
|
||||
audio_info.channel_stride = audio_frame.channel_stride_in_bytes / sizeof(float);
|
||||
const int total = audio_frame.no_channels * audio_info.channel_stride;
|
||||
audio_out.assign(audio_frame.p_data, audio_frame.p_data + total);
|
||||
NDIlib_recv_free_audio_v3(recv_, &audio_frame);
|
||||
return FrameKind::Audio;
|
||||
}
|
||||
|
||||
return FrameKind::None;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user