summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gst/rtsp-server/rtsp-address-pool.c66
1 files changed, 54 insertions, 12 deletions
diff --git a/gst/rtsp-server/rtsp-address-pool.c b/gst/rtsp-server/rtsp-address-pool.c
index b6e2711..6aef1d2 100644
--- a/gst/rtsp-server/rtsp-address-pool.c
+++ b/gst/rtsp-server/rtsp-address-pool.c
@@ -72,6 +72,8 @@ struct _GstRTSPAddressPoolPrivate
GList *allocated;
gboolean has_unicast_addresses;
+
+ gboolean allow_any_port;
};
#define ADDR_IS_IPV4(a) ((a)->size == 4)
@@ -90,6 +92,8 @@ typedef struct
Addr min;
Addr max;
guint8 ttl;
+
+ gboolean is_any_port;
} AddrRange;
#define RANGE_IS_SINGLE(r) (memcmp ((r)->min.bytes, (r)->max.bytes, (r)->min.size) == 0)
@@ -512,16 +516,20 @@ gst_rtsp_address_pool_release_address (GstRTSPAddressPool * pool,
addr->priv = NULL;
addr->pool = NULL;
- g_mutex_lock (&priv->lock);
- find = g_list_find (priv->allocated, range);
- if (find == NULL)
- goto not_found;
+ if (range->is_any_port) {
+ g_slice_free (AddrRange, range);
+ } else {
+ g_mutex_lock (&priv->lock);
+ find = g_list_find (priv->allocated, range);
+ if (find == NULL)
+ goto not_found;
- priv->allocated = g_list_delete_link (priv->allocated, find);
+ priv->allocated = g_list_delete_link (priv->allocated, find);
- /* FIXME, merge and do something clever */
- priv->addresses = g_list_prepend (priv->addresses, range);
- g_mutex_unlock (&priv->lock);
+ /* FIXME, merge and do something clever */
+ priv->addresses = g_list_prepend (priv->addresses, range);
+ g_mutex_unlock (&priv->lock);
+ }
g_object_unref (pool);
@@ -632,13 +640,24 @@ gst_rtsp_address_pool_reserve_address (GstRTSPAddressPool * pool,
memcmp (range->max.bytes, input_addr.bytes, input_addr.size) < 0)
continue;
- /* Make sure the requested ports are inside the range */
- if (port < range->min.port || port + n_ports - 1 > range->max.port)
- continue;
-
+ /* Make sure the ttl is the same */
if (ttl != range->ttl)
continue;
+ /* Make sure the requested ports are inside the range */
+ if (port < range->min.port || port + n_ports - 1 > range->max.port) {
+ if (priv->allow_any_port) {
+ result = g_slice_new0 (AddrRange);
+ result->min = input_addr;
+ result->max = input_addr;
+ result->max.port = port + n_ports - 1;
+ result->ttl = ttl;
+ result->is_any_port = TRUE;
+ } else {
+ continue;
+ }
+ }
+
skip_addr = diff_address (&input_addr, &range->min);
skip_port = port - range->min.port;
@@ -692,3 +711,26 @@ gst_rtsp_address_pool_has_unicast_addresses (GstRTSPAddressPool * pool)
return has_unicast_addresses;
}
+
+/**
+ * gst_rtsp_address_pool_allow_any_port:
+ * @pool: a #GstRTSPAddressPool
+ * @allow_any_port: %TRUE to accept any client
+ *
+ * Allow clients to reserve any port on an address on the range when
+ * using gst_rtsp_address_pool_reserve_address(), this enables the server
+ * to accept port requests from the client even if they are outside of the
+ * allocated pool.
+ */
+void
+gst_rtsp_address_pool_allow_any_port (GstRTSPAddressPool * pool,
+ gboolean allow_any_port)
+{
+ GstRTSPAddressPoolPrivate *priv;
+
+ g_return_if_fail (GST_IS_RTSP_ADDRESS_POOL (pool));
+
+ priv = pool->priv;
+
+ priv->allow_any_port = allow_any_port;
+}