[Spice-devel] [spice-gtk v1 3/4] channel-display-gst: improve check for decoder element

Victor Toso victortoso at redhat.com
Tue Oct 18 21:27:06 UTC 2016


From: Victor Toso <me at victortoso.com>

Instead of creating the whole pipeline and check for errors (which
would create and destroy the SpiceGstDecoder), let's use
gst_element_factory_find() function.

Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/channel-display-gst.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
index 68ebd1f..c0f0a1e 100644
--- a/src/channel-display-gst.c
+++ b/src/channel-display-gst.c
@@ -484,13 +484,24 @@ VideoDecoder* create_gstreamer_decoder(int codec_type, display_stream *stream)
 G_GNUC_INTERNAL
 gboolean gstvideo_has_codec(int codec_type)
 {
-    gboolean has_codec = FALSE;
+    gint i;
+    gchar **elements;
 
-    VideoDecoder *decoder = create_gstreamer_decoder(codec_type, NULL);
-    if (decoder) {
-        has_codec = TRUE;
-        decoder->destroy(decoder);
-    }
+    g_return_val_if_fail(gstvideo_init(), FALSE);
+    g_return_val_if_fail(VALID_VIDEO_CODEC_TYPE(codec_type), FALSE);
+
+    elements = g_strsplit(gst_opts[codec_type].dec_name, "!", 0);
+    for (i = 0; elements[i] != NULL; i++) {
+        GstElementFactory *factory;
 
-    return has_codec;
+        factory = gst_element_factory_find(g_strstrip(elements[i]));
+        if (factory == NULL) {
+            SPICE_DEBUG("no element %s", elements[i]);
+            g_strfreev(elements);
+            return FALSE;
+        }
+        gst_object_unref(factory);
+    }
+    g_strfreev(elements);
+    return TRUE;
 }
-- 
2.9.3



More information about the Spice-devel mailing list