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
|
|
|
|
2024-05-10 07:35:19 +00:00
|
|
|
use std::{marker::PhantomData, ptr};
|
2023-01-03 18:58:25 +00:00
|
|
|
|
2024-02-03 08:13:51 +00:00
|
|
|
use glib::{prelude::*, translate::*};
|
2023-12-08 15:48:03 +00:00
|
|
|
use gst_rtsp::{rtsp_message::RTSPMessage, RTSPUrl};
|
|
|
|
|
|
|
|
use crate::{RTSPClient, RTSPSession, RTSPToken};
|
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 {
|
2024-05-10 07:35:19 +00:00
|
|
|
let uri = RTSPUrl::from_glib_ptr_borrow(&(*ptr).uri);
|
2023-05-30 10:36:08 +00:00
|
|
|
Some(uri)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-08 15:48:03 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn client(&self) -> Option<&RTSPClient> {
|
|
|
|
unsafe {
|
|
|
|
let ptr = self.0.as_ptr();
|
|
|
|
if (*ptr).client.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2024-05-10 07:35:19 +00:00
|
|
|
let client = RTSPClient::from_glib_ptr_borrow(&(*ptr).client);
|
2023-12-08 15:48:03 +00:00
|
|
|
Some(client)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn request(&self) -> Option<&RTSPMessage> {
|
|
|
|
unsafe {
|
|
|
|
let ptr = self.0.as_ptr();
|
|
|
|
if (*ptr).request.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2024-05-10 07:35:19 +00:00
|
|
|
let msg = RTSPMessage::from_glib_ptr_borrow(&(*ptr).request);
|
2023-12-08 15:48:03 +00:00
|
|
|
Some(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn response(&self) -> Option<&RTSPMessage> {
|
|
|
|
unsafe {
|
|
|
|
let ptr = self.0.as_ptr();
|
|
|
|
if (*ptr).response.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2024-05-10 07:35:19 +00:00
|
|
|
let msg = RTSPMessage::from_glib_ptr_borrow(&(*ptr).response);
|
2023-12-08 15:48:03 +00:00
|
|
|
Some(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn session(&self) -> Option<&RTSPSession> {
|
|
|
|
unsafe {
|
|
|
|
let ptr = self.0.as_ptr();
|
|
|
|
if (*ptr).session.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2024-05-10 07:35:19 +00:00
|
|
|
let sess = RTSPSession::from_glib_ptr_borrow(&(*ptr).session);
|
2023-12-08 15:48:03 +00:00
|
|
|
Some(sess)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn token(&self) -> Option<RTSPToken> {
|
|
|
|
unsafe {
|
|
|
|
let ptr = self.0.as_ptr();
|
|
|
|
if (*ptr).token.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
let token = RTSPToken::from_glib_none((*ptr).token as *const ffi::GstRTSPToken);
|
|
|
|
Some(token)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[doc(alias = "gst_rtsp_context_set_token")]
|
|
|
|
pub fn set_token(&self, token: RTSPToken) {
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_rtsp_context_set_token(self.0.as_ptr(), token.into_glib_ptr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-30 10:36:08 +00:00
|
|
|
// 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!()
|
|
|
|
}
|
|
|
|
}
|