Coverage for /home/antoine/projects/xpra-git/dist/python3/lib64/python/xpra/sound/pulseaudio/pulseaudio_util.py : 65%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
2# This file is part of Xpra.
3# Copyright (C) 2010-2015 Antoine Martin <antoine@xpra.org>
4# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
5# later version. See the file COPYING for details.
7import sys
8import os.path
10from xpra.os_util import WIN32, OSX
11from xpra.log import Logger
12log = Logger("sound")
14default_icon_path = None
15def set_icon_path(v):
16 global default_icon_path
17 default_icon_path = v
19def add_audio_tagging_env(env_dict=os.environ, icon_path=None):
20 """
21 This is called audio-tagging in PulseAudio, see:
22 http://pulseaudio.org/wiki/ApplicationProperties
23 http://0pointer.de/blog/projects/tagging-audio.html
24 """
25 from xpra.version_util import XPRA_VERSION
26 env_dict.update({
27 "PULSE_PROP_application.name" : "xpra",
28 "PULSE_PROP_application.id" : "xpra",
29 "PULSE_PROP_application.version" : XPRA_VERSION,
30 "PULSE_PROP_media.role" : "music",
31 })
32 if not icon_path:
33 icon_path = default_icon_path
34 if icon_path and os.path.exists(icon_path):
35 env_dict["PULSE_PROP_application.icon_name"] = str(icon_path)
38try:
39 #use "none" on win32 and osx:
40 if WIN32 or OSX:
41 from xpra.sound.pulseaudio import pulseaudio_none_util as _pulseaudio_util
42 else:
43 from xpra.sound.pulseaudio import pulseaudio_pactl_util as _pulseaudio_util
44except ImportError as e:
45 #fallback forks a process and parses the output:
46 log("cannot import default pulseaudio util: %s", e)
47 log("using pulseaudio none fallback")
48 del e
49 from xpra.sound.pulseaudio import pulseaudio_none_util as _pulseaudio_util
51get_info = _pulseaudio_util.get_info
52has_pa = _pulseaudio_util.has_pa
53get_pa_device_options = _pulseaudio_util.get_pa_device_options
54get_default_sink = _pulseaudio_util.get_default_sink
55get_pulse_server = _pulseaudio_util.get_pulse_server
56get_pulse_id = _pulseaudio_util.get_pulse_id
57get_pulse_cookie_hash = _pulseaudio_util.get_pulse_cookie_hash
58get_pactl_server = _pulseaudio_util.get_pactl_server
59set_source_mute = _pulseaudio_util.set_source_mute
60set_sink_mute = _pulseaudio_util.set_sink_mute
63def main():
64 from xpra.platform import program_context
65 from xpra.log import enable_color
66 from xpra.util import print_nested_dict
67 with program_context("Pulseaudio-Info"):
68 enable_color()
69 if "-v" in sys.argv or "--verbose" in sys.argv:
70 log.enable_debug()
71 i = get_info()
72 print_nested_dict(i)
75if __name__ == "__main__":
76 main()