2018-09-05 02:59:34 +02:00
|
|
|
# Copyright (C) 2009 Thibaut GIRKA <thib AT sitedethib.com>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2009-11-29 15:39:26 +01:00
|
|
|
|
2016-03-29 22:54:40 +02:00
|
|
|
import gi
|
2018-03-24 21:57:40 +01:00
|
|
|
import logging
|
2016-03-29 22:54:40 +02:00
|
|
|
gi.require_version('Gst', '1.0')
|
2014-03-25 21:26:57 +01:00
|
|
|
from gi.repository import Gst
|
2009-11-29 15:39:26 +01:00
|
|
|
|
2018-03-24 21:57:40 +01:00
|
|
|
log = logging.getLogger('gajim.c.multimedia_helpers')
|
|
|
|
|
2009-11-29 15:39:26 +01:00
|
|
|
|
|
|
|
class DeviceManager(object):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self):
|
|
|
|
self.devices = {}
|
|
|
|
|
|
|
|
def detect(self):
|
|
|
|
self.devices = {}
|
|
|
|
|
|
|
|
def get_devices(self):
|
|
|
|
if not self.devices:
|
|
|
|
self.detect()
|
|
|
|
return self.devices
|
|
|
|
|
|
|
|
def detect_element(self, name, text, pipe='%s'):
|
2014-03-25 21:26:57 +01:00
|
|
|
if Gst.ElementFactory.find(name):
|
|
|
|
element = Gst.ElementFactory.make(name, '%spresencetest' % name)
|
2018-03-24 21:57:40 +01:00
|
|
|
if element is None:
|
|
|
|
log.warning('could not create %spresencetest', name)
|
2018-04-04 22:09:51 +02:00
|
|
|
return
|
2014-03-25 21:26:57 +01:00
|
|
|
if hasattr(element.props, 'device'):
|
|
|
|
element.set_state(Gst.State.READY)
|
|
|
|
devices = element.get_properties('device')
|
|
|
|
if devices:
|
2017-01-04 13:14:10 +01:00
|
|
|
self.devices[text % _('Default device')] = pipe % name
|
2014-03-25 21:26:57 +01:00
|
|
|
for device in devices:
|
2018-03-25 00:48:29 +01:00
|
|
|
if device is None:
|
|
|
|
continue
|
2014-03-25 21:26:57 +01:00
|
|
|
element.set_state(Gst.State.NULL)
|
|
|
|
element.set_property('device', device)
|
|
|
|
element.set_state(Gst.State.READY)
|
|
|
|
device_name = element.get_property('device-name')
|
|
|
|
self.devices[text % device_name] = pipe % \
|
|
|
|
'%s device=%s' % (name, device)
|
|
|
|
element.set_state(Gst.State.NULL)
|
|
|
|
else:
|
|
|
|
self.devices[text] = pipe % name
|
|
|
|
else:
|
2018-03-24 21:57:40 +01:00
|
|
|
log.info('element %s not found', name)
|
2009-11-29 15:39:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AudioInputManager(DeviceManager):
|
2010-02-08 15:08:40 +01:00
|
|
|
def detect(self):
|
|
|
|
self.devices = {}
|
|
|
|
# Test src
|
|
|
|
self.detect_element('audiotestsrc', _('Audio test'),
|
2011-03-27 18:47:02 +02:00
|
|
|
'%s is-live=true name=gajim_vol')
|
2010-02-08 15:08:40 +01:00
|
|
|
# Auto src
|
|
|
|
self.detect_element('autoaudiosrc', _('Autodetect'),
|
2011-03-27 18:47:02 +02:00
|
|
|
'%s ! volume name=gajim_vol')
|
2010-02-08 15:08:40 +01:00
|
|
|
# Alsa src
|
|
|
|
self.detect_element('alsasrc', _('ALSA: %s'),
|
2011-03-27 18:47:02 +02:00
|
|
|
'%s ! volume name=gajim_vol')
|
|
|
|
# Pulseaudio src
|
|
|
|
self.detect_element('pulsesrc', _('Pulse: %s'),
|
|
|
|
'%s ! volume name=gajim_vol')
|
2009-11-29 15:39:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AudioOutputManager(DeviceManager):
|
2010-02-08 15:08:40 +01:00
|
|
|
def detect(self):
|
|
|
|
self.devices = {}
|
|
|
|
# Fake sink
|
|
|
|
self.detect_element('fakesink', _('Fake audio output'))
|
|
|
|
# Auto sink
|
|
|
|
self.detect_element('autoaudiosink', _('Autodetect'))
|
|
|
|
# Alsa sink
|
2011-03-27 18:47:02 +02:00
|
|
|
self.detect_element('alsasink', _('ALSA: %s'), '%s sync=false')
|
|
|
|
# Pulseaudio sink
|
2011-04-15 14:23:02 +02:00
|
|
|
self.detect_element('pulsesink', _('Pulse: %s'), '%s sync=true')
|
2009-11-29 15:39:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class VideoInputManager(DeviceManager):
|
2010-02-08 15:08:40 +01:00
|
|
|
def detect(self):
|
|
|
|
self.devices = {}
|
|
|
|
# Test src
|
|
|
|
self.detect_element('videotestsrc', _('Video test'),
|
2015-12-23 22:40:53 +01:00
|
|
|
'%s is-live=true ! video/x-raw,framerate=10/1')
|
2010-02-08 15:08:40 +01:00
|
|
|
# Auto src
|
|
|
|
self.detect_element('autovideosrc', _('Autodetect'))
|
2010-03-18 14:40:00 +01:00
|
|
|
# V4L2 src
|
2010-02-08 15:08:40 +01:00
|
|
|
self.detect_element('v4l2src', _('V4L2: %s'))
|
|
|
|
# Funny things, just to test...
|
|
|
|
# self.devices['GOOM'] = 'audiotestsrc ! goom'
|
2012-04-20 16:28:10 +02:00
|
|
|
self.detect_element('ximagesrc', _('Screen'), '%s ! ffmpegcolorspace')
|
2009-11-29 15:39:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class VideoOutputManager(DeviceManager):
|
2010-02-08 15:08:40 +01:00
|
|
|
def detect(self):
|
|
|
|
self.devices = {}
|
|
|
|
# Fake video output
|
2012-12-30 18:59:48 +01:00
|
|
|
self.detect_element('fakesink', _('Fake video output'))
|
2010-02-08 15:08:40 +01:00
|
|
|
# Auto sink
|
2011-03-27 18:47:02 +02:00
|
|
|
self.detect_element('xvimagesink',
|
|
|
|
_('X Window System (X11/XShm/Xv): %s'))
|
2010-02-08 15:08:40 +01:00
|
|
|
# ximagesink
|
|
|
|
self.detect_element('ximagesink', _('X Window System (without Xv)'))
|
|
|
|
self.detect_element('autovideosink', _('Autodetect'))
|