Skip to content

Commit

Permalink
#669: with servers that send a sound sequence with the eos event, we …
Browse files Browse the repository at this point in the history
…can restart the sink faster and more safely

git-svn-id: https://xpra.org/svn/Xpra/trunk@8961 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 8, 2015
1 parent 765ac67 commit cf00f4c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
35 changes: 19 additions & 16 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ def __init__(self):
soundlog("sound support unavailable: %s", e)
has_gst = False
#sound state:
self.sink_restart_pending = False
self.on_sink_ready = None
self.sound_sink = None
self.server_sound_sequence = False
self.min_sound_sequence = 0
self.server_sound_eos_sequence = False
self.sound_source = None
self.sound_in_bytecount = 0
self.sound_out_bytecount = 0
Expand Down Expand Up @@ -1314,6 +1314,7 @@ def getenclist(k, default_value=[]):
self.server_randr = c.boolget("resize_screen")
log("server has randr: %s", self.server_randr)
self.server_sound_sequence = c.boolget("sound_sequence")
self.server_sound_eos_sequence = c.boolget("sound.eos-sequence")
self.server_info_request = c.boolget("info-request")
e = c.strget("encoding")
if e:
Expand Down Expand Up @@ -1645,29 +1646,31 @@ def sound_sink_error(self, sound_sink, error):
self.stop_receiving_sound()
def sound_process_stopped(self, sound_sink, *args):
soundlog("the sound sink process %s has stopped, current sound sink=%s", sound_sink, self.sound_sink)
if not self.sink_restart_pending and sound_sink==self.sound_sink:
if sound_sink==self.sound_sink:
soundlog.warn("the sound process has stopped")
self.stop_receiving_sound()

def sound_sink_overrun(self, *args):
if self.sink_restart_pending:
soundlog("overrun re-start is already pending")
def sound_sink_overrun(self, sound_sink, *args):
if sound_sink!=self.sound_sink:
soundlog("sound_sink_overrun() not the current sink, ignoring it")
return
soundlog.warn("re-starting speaker because of overrun")
codec = self.sound_sink.codec
self.sink_restart_pending = True
if self.server_sound_sequence:
self.min_sound_sequence += 1
#Note: the next sound packet will take care of starting a new pipeline
self.stop_receiving_sound()
def restart():
self.sink_restart_pending = False
soundlog("restart() sound_sink=%s, codec=%s, server_sound_sequence=%s", self.sound_sink, codec, self.server_sound_sequence)
soundlog("sound_sink=%s, codec=%s, server_sound_sequence=%s", self.sound_sink, codec, self.server_sound_sequence)
if self.server_sound_sequence:
self.send_new_sound_sequence()
self.start_receiving_sound()
return False
self.timeout_add(200, restart)
#by default for older servers,
#wait before restarting so we can process the "end-of-stream" message:
delay = 500
if self.server_sound_eos_sequence:
#no need to wait, we won't mistakenly stop() the wrong sink:
delay = 0
self.timeout_add(delay, restart)

def start_sound_sink(self, codec):
soundlog("start_sound_sink(%s)", codec)
Expand Down Expand Up @@ -1720,15 +1723,15 @@ def _process_sound_data(self, packet):
else:
soundlog("speaker is now disabled - dropping packet")
return
elif metadata.boolget("end-of-stream"):
if self.sound_sink:
soundlog("server sent end-of-stream, closing sound pipeline")
self.stop_receiving_sound(False)
return
seq = metadata.intget("sequence", -1)
if self.min_sound_sequence>0 and seq<self.min_sound_sequence:
soundlog("ignoring sound data with old sequence number %s", seq)
return
if metadata.boolget("end-of-stream"):
if self.sound_sink:
soundlog("server sent end-of-stream, closing sound pipeline")
self.stop_receiving_sound(False)
return
ss = self.sound_sink
if ss is not None and codec!=self.sound_sink.codec:
log.error("sound codec change not supported! (from %s to %s)", ss.codec, codec)
Expand Down
3 changes: 2 additions & 1 deletion src/xpra/server/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,8 @@ def get_server_features(self):
"encoding.generic", "encoding.strict_control",
"sound.server_driven",
"command_request",
"event_request", "server-events")
"event_request", "server-events",
"sound.eos-sequence")

def make_hello(self, source):
capabilities = ServerCore.make_hello(self, source)
Expand Down
3 changes: 2 additions & 1 deletion src/xpra/server/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ def stop_sending_sound(self):
self.sound_source = None
if self.server_driven:
#tell the client this is the end:
self.send("sound-data", ss.codec, "", {"end-of-stream" : True})
self.send("sound-data", ss.codec, "", {"end-of-stream" : True,
"sequence" : self.sound_source_sequence})
ss.cleanup()

def new_stream(self, sound_source, codec):
Expand Down

0 comments on commit cf00f4c

Please sign in to comment.