diff --git a/ChangeLog b/ChangeLog index 72373af51c..1b9747b9d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-03-29 Jan Schmidt + + * 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 * plugins/elements/gstmultiqueue.c: (gst_single_queue_free): diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c index 1bd0e526b9..cf4597c535 100644 --- a/libs/gst/base/gstadapter.c +++ b/libs/gst/base/gstadapter.c @@ -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); - buffer = gst_buffer_new (); - GST_BUFFER_DATA (buffer) = data; - GST_BUFFER_MALLOCDATA (buffer) = data; - GST_BUFFER_SIZE (buffer) = 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); + } + + gst_adapter_flush (adapter, nbytes); return buffer; }