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