diff options
author | Wim Taymans <wim.taymans@gmail.com> | 2007-09-04 22:42:21 +0000 |
---|---|---|
committer | Wim Taymans <wim.taymans@gmail.com> | 2007-09-04 22:42:21 +0000 |
commit | 93e1176891d983ce7a1ee95c4016a03f13efb1e5 (patch) | |
tree | 7a8505f9589ef46dd791af0dd9fb7938667e446b /gst/udp | |
parent | ec68d41d6984e0d5d0560edef81e8c54dd641495 (diff) |
gst/udp/gstmultiudpsink.c: Add property do configure destination address/port pairs
Original commit message from CVS:
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_class_init),
(gst_multiudpsink_set_clients_string),
(gst_multiudpsink_get_clients_string),
(gst_multiudpsink_set_property), (gst_multiudpsink_get_property),
(gst_multiudpsink_init_send), (gst_multiudpsink_add_internal),
(gst_multiudpsink_add), (gst_multiudpsink_clear_internal),
(gst_multiudpsink_clear):
Add property do configure destination address/port pairs
API:GstMultiUDPSink::clients
Diffstat (limited to 'gst/udp')
-rw-r--r-- | gst/udp/gstmultiudpsink.c | 108 |
1 files changed, 99 insertions, 9 deletions
diff --git a/gst/udp/gstmultiudpsink.c b/gst/udp/gstmultiudpsink.c index 2e6117cd..a30ca543 100644 --- a/gst/udp/gstmultiudpsink.c +++ b/gst/udp/gstmultiudpsink.c @@ -71,6 +71,7 @@ enum #define DEFAULT_SOCKFD -1 #define DEFAULT_CLOSEFD TRUE #define DEFAULT_SOCK -1 +#define DEFAULT_CLIENTS NULL enum { @@ -79,7 +80,8 @@ enum PROP_BYTES_SERVED, PROP_SOCKFD, PROP_CLOSEFD, - PROP_SOCK + PROP_SOCK, + PROP_CLIENTS /* FILL ME */ }; @@ -103,6 +105,11 @@ static void gst_multiudpsink_set_property (GObject * object, guint prop_id, static void gst_multiudpsink_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +static void gst_multiudpsink_add_internal (GstMultiUDPSink * sink, + const gchar * host, gint port, gboolean lock); +static void gst_multiudpsink_clear_internal (GstMultiUDPSink * sink, + gboolean lock); + static void free_client (GstUDPClient * client); static GstElementClass *parent_class = NULL; @@ -266,6 +273,10 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass) g_param_spec_int ("sock", "Socket Handle", "Socket currently in use for UDP sending. (-1 == no socket)", -1, G_MAXINT, DEFAULT_SOCK, G_PARAM_READABLE)); + g_object_class_install_property (gobject_class, PROP_CLIENTS, + g_param_spec_string ("clients", "Clients", + "A comma separated list of host:port pairs with destinations", + DEFAULT_CLIENTS, G_PARAM_READWRITE)); gstelement_class->change_state = gst_multiudpsink_change_state; @@ -370,6 +381,61 @@ send_error: } static void +gst_multiudpsink_set_clients_string (GstMultiUDPSink * sink, + const gchar * string) +{ + gchar **clients; + gint i; + + clients = g_strsplit (string, ",", 0); + + g_mutex_lock (sink->client_lock); + /* clear all existing clients */ + gst_multiudpsink_clear_internal (sink, FALSE); + for (i = 0; clients[i]; i++) { + gchar *host, *p; + gint port = 0; + + host = clients[i]; + p = strstr (clients[i], ":"); + if (p != NULL) { + *p = '\0'; + port = atoi (p + 1); + } + if (port != 0) + gst_multiudpsink_add_internal (sink, host, port, FALSE); + } + g_mutex_unlock (sink->client_lock); + + g_strfreev (clients); +} + +static gchar * +gst_multiudpsink_get_clients_string (GstMultiUDPSink * sink) +{ + GString *str; + GList *clients; + + str = g_string_new (""); + + g_mutex_lock (sink->client_lock); + clients = sink->clients; + while (clients) { + GstUDPClient *client; + + client = (GstUDPClient *) clients->data; + + clients = g_list_next (clients); + + g_string_append_printf (str, "%s:%d%s", client->host, client->port, + (clients ? "," : "")); + } + g_mutex_unlock (sink->client_lock); + + return g_string_free (str, FALSE); +} + +static void gst_multiudpsink_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { @@ -385,6 +451,9 @@ gst_multiudpsink_set_property (GObject * object, guint prop_id, case PROP_CLOSEFD: udpsink->closefd = g_value_get_boolean (value); break; + case PROP_CLIENTS: + gst_multiudpsink_set_clients_string (udpsink, g_value_get_string (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -415,6 +484,10 @@ gst_multiudpsink_get_property (GObject * object, guint prop_id, GValue * value, case PROP_SOCK: g_value_set_int (value, udpsink->sock); break; + case PROP_CLIENTS: + g_value_take_string (value, + gst_multiudpsink_get_clients_string (udpsink)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -512,8 +585,9 @@ gst_multiudpsink_close (GstMultiUDPSink * sink) CLOSE_IF_REQUESTED (sink); } -void -gst_multiudpsink_add (GstMultiUDPSink * sink, const gchar * host, gint port) +static void +gst_multiudpsink_add_internal (GstMultiUDPSink * sink, const gchar * host, + gint port, gboolean lock) { struct hostent *he; struct in_addr addr; @@ -563,9 +637,11 @@ gst_multiudpsink_add (GstMultiUDPSink * sink, const gchar * host, gint port) goto host_error; } - g_mutex_lock (sink->client_lock); + if (lock) + g_mutex_lock (sink->client_lock); sink->clients = g_list_prepend (sink->clients, client); - g_mutex_unlock (sink->client_lock); + if (lock) + g_mutex_unlock (sink->client_lock); g_signal_emit (G_OBJECT (sink), gst_multiudpsink_signals[SIGNAL_CLIENT_ADDED], 0, host, port); @@ -582,6 +658,12 @@ host_error: } } +void +gst_multiudpsink_add (GstMultiUDPSink * sink, const gchar * host, gint port) +{ + gst_multiudpsink_add_internal (sink, host, port, TRUE); +} + static gint client_compare (GstUDPClient * a, GstUDPClient * b) { @@ -648,17 +730,25 @@ not_found: } } -void -gst_multiudpsink_clear (GstMultiUDPSink * sink) +static void +gst_multiudpsink_clear_internal (GstMultiUDPSink * sink, gboolean lock) { GST_DEBUG_OBJECT (sink, "clearing"); /* we only need to remove the client structure, there is no additional * socket or anything to free for UDP */ - g_mutex_lock (sink->client_lock); + if (lock) + g_mutex_lock (sink->client_lock); g_list_foreach (sink->clients, (GFunc) free_client, sink); g_list_free (sink->clients); sink->clients = NULL; - g_mutex_unlock (sink->client_lock); + if (lock) + g_mutex_unlock (sink->client_lock); +} + +void +gst_multiudpsink_clear (GstMultiUDPSink * sink) +{ + gst_multiudpsink_clear_internal (sink, TRUE); } GValueArray * |