[spice-gtk,2/2] spicy: send ordered list of preferred video codecs

Submitted by Kevin Pouget on July 4, 2019, 10:29 a.m.

Details

Message ID 20190704102922.17433-2-kpouget@redhat.com
State Accepted
Commit 71511c376d853b8acc411ef8729616d4e992c7c1
Headers show
Series "Series without cover letter" ( rev: 4 3 2 1 ) in Spice

Not browsing as part of any series.

Commit Message

Kevin Pouget July 4, 2019, 10:29 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>
---
 tools/spicy.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

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



On Thu, Jul 11, 2019 at 10:08 AM Victor Toso <victortoso@redhat.com> wrote:
>
> On Thu, Jul 04, 2019 at 12:29:22PM +0200, Kevin Pouget 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>
> > ---
> >  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));
>
> This will leak, no? Maybe move the static var to global scope and
> cleanup in the end of main() ?

my rule/understanding is that memory allocated once, and accessible
all along the execution, is not considered as a leak,
so I wouldn't change it, even if it were not a testing tool

(let me know if I'm wrong!)

> Not a big issue, this is just testing tool. Either way,
>
> Acked-by: Victor Toso <victortoso@redhat.com>

thanks,

Kevin


> > +        /* 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
> >
> > _______________________________________________
> > Spice-devel mailing list
> > Spice-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/spice-devel