Exemplo n.º 1
0
def start_sending_sound(codec, remote_decoders, local_decoders, remote_pulseaudio_server, remote_pulseaudio_id):
    try:
        matching_codecs = [x for x in remote_decoders if x in local_decoders]
        ordered_codecs = [x for x in CODEC_ORDER if x in matching_codecs]
        if len(ordered_codecs)==0:
            log.error("no matching codecs between remote (%s) and local (%s) - sound disabled", remote_decoders, local_decoders)
            return    None
        if codec is not None and codec not in matching_codecs:
            log.warn("invalid codec specified: %s", codec)
            codec = None
        if codec is None:
            codec = ordered_codecs[0]
        log.info("using sound codec %s", codec)
        from xpra.sound.src import SoundSource
        if SOUND_TEST_MODE:
            sound_source = SoundSource("audiotestsrc", {"wave":2, "freq":110, "volume":0.4}, codec, {})
            log.info("using test sound source")
        else:
            from xpra.sound.pulseaudio_util import has_pa, get_pa_device_options, get_default_sink
            from xpra.sound.pulseaudio_util import get_pulse_server, get_pulse_id, set_source_mute
            if not has_pa():
                log.error("pulseaudio not supported - sound disabled")
                return    None
            pa_server = get_pulse_server()
            soundlog("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("identical pulseaudio server, refusing to create a sound loop - sound disabled")
                return    None
            pa_id = get_pulse_id()
            soundlog("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("identical pulseaudio ID, refusing to create a sound loop - sound disabled")
                return    None
            monitor_devices = get_pa_device_options(True, False)
            soundlog("found pulseaudio monitor devices: %s", monitor_devices)
            if len(monitor_devices)==0:
                log.error("could not detect any pulseaudio monitor devices - sound forwarding is disabled")
                return    None
            #default to first one:
            monitor_device = monitor_devices.items()[0][0]
            if len(monitor_devices)>1:
                default_sink = get_default_sink()
                default_monitor = default_sink+".monitor"
                log.warn("found more than one monitor device: %s", monitor_devices)
                if default_monitor in monitor_devices:
                    log.warn("using monitor of default sink: %s", monitor_devices.get(default_monitor))
                    monitor_device = default_monitor
                else:
                    log.warn("using first device: %s", monitor_devices.items()[0][1])
            #make sure it is not muted:
            set_source_mute(monitor_device, mute=False)
            sound_source = SoundSource("pulsesrc", {"device" : monitor_device}, codec, {})
            log.info("starting sound using pulseaudio device %s", monitor_device)
        return sound_source
    except Exception, e:
        log.error("error setting up sound: %s", e, exc_info=True)
        return    None
Exemplo n.º 2
0
def get_pulse_defaults(remote):
    """
        choose the device to use
    """
    from xpra.sound.pulseaudio_util import has_pa, get_pa_device_options, get_default_sink
    from xpra.sound.pulseaudio_util import get_pulse_server, get_pulse_id, set_source_mute
    if not has_pa():
        log.warn("pulseaudio is not available!")
        return None
    pa_server = get_pulse_server()
    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(
            "identical Pulseaudio server, refusing to create a sound loop - sound disabled"
        )
        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(
            "identical Pulseaudio ID, refusing to create a sound loop - sound disabled"
        )
        return None
    monitor_devices = get_pa_device_options(True, False)
    log("found pulseaudio monitor devices: %s", monitor_devices)
    if len(monitor_devices) == 0:
        log.error(
            "could not detect any Pulseaudio monitor devices - sound forwarding is disabled"
        )
        return None
    #default to first one:
    monitor_device, monitor_device_name = monitor_devices.items()[0]
    if len(monitor_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
            log.warn("found more than one audio monitor device:")
            for k, v in monitor_devices.items():
                log.warn(" * %s (\"%s\")", v, k)
        if default_monitor in monitor_devices:
            monitor_device = default_monitor
            monitor_device_name = monitor_devices.get(default_monitor)
            if not WARNED_MULTIPLE_DEVICES:
                log.warn("using monitor of default sink: %s",
                         monitor_device_name)
        else:
            if not WARNED_MULTIPLE_DEVICES:
                log.warn("using the first device")
    log.info("using Pulseaudio device '%s'", monitor_device_name)
    #make sure it is not muted:
    set_source_mute(monitor_device, mute=False)
    return {"device": monitor_device}
Exemplo n.º 3
0
def get_pulse_defaults(remote):
    """
        choose the device to use
    """
    from xpra.sound.pulseaudio_util import has_pa, get_pa_device_options, get_default_sink
    from xpra.sound.pulseaudio_util import get_pulse_server, get_pulse_id, set_source_mute
    if not has_pa():
        log.warn("pulseaudio is not available!")
        return    None
    pa_server = get_pulse_server()
    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("identical Pulseaudio server, refusing to create a sound loop - sound disabled")
        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("identical Pulseaudio ID, refusing to create a sound loop - sound disabled")
        return    None
    monitor_devices = get_pa_device_options(True, False)
    log("found pulseaudio monitor devices: %s", monitor_devices)
    if len(monitor_devices)==0:
        log.error("could not detect any Pulseaudio monitor devices - sound forwarding is disabled")
        return    None
    #default to first one:
    monitor_device, monitor_device_name = monitor_devices.items()[0]
    if len(monitor_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
            log.warn("found more than one audio monitor device:")
            for k,v in monitor_devices.items():
                log.warn(" * %s (\"%s\")", v, k)
        if default_monitor in monitor_devices:
            monitor_device = default_monitor
            monitor_device_name = monitor_devices.get(default_monitor)
            if not WARNED_MULTIPLE_DEVICES:
                log.warn("using monitor of default sink: %s", monitor_device_name)
        else:
            if not WARNED_MULTIPLE_DEVICES:
                log.warn("using the first device")
    log.info("using Pulseaudio device '%s'", monitor_device_name)
    #make sure it is not muted:
    set_source_mute(monitor_device, mute=False)
    return {"device" : monitor_device}
Exemplo n.º 4
0
def start_sending_sound(remote_decoders, local_decoders, remote_pulseaudio_server, remote_pulseaudio_id):
    try:
        matching_codecs = [x for x in remote_decoders if x in local_decoders]
        ordered_codecs = [x for x in CODEC_ORDER if x in matching_codecs]
        if len(ordered_codecs)==0:
            log.error("no matching codecs between remote (%s) and local (%s) - sound disabled", remote_decoders, local_decoders)
            return    None
        codec = ordered_codecs[0]
        log.info("using sound codec %s", codec)
        from xpra.sound.src import SoundSource
        if SOUND_TEST_MODE:
            sound_source = SoundSource("audiotestsrc", {"wave":2, "freq":110, "volume":0.4}, codec, {})
            log.info("using test sound source")
        else:
            from xpra.sound.pulseaudio_util import has_pa, get_pa_device_options
            from xpra.sound.pulseaudio_util import get_pulse_server, get_pulse_id
            if not has_pa():
                log.error("pulseaudio not supported - sound disabled")
                return    None
            pa_server = get_pulse_server()
            log("start sound, remote pulseaudio server=%s, local pulseaudio server=%s", remote_pulseaudio_server, pa_server)
            if remote_pulseaudio_server and (remote_pulseaudio_server==pa_server or len(pa_server)>16 and remote_pulseaudio_server.endswith(pa_server)):
                log.error("identical pulseaudio server, refusing to create a sound loop - sound disabled")
                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("identical pulseaudio ID, refusing to create a sound loop - sound disabled")
                return    None
            monitor_devices = get_pa_device_options(True, False)
            log("found pulseaudio monitor devices: %s", monitor_devices)
            if len(monitor_devices)==0:
                log.error("could not detect any pulseaudio monitor devices - sound forwarding is disabled")
                return    None
            if len(monitor_devices)>1:
                log.warn("found more than one monitor device: %s", monitor_devices)
                log.warn("using: %s", monitor_devices.items()[0][1])
            monitor_device = monitor_devices.items()[0][0]
            sound_source = SoundSource("pulsesrc", {"device" : monitor_device}, codec, {})
            log.info("starting sound using pulseaudio device %s", monitor_device)
        return sound_source
    except Exception, e:
        log.error("error setting up sound: %s", e, exc_info=True)
        return    None
Exemplo n.º 5
0
def start_sending_sound(remote_decoders, local_decoders,
                        remote_pulseaudio_server, remote_pulseaudio_id):
    try:
        matching_codecs = [x for x in remote_decoders if x in local_decoders]
        ordered_codecs = [x for x in CODEC_ORDER if x in matching_codecs]
        if len(ordered_codecs) == 0:
            log.error(
                "no matching codecs between remote (%s) and local (%s) - sound disabled",
                remote_decoders, local_decoders)
            return None
        codec = ordered_codecs[0]
        log.info("using sound codec %s", codec)
        from xpra.sound.src import SoundSource
        if SOUND_TEST_MODE:
            sound_source = SoundSource("audiotestsrc", {
                "wave": 2,
                "freq": 110,
                "volume": 0.4
            }, codec, {})
            log.info("using test sound source")
        else:
            from xpra.sound.pulseaudio_util import has_pa, get_pa_device_options
            from xpra.sound.pulseaudio_util import get_pulse_server, get_pulse_id
            if not has_pa():
                log.error("pulseaudio not supported - sound disabled")
                return None
            pa_server = get_pulse_server()
            log(
                "start sound, remote pulseaudio server=%s, local pulseaudio server=%s",
                remote_pulseaudio_server, pa_server)
            if remote_pulseaudio_server and (
                    remote_pulseaudio_server == pa_server
                    or len(pa_server) > 16
                    and remote_pulseaudio_server.endswith(pa_server)):
                log.error(
                    "identical pulseaudio server, refusing to create a sound loop - sound disabled"
                )
                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(
                    "identical pulseaudio ID, refusing to create a sound loop - sound disabled"
                )
                return None
            monitor_devices = get_pa_device_options(True, False)
            log("found pulseaudio monitor devices: %s", monitor_devices)
            if len(monitor_devices) == 0:
                log.error(
                    "could not detect any pulseaudio monitor devices - sound forwarding is disabled"
                )
                return None
            if len(monitor_devices) > 1:
                log.warn("found more than one monitor device: %s",
                         monitor_devices)
                log.warn("using: %s", monitor_devices.items()[0][1])
            monitor_device = monitor_devices.items()[0][0]
            sound_source = SoundSource("pulsesrc", {"device": monitor_device},
                                       codec, {})
            log.info("starting sound using pulseaudio device %s",
                     monitor_device)
        return sound_source
    except Exception, e:
        log.error("error setting up sound: %s", e, exc_info=True)
        return None
Exemplo n.º 6
0
def start_sending_sound(codec, volume, remote_decoders, local_decoders,
                        remote_pulseaudio_server, remote_pulseaudio_id):
    assert has_gst
    try:
        matching_codecs = [x for x in remote_decoders if x in local_decoders]
        ordered_codecs = [x for x in CODEC_ORDER if x in matching_codecs]
        if len(ordered_codecs) == 0:
            log.error(
                "no matching codecs between remote (%s) and local (%s) - sound disabled",
                remote_decoders, local_decoders)
            return None
        if codec is not None and codec not in matching_codecs:
            log.warn("invalid codec specified: %s", codec)
            codec = None
        if codec is None:
            codec = ordered_codecs[0]
        log("using sound codec %s", codec)
        from xpra.sound.src import SoundSource
        if SOUND_TEST_MODE:
            sound_source = SoundSource("audiotestsrc", {
                "wave": 2,
                "freq": 110,
                "volume": 0.4
            }, codec, volume, {})
            log.info("using test sound source")
        else:
            from xpra.sound.pulseaudio_util import has_pa, get_pa_device_options, get_default_sink
            from xpra.sound.pulseaudio_util import get_pulse_server, get_pulse_id, set_source_mute
            if not has_pa():
                log.error("pulseaudio not supported - sound disabled")
                return None
            pa_server = get_pulse_server()
            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(
                    "identical pulseaudio server, refusing to create a sound loop - sound disabled"
                )
                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(
                    "identical pulseaudio ID, refusing to create a sound loop - sound disabled"
                )
                return None
            monitor_devices = get_pa_device_options(True, False)
            log("found pulseaudio monitor devices: %s", monitor_devices)
            if len(monitor_devices) == 0:
                log.error(
                    "could not detect any pulseaudio monitor devices - sound forwarding is disabled"
                )
                return None
            #default to first one:
            monitor_device, monitor_device_name = monitor_devices.items()[0]
            if len(monitor_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
                    log.warn("found more than one audio monitor device:")
                    for k, v in monitor_devices.items():
                        log.warn(" * %s (\"%s\")", v, k)
                if default_monitor in monitor_devices:
                    monitor_device = default_monitor
                    monitor_device_name = monitor_devices.get(default_monitor)
                    if not WARNED_MULTIPLE_DEVICES:
                        log.warn("using monitor of default sink: %s",
                                 monitor_device_name)
                else:
                    if not WARNED_MULTIPLE_DEVICES:
                        log.warn("using the first device")
            #make sure it is not muted:
            set_source_mute(monitor_device, mute=False)
            sound_source = SoundSource("pulsesrc", {"device": monitor_device},
                                       codec, volume, {})
            log.info("starting sound capture using pulseaudio device: %s",
                     monitor_device_name)
        return sound_source
    except:
        e = sys.exc_info()[1]
        log.error("error setting up sound: %s", e, exc_info=True)
        return None
Exemplo n.º 7
0
def get_pulse_defaults(want_monitor_device, remote):
    """
        choose the device to use
    """
    from xpra.sound.pulseaudio_util import has_pa, get_pa_device_options, get_default_sink
    from xpra.sound.pulseaudio_util import get_pulse_server, get_pulse_id, set_source_mute
    if not has_pa():
        log.warn("pulseaudio is not available!")
        return    None
    pa_server = get_pulse_server()
    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 = ["input", "monitor"][want_monitor_device]
    devices = get_pa_device_options(want_monitor_device, not want_monitor_device)
    log("found pulseaudio %s devices: %s", device_type_str, 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 and INPUT_DEVICE_NAME:
        devices = dict((k,v) for k,v in devices.items() if k.find(INPUT_DEVICE_NAME)>=0 or v.find(INPUT_DEVICE_NAME)>0)
        if len(devices)==0:
            log.warn("Warning: Pulseaudio %s device name filter '%s'", device_type_str, INPUT_DEVICE_NAME)
            log.warn(" did not match any devices")
            return None
        elif len(devices)>1:
            log.warn("Warning: Pulseaudio %s device name filter '%s'", device_type_str, INPUT_DEVICE_NAME)
            log.warn(" matched %i devices", len(devices))
    #default to first one:
    device, device_name = devices.items()[0]
    if len(devices)>1 and want_monitor_device:
        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 INPUT_DEVICE_NAME: #warned already
                log.warn("Warning: found more than one audio monitor device:")
            for k,v in devices.items():
                log.warn(" * %s", v)
                log.warn("   %s", k)
            if not INPUT_DEVICE_NAME: #used already!
                log.warn(" use the environment variable XPRA_INPUT_DEVICE_NAME to select a specific one")
        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:
    set_source_mute(device, mute=False)
    return {"device" : device}
Exemplo n.º 8
0
def get_pulse_defaults(want_monitor_device, remote):
    """
        choose the device to use
    """
    from xpra.sound.pulseaudio_util import has_pa, get_pa_device_options, get_default_sink
    from xpra.sound.pulseaudio_util import get_pulse_server, get_pulse_id, set_source_mute
    if not has_pa():
        log.warn("pulseaudio is not available!")
        return None
    pa_server = get_pulse_server()
    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 = ["input", "monitor"][want_monitor_device]
    devices = get_pa_device_options(want_monitor_device,
                                    not want_monitor_device)
    log("found pulseaudio %s devices: %s", device_type_str, 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 and INPUT_DEVICE_NAME:
        devices = dict(
            (k, v) for k, v in devices.items()
            if k.find(INPUT_DEVICE_NAME) >= 0 or v.find(INPUT_DEVICE_NAME) > 0)
        if len(devices) == 0:
            log.warn("Warning: Pulseaudio %s device name filter '%s'",
                     device_type_str, INPUT_DEVICE_NAME)
            log.warn(" did not match any devices")
            return None
        elif len(devices) > 1:
            log.warn("Warning: Pulseaudio %s device name filter '%s'",
                     device_type_str, INPUT_DEVICE_NAME)
            log.warn(" matched %i devices", len(devices))
    #default to first one:
    device, device_name = devices.items()[0]
    if len(devices) > 1 and want_monitor_device:
        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 INPUT_DEVICE_NAME:  #warned already
                log.warn("Warning: found more than one audio monitor device:")
            for k, v in devices.items():
                log.warn(" * %s", v)
                log.warn("   %s", k)
            if not INPUT_DEVICE_NAME:  #used already!
                log.warn(
                    " use the environment variable XPRA_INPUT_DEVICE_NAME to select a specific one"
                )
        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:
    set_source_mute(device, mute=False)
    return {"device": device}