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

95 lines
2.4 KiB
Rust
Raw Normal View History

use ffi;
2018-03-01 23:46:12 +00:00
use glib;
use glib::translate::*;
2018-04-01 08:30:03 +00:00
use glib::value::ToSendValue;
2018-04-25 08:10:06 +00:00
use glib::StaticType;
2018-04-01 08:30:03 +00:00
use gst;
use gst_ffi;
2018-04-01 08:30:03 +00:00
use gst::miniobject::{GstRc, MiniObject};
2018-03-01 23:46:12 +00:00
pub trait GstRcRTSPTokenExt<T: MiniObject> {
fn new_empty() -> Self;
fn new(values: &[(&str, &ToSendValue)]) -> Self;
}
pub type RTSPToken = GstRc<RTSPTokenRef>;
pub struct RTSPTokenRef(ffi::GstRTSPToken);
unsafe impl MiniObject for RTSPTokenRef {
type GstType = ffi::GstRTSPToken;
}
impl GstRcRTSPTokenExt<RTSPTokenRef> for GstRc<RTSPTokenRef> {
fn new_empty() -> Self {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gst_rtsp_token_new_empty()) }
}
fn new(values: &[(&str, &ToSendValue)]) -> Self {
let mut token = RTSPToken::new_empty();
{
let token = token.get_mut().unwrap();
let structure = token.get_mut_structure().unwrap();
for &(f, v) in values {
structure.set_value(f, v.to_send_value());
}
}
token
}
2018-03-01 23:46:12 +00:00
}
impl RTSPTokenRef {
pub fn get_string(&self, field: &str) -> Option<String> {
unsafe {
2018-04-01 08:30:03 +00:00
from_glib_none(ffi::gst_rtsp_token_get_string(
self.as_mut_ptr(),
field.to_glib_none().0,
))
2018-03-01 23:46:12 +00:00
}
}
pub fn get_structure(&self) -> Option<gst::Structure> {
2018-04-01 08:30:03 +00:00
unsafe { from_glib_none(ffi::gst_rtsp_token_get_structure(self.as_mut_ptr())) }
2018-03-01 23:46:12 +00:00
}
pub fn is_allowed(&self, field: &str) -> bool {
unsafe {
2018-04-01 08:30:03 +00:00
from_glib(ffi::gst_rtsp_token_is_allowed(
self.as_mut_ptr(),
field.to_glib_none().0,
))
2018-03-01 23:46:12 +00:00
}
}
pub fn get_mut_structure(&mut self) -> Option<&mut gst::StructureRef> {
unsafe {
2018-03-01 23:46:12 +00:00
let structure = ffi::gst_rtsp_token_writable_structure(self.as_mut_ptr());
if structure.is_null() {
None
} else {
Some(gst::StructureRef::from_glib_borrow_mut(structure))
}
}
}
}
2018-03-01 23:46:12 +00:00
impl ToOwned for RTSPTokenRef {
type Owned = GstRc<RTSPTokenRef>;
fn to_owned(&self) -> GstRc<RTSPTokenRef> {
2018-04-01 08:30:03 +00:00
unsafe {
from_glib_full(gst_ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _)
}
2018-03-01 23:46:12 +00:00
}
}
impl StaticType for RTSPTokenRef {
fn static_type() -> glib::Type {
unsafe { from_glib(ffi::gst_rtsp_token_get_type()) }
}
}