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
This commit is contained in:
Wim Taymans 2002-07-25 18:47:48 +00:00
parent 12fddba0bd
commit c2a0080f90
3 changed files with 16 additions and 9 deletions

View 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,

View 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;
}

View 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 */