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