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