libs/gst/base/gstadapter.c: Make take_buffer a bit quicker by removing redundant...
authorJan Schmidt <thaytan@mad.scientist.com>
Thu, 29 Mar 2007 15:53:03 +0000 (15:53 +0000)
committerJan Schmidt <thaytan@mad.scientist.com>
Thu, 29 Mar 2007 15:53:03 +0000 (15:53 +0000)
Original commit message from CVS:
* libs/gst/base/gstadapter.c: (gst_adapter_take_buffer):
Make take_buffer a bit quicker by removing redundant checks
caused by calling gst_adapter_take.

ChangeLog
libs/gst/base/gstadapter.c

index 72373af..1b9747b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-03-29  Jan Schmidt  <thaytan@mad.scientist.com>
+
+       * libs/gst/base/gstadapter.c: (gst_adapter_take_buffer):
+       Make take_buffer a bit quicker by removing redundant checks
+       caused by calling gst_adapter_take.
+
 2007-03-28  Tim-Philipp Müller  <tim at centricular dot net>
 
        * plugins/elements/gstmultiqueue.c: (gst_single_queue_free):
index 1bd0e52..cf4597c 100644 (file)
@@ -458,7 +458,6 @@ gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes)
 {
   GstBuffer *buffer;
   GstBuffer *cur;
-  guint8 *data;
 
   g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
   g_return_val_if_fail (nbytes > 0, NULL);
@@ -483,14 +482,18 @@ gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes)
     return buffer;
   }
 
-  data = gst_adapter_take (adapter, nbytes);
-  if (data == NULL)
-    return NULL;
+  buffer = gst_buffer_new_and_alloc (nbytes);
+
+  /* we have enough assembled data, copy from there */
+  if (adapter->assembled_len >= nbytes) {
+    GST_LOG_OBJECT (adapter, "taking %u bytes already assembled", nbytes);
+    memcpy (GST_BUFFER_DATA (buffer), adapter->assembled_data, nbytes);
+  } else {
+    GST_LOG_OBJECT (adapter, "taking %u bytes by collection", nbytes);
+    gst_adapter_peek_into (adapter, GST_BUFFER_DATA (buffer), nbytes);
+  }
 
-  buffer = gst_buffer_new ();
-  GST_BUFFER_DATA (buffer) = data;
-  GST_BUFFER_MALLOCDATA (buffer) = data;
-  GST_BUFFER_SIZE (buffer) = nbytes;
+  gst_adapter_flush (adapter, nbytes);
 
   return buffer;
 }