From 8d7cab1f0d830bf80a5b025be129ff0c97a275a4 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Tue, 21 Feb 2023 19:54:12 +0900 Subject: [PATCH] nvcodec: Remove stateful decoders Use H.264, H.265, VP8, and VP9 stateless decoders unconditionally and don't register its stateful counterpart Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1768 Fixes: https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1621 Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1432 Part-of: --- .../sys/nvcodec/gstnvh264dec.cpp | 22 ++--- .../sys/nvcodec/gstnvh264dec.h | 3 +- .../sys/nvcodec/gstnvh265dec.cpp | 22 ++--- .../sys/nvcodec/gstnvh265dec.h | 3 +- .../sys/nvcodec/gstnvvp8dec.cpp | 22 ++--- .../gst-plugins-bad/sys/nvcodec/gstnvvp8dec.h | 3 +- .../sys/nvcodec/gstnvvp9dec.cpp | 22 ++--- .../gst-plugins-bad/sys/nvcodec/gstnvvp9dec.h | 3 +- .../gst-plugins-bad/sys/nvcodec/plugin.c | 81 +++---------------- 9 files changed, 38 insertions(+), 143 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh264dec.cpp b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh264dec.cpp index 415555b043..9cd83ac1d6 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh264dec.cpp +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh264dec.cpp @@ -274,7 +274,7 @@ gst_nv_h264_dec_class_init (GstNvH264DecClass * klass, parent_class = (GTypeClass *) g_type_class_peek_parent (klass); gst_element_class_set_static_metadata (element_class, - "NVDEC H.264 Stateless Decoder", + "NVDEC H.264 Decoder", "Codec/Decoder/Video/Hardware", "NVIDIA H.264 video decoder", "Seungha Yang "); @@ -1091,7 +1091,7 @@ gst_nv_h264_dec_get_preferred_output_delay (GstH264Decoder * decoder, void gst_nv_h264_dec_register (GstPlugin * plugin, guint device_id, guint rank, - GstCaps * sink_caps, GstCaps * src_caps, gboolean is_primary) + GstCaps * sink_caps, GstCaps * src_caps) { GType type; gchar *type_name; @@ -1135,25 +1135,15 @@ gst_nv_h264_dec_register (GstPlugin * plugin, guint device_id, guint rank, cdata->src_caps = gst_caps_ref (src_caps); cdata->cuda_device_id = device_id; - if (is_primary) { - type_name = g_strdup ("GstNvH264Dec"); - feature_name = g_strdup ("nvh264dec"); - } else { - type_name = g_strdup ("GstNvH264SLDec"); - feature_name = g_strdup ("nvh264sldec"); - } + type_name = g_strdup ("GstNvH264Dec"); + feature_name = g_strdup ("nvh264dec"); while (g_type_from_name (type_name)) { index++; g_free (type_name); g_free (feature_name); - if (is_primary) { - type_name = g_strdup_printf ("GstNvH264Device%dDec", index); - feature_name = g_strdup_printf ("nvh264device%ddec", index); - } else { - type_name = g_strdup_printf ("GstNvH264SLDevice%dDec", index); - feature_name = g_strdup_printf ("nvh264sldevice%ddec", index); - } + type_name = g_strdup_printf ("GstNvH264Device%dDec", index); + feature_name = g_strdup_printf ("nvh264device%ddec", index); } type_info.class_data = cdata; diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh264dec.h b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh264dec.h index 69d209a13b..e19cd21178 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh264dec.h +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh264dec.h @@ -29,8 +29,7 @@ void gst_nv_h264_dec_register (GstPlugin * plugin, guint device_id, guint rank, GstCaps * sink_caps, - GstCaps * src_caps, - gboolean is_primary); + GstCaps * src_caps); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh265dec.cpp b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh265dec.cpp index da1248d150..8240ff8147 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh265dec.cpp +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh265dec.cpp @@ -265,7 +265,7 @@ gst_nv_h265_dec_class_init (GstNvH265DecClass * klass, parent_class = (GTypeClass *) g_type_class_peek_parent (klass); gst_element_class_set_static_metadata (element_class, - "NVDEC H.265 Stateless Decoder", + "NVDEC H.265 Decoder", "Codec/Decoder/Video/Hardware", "NVIDIA H.265 video decoder", "Seungha Yang "); @@ -1132,7 +1132,7 @@ gst_nv_h265_dec_get_preferred_output_delay (GstH265Decoder * decoder, void gst_nv_h265_dec_register (GstPlugin * plugin, guint device_id, guint rank, - GstCaps * sink_caps, GstCaps * src_caps, gboolean is_primary) + GstCaps * sink_caps, GstCaps * src_caps) { GType type; gchar *type_name; @@ -1189,25 +1189,15 @@ gst_nv_h265_dec_register (GstPlugin * plugin, guint device_id, guint rank, cdata->src_caps = gst_caps_ref (src_caps); cdata->cuda_device_id = device_id; - if (is_primary) { - type_name = g_strdup ("GstNvH265Dec"); - feature_name = g_strdup ("nvh265dec"); - } else { - type_name = g_strdup ("GstNvH265SLDec"); - feature_name = g_strdup ("nvh265sldec"); - } + type_name = g_strdup ("GstNvH265Dec"); + feature_name = g_strdup ("nvh265dec"); while (g_type_from_name (type_name)) { index++; g_free (type_name); g_free (feature_name); - if (is_primary) { - type_name = g_strdup_printf ("GstNvH265Device%dDec", index); - feature_name = g_strdup_printf ("nvh265device%ddec", index); - } else { - type_name = g_strdup_printf ("GstNvH265SLDevice%dDec", index); - feature_name = g_strdup_printf ("nvh265sldevice%ddec", index); - } + type_name = g_strdup_printf ("GstNvH265Device%dDec", index); + feature_name = g_strdup_printf ("nvh265device%ddec", index); } type_info.class_data = cdata; diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh265dec.h b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh265dec.h index 7dffa3e937..395c81e6f8 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh265dec.h +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvh265dec.h @@ -29,8 +29,7 @@ void gst_nv_h265_dec_register (GstPlugin * plugin, guint device_id, guint rank, GstCaps * sink_caps, - GstCaps * src_caps, - gboolean is_primary); + GstCaps * src_caps); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp8dec.cpp b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp8dec.cpp index 973c63b9c6..4241580ed6 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp8dec.cpp +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp8dec.cpp @@ -191,7 +191,7 @@ gst_nv_vp8_dec_class_init (GstNvVp8DecClass * klass, parent_class = (GTypeClass *) g_type_class_peek_parent (klass); gst_element_class_set_metadata (element_class, - "NVDEC VP8 Stateless Decoder", + "NVDEC VP8 Decoder", "Codec/Decoder/Video/Hardware", "NVIDIA VP8 video decoder", "Seungha Yang "); @@ -653,7 +653,7 @@ gst_nv_vp8_dec_get_preferred_output_delay (GstVp8Decoder * decoder, void gst_nv_vp8_dec_register (GstPlugin * plugin, guint device_id, guint rank, - GstCaps * sink_caps, GstCaps * src_caps, gboolean is_primary) + GstCaps * sink_caps, GstCaps * src_caps) { GType type; gchar *type_name; @@ -689,25 +689,15 @@ gst_nv_vp8_dec_register (GstPlugin * plugin, guint device_id, guint rank, cdata->src_caps = gst_caps_ref (src_caps); cdata->cuda_device_id = device_id; - if (is_primary) { - type_name = g_strdup ("GstNvVp8Dec"); - feature_name = g_strdup ("nvvp8dec"); - } else { - type_name = g_strdup ("GstNvVp8SLDec"); - feature_name = g_strdup ("nvvp8sldec"); - } + type_name = g_strdup ("GstNvVp8Dec"); + feature_name = g_strdup ("nvvp8dec"); while (g_type_from_name (type_name)) { index++; g_free (type_name); g_free (feature_name); - if (is_primary) { - type_name = g_strdup_printf ("GstNvVp8Device%dDec", index); - feature_name = g_strdup_printf ("nvvp8device%ddec", index); - } else { - type_name = g_strdup_printf ("GstNvVp8SLDevice%dDec", index); - feature_name = g_strdup_printf ("nvvp8sldevice%ddec", index); - } + type_name = g_strdup_printf ("GstNvVp8Device%dDec", index); + feature_name = g_strdup_printf ("nvvp8device%ddec", index); } type_info.class_data = cdata; diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp8dec.h b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp8dec.h index 3bc6c3085f..9dd5e145f0 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp8dec.h +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp8dec.h @@ -29,8 +29,7 @@ void gst_nv_vp8_dec_register (GstPlugin * plugin, guint device_id, guint rank, GstCaps * sink_caps, - GstCaps * src_caps, - gboolean is_primary); + GstCaps * src_caps); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.cpp b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.cpp index 8a621145f1..17799ab768 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.cpp +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.cpp @@ -194,7 +194,7 @@ gst_nv_vp9_dec_class_init (GstNvVp9DecClass * klass, parent_class = (GTypeClass *) g_type_class_peek_parent (klass); gst_element_class_set_metadata (element_class, - "NVDEC VP9 Stateless Decoder", + "NVDEC VP9 Decoder", "Codec/Decoder/Video/Hardware", "NVIDIA VP9 video decoder", "Seungha Yang "); @@ -749,7 +749,7 @@ gst_nv_vp9_dec_get_preferred_output_delay (GstVp9Decoder * decoder, void gst_nv_vp9_dec_register (GstPlugin * plugin, guint device_id, guint rank, - GstCaps * sink_caps, GstCaps * src_caps, gboolean is_primary) + GstCaps * sink_caps, GstCaps * src_caps) { GType type; gchar *type_name; @@ -789,25 +789,15 @@ gst_nv_vp9_dec_register (GstPlugin * plugin, guint device_id, guint rank, cdata->src_caps = gst_caps_ref (src_caps); cdata->cuda_device_id = device_id; - if (is_primary) { - type_name = g_strdup ("GstNvVp9Dec"); - feature_name = g_strdup ("nvvp9dec"); - } else { - type_name = g_strdup ("GstNvVp9SLDec"); - feature_name = g_strdup ("nvvp9sldec"); - } + type_name = g_strdup ("GstNvVp9Dec"); + feature_name = g_strdup ("nvvp9dec"); while (g_type_from_name (type_name)) { index++; g_free (type_name); g_free (feature_name); - if (is_primary) { - type_name = g_strdup_printf ("GstNvVp9Device%dDec", index); - feature_name = g_strdup_printf ("nvvp9device%ddec", index); - } else { - type_name = g_strdup_printf ("GstNvVp9SLDevice%dDec", index); - feature_name = g_strdup_printf ("nvvp9sldevice%ddec", index); - } + type_name = g_strdup_printf ("GstNvVp9Device%dDec", index); + feature_name = g_strdup_printf ("nvvp9device%ddec", index); } type_info.class_data = cdata; diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.h b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.h index 9d53972955..bd60964511 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.h +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.h @@ -29,8 +29,7 @@ void gst_nv_vp9_dec_register (GstPlugin * plugin, guint device_id, guint rank, GstCaps * sink_caps, - GstCaps * src_caps, - gboolean is_primary); + GstCaps * src_caps); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/plugin.c b/subprojects/gst-plugins-bad/sys/nvcodec/plugin.c index 0da0d56d18..3c890aa7a6 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/plugin.c +++ b/subprojects/gst-plugins-bad/sys/nvcodec/plugin.c @@ -73,11 +73,6 @@ 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; - gboolean use_h265_sl_dec = FALSE; - gboolean use_vp8_sl_dec = FALSE; - gboolean use_vp9_sl_dec = FALSE; GList *h264_enc_cdata = NULL; GList *h265_enc_cdata = NULL; @@ -129,33 +124,6 @@ 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; - } else if (g_ascii_strcasecmp (*iter, "h265") == 0) { - GST_INFO ("Found %s in GST_USE_NV_STATELESS_CODEC environment", *iter); - use_h265_sl_dec = TRUE; - } else if (g_ascii_strcasecmp (*iter, "vp8") == 0) { - GST_INFO ("Found %s in GST_USE_NV_STATELESS_CODEC environment", *iter); - use_vp8_sl_dec = TRUE; - } else if (g_ascii_strcasecmp (*iter, "vp9") == 0) { - GST_INFO ("Found %s in GST_USE_NV_STATELESS_CODEC environment", *iter); - use_vp9_sl_dec = TRUE; - } - } - - g_strfreev (split); - } - for (i = 0; i < dev_count; i++) { GstCudaContext *context = gst_cuda_context_new (i); CUcontext cuda_ctx; @@ -173,7 +141,7 @@ plugin_init (GstPlugin * plugin) GstCaps *sink_template = NULL; GstCaps *src_template = NULL; cudaVideoCodec codec = (cudaVideoCodec) j; - gboolean register_cuviddec = TRUE; + gboolean register_cuviddec = FALSE; if (gst_nv_decoder_check_device_caps (cuda_ctx, codec, &sink_template, &src_template)) { @@ -185,59 +153,30 @@ plugin_init (GstPlugin * plugin) switch (codec) { case cudaVideoCodec_H264: + /* higher than avdec_h264 */ gst_nv_h264_dec_register (plugin, - i, GST_RANK_SECONDARY, sink_template, src_template, FALSE); - if (use_h264_sl_dec) { - GST_INFO - ("Skipping registration of CUVID parser based nvh264dec element"); - register_cuviddec = FALSE; - - gst_nv_h264_dec_register (plugin, - i, GST_RANK_PRIMARY, sink_template, src_template, TRUE); - } + i, GST_RANK_PRIMARY + 1, sink_template, src_template); break; case cudaVideoCodec_HEVC: + /* higher than avdec_h265 */ gst_nv_h265_dec_register (plugin, - i, GST_RANK_SECONDARY, sink_template, src_template, FALSE); - if (use_h265_sl_dec) { - GST_INFO - ("Skipping registration of CUVID parser based nvh265dec element"); - register_cuviddec = FALSE; - - gst_nv_h265_dec_register (plugin, - i, GST_RANK_PRIMARY, sink_template, src_template, TRUE); - } + i, GST_RANK_PRIMARY + 1, sink_template, src_template); break; case cudaVideoCodec_VP8: gst_nv_vp8_dec_register (plugin, - i, GST_RANK_SECONDARY, sink_template, src_template, FALSE); - if (use_vp8_sl_dec) { - GST_INFO - ("Skipping registration of CUVID parser based nvhvp8dec element"); - register_cuviddec = FALSE; - - gst_nv_vp8_dec_register (plugin, - i, GST_RANK_PRIMARY, sink_template, src_template, TRUE); - } + i, GST_RANK_PRIMARY, sink_template, src_template); break; case cudaVideoCodec_VP9: gst_nv_vp9_dec_register (plugin, - i, GST_RANK_SECONDARY, sink_template, src_template, FALSE); - if (use_vp9_sl_dec) { - GST_INFO ("Skip register cuvid parser based nvhvp9dec"); - register_cuviddec = FALSE; - - gst_nv_vp9_dec_register (plugin, - i, GST_RANK_PRIMARY, sink_template, src_template, TRUE); - } + i, GST_RANK_PRIMARY, sink_template, src_template); break; case cudaVideoCodec_AV1: - gst_nv_av1_dec_register (plugin, i, GST_RANK_PRIMARY, + /* rust dav1ddec has "primary" rank */ + gst_nv_av1_dec_register (plugin, i, GST_RANK_PRIMARY + 1, sink_template, src_template); - /* Stateless decoder only in case of AV1 */ - register_cuviddec = FALSE; break; default: + register_cuviddec = TRUE; break; }