mem = GST_BUFFER_MEM_PTR (buffer, idx);
- if (G_UNLIKELY (write && !GST_MEMORY_IS_WRITABLE (mem))) {
+ if (G_UNLIKELY (write && !gst_memory_is_writable (mem))) {
GstMemory *copy;
GST_CAT_LOG (GST_CAT_BUFFER,
"making writable copy of memory %p in buffer %p", mem, buffer);
if (offset != 0 || left != bsize) {
/* we need to clip something */
- if (GST_MEMORY_IS_WRITABLE (mem)) {
+ if (gst_memory_is_writable (mem)) {
gst_memory_resize (mem, offset, left);
} else {
GstMemory *tmp;
}
}
- if (G_UNLIKELY (write && !GST_MEMORY_IS_WRITABLE (mem))) {
+ if (G_UNLIKELY (write && !gst_memory_is_writable (mem))) {
GstMemory *copy;
/* replace with a writable copy */
copy = gst_memory_copy (mem, 0, -1);
gst_memory_resize (GstMemory * mem, gssize offset, gsize size)
{
g_return_if_fail (mem != NULL);
- g_return_if_fail (GST_MEMORY_IS_WRITABLE (mem));
+ g_return_if_fail (gst_memory_is_writable (mem));
mem->allocator->info.resize (mem, offset, size);
}
+/**
+ * gst_memory_is_writable:
+ * @mem: a #GstMemory
+ *
+ * Check if @mem is writable.
+ *
+ * Returns: %TRUE is @mem is writable.
+ */
+gboolean
+gst_memory_is_writable (GstMemory * mem)
+{
+ g_return_val_if_fail (mem != NULL, FALSE);
+
+ return (mem->refcount == 1) &&
+ ((mem->parent == NULL) || (mem->parent->refcount == 1)) &&
+ ((mem->flags & GST_MEMORY_FLAG_READONLY) == 0);
+}
+
/**
* gst_memory_map:
* @mem: a #GstMemory
g_return_val_if_fail (mem != NULL, NULL);
access_mode = flags & 3;
g_return_val_if_fail (!(access_mode & GST_MAP_WRITE)
- || GST_MEMORY_IS_WRITABLE (mem), NULL);
+ || gst_memory_is_writable (mem), NULL);
do {
state = g_atomic_int_get (&mem->state);
GST_MEMORY_FLAG_LAST = (1 << 16)
} GstMemoryFlags;
-/**
- * GST_MEMORY_IS_WRITABLE:
- * @mem: a #GstMemory
- *
- * Check if @mem is writable.
- */
-#define GST_MEMORY_IS_WRITABLE(mem) (((mem)->refcount == 1) && \
- (((mem)->parent == NULL) || ((mem)->parent->refcount == 1)) && \
- (((mem)->flags & GST_MEMORY_FLAG_READONLY) == 0))
-
/**
* GstMemory:
* @allocator: pointer to the #GstAllocator
gsize maxsize, gsize offset, gsize size);
/* refcounting */
-GstMemory * gst_memory_ref (GstMemory *mem);
-void gst_memory_unref (GstMemory *mem);
+GstMemory * gst_memory_ref (GstMemory *mem);
+void gst_memory_unref (GstMemory *mem);
/* getting/setting memory properties */
-gsize gst_memory_get_sizes (GstMemory *mem, gsize *offset, gsize *maxsize);
-void gst_memory_resize (GstMemory *mem, gssize offset, gsize size);
+gsize gst_memory_get_sizes (GstMemory *mem, gsize *offset, gsize *maxsize);
+void gst_memory_resize (GstMemory *mem, gssize offset, gsize size);
/* retrieving data */
-gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize,
- GstMapFlags flags);
-gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gssize size);
+gboolean gst_memory_is_writable (GstMemory *mem);
+
+gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize,
+ GstMapFlags flags);
+gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gssize size);
/* copy and subregions */
-GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gssize size);
-GstMemory * gst_memory_share (GstMemory *mem, gssize offset, gssize size);
+GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gssize size);
+GstMemory * gst_memory_share (GstMemory *mem, gssize offset, gssize size);
/* span memory */
-gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset);
+gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset);
G_END_DECLS
/* assign some read-only data to the new memory */
mem = gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) ro_memory, NULL, sizeof (ro_memory), 0, sizeof (ro_memory));
- fail_if (GST_MEMORY_IS_WRITABLE (mem));
+ fail_if (gst_memory_is_writable (mem));
return mem;
}
mem = create_read_only_memory ();
ASSERT_CRITICAL (gst_memory_map (mem, &size, NULL, GST_MAP_WRITE));
- fail_if (GST_MEMORY_IS_WRITABLE (mem));
+ fail_if (gst_memory_is_writable (mem));
mem2 = gst_memory_copy (mem, 0, -1);
- fail_if (GST_MEMORY_IS_WRITABLE (mem));
- fail_unless (GST_MEMORY_IS_WRITABLE (mem2));
+ fail_if (gst_memory_is_writable (mem));
+ fail_unless (gst_memory_is_writable (mem2));
data = gst_memory_map (mem2, &size, NULL, GST_MAP_WRITE);
data[4] = 'a';
mem = create_read_only_memory ();
sub_mem = gst_memory_share (mem, 0, 8);
- fail_if (GST_MEMORY_IS_WRITABLE (sub_mem));
+ fail_if (gst_memory_is_writable (sub_mem));
ASSERT_CRITICAL (gst_memory_map (mem, &size, NULL, GST_MAP_WRITE));
ASSERT_CRITICAL (gst_memory_map (sub_mem, &size, NULL, GST_MAP_WRITE));