rtsp: use AddressPool

Remove the multicast_group property.
Use the configured addresspool to allocate multicast addresses.
This commit is contained in:
Wim Taymans 2012-11-14 17:23:59 +01:00
parent d0ffc8e679
commit f15ffb521c
5 changed files with 139 additions and 108 deletions

View file

@ -978,13 +978,26 @@ configure_client_transport (GstRTSPClient * client, GstRTSPClientState * state,
/* we have a valid transport now, set the destination of the client. */
if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
if (ct->destination == NULL || !client->use_client_settings) {
GstRTSPAddressPool *pool;
gchar *address;
guint16 port;
guint8 ttl;
gpointer id;
pool = gst_rtsp_media_get_address_pool (state->media);
if (pool == NULL)
goto no_pool;
id = gst_rtsp_address_pool_acquire_address (pool,
GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 2, &address, &port, &ttl);
if (id == NULL)
goto no_address;
g_free (ct->destination);
ct->destination = gst_rtsp_media_get_multicast_group (state->media);
}
/* reset ttl and port if client settings are not allowed */
if (!client->use_client_settings) {
ct->port = state->stream->server_port;
ct->ttl = 0;
ct->destination = address;
ct->port.min = port;
ct->port.max = port + 1;
ct->ttl = ttl;
}
} else {
GstRTSPUrl *url;
@ -1002,6 +1015,16 @@ configure_client_transport (GstRTSPClient * client, GstRTSPClientState * state,
}
}
return TRUE;
/* ERRORS */
no_pool:
{
return FALSE;
}
no_address:
{
return FALSE;
}
}
static GstRTSPTransport *
@ -1143,7 +1166,8 @@ handle_setup_request (GstRTSPClient * client, GstRTSPClientState * state)
goto invalid_blocksize;
/* update the client transport */
configure_client_transport (client, state, ct);
if (!configure_client_transport (client, state, ct))
goto unsupported_client_transport;
/* set in the session media transport */
trans = gst_rtsp_session_media_set_transport (sessmedia, stream, ct);
@ -1206,6 +1230,13 @@ invalid_blocksize:
gst_rtsp_transport_free (ct);
return FALSE;
}
unsupported_client_transport:
{
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
g_object_unref (session);
gst_rtsp_transport_free (ct);
return FALSE;
}
no_transport:
{
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
@ -1262,7 +1293,11 @@ create_sdp (GstRTSPClient * client, GstRTSPMedia * media)
info.server_proto = proto;
protocols = gst_rtsp_media_get_protocols (media);
if (protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST)
#if 0
info.server_ip = gst_rtsp_media_get_multicast_group (media);
#else
info.server_ip = g_strdup (client->server_ip);
#endif
else
info.server_ip = g_strdup (client->server_ip);

View file

@ -24,7 +24,6 @@
#define DEFAULT_EOS_SHUTDOWN FALSE
#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_TCP
#define DEFAULT_BUFFER_SIZE 0x80000
#define DEFAULT_MULTICAST_GROUP "224.2.0.1"
enum
{
@ -34,7 +33,6 @@ enum
PROP_EOS_SHUTDOWN,
PROP_PROTOCOLS,
PROP_BUFFER_SIZE,
PROP_MULTICAST_GROUP,
PROP_LAST
};
@ -121,11 +119,6 @@ gst_rtsp_media_factory_class_init (GstRTSPMediaFactoryClass * klass)
"The kernel UDP buffer size to use", 0, G_MAXUINT,
DEFAULT_BUFFER_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MULTICAST_GROUP,
g_param_spec_string ("multicast-group", "Multicast Group",
"The Multicast group to send media to",
DEFAULT_MULTICAST_GROUP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_rtsp_media_factory_signals[SIGNAL_MEDIA_CONSTRUCTED] =
g_signal_new ("media-constructed", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPMediaFactoryClass,
@ -156,7 +149,6 @@ gst_rtsp_media_factory_init (GstRTSPMediaFactory * factory)
factory->eos_shutdown = DEFAULT_EOS_SHUTDOWN;
factory->protocols = DEFAULT_PROTOCOLS;
factory->buffer_size = DEFAULT_BUFFER_SIZE;
factory->multicast_group = g_strdup (DEFAULT_MULTICAST_GROUP);
g_mutex_init (&factory->lock);
g_mutex_init (&factory->medias_lock);
@ -172,10 +164,11 @@ gst_rtsp_media_factory_finalize (GObject * obj)
g_hash_table_unref (factory->medias);
g_mutex_clear (&factory->medias_lock);
g_free (factory->launch);
g_free (factory->multicast_group);
g_mutex_clear (&factory->lock);
if (factory->auth)
g_object_unref (factory->auth);
if (factory->pool)
g_object_unref (factory->pool);
G_OBJECT_CLASS (gst_rtsp_media_factory_parent_class)->finalize (obj);
}
@ -204,10 +197,6 @@ gst_rtsp_media_factory_get_property (GObject * object, guint propid,
g_value_set_uint (value,
gst_rtsp_media_factory_get_buffer_size (factory));
break;
case PROP_MULTICAST_GROUP:
g_value_take_string (value,
gst_rtsp_media_factory_get_multicast_group (factory));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
}
@ -237,10 +226,6 @@ gst_rtsp_media_factory_set_property (GObject * object, guint propid,
gst_rtsp_media_factory_set_buffer_size (factory,
g_value_get_uint (value));
break;
case PROP_MULTICAST_GROUP:
gst_rtsp_media_factory_set_multicast_group (factory,
g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
}
@ -438,41 +423,50 @@ gst_rtsp_media_factory_get_buffer_size (GstRTSPMediaFactory * factory)
}
/**
* gst_rtsp_media_factory_set_multicast_group:
* @factory: a #GstRTSPMedia
* @mc: the new multicast group
* gst_rtsp_media_factory_set_address_pool:
* @factory: a #GstRTSPMediaFactory
* @pool: a #GstRTSPAddressPool
*
* Set the multicast group that media from @factory will be streamed to.
* configure @pool to be used as the address pool of @factory.
*/
void
gst_rtsp_media_factory_set_multicast_group (GstRTSPMediaFactory * factory,
const gchar * mc)
gst_rtsp_media_factory_set_address_pool (GstRTSPMediaFactory * factory,
GstRTSPAddressPool * pool)
{
GstRTSPAddressPool *old;
g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
GST_RTSP_MEDIA_FACTORY_LOCK (factory);
g_free (factory->multicast_group);
factory->multicast_group = g_strdup (mc);
if ((old = factory->pool) != pool)
factory->pool = pool ? g_object_ref (pool) : NULL;
else
old = NULL;
GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
if (old)
g_object_unref (old);
}
/**
* gst_rtsp_media_factory_get_multicast_group:
* @factory: a #GstRTSPMedia
* gst_rtsp_media_factory_get_address_pool:
* @factory: a #GstRTSPMediaFactory
*
* Get the multicast group that media from @factory will be streamed to.
* Get the #GstRTSPAddressPool used as the address pool of @factory.
*
* Returns: the multicast group
* Returns: (transfer full): the #GstRTSPAddressPool of @factory. g_object_unref() after
* usage.
*/
gchar *
gst_rtsp_media_factory_get_multicast_group (GstRTSPMediaFactory * factory)
GstRTSPAddressPool *
gst_rtsp_media_factory_get_address_pool (GstRTSPMediaFactory * factory)
{
gchar *result;
GstRTSPAddressPool *result;
g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL);
GST_RTSP_MEDIA_FACTORY_LOCK (factory);
result = g_strdup (factory->multicast_group);
if ((result = factory->pool))
g_object_ref (result);
GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
return result;
@ -808,7 +802,7 @@ default_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media)
guint size;
GstRTSPAuth *auth;
GstRTSPLowerTrans protocols;
gchar *mc;
GstRTSPAddressPool *pool;
/* configure the sharedness */
GST_RTSP_MEDIA_FACTORY_LOCK (factory);
@ -827,9 +821,9 @@ default_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media)
gst_rtsp_media_set_auth (media, auth);
g_object_unref (auth);
}
if ((mc = gst_rtsp_media_factory_get_multicast_group (factory))) {
gst_rtsp_media_set_multicast_group (media, mc);
g_free (mc);
if ((pool = gst_rtsp_media_factory_get_address_pool (factory))) {
gst_rtsp_media_set_address_pool (media, pool);
g_object_unref (pool);
}
}

