| 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 | |
| 15 | use std::any::Any; |
| 16 | |
| 17 | use crate::impl_thread_safety; |
| 18 | |
| 19 | #[cxx::bridge(namespace = "livekit_ffi")] |
| 20 | pub mod ffi { |
| 21 | |
| 22 | extern "C++" { |
| 23 | include!("livekit/webrtc.h"); |
| 24 | include!("livekit/rtp_parameters.h"); |
| 25 | include!("livekit/helper.h"); |
| 26 | include!("livekit/media_stream.h"); |
| 27 | |
| 28 | type MediaType = crate::webrtc::ffi::MediaType; |
| 29 | type RtpParameters = crate::rtp_parameters::ffi::RtpParameters; |
| 30 | type MediaStreamPtr = crate::helper::ffi::MediaStreamPtr; |
| 31 | type MediaStreamTrack = crate::media_stream::ffi::MediaStreamTrack; |
| 32 | type MediaStream = crate::media_stream::ffi::MediaStream; |
| 33 | } |
| 34 | |
| 35 | pub struct RtpSourceEntry { |
| 36 | pub source_id: u32, |
| 37 | pub is_csrc: bool, |
| 38 | pub audio_level: i16, |
| 39 | pub timestamp_ms: i64, |
| 40 | } |
| 41 | |
| 42 | unsafe extern "C++" { |
| 43 | include!("livekit/rtp_receiver.h"); |
| 44 | |
| 45 | type RtpReceiver; |
| 46 | |
| 47 | fn track(self: &RtpReceiver) -> SharedPtr<MediaStreamTrack>; |
| 48 | fn get_stats( |
| 49 | self: &RtpReceiver, |
| 50 | ctx: Box<ReceiverContext>, |
| 51 | on_stats: fn(ctx: Box<ReceiverContext>, json: String), |
| 52 | ); |
| 53 | fn stream_ids(self: &RtpReceiver) -> Vec<String>; |
| 54 | fn streams(self: &RtpReceiver) -> Vec<MediaStreamPtr>; |
| 55 | fn media_type(self: &RtpReceiver) -> MediaType; |
| 56 | fn id(self: &RtpReceiver) -> String; |
| 57 | fn get_parameters(self: &RtpReceiver) -> RtpParameters; |
| 58 | fn set_jitter_buffer_minimum_delay(self: &RtpReceiver, is_some: bool, delay_seconds: f64); |
| 59 | fn get_sources(self: &RtpReceiver) -> Vec<RtpSourceEntry>; |
| 60 | |
| 61 | fn _shared_rtp_receiver() -> SharedPtr<RtpReceiver>; |
| 62 | } |
| 63 | |
| 64 | extern "Rust" { |
| 65 | type ReceiverContext; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | pub struct ReceiverContext(pub Box<dyn Any + Send>); |
| 70 | |
| 71 | impl_thread_safety!(ffi::RtpReceiver, Send + Sync); |