gstreamer-rs/gstreamer-rtsp-server/src/r_t_s_p_session_pool.rs
Mathieu Duponchelle a00243d529 Add initial libgstsdp, libgstrtsp and libgstrtspserver bindings
Only automatic bindings for now, which is enough to allow
implementing a simple rtsp-server example.

Depends on https://github.com/sdroege/gstreamer-sys/pull/8

Uses a new gir feature proposed at
https://github.com/gtk-rs/gir/pull/539 to make doc regeneration
easier.

Fixes https://github.com/sdroege/gstreamer-rs/pull/80
2018-02-14 18:57:58 +02:00

78 lines
2.4 KiB
Rust

use std::cell::RefCell;
use std::mem::transmute;
use RTSPSessionPool;
use ffi;
use glib;
use glib_ffi;
use glib::object::IsA;
use glib::translate::*;
use glib::source::{CallbackGuard, Continue, Priority};
use glib_ffi::{gboolean, gpointer};
unsafe extern "C" fn trampoline_watch(
pool: *mut ffi::GstRTSPSessionPool,
func: gpointer,
) -> gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>> = transmute(func);
(&mut *func.borrow_mut())(&from_glib_borrow(pool)).to_glib()
}
unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>>>::from_raw(
ptr as *mut _,
);
}
fn into_raw_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(func: F) -> gpointer {
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
let func: Box<RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>>> =
Box::new(RefCell::new(Box::new(func)));
Box::into_raw(func) as gpointer
}
pub trait RTSPSessionPoolExtManual {
fn create_watch<'a, N: Into<Option<&'a str>>, F>(
&self,
name: N,
priority: Priority,
func: F,
) -> glib::Source
where
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static;
}
impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExtManual for O {
fn create_watch<'a, N: Into<Option<&'a str>>, F>(
&self,
name: N,
priority: Priority,
func: F,
) -> glib::Source
where
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static
{
skip_assert_initialized!();
unsafe {
let source = ffi::gst_rtsp_session_pool_create_watch(self.to_glib_none().0);
let trampoline = trampoline_watch as gpointer;
glib_ffi::g_source_set_callback(
source,
Some(transmute(trampoline)),
into_raw_watch(func),
Some(destroy_closure_watch),
);
glib_ffi::g_source_set_priority(source, priority.to_glib());
let name = name.into();
if let Some(name) = name {
glib_ffi::g_source_set_name(source, name.to_glib_none().0);
}
from_glib_full(source)
}
}
}