| 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 crate::impl_thread_safety; |
| 16 | |
| 17 | #[cxx::bridge(namespace = "livekit_ffi")] |
| 18 | pub mod ffi { |
| 19 | |
| 20 | #[derive(Debug)] |
| 21 | pub struct RtpTransceiverInit { |
| 22 | pub direction: RtpTransceiverDirection, |
| 23 | pub stream_ids: Vec<String>, |
| 24 | pub send_encodings: Vec<RtpEncodingParameters>, |
| 25 | } |
| 26 | |
| 27 | extern "C++" { |
| 28 | include!("livekit/webrtc.h"); |
| 29 | include!("livekit/rtp_parameters.h"); |
| 30 | include!("livekit/rtp_sender.h"); |
| 31 | include!("livekit/rtp_receiver.h"); |
| 32 | |
| 33 | type MediaType = crate::webrtc::ffi::MediaType; |
| 34 | type RtpTransceiverDirection = crate::webrtc::ffi::RtpTransceiverDirection; |
| 35 | type RtpEncodingParameters = crate::rtp_parameters::ffi::RtpEncodingParameters; |
| 36 | type RtpCodecCapability = crate::rtp_parameters::ffi::RtpCodecCapability; |
| 37 | type RtpHeaderExtensionCapability = |
| 38 | crate::rtp_parameters::ffi::RtpHeaderExtensionCapability; |
| 39 | type RtpSender = crate::rtp_sender::ffi::RtpSender; |
| 40 | type RtpReceiver = crate::rtp_receiver::ffi::RtpReceiver; |
| 41 | type RtcError = crate::rtc_error::ffi::RtcError; |
| 42 | } |
| 43 | |
| 44 | unsafe extern "C++" { |
| 45 | include!("livekit/rtp_transceiver.h"); |
| 46 | |
| 47 | type RtpTransceiver; |
| 48 | |
| 49 | fn media_type(self: &RtpTransceiver) -> MediaType; |
| 50 | fn mid(self: &RtpTransceiver) -> Result<String>; |
| 51 | fn sender(self: &RtpTransceiver) -> SharedPtr<RtpSender>; |
| 52 | fn receiver(self: &RtpTransceiver) -> SharedPtr<RtpReceiver>; |
| 53 | fn stopped(self: &RtpTransceiver) -> bool; |
| 54 | fn stopping(self: &RtpTransceiver) -> bool; |
| 55 | fn direction(self: &RtpTransceiver) -> RtpTransceiverDirection; |
| 56 | fn set_direction(self: &RtpTransceiver, direction: RtpTransceiverDirection) -> Result<()>; |
| 57 | fn current_direction(self: &RtpTransceiver) -> Result<RtpTransceiverDirection>; |
| 58 | fn fired_direction(self: &RtpTransceiver) -> Result<RtpTransceiverDirection>; |
| 59 | fn stop_standard(self: &RtpTransceiver) -> Result<()>; |
| 60 | fn set_codec_preferences( |
| 61 | self: &RtpTransceiver, |
| 62 | codecs: Vec<RtpCodecCapability>, |
| 63 | ) -> Result<()>; |
| 64 | fn codec_preferences(self: &RtpTransceiver) -> Vec<RtpCodecCapability>; |
| 65 | fn header_extensions_to_negotiate( |
| 66 | self: &RtpTransceiver, |
| 67 | ) -> Vec<RtpHeaderExtensionCapability>; |
| 68 | fn negotiated_header_extensions(self: &RtpTransceiver) |
| 69 | -> Vec<RtpHeaderExtensionCapability>; |
| 70 | fn set_header_extensions_to_negotiate( |
| 71 | self: &RtpTransceiver, |
| 72 | headers: Vec<RtpHeaderExtensionCapability>, |
| 73 | ) -> Result<()>; |
| 74 | |
| 75 | fn _shared_rtp_transceiver() -> SharedPtr<RtpTransceiver>; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | impl_thread_safety!(ffi::RtpTransceiver, Send + Sync); |