Skip to main content

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