From 1a53983b3bd475c348e1f2dddd224de1651699a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 8 Dec 2018 11:31:07 +0200 Subject: [PATCH] Properly implement gst_rtsp_server::RTSPToken bindings We can now properly implement miniobject bindings outside the main trait. --- gstreamer-rtsp-server/src/lib.rs | 2 +- gstreamer-rtsp-server/src/rtsp_token.rs | 43 ++++++++----------------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/gstreamer-rtsp-server/src/lib.rs b/gstreamer-rtsp-server/src/lib.rs index e38a3cb1f..72cc4214d 100644 --- a/gstreamer-rtsp-server/src/lib.rs +++ b/gstreamer-rtsp-server/src/lib.rs @@ -19,6 +19,7 @@ use std::ffi::CStr; extern crate glib; extern crate glib_sys as glib_ffi; extern crate gobject_sys as gobject_ffi; +#[macro_use] extern crate gstreamer as gst; extern crate gstreamer_net as gst_net; extern crate gstreamer_net_sys as gst_net_ffi; @@ -140,5 +141,4 @@ pub mod prelude { pub use rtsp_media_factory::RTSPMediaFactoryExtManual; pub use rtsp_server::RTSPServerExtManual; pub use rtsp_session_pool::RTSPSessionPoolExtManual; - pub use rtsp_token::GstRcRTSPTokenExt; } diff --git a/gstreamer-rtsp-server/src/rtsp_token.rs b/gstreamer-rtsp-server/src/rtsp_token.rs index a25ed1db6..438e25679 100644 --- a/gstreamer-rtsp-server/src/rtsp_token.rs +++ b/gstreamer-rtsp-server/src/rtsp_token.rs @@ -2,31 +2,22 @@ use ffi; use glib; use glib::translate::*; use glib::value::ToSendValue; -use glib::StaticType; use gst; -use gst_ffi; +use gst::miniobject::*; -use gst::miniobject::{GstRc, MiniObject}; +use std::fmt; -pub trait GstRcRTSPTokenExt { - fn new_empty() -> Self; - fn new(values: &[(&str, &ToSendValue)]) -> Self; -} +gst_define_mini_object_wrapper!(RTSPToken, RTSPTokenRef, ffi::GstRTSPToken, [Debug,], || { + ffi::gst_rtsp_token_get_type() +}); -pub type RTSPToken = GstRc; -pub struct RTSPTokenRef(ffi::GstRTSPToken); - -unsafe impl MiniObject for RTSPTokenRef { - type GstType = ffi::GstRTSPToken; -} - -impl GstRcRTSPTokenExt for GstRc { - fn new_empty() -> Self { +impl RTSPToken { + pub fn new_empty() -> Self { assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_rtsp_token_new_empty()) } } - fn new(values: &[(&str, &ToSendValue)]) -> Self { + pub fn new(values: &[(&str, &ToSendValue)]) -> Self { let mut token = RTSPToken::new_empty(); { @@ -77,18 +68,10 @@ impl RTSPTokenRef { } } -impl ToOwned for RTSPTokenRef { - type Owned = GstRc; - - fn to_owned(&self) -> GstRc { - unsafe { - from_glib_full(gst_ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _) - } - } -} - -impl StaticType for RTSPTokenRef { - fn static_type() -> glib::Type { - unsafe { from_glib(ffi::gst_rtsp_token_get_type()) } +impl fmt::Debug for RTSPTokenRef { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("RTSPToken") + .field("structure", &self.get_structure()) + .finish() } }