webrtc_sys/
rtp_receiver.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 std::any::Any;
16
17use crate::impl_thread_safety;
18
19#[cxx::bridge(namespace = "livekit")]
20pub 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    unsafe extern "C++" {
36        include!("livekit/rtp_receiver.h");
37
38        type RtpReceiver;
39
40        fn track(self: &RtpReceiver) -> SharedPtr<MediaStreamTrack>;
41        fn get_stats(
42            self: &RtpReceiver,
43            ctx: Box<ReceiverContext>,
44            on_stats: fn(ctx: Box<ReceiverContext>, json: String),
45        );
46        fn stream_ids(self: &RtpReceiver) -> Vec<String>;
47        fn streams(self: &RtpReceiver) -> Vec<MediaStreamPtr>;
48        fn media_type(self: &RtpReceiver) -> MediaType;
49        fn id(self: &RtpReceiver) -> String;
50        fn get_parameters(self: &RtpReceiver) -> RtpParameters;
51        fn set_jitter_buffer_minimum_delay(self: &RtpReceiver, is_some: bool, delay_seconds: f64);
52
53        fn _shared_rtp_receiver() -> SharedPtr<RtpReceiver>;
54    }
55
56    extern "Rust" {
57        type ReceiverContext;
58    }
59}
60
61pub struct ReceiverContext(pub Box<dyn Any + Send>);
62
63impl_thread_safety!(ffi::RtpReceiver, Send + Sync);