qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Corentin Chary <corentincj@iksaif.net>
To: Qemu-development List <qemu-devel@nongnu.org>
Cc: Corentin Chary <corentincj@iksaif.net>,
	Anthony Liguori <aliguori@linux.vnet.ibm.com>,
	Alexander Graf <agraf@suse.de>,
	Andre Przywara <andre.przywara@amd.com>
Subject: [Qemu-devel] [PATCH v2 04/15] vnc: tight: use the update frequency to choose between lossy and lossless
Date: Thu, 11 Nov 2010 17:56:53 +0100	[thread overview]
Message-ID: <1289494624-12807-5-git-send-email-corentincj@iksaif.net> (raw)
In-Reply-To: <1289494624-12807-1-git-send-email-corentincj@iksaif.net>

Use the new update frequency infrastructure to use jpeg for regions with
high update frequency.

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 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 af45edd..ad9a9a8 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;
@@ -1476,12 +1496,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);
@@ -1493,8 +1514,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 != (uint8_t)-1) {
-        ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, palette);
+    if (allow_jpeg && vs->tight.quality != (uint8_t)-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. */
 
-- 
1.7.3.2

  parent reply	other threads:[~2010-11-11 16:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-11 16:56 [Qemu-devel] [PATCH v2 00/15] vnc: adapative tight, zrle, zywrle, and bitmap module Corentin Chary
2010-11-11 16:56 ` [Qemu-devel] [PATCH v2 01/15] vnc: don't set the quality if lossy encoding are disabled Corentin Chary
2010-11-11 16:56 ` [Qemu-devel] [PATCH v2 02/15] vnc: add a way to get the update frequency for a given region Corentin Chary
2010-11-11 16:56 ` [Qemu-devel] [PATCH v2 03/15] vnc: refresh lossy rect after a given timeout Corentin Chary
2010-11-11 18:44   ` Blue Swirl
2010-11-11 16:56 ` Corentin Chary [this message]
2010-11-11 16:56 ` [Qemu-devel] [PATCH v2 05/15] vnc: palette: use a pool to reduce memory allocations Corentin Chary
2010-11-11 16:56 ` [Qemu-devel] [PATCH v2 06/15] vnc: palette: add palette_init calls Corentin Chary
2010-11-11 16:56 ` [Qemu-devel] [PATCH v2 07/15] vnc: palette: and fill and color calls Corentin Chary
2010-11-11 16:56 ` [Qemu-devel] [PATCH v2 08/15] vnc: Add ZRLE and ZYWRLE encodings Corentin Chary
2010-11-11 18:58   ` Blue Swirl
2010-11-11 16:56 ` [Qemu-devel] [PATCH v2 09/15] vnc: fix uint8_t comparisons with negative values Corentin Chary
2010-11-11 16:56 ` [Qemu-devel] [PATCH v2 10/15] vnc: fix lossy rect refreshing Corentin Chary
2010-11-11 16:57 ` [Qemu-devel] [PATCH v2 11/15] bitmap: add a generic bitmap and bitops library Corentin Chary
2010-11-11 19:07   ` Blue Swirl
2010-11-11 21:25     ` Corentin Chary
2010-11-11 16:57 ` [Qemu-devel] [PATCH v2 12/15] vnc: use the new generic bitmap functions Corentin Chary
2010-11-11 16:57 ` [Qemu-devel] [PATCH v2 13/15] vnc: don't try to send bigger updates that client height Corentin Chary
2010-11-11 16:57 ` [Qemu-devel] [PATCH v2 14/15] vnc: tight: tweak adaptive tight settings Corentin Chary
2010-11-11 16:57 ` [Qemu-devel] [PATCH v2 15/15] vnc: add a non-adaptive option Corentin Chary
2010-11-11 17:02 ` [Qemu-devel] Re: [PATCH v2 00/15] vnc: adapative tight, zrle, zywrle, and bitmap module Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289494624-12807-5-git-send-email-corentincj@iksaif.net \
    --to=corentincj@iksaif.net \
    --cc=agraf@suse.de \
    --cc=aliguori@linux.vnet.ibm.com \
    --cc=andre.przywara@amd.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).