vaapidecode: Autogenerate caps template.

vaapidecode is used in vaapidecodebin and it exposes all the
theoretically supported caps, but that slows down autoplug. With this
autplug is negotiated faster, giving more option to decodebin to select
other decoder.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1405>
This commit is contained in:
Víctor Manuel Jáquez Leal 2021-12-01 12:26:11 +01:00
parent d04fba93f8
commit 90df5b5ab8

View file

@ -67,19 +67,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_debug_vaapidecode);
#define GST_CAPS_CODEC(CODEC) CODEC "; " #define GST_CAPS_CODEC(CODEC) CODEC "; "
/* *INDENT-OFF* */ /* *INDENT-OFF* */
static const char gst_vaapidecode_sink_caps_str[] = char *gst_vaapidecode_sink_caps_str = NULL;
GST_CAPS_CODEC("video/mpeg, mpegversion=2, systemstream=(boolean)false")
GST_CAPS_CODEC("video/mpeg, mpegversion=4")
GST_CAPS_CODEC("video/x-divx")
GST_CAPS_CODEC("video/x-xvid")
GST_CAPS_CODEC("video/x-h263")
GST_CAPS_CODEC("video/x-h264")
GST_CAPS_CODEC("video/x-h265")
GST_CAPS_CODEC("video/x-wmv")
GST_CAPS_CODEC("video/x-vp8")
GST_CAPS_CODEC("video/x-vp9")
GST_CAPS_CODEC("video/x-av1")
;
static const char gst_vaapidecode_src_caps_str[] = static const char gst_vaapidecode_src_caps_str[] =
GST_VAAPI_MAKE_SURFACE_CAPS "; " GST_VAAPI_MAKE_SURFACE_CAPS "; "
@ -123,8 +111,7 @@ static const GstVaapiDecoderMap vaapi_decode_map[] = {
{GST_VAAPI_CODEC_VP9, GST_RANK_PRIMARY, "vp9", "video/x-vp9", NULL}, {GST_VAAPI_CODEC_VP9, GST_RANK_PRIMARY, "vp9", "video/x-vp9", NULL},
{GST_VAAPI_CODEC_H265, GST_RANK_PRIMARY, "h265", "video/x-h265", NULL}, {GST_VAAPI_CODEC_H265, GST_RANK_PRIMARY, "h265", "video/x-h265", NULL},
{GST_VAAPI_CODEC_AV1, GST_RANK_PRIMARY, "av1", "video/x-av1", NULL}, {GST_VAAPI_CODEC_AV1, GST_RANK_PRIMARY, "av1", "video/x-av1", NULL},
{0 /* the rest */ , GST_RANK_PRIMARY + 1, NULL, {0 /* the rest */ , GST_RANK_PRIMARY + 1, NULL, NULL, NULL},
gst_vaapidecode_sink_caps_str, NULL},
}; };
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -1567,7 +1554,12 @@ gst_vaapidecode_class_init (GstVaapiDecodeClass * klass)
map->install_properties (object_class); map->install_properties (object_class);
/* sink pad */ /* sink pad */
caps = gst_caps_from_string (map->caps_str); if (map->caps_str) {
caps = gst_caps_from_string (map->caps_str);
} else {
caps = gst_caps_from_string (gst_vaapidecode_sink_caps_str);
g_free (gst_vaapidecode_sink_caps_str);
}
pad_template = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, pad_template = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
caps); caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1593,7 +1585,7 @@ gst_vaapidecode_register (GstPlugin * plugin, GArray * decoders)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
guint i, codec, rank; guint i, codec, rank;
gchar *type_name, *element_name; gchar *type_name, *element_name, *sink_caps_str;
const gchar *name; const gchar *name;
GType type; GType type;
GTypeInfo typeinfo = { GTypeInfo typeinfo = {
@ -1616,6 +1608,15 @@ gst_vaapidecode_register (GstPlugin * plugin, GArray * decoders)
if (codec && !gst_vaapi_codecs_has_codec (decoders, codec)) if (codec && !gst_vaapi_codecs_has_codec (decoders, codec))
continue; continue;
if (!gst_vaapidecode_sink_caps_str) {
gst_vaapidecode_sink_caps_str = g_strdup (vaapi_decode_map[i].caps_str);
} else {
sink_caps_str = g_strconcat (gst_vaapidecode_sink_caps_str, "; ",
vaapi_decode_map[i].caps_str, NULL);
g_clear_pointer (&gst_vaapidecode_sink_caps_str, g_free);
gst_vaapidecode_sink_caps_str = sink_caps_str;
}
if (codec) { if (codec) {
type_name = g_strdup_printf ("GstVaapiDecode_%s", name); type_name = g_strdup_printf ("GstVaapiDecode_%s", name);
element_name = g_strdup_printf ("vaapi%sdec", name); element_name = g_strdup_printf ("vaapi%sdec", name);