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

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

  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,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  import gobject 
 19  import gst 
 20   
 21  from flumotion.common.i18n import gettexter 
 22  from flumotion.component import feedcomponent 
 23   
 24  __version__ = "$Rev$" 
 25  T_ = gettexter() 
 26   
 27   
28 -class AudioResyncer(gst.Element):
29 ''' 30 I retimestamp incomming buffers adding a fixed delay. 31 ''' 32 33 __gproperties__ = { 34 'delay': (float, 'delay (in ms)', 35 'Resynchronisation delay in milliseconds', 36 -1000000, 1000000, 0, 37 gobject.PARAM_READWRITE)} 38 39 _sinkpadtemplate = gst.PadTemplate("sink", 40 gst.PAD_SINK, 41 gst.PAD_ALWAYS, 42 gst.caps_from_string( 43 "audio/x-raw-float;" 44 "audio/x-raw-int")) 45 46 _srcpadtemplate = gst.PadTemplate("src", 47 gst.PAD_SRC, 48 gst.PAD_ALWAYS, 49 gst.caps_from_string( 50 "audio/x-raw-float;" 51 "audio/x-raw-int")) 52
53 - def __init__(self, delay=0):
54 gst.Element.__init__(self) 55 56 self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink") 57 self.sinkpad.set_chain_function(self.chainfunc) 58 self.add_pad(self.sinkpad) 59 60 self.srcpad = gst.Pad(self._srcpadtemplate, "src") 61 self.add_pad(self.srcpad) 62 63 self._delay = long(delay * gst.MSECOND) 64 print self._delay
65
66 - def do_get_property(self, property):
67 if property.name == "delay": 68 return self._delay 69 else: 70 raise AttributeError('unknown property %s' % property.name)
71
72 - def do_set_property(self, property, value):
73 if property.name == "delay": 74 self._delay = long(value * gst.MSECOND) 75 else: 76 raise AttributeError('unknown property %s' % property.name)
77
78 - def chainfunc(self, pad, buffer):
79 if self._delay != 0: 80 buffer.make_metadata_writable 81 buffer.timestamp = buffer.timestamp + self._delay 82 self.srcpad.push(buffer) 83 return gst.FLOW_OK
84 85
86 -class Audioresync(feedcomponent.PostProcEffect):
87 """ 88 Post processing audio effect to increase/decrease the audio delay an 89 synchronise it on the fly with the video stream. 90 """ 91 logCategory = "audioresync-effect" 92
93 - def __init__(self, name, sourcePad, pipeline, delay):
94 """ 95 @param element: the video source element on which the post 96 processing effect will be added 97 @param sourcePad: source pad used for linking the effect 98 @param pipeline: the pipeline of the element 99 @param delay: audio delay added 100 """ 101 feedcomponent.PostProcEffect.__init__(self, name, sourcePad, 102 AudioResyncer(delay), pipeline)
103
104 - def setUIState(self, state):
105 feedcomponent.Effect.setUIState(self, state) 106 if state: 107 state.addKey('audioresync-delay', 108 self.effectBin.get_property('delay'))
109
110 - def effect_setDelay(self, delay):
111 self.effectBin.set_property("delay", delay) 112 return delay
113
114 - def effect_getDelay(self):
115 return self.effectBin.get_property('delay')
116