[Spice-devel] [PATCH spice-gtk v4 5/7] display-gst: check GstRegistry for decoding elements

Daimon Wang daimon_swang at yahoo.com
Wed Jul 5 02:08:37 UTC 2017


Hi. 
>G_GNUC_INTERNAL
>gboolean gstvideo_has_codec(int codec_type)
>{
>-    gboolean has_codec = FALSE;
>+    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);>
>
>-    VideoDecoder *decoder = create_gstreamer_decoder(codec_type, NULL);
>-    if (decoder) {
>-        has_codec = TRUE;
>-        decoder->destroy(decoder);
>+    type = GST_ELEMENT_FACTORY_TYPE_DECODER | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO;
>+    all_decoders = gst_element_factory_list_get_elements(type, GST_RANK_NONE);
Playbin is using GST_RANK_MARGINAL to filter its elements. Maybe we could follow that?

    On Wednesday, June 28, 2017 8:43 PM, Victor Toso <victortoso at redhat.com> wrote:
 

 From: Victor Toso <me at victortoso.com>

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 a 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 at redhat.com>
Acked-by: Frediano Ziglio <fziglio at redhat.com>
Signed-off-by: Victor Toso <me at victortoso.com>
---
 src/channel-display-gst.c | 56 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 50 insertions(+), 6 deletions(-)

diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
index 57f0eb7..1b40002 100644
--- a/src/channel-display-gst.c
+++ b/src/channel-display-gst.c
@@ -521,16 +521,60 @@ VideoDecoder* create_gstreamer_decoder(int codec_type, display_stream *stream)
    return (VideoDecoder*)decoder;
 }
 
+static void gstvideo_debug_available_decoders(int codec_type,
+                                              GList *all_decoders,
+                                              GList *codec_decoders)
+{
+    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));
+    }
+
+    /* Drop trailing ", " */
+    g_string_truncate(msg, msg->len - 2);
+    spice_debug("%s", msg->str);
+    g_string_free(msg, TRUE);
+}
+
 G_GNUC_INTERNAL
 gboolean gstvideo_has_codec(int codec_type)
 {
-    gboolean has_codec = FALSE;
+    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);
 
-    VideoDecoder *decoder = create_gstreamer_decoder(codec_type, NULL);
-    if (decoder) {
-        has_codec = TRUE;
-        decoder->destroy(decoder);
+    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;
    }
 
-    return has_codec;
+    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())
+        gstvideo_debug_available_decoders(codec_type, all_decoders, codec_decoders);
+
+    gst_plugin_feature_list_free(codec_decoders);
+    gst_plugin_feature_list_free(all_decoders);
+    return TRUE;
 }
-- 
2.13.0

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


   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170705/42131f56/attachment-0001.html>


More information about the Spice-devel mailing list