Skip to main content

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;
27pub mod messages;
28
29// Diagnostics helper to publish video metrics via the shared event bus.
30#[cfg(feature = "wasm")]
31pub mod video_diagnostics {
32    use videocall_diagnostics::{global_sender, metric, now_ms, DiagEvent};
33
34    /// Publish video stats to the global diagnostics stream. `stream_id` should be
35    /// in the format "from_peer->to_peer" to align with health reporting expectations.
36    pub fn report_video_stats(stream_id: String, fps: Option<f64>, frames_buffered: Option<u64>) {
37        let mut metrics = Vec::new();
38        if let Some(f) = fps {
39            metrics.push(metric!("fps_received", f));
40        }
41        if let Some(b) = frames_buffered {
42            metrics.push(metric!("frames_buffered", b));
43        }
44
45        if metrics.is_empty() {
46            return;
47        }
48
49        let event = DiagEvent {
50            subsystem: "video",
51            stream_id: Some(stream_id),
52            ts_ms: now_ms(),
53            metrics,
54        };
55        // Best-effort broadcast; ignore backpressure errors
56        let _ = global_sender().try_broadcast(event);
57    }
58}