Also handle READONLY buffers in the copy_on_write function
authorWim Taymans <wim.taymans@gmail.com>
Thu, 25 Jul 2002 18:47:48 +0000 (18:47 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Thu, 25 Jul 2002 18:47:48 +0000 (18:47 +0000)
Original commit message from CVS:
Also handle READONLY buffers in the copy_on_write function

gst/gstbuffer.h
gst/gstdata.c
gst/gstdata.h

index 21459b5..debf665 100644 (file)
@@ -61,8 +61,8 @@ extern GType _gst_buffer_pool_type;
 #define GST_BUFFER_POOL_PRIVATE(buf)           (GST_BUFFER(buf)->pool_private)
 
 typedef enum {
-  GST_BUFFER_READONLY   = GST_DATA_FLAG_LAST,
-  GST_BUFFER_SUBBUFFER,
+  GST_BUFFER_READONLY   = GST_DATA_READONLY,
+  GST_BUFFER_SUBBUFFER  = GST_DATA_FLAG_LAST,
   GST_BUFFER_ORIGINAL,
   GST_BUFFER_DONTFREE,
   GST_BUFFER_DISCONTINOUS,
index ac565a5..00cd658 100644 (file)
@@ -79,7 +79,9 @@ gst_data_dispose (GstData *data)
  * Copies the given #GstData. This function will call the custom subclass
  * copy function or return NULL if no function was provided by the subclass.
  *
- * Returns: a copy of the data or NULL if the data cannot be copied.
+ * Returns: a copy of the data or NULL if the data cannot be copied. The refcount
+ * of the original buffer is not changed so you should unref it when you don't
+ * need it anymore.
  */
 GstData*
 gst_data_copy (const GstData *data) 
@@ -98,20 +100,25 @@ gst_data_copy (const GstData *data)
  * #GstData object can be written to safely.
  *
  * Returns: a copy of the data if the refcount is > 1, data if the refcount == 1
- * or NULL if the data could not be copied.
+ * or NULL if the data could not be copied. The refcount of the original buffer
+ * is decreased when a copy is made, so you are not supposed to use it after a
+ * call to this function.
  */
 GstData*
-gst_data_copy_on_write (const GstData *data) 
+gst_data_copy_on_write (GstData *data) 
 {
   gint refcount;
 
   GST_ATOMIC_INT_READ (&data->refcount, &refcount);
 
-  if (refcount == 1)
+  if (refcount == 1 && !GST_DATA_FLAG_IS_SET (data, GST_DATA_READONLY))
     return GST_DATA (data);
        
-  if (data->copy)
-    return data->copy (data); 
+  if (data->copy) {
+    GstData *copy = data->copy (data); 
+    gst_data_unref (data);
+    return copy; 
+  }
 
   return NULL;
 }
index 903f16c..1236941 100644 (file)
@@ -87,7 +87,7 @@ void                  gst_data_copy_into              (const GstData *data, GstData *target);
 
 /* basic operations on data */
 GstData*               gst_data_copy                   (const GstData *data);
-GstData*               gst_data_copy_on_write          (const GstData *data);
+GstData*               gst_data_copy_on_write          (GstData *data);
 void                   gst_data_free                   (GstData *data);
 
 /* reference counting */