spicy: send ordered list of preferred video codecs

Submitted by Kevin Pouget on July 11, 2019, 7:58 a.m.

Details

Message ID 20190711075850.17989-1-kpouget@redhat.com
State Accepted
Headers show
Series "Series without cover letter" ( rev: 2 ) in Spice

Not browsing as part of any series.

Commit Message

Kevin Pouget July 11, 2019, 7:58 a.m.
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@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>

---

guard, style fix and
spice_display_channel_change_preferred_video_codec_type deprecation
applied

thanks,

Kevin

---
 tools/spicy.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

--
2.21.0

Patch hide | download patch | download mbox

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

Comments

hum, sorry, I messed things up with git send-email, forget about the
message below

On Thu, Jul 11, 2019 at 10:00 AM Kevin Pouget <kpouget@redhat.com> wrote:
>
> 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@redhat.com>
> Acked-by: Victor Toso <victortoso@redhat.com>
>
> ---
>
> guard, style fix and
> spice_display_channel_change_preferred_video_codec_type deprecation
> applied
>
> thanks,
>
> Kevin
>
> ---
>  tools/spicy.c | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
>
> 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
> --
> 2.21.0