*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
/**
* 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().
* 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
static void
_gst_memory_free (GstMemory * mem)
{
+ GstAllocator *allocator;
+
GST_CAT_DEBUG (GST_CAT_MEMORY, "free memory %p", mem);
if (mem->parent) {
gst_memory_unref (mem->parent);
}
- gst_allocator_free (mem->allocator, mem);
+ allocator = mem->allocator;
+
+ gst_allocator_free (allocator, mem);
+ gst_object_unref (allocator);
}
/**
(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);
}
/**
+ * 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
* 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 *
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);
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;
}
}
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);
}
/**