stream: add methods to deal with address pool

Add methods to get and set the address pool for the stream
Add method to allocate and get the multicast addresses for this stream.
This commit is contained in:
Wim Taymans 2012-11-15 15:36:21 +01:00
parent 1b4ac6e5b0
commit 44a2855eb3
2 changed files with 111 additions and 0 deletions

View file

@ -72,6 +72,10 @@ gst_rtsp_stream_finalize (GObject * obj)
/* we really need to be unjoined now */
g_return_if_fail (!stream->is_joined);
if (stream->addr)
gst_rtsp_address_free (stream->addr);
if (stream->pool)
g_object_unref (stream->pool);
gst_object_unref (stream->payloader);
gst_object_unref (stream->srcpad);
g_mutex_clear (&stream->lock);
@ -142,6 +146,100 @@ gst_rtsp_stream_get_mtu (GstRTSPStream * stream)
return mtu;
}
/**
* gst_rtsp_stream_set_address_pool:
* @stream: a #GstRTSPStream
* @pool: a #GstRTSPAddressPool
*
* configure @pool to be used as the address pool of @stream.
*/
void
gst_rtsp_stream_set_address_pool (GstRTSPStream * stream,
GstRTSPAddressPool * pool)
{
GstRTSPAddressPool *old;
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
g_mutex_lock (&stream->lock);
if ((old = stream->pool) != pool)
stream->pool = pool ? g_object_ref (pool) : NULL;
else
old = NULL;
g_mutex_unlock (&stream->lock);
if (old)
g_object_unref (old);
}
/**
* gst_rtsp_stream_get_address_pool:
* @stream: a #GstRTSPStream
*
* Get the #GstRTSPAddressPool used as the address pool of @stream.
*
* Returns: (transfer full): the #GstRTSPAddressPool of @stream. g_object_unref() after
* usage.
*/
GstRTSPAddressPool *
gst_rtsp_stream_get_address_pool (GstRTSPStream * stream)
{
GstRTSPAddressPool *result;
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
g_mutex_lock (&stream->lock);
if ((result = stream->pool))
g_object_ref (result);
g_mutex_unlock (&stream->lock);
return result;
}
/**
* gst_rtsp_stream_get_address:
* @stream: a #GstRTSPStream
*
* Get the multicast address of @stream.
*
* Returns: the #GstRTSPAddress of @stream or %NULL when no address could be
* allocated. gst_rtsp_address_free() after usage.
*/
GstRTSPAddress *
gst_rtsp_stream_get_address (GstRTSPStream * stream)
{
GstRTSPAddress *result;
g_mutex_lock (&stream->lock);
if (stream->addr == NULL) {
if (stream->pool == NULL)
goto no_pool;
stream->addr = gst_rtsp_address_pool_acquire_address (stream->pool,
GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 2);
if (stream->addr == NULL)
goto no_address;
}
result = gst_rtsp_address_copy (stream->addr);
g_mutex_unlock (&stream->lock);
return result;
/* ERRORS */
no_pool:
{
GST_ERROR_OBJECT (stream, "no address pool specified");
g_mutex_unlock (&stream->lock);
return NULL;
}
no_address:
{
GST_ERROR_OBJECT (stream, "failed to acquire address from pool");
g_mutex_unlock (&stream->lock);
return NULL;
}
}
/* must be called with lock */
static gboolean
alloc_ports (GstRTSPStream * stream)

View file

@ -40,6 +40,7 @@ typedef struct _GstRTSPStream GstRTSPStream;
typedef struct _GstRTSPStreamClass GstRTSPStreamClass;
#include "rtsp-stream-transport.h"
#include "rtsp-address-pool.h"
/**
* GstRTSPStream:
@ -63,6 +64,8 @@ typedef struct _GstRTSPStreamClass GstRTSPStreamClass;
* @tee: tee for the sending to udpsink and appsink
* @funnel: tee for the receiving from udpsrc and appsrc
* @server_port: the server ports for this stream
* @pool: the address pool for this stream
* @addr: the address for this stream
* @caps_sig: the signal id for detecting caps
* @caps: the caps of the stream
* @n_active: the number of active transports in @transports
@ -104,6 +107,10 @@ struct _GstRTSPStream {
/* server ports for sending/receiving */
GstRTSPRange server_port;
/* multicast addresses */
GstRTSPAddressPool *pool;
GstRTSPAddress *addr;
/* the caps of the stream */
gulong caps_sig;
GstCaps *caps;
@ -125,6 +132,12 @@ GstRTSPStream * gst_rtsp_stream_new (guint idx, GstElement *paylo
void gst_rtsp_stream_set_mtu (GstRTSPStream * stream, guint mtu);
guint gst_rtsp_stream_get_mtu (GstRTSPStream * stream);
void gst_rtsp_stream_set_address_pool (GstRTSPStream *stream, GstRTSPAddressPool *pool);
GstRTSPAddressPool *
gst_rtsp_stream_get_address_pool (GstRTSPStream *stream);
GstRTSPAddress * gst_rtsp_stream_get_address (GstRTSPStream *stream);
gboolean gst_rtsp_stream_join_bin (GstRTSPStream * stream,
GstBin *bin, GstElement *rtpbin,
GstState state);