From: Tim-Philipp Müller Date: Wed, 27 May 2015 14:55:56 +0000 (+0100) Subject: udpsink, multiudpsink: keep GCancellable fd around instead of re-creating it constantly X-Git-Tag: 1.19.3~509^2~3602 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b33d30621c5730af771b31509f5492beda1b49b0;p=platform%2Fupstream%2Fgstreamer.git 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. --- diff --git a/gst/udp/gstmultiudpsink.c b/gst/udp/gstmultiudpsink.c index 0b2b9dd..bb84997 100644 --- a/gst/udp/gstmultiudpsink.c +++ b/gst/udp/gstmultiudpsink.c @@ -374,6 +374,26 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass) } 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) { guint max_mem; @@ -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; } diff --git a/gst/udp/gstmultiudpsink.h b/gst/udp/gstmultiudpsink.h index ba6f12c..8849f38 100644 --- a/gst/udp/gstmultiudpsink.h +++ b/gst/udp/gstmultiudpsink.h @@ -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;