View file

@ -22,6 +22,7 @@
#include "rtsp-media.h"
#include "rtsp-auth.h"
#include "rtsp-address-pool.h"
#ifndef __GST_RTSP_MEDIA_FACTORY_H__
#define __GST_RTSP_MEDIA_FACTORY_H__
@ -55,7 +56,7 @@ typedef struct _GstRTSPMediaFactoryClass GstRTSPMediaFactoryClass;
* @protocols: allowed transport protocols
* @auth: the authentication manager
* @buffer_size: the kernel udp buffer size
* @multicast_group: the multicast group to send to
* @pool: the multicast address pool to use
* @medias_lock: mutex protecting the medias.
* @medias: hashtable of shared media
*
@ -72,7 +73,7 @@ struct _GstRTSPMediaFactory {
GstRTSPLowerTrans protocols;
GstRTSPAuth *auth;
guint buffer_size;
gchar *multicast_group;
GstRTSPAddressPool *pool;
GMutex medias_lock;
GHashTable *medias;
@ -139,12 +140,13 @@ GstRTSPLowerTrans gst_rtsp_media_factory_get_protocols (GstRTSPMediaFactory
void gst_rtsp_media_factory_set_auth (GstRTSPMediaFactory *factory, GstRTSPAuth *auth);
GstRTSPAuth * gst_rtsp_media_factory_get_auth (GstRTSPMediaFactory *factory);
void gst_rtsp_media_factory_set_address_pool (GstRTSPMediaFactory * factory,
GstRTSPAddressPool * pool);
GstRTSPAddressPool * gst_rtsp_media_factory_get_address_pool (GstRTSPMediaFactory * factory);
void gst_rtsp_media_factory_set_buffer_size (GstRTSPMediaFactory * factory, guint size);
guint gst_rtsp_media_factory_get_buffer_size (GstRTSPMediaFactory * factory);
void gst_rtsp_media_factory_set_multicast_group (GstRTSPMediaFactory * factory, const gchar *mc);
gchar * gst_rtsp_media_factory_get_multicast_group (GstRTSPMediaFactory * factory);
/* creating the media from the factory and a url */
GstRTSPMedia * gst_rtsp_media_factory_construct (GstRTSPMediaFactory *factory,
const GstRTSPUrl *url);

View file

@ -31,7 +31,6 @@
//#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP_MCAST
#define DEFAULT_EOS_SHUTDOWN FALSE
#define DEFAULT_BUFFER_SIZE 0x80000
#define DEFAULT_MULTICAST_GROUP "224.2.0.1"
#define DEFAULT_MTU 0
/* define to dump received RTCP packets */
@ -45,7 +44,6 @@ enum
PROP_PROTOCOLS,
PROP_EOS_SHUTDOWN,
PROP_BUFFER_SIZE,
PROP_MULTICAST_GROUP,
PROP_MTU,
PROP_LAST
};
@ -113,11 +111,6 @@ gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
"The kernel UDP buffer size to use", 0, G_MAXUINT,
DEFAULT_BUFFER_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MULTICAST_GROUP,
g_param_spec_string ("multicast-group", "Multicast Group",
"The Multicast group to send media to",
DEFAULT_MULTICAST_GROUP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MTU,
g_param_spec_uint ("mtu", "MTU",
"The MTU for the payloaders (0 = default)",
@ -163,7 +156,6 @@ gst_rtsp_media_init (GstRTSPMedia * media)
media->protocols = DEFAULT_PROTOCOLS;
media->eos_shutdown = DEFAULT_EOS_SHUTDOWN;
media->buffer_size = DEFAULT_BUFFER_SIZE;
media->multicast_group = g_strdup (DEFAULT_MULTICAST_GROUP);
}
static void
@ -185,7 +177,10 @@ gst_rtsp_media_finalize (GObject * obj)
g_source_destroy (media->source);
g_source_unref (media->source);
}
g_free (media->multicast_group);
if (media->auth)
g_object_unref (media->auth);
if (media->pool)
g_object_unref (media->pool);
g_mutex_clear (&media->lock);
g_cond_clear (&media->cond);
g_rec_mutex_clear (&media->state_lock);
@ -215,9 +210,6 @@ gst_rtsp_media_get_property (GObject * object, guint propid,
case PROP_BUFFER_SIZE:
g_value_set_uint (value, gst_rtsp_media_get_buffer_size (media));
break;
case PROP_MULTICAST_GROUP:
g_value_take_string (value, gst_rtsp_media_get_multicast_group (media));
break;
case PROP_MTU:
g_value_set_uint (value, gst_rtsp_media_get_mtu (media));
break;
@ -248,9 +240,6 @@ gst_rtsp_media_set_property (GObject * object, guint propid,
case PROP_BUFFER_SIZE:
gst_rtsp_media_set_buffer_size (media, g_value_get_uint (value));
break;
case PROP_MULTICAST_GROUP:
gst_rtsp_media_set_multicast_group (media, g_value_get_string (value));
break;
case PROP_MTU:
gst_rtsp_media_set_mtu (media, g_value_get_uint (value));
break;
@ -539,46 +528,6 @@ gst_rtsp_media_get_buffer_size (GstRTSPMedia * media)
return res;
}
/**
* gst_rtsp_media_set_multicast_group:
* @media: a #GstRTSPMedia
* @mc: the new multicast group
*
* Set the multicast group that media from @media will be streamed to.
*/
void
gst_rtsp_media_set_multicast_group (GstRTSPMedia * media, const gchar * mc)
{
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
g_mutex_lock (&media->lock);
g_free (media->multicast_group);
media->multicast_group = g_strdup (mc);
g_mutex_unlock (&media->lock);
}
/**
* gst_rtsp_media_get_multicast_group:
* @media: (transfer full): a #GstRTSPMedia
*
* Get the multicast group that media from @media will be streamed to.
*
* Returns: the multicast group, g_free after usage.
*/
gchar *
gst_rtsp_media_get_multicast_group (GstRTSPMedia * media)
{
gchar *result;
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
g_mutex_lock (&media->lock);
result = g_strdup (media->multicast_group);
g_mutex_unlock (&media->lock);
return result;
}
/**
* gst_rtsp_media_set_auth:
* @media: a #GstRTSPMedia
@ -628,6 +577,56 @@ gst_rtsp_media_get_auth (GstRTSPMedia * media)
return result;
}
/**
* gst_rtsp_media_set_address_pool:
* @media: a #GstRTSPMedia
* @pool: a #GstRTSPAddressPool
*
* configure @pool to be used as the address pool of @media.
*/
void
gst_rtsp_media_set_address_pool (GstRTSPMedia * media,
GstRTSPAddressPool * pool)
{
GstRTSPAddressPool *old;
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
g_mutex_lock (&media->lock);
if ((old = media->pool) != pool)
media->pool = pool ? g_object_ref (pool) : NULL;
else
old = NULL;
g_mutex_unlock (&media->lock);
if (old)
g_object_unref (old);
}
/**
* gst_rtsp_media_get_address_pool:
* @media: a #GstRTSPMedia
*
* Get the #GstRTSPAddressPool used as the address pool of @media.
*
* Returns: (transfer full): the #GstRTSPAddressPool of @media. g_object_unref() after
* usage.
*/
GstRTSPAddressPool *
gst_rtsp_media_get_address_pool (GstRTSPMedia * media)
{
GstRTSPAddressPool *result;
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
g_mutex_lock (&media->lock);
if ((result = media->pool))
g_object_ref (result);
g_mutex_unlock (&media->lock);
return result;
}
/**
* gst_rtsp_media_set_mtu:
* @media: a #GstRTSPMedia

View file

@ -41,6 +41,7 @@ typedef struct _GstRTSPMediaClass GstRTSPMediaClass;
#include "rtsp-stream.h"
#include "rtsp-auth.h"
#include "rtsp-address-pool.h"
/**
* GstRTSPMediaStatus:
@ -112,7 +113,7 @@ struct _GstRTSPMedia {
gboolean eos_shutdown;
guint buffer_size;
GstRTSPAuth *auth;
gchar *multicast_group;
GstRTSPAddressPool*pool;
guint mtu;
GstElement *element;
@ -191,12 +192,12 @@ gboolean gst_rtsp_media_is_eos_shutdown (GstRTSPMedia *media);
void gst_rtsp_media_set_auth (GstRTSPMedia *media, GstRTSPAuth *auth);
GstRTSPAuth * gst_rtsp_media_get_auth (GstRTSPMedia *media);
void gst_rtsp_media_set_address_pool (GstRTSPMedia *media, GstRTSPAddressPool *pool);
GstRTSPAddressPool * gst_rtsp_media_get_address_pool (GstRTSPMedia *media);
void gst_rtsp_media_set_buffer_size (GstRTSPMedia *media, guint size);
guint gst_rtsp_media_get_buffer_size (GstRTSPMedia *media);
void gst_rtsp_media_set_multicast_group (GstRTSPMedia *media, const gchar * mc);
gchar * gst_rtsp_media_get_multicast_group (GstRTSPMedia *media);
void gst_rtsp_media_set_mtu (GstRTSPMedia *media, guint mtu);
guint gst_rtsp_media_get_mtu (GstRTSPMedia *media);