From 3232eb0312d2afb341b2993d7a1ce29aad4c43d8 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 11 Sep 2026 00:52:22 +0200 Subject: [PATCH] A headless receive probe Dials an advertised endpoint and reports frames, audio, bytes and feedback per second: the whole receive path minus the renderer. First run tonight: 416 frames in 14 s from Raven to Starfire, nothing expired, nothing repaired. Co-Authored-By: Claude Fable 5.1 --- crates/ratatoskr-core/examples/receive.rs | 75 +++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 crates/ratatoskr-core/examples/receive.rs diff --git a/crates/ratatoskr-core/examples/receive.rs b/crates/ratatoskr-core/examples/receive.rs new file mode 100644 index 0000000..f165691 --- /dev/null +++ b/crates/ratatoskr-core/examples/receive.rs @@ -0,0 +1,75 @@ +//! Dial a producer and say what arrives, without OBS. +//! +//! ```text +//! cargo run --example receive -- [seconds] [receiver-id] +//! ``` +//! +//! `` and `` are what the advertisement says +//! (`dial … conn …` in the `catalog` example). Prints attachment, then one +//! line per second: whole video frames completed, chunks repaired, frames +//! given up on, audio packets, bytes, and what was sent back. This is the +//! whole receive path the OBS source runs, minus the renderer, so a working +//! line here and a black source in OBS is a plugin question, not a pipe one. + +use std::net::ToSocketAddrs; +use std::time::{Duration, Instant}; + +use ratatoskr_core::{MediaEvent, RatatoskrReceiver, ReceiverOptions}; + +fn main() -> anyhow::Result<()> { + let args: Vec = std::env::args().skip(1).collect(); + let [endpoint, connection, rest @ ..] = args.as_slice() else { + anyhow::bail!("usage: receive [seconds] [receiver-id]"); + }; + let seconds: u64 = rest.first().map(|s| s.parse()).transpose()?.unwrap_or(15); + let receiver_id = rest.get(1).cloned().unwrap_or_else(|| "ratatoskr-receive-probe".to_string()); + let connection_id = u32::from_str_radix(connection.trim_start_matches("0x"), 16) + .or_else(|_| connection.parse::())?; + let producer = endpoint + .to_socket_addrs()? + .next() + .ok_or_else(|| anyhow::anyhow!("{endpoint} resolves to nothing"))?; + + let mut receiver = RatatoskrReceiver::open(ReceiverOptions::new(producer, receiver_id, connection_id))?; + println!("dialling {producer} conn {connection_id:#x} for {seconds}s"); + let started = Instant::now(); + let mut next_line = started + Duration::from_secs(1); + let (mut frames, mut audio, mut keyframes) = (0u64, 0u64, 0u64); + while started.elapsed() < Duration::from_secs(seconds) { + for event in receiver.poll()? { + match event { + MediaEvent::ProducerAttached { remote } => println!("attached to {remote}"), + MediaEvent::ProducerDetached { remote, reason } => println!("detached from {remote}: {reason}"), + MediaEvent::VideoFrame { frame } => { + frames += 1; + if frame.keyframe { + keyframes += 1; + } + } + MediaEvent::Audio { .. } => audio += 1, + MediaEvent::Undecodable { reason, .. } => println!("undecodable: {reason}"), + MediaEvent::Rejected { reason } => println!("rejected: {reason}"), + _ => {} + } + } + if Instant::now() >= next_line { + let (payloads, bytes) = receiver.delivered(); + let video = receiver.video_stats(); + let feedback = receiver.feedback_stats(); + println!( + "{:>3}s attached={} frames={frames} (key {keyframes}) audio={audio} payloads={payloads} bytes={bytes} repaired={} expired={} redials={} fed_back={} repairs_asked={} keyframes_asked={}", + started.elapsed().as_secs(), + receiver.attached(), + video.repaired_chunks, + video.expired, + receiver.redials(), + feedback.sent, + feedback.chunks_requested, + feedback.keyframes_requested, + ); + next_line += Duration::from_secs(1); + } + std::thread::sleep(Duration::from_millis(2)); + } + Ok(()) +}