cuda: Factor out a public GstCUDA library

So applications and elements implemented outside GStreamer can reuse
our infrastructure

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1472>
This commit is contained in:
Thibault Saunier 2021-12-08 11:48:08 +00:00 committed by GStreamer Marge Bot
parent 3549d59725
commit c033f8fad2
55 changed files with 720 additions and 188 deletions

View file

@ -0,0 +1,7 @@
# Cuda library
This library should be linked to by getting cflags and libs from
gstreamer-cuda-{{ gst_api_version.md }}.pc
> NOTE: This library API is considered *unstable*

View file

@ -0,0 +1 @@
gi-index

View file

@ -125,6 +125,7 @@ if build_gir
{'name': 'audio', 'gir': audio_gir, 'lib': gstbadaudio_dep, 'prefix': 'bad-'}, {'name': 'audio', 'gir': audio_gir, 'lib': gstbadaudio_dep, 'prefix': 'bad-'},
{'name': 'transcoder', 'gir': transcoder_gir, 'lib': gst_transcoder_dep}, {'name': 'transcoder', 'gir': transcoder_gir, 'lib': gst_transcoder_dep},
{'name': 'codecs', 'gir': codecs_gir, 'lib': gstcodecs_dep}, {'name': 'codecs', 'gir': codecs_gir, 'lib': gstcodecs_dep},
{'name': 'cuda', 'gir': gst_cuda_gir, 'lib': gstcuda_dep},
] ]
if gstopencv_dep.found() if gstopencv_dep.found()

View file

