mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-20 04:56:24 +00:00
udpsink: avoid alloc and free in render function
Avoid doing alloc and free in the render function for each buffer. Instead, allocate the needed arrays in _init and use those.
This commit is contained in:
parent
48b9919e31
commit
f96aa414e1
2 changed files with 20 additions and 5 deletions
|
@ -356,6 +356,8 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
|
||||||
static void
|
static void
|
||||||
gst_multiudpsink_init (GstMultiUDPSink * sink)
|
gst_multiudpsink_init (GstMultiUDPSink * sink)
|
||||||
{
|
{
|
||||||
|
guint max_mem;
|
||||||
|
|
||||||
g_mutex_init (&sink->client_lock);
|
g_mutex_init (&sink->client_lock);
|
||||||
sink->socket = DEFAULT_SOCKET;
|
sink->socket = DEFAULT_SOCKET;
|
||||||
sink->used_socket = DEFAULT_USED_SOCKET;
|
sink->used_socket = DEFAULT_USED_SOCKET;
|
||||||
|
@ -371,6 +373,14 @@ gst_multiudpsink_init (GstMultiUDPSink * sink)
|
||||||
sink->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
|
sink->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
|
||||||
|
|
||||||
sink->cancellable = g_cancellable_new ();
|
sink->cancellable = g_cancellable_new ();
|
||||||
|
|
||||||
|
/* allocate OutputVector and MapInfo for use in the render function, buffers can
|
||||||
|
* hold up to a maximum amount of memory so we can create a maximally sized
|
||||||
|
* array for them. */
|
||||||
|
max_mem = gst_buffer_get_max_memory ();
|
||||||
|
|
||||||
|
sink->vec = g_new (GOutputVector, max_mem);
|
||||||
|
sink->map = g_new (GstMapInfo, max_mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstUDPClient *
|
static GstUDPClient *
|
||||||
|
@ -463,6 +473,9 @@ gst_multiudpsink_finalize (GObject * object)
|
||||||
g_free (sink->multi_iface);
|
g_free (sink->multi_iface);
|
||||||
sink->multi_iface = NULL;
|
sink->multi_iface = NULL;
|
||||||
|
|
||||||
|
g_free (sink->vec);
|
||||||
|
g_free (sink->map);
|
||||||
|
|
||||||
g_mutex_clear (&sink->client_lock);
|
g_mutex_clear (&sink->client_lock);
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
|
@ -487,8 +500,10 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
||||||
if (n_mem == 0)
|
if (n_mem == 0)
|
||||||
goto no_data;
|
goto no_data;
|
||||||
|
|
||||||
vec = g_new (GOutputVector, n_mem);
|
/* allocated on the stack, the max number of memory blocks is limited so this
|
||||||
map = g_new (GstMapInfo, n_mem);
|
* should not cause stack overflows */
|
||||||
|
vec = sink->vec;
|
||||||
|
map = sink->map;
|
||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
for (i = 0; i < n_mem; i++) {
|
for (i = 0; i < n_mem; i++) {
|
||||||
|
@ -562,9 +577,6 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
||||||
gst_memory_unref (map[i].memory);
|
gst_memory_unref (map[i].memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (vec);
|
|
||||||
g_free (map);
|
|
||||||
|
|
||||||
GST_LOG_OBJECT (sink, "sent %" G_GSIZE_FORMAT " bytes to %d (of %d) clients",
|
GST_LOG_OBJECT (sink, "sent %" G_GSIZE_FORMAT " bytes to %d (of %d) clients",
|
||||||
size, num, no_clients);
|
size, num, no_clients);
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,9 @@ struct _GstMultiUDPSink {
|
||||||
GMutex client_lock;
|
GMutex client_lock;
|
||||||
GList *clients;
|
GList *clients;
|
||||||
|
|
||||||
|
GOutputVector *vec;
|
||||||
|
GstMapInfo *map;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
guint64 bytes_to_serve;
|
guint64 bytes_to_serve;
|
||||||
guint64 bytes_served;
|
guint64 bytes_served;
|
||||||
|
|
Loading…
Reference in a new issue