cuda: Report device open error

Call gst_cuda_result() with CUDA_ERROR_NO_DEVICE error code if
we could not open device, so that application can catch the error

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6006>
This commit is contained in:
Seungha Yang 2024-01-29 23:25:35 +09:00 committed by GStreamer Marge Bot
parent cd6d62ddf0
commit 51162acc31
5 changed files with 15 additions and 1 deletions

View file

@ -489,6 +489,8 @@ and/or use gtk-doc annotations. -->
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/cuda/stub/cuda.h"/>
<member name="success" value="0" c:identifier="CUDA_SUCCESS">
</member>
<member name="error_no_device" value="100" c:identifier="CUDA_ERROR_NO_DEVICE">
</member>
<member name="error_already_mapped" value="208" c:identifier="CUDA_ERROR_ALREADY_MAPPED">
</member>
<member name="error_not_supported" value="801" c:identifier="CUDA_ERROR_NOT_SUPPORTED">

View file

@ -39,6 +39,7 @@ typedef gint CUdevice;
typedef enum
{
CUDA_SUCCESS = 0,
CUDA_ERROR_NO_DEVICE = 100,
CUDA_ERROR_ALREADY_MAPPED = 208,
CUDA_ERROR_NOT_SUPPORTED = 801,
} CUresult;

View file

@ -460,7 +460,13 @@ gst_nv_base_enc_open_encode_session (GstNvBaseEnc * nvenc)
params.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
nv_ret = NvEncOpenEncodeSessionEx (&params, &nvenc->encoder);
return nv_ret == NV_ENC_SUCCESS;
if (nv_ret != NV_ENC_SUCCESS) {
/* Report error to abort if GST_CUDA_CRITICAL_ERRORS is configured */
gst_cuda_result (CUDA_ERROR_NO_DEVICE);
return FALSE;
}
return TRUE;
}
static gboolean

View file

@ -173,6 +173,8 @@ GstNvEncObject::CreateInstance (GstElement * client, GstObject * device,
status = NvEncOpenEncodeSessionEx (params, &session);
if (!NVENC_IS_SUCCESS (status, nullptr)) {
GST_ERROR_OBJECT (device, "NvEncOpenEncodeSessionEx failed");
/* Report error to abort if GST_CUDA_CRITICAL_ERRORS is configured */
gst_cuda_result (CUDA_ERROR_NO_DEVICE);
return nullptr;
}

View file

@ -121,6 +121,9 @@ plugin_init (GstPlugin * plugin)
CuGetErrorString (cuda_ret, &err_desc);
GST_ERROR ("Failed to init cuda, cuInit ret: 0x%x: %s: %s",
(int) cuda_ret, err_name, err_desc);
/* to abort if GST_CUDA_CRITICAL_ERRORS is configured */
gst_cuda_result (CUDA_ERROR_NO_DEVICE);
return TRUE;
}