use gio;
use glib;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::GString;
use glib::StaticType;
use glib::Value;
use glib_sys;
use gobject_sys;
use gst_rtsp_server_sys;
use std::boxed::Box as Box_;
use std::mem::transmute;
use std::ptr;
use RTSPAuth;
use RTSPClient;
use RTSPFilterResult;
use RTSPMountPoints;
use RTSPSessionPool;
use RTSPThreadPool;
glib_wrapper! {
pub struct RTSPServer(Object<gst_rtsp_server_sys::GstRTSPServer, gst_rtsp_server_sys::GstRTSPServerClass, RTSPServerClass>);
match fn {
get_type => || gst_rtsp_server_sys::gst_rtsp_server_get_type(),
}
}
impl RTSPServer {
pub fn new() -> RTSPServer {
assert_initialized_main_thread!();
unsafe { from_glib_full(gst_rtsp_server_sys::gst_rtsp_server_new()) }
}
pub fn io_func<P: IsA<gio::Socket>, Q: IsA<RTSPServer>>(
socket: &P,
condition: glib::IOCondition,
server: &Q,
) -> Result<(), glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
glib_result_from_gboolean!(
gst_rtsp_server_sys::gst_rtsp_server_io_func(
socket.as_ref().to_glib_none().0,
condition.to_glib(),
server.as_ref().to_glib_none().0
),
"Failed to connect the source"
)
}
}
}
impl Default for RTSPServer {
fn default() -> Self {
Self::new()
}
}
unsafe impl Send for RTSPServer {}
unsafe impl Sync for RTSPServer {}
pub const NONE_RTSP_SERVER: Option<&RTSPServer> = None;
pub trait RTSPServerExt: 'static {
fn client_filter(
&self,
func: Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)>,
) -> Vec<RTSPClient>;
fn create_socket<P: IsA<gio::Cancellable>>(
&self,
cancellable: Option<&P>,
) -> Result<gio::Socket, glib::Error>;
fn create_source<P: IsA<gio::Cancellable>>(
&self,
cancellable: Option<&P>,
) -> Result<glib::Source, glib::Error>;
fn get_address(&self) -> Option<GString>;
fn get_auth(&self) -> Option<RTSPAuth>;
fn get_backlog(&self) -> i32;
fn get_bound_port(&self) -> i32;
#[cfg(any(feature = "v1_18", feature = "dox"))]
fn get_content_length_limit(&self) -> u32;
fn get_mount_points(&self) -> Option<RTSPMountPoints>;
fn get_service(&self) -> Option<GString>;
fn get_session_pool(&self) -> Option<RTSPSessionPool>;
fn get_thread_pool(&self) -> Option<RTSPThreadPool>;
fn set_address(&self, address: &str);
fn set_auth<P: IsA<RTSPAuth>>(&self, auth: Option<&P>);
fn set_backlog(&self, backlog: i32);
#[cfg(any(feature = "v1_18", feature = "dox"))]
fn set_content_length_limit(&self, limit: u32);
fn set_mount_points<P: IsA<RTSPMountPoints>>(&self, mounts: Option<&P>);
fn set_service(&self, service: &str);
fn set_session_pool<P: IsA<RTSPSessionPool>>(&self, pool: Option<&P>);
fn set_thread_pool<P: IsA<RTSPThreadPool>>(&self, pool: Option<&P>);
fn transfer_connection<P: IsA<gio::Socket>>(
&self,
socket: &P,
ip: &str,
port: i32,
initial_buffer: Option<&str>,
) -> Result<(), glib::error::BoolError>;
fn get_property_content_length_limit(&self) -> u32;
fn set_property_content_length_limit(&self, content_length_limit: u32);
fn connect_client_connected<F: Fn(&Self, &RTSPClient) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_backlog_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_bound_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_content_length_limit_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_mount_points_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_service_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_session_pool_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId;
}
impl<O: IsA<RTSPServer>> RTSPServerExt for O {
fn client_filter(
&self,
func: Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)>,
) -> Vec<RTSPClient> {
let func_data: Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)> =
func;
unsafe extern "C" fn func_func(
server: *mut gst_rtsp_server_sys::GstRTSPServer,
client: *mut gst_rtsp_server_sys::GstRTSPClient,
user_data: glib_sys::gpointer,
) -> gst_rtsp_server_sys::GstRTSPFilterResult {
let server = from_glib_borrow(server);
let client = from_glib_borrow(client);
let callback: *mut Option<
&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult),
> = user_data as *const _ as usize
as *mut Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)>;
let res = if let Some(ref mut callback) = *callback {
callback(&server, &client)
} else {
panic!("cannot get closure...")
};
res.to_glib()
}
let func = if func_data.is_some() {
Some(func_func as _)
} else {
None
};
let super_callback0: &Option<
&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult),
> = &func_data;
unsafe {
FromGlibPtrContainer::from_glib_full(
gst_rtsp_server_sys::gst_rtsp_server_client_filter(
self.as_ref().to_glib_none().0,
func,
super_callback0 as *const _ as usize as *mut _,
),
)
}
}
fn create_socket<P: IsA<gio::Cancellable>>(
&self,
cancellable: Option<&P>,
) -> Result<gio::Socket, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = gst_rtsp_server_sys::gst_rtsp_server_create_socket(
self.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
fn create_source<P: IsA<gio::Cancellable>>(
&self,
cancellable: Option<&P>,
) -> Result<glib::Source, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = gst_rtsp_server_sys::gst_rtsp_server_create_source(
self.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
fn get_address(&self) -> Option<GString> {
unsafe {
from_glib_full(gst_rtsp_server_sys::gst_rtsp_server_get_address(
self.as_ref().to_glib_none().0,
))
}
}
fn get_auth(&self) -> Option<RTSPAuth> {
unsafe {
from_glib_full(gst_rtsp_server_sys::gst_rtsp_server_get_auth(
self.as_ref().to_glib_none().0,
))
}
}
fn get_backlog(&self) -> i32 {
unsafe { gst_rtsp_server_sys::gst_rtsp_server_get_backlog(self.as_ref().to_glib_none().0) }
}
fn get_bound_port(&self) -> i32 {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_get_bound_port(self.as_ref().to_glib_none().0)
}
}
#[cfg(any(feature = "v1_18", feature = "dox"))]
fn get_content_length_limit(&self) -> u32 {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_get_content_length_limit(
self.as_ref().to_glib_none().0,
)
}
}
fn get_mount_points(&self) -> Option<RTSPMountPoints> {
unsafe {
from_glib_full(gst_rtsp_server_sys::gst_rtsp_server_get_mount_points(
self.as_ref().to_glib_none().0,
))
}
}
fn get_service(&self) -> Option<GString> {
unsafe {
from_glib_full(gst_rtsp_server_sys::gst_rtsp_server_get_service(
self.as_ref().to_glib_none().0,
))
}
}
fn get_session_pool(&self) -> Option<RTSPSessionPool> {
unsafe {
from_glib_full(gst_rtsp_server_sys::gst_rtsp_server_get_session_pool(
self.as_ref().to_glib_none().0,
))
}
}
fn get_thread_pool(&self) -> Option<RTSPThreadPool> {
unsafe {
from_glib_full(gst_rtsp_server_sys::gst_rtsp_server_get_thread_pool(
self.as_ref().to_glib_none().0,
))
}
}
fn set_address(&self, address: &str) {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_set_address(
self.as_ref().to_glib_none().0,
address.to_glib_none().0,
);
}
}
fn set_auth<P: IsA<RTSPAuth>>(&self, auth: Option<&P>) {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_set_auth(
self.as_ref().to_glib_none().0,
auth.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
fn set_backlog(&self, backlog: i32) {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_set_backlog(
self.as_ref().to_glib_none().0,
backlog,
);
}
}
#[cfg(any(feature = "v1_18", feature = "dox"))]
fn set_content_length_limit(&self, limit: u32) {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_set_content_length_limit(
self.as_ref().to_glib_none().0,
limit,
);
}
}
fn set_mount_points<P: IsA<RTSPMountPoints>>(&self, mounts: Option<&P>) {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_set_mount_points(
self.as_ref().to_glib_none().0,
mounts.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
fn set_service(&self, service: &str) {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_set_service(
self.as_ref().to_glib_none().0,
service.to_glib_none().0,
);
}
}
fn set_session_pool<P: IsA<RTSPSessionPool>>(&self, pool: Option<&P>) {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_set_session_pool(
self.as_ref().to_glib_none().0,
pool.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
fn set_thread_pool<P: IsA<RTSPThreadPool>>(&self, pool: Option<&P>) {
unsafe {
gst_rtsp_server_sys::gst_rtsp_server_set_thread_pool(
self.as_ref().to_glib_none().0,
pool.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
fn transfer_connection<P: IsA<gio::Socket>>(
&self,
socket: &P,
ip: &str,
port: i32,
initial_buffer: Option<&str>,
) -> Result<(), glib::error::BoolError> {
unsafe {
glib_result_from_gboolean!(
gst_rtsp_server_sys::gst_rtsp_server_transfer_connection(
self.as_ref().to_glib_none().0,
socket.as_ref().to_glib_full(),
ip.to_glib_none().0,
port,
initial_buffer.to_glib_none().0
),
"Failed to transfer to the connection"
)
}
}
fn get_property_content_length_limit(&self) -> u32 {
unsafe {
let mut value = Value::from_type(<u32 as StaticType>::static_type());
gobject_sys::g_object_get_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"content-length-limit\0".as_ptr() as *const _,
value.to_glib_none_mut().0,
);
value
.get()
.expect("Return Value for property `content-length-limit` getter")
.unwrap()
}
}
fn set_property_content_length_limit(&self, content_length_limit: u32) {
unsafe {
gobject_sys::g_object_set_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"content-length-limit\0".as_ptr() as *const _,
Value::from(&content_length_limit).to_glib_none().0,
);
}
}
fn connect_client_connected<F: Fn(&Self, &RTSPClient) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn client_connected_trampoline<
P,
F: Fn(&P, &RTSPClient) + Send + Sync + 'static,
>(
this: *mut gst_rtsp_server_sys::GstRTSPServer,
object: *mut gst_rtsp_server_sys::GstRTSPClient,
f: glib_sys::gpointer,
) where
P: IsA<RTSPServer>,
{
let f: &F = &*(f as *const F);
f(
&RTSPServer::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(object),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"client-connected\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
client_connected_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_address_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
this: *mut gst_rtsp_server_sys::GstRTSPServer,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<RTSPServer>,
{
let f: &F = &*(f as *const F);
f(&RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::address\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_address_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_backlog_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_backlog_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
this: *mut gst_rtsp_server_sys::GstRTSPServer,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<RTSPServer>,
{
let f: &F = &*(f as *const F);
f(&RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::backlog\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_backlog_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_bound_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_bound_port_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
this: *mut gst_rtsp_server_sys::GstRTSPServer,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<RTSPServer>,
{
let f: &F = &*(f as *const F);
f(&RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::bound-port\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_bound_port_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_content_length_limit_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_content_length_limit_trampoline<
P,
F: Fn(&P) + Send + Sync + 'static,
>(
this: *mut gst_rtsp_server_sys::GstRTSPServer,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<RTSPServer>,
{
let f: &F = &*(f as *const F);
f(&RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::content-length-limit\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_content_length_limit_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_mount_points_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_mount_points_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
this: *mut gst_rtsp_server_sys::GstRTSPServer,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<RTSPServer>,
{
let f: &F = &*(f as *const F);
f(&RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::mount-points\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_mount_points_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_service_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_service_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
this: *mut gst_rtsp_server_sys::GstRTSPServer,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<RTSPServer>,
{
let f: &F = &*(f as *const F);
f(&RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::service\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_service_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_session_pool_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_session_pool_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
this: *mut gst_rtsp_server_sys::GstRTSPServer,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<RTSPServer>,
{
let f: &F = &*(f as *const F);
f(&RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::session-pool\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_session_pool_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}