[Spice-devel] [PATCH spice-gtk 1/2] spice-client-gtk-module: allow sending multiple preferred video codecs

Kevin Pouget kpouget at redhat.com
Thu Jul 11 09:44:47 UTC 2019


spice_display_channel_change_preferred_video_codec_types: new function
for sending an array of video codecs instead of only one.

Signed-off-by: Kevin Pouget <kpouget at redhat.com>
---

this is the version that was pushed

---
 doc/reference/spice-gtk-sections.txt |  1 +
 src/channel-display.c                | 77 +++++++++++++++++++++++-----
 src/channel-display.h                |  2 +
 src/map-file                         |  1 +
 src/spice-glib-sym-file              |  1 +
 5 files changed, 69 insertions(+), 13 deletions(-)

diff --git a/doc/reference/spice-gtk-sections.txt b/doc/reference/spice-gtk-sections.txt
index a0336aa..33f4038 100644
--- a/doc/reference/spice-gtk-sections.txt
+++ b/doc/reference/spice-gtk-sections.txt
@@ -185,6 +185,7 @@ spice_display_change_preferred_compression
 spice_display_channel_change_preferred_compression
 spice_display_change_preferred_video_codec_type
 spice_display_channel_change_preferred_video_codec_type
+spice_display_channel_change_preferred_video_codec_types
 spice_gl_scanout_free
 <SUBSECTION Standard>
 SPICE_DISPLAY_CHANNEL
diff --git a/src/channel-display.c b/src/channel-display.c
index 9a83c53..44555e3 100644
--- a/src/channel-display.c
+++ b/src/channel-display.c
@@ -20,6 +20,7 @@
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
+#include <glib/gi18n-lib.h>

 #include "spice-client.h"
 #include "spice-common.h"
@@ -610,18 +611,15 @@ void spice_display_channel_change_preferred_compression(SpiceChannel *channel, g
 }

 static void spice_display_send_client_preferred_video_codecs(SpiceChannel *channel,
-                                                             const GArray *codecs)
+                                                             const gint *codecs, gsize ncodecs)
 {
-    guint i;
     SpiceMsgOut *out;
     SpiceMsgcDisplayPreferredVideoCodecType *msg;

     msg = g_malloc0(sizeof(SpiceMsgcDisplayPreferredVideoCodecType) +
-                    (sizeof(SpiceVideoCodecType) * codecs->len));
-    msg->num_of_codecs = codecs->len;
-    for (i = 0; i < codecs->len; i++) {
-        msg->codecs[i] = g_array_index(codecs, gint, i);
-    }
+                    (sizeof(SpiceVideoCodecType) * ncodecs));
+    msg->num_of_codecs = ncodecs;
+    memcpy(msg->codecs, codecs, sizeof(*codecs) * ncodecs);

     out = spice_msg_out_new(channel, SPICE_MSGC_DISPLAY_PREFERRED_VIDEO_CODEC_TYPE);
     out->marshallers->msgc_display_preferred_video_codec_type(out->marshaller, msg);
