[Spice-devel] [spice-server v2 7/9] reds: set video codec in a different function
Victor Toso
victortoso at redhat.com
Wed Nov 2 17:30:37 UTC 2016
From: Victor Toso <me at victortoso.com>
Small refactor. This will be useful in the next patch.
Signed-off-by: Victor Toso <victortoso at redhat.com>
---
server/reds.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/server/reds.c b/server/reds.c
index bfa479e..cd57592 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3629,17 +3629,26 @@ static const char* parse_video_codecs(const char *codecs, char **encoder,
return codecs + n;
}
-static void reds_set_video_codecs(RedsState *reds, const char *codecs)
+static void reds_set_video_codecs(RedsState *reds, GArray *video_codecs)
+{
+ /* The video_codecs array is immutable */
+ g_clear_pointer(&reds->config->video_codecs, g_array_unref);
+
+ spice_return_if_fail(video_codecs != NULL);
+
+ reds->config->video_codecs = video_codecs;
+}
+
+static void reds_set_video_codecs_from_string(RedsState *reds, const char *codecs)
{
char *encoder_name, *codec_name;
+ GArray *video_codecs;
if (strcmp(codecs, "auto") == 0) {
codecs = default_video_codecs;
}
- /* The video_codecs array is immutable */
- g_array_unref(reds->config->video_codecs);
- reds->config->video_codecs = g_array_new(FALSE, FALSE, sizeof(RedVideoCodec));
+ video_codecs = g_array_new(FALSE, FALSE, sizeof(RedVideoCodec));
const char *c = codecs;
while ( (c = parse_video_codecs(c, &encoder_name, &codec_name)) ) {
uint32_t encoder_index, codec_index;
@@ -3660,13 +3669,21 @@ static void reds_set_video_codecs(RedsState *reds, const char *codecs)
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];
- g_array_append_val(reds->config->video_codecs, new_codec);
+ g_array_append_val(video_codecs, new_codec);
}
free(encoder_name);
free(codec_name);
codecs = c;
}
+
+ if (video_codecs->len == 0) {
+ spice_debug("Failed to set video codecs");
+ g_array_unref(video_codecs);
+ return;
+ }
+
+ reds_set_video_codecs(reds, video_codecs);
}
SPICE_GNUC_VISIBLE int spice_server_init(SpiceServer *reds, SpiceCoreInterface *core)
@@ -3678,7 +3695,7 @@ SPICE_GNUC_VISIBLE int spice_server_init(SpiceServer *reds, SpiceCoreInterface *
reds_add_renderer(reds, default_renderer);
}
if (reds->config->video_codecs->len == 0) {
- reds_set_video_codecs(reds, default_video_codecs);
+ reds_set_video_codecs_from_string(reds, default_video_codecs);
}
return ret;
}
@@ -3992,7 +4009,7 @@ uint32_t reds_get_streaming_video(const RedsState *reds)
SPICE_GNUC_VISIBLE int spice_server_set_video_codecs(SpiceServer *reds, const char *video_codecs)
{
- reds_set_video_codecs(reds, video_codecs);
+ reds_set_video_codecs_from_string(reds, video_codecs);
reds_on_vc_change(reds);
return 0;
}
--
2.9.3
More information about the Spice-devel
mailing list