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::*,
|
2023-07-06 20:22:43 +00:00
|
|
|
source::Priority,
|
2023-01-03 18:58:25 +00:00
|
|
|
translate::*,
|
2023-07-06 20:22:43 +00:00
|
|
|
ControlFlow,
|
2023-01-03 18:58:25 +00:00
|
|
|
};
|
|
|
|
|
2024-06-02 08:48:53 +00:00
|
|
|
use crate::{ffi, RTSPSessionPool};
|
2023-01-03 18:58:25 +00:00
|
|
|
|
2023-07-06 13:15:14 +00:00
|
|
|
unsafe extern "C" fn trampoline_watch<
|
|
|
|
F: FnMut(&RTSPSessionPool) -> ControlFlow + 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<
|
2023-07-06 13:15:14 +00:00
|
|
|
F: FnMut(&RTSPSessionPool) -> ControlFlow + Send + 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-07-06 13:15:14 +00:00
|
|
|
fn into_raw_watch<F: FnMut(&RTSPSessionPool) -> ControlFlow + 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
|
|
|
|
}
|
|
|
|
|
2024-10-19 15:09:56 +00:00
|
|
|
pub trait RTSPSessionPoolExtManual: IsA<RTSPSessionPool> + 'static {
|
2023-07-05 20:21:43 +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
|
2023-07-06 13:15:14 +00:00
|
|
|
F: FnMut(&RTSPSessionPool) -> ControlFlow + 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::<
|
2024-06-14 05:08:27 +00:00
|
|
|
*const (),
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-05 20:21:43 +00:00
|
|
|
|
|
|
|
impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExtManual for O {}
|