gst/gstbuffer.c: (gst_buffer_join): Add function gst_buffer_join() to eventually...
authorDavid Schleef <ds@schleef.org>
Thu, 1 Apr 2004 00:40:26 +0000 (00:40 +0000)
committerDavid Schleef <ds@schleef.org>
Thu, 1 Apr 2004 00:40:26 +0000 (00:40 +0000)
Original commit message from CVS:
* gst/gstbuffer.c: (gst_buffer_join):  Add function gst_buffer_join()
to eventually deprecate gst_buffer_merge().  (bug: #136408)
* gst/gstbuffer.h:

ChangeLog
gst/gstbuffer.c
gst/gstbuffer.h

index 7c8c3e5..8e8310c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2004-03-31  David Schleef  <ds@schleef.org>
 
+       * gst/gstbuffer.c: (gst_buffer_join):  Add function gst_buffer_join()
+       to eventually deprecate gst_buffer_merge().  (bug: #136408)
+       * gst/gstbuffer.h:
+
+2004-03-31  David Schleef  <ds@schleef.org>
+
        * gst/gstvalue.c: (gst_value_union_int_int_range),
        (gst_value_union_int_range_int_range), (gst_value_can_union),
        (gst_value_union), (_gst_value_initialize):  Add some union
index 325a9c2..474ec0d 100644 (file)
@@ -318,8 +318,11 @@ gst_buffer_create_sub (GstBuffer * parent, guint offset, guint size)
  * buffers.  The original source buffers will not be modified or
  * unref'd.
  *
- * Internally is nothing more than a specialized gst_buffer_span(),
- * so the same optimizations can occur.
+ * WARNING: Incorrect use of this function can lead to memory leaks.
+ * It is recommended to use gst_buffer_join() instead of this function.
+ *
+ * If the buffers point to contiguous areas of memory, the buffer
+ * is created without copying the data.
  *
  * Returns: the new #GstBuffer that's the concatenation of the source buffers.
  */
@@ -335,6 +338,33 @@ gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
 }
 
 /**
+ * gst_buffer_join:
+ * @buf1: a first source #GstBuffer to merge.
+ * @buf2: the second source #GstBuffer to merge.
+ *
+ * Create a new buffer that is the concatenation of the two source
+ * buffers.  The original buffers are unreferenced.
+ *
+ * If the buffers point to contiguous areas of memory, the buffer
+ * is created without copying the data.
+ *
+ * Returns: the new #GstBuffer that's the concatenation of the source buffers.
+ */
+GstBuffer *
+gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
+{
+  GstBuffer *result;
+
+  /* we're just a specific case of the more general gst_buffer_span() */
+  result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
+
+  gst_buffer_unref (buf1);
+  gst_buffer_unref (buf2);
+
+  return result;
+}
+
+/**
  * gst_buffer_is_span_fast:
  * @buf1: a first source #GstBuffer.
  * @buf2: the second source #GstBuffer.
index 8fb65b1..7731453 100644 (file)
@@ -138,6 +138,7 @@ GstBuffer*  gst_buffer_create_sub           (GstBuffer *parent, guint offset, guint size);
 
 /* merge, span, or append two buffers, intelligently */
 GstBuffer*     gst_buffer_merge                (GstBuffer *buf1, GstBuffer *buf2);
+GstBuffer*     gst_buffer_join                 (GstBuffer *buf1, GstBuffer *buf2);
 gboolean       gst_buffer_is_span_fast         (GstBuffer *buf1, GstBuffer *buf2);
 GstBuffer*     gst_buffer_span                 (GstBuffer *buf1, guint32 offset, GstBuffer *buf2, guint32 len);