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