Exemple #1
0
 def got_contents(dtype, dformat, data):
     debug("got_contents(%s, %s, %s:%s) data=0x%s..", dtype, dformat,
           type(data), len(data or ""),
           binascii.hexlify(str(data)[:200]))
     if dtype is None or data is None:
         no_contents()
         return
     munged = self._munge_raw_selection_to_wire(target, dtype, dformat,
                                                data)
     wire_encoding, wire_data = munged
     debug("clipboard raw -> wire: %r -> %r", (dtype, dformat, data),
           munged)
     if wire_encoding is None:
         no_contents()
         return
     if len(wire_data) > 256:
         wire_data = zlib_compress(
             "clipboard: %s / %s" % (dtype, dformat), wire_data)
         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)
             no_contents()
             return
     self.send("clipboard-contents", request_id, selection, dtype,
               dformat, wire_encoding, wire_data)
Exemple #2
0
            def got_contents(dtype, dformat, data):
                debug("got_contents(%s, %s, %s:%s) data=%s, str(data)=%s",
                      dtype, dformat, type(data), len(data or ""),
                      list(bytearray(data or "")[:200]),
                      str(data)[:200])

                def no_contents():
                    self.send("clipboard-contents-none", request_id, selection)

                if dtype is None or data is None:
                    no_contents()
                    return
                munged = self._munge_raw_selection_to_wire(
                    target, dtype, dformat, data)
                wire_encoding, wire_data = munged
                debug("clipboard raw -> wire: %r -> %r",
                      (dtype, dformat, data), munged)
                if wire_encoding is None:
                    no_contents()
                    return
                if len(wire_data) > 256:
                    wire_data = zlib_compress(
                        "clipboard: %s / %s" % (dtype, dformat), wire_data)
                    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"
                            % len(wire_data))
                        no_contents()
                        return
                self.send("clipboard-contents", request_id, selection, dtype,
                          dformat, wire_encoding, wire_data)
Exemple #3
0
 def rgb24_encode(self, data):
     #compress here and return a wrapper so network code knows it is already zlib compressed:
     zlib = zlib_compress("rgb24", data)
     if not self.encoding_client_options or not self.supports_rgb24zlib:
         return zlib, {}
     #wrap it using "Compressed" so the network layer receiving it
     #won't decompress it (leave it to the client's draw thread)
     return Compressed("rgb24", zlib.data), {"zlib": zlib.level}
Exemple #4
0
 def rgb24_encode(self, data):
     #compress here and return a wrapper so network code knows it is already zlib compressed:
     zlib = zlib_compress("rgb24", data)
     if not self.encoding_client_options or not self.supports_rgb24zlib:
         return  zlib, {}
     #wrap it using "Compressed" so the network layer receiving it
     #won't decompress it (leave it to the client's draw thread)
     return Compressed("rgb24", zlib.data), {"zlib" : zlib.level}
Exemple #5
0
 def send_cursor(self):
     self.send_cursor_pending = False
     self.cursor_data = get_cursor_image()
     if self.cursor_data:
         pixels = self.cursor_data[7]
         if self.default_cursor_data and pixels==self.default_cursor_data[7]:
             log("send_cursor(): default cursor - clearing it")
             self.cursor_data = None
         elif pixels is not None:
             if len(pixels)<64:
                 self.cursor_data[7] = str(pixels)
             else:
                 self.cursor_data[7] = zlib_compress("cursor", pixels)
     else:
         log("send_cursor() failed to get cursor image")
     for ss in self._server_sources.values():
         ss.send_cursor(self.cursor_data)
     return False
Exemple #6
0
 def send_cursor(self):
     self.send_cursor_pending = False
     self.cursor_data = get_cursor_image()
     if self.cursor_data:
         pixels = self.cursor_data[7]
         if self.default_cursor_data and pixels == self.default_cursor_data[
                 7]:
             log("send_cursor(): default cursor - clearing it")
             self.cursor_data = None
         elif pixels is not None:
             if len(pixels) < 64:
                 self.cursor_data[7] = str(pixels)
             else:
                 self.cursor_data[7] = zlib_compress("cursor", pixels)
     else:
         log("send_cursor() failed to get cursor image")
     for ss in self._server_sources.values():
         ss.send_cursor(self.cursor_data)
     return False
Exemple #7
0
 def got_contents(dtype, dformat, data):
     debug("got_contents(%s, %s, %s:%s) data=%s, str(data)=%s", dtype, dformat, type(data), len(data or ""), list(bytearray(data or "")[:200]), str(data)[:200])
     def no_contents():
         self.send("clipboard-contents-none", request_id, selection)
     if dtype is None or data is None:
         no_contents()
         return
     munged = self._munge_raw_selection_to_wire(target, dtype, dformat, data)
     wire_encoding, wire_data = munged
     debug("clipboard raw -> wire: %r -> %r", (dtype, dformat, data), munged)
     if wire_encoding is None:
         no_contents()
         return
     if len(wire_data)>256:
         wire_data = zlib_compress("clipboard: %s / %s" % (dtype, dformat), wire_data)
         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" % len(wire_data))
             no_contents()
             return
     self.send("clipboard-contents", request_id, selection,
                dtype, dformat, wire_encoding, wire_data)
Exemple #8
0
 def got_contents(dtype, dformat, data):
     debug("got_contents(%s, %s, %s:%s) data=0x%s..",
           dtype, dformat, type(data), len(data or ""), binascii.hexlify(str(data)[:200]))
     if dtype is None or data is None:
         no_contents()
         return
     munged = self._munge_raw_selection_to_wire(target, dtype, dformat, data)
     wire_encoding, wire_data = munged
     debug("clipboard raw -> wire: %r -> %r", (dtype, dformat, data), munged)
     if wire_encoding is None:
         no_contents()
         return
     if len(wire_data)>256:
         wire_data = zlib_compress("clipboard: %s / %s" % (dtype, dformat), wire_data)
         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)
             no_contents()
             return
     self.send("clipboard-contents", request_id, selection,
                dtype, dformat, wire_encoding, wire_data)
Exemple #9
0
    def make_data_packet(self, damage_time, process_damage_time, wid, x, y, w,
                         h, coding, data, rowstride, sequence, options):
        """
            Picture encoding - non-UI thread.
            Converts a damage item picked from the 'damage_data_queue'
            by the 'data_to_packet' thread and returns a packet
            ready for sending by the network layer.

            * 'mmap' will use 'mmap_send' - always if available, otherwise:
            * 'jpeg' and 'png' are handled by 'PIL_encode'.
            * 'x264' and 'vpx' use 'video_encode'
            * 'rgb24' uses the 'Compressed' wrapper to tell the network layer it is already zlibbed
        """
        if self.is_cancelled(sequence):
            log(
                "make_data_packet: dropping data packet for window %s with sequence=%s",
                wid, sequence)
            return None
        assert w > 0 and h > 0, "invalid dimensions: %sx%s" % (w, h)
        assert data, "data is missing"
        log("make_data_packet: damage data: %s", (wid, x, y, w, h, coding))
        start = time.time()
        if self._mmap and self._mmap_size > 0 and len(data) > 256:
            #try with mmap (will change coding to "mmap" if it succeeds)
            coding, data = self.mmap_send(coding, data)

        client_options = {}
        if coding in ("jpeg", "png"):
            data, client_options = self.PIL_encode(w, h, coding, data,
                                                   rowstride, options)
        elif coding == "x264":
            #x264 needs sizes divisible by 2:
            w = w & 0xFFFE
            h = h & 0xFFFE
            if w == 0 or h == 0:
                return None
            data, client_options = self.video_encode(wid, x, y, w, h, coding,
                                                     data, rowstride, options)
        elif coding == "vpx":
            data, client_options = self.video_encode(wid, x, y, w, h, coding,
                                                     data, rowstride, options)
        elif coding == "rgb24":
            #compress here and return a wrapper so network code knows it is already zlib compressed:
            data = zlib_compress(coding, data)
        elif coding == "mmap":
            pass  #already handled via mmap_send
        else:
            raise Exception("invalid encoding: %s" % coding)
        #check cancellation list again since the code above may take some time:
        #but always send mmap data so we can reclaim the space!
        if coding != "mmap" and self.is_cancelled(sequence):
            log(
                "make_data_packet: dropping data packet for window %s with sequence=%s",
                wid, sequence)
            return None
        #actual network packet:
        packet = [
            "draw", wid, x, y, w, h, coding, data,
            self._damage_packet_sequence, rowstride, client_options
        ]
        end = time.time()
        self._damage_packet_sequence += 1
        self.statistics.encoding_stats.append(
            (coding, w * h, len(data), end - start))
        return packet