gstreamer_webrtc/
web_rtc_session_description.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{WebRTCSDPType, WebRTCSessionDescription};
6
7impl WebRTCSessionDescription {
8    #[doc(alias = "gst_webrtc_session_description_new")]
9    pub fn new(type_: WebRTCSDPType, sdp: gst_sdp::SDPMessage) -> WebRTCSessionDescription {
10        skip_assert_initialized!();
11        unsafe {
12            from_glib_full(crate::ffi::gst_webrtc_session_description_new(
13                type_.into_glib(),
14                sdp.into_glib_ptr(),
15            ))
16        }
17    }
18
19    #[doc(alias = "get_type")]
20    pub fn type_(&self) -> crate::WebRTCSDPType {
21        unsafe { from_glib((*self.as_ptr()).type_) }
22    }
23
24    // rustdoc-stripper-ignore-next
25    /// Changes the type of this Session Description to the specified variant.
26    pub fn set_type(&mut self, type_: WebRTCSDPType) {
27        unsafe {
28            (*self.as_ptr()).type_ = type_.into_glib();
29        }
30    }
31
32    #[doc(alias = "get_sdp")]
33    pub fn sdp(&self) -> &gst_sdp::SDPMessageRef {
34        unsafe { &*((*self.as_ptr()).sdp as *const gst_sdp::SDPMessageRef) }
35    }
36
37    pub fn sdp_mut(&mut self) -> &mut gst_sdp::SDPMessageRef {
38        unsafe { &mut *((*self.as_ptr()).sdp as *mut gst_sdp::SDPMessageRef) }
39    }
40}
41
42#[cfg(test)]
43mod tests {
44    use crate::WebRTCSDPType;
45    use gst_sdp::SDPMessage;
46
47    #[test]
48    fn change_type() {
49        gst::init().unwrap();
50
51        let mut desc =
52            crate::WebRTCSessionDescription::new(crate::WebRTCSDPType::Offer, SDPMessage::new());
53        assert_eq!(desc.type_(), WebRTCSDPType::Offer);
54
55        desc.set_type(WebRTCSDPType::Rollback);
56        assert_eq!(desc.type_(), WebRTCSDPType::Rollback);
57    }
58
59    #[test]
60    fn update_inner_msg() {
61        gst::init().unwrap();
62
63        let mut sdp = SDPMessage::new();
64        sdp.set_information("init");
65
66        let mut desc = crate::WebRTCSessionDescription::new(WebRTCSDPType::Offer, sdp);
67        assert_eq!(desc.sdp().information(), Some("init"));
68
69        let sdp_owned = desc.sdp().to_owned();
70
71        // update inner sdp message
72        desc.sdp_mut().set_information("update");
73        assert_eq!(desc.sdp().information(), Some("update"));
74
75        // previously acquired owned sdp message unchanged
76        assert_eq!(sdp_owned.information(), Some("init"));
77    }
78}