Skip to main content

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::{RTSPAddress, RTSPAddressFlags, ffi};
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
47/// Trait containing all [`struct@RTSPAddressPool`] methods.
48///
49/// # Implementors
50///
51/// [`RTSPAddressPool`][struct@crate::RTSPAddressPool]
52pub trait RTSPAddressPoolExt: IsA<RTSPAddressPool> + 'static {
53    /// Take an address and ports from `self`. `flags` can be used to control the
54    /// allocation. `n_ports` consecutive ports will be allocated of which the first
55    /// one can be found in `port`.
56    /// ## `flags`
57    /// flags
58    /// ## `n_ports`
59    /// the amount of ports
60    ///
61    /// # Returns
62    ///
63    /// a [`RTSPAddress`][crate::RTSPAddress] that should be freed with
64    /// gst_rtsp_address_free after use or [`None`] when no address could be
65    /// acquired.
66    #[doc(alias = "gst_rtsp_address_pool_acquire_address")]
67    fn acquire_address(
68        &self,
69        flags: RTSPAddressFlags,
70        n_ports: i32,
71    ) -> Result<RTSPAddress, glib::BoolError> {
72        unsafe {
73            Option::<_>::from_glib_full(ffi::gst_rtsp_address_pool_acquire_address(
74                self.as_ref().to_glib_none().0,
75                flags.into_glib(),
76                n_ports,
77            ))
78            .ok_or_else(|| glib::bool_error!("Failed to acquire address"))
79        }
80    }
81
82    ///  0, `min_address` and `max_address` should be multicast addresses.
83    /// ## `min_address`
84    /// a minimum address to add
85    /// ## `max_address`
86    /// a maximum address to add
87    /// ## `min_port`
88    /// the minimum port
89    /// ## `max_port`
90    /// the maximum port
91    /// ## `ttl`
92    /// a TTL or 0 for unicast addresses
93    ///
94    /// # Returns
95    ///
96    /// [`true`] if the addresses could be added.
97    #[doc(alias = "gst_rtsp_address_pool_add_range")]
98    fn add_range(
99        &self,
100        min_address: &str,
101        max_address: &str,
102        min_port: u16,
103        max_port: u16,
104        ttl: u8,
105    ) -> Result<(), glib::error::BoolError> {
106        unsafe {
107            glib::result_from_gboolean!(
108                ffi::gst_rtsp_address_pool_add_range(
109                    self.as_ref().to_glib_none().0,
110                    min_address.to_glib_none().0,
111                    max_address.to_glib_none().0,
112                    min_port,
113                    max_port,
114                    ttl
115                ),
116                "Failed to add address range"
117            )
118        }
119    }
120
121    /// Clear all addresses in `self`. There should be no outstanding
122    /// allocations.
123    #[doc(alias = "gst_rtsp_address_pool_clear")]
124    fn clear(&self) {
125        unsafe {
126            ffi::gst_rtsp_address_pool_clear(self.as_ref().to_glib_none().0);
127        }
128    }
129
130    /// Dump the free and allocated addresses to stdout.
131    #[doc(alias = "gst_rtsp_address_pool_dump")]
132    fn dump(&self) {
133        unsafe {
134            ffi::gst_rtsp_address_pool_dump(self.as_ref().to_glib_none().0);
135        }
136    }
137
138    /// Used to know if the pool includes any unicast addresses.
139    ///
140    /// # Returns
141    ///
142    /// [`true`] if the pool includes any unicast addresses, [`false`] otherwise
143    #[doc(alias = "gst_rtsp_address_pool_has_unicast_addresses")]
144    fn has_unicast_addresses(&self) -> bool {
145        unsafe {
146            from_glib(ffi::gst_rtsp_address_pool_has_unicast_addresses(
147                self.as_ref().to_glib_none().0,
148            ))
149        }
150    }
151}
152
153impl<O: IsA<RTSPAddressPool>> RTSPAddressPoolExt for O {}