#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,
* 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)
* #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;
}
/* 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 */