Skip to content

Commit

Permalink
#669:
Browse files Browse the repository at this point in the history
* remove bitrate-changed signal, never used for anything useful
* reduce logging on info_update to just the important part
* ensure we do export info
* switch from a timer to and event based info publishing
 (but rate limit the info update)

git-svn-id: https://xpra.org/svn/Xpra/trunk@8983 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 10, 2015
1 parent d851db3 commit db9eb4c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
4 changes: 0 additions & 4 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,16 +1549,13 @@ def start_sound_source(self):
assert self.sound_source is None
def sound_source_state_changed(*args):
self.emit("microphone-changed")
def sound_source_bitrate_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:
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.connect("bitrate-changed", sound_source_bitrate_changed)
self.sound_source.start()
soundlog("start_sound_source() sound source %s started", self.sound_source)
return True
Expand Down Expand Up @@ -1693,7 +1690,6 @@ def start_sound_sink(self, codec):
return False
self.sound_sink = ss
ss.connect("state-changed", self.sound_sink_state_changed)
ss.connect("bitrate-changed", self.sound_sink_bitrate_changed)
ss.connect("error", self.sound_sink_error)
ss.connect("overrun", self.sound_sink_overrun)
from xpra.net.protocol import Protocol
Expand Down
4 changes: 4 additions & 0 deletions src/xpra/server/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,14 @@ def start_sending_sound(self, codec, volume=1.0):
ss.sequence = self.sound_source_sequence
ss.connect("new-buffer", self.new_sound_buffer)
ss.connect("new-stream", self.new_stream)
ss.connect("info", self.sound_source_info)
ss.start()
except Exception as e:
log.error("error setting up sound: %s", e, exc_info=True)

def sound_source_info(self, info):
soundlog("sound_source_info(%s)", info)

def stop_sending_sound(self):
ss = self.sound_source
soundlog("stop_sending_sound() sound_source=%s", ss)
Expand Down
5 changes: 5 additions & 0 deletions src/xpra/sound/sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def queue_pushing(self, *args):
ltime = int(self.queue.get_property("current-level-time")/MS_TO_NS)
log("queue pushing: level=%s", ltime)
self.queue_state = "pushing"
self.emit_info()

def queue_running(self, *args):
ltime = int(self.queue.get_property("current-level-time")/MS_TO_NS)
Expand All @@ -143,6 +144,7 @@ def queue_running(self, *args):
self.queue.set_property("min-threshold-time", 0)
#pass
self.queue_state = "running"
self.emit_info()

def queue_underrun(self, *args):
ltime = int(self.queue.get_property("current-level-time")/MS_TO_NS)
Expand All @@ -151,6 +153,7 @@ def queue_underrun(self, *args):
#lift min time restrictions:
self.queue.set_property("min-threshold-time", QUEUE_MIN_TIME)
self.queue_state = "underrun"
self.emit_info()

def queue_overrun(self, *args):
ltime = int(self.queue.get_property("current-level-time")/MS_TO_NS)
Expand All @@ -163,6 +166,7 @@ def queue_overrun(self, *args):
log("queue overrun: level=%s", ltime)
self.overruns += 1
self.emit("overrun", ltime)
self.emit_info()

def eos(self):
log("eos()")
Expand Down Expand Up @@ -218,6 +222,7 @@ def add_data(self, data, metadata=None):
self.byte_count += len(data)
ltime = int(self.queue.get_property("current-level-time")/MS_TO_NS)
log("pushed %s bytes, new buffer level: %sms", len(data), ltime)
self.emit_info()

def push_buffer(self, buf):
#buf.size = size
Expand Down
16 changes: 14 additions & 2 deletions src/xpra/sound/sound_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class SoundPipeline(gobject.GObject):

__generic_signals__ = {
"state-changed" : one_arg_signal,
"bitrate-changed" : one_arg_signal,
"error" : one_arg_signal,
"new-stream" : one_arg_signal,
"info" : one_arg_signal,
}

def __init__(self, codec):
Expand All @@ -38,10 +38,20 @@ def __init__(self, codec):
self.state = "stopped"
self.buffer_count = 0
self.byte_count = 0
self.emit_info_due = False

def idle_emit(self, sig, *args):
gobject.idle_add(self.emit, sig, *args)

def emit_info(self):
if self.emit_info_due:
return
self.emit_info_due = True
def do_emit_info():
self.emit_info_due = False
self.emit("info", self.get_info())
gobject.timeout_add(50, do_emit_info)

def get_info(self):
info = {"codec" : self.codec,
"codec_description" : self.codec_description,
Expand Down Expand Up @@ -84,7 +94,7 @@ def update_bitrate(self, new_bitrate):
return
self.bitrate = new_bitrate
log("new bitrate: %s", self.bitrate)
#self.emit("bitrate-changed", new_bitrate)
self.emit_info()


def set_volume(self, volume=100):
Expand All @@ -102,6 +112,7 @@ def start(self):
self.idle_emit("new-stream", self.codec)
self.state = "active"
self.pipeline.set_state(gst.STATE_PLAYING)
self.emit_info()
log("SoundPipeline.start() done")

def stop(self):
Expand Down Expand Up @@ -196,6 +207,7 @@ def on_message(self, bus, message):
log.info("pipeline warning: %s", w[1:])
else:
log.info("unhandled bus message type %s: %s", t, message)
self.emit_info()

def parse_message0(self, message):
#message parsing code for GStreamer 0.10
Expand Down
1 change: 1 addition & 0 deletions src/xpra/sound/src.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def do_emit_buffer(self, data, metadata={}):
self.byte_count += len(data)
metadata["time"] = int(time.time()*1000)
self.idle_emit("new-buffer", data, metadata)
self.emit_info()


gobject.type_register(SoundSource)
Expand Down
7 changes: 2 additions & 5 deletions src/xpra/sound/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

DEBUG_SOUND = os.environ.get("XPRA_SOUND_DEBUG", "0")=="1"
SUBPROCESS_DEBUG = os.environ.get("XPRA_SOUND_SUBPROCESS_DEBUG", "").split(",")
EXPORT_INFO_TIME = int(os.environ.get("XPRA_SOUND_INFO_TIME", "1000"))
FAKE_OVERRUN = int(os.environ.get("XPRA_FAKE_OVERRUN", "0"))


Expand Down Expand Up @@ -46,14 +45,12 @@ class sound_subprocess(subprocess_callee):
def __init__(self, wrapped_object, method_whitelist, exports_list):
#add bits common to both record and play:
methods = method_whitelist+["set_volume", "stop", "cleanup"]
exports = ["state-changed", "bitrate-changed", "error"] + exports_list
exports = ["state-changed", "info", "error"] + exports_list
subprocess_callee.__init__(self, wrapped_object=wrapped_object, method_whitelist=methods)
for x in exports:
self.connect_export(x)

def start(self):
if EXPORT_INFO_TIME>0:
gobject.timeout_add(EXPORT_INFO_TIME, self.export_info)
gobject.idle_add(self.wrapped_object.start)
subprocess_callee.start(self)

Expand Down Expand Up @@ -173,7 +170,7 @@ def get_info(self):
return self.last_info

def info_update(self, sink, info):
log("info_update(%s, %s)", sink, info)
log("info_update: %s", info)
self.last_info = info
self.last_info["time"] = int(time.time())
self.codec_description = info.get("codec_description")
Expand Down

0 comments on commit db9eb4c

Please sign in to comment.