[Spice-devel] [client v11 25/27] spice-gtk: Probe GStreamer before advertising support for a codec

Francois Gouget fgouget at codeweavers.com
Fri Mar 25 12:47:30 UTC 2016


Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 src/channel-display-gst.c  | 17 +++++++++++++++--
 src/channel-display-priv.h |  4 ++--
 src/channel-display.c      | 21 +++++++++++++++++----
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
index 4d7b26e..36780de 100644
--- a/src/channel-display-gst.c
+++ b/src/channel-display-gst.c
@@ -464,8 +464,7 @@ static void spice_gst_decoder_queue_frame(VideoDecoder *video_decoder,
     }
 }
 
-G_GNUC_INTERNAL
-gboolean gstvideo_init(void)
+static gboolean gstvideo_init(void)
 {
     static int success = 0;
     if (!success) {
@@ -499,3 +498,17 @@ VideoDecoder* create_gstreamer_decoder(int codec_type, display_stream *stream)
 
     return (VideoDecoder*)decoder;
 }
+
+G_GNUC_INTERNAL
+gboolean gstvideo_has_codec(int codec_type)
+{
+    gboolean has_codec = FALSE;
+
+    VideoDecoder *decoder = create_gstreamer_decoder(codec_type, NULL);
+    if (decoder) {
+        has_codec = create_pipeline((SpiceGstDecoder*)decoder);
+        decoder->destroy(decoder);
+    }
+
+    return has_codec;
+}
diff --git a/src/channel-display-priv.h b/src/channel-display-priv.h
index 3989899..e27c499 100644
--- a/src/channel-display-priv.h
+++ b/src/channel-display-priv.h
@@ -73,9 +73,9 @@ VideoDecoder* create_mjpeg_decoder(int codec_type, display_stream *stream);
 #endif
 #ifdef HAVE_GSTVIDEO
 VideoDecoder* create_gstreamer_decoder(int codec_type, display_stream *stream);
-gboolean gstvideo_init(void);
+gboolean gstvideo_has_codec(int codec_type);
 #else
-# define gstvideo_init() FALSE
+# define gstvideo_has_codec(codec_type) FALSE
 #endif
 
 
diff --git a/src/channel-display.c b/src/channel-display.c
index f3a152f..1b28e34 100644
--- a/src/channel-display.c
+++ b/src/channel-display.c
@@ -718,10 +718,23 @@ static void spice_display_channel_reset_capabilities(SpiceChannel *channel)
 #ifdef HAVE_BUILTIN_MJPEG
     spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_DISPLAY_CAP_CODEC_MJPEG);
 #endif
-    if (gstvideo_init()) {
-        spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_DISPLAY_CAP_CODEC_MJPEG);
-        spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_DISPLAY_CAP_CODEC_VP8);
-        spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_DISPLAY_CAP_CODEC_H264);
+    if (gstvideo_has_codec(SPICE_VIDEO_CODEC_TYPE_MJPEG)) {
+        spice_channel_set_capability(SPICE_CHANNEL(channel),
+                                     SPICE_DISPLAY_CAP_CODEC_MJPEG);
+    } else {
+        spice_info("GStreamer does not support the mjpeg codec");
+    }
+    if (gstvideo_has_codec(SPICE_VIDEO_CODEC_TYPE_VP8)) {
+        spice_channel_set_capability(SPICE_CHANNEL(channel),
+                                     SPICE_DISPLAY_CAP_CODEC_VP8);
+    } else {
+        spice_info("GStreamer does not support the vp8 codec");
+    }
+    if (gstvideo_has_codec(SPICE_VIDEO_CODEC_TYPE_H264)) {
+        spice_channel_set_capability(SPICE_CHANNEL(channel),
+                                     SPICE_DISPLAY_CAP_CODEC_H264);
+    } else {
+        spice_info("GStreamer does not support the h264 codec");
     }
 }
 
-- 
2.7.0



More information about the Spice-devel mailing list