Skip to content

Commit

Permalink
#835: gradually increase (or decrease) the av-sync delay actually use…
Browse files Browse the repository at this point in the history
…d with each video frame we send - prevents initial stuttering look

git-svn-id: https://xpra.org/svn/Xpra/trunk@9517 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed May 25, 2015
1 parent 22dea45 commit 5dc540f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/xpra/server/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ def update_av_sync_delay_total(self):
avsynclog("av-sync support is disabled, setting it to 0")
self.av_sync_delay_total = 0
for ws in self.window_sources.values():
ws.av_sync_delay = self.av_sync_delay_total
ws.set_av_sync_delay(self.av_sync_delay_total)


def set_screen_sizes(self, screen_sizes):
Expand Down
22 changes: 22 additions & 0 deletions src/xpra/server/window_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(self, queue_size, call_in_encode_thread, queue_packet, compressed_w
self.statistics = WindowPerformanceStatistics()
self.av_sync = av_sync
self.av_sync_delay = av_sync_delay
self.av_sync_delay_target = av_sync_delay
self.encode_queue = []

self.server_core_encodings = server_core_encodings
Expand Down Expand Up @@ -292,6 +293,8 @@ def get_info(self):
def up(prefix, d):
updict(info, prefix, d)

up("av-sync", {"current" : self.av_sync_delay,
"target" : self.av_sync_delay_target})
#heuristics
up("encoding.lossless_threshold", {
"base" : self._lossless_threshold_base,
Expand Down Expand Up @@ -539,6 +542,24 @@ def do_set_client_properties(self, properties):
def set_auto_refresh_delay(self, d):
self.auto_refresh_delay = d

def set_av_sync_delay(self, new_delay):
self.av_sync_delay_target = new_delay
self.update_av_sync_delay()

def update_av_sync_delay(self):
if not self.av_sync:
self.av_sync_delay = 0
return
delta = self.av_sync_delay_target-self.av_sync_delay
if delta==0:
return
#limit the rate of change:
AV_SYNC_RATE_CHANGE = 20
rdelta = min(AV_SYNC_RATE_CHANGE, max(-AV_SYNC_RATE_CHANGE, delta))
avsynclog("update_av_sync_delay() current=%s, target=%s, adding %s (capped to +-%s from %s)", self.av_sync_delay, self.av_sync_delay_target, rdelta, AV_SYNC_RATE_CHANGE, delta)
self.av_sync_delay += rdelta


def set_new_encoding(self, encoding, strict):
""" Changes the encoder for the given 'window_ids',
or for all windows if 'window_ids' is None.
Expand Down Expand Up @@ -1218,6 +1239,7 @@ def encode_from_queue(self):
avsynclog("encode_from_queue: %s items", len(eq))
if not eq:
return #nothing to encode, must have been picked off already
self.update_av_sync_delay()
#find the first item which is due
#in seconds, same as time.time():
av_delay = self.av_sync_delay/1000.0
Expand Down

0 comments on commit 5dc540f

Please sign in to comment.