@@ -656,11 +654,10 @@ void spice_display_change_preferred_video_codec_type(SpiceChannel *channel, gint
  * display channel.
  *
  * Since: 0.35
+ * Deprecated: 0.38: use spice_display_channel_change_preferred_video_codec_types() instead.
  */
 void spice_display_channel_change_preferred_video_codec_type(SpiceChannel *channel, gint codec_type)
 {
-    GArray *codecs;
-
     g_return_if_fail(SPICE_IS_DISPLAY_CHANNEL(channel));
     g_return_if_fail(codec_type >= SPICE_VIDEO_CODEC_TYPE_MJPEG &&
                      codec_type < SPICE_VIDEO_CODEC_TYPE_ENUM_END);
@@ -675,10 +672,64 @@ void spice_display_channel_change_preferred_video_codec_type(SpiceChannel *chann
      * This array can be rearranged to have @codec_type in the front (which is
      * the preferred for the client side) */
     CHANNEL_DEBUG(channel, "changing preferred video codec type to %s", gst_opts[codec_type].name);
-    codecs = g_array_new(FALSE, FALSE, sizeof(gint));
-    g_array_append_val(codecs, codec_type);
-    spice_display_send_client_preferred_video_codecs(channel, codecs);
-    g_array_unref(codecs);
+    spice_display_send_client_preferred_video_codecs(channel, &codec_type, 1);
+}
+
+/**
+ * spice_display_channel_change_preferred_video_codecs_types:
+ * @channel: a #SpiceDisplayChannel
+ * @codecs: an array of @ncodecs #SpiceVideoCodecType types
+ * @ncodecs: the number of codec types in the @codecs array
+ * @err: #GError describing the reason why the change failed
+ *
+ * Tells the spice server the ordered preferred video codec types to
+ * use for streaming in @channel.
+ *
+ * Returns: %TRUE if the preferred codec list was successfully changed, and %FALSE
+ * otherwise.
+ *
+ * Since: 0.38
+ */
+gboolean spice_display_channel_change_preferred_video_codec_types(SpiceChannel *channel,
+                                                                  const gint *codecs, gsize ncodecs,
+                                                                  GError **err)
+{
+    gsize i;
+    GString *msg;
+
+    g_return_val_if_fail(SPICE_IS_DISPLAY_CHANNEL(channel), FALSE);
+    g_return_val_if_fail(ncodecs != 0, FALSE);
+
+    if (!spice_channel_test_capability(channel, SPICE_DISPLAY_CAP_PREF_VIDEO_CODEC_TYPE)) {
+        CHANNEL_DEBUG(channel, "does not have capability to change the preferred video codec type");
+        g_set_error_literal(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
+                            _("Channel does not have capability to change the preferred video codec type"));
+
+        return FALSE;
+    }
+
+    msg = g_string_new("changing preferred video codec type to: ");
+    for (i = 0; i < ncodecs; i++) {
+        gint codec_type = codecs[i];
+
+        if (codec_type < SPICE_VIDEO_CODEC_TYPE_MJPEG ||
+            codec_type >= SPICE_VIDEO_CODEC_TYPE_ENUM_END) {
+            g_string_free(msg, TRUE);
+            g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
+                        _("Invalid codec-type found (%d) ... "), codec_type);
+
+            return FALSE;
+        }
+
+        g_string_append_printf(msg, "%s ", gst_opts[codec_type].name);
+
+    }
+    CHANNEL_DEBUG(channel, "%s", msg->str);
+    g_string_free(msg, TRUE);
+
+    spice_display_send_client_preferred_video_codecs(channel, codecs, ncodecs);
+
+    return TRUE;
 }

 /**
diff --git a/src/channel-display.h b/src/channel-display.h
index 5b48d2f..cf18538 100644
--- a/src/channel-display.h
+++ b/src/channel-display.h
@@ -150,6 +150,8 @@ gboolean        spice_display_channel_get_primary(SpiceChannel *channel, guint32

 void spice_display_channel_change_preferred_compression(SpiceChannel *channel, gint compression);
 void spice_display_channel_change_preferred_video_codec_type(SpiceChannel *channel, gint codec_type);
+gboolean spice_display_channel_change_preferred_video_codec_types(SpiceChannel *channel, const gint *codecs,
+                                                                  gsize ncodecs, GError **err);

 GType           spice_gl_scanout_get_type     (void) G_GNUC_CONST;
 void            spice_gl_scanout_free         (SpiceGlScanout *scanout);
diff --git a/src/map-file b/src/map-file
index 500683c..3cb9873 100644
--- a/src/map-file
+++ b/src/map-file
@@ -25,6 +25,7 @@ spice_display_change_preferred_compression;
 spice_display_change_preferred_video_codec_type;
 spice_display_channel_change_preferred_compression;
 spice_display_channel_change_preferred_video_codec_type;
+spice_display_channel_change_preferred_video_codec_types;
 spice_display_channel_get_gl_scanout;
 spice_display_channel_get_primary;
 spice_display_channel_get_type;
diff --git a/src/spice-glib-sym-file b/src/spice-glib-sym-file
index 2df1cc0..c3b2561 100644
--- a/src/spice-glib-sym-file
+++ b/src/spice-glib-sym-file
@@ -23,6 +23,7 @@ spice_display_change_preferred_compression
 spice_display_change_preferred_video_codec_type
 spice_display_channel_change_preferred_compression
 spice_display_channel_change_preferred_video_codec_type
+spice_display_channel_change_preferred_video_codec_types
 spice_display_channel_get_gl_scanout
 spice_display_channel_get_primary
 spice_display_channel_get_type
--
2.21.0


More information about the Spice-devel mailing list