gstreamer_rtsp_server/auto/
rtsp_session.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, RTSPFilterResult, RTSPMedia, RTSPSessionMedia};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// Session information kept by the server for a specific client.
16    /// One client session, identified with a session id, can handle multiple medias
17    /// identified with the url of a media.
18    ///
19    /// ## Properties
20    ///
21    ///
22    /// #### `extra-timeout`
23    ///  Readable | Writeable
24    ///
25    ///
26    /// #### `sessionid`
27    ///  Readable | Writeable | Construct Only
28    ///
29    ///
30    /// #### `timeout`
31    ///  Readable | Writeable
32    ///
33    ///
34    /// #### `timeout-always-visible`
35    ///  Readable | Writeable
36    ///
37    /// # Implements
38    ///
39    /// [`RTSPSessionExt`][trait@crate::prelude::RTSPSessionExt], [`trait@glib::ObjectExt`]
40    #[doc(alias = "GstRTSPSession")]
41    pub struct RTSPSession(Object<ffi::GstRTSPSession, ffi::GstRTSPSessionClass>);
42
43    match fn {
44        type_ => || ffi::gst_rtsp_session_get_type(),
45    }
46}
47
48impl RTSPSession {
49    pub const NONE: Option<&'static RTSPSession> = None;
50
51    /// Create a new [`RTSPSession`][crate::RTSPSession] instance with `sessionid`.
52    /// ## `sessionid`
53    /// a session id
54    ///
55    /// # Returns
56    ///
57    /// a new [`RTSPSession`][crate::RTSPSession]
58    #[doc(alias = "gst_rtsp_session_new")]
59    pub fn new(sessionid: &str) -> RTSPSession {
60        assert_initialized_main_thread!();
61        unsafe { from_glib_full(ffi::gst_rtsp_session_new(sessionid.to_glib_none().0)) }
62    }
63}
64
65unsafe impl Send for RTSPSession {}
66unsafe impl Sync for RTSPSession {}
67
68/// Trait containing all [`struct@RTSPSession`] methods.
69///
70/// # Implementors
71///
72/// [`RTSPSession`][struct@crate::RTSPSession]
73pub trait RTSPSessionExt: IsA<RTSPSession> + 'static {
74    /// Allow `self` to expire. This method must be called an equal
75    /// amount of time as [`prevent_expire()`][Self::prevent_expire()].
76    #[doc(alias = "gst_rtsp_session_allow_expire")]
77    fn allow_expire(&self) {
78        unsafe {
79            ffi::gst_rtsp_session_allow_expire(self.as_ref().to_glib_none().0);
80        }
81    }
82
83    /// Call `func` for each media in `self`. The result value of `func` determines
84    /// what happens to the media. `func` will be called with `self`
85    /// locked so no further actions on `self` can be performed from `func`.
86    ///
87    /// If `func` returns [`RTSPFilterResult::Remove`][crate::RTSPFilterResult::Remove], the media will be removed from
88    /// `self`.
89    ///
90    /// If `func` returns [`RTSPFilterResult::Keep`][crate::RTSPFilterResult::Keep], the media will remain in `self`.
91    ///
92    /// If `func` returns [`RTSPFilterResult::Ref`][crate::RTSPFilterResult::Ref], the media will remain in `self` but
93    /// will also be added with an additional ref to the result `GList` of this
94    /// function..
95    ///
96    /// When `func` is [`None`], [`RTSPFilterResult::Ref`][crate::RTSPFilterResult::Ref] will be assumed for all media.
97    /// ## `func`
98    /// a callback
99    ///
100    /// # Returns
101    ///
102    /// a GList with all
103    /// media for which `func` returned [`RTSPFilterResult::Ref`][crate::RTSPFilterResult::Ref]. After usage, each
104    /// element in the `GList` should be unreffed before the list is freed.
105    #[doc(alias = "gst_rtsp_session_filter")]
106    fn filter(
107        &self,
108        func: Option<&mut dyn (FnMut(&RTSPSession, &RTSPSessionMedia) -> RTSPFilterResult)>,
109    ) -> Vec<RTSPSessionMedia> {
110        let mut func_data: Option<
111            &mut dyn (FnMut(&RTSPSession, &RTSPSessionMedia) -> RTSPFilterResult),
112        > = func;
113        unsafe extern "C" fn func_func(
114            sess: *mut ffi::GstRTSPSession,
115            media: *mut ffi::GstRTSPSessionMedia,
116            user_data: glib::ffi::gpointer,
117        ) -> ffi::GstRTSPFilterResult {
118            let sess = from_glib_borrow(sess);
119            let media = from_glib_borrow(media);
120            let callback = user_data
121                as *mut Option<
122                    &mut dyn (FnMut(&RTSPSession, &RTSPSessionMedia) -> RTSPFilterResult),
123                >;
124            if let Some(ref mut callback) = *callback {
125                callback(&sess, &media)
126            } else {
127                panic!("cannot get closure...")
128            }
129            .into_glib()
130        }
131        let func = if func_data.is_some() {
132            Some(func_func as _)
133        } else {
134            None
135        };
136        let super_callback0: &mut Option<
137            &mut dyn (FnMut(&RTSPSession, &RTSPSessionMedia) -> RTSPFilterResult),
138        > = &mut func_data;
139        unsafe {
140            FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_session_filter(
141                self.as_ref().to_glib_none().0,
142                func,
143                super_callback0 as *mut _ as *mut _,
144            ))
145        }
146    }
147
148    /// Get the string that can be placed in the Session header field.
149    ///
150    /// # Returns
151    ///
152    /// the Session header of `self`.
153    /// `g_free()` after usage.
154    #[doc(alias = "gst_rtsp_session_get_header")]
155    #[doc(alias = "get_header")]
156    fn header(&self) -> Option<glib::GString> {
157        unsafe {
158            from_glib_full(ffi::gst_rtsp_session_get_header(
159                self.as_ref().to_glib_none().0,
160            ))
161        }
162    }
163
164    /// Get the sessionid of `self`.
165    ///
166    /// # Returns
167    ///
168    /// the sessionid of `self`.
169    /// The value remains valid as long as `self` is alive.
170    #[doc(alias = "gst_rtsp_session_get_sessionid")]
171    #[doc(alias = "get_sessionid")]
172    fn sessionid(&self) -> Option<glib::GString> {
173        unsafe {
174            from_glib_none(ffi::gst_rtsp_session_get_sessionid(
175                self.as_ref().to_glib_none().0,
176            ))
177        }
178    }
179
180    /// Get the timeout value of `self`.
181    ///
182    /// # Returns
183    ///
184    /// the timeout of `self` in seconds.
185    #[doc(alias = "gst_rtsp_session_get_timeout")]
186    #[doc(alias = "get_timeout")]
187    fn timeout(&self) -> u32 {
188        unsafe { ffi::gst_rtsp_session_get_timeout(self.as_ref().to_glib_none().0) }
189    }
190
191    //#[doc(alias = "gst_rtsp_session_is_expired")]
192    //fn is_expired(&self, now: /*Ignored*/&mut glib::TimeVal) -> bool {
193    //    unsafe { TODO: call ffi:gst_rtsp_session_is_expired() }
194    //}
195
196    /// Check if `self` timeout out.
197    /// ## `now`
198    /// the current monotonic time
199    ///
200    /// # Returns
201    ///
202    /// [`true`] if `self` timed out
203    #[doc(alias = "gst_rtsp_session_is_expired_usec")]
204    fn is_expired_usec(&self, now: i64) -> bool {
205        unsafe {
206            from_glib(ffi::gst_rtsp_session_is_expired_usec(
207                self.as_ref().to_glib_none().0,
208                now,
209            ))
210        }
211    }
212
213    /// Manage the media object `obj` in `self`. `path` will be used to retrieve this
214    /// media from the session with [`RTSPSessionExtManual::media()`][crate::prelude::RTSPSessionExtManual::media()].
215    ///
216    /// Ownership is taken from `media`.
217    /// ## `path`
218    /// the path for the media
219    /// ## `media`
220    /// a [`RTSPMedia`][crate::RTSPMedia]
221    ///
222    /// # Returns
223    ///
224    /// a new [`RTSPSessionMedia`][crate::RTSPSessionMedia] object.
225    #[doc(alias = "gst_rtsp_session_manage_media")]
226    fn manage_media(&self, path: &str, media: impl IsA<RTSPMedia>) -> RTSPSessionMedia {
227        unsafe {
228            from_glib_none(ffi::gst_rtsp_session_manage_media(
229                self.as_ref().to_glib_none().0,
230                path.to_glib_none().0,
231                media.upcast().into_glib_ptr(),
232            ))
233        }
234    }
235
236    //#[doc(alias = "gst_rtsp_session_next_timeout")]
237    //fn next_timeout(&self, now: /*Ignored*/&mut glib::TimeVal) -> i32 {
238    //    unsafe { TODO: call ffi:gst_rtsp_session_next_timeout() }
239    //}
240
241    /// Get the amount of milliseconds till the session will expire.
242    /// ## `now`
243    /// the current monotonic time
244    ///
245    /// # Returns
246    ///
247    /// the amount of milliseconds since the session will time out.
248    #[doc(alias = "gst_rtsp_session_next_timeout_usec")]
249    fn next_timeout_usec(&self, now: i64) -> i32 {
250        unsafe { ffi::gst_rtsp_session_next_timeout_usec(self.as_ref().to_glib_none().0, now) }
251    }
252
253    /// Prevent `self` from expiring.
254    #[doc(alias = "gst_rtsp_session_prevent_expire")]
255    fn prevent_expire(&self) {
256        unsafe {
257            ffi::gst_rtsp_session_prevent_expire(self.as_ref().to_glib_none().0);
258        }
259    }
260
261    /// Release the managed `media` in `self`, freeing the memory allocated by it.
262    /// ## `media`
263    /// a [`RTSPMedia`][crate::RTSPMedia]
264    ///
265    /// # Returns
266    ///
267    /// [`true`] if there are more media session left in `self`.
268    #[doc(alias = "gst_rtsp_session_release_media")]
269    fn release_media(&self, media: &impl IsA<RTSPSessionMedia>) -> bool {
270        unsafe {
271            from_glib(ffi::gst_rtsp_session_release_media(
272                self.as_ref().to_glib_none().0,
273                media.as_ref().to_glib_none().0,
274            ))
275        }
276    }
277
278    /// Configure `self` for a timeout of `timeout` seconds. The session will be
279    /// cleaned up when there is no activity for `timeout` seconds.
280    /// ## `timeout`
281    /// the new timeout
282    #[doc(alias = "gst_rtsp_session_set_timeout")]
283    #[doc(alias = "timeout")]
284    fn set_timeout(&self, timeout: u32) {
285        unsafe {
286            ffi::gst_rtsp_session_set_timeout(self.as_ref().to_glib_none().0, timeout);
287        }
288    }
289
290    /// Update the last_access time of the session to the current time.
291    #[doc(alias = "gst_rtsp_session_touch")]
292    fn touch(&self) {
293        unsafe {
294            ffi::gst_rtsp_session_touch(self.as_ref().to_glib_none().0);
295        }
296    }
297
298    #[doc(alias = "extra-timeout")]
299    fn extra_timeout(&self) -> u32 {
300        ObjectExt::property(self.as_ref(), "extra-timeout")
301    }
302
303    #[doc(alias = "extra-timeout")]
304    fn set_extra_timeout(&self, extra_timeout: u32) {
305        ObjectExt::set_property(self.as_ref(), "extra-timeout", extra_timeout)
306    }
307
308    #[doc(alias = "timeout-always-visible")]
309    fn is_timeout_always_visible(&self) -> bool {
310        ObjectExt::property(self.as_ref(), "timeout-always-visible")
311    }
312
313    #[doc(alias = "timeout-always-visible")]
314    fn set_timeout_always_visible(&self, timeout_always_visible: bool) {
315        ObjectExt::set_property(
316            self.as_ref(),
317            "timeout-always-visible",
318            timeout_always_visible,
319        )
320    }
321
322    #[doc(alias = "extra-timeout")]
323    fn connect_extra_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(
324        &self,
325        f: F,
326    ) -> SignalHandlerId {
327        unsafe extern "C" fn notify_extra_timeout_trampoline<
328            P: IsA<RTSPSession>,
329            F: Fn(&P) + Send + Sync + 'static,
330        >(
331            this: *mut ffi::GstRTSPSession,
332            _param_spec: glib::ffi::gpointer,
333            f: glib::ffi::gpointer,
334        ) {
335            let f: &F = &*(f as *const F);
336            f(RTSPSession::from_glib_borrow(this).unsafe_cast_ref())
337        }
338        unsafe {
339            let f: Box_<F> = Box_::new(f);
340            connect_raw(
341                self.as_ptr() as *mut _,
342                c"notify::extra-timeout".as_ptr() as *const _,
343                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
344                    notify_extra_timeout_trampoline::<Self, F> as *const (),
345                )),
346                Box_::into_raw(f),
347            )
348        }
349    }
350
351    #[doc(alias = "timeout")]
352    fn connect_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(
353        &self,
354        f: F,
355    ) -> SignalHandlerId {
356        unsafe extern "C" fn notify_timeout_trampoline<
357            P: IsA<RTSPSession>,
358            F: Fn(&P) + Send + Sync + 'static,
359        >(
360            this: *mut ffi::GstRTSPSession,
361            _param_spec: glib::ffi::gpointer,
362            f: glib::ffi::gpointer,
363        ) {
364            let f: &F = &*(f as *const F);
365            f(RTSPSession::from_glib_borrow(this).unsafe_cast_ref())
366        }
367        unsafe {
368            let f: Box_<F> = Box_::new(f);
369            connect_raw(
370                self.as_ptr() as *mut _,
371                c"notify::timeout".as_ptr() as *const _,
372                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
373                    notify_timeout_trampoline::<Self, F> as *const (),
374                )),
375                Box_::into_raw(f),
376            )
377        }
378    }
379
380    #[doc(alias = "timeout-always-visible")]
381    fn connect_timeout_always_visible_notify<F: Fn(&Self) + Send + Sync + 'static>(
382        &self,
383        f: F,
384    ) -> SignalHandlerId {
385        unsafe extern "C" fn notify_timeout_always_visible_trampoline<
386            P: IsA<RTSPSession>,
387            F: Fn(&P) + Send + Sync + 'static,
388        >(
389            this: *mut ffi::GstRTSPSession,
390            _param_spec: glib::ffi::gpointer,
391            f: glib::ffi::gpointer,
392        ) {
393            let f: &F = &*(f as *const F);
394            f(RTSPSession::from_glib_borrow(this).unsafe_cast_ref())
395        }
396        unsafe {
397            let f: Box_<F> = Box_::new(f);
398            connect_raw(
399                self.as_ptr() as *mut _,
400                c"notify::timeout-always-visible".as_ptr() as *const _,
401                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
402                    notify_timeout_always_visible_trampoline::<Self, F> as *const (),
403                )),
404                Box_::into_raw(f),
405            )
406        }
407    }
408}
409
410impl<O: IsA<RTSPSession>> RTSPSessionExt for O {}