From patchwork Wed Aug 11 05:49:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Chary X-Patchwork-Id: 61440 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 76B12B6EF2 for ; Wed, 11 Aug 2010 15:52:28 +1000 (EST) Received: from localhost ([127.0.0.1]:37767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oj4Ej-0005nl-BV for incoming@patchwork.ozlabs.org; Wed, 11 Aug 2010 01:52:25 -0400 Received: from [140.186.70.92] (port=37832 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oj4Ck-0005mU-5X for qemu-devel@nongnu.org; Wed, 11 Aug 2010 01:50:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oj4Ci-0007Pp-JJ for qemu-devel@nongnu.org; Wed, 11 Aug 2010 01:50:22 -0400 Received: from relay1-v.mail.gandi.net ([217.70.178.75]:38607 helo=mrelay1-v.mgt.gandi.net) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oj4Ci-0007Pi-86 for qemu-devel@nongnu.org; Wed, 11 Aug 2010 01:50:20 -0400 X-Originating-IP: 217.70.178.38 Received: from mfilter4-v.gandi.net (mfilter4-v.gandi.net [217.70.178.38]) by mrelay1-v.mgt.gandi.net (Postfix) with ESMTP id C97BB362B8; Wed, 11 Aug 2010 07:50:19 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter4-v.gandi.net Received: from mrelay1-v.mgt.gandi.net ([217.70.178.75]) by mfilter4-v.gandi.net (mfilter4-v.gandi.net [217.70.178.38]) (amavisd-new, port 10024) with ESMTP id a5XGzTxmeXQt; Wed, 11 Aug 2010 07:50:19 +0200 (CEST) X-Originating-IP: 82.241.209.44 Received: from tartiflon (falgoret.iksaif.net [82.241.209.44]) (Authenticated sender: fake@iksaif.net) by mrelay1-v.mgt.gandi.net (Postfix) with ESMTPSA id CF244362C2; Wed, 11 Aug 2010 07:50:15 +0200 (CEST) From: Corentin Chary To: Qemu-development List Date: Wed, 11 Aug 2010 07:49:34 +0200 Message-Id: <1281505785-22523-5-git-send-email-corentincj@iksaif.net> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1281505785-22523-1-git-send-email-corentincj@iksaif.net> References: <1281505785-22523-1-git-send-email-corentincj@iksaif.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Corentin Chary , Anthony Liguori , Alexander Graf , Andre Przywara Subject: [Qemu-devel] [PATCH 04/15] vnc: tight: use the update frequency to choose between lossy and lossless 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 Use the new update frequency infrastructure to use jpeg for regions with high update frequency. Signed-off-by: Corentin Chary --- ui/vnc-enc-tight.c | 75 +++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 62 insertions(+), 13 deletions(-) diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index 8ca5570..5ca4342 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -72,6 +72,26 @@ static const struct { static int tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); +#ifdef CONFIG_VNC_JPEG +static const struct { + double jpeg_freq_min; /* Don't send JPEG if the freq is bellow */ + double jpeg_freq_threshold; /* Always send JPEG if the freq is above */ + int jpeg_idx; /* Allow indexed JPEG */ + int jpeg_full; /* Allow full color JPEG */ +} tight_jpeg_conf[] = { + { 0, 4, 1, 1 }, + { 0, 4, 1, 1 }, + { 0, 4, 1, 1 }, + { 0, 4, 1, 1 }, + { 0, 4, 0, 1 }, + { 0.1, 4, 0, 1 }, + { 0.2, 4, 0, 1 }, + { 0.3, 6, 0, 0 }, + { 0.4, 8, 0, 0 }, + { 0.5, 10, 0, 0 }, +}; +#endif + #ifdef CONFIG_VNC_PNG static const struct { int png_zlib_level, png_filters; @@ -1478,12 +1498,13 @@ static int send_sub_rect_nojpeg(VncState *vs, int x, int y, int w, int h, #ifdef CONFIG_VNC_JPEG static int send_sub_rect_jpeg(VncState *vs, int x, int y, int w, int h, int bg, int fg, int colors, - VncPalette *palette) + VncPalette *palette, bool force) { int ret; if (colors == 0) { - if (tight_detect_smooth_image(vs, w, h)) { + if (force || (tight_jpeg_conf[vs->tight.quality].jpeg_full && + tight_detect_smooth_image(vs, w, h))) { int quality = tight_conf[vs->tight.quality].jpeg_quality; ret = send_jpeg_rect(vs, x, y, w, h, quality); @@ -1495,8 +1516,9 @@ static int send_sub_rect_jpeg(VncState *vs, int x, int y, int w, int h, } else if (colors == 2) { ret = send_mono_rect(vs, x, y, w, h, bg, fg); } else if (colors <= 256) { - if (colors > 96 && - tight_detect_smooth_image(vs, w, h)) { + if (force || (colors > 96 && + tight_jpeg_conf[vs->tight.quality].jpeg_idx && + tight_detect_smooth_image(vs, w, h))) { int quality = tight_conf[vs->tight.quality].jpeg_quality; ret = send_jpeg_rect(vs, x, y, w, h, quality); @@ -1514,6 +1536,8 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h) uint32_t bg = 0, fg = 0; int colors; int ret = 0; + bool force_jpeg = false; + bool allow_jpeg = true; vnc_framebuffer_update(vs, x, y, w, h, vs->tight.type); @@ -1521,11 +1545,26 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h) vnc_raw_send_framebuffer_update(vs, x, y, w, h); vnc_tight_stop(vs); +#ifdef CONFIG_VNC_JPEG + if (vs->tight.quality != -1) { + double freq = vnc_update_freq(vs, x, y, w, h); + + if (freq < tight_jpeg_conf[vs->tight.quality].jpeg_freq_min) { + allow_jpeg = false; + } + if (freq >= tight_jpeg_conf[vs->tight.quality].jpeg_freq_threshold) { + force_jpeg = true; + vnc_sent_lossy_rect(vs, x, y, w, h); + } + } +#endif + colors = tight_fill_palette(vs, x, y, w * h, &fg, &bg, &palette); #ifdef CONFIG_VNC_JPEG - if (vs->tight.quality != -1) { - ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, palette); + if (allow_jpeg && vs->tight.quality != -1) { + ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, palette, + force_jpeg); } else { ret = send_sub_rect_nojpeg(vs, x, y, w, h, bg, fg, colors, palette); } @@ -1548,7 +1587,8 @@ static int send_sub_rect_solid(VncState *vs, int x, int y, int w, int h) return send_solid_rect(vs); } -static int send_rect_simple(VncState *vs, int x, int y, int w, int h) +static int send_rect_simple(VncState *vs, int x, int y, int w, int h, + bool split) { int max_size, max_width; int max_sub_width, max_sub_height; @@ -1559,7 +1599,7 @@ static int send_rect_simple(VncState *vs, int x, int y, int w, int h) max_size = tight_conf[vs->tight.compression].max_rect_size; max_width = tight_conf[vs->tight.compression].max_rect_width; - if (w > max_width || w * h > max_size) { + if (split && (w > max_width || w * h > max_size)) { max_sub_width = (w > max_width) ? max_width : w; max_sub_height = max_size / max_sub_width; @@ -1590,7 +1630,7 @@ static int find_large_solid_color_rect(VncState *vs, int x, int y, /* If a rectangle becomes too large, send its upper part now. */ if (dy - y >= max_rows) { - n += send_rect_simple(vs, x, y, w, max_rows); + n += send_rect_simple(vs, x, y, w, max_rows, true); y += max_rows; h -= max_rows; } @@ -1629,7 +1669,7 @@ static int find_large_solid_color_rect(VncState *vs, int x, int y, /* Send rectangles at top and left to solid-color area. */ if (y_best != y) { - n += send_rect_simple(vs, x, y, w, y_best-y); + n += send_rect_simple(vs, x, y, w, y_best-y, true); } if (x_best != x) { n += tight_send_framebuffer_update(vs, x, y_best, @@ -1656,7 +1696,7 @@ static int find_large_solid_color_rect(VncState *vs, int x, int y, return n; } } - return n + send_rect_simple(vs, x, y, w, h); + return n + send_rect_simple(vs, x, y, w, h, true); } static int tight_send_framebuffer_update(VncState *vs, int x, int y, @@ -1671,8 +1711,17 @@ static int tight_send_framebuffer_update(VncState *vs, int x, int y, vs->tight.pixel24 = false; } - if (w * h < VNC_TIGHT_MIN_SPLIT_RECT_SIZE) - return send_rect_simple(vs, x, y, w, h); + if (vs->tight.quality != -1) { + double freq = vnc_update_freq(vs, x, y, w, h); + + if (freq > tight_jpeg_conf[vs->tight.quality].jpeg_freq_threshold) { + return send_rect_simple(vs, x, y, w, h, false); + } + } + + if (w * h < VNC_TIGHT_MIN_SPLIT_RECT_SIZE) { + return send_rect_simple(vs, x, y, w, h, true); + } /* Calculate maximum number of rows in one non-solid rectangle. */