gstreamer_sdp/
sdp_connection.rs
1use std::{ffi::CStr, fmt, mem};
4
5use crate::ffi;
6use glib::translate::*;
7
8#[repr(transparent)]
9#[doc(alias = "GstSDPConnection")]
10pub struct SDPConnection(pub(crate) ffi::GstSDPConnection);
11
12unsafe impl Send for SDPConnection {}
13unsafe impl Sync for SDPConnection {}
14
15impl SDPConnection {
16 pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Self {
17 assert_initialized_main_thread!();
18 unsafe {
19 let mut conn = mem::MaybeUninit::uninit();
20 ffi::gst_sdp_connection_set(
21 conn.as_mut_ptr(),
22 nettype.to_glib_none().0,
23 addrtype.to_glib_none().0,
24 address.to_glib_none().0,
25 ttl,
26 addr_number,
27 );
28 SDPConnection(conn.assume_init())
29 }
30 }
31
32 pub fn nettype(&self) -> Option<&str> {
33 unsafe {
34 if self.0.nettype.is_null() {
35 None
36 } else {
37 Some(CStr::from_ptr(self.0.nettype).to_str().unwrap())
38 }
39 }
40 }
41
42 pub fn addrtype(&self) -> Option<&str> {
43 unsafe {
44 if self.0.addrtype.is_null() {
45 None
46 } else {
47 Some(CStr::from_ptr(self.0.addrtype).to_str().unwrap())
48 }
49 }
50 }
51
52 pub fn address(&self) -> Option<&str> {
53 unsafe {
54 if self.0.address.is_null() {
55 None
56 } else {
57 Some(CStr::from_ptr(self.0.address).to_str().unwrap())
58 }
59 }
60 }
61
62 pub fn ttl(&self) -> u32 {
63 self.0.ttl
64 }
65
66 pub fn addr_number(&self) -> u32 {
67 self.0.addr_number
68 }
69}
70
71impl Clone for SDPConnection {
72 fn clone(&self) -> Self {
73 skip_assert_initialized!();
74 unsafe {
75 let mut conn = mem::MaybeUninit::uninit();
76 ffi::gst_sdp_connection_set(
77 conn.as_mut_ptr(),
78 self.0.nettype,
79 self.0.addrtype,
80 self.0.address,
81 self.0.ttl,
82 self.0.addr_number,
83 );
84 SDPConnection(conn.assume_init())
85 }
86 }
87}
88
89impl Drop for SDPConnection {
90 fn drop(&mut self) {
91 unsafe {
92 ffi::gst_sdp_connection_clear(&mut self.0);
93 }
94 }
95}
96
97impl fmt::Debug for SDPConnection {
98 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
99 f.debug_struct("SDPConnection")
100 .field("nettype", &self.nettype())
101 .field("addrtype", &self.addrtype())
102 .field("address", &self.address())
103 .field("ttl", &self.ttl())
104 .field("addr_number", &self.addr_number())
105 .finish()
106 }
107}