webrtc_sys/
rtp_parameters.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
15pub const DEFAULT_BITRATE_PRIORITY: f64 = 1.0;
16
17#[cxx::bridge(namespace = "livekit")]
18pub 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        Disabled,
57        MaintainFramerate,
58        MaintainResolution,
59        Balanced,
60    }
61
62    #[derive(Debug)]
63    pub struct RtcpFeedback {
64        pub feedback_type: RtcpFeedbackType,
65        pub has_message_type: bool,
66        pub message_type: RtcpFeedbackMessageType,
67    }
68
69    #[derive(Debug)]
70    pub struct RtpCodecCapability {
71        pub mime_type: String, // filled with mime_type fnc
72        pub name: String,
73        pub kind: MediaType,
74        pub has_clock_rate: bool,
75        pub clock_rate: i32,
76        pub has_preferred_payload_type: bool,
77        pub preferred_payload_type: i32,
78        pub has_num_channels: bool,
79        pub num_channels: i32,
80        pub rtcp_feedback: Vec<RtcpFeedback>,
81        pub parameters: Vec<StringKeyValue>,
82    }
83
84    #[derive(Debug)]
85    pub struct RtpHeaderExtensionCapability {
86        pub uri: String,
87        pub has_preferred_id: bool,
88        pub preferred_id: i32,
89        pub preferred_encrypt: bool,
90        pub direction: RtpTransceiverDirection,
91    }
92
93    #[derive(Debug)]
94    #[repr(i32)]
95    pub enum RtpExtensionFilter {
96        DiscardEncryptedExtension,
97        PreferEncryptedExtension,
98        RequireEncryptedExtension,
99    }
100
101    #[derive(Debug)]
102    pub struct RtpExtension {
103        // TODO(theomonnom): export available URI inside api/rtp_parameters.h
104        pub uri: String,
105        pub id: i32,
106        pub encrypt: bool,
107    }
108
109    #[derive(Debug)]
110    pub struct RtpFecParameters {
111        pub has_ssrc: bool,
112        pub ssrc: u32,
113        pub mechanism: FecMechanism,
114    }
115
116    #[derive(Debug)]
117    pub struct RtpRtxParameters {
118        pub has_ssrc: bool,
119        pub ssrc: u32,
120    }
121
122    #[derive(Debug)]
123    pub struct RtpEncodingParameters {
124        pub has_ssrc: bool,
125        pub ssrc: u32,
126        pub bitrate_priority: f64,
127        pub network_priority: Priority, // Todo link type
128        pub has_max_bitrate_bps: bool,
129        pub max_bitrate_bps: i32,
130        pub has_min_bitrate_bps: bool,
131        pub min_bitrate_bps: i32,
132        pub has_max_framerate: bool,
133        pub max_framerate: f64,
134        pub has_num_temporal_layers: bool,
135        pub num_temporal_layers: i32,
136        pub has_scale_resolution_down_by: bool,
137        pub scale_resolution_down_by: f64,
138        pub has_scalability_mode: bool,
139        pub scalability_mode: String,
140        pub active: bool,
141        pub rid: String,
142        pub adaptive_ptime: bool,
143    }
144
145    #[derive(Debug)]
146    pub struct RtpCodecParameters {
147        pub mime_type: String, // filled with mime_type fnc
148        pub name: String,
149        pub kind: MediaType,
150        pub payload_type: i32,
151        pub has_clock_rate: bool,
152        pub clock_rate: i32,
153        pub has_num_channels: bool,
154        pub num_channels: i32,
155        pub has_max_ptime: bool,
156        pub max_ptime: i32,
157        pub has_ptime: bool,
158        pub ptime: i32,
159        pub rtcp_feedback: Vec<RtcpFeedback>,
160        pub parameters: Vec<StringKeyValue>,
161    }
162
163    #[derive(Debug)]
164    pub struct RtpCapabilities {
165        pub codecs: Vec<RtpCodecCapability>,
166        pub header_extensions: Vec<RtpHeaderExtensionCapability>,
167        pub fec: Vec<FecMechanism>,
168    }
169
170    #[derive(Debug)]
171    pub struct RtcpParameters {
172        pub has_ssrc: bool,
173        pub ssrc: u32,
174        pub cname: String,
175        pub reduced_size: bool,
176        pub mux: bool,
177    }
178
179    #[derive(Debug)]
180    pub struct RtpParameters {
181        pub transaction_id: String,
182        pub mid: String,
183        pub codecs: Vec<RtpCodecParameters>,
184        pub header_extensions: Vec<RtpExtension>,
185        pub encodings: Vec<RtpEncodingParameters>,
186        pub rtcp: RtcpParameters,
187        pub has_degradation_preference: bool,
188        pub degradation_preference: DegradationPreference,
189    }
190
191    extern "C++" {
192        include!("livekit/webrtc.h");
193
194        type Priority = crate::webrtc::ffi::Priority;
195        type MediaType = crate::webrtc::ffi::MediaType;
196        type RtpTransceiverDirection = crate::webrtc::ffi::RtpTransceiverDirection;
197    }
198}