diff options
-rw-r--r-- | gst/gstbuffer.c | 6 | ||||
-rw-r--r-- | gst/gstmemory.c | 22 | ||||
-rw-r--r-- | gst/gstmemory.h | 32 | ||||
-rw-r--r-- | tests/check/gst/gstmemory.c | 10 |
4 files changed, 40 insertions, 30 deletions
diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index 4e8ece612..f333cd66c 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -652,7 +652,7 @@ _get_memory (GstBuffer * buffer, guint idx, gboolean write) 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); @@ -868,7 +868,7 @@ gst_buffer_resize (GstBuffer * buffer, gssize offset, gssize size) 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; @@ -968,7 +968,7 @@ gst_buffer_map (GstBuffer * buffer, gsize * size, gsize * maxsize, } } - 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); diff --git a/gst/gstmemory.c b/gst/gstmemory.c index a8a8995d3..281a54d66 100644 --- a/gst/gstmemory.c +++ b/gst/gstmemory.c @@ -460,12 +460,30 @@ void 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 * @size: (out) (allow-none): pointer for size @@ -489,7 +507,7 @@ gst_memory_map (GstMemory * mem, gsize * size, gsize * maxsize, 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); diff --git a/gst/gstmemory.h b/gst/gstmemory.h index 0268da1a2..f0756aeac 100644 --- a/gst/gstmemory.h +++ b/gst/gstmemory.h @@ -56,16 +56,6 @@ typedef enum { } 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 * @flags: memory flags @@ -289,24 +279,26 @@ GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, GFr 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 diff --git a/tests/check/gst/gstmemory.c b/tests/check/gst/gstmemory.c index f3c896267..02115c751 100644 --- a/tests/check/gst/gstmemory.c +++ b/tests/check/gst/gstmemory.c @@ -134,7 +134,7 @@ create_read_only_memory (void) /* 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; } @@ -149,11 +149,11 @@ GST_START_TEST (test_writable) 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'; @@ -183,7 +183,7 @@ GST_START_TEST (test_submemory_writable) 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)); |