summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyunjun Ko <zzoon.ko@samsung.com>2015-07-09 00:21:42 +0900
committerSebastian Dröge <sebastian@centricular.com>2015-07-08 18:59:31 +0300
commitaf62e2874fb2d84b91a6f5510a4ca5a8a0e72139 (patch)
tree1a3585566dddb877f08a2585221ca99ca5c6ec91
parent9338f93494c96f810c3abe1b478b59066397275a (diff)
adapter: fix to get valid (buffer_)list
get_list/get_buffer_list should be done with buffers in adapter remaining while take_list/take_buffer_list flushes each buffer one by one. https://bugzilla.gnome.org/show_bug.cgi?id=752116
-rw-r--r--libs/gst/base/gstadapter.c49
1 files changed, 40 insertions, 9 deletions
diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c
index e06bc41d9..0e4f213c6 100644
--- a/libs/gst/base/gstadapter.c
+++ b/libs/gst/base/gstadapter.c
@@ -1090,26 +1090,40 @@ GList *
gst_adapter_get_list (GstAdapter * adapter, gsize nbytes)
{
GQueue queue = G_QUEUE_INIT;
- GstBuffer *cur;
+ GstBuffer *cur, *buffer;
gsize hsize, skip, cur_size;
+ GSList *g = NULL;
g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
g_return_val_if_fail (nbytes <= adapter->size, NULL);
GST_LOG_OBJECT (adapter, "getting %" G_GSIZE_FORMAT " bytes", nbytes);
+ g = adapter->buflist;
+ skip = adapter->skip;
+
while (nbytes > 0) {
- cur = adapter->buflist->data;
- skip = adapter->skip;
+ cur = g->data;
cur_size = gst_buffer_get_size (cur);
hsize = MIN (nbytes, cur_size - skip);
- cur = gst_adapter_get_buffer (adapter, hsize);
+ if (skip == 0 && cur_size == hsize) {
+ GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
+ " as head buffer", hsize);
+ buffer = gst_buffer_ref (cur);
+ } else {
+ GST_LOG_OBJECT (adapter, "appending %" G_GSIZE_FORMAT " bytes"
+ " via region copy", hsize);
+ buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, hsize);
+ }
- g_queue_push_tail (&queue, cur);
+ g_queue_push_tail (&queue, buffer);
nbytes -= hsize;
+ skip = 0;
+ g = g_slist_next (g);
}
+
return queue.head;
}
@@ -1189,9 +1203,10 @@ GstBufferList *
gst_adapter_get_buffer_list (GstAdapter * adapter, gsize nbytes)
{
GstBufferList *buffer_list;
- GstBuffer *cur;
+ GstBuffer *cur, *buffer;
gsize hsize, skip, cur_size;
guint n_bufs;
+ GSList *g = NULL;
g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
@@ -1208,15 +1223,31 @@ gst_adapter_get_buffer_list (GstAdapter * adapter, gsize nbytes)
buffer_list = gst_buffer_list_new_sized (n_bufs);
+ g = adapter->buflist;
+ skip = adapter->skip;
+
while (nbytes > 0) {
- cur = adapter->buflist->data;
- skip = adapter->skip;
+ cur = g->data;
cur_size = gst_buffer_get_size (cur);
hsize = MIN (nbytes, cur_size - skip);
- gst_buffer_list_add (buffer_list, gst_adapter_get_buffer (adapter, hsize));
+ if (skip == 0 && cur_size == hsize) {
+ GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
+ " as head buffer", hsize);
+ buffer = gst_buffer_ref (cur);
+ } else {
+ GST_LOG_OBJECT (adapter, "appending %" G_GSIZE_FORMAT " bytes"
+ " via region copy", hsize);
+ buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, hsize);
+ }
+
+ gst_buffer_list_add (buffer_list, buffer);
+
nbytes -= hsize;
+ skip = 0;
+ g = g_slist_next (g);
}
+
return buffer_list;
}