gstreamer-rs/gstreamer-rtsp-server/src/rtsp_token.rs

85 lines
2.3 KiB
Rust
Raw Normal View History

2020-12-15 10:53:31 +00:00
// Take a look at the license at the top of the repository in the LICENSE file.
use std::fmt;
2018-03-01 23:46:12 +00:00
use glib::{translate::*, value::ToSendValue};
gst::mini_object_wrapper!(RTSPToken, RTSPTokenRef, ffi::GstRTSPToken, || {
ffi::gst_rtsp_token_get_type()
});
2018-03-01 23:46:12 +00:00
impl RTSPToken {
#[doc(alias = "gst_rtsp_token_new_empty")]
pub fn new_empty() -> Self {
2018-03-01 23:46:12 +00:00
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gst_rtsp_token_new_empty()) }
2018-03-01 23:46:12 +00:00
}
2021-04-20 07:19:02 +00:00
pub fn new(values: &[(&str, &(dyn ToSendValue + Sync))]) -> Self {
skip_assert_initialized!();
let mut token = RTSPToken::new_empty();
{
let token = token.get_mut().unwrap();
let structure = token.structure_mut();
for &(f, v) in values {
structure.set_value(f, v.to_send_value());
}
}
token
}
2018-03-01 23:46:12 +00:00
}
impl RTSPTokenRef {
#[doc(alias = "get_string")]
#[doc(alias = "gst_rtsp_token_get_string")]
2021-04-20 10:23:24 +00:00
pub fn string(&self, field: &str) -> Option<String> {
2018-03-01 23:46:12 +00:00
unsafe {
from_glib_none(ffi::gst_rtsp_token_get_string(
2018-04-01 08:30:03 +00:00
self.as_mut_ptr(),
field.to_glib_none().0,
))
2018-03-01 23:46:12 +00:00
}
}
#[doc(alias = "get_structure")]
#[doc(alias = "gst_rtsp_token_get_structure")]
2021-04-11 19:39:50 +00:00
pub fn structure(&self) -> Option<gst::Structure> {
unsafe { from_glib_none(ffi::gst_rtsp_token_get_structure(self.as_mut_ptr())) }
2018-03-01 23:46:12 +00:00
}
#[doc(alias = "gst_rtsp_token_is_allowed")]
2018-03-01 23:46:12 +00:00
pub fn is_allowed(&self, field: &str) -> bool {
unsafe {
from_glib(ffi::gst_rtsp_token_is_allowed(
2018-04-01 08:30:03 +00:00
self.as_mut_ptr(),
field.to_glib_none().0,
))
2018-03-01 23:46:12 +00:00
}
}
#[doc(alias = "get_mut_structure")]
pub fn structure_mut(&mut self) -> &mut gst::StructureRef {
unsafe {
let structure = ffi::gst_rtsp_token_writable_structure(self.as_mut_ptr());
gst::StructureRef::from_glib_borrow_mut(structure)
}
}
}
2018-03-01 23:46:12 +00:00
impl fmt::Debug for RTSPToken {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
RTSPTokenRef::fmt(self, f)
}
}
impl fmt::Debug for RTSPTokenRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("RTSPToken")
2021-04-11 19:39:50 +00:00
.field("structure", &self.structure())
.finish()
2018-03-01 23:46:12 +00:00
}
}