1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{prelude::*, source::SourceId, translate::*};

use crate::{ffi, RTSPServer};

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::RTSPServer>> Sealed for T {}
}

pub trait RTSPServerExtManual: sealed::Sealed + IsA<RTSPServer> + 'static {
    /// Attaches `self` to `context`. When the mainloop for `context` is run, the
    /// server will be dispatched. When `context` is [`None`], the default context will be
    /// used).
    ///
    /// This function should be called when the server properties and urls are fully
    /// configured and the server is ready to start.
    ///
    /// This takes a reference on `self` until the source is destroyed. Note that
    /// if `context` is not the default main context as returned by
    /// [`glib::MainContext::default()`][crate::glib::MainContext::default()] (or [`None`]), [`glib::Source::remove()`][crate::glib::Source::remove()] cannot be used to
    /// destroy the source. In that case it is recommended to use
    /// [`RTSPServerExt::create_source()`][crate::prelude::RTSPServerExt::create_source()] and attach it to `context` manually.
    /// ## `context`
    /// a [`glib::MainContext`][crate::glib::MainContext]
    ///
    /// # Returns
    ///
    /// the ID (greater than 0) for the source within the GMainContext.
    #[doc(alias = "gst_rtsp_server_attach")]
    fn attach(
        &self,
        context: Option<&glib::MainContext>,
    ) -> Result<SourceId, glib::error::BoolError> {
        unsafe {
            match ffi::gst_rtsp_server_attach(
                self.as_ref().to_glib_none().0,
                context.to_glib_none().0,
            ) {
                0 => Err(glib::bool_error!(
                    "Failed to attach main context to RTSP server"
                )),
                id => Ok(from_glib(id)),
            }
        }
    }
}

impl<O: IsA<RTSPServer>> RTSPServerExtManual for O {}