gst/udp/gstmultiudpsink.*: Updated docs.

Original commit message from CVS:
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_class_init),
(gst_multiudpsink_render), (gst_multiudpsink_get_property),
(gst_multiudpsink_init_send), (gst_multiudpsink_add),
(gst_multiudpsink_remove), (gst_multiudpsink_clear),
(gst_multiudpsink_get_stats), (gst_multiudpsink_change_state):
* gst/udp/gstmultiudpsink.h:
Updated docs.
Added properties bytes-served, bytes_to_serve.
Post proper error messages,
Emit client added signal too.
This commit is contained in:
Wim Taymans 2006-02-06 17:26:43 +00:00
parent 2651b40adf
commit 21dbd4eb9a
3 changed files with 146 additions and 51 deletions

View file

@ -1,3 +1,16 @@
2006-02-06 Wim Taymans <wim@fluendo.com>
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_class_init),
(gst_multiudpsink_render), (gst_multiudpsink_get_property),
(gst_multiudpsink_init_send), (gst_multiudpsink_add),
(gst_multiudpsink_remove), (gst_multiudpsink_clear),
(gst_multiudpsink_get_stats), (gst_multiudpsink_change_state):
* gst/udp/gstmultiudpsink.h:
Updated docs.
Added properties bytes-served, bytes_to_serve.
Post proper error messages,
Emit client added signal too.
2006-02-06 Thomas Vander Stichele <thomas at apestaart dot org> 2006-02-06 Thomas Vander Stichele <thomas at apestaart dot org>
* docs/plugins/Makefile.am: * docs/plugins/Makefile.am:

View file

@ -71,6 +71,9 @@ enum
enum enum
{ {
PROP_0, PROP_0,
PROP_BYTES_TO_SERVE,
PROP_BYTES_SERVED,
/* FILL ME */ /* FILL ME */
}; };
@ -152,6 +155,9 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
* @gstmultiudpsink: the sink on which the signal is emitted * @gstmultiudpsink: the sink on which the signal is emitted
* @host: the hostname/IP address of the client to add * @host: the hostname/IP address of the client to add
* @port: the port of the client to add * @port: the port of the client to add
*
* Add a client with destination @host and @port to the list of
* clients.
*/ */
gst_multiudpsink_signals[SIGNAL_ADD] = gst_multiudpsink_signals[SIGNAL_ADD] =
g_signal_new ("add", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, g_signal_new ("add", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
@ -163,12 +169,21 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
* @gstmultiudpsink: the sink on which the signal is emitted * @gstmultiudpsink: the sink on which the signal is emitted
* @host: the hostname/IP address of the client to remove * @host: the hostname/IP address of the client to remove
* @port: the port of the client to remove * @port: the port of the client to remove
*
* Remove the client with destination @host and @port from the list of
* clients.
*/ */
gst_multiudpsink_signals[SIGNAL_REMOVE] = gst_multiudpsink_signals[SIGNAL_REMOVE] =
g_signal_new ("remove", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, g_signal_new ("remove", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstMultiUDPSinkClass, remove), G_STRUCT_OFFSET (GstMultiUDPSinkClass, remove),
NULL, NULL, gst_udp_marshal_VOID__STRING_INT, G_TYPE_NONE, 2, NULL, NULL, gst_udp_marshal_VOID__STRING_INT, G_TYPE_NONE, 2,
G_TYPE_STRING, G_TYPE_INT); G_TYPE_STRING, G_TYPE_INT);
/**
* GstMultiUDPSink::clear:
* @gstmultiudpsink: the sink on which the signal is emitted
*
* Clear the list of clients.
*/
gst_multiudpsink_signals[SIGNAL_CLEAR] = gst_multiudpsink_signals[SIGNAL_CLEAR] =
g_signal_new ("clear", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, g_signal_new ("clear", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstMultiUDPSinkClass, clear), G_STRUCT_OFFSET (GstMultiUDPSinkClass, clear),
@ -179,7 +194,9 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
* @host: the hostname/IP address of the client to get stats on * @host: the hostname/IP address of the client to get stats on
* @port: the port of the client to get stats on * @port: the port of the client to get stats on
* *
* @returns: a GValueArray of uint64: bytes_sent, packets_sent, * Get the statistics of the client with destination @host and @port.
*
* Returns: a GValueArray of uint64: bytes_sent, packets_sent,
* connect_time (in epoch seconds), disconnect_time (in epoch seconds) * connect_time (in epoch seconds), disconnect_time (in epoch seconds)
*/ */
gst_multiudpsink_signals[SIGNAL_GET_STATS] = gst_multiudpsink_signals[SIGNAL_GET_STATS] =
@ -192,6 +209,9 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
* @gstmultiudpsink: the sink emitting the signal * @gstmultiudpsink: the sink emitting the signal
* @host: the hostname/IP address of the added client * @host: the hostname/IP address of the added client
* @port: the port of the added client * @port: the port of the added client
*
* Signal emited when a new client is added to the list of
* clients.
*/ */
gst_multiudpsink_signals[SIGNAL_CLIENT_ADDED] = gst_multiudpsink_signals[SIGNAL_CLIENT_ADDED] =
g_signal_new ("client-added", G_TYPE_FROM_CLASS (klass), g_signal_new ("client-added", G_TYPE_FROM_CLASS (klass),
@ -203,6 +223,9 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
* @gstmultiudpsink: the sink emitting the signal * @gstmultiudpsink: the sink emitting the signal
* @host: the hostname/IP address of the removed client * @host: the hostname/IP address of the removed client
* @port: the port of the removed client * @port: the port of the removed client
*
* Signal emited when a client is removed from the list of
* clients.
*/ */
gst_multiudpsink_signals[SIGNAL_CLIENT_REMOVED] = gst_multiudpsink_signals[SIGNAL_CLIENT_REMOVED] =
g_signal_new ("client-removed", G_TYPE_FROM_CLASS (klass), g_signal_new ("client-removed", G_TYPE_FROM_CLASS (klass),
@ -210,6 +233,15 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
client_removed), NULL, NULL, gst_udp_marshal_VOID__STRING_INT, client_removed), NULL, NULL, gst_udp_marshal_VOID__STRING_INT,
G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT); G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT);
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BYTES_TO_SERVE,
g_param_spec_uint64 ("bytes-to-serve", "Bytes to serve",
"Number of bytes received to serve to clients", 0, G_MAXUINT64, 0,
G_PARAM_READABLE));
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BYTES_SERVED,
g_param_spec_uint64 ("bytes-served", "Bytes served",
"Total number of bytes send to all clients", 0, G_MAXUINT64, 0,
G_PARAM_READABLE));
gstelement_class->change_state = gst_multiudpsink_change_state; gstelement_class->change_state = gst_multiudpsink_change_state;
gstbasesink_class->render = gst_multiudpsink_render; gstbasesink_class->render = gst_multiudpsink_render;
@ -253,6 +285,10 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
size = GST_BUFFER_SIZE (buffer); size = GST_BUFFER_SIZE (buffer);
data = GST_BUFFER_DATA (buffer); data = GST_BUFFER_DATA (buffer);
sink->bytes_to_serve += size;
/* grab lock while iterating and sending to clients, this shuld be
* fast as UDP never blocks */
g_mutex_lock (sink->client_lock); g_mutex_lock (sink->client_lock);
GST_LOG_OBJECT (bsink, "about to send %d bytes", size); GST_LOG_OBJECT (bsink, "about to send %d bytes", size);
@ -260,7 +296,7 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
GstUDPClient *client; GstUDPClient *client;
client = (GstUDPClient *) clients->data; client = (GstUDPClient *) clients->data;
++num; num++;
GST_LOG_OBJECT (sink, "sending %d bytes to client %p", size, client); GST_LOG_OBJECT (sink, "sending %d bytes to client %p", size, client);
while (TRUE) { while (TRUE) {
@ -274,6 +310,7 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
} else { } else {
client->bytes_sent += ret; client->bytes_sent += ret;
client->packets_sent++; client->packets_sent++;
sink->bytes_served += ret;
break; break;
} }
} }
@ -284,10 +321,14 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
return GST_FLOW_OK; return GST_FLOW_OK;
/* ERRORS */
send_error: send_error:
{ {
/* if sendto returns an error, something is seriously wrong */
g_mutex_unlock (sink->client_lock); g_mutex_unlock (sink->client_lock);
GST_DEBUG ("got send error %s (%d)", g_strerror (errno), errno); GST_DEBUG_OBJECT (sink, "got send error %d: %s", errno, g_strerror (errno));
GST_ELEMENT_ERROR (sink, STREAM, FAILED, (NULL),
("Got send error %d: %s", errno, g_strerror (errno)));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
} }
@ -316,6 +357,13 @@ gst_multiudpsink_get_property (GObject * object, guint prop_id, GValue * value,
udpsink = GST_MULTIUDPSINK (object); udpsink = GST_MULTIUDPSINK (object);
switch (prop_id) { switch (prop_id) {
case PROP_BYTES_TO_SERVE:
g_value_set_uint64 (value, udpsink->bytes_to_serve);
break;
case PROP_BYTES_SERVED:
g_value_set_uint64 (value, udpsink->bytes_served);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -340,17 +388,23 @@ gst_multiudpsink_init_send (GstMultiUDPSink * sink)
sizeof (bc_val))) < 0) sizeof (bc_val))) < 0)
goto no_broadcast; goto no_broadcast;
sink->bytes_to_serve = 0;
sink->bytes_served = 0;
return TRUE; return TRUE;
/* ERRORS */ /* ERRORS */
no_socket: no_socket:
{ {
perror ("socket"); GST_ELEMENT_ERROR (sink, RESOURCE, FAILED, (NULL),
("Could not create socket (%d): %s", errno, g_strerror (errno)));
return FALSE; return FALSE;
} }
no_broadcast: no_broadcast:
{ {
perror ("setsockopt"); GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL),
("Could not set broadcast socket option (%d): %s", errno,
g_strerror (errno)));
return FALSE; return FALSE;
} }
} }
@ -417,12 +471,15 @@ gst_multiudpsink_add (GstMultiUDPSink * sink, const gchar * host, gint port)
sink->clients = g_list_prepend (sink->clients, client); sink->clients = g_list_prepend (sink->clients, client);
g_mutex_unlock (sink->client_lock); g_mutex_unlock (sink->client_lock);
g_signal_emit (G_OBJECT (sink),
gst_multiudpsink_signals[SIGNAL_CLIENT_ADDED], 0, host, port);
return; return;
/* ERRORS */ /* ERRORS */
host_error: host_error:
{ {
GST_DEBUG ("hostname lookup error?"); GST_WARNING_OBJECT (sink, "hostname lookup error?");
g_free (client->host); g_free (client->host);
g_free (client); g_free (client);
return; return;
@ -450,6 +507,8 @@ gst_multiudpsink_remove (GstMultiUDPSink * sink, const gchar * host, gint port)
{ {
GList *find; GList *find;
GstUDPClient udpclient; GstUDPClient udpclient;
GstUDPClient *client;
GTimeVal now;
udpclient.host = (gchar *) host; udpclient.host = (gchar *) host;
udpclient.port = port; udpclient.port = port;
@ -457,9 +516,10 @@ gst_multiudpsink_remove (GstMultiUDPSink * sink, const gchar * host, gint port)
g_mutex_lock (sink->client_lock); g_mutex_lock (sink->client_lock);
find = g_list_find_custom (sink->clients, &udpclient, find = g_list_find_custom (sink->clients, &udpclient,
(GCompareFunc) client_compare); (GCompareFunc) client_compare);
if (find) { if (!find)
GstUDPClient *client; goto not_found;
GTimeVal now;
GST_DEBUG_OBJECT (sink, "remove client with host %s, port %d", host, port);
client = (GstUDPClient *) find->data; client = (GstUDPClient *) find->data;
@ -475,16 +535,26 @@ gst_multiudpsink_remove (GstMultiUDPSink * sink, const gchar * host, gint port)
sink->clients = g_list_delete_link (sink->clients, find); sink->clients = g_list_delete_link (sink->clients, find);
free_client (client); free_client (client);
}
g_mutex_unlock (sink->client_lock); g_mutex_unlock (sink->client_lock);
return;
/* ERRORS */
not_found:
{
g_mutex_unlock (sink->client_lock);
GST_WARNING_OBJECT (sink, "client at host %s, port %d not found",
host, port);
return;
}
} }
/* FIXME: what's the point of this signal/method ? It frees client structure
* data without removing them from the sink */
void void
gst_multiudpsink_clear (GstMultiUDPSink * sink) gst_multiudpsink_clear (GstMultiUDPSink * sink)
{ {
GST_DEBUG_OBJECT (sink, "clearing"); 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); g_mutex_lock (sink->client_lock);
g_list_foreach (sink->clients, (GFunc) free_client, sink); g_list_foreach (sink->clients, (GFunc) free_client, sink);
g_list_free (sink->clients); g_list_free (sink->clients);
@ -500,6 +570,7 @@ gst_multiudpsink_get_stats (GstMultiUDPSink * sink, const gchar * host,
GValueArray *result = NULL; GValueArray *result = NULL;
GstUDPClient udpclient; GstUDPClient udpclient;
GList *find; GList *find;
GValue value = { 0 };
udpclient.host = (gchar *) host; udpclient.host = (gchar *) host;
udpclient.port = port; udpclient.port = port;
@ -508,8 +579,10 @@ gst_multiudpsink_get_stats (GstMultiUDPSink * sink, const gchar * host,
find = g_list_find_custom (sink->clients, &udpclient, find = g_list_find_custom (sink->clients, &udpclient,
(GCompareFunc) client_compare); (GCompareFunc) client_compare);
if (find) { if (!find)
GValue value = { 0 }; goto not_found;
GST_DEBUG_OBJECT (sink, "stats for client with host %s, port %d", host, port);
client = (GstUDPClient *) find->data; client = (GstUDPClient *) find->data;
@ -536,16 +609,21 @@ gst_multiudpsink_get_stats (GstMultiUDPSink * sink, const gchar * host,
g_value_set_uint64 (&value, client->disconnect_time); g_value_set_uint64 (&value, client->disconnect_time);
result = g_value_array_append (result, &value); result = g_value_array_append (result, &value);
g_value_unset (&value); g_value_unset (&value);
}
g_mutex_unlock (sink->client_lock); g_mutex_unlock (sink->client_lock);
return result;
/* ERRORS */
not_found:
{
g_mutex_unlock (sink->client_lock);
GST_WARNING_OBJECT (sink, "client with host %s, port %d not found",
host, port);
/* Apparently (see comment in gstmultifdsink.c) returning NULL from here may /* Apparently (see comment in gstmultifdsink.c) returning NULL from here may
* confuse/break python bindings */ * confuse/break python bindings */
if (result == NULL) return g_value_array_new (0);
result = g_value_array_new (0); }
return result;
} }
static GstStateChangeReturn static GstStateChangeReturn
@ -579,6 +657,7 @@ gst_multiudpsink_change_state (GstElement * element, GstStateChange transition)
/* ERRORS */ /* ERRORS */
no_init: no_init:
{ {
/* _init_send() posted specific error already */
return GST_STATE_CHANGE_FAILURE; return GST_STATE_CHANGE_FAILURE;
} }
} }

View file

@ -74,6 +74,9 @@ struct _GstMultiUDPSink {
GMutex *client_lock; GMutex *client_lock;
GList *clients; GList *clients;
guint64 bytes_to_serve;
guint64 bytes_served;
}; };
struct _GstMultiUDPSinkClass { struct _GstMultiUDPSinkClass {