Package flumotion :: Package component :: Package producers :: Package audiotest :: Module audiotest
[hide private]

Source Code for Module flumotion.component.producers.audiotest.audiotest

  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 gst 
 23   
 24  from twisted.internet import defer 
 25   
 26  from flumotion.common import errors, gstreamer, messages 
 27  from flumotion.common.i18n import N_, gettexter 
 28  from flumotion.component import feedcomponent 
 29  from flumotion.component.effects.volume import volume 
 30  from flumotion.worker.checks import check 
 31   
 32  __version__ = "$Rev: 8413 $" 
 33  T_ = gettexter() 
 34   
 35   
36 -class AudioTestMedium(feedcomponent.FeedComponentMedium):
37
38 - def remote_setFrequency(self, frequency):
39 """ 40 @type frequency: int 41 """ 42 return self.comp.setFrequency(frequency)
43
44 - def remote_setWave(self, wave):
45 """ 46 @type wave: int 47 """ 48 return self.comp.setWave(wave)
49 50
51 -class AudioTest(feedcomponent.ParseLaunchComponent):
52 componentMediumClass = AudioTestMedium 53
54 - def init(self):
55 self.uiState.addKey('wave', 0) 56 self.uiState.addKey('frequency', 440) 57 self.uiState.addKey('samplerate', 44100)
58
59 - def do_check(self):
60 levelD = check.do_check(self, check.checkPlugin, 'level', 'level') 61 audiotestD = check.do_check(self, check.checkPlugin, 'audiotestsrc', 62 'audiotestsrc') 63 volumeD = check.do_check(self, check.checkPlugin, 'volume', 'volume') 64 dl = defer.DeferredList([levelD, audiotestD, volumeD]) 65 return dl
66
67 - def get_pipeline_string(self, properties):
68 samplerate = properties.get('samplerate', 44100) 69 wave = properties.get('wave', 0) 70 self.samplerate = samplerate 71 volume = properties.get('volume', 1.0) 72 73 is_live = 'is-live=true' 74 source = 'audiotestsrc' 75 76 if not gstreamer.element_factory_exists(source): 77 raise errors.MissingElementError(source) 78 79 return ('%s name=source wave=%s %s ! ' \ 80 'identity name=identity silent=TRUE ! ' \ 81 'audio/x-raw-int,rate=%d ! ' \ 82 'volume name=volume volume=%f ! level name=level' 83 % (source, wave, is_live, samplerate, volume))
84
85 - def configure_pipeline(self, pipeline, properties):
86 87 self.fixRenamedProperties(properties, [ 88 ('freq', 'frequency'), 89 ]) 90 91 element = self.get_element('source') 92 if 'frequency' in properties: 93 element.set_property('freq', properties['frequency']) 94 self.uiState.set('frequency', properties['frequency']) 95 96 if 'drop-probability' in properties: 97 vt = gstreamer.get_plugin_version('coreelements') 98 if not vt: 99 raise errors.MissingElementError('identity') 100 if not vt > (0, 10, 12, 0): 101 self.addMessage( 102 messages.Warning(T_(N_( 103 "The 'drop-probability' property is specified, but " 104 "it only works with GStreamer core newer than 0.10.12." 105 " You should update your version of GStreamer.")))) 106 else: 107 drop_probability = properties['drop-probability'] 108 if drop_probability < 0.0 or drop_probability > 1.0: 109 self.addMessage( 110 messages.Warning(T_(N_( 111 "The 'drop-probability' property can only be " 112 "between 0.0 and 1.0.")))) 113 else: 114 identity = self.get_element('identity') 115 identity.set_property('drop-probability', 116 drop_probability) 117 118 self.uiState.set('samplerate', self.samplerate) 119 self.uiState.set('wave', int(element.get_property('wave'))) 120 121 level = pipeline.get_by_name('level') 122 vol = volume.Volume('volume', level, pipeline) 123 self.addEffect(vol)
124
125 - def setVolume(self, value):
126 self.debug("Volume set to %d" % value) 127 element = self.get_element('volume') 128 element.set_property('volume', value)
129
130 - def getVolume(self):
131 element = self.get_element('volume') 132 return element.get_property('volume')
133
134 - def setFrequency(self, frequency):
135 element = self.get_element('source') 136 element.set_property('freq', frequency) 137 self.uiState.set('frequency', frequency)
138
139 - def setWave(self, wave):
140 element = self.get_element('source') 141 element.set_property('wave', wave) 142 self.uiState.set('wave', wave)
143