mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 11:45:25 +00:00
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
This commit is contained in:
parent
ec68d41d69
commit
93e1176891
2 changed files with 111 additions and 9 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2007-09-04 Wim Taymans <wim.taymans@gmail.com>
|
||||
|
||||
* 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
|
||||
|
||||
2007-09-04 Wim Taymans <wim.taymans@gmail.com>
|
||||
|
||||
* tests/examples/Makefile.am:
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -369,6 +380,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 *
|
||||
|
|
Loading…
Reference in a new issue