Skip to content

Commit

Permalink
#400: allow more granular speaker and microphone settings: on, off or…
Browse files Browse the repository at this point in the history
… disabled

git-svn-id: https://xpra.org/svn/Xpra/trunk@7700 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Sep 19, 2014
1 parent 3d6fe0f commit 49656b7
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 37 deletions.
15 changes: 11 additions & 4 deletions src/etc/xpra/xpra.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ clipboard = yes
# Enable forwarding of notifications:
notifications = yes

# Show Xpra's tray menu
tray = yes

# Enable forwarding of system tray icons:
system-tray = yes

# Forward sound output to clients:
speaker = yes
#speaker = off
#speaker = disabled
speaker = on

# Forward sound input to server:
# microphone = disabled
# microphone = on
microphone = off

# Debugging:
#debug =
Expand Down Expand Up @@ -119,9 +129,6 @@ dpi = 96
#speaker-codec = speex
#speaker-codec = opus

# Forward sound input to server:
# microphone = yes

# Codec(s) to use for forwarding microphone sound:
#microphone-codec = mp3
#microphone-codec = flac
Expand Down
20 changes: 9 additions & 11 deletions src/man/xpra.1
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ xpra \- viewer for remote, persistent X applications
[\fB\-\-keyboard\-sync\fP=\fIyes\fP|\fIno\fP]
[\fB\-\-tray\fP=\fIyes\fP|\fIno\fP]
[\fB\-\-sound\-source\fP=\fIPLUGIN\fP]
[\fB\-\-speaker\fP=\fIyes\fP|\fIno\fP]
[\fB\-\-speaker\fP=\fIon\fP|\fIoff\fP|\fIdisabled\fP]
[\fB\-\-speaker\-codec\fP=\fICODEC\fP]
[\fB\-\-microphone\fP=\fIyes\fP|\fIno\fP]
[\fB\-\-microphone\fP=\fIon\fP|\fIoff\fP|\fIdisabled\fP]
[\fB\-\-microphone\-codec\fP=\fICODEC\fP]
[\fB\-\-delay\-tray\fP]
[\fB\-\-encoding\fP=\fIENCODING\fP]
Expand Down Expand Up @@ -101,9 +101,9 @@ xpra \- viewer for remote, persistent X applications
[\fB\-\-notifications\fP=\fIyes\fP|\fIno\fP]
[\fB\-\-bell\fP=\fIyes\fP|\fIno\fP]
[\fB\-\-sound\-source\fP=\fIPLUGIN\fP]
[\fB\-\-speaker\fP=\fIyes\fP|\fIno\fP]
[\fB\-\-speaker\fP=\fIon\fP|\fIoff\fP|\fIdisabled\fP]
[\fB\-\-speaker\-codec\fP=\fICODEC\fP]
[\fB\-\-microphone\fP=\fIyes\fP|\fIno\fP]
[\fB\-\-microphone\fP=\fIon\fP|\fIoff\fP|\fIdisabled\fP]
[\fB\-\-microphone\-codec\fP=\fICODEC\fP]
[\fB\-\-bind\-tcp\fP=\fI[HOST]:PORT\fP]
[\fB\-\-auth\fP=\fIMODULE\fP]
Expand Down Expand Up @@ -784,13 +784,11 @@ To get a list of options use the special value 'help'.
It is also possible to specify plugin options using the form:
\fI--sound-source=pulse:device=device.alsa_input.pci-0000_00_14.2.analog-stereo\fP
.TP
\fB\-\-speaker\fP=\fIyes\fP|\fIno\fP
Enable or disable sound output forwarding support. When disabled,
application sound output will not be sent to the client(s).
.TP
\fB\-\-microphone\fP=\fIyes\fP|\fIno\fP
Enable or disable sound input forwarding support.
Application sound input will not be sent from the client(s) to the server.
\fB\-\-speaker\fP=\fIon\fP|\fIoff\fP|\fIdisabled\fP and \fB\-\-microphone\fP=\fIon\fP|\fIoff\fP|\fIdisabled\fP
Sound input and output forwarding support: \fIon\fP will start the forwarding
as soon as the connection is established, \fIoff\fP will require
the user to enable it via the menu, \fIdisabled\fP will
prevent it from being used and the menu entry will be disabled.
.TP
\fB\-\-speaker\-codec\fP=\fICODEC\fP and \fB\-\-microphone\-codec\fP=\fICODEC\fP
Specify the codec(s) to use for sound output (speaker) or input (microphone).
Expand Down
12 changes: 10 additions & 2 deletions src/xpra/client/gtk_base/gtk_tray_menu_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ def set_menu_title(*args):
menu.append(self.make_encodingsmenuitem())
menu.append(self.make_qualitymenuitem())
menu.append(self.make_speedmenuitem())
if self.client.speaker_allowed and STARTSTOP_SOUND_MENU:
if STARTSTOP_SOUND_MENU:
menu.append(self.make_speakermenuitem())
if self.client.microphone_allowed and STARTSTOP_SOUND_MENU:
if STARTSTOP_SOUND_MENU:
menu.append(self.make_microphonemenuitem())
if SHOW_COMPRESSION_MENU:
menu.append(self.make_compressionmenu())
Expand Down Expand Up @@ -671,6 +671,10 @@ def make_speakermenuitem(self):
def is_speaker_on(*args):
return self.client.speaker_enabled
def speaker_state(*args):
if not self.client.speaker_allowed:
speaker.set_sensitive(False)
set_tooltip_text(speaker, "Speaker forwarding has been disabled")
return
if not self.client.server_sound_send:
speaker.set_sensitive(False)
set_tooltip_text(speaker, "Server does not support speaker forwarding")
Expand All @@ -692,6 +696,10 @@ def make_microphonemenuitem(self):
def is_microphone_on(*args):
return self.client.microphone_enabled
def microphone_state(*args):
if not self.client.microphone_allowed:
microphone.set_sensitive(False)
set_tooltip_text(microphone, "Microphone forwarding has been disabled")
return
if not self.client.server_sound_receive:
microphone.set_sensitive(False)
set_tooltip_text(microphone, "Server does not support microphone forwarding")
Expand Down
16 changes: 10 additions & 6 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from xpra.codecs.codec_constants import get_PIL_decodings
from xpra.codecs.loader import codec_versions, has_codec, get_codec, PREFERED_ENCODING_ORDER, ALL_NEW_ENCODING_NAMES_TO_OLD, OLD_ENCODING_NAMES_TO_NEW, PROBLEMATIC_ENCODINGS
from xpra.codecs.video_helper import getVideoHelper, NO_GFX_CSC_OPTIONS
from xpra.scripts.main import sound_option
from xpra.simple_stats import std_unit
from xpra.net import compression, packet_encoding
from xpra.daemon_thread import make_daemon_thread
Expand Down Expand Up @@ -238,14 +239,18 @@ def init(self, opts):
except:
has_gst = False
self.sound_source_plugin = opts.sound_source
self.speaker_allowed = bool(opts.speaker) and has_gst
self.microphone_allowed = bool(opts.microphone) and has_gst
self.speaker_allowed = sound_option(opts.speaker) in ("on", "off") and has_gst
self.speaker_enabled = sound_option(opts.speaker)=="on" and has_gst
self.microphone_allowed = sound_option(opts.microphone) in ("on", "off") and has_gst
self.microphone_enabled = sound_option(opts.microphone)=="on" and has_gst
self.speaker_codecs = opts.speaker_codec
if len(self.speaker_codecs)==0 and self.speaker_allowed:
assert has_gst
self.speaker_codecs = get_sound_codecs(True, False)
self.speaker_allowed = len(self.speaker_codecs)>0
self.microphone_codecs = opts.microphone_codec
if len(self.microphone_codecs)==0 and self.microphone_allowed:
assert has_gst
self.microphone_codecs = get_sound_codecs(False, False)
self.microphone_allowed = len(self.microphone_codecs)>0

