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
|
|
|
|
2023-05-30 10:36:08 +00:00
|
|
|
use std::{
|
|
|
|
marker::PhantomData,
|
|
|
|
ptr::{self, addr_of},
|
|
|
|
};
|
2023-01-03 18:58:25 +00:00
|
|
|
|
2020-04-05 14:52:56 +00:00
|
|
|
use glib::translate::*;
|
2023-05-30 10:36:08 +00:00
|
|
|
use gst_rtsp::RTSPUrl;
|
2018-02-15 15:03:31 +00:00
|
|
|
|
2019-01-22 15:43:29 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstRTSPContext")]
|
2023-05-30 10:36:08 +00:00
|
|
|
#[repr(transparent)]
|
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 {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-02-15 15:03:31 +00:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-30 10:36:08 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn uri(&self) -> Option<&RTSPUrl> {
|
|
|
|
unsafe {
|
|
|
|
let ptr = self.0.as_ptr();
|
|
|
|
if (*ptr).uri.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
let uri = RTSPUrl::from_glib_ptr_borrow(
|
|
|
|
addr_of!((*ptr).uri) as *const *const gst_rtsp::ffi::GstRTSPUrl
|
|
|
|
);
|
|
|
|
Some(uri)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Add additional getters for all the contained fields as needed
|
2018-02-15 15:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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> {
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_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 {
|
2022-12-17 16:48:35 +00:00
|
|
|
type Storage = PhantomData<&'a RTSPContext>;
|
2020-02-23 07:58:54 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2020-11-22 10:45:51 +00:00
|
|
|
fn to_glib_none(&'a self) -> Stash<'a, *mut ffi::GstRTSPContext, Self> {
|
2022-12-17 16:48:35 +00:00
|
|
|
Stash(self.0.as_ptr(), PhantomData)
|
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!()
|
|
|
|
}
|
|
|
|
}
|