cudamemory: Allow nullptr allocator object

The GstCudaAllocator object doesn't hold any device object.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3629>
This commit is contained in:
Seungha Yang 2022-12-19 22:16:01 +09:00 committed by GStreamer Marge Bot
parent 0a81c8deb3
commit 9eaae61a44
3 changed files with 14 additions and 14 deletions

View file

@ -30,7 +30,6 @@ GST_DEBUG_CATEGORY_STATIC (gst_cuda_buffer_pool_debug);
struct _GstCudaBufferPoolPrivate
{
GstCudaAllocator *allocator;
GstVideoInfo info;
};
@ -74,15 +73,7 @@ gst_cuda_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
return FALSE;
}
gst_clear_object (&priv->allocator);
priv->allocator = (GstCudaAllocator *)
gst_allocator_find (GST_CUDA_MEMORY_TYPE_NAME);
if (!priv->allocator) {
GST_WARNING_OBJECT (self, "CudaAllocator is unavailable");
return FALSE;
}
mem = gst_cuda_allocator_alloc (priv->allocator, self->context, &info);
mem = gst_cuda_allocator_alloc (NULL, self->context, &info);
if (!mem) {
GST_WARNING_OBJECT (self, "Failed to allocate memory");
return FALSE;
@ -111,7 +102,7 @@ gst_cuda_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
GstMemory *mem;
GstCudaMemory *cmem;
mem = gst_cuda_allocator_alloc (priv->allocator, self->context, &priv->info);
mem = gst_cuda_allocator_alloc (NULL, self->context, &priv->info);
if (!mem) {
GST_WARNING_OBJECT (pool, "Cannot create CUDA memory");
return GST_FLOW_ERROR;
@ -161,9 +152,7 @@ static void
gst_cuda_buffer_pool_dispose (GObject * object)
{
GstCudaBufferPool *self = GST_CUDA_BUFFER_POOL_CAST (object);
GstCudaBufferPoolPrivate *priv = self->priv;
gst_clear_object (&priv->allocator);
gst_clear_object (&self->context);
G_OBJECT_CLASS (parent_class)->dispose (object);

View file

@ -24,6 +24,7 @@
#include "gstcudaloader.h"
#include "gstcudacontext.h"
#include "gstcudautils.h"
#include "gstcudamemory.h"
#ifdef GST_CUDA_HAS_D3D
#include <gst/d3d11/gstd3d11.h>
@ -99,6 +100,8 @@ gst_cuda_context_class_init (GstCudaContextClass * klass)
GST_PARAM_CONDITIONALLY_AVAILABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
#endif
gst_cuda_memory_init_once ();
}
static void

View file

@ -462,6 +462,7 @@ gst_cuda_memory_init_once (void)
_gst_cuda_allocator =
(GstAllocator *) g_object_new (GST_TYPE_CUDA_ALLOCATOR, NULL);
gst_object_ref_sink (_gst_cuda_allocator);
gst_object_ref (_gst_cuda_allocator);
gst_allocator_register (GST_CUDA_MEMORY_TYPE_NAME, _gst_cuda_allocator);
g_once_init_leave (&_init, 1);
@ -485,6 +486,11 @@ gst_is_cuda_memory (GstMemory * mem)
/**
* gst_cuda_allocator_alloc:
* @allocator: (transfer none) (allow-none): a #GstCudaAllocator
* @context: (transfer none): a #GstCudaContext
* @info: a #GstVideoInfo
*
* Returns: (transfer full) (nullable): a newly allocated #GstCudaMemory
*
* Since: 1.22
*/
@ -494,10 +500,12 @@ gst_cuda_allocator_alloc (GstCudaAllocator * allocator,
{
guint alloc_height;
g_return_val_if_fail (GST_IS_CUDA_ALLOCATOR (allocator), NULL);
g_return_val_if_fail (GST_IS_CUDA_CONTEXT (context), NULL);
g_return_val_if_fail (info != NULL, NULL);
if (!allocator)
allocator = (GstCudaAllocator *) _gst_cuda_allocator;
alloc_height = GST_VIDEO_INFO_HEIGHT (info);
/* make sure valid height for subsampled formats */