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-04-13 16:18:57 +00:00
|
|
|
use std::mem::transmute;
|
2018-02-09 02:30:08 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use glib::{
|
|
|
|
ffi::{gboolean, gpointer},
|
|
|
|
prelude::*,
|
|
|
|
source::{Continue, Priority},
|
|
|
|
translate::*,
|
|
|
|
};
|
|
|
|
|
|
|
|
use crate::RTSPSessionPool;
|
|
|
|
|
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 {
|
2022-04-03 08:15:19 +00:00
|
|
|
let func: &mut F = &mut *(func as *mut F);
|
|
|
|
func(&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,
|
|
|
|
) {
|
2022-08-10 09:27:00 +00:00
|
|
|
let _ = Box::<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)]
|
2022-04-03 08:15:19 +00:00
|
|
|
let func: Box<F> = Box::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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|