Skip to content
Snippets Groups Projects
Commit e90785e1 authored by Victor Toso's avatar Victor Toso
Browse files

display-gst: check GstRegistry for decoding elements


With this patch, we can find all the elements in the registry that are
video decoders which can handle the predefined GstCaps.

Main benefits are:
- We don't rely on predefined list of GstElements. We don't need to
  update them;
- debugging: It does help to know what the registry has at runtime;

Signed-off-by: default avatarVictor Toso <victortoso@redhat.com>
Acked-by: default avatarFrediano Ziglio <fziglio@redhat.com>
parent 06f64c44
No related branches found
No related tags found
No related merge requests found
......@@ -524,6 +524,54 @@ VideoDecoder* create_gstreamer_decoder(int codec_type, display_stream *stream)
G_GNUC_INTERNAL
gboolean gstvideo_has_codec(int codec_type)
{
#if GST_CHECK_VERSION(1,9,0)
GList *all_decoders, *codec_decoders;
GstCaps *caps;
GstElementFactoryListType type;
g_return_val_if_fail(gstvideo_init(), FALSE);
g_return_val_if_fail(VALID_VIDEO_CODEC_TYPE(codec_type), FALSE);
type = GST_ELEMENT_FACTORY_TYPE_DECODER | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO;
all_decoders = gst_element_factory_list_get_elements(type, GST_RANK_NONE);
if (all_decoders == NULL) {
spice_warning("No video decoders from GStreamer were found");
return FALSE;
}
caps = gst_caps_from_string(gst_opts[codec_type].dec_caps);
codec_decoders = gst_element_factory_list_filter(all_decoders, caps, GST_PAD_SINK, TRUE);
gst_caps_unref(caps);
if (codec_decoders == NULL) {
spice_debug("From %u decoders, none can handle '%s'",
g_list_length(all_decoders), gst_opts[codec_type].dec_caps);
gst_plugin_feature_list_free(all_decoders);
return FALSE;
}
if (spice_util_get_debug()) {
GList *l;
GString *msg = g_string_new(NULL);
/* Print list of available decoders to make debugging easier */
g_string_printf(msg, "From %3u video decoder elements, %2u can handle caps %12s: ",
g_list_length(all_decoders), g_list_length(codec_decoders),
gst_opts[codec_type].dec_caps);
for (l = codec_decoders; l != NULL; l = l->next) {
GstPluginFeature *pfeat = GST_PLUGIN_FEATURE(l->data);
g_string_append_printf(msg, "%s, ", gst_plugin_feature_get_name(pfeat));
}
msg->str[msg->len - 2] = '\0';
spice_debug("%s", msg->str);
g_string_free(msg, TRUE);
}
gst_plugin_feature_list_free(codec_decoders);
gst_plugin_feature_list_free(all_decoders);
return TRUE;
#else
gboolean has_codec = FALSE;
VideoDecoder *decoder = create_gstreamer_decoder(codec_type, NULL);
......@@ -533,4 +581,5 @@ gboolean gstvideo_has_codec(int codec_type)
}
return has_codec;
#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment