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

Source Code for Module flumotion.worker.checks.audio

  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  __version__ = "$Rev: 7097 $" 
 23   
 24  import gst 
 25   
 26  from flumotion.common import messages, log, errors, gstreamer 
 27  from flumotion.common.i18n import N_, gettexter 
 28  from flumotion.worker.checks import check 
 29   
 30  from gst010 import do_element_check 
 31   
 32  T_ = gettexter() 
 33   
34 -def checkMixerTracks(source_factory, device, channels, mid=None):
35 """ 36 Probe the given GStreamer element factory with the given device for 37 audio mixer tracks. 38 Return a deferred firing a result. 39 40 The result is either: 41 - succesful, with a None value: no device found 42 - succesful, with a human-readable device name and a list of mixer 43 track labels. 44 - failed 45 46 @rtype: L{twisted.internet.defer.Deferred} 47 """ 48 result = messages.Result() 49 50 def get_tracks(element): 51 # Only mixers have list_tracks. Why is this a perm error? FIXME in 0.9? 52 if not element.implements_interface(gst.interfaces.Mixer): 53 msg = 'Cannot get mixer tracks from the device. '\ 54 'Check permissions on the mixer device.' 55 log.debug('checks', "returning failure: %s" % msg) 56 raise check.CheckProcError(msg) 57 return (element.get_property('device-name'), 58 [track.label for track in element.list_tracks()])
59 60 pipeline = ('%s name=source device=%s ! ' 61 'audio/x-raw-int,channels=%d ! fakesink') % ( 62 source_factory, device, channels) 63 d = do_element_check(pipeline, 'source', get_tracks, 64 set_state_deferred=True) 65 66 def errbackAlsaBugResult(failure, result, mid, device): 67 # alsasrc in gst-plugins-base <= 0.10.14 was accidentally reporting 68 # GST_RESOURCE_ERROR_WRITE when it could not be opened for reading. 69 if not failure.check(errors.GStreamerGstError): 70 return failure 71 if source_factory != 'alsasrc': 72 return failure 73 version = gstreamer.get_plugin_version('alsasrc') 74 if version > (0, 10, 14): 75 return failure 76 77 source, gerror, debug = failure.value.args 78 log.debug('check', 79 'GStreamer GError: %s (domain %s, code %d, debug %s)' % ( 80 gerror.message, gerror.domain, gerror.code, debug)) 81 82 if gerror.domain == "gst-resource-error-quark": 83 if gerror.code == int(gst.RESOURCE_ERROR_OPEN_WRITE): 84 m = messages.Error(T_( 85 N_("Could not open device '%s' for reading. " 86 "Check permissions on the device."), device)) 87 result.add(m) 88 return result 89 90 return failure 91 92 93 d.addCallback(check.callbackResult, result) 94 d.addErrback(check.errbackNotFoundResult, result, mid, device) 95 d.addErrback(errbackAlsaBugResult, result, mid, device) 96 d.addErrback(check.errbackResult, result, mid, device) 97 98 return d 99