cuda: Use d3d11 token data for interop data

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5409>
This commit is contained in:
Seungha Yang 2023-09-27 20:50:20 +09:00 committed by GStreamer Marge Bot
parent c818906236
commit 91e0c3aafa

View file

@ -27,6 +27,7 @@
#include <atomic> #include <atomic>
#include <set> #include <set>
#include <string> #include <string>
#include <mutex>
#ifdef HAVE_CUDA_GST_GL #ifdef HAVE_CUDA_GST_GL
#include <gst/gl/gl.h> #include <gst/gl/gl.h>
@ -1307,8 +1308,14 @@ ensure_d3d11_interop (GstCudaContext * context, GstD3D11Device * device)
static GstCudaGraphicsResource * static GstCudaGraphicsResource *
ensure_cuda_d3d11_graphics_resource (GstCudaContext * context, GstMemory * mem) ensure_cuda_d3d11_graphics_resource (GstCudaContext * context, GstMemory * mem)
{ {
GQuark quark; static gint64 d3d11_interop_token = 0;
static std::once_flag once_flag;
GstCudaGraphicsResource *ret = nullptr; GstCudaGraphicsResource *ret = nullptr;
GstD3D11Memory *dmem;
GST_CUDA_CALL_ONCE_BEGIN {
d3d11_interop_token = gst_d3d11_create_user_token ();
} GST_CUDA_CALL_ONCE_END;
if (!gst_is_d3d11_memory (mem)) { if (!gst_is_d3d11_memory (mem)) {
GST_WARNING_OBJECT (context, "memory is not D3D11 memory, %s", GST_WARNING_OBJECT (context, "memory is not D3D11 memory, %s",
@ -1316,9 +1323,9 @@ ensure_cuda_d3d11_graphics_resource (GstCudaContext * context, GstMemory * mem)
return nullptr; return nullptr;
} }
quark = gst_cuda_quark_from_id (GST_CUDA_QUARK_GRAPHICS_RESOURCE); dmem = GST_D3D11_MEMORY_CAST (mem);
ret = (GstCudaGraphicsResource *) ret = (GstCudaGraphicsResource *)
gst_mini_object_get_qdata (GST_MINI_OBJECT (mem), quark); gst_d3d11_memory_get_token_data (dmem, d3d11_interop_token);
if (!ret) { if (!ret) {
ret = gst_cuda_graphics_resource_new (context, ret = gst_cuda_graphics_resource_new (context,
@ -1331,11 +1338,11 @@ ensure_cuda_d3d11_graphics_resource (GstCudaContext * context, GstMemory * mem)
GST_ERROR_OBJECT (context, "failed to register d3d11 resource"); GST_ERROR_OBJECT (context, "failed to register d3d11 resource");
gst_cuda_graphics_resource_free (ret); gst_cuda_graphics_resource_free (ret);
return nullptr; ret = nullptr;
} else {
gst_d3d11_memory_set_token_data (dmem, d3d11_interop_token, ret,
(GDestroyNotify) gst_cuda_graphics_resource_free);
} }
gst_mini_object_set_qdata (GST_MINI_OBJECT (mem), quark, ret,
(GDestroyNotify) gst_cuda_graphics_resource_free);
} }
return ret; return ret;