From 24c34cadecf007f9faac62a96c0bc96f9d63bd59 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Mon, 18 Sep 2023 14:38:23 -0400 Subject: [PATCH] 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: --- subprojects/gstreamer/gst/gstallocator.c | 3 ++- subprojects/gstreamer/gst/gstallocator.h | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/subprojects/gstreamer/gst/gstallocator.c b/subprojects/gstreamer/gst/gstallocator.c index 6ce64dd4d6..996f5dc946 100644 --- a/subprojects/gstreamer/gst/gstallocator.c +++ b/subprojects/gstreamer/gst/gstallocator.c @@ -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, ¶ms); diff --git a/subprojects/gstreamer/gst/gstallocator.h b/subprojects/gstreamer/gst/gstallocator.h index 0989dd8db1..74c38705e2 100644 --- a/subprojects/gstreamer/gst/gstallocator.h +++ b/subprojects/gstreamer/gst/gstallocator.h @@ -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;