From b4bbe19e9943c3f27d3a3dabcc7eadd1bb416459 Mon Sep 17 00:00:00 2001
From: Arnaud Vrac <avrac@freebox.fr>
Date: Fri, 17 Aug 2012 19:16:48 +0200
Subject: adapter: always clear buffer flags, metas and timestamps

gst_adapter_take_buffer sometimes returns a reference on the input
buffer, sometimes copies a buffer region and sometimes creates a new
buffer with merged memory.

Make behaviour consistent by always returning a buffer with no
timestamps or metas, and flags cleared.

diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c
index 5a15e68..7cdcd08 100644
--- a/libs/gst/base/gstadapter.c
+++ b/libs/gst/base/gstadapter.c
@@ -755,16 +755,12 @@ gst_adapter_take_buffer (GstAdapter * adapter, gsize nbytes)
   skip = adapter->skip;
   hsize = gst_buffer_get_size (cur);
 
-  /* our head buffer has enough data left, return it */
-  if (skip == 0 && hsize == nbytes) {
-    GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
-        " as head buffer", nbytes);
-    buffer = gst_buffer_ref (cur);
-    goto done;
-  } else if (hsize >= nbytes + skip) {
+  /* our head buffer has enough data left, return a copy with
+   * timestamps, metas and flags removed. */
+  if (hsize >= nbytes + skip) {
     GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
         " via region copy", nbytes);
-    buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, nbytes);
+    buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_MEMORY, skip, nbytes);
     goto done;
   }
 #if 0
@@ -775,7 +771,8 @@ gst_adapter_take_buffer (GstAdapter * adapter, gsize nbytes)
     if (gst_buffer_get_size (cur) >= nbytes + skip) {
       GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
           " via sub-buffer", nbytes);
-      buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, nbytes);
+      buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_MEMORY,
+          skip, nbytes);
       goto done;
     }
   }
-- 
1.7.10.4