Expand Down Expand Up @@ -1326,11 +1331,10 @@ def process_ui_capabilities(self):
soundlog("pulseaudio id=%s, server=%s, sound decoders=%s, sound encoders=%s, receive=%s, send=%s",
self.server_pulseaudio_id, self.server_pulseaudio_server, self.server_sound_decoders,
self.server_sound_encoders, self.server_sound_receive, self.server_sound_send)
if self.server_sound_send and self.speaker_allowed:
if self.server_sound_send and self.speaker_enabled:
self.start_receiving_sound()
#dont' send sound automatically, wait for user to request it:
#if self.server_sound_receive and self.microphone_allowed:
# self.start_sending_sound()
if self.server_sound_receive and self.microphone_enabled:
self.start_sending_sound()

self.key_repeat_delay, self.key_repeat_interval = c.intpair("key_repeat", (-1,-1))
self.emit("handshake-complete")
Expand Down
9 changes: 5 additions & 4 deletions src/xpra/scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def read_xpra_defaults():
"tcp-proxy" : str,
"debug" : str,
"input-method" : str,
"microphone" : str,
"speaker" : str,
"sound-source" : str,
#int options:
"quality" : int,
Expand All @@ -288,8 +290,6 @@ def read_xpra_defaults():
"dbus-proxy" : bool,
"mmap" : bool,
"mmap-group" : bool,
"speaker" : bool,
"microphone" : bool,
"readonly" : bool,
"keyboard-sync" : bool,
"pings" : bool,
Expand Down Expand Up @@ -380,8 +380,8 @@ def get_defaults():
"dbus-proxy" : os.name=="posix" and not sys.platform.startswith("darwin"),
"mmap" : True,
"mmap-group" : False,
"speaker" : has_sound_support,
"microphone" : has_sound_support,
"speaker" : ["disabled", "on"][has_sound_support],
"microphone" : ["disabled", "off"][has_sound_support],
"readonly" : False,
"keyboard-sync" : True,
"pings" : False,
Expand Down Expand Up @@ -432,6 +432,7 @@ def parse_bool(k, v):
return None
else:
warn("Warning: cannot parse value '%s' for '%s' as a boolean" % (v, k))
return None

