videocall_codecs/lib.rs
1/*
2 * Copyright 2025 Security Union LLC
3 *
4 * Licensed under either of
5 *
6 * * Apache License, Version 2.0
7 * (http://www.apache.org/licenses/LICENSE-2.0)
8 * * MIT license
9 * (http://opensource.org/licenses/MIT)
10 *
11 * at your option.
12 *
13 * Unless you explicitly state otherwise, any contribution intentionally
14 * submitted for inclusion in the work by you, as defined in the Apache-2.0
15 * license, shall be dual licensed as above, without any additional terms or
16 * conditions.
17 */
18
19//! A high-fidelity, cross-platform video decoder jitter buffer implementation in Rust.
20
21pub mod decoder;
22#[cfg(not(target_arch = "wasm32"))]
23pub mod encoder;
24pub mod frame;
25pub mod jitter_buffer;
26pub mod jitter_estimator;
27
28// Diagnostics helper to publish video metrics via the shared event bus.
29#[cfg(feature = "wasm")]
30pub mod video_diagnostics {
31 use videocall_diagnostics::{global_sender, metric, now_ms, DiagEvent};
32
33 /// Publish video stats to the global diagnostics stream. `stream_id` should be
34 /// in the format "from_peer->to_peer" to align with health reporting expectations.
35 pub fn report_video_stats(stream_id: String, fps: Option<f64>, frames_buffered: Option<u64>) {
36 let mut metrics = Vec::new();
37 if let Some(f) = fps {
38 metrics.push(metric!("fps_received", f));
39 }
40 if let Some(b) = frames_buffered {
41 metrics.push(metric!("frames_buffered", b));
42 }
43
44 if metrics.is_empty() {
45 return;
46 }
47
48 let event = DiagEvent {
49 subsystem: "video",
50 stream_id: Some(stream_id),
51 ts_ms: now_ms(),
52 metrics,
53 };
54 // Best-effort broadcast; ignore backpressure errors
55 let _ = global_sender().try_broadcast(event);
56 }
57}