From 733c109ce962ad2d6380bbe8f165f25aad475fa8 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Thu, 25 Jul 2019 16:45:21 +0900 Subject: [PATCH] nvcodec: Clean up pointless return values around plugin init Any plugin which returned FALSE from plugin_init will be blacklisted so the plugin will be unusable even if an user install required runtime dependency next time. So that's the reason why nvcodec returns TRUE always. This commit is to remove possible misreading code. --- sys/nvcodec/gstnvdec.c | 17 ++++++----------- sys/nvcodec/gstnvdec.h | 2 +- sys/nvcodec/gstnvenc.c | 22 +++++++--------------- sys/nvcodec/gstnvenc.h | 2 +- sys/nvcodec/plugin.c | 6 ++---- 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/sys/nvcodec/gstnvdec.c b/sys/nvcodec/gstnvdec.c index f82652ffaa..60834afa2e 100644 --- a/sys/nvcodec/gstnvdec.c +++ b/sys/nvcodec/gstnvdec.c @@ -1122,7 +1122,7 @@ typedef struct cudaVideoChromaFormat format; } GstNvdecChromaMap; -static gboolean +static void gst_nvdec_register (GstPlugin * plugin, GType type, cudaVideoCodec codec_type, const gchar * codec, const gchar * sink_caps_string, guint rank, gint device_count) @@ -1274,8 +1274,6 @@ gst_nvdec_register (GstPlugin * plugin, GType type, cudaVideoCodec codec_type, gst_clear_caps (&sink_templ); gst_clear_caps (&src_templ); } - - return TRUE; } typedef struct @@ -1316,13 +1314,12 @@ const GstNvCodecMap codec_map[] = { {cudaVideoCodec_VP9, "vp9", "video/x-vp9"} }; -gboolean +void gst_nvdec_plugin_init (GstPlugin * plugin) { gint i; CUresult cuda_ret; gint dev_count = 0; - gboolean ret = TRUE; GST_DEBUG_CATEGORY_INIT (gst_nvdec_debug_category, "nvdec", 0, "Debug category for the nvdec element"); @@ -1346,26 +1343,24 @@ gst_nvdec_plugin_init (GstPlugin * plugin) codec_map[i].codec_name, 0, GST_RANK_PRIMARY, sink_templ, src_templ); } - return TRUE; + return; } cuda_ret = CuInit (0); if (cuda_ret != CUDA_SUCCESS) { GST_ERROR ("Failed to initialize CUDA API"); - return TRUE; + return; } cuda_ret = CuDeviceGetCount (&dev_count); if (cuda_ret != CUDA_SUCCESS || dev_count == 0) { GST_ERROR ("No CUDA devices detected"); - return TRUE; + return; } for (i = 0; i < G_N_ELEMENTS (codec_map); i++) { - ret &= gst_nvdec_register (plugin, GST_TYPE_NVDEC, codec_map[i].codec, + gst_nvdec_register (plugin, GST_TYPE_NVDEC, codec_map[i].codec, codec_map[i].codec_name, codec_map[i].sink_caps_string, GST_RANK_PRIMARY, dev_count); } - - return ret; } diff --git a/sys/nvcodec/gstnvdec.h b/sys/nvcodec/gstnvdec.h index 8578c7c67b..727448c9f9 100644 --- a/sys/nvcodec/gstnvdec.h +++ b/sys/nvcodec/gstnvdec.h @@ -87,7 +87,7 @@ struct _GstNvDecClass GType gst_nvdec_get_type (void); -gboolean gst_nvdec_plugin_init (GstPlugin * plugin); +void gst_nvdec_plugin_init (GstPlugin * plugin); G_END_DECLS diff --git a/sys/nvcodec/gstnvenc.c b/sys/nvcodec/gstnvenc.c index fe17dd6147..d580d27865 100644 --- a/sys/nvcodec/gstnvenc.c +++ b/sys/nvcodec/gstnvenc.c @@ -635,7 +635,7 @@ gst_nv_enc_get_supported_codec_profiles (gpointer enc, GUID codec_id) return ret; } -static gboolean +static void gst_nv_enc_register (GstPlugin * plugin, GType type, GUID codec_id, const gchar * codec, guint rank, gint device_count) { @@ -780,22 +780,18 @@ gst_nv_enc_register (GstPlugin * plugin, GType type, GUID codec_id, gst_clear_caps (&sink_templ); gst_clear_caps (&src_templ); } - - return TRUE; } -gboolean +void gst_nvenc_plugin_init (GstPlugin * plugin) { - gboolean ret = TRUE; - GST_DEBUG_CATEGORY_INIT (gst_nvenc_debug, "nvenc", 0, "Nvidia NVENC encoder"); nvenc_api.version = NV_ENCODE_API_FUNCTION_LIST_VER; if (!load_nvenc_library ()) { GST_INFO ("Failed to load nvenc library"); - return TRUE; + return; } if (nvEncodeAPICreateInstance (&nvenc_api) != NV_ENC_SUCCESS) { @@ -809,23 +805,19 @@ gst_nvenc_plugin_init (GstPlugin * plugin) cuda_ret = CuInit (0); if (cuda_ret != CUDA_SUCCESS) { GST_ERROR ("Failed to initialize CUDA API"); - return TRUE; + return; } cuda_ret = CuDeviceGetCount (&dev_count); if (cuda_ret != CUDA_SUCCESS || dev_count == 0) { GST_ERROR ("No CUDA devices detected"); - return TRUE; + return; } - ret &= - gst_nv_enc_register (plugin, GST_TYPE_NV_H264_ENC, + gst_nv_enc_register (plugin, GST_TYPE_NV_H264_ENC, NV_ENC_CODEC_H264_GUID, "h264", GST_RANK_PRIMARY * 2, dev_count); - ret &= - gst_nv_enc_register (plugin, GST_TYPE_NV_H265_ENC, + gst_nv_enc_register (plugin, GST_TYPE_NV_H265_ENC, NV_ENC_CODEC_HEVC_GUID, "h265", GST_RANK_PRIMARY * 2, dev_count); } - - return ret; } diff --git a/sys/nvcodec/gstnvenc.h b/sys/nvcodec/gstnvenc.h index 07e0920b75..39a0409ac3 100644 --- a/sys/nvcodec/gstnvenc.h +++ b/sys/nvcodec/gstnvenc.h @@ -48,7 +48,7 @@ GValue * gst_nv_enc_get_supported_codec_profiles (gpointer enc, GUID codec_id); -gboolean gst_nvenc_plugin_init (GstPlugin * plugin); +void gst_nvenc_plugin_init (GstPlugin * plugin); #endif /* __GST_NVENC_H_INCLUDED__ */ diff --git a/sys/nvcodec/plugin.c b/sys/nvcodec/plugin.c index 3dc27afbe1..385df55984 100644 --- a/sys/nvcodec/plugin.c +++ b/sys/nvcodec/plugin.c @@ -38,19 +38,17 @@ static gboolean plugin_init (GstPlugin * plugin) { - gboolean ret = TRUE; - if (!gst_cuda_load_library ()) return TRUE; #if HAVE_NVCODEC_GST_GL /* FIXME: make nvdec usable without OpenGL dependency */ if (gst_cuvid_load_library ()) { - ret &= gst_nvdec_plugin_init (plugin); + gst_nvdec_plugin_init (plugin); } #endif - ret &= gst_nvenc_plugin_init (plugin); + gst_nvenc_plugin_init (plugin); return TRUE; }