Skip to main content

active_call/media/
mod.rs

1use serde::{Deserialize, Serialize};
2
3pub mod agc;
4pub mod ambiance;
5pub mod asr_processor;
6pub mod cache;
7pub mod denoiser;
8pub mod dtmf;
9pub mod engine;
10pub mod inactivity;
11pub mod loader;
12pub mod monitor;
13pub mod negotiate;
14pub mod processor;
15pub mod realtime_processor;
16pub mod recorder;
17#[cfg(feature = "ringback-detection")]
18pub mod ringback_detection;
19pub mod stream;
20#[cfg(test)]
21mod tests;
22pub mod track;
23pub mod vad;
24pub mod volume_control;
25pub use audio_codec::PcmBuf;
26pub use audio_codec::Sample;
27pub const INTERNAL_SAMPLERATE: u32 = 16000;
28pub type TrackId = String;
29pub type PayloadBuf = Vec<u8>;
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub enum Samples {
33    PCM {
34        samples: PcmBuf,
35    },
36    RTP {
37        sequence_number: u16,
38        payload_type: u8,
39        payload: PayloadBuf,
40    },
41    /// Transport-agnostic DTMF event update (RFC 4733 semantics). Emitted once
42    /// per ptime while a digit is held; `duration_ms` is cumulative since the
43    /// event started, `end` marks the final update. RTP tracks map it to the
44    /// negotiated telephone-event payload type and clock.
45    Dtmf {
46        event: u8,
47        duration_ms: u32,
48        end: bool,
49    },
50    Empty,
51}
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct SourcePacket {
54    pub sequence_number: u16,
55    pub payload_type: u8,
56    pub payload: PayloadBuf,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct AudioFrame {
61    pub track_id: TrackId,
62    pub samples: Samples,
63    pub src_packet: Option<SourcePacket>,
64    pub timestamp: u64,
65    pub sample_rate: u32,
66    pub channels: u16,
67    #[serde(default, skip_serializing_if = "Option::is_none")]
68    pub speech_probability: Option<f32>,
69}
70
71impl Samples {
72    pub fn payload_type(&self) -> Option<u8> {
73        match self {
74            Samples::RTP { payload_type, .. } => Some(*payload_type),
75            _ => None,
76        }
77    }
78}
79
80// get timestamp in milliseconds
81pub fn get_timestamp() -> u64 {
82    let now = std::time::SystemTime::now();
83    now.duration_since(std::time::UNIX_EPOCH)
84        .expect("Time went backwards")
85        .as_millis() as u64
86}