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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use glib;
use glib::object::IsA;
use glib::translate::*;
use gst_rtsp_server_sys;
use RTSPAddress;
use RTSPAddressFlags;

glib_wrapper! {
    /// An address pool, all member are private
    ///
    /// # Implements
    ///
    /// [`RTSPAddressPoolExt`](trait.RTSPAddressPoolExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`RTSPAddressPoolExtManual`](prelude/trait.RTSPAddressPoolExtManual.html)
    pub struct RTSPAddressPool(Object<gst_rtsp_server_sys::GstRTSPAddressPool, gst_rtsp_server_sys::GstRTSPAddressPoolClass, RTSPAddressPoolClass>);

    match fn {
        get_type => || gst_rtsp_server_sys::gst_rtsp_address_pool_get_type(),
    }
}

impl RTSPAddressPool {
    /// Make a new `RTSPAddressPool`.
    ///
    /// # Returns
    ///
    /// a new `RTSPAddressPool`
    pub fn new() -> RTSPAddressPool {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(gst_rtsp_server_sys::gst_rtsp_address_pool_new()) }
    }
}

impl Default for RTSPAddressPool {
    fn default() -> Self {
        Self::new()
    }
}

unsafe impl Send for RTSPAddressPool {}
unsafe impl Sync for RTSPAddressPool {}

pub const NONE_RTSP_ADDRESS_POOL: Option<&RTSPAddressPool> = None;

/// Trait containing all `RTSPAddressPool` methods.
///
/// # Implementors
///
/// [`RTSPAddressPool`](struct.RTSPAddressPool.html)
pub trait RTSPAddressPoolExt: 'static {
    /// Take an address and ports from `self`. `flags` can be used to control the
    /// allocation. `n_ports` consecutive ports will be allocated of which the first
    /// one can be found in `port`.
    /// ## `flags`
    /// flags
    /// ## `n_ports`
    /// the amount of ports
    ///
    /// # Returns
    ///
    /// a `RTSPAddress` that should be freed with
    /// gst_rtsp_address_free after use or `None` when no address could be
    /// acquired.
    fn acquire_address(
        &self,
        flags: RTSPAddressFlags,
        n_ports: i32,
    ) -> Result<RTSPAddress, glib::BoolError>;

    /// Adds the addresses from `min_addess` to `max_address` (inclusive)
    /// to `self`. The valid port range for the addresses will be from `min_port` to
    /// `max_port` inclusive.
    ///
    /// When `ttl` is 0, `min_address` and `max_address` should be unicast addresses.
    /// `min_address` and `max_address` can be set to
    /// `GST_RTSP_ADDRESS_POOL_ANY_IPV4` or `GST_RTSP_ADDRESS_POOL_ANY_IPV6` to bind
    /// to all available IPv4 or IPv6 addresses.
    ///
    /// When `ttl` > 0, `min_address` and `max_address` should be multicast addresses.
    /// ## `min_address`
    /// a minimum address to add
    /// ## `max_address`
    /// a maximum address to add
    /// ## `min_port`
    /// the minimum port
    /// ## `max_port`
    /// the maximum port
    /// ## `ttl`
    /// a TTL or 0 for unicast addresses
    ///
    /// # Returns
    ///
    /// `true` if the addresses could be added.
    fn add_range(
        &self,
        min_address: &str,
        max_address: &str,
        min_port: u16,
        max_port: u16,
        ttl: u8,
    ) -> Result<(), glib::error::BoolError>;

    /// Clear all addresses in `self`. There should be no outstanding
    /// allocations.
    fn clear(&self);

    /// Dump the free and allocated addresses to stdout.
    fn dump(&self);

    /// Used to know if the pool includes any unicast addresses.
    ///
    /// # Returns
    ///
    /// `true` if the pool includes any unicast addresses, `false` otherwise
    fn has_unicast_addresses(&self) -> bool;
}

impl<O: IsA<RTSPAddressPool>> RTSPAddressPoolExt for O {
    fn acquire_address(
        &self,
        flags: RTSPAddressFlags,
        n_ports: i32,
    ) -> Result<RTSPAddress, glib::BoolError> {
        unsafe {
            Option::<_>::from_glib_full(gst_rtsp_server_sys::gst_rtsp_address_pool_acquire_address(
                self.as_ref().to_glib_none().0,
                flags.to_glib(),
                n_ports,
            ))
            .ok_or_else(|| glib_bool_error!("Failed to acquire address"))
        }
    }

    fn add_range(
        &self,
        min_address: &str,
        max_address: &str,
        min_port: u16,
        max_port: u16,
        ttl: u8,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_rtsp_server_sys::gst_rtsp_address_pool_add_range(
                    self.as_ref().to_glib_none().0,
                    min_address.to_glib_none().0,
                    max_address.to_glib_none().0,
                    min_port,
                    max_port,
                    ttl
                ),
                "Failed to add address range"
            )
        }
    }

    fn clear(&self) {
        unsafe {
            gst_rtsp_server_sys::gst_rtsp_address_pool_clear(self.as_ref().to_glib_none().0);
        }
    }

    fn dump(&self) {
        unsafe {
            gst_rtsp_server_sys::gst_rtsp_address_pool_dump(self.as_ref().to_glib_none().0);
        }
    }

    fn has_unicast_addresses(&self) -> bool {
        unsafe {
            from_glib(
                gst_rtsp_server_sys::gst_rtsp_address_pool_has_unicast_addresses(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }
}