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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4015>
This commit is contained in:
Seungha Yang 2023-02-21 19:54:12 +09:00 committed by GStreamer Marge Bot
parent f3e16deaad
commit 8d7cab1f0d
9 changed files with 38 additions and 143 deletions

View file

@ -274,7 +274,7 @@ gst_nv_h264_dec_class_init (GstNvH264DecClass * klass,
parent_class = (GTypeClass *) g_type_class_peek_parent (klass); parent_class = (GTypeClass *) g_type_class_peek_parent (klass);
gst_element_class_set_static_metadata (element_class, gst_element_class_set_static_metadata (element_class,
"NVDEC H.264 Stateless Decoder", "NVDEC H.264 Decoder",
"Codec/Decoder/Video/Hardware", "Codec/Decoder/Video/Hardware",
"NVIDIA H.264 video decoder", "Seungha Yang <seungha@centricular.com>"); "NVIDIA H.264 video decoder", "Seungha Yang <seungha@centricular.com>");
@ -1091,7 +1091,7 @@ gst_nv_h264_dec_get_preferred_output_delay (GstH264Decoder * decoder,
void void
gst_nv_h264_dec_register (GstPlugin * plugin, guint device_id, guint rank, 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; GType type;
gchar *type_name; 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->src_caps = gst_caps_ref (src_caps);
cdata->cuda_device_id = device_id; cdata->cuda_device_id = device_id;
if (is_primary) { type_name = g_strdup ("GstNvH264Dec");
type_name = g_strdup ("GstNvH264Dec"); feature_name = g_strdup ("nvh264dec");
feature_name = g_strdup ("nvh264dec");
} else {
type_name = g_strdup ("GstNvH264SLDec");
feature_name = g_strdup ("nvh264sldec");
}
while (g_type_from_name (type_name)) { while (g_type_from_name (type_name)) {
index++; index++;
g_free (type_name); g_free (type_name);
g_free (feature_name); g_free (feature_name);
if (is_primary) { type_name = g_strdup_printf ("GstNvH264Device%dDec", index);
type_name = g_strdup_printf ("GstNvH264Device%dDec", index); feature_name = g_strdup_printf ("nvh264device%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_info.class_data = cdata; type_info.class_data = cdata;

View file

@ -29,8 +29,7 @@ void gst_nv_h264_dec_register (GstPlugin * plugin,
guint device_id, guint device_id,
guint rank, guint rank,
GstCaps * sink_caps, GstCaps * sink_caps,
GstCaps * src_caps, GstCaps * src_caps);
gboolean is_primary);
G_END_DECLS G_END_DECLS

View file

@ -265,7 +265,7 @@ gst_nv_h265_dec_class_init (GstNvH265DecClass * klass,
parent_class = (GTypeClass *) g_type_class_peek_parent (klass); parent_class = (GTypeClass *) g_type_class_peek_parent (klass);
gst_element_class_set_static_metadata (element_class, gst_element_class_set_static_metadata (element_class,
"NVDEC H.265 Stateless Decoder", "NVDEC H.265 Decoder",
"Codec/Decoder/Video/Hardware", "Codec/Decoder/Video/Hardware",
"NVIDIA H.265 video decoder", "Seungha Yang <seungha@centricular.com>"); "NVIDIA H.265 video decoder", "Seungha Yang <seungha@centricular.com>");
@ -1132,7 +1132,7 @@ gst_nv_h265_dec_get_preferred_output_delay (GstH265Decoder * decoder,
void void
gst_nv_h265_dec_register (GstPlugin * plugin, guint device_id, guint rank, 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; GType type;
gchar *type_name; 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->src_caps = gst_caps_ref (src_caps);
cdata->cuda_device_id = device_id; cdata->cuda_device_id = device_id;
if (is_primary) { type_name = g_strdup ("GstNvH265Dec");
type_name = g_strdup ("GstNvH265Dec"); feature_name = g_strdup ("nvh265dec");
feature_name = g_strdup ("nvh265dec");
} else {
type_name = g_strdup ("GstNvH265SLDec");
feature_name = g_strdup ("nvh265sldec");
}
while (g_type_from_name (type_name)) { while (g_type_from_name (type_name)) {
index++; index++;
g_free (type_name); g_free (type_name);
g_free (feature_name); g_free (feature_name);
if (is_primary) { type_name = g_strdup_printf ("GstNvH265Device%dDec", index);
type_name = g_strdup_printf ("GstNvH265Device%dDec", index); feature_name = g_strdup_printf ("nvh265device%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_info.class_data = cdata; type_info.class_data = cdata;

View file

@ -29,8 +29,7 @@ void gst_nv_h265_dec_register (GstPlugin * plugin,
guint device_id, guint device_id,
guint rank, guint rank,
GstCaps * sink_caps, GstCaps * sink_caps,
GstCaps * src_caps, GstCaps * src_caps);
gboolean is_primary);
G_END_DECLS G_END_DECLS

View file

@ -191,7 +191,7 @@ gst_nv_vp8_dec_class_init (GstNvVp8DecClass * klass,
parent_class = (GTypeClass *) g_type_class_peek_parent (klass); parent_class = (GTypeClass *) g_type_class_peek_parent (klass);
gst_element_class_set_metadata (element_class, gst_element_class_set_metadata (element_class,
"NVDEC VP8 Stateless Decoder", "NVDEC VP8 Decoder",
"Codec/Decoder/Video/Hardware", "Codec/Decoder/Video/Hardware",
"NVIDIA VP8 video decoder", "Seungha Yang <seungha@centricular.com>"); "NVIDIA VP8 video decoder", "Seungha Yang <seungha@centricular.com>");
@ -653,7 +653,7 @@ gst_nv_vp8_dec_get_preferred_output_delay (GstVp8Decoder * decoder,
void void
gst_nv_vp8_dec_register (GstPlugin * plugin, guint device_id, guint rank, 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; GType type;
gchar *type_name; 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->src_caps = gst_caps_ref (src_caps);
cdata->cuda_device_id = device_id; cdata->cuda_device_id = device_id;
if (is_primary) { type_name = g_strdup ("GstNvVp8Dec");
type_name = g_strdup ("GstNvVp8Dec"); feature_name = g_strdup ("nvvp8dec");
feature_name = g_strdup ("nvvp8dec");
} else {
type_name = g_strdup ("GstNvVp8SLDec");
feature_name = g_strdup ("nvvp8sldec");
}
while (g_type_from_name (type_name)) { while (g_type_from_name (type_name)) {
index++; index++;
g_free (type_name); g_free (type_name);
g_free (feature_name); g_free (feature_name);
if (is_primary) { type_name = g_strdup_printf ("GstNvVp8Device%dDec", index);
type_name = g_strdup_printf ("GstNvVp8Device%dDec", index); feature_name = g_strdup_printf ("nvvp8device%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_info.class_data = cdata; type_info.class_data = cdata;

View file

@ -29,8 +29,7 @@ void gst_nv_vp8_dec_register (GstPlugin * plugin,
guint device_id, guint device_id,
guint rank, guint rank,
GstCaps * sink_caps, GstCaps * sink_caps,
GstCaps * src_caps, GstCaps * src_caps);
gboolean is_primary);
G_END_DECLS G_END_DECLS

View file

@ -194,7 +194,7 @@ gst_nv_vp9_dec_class_init (GstNvVp9DecClass * klass,
parent_class = (GTypeClass *) g_type_class_peek_parent (klass); parent_class = (GTypeClass *) g_type_class_peek_parent (klass);
gst_element_class_set_metadata (element_class, gst_element_class_set_metadata (element_class,
"NVDEC VP9 Stateless Decoder", "NVDEC VP9 Decoder",
"Codec/Decoder/Video/Hardware", "Codec/Decoder/Video/Hardware",
"NVIDIA VP9 video decoder", "Seungha Yang <seungha@centricular.com>"); "NVIDIA VP9 video decoder", "Seungha Yang <seungha@centricular.com>");
@ -749,7 +749,7 @@ gst_nv_vp9_dec_get_preferred_output_delay (GstVp9Decoder * decoder,
void void
gst_nv_vp9_dec_register (GstPlugin * plugin, guint device_id, guint rank, 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; GType type;
gchar *type_name; 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->src_caps = gst_caps_ref (src_caps);
cdata->cuda_device_id = device_id; cdata->cuda_device_id = device_id;
if (is_primary) { type_name = g_strdup ("GstNvVp9Dec");
type_name = g_strdup ("GstNvVp9Dec"); feature_name = g_strdup ("nvvp9dec");
feature_name = g_strdup ("nvvp9dec");
} else {
type_name = g_strdup ("GstNvVp9SLDec");
feature_name = g_strdup ("nvvp9sldec");
}
while (g_type_from_name (type_name)) { while (g_type_from_name (type_name)) {
index++; index++;
g_free (type_name); g_free (type_name);
g_free (feature_name); g_free (feature_name);
if (is_primary) { type_name = g_strdup_printf ("GstNvVp9Device%dDec", index);
type_name = g_strdup_printf ("GstNvVp9Device%dDec", index); feature_name = g_strdup_printf ("nvvp9device%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_info.class_data = cdata; type_info.class_data = cdata;

View file

@ -29,8 +29,7 @@ void gst_nv_vp9_dec_register (GstPlugin * plugin,
guint device_id, guint device_id,
guint rank, guint rank,
GstCaps * sink_caps, GstCaps * sink_caps,
GstCaps * src_caps, GstCaps * src_caps);
gboolean is_primary);
G_END_DECLS G_END_DECLS

View file

@ -73,11 +73,6 @@ plugin_init (GstPlugin * plugin)
/* hardcoded minimum supported version */ /* hardcoded minimum supported version */
guint api_major_ver = 8; guint api_major_ver = 8;
guint api_minor_ver = 1; 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 *h264_enc_cdata = NULL;
GList *h265_enc_cdata = NULL; GList *h265_enc_cdata = NULL;
@ -129,33 +124,6 @@ plugin_init (GstPlugin * plugin)
return TRUE; 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++) { for (i = 0; i < dev_count; i++) {
GstCudaContext *context = gst_cuda_context_new (i); GstCudaContext *context = gst_cuda_context_new (i);
CUcontext cuda_ctx; CUcontext cuda_ctx;
@ -173,7 +141,7 @@ plugin_init (GstPlugin * plugin)
GstCaps *sink_template = NULL; GstCaps *sink_template = NULL;
GstCaps *src_template = NULL; GstCaps *src_template = NULL;
cudaVideoCodec codec = (cudaVideoCodec) j; cudaVideoCodec codec = (cudaVideoCodec) j;
gboolean register_cuviddec = TRUE; gboolean register_cuviddec = FALSE;
if (gst_nv_decoder_check_device_caps (cuda_ctx, if (gst_nv_decoder_check_device_caps (cuda_ctx,
codec, &sink_template, &src_template)) { codec, &sink_template, &src_template)) {
@ -185,59 +153,30 @@ plugin_init (GstPlugin * plugin)
switch (codec) { switch (codec) {
case cudaVideoCodec_H264: case cudaVideoCodec_H264:
/* higher than avdec_h264 */
gst_nv_h264_dec_register (plugin, gst_nv_h264_dec_register (plugin,
i, GST_RANK_SECONDARY, sink_template, src_template, FALSE); i, GST_RANK_PRIMARY + 1, sink_template, src_template);
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);
}
break; break;
case cudaVideoCodec_HEVC: case cudaVideoCodec_HEVC:
/* higher than avdec_h265 */
gst_nv_h265_dec_register (plugin, gst_nv_h265_dec_register (plugin,
i, GST_RANK_SECONDARY, sink_template, src_template, FALSE); i, GST_RANK_PRIMARY + 1, sink_template, src_template);
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);
}
break; break;
case cudaVideoCodec_VP8: case cudaVideoCodec_VP8:
gst_nv_vp8_dec_register (plugin, gst_nv_vp8_dec_register (plugin,
i, GST_RANK_SECONDARY, sink_template, src_template, FALSE); i, GST_RANK_PRIMARY, sink_template, src_template);
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);
}
break; break;
case cudaVideoCodec_VP9: case cudaVideoCodec_VP9:
gst_nv_vp9_dec_register (plugin, gst_nv_vp9_dec_register (plugin,
i, GST_RANK_SECONDARY, sink_template, src_template, FALSE); i, GST_RANK_PRIMARY, sink_template, src_template);
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);
}
break; break;
case cudaVideoCodec_AV1: 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); sink_template, src_template);
/* Stateless decoder only in case of AV1 */
register_cuviddec = FALSE;
break; break;
default: default:
register_cuviddec = TRUE;
break; break;
} }