def test_sound_option(self): ONE_OPTION = [common.VORBIS, ] assert common.sound_option_or_all("unspecified", None, ONE_OPTION)==ONE_OPTION assert common.sound_option_or_all("unspecified", (), ONE_OPTION)==ONE_OPTION assert common.sound_option_or_all("valid", ONE_OPTION, ONE_OPTION)==ONE_OPTION with LoggerSilencer(common, ("error", "warn")): assert common.sound_option_or_all("invalid options", (common.VORBIS, common.OGG, ), ONE_OPTION)==ONE_OPTION assert common.sound_option_or_all("no valid options", (common.VORBIS, common.OGG, ), ())==[]
def init_sound_options(self): def sound_option_or_all(*_args): return [] if self.supports_speaker or self.supports_microphone: try: from xpra.sound.common import sound_option_or_all from xpra.sound.wrapper import query_sound self.sound_properties = query_sound() assert self.sound_properties, "query did not return any data" def vinfo(k): val = self.sound_properties.listget(k) assert val, "%s not found in sound properties" % bytestostr( k) return ".".join(bytestostr(x) for x in val[:3]) bits = self.sound_properties.intget("python.bits", 32) soundlog.info("GStreamer version %s for Python %s %i-bit", vinfo("gst.version"), vinfo("python.version"), bits) except Exception as e: soundlog("failed to query sound", exc_info=True) soundlog.error("Error: failed to query sound subsystem:") soundlog.error(" %s", e) self.speaker_allowed = False self.microphone_allowed = False encoders = self.sound_properties.strlistget("encoders", []) decoders = self.sound_properties.strlistget("decoders", []) self.speaker_codecs = sound_option_or_all("speaker-codec", self.speaker_codec_str, encoders) self.microphone_codecs = sound_option_or_all("microphone-codec", self.microphone_codec_str, decoders) if not self.speaker_codecs: self.supports_speaker = False if not self.microphone_codecs: self.supports_microphone = False if bool(self.sound_properties): try: from xpra.sound.pulseaudio.pulseaudio_util import set_icon_path, get_info as get_pa_info pa_info = get_pa_info() soundlog("pulseaudio info=%s", pa_info) self.sound_properties.update(pa_info) set_icon_path(get_icon_filename("xpra.png")) except ImportError as e: if POSIX and not OSX: log.warn("Warning: failed to set pulseaudio tagging icon:") log.warn(" %s", e) soundlog("init_sound_options speaker: supported=%s, encoders=%s", self.supports_speaker, csv(self.speaker_codecs)) soundlog("init_sound_options microphone: supported=%s, decoders=%s", self.supports_microphone, csv(self.microphone_codecs)) soundlog("init_sound_options sound properties=%s", self.sound_properties)
def init_sound_options(self): def sound_option_or_all(*_args): return [] if self.supports_speaker or self.supports_microphone: try: from xpra.sound.common import sound_option_or_all from xpra.sound.wrapper import query_sound self.sound_properties = query_sound() assert self.sound_properties, "query did not return any data" def vinfo(k): val = self.sound_properties.tupleget(k) assert val, "%s not found in sound properties" % bytestostr( k) return ".".join(bytestostr(x) for x in val[:3]) bits = self.sound_properties.intget("python.bits", 32) soundlog.info("GStreamer version %s for Python %s %i-bit", vinfo("gst.version"), vinfo("python.version"), bits) except Exception as e: soundlog("failed to query sound", exc_info=True) soundlog.error("Error: failed to query sound subsystem:") soundlog.error(" %s", e) self.speaker_allowed = False self.microphone_allowed = False encoders = self.sound_properties.strtupleget("encoders") decoders = self.sound_properties.strtupleget("decoders") self.speaker_codecs = sound_option_or_all("speaker-codec", self.speaker_codecs, encoders) self.microphone_codecs = sound_option_or_all("microphone-codec", self.microphone_codecs, decoders) if not self.speaker_codecs: self.supports_speaker = False if not self.microphone_codecs: self.supports_microphone = False #query_pulseaudio_properties may access X11, #do this from the main thread: if bool(self.sound_properties): GLib.idle_add(self.query_pulseaudio_properties) GLib.idle_add(self.log_sound_properties) self.audio_init_done.set()
def init(self, opts): self.av_sync = opts.av_sync self.sound_properties = typedict() self.speaker_allowed = sound_option(opts.speaker) in ("on", "off") #ie: "on", "off", "on:Some Device", "off:Some Device" mic = [x.strip() for x in opts.microphone.split(":", 1)] self.microphone_allowed = sound_option(mic[0]) in ("on", "off") self.microphone_device = None if self.microphone_allowed and len(mic) == 2: self.microphone_device = mic[1] self.sound_source_plugin = opts.sound_source def sound_option_or_all(*_args): return [] if self.speaker_allowed or self.microphone_allowed: try: from xpra.sound import common assert common except ImportError as e: self.may_notify_audio( "No Audio", "audio subsystem is not installed\n" + " speaker and microphone forwarding are disabled") self.speaker_allowed = False self.microphone_allowed = False else: try: from xpra.sound.common import sound_option_or_all from xpra.sound.wrapper import query_sound self.sound_properties = query_sound() assert self.sound_properties, "query did not return any data" def vinfo(k): val = self.sound_properties.strtupleget(k) assert val, "%s not found in sound properties" % k return ".".join(val[:3]) bits = self.sound_properties.intget("python.bits", 32) log.info("GStreamer version %s for Python %s %s-bit", vinfo("gst.version"), vinfo("python.version"), bits) except Exception as e: log("failed to query sound", exc_info=True) log.error("Error: failed to query sound subsystem:") log.error(" %s", e) self.speaker_allowed = False self.microphone_allowed = False encoders = self.sound_properties.strtupleget("encoders") decoders = self.sound_properties.strtupleget("decoders") self.speaker_codecs = sound_option_or_all("speaker-codec", opts.speaker_codec, decoders) self.microphone_codecs = sound_option_or_all("microphone-codec", opts.microphone_codec, encoders) if not self.speaker_codecs: self.speaker_allowed = False if not self.microphone_codecs: self.microphone_allowed = False self.speaker_enabled = self.speaker_allowed and sound_option( opts.speaker) == "on" self.microphone_enabled = self.microphone_allowed and opts.microphone.lower( ) == "on" log("speaker: codecs=%s, allowed=%s, enabled=%s", encoders, self.speaker_allowed, csv(self.speaker_codecs)) log("microphone: codecs=%s, allowed=%s, enabled=%s, default device=%s", decoders, self.microphone_allowed, csv(self.microphone_codecs), self.microphone_device) log("av-sync=%s", self.av_sync) if POSIX and not OSX: try: from xpra.sound.pulseaudio.pulseaudio_util import get_info as get_pa_info pa_info = get_pa_info() log("pulseaudio info=%s", pa_info) self.sound_properties.update(pa_info) except ImportError as e: log.warn("Warning: no pulseaudio information available") log.warn(" %s", e) except Exception: log.error("failed to add pulseaudio info", exc_info=True) #audio tagging: self.init_audio_tagging(opts.tray_icon)