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-12-08 09:31:07 +00:00
|
|
|
use std::fmt;
|
2018-03-01 23:46:12 +00:00
|
|
|
|
2024-04-09 06:24:16 +00:00
|
|
|
use glib::{translate::*, SendValue};
|
2023-01-03 18:58:25 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::mini_object_wrapper!(RTSPToken, RTSPTokenRef, ffi::GstRTSPToken, || {
|
2020-11-22 10:45:51 +00:00
|
|
|
ffi::gst_rtsp_token_get_type()
|
|
|
|
});
|
2018-03-01 23:46:12 +00:00
|
|
|
|
2018-12-08 09:31:07 +00:00
|
|
|
impl RTSPToken {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_rtsp_token_new_empty")]
|
2018-12-08 09:31:07 +00:00
|
|
|
pub fn new_empty() -> Self {
|
2018-03-01 23:46:12 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-11-22 10:45:51 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_rtsp_token_new_empty()) }
|
2018-03-01 23:46:12 +00:00
|
|
|
}
|
|
|
|
|
2024-04-09 06:24:16 +00:00
|
|
|
#[doc(alias = "gst_rtsp_token_new")]
|
|
|
|
pub fn builder() -> Builder {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2024-04-09 06:24:16 +00:00
|
|
|
Builder::new()
|
|
|
|
}
|
2018-02-23 02:33:37 +00:00
|
|
|
|
2024-04-09 06:24:16 +00:00
|
|
|
#[allow(clippy::should_implement_trait)]
|
|
|
|
pub fn from_iter(iter: impl IntoIterator<Item = (impl IntoGStr, SendValue)>) -> RTSPToken {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
let mut token = RTSPToken::new_empty();
|
2018-02-23 02:33:37 +00:00
|
|
|
|
2024-04-09 06:24:16 +00:00
|
|
|
let s = token.get_mut().unwrap().structure_mut();
|
|
|
|
iter.into_iter().for_each(|(f, v)| s.set_value(f, v));
|
2018-02-23 02:33:37 +00:00
|
|
|
|
|
|
|
token
|
|
|
|
}
|
2018-03-01 23:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl RTSPTokenRef {
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_string")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[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 {
|
2020-11-22 10:45:51 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_structure")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_rtsp_token_get_structure")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn structure(&self) -> Option<gst::Structure> {
|
2020-11-22 10:45:51 +00:00
|
|
|
unsafe { from_glib_none(ffi::gst_rtsp_token_get_structure(self.as_mut_ptr())) }
|
2018-03-01 23:46:12 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +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 {
|
2020-11-22 10:45:51 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2018-02-23 02:33:37 +00:00
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_mut_structure")]
|
2022-10-18 11:16:04 +00:00
|
|
|
pub fn structure_mut(&mut self) -> &mut gst::StructureRef {
|
2018-02-23 02:33:37 +00:00
|
|
|
unsafe {
|
2020-11-22 10:45:51 +00:00
|
|
|
let structure = ffi::gst_rtsp_token_writable_structure(self.as_mut_ptr());
|
2022-10-18 11:16:04 +00:00
|
|
|
gst::StructureRef::from_glib_borrow_mut(structure)
|
2018-02-23 02:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-01 23:46:12 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
impl fmt::Debug for RTSPToken {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
RTSPTokenRef::fmt(self, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 09:31:07 +00:00
|
|
|
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())
|
2018-12-08 09:31:07 +00:00
|
|
|
.finish()
|
2018-03-01 23:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-09 06:24:16 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[must_use = "The builder must be built to be used"]
|
|
|
|
pub struct Builder {
|
|
|
|
token: RTSPToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Builder {
|
|
|
|
fn new() -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
Builder {
|
|
|
|
token: RTSPToken::new_empty(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn field(mut self, name: impl IntoGStr, value: impl Into<glib::Value> + Send) -> Self {
|
|
|
|
self.token
|
|
|
|
.get_mut()
|
|
|
|
.unwrap()
|
|
|
|
.structure_mut()
|
|
|
|
.set(name, value);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2024-03-29 16:04:34 +00:00
|
|
|
pub fn field_if_some(
|
|
|
|
self,
|
|
|
|
name: impl IntoGStr,
|
|
|
|
value: Option<impl Into<glib::Value> + Send>,
|
|
|
|
) -> Self {
|
|
|
|
if let Some(value) = value {
|
|
|
|
self.field(name, value)
|
|
|
|
} else {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-09 06:24:16 +00:00
|
|
|
#[must_use = "Building the structure without using it has no effect"]
|
|
|
|
pub fn build(self) -> RTSPToken {
|
|
|
|
self.token
|
|
|
|
}
|
|
|
|
}
|