Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return
for _, factor, weight in valid_factors:
target_delay = max(min_delay, min(max_delay, current_delay*factor))
w = max(1, hist_w)*weight/all_factors_weight
tw += w
tv += target_delay*w
batch.delay = max(min_delay, min(max_delay, tv / tw))
batch.last_updated = now
if DEBUG_DELAY:
decimal_delays = [dec1(x) for _,x in batch.last_delays]
if len(decimal_delays)==0:
decimal_delays.append(0)
logfactors = [(msg, dec2(f), dec2(w)) for (msg, f, w) in valid_factors]
rec = ("update_batch_delay: wid=%s, last updated %s ms ago, decay=%s, change factor=%s%%, delay min=%s, avg=%s, max=%s, cur=%s, w. average=%s, tot wgt=%s, hist_w=%s, new delay=%s\n %s",
batch.wid, dec2(1000.0*now-1000.0*last_updated), dec2(decay), dec1(100*(batch.delay/current_delay-1)), min(decimal_delays), dec1(sum(decimal_delays)/len(decimal_delays)), max(decimal_delays),
dec1(current_delay), dec1(avg), dec1(tw), dec1(hist_w), dec1(batch.delay), "\n ".join([str(x) for x in logfactors]))
add_DEBUG_DELAY_MESSAGE(rec)
batch.delay = max(batch.min_delay, min(batch.max_delay, tv / tw))
batch.last_updated = time.time()
if DEBUG_DELAY:
fps = 0
now = time.time()
for event_list in self._damage_last_events.values():
for event_time, _ in event_list:
if event_time+1.0>now:
fps += 1
decimal_delays = [dec1(x) for _,x in batch.last_delays]
if len(decimal_delays)==0:
decimal_delays.append(0)
logfactors = [(msg, dec2(f), dec2(w)) for (msg, f, w) in valid_factors]
rec = ("update_batch_delay: wid=%s, fps=%s, last updated %s ms ago, decay=%s, change factor=%s%%, delay min=%s, avg=%s, max=%s, cur=%s, w. average=%s, tot wgt=%s, hist_w=%s, new delay=%s\n %s",
batch.wid, fps, dec2(1000.0*now-1000.0*last_updated), dec2(decay), dec1(100*(batch.delay/current_delay-1)), min(decimal_delays), dec1(sum(decimal_delays)/len(decimal_delays)), max(decimal_delays),
dec1(current_delay), dec1(avg), dec1(tw), dec1(hist_w), dec1(batch.delay), "\n ".join([str(x) for x in logfactors]))
self.add_DEBUG_DELAY_MESSAGE(rec)
client_decode_list.append((time.time(), width*height, decode_time))
ack_pending = self._damage_ack_pending.get(wid)
if not ack_pending:
log("cannot find damage_pending list for window %s - already removed?", wid)
return
pending = ack_pending.get(damage_packet_sequence)
if pending is None:
log("cannot find sent time for sequence %s", damage_packet_sequence)
return
del ack_pending[damage_packet_sequence]
if decode_time>0:
sent_at, pixels = pending
now = time.time()
diff = now-sent_at
latency = max(0, diff-decode_time/1000/1000)
log("client_ack_damage: took %s ms round trip, %s for decoding of %s pixels, %s for network", dec1(diff*1000), dec1(decode_time/1000), pixels, dec1(latency*1000))
if self._min_client_latency is None or self._min_client_latency>latency:
self._min_client_latency = latency
self._client_latency.append((now, width*height, latency))
region = gtk.gdk.Region()
region.union_with_rect(gtk.gdk.Rectangle(x, y, w, h))
self._sequence += 1
self._damage_delayed = (now, window, region, coding, self._sequence, options)
def send_delayed():
""" move the delayed rectangles to the expired list """
if self._damage_delayed:
damage_time = self._damage_delayed[0]
log("send_delayed for wid %s, batch delay is %s, elapsed time is %s ms", self.wid, self.batch_config.delay, dec1(1000*(time.time()-damage_time)))
delayed = self._damage_delayed
self._damage_delayed = None
self.send_delayed_regions(*delayed)
else:
log("window %s already removed from delayed list?", self.wid)
return False
log("damage(%s, %s, %s, %s) wid=%s, scheduling batching expiry for sequence %s in %s ms", x, y, w, h, self.wid, self._sequence, dec1(self.batch_config.delay))
self.batch_config.last_delays.append((now, self.batch_config.delay))
gobject.timeout_add(int(self.batch_config.delay), send_delayed)
def process_damage_region(self, damage_time, pixmap, x, y, w, h, coding, sequence, options):
"""
Called by 'damage_now' or 'send_delayed_regions' to process a damage region,
we extract the rgb data from the pixmap and place it on the damage queue.
"""
if w==0 or h==0:
return
process_damage_time = time.time()
data = get_rgb_rawdata(damage_time, process_damage_time, self.wid, pixmap, x, y, w, h, coding, sequence, options)
if data:
log("process_damage_regions: adding pixel data %s to queue, elapsed time: %s ms", data[:6], dec1(1000*(time.time()-damage_time)))
def make_data_packet(*args):
#NOTE: this function is called from the damage data thread!
packet = self.make_data_packet(*data)
if packet:
self.queue_damage_packet(packet, damage_time, process_damage_time)
self.queue_damage(make_data_packet)
log("window %s already removed from delayed list?", self.wid)
return False
damage_time = self._damage_delayed[0]
packets_backlog = self.get_packets_backlog()
now = time.time()
actual_delay = 1000.0*(time.time()-damage_time)
if packets_backlog>0:
if actual_delay