docs: convert NULL, TRUE, and FALSE to %NULL, %TRUE, and %FALSE
[platform/upstream/gstreamer.git] / gst / gstmemory.c
index 8101c91..d5811f6 100644 (file)
@@ -33,7 +33,7 @@
  * in the allocated region.
  *
  * Memory is usually created by allocators with a gst_allocator_alloc()
- * method call. When NULL is used as the allocator, the default allocator will
+ * method call. When %NULL is used as the allocator, the default allocator will
  * be used.
  *
  * New allocators can be registered with gst_allocator_register().
@@ -59,9 +59,7 @@
  * memory with an existing memory block at a custom offset and with a custom
  * size.
  *
- * Memory can be efficiently merged when gst_memory_is_span() returns TRUE.
- *
- * Last reviewed on 2012-03-28 (0.11.3)
+ * Memory can be efficiently merged when gst_memory_is_span() returns %TRUE.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -83,6 +81,8 @@ _gst_memory_copy (GstMemory * mem)
 static void
 _gst_memory_free (GstMemory * mem)
 {
+  GstAllocator *allocator;
+
   GST_CAT_DEBUG (GST_CAT_MEMORY, "free memory %p", mem);
 
   if (mem->parent) {
@@ -90,7 +90,10 @@ _gst_memory_free (GstMemory * mem)
     gst_memory_unref (mem->parent);
   }
 
-  gst_allocator_free (mem->allocator, mem);
+  allocator = mem->allocator;
+
+  gst_allocator_free (allocator, mem);
+  gst_object_unref (allocator);
 }
 
 /**
@@ -117,7 +120,7 @@ gst_memory_init (GstMemory * mem, GstMemoryFlags flags,
       (GstMiniObjectCopyFunction) _gst_memory_copy, NULL,
       (GstMiniObjectFreeFunction) _gst_memory_free);
 
-  mem->allocator = allocator;
+  mem->allocator = gst_object_ref (allocator);
   if (parent) {
     gst_memory_lock (parent, GST_LOCK_FLAG_EXCLUSIVE);
     gst_memory_ref (parent);
@@ -134,6 +137,27 @@ gst_memory_init (GstMemory * mem, GstMemoryFlags flags,
 }
 
 /**
+ * gst_memory_is_type:
+ * @mem: a #GstMemory
+ * @mem_type: a memory type
+ *
+ * Check if @mem if allocated with an allocator for @mem_type.
+ *
+ * Returns: %TRUE if @mem was allocated from an allocator for @mem_type.
+ *
+ * Since: 1.2
+ */
+gboolean
+gst_memory_is_type (GstMemory * mem, const gchar * mem_type)
+{
+  g_return_val_if_fail (mem != NULL, FALSE);
+  g_return_val_if_fail (mem->allocator != NULL, FALSE);
+  g_return_val_if_fail (mem_type != NULL, FALSE);
+
+  return (g_strcmp0 (mem->allocator->mem_type, mem_type) == 0);
+}
+
+/**
  * gst_memory_get_sizes:
  * @mem: a #GstMemory
  * @offset: pointer to offset
@@ -200,7 +224,7 @@ gst_memory_resize (GstMemory * mem, gssize offset, gsize size)
  * This function takes ownership of old @mem and returns a reference to a new
  * #GstMemory.
  *
- * Returns: (transfer full): a #GstMemory object mapped with @flags or NULL when
+ * Returns: (transfer full): a #GstMemory object mapped with @flags or %NULL when
  * a mapping is not possible.
  */
 GstMemory *
@@ -264,7 +288,7 @@ gst_memory_map (GstMemory * mem, GstMapInfo * info, GstMapFlags flags)
   g_return_val_if_fail (mem != NULL, FALSE);
   g_return_val_if_fail (info != NULL, FALSE);
 
-  if (!gst_memory_lock (mem, flags))
+  if (!gst_memory_lock (mem, (GstLockFlags) flags))
     goto lock_failed;
 
   info->data = mem->allocator->mem_map (mem, mem->maxsize, flags);
@@ -284,13 +308,15 @@ gst_memory_map (GstMemory * mem, GstMapInfo * info, GstMapFlags flags)
 lock_failed:
   {
     GST_CAT_DEBUG (GST_CAT_MEMORY, "mem %p: lock %d failed", mem, flags);
+    memset (info, 0, sizeof (GstMapInfo));
     return FALSE;
   }
 error:
   {
     /* something went wrong, restore the orginal state again */
     GST_CAT_ERROR (GST_CAT_MEMORY, "mem %p: subclass map failed", mem);
-    gst_memory_unlock (mem, flags);
+    gst_memory_unlock (mem, (GstLockFlags) flags);
+    memset (info, 0, sizeof (GstMapInfo));
     return FALSE;
   }
 }
@@ -310,7 +336,7 @@ gst_memory_unmap (GstMemory * mem, GstMapInfo * info)
   g_return_if_fail (info->memory == mem);
 
   mem->allocator->mem_unmap (mem);
-  gst_memory_unlock (mem, info->flags);
+  gst_memory_unlock (mem, (GstLockFlags) info->flags);
 }
 
 /**