address-pool: cleanups

Remove redundant method, improve docs.
This commit is contained in:
Wim Taymans 2013-07-16 12:32:00 +02:00
parent 0a8f5c8892
commit d3d7df5a1e
5 changed files with 34 additions and 51 deletions

View file

@ -17,7 +17,6 @@ gst_rtsp_address_pool_new
gst_rtsp_address_pool_clear
gst_rtsp_address_pool_dump
gst_rtsp_address_pool_add_range
gst_rtsp_address_pool_add_range_unicast
gst_rtsp_address_pool_has_unicast_addresses
gst_rtsp_address_pool_acquire_address
gst_rtsp_address_pool_reserve_address

View file

@ -247,12 +247,19 @@ get_address_string (Addr * addr)
* @max_address: a maximum address to add
* @min_port: the minimum port
* @max_port: the maximum port
* @ttl: a TTL
* @ttl: a TTL or 0 for unicast addresses
*
* Adds the multicast addresses from @min_addess to @max_address (inclusive)
* Adds the addresses from @min_addess to @max_address (inclusive)
* to @pool. 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.
*
* Returns: %TRUE if the addresses could be added.
*/
gboolean
@ -262,17 +269,20 @@ gst_rtsp_address_pool_add_range (GstRTSPAddressPool * pool,
{
AddrRange *range;
GstRTSPAddressPoolPrivate *priv;
gboolean is_multicast;
g_return_val_if_fail (GST_IS_RTSP_ADDRESS_POOL (pool), FALSE);
g_return_val_if_fail (min_port <= max_port, FALSE);
priv = pool->priv;
is_multicast = ttl != 0;
range = g_slice_new0 (AddrRange);
if (!fill_address (min_address, min_port, &range->min, (ttl != 0)))
if (!fill_address (min_address, min_port, &range->min, is_multicast))
goto invalid;
if (!fill_address (max_address, max_port, &range->max, (ttl != 0)))
if (!fill_address (max_address, max_port, &range->max, is_multicast))
goto invalid;
if (range->min.size != range->max.size)
@ -288,7 +298,7 @@ gst_rtsp_address_pool_add_range (GstRTSPAddressPool * pool,
g_mutex_lock (&priv->lock);
priv->addresses = g_list_prepend (priv->addresses, range);
if (ttl == 0)
if (!is_multicast)
priv->has_unicast_addresses = TRUE;
g_mutex_unlock (&priv->lock);
@ -304,35 +314,6 @@ invalid:
}
}
/**
* gst_rtsp_address_pool_add_range_unicast:
* @pool: a #GstRTSPAddressPool
* @min_address: a minimum address to add
* @max_address: a maximum address to add
* @min_port: the minimum port
* @max_port: the maximum port
*
* Adds the unicast addresses from @min_addess to @max_address (inclusive)
* to @pool. The valid port range for the addresses will be from @min_port to
* @max_port inclusive.
*
* @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.
*
* Returns: %TRUE if the addresses could be added.
*/
gboolean
gst_rtsp_address_pool_add_range_unicast (GstRTSPAddressPool * pool,
const gchar * min_address, const gchar * max_address,
guint16 min_port, guint16 max_port)
{
return gst_rtsp_address_pool_add_range (pool, min_address, max_address,
min_port, max_port, 0);
}
/* increments the address by count */
static void
inc_address (Addr * addr, guint8 count)
{
@ -605,12 +586,14 @@ gst_rtsp_address_pool_dump (GstRTSPAddressPool * pool)
* ports will be allocated of which the first one can be found in
* @port.
*
* If @ttl is 0, @address should be a unicast address. If @ttl > 0, @address
* should be a valid multicast address.
*
* This function should only be used internally.
*
* Returns: a #GstRTSPAddress that should be freed with gst_rtsp_address_free
* after use or %NULL when no address could be acquired.
*/
GstRTSPAddress *
gst_rtsp_address_pool_reserve_address (GstRTSPAddressPool * pool,
const gchar * address, guint port, guint n_ports, guint ttl)
@ -620,6 +603,7 @@ gst_rtsp_address_pool_reserve_address (GstRTSPAddressPool * pool,
GList *walk, *next;
AddrRange *result;
GstRTSPAddress *addr;
gboolean is_multicast;
g_return_val_if_fail (GST_IS_RTSP_ADDRESS_POOL (pool), NULL);
g_return_val_if_fail (address != NULL, NULL);
@ -629,11 +613,10 @@ gst_rtsp_address_pool_reserve_address (GstRTSPAddressPool * pool,
priv = pool->priv;
result = NULL;
addr = NULL;
is_multicast = ttl != 0;
if (!fill_address (address, port, &input_addr, (ttl != 0))) {
GST_ERROR_OBJECT (pool, "invalid address %s", address);
return NULL;
}
if (!fill_address (address, port, &input_addr, is_multicast))
goto invalid;
g_mutex_lock (&priv->lock);
/* go over available ranges */
@ -684,8 +667,15 @@ gst_rtsp_address_pool_reserve_address (GstRTSPAddressPool * pool,
GST_DEBUG_OBJECT (pool, "reserved address %s:%u ttl %u", addr->address,
addr->port, addr->ttl);
}
return addr;
/* ERRORS */
invalid:
{
GST_ERROR_OBJECT (pool, "invalid address %s:%u/%u/%u", address,
port, n_ports, ttl);
return NULL;
}
}
/**

View file

@ -139,12 +139,6 @@ gboolean gst_rtsp_address_pool_add_range (GstRTSPAddressPool
guint16 max_port,
guint8 ttl);
gboolean gst_rtsp_address_pool_add_range_unicast (GstRTSPAddressPool * pool,
const gchar *min_address,
const gchar *max_address,
guint16 min_port,
guint16 max_port);
GstRTSPAddress * gst_rtsp_address_pool_acquire_address (GstRTSPAddressPool * pool,
GstRTSPAddressFlags flags,
gint n_ports);

View file

@ -188,8 +188,8 @@ GST_START_TEST (test_pool)
fail_unless (gst_rtsp_address_pool_add_range (pool,
"233.252.1.1", "233.252.1.1", 5000, 5001, 1));
fail_unless (gst_rtsp_address_pool_add_range_unicast (pool,
"192.168.1.1", "192.168.1.1", 6000, 6001));
fail_unless (gst_rtsp_address_pool_add_range (pool,
"192.168.1.1", "192.168.1.1", 6000, 6001, 0));
addr = gst_rtsp_address_pool_acquire_address (pool,
GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);

View file

@ -1268,8 +1268,8 @@ GST_START_TEST (test_play_specific_server_port)
factory = gst_rtsp_media_factory_new ();
pool = gst_rtsp_address_pool_new ();
gst_rtsp_address_pool_add_range_unicast (pool, GST_RTSP_ADDRESS_POOL_ANY_IPV4,
GST_RTSP_ADDRESS_POOL_ANY_IPV4, 7770, 7780);
gst_rtsp_address_pool_add_range (pool, GST_RTSP_ADDRESS_POOL_ANY_IPV4,
GST_RTSP_ADDRESS_POOL_ANY_IPV4, 7770, 7780, 0);
gst_rtsp_media_factory_set_address_pool (factory, pool);
g_object_unref (pool);
gst_rtsp_media_factory_set_launch (factory, "( " VIDEO_PIPELINE " )");