| 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 | pub const DEFAULT_BITRATE_PRIORITY: f64 = 1.0; |
| 16 | |
| 17 | #[cxx::bridge(namespace = "livekit_ffi")] |
| 18 | pub mod ffi { |
| 19 | |
| 20 | // Used to replace std::map |
| 21 | #[derive(Debug)] |
| 22 | pub struct StringKeyValue { |
| 23 | pub key: String, |
| 24 | pub value: String, |
| 25 | } |
| 26 | |
| 27 | #[derive(Debug)] |
| 28 | #[repr(i32)] |
| 29 | pub enum FecMechanism { |
| 30 | Red, |
| 31 | RedAndUlpfec, |
| 32 | FlexFec, |
| 33 | } |
| 34 | |
| 35 | #[derive(Debug)] |
| 36 | #[repr(i32)] |
| 37 | pub enum RtcpFeedbackType { |
| 38 | Ccm, |
| 39 | Lntf, |
| 40 | Nack, |
| 41 | Remb, |
| 42 | TransportCC, |
| 43 | } |
| 44 | |
| 45 | #[derive(Debug)] |
| 46 | #[repr(i32)] |
| 47 | pub enum RtcpFeedbackMessageType { |
| 48 | GenericNack, |
| 49 | Pli, |
| 50 | Fir, |
| 51 | } |
| 52 | |
| 53 | #[derive(Debug)] |
| 54 | #[repr(i32)] |
| 55 | pub enum DegradationPreference { |
| 56 | /// Maintain both framerate and resolution. Frames may be dropped before encoding |
| 57 | /// if necessary to avoid overusing network and encoder resources. |
| 58 | /// Note: This was previously called `Disabled` in older WebRTC versions. |
| 59 | MaintainFramerateAndResolution, |
| 60 | MaintainFramerate, |
| 61 | MaintainResolution, |
| 62 | Balanced, |
| 63 | } |
| 64 | |
| 65 | #[derive(Debug)] |
| 66 | pub struct RtcpFeedback { |
| 67 | pub feedback_type: RtcpFeedbackType, |
| 68 | pub has_message_type: bool, |
| 69 | pub message_type: RtcpFeedbackMessageType, |
| 70 | } |
| 71 | |
| 72 | #[derive(Debug)] |
| 73 | pub struct RtpCodecCapability { |
| 74 | pub mime_type: String, // filled with mime_type fnc |
| 75 | pub name: String, |
| 76 | pub kind: MediaType, |
| 77 | pub has_clock_rate: bool, |
| 78 | pub clock_rate: i32, |
| 79 | pub has_preferred_payload_type: bool, |
| 80 | pub preferred_payload_type: i32, |
| 81 | pub has_num_channels: bool, |
| 82 | pub num_channels: i32, |
| 83 | pub rtcp_feedback: Vec<RtcpFeedback>, |
| 84 | pub parameters: Vec<StringKeyValue>, |
| 85 | } |
| 86 | |
| 87 | #[derive(Debug)] |
| 88 | pub struct RtpHeaderExtensionCapability { |
| 89 | pub uri: String, |
| 90 | pub has_preferred_id: bool, |
| 91 | pub preferred_id: i32, |
| 92 | pub preferred_encrypt: bool, |
| 93 | pub direction: RtpTransceiverDirection, |
| 94 | } |
| 95 | |
| 96 | #[derive(Debug)] |
| 97 | #[repr(i32)] |
| 98 | pub enum RtpExtensionFilter { |
| 99 | DiscardEncryptedExtension, |
| 100 | PreferEncryptedExtension, |
| 101 | RequireEncryptedExtension, |
| 102 | } |
| 103 | |
| 104 | #[derive(Debug)] |
| 105 | pub struct RtpExtension { |
| 106 | // TODO(theomonnom): export available URI inside api/rtp_parameters.h |
| 107 | pub uri: String, |
| 108 | pub id: i32, |
| 109 | pub encrypt: bool, |
| 110 | } |
| 111 | |
| 112 | #[derive(Debug)] |
| 113 | pub struct RtpFecParameters { |
| 114 | pub has_ssrc: bool, |
| 115 | pub ssrc: u32, |
| 116 | pub mechanism: FecMechanism, |
| 117 | } |
| 118 | |
| 119 | #[derive(Debug)] |
| 120 | pub struct RtpRtxParameters { |
| 121 | pub has_ssrc: bool, |
| 122 | pub ssrc: u32, |
| 123 | } |
| 124 | |
| 125 | #[derive(Debug)] |
| 126 | pub struct RtpEncodingParameters { |
| 127 | pub has_ssrc: bool, |
| 128 | pub ssrc: u32, |
| 129 | pub bitrate_priority: f64, |
| 130 | pub network_priority: Priority, // Todo link type |
| 131 | pub has_max_bitrate_bps: bool, |
| 132 | pub max_bitrate_bps: i32, |
| 133 | pub has_min_bitrate_bps: bool, |
| 134 | pub min_bitrate_bps: i32, |
| 135 | pub has_max_framerate: bool, |
| 136 | pub max_framerate: f64, |
| 137 | pub has_num_temporal_layers: bool, |
| 138 | pub num_temporal_layers: i32, |
| 139 | pub has_scale_resolution_down_by: bool, |
| 140 | pub scale_resolution_down_by: f64, |
| 141 | pub has_scalability_mode: bool, |
| 142 | pub scalability_mode: String, |
| 143 | pub active: bool, |
| 144 | pub rid: String, |
| 145 | pub adaptive_ptime: bool, |
| 146 | } |
| 147 | |
| 148 | #[derive(Debug)] |
| 149 | pub struct RtpCodecParameters { |
| 150 | pub mime_type: String, // filled with mime_type fnc |
| 151 | pub name: String, |
| 152 | pub kind: MediaType, |
| 153 | pub payload_type: i32, |
| 154 | pub has_clock_rate: bool, |
| 155 | pub clock_rate: i32, |
| 156 | pub has_num_channels: bool, |
| 157 | pub num_channels: i32, |
| 158 | pub has_max_ptime: bool, |
| 159 | pub max_ptime: i32, |
| 160 | pub has_ptime: bool, |
| 161 | pub ptime: i32, |
| 162 | pub rtcp_feedback: Vec<RtcpFeedback>, |
| 163 | pub parameters: Vec<StringKeyValue>, |
| 164 | } |
| 165 | |
| 166 | #[derive(Debug)] |
| 167 | pub struct RtpCapabilities { |
| 168 | pub codecs: Vec<RtpCodecCapability>, |
| 169 | pub header_extensions: Vec<RtpHeaderExtensionCapability>, |
| 170 | pub fec: Vec<FecMechanism>, |
| 171 | } |
| 172 | |
| 173 | #[derive(Debug)] |
| 174 | pub struct RtcpParameters { |
| 175 | pub has_ssrc: bool, |
| 176 | pub ssrc: u32, |
| 177 | pub cname: String, |
| 178 | pub reduced_size: bool, |
| 179 | pub mux: bool, |
| 180 | } |
| 181 | |
| 182 | #[derive(Debug)] |
| 183 | pub struct RtpParameters { |
| 184 | pub transaction_id: String, |
| 185 | pub mid: String, |
| 186 | pub codecs: Vec<RtpCodecParameters>, |
| 187 | pub header_extensions: Vec<RtpExtension>, |
| 188 | pub encodings: Vec<RtpEncodingParameters>, |
| 189 | pub rtcp: RtcpParameters, |
| 190 | pub has_degradation_preference: bool, |
| 191 | pub degradation_preference: DegradationPreference, |
| 192 | } |
| 193 | |
| 194 | extern "C++" { |
| 195 | include!("livekit/webrtc.h"); |
| 196 | |
| 197 | type Priority = crate::webrtc::ffi::Priority; |
| 198 | type MediaType = crate::webrtc::ffi::MediaType; |
| 199 | type RtpTransceiverDirection = crate::webrtc::ffi::RtpTransceiverDirection; |
| 200 | } |
| 201 | } |