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