Skip to main content

rtp_engine/
lib.rs

1//! # rtp-engine
2//!
3//! A pure Rust RTP media engine for VoIP applications.
4//!
5//! This crate provides the building blocks for real-time audio communication:
6//!
7//! - **Codecs**: G.711 (μ-law/A-law) and Opus encoding/decoding
8//! - **RTP/RTCP**: Packet construction, parsing, and statistics
9//! - **SRTP**: Secure RTP with AES-CM-128-HMAC-SHA1-80
10//! - **Audio devices**: Cross-platform capture and playback via cpal
11//! - **Resampling**: Sample rate conversion between codecs and devices
12//!
13//! ## Quick Start
14//!
15//! ```rust,no_run
16//! use rtp_engine::{MediaSession, CodecType};
17//! use std::net::SocketAddr;
18//!
19//! #[tokio::main]
20//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//!     let remote: SocketAddr = "192.168.1.100:5004".parse()?;
22//!     
23//!     // Start a media session with G.711 μ-law
24//!     let session = MediaSession::start(10000, remote, CodecType::Pcmu).await?;
25//!     
26//!     // The session captures from mic and plays to speaker automatically
27//!     // Send DTMF
28//!     session.send_dtmf("1");
29//!     
30//!     // Mute/unmute
31//!     session.set_mute(true);
32//!     
33//!     // Get statistics
34//!     let stats = session.stats();
35//!     println!("Packets sent: {}", stats.packets_sent);
36//!     
37//!     // Stop when done
38//!     session.stop();
39//!     Ok(())
40//! }
41//! ```
42//!
43//! ## Feature Flags
44//!
45//! - `g711` (default): G.711 μ-law and A-law codecs
46//! - `opus`: Opus codec support (requires libopus)
47//! - `srtp`: SRTP/SRTCP encryption
48//! - `device`: Audio device capture/playback via cpal
49
50#![warn(missing_docs)]
51#![warn(rustdoc::missing_crate_level_docs)]
52
53pub mod codec;
54pub mod error;
55pub mod jitter;
56pub mod rtp;
57
58#[cfg(feature = "srtp")]
59pub mod srtp;
60
61#[cfg(feature = "device")]
62pub mod device;
63
64pub mod resample;
65mod session;
66
67// Re-exports for convenience
68pub use codec::CodecType;
69pub use error::{Error, Result};
70pub use jitter::{JitterBuffer, JitterConfig, JitterMode, JitterStats};
71pub use resample::{f32_to_i16, i16_to_f32, resample_linear, resample_linear_i16};
72pub use rtp::RtpStats;
73pub use session::MediaSession;
74
75#[cfg(feature = "srtp")]
76pub use srtp::SrtpContext;