Commit 4d585c64 authored by Seungha Yang's avatar Seungha Yang 🐑 Committed by GStreamer Marge Bot
Browse files

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: <!1198>
parent 9c21923f
Pipeline #137148 waiting for manual action with stages
in 17 seconds
......@@ -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;
}
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
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