dynudpsink: keep GCancellable fd around instead of re-creating it constantly
authorTim-Philipp Müller <tim@centricular.com>
Wed, 27 May 2015 15:31:23 +0000 (16:31 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Wed, 27 May 2015 16:08:47 +0000 (17:08 +0100)
And create it only when starting the element.

gst/udp/gstdynudpsink.c
gst/udp/gstdynudpsink.h

index 2a23ddc..f9cd5a2 100644 (file)
@@ -162,7 +162,6 @@ gst_dynudpsink_init (GstDynUDPSink * sink)
 
   sink->used_socket = NULL;
   sink->used_socket_v6 = NULL;
-  sink->cancellable = g_cancellable_new ();
 }
 
 static void
@@ -172,10 +171,6 @@ gst_dynudpsink_finalize (GObject * object)
 
   sink = GST_DYNUDPSINK (object);
 
-  if (sink->cancellable)
-    g_object_unref (sink->cancellable);
-  sink->cancellable = NULL;
-
   if (sink->socket)
     g_object_unref (sink->socket);
   sink->socket = NULL;
@@ -372,6 +367,26 @@ gst_dynudpsink_get_property (GObject * object, guint prop_id, GValue * value,
   }
 }
 
+static void
+gst_dynudpsink_create_cancellable (GstDynUDPSink * sink)
+{
+  GPollFD pollfd;
+
+  sink->cancellable = g_cancellable_new ();
+  sink->made_cancel_fd = g_cancellable_make_pollfd (sink->cancellable, &pollfd);
+}
+
+static void
+gst_dynudpsink_free_cancellable (GstDynUDPSink * 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;
+}
+
 /* create a socket for sending to remote machine */
 static gboolean
 gst_dynudpsink_start (GstBaseSink * bsink)
@@ -381,6 +396,8 @@ gst_dynudpsink_start (GstBaseSink * bsink)
 
   udpsink = GST_DYNUDPSINK (bsink);
 
+  gst_dynudpsink_create_cancellable (udpsink);
+
   udpsink->external_socket = FALSE;
 
   if (udpsink->socket) {
@@ -552,6 +569,8 @@ gst_dynudpsink_stop (GstBaseSink * bsink)
     udpsink->used_socket_v6 = NULL;
   }
 
+  gst_dynudpsink_free_cancellable (udpsink);
+
   return TRUE;
 }
 
@@ -574,8 +593,8 @@ gst_dynudpsink_unlock_stop (GstBaseSink * bsink)
 
   udpsink = GST_DYNUDPSINK (bsink);
 
-  g_object_unref (udpsink->cancellable);
-  udpsink->cancellable = g_cancellable_new ();
+  gst_dynudpsink_free_cancellable (udpsink);
+  gst_dynudpsink_create_cancellable (udpsink);
 
   return TRUE;
 }
index 9b82eec..6d85bb6 100644 (file)
@@ -52,6 +52,7 @@ struct _GstDynUDPSink {
   /* the socket in use */
   GSocket *used_socket, *used_socket_v6;
   gboolean external_socket;
+  gboolean made_cancel_fd;
   GCancellable *cancellable;
 };