def get_pulse_defaults(device_name_match=None, want_monitor_device=True, input_or_output=None, remote=None, env_device_name=None): try: device = get_pulse_device(device_name_match, want_monitor_device, input_or_output, remote, env_device_name) except Exception as e: log.warn( "Warning: failed to identify the pulseaudio default device to use") log.warn(" %s", e) return {} if not device: return {} #make sure it is not muted: try: from xpra.sound.pulseaudio.pulseaudio_util import has_pa, set_source_mute, set_sink_mute if has_pa(): if input_or_output is True or want_monitor_device: set_source_mute(device, mute=False) elif input_or_output is False: set_sink_mute(device, mute=False) except Exception as e: log("device %s may still be muted: %s", device, e) return {"device": device}
def get_pulse_defaults(device_name_match=None, want_monitor_device=True, input_or_output=None, remote=None, xpra_device_name=None): device = get_pulse_device(device_name_match, want_monitor_device, input_or_output, remote, xpra_device_name) if not device: return {} #make sure it is not muted: try: from xpra.sound.pulseaudio.pulseaudio_util import has_pa, set_source_mute, set_sink_mute if has_pa(): if input_or_output is True or want_monitor_device: set_source_mute(device, mute=False) elif input_or_output is False: set_sink_mute(device, mute=False) except Exception as e: log("device %s may still be muted: %s", device, e) return {"device" : device}
def get_pulse_defaults(device_name_match=None, want_monitor_device=True, input_or_output=None, remote=None, xpra_device_name=None): """ choose the device to use """ try: from xpra.sound.pulseaudio.pulseaudio_util import has_pa, get_pa_device_options, get_default_sink from xpra.sound.pulseaudio.pulseaudio_util import get_pulse_server, get_pulse_id, set_source_mute, set_sink_mute if not has_pa(): log.warn("Warning: pulseaudio is not available!") return None except ImportError as e: log.warn("Warning: pulseaudio is not available!") log.warn(" %s", e) return None pa_server = get_pulse_server() if remote: log( "start sound, remote pulseaudio server=%s, local pulseaudio server=%s", remote.pulseaudio_server, pa_server) #only worth comparing if we have a real server string #one that starts with {UUID}unix:/.. if pa_server and pa_server.startswith("{") and \ remote.pulseaudio_server and remote.pulseaudio_server==pa_server: log.error("Error: sound is disabled to prevent a sound loop") log.error(" identical Pulseaudio server '%s'", pa_server) return None pa_id = get_pulse_id() log("start sound, client id=%s, server id=%s", remote.pulseaudio_id, pa_id) if remote.pulseaudio_id and remote.pulseaudio_id == pa_id: log.error("Error: sound is disabled to prevent a sound loop") log.error(" identical Pulseaudio ID '%s'", pa_id) return None device_type_str = "" if input_or_output is not None: device_type_str = ["output", "input"][input_or_output] if want_monitor_device: device_type_str += " monitor" #def get_pa_device_options(monitors=False, input_or_output=None, ignored_devices=["bell-window-system"], log_errors=True) devices = get_pa_device_options(want_monitor_device, input_or_output) log("found %i pulseaudio %s device%s: %s", len(devices), device_type_str, engs(devices), devices) if len(devices) == 0: log.error("Error: sound forwarding is disabled") log.error(" could not detect any Pulseaudio %s devices", device_type_str) return None if len(devices) > 1: filters = [] matches = [] for match in (device_name_match, PULSEAUDIO_DEVICE_NAME, xpra_device_name): if not match: continue if match != xpra_device_name: filters.append(match) match = match.lower() matches = dict( (k, v) for k, v in devices.items() if k.lower().find(match) >= 0 or v.lower().find(match) >= 0) #log("matches(%s, %s)=%s", devices, match, matches) if len(matches) == 1: log("found name match for '%s': %s", match, matches.items()[0]) break elif len(matches) > 1: log.warn("Warning: Pulseaudio %s device name filter '%s'", device_type_str, match) log.warn(" matched %i devices", len(matches)) if filters or len(matches) > 0: if len(matches) == 0: log.warn("Warning: Pulseaudio %s device name filter%s:", device_type_str, engs(filters)) log.warn(" %s", csv("'%s'" % x for x in filters)) log.warn(" did not match the devices found:") for k, v in devices.items(): log.warn(" * '%s'", k) log.warn(" '%s'", v) return None devices = matches #default to first one: device, device_name = devices.items()[0] if len(devices) > 1: default_sink = get_default_sink() default_monitor = default_sink + ".monitor" global WARNED_MULTIPLE_DEVICES if not WARNED_MULTIPLE_DEVICES: WARNED_MULTIPLE_DEVICES = True if not PULSEAUDIO_DEVICE_NAME: #warned already log.warn("Warning: found %i audio devices:", len(devices)) for k, v in devices.items(): log.warn(" * %s", v) log.warn(" %s", k) if not PULSEAUDIO_DEVICE_NAME: #used already! log.warn(" to select a specific one,") log.warn( " use the environment variable XPRA_PULSEAUDIO_DEVICE_NAME" ) if default_monitor in devices: device = default_monitor device_name = devices.get(default_monitor) if not WARNED_MULTIPLE_DEVICES: log.warn("using monitor of default sink: %s", device_name) else: if not WARNED_MULTIPLE_DEVICES: log.warn("using the first device") log.info("using pulseaudio device:") log.info(" '%s'", device_name) #make sure it is not muted: if input_or_output is True or want_monitor_device: set_source_mute(device, mute=False) elif input_or_output is False: set_sink_mute(device, mute=False) return {"device": device}
def get_pulse_defaults(device_name_match=None, want_monitor_device=True, input_or_output=None, remote=None, xpra_device_name=None): """ choose the device to use """ try: from xpra.sound.pulseaudio.pulseaudio_util import has_pa, get_pa_device_options, get_default_sink from xpra.sound.pulseaudio.pulseaudio_util import get_pulse_server, get_pulse_id, set_source_mute, set_sink_mute if not has_pa(): log.warn("Warning: pulseaudio is not available!") return None except ImportError as e: log.warn("Warning: pulseaudio is not available!") log.warn(" %s", e) return None pa_server = get_pulse_server() if remote: log("start sound, remote pulseaudio server=%s, local pulseaudio server=%s", remote.pulseaudio_server, pa_server) #only worth comparing if we have a real server string #one that starts with {UUID}unix:/.. if pa_server and pa_server.startswith("{") and \ remote.pulseaudio_server and remote.pulseaudio_server==pa_server: log.error("Error: sound is disabled to prevent a sound loop") log.error(" identical Pulseaudio server '%s'", pa_server) return None pa_id = get_pulse_id() log("start sound, client id=%s, server id=%s", remote.pulseaudio_id, pa_id) if remote.pulseaudio_id and remote.pulseaudio_id==pa_id: log.error("Error: sound is disabled to prevent a sound loop") log.error(" identical Pulseaudio ID '%s'", pa_id) return None device_type_str = "" if input_or_output is not None: device_type_str = ["output", "input"][input_or_output] if want_monitor_device: device_type_str += " monitor" #def get_pa_device_options(monitors=False, input_or_output=None, ignored_devices=["bell-window-system"], log_errors=True) devices = get_pa_device_options(want_monitor_device, input_or_output) log("found %i pulseaudio %s device%s: %s", len(devices), device_type_str, engs(devices), devices) if len(devices)==0: log.error("Error: sound forwarding is disabled") log.error(" could not detect any Pulseaudio %s devices", device_type_str) return None if len(devices)>1: filters = [] matches = [] for match in (device_name_match, PULSEAUDIO_DEVICE_NAME, xpra_device_name): if not match: continue if match!=xpra_device_name: filters.append(match) match = match.lower() matches = dict((k,v) for k,v in devices.items() if k.lower().find(match)>=0 or v.lower().find(match)>=0) #log("matches(%s, %s)=%s", devices, match, matches) if len(matches)==1: log("found name match for '%s': %s", match, matches.items()[0]) break elif len(matches)>1: log.warn("Warning: Pulseaudio %s device name filter '%s'", device_type_str, match) log.warn(" matched %i devices", len(matches)) if filters or len(matches)>0: if len(matches)==0: log.warn("Warning: Pulseaudio %s device name filter%s:", device_type_str, engs(filters)) log.warn(" %s", csv("'%s'" % x for x in filters)) log.warn(" did not match the devices found:") for k,v in devices.items(): log.warn(" * '%s'", k) log.warn(" '%s'", v) return None devices = matches #default to first one: device, device_name = devices.items()[0] if len(devices)>1: default_sink = get_default_sink() default_monitor = default_sink+".monitor" global WARNED_MULTIPLE_DEVICES if not WARNED_MULTIPLE_DEVICES: WARNED_MULTIPLE_DEVICES = True if not PULSEAUDIO_DEVICE_NAME: #warned already log.warn("Warning: found %i audio devices:", len(devices)) for k,v in devices.items(): log.warn(" * %s", v) log.warn(" %s", k) if not PULSEAUDIO_DEVICE_NAME: #used already! log.warn(" to select a specific one,") log.warn(" use the environment variable XPRA_PULSEAUDIO_DEVICE_NAME") if default_monitor in devices: device = default_monitor device_name = devices.get(default_monitor) if not WARNED_MULTIPLE_DEVICES: log.warn("using monitor of default sink: %s", device_name) else: if not WARNED_MULTIPLE_DEVICES: log.warn("using the first device") log.info("using pulseaudio device:") log.info(" '%s'", device_name) #make sure it is not muted: if input_or_output is True or want_monitor_device: set_source_mute(device, mute=False) elif input_or_output is False: set_sink_mute(device, mute=False) return {"device" : device}