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-02-15 15:03:31 +00:00
|
|
|
|
2020-04-05 14:52:56 +00:00
|
|
|
use glib::translate::*;
|
2019-01-22 15:43:29 +00:00
|
|
|
use std::ptr;
|
2018-02-15 15:03:31 +00:00
|
|
|
|
2019-01-22 15:43:29 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2020-11-22 10:45:51 +00:00
|
|
|
pub struct RTSPContext(ptr::NonNull<ffi::GstRTSPContext>);
|
2018-02-15 15:03:31 +00:00
|
|
|
|
|
|
|
impl RTSPContext {
|
|
|
|
pub fn with_current_context<F: FnOnce(&RTSPContext) -> T, T>(func: F) -> Option<T> {
|
|
|
|
unsafe {
|
2020-11-22 10:45:51 +00:00
|
|
|
let ptr = ffi::gst_rtsp_context_get_current();
|
2018-02-15 15:03:31 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2019-01-22 15:43:29 +00:00
|
|
|
let ctx = RTSPContext(ptr::NonNull::new_unchecked(ptr));
|
2018-02-15 15:03:31 +00:00
|
|
|
Some(func(&ctx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Add various getters for all the contained fields as needed
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-22 10:45:51 +00:00
|
|
|
impl FromGlibPtrBorrow<*mut ffi::GstRTSPContext> for RTSPContext {
|
2018-02-15 15:03:31 +00:00
|
|
|
#[inline]
|
2020-11-22 10:45:51 +00:00
|
|
|
unsafe fn from_glib_borrow(ptr: *mut ffi::GstRTSPContext) -> Borrowed<Self> {
|
2019-01-22 15:43:29 +00:00
|
|
|
assert!(!ptr.is_null());
|
2020-04-05 14:52:56 +00:00
|
|
|
Borrowed::new(RTSPContext(ptr::NonNull::new_unchecked(ptr)))
|
2018-02-15 15:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-23 07:58:54 +00:00
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-22 10:45:51 +00:00
|
|
|
impl<'a> ToGlibPtr<'a, *mut ffi::GstRTSPContext> for RTSPContext {
|
2020-02-23 07:58:54 +00:00
|
|
|
type Storage = &'a RTSPContext;
|
|
|
|
|
2020-11-22 10:45:51 +00:00
|
|
|
fn to_glib_none(&'a self) -> Stash<'a, *mut ffi::GstRTSPContext, Self> {
|
2020-04-05 14:52:56 +00:00
|
|
|
Stash(self.0.as_ptr(), self)
|
2020-02-23 07:58:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 10:45:51 +00:00
|
|
|
fn to_glib_full(&self) -> *mut ffi::GstRTSPContext {
|
2020-02-23 07:58:54 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|