1use crate::{
7 RTSPAuth, RTSPClient, RTSPFilterResult, RTSPMountPoints, RTSPSessionPool, RTSPThreadPool, ffi,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GstRTSPServer")]
61 pub struct RTSPServer(Object<ffi::GstRTSPServer, ffi::GstRTSPServerClass>);
62
63 match fn {
64 type_ => || ffi::gst_rtsp_server_get_type(),
65 }
66}
67
68impl RTSPServer {
69 pub const NONE: Option<&'static RTSPServer> = None;
70
71 #[doc(alias = "gst_rtsp_server_new")]
77 pub fn new() -> RTSPServer {
78 assert_initialized_main_thread!();
79 unsafe { from_glib_full(ffi::gst_rtsp_server_new()) }
80 }
81
82 #[doc(alias = "gst_rtsp_server_io_func")]
95 pub fn io_func(
96 socket: &impl IsA<gio::Socket>,
97 condition: glib::IOCondition,
98 server: &impl IsA<RTSPServer>,
99 ) -> Result<(), glib::error::BoolError> {
100 skip_assert_initialized!();
101 unsafe {
102 glib::result_from_gboolean!(
103 ffi::gst_rtsp_server_io_func(
104 socket.as_ref().to_glib_none().0,
105 condition.into_glib(),
106 server.as_ref().to_glib_none().0
107 ),
108 "Failed to connect the source"
109 )
110 }
111 }
112}
113
114impl Default for RTSPServer {
115 fn default() -> Self {
116 Self::new()
117 }
118}
119
120unsafe impl Send for RTSPServer {}
121unsafe impl Sync for RTSPServer {}
122
123pub trait RTSPServerExt: IsA<RTSPServer> + 'static {
129 #[doc(alias = "gst_rtsp_server_client_filter")]
152 fn client_filter(
153 &self,
154 func: Option<&mut dyn FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult>,
155 ) -> Vec<RTSPClient> {
156 let mut func_data: Option<&mut dyn FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult> =
157 func;
158 unsafe extern "C" fn func_func(
159 server: *mut ffi::GstRTSPServer,
160 client: *mut ffi::GstRTSPClient,
161 user_data: glib::ffi::gpointer,
162 ) -> ffi::GstRTSPFilterResult {
163 unsafe {
164 let server = from_glib_borrow(server);
165 let client = from_glib_borrow(client);
166 let callback = user_data
167 as *mut Option<&mut dyn FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult>;
168 if let Some(ref mut callback) = *callback {
169 callback(&server, &client)
170 } else {
171 panic!("cannot get closure...")
172 }
173 .into_glib()
174 }
175 }
176 let func = if func_data.is_some() {
177 Some(func_func as _)
178 } else {
179 None
180 };
181 let super_callback0: &mut Option<
182 &mut dyn FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult,
183 > = &mut func_data;
184 unsafe {
185 FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_server_client_filter(
186 self.as_ref().to_glib_none().0,
187 func,
188 super_callback0 as *mut _ as *mut _,
189 ))
190 }
191 }
192
193 #[doc(alias = "gst_rtsp_server_create_socket")]
203 fn create_socket(
204 &self,
205 cancellable: Option<&impl IsA<gio::Cancellable>>,
206 ) -> Result<gio::Socket, glib::Error> {
207 unsafe {
208 let mut error = std::ptr::null_mut();
209 let ret = ffi::gst_rtsp_server_create_socket(
210 self.as_ref().to_glib_none().0,
211 cancellable.map(|p| p.as_ref()).to_glib_none().0,
212 &mut error,
213 );
214 if error.is_null() {
215 Ok(from_glib_full(ret))
216 } else {
217 Err(from_glib_full(error))
218 }
219 }
220 }
221
222 #[doc(alias = "gst_rtsp_server_create_source")]
239 fn create_source(
240 &self,
241 cancellable: Option<&impl IsA<gio::Cancellable>>,
242 ) -> Result<glib::Source, glib::Error> {
243 unsafe {
244 let mut error = std::ptr::null_mut();
245 let ret = ffi::gst_rtsp_server_create_source(
246 self.as_ref().to_glib_none().0,
247 cancellable.map(|p| p.as_ref()).to_glib_none().0,
248 &mut error,
249 );
250 if error.is_null() {
251 Ok(from_glib_full(ret))
252 } else {
253 Err(from_glib_full(error))
254 }
255 }
256 }
257
258 #[doc(alias = "gst_rtsp_server_get_address")]
264 #[doc(alias = "get_address")]
265 fn address(&self) -> Option<glib::GString> {
266 unsafe {
267 from_glib_full(ffi::gst_rtsp_server_get_address(
268 self.as_ref().to_glib_none().0,
269 ))
270 }
271 }
272
273 #[doc(alias = "gst_rtsp_server_get_auth")]
280 #[doc(alias = "get_auth")]
281 fn auth(&self) -> Option<RTSPAuth> {
282 unsafe {
283 from_glib_full(ffi::gst_rtsp_server_get_auth(
284 self.as_ref().to_glib_none().0,
285 ))
286 }
287 }
288
289 #[doc(alias = "gst_rtsp_server_get_backlog")]
295 #[doc(alias = "get_backlog")]
296 fn backlog(&self) -> i32 {
297 unsafe { ffi::gst_rtsp_server_get_backlog(self.as_ref().to_glib_none().0) }
298 }
299
300 #[doc(alias = "gst_rtsp_server_get_bound_port")]
306 #[doc(alias = "get_bound_port")]
307 #[doc(alias = "bound-port")]
308 fn bound_port(&self) -> i32 {
309 unsafe { ffi::gst_rtsp_server_get_bound_port(self.as_ref().to_glib_none().0) }
310 }
311
312 #[cfg(feature = "v1_18")]
318 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
319 #[doc(alias = "gst_rtsp_server_get_content_length_limit")]
320 #[doc(alias = "get_content_length_limit")]
321 #[doc(alias = "content-length-limit")]
322 fn content_length_limit(&self) -> u32 {
323 unsafe { ffi::gst_rtsp_server_get_content_length_limit(self.as_ref().to_glib_none().0) }
324 }
325
326 #[doc(alias = "gst_rtsp_server_get_mount_points")]
333 #[doc(alias = "get_mount_points")]
334 #[doc(alias = "mount-points")]
335 fn mount_points(&self) -> Option<RTSPMountPoints> {
336 unsafe {
337 from_glib_full(ffi::gst_rtsp_server_get_mount_points(
338 self.as_ref().to_glib_none().0,
339 ))
340 }
341 }
342
343 #[doc(alias = "gst_rtsp_server_get_service")]
349 #[doc(alias = "get_service")]
350 fn service(&self) -> glib::GString {
351 unsafe {
352 from_glib_full(ffi::gst_rtsp_server_get_service(
353 self.as_ref().to_glib_none().0,
354 ))
355 }
356 }
357
358 #[doc(alias = "gst_rtsp_server_get_session_pool")]
365 #[doc(alias = "get_session_pool")]
366 #[doc(alias = "session-pool")]
367 fn session_pool(&self) -> Option<RTSPSessionPool> {
368 unsafe {
369 from_glib_full(ffi::gst_rtsp_server_get_session_pool(
370 self.as_ref().to_glib_none().0,
371 ))
372 }
373 }
374
375 #[doc(alias = "gst_rtsp_server_get_thread_pool")]
382 #[doc(alias = "get_thread_pool")]
383 fn thread_pool(&self) -> Option<RTSPThreadPool> {
384 unsafe {
385 from_glib_full(ffi::gst_rtsp_server_get_thread_pool(
386 self.as_ref().to_glib_none().0,
387 ))
388 }
389 }
390
391 #[doc(alias = "gst_rtsp_server_set_address")]
397 #[doc(alias = "address")]
398 fn set_address(&self, address: &str) {
399 unsafe {
400 ffi::gst_rtsp_server_set_address(
401 self.as_ref().to_glib_none().0,
402 address.to_glib_none().0,
403 );
404 }
405 }
406
407 #[doc(alias = "gst_rtsp_server_set_auth")]
411 fn set_auth(&self, auth: Option<&impl IsA<RTSPAuth>>) {
412 unsafe {
413 ffi::gst_rtsp_server_set_auth(
414 self.as_ref().to_glib_none().0,
415 auth.map(|p| p.as_ref()).to_glib_none().0,
416 );
417 }
418 }
419
420 #[doc(alias = "gst_rtsp_server_set_backlog")]
427 #[doc(alias = "backlog")]
428 fn set_backlog(&self, backlog: i32) {
429 unsafe {
430 ffi::gst_rtsp_server_set_backlog(self.as_ref().to_glib_none().0, backlog);
431 }
432 }
433
434 #[cfg(feature = "v1_18")]
437 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
438 #[doc(alias = "gst_rtsp_server_set_content_length_limit")]
439 #[doc(alias = "content-length-limit")]
440 fn set_content_length_limit(&self, limit: u32) {
441 unsafe {
442 ffi::gst_rtsp_server_set_content_length_limit(self.as_ref().to_glib_none().0, limit);
443 }
444 }
445
446 #[doc(alias = "gst_rtsp_server_set_mount_points")]
450 #[doc(alias = "mount-points")]
451 fn set_mount_points(&self, mounts: Option<&impl IsA<RTSPMountPoints>>) {
452 unsafe {
453 ffi::gst_rtsp_server_set_mount_points(
454 self.as_ref().to_glib_none().0,
455 mounts.map(|p| p.as_ref()).to_glib_none().0,
456 );
457 }
458 }
459
460 #[doc(alias = "gst_rtsp_server_set_service")]
472 #[doc(alias = "service")]
473 fn set_service(&self, service: &str) {
474 unsafe {
475 ffi::gst_rtsp_server_set_service(
476 self.as_ref().to_glib_none().0,
477 service.to_glib_none().0,
478 );
479 }
480 }
481
482 #[doc(alias = "gst_rtsp_server_set_session_pool")]
486 #[doc(alias = "session-pool")]
487 fn set_session_pool(&self, pool: Option<&impl IsA<RTSPSessionPool>>) {
488 unsafe {
489 ffi::gst_rtsp_server_set_session_pool(
490 self.as_ref().to_glib_none().0,
491 pool.map(|p| p.as_ref()).to_glib_none().0,
492 );
493 }
494 }
495
496 #[doc(alias = "gst_rtsp_server_set_thread_pool")]
500 fn set_thread_pool(&self, pool: Option<&impl IsA<RTSPThreadPool>>) {
501 unsafe {
502 ffi::gst_rtsp_server_set_thread_pool(
503 self.as_ref().to_glib_none().0,
504 pool.map(|p| p.as_ref()).to_glib_none().0,
505 );
506 }
507 }
508
509 #[doc(alias = "gst_rtsp_server_transfer_connection")]
526 fn transfer_connection(
527 &self,
528 socket: impl IsA<gio::Socket>,
529 ip: &str,
530 port: i32,
531 initial_buffer: Option<&str>,
532 ) -> Result<(), glib::error::BoolError> {
533 unsafe {
534 glib::result_from_gboolean!(
535 ffi::gst_rtsp_server_transfer_connection(
536 self.as_ref().to_glib_none().0,
537 socket.upcast().into_glib_ptr(),
538 ip.to_glib_none().0,
539 port,
540 initial_buffer.to_glib_none().0
541 ),
542 "Failed to transfer to the connection"
543 )
544 }
545 }
546
547 #[cfg(not(feature = "v1_18"))]
548 #[cfg_attr(docsrs, doc(cfg(not(feature = "v1_18"))))]
549 #[doc(alias = "content-length-limit")]
550 fn content_length_limit(&self) -> u32 {
551 ObjectExt::property(self.as_ref(), "content-length-limit")
552 }
553
554 #[cfg(not(feature = "v1_18"))]
555 #[cfg_attr(docsrs, doc(cfg(not(feature = "v1_18"))))]
556 #[doc(alias = "content-length-limit")]
557 fn set_content_length_limit(&self, content_length_limit: u32) {
558 ObjectExt::set_property(self.as_ref(), "content-length-limit", content_length_limit)
559 }
560
561 #[doc(alias = "client-connected")]
562 fn connect_client_connected<F: Fn(&Self, &RTSPClient) + Send + Sync + 'static>(
563 &self,
564 f: F,
565 ) -> SignalHandlerId {
566 unsafe extern "C" fn client_connected_trampoline<
567 P: IsA<RTSPServer>,
568 F: Fn(&P, &RTSPClient) + Send + Sync + 'static,
569 >(
570 this: *mut ffi::GstRTSPServer,
571 object: *mut ffi::GstRTSPClient,
572 f: glib::ffi::gpointer,
573 ) {
574 unsafe {
575 let f: &F = &*(f as *const F);
576 f(
577 RTSPServer::from_glib_borrow(this).unsafe_cast_ref(),
578 &from_glib_borrow(object),
579 )
580 }
581 }
582 unsafe {
583 let f: Box_<F> = Box_::new(f);
584 connect_raw(
585 self.as_ptr() as *mut _,
586 c"client-connected".as_ptr(),
587 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
588 client_connected_trampoline::<Self, F> as *const (),
589 )),
590 Box_::into_raw(f),
591 )
592 }
593 }
594
595 #[doc(alias = "address")]
596 fn connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
597 &self,
598 f: F,
599 ) -> SignalHandlerId {
600 unsafe extern "C" fn notify_address_trampoline<
601 P: IsA<RTSPServer>,
602 F: Fn(&P) + Send + Sync + 'static,
603 >(
604 this: *mut ffi::GstRTSPServer,
605 _param_spec: glib::ffi::gpointer,
606 f: glib::ffi::gpointer,
607 ) {
608 unsafe {
609 let f: &F = &*(f as *const F);
610 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
611 }
612 }
613 unsafe {
614 let f: Box_<F> = Box_::new(f);
615 connect_raw(
616 self.as_ptr() as *mut _,
617 c"notify::address".as_ptr(),
618 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
619 notify_address_trampoline::<Self, F> as *const (),
620 )),
621 Box_::into_raw(f),
622 )
623 }
624 }
625
626 #[doc(alias = "backlog")]
627 fn connect_backlog_notify<F: Fn(&Self) + Send + Sync + 'static>(
628 &self,
629 f: F,
630 ) -> SignalHandlerId {
631 unsafe extern "C" fn notify_backlog_trampoline<
632 P: IsA<RTSPServer>,
633 F: Fn(&P) + Send + Sync + 'static,
634 >(
635 this: *mut ffi::GstRTSPServer,
636 _param_spec: glib::ffi::gpointer,
637 f: glib::ffi::gpointer,
638 ) {
639 unsafe {
640 let f: &F = &*(f as *const F);
641 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
642 }
643 }
644 unsafe {
645 let f: Box_<F> = Box_::new(f);
646 connect_raw(
647 self.as_ptr() as *mut _,
648 c"notify::backlog".as_ptr(),
649 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
650 notify_backlog_trampoline::<Self, F> as *const (),
651 )),
652 Box_::into_raw(f),
653 )
654 }
655 }
656
657 #[doc(alias = "bound-port")]
658 fn connect_bound_port_notify<F: Fn(&Self) + Send + Sync + 'static>(
659 &self,
660 f: F,
661 ) -> SignalHandlerId {
662 unsafe extern "C" fn notify_bound_port_trampoline<
663 P: IsA<RTSPServer>,
664 F: Fn(&P) + Send + Sync + 'static,
665 >(
666 this: *mut ffi::GstRTSPServer,
667 _param_spec: glib::ffi::gpointer,
668 f: glib::ffi::gpointer,
669 ) {
670 unsafe {
671 let f: &F = &*(f as *const F);
672 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
673 }
674 }
675 unsafe {
676 let f: Box_<F> = Box_::new(f);
677 connect_raw(
678 self.as_ptr() as *mut _,
679 c"notify::bound-port".as_ptr(),
680 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
681 notify_bound_port_trampoline::<Self, F> as *const (),
682 )),
683 Box_::into_raw(f),
684 )
685 }
686 }
687
688 #[doc(alias = "content-length-limit")]
689 fn connect_content_length_limit_notify<F: Fn(&Self) + Send + Sync + 'static>(
690 &self,
691 f: F,
692 ) -> SignalHandlerId {
693 unsafe extern "C" fn notify_content_length_limit_trampoline<
694 P: IsA<RTSPServer>,
695 F: Fn(&P) + Send + Sync + 'static,
696 >(
697 this: *mut ffi::GstRTSPServer,
698 _param_spec: glib::ffi::gpointer,
699 f: glib::ffi::gpointer,
700 ) {
701 unsafe {
702 let f: &F = &*(f as *const F);
703 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
704 }
705 }
706 unsafe {
707 let f: Box_<F> = Box_::new(f);
708 connect_raw(
709 self.as_ptr() as *mut _,
710 c"notify::content-length-limit".as_ptr(),
711 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
712 notify_content_length_limit_trampoline::<Self, F> as *const (),
713 )),
714 Box_::into_raw(f),
715 )
716 }
717 }
718
719 #[doc(alias = "mount-points")]
720 fn connect_mount_points_notify<F: Fn(&Self) + Send + Sync + 'static>(
721 &self,
722 f: F,
723 ) -> SignalHandlerId {
724 unsafe extern "C" fn notify_mount_points_trampoline<
725 P: IsA<RTSPServer>,
726 F: Fn(&P) + Send + Sync + 'static,
727 >(
728 this: *mut ffi::GstRTSPServer,
729 _param_spec: glib::ffi::gpointer,
730 f: glib::ffi::gpointer,
731 ) {
732 unsafe {
733 let f: &F = &*(f as *const F);
734 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
735 }
736 }
737 unsafe {
738 let f: Box_<F> = Box_::new(f);
739 connect_raw(
740 self.as_ptr() as *mut _,
741 c"notify::mount-points".as_ptr(),
742 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
743 notify_mount_points_trampoline::<Self, F> as *const (),
744 )),
745 Box_::into_raw(f),
746 )
747 }
748 }
749
750 #[doc(alias = "service")]
751 fn connect_service_notify<F: Fn(&Self) + Send + Sync + 'static>(
752 &self,
753 f: F,
754 ) -> SignalHandlerId {
755 unsafe extern "C" fn notify_service_trampoline<
756 P: IsA<RTSPServer>,
757 F: Fn(&P) + Send + Sync + 'static,
758 >(
759 this: *mut ffi::GstRTSPServer,
760 _param_spec: glib::ffi::gpointer,
761 f: glib::ffi::gpointer,
762 ) {
763 unsafe {
764 let f: &F = &*(f as *const F);
765 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
766 }
767 }
768 unsafe {
769 let f: Box_<F> = Box_::new(f);
770 connect_raw(
771 self.as_ptr() as *mut _,
772 c"notify::service".as_ptr(),
773 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
774 notify_service_trampoline::<Self, F> as *const (),
775 )),
776 Box_::into_raw(f),
777 )
778 }
779 }
780
781 #[doc(alias = "session-pool")]
782 fn connect_session_pool_notify<F: Fn(&Self) + Send + Sync + 'static>(
783 &self,
784 f: F,
785 ) -> SignalHandlerId {
786 unsafe extern "C" fn notify_session_pool_trampoline<
787 P: IsA<RTSPServer>,
788 F: Fn(&P) + Send + Sync + 'static,
789 >(
790 this: *mut ffi::GstRTSPServer,
791 _param_spec: glib::ffi::gpointer,
792 f: glib::ffi::gpointer,
793 ) {
794 unsafe {
795 let f: &F = &*(f as *const F);
796 f(RTSPServer::from_glib_borrow(this).unsafe_cast_ref())
797 }
798 }
799 unsafe {
800 let f: Box_<F> = Box_::new(f);
801 connect_raw(
802 self.as_ptr() as *mut _,
803 c"notify::session-pool".as_ptr(),
804 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
805 notify_session_pool_trampoline::<Self, F> as *const (),
806 )),
807 Box_::into_raw(f),
808 )
809 }
810 }
811}
812
813impl<O: IsA<RTSPServer>> RTSPServerExt for O {}