gstreamer_rtsp_server/
rtsp_server.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{prelude::*, source::SourceId, translate::*};
4
5use crate::{ffi, RTSPServer};
6
7mod sealed {
8    pub trait Sealed {}
9    impl<T: super::IsA<super::RTSPServer>> Sealed for T {}
10}
11
12pub trait RTSPServerExtManual: sealed::Sealed + IsA<RTSPServer> + 'static {
13    /// Attaches `self` to `context`. When the mainloop for `context` is run, the
14    /// server will be dispatched. When `context` is [`None`], the default context will be
15    /// used).
16    ///
17    /// This function should be called when the server properties and urls are fully
18    /// configured and the server is ready to start.
19    ///
20    /// This takes a reference on `self` until the source is destroyed. Note that
21    /// if `context` is not the default main context as returned by
22    /// [`glib::MainContext::default()`][crate::glib::MainContext::default()] (or [`None`]), [`glib::Source::remove()`][crate::glib::Source::remove()] cannot be used to
23    /// destroy the source. In that case it is recommended to use
24    /// [`RTSPServerExt::create_source()`][crate::prelude::RTSPServerExt::create_source()] and attach it to `context` manually.
25    /// ## `context`
26    /// a [`glib::MainContext`][crate::glib::MainContext]
27    ///
28    /// # Returns
29    ///
30    /// the ID (greater than 0) for the source within the GMainContext.
31    #[doc(alias = "gst_rtsp_server_attach")]
32    fn attach(
33        &self,
34        context: Option<&glib::MainContext>,
35    ) -> Result<SourceId, glib::error::BoolError> {
36        unsafe {
37            match ffi::gst_rtsp_server_attach(
38                self.as_ref().to_glib_none().0,
39                context.to_glib_none().0,
40            ) {
41                0 => Err(glib::bool_error!(
42                    "Failed to attach main context to RTSP server"
43                )),
44                id => Ok(from_glib(id)),
45            }
46        }
47    }
48}
49
50impl<O: IsA<RTSPServer>> RTSPServerExtManual for O {}