Index: gst/gstbuffer.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstbuffer.c,v
retrieving revision 1.133
diff -u -B -b -p -r1.133 gstbuffer.c
--- gst/gstbuffer.c	21 Aug 2006 09:30:03 -0000	1.133
+++ gst/gstbuffer.c	6 Mar 2007 09:34:47 -0000
@@ -192,24 +192,53 @@ gst_buffer_finalize (GstBuffer * buffer)
   gst_caps_replace (&GST_BUFFER_CAPS (buffer), NULL);
 }
 
-static GstBuffer *
-_gst_buffer_copy (GstBuffer * buffer)
+/**
+ * gst_buffer_copy_metadata_into:
+ * @src: a source #GstBuffer
+ * @dest: a destination #GstBuffer
+ *
+ * Copies the metadata from @src into @dest. The data, size and mallocdata
+ * fields are not copied.
+ *
+ * This function is typically called from a custom buffer copy function after
+ * creating @dest and setting the data, size, mallocdata.
+ */
+void
+gst_buffer_copy_metadata_into (GstBuffer *src, GstBuffer *dest)
 {
-  GstBuffer *copy;
   guint mask;
 
-  g_return_val_if_fail (buffer != NULL, NULL);
-
-  /* create a fresh new buffer */
-  copy = gst_buffer_new ();
+  g_return_if_fail (src != NULL);
+  g_return_if_fail (dest != NULL);
 
-  GST_CAT_LOG (GST_CAT_BUFFER, "copy %p to %p", buffer, copy);
+  GST_CAT_LOG (GST_CAT_BUFFER, "copy %p to %p", src, dest);
 
   /* copy relevant flags */
   mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
       GST_BUFFER_FLAG_DELTA_UNIT | GST_BUFFER_FLAG_DISCONT |
       GST_BUFFER_FLAG_GAP;
-  GST_MINI_OBJECT_FLAGS (copy) |= GST_MINI_OBJECT_FLAGS (buffer) & mask;
+  GST_MINI_OBJECT_FLAGS (dest) |= GST_MINI_OBJECT_FLAGS (src) & mask;
+
+  GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
+  GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
+  GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
+  GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
+
+  if (GST_BUFFER_CAPS (src))
+    GST_BUFFER_CAPS (dest) = gst_caps_ref (GST_BUFFER_CAPS (src));
+  else
+    GST_BUFFER_CAPS (dest) = NULL;
+}
+
+static GstBuffer *
+_gst_buffer_copy (GstBuffer * buffer)
+{
+  GstBuffer *copy;
+
+  g_return_val_if_fail (buffer != NULL, NULL);
+
+  /* create a fresh new buffer */
+  copy = gst_buffer_new ();
 
   /* we simply copy everything from our parent */
   copy->data = g_memdup (buffer->data, buffer->size);
@@ -216,18 +245,9 @@ _gst_buffer_copy (GstBuffer * buffer)
   /* make sure it gets freed (even if the parent is subclassed, we return a
      normal buffer) */
   copy->malloc_data = copy->data;
-
   copy->size = buffer->size;
 
-  GST_BUFFER_TIMESTAMP (copy) = GST_BUFFER_TIMESTAMP (buffer);
-  GST_BUFFER_DURATION (copy) = GST_BUFFER_DURATION (buffer);
-  GST_BUFFER_OFFSET (copy) = GST_BUFFER_OFFSET (buffer);
-  GST_BUFFER_OFFSET_END (copy) = GST_BUFFER_OFFSET_END (buffer);
-
-  if (GST_BUFFER_CAPS (buffer))
-    GST_BUFFER_CAPS (copy) = gst_caps_ref (GST_BUFFER_CAPS (buffer));
-  else
-    GST_BUFFER_CAPS (copy) = NULL;
+  gst_buffer_copy_metadata_into (buffer, copy);
 
   return copy;
 }
Index: gst/gstbuffer.h
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstbuffer.h,v
retrieving revision 1.115
diff -u -B -b -p -r1.115 gstbuffer.h
--- gst/gstbuffer.h	18 Oct 2006 10:08:45 -0000	1.115
+++ gst/gstbuffer.h	6 Mar 2007 09:34:47 -0000
@@ -338,6 +338,10 @@ gst_buffer_ref (GstBuffer * buf)
  * copy of the data the source buffer contains.
  */
 #define		gst_buffer_copy(buf)		GST_BUFFER_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CAST (buf)))
+
+/* copies metadata into newly allocated buffer */
+void            gst_buffer_copy_metadata_into   (GstBuffer *src, GstBuffer *dest);
+
 /**
  * gst_buffer_is_writable:
  * @buf: a #GstBuffer
