Skip to content

Commit

Permalink
#669: update microphone side code to use the new sound code and safer…
Browse files Browse the repository at this point in the history
… var references (copy before use)

git-svn-id: https://xpra.org/svn/Xpra/trunk@9201 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 30, 2015
1 parent 4a8d328 commit d1c9a87
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
35 changes: 25 additions & 10 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,12 +1551,13 @@ def start_sending_sound(self):
log.warn("cannot start sound: identical user environment as the server (loop)")
return

if self.sound_source:
if self.sound_source.get_state()=="active":
ss = self.sound_source
if ss:
if ss.get_state()=="active":
log.error("already sending sound!")
return
self.sound_source.start()
if not self.start_sound_source():
ss.start()
elif not self.start_sound_source():
return
self.microphone_enabled = True
self.emit("microphone-changed")
Expand All @@ -1569,18 +1570,32 @@ def sound_source_state_changed(*args):
self.emit("microphone-changed")
try:
from xpra.sound.wrapper import start_sending_sound
self.sound_source = start_sending_sound(self.sound_source_plugin, None, 1.0, self.server_sound_decoders, self.server_pulseaudio_server, self.server_pulseaudio_id)
if not self.sound_source:
ss = start_sending_sound(self.sound_source_plugin, None, 1.0, self.server_sound_decoders, self.server_pulseaudio_server, self.server_pulseaudio_id)
if not ss:
return False
self.sound_source.connect("new-buffer", self.new_sound_buffer)
self.sound_source.connect("state-changed", sound_source_state_changed)
self.sound_source.start()
soundlog("start_sound_source() sound source %s started", self.sound_source)
self.sound_source = ss
ss.connect("new-buffer", self.new_sound_buffer)
ss.connect("state-changed", sound_source_state_changed)
ss.connect("new-stream", self.new_stream)
ss.start()
soundlog("start_sound_source() sound source %s started", ss)
return True
except Exception as e:
log.error("error setting up sound: %s", e)
return False

def new_stream(self, sound_source, codec):
soundlog("new_stream(%s)", codec)
if self.sound_source!=sound_source:
soundlog("dropping new-stream signal (current source=%s, signal source=%s)", self.sound_source, sound_source)
return
sound_source.codec = codec
#tell the server this is the start:
self.send("sound-data", sound_source.codec, "",
{"start-of-stream" : True,
"codec" : sound_source.codec,
"sequence" : sound_source.sequence})

def stop_sending_sound(self):
""" stop the sound source and emit client signal """
soundlog("stop_sending_sound() sound source=%s", self.sound_source)
Expand Down
26 changes: 17 additions & 9 deletions src/xpra/server/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,10 @@ def sound_data(self, codec, data, metadata, *args):
log.info("sound codec changed from %s to %s", self.sound_sink.codec, codec)
self.sound_sink.cleanup()
self.sound_sink = None
if metadata.boolget("end-of-stream"):
soundlog("client sent end-of-stream, closing sound pipeline")
self.stop_receiving_sound(False)
return
if not self.sound_sink:
try:
def sound_sink_error(*args):
Expand All @@ -910,20 +914,24 @@ def sound_sink_overrun(*args):
log.warn("re-starting sound input because of overrun")
def sink_clean():
soundlog("sink_clean() sound_sink=%s", self.sound_sink)
if self.sound_sink:
self.sound_sink.cleanup()
ss = self.sound_sink
if ss:
self.sound_sink = None
ss.cleanup()
self.idle_add(sink_clean)
#Note: the next sound packet will take care of starting a new pipeline
from xpra.sound.sink import SoundSink
self.sound_sink = SoundSink(codec=codec)
from xpra.sound.wrapper import start_receiving_sound
ss = start_receiving_sound(codec)
if not ss:
return
self.sound_sink = ss
soundlog("sound_data(..) created sound sink: %s", self.sound_sink)
self.sound_sink.connect("error", sound_sink_error)
self.sound_sink.connect("overrun", sound_sink_overrun)
self.sound_sink.start()
ss.connect("error", sound_sink_error)
ss.connect("overrun", sound_sink_overrun)
ss.start()
soundlog("sound_data(..) sound sink started")
except Exception as e:
log.error("failed to setup sound: %s", e)
except Exception:
log.error("failed to setup sound", exc_info=True)
return
self.sound_sink.add_data(data, metadata)

Expand Down

0 comments on commit d1c9a87

Please sign in to comment.