From c2a0080f900a6bdcbfa97b201eea28ee3e46f3f4 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 25 Jul 2002 18:47:48 +0000 Subject: [PATCH] Also handle READONLY buffers in the copy_on_write function Original commit message from CVS: Also handle READONLY buffers in the copy_on_write function --- gst/gstbuffer.h | 4 ++-- gst/gstdata.c | 19 +++++++++++++------ gst/gstdata.h | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h index 21459b5e5d..debf665099 100644 --- a/gst/gstbuffer.h +++ b/gst/gstbuffer.h @@ -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, diff --git a/gst/gstdata.c b/gst/gstdata.c index ac565a5c38..00cd6586db 100644 --- a/gst/gstdata.c +++ b/gst/gstdata.c @@ -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; } diff --git a/gst/gstdata.h b/gst/gstdata.h index 903f16c20d..12369415ac 100644 --- a/gst/gstdata.h +++ b/gst/gstdata.h @@ -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 */