From patchwork Thu Oct 7 07:55:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 67003 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 99F75B6F11 for ; Thu, 7 Oct 2010 19:05:23 +1100 (EST) Received: from localhost ([127.0.0.1]:42228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3lTc-0002W0-Kh for incoming@patchwork.ozlabs.org; Thu, 07 Oct 2010 04:05:20 -0400 Received: from [140.186.70.92] (port=36355 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3lKF-0006sK-6C for qemu-devel@nongnu.org; Thu, 07 Oct 2010 03:55:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P3lKA-0003gQ-Pa for qemu-devel@nongnu.org; Thu, 07 Oct 2010 03:55:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P3lKA-0003fx-Gc for qemu-devel@nongnu.org; Thu, 07 Oct 2010 03:55:34 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o977tXMO029279 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Oct 2010 03:55:33 -0400 Received: from rincewind.home.kraxel.org (vpn1-5-214.ams2.redhat.com [10.36.5.214]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o977tT7b026581; Thu, 7 Oct 2010 03:55:31 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 2C7B74556B; Thu, 7 Oct 2010 09:55:26 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 7 Oct 2010 09:55:23 +0200 Message-Id: <1286438126-11250-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1286438126-11250-1-git-send-email-kraxel@redhat.com> References: <1286438126-11250-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Yonit Halperin Subject: [Qemu-devel] [PATCH 2/5] spice: make compression configurable. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Yonit Halperin --- qemu-config.c | 9 ++++++ qemu-options.hx | 9 ++++++ ui/spice-core.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 26748a5..8b545b1 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -391,6 +391,15 @@ QemuOptsList qemu_spice_opts = { },{ .name = "tls-ciphers", .type = QEMU_OPT_STRING, + },{ + .name = "image-compression", + .type = QEMU_OPT_STRING, + },{ + .name = "jpeg-wan-compression", + .type = QEMU_OPT_STRING, + },{ + .name = "zlib-glz-wan-compression", + .type = QEMU_OPT_STRING, }, { /* end if list */ } }, diff --git a/qemu-options.hx b/qemu-options.hx index 9d3f8ef..59db632 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -704,6 +704,15 @@ The x509 file names can also be configured individually. @item tls-ciphers= Specify which ciphers to use. +@item image-compression=[auto_glz|auto_lz|quic|glz|lz|off] +Configure image compression (lossless). +Default is auto_glz. + +@item jpeg-wan-compression=[auto|never|allways] +@item zlib-glz-wan-compression=[auto|never|allways] +Configure wan image compression (lossy for slow links). +Default is auto. + @end table ETEXI diff --git a/ui/spice-core.c b/ui/spice-core.c index 51aa782..1567046 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -137,6 +137,59 @@ static SpiceCoreInterface core_interface = { .watch_remove = watch_remove, }; +/* config string parsing */ + +static int name2enum(const char *string, const char *table[], int entries) +{ + int i; + + if (string) { + for (i = 0; i < entries; i++) { + if (!table[i]) { + continue; + } + if (strcmp(string, table[i]) != 0) { + continue; + } + return i; + } + } + return -1; +} + +static int parse_name(const char *string, const char *optname, + const char *table[], int entries) +{ + int value = name2enum(string, table, entries); + + if (value != -1) { + return value; + } + fprintf(stderr, "spice: invalid %s: %s\n", optname, string); + exit(1); +} + +static const char *compression_names[] = { + [ SPICE_IMAGE_COMPRESS_OFF ] = "off", + [ SPICE_IMAGE_COMPRESS_AUTO_GLZ ] = "auto_glz", + [ SPICE_IMAGE_COMPRESS_AUTO_LZ ] = "auto_lz", + [ SPICE_IMAGE_COMPRESS_QUIC ] = "quic", + [ SPICE_IMAGE_COMPRESS_GLZ ] = "glz", + [ SPICE_IMAGE_COMPRESS_LZ ] = "lz", +}; +#define parse_compression(_name) \ + parse_name(_name, "image compression", \ + compression_names, ARRAY_SIZE(compression_names)) + +static const char *wan_compression_names[] = { + [ SPICE_WAN_COMPRESSION_AUTO ] = "auto", + [ SPICE_WAN_COMPRESSION_NEVER ] = "never", + [ SPICE_WAN_COMPRESSION_ALWAYS ] = "always", +}; +#define parse_wan_compression(_name) \ + parse_name(_name, "wan compression", \ + wan_compression_names, ARRAY_SIZE(wan_compression_names)) + /* functions for the rest of qemu */ void qemu_spice_init(void) @@ -150,6 +203,8 @@ void qemu_spice_init(void) *x509_cert_file = NULL, *x509_cacert_file = NULL; int port, tls_port, len; + spice_image_compression_t compression; + spice_wan_compression_t wan_compr; if (!opts) { return; @@ -217,8 +272,26 @@ void qemu_spice_init(void) spice_server_set_noauth(spice_server); } - /* TODO: make configurable via cmdline */ - spice_server_set_image_compression(spice_server, SPICE_IMAGE_COMPRESS_AUTO_GLZ); + compression = SPICE_IMAGE_COMPRESS_AUTO_GLZ; + str = qemu_opt_get(opts, "image-compression"); + if (str) { + compression = parse_compression(str); + } + spice_server_set_image_compression(spice_server, compression); + + wan_compr = SPICE_WAN_COMPRESSION_AUTO; + str = qemu_opt_get(opts, "jpeg-wan-compression"); + if (str) { + wan_compr = parse_wan_compression(str); + } + spice_server_set_jpeg_compression(spice_server, wan_compr); + + wan_compr = SPICE_WAN_COMPRESSION_AUTO; + str = qemu_opt_get(opts, "zlib-glz-wan-compression"); + if (str) { + wan_compr = parse_wan_compression(str); + } + spice_server_set_zlib_glz_compression(spice_server, wan_compr); spice_server_init(spice_server, &core_interface); using_spice = 1;