2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
|
|
|
|
2020-11-22 10:45:51 +00:00
|
|
|
use crate::RTSPSessionPool;
|
|
|
|
use glib::ffi::{gboolean, gpointer};
|
2021-04-26 12:15:53 +00:00
|
|
|
use glib::prelude::*;
|
2018-06-24 11:44:38 +00:00
|
|
|
use glib::source::{Continue, Priority};
|
2018-04-01 08:30:03 +00:00
|
|
|
use glib::translate::*;
|
|
|
|
use std::cell::RefCell;
|
2020-04-13 16:18:57 +00:00
|
|
|
use std::mem::transmute;
|
2018-02-09 02:30:08 +00:00
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(
|
2020-11-22 10:45:51 +00:00
|
|
|
pool: *mut ffi::GstRTSPSessionPool,
|
2018-02-09 02:30:08 +00:00
|
|
|
func: gpointer,
|
|
|
|
) -> gboolean {
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &RefCell<F> = &*(func as *const RefCell<F>);
|
2021-04-27 15:15:46 +00:00
|
|
|
(&mut *func.borrow_mut())(&from_glib_borrow(pool)).into_glib()
|
2018-02-09 02:30:08 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn destroy_closure_watch<
|
|
|
|
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static,
|
|
|
|
>(
|
|
|
|
ptr: gpointer,
|
|
|
|
) {
|
|
|
|
Box::<RefCell<F>>::from_raw(ptr as *mut _);
|
2018-02-09 02:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn into_raw_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(func: F) -> gpointer {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2019-01-30 13:02:03 +00:00
|
|
|
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
|
2018-02-09 02:30:08 +00:00
|
|
|
Box::into_raw(func) as gpointer
|
|
|
|
}
|
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait RTSPSessionPoolExtManual: 'static {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_rtsp_session_pool_create_watch")]
|
2019-05-23 18:19:24 +00:00
|
|
|
fn create_watch<F>(&self, name: Option<&str>, priority: Priority, func: F) -> glib::Source
|
2018-02-09 02:30:08 +00:00
|
|
|
where
|
|
|
|
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExtManual for O {
|
2019-05-23 18:19:24 +00:00
|
|
|
fn create_watch<F>(&self, name: Option<&str>, priority: Priority, func: F) -> glib::Source
|
2018-02-09 02:30:08 +00:00
|
|
|
where
|
2018-02-22 10:18:37 +00:00
|
|
|
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static,
|
2018-02-09 02:30:08 +00:00
|
|
|
{
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
2020-11-22 10:45:51 +00:00
|
|
|
let source = ffi::gst_rtsp_session_pool_create_watch(self.as_ref().to_glib_none().0);
|
|
|
|
glib::ffi::g_source_set_callback(
|
2018-02-09 02:30:08 +00:00
|
|
|
source,
|
2020-04-13 16:18:57 +00:00
|
|
|
Some(transmute::<
|
|
|
|
_,
|
2020-11-22 10:45:51 +00:00
|
|
|
unsafe extern "C" fn(glib::ffi::gpointer) -> i32,
|
2020-04-13 16:18:57 +00:00
|
|
|
>(trampoline_watch::<F> as *const ())),
|
2018-02-09 02:30:08 +00:00
|
|
|
into_raw_watch(func),
|
2019-01-30 13:02:03 +00:00
|
|
|
Some(destroy_closure_watch::<F>),
|
2018-02-09 02:30:08 +00:00
|
|
|
);
|
2021-04-27 15:15:46 +00:00
|
|
|
glib::ffi::g_source_set_priority(source, priority.into_glib());
|
2018-02-09 02:30:08 +00:00
|
|
|
|
|
|
|
if let Some(name) = name {
|
2020-11-22 10:45:51 +00:00
|
|
|
glib::ffi::g_source_set_name(source, name.to_glib_none().0);
|
2018-02-09 02:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
from_glib_full(source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|