vnc: add basic tight support
RFC 1/1 vnc: add basic tight support
This patch only add support for "basic" compression without any filter.
This should not be merged right now, because it's currently worse than zlib, but clients would prefer it. This only for preliminary review and comments.
Thanks,
--- Makefile | 2 + Makefile.objs | 1 + vnc-encoding-hextile.c | 5 +- vnc-encoding-tight.c | 287 ++++++++++++++++++++++++++++++++++++++++++++++++ vnc-encoding-tight.h | 200 +++++++++++++++++++++++++++++++++ vnc-encoding-zlib.c | 17 ++- vnc.c | 37 +++++-- vnc.h | 17 +++- 8 files changed, 544 insertions(+), 22 deletions(-) create mode 100644 vnc-encoding-tight.c create mode 100644 vnc-encoding-tight.h
Makefile +2 -0
@@ -124,6 +124,8 @@ vnc-encoding-zlib.o: vnc.h vnc-encoding-hextile.o: vnc.h +vnc-encoding-tight.o: vnc.h vnc-encoding-tight.h + curses.o: curses.c keymaps.h curses_keys.h bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS)
Makefile.objs +1 -0
@@ -104,6 +104,7 @@ common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o common-obj-$(CONFIG_CURSES) += curses.o common-obj-y += vnc.o acl.o d3des.o common-obj-y += vnc-encoding-zlib.o vnc-encoding-hextile.o +common-obj-y += vnc-encoding-tight.o common-obj-y += iov.o common-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o common-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
vnc-encoding-hextile.c +3 -2
@@ -62,8 +62,8 @@ static void hextile_enc_cord(uint8_t *ptr, int x, int y, int w, int h)#undef BPP#undef GENERIC -void vnc_hextile_send_framebuffer_update (VncState *vs,int x, -int y,int w,int h) +int vnc_hextile_send_framebuffer_update (VncState *vs,int x, +int y,int w,int h) {int i, j;int has_fg, has_bg;
@@ -83,6 +83,7 @@ void vnc_hextile_send_framebuffer_update(VncState *vs, int x,free (last_fg);free (last_bg); +return 1 ; }void vnc_hextile_set_pixel_conversion (VncState *vs,int generic)
vnc-encoding-tight.c new file +287 -0
287 lines not on this page · raw message
vnc-encoding-tight.h new file +200 -0
200 lines not on this page · raw message
vnc-encoding-zlib.c +10 -7
@@ -28,7 +28,7 @@#define ZALLOC_ALIGNMENT 16 -static void *zalloc (void *x,unsigned items,unsigned size) +void *vnc_zlib_zalloc (void *x,unsigned items,unsigned size) {void *p;
@@ -40,7 +40,7 @@ static void *zalloc(void *x, unsigned items, unsigned size)return (p); } -static void zfree (void *x,void *addr) +void vnc_zlib_zfree (void *x,void *addr) {qemu_free (addr); }
@@ -72,8 +72,8 @@ static int vnc_zlib_stop(VncState *vs)VNC_DEBUG ("VNC: initializing zlib stream\n" );VNC_DEBUG ("VNC: opaque = %p | vs = %p\n" , zstream->opaque, vs); - zstream->zalloc = zalloc; - zstream->zfree = zfree; + zstream->zalloc = vnc_zlib_zalloc; + zstream->zfree = vnc_zlib_zfree; err =deflateInit2 (zstream, vs->tight_compression,Z_DEFLATED ,MAX_WBITS ,MAX_MEM_LEVEL ,Z_DEFAULT_STRATEGY );
@@ -116,7 +116,7 @@ static int vnc_zlib_stop(VncState *vs)return zstream->total_out - previous_out; } -void vnc_zlib_send_framebuffer_update (VncState *vs,int x,int y,int w,int h) +int vnc_zlib_send_framebuffer_update (VncState *vs,int x,int y,int w,int h) {int old_offset, new_offset, bytes_written;
@@ -131,14 +131,17 @@ void vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h)vnc_raw_send_framebuffer_update (vs, x, y, w, h); bytes_written =vnc_zlib_stop (vs); -if (bytes_written ==-1 ) -return ; +if (bytes_written ==-1 ) { +return 0 ; + }// hack in the size new_offset = vs->output.offset; vs->output.offset = old_offset;vnc_write_u32 (vs, bytes_written); vs->output.offset = new_offset; + +return 1 ; }void vnc_zlib_init (VncState *vs)
vnc.c +27 -10
@@ -638,7 +638,7 @@ static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size) } } -void vnc_raw_send_framebuffer_update (VncState *vs,int x,int y,int w,int h) +int vnc_raw_send_framebuffer_update (VncState *vs,int x,int y,int w,int h) {int i;uint8_t *row;
@@ -649,23 +649,31 @@ void vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h) vs->write_pixels (vs, row, w *ds_get_bytes_per_pixel (vs->ds)); row +=ds_get_linesize (vs->ds); } +return 1 ; } -static void send_framebuffer_update (VncState *vs,int x,int y,int w,int h) +static int send_framebuffer_update (VncState *vs,int x,int y,int w,int h) { +int n =0 ; +switch (vs->vnc_encoding) {case VNC_ENCODING_ZLIB : -vnc_zlib_send_framebuffer_update (vs, x, y, w, h); + n =vnc_zlib_send_framebuffer_update (vs, x, y, w, h);break ;case VNC_ENCODING_HEXTILE :vnc_framebuffer_update (vs, x, y, w, h,VNC_ENCODING_HEXTILE ); -vnc_hextile_send_framebuffer_update (vs, x, y, w, h); + n =vnc_hextile_send_framebuffer_update (vs, x, y, w, h); +break ; +case VNC_ENCODING_TIGHT : + n =vnc_tight_send_framebuffer_update (vs, x, y, w, h);break ;default :vnc_framebuffer_update (vs, x, y, w, h,VNC_ENCODING_RAW ); -vnc_raw_send_framebuffer_update (vs, x, y, w, h); + n =vnc_raw_send_framebuffer_update (vs, x, y, w, h);break ; } + +return n; }static void vnc_copy (VncState *vs,int src_x,int src_y,int dst_x,int dst_y,int w,int h)
@@ -776,6 +784,7 @@ static int vnc_update_client(VncState *vs, int has_dirty)int y;int n_rectangles;int saved_offset; +int n;if (vs->output.offset && !vs->audio_cap && !vs->force_update)/* kernel send buffers are full -> drop frames to throttle */
@@ -808,16 +817,18 @@ static int vnc_update_client(VncState *vs, int has_dirty) }else {if (last_x !=-1 ) {int h =find_and_clear_dirty_height (vs, y, last_x, x); -send_framebuffer_update (vs, last_x *16 , y, (x - last_x) *16 , h); - n_rectangles++; + n =send_framebuffer_update (vs, last_x *16 , y, + (x - last_x) *16 , h); + n_rectangles += n; } last_x =-1 ; } }if (last_x !=-1 ) {int h =find_and_clear_dirty_height (vs, y, last_x, x); -send_framebuffer_update (vs, last_x *16 , y, (x - last_x) *16 , h); - n_rectangles++; + n =send_framebuffer_update (vs, last_x *16 , y, + (x - last_x) *16 , h); + n_rectangles += n; } } vs->output.buffer[saved_offset] = (n_rectangles >>8 ) &0xFF ;
@@ -1600,8 +1611,10 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)unsigned int enc =0 ;vnc_zlib_init (vs); +vnc_tight_init (vs); vs->features =0 ; - vs->vnc_encoding =-1 ; +if (!vs->vnc_encoding) + vs->vnc_encoding =-1 ; vs->tight_compression =9 ; vs->tight_quality =9 ; vs->absolute =-1 ;
@@ -1619,6 +1632,10 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings) vs->features |=VNC_FEATURE_HEXTILE_MASK ;set_encoding (vs, enc);break ; +case VNC_ENCODING_TIGHT : + vs->features |=VNC_FEATURE_TIGHT_MASK ; +set_encoding (vs, enc); +break ;case VNC_ENCODING_ZLIB : vs->features |=VNC_FEATURE_ZLIB_MASK ;set_encoding (vs, enc);
vnc.h +14 -3
@@ -166,6 +166,12 @@ struct VncState/* Tight */ uint8_t tight_quality;uint8_t tight_compression; +uint8_t tight_pixel24; +Buffer tight; +Buffer tight_tmp; +Buffer tight_zlib; +int tight_levels[4 ]; +z_stream tight_stream[4 ];/* Hextile */ VncSendHextileTile *send_hextile_tile;
@@ -391,13 +397,18 @@ void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,void vnc_convert_pixel (VncState *vs,uint8_t *buf,uint32_t v);/* Encodings */ -void vnc_raw_send_framebuffer_update (VncState *vs,int x,int y,int w,int h); +int vnc_raw_send_framebuffer_update (VncState *vs,int x,int y,int w,int h); -void vnc_hextile_send_framebuffer_update (VncState *vs,int x, +int vnc_hextile_send_framebuffer_update (VncState *vs,int x,int y,int w,int h);void vnc_hextile_set_pixel_conversion (VncState *vs,int generic);void vnc_zlib_init (VncState *vs); -void vnc_zlib_send_framebuffer_update (VncState *vs,int x,int y,int w,int h); +void *vnc_zlib_zalloc (void *x,unsigned items,unsigned size); +void vnc_zlib_zfree (void *x,void *addr); +int vnc_zlib_send_framebuffer_update (VncState *vs,int x,int y,int w,int h); + +void vnc_tight_init (VncState *vs); +int vnc_tight_send_framebuffer_update (VncState *vs,int x,int y,int w,int h);#endif /* __QEMU_VNC_H */
Signature · 1 line
1.7.1