Package flumotion :: Package component :: Package effects :: Package audiorate :: Module audiorate
[hide private]

Source Code for Module flumotion.component.effects.audiorate.audiorate

  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 gobject 
 23  import gst 
 24   
 25  from flumotion.common.i18n import gettexter 
 26  from flumotion.component import feedcomponent 
 27   
 28  __version__ = "$Rev$" 
 29  T_ = gettexter() 
 30   
 31   
32 -class AudiorateBin(gst.Bin):
33 """ 34 I am a GStreamer bin that can change the samplerate of an audio stream. 35 """ 36 logCategory = "audiorate" 37 CAPS_TEMPLATE = "audio/x-raw-int,rate=%(rate)d;"\ 38 "audio/x-raw-float,rate=%(rate)d" 39 40 __gproperties__ = { 41 'samplerate': (gobject.TYPE_UINT, 'samplerate', 42 'Audio samplerate', 1, 200000, 44100, 43 gobject.PARAM_READWRITE)} 44
45 - def __init__(self, samplerate=44100):
46 gst.Bin.__init__(self) 47 self._samplerate = samplerate 48 49 self._audioconv = gst.element_factory_make("audioconvert") 50 self._audiorate = gst.element_factory_make("legacyresample") 51 self._capsfilter = gst.element_factory_make("capsfilter") 52 self._identity = gst.element_factory_make("identity") 53 self.add(self._audioconv) 54 self.add(self._audiorate) 55 self.add(self._capsfilter) 56 self.add(self._identity) 57 58 self._audioconv.link(self._audiorate) 59 self._audiorate.link(self._capsfilter) 60 self._capsfilter.link(self._identity) 61 62 # Create source and sink pads 63 self._sinkPad = gst.GhostPad('sink', self._audioconv.get_pad('sink')) 64 self._srcPad = gst.GhostPad('src', self._identity.get_pad('src')) 65 self.add_pad(self._sinkPad) 66 self.add_pad(self._srcPad) 67 68 self._setSamplerate(samplerate)
69
70 - def _setSamplerate(self, samplerate):
71 self._samplerate = samplerate 72 self._capsfilter.set_property('caps', 73 gst.Caps(self.CAPS_TEMPLATE % dict(rate=samplerate)))
74
75 - def do_set_property(self, property, value):
76 if property.name == 'samplerate': 77 self._setSamplerate(value) 78 else: 79 raise AttributeError('unknown property %s' % property.name)
80
81 - def do_get_property(self, property):
82 if property.name == 'samplerate': 83 return self._samplerate 84 else: 85 raise AttributeError('unknown property %s' % property.name)
86 87
88 -class Audiorate(feedcomponent.PostProcEffect):
89 """ 90 I am an effect that can be added to any component that changes the 91 samplerate of the audio output. 92 """ 93 logCategory = "audiorate-effect" 94
95 - def __init__(self, name, sourcePad, pipeline, samplerate):
96 """ 97 @param element: the video source element on which the post 98 processing effect will be added 99 @param sourcePad: source pad used for linking the effect 100 @param pipeline: the pipeline of the element 101 @param samplerate: output samplerate 102 """ 103 feedcomponent.PostProcEffect.__init__(self, name, sourcePad, 104 AudiorateBin(samplerate), pipeline)
105
106 - def effect_setSamplerate(self, samplerate):
107 self.effectBin.set_property("samplerate", samplerate) 108 return samplerate
109
110 - def effect_getSamplerate(self):
111 return self.effectBin.get_property('samplerate')
112