Skip to content

Commit

Permalink
#621 part 1:
Browse files Browse the repository at this point in the history
* extract the compression from the clipboard class and move it to ServerSource / Client classes which now know about which compressors the other end supports and can compress it there
* bump the maximum clipboard packet size since we check it uncompressed

git-svn-id: https://xpra.org/svn/Xpra/trunk@7041 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 30, 2014
1 parent 0808fc7 commit f14558f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
20 changes: 19 additions & 1 deletion src/xpra/client/gtk2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,14 @@ def setup_clipboard_helper(self, helperClass, *args, **kwargs):
clipboardlog("setup_clipboard_helper(%s, %s, %s)", helperClass, args, kwargs)
def clipboard_send(*parts):
if self.clipboard_enabled:
self.send(*parts)
#handle clipboard compression if needed:
from xpra.net.compression import Uncompressed
packet = list(parts)
for i in range(len(packet)):
v = packet[i]
if type(v)==Uncompressed:
packet[i] = self.compressed_wrapper(v.datatype, v.data)
self.send(*packet)
else:
clipboardlog("clipboard is disabled, not sending clipboard packet")
def clipboard_progress(local_requests, remote_requests):
Expand Down Expand Up @@ -274,6 +281,17 @@ def clipboard_notify(self, n):
self.tray.set_blinking(False)


def compressed_wrapper(self, datatype, data):
#FIXME: ugly assumptions here, should pass by name!
zlib = "zlib" in self.server_compressors
lz4 = "lz4" in self.server_compressors
lzo = "lzo" in self.server_compressors
if zlib or lz4 or lzo:
from xpra.net import compression
return compression.compressed_wrapper(datatype, data, zlib=zlib, lz4=lz4, lzo=lzo, can_inline=False)
return data


def make_hello(self):
capabilities = GTKXpraClient.make_hello(self)
if xor_str is not None:
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ def parse_server_capabilities(self):
self.bell_enabled = self.server_supports_bell and self.client_supports_bell
self.server_supports_clipboard = c.boolget("clipboard")
self.server_clipboards = c.strlistget("clipboards", ALL_CLIPBOARDS)
self.server_compressors = c.strlistget("compressors", ["zlib"])
self.clipboard_enabled = self.client_supports_clipboard and self.server_supports_clipboard
self.server_dbus_proxy = c.boolget("dbus_proxy")
self.mmap_enabled = self.supports_mmap and self.mmap_enabled and c.boolget("mmap_enabled")
Expand Down
16 changes: 7 additions & 9 deletions src/xpra/clipboard/clipboard_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from xpra.gtk_common.gobject_util import n_arg_signal
from xpra.gtk_common.gtk_util import GetClipboard, PROPERTY_CHANGE_MASK
from xpra.gtk_common.nested_main import NestedMainLoop
from xpra.net.compression import compressed_wrapper
from xpra.net.compression import Uncompressed


MAX_CLIPBOARD_PACKET_SIZE = 256*1024
MAX_CLIPBOARD_PACKET_SIZE = 4*1024*1024

ALL_CLIPBOARDS = ["CLIPBOARD", "PRIMARY", "SECONDARY"]
CLIPBOARDS = ALL_CLIPBOARDS
Expand Down Expand Up @@ -340,13 +340,11 @@ def got_contents(dtype, dformat, data):
proxy.get_contents(target, got_contents)

def _may_compress(self, dtype, dformat, wire_data):
if len(wire_data)>256:
wire_data = compressed_wrapper("clipboard: %s / %s" % (dtype, dformat), wire_data, zlib=True)
if len(wire_data)>self.max_clipboard_packet_size:
log.warn("even compressed, clipboard contents are too big and have not been sent:"
" %s compressed bytes dropped (maximum is %s)", len(wire_data), self.max_clipboard_packet_size)
return None
return wire_data
if len(wire_data)>self.max_clipboard_packet_size:
log.warn("clipboard contents are too big and have not been sent:"
" %s compressed bytes dropped (maximum is %s)", len(wire_data), self.max_clipboard_packet_size)
return None
return Uncompressed("clipboard: %s / %s" % (dtype, dformat), wire_data)

def _process_clipboard_contents(self, packet):
request_id, selection, dtype, dformat, wire_encoding, wire_data = packet[1:8]
Expand Down
10 changes: 10 additions & 0 deletions src/xpra/net/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ def __repr__(self):
return "LevelCompressed(%s: %s bytes as %s/%s)" % (self.datatype, len(self.data), self.algorithm, self.level)


class Uncompressed(object):
def __init__(self, datatype, data):
self.datatype = datatype
self.data = data
def __len__(self):
return len(self.data)
def __repr__(self):
return "Uncompressed(%s: %s bytes)" % (self.datatype, len(self.data))


def compressed_wrapper(datatype, data, level=5, zlib=False, lz4=False, lzo=False, can_inline=True):
if lz4:
assert use_lz4, "cannot use lz4"
Expand Down
5 changes: 2 additions & 3 deletions src/xpra/net/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def get_network_caps(legacy=True):
mmap = False
caps = {
"digest" : ("hmac", "xor"),
"rencode" : packet_encoding.use_rencode,
"bencode" : packet_encoding.use_bencode,
"yaml" : packet_encoding.use_yaml,
"compressors" : compression.get_enabled_compressors(),
"encoders" : packet_encoding.get_enabled_encoders(),
"mmap" : mmap,
}
if legacy:
Expand Down
11 changes: 10 additions & 1 deletion src/xpra/server/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from xpra.codecs.loader import get_codec, has_codec, OLD_ENCODING_NAMES_TO_NEW, NEW_ENCODING_NAMES_TO_OLD
from xpra.codecs.video_helper import getVideoHelper
from xpra.codecs.codec_constants import codec_spec
from xpra.net.compression import compressed_wrapper, Compressed
from xpra.net.compression import compressed_wrapper, Compressed, Uncompressed
from xpra.daemon_thread import make_daemon_thread
from xpra.os_util import platform_name, StringIOClass, thread, Queue, get_machine_id, get_user_uuid
from xpra.server.background_worker import add_work_item
Expand Down Expand Up @@ -1192,6 +1192,15 @@ def send_clipboard_enabled(self, reason=""):
def send_clipboard(self, packet):
if not self.clipboard_enabled or self.suspended:
return
packet = list(packet)
for i in range(len(packet)):
v = packet[i]
if type(v)==Uncompressed:
log.info("Uncompressed in clipboard packet!")
packet[i] = self.compressed_wrapper(v.datatype, v.data)
#TODO: move this out of the UI thread
#and compress it using the self.damage_data_queue
#or using a wrapper telling the network encode layer to do it
self.send(*packet)


Expand Down

0 comments on commit f14558f

Please sign in to comment.