gstreamer_rtsp_server/auto/
rtsp_address_pool.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, RTSPAddress, RTSPAddressFlags};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10    /// An address pool, all member are private
11    ///
12    /// # Implements
13    ///
14    /// [`RTSPAddressPoolExt`][trait@crate::prelude::RTSPAddressPoolExt], [`trait@glib::ObjectExt`], [`RTSPAddressPoolExtManual`][trait@crate::prelude::RTSPAddressPoolExtManual]
15    #[doc(alias = "GstRTSPAddressPool")]
16    pub struct RTSPAddressPool(Object<ffi::GstRTSPAddressPool, ffi::GstRTSPAddressPoolClass>);
17
18    match fn {
19        type_ => || ffi::gst_rtsp_address_pool_get_type(),
20    }
21}
22
23impl RTSPAddressPool {
24    pub const NONE: Option<&'static RTSPAddressPool> = None;
25
26    /// Make a new [`RTSPAddressPool`][crate::RTSPAddressPool].
27    ///
28    /// # Returns
29    ///
30    /// a new [`RTSPAddressPool`][crate::RTSPAddressPool]
31    #[doc(alias = "gst_rtsp_address_pool_new")]
32    pub fn new() -> RTSPAddressPool {
33        assert_initialized_main_thread!();
34        unsafe { from_glib_full(ffi::gst_rtsp_address_pool_new()) }
35    }
36}
37
38impl Default for RTSPAddressPool {
39    fn default() -> Self {
40        Self::new()
41    }
42}
43
44unsafe impl Send for RTSPAddressPool {}
45unsafe impl Sync for RTSPAddressPool {}
46
47mod sealed {
48    pub trait Sealed {}
49    impl<T: super::IsA<super::RTSPAddressPool>> Sealed for T {}
50}
51
52/// Trait containing all [`struct@RTSPAddressPool`] methods.
53///
54/// # Implementors
55///
56/// [`RTSPAddressPool`][struct@crate::RTSPAddressPool]
57pub trait RTSPAddressPoolExt: IsA<RTSPAddressPool> + sealed::Sealed + 'static {
58    /// Take an address and ports from `self`. `flags` can be used to control the
59    /// allocation. `n_ports` consecutive ports will be allocated of which the first
60    /// one can be found in `port`.
61    /// ## `flags`
62    /// flags
63    /// ## `n_ports`
64    /// the amount of ports
65    ///
66    /// # Returns
67    ///
68    /// a [`RTSPAddress`][crate::RTSPAddress] that should be freed with
69    /// gst_rtsp_address_free after use or [`None`] when no address could be
70    /// acquired.
71    #[doc(alias = "gst_rtsp_address_pool_acquire_address")]
72    fn acquire_address(
73        &self,
74        flags: RTSPAddressFlags,
75        n_ports: i32,
76    ) -> Result<RTSPAddress, glib::BoolError> {
77        unsafe {
78            Option::<_>::from_glib_full(ffi::gst_rtsp_address_pool_acquire_address(
79                self.as_ref().to_glib_none().0,
80                flags.into_glib(),
81                n_ports,
82            ))
83            .ok_or_else(|| glib::bool_error!("Failed to acquire address"))
84        }
85    }
86
87    /// Adds the addresses from `min_addess` to `max_address` (inclusive)
88    /// to `self`. The valid port range for the addresses will be from `min_port` to
89    /// `max_port` inclusive.
90    ///
91    /// When `ttl` is 0, `min_address` and `max_address` should be unicast addresses.
92    /// `min_address` and `max_address` can be set to
93    /// `GST_RTSP_ADDRESS_POOL_ANY_IPV4` or `GST_RTSP_ADDRESS_POOL_ANY_IPV6` to bind
94    /// to all available IPv4 or IPv6 addresses.
95    ///
96    /// When `ttl` > 0, `min_address` and `max_address` should be multicast addresses.
97    /// ## `min_address`
98    /// a minimum address to add
99    /// ## `max_address`
100    /// a maximum address to add
101    /// ## `min_port`
102    /// the minimum port
103    /// ## `max_port`
104    /// the maximum port
105    /// ## `ttl`
106    /// a TTL or 0 for unicast addresses
107    ///
108    /// # Returns
109    ///
110    /// [`true`] if the addresses could be added.
111    #[doc(alias = "gst_rtsp_address_pool_add_range")]
112    fn add_range(
113        &self,
114        min_address: &str,
115        max_address: &str,
116        min_port: u16,
117        max_port: u16,
118        ttl: u8,
119    ) -> Result<(), glib::error::BoolError> {
120        unsafe {
121            glib::result_from_gboolean!(
122                ffi::gst_rtsp_address_pool_add_range(
123                    self.as_ref().to_glib_none().0,
124                    min_address.to_glib_none().0,
125                    max_address.to_glib_none().0,
126                    min_port,
127                    max_port,
128                    ttl
129                ),
130                "Failed to add address range"
131            )
132        }
133    }
134
135    /// Clear all addresses in `self`. There should be no outstanding
136    /// allocations.
137    #[doc(alias = "gst_rtsp_address_pool_clear")]
138    fn clear(&self) {
139        unsafe {
140            ffi::gst_rtsp_address_pool_clear(self.as_ref().to_glib_none().0);
141        }
142    }
143
144    /// Dump the free and allocated addresses to stdout.
145    #[doc(alias = "gst_rtsp_address_pool_dump")]
146    fn dump(&self) {
147        unsafe {
148            ffi::gst_rtsp_address_pool_dump(self.as_ref().to_glib_none().0);
149        }
150    }
151
152    /// Used to know if the pool includes any unicast addresses.
153    ///
154    /// # Returns
155    ///
156    /// [`true`] if the pool includes any unicast addresses, [`false`] otherwise
157    #[doc(alias = "gst_rtsp_address_pool_has_unicast_addresses")]
158    fn has_unicast_addresses(&self) -> bool {
159        unsafe {
160            from_glib(ffi::gst_rtsp_address_pool_has_unicast_addresses(
161                self.as_ref().to_glib_none().0,
162            ))
163        }
164    }
165}
166
167impl<O: IsA<RTSPAddressPool>> RTSPAddressPoolExt for O {}