webrtc_sys/
apm.rs

1// Copyright 2025 LiveKit, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::impl_thread_safety;
16
17#[cxx::bridge(namespace = "livekit")]
18pub mod ffi {
19    unsafe extern "C++" {
20        include!("livekit/apm.h");
21
22        type AudioProcessingModule;
23
24        unsafe fn process_stream(
25            self: Pin<&mut AudioProcessingModule>,
26            src: *const i16,
27            src_len: usize,
28            dst: *mut i16,
29            dst_len: usize,
30            sample_rate: i32,
31            num_channels: i32,
32        ) -> i32;
33
34        unsafe fn process_reverse_stream(
35            self: Pin<&mut AudioProcessingModule>,
36            src: *const i16,
37            src_len: usize,
38            dst: *mut i16,
39            dst_len: usize,
40            sample_rate: i32,
41            num_channels: i32,
42        ) -> i32;
43
44        fn set_stream_delay_ms(self: Pin<&mut AudioProcessingModule>, delay: i32) -> i32;
45
46        fn create_apm(
47            echo_canceller_enabled: bool,
48            gain_controller_enabled: bool,
49            high_pass_filter_enabled: bool,
50            noise_suppression_enabled: bool,
51        ) -> UniquePtr<AudioProcessingModule>;
52    }
53}
54
55impl_thread_safety!(ffi::AudioProcessingModule, Send + Sync);