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 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  import os 
 23   
 24  import gobject 
 25  import gst 
 26  import gst.interfaces 
 27  from twisted.internet.threads import deferToThread 
 28  from twisted.internet import defer 
 29   
 30  from flumotion.common import gstreamer, errors, log, messages 
 31  from flumotion.common.i18n import N_, gettexter 
 32  from flumotion.twisted import defer as fdefer 
 33  from flumotion.worker.checks import check 
 34   
 35  __version__ = "$Rev: 7678 $" 
 36  T_ = gettexter() 
 37   
 38   
39 -def fetchDevices(mid, factories, parameter):
40 """ 41 Fetches the available devices on the system according to the specified 42 factories. If the first factory succeeds the other are ignored. 43 44 The result is either: 45 - succesful, with a list of tuples with guid and device-name 46 - succesful, with an error 47 - failed 48 49 @param mid: the id to set on the message. 50 @param factories: The gstreamer elements to check 51 @type factories: L{str} 52 @param parameter: The parameter that specifies the device 53 @type parameter: str 54 55 @rtype: L{twisted.internet.defer.Deferred} of 56 L{flumotion.common.messages.Result} 57 """ 58 result = messages.Result() 59 60 factory = factories.pop() 61 62 element = gst.element_factory_make(factory) 63 64 if not element: 65 log.debug("device-check", 66 "Could not instantiate the %s factory.", 67 factory) 68 if not factories: 69 log.debug("device-check", "No more factories were specified.") 70 m = messages.Error(T_( 71 N_("GStreamer error, %s factory could not be found.\n" 72 "Maybe the plugin is not properly installed.")), mid=mid) 73 result.add(m) 74 75 return defer.succeed(result) 76 else: 77 return fetchDevices(mid, factories, parameter) 78 79 element.probe_property_name(parameter) 80 ids = element.probe_get_values_name(parameter) 81 82 pipeline_str = "%s name=source %s" % (factory, parameter) 83 pipeline_str += "=%s ! fakesink" 84 85 devices = [] 86 87 for id in ids: 88 pipeline = gst.parse_launch(pipeline_str % id) 89 pipeline.set_state(gst.STATE_READY) 90 source = pipeline.get_by_name("source") 91 name = source.get_property("device-name") 92 log.debug("device-check", "New device found: %s with ids=%s", 93 name, id) 94 devices.append((name, id)) 95 pipeline.set_state(gst.STATE_NULL) 96 97 if devices: 98 result.succeed(devices) 99 return defer.succeed(result) 100 else: 101 log.debug("device-check", 102 "No devices were found using %s factory.", 103 factory) 104 if factories: 105 return fetchDevices(mid, factories, parameter) 106 else: 107 108 m = messages.Error(T_( 109 N_("No devices were found for %s."), factory), mid=mid) 110 result.add(m) 111 return defer.succeed(result)
112