From: Hyunjun Ko Date: Wed, 8 Jul 2015 15:21:42 +0000 (+0900) Subject: adapter: fix to get valid (buffer_)list X-Git-Tag: 1.6.1~123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af62e2874fb2d84b91a6f5510a4ca5a8a0e72139;p=platform%2Fupstream%2Fgstreamer.git 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 --- diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c index e06bc41..0e4f213 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; }