[spice-server v2 8/9] reds: add support to ranks for video codecs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Victor Toso <me@xxxxxxxxxxxxxx>

This patch implements a new value to the preference introduced in
497fcbb0a315b034ba keeping it backwards compatible. The new value is
the rank, which is an unsigned integer and should be set as last
argument. e.g: encoder:codec:rank

Video codecs will now be ordered by rank.

The logic around the rank is the following:
* Default rank value is 1;
* Higher the rank means preferable codec for encoding;
* Rank of value 0 disables encoding with this particular codec;
* Ranks should be a single digit (0-9)

Signed-off-by: Victor Toso <victortoso@xxxxxxxxxx>
---
 server/reds.c          | 23 ++++++++++++++++++-----
 server/video-encoder.h |  1 +
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index cd57592..cc44db2 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3607,7 +3607,7 @@ static const int video_codec_caps[] = {
 
 /* Expected string:  encoder:codec;encoder:codec */
 static const char* parse_video_codecs(const char *codecs, char **encoder,
-                                      char **codec)
+                                      char **codec, char **rank)
 {
     if (!codecs) {
         return NULL;
@@ -3619,8 +3619,8 @@ static const char* parse_video_codecs(const char *codecs, char **encoder,
         return NULL;
     }
     int n;
-    *encoder = *codec = NULL;
-    if (sscanf(codecs, "%m[0-9a-zA-Z_]:%m[0-9a-zA-Z_]%n", encoder, codec, &n) != 2) {
+    *encoder = *codec = *rank = NULL;
+    if (sscanf(codecs, "%m[0-9a-zA-Z_]:%m[0-9a-zA-Z_]:%m[0-9]%n", encoder, codec, rank, &n) >= 2) {
         while (*codecs != '\0' && *codecs != ';') {
             codecs++;
         }
@@ -3629,6 +3629,14 @@ static const char* parse_video_codecs(const char *codecs, char **encoder,
     return codecs + n;
 }
 
+static gint sort_video_codecs_on_rank(gconstpointer a_pointer, gconstpointer b_pointer)
+{
+    const RedVideoCodec* a = a_pointer;
+    const RedVideoCodec* b = b_pointer;
+
+    return (b->rank - a->rank);
+}
+
 static void reds_set_video_codecs(RedsState *reds, GArray *video_codecs)
 {
     /* The video_codecs array is immutable */
@@ -3636,12 +3644,14 @@ static void reds_set_video_codecs(RedsState *reds, GArray *video_codecs)
 
     spice_return_if_fail(video_codecs != NULL);
 
+    g_array_sort(video_codecs, sort_video_codecs_on_rank);
+
     reds->config->video_codecs = video_codecs;
 }
 
 static void reds_set_video_codecs_from_string(RedsState *reds, const char *codecs)
 {
-    char *encoder_name, *codec_name;
+    char *encoder_name, *codec_name, *codec_rank;
     GArray *video_codecs;
 
     if (strcmp(codecs, "auto") == 0) {
@@ -3650,7 +3660,7 @@ static void reds_set_video_codecs_from_string(RedsState *reds, const char *codec
 
     video_codecs = g_array_new(FALSE, FALSE, sizeof(RedVideoCodec));
     const char *c = codecs;
-    while ( (c = parse_video_codecs(c, &encoder_name, &codec_name)) ) {
+    while ( (c = parse_video_codecs(c, &encoder_name, &codec_name, &codec_rank)) ) {
         uint32_t encoder_index, codec_index;
         if (!encoder_name || !codec_name) {
             spice_warning("spice: invalid encoder:codec value at %s", codecs);
@@ -3666,14 +3676,17 @@ static void reds_set_video_codecs_from_string(RedsState *reds, const char *codec
 
         } else {
             RedVideoCodec new_codec;
+
             new_codec.create = video_encoder_procs[encoder_index];
             new_codec.type = video_codec_names[codec_index].id;
             new_codec.cap = video_codec_caps[codec_index];
+            new_codec.rank = (codec_rank != NULL) ? atoi(codec_rank) : 1;
             g_array_append_val(video_codecs, new_codec);
         }
 
         free(encoder_name);
         free(codec_name);
+        free(codec_rank);
         codecs = c;
     }
 
diff --git a/server/video-encoder.h b/server/video-encoder.h
index a4cd2b3..ecce749 100644
--- a/server/video-encoder.h
+++ b/server/video-encoder.h
@@ -210,6 +210,7 @@ VideoEncoder* gstreamer_encoder_new(SpiceVideoCodecType codec_type,
 typedef struct RedVideoCodec {
     new_video_encoder_t create;
     SpiceVideoCodecType type;
+    uint8_t rank;
     uint32_t cap;
 } RedVideoCodec;
 
-- 
2.9.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]