def print_bool(k, v, true_str='yes', false_str='no'):
if type(v)==type(None):
Expand Down
25 changes: 17 additions & 8 deletions src/xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@
TCP_NODELAY = int(os.environ.get("XPRA_TCP_NODELAY", "1"))


def enabled_str(v):
def enabled_str(v, true_str="yes", false_str="no"):
if v:
return "yes"
else:
return "no"
return true_str
return false_str

def bool_or(v, other_value, true_str, false_str, other_str):
vs = str(v).lower()
if vs==other_value:
return other_str
bv = parse_bool("", v)
return enabled_str(bv, true_str, false_str)

def sound_option(v):
#ensures we return only: "on", "off" or "disabled" given any value
return bool_or(v, "disabled", "on", "off", "disabled")

def warn(msg):
#use this function to print warnings
Expand Down Expand Up @@ -423,9 +432,9 @@ def legacy_bool_parse(optionname, newoptionname=None):
help="Allow more than one client to connect to the same session. Default: %s." % enabled_str(defaults.sharing))
if has_sound_support:
legacy_bool_parse("speaker")
group.add_option("--speaker", action="store", metavar="yes|no",
group.add_option("--speaker", action="store", metavar="on|off|disabled",
dest="speaker", default=defaults.speaker,
help="Forward sound output to the client(s). Default: %s." % enabled_str(defaults.speaker))
help="Forward sound output to the client(s). Default: %s." % sound_option(defaults.speaker))
CODEC_HELP = """Specify the codec(s) to use for forwarding the %s sound output.
This parameter can be specified multiple times and the order in which the codecs
are specified defines the preferred codec order.
Expand All @@ -435,9 +444,9 @@ def legacy_bool_parse(optionname, newoptionname=None):
dest="speaker_codec", default=list(defaults.speaker_codec or []),
help=CODEC_HELP % "speaker")
legacy_bool_parse("microphone")
group.add_option("--microphone", action="store", metavar="yes|no",
group.add_option("--microphone", action="store", metavar="on|off|disabled",
dest="microphone", default=defaults.microphone,
help="Forward sound input to the server. Default: %s." % enabled_str(defaults.microphone))
help="Forward sound input to the server. Default: %s." % sound_option(defaults.microphone))
group.add_option("--microphone-codec", action="append",
dest="microphone_codec", default=list(defaults.microphone_codec or []),
help=CODEC_HELP % "microphone")
Expand Down
5 changes: 3 additions & 2 deletions src/xpra/server/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from xpra.os_util import thread, get_hex_uuid
from xpra.util import typedict, updict, log_screen_sizes, SERVER_EXIT, SERVER_ERROR, SERVER_SHUTDOWN, CLIENT_REQUEST, DETACH_REQUEST, NEW_CLIENT, DONE
from xpra.scripts.config import python_platform
from xpra.scripts.main import sound_option
from xpra.codecs.loader import PREFERED_ENCODING_ORDER, PROBLEMATIC_ENCODINGS, codec_versions, has_codec, get_codec
from xpra.codecs.codec_constants import get_PIL_encodings
from xpra.codecs.video_helper import getVideoHelper, ALL_VIDEO_ENCODER_OPTIONS, ALL_CSC_MODULE_OPTIONS
Expand Down Expand Up @@ -250,8 +251,8 @@ def init_sound(self, sound_source_plugin, speaker, speaker_codec, microphone, mi
has_gst = False
log("init_sound%s has_gst=%s", (sound_source_plugin, speaker, speaker_codec, microphone, microphone_codec), has_gst)
self.sound_source_plugin = sound_source_plugin
self.supports_speaker = bool(speaker) and has_gst
self.supports_microphone = bool(microphone) and has_gst
self.supports_speaker = sound_option(speaker) in ("on", "off") and has_gst
self.supports_microphone = sound_option(microphone) in ("on", "off") and has_gst
self.speaker_codecs = speaker_codec
if len(self.speaker_codecs)==0 and self.supports_speaker:
self.speaker_codecs = get_sound_codecs(True, True)
Expand Down

0 comments on commit 49656b7

Please sign in to comment.