2018-02-15 15:03:31 +00:00
|
|
|
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2020-04-05 14:52:56 +00:00
|
|
|
use glib::translate::*;
|
2019-03-19 07:58:20 +00:00
|
|
|
use gst_rtsp_server_sys;
|
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)]
|
2019-03-19 07:58:20 +00:00
|
|
|
pub struct RTSPContext(ptr::NonNull<gst_rtsp_server_sys::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 {
|
2019-03-19 07:58:20 +00:00
|
|
|
let ptr = gst_rtsp_server_sys::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-04-05 14:52:56 +00:00
|
|
|
impl FromGlibPtrBorrow<*mut gst_rtsp_server_sys::GstRTSPContext> for RTSPContext {
|
2018-02-15 15:03:31 +00:00
|
|
|
#[inline]
|
2020-04-05 14:52:56 +00:00
|
|
|
unsafe fn from_glib_borrow(ptr: *mut gst_rtsp_server_sys::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-04-05 14:52:56 +00:00
|
|
|
impl<'a> ToGlibPtr<'a, *mut gst_rtsp_server_sys::GstRTSPContext> for RTSPContext {
|
2020-02-23 07:58:54 +00:00
|
|
|
type Storage = &'a RTSPContext;
|
|
|
|
|
2020-04-05 14:52:56 +00:00
|
|
|
fn to_glib_none(&'a self) -> Stash<'a, *mut gst_rtsp_server_sys::GstRTSPContext, Self> {
|
|
|
|
Stash(self.0.as_ptr(), self)
|
2020-02-23 07:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_full(&self) -> *mut gst_rtsp_server_sys::GstRTSPContext {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|