gstreamer_rtsp_server/
rtsp_address_pool.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ptr;
4
5use glib::{prelude::*, translate::*};
6
7use crate::{ffi, RTSPAddress, RTSPAddressPool, RTSPAddressPoolResult};
8
9mod sealed {
10    pub trait Sealed {}
11    impl<T: super::IsA<super::RTSPAddressPool>> Sealed for T {}
12}
13
14pub trait RTSPAddressPoolExtManual: sealed::Sealed + IsA<RTSPAddressPool> + 'static {
15    /// Take a specific address and ports from `self`. `n_ports` consecutive
16    /// ports will be allocated of which the first one can be found in
17    /// `port`.
18    ///
19    /// If `ttl` is 0, `address` should be a unicast address. If `ttl` > 0, `address`
20    /// should be a valid multicast address.
21    /// ## `ip_address`
22    /// The IP address to reserve
23    /// ## `port`
24    /// The first port to reserve
25    /// ## `n_ports`
26    /// The number of ports
27    /// ## `ttl`
28    /// The requested ttl
29    ///
30    /// # Returns
31    ///
32    /// [`RTSPAddressPoolResult::Ok`][crate::RTSPAddressPoolResult::Ok] if an address was reserved. The address
33    /// is returned in `address` and should be freed with gst_rtsp_address_free
34    /// after use.
35    ///
36    /// ## `address`
37    /// storage for a [`RTSPAddress`][crate::RTSPAddress]
38    #[doc(alias = "gst_rtsp_address_pool_reserve_address")]
39    fn reserve_address(
40        &self,
41        ip_address: &str,
42        port: u32,
43        n_ports: u32,
44        ttl: u32,
45    ) -> Result<RTSPAddress, RTSPAddressPoolResult> {
46        unsafe {
47            let mut address = ptr::null_mut();
48            let ret = from_glib(ffi::gst_rtsp_address_pool_reserve_address(
49                self.as_ref().to_glib_none().0,
50                ip_address.to_glib_none().0,
51                port,
52                n_ports,
53                ttl,
54                &mut address,
55            ));
56            match ret {
57                RTSPAddressPoolResult::Ok => Ok(from_glib_full(address)),
58                _ => Err(ret),
59            }
60        }
61    }
62}
63
64impl<O: IsA<RTSPAddressPool>> RTSPAddressPoolExtManual for O {}