gstreamer_sdp/
sdp_zone.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{ffi::CStr, fmt, mem};
4
5use crate::ffi;
6use glib::translate::*;
7
8#[repr(transparent)]
9#[doc(alias = "GstSDPZone")]
10pub struct SDPZone(pub(crate) ffi::GstSDPZone);
11
12unsafe impl Send for SDPZone {}
13unsafe impl Sync for SDPZone {}
14
15impl SDPZone {
16    pub fn new(time: &str, typed_time: &str) -> Self {
17        assert_initialized_main_thread!();
18        unsafe {
19            let mut zone = mem::MaybeUninit::uninit();
20            ffi::gst_sdp_zone_set(
21                zone.as_mut_ptr(),
22                time.to_glib_none().0,
23                typed_time.to_glib_none().0,
24            );
25            SDPZone(zone.assume_init())
26        }
27    }
28
29    pub fn time(&self) -> Option<&str> {
30        unsafe {
31            if self.0.time.is_null() {
32                None
33            } else {
34                Some(CStr::from_ptr(self.0.time).to_str().unwrap())
35            }
36        }
37    }
38
39    pub fn typed_time(&self) -> Option<&str> {
40        unsafe {
41            if self.0.typed_time.is_null() {
42                None
43            } else {
44                Some(CStr::from_ptr(self.0.typed_time).to_str().unwrap())
45            }
46        }
47    }
48}
49
50impl Clone for SDPZone {
51    fn clone(&self) -> Self {
52        skip_assert_initialized!();
53        unsafe {
54            let mut zone = mem::MaybeUninit::uninit();
55            ffi::gst_sdp_zone_set(zone.as_mut_ptr(), self.0.time, self.0.typed_time);
56            SDPZone(zone.assume_init())
57        }
58    }
59}
60
61impl Drop for SDPZone {
62    fn drop(&mut self) {
63        unsafe {
64            ffi::gst_sdp_zone_clear(&mut self.0);
65        }
66    }
67}
68
69impl fmt::Debug for SDPZone {
70    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
71        f.debug_struct("SDPZone")
72            .field("time", &self.time())
73            .field("typed_time", &self.typed_time())
74            .finish()
75    }
76}