Commit ff2c257c authored by Seungha Yang's avatar Seungha Yang 🐑
Browse files

nvenc: Port to dynamic CUDA library loading

parent 5f1ff979
......@@ -976,7 +976,7 @@ gst_nv_base_enc_free_buffers (GstNvBaseEnc * nvenc)
if (nvenc->gl_input) {
struct gl_input_resource *in_gl_resource = nvenc->input_bufs[i];
cuCtxPushCurrent (nvenc->cuda_ctx);
CuCtxPushCurrent (nvenc->cuda_ctx);
if (in_gl_resource->mapped) {
GST_LOG_OBJECT (nvenc, "Unmap resource %p", in_gl_resource);
......@@ -998,14 +998,14 @@ gst_nv_base_enc_free_buffers (GstNvBaseEnc * nvenc)
GST_ERROR_OBJECT (nvenc, "Failed to unregister resource %p, ret %d",
in_gl_resource, nv_ret);
nv_ret = cuMemFree ((CUdeviceptr) in_gl_resource->cuda_pointer);
nv_ret = CuMemFree ((CUdeviceptr) in_gl_resource->cuda_pointer);
if (nv_ret != NV_ENC_SUCCESS) {
GST_ERROR_OBJECT (nvenc, "Failed to free CUDA device memory, ret %d",
nv_ret);
}
g_free (in_gl_resource);
cuCtxPopCurrent (NULL);
CuCtxPopCurrent (NULL);
} else
#endif
{
......@@ -1300,7 +1300,7 @@ gst_nv_base_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
pixel_depth += GST_VIDEO_INFO_COMP_DEPTH (info, i);
}
cuCtxPushCurrent (nvenc->cuda_ctx);
CuCtxPushCurrent (nvenc->cuda_ctx);
for (i = 0; i < nvenc->n_bufs; ++i) {
struct gl_input_resource *in_gl_resource =
g_new0 (struct gl_input_resource, 1);
......@@ -1313,13 +1313,13 @@ gst_nv_base_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
/* scratch buffer for non-contigious planer into a contigious buffer */
cu_ret =
cuMemAllocPitch ((CUdeviceptr *) & in_gl_resource->cuda_pointer,
CuMemAllocPitch ((CUdeviceptr *) & in_gl_resource->cuda_pointer,
&in_gl_resource->cuda_stride, input_width,
_get_frame_data_height (info), 16);
if (cu_ret != CUDA_SUCCESS) {
const gchar *err;
cuGetErrorString (cu_ret, &err);
CuGetErrorString (cu_ret, &err);
GST_ERROR_OBJECT (nvenc, "failed to alocate cuda scratch buffer "
"ret %d error :%s", cu_ret, err);
g_assert_not_reached ();
......@@ -1347,7 +1347,7 @@ gst_nv_base_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
g_async_queue_push (nvenc->in_bufs_pool, nvenc->input_bufs[i]);
}
cuCtxPopCurrent (NULL);
CuCtxPopCurrent (NULL);
} else
#endif
{
......@@ -1501,7 +1501,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
guint i;
CUDA_MEMCPY2D param;
cuCtxPushCurrent (data->nvenc->cuda_ctx);
CuCtxPushCurrent (data->nvenc->cuda_ctx);
data_pointer = data->in_gl_resource->cuda_pointer;
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (data->info); i++) {
guint plane_n_components;
......@@ -1527,7 +1527,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
gl_mem->mem.tex_id);
cuda_ret =
cuGraphicsGLRegisterBuffer (&data->in_gl_resource->cuda_texture,
CuGraphicsGLRegisterBuffer (&data->in_gl_resource->cuda_texture,
gl_buf_obj->id, cudaGraphicsRegisterFlagsReadOnly);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to register GL texture %u to cuda "
......@@ -1536,7 +1536,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
}
cuda_ret =
cuGraphicsMapResources (1, &data->in_gl_resource->cuda_texture, 0);
CuGraphicsMapResources (1, &data->in_gl_resource->cuda_texture, 0);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to map GL texture %u into cuda "
"ret :%d", gl_mem->mem.tex_id, cuda_ret);
......@@ -1544,7 +1544,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
}
cuda_ret =
cuGraphicsResourceGetMappedPointer (&data->in_gl_resource->
CuGraphicsResourceGetMappedPointer (&data->in_gl_resource->
cuda_plane_pointers[i], &data->in_gl_resource->cuda_num_bytes,
data->in_gl_resource->cuda_texture);
if (cuda_ret != cudaSuccess) {
......@@ -1571,7 +1571,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
param.WidthInBytes = _get_plane_width (data->info, i) * plane_n_components;
param.Height = _get_plane_height (data->info, i);
cuda_ret = cuMemcpy2D (&param);
cuda_ret = CuMemcpy2D (&param);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to copy GL texture %u into cuda "
"ret :%d", gl_mem->mem.tex_id, cuda_ret);
......@@ -1579,7 +1579,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
}
cuda_ret =
cuGraphicsUnmapResources (1, &data->in_gl_resource->cuda_texture, 0);
CuGraphicsUnmapResources (1, &data->in_gl_resource->cuda_texture, 0);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to unmap GL texture %u from cuda "
"ret :%d", gl_mem->mem.tex_id, cuda_ret);
......@@ -1587,7 +1587,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
}
cuda_ret =
cuGraphicsUnregisterResource (data->in_gl_resource->cuda_texture);
CuGraphicsUnregisterResource (data->in_gl_resource->cuda_texture);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to unregister GL texture %u from "
"cuda ret :%d", gl_mem->mem.tex_id, cuda_ret);
......@@ -1599,7 +1599,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
data->in_gl_resource->cuda_stride *
_get_plane_height (&data->nvenc->input_info, i);
}
cuCtxPopCurrent (NULL);
CuCtxPopCurrent (NULL);
}
#endif
......
......@@ -283,7 +283,7 @@ gst_nvenc_create_cuda_context (guint device_id)
GST_INFO ("Initialising CUDA..");
cres = cuInit (0);
cres = CuInit (0);
if (cres != CUDA_SUCCESS) {
GST_WARNING ("Failed to initialise CUDA, error code: 0x%08x", cres);
......@@ -292,7 +292,7 @@ gst_nvenc_create_cuda_context (guint device_id)
GST_INFO ("Initialised CUDA");
cres = cuDeviceGetCount (&dev_count);
cres = CuDeviceGetCount (&dev_count);
if (cres != CUDA_SUCCESS || dev_count == 0) {
GST_WARNING ("No CUDA devices detected");
return NULL;
......@@ -300,11 +300,11 @@ gst_nvenc_create_cuda_context (guint device_id)
GST_INFO ("%d CUDA device(s) detected", dev_count);
for (i = 0; i < dev_count; ++i) {
if (cuDeviceGet (&cdev, i) == CUDA_SUCCESS
&& cuDeviceGetName (name, sizeof (name), cdev) == CUDA_SUCCESS
&& cuDeviceGetAttribute (&maj,
if (CuDeviceGet (&cdev, i) == CUDA_SUCCESS
&& CuDeviceGetName (name, sizeof (name), cdev) == CUDA_SUCCESS
&& CuDeviceGetAttribute (&maj,
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, cdev) == CUDA_SUCCESS
&& cuDeviceGetAttribute (&min,
&& CuDeviceGetAttribute (&min,
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR,
cdev) == CUDA_SUCCESS) {
GST_INFO ("GPU #%d supports NVENC: %s (%s) (Compute SM %d.%d)", i,
......@@ -321,12 +321,12 @@ gst_nvenc_create_cuda_context (guint device_id)
return NULL;
}
if (cuCtxCreate (&cuda_ctx, 0, cuda_dev) != CUDA_SUCCESS) {
if (CuCtxCreate (&cuda_ctx, 0, cuda_dev) != CUDA_SUCCESS) {
GST_WARNING ("Failed to create CUDA context for cuda device %d", cuda_dev);
return NULL;
}
if (cuCtxPopCurrent (&old_ctx) != CUDA_SUCCESS) {
if (CuCtxPopCurrent (&old_ctx) != CUDA_SUCCESS) {
return NULL;
}
......@@ -339,7 +339,7 @@ gboolean
gst_nvenc_destroy_cuda_context (CUcontext ctx)
{
GST_INFO ("Destroying CUDA context %p", ctx);
return (cuCtxDestroy (ctx) == CUDA_SUCCESS);
return (CuCtxDestroy (ctx) == CUDA_SUCCESS);
}
static gboolean
......
......@@ -23,8 +23,8 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstcudaloader.h"
#include "nvEncodeAPI.h"
#include <cuda.h>
GST_DEBUG_CATEGORY_EXTERN (gst_nvenc_debug);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment