[herfik] improve pulsaudio support in jingle audio. Fixes #6859
[gajim.git] / src / common / multimedia_helpers.py
blob6aabbfb3da7991355ba67d42e71fec1a8fdd9a17
1 ##
2 ## Copyright (C) 2009 Thibaut GIRKA <thib AT sitedethib.com>
3 ##
4 ## This program is free software; you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published
6 ## by the Free Software Foundation; version 2 only.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
14 import gst
17 class DeviceManager(object):
18 def __init__(self):
19 self.devices = {}
21 def detect(self):
22 self.devices = {}
24 def get_devices(self):
25 if not self.devices:
26 self.detect()
27 return self.devices
29 def detect_element(self, name, text, pipe='%s'):
30 try:
31 if gst.element_factory_find(name):
32 element = gst.element_factory_make(name,
33 '%spresencetest' % name)
34 if isinstance(element, gst.interfaces.PropertyProbe):
35 element.set_state(gst.STATE_READY)
36 element.probe_property_name('device')
37 devices = element.probe_get_values_name('device')
38 if devices:
39 self.devices[text % _(' Default device')] = pipe % name
40 for device in devices:
41 element.set_state(gst.STATE_NULL)
42 element.set_property('device', device)
43 element.set_state(gst.STATE_READY)
44 device_name = element.get_property('device-name')
45 self.devices[text % device_name] = pipe % \
46 '%s device=%s' % (name, device)
47 element.set_state(gst.STATE_NULL)
48 else:
49 self.devices[text] = pipe % name
50 except ImportError:
51 pass
52 except gst.ElementNotFoundError:
53 print 'element \'%s\' not found' % name
56 class AudioInputManager(DeviceManager):
57 def detect(self):
58 self.devices = {}
59 # Test src
60 self.detect_element('audiotestsrc', _('Audio test'),
61 '%s is-live=true name=gajim_vol')
62 # Auto src
63 self.detect_element('autoaudiosrc', _('Autodetect'),
64 '%s ! volume name=gajim_vol')
65 # Alsa src
66 self.detect_element('alsasrc', _('ALSA: %s'),
67 '%s ! volume name=gajim_vol')
68 # Pulseaudio src
69 self.detect_element('pulsesrc', _('Pulse: %s'),
70 '%s ! volume name=gajim_vol')
73 class AudioOutputManager(DeviceManager):
74 def detect(self):
75 self.devices = {}
76 # Fake sink
77 self.detect_element('fakesink', _('Fake audio output'))
78 # Auto sink
79 self.detect_element('autoaudiosink', _('Autodetect'))
80 # Alsa sink
81 self.detect_element('alsasink', _('ALSA: %s'), '%s sync=false')
82 # Pulseaudio sink
83 self.detect_element('pulsesink', _('Pulse: %s'), '%s sync=true')
86 class VideoInputManager(DeviceManager):
87 def detect(self):
88 self.devices = {}
89 # Test src
90 self.detect_element('videotestsrc', _('Video test'),
91 '%s is-live=true ! video/x-raw-yuv,framerate=10/1')
92 # Auto src
93 self.detect_element('autovideosrc', _('Autodetect'))
94 # V4L2 src
95 self.detect_element('v4l2src', _('V4L2: %s'))
96 # Funny things, just to test...
97 # self.devices['GOOM'] = 'audiotestsrc ! goom'
98 # self.devices['screen'] = 'ximagesrc'
101 class VideoOutputManager(DeviceManager):
102 def detect(self):
103 self.devices = {}
104 # Fake video output
105 self.detect_element('fakesink', _('Fake audio output'))
106 # Auto sink
107 self.detect_element('xvimagesink',
108 _('X Window System (X11/XShm/Xv): %s'))
109 # ximagesink
110 self.detect_element('ximagesink', _('X Window System (without Xv)'))
111 self.detect_element('autovideosink', _('Autodetect'))