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