Skip to main content

gstreamer_webrtc/
web_rtc_ice_candidate.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ffi::CStr;
4
5use crate::{WebRTCICECandidate, WebRTCICECandidateStats};
6
7impl WebRTCICECandidate {
8    pub fn candidate(&self) -> Option<&str> {
9        unsafe {
10            let ptr = (*self.as_ptr()).candidate;
11            if ptr.is_null() {
12                None
13            } else {
14                Some(CStr::from_ptr(ptr).to_str().unwrap())
15            }
16        }
17    }
18
19    pub fn component(&self) -> i32 {
20        unsafe { (*self.as_ptr()).component }
21    }
22
23    pub fn sdp_mid(&self) -> Option<&str> {
24        unsafe {
25            let ptr = (*self.as_ptr()).sdp_mid;
26            if ptr.is_null() {
27                None
28            } else {
29                Some(CStr::from_ptr(ptr).to_str().unwrap())
30            }
31        }
32    }
33
34    pub fn sdp_mline_index(&self) -> i32 {
35        unsafe { (*self.as_ptr()).sdp_mline_index }
36    }
37
38    pub fn stats(&self) -> Option<&WebRTCICECandidateStats> {
39        unsafe {
40            if (*self.as_ptr()).stats.is_null() {
41                None
42            } else {
43                Some(WebRTCICECandidateStats::from_glib_ptr_borrow(
44                    &(*self.as_ptr()).stats,
45                ))
46            }
47        }
48    }
49}