summaryrefslogtreecommitdiff
path: root/sys/nvcodec
diff options
context:
space:
mode:
authorSeungha Yang <seungha@centricular.com>2020-04-22 14:57:12 +0900
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>2020-04-24 09:23:10 +0000
commit4d585c64d11a12eb873459eb627d642c3f754b61 (patch)
tree885c3db4e0a8d807ae735b07b48bea188725131b /sys/nvcodec
parent9c21923f0451a88e81d0dc5b4cd6affdfc11a93d (diff)
downloadgstreamer-plugins-bad-4d585c64d11a12eb873459eb627d642c3f754b61.tar.gz
nvcodec: Add suppport for environment based primary h264 decoder implementation
Introduce GST_USE_NV_STATELESS_CODEC environment to allow user to select primary nvidia decoder implementation. In case the environment GST_USE_NV_STATELESS_CODEC=h264 was set, old nvidia h264 decoder element will not be registered. Instead, both nvh264dec and nvh264sldec factory name will create gstcodecs based new nvidia h264 decoder element. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1198>
Diffstat (limited to 'sys/nvcodec')
-rw-r--r--sys/nvcodec/gstnvh264dec.c21
-rw-r--r--sys/nvcodec/gstnvh264dec.h3
-rw-r--r--sys/nvcodec/plugin.c40
3 files changed, 54 insertions, 10 deletions
diff --git a/sys/nvcodec/gstnvh264dec.c b/sys/nvcodec/gstnvh264dec.c
index a4a4dc38d..ad1c558b4 100644
--- a/sys/nvcodec/gstnvh264dec.c
+++ b/sys/nvcodec/gstnvh264dec.c
@@ -1011,7 +1011,7 @@ gst_nv_h264_dec_subclass_init (gpointer klass, GstNvH264DecClassData * cdata)
void
gst_nv_h264_dec_register (GstPlugin * plugin, guint device_id, guint rank,
- GstCaps * sink_caps, GstCaps * src_caps)
+ GstCaps * sink_caps, GstCaps * src_caps, gboolean is_primary)
{
GTypeQuery type_query;
GTypeInfo type_info = { 0, };
@@ -1048,14 +1048,25 @@ gst_nv_h264_dec_register (GstPlugin * plugin, guint device_id, guint rank,
type_info.class_init = (GClassInitFunc) gst_nv_h264_dec_subclass_init;
type_info.class_data = cdata;
- type_name = g_strdup ("GstNvH264StatelessDec");
- feature_name = g_strdup ("nvh264sldec");
+ if (is_primary) {
+ type_name = g_strdup ("GstNvH264StatelessPrimaryDec");
+ feature_name = g_strdup ("nvh264dec");
+ } else {
+ type_name = g_strdup ("GstNvH264StatelessDec");
+ feature_name = g_strdup ("nvh264sldec");
+ }
if (g_type_from_name (type_name) != 0) {
g_free (type_name);
g_free (feature_name);
- type_name = g_strdup_printf ("GstNvH264StatelessDevice%dDec", device_id);
- feature_name = g_strdup_printf ("nvh264sldevice%ddec", device_id);
+ if (is_primary) {
+ type_name =
+ g_strdup_printf ("GstNvH264StatelessPrimaryDevice%dDec", device_id);
+ feature_name = g_strdup_printf ("nvh264device%ddec", device_id);
+ } else {
+ type_name = g_strdup_printf ("GstNvH264StatelessDevice%dDec", device_id);
+ feature_name = g_strdup_printf ("nvh264sldevice%ddec", device_id);
+ }
is_default = FALSE;
}
diff --git a/sys/nvcodec/gstnvh264dec.h b/sys/nvcodec/gstnvh264dec.h
index f29f776a5..c1cf8219c 100644
--- a/sys/nvcodec/gstnvh264dec.h
+++ b/sys/nvcodec/gstnvh264dec.h
@@ -41,7 +41,8 @@ void gst_nv_h264_dec_register (GstPlugin * plugin,
guint device_id,
guint rank,
GstCaps * sink_caps,
- GstCaps * src_caps);
+ GstCaps * src_caps,
+ gboolean is_primary);
G_END_DECLS
diff --git a/sys/nvcodec/plugin.c b/sys/nvcodec/plugin.c
index 1d813c018..e35031431 100644
--- a/sys/nvcodec/plugin.c
+++ b/sys/nvcodec/plugin.c
@@ -52,6 +52,8 @@ plugin_init (GstPlugin * plugin)
/* hardcoded minimum supported version */
guint api_major_ver = 8;
guint api_minor_ver = 1;
+ const gchar *env;
+ gboolean use_h264_sl_dec = FALSE;
GST_DEBUG_CATEGORY_INIT (gst_nvcodec_debug, "nvcodec", 0, "nvcodec");
GST_DEBUG_CATEGORY_INIT (gst_nvdec_debug, "nvdec", 0, "nvdec");
@@ -89,6 +91,26 @@ plugin_init (GstPlugin * plugin)
return TRUE;
}
+ /* check environment to determine primary h264decoder */
+ env = g_getenv ("GST_USE_NV_STATELESS_CODEC");
+ if (env) {
+ gchar **split;
+ gchar **iter;
+
+ split = g_strsplit (env, ",", 0);
+
+ for (iter = split; *iter; iter++) {
+ if (g_ascii_strcasecmp (*iter, "h264") == 0) {
+ GST_INFO ("Found %s in GST_USE_NV_STATELESS_CODEC environment", *iter);
+ use_h264_sl_dec = TRUE;
+ break;
+ }
+
+ }
+
+ g_strfreev (split);
+ }
+
for (i = 0; i < dev_count; i++) {
CUdevice cuda_device;
CUcontext cuda_ctx;
@@ -115,6 +137,7 @@ plugin_init (GstPlugin * plugin)
GstCaps *sink_template = NULL;
GstCaps *src_template = NULL;
cudaVideoCodec codec = (cudaVideoCodec) j;
+ gboolean register_cuviddec = TRUE;
if (gst_nv_decoder_check_device_caps (cuda_ctx,
codec, &sink_template, &src_template)) {
@@ -124,12 +147,21 @@ plugin_init (GstPlugin * plugin)
"src template %" GST_PTR_FORMAT, codec_name,
sink_template, src_template);
- gst_nvdec_plugin_init (plugin,
- i, codec, codec_name, sink_template, src_template);
-
if (codec == cudaVideoCodec_H264) {
gst_nv_h264_dec_register (plugin,
- i, GST_RANK_SECONDARY, sink_template, src_template);
+ i, GST_RANK_SECONDARY, sink_template, src_template, FALSE);
+ if (use_h264_sl_dec) {
+ GST_INFO ("Skip register cuvid parser based nvh264dec");
+ register_cuviddec = FALSE;
+
+ gst_nv_h264_dec_register (plugin,
+ i, GST_RANK_PRIMARY, sink_template, src_template, TRUE);
+ }
+ }
+
+ if (register_cuviddec) {
+ gst_nvdec_plugin_init (plugin,
+ i, codec, codec_name, sink_template, src_template);
}
gst_caps_unref (sink_template);