1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//! # kessel-audio
//!
//! A real-time voice audio pipeline in pure Rust, for apps that carry live
//! calls over their own transport. It owns everything between the
//! microphone and speaker and the encoded frames on the wire:
//!
//! - **devices:** capture and playback through cpal (CoreAudio, WASAPI,
//! ALSA), device lists, hot-plug, switching, and a null device for
//! headless use; on iOS and Android, the OS's own voice processing
//! (`Backend::OsVoiceProcessing`);
//! - **resampling** between the device rate and 48 kHz (rubato);
//! - **echo cancellation, noise suppression and gain control** (sonora, a
//! port of WebRTC's audio processing), with the playback mix as the echo
//! reference;
//! - **a capture stage** of your own (a noise-removal model, say) between
//! echo cancellation and gain control, held to a time budget with a
//! bypass that never shifts the timing ([`CaptureStage`]);
//! - **Opus** encode and decode (ropus), 48 kHz mono, 20 ms frames, with
//! the caller's bitrate, FEC, DTX and complexity;
//! - **a jitter buffer per participant** with loss concealment and FEC
//! recovery;
//! - **mixing**, **levels** (about every 50 ms) and **statistics**.
//!
//! The transport (RTP, encryption, signalling) stays outside: kessel-audio
//! produces plaintext [`EncodedFrame`]s and consumes [`RecvFrame`]s that the
//! transport has already decrypted and verified.
//!
//! ## Example
//!
//! ```no_run
//! use kessel_audio::{AudioEngine, EngineConfig, RecvFrame};
//!
//! let engine = AudioEngine::start(EngineConfig::default())?;
//! let frames = engine.capture_frames();
//! engine.add_participant(7);
//! loop {
//! // Send path: encrypt and send each encoded frame.
//! while let Some(f) = frames.try_recv() {
//! let _ = (f.payload, f.ts48k);
//! }
//! // Receive path: hand over each decrypted, verified packet.
//! # let packet: Option<RecvFrame> = None;
//! if let Some(p) = packet {
//! engine.push(p);
//! }
//! # break;
//! }
//! # Ok::<(), kessel_audio::AudioError>(())
//! ```
//!
//! ## Threads
//!
//! [`AudioEngine`] is a `Send + Sync` handle; no async runtime is needed.
//! Device callbacks only move samples through lock-free rings; one
//! processing thread does the signal processing and codec work; a control
//! thread handles devices and events. Every queue between the caller and
//! the engine is bounded and lock-free, and the audio side never blocks on
//! one: a full queue drops (and counts) instead.
// macOS's microphone permission calls (`mic::macos`) and the phone
// backends' OS calls (`phone::ios`, `phone::android`) are the only `unsafe`
// outside tests.
// Runs the README's examples as doctests.
;
pub use ;
/// The `bytes` crate, re-exported so callers build payloads with the same
/// version.
pub use bytes;
pub use ;
pub use ;
pub use AudioEngine;
pub use ;
pub use ;
pub use ;
pub use JitterConfig;
pub use ;
pub use ;
pub use ;