[Spice-commits] 2 commits - doc/reference src/channel-display.c src/channel-display.h src/map-file src/spice-glib-sym-file tools/spicy.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jul 11 09:05:01 UTC 2019


 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 
 tools/spicy.c                        |   31 +++++++++++++-
 6 files changed, 98 insertions(+), 15 deletions(-)

New commits:
commit 71511c376d853b8acc411ef8729616d4e992c7c1
Author: Kevin Pouget <kpouget at redhat.com>
Date:   Tue Jun 18 15:31:26 2019 +0200

    spicy: send ordered list of preferred video codecs
    
    Instead of sending only the preferred video codec (selected), spicy
    now sends an ordered list. When a video codec is selected in the radio
    box, this codec is moved to beginning of the list.
    
    Signed-off-by: Kevin Pouget <kpouget at redhat.com>

diff --git a/tools/spicy.c b/tools/spicy.c
index 8a6d077..403a66d 100644
--- a/tools/spicy.c
+++ b/tools/spicy.c
@@ -1014,8 +1014,35 @@ static void video_codec_type_cb(GtkRadioAction *action G_GNUC_UNUSED,
                                 GtkRadioAction *current,
                                 gpointer user_data)
 {
-    spice_display_channel_change_preferred_video_codec_type(SPICE_CHANNEL(user_data),
-                                                            gtk_radio_action_get_current_value(current));
+    static GArray *preferred_codecs = NULL;
+    gint selected_codec = gtk_radio_action_get_current_value(current);
+    guint i;
+    GError *err = NULL;
+
+    if (!preferred_codecs) {
+        preferred_codecs = g_array_sized_new(FALSE, FALSE,
+                                             sizeof(gint),
+                                             G_N_ELEMENTS(video_codec_type_entries));
+        /* initialize with the menu ordering */
+        for (i = 0; i < G_N_ELEMENTS(video_codec_type_entries); i++) {
+            g_array_append_val(preferred_codecs, video_codec_type_entries[i].value);
+        }
+    }
+
+    /* remove codec from array and insert at the beginning */
+    for (i = 0; i < preferred_codecs->len &&
+                g_array_index(preferred_codecs, gint, i) != selected_codec; i++);
+
+    g_assert(i < preferred_codecs->len);
+    g_array_remove_index(preferred_codecs, i);
+    g_array_prepend_val(preferred_codecs, selected_codec);
+
+    if (!spice_display_channel_change_preferred_video_codec_types(SPICE_CHANNEL(user_data),
+                                                                  (gint *) preferred_codecs->data,
+                                                                  preferred_codecs->len, &err)) {
+        g_warning("setting preferred video codecs failed: %s", err->message);
+        g_error_free(err);
+    }
 }
 
 static void
commit 7387f7fae9ae0701454c09fdc9b2a955ea835877
Author: Kevin Pouget <kpouget at redhat.com>
Date:   Tue Jun 18 15:31:00 2019 +0200

    spice-client-gtk-module: allow sending multiple preferred video codecs
    
    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>

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


More information about the Spice-commits mailing list