@ -1,141 +1,153 @@
/* GStreamer #pragma once
* Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_CUDA_LOADER_H__ #include "cuda-prelude.h"
#define __GST_CUDA_LOADER_H__ #include <nvrtc.h>
#include <cuda.h>
#include "stub/cuda.h" #include <cudaGL.h>
#include <gst/gst.h>
G_BEGIN_DECLS G_BEGIN_DECLS
gboolean gst_cuda_load_library (void);
/* cuda.h */ /* cuda.h */
GST_CUDA_API
CUresult CUDAAPI CuInit (unsigned int Flags); CUresult CUDAAPI CuInit (unsigned int Flags);
GST_CUDA_API
CUresult CUDAAPI CuGetErrorName (CUresult error, CUresult CUDAAPI CuGetErrorName (CUresult error,
const char **pStr); const char **pStr);
GST_CUDA_API
CUresult CUDAAPI CuGetErrorString (CUresult error, CUresult CUDAAPI CuGetErrorString (CUresult error,
const char **pStr); const char **pStr);
GST_CUDA_API
CUresult CUDAAPI CuCtxCreate (CUcontext * pctx, CUresult CUDAAPI CuCtxCreate (CUcontext * pctx,
unsigned int flags, unsigned int flags,
CUdevice dev); CUdevice dev);
GST_CUDA_API
CUresult CUDAAPI CuCtxDestroy (CUcontext ctx); CUresult CUDAAPI CuCtxDestroy (CUcontext ctx);
GST_CUDA_API
CUresult CUDAAPI CuCtxPopCurrent (CUcontext * pctx); CUresult CUDAAPI CuCtxPopCurrent (CUcontext * pctx);
GST_CUDA_API
CUresult CUDAAPI CuCtxPushCurrent (CUcontext ctx); CUresult CUDAAPI CuCtxPushCurrent (CUcontext ctx);
GST_CUDA_API
CUresult CUDAAPI CuCtxEnablePeerAccess (CUcontext peerContext, CUresult CUDAAPI CuCtxEnablePeerAccess (CUcontext peerContext,
unsigned int Flags); unsigned int Flags);
GST_CUDA_API
CUresult CUDAAPI CuCtxDisablePeerAccess (CUcontext peerContext); CUresult CUDAAPI CuCtxDisablePeerAccess (CUcontext peerContext);
GST_CUDA_API
CUresult CUDAAPI CuGraphicsMapResources (unsigned int count, CUresult CUDAAPI CuGraphicsMapResources (unsigned int count,
CUgraphicsResource * resources, CUgraphicsResource * resources,
CUstream hStream); CUstream hStream);
GST_CUDA_API
CUresult CUDAAPI CuGraphicsUnmapResources (unsigned int count, CUresult CUDAAPI CuGraphicsUnmapResources (unsigned int count,
CUgraphicsResource * resources, CUgraphicsResource * resources,
CUstream hStream); CUstream hStream);
CUresult CUDAAPI CuGraphicsResourceSetMapFlags (CUgraphicsResource resource, GST_CUDA_API
unsigned int flags);
CUresult CUDAAPI CuGraphicsSubResourceGetMappedArray (CUarray * pArray, CUresult CUDAAPI CuGraphicsSubResourceGetMappedArray (CUarray * pArray,
CUgraphicsResource resource, CUgraphicsResource resource,
unsigned int arrayIndex, unsigned int arrayIndex,
unsigned int mipLevel); unsigned int mipLevel);
GST_CUDA_API
CUresult CUDAAPI CuGraphicsResourceGetMappedPointer (CUdeviceptr * pDevPtr, CUresult CUDAAPI CuGraphicsResourceGetMappedPointer (CUdeviceptr * pDevPtr,
size_t * pSize, size_t * pSize,
CUgraphicsResource resource); CUgraphicsResource resource);
GST_CUDA_API
CUresult CUDAAPI CuGraphicsUnregisterResource (CUgraphicsResource resource); CUresult CUDAAPI CuGraphicsUnregisterResource (CUgraphicsResource resource);
GST_CUDA_API
CUresult CUDAAPI CuMemAlloc (CUdeviceptr * dptr, CUresult CUDAAPI CuMemAlloc (CUdeviceptr * dptr,
unsigned int bytesize); unsigned int bytesize);
GST_CUDA_API
CUresult CUDAAPI CuMemAllocPitch (CUdeviceptr * dptr, CUresult CUDAAPI CuMemAllocPitch (CUdeviceptr * dptr,
size_t * pPitch, size_t * pPitch,
size_t WidthInBytes, size_t WidthInBytes,
size_t Height, size_t Height,
unsigned int ElementSizeBytes); unsigned int ElementSizeBytes);
GST_CUDA_API
CUresult CUDAAPI CuMemAllocHost (void **pp, CUresult CUDAAPI CuMemAllocHost (void **pp,
unsigned int bytesize); unsigned int bytesize);
GST_CUDA_API
CUresult CUDAAPI CuMemcpy2D (const CUDA_MEMCPY2D * pCopy); CUresult CUDAAPI CuMemcpy2D (const CUDA_MEMCPY2D * pCopy);
GST_CUDA_API
CUresult CUDAAPI CuMemcpy2DAsync (const CUDA_MEMCPY2D *pCopy, CUstream hStream); CUresult CUDAAPI CuMemcpy2DAsync (const CUDA_MEMCPY2D *pCopy, CUstream hStream);
GST_CUDA_API
CUresult CUDAAPI CuMemFree (CUdeviceptr dptr); CUresult CUDAAPI CuMemFree (CUdeviceptr dptr);
GST_CUDA_API
CUresult CUDAAPI CuMemFreeHost (void *p); CUresult CUDAAPI CuMemFreeHost (void *p);
GST_CUDA_API
CUresult CUDAAPI CuStreamCreate (CUstream *phStream, CUresult CUDAAPI CuStreamCreate (CUstream *phStream,
unsigned int Flags); unsigned int Flags);
GST_CUDA_API
CUresult CUDAAPI CuStreamDestroy (CUstream hStream); CUresult CUDAAPI CuStreamDestroy (CUstream hStream);
GST_CUDA_API
CUresult CUDAAPI CuStreamSynchronize (CUstream hStream); CUresult CUDAAPI CuStreamSynchronize (CUstream hStream);
GST_CUDA_API
CUresult CUDAAPI CuDeviceGet (CUdevice * device, CUresult CUDAAPI CuDeviceGet (CUdevice * device,
int ordinal); int ordinal);
GST_CUDA_API
CUresult CUDAAPI CuDeviceGetCount (int *count); CUresult CUDAAPI CuDeviceGetCount (int *count);
GST_CUDA_API
CUresult CUDAAPI CuDeviceGetName (char *name, CUresult CUDAAPI CuDeviceGetName (char *name,
int len, int len,
CUdevice dev); CUdevice dev);
GST_CUDA_API
CUresult CUDAAPI CuDeviceGetAttribute (int *pi, CUresult CUDAAPI CuDeviceGetAttribute (int *pi,
CUdevice_attribute attrib, CUdevice_attribute attrib,
CUdevice dev); CUdevice dev);
GST_CUDA_API
CUresult CUDAAPI CuDeviceCanAccessPeer (int *canAccessPeer, CUresult CUDAAPI CuDeviceCanAccessPeer (int *canAccessPeer,
CUdevice dev, CUdevice dev,
CUdevice peerDev); CUdevice peerDev);
GST_CUDA_API
CUresult CUDAAPI CuDriverGetVersion (int * driverVersion); CUresult CUDAAPI CuDriverGetVersion (int * driverVersion);
GST_CUDA_API
CUresult CUDAAPI CuModuleLoadData (CUmodule* module, CUresult CUDAAPI CuModuleLoadData (CUmodule* module,
const void *image); const void *image);
GST_CUDA_API
CUresult CUDAAPI CuModuleUnload (CUmodule module); CUresult CUDAAPI CuModuleUnload (CUmodule module);
GST_CUDA_API
CUresult CUDAAPI CuModuleGetFunction (CUfunction* hfunc, CUresult CUDAAPI CuModuleGetFunction (CUfunction* hfunc,
CUmodule hmod, CUmodule hmod,
const char* name); const char* name);
GST_CUDA_API
CUresult CUDAAPI CuTexObjectCreate (CUtexObject *pTexObject, CUresult CUDAAPI CuTexObjectCreate (CUtexObject *pTexObject,
const CUDA_RESOURCE_DESC *pResDesc, const CUDA_RESOURCE_DESC *pResDesc,
const CUDA_TEXTURE_DESC *pTexDesc, const CUDA_TEXTURE_DESC *pTexDesc,
const CUDA_RESOURCE_VIEW_DESC *pResViewDesc); const CUDA_RESOURCE_VIEW_DESC *pResViewDesc);
GST_CUDA_API
CUresult CUDAAPI CuTexObjectDestroy (CUtexObject texObject); CUresult CUDAAPI CuTexObjectDestroy (CUtexObject texObject);
GST_CUDA_API
CUresult CUDAAPI CuLaunchKernel (CUfunction f, CUresult CUDAAPI CuLaunchKernel (CUfunction f,
unsigned int gridDimX, unsigned int gridDimX,
unsigned int gridDimY, unsigned int gridDimY,
@ -149,33 +161,78 @@ CUresult CUDAAPI CuLaunchKernel (CUfunction f,
void **extra); void **extra);
/* cudaGL.h */ /* cudaGL.h */
GST_CUDA_API
CUresult CUDAAPI CuGraphicsGLRegisterImage (CUgraphicsResource * pCudaResource, CUresult CUDAAPI CuGraphicsGLRegisterImage (CUgraphicsResource * pCudaResource,
unsigned int image, unsigned int image,
unsigned int target, unsigned int target,
unsigned int Flags); unsigned int Flags);
GST_CUDA_API
CUresult CUDAAPI CuGraphicsGLRegisterBuffer (CUgraphicsResource * pCudaResource, CUresult CUDAAPI CuGraphicsGLRegisterBuffer (CUgraphicsResource * pCudaResource,
unsigned int buffer, unsigned int buffer,
unsigned int Flags); unsigned int Flags);
GST_CUDA_API
CUresult CUDAAPI CuGraphicsResourceSetMapFlags (CUgraphicsResource resource,
unsigned int flags);
GST_CUDA_API
CUresult CUDAAPI CuGLGetDevices (unsigned int * pCudaDeviceCount, CUresult CUDAAPI CuGLGetDevices (unsigned int * pCudaDeviceCount,
CUdevice * pCudaDevices, CUdevice * pCudaDevices,
unsigned int cudaDeviceCount, unsigned int cudaDeviceCount,
CUGLDeviceList deviceList); CUGLDeviceList deviceList);
#ifdef GST_CUDA_HAS_D3D
/* cudaD3D11.h */ /* cudaD3D11.h */
GST_CUDA_API
CUresult CUDAAPI CuGraphicsD3D11RegisterResource(CUgraphicsResource * pCudaResource, CUresult CUDAAPI CuGraphicsD3D11RegisterResource(CUgraphicsResource * pCudaResource,
gpointer pD3DResource, gpointer pD3DResource,
unsigned int Flags); unsigned int Flags);
GST_CUDA_API
CUresult CUDAAPI CuD3D11GetDevice(CUdevice * device, CUresult CUDAAPI CuD3D11GetDevice(CUdevice * device,
gpointer pAdapter); gpointer pAdapter);
GST_CUDA_API
CUresult CUDAAPI CuD3D11GetDevices(unsigned int * pCudaDeviceCount, CUresult CUDAAPI CuD3D11GetDevices(unsigned int * pCudaDeviceCount,
CUdevice* pCudaDevices, CUdevice* pCudaDevices,
unsigned int cudaDeviceCount, unsigned int cudaDeviceCount,
gpointer pD3D11Device, gpointer pD3D11Device,
CUD3D11DeviceList deviceList); CUD3D11DeviceList deviceList);
#endif
/* nvrtc.h */
GST_CUDA_API
nvrtcResult NvrtcCompileProgram (nvrtcProgram prog,
int numOptions,
const char** options);
GST_CUDA_API
nvrtcResult NvrtcCreateProgram (nvrtcProgram* prog,
const char* src,
const char* name,
int numHeaders,
const char** headers,
const char** includeNames);
GST_CUDA_API
nvrtcResult NvrtcDestroyProgram (nvrtcProgram* prog);
GST_CUDA_API
nvrtcResult NvrtcGetPTX (nvrtcProgram prog,
char* ptx);
GST_CUDA_API
nvrtcResult NvrtcGetPTXSize (nvrtcProgram prog,
size_t* ptxSizeRet);
GST_CUDA_API
nvrtcResult NvrtcGetProgramLog (nvrtcProgram prog,
char* log);
GST_CUDA_API
nvrtcResult NvrtcGetProgramLogSize (nvrtcProgram prog,
size_t* logSizeRet);
G_END_DECLS G_END_DECLS
#endif /* __GST_CUDA_LOADER_H__ */

View file

@ -0,0 +1,36 @@
/* GStreamer Cuda Library
* Copyright (C) 2021 GStreamer developers
*
* -prelude.h: prelude include header for gst-cuda library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_CUDA_PRELUDE_H__
#define __GST_CUDA_PRELUDE_H__
#include <gst/gst.h>
#ifndef GST_CUDA_API
# ifdef BUILDING_GST_CUDA
# define GST_CUDA_API GST_API_EXPORT /* from config.h */
# else
# define GST_CUDA_API GST_API_IMPORT
# endif
#endif
#endif /* __GST_CUDA_PRELUDE_H__ */

View file

@ -134,6 +134,14 @@ gst_cuda_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
return GST_FLOW_OK; return GST_FLOW_OK;
} }
/**
* gst_cuda_buffer_pool_new:
* @context: The #GstCudaContext to use for the new buffer pool
*
* Returns: A newly created #GstCudaBufferPool
*
* Since: 1.22
*/
GstBufferPool * GstBufferPool *
gst_cuda_buffer_pool_new (GstCudaContext * context) gst_cuda_buffer_pool_new (GstCudaContext * context)
{ {

View file

@ -20,6 +20,12 @@
#ifndef __GST_CUDA_BUFFER_POOL_H__ #ifndef __GST_CUDA_BUFFER_POOL_H__
#define __GST_CUDA_BUFFER_POOL_H__ #define __GST_CUDA_BUFFER_POOL_H__
#ifndef GST_USE_UNSTABLE_API
#warning "The Cuda library from gst-plugins-bad is unstable API and may change in future."
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
#endif
#include "cuda-prelude.h"
#include <gst/video/gstvideometa.h> #include <gst/video/gstvideometa.h>
#include <gst/video/gstvideopool.h> #include <gst/video/gstvideopool.h>
@ -33,14 +39,21 @@ G_BEGIN_DECLS
#define GST_CUDA_BUFFER_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CUDA_BUFFER_POOL,GstCudaBufferPoolClass)) #define GST_CUDA_BUFFER_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CUDA_BUFFER_POOL,GstCudaBufferPoolClass))
#define GST_IS_CUDA_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),GST_TYPE_CUDA_BUFFER_POOL)) #define GST_IS_CUDA_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),GST_TYPE_CUDA_BUFFER_POOL))
#define GST_IS_CUDA_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_CUDA_BUFFER_POOL)) #define GST_IS_CUDA_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_CUDA_BUFFER_POOL))
/**
* GST_CUDA_BUFFER_POOL_CAST:
*
* Since: 1.22
*/
#define GST_CUDA_BUFFER_POOL_CAST(obj) ((GstCudaBufferPool*)(obj)) #define GST_CUDA_BUFFER_POOL_CAST(obj) ((GstCudaBufferPool*)(obj))
typedef struct _GstCudaBufferPool GstCudaBufferPool; typedef struct _GstCudaBufferPool GstCudaBufferPool;
typedef struct _GstCudaBufferPoolClass GstCudaBufferPoolClass; typedef struct _GstCudaBufferPoolClass GstCudaBufferPoolClass;
typedef struct _GstCudaBufferPoolPrivate GstCudaBufferPoolPrivate; typedef struct _GstCudaBufferPoolPrivate GstCudaBufferPoolPrivate;
/* /**
* GstCudaBufferPool: * GstCudaBufferPool:
*
* Since: 1.22
*/ */
struct _GstCudaBufferPool struct _GstCudaBufferPool
{ {
@ -59,8 +72,10 @@ struct _GstCudaBufferPoolClass
GstBufferPoolClass parent_class; GstBufferPoolClass parent_class;
}; };
GST_CUDA_API
GType gst_cuda_buffer_pool_get_type (void); GType gst_cuda_buffer_pool_get_type (void);
GST_CUDA_API
GstBufferPool * gst_cuda_buffer_pool_new (GstCudaContext * context); GstBufferPool * gst_cuda_buffer_pool_new (GstCudaContext * context);
G_END_DECLS G_END_DECLS

View file

@ -25,7 +25,7 @@
#include "gstcudacontext.h" #include "gstcudacontext.h"
#include "gstcudautils.h" #include "gstcudautils.h"
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
#include <gst/d3d11/gstd3d11.h> #include <gst/d3d11/gstd3d11.h>
#endif #endif
@ -76,16 +76,23 @@ gst_cuda_context_class_init (GstCudaContextClass * klass)
gobject_class->set_property = gst_cuda_context_set_property; gobject_class->set_property = gst_cuda_context_set_property;
gobject_class->get_property = gst_cuda_context_get_property; gobject_class->get_property = gst_cuda_context_get_property;
gobject_class->constructed = gst_cuda_context_constructed;
gobject_class->finalize = gst_cuda_context_finalize; gobject_class->finalize = gst_cuda_context_finalize;
gobject_class->constructed = gst_cuda_context_constructed;
/**
* GstCudaContext::cuda-device-id:
*
* The GPU index to use for the context.
*
* Since: 1.22
*/
g_object_class_install_property (gobject_class, PROP_DEVICE_ID, g_object_class_install_property (gobject_class, PROP_DEVICE_ID,
g_param_spec_uint ("cuda-device-id", "Cuda Device ID", g_param_spec_uint ("cuda-device-id", "Cuda Device ID",
"Set the GPU device to use for operations", "Set the GPU device to use for operations",
0, G_MAXUINT, 0, 0, G_MAXUINT, 0,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
g_object_class_install_property (gobject_class, PROP_DXGI_ADAPTER_LUID, g_object_class_install_property (gobject_class, PROP_DXGI_ADAPTER_LUID,
g_param_spec_int64 ("dxgi-adapter-luid", "DXGI Adapter LUID", g_param_spec_int64 ("dxgi-adapter-luid", "DXGI Adapter LUID",
"Associated DXGI Adapter LUID (Locally Unique Identifier) ", "Associated DXGI Adapter LUID (Locally Unique Identifier) ",
@ -145,7 +152,7 @@ gst_cuda_context_get_property (GObject * object, guint prop_id,
} }
} }
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
static gint64 static gint64
gst_cuda_context_find_dxgi_adapter_luid (CUdevice cuda_device) gst_cuda_context_find_dxgi_adapter_luid (CUdevice cuda_device)
{ {
@ -246,7 +253,7 @@ gst_cuda_context_constructed (GObject * object)
priv->context = cuda_ctx; priv->context = cuda_ctx;
priv->device = cdev; priv->device = cdev;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
priv->dxgi_adapter_luid = gst_cuda_context_find_dxgi_adapter_luid (cdev); priv->dxgi_adapter_luid = gst_cuda_context_find_dxgi_adapter_luid (cdev);
#endif #endif
@ -393,6 +400,8 @@ gst_cuda_context_new (guint device_id)
* so all CUDA functions that operate on the current context are affected. * so all CUDA functions that operate on the current context are affected.
* *
* Returns: %TRUE if @ctx was pushed without error. * Returns: %TRUE if @ctx was pushed without error.
*
* Since: 1.22
*/ */
gboolean gboolean
gst_cuda_context_push (GstCudaContext * ctx) gst_cuda_context_push (GstCudaContext * ctx)
@ -409,6 +418,8 @@ gst_cuda_context_push (GstCudaContext * ctx)
* Pops the current CUDA context from CPU thread * Pops the current CUDA context from CPU thread
* *
* Returns: %TRUE if @ctx was pushed without error. * Returns: %TRUE if @ctx was pushed without error.
*
* Since: 1.22
*/ */
gboolean gboolean
gst_cuda_context_pop (CUcontext * cuda_ctx) gst_cuda_context_pop (CUcontext * cuda_ctx)
@ -423,7 +434,9 @@ gst_cuda_context_pop (CUcontext * cuda_ctx)
* Get CUDA device context. Caller must not modify and/or destroy * Get CUDA device context. Caller must not modify and/or destroy
* returned device context. * returned device context.
* *
* Returns: the #CUcontext of @ctx * Returns: the `CUcontext` of @ctx
*
* Since: 1.22
*/ */
gpointer gpointer
gst_cuda_context_get_handle (GstCudaContext * ctx) gst_cuda_context_get_handle (GstCudaContext * ctx)
@ -440,7 +453,9 @@ gst_cuda_context_get_handle (GstCudaContext * ctx)
* *
* Get required texture alignment by device * Get required texture alignment by device
* *
* Returns: the #CUcontext of @ctx * Returns: the `CUcontext` of @ctx
*
* Since: 1.22
*/ */
gint gint
gst_cuda_context_get_texture_alignment (GstCudaContext * ctx) gst_cuda_context_get_texture_alignment (GstCudaContext * ctx)
@ -457,8 +472,10 @@ gst_cuda_context_get_texture_alignment (GstCudaContext * ctx)
* @peer: a #GstCudaContext * @peer: a #GstCudaContext
* *
* Query whether @ctx can access any memory which belongs to @peer directly. * Query whether @ctx can access any memory which belongs to @peer directly.
*
* Returns: %TRUE if @ctx can access @peer directly * Returns: %TRUE if @ctx can access @peer directly
*
* Since: 1.22
*/ */
gboolean gboolean
gst_cuda_context_can_access_peer (GstCudaContext * ctx, GstCudaContext * peer) gst_cuda_context_can_access_peer (GstCudaContext * ctx, GstCudaContext * peer)

View file

@ -20,8 +20,14 @@
#ifndef __GST_CUDA_CONTEXT_H__ #ifndef __GST_CUDA_CONTEXT_H__
#define __GST_CUDA_CONTEXT_H__ #define __GST_CUDA_CONTEXT_H__
#ifndef GST_USE_UNSTABLE_API
#warning "The Cuda library from gst-plugins-bad is unstable API and may change in future."
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
#endif
#include "cuda-prelude.h"
#include <gst/gst.h> #include <gst/gst.h>
#include <cuda.h> #include "cuda.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -31,16 +37,29 @@ G_BEGIN_DECLS
#define GST_CUDA_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CUDA_CONTEXT,GstCudaContextClass)) #define GST_CUDA_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CUDA_CONTEXT,GstCudaContextClass))
#define GST_IS_CUDA_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),GST_TYPE_CUDA_CONTEXT)) #define GST_IS_CUDA_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),GST_TYPE_CUDA_CONTEXT))
#define GST_IS_CUDA_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_CUDA_CONTEXT)) #define GST_IS_CUDA_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_CUDA_CONTEXT))
/**
* GST_CUDA_CONTEXT_CAST:
*
* Since: 1.22
*/
#define GST_CUDA_CONTEXT_CAST(obj) ((GstCudaContext*)(obj)) #define GST_CUDA_CONTEXT_CAST(obj) ((GstCudaContext*)(obj))
/**
* GST_CUDA_CONTEXT_TYPE:
*
* Since: 1.22
*/
#define GST_CUDA_CONTEXT_TYPE "gst.cuda.context" #define GST_CUDA_CONTEXT_TYPE "gst.cuda.context"
typedef struct _GstCudaContext GstCudaContext; typedef struct _GstCudaContext GstCudaContext;
typedef struct _GstCudaContextClass GstCudaContextClass; typedef struct _GstCudaContextClass GstCudaContextClass;
typedef struct _GstCudaContextPrivate GstCudaContextPrivate; typedef struct _GstCudaContextPrivate GstCudaContextPrivate;
/* /**
* GstCudaContext: * GstCudaContext:
*
* Since: 1.22
*/ */
struct _GstCudaContext struct _GstCudaContext
{ {
@ -50,26 +69,30 @@ struct _GstCudaContext
GstCudaContextPrivate *priv; GstCudaContextPrivate *priv;
}; };
/*
* GstCudaContextClass:
*/
struct _GstCudaContextClass struct _GstCudaContextClass
{ {
GstObjectClass parent_class; GstObjectClass parent_class;
}; };
GST_CUDA_API
GType gst_cuda_context_get_type (void); GType gst_cuda_context_get_type (void);
GST_CUDA_API
GstCudaContext * gst_cuda_context_new (guint device_id); GstCudaContext * gst_cuda_context_new (guint device_id);
GST_CUDA_API
gboolean gst_cuda_context_push (GstCudaContext * ctx); gboolean gst_cuda_context_push (GstCudaContext * ctx);
GST_CUDA_API
gboolean gst_cuda_context_pop (CUcontext * cuda_ctx); gboolean gst_cuda_context_pop (CUcontext * cuda_ctx);
GST_CUDA_API
gpointer gst_cuda_context_get_handle (GstCudaContext * ctx); gpointer gst_cuda_context_get_handle (GstCudaContext * ctx);
GST_CUDA_API
gint gst_cuda_context_get_texture_alignment (GstCudaContext * ctx); gint gst_cuda_context_get_texture_alignment (GstCudaContext * ctx);
GST_CUDA_API
gboolean gst_cuda_context_can_access_peer (GstCudaContext * ctx, gboolean gst_cuda_context_can_access_peer (GstCudaContext * ctx,
GstCudaContext * peer); GstCudaContext * peer);

View file

@ -21,11 +21,12 @@
#include "config.h" #include "config.h"
#endif #endif
#include "cuda-gst.h"
#include "gstcudaloader.h" #include "gstcudaloader.h"
#include <gmodule.h> #include <gmodule.h>
GST_DEBUG_CATEGORY_EXTERN (gst_nvcodec_debug); GST_DEBUG_CATEGORY (gst_cudaloader_debug);
#define GST_CAT_DEFAULT gst_nvcodec_debug #define GST_CAT_DEFAULT gst_cudaloader_debug
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
#define CUDA_LIBNAME "libcuda.so.1" #define CUDA_LIBNAME "libcuda.so.1"
@ -134,12 +135,29 @@ typedef struct _GstNvCodecCudaVTable
static GstNvCodecCudaVTable gst_cuda_vtable = { 0, }; static GstNvCodecCudaVTable gst_cuda_vtable = { 0, };
/**
* gst_cuda_load_library:
*
* Loads the cuda library
*
* Returns: %TRUE if the libcuda could be loaded %FALSE otherwise
*
* Since: 1.22
*/
gboolean gboolean
gst_cuda_load_library (void) gst_cuda_load_library (void)
{ {
GModule *module; GModule *module;
const gchar *filename = CUDA_LIBNAME; const gchar *filename = CUDA_LIBNAME;
GstNvCodecCudaVTable *vtable; GstNvCodecCudaVTable *vtable;
static gsize debug_initialized = FALSE;
if (g_once_init_enter (&debug_initialized)) {
GST_DEBUG_CATEGORY_INIT (gst_cudaloader_debug, "cudaloader", 0,
"cudaloader");
g_once_init_leave (&debug_initialized, TRUE);
}
if (gst_cuda_vtable.loaded) if (gst_cuda_vtable.loaded)
return TRUE; return TRUE;
@ -205,7 +223,7 @@ gst_cuda_load_library (void)
LOAD_SYMBOL (cuGraphicsGLRegisterBuffer, CuGraphicsGLRegisterBuffer); LOAD_SYMBOL (cuGraphicsGLRegisterBuffer, CuGraphicsGLRegisterBuffer);
LOAD_SYMBOL (cuGLGetDevices, CuGLGetDevices); LOAD_SYMBOL (cuGLGetDevices, CuGLGetDevices);
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
/* cudaD3D11.h */ /* cudaD3D11.h */
LOAD_SYMBOL (cuGraphicsD3D11RegisterResource, LOAD_SYMBOL (cuGraphicsD3D11RegisterResource,
CuGraphicsD3D11RegisterResource); CuGraphicsD3D11RegisterResource);
@ -572,6 +590,7 @@ CuGLGetDevices (unsigned int *pCudaDeviceCount, CUdevice * pCudaDevices,
} }
/* cudaD3D11.h */ /* cudaD3D11.h */
#ifdef GST_CUDA_HAS_D3D
CUresult CUDAAPI CUresult CUDAAPI
CuGraphicsD3D11RegisterResource (CUgraphicsResource * pCudaResource, CuGraphicsD3D11RegisterResource (CUgraphicsResource * pCudaResource,
gpointer pD3DResource, unsigned int Flags) gpointer pD3DResource, unsigned int Flags)
@ -601,3 +620,4 @@ CuD3D11GetDevices (unsigned int *pCudaDeviceCount,
return gst_cuda_vtable.CuD3D11GetDevices (pCudaDeviceCount, pCudaDevices, return gst_cuda_vtable.CuD3D11GetDevices (pCudaDeviceCount, pCudaDevices,
cudaDeviceCount, pD3D11Device, deviceList); cudaDeviceCount, pD3D11Device, deviceList);
} }
#endif

View file

@ -0,0 +1,40 @@
/* GStreamer
* Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_CUDA_LOADER_H__
#define __GST_CUDA_LOADER_H__
#ifndef GST_USE_UNSTABLE_API
#warning "The Cuda library from gst-plugins-bad is unstable API and may change in future."
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
#endif
#include "cuda.h"
#include "cudaGL.h"
#include "cuda-prelude.h"
#include <gst/gst.h>
G_BEGIN_DECLS
GST_CUDA_API
gboolean gst_cuda_load_library (void);
G_END_DECLS
#endif /* __GST_CUDA_LOADER_H__ */

View file

@ -420,6 +420,13 @@ cuda_mem_copy (GstMemory * mem, gssize offset, gssize size)
return copy; return copy;
} }
/**
* gst_cuda_memory_init_once:
*
* Ensures that the #GstCudaAllocator is initialized and ready to be used.
*
* Since: 1.22
*/
void void
gst_cuda_memory_init_once (void) gst_cuda_memory_init_once (void)
{ {
@ -435,6 +442,14 @@ gst_cuda_memory_init_once (void)
} }
} }
/**
* gst_is_cuda_memory:
* @mem: A #GstMemory
*
* Check if @mem is a cuda memory
*
* Since: 1.22
*/
gboolean gboolean
gst_is_cuda_memory (GstMemory * mem) gst_is_cuda_memory (GstMemory * mem)
{ {
@ -442,6 +457,11 @@ gst_is_cuda_memory (GstMemory * mem)
GST_IS_CUDA_ALLOCATOR (mem->allocator); GST_IS_CUDA_ALLOCATOR (mem->allocator);
} }
/**
* gst_cuda_allocator_alloc:
*
* Since: 1.22
*/
GstMemory * GstMemory *
gst_cuda_allocator_alloc (GstCudaAllocator * allocator, gst_cuda_allocator_alloc (GstCudaAllocator * allocator,
GstCudaContext * context, const GstVideoInfo * info) GstCudaContext * context, const GstVideoInfo * info)

View file

@ -20,6 +20,12 @@
#ifndef __GST_CUDA_MEMORY_H__ #ifndef __GST_CUDA_MEMORY_H__
#define __GST_CUDA_MEMORY_H__ #define __GST_CUDA_MEMORY_H__
#ifndef GST_USE_UNSTABLE_API
#warning "The Cuda library from gst-plugins-bad is unstable API and may change in future."
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
#endif
#include "cuda-prelude.h"
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/gstallocator.h> #include <gst/gstallocator.h>
#include <gst/video/video.h> #include <gst/video/video.h>
@ -34,9 +40,26 @@ G_BEGIN_DECLS
#define GST_CUDA_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CUDA_ALLOCATOR,GstCudaAllocatorClass)) #define GST_CUDA_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CUDA_ALLOCATOR,GstCudaAllocatorClass))
#define GST_IS_CUDA_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CUDA_ALLOCATOR)) #define GST_IS_CUDA_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CUDA_ALLOCATOR))
#define GST_IS_CUDA_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_CUDA_ALLOCATOR)) #define GST_IS_CUDA_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_CUDA_ALLOCATOR))
/**
* GST_CUDA_ALLOCATOR_CAST:
*
* Since: 1.22
*/
#define GST_CUDA_ALLOCATOR_CAST(obj) ((GstCudaAllocator *)(obj)) #define GST_CUDA_ALLOCATOR_CAST(obj) ((GstCudaAllocator *)(obj))
/**
* GST_CUDA_MEMORY_CAST:
*
* Since: 1.22
*/
#define GST_CUDA_MEMORY_CAST(mem) ((GstCudaMemory *) (mem)) #define GST_CUDA_MEMORY_CAST(mem) ((GstCudaMemory *) (mem))
/**
* GstCudaAllocator:
*
* A #GstAllocator subclass for cuda memory
*
* Since: 1.22
*/
typedef struct _GstCudaAllocator GstCudaAllocator; typedef struct _GstCudaAllocator GstCudaAllocator;
typedef struct _GstCudaAllocatorClass GstCudaAllocatorClass; typedef struct _GstCudaAllocatorClass GstCudaAllocatorClass;
@ -54,15 +77,26 @@ typedef struct _GstCudaMemoryPrivate GstCudaMemoryPrivate;
* Conversely, combining #GST_MAP_CUDA with * Conversely, combining #GST_MAP_CUDA with
* #GST_MAP_READ has the same semantics as though you are reading from * #GST_MAP_READ has the same semantics as though you are reading from
* CUDA device/host memory * CUDA device/host memory
*
* Since: 1.22
*/ */
#define GST_MAP_CUDA (GST_MAP_FLAG_LAST << 1) #define GST_MAP_CUDA (GST_MAP_FLAG_LAST << 1)
/**
* GST_CUDA_MEMORY_TYPE_NAME:
*
* Name of cuda memory type
*
* Since: 1.22
*/
#define GST_CUDA_MEMORY_TYPE_NAME "gst.cuda.memory" #define GST_CUDA_MEMORY_TYPE_NAME "gst.cuda.memory"
/** /**
* GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY: * GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY:
* *
* Name of the caps feature for indicating the use of #GstCudaMemory * Name of the caps feature for indicating the use of #GstCudaMemory
*
* Since: 1.22
*/ */
#define GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY "memory:CUDAMemory" #define GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY "memory:CUDAMemory"
@ -72,6 +106,8 @@ typedef struct _GstCudaMemoryPrivate GstCudaMemoryPrivate;
* to the staging memory * to the staging memory
* @GST_CUDA_MEMORY_TRANSFER_NEED_UPLOAD: the staging memory needs uploading * @GST_CUDA_MEMORY_TRANSFER_NEED_UPLOAD: the staging memory needs uploading
* to the device memory * to the device memory
*
* Since: 1.22
*/ */
typedef enum typedef enum
{ {
@ -79,6 +115,11 @@ typedef enum
GST_CUDA_MEMORY_TRANSFER_NEED_UPLOAD = (GST_MEMORY_FLAG_LAST << 1) GST_CUDA_MEMORY_TRANSFER_NEED_UPLOAD = (GST_MEMORY_FLAG_LAST << 1)
} GstCudaMemoryTransfer; } GstCudaMemoryTransfer;
/**
* GstCudaMemory:
*
* Since: 1.22
*/
struct _GstCudaMemory struct _GstCudaMemory
{ {
GstMemory mem; GstMemory mem;
@ -102,12 +143,16 @@ struct _GstCudaAllocatorClass
GstAllocatorClass parent_class; GstAllocatorClass parent_class;
}; };
GST_CUDA_API
void gst_cuda_memory_init_once (void); void gst_cuda_memory_init_once (void);
GST_CUDA_API
gboolean gst_is_cuda_memory (GstMemory * mem); gboolean gst_is_cuda_memory (GstMemory * mem);
GST_CUDA_API
GType gst_cuda_allocator_get_type (void); GType gst_cuda_allocator_get_type (void);
GST_CUDA_API
GstMemory * gst_cuda_allocator_alloc (GstCudaAllocator * allocator, GstMemory * gst_cuda_allocator_alloc (GstCudaAllocator * allocator,
GstCudaContext * context, GstCudaContext * context,
const GstVideoInfo * info); const GstVideoInfo * info);

View file

@ -21,6 +21,7 @@
#include "config.h" #include "config.h"
#endif #endif
#include "cuda-gst.h"
#include "gstcudanvrtc.h" #include "gstcudanvrtc.h"
GST_DEBUG_CATEGORY_STATIC (gst_cuda_nvrtc_debug); GST_DEBUG_CATEGORY_STATIC (gst_cuda_nvrtc_debug);
@ -39,6 +40,12 @@ _init_debug (void)
} }
} }
/**
* gst_cuda_nvrtc_compile:
* @source: Source code to compile
*
* Since: 1.22
*/
gchar * gchar *
gst_cuda_nvrtc_compile (const gchar * source) gst_cuda_nvrtc_compile (const gchar * source)
{ {

View file

@ -20,12 +20,19 @@
#ifndef __GST_CUDA_NVRTC_H__ #ifndef __GST_CUDA_NVRTC_H__
#define __GST_CUDA_NVRTC_H__ #define __GST_CUDA_NVRTC_H__
#ifndef GST_USE_UNSTABLE_API
#warning "The Cuda library from gst-plugins-bad is unstable API and may change in future."
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
#endif
#include "cuda-prelude.h"
#include <gst/gst.h> #include <gst/gst.h>
#include "gstcudaloader.h" #include "gstcudaloader.h"
#include "gstnvrtcloader.h" #include "gstnvrtcloader.h"
G_BEGIN_DECLS G_BEGIN_DECLS
GST_CUDA_API
gchar * gst_cuda_nvrtc_compile (const gchar * source); gchar * gst_cuda_nvrtc_compile (const gchar * source);
G_END_DECLS G_END_DECLS

View file

@ -29,7 +29,7 @@
#include <gst/gl/gstglfuncs.h> #include <gst/gl/gstglfuncs.h>
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
#include <gst/d3d11/gstd3d11.h> #include <gst/d3d11/gstd3d11.h>
#endif #endif
@ -189,6 +189,8 @@ context_set_cuda_context (GstContext * context, GstCudaContext * cuda_ctx)
* necessary for #GstCudaContext. * necessary for #GstCudaContext.
* *
* Returns: whether a #GstCudaContext exists in @cuda_ctx * Returns: whether a #GstCudaContext exists in @cuda_ctx
*
* Since: 1.22
*/ */
gboolean gboolean
gst_cuda_ensure_element_context (GstElement * element, gint device_id, gst_cuda_ensure_element_context (GstElement * element, gint device_id,
@ -253,6 +255,8 @@ gst_cuda_ensure_element_context (GstElement * element, gint device_id,
* Retrieves the #GstCudaContext in @context and places the result in @cuda_ctx. * Retrieves the #GstCudaContext in @context and places the result in @cuda_ctx.
* *
* Returns: whether the @cuda_ctx could be set successfully * Returns: whether the @cuda_ctx could be set successfully
*
* Since: 1.22
*/ */
gboolean gboolean
gst_cuda_handle_set_context (GstElement * element, gst_cuda_handle_set_context (GstElement * element,
@ -305,6 +309,8 @@ gst_cuda_handle_set_context (GstElement * element,
* *
* Returns: Whether the @query was successfully responded to from the passed * Returns: Whether the @query was successfully responded to from the passed
* @context. * @context.
*
* Since: 1.22
*/ */
gboolean gboolean
gst_cuda_handle_context_query (GstElement * element, gst_cuda_handle_context_query (GstElement * element,
@ -347,10 +353,12 @@ gst_cuda_handle_context_query (GstElement * element,
/** /**
* gst_context_new_cuda_context: * gst_context_new_cuda_context:
* @cuda_ctx: (transfer none) a #GstCudaContext * @cuda_ctx: (transfer none): a #GstCudaContext
* *
* Returns: (transfer full) (nullable): a new #GstContext embedding the @cuda_ctx * Returns: (transfer full) (nullable): a new #GstContext embedding the @cuda_ctx
* or %NULL * or %NULL
*
* Since: 1.22
*/ */
GstContext * GstContext *
gst_context_new_cuda_context (GstCudaContext * cuda_ctx) gst_context_new_cuda_context (GstCudaContext * cuda_ctx)
@ -391,6 +399,8 @@ init_cuda_quark_once (void)
* @id: a #GstCudaQuarkId * @id: a #GstCudaQuarkId
* *
* Returns: the GQuark for given @id or 0 if @id is unknown value * Returns: the GQuark for given @id or 0 if @id is unknown value
*
* Since: 1.22
*/ */
GQuark GQuark
gst_cuda_quark_from_id (GstCudaQuarkId id) gst_cuda_quark_from_id (GstCudaQuarkId id)
@ -413,6 +423,8 @@ gst_cuda_quark_from_id (GstCudaQuarkId id)
* *
* Returns: a new #GstCudaGraphicsResource. * Returns: a new #GstCudaGraphicsResource.
* Free with gst_cuda_graphics_resource_free * Free with gst_cuda_graphics_resource_free
*
* Since: 1.22
*/ */
GstCudaGraphicsResource * GstCudaGraphicsResource *
gst_cuda_graphics_resource_new (GstCudaContext * gst_cuda_graphics_resource_new (GstCudaContext *
@ -436,13 +448,15 @@ gst_cuda_graphics_resource_new (GstCudaContext *
* gst_cuda_graphics_resource_register_gl_buffer: (skip) * gst_cuda_graphics_resource_register_gl_buffer: (skip)
* @resource a #GstCudaGraphicsResource * @resource a #GstCudaGraphicsResource
* @buffer: a GL buffer object * @buffer: a GL buffer object
* @flags: a #CUgraphicsRegisterFlags * @flags: a `CUgraphicsRegisterFlags`
* *
* Register the @buffer for access by CUDA. * Register the @buffer for access by CUDA.
* Must be called from the gl context thread with current cuda context was * Must be called from the gl context thread with current cuda context was
* pushed on the current thread * pushed on the current thread
* *
* Returns: whether @buffer was registered or not * Returns: whether @buffer was registered or not
*
* Since: 1.22
*/ */
gboolean gboolean
gst_cuda_graphics_resource_register_gl_buffer (GstCudaGraphicsResource * gst_cuda_graphics_resource_register_gl_buffer (GstCudaGraphicsResource *
@ -467,17 +481,20 @@ gst_cuda_graphics_resource_register_gl_buffer (GstCudaGraphicsResource *
return TRUE; return TRUE;
} }
#ifdef GST_CUDA_HAS_D3D
/** /**
* gst_cuda_graphics_resource_register_d3d11_resource: (skip) * gst_cuda_graphics_resource_register_d3d11_resource: (skip)
* @resource a #GstCudaGraphicsResource * @resource a #GstCudaGraphicsResource
* @d3d11_resource: a ID3D11Resource * @d3d11_resource: a ID3D11Resource
* @flags: a #CUgraphicsRegisterFlags * @flags: a CUgraphicsRegisterFlags
* *
* Register the @d3d11_resource for accessing by CUDA. * Register the @d3d11_resource for accessing by CUDA.
* Must be called with d3d11 device lock with current cuda context was * Must be called with d3d11 device lock with current cuda context was
* pushed on the current thread * pushed on the current thread
* *
* Returns: whether @d3d11_resource was registered or not * Returns: whether @d3d11_resource was registered or not
*
* Since: 1.22
*/ */
gboolean gboolean
gst_cuda_graphics_resource_register_d3d11_resource (GstCudaGraphicsResource * gst_cuda_graphics_resource_register_d3d11_resource (GstCudaGraphicsResource *
@ -502,6 +519,7 @@ gst_cuda_graphics_resource_register_d3d11_resource (GstCudaGraphicsResource *
return TRUE; return TRUE;
} }
#endif
/** /**
* gst_cuda_graphics_resource_unregister: (skip) * gst_cuda_graphics_resource_unregister: (skip)
@ -511,6 +529,8 @@ gst_cuda_graphics_resource_register_d3d11_resource (GstCudaGraphicsResource *
* For GL resource, this method must be called from gl context thread. * For GL resource, this method must be called from gl context thread.
* Also, current cuda context should be pushed on the current thread * Also, current cuda context should be pushed on the current thread
* before calling this method. * before calling this method.
*
* Since: 1.22
*/ */
void void
gst_cuda_graphics_resource_unregister (GstCudaGraphicsResource * resource) gst_cuda_graphics_resource_unregister (GstCudaGraphicsResource * resource)
@ -532,12 +552,14 @@ gst_cuda_graphics_resource_unregister (GstCudaGraphicsResource * resource)
/** /**
* gst_cuda_graphics_resource_map: (skip) * gst_cuda_graphics_resource_map: (skip)
* @resource: a #GstCudaGraphicsResource * @resource: a #GstCudaGraphicsResource
* @stream: a #CUstream * @stream: a CUstream
* @flags: a #CUgraphicsMapResourceFlags * @flags: a CUgraphicsMapResourceFlags
* *
* Map previously registered resource with map flags * Map previously registered resource with map flags
* *
* Returns: the #CUgraphicsResource if successful or %NULL when failed * Returns: the `CUgraphicsResource` if successful or %NULL when failed
*
* Since: 1.22
*/ */
CUgraphicsResource CUgraphicsResource
gst_cuda_graphics_resource_map (GstCudaGraphicsResource * resource, gst_cuda_graphics_resource_map (GstCudaGraphicsResource * resource,
@ -566,9 +588,11 @@ gst_cuda_graphics_resource_map (GstCudaGraphicsResource * resource,
/** /**
* gst_cuda_graphics_resource_unmap: (skip) * gst_cuda_graphics_resource_unmap: (skip)
* @resource: a #GstCudaGraphicsResource * @resource: a #GstCudaGraphicsResource
* @stream: a #CUstream * @stream: a `CUstream`
* *
* Unmap previously mapped resource * Unmap previously mapped resource
*
* Since: 1.22
*/ */
void void
gst_cuda_graphics_resource_unmap (GstCudaGraphicsResource * resource, gst_cuda_graphics_resource_unmap (GstCudaGraphicsResource * resource,
@ -607,7 +631,7 @@ unregister_resource_from_gl_thread (GstGLContext * gl_context,
} }
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
static void static void
unregister_d3d11_resource (GstCudaGraphicsResource * resource) unregister_d3d11_resource (GstCudaGraphicsResource * resource)
{ {
@ -634,6 +658,8 @@ unregister_d3d11_resource (GstCudaGraphicsResource * resource)
* @resource: a #GstCudaGraphicsResource * @resource: a #GstCudaGraphicsResource
* *
* Free @resource * Free @resource
*
* Since: 1.22
*/ */
void void
gst_cuda_graphics_resource_free (GstCudaGraphicsResource * resource) gst_cuda_graphics_resource_free (GstCudaGraphicsResource * resource)
@ -648,7 +674,7 @@ gst_cuda_graphics_resource_free (GstCudaGraphicsResource * resource)
resource); resource);
} else } else
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (resource->type == GST_CUDA_GRAPHICS_RESOURCE_D3D11_RESOURCE) { if (resource->type == GST_CUDA_GRAPHICS_RESOURCE_D3D11_RESOURCE) {
unregister_d3d11_resource (resource); unregister_d3d11_resource (resource);
} else } else
@ -1250,7 +1276,7 @@ cuda_copy_gl_interop (GstBuffer * dst_buf, const GstVideoInfo * dst_info,
} }
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
static gboolean static gboolean
ensure_d3d11_interop (GstCudaContext * context, GstD3D11Device * device) ensure_d3d11_interop (GstCudaContext * context, GstD3D11Device * device)
{ {
@ -1454,7 +1480,7 @@ gst_cuda_buffer_copy (GstBuffer * dst, GstCudaBufferCopyType dst_type,
{ {
gboolean use_copy_2d = FALSE; gboolean use_copy_2d = FALSE;
GstMemory *dst_mem, *src_mem; GstMemory *dst_mem, *src_mem;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
D3D11_TEXTURE2D_DESC desc; D3D11_TEXTURE2D_DESC desc;
#endif #endif
GstCudaContext *cuda_context; GstCudaContext *cuda_context;
@ -1524,7 +1550,7 @@ gst_cuda_buffer_copy (GstBuffer * dst, GstCudaBufferCopyType dst_type,
} }
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (src_type == GST_CUDA_BUFFER_COPY_D3D11 && gst_is_d3d11_memory (src_mem) && if (src_type == GST_CUDA_BUFFER_COPY_D3D11 && gst_is_d3d11_memory (src_mem) &&
gst_d3d11_memory_get_texture_desc (GST_D3D11_MEMORY_CAST (src_mem), &desc) gst_d3d11_memory_get_texture_desc (GST_D3D11_MEMORY_CAST (src_mem), &desc)
&& desc.Usage == D3D11_USAGE_DEFAULT && gst_is_cuda_memory (dst_mem)) { && desc.Usage == D3D11_USAGE_DEFAULT && gst_is_cuda_memory (dst_mem)) {

View file

@ -20,10 +20,18 @@
#ifndef __GST_CUDA_UTILS_H__ #ifndef __GST_CUDA_UTILS_H__
#define __GST_CUDA_UTILS_H__ #define __GST_CUDA_UTILS_H__
#ifndef GST_USE_UNSTABLE_API
#warning "The Cuda library from gst-plugins-bad is unstable API and may change in future."
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
#endif
#include "cuda-prelude.h"
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#include "cuda-gst.h"
#include "gstcudaloader.h" #include "gstcudaloader.h"
#include "gstcudacontext.h" #include "gstcudacontext.h"
#include "gstcudamemory.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -47,7 +55,7 @@ _gst_cuda_debug(CUresult result, GstDebugCategory * category,
/** /**
* gst_cuda_result: * gst_cuda_result:
* @result: CUDA device API return code #CUresult * @result: CUDA device API return code `CUresult`
* *
* Returns: %TRUE if CUDA device API call result is CUDA_SUCCESS * Returns: %TRUE if CUDA device API call result is CUDA_SUCCESS
*/ */
@ -64,14 +72,22 @@ _gst_cuda_debug(CUresult result, GstDebugCategory * category,
/** /**
* gst_cuda_result: * gst_cuda_result:
* @result: CUDA device API return code #CUresult * @result: CUDA device API return code `CUresult`
* *
* Returns: %TRUE if CUDA device API call result is CUDA_SUCCESS * Returns: %TRUE if CUDA device API call result is CUDA_SUCCESS
*
* Since: 1.22
*/ */
#define gst_cuda_result(result) \ #define gst_cuda_result(result) \
_gst_cuda_debug(result, NULL, __FILE__, GST_FUNCTION, __LINE__) _gst_cuda_debug(result, NULL, __FILE__, GST_FUNCTION, __LINE__)
#endif #endif
/**
* GstCudaQuarkId:
*
* Since: 1.22
*/
typedef enum typedef enum
{ {
GST_CUDA_QUARK_GRAPHICS_RESOURCE = 0, GST_CUDA_QUARK_GRAPHICS_RESOURCE = 0,
@ -80,6 +96,14 @@ typedef enum
GST_CUDA_QUARK_MAX = 1 GST_CUDA_QUARK_MAX = 1
} GstCudaQuarkId; } GstCudaQuarkId;
/**
* GstCudaGraphicsResourceType:
* @GST_CUDA_GRAPHICS_RESSOURCE_NONE: Ressource represents a CUDA buffer.
* @GST_CUDA_GRAPHICS_RESSOURCE_GL_BUFFER: Ressource represents a GL buffer.
* @GST_CUDA_GRAPHICS_RESSOURCE_D3D11_RESOURCE: Ressource represents a D3D resource.
*
* Since: 1.22
*/
typedef enum typedef enum
{ {
GST_CUDA_GRAPHICS_RESOURCE_NONE = 0, GST_CUDA_GRAPHICS_RESOURCE_NONE = 0,
@ -87,6 +111,11 @@ typedef enum
GST_CUDA_GRAPHICS_RESOURCE_D3D11_RESOURCE = 2, GST_CUDA_GRAPHICS_RESOURCE_D3D11_RESOURCE = 2,
} GstCudaGraphicsResourceType; } GstCudaGraphicsResourceType;
/**
* GstCudaGraphicsResource:
*
* Since: 1.22
*/
typedef struct _GstCudaGraphicsResource typedef struct _GstCudaGraphicsResource
{ {
GstCudaContext *cuda_context; GstCudaContext *cuda_context;
@ -101,46 +130,70 @@ typedef struct _GstCudaGraphicsResource
gboolean mapped; gboolean mapped;
} GstCudaGraphicsResource; } GstCudaGraphicsResource;
GST_CUDA_API
gboolean gst_cuda_ensure_element_context (GstElement * element, gboolean gst_cuda_ensure_element_context (GstElement * element,
gint device_id, gint device_id,
GstCudaContext ** cuda_ctx); GstCudaContext ** cuda_ctx);
GST_CUDA_API
gboolean gst_cuda_handle_set_context (GstElement * element, gboolean gst_cuda_handle_set_context (GstElement * element,
GstContext * context, GstContext * context,
gint device_id, gint device_id,
GstCudaContext ** cuda_ctx); GstCudaContext ** cuda_ctx);
GST_CUDA_API
gboolean gst_cuda_handle_context_query (GstElement * element, gboolean gst_cuda_handle_context_query (GstElement * element,
GstQuery * query, GstQuery * query,
GstCudaContext * cuda_ctx); GstCudaContext * cuda_ctx);
GstContext * gst_context_new_cuda_context (GstCudaContext * context); GST_CUDA_API
GstContext * gst_context_new_cuda_context (GstCudaContext * cuda_ctx);
GST_CUDA_API
GQuark gst_cuda_quark_from_id (GstCudaQuarkId id); GQuark gst_cuda_quark_from_id (GstCudaQuarkId id);
GST_CUDA_API
GstCudaGraphicsResource * gst_cuda_graphics_resource_new (GstCudaContext * context, GstCudaGraphicsResource * gst_cuda_graphics_resource_new (GstCudaContext * context,
GstObject * graphics_context, GstObject * graphics_context,
GstCudaGraphicsResourceType type); GstCudaGraphicsResourceType type);
GST_CUDA_API
gboolean gst_cuda_graphics_resource_register_gl_buffer (GstCudaGraphicsResource * resource, gboolean gst_cuda_graphics_resource_register_gl_buffer (GstCudaGraphicsResource * resource,
guint buffer, guint buffer,
CUgraphicsRegisterFlags flags); CUgraphicsRegisterFlags flags);
#ifdef GST_CUDA_HAS_D3D
GST_CUDA_API
gboolean gst_cuda_graphics_resource_register_d3d11_resource (GstCudaGraphicsResource * resource, gboolean gst_cuda_graphics_resource_register_d3d11_resource (GstCudaGraphicsResource * resource,
gpointer d3d11_resource, gpointer d3d11_resource,
CUgraphicsRegisterFlags flags); CUgraphicsRegisterFlags flags);
#endif
GST_CUDA_API
void gst_cuda_graphics_resource_unregister (GstCudaGraphicsResource * resource); void gst_cuda_graphics_resource_unregister (GstCudaGraphicsResource * resource);
GST_CUDA_API
CUgraphicsResource gst_cuda_graphics_resource_map (GstCudaGraphicsResource * resource, CUgraphicsResource gst_cuda_graphics_resource_map (GstCudaGraphicsResource * resource,
CUstream stream, CUstream stream,
CUgraphicsMapResourceFlags flags); CUgraphicsMapResourceFlags flags);
GST_CUDA_API
void gst_cuda_graphics_resource_unmap (GstCudaGraphicsResource * resource, void gst_cuda_graphics_resource_unmap (GstCudaGraphicsResource * resource,
CUstream stream); CUstream stream);
GST_CUDA_API
void gst_cuda_graphics_resource_free (GstCudaGraphicsResource * resource); void gst_cuda_graphics_resource_free (GstCudaGraphicsResource * resource);
/**
* GstCudaBufferCopyType:
* GST_CUDA_BUFFER_COPY_SYSTEM: Copy from/to system memory
* GST_CUDA_BUFFER_COPY_CUDA: Copy from/to cuda memory
* GST_CUDA_BUFFER_COPY_GL: Copy from/to GL memory
* GST_CUDA_BUFFER_COPY_D3D11: Copy from/to D3D11 memory
* GST_CUDA_BUFFER_COPY_NVMM: Copy from/to NVMM memory
*
* Since: 1.22
*/
typedef enum typedef enum
{ {
GST_CUDA_BUFFER_COPY_SYSTEM, GST_CUDA_BUFFER_COPY_SYSTEM,
@ -150,8 +203,35 @@ typedef enum
GST_CUDA_BUFFER_COPY_NVMM, GST_CUDA_BUFFER_COPY_NVMM,
} GstCudaBufferCopyType; } GstCudaBufferCopyType;
/**
* gst_cuda_buffery_copy_type_to_string:
* @type: The #GstCudaBufferCopyType to get name from
*
* Returns: The human readable name of @type
*
* Since: 1.22
*/
GST_CUDA_API
const gchar * gst_cuda_buffery_copy_type_to_string (GstCudaBufferCopyType type); const gchar * gst_cuda_buffery_copy_type_to_string (GstCudaBufferCopyType type);
/**
* gst_cuda_buffer_copy:
* @dst: The buffer into which to copy @src content
* @dst_type: The #GstCudaBufferCopyType to copy @src into
* @dst_info: #GstVideoInfo defining @dst
* @src: The source buffer to copy
* @src_type: The #GstCudaBufferCopyType @src is in
* @src_info: $GstVideoInfo defining @src
* @context: The #GstCudaContext to use to copy @src into @dst
* @stream: The @CUStream to use to copy @src into @dst
*
* Copies @src into @dst with the specified arguments.
*
* Returns: %TRUE if the buffer could be copied %FALSE otherwise
*
* Since: 1.22
*/
GST_CUDA_API
gboolean gst_cuda_buffer_copy (GstBuffer * dst, gboolean gst_cuda_buffer_copy (GstBuffer * dst,
GstCudaBufferCopyType dst_type, GstCudaBufferCopyType dst_type,
const GstVideoInfo * dst_info, const GstVideoInfo * dst_info,

View file

@ -21,13 +21,14 @@
#include "config.h" #include "config.h"
#endif #endif
#include "cuda-gst.h"
#include "gstnvrtcloader.h" #include "gstnvrtcloader.h"
#include "gstcudaloader.h" #include "gstcudaloader.h"
#include <gmodule.h> #include <gmodule.h>
GST_DEBUG_CATEGORY_EXTERN (gst_nvcodec_debug); GST_DEBUG_CATEGORY (gst_nvrtcloader_debug);
#define GST_CAT_DEFAULT gst_nvcodec_debug #define GST_CAT_DEFAULT gst_nvrtcloader_debug
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
#define NVRTC_LIBNAME "libnvrtc.so" #define NVRTC_LIBNAME "libnvrtc.so"
@ -63,6 +64,15 @@ typedef struct _GstNvCodecNvrtcVtahle
static GstNvCodecNvrtcVtahle gst_nvrtc_vtable = { 0, }; static GstNvCodecNvrtcVtahle gst_nvrtc_vtable = { 0, };
/**
* gst_nvrtc_load_library:
*
* Loads the nvrtc library.
*
* Returns: %TRUE if the library could be loaded, %FALSE otherwise
*
* Since: 1.22
*/
gboolean gboolean
gst_nvrtc_load_library (void) gst_nvrtc_load_library (void)
{ {
@ -72,10 +82,19 @@ gst_nvrtc_load_library (void)
const gchar *fname; const gchar *fname;
gint cuda_version; gint cuda_version;
GstNvCodecNvrtcVtahle *vtable; GstNvCodecNvrtcVtahle *vtable;
static gsize debug_initialized = FALSE;
if (gst_nvrtc_vtable.loaded) if (gst_nvrtc_vtable.loaded)
return TRUE; return TRUE;
if (g_once_init_enter (&debug_initialized)) {
GST_DEBUG_CATEGORY_INIT (gst_nvrtcloader_debug, "nvrtcloader", 0,
"nvrtcloader");
g_once_init_leave (&debug_initialized, TRUE);
}
CuDriverGetVersion (&cuda_version); CuDriverGetVersion (&cuda_version);
fname = filename_env = g_getenv ("GST_NVCODEC_NVRTC_LIBNAME"); fname = filename_env = g_getenv ("GST_NVCODEC_NVRTC_LIBNAME");

View file

@ -20,37 +20,19 @@
#ifndef __GST_NVRTC_LOADER_H__ #ifndef __GST_NVRTC_LOADER_H__
#define __GST_NVRTC_LOADER_H__ #define __GST_NVRTC_LOADER_H__
#ifndef GST_USE_UNSTABLE_API
#warning "The Cuda library from gst-plugins-bad is unstable API and may change in future."
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
#endif
#include "cuda-prelude.h"
#include <gst/gst.h> #include <gst/gst.h>
#include <nvrtc.h> #include <nvrtc.h>
G_BEGIN_DECLS G_BEGIN_DECLS
GST_CUDA_API
gboolean gst_nvrtc_load_library (void); gboolean gst_nvrtc_load_library (void);
nvrtcResult NvrtcCompileProgram (nvrtcProgram prog,
int numOptions,
const char** options);
nvrtcResult NvrtcCreateProgram (nvrtcProgram* prog,
const char* src,
const char* name,
int numHeaders,
const char** headers,
const char** includeNames);
nvrtcResult NvrtcDestroyProgram (nvrtcProgram* prog);
nvrtcResult NvrtcGetPTX (nvrtcProgram prog,
char* ptx);
nvrtcResult NvrtcGetPTXSize (nvrtcProgram prog,
size_t* ptxSizeRet);
nvrtcResult NvrtcGetProgramLog (nvrtcProgram prog,
char* log);
nvrtcResult NvrtcGetProgramLogSize (nvrtcProgram prog,
size_t* logSizeRet);
G_END_DECLS G_END_DECLS
#endif /* __GST_NVRTC_LOADER_H__ */ #endif /* __GST_NVRTC_LOADER_H__ */

View file

@ -0,0 +1,101 @@
cuda_sources = [
'gstcudaloader.c',
'gstcudacontext.c',
'gstcudautils.c',
'gstcudamemory.c',
'gstcudabufferpool.c',
'gstcudanvrtc.c',
'gstnvrtcloader.c',
]
cuda_headers = [
'cuda-prelude.h',
'cuda-gst.h',
'gstcudabufferpool.h',
'gstcudacontext.h',
'gstcudaloader.h',
'gstcudamemory.h',
'gstcudanvrtc.h',
'gstcudautils.h',
'gstnvrtcloader.h',
]
cuda_stubinc = include_directories('./stub')
extra_c_args = ['-DGST_USE_UNSTABLE_API']
if gstgl_dep.found()
extra_c_args += ['-DHAVE_NVCODEC_GST_GL=1']
endif
if gstd3d11_dep.found()
extra_c_args += ['-DGST_CUDA_HAS_D3D=1', '-DCOBJMACROS']
endif
pkg_name = 'gstreamer-cuda-' + api_version
gstcuda= library('gstcuda-' + api_version,
cuda_sources,
c_args : gst_plugins_bad_args + extra_c_args + ['-DGST_USE_UNSTABLE_API', '-DBUILDING_GST_CUDA', '-DG_LOG_DOMAIN="GStreamer-Cuda"'],
cpp_args : gst_plugins_bad_args,
include_directories : [configinc, libsinc, cuda_stubinc],
version : libversion,
soversion : soversion,
install : true,
dependencies : [gstbase_dep, gmodule_dep, gstvideo_dep, gstglproto_dep, gstd3d11_dep]
)
gen_sources = []
library_def = {'lib': gstcuda}
if build_gir
gir_includes = ['Gst-1.0', 'GstBase-1.0', 'GstVideo-1.0', 'CudaGst-1.0']
if gstglproto_dep.found()
gir_includes += ['GstGL-1.0']
endif
cuda_gir = {
'sources' : files('stub/cuda.h', 'stub/cudaGL.h'),
'namespace' : 'CudaGst',
'nsversion' : api_version,
'identifier_prefix' : 'CU',
'symbol_prefix' : 'cu',
'export_packages' : pkg_name,
'includes' : [],
'install' : true,
'extra_args' : [],
'dependencies' : [],
}
gir = {
'sources' : cuda_sources + cuda_headers,
'namespace' : 'GstCuda',
'nsversion' : api_version,
'identifier_prefix' : 'Gst',
'symbol_prefix' : 'gst',
'export_packages' : pkg_name,
'includes' : gir_includes,
'install' : true,
'extra_args' : gir_init_section + ['-DGST_USE_UNSTABLE_API'],
'dependencies' : [gstbase_dep, gstvideo_dep, gstglproto_dep],
}
if not static_build
cudagst_gir = gnome.generate_gir(gstcuda, kwargs: cuda_gir)
gir += {'includes': gir['includes'] + [cudagst_gir[0]]}
gst_cuda_gir = gnome.generate_gir(gstcuda, kwargs: gir)
gen_sources += gst_cuda_gir
endif
library_def += {'gir': [gir, cuda_gir]}
endif
libraries += [[pkg_name, library_def]]
pkgconfig.generate(gstcuda,
libraries : [gstbase_dep, gmodule_dep, gstvideo_dep, gstglproto_dep],
variables : pkgconfig_variables,
subdirs : pkgconfig_subdirs,
name : pkg_name,
description : 'Unstable library to work with CUDA inside GStreamer',
)
install_headers(cuda_headers, subdir : 'gstreamer-1.0/gst/cuda')
gstcuda_dep = declare_dependency(link_with : gstcuda,
include_directories : [libsinc],
dependencies : [gstbase_dep, gmodule_dep, gstvideo_dep, gstglproto_dep],
sources: gen_sources)

View file

@ -132,11 +132,6 @@ typedef struct
gsize Height; gsize Height;
} CUDA_MEMCPY2D; } CUDA_MEMCPY2D;
typedef enum
{
CU_GL_DEVICE_LIST_ALL = 0x01,
} CUGLDeviceList;
typedef enum typedef enum
{ {
CU_D3D11_DEVICE_LIST_ALL = 0x01, CU_D3D11_DEVICE_LIST_ALL = 0x01,
@ -225,7 +220,6 @@ typedef struct
#define cuMemcpy2D cuMemcpy2D_v2 #define cuMemcpy2D cuMemcpy2D_v2
#define cuMemcpy2DAsync cuMemcpy2DAsync_v2 #define cuMemcpy2DAsync cuMemcpy2DAsync_v2
#define cuMemFree cuMemFree_v2 #define cuMemFree cuMemFree_v2
#define cuGLGetDevices cuGLGetDevices_v2
#define CU_TRSF_READ_AS_INTEGER 1 #define CU_TRSF_READ_AS_INTEGER 1

View file

@ -0,0 +1,16 @@
#ifndef __GST_CUDA_GLSTUB_H__
#define __GST_CUDA_GLSTUB_H__
#include <glib.h>
G_BEGIN_DECLS
typedef enum
{
CU_GL_DEVICE_LIST_ALL = 0x01,
} CUGLDeviceList;
#define cuGLGetDevices cuGLGetDevices_v2
G_END_DECLS
#endif /* __GST_CUDA_GLSTUB_H__ */

View file

@ -6,6 +6,8 @@ subdir('basecamerabinsrc')
subdir('codecparsers') subdir('codecparsers')
subdir('codecs') subdir('codecs')
subdir('d3d11') subdir('d3d11')
# cuda can depend on d3d11
subdir('cuda')
subdir('insertbin') subdir('insertbin')
subdir('interfaces') subdir('interfaces')
subdir('isoff') subdir('isoff')

View file

@ -46,9 +46,9 @@
#endif #endif
#include "cuda-converter.h" #include "cuda-converter.h"
#include "gstcudautils.h" #include <gst/cuda/gstcudautils.h>
#include "gstcudaloader.h" #include <gst/cuda/gstcudaloader.h>
#include "gstcudanvrtc.h" #include <gst/cuda/gstcudanvrtc.h>
#include <string.h> #include <string.h>
#define CUDA_BLOCK_X 16 #define CUDA_BLOCK_X 16

View file

@ -21,8 +21,8 @@
#define __GST_CUDA_CONVERTER_H__ #define __GST_CUDA_CONVERTER_H__
#include <gst/video/video.h> #include <gst/video/video.h>
#include "gstcudacontext.h" #include <gst/cuda/gstcudacontext.h>
#include "gstcudamemory.h" #include <gst/cuda/gstcudamemory.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -32,8 +32,9 @@
#endif #endif
#include "gstcudabasefilter.h" #include "gstcudabasefilter.h"
#include "gstcudautils.h"
#include "gstcudaformat.h" #include "gstcudaformat.h"
#include <gst/cuda/gstcudautils.h>
#include <string.h> #include <string.h>
GST_DEBUG_CATEGORY_STATIC (gst_cuda_base_filter_debug); GST_DEBUG_CATEGORY_STATIC (gst_cuda_base_filter_debug);

View file

@ -29,8 +29,9 @@
# include <config.h> # include <config.h>
#endif #endif
#include <gst/cuda/gstcudautils.h>
#include "gstcudabasetransform.h" #include "gstcudabasetransform.h"
#include "gstcudautils.h"
GST_DEBUG_CATEGORY_STATIC (gst_cuda_base_transform_debug); GST_DEBUG_CATEGORY_STATIC (gst_cuda_base_transform_debug);
#define GST_CAT_DEFAULT gst_cuda_base_transform_debug #define GST_CAT_DEFAULT gst_cuda_base_transform_debug

View file

@ -23,8 +23,8 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/base/gstbasetransform.h> #include <gst/base/gstbasetransform.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#include "gstcudacontext.h" #include <gst/cuda/gstcudacontext.h>
#include "gstcudabufferpool.h" #include <gst/cuda/gstcudabufferpool.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -41,8 +41,9 @@
# include <config.h> # include <config.h>
#endif #endif
#include <gst/cuda/gstcudautils.h>
#include "gstcudaconvert.h" #include "gstcudaconvert.h"
#include "gstcudautils.h"
GST_DEBUG_CATEGORY_STATIC (gst_cuda_convert_debug); GST_DEBUG_CATEGORY_STATIC (gst_cuda_convert_debug);
#define GST_CAT_DEFAULT gst_cuda_convert_debug #define GST_CAT_DEFAULT gst_cuda_convert_debug

View file

@ -21,10 +21,11 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/cuda/gstcudaloader.h>
#include <gst/cuda/gstnvrtcloader.h>
#include <gst/cuda/gstcudanvrtc.h>
#include "gstcudafilter.h" #include "gstcudafilter.h"
#include "gstcudaloader.h"
#include "gstnvrtcloader.h"
#include "gstcudanvrtc.h"
#include "gstcudaconvert.h" #include "gstcudaconvert.h"
#include "gstcudascale.h" #include "gstcudascale.h"

View file

@ -33,7 +33,7 @@
#include "gstcudabasetransform.h" #include "gstcudabasetransform.h"
#include "gstcudamemorycopy.h" #include "gstcudamemorycopy.h"
#include "gstcudaformat.h" #include "gstcudaformat.h"
#include "gstcudautils.h" #include <gst/cuda/gstcudautils.h>
#ifdef HAVE_NVCODEC_NVMM #ifdef HAVE_NVCODEC_NVMM
#include "gstcudanvmm.h" #include "gstcudanvmm.h"
#endif #endif
@ -41,7 +41,7 @@
#ifdef HAVE_NVCODEC_GST_GL #ifdef HAVE_NVCODEC_GST_GL
#include <gst/gl/gl.h> #include <gst/gl/gl.h>
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
#include <gst/d3d11/gstd3d11.h> #include <gst/d3d11/gstd3d11.h>
#endif #endif
@ -67,7 +67,7 @@ struct _GstCudaMemoryCopy
GstGLContext *gl_context; GstGLContext *gl_context;
GstGLContext *other_gl_context; GstGLContext *other_gl_context;
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
GstD3D11Device *d3d11_device; GstD3D11Device *d3d11_device;
#endif #endif
}; };
@ -158,7 +158,7 @@ gst_cuda_memory_copy_set_context (GstElement * element, GstContext * context)
static gboolean static gboolean
gst_cuda_memory_copy_transform_stop (GstBaseTransform * trans) gst_cuda_memory_copy_transform_stop (GstBaseTransform * trans)
{ {
#if defined(HAVE_NVCODEC_GST_GL) || defined(HAVE_NVCODEC_GST_D3D11) #if defined(HAVE_NVCODEC_GST_GL) || defined(GST_CUDA_HAS_D3D)
GstCudaMemoryCopy *self = GST_CUDA_MEMORY_COPY (trans); GstCudaMemoryCopy *self = GST_CUDA_MEMORY_COPY (trans);
# ifdef HAVE_NVCODEC_GST_GL # ifdef HAVE_NVCODEC_GST_GL
@ -166,7 +166,7 @@ gst_cuda_memory_copy_transform_stop (GstBaseTransform * trans)
gst_clear_object (&self->gl_context); gst_clear_object (&self->gl_context);
gst_clear_object (&self->other_gl_context); gst_clear_object (&self->other_gl_context);
# endif # endif
# ifdef HAVE_NVCODEC_GST_D3D11 # ifdef GST_CUDA_HAS_D3D
gst_clear_object (&self->d3d11_device); gst_clear_object (&self->d3d11_device);
# endif # endif
#endif #endif
@ -244,7 +244,7 @@ create_transform_caps (GstCaps * caps, gboolean to_cuda)
new_caps = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_GL_MEMORY); new_caps = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
ret = gst_caps_merge (ret, new_caps); ret = gst_caps_merge (ret, new_caps);
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
new_caps = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY); new_caps = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY);
ret = gst_caps_merge (ret, new_caps); ret = gst_caps_merge (ret, new_caps);
#endif #endif
@ -368,7 +368,7 @@ gst_cuda_memory_copy_ensure_gl_context (GstCudaMemoryCopy * self)
} }
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
static gboolean static gboolean
gst_cuda_memory_copy_ensure_d3d11_interop (GstCudaContext * context, gst_cuda_memory_copy_ensure_d3d11_interop (GstCudaContext * context,
GstD3D11Device * device) GstD3D11Device * device)
@ -462,7 +462,7 @@ gst_cuda_memory_copy_propose_allocation (GstBaseTransform * trans,
pool = gst_gl_buffer_pool_new (self->gl_context); pool = gst_gl_buffer_pool_new (self->gl_context);
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
} else if (features && gst_caps_features_contains (features, } else if (features && gst_caps_features_contains (features,
GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY) && GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY) &&
gst_cuda_memory_copy_ensure_d3d11_context (self)) { gst_cuda_memory_copy_ensure_d3d11_context (self)) {
@ -554,7 +554,7 @@ gst_cuda_memory_copy_decide_allocation (GstBaseTransform * trans,
#ifdef HAVE_NVCODEC_GST_GL #ifdef HAVE_NVCODEC_GST_GL
gboolean need_gl = FALSE; gboolean need_gl = FALSE;
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
gboolean need_d3d11 = FALSE; gboolean need_d3d11 = FALSE;
#endif #endif
#ifdef HAVE_NVCODEC_NVMM #ifdef HAVE_NVCODEC_NVMM
@ -578,7 +578,7 @@ gst_cuda_memory_copy_decide_allocation (GstBaseTransform * trans,
need_gl = TRUE; need_gl = TRUE;
} }
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
else if (features && gst_caps_features_contains (features, else if (features && gst_caps_features_contains (features,
GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY) && GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY) &&
gst_cuda_memory_copy_ensure_d3d11_context (self)) { gst_cuda_memory_copy_ensure_d3d11_context (self)) {
@ -632,7 +632,7 @@ gst_cuda_memory_copy_decide_allocation (GstBaseTransform * trans,
pool = gst_gl_buffer_pool_new (self->gl_context); pool = gst_gl_buffer_pool_new (self->gl_context);
} }
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
else if (need_d3d11) { else if (need_d3d11) {
GST_DEBUG_OBJECT (self, "creating d3d11 pool"); GST_DEBUG_OBJECT (self, "creating d3d11 pool");
pool = gst_d3d11_buffer_pool_new (self->d3d11_device); pool = gst_d3d11_buffer_pool_new (self->d3d11_device);
@ -711,7 +711,7 @@ static gboolean
gst_cuda_memory_copy_query (GstBaseTransform * trans, gst_cuda_memory_copy_query (GstBaseTransform * trans,
GstPadDirection direction, GstQuery * query) GstPadDirection direction, GstQuery * query)
{ {
#if defined(HAVE_NVCODEC_GST_GL) || defined(HAVE_NVCODEC_GST_D3D11) #if defined(HAVE_NVCODEC_GST_GL) || defined(GST_CUDA_HAS_D3D)
GstCudaMemoryCopy *self = GST_CUDA_MEMORY_COPY (trans); GstCudaMemoryCopy *self = GST_CUDA_MEMORY_COPY (trans);
switch (GST_QUERY_TYPE (query)) { switch (GST_QUERY_TYPE (query)) {
@ -724,7 +724,7 @@ gst_cuda_memory_copy_query (GstBaseTransform * trans,
if (ret) if (ret)
return TRUE; return TRUE;
# endif # endif
# ifdef HAVE_NVCODEC_GST_D3D11 # ifdef GST_CUDA_HAS_D3D
ret = gst_d3d11_handle_context_query (GST_ELEMENT (self), query, ret = gst_d3d11_handle_context_query (GST_ELEMENT (self), query,
self->d3d11_device); self->d3d11_device);
if (ret) if (ret)
@ -787,7 +787,7 @@ gst_cuda_memory_copy_transform (GstBaseTransform * trans, GstBuffer * inbuf,
GstCudaBufferCopyType in_type = GST_CUDA_BUFFER_COPY_SYSTEM; GstCudaBufferCopyType in_type = GST_CUDA_BUFFER_COPY_SYSTEM;
GstCudaBufferCopyType out_type = GST_CUDA_BUFFER_COPY_SYSTEM; GstCudaBufferCopyType out_type = GST_CUDA_BUFFER_COPY_SYSTEM;
gboolean use_device_copy = FALSE; gboolean use_device_copy = FALSE;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
D3D11_TEXTURE2D_DESC desc; D3D11_TEXTURE2D_DESC desc;
#endif #endif
@ -816,7 +816,7 @@ gst_cuda_memory_copy_transform (GstBaseTransform * trans, GstBuffer * inbuf,
} else if (self->gl_context && gst_is_gl_memory_pbo (in_mem)) { } else if (self->gl_context && gst_is_gl_memory_pbo (in_mem)) {
in_type = GST_CUDA_BUFFER_COPY_GL; in_type = GST_CUDA_BUFFER_COPY_GL;
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
} else if (self->d3d11_device && gst_is_d3d11_memory (in_mem) } else if (self->d3d11_device && gst_is_d3d11_memory (in_mem)
&& gst_d3d11_memory_get_texture_desc (GST_D3D11_MEMORY_CAST (in_mem), && gst_d3d11_memory_get_texture_desc (GST_D3D11_MEMORY_CAST (in_mem),
&desc) && desc.Usage == D3D11_USAGE_DEFAULT) { &desc) && desc.Usage == D3D11_USAGE_DEFAULT) {
@ -836,7 +836,7 @@ gst_cuda_memory_copy_transform (GstBaseTransform * trans, GstBuffer * inbuf,
} else if (self->gl_context && gst_is_gl_memory_pbo (out_mem)) { } else if (self->gl_context && gst_is_gl_memory_pbo (out_mem)) {
out_type = GST_CUDA_BUFFER_COPY_GL; out_type = GST_CUDA_BUFFER_COPY_GL;
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
} else if (self->d3d11_device && gst_is_d3d11_memory (out_mem) } else if (self->d3d11_device && gst_is_d3d11_memory (out_mem)
&& gst_d3d11_memory_get_texture_desc (GST_D3D11_MEMORY_CAST (out_mem), && gst_d3d11_memory_get_texture_desc (GST_D3D11_MEMORY_CAST (out_mem),
&desc) && desc.Usage == D3D11_USAGE_DEFAULT) { &desc) && desc.Usage == D3D11_USAGE_DEFAULT) {
@ -1030,7 +1030,7 @@ gst_cuda_memory_copy_register (GstPlugin * plugin, guint rank)
#ifdef HAVE_NVCODEC_GST_GL #ifdef HAVE_NVCODEC_GST_GL
GstCaps *gl_caps; GstCaps *gl_caps;
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
GstCaps *d3d11_caps; GstCaps *d3d11_caps;
#endif #endif
GstCaps *upload_sink_caps; GstCaps *upload_sink_caps;
@ -1059,7 +1059,7 @@ gst_cuda_memory_copy_register (GstPlugin * plugin, guint rank)
gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY, GST_CUDA_GL_FORMATS)); (GST_CAPS_FEATURE_MEMORY_GL_MEMORY, GST_CUDA_GL_FORMATS));
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
d3d11_caps = d3d11_caps =
gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY, GST_CUDA_D3D11_FORMATS)); (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY, GST_CUDA_D3D11_FORMATS));
@ -1069,7 +1069,7 @@ gst_cuda_memory_copy_register (GstPlugin * plugin, guint rank)
#ifdef HAVE_NVCODEC_GST_GL #ifdef HAVE_NVCODEC_GST_GL
upload_sink_caps = gst_caps_merge (upload_sink_caps, gst_caps_copy (gl_caps)); upload_sink_caps = gst_caps_merge (upload_sink_caps, gst_caps_copy (gl_caps));
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
upload_sink_caps = upload_sink_caps =
gst_caps_merge (upload_sink_caps, gst_caps_copy (d3d11_caps)); gst_caps_merge (upload_sink_caps, gst_caps_copy (d3d11_caps));
#endif #endif
@ -1105,7 +1105,7 @@ gst_cuda_memory_copy_register (GstPlugin * plugin, guint rank)
#ifdef HAVE_NVCODEC_GST_GL #ifdef HAVE_NVCODEC_GST_GL
download_src_caps = gst_caps_merge (download_src_caps, gl_caps); download_src_caps = gst_caps_merge (download_src_caps, gl_caps);
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
download_src_caps = gst_caps_merge (download_src_caps, d3d11_caps); download_src_caps = gst_caps_merge (download_src_caps, d3d11_caps);
#endif #endif
#ifdef HAVE_NVCODEC_NVMM #ifdef HAVE_NVCODEC_NVMM

View file

@ -50,8 +50,9 @@
# include <config.h> # include <config.h>
#endif #endif
#include <gst/cuda/gstcudautils.h>
#include "gstcudascale.h" #include "gstcudascale.h"
#include "gstcudautils.h"
GST_DEBUG_CATEGORY_STATIC (gst_cuda_scale_debug); GST_DEBUG_CATEGORY_STATIC (gst_cuda_scale_debug);
#define GST_CAT_DEFAULT gst_cuda_scale_debug #define GST_CAT_DEFAULT gst_cuda_scale_debug

View file

@ -21,7 +21,7 @@
#define __GST_CUVID_LOADER_H__ #define __GST_CUVID_LOADER_H__
#include <gst/gst.h> #include <gst/gst.h>
#include "stub/cuda.h" #include "cuda.h"
#include "nvcuvid.h" #include "nvcuvid.h"
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -22,8 +22,8 @@
#endif #endif
#include "gstnvbaseenc.h" #include "gstnvbaseenc.h"
#include "gstcudautils.h" #include <gst/cuda/gstcudautils.h>
#include "gstcudabufferpool.h" #include <gst/cuda/gstcudabufferpool.h>
#include <gst/pbutils/codec-utils.h> #include <gst/pbutils/codec-utils.h>

View file

@ -23,7 +23,7 @@
#include "gstnvenc.h" #include "gstnvenc.h"
#include <gst/video/gstvideoencoder.h> #include <gst/video/gstvideoencoder.h>
#include "gstcudacontext.h" #include <gst/cuda/gstcudacontext.h>
#define GST_TYPE_NV_BASE_ENC \ #define GST_TYPE_NV_BASE_ENC \
(gst_nv_base_enc_get_type()) (gst_nv_base_enc_get_type())

View file

@ -29,9 +29,11 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/cuda/gstcudautils.h>
#include <gst/cuda/gstcudabufferpool.h>
#include "gstcuvidloader.h"
#include "gstnvdec.h" #include "gstnvdec.h"
#include "gstcudautils.h"
#include "gstcudabufferpool.h"
#include <string.h> #include <string.h>

View file

@ -33,12 +33,12 @@
#include <gst/gl/gstglfuncs.h> #include <gst/gl/gstglfuncs.h>
#endif #endif
#include "nvcuvid.h"
#include <gst/video/video.h> #include <gst/video/video.h>
#include <gst/codecparsers/gsth264parser.h> #include <gst/codecparsers/gsth264parser.h>
#include <gst/codecparsers/gsth265parser.h> #include <gst/codecparsers/gsth265parser.h>
#include "gstcuvidloader.h" #include <gst/cuda/gstcudaloader.h>
#include "gstcudaloader.h" #include <gst/cuda/gstcudacontext.h>
#include "gstcudacontext.h"
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -50,9 +50,9 @@
#include <gst/gl/gstglfuncs.h> #include <gst/gl/gstglfuncs.h>
#endif #endif
#include "gstcudamemory.h" #include <gst/cuda/gstcudamemory.h>
#include <gst/cuda/gstcudabufferpool.h>
#include "gstnvdecoder.h" #include "gstnvdecoder.h"
#include "gstcudabufferpool.h"
#include <string.h> #include <string.h>
GST_DEBUG_CATEGORY_EXTERN (gst_nv_decoder_debug); GST_DEBUG_CATEGORY_EXTERN (gst_nv_decoder_debug);

View file

@ -22,7 +22,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#include "gstcudautils.h" #include <gst/cuda/gstcudautils.h>
#include "gstcuvidloader.h" #include "gstcuvidloader.h"
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -24,7 +24,8 @@
#include "gstnvenc.h" #include "gstnvenc.h"
#include "gstnvh264enc.h" #include "gstnvh264enc.h"
#include "gstnvh265enc.h" #include "gstnvh265enc.h"
#include "gstcudabufferpool.h" #include <gst/cuda/gstcudautils.h>
#include <gst/cuda/gstcudabufferpool.h>
#include <gmodule.h> #include <gmodule.h>

View file

@ -22,8 +22,8 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#include <gst/cuda/gstcudaloader.h>
#include "gstcudaloader.h"
#include "nvEncodeAPI.h" #include "nvEncodeAPI.h"
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -22,12 +22,13 @@
#endif #endif
#include "gstnvencoder.h" #include "gstnvencoder.h"
#include "gstcudautils.h"
#include "gstcudamemory.h" #include <gst/cuda/gstcudautils.h>
#include "gstcudabufferpool.h" #include <gst/cuda/gstcudamemory.h>
#include <gst/cuda/gstcudabufferpool.h>
#include <string.h> #include <string.h>
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
#include <gst/d3d11/gstd3d11.h> #include <gst/d3d11/gstd3d11.h>
#endif #endif
@ -57,7 +58,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_nv_encoder_debug);
struct _GstNvEncoderPrivate struct _GstNvEncoderPrivate
{ {
GstCudaContext *context; GstCudaContext *context;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
GstD3D11Device *device; GstD3D11Device *device;
#endif #endif
@ -179,7 +180,7 @@ gst_nv_encoder_set_context (GstElement * element, GstContext * context)
GstNvEncoder *self = GST_NV_ENCODER (element); GstNvEncoder *self = GST_NV_ENCODER (element);
GstNvEncoderPrivate *priv = self->priv; GstNvEncoderPrivate *priv = self->priv;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (priv->d3d11_mode) { if (priv->d3d11_mode) {
gst_d3d11_handle_set_context_for_adapter_luid (element, gst_d3d11_handle_set_context_for_adapter_luid (element,
context, priv->dxgi_adapter_luid, &priv->device); context, priv->dxgi_adapter_luid, &priv->device);
@ -224,7 +225,7 @@ gst_nv_encoder_device_lock (GstNvEncoder * self)
{ {
GstNvEncoderPrivate *priv = self->priv; GstNvEncoderPrivate *priv = self->priv;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (priv->d3d11_mode) { if (priv->d3d11_mode) {
gst_d3d11_device_lock (priv->device); gst_d3d11_device_lock (priv->device);
return TRUE; return TRUE;
@ -237,7 +238,7 @@ gst_nv_encoder_device_lock (GstNvEncoder * self)
static gboolean static gboolean
gst_nv_encoder_device_unlock (GstNvEncoder * self) gst_nv_encoder_device_unlock (GstNvEncoder * self)
{ {
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
GstNvEncoderPrivate *priv = self->priv; GstNvEncoderPrivate *priv = self->priv;
if (priv->d3d11_mode) { if (priv->d3d11_mode) {
@ -338,7 +339,7 @@ gst_nv_encoder_drain (GstNvEncoder * self, gboolean locked)
return TRUE; return TRUE;
} }
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
static gboolean static gboolean
gst_nv_encoder_open_d3d11_device (GstNvEncoder * self) gst_nv_encoder_open_d3d11_device (GstNvEncoder * self)
{ {
@ -374,7 +375,7 @@ gst_nv_encoder_open (GstVideoEncoder * encoder)
GstNvEncoder *self = GST_NV_ENCODER (encoder); GstNvEncoder *self = GST_NV_ENCODER (encoder);
GstNvEncoderPrivate *priv = self->priv; GstNvEncoderPrivate *priv = self->priv;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (priv->d3d11_mode) { if (priv->d3d11_mode) {
return gst_nv_encoder_open_d3d11_device (self); return gst_nv_encoder_open_d3d11_device (self);
} }
@ -396,7 +397,7 @@ gst_nv_encoder_close (GstVideoEncoder * encoder)
GstNvEncoderPrivate *priv = self->priv; GstNvEncoderPrivate *priv = self->priv;
gst_clear_object (&priv->context); gst_clear_object (&priv->context);
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
gst_clear_object (&priv->device); gst_clear_object (&priv->device);
#endif #endif
@ -423,7 +424,7 @@ gst_nv_encoder_handle_context_query (GstNvEncoder * self, GstQuery * query)
{ {
GstNvEncoderPrivate *priv = self->priv; GstNvEncoderPrivate *priv = self->priv;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (priv->d3d11_mode) { if (priv->d3d11_mode) {
return gst_d3d11_handle_context_query (GST_ELEMENT (self), return gst_d3d11_handle_context_query (GST_ELEMENT (self),
query, priv->device); query, priv->device);
@ -493,7 +494,7 @@ gst_nv_encoder_propose_allocation (GstVideoEncoder * encoder, GstQuery * query)
} }
features = gst_caps_get_features (caps, 0); features = gst_caps_get_features (caps, 0);
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (priv->d3d11_mode && features && gst_caps_features_contains (features, if (priv->d3d11_mode && features && gst_caps_features_contains (features,
GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY)) { GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY)) {
GST_DEBUG_OBJECT (self, "upstream support d3d11 memory"); GST_DEBUG_OBJECT (self, "upstream support d3d11 memory");
@ -967,7 +968,7 @@ gst_nv_encoder_open_encode_session (GstNvEncoder * self, gpointer * session)
session_params.apiVersion = gst_nvenc_get_api_version (); session_params.apiVersion = gst_nvenc_get_api_version ();
NVENCSTATUS status; NVENCSTATUS status;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (priv->d3d11_mode) { if (priv->d3d11_mode) {
session_params.deviceType = NV_ENC_DEVICE_TYPE_DIRECTX; session_params.deviceType = NV_ENC_DEVICE_TYPE_DIRECTX;
session_params.device = gst_d3d11_device_get_device_handle (priv->device); session_params.device = gst_d3d11_device_get_device_handle (priv->device);
@ -988,7 +989,7 @@ gst_nv_encoder_open_encode_session (GstNvEncoder * self, gpointer * session)
return TRUE; return TRUE;
} }
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
static GstBufferPool * static GstBufferPool *
gst_nv_encoder_create_d3d11_pool (GstNvEncoder * self, gst_nv_encoder_create_d3d11_pool (GstNvEncoder * self,
GstVideoCodecState * state) GstVideoCodecState * state)
@ -1033,7 +1034,7 @@ gst_nv_encoder_create_pool (GstNvEncoder * self, GstVideoCodecState * state)
GstNvEncoderPrivate *priv = self->priv; GstNvEncoderPrivate *priv = self->priv;
GstStructure *config; GstStructure *config;
GstBufferPool *pool = NULL; GstBufferPool *pool = NULL;
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (priv->d3d11_mode) if (priv->d3d11_mode)
return gst_nv_encoder_create_d3d11_pool (self, state); return gst_nv_encoder_create_d3d11_pool (self, state);
#endif #endif
@ -1402,7 +1403,7 @@ gst_nv_encoder_prepare_task_input_cuda (GstNvEncoder * self,
return GST_FLOW_OK; return GST_FLOW_OK;
} }
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
static GstBuffer * static GstBuffer *
gst_nv_encoder_copy_d3d11 (GstNvEncoder * self, gst_nv_encoder_copy_d3d11 (GstNvEncoder * self,
GstBuffer * src_buffer, GstBufferPool * pool, gboolean shared) GstBuffer * src_buffer, GstBufferPool * pool, gboolean shared)
@ -1679,7 +1680,7 @@ gst_nv_encoder_prepare_task_input (GstNvEncoder * self,
const GstVideoInfo * info, GstBuffer * buffer, gpointer session, const GstVideoInfo * info, GstBuffer * buffer, gpointer session,
GstBufferPool * pool, GstNvEncoderTask * task) GstBufferPool * pool, GstNvEncoderTask * task)
{ {
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
GstNvEncoderPrivate *priv = self->priv; GstNvEncoderPrivate *priv = self->priv;
if (priv->d3d11_mode) { if (priv->d3d11_mode) {
return gst_nv_encoder_prepare_task_input_d3d11 (self, info, buffer, return gst_nv_encoder_prepare_task_input_d3d11 (self, info, buffer,

View file

@ -22,7 +22,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
#include <gst/d3d11/gstd3d11.h> #include <gst/d3d11/gstd3d11.h>
#endif #endif
@ -30,7 +30,7 @@
#include "nvEncodeAPI.h" #include "nvEncodeAPI.h"
#include "gstnvenc.h" #include "gstnvenc.h"
#include "gstcudamemory.h" #include <gst/cuda/gstcudamemory.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -74,8 +74,9 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/cuda/gstcudautils.h>
#include "gstnvh264dec.h" #include "gstnvh264dec.h"
#include "gstcudautils.h"
#include "gstnvdecoder.h" #include "gstnvdecoder.h"
#include <string.h> #include <string.h>

View file

@ -1741,7 +1741,7 @@ gst_nv_h264_encoder_create_class_data (GstObject * device, gpointer session,
system_caps = gst_caps_from_string (sink_caps_str.c_str ()); system_caps = gst_caps_from_string (sink_caps_str.c_str ());
sink_caps = gst_caps_copy (system_caps); sink_caps = gst_caps_copy (system_caps);
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (d3d11_mode) { if (d3d11_mode) {
gst_caps_set_features (sink_caps, 0, gst_caps_set_features (sink_caps, 0,
gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY, NULL)); gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY, NULL));
@ -1843,7 +1843,7 @@ gst_nv_h264_encoder_register_cuda (GstPlugin * plugin, GstCudaContext * context,
g_free (feature_name); g_free (feature_name);
} }
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
void void
gst_nv_h264_encoder_register_d3d11 (GstPlugin * plugin, GstD3D11Device * device, gst_nv_h264_encoder_register_d3d11 (GstPlugin * plugin, GstD3D11Device * device,
guint rank) guint rank)

View file

@ -27,7 +27,7 @@ void gst_nv_h264_encoder_register_cuda (GstPlugin * plugin,
GstCudaContext * context, GstCudaContext * context,
guint rank); guint rank);
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
void gst_nv_h264_encoder_register_d3d11 (GstPlugin * plugin, void gst_nv_h264_encoder_register_d3d11 (GstPlugin * plugin,
GstD3D11Device * device, GstD3D11Device * device,
guint rank); guint rank);

View file

@ -74,8 +74,8 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/cuda/gstcudautils.h>
#include "gstnvh265dec.h" #include "gstnvh265dec.h"
#include "gstcudautils.h"
#include "gstnvdecoder.h" #include "gstnvdecoder.h"
#include <string.h> #include <string.h>

View file

@ -1752,7 +1752,7 @@ gst_nv_h265_encoder_create_class_data (GstObject * device, gpointer session,
system_caps = gst_caps_from_string (sink_caps_str.c_str ()); system_caps = gst_caps_from_string (sink_caps_str.c_str ());
sink_caps = gst_caps_copy (system_caps); sink_caps = gst_caps_copy (system_caps);
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (d3d11_mode) { if (d3d11_mode) {
gst_caps_set_features (sink_caps, 0, gst_caps_set_features (sink_caps, 0,
gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY, NULL)); gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY, NULL));
@ -1854,7 +1854,7 @@ gst_nv_h265_encoder_register_cuda (GstPlugin * plugin, GstCudaContext * context,
g_free (feature_name); g_free (feature_name);
} }
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
void void
gst_nv_h265_encoder_register_d3d11 (GstPlugin * plugin, GstD3D11Device * device, gst_nv_h265_encoder_register_d3d11 (GstPlugin * plugin, GstD3D11Device * device,
guint rank) guint rank)

View file

@ -27,7 +27,7 @@ void gst_nv_h265_encoder_register_cuda (GstPlugin * plugin,
GstCudaContext * context, GstCudaContext * context,
guint rank); guint rank);
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
void gst_nv_h265_encoder_register_d3d11 (GstPlugin * plugin, void gst_nv_h265_encoder_register_d3d11 (GstPlugin * plugin,
GstD3D11Device * device, GstD3D11Device * device,
guint rank); guint rank);

View file

@ -21,8 +21,9 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/cuda/gstcudautils.h>
#include "gstnvvp8dec.h" #include "gstnvvp8dec.h"
#include "gstcudautils.h"
#include "gstnvdecoder.h" #include "gstnvdecoder.h"
#include <string.h> #include <string.h>

View file

@ -21,8 +21,9 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/cuda/gstcudautils.h>
#include "gstnvvp9dec.h" #include "gstnvvp9dec.h"
#include "gstcudautils.h"
#include "gstnvdecoder.h" #include "gstnvdecoder.h"
#include <string.h> #include <string.h>

View file

@ -4,20 +4,13 @@ nvcodec_sources = [
'gstnvbaseenc.c', 'gstnvbaseenc.c',
'gstnvh264enc.c', 'gstnvh264enc.c',
'gstnvh265enc.c', 'gstnvh265enc.c',
'gstcudaloader.c',
'gstnvdec.c', 'gstnvdec.c',
'gstcuvidloader.c', 'gstcuvidloader.c',
'gstcudacontext.c',
'gstcudautils.c',
'gstnvdecoder.c', 'gstnvdecoder.c',
'gstnvh264dec.c', 'gstnvh264dec.c',
'gstnvh265dec.c', 'gstnvh265dec.c',
'gstcudamemory.c',
'gstcudabufferpool.c',
'gstcudabasetransform.c', 'gstcudabasetransform.c',
'gstcudamemorycopy.c', 'gstcudamemorycopy.c',
'gstcudanvrtc.c',
'gstnvrtcloader.c',
'cuda-converter.c', 'cuda-converter.c',
'gstcudafilter.c', 'gstcudafilter.c',
'gstcudabasefilter.c', 'gstcudabasefilter.c',
@ -38,7 +31,7 @@ if get_option('nvcodec').disabled()
subdir_done() subdir_done()
endif endif
plugin_incdirs = [configinc, include_directories('./stub')] plugin_incdirs = [configinc, cuda_stubinc]
extra_args = ['-DGST_USE_UNSTABLE_API'] extra_args = ['-DGST_USE_UNSTABLE_API']
if gstgl_dep.found() if gstgl_dep.found()
@ -46,7 +39,7 @@ if gstgl_dep.found()
endif endif
if gstd3d11_dep.found() if gstd3d11_dep.found()
extra_args += ['-DHAVE_NVCODEC_GST_D3D11=1', '-DCOBJMACROS'] extra_args += ['-DGST_CUDA_HAS_D3D=1', '-DCOBJMACROS']
endif endif
if host_system == 'linux' if host_system == 'linux'
@ -84,7 +77,7 @@ gstnvcodec = library('gstnvcodec',
cpp_args : gst_plugins_bad_args + extra_args, cpp_args : gst_plugins_bad_args + extra_args,
override_options: override_opt, override_options: override_opt,
include_directories : plugin_incdirs, include_directories : plugin_incdirs,
dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstgl_dep, gstglproto_dep, gmodule_dep, gstcodecs_dep, gstd3d11_dep], dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstgl_dep, gstglproto_dep, gmodule_dep, gstcodecs_dep, gstd3d11_dep, gstcuda_dep],
install : true, install : true,
install_dir : plugins_install_dir, install_dir : plugins_install_dir,
) )

View file

@ -38,12 +38,12 @@
#include "gstnvdecoder.h" #include "gstnvdecoder.h"
#include "gstcudamemorycopy.h" #include "gstcudamemorycopy.h"
#include "gstcudafilter.h" #include "gstcudafilter.h"
#include "gstcudamemory.h" #include <gst/cuda/gstcudamemory.h>
#ifdef HAVE_NVCODEC_NVMM #ifdef HAVE_NVCODEC_NVMM
#include "gstcudanvmm.h" #include "gstcudanvmm.h"
#endif #endif
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
#include <gst/d3d11/gstd3d11.h> #include <gst/d3d11/gstd3d11.h>
#endif #endif
#include "gstnvh264encoder.h" #include "gstnvh264encoder.h"
@ -235,7 +235,7 @@ plugin_init (GstPlugin * plugin)
} }
if (nvenc_available) { if (nvenc_available) {
#ifdef HAVE_NVCODEC_GST_D3D11 #ifdef GST_CUDA_HAS_D3D
if (g_win32_check_windows_version (6, 0, 0, G_WIN32_OS_ANY)) { if (g_win32_check_windows_version (6, 0, 0, G_WIN32_OS_ANY)) {
gint64 adapter_luid; gint64 adapter_luid;
GstD3D11Device *d3d11_device; GstD3D11Device *d3d11_device;

View file

@ -1109,7 +1109,10 @@ if build_gstgl
include_directories : [libsinc, compat_includes], include_directories : [libsinc, compat_includes],
sources: gen_sources, sources: gen_sources,
dependencies : [video_dep, gst_base_dep]) dependencies : [video_dep, gst_base_dep])
gstglproto_dep = declare_dependency(dependencies : [gstgl_dep] + gl_lib_deps) gstglproto_dep = declare_dependency(
dependencies : [gstgl_dep] + gl_lib_deps,
sources: gen_sources
)
meson.override_dependency('gstreamer-gl-1.0', gstgl_dep) meson.override_dependency('gstreamer-gl-1.0', gstgl_dep)
meson.override_dependency('gstreamer-gl-prototypes-1.0', gstglproto_dep) meson.override_dependency('gstreamer-gl-prototypes-1.0', gstglproto_dep)