2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-04-05 18:22:40 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use glib::translate::*;
|
|
|
|
|
|
|
|
use crate::{WebRTCSDPType, WebRTCSessionDescription};
|
|
|
|
|
2018-04-05 18:22:40 +00:00
|
|
|
impl WebRTCSessionDescription {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_webrtc_session_description_new")]
|
2020-04-09 12:59:14 +00:00
|
|
|
pub fn new(type_: WebRTCSDPType, sdp: gst_sdp::SDPMessage) -> WebRTCSessionDescription {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2018-04-05 18:22:40 +00:00
|
|
|
unsafe {
|
2020-11-22 10:49:02 +00:00
|
|
|
from_glib_full(ffi::gst_webrtc_session_description_new(
|
2021-04-27 15:15:46 +00:00
|
|
|
type_.into_glib(),
|
2024-03-11 12:03:26 +00:00
|
|
|
sdp.into_glib_ptr(),
|
2020-04-11 18:18:18 +00:00
|
|
|
))
|
2018-04-05 18:22:40 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-05 21:31:05 +00:00
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_type")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn type_(&self) -> crate::WebRTCSDPType {
|
2023-01-17 07:59:02 +00:00
|
|
|
unsafe { from_glib((*self.as_ptr()).type_) }
|
2018-06-05 21:31:05 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 12:03:26 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Changes the type of this Session Description to the specified variant.
|
|
|
|
pub fn set_type(&mut self, type_: WebRTCSDPType) {
|
|
|
|
unsafe {
|
|
|
|
(*self.as_ptr()).type_ = type_.into_glib();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_sdp")]
|
2024-03-11 12:03:26 +00:00
|
|
|
pub fn sdp(&self) -> &gst_sdp::SDPMessageRef {
|
|
|
|
unsafe { &*((*self.as_ptr()).sdp as *const gst_sdp::SDPMessageRef) }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sdp_mut(&mut self) -> &mut gst_sdp::SDPMessageRef {
|
|
|
|
unsafe { &mut *((*self.as_ptr()).sdp as *mut gst_sdp::SDPMessageRef) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use crate::WebRTCSDPType;
|
|
|
|
use gst_sdp::SDPMessage;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn change_type() {
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
|
|
|
let mut desc =
|
|
|
|
crate::WebRTCSessionDescription::new(crate::WebRTCSDPType::Offer, SDPMessage::new());
|
|
|
|
assert_eq!(desc.type_(), WebRTCSDPType::Offer);
|
|
|
|
|
|
|
|
desc.set_type(WebRTCSDPType::Rollback);
|
|
|
|
assert_eq!(desc.type_(), WebRTCSDPType::Rollback);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn update_inner_msg() {
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
|
|
|
let mut sdp = SDPMessage::new();
|
|
|
|
sdp.set_information("init");
|
|
|
|
|
|
|
|
let mut desc = crate::WebRTCSessionDescription::new(WebRTCSDPType::Offer, sdp);
|
|
|
|
assert_eq!(desc.sdp().information(), Some("init"));
|
|
|
|
|
|
|
|
let sdp_owned = desc.sdp().to_owned();
|
|
|
|
|
|
|
|
// update inner sdp message
|
|
|
|
desc.sdp_mut().set_information("update");
|
|
|
|
assert_eq!(desc.sdp().information(), Some("update"));
|
|
|
|
|
|
|
|
// previously acquired owned sdp message unchanged
|
|
|
|
assert_eq!(sdp_owned.information(), Some("init"));
|
2018-06-05 21:31:05 +00:00
|
|
|
}
|
2018-04-05 18:22:40 +00:00
|
|
|
}
|