webrtc_sys/
helper.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
15#[cxx::bridge(namespace = "livekit_ffi")]
16pub mod ffi {
17    // Wrapper to opaque C++ objects
18    // https://github.com/dtolnay/cxx/issues/741
19    // Used to allow SharedPtr/UniquePtr type inside a rust::Vec
20    pub struct MediaStreamPtr {
21        pub ptr: SharedPtr<MediaStream>,
22    }
23
24    pub struct CandidatePtr {
25        pub ptr: SharedPtr<Candidate>,
26    }
27
28    pub struct AudioTrackPtr {
29        pub ptr: SharedPtr<AudioTrack>,
30    }
31
32    pub struct VideoTrackPtr {
33        pub ptr: SharedPtr<VideoTrack>,
34    }
35
36    pub struct RtpSenderPtr {
37        pub ptr: SharedPtr<RtpSender>,
38    }
39
40    pub struct RtpReceiverPtr {
41        pub ptr: SharedPtr<RtpReceiver>,
42    }
43
44    pub struct RtpTransceiverPtr {
45        pub ptr: SharedPtr<RtpTransceiver>,
46    }
47
48    unsafe extern "C++" {
49        include!("livekit/helper.h");
50
51        type MediaStream = crate::media_stream::ffi::MediaStream;
52        type AudioTrack = crate::media_stream::ffi::AudioTrack;
53        type VideoTrack = crate::media_stream::ffi::VideoTrack;
54        type Candidate = crate::candidate::ffi::Candidate;
55        type RtpSender = crate::rtp_sender::ffi::RtpSender;
56        type RtpReceiver = crate::rtp_receiver::ffi::RtpReceiver;
57        type RtpTransceiver = crate::rtp_transceiver::ffi::RtpTransceiver;
58
59        fn _vec_media_stream_ptr() -> Vec<MediaStreamPtr>;
60        fn _vec_candidate_ptr() -> Vec<CandidatePtr>;
61        fn _vec_audio_track_ptr() -> Vec<AudioTrackPtr>;
62        fn _vec_video_track_ptr() -> Vec<VideoTrackPtr>;
63        fn _vec_rtp_sender_ptr() -> Vec<RtpSenderPtr>;
64        fn _vec_rtp_receiver_ptr() -> Vec<RtpReceiverPtr>;
65        fn _vec_rtp_transceiver_ptr() -> Vec<RtpTransceiverPtr>;
66    }
67}