udpsink, multiudpsink: keep GCancellable fd around instead of re-creating it constantly

Otherwise we constantly create/close event file descriptors,
every time we call g_socket_condition_timed_wait() or
g_socket_send_message(s)(), i.e. a lot. Which is not
particularly good for performance.

Can't create GCancellable in ::start() here because it's used
in client_new() which may be called via the add-client action
signal which may be called before the element is up and running.
This commit is contained in:
Tim-Philipp Müller 2015-05-27 15:55:56 +01:00
parent 11bb21f3c2
commit b33d30621c
2 changed files with 26 additions and 6 deletions

View file

@ -373,6 +373,26 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
GST_DEBUG_CATEGORY_INIT (multiudpsink_debug, "multiudpsink", 0, "UDP sink");
}
static void
gst_multiudpsink_create_cancellable (GstMultiUDPSink * sink)
{
GPollFD pollfd;
sink->cancellable = g_cancellable_new ();
sink->made_cancel_fd = g_cancellable_make_pollfd (sink->cancellable, &pollfd);
}
static void
gst_multiudpsink_free_cancellable (GstMultiUDPSink * sink)
{
if (sink->made_cancel_fd) {
g_cancellable_release_fd (sink->cancellable);
sink->made_cancel_fd = FALSE;
}
g_object_unref (sink->cancellable);
sink->cancellable = NULL;
}
static void
gst_multiudpsink_init (GstMultiUDPSink * sink)
{
@ -400,7 +420,7 @@ gst_multiudpsink_init (GstMultiUDPSink * sink)
sink->send_duplicates = DEFAULT_SEND_DUPLICATES;
sink->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
sink->cancellable = g_cancellable_new ();
gst_multiudpsink_create_cancellable (sink);
/* pre-allocate OutputVector, MapInfo and OutputMessage arrays
* for use in the render and render_list functions */
@ -522,9 +542,7 @@ gst_multiudpsink_finalize (GObject * object)
g_object_unref (sink->used_socket_v6);
sink->used_socket_v6 = NULL;
if (sink->cancellable)
g_object_unref (sink->cancellable);
sink->cancellable = NULL;
gst_multiudpsink_free_cancellable (sink);
g_free (sink->multi_iface);
sink->multi_iface = NULL;
@ -1845,8 +1863,8 @@ gst_multiudpsink_unlock_stop (GstBaseSink * bsink)
sink = GST_MULTIUDPSINK (bsink);
g_object_unref (sink->cancellable);
sink->cancellable = g_cancellable_new ();
gst_multiudpsink_free_cancellable (sink);
gst_multiudpsink_create_cancellable (sink);
return TRUE;
}

View file

@ -81,7 +81,9 @@ struct _GstMultiUDPSink {
GstBaseSink parent;
GSocket *used_socket, *used_socket_v6;
GCancellable *cancellable;
gboolean made_cancel_fd;
/* client management */
GMutex client_lock;