Skip to content

Commit

Permalink
#1199: distinguish between encoding functions we must call (ie: encod…
Browse files Browse the repository at this point in the history
…er or csc cleanup) and ones we can drop (ie: frame encoding, clipboard packet) when the source is closed

git-svn-id: https://xpra.org/svn/Xpra/trunk@12603 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed May 18, 2016
1 parent 7f551a5 commit 19d5ab9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/xpra/server/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ def send_clipboard(self, packet):
self.send_clipboard_enabled(msg)
return
#call compress_clibboard via the work queue:
self.encode_work_queue.put((self.compress_clipboard, packet))
self.encode_work_queue.put((True, self.compress_clipboard, packet))

def compress_clipboard(self, packet):
#Note: this runs in the 'encode' thread!
Expand Down Expand Up @@ -2122,8 +2122,13 @@ def encode_loop(self):
fn_and_args = self.encode_work_queue.get(True)
if fn_and_args is None:
return #empty marker
#some function calls are optional and can be skipped when closing:
#(but some are not, like encoder clean functions)
optional_when_closing = fn_and_args[0]
if optional_when_closing and self.is_closed():
continue
try:
fn_and_args[0](*fn_and_args[1:])
fn_and_args[1](*fn_and_args[2:])
except Exception as e:
if self.is_closed():
log("ignoring encoding error in %s as source is already closed:", fn_and_args[0])
Expand Down
10 changes: 5 additions & 5 deletions src/xpra/server/window/window_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def send_window_icon(self, window):
#and delay sending it by a bit to allow basic icon batching:
delay = max(50, int(self.batch_config.delay))
iconlog("send_window_icon(%s) wid=%s, icon=%s, compression scheduled in %sms", window, self.wid, surf, delay)
self.timeout_add(delay, self.call_in_encode_thread, self.compress_and_send_window_icon)
self.timeout_add(delay, self.call_in_encode_thread, True, self.compress_and_send_window_icon)

def compress_and_send_window_icon(self):
#this runs in the work queue
Expand Down Expand Up @@ -1350,20 +1350,20 @@ def process_damage_region(self, damage_time, window, x, y, w, h, coding, options
av_sync = options.get("av-sync", False)
av_delay = self.av_sync_delay*int(av_sync)
if not av_sync:
self.call_in_encode_thread(self.make_data_packet_cb, *item)
self.call_in_encode_thread(True, self.make_data_packet_cb, *item)
else:
#schedule encode via queue, after freezing the pixels:
if not image.freeze():
avsynclog("Warning: failed to freeze image pixels for:")
avsynclog(" %s", image)
self.call_in_encode_thread(self.make_data_packet_cb, *item)
self.call_in_encode_thread(True, self.make_data_packet_cb, *item)
return
self.encode_queue.append(item)
l = len(self.encode_queue)
if l>=self.encode_queue_max_size:
av_delay = 0 #we must free some space!
avsynclog("scheduling encode queue iteration in %ims, encode queue size=%i (max=%i)", av_delay, l, self.encode_queue_max_size)
self.timeout_add(av_delay, self.call_in_encode_thread, self.encode_from_queue)
self.timeout_add(av_delay, self.call_in_encode_thread, True, self.encode_from_queue)

def encode_from_queue(self):
#note: we use a queue here to ensure we preserve the order
Expand Down Expand Up @@ -1413,7 +1413,7 @@ def encode_from_queue(self):
return
first_due = int(max(0, min(still_due)-time.time())*1000)
avsynclog("encode_from_queue: first due in %ims, due list=%s", first_due, still_due)
self.timeout_add(first_due, self.call_in_encode_thread, self.encode_from_queue)
self.timeout_add(first_due, self.call_in_encode_thread, True, self.encode_from_queue)


def make_data_packet_cb(self, window, w, h, damage_time, process_damage_time, wid, image, coding, sequence, options, flush):
Expand Down
4 changes: 2 additions & 2 deletions src/xpra/server/window/window_video_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ def csc_encoder_clean(self):
csce = self._csc_encoder
if csce:
self._csc_encoder = None
self.call_in_encode_thread(csce.clean)
self.call_in_encode_thread(False, csce.clean)

def video_encoder_clean(self):
""" Calls self._video_encoder.clean() from the encode thread """
ve = self._video_encoder
if ve:
self._video_encoder = None
self.call_in_encode_thread(ve.clean)
self.call_in_encode_thread(False, ve.clean)


def parse_csc_modes(self, full_csc_modes):
Expand Down

0 comments on commit 19d5ab9

Please sign in to comment.