mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-19 08:11:16 +00:00
adapter: minor optimisation for gst_adapter_take_buffer_list()
Try to allocate buffer list with a suitable size from the beginning to avoid having to re-alloc the buffer list array.
This commit is contained in:
parent
b1b718c6d0
commit
2b4d066355
1 changed files with 13 additions and 1 deletions
|
@ -132,6 +132,7 @@ struct _GstAdapter
|
|||
GSList *buflist_end;
|
||||
gsize size;
|
||||
gsize skip;
|
||||
guint count;
|
||||
|
||||
/* we keep state of assembled pieces */
|
||||
gpointer assembled_data;
|
||||
|
@ -233,6 +234,7 @@ gst_adapter_clear (GstAdapter * adapter)
|
|||
g_slist_free (adapter->buflist);
|
||||
adapter->buflist = NULL;
|
||||
adapter->buflist_end = NULL;
|
||||
adapter->count = 0;
|
||||
adapter->size = 0;
|
||||
adapter->skip = 0;
|
||||
adapter->assembled_len = 0;
|
||||
|
@ -346,6 +348,7 @@ gst_adapter_push (GstAdapter * adapter, GstBuffer * buf)
|
|||
adapter->buflist_end = g_slist_append (adapter->buflist_end, buf);
|
||||
adapter->buflist_end = g_slist_next (adapter->buflist_end);
|
||||
}
|
||||
++adapter->count;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -607,6 +610,7 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush)
|
|||
|
||||
gst_buffer_unref (cur);
|
||||
g = g_slist_delete_link (g, g);
|
||||
--adapter->count;
|
||||
|
||||
if (G_UNLIKELY (g == NULL)) {
|
||||
GST_LOG_OBJECT (adapter, "adapter empty now");
|
||||
|
@ -972,6 +976,7 @@ gst_adapter_take_buffer_list (GstAdapter * adapter, gsize nbytes)
|
|||
GstBufferList *buffer_list;
|
||||
GstBuffer *cur;
|
||||
gsize hsize, skip, cur_size;
|
||||
guint n_bufs;
|
||||
|
||||
g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
|
||||
|
||||
|
@ -980,7 +985,14 @@ gst_adapter_take_buffer_list (GstAdapter * adapter, gsize nbytes)
|
|||
|
||||
GST_LOG_OBJECT (adapter, "taking %" G_GSIZE_FORMAT " bytes", nbytes);
|
||||
|
||||
buffer_list = gst_buffer_list_new ();
|
||||
/* try to create buffer list with sufficient size, so no resize is done later */
|
||||
if (adapter->count < 64)
|
||||
n_bufs = adapter->count;
|
||||
else
|
||||
n_bufs = (adapter->count * nbytes * 1.2 / adapter->size) + 1;
|
||||
|
||||
buffer_list = gst_buffer_list_new_sized (n_bufs);
|
||||
|
||||
while (nbytes > 0) {
|
||||
cur = adapter->buflist->data;
|
||||
skip = adapter->skip;
|
||||
|
|
Loading…
Reference in a new issue