Commit 2e5df10e authored by Tim-Philipp Müller's avatar Tim-Philipp Müller
Browse files

dynudpsink: keep GCancellable fd around instead of re-creating it constantly

And create it only when starting the element.
parent b33d3062
...@@ -162,7 +162,6 @@ gst_dynudpsink_init (GstDynUDPSink * sink) ...@@ -162,7 +162,6 @@ gst_dynudpsink_init (GstDynUDPSink * sink)
sink->used_socket = NULL; sink->used_socket = NULL;
sink->used_socket_v6 = NULL; sink->used_socket_v6 = NULL;
sink->cancellable = g_cancellable_new ();
} }
static void static void
...@@ -172,10 +171,6 @@ gst_dynudpsink_finalize (GObject * object) ...@@ -172,10 +171,6 @@ gst_dynudpsink_finalize (GObject * object)
sink = GST_DYNUDPSINK (object); sink = GST_DYNUDPSINK (object);
if (sink->cancellable)
g_object_unref (sink->cancellable);
sink->cancellable = NULL;
if (sink->socket) if (sink->socket)
g_object_unref (sink->socket); g_object_unref (sink->socket);
sink->socket = NULL; sink->socket = NULL;
...@@ -372,6 +367,26 @@ gst_dynudpsink_get_property (GObject * object, guint prop_id, GValue * value, ...@@ -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 */ /* create a socket for sending to remote machine */
static gboolean static gboolean
gst_dynudpsink_start (GstBaseSink * bsink) gst_dynudpsink_start (GstBaseSink * bsink)
...@@ -381,6 +396,8 @@ gst_dynudpsink_start (GstBaseSink * bsink) ...@@ -381,6 +396,8 @@ gst_dynudpsink_start (GstBaseSink * bsink)
udpsink = GST_DYNUDPSINK (bsink); udpsink = GST_DYNUDPSINK (bsink);
gst_dynudpsink_create_cancellable (udpsink);
udpsink->external_socket = FALSE; udpsink->external_socket = FALSE;
if (udpsink->socket) { if (udpsink->socket) {
...@@ -552,6 +569,8 @@ gst_dynudpsink_stop (GstBaseSink * bsink) ...@@ -552,6 +569,8 @@ gst_dynudpsink_stop (GstBaseSink * bsink)
udpsink->used_socket_v6 = NULL; udpsink->used_socket_v6 = NULL;
} }
gst_dynudpsink_free_cancellable (udpsink);
return TRUE; return TRUE;
} }
...@@ -574,8 +593,8 @@ gst_dynudpsink_unlock_stop (GstBaseSink * bsink) ...@@ -574,8 +593,8 @@ gst_dynudpsink_unlock_stop (GstBaseSink * bsink)
udpsink = GST_DYNUDPSINK (bsink); udpsink = GST_DYNUDPSINK (bsink);
g_object_unref (udpsink->cancellable); gst_dynudpsink_free_cancellable (udpsink);
udpsink->cancellable = g_cancellable_new (); gst_dynudpsink_create_cancellable (udpsink);
return TRUE; return TRUE;
} }
...@@ -52,6 +52,7 @@ struct _GstDynUDPSink { ...@@ -52,6 +52,7 @@ struct _GstDynUDPSink {
/* the socket in use */ /* the socket in use */
GSocket *used_socket, *used_socket_v6; GSocket *used_socket, *used_socket_v6;
gboolean external_socket; gboolean external_socket;
gboolean made_cancel_fd;
GCancellable *cancellable; GCancellable *cancellable;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment