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-03-29 18:43:25 +00:00
|
|
|
|
|
|
|
use std::ffi::CStr;
|
2019-02-28 18:09:00 +00:00
|
|
|
use std::fmt;
|
2018-04-05 17:41:31 +00:00
|
|
|
use std::mem;
|
2018-03-29 18:43:25 +00:00
|
|
|
|
2018-04-04 18:40:45 +00:00
|
|
|
use glib::translate::*;
|
2018-03-29 18:43:25 +00:00
|
|
|
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstSDPAttribute")]
|
2020-11-22 10:38:16 +00:00
|
|
|
pub struct SDPAttribute(pub(crate) ffi::GstSDPAttribute);
|
2018-03-29 18:43:25 +00:00
|
|
|
|
2019-12-18 15:04:42 +00:00
|
|
|
unsafe impl Send for SDPAttribute {}
|
|
|
|
unsafe impl Sync for SDPAttribute {}
|
|
|
|
|
2018-03-29 18:43:25 +00:00
|
|
|
impl SDPAttribute {
|
2019-02-28 18:09:00 +00:00
|
|
|
pub fn new(key: &str, value: Option<&str>) -> Self {
|
2018-03-29 18:43:25 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2019-07-11 13:02:46 +00:00
|
|
|
let mut attr = mem::MaybeUninit::zeroed();
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::gst_sdp_attribute_set(
|
2019-07-11 13:02:46 +00:00
|
|
|
attr.as_mut_ptr(),
|
2019-03-19 07:58:20 +00:00
|
|
|
key.to_glib_none().0,
|
|
|
|
value.to_glib_none().0,
|
|
|
|
);
|
2019-07-11 13:02:46 +00:00
|
|
|
SDPAttribute(attr.assume_init())
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn key(&self) -> &str {
|
2018-04-05 17:41:31 +00:00
|
|
|
unsafe { CStr::from_ptr(self.0.key).to_str().unwrap() }
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 18:09:00 +00:00
|
|
|
pub fn value(&self) -> Option<&str> {
|
|
|
|
unsafe {
|
|
|
|
let ptr = self.0.value;
|
|
|
|
|
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(CStr::from_ptr(ptr).to_str().unwrap())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clone for SDPAttribute {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
SDPAttribute::new(self.key(), self.value())
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for SDPAttribute {
|
|
|
|
fn drop(&mut self) {
|
2018-04-04 18:40:45 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::gst_sdp_attribute_clear(&mut self.0);
|
2018-04-04 18:40:45 +00:00
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-28 18:09:00 +00:00
|
|
|
|
|
|
|
impl fmt::Debug for SDPAttribute {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("SDPAttribute")
|
|
|
|
.field("key", &self.key())
|
|
|
|
.field("value", &self.value())
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|