[PATCH spice-gtk 3/5] display-gst: check GstRegistry for decoding elements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Victor Toso <me@xxxxxxxxxxxxxx>

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: Victor Toso <victortoso@xxxxxxxxxx>
Signed-off-by: Victor Toso <me@xxxxxxxxxxxxxx>
---
 src/channel-display-gst.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
index 773bd1c..000e3a9 100644
--- a/src/channel-display-gst.c
+++ b/src/channel-display-gst.c
@@ -526,6 +526,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);
@@ -535,4 +583,5 @@ gboolean gstvideo_has_codec(int codec_type)
     }
 
     return has_codec;
+#endif
 }
-- 
2.12.2

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]