mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 05:06:17 +00:00
udpsrc: keep GCancellable fd around instead of re-creating it constantly
Otherwise we constantly create/close event file descriptors, every single time we call g_socket_condition_timed_wait() or g_socket_receive_message(), i.e. twice per packet received! This was not particularly good for performance. Also only create GCancellable on start-up.
This commit is contained in:
parent
6d06a74f7f
commit
11bb21f3c2
2 changed files with 30 additions and 9 deletions
|
@ -323,8 +323,6 @@ gst_udpsrc_init (GstUDPSrc * udpsrc)
|
||||||
udpsrc->used_socket = UDP_DEFAULT_USED_SOCKET;
|
udpsrc->used_socket = UDP_DEFAULT_USED_SOCKET;
|
||||||
udpsrc->reuse = UDP_DEFAULT_REUSE;
|
udpsrc->reuse = UDP_DEFAULT_REUSE;
|
||||||
|
|
||||||
udpsrc->cancellable = g_cancellable_new ();
|
|
||||||
|
|
||||||
/* configure basesrc to be a live source */
|
/* configure basesrc to be a live source */
|
||||||
gst_base_src_set_live (GST_BASE_SRC (udpsrc), TRUE);
|
gst_base_src_set_live (GST_BASE_SRC (udpsrc), TRUE);
|
||||||
/* make basesrc output a segment in time */
|
/* make basesrc output a segment in time */
|
||||||
|
@ -362,10 +360,6 @@ gst_udpsrc_finalize (GObject * object)
|
||||||
g_object_unref (udpsrc->used_socket);
|
g_object_unref (udpsrc->used_socket);
|
||||||
udpsrc->used_socket = NULL;
|
udpsrc->used_socket = NULL;
|
||||||
|
|
||||||
if (udpsrc->cancellable)
|
|
||||||
g_object_unref (udpsrc->cancellable);
|
|
||||||
udpsrc->cancellable = NULL;
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,6 +495,26 @@ gst_udpsrc_ensure_mem (GstUDPSrc * src)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_udpsrc_create_cancellable (GstUDPSrc * src)
|
||||||
|
{
|
||||||
|
GPollFD pollfd;
|
||||||
|
|
||||||
|
src->cancellable = g_cancellable_new ();
|
||||||
|
src->made_cancel_fd = g_cancellable_make_pollfd (src->cancellable, &pollfd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_udpsrc_free_cancellable (GstUDPSrc * src)
|
||||||
|
{
|
||||||
|
if (src->made_cancel_fd) {
|
||||||
|
g_cancellable_release_fd (src->cancellable);
|
||||||
|
src->made_cancel_fd = FALSE;
|
||||||
|
}
|
||||||
|
g_object_unref (src->cancellable);
|
||||||
|
src->cancellable = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
|
gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
|
||||||
{
|
{
|
||||||
|
@ -898,6 +912,8 @@ gst_udpsrc_open (GstUDPSrc * src)
|
||||||
GSocketAddress *bind_saddr;
|
GSocketAddress *bind_saddr;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
|
|
||||||
|
gst_udpsrc_create_cancellable (src);
|
||||||
|
|
||||||
if (src->socket == NULL) {
|
if (src->socket == NULL) {
|
||||||
/* need to allocate a socket */
|
/* need to allocate a socket */
|
||||||
GST_DEBUG_OBJECT (src, "allocating socket for %s:%d", src->address,
|
GST_DEBUG_OBJECT (src, "allocating socket for %s:%d", src->address,
|
||||||
|
@ -1139,8 +1155,9 @@ gst_udpsrc_unlock_stop (GstBaseSrc * bsrc)
|
||||||
src = GST_UDPSRC (bsrc);
|
src = GST_UDPSRC (bsrc);
|
||||||
|
|
||||||
GST_LOG_OBJECT (src, "No longer flushing");
|
GST_LOG_OBJECT (src, "No longer flushing");
|
||||||
g_object_unref (src->cancellable);
|
|
||||||
src->cancellable = g_cancellable_new ();
|
gst_udpsrc_free_cancellable (src);
|
||||||
|
gst_udpsrc_create_cancellable (src);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1184,6 +1201,8 @@ gst_udpsrc_close (GstUDPSrc * src)
|
||||||
|
|
||||||
gst_udpsrc_reset_memory_allocator (src);
|
gst_udpsrc_reset_memory_allocator (src);
|
||||||
|
|
||||||
|
gst_udpsrc_free_cancellable (src);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,10 +66,12 @@ struct _GstUDPSrc {
|
||||||
|
|
||||||
/* our sockets */
|
/* our sockets */
|
||||||
GSocket *used_socket;
|
GSocket *used_socket;
|
||||||
GCancellable *cancellable;
|
|
||||||
GInetSocketAddress *addr;
|
GInetSocketAddress *addr;
|
||||||
gboolean external_socket;
|
gboolean external_socket;
|
||||||
|
|
||||||
|
gboolean made_cancel_fd;
|
||||||
|
GCancellable *cancellable;
|
||||||
|
|
||||||
/* memory management */
|
/* memory management */
|
||||||
GstAllocator *allocator;
|
GstAllocator *allocator;
|
||||||
GstAllocationParams params;
|
GstAllocationParams params;
|
||||||
|
|
Loading…
Reference in a new issue