Trees | Indices | Help |
---|
|
1 # -*- Mode: Python; test-case-name:flumotion.test.test_soundcard -*- 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 gst 23 import gst.interfaces 24 25 from twisted.internet import defer 26 27 from flumotion.common import messages 28 from flumotion.common.i18n import N_, gettexter 29 from flumotion.component import feedcomponent 30 from flumotion.component.effects.volume import volume 31 32 __version__ = "$Rev$" 33 T_ = gettexter() 34 353717639 self.debug('running PyGTK/PyGST checks') 40 from flumotion.component.producers import checks 41 d1 = checks.checkTicket347() 42 d2 = checks.checkTicket348() 43 dl = defer.DeferredList([d1, d2]) 44 dl.addCallback(self._checkCallback) 45 return dl46 5153 element = properties.get('source-element', 'alsasrc') 54 self.device = properties.get('device', 'hw:0') 55 samplerate = properties.get('samplerate', 44100) 56 depth = properties.get('depth', 16) 57 channels = properties.get('channels', 2) 58 self.inputTrackLabel = properties.get('input-track', None) 59 d = self._change_monitor.add(gst.STATE_CHANGE_NULL_TO_READY) 60 d.addCallback(self._set_input_track, self.inputTrackLabel) 61 # FIXME: we should find a way to figure out what the card supports, 62 # so we can add in correct elements on the fly 63 # just adding audioscale and audioconvert always makes the soundcard 64 # open in 1000 Hz, mono 65 caps = 'audio/x-raw-int,rate=(int)%d,depth=%d,channels=%d' % ( 66 samplerate, depth, channels) 67 pipeline = "%s device=%s name=src ! %s ! " \ 68 "level name=volumelevel message=true" % ( 69 element, self.device, caps) 70 self._srcelement = None 71 return pipeline7274 # add volume effect 75 comp_level = pipeline.get_by_name('volumelevel') 76 allowVolumeSet = True 77 if gst.pygst_version < (0, 10, 7): 78 allowVolumeSet = False 79 m = messages.Info(T_( 80 N_("The soundcard volume cannot be changed with this version " 81 "of the 'gst-python' library.\n")), 82 mid='mixer-track-setting') 83 m.add(T_(N_("Please upgrade '%s' to version %s or later " 84 "if you require this functionality."), 85 'gst-python', '0.10.7')) 86 self.addMessage(m) 87 88 vol = volume.Volume('inputVolume', comp_level, pipeline, 89 allowIncrease=False, allowVolumeSet=allowVolumeSet) 90 self.addEffect(vol) 91 self._srcelement = pipeline.get_by_name("src")9294 element = self._srcelement 95 for track in element.list_tracks(): 96 if trackLabel != None: 97 self.debug("Setting track %s to record", trackLabel) 98 # some low-end sound cards require the Capture track to be 99 # set to recording to get any sound, so set that track and 100 # the input track we selected 101 element.set_record(track, 102 (track.get_property("label") == trackLabel or 103 track.get_property("label") == "Capture"))104106 if gst.pygst_version < (0, 10, 7): 107 self.warning( 108 "Cannot set volume on soundcards with gst-python < 0.10.7") 109 return 110 self.debug("Volume set to: %f", value) 111 if self.inputTrackLabel and self._srcelement: 112 element = self._srcelement 113 volumeSet = False 114 for track in element.list_tracks(): 115 if track.get_property("label") == self.inputTrackLabel: 116 volumeVals = tuple(int(value/1.0 * 117 track.get_property("max-volume")) 118 for _ in xrange(0, track.get_property("num-channels"))) 119 element.set_volume(track, volumeVals) 120 volumeSet = True 121 break 122 if not volumeSet: 123 self.warning("could not find track %s", self.inputTrackLabel) 124 else: 125 self.warning("no input track selected, cannot set volume")126128 if gst.pygst_version < (0, 10, 7): 129 self.warning( 130 "Cannot query volume on soundcards with gst-python < 0.10.7") 131 return 1.0 132 if self.inputTrackLabel and self._srcelement: 133 element = self._srcelement 134 for track in element.list_tracks(): 135 if track.get_property("label") == self.inputTrackLabel: 136 volumeVals = element.get_volume(track) 137 vol = 0 138 nchannels = track.get_property("num-channels") 139 for k in range(0, track.get_property("num-channels")): 140 vol = vol + (volumeVals[k] / nchannels) 141 maxVolume = float(track.get_property('max-volume')) 142 self.debug("vol: %f max vol: %f", vol, maxVolume) 143 144 if maxVolume == 0.0: 145 return 1.0 146 147 v = vol / maxVolume 148 149 self.debug("v: %f", v) 150 return v 151 self.warning("could not find track %s", self.inputTrackLabel) 152 else: 153 self.warning("no input track selected, cannot set volume") 154 return 1.0155157 if gerror.domain == 'gst-resource-error-quark': 158 # before 0.10.14 gst-plugins-base had the error as WRITE by mistake 159 if gerror.code in [ 160 gst.RESOURCE_ERROR_OPEN_WRITE, 161 gst.RESOURCE_ERROR_OPEN_READ]: 162 m = messages.Error(T_(N_( 163 "Could not open sound device '%s'. " 164 "Please check permissions on the device."), 165 self.device), debug=debug) 166 return m 167 if gerror.code == gst.RESOURCE_ERROR_BUSY: 168 m = messages.Error(T_(N_( 169 "The sound device '%s' is in use by another program. " 170 "Please stop the other program and try again."), 171 self.device)) 172 return m 173 174 base = feedcomponent.ParseLaunchComponent 175 return base.make_message_for_gstreamer_error(self, gerror, debug)
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Apr 29 18:56:31 2011 | http://epydoc.sourceforge.net |