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