From: Victor Toso <me@xxxxxxxxxxxxxx> SpiceVideoCodecRank was recently introduce in spice-protocol as a client side preference for video codecs. This patch implements a new value to the preference introduced in 497fcbb0a315b034ba keeping it backwards compatible. The new value is the SpiceVideoCodecRank and should be set as last argument as for instance: encoder:codec:rank Video codecs will now be ordered by rank. Signed-off-by: Victor Toso <victortoso@xxxxxxxxxx> --- configure.ac | 2 +- server/reds.c | 27 ++++++++++++++++++++++----- server/video-encoder.h | 1 + 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 68aed15..2d4aa3e 100644 --- a/configure.ac +++ b/configure.ac @@ -143,7 +143,7 @@ AS_IF([test x"$have_smartcard" = "xyes"], [ AS_VAR_APPEND([SPICE_REQUIRES], [" libcacard >= 0.1.2"]) ]) -SPICE_PROTOCOL_MIN_VER=0.12.12 +SPICE_PROTOCOL_MIN_VER=0.12.13 PKG_CHECK_MODULES([SPICE_PROTOCOL], [spice-protocol >= $SPICE_PROTOCOL_MIN_VER]) AC_SUBST([SPICE_PROTOCOL_MIN_VER]) diff --git a/server/reds.c b/server/reds.c index b5d1270..6dbc010 100644 --- a/server/reds.c +++ b/server/reds.c @@ -3607,7 +3607,7 @@ static 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,21 @@ static void reds_set_video_codecs_from_string(RedsState *reds, const char *codec } else { RedVideoCodec new_codec; + SpiceVideoCodecRank rank = SPICE_VIDEO_CODEC_RANK_SOFTWARE_DECODER; + + if (codec_rank != NULL) + rank = atoi(codec_rank); + 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 = rank; 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..75a613d 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; + SpiceVideoCodecRank rank; uint32_t cap; } RedVideoCodec; -- 2.9.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel