GstAllocator: Add GST_ALLOCATOR_FLAG_NO_COPY flag

Detail a bit the intention behind GST_ALLOCATOR_FLAG_CUSTOM_ALLOC, even
if implementation does not currently fully follow that usage. Introduce
a new flag specifically for copying memories using the default system
allocator.

Sponsored-by: Netflix Inc.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5328>
This commit is contained in:
Xavier Claessens 2023-09-18 14:38:23 -04:00 committed by GStreamer Marge Bot
parent e3e8147a74
commit 24c34cadec
2 changed files with 20 additions and 1 deletions

View file

@ -104,7 +104,8 @@ _fallback_mem_copy (GstMemory * mem, gssize offset, gssize size)
/* use the same allocator as the memory we copy */
allocator = mem->allocator;
if (GST_OBJECT_FLAG_IS_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC))
if (GST_OBJECT_FLAG_IS_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC) ||
GST_OBJECT_FLAG_IS_SET (allocator, GST_ALLOCATOR_FLAG_NO_COPY))
allocator = NULL;
copy = gst_allocator_alloc (allocator, size, &params);

View file

@ -84,12 +84,30 @@ struct _GstAllocationParams {
/**
* GstAllocatorFlags:
* @GST_ALLOCATOR_FLAG_CUSTOM_ALLOC: The allocator has a custom alloc function.
* Only elements designed to work with this allocator should be using it,
* other elements should ignore it from allocation propositions.
* This implies %GST_ALLOCATOR_FLAG_NO_COPY.
* @GST_ALLOCATOR_FLAG_NO_COPY: When copying a #GstMemory allocated with this
* allocator, the copy will instead be allocated using the default allocator.
* Use this when allocating a new memory is an heavy opperation that should
* only be done with a #GstBufferPool for example. (Since: 1.24)
* @GST_ALLOCATOR_FLAG_LAST: first flag that can be used for custom purposes
*
* Flags for allocators.
*/
/**
* GST_ALLOCATOR_FLAG_NO_COPY:
*
* When copying a #GstMemory allocated with this allocator, the copy will
* instead be allocated using the default allocator. Use this when allocating a
* new memory is an heavy opperation that should only be done with a
* #GstBufferPool for example.
*
* Since: 1.24
*/
typedef enum {
GST_ALLOCATOR_FLAG_CUSTOM_ALLOC = (GST_OBJECT_FLAG_LAST << 0),
GST_ALLOCATOR_FLAG_NO_COPY = (GST_OBJECT_FLAG_LAST << 1),
GST_ALLOCATOR_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 16)
} GstAllocatorFlags;