Package flumotion :: Package worker :: Package checks :: Module device
[hide private]

Source Code for Module flumotion.worker.checks.device

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  import gst 
 19  import gst.interfaces 
 20  from twisted.internet.threads import deferToThread 
 21  from twisted.internet import defer 
 22   
 23  from flumotion.common import log, messages 
 24  from flumotion.common.i18n import N_, gettexter 
 25   
 26  __version__ = "$Rev: 7678 $" 
 27  T_ = gettexter() 
 28   
 29   
30 -def fetchDevices(mid, factories, parameter):
31 """ 32 Fetches the available devices on the system according to the specified 33 factories. If the first factory succeeds the other are ignored. 34 35 The result is either: 36 - succesful, with a list of tuples with guid and device-name 37 - succesful, with an error 38 - failed 39 40 @param mid: the id to set on the message. 41 @param factories: The gstreamer elements to check 42 @type factories: L{str} 43 @param parameter: The parameter that specifies the device 44 @type parameter: str 45 46 @rtype: L{twisted.internet.defer.Deferred} of 47 L{flumotion.common.messages.Result} 48 """ 49 result = messages.Result() 50 51 factory = factories.pop() 52 53 try: 54 element = gst.element_factory_make(factory) 55 except gst.ElementNotFoundError: 56 element = None 57 58 if not element: 59 log.debug("device-check", 60 "Could not instantiate the %s factory.", 61 factory) 62 if not factories: 63 log.debug("device-check", "No more factories were specified.") 64 m = messages.Error(T_( 65 N_("GStreamer error, %s factory could not be found.\n" 66 "Maybe the plugin is not properly installed.")), mid=mid) 67 result.add(m) 68 69 return defer.succeed(result) 70 else: 71 return fetchDevices(mid, factories, parameter) 72 73 element.probe_property_name(parameter) 74 values = element.probe_get_values_name(parameter) 75 76 pipeline_str = "%s name=source %s" % (factory, parameter) 77 pipeline_str += "=%s ! fakesink" 78 79 devices = [] 80 81 for value in values: 82 pipeline = gst.parse_launch(pipeline_str % value) 83 pipeline.set_state(gst.STATE_READY) 84 source = pipeline.get_by_name("source") 85 name = source.get_property("device-name") 86 log.debug("device-check", "New device found: %s with values=%s", 87 name, value) 88 devices.append((name, value)) 89 pipeline.set_state(gst.STATE_NULL) 90 91 if devices: 92 result.succeed(devices) 93 return defer.succeed(result) 94 else: 95 log.debug("device-check", 96 "No devices were found using %s factory.", 97 factory) 98 if factories: 99 return fetchDevices(mid, factories, parameter) 100 else: 101 102 m = messages.Error(T_( 103 N_("No devices were found for %s."), factory), mid=mid) 104 result.add(m) 105 return defer.succeed(result)
106