1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use janus_plugin_sys as ffi;
pub fn has_fir(packet: &[i8]) -> bool {
unsafe { ffi::rtcp::janus_rtcp_has_fir(packet.as_ptr() as *mut _, packet.len() as i32) == 1 }
}
pub fn has_pli(packet: &[i8]) -> bool {
unsafe { ffi::rtcp::janus_rtcp_has_pli(packet.as_ptr() as *mut _, packet.len() as i32) == 1 }
}
pub fn get_remb(packet: &[i8]) -> Option<u32> {
unsafe {
match ffi::rtcp::janus_rtcp_get_remb(packet.as_ptr() as *mut _, packet.len() as i32) {
0 => None,
n => Some(n)
}
}
}
pub fn gen_fir(seq: &mut i32) -> Vec<i8> {
let mut packet = Vec::with_capacity(20);
let result = unsafe { ffi::rtcp::janus_rtcp_fir(packet.as_mut_ptr(), 20, seq) };
match result {
err if err < 0 => unreachable!(format!("Error generating FIR packet (code {}) :(", err)),
len => {
unsafe { packet.set_len(len as usize) };
packet
}
}
}
pub fn gen_pli() -> Vec<i8> {
let mut packet = Vec::with_capacity(12);
let result = unsafe { ffi::rtcp::janus_rtcp_pli(packet.as_mut_ptr(), 12) };
match result {
err if err < 0 => unreachable!(format!("Error generating PLI packet (code {}) :(", err)),
len => {
unsafe { packet.set_len(len as usize) };
packet
}
}
}
pub fn gen_remb(bitrate: u32) -> Vec<i8> {
let mut packet = Vec::with_capacity(24);
let result = unsafe { ffi::rtcp::janus_rtcp_remb(packet.as_mut_ptr(), 24, bitrate) };
match result {
err if err < 0 => unreachable!(format!("Error generating REMB packet (code {}).", err)),
len => {
unsafe { packet.set_len(len as usize) };
packet
}
}
}