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

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

  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  from twisted.internet import reactor 
 19  import gobject 
 20  import gst 
 21   
 22  from flumotion.common.i18n import N_, gettexter 
 23  from flumotion.component import feedcomponent 
 24   
 25  # register serializables 
 26  from flumotion.common import messages 
 27   
 28  __version__ = "$Rev$" 
 29  T_ = gettexter() 
 30   
 31   
32 -class VideorateBin(gst.Bin):
33 """ 34 I am a GStreamer bin that can change the framerate of a video stream. 35 """ 36 logCategory = "videosrate" 37 CAPS_TEMPLATE = "video/x-raw-yuv%(fr)s;"\ 38 "video/x-raw-rgb%(fr)s" 39 40 __gproperties__ = { 41 'framerate': (gobject.TYPE_OBJECT, 'framerate', 42 'Video framerate', gobject.PARAM_READWRITE)} 43
44 - def __init__(self, framerate=gst.Fraction(25, 1)):
45 gst.Bin.__init__(self) 46 self._framerate = framerate 47 48 self._videorate = gst.element_factory_make("videorate") 49 self._capsfilter = gst.element_factory_make("capsfilter") 50 self.add(self._videorate, self._capsfilter) 51 52 self._videorate.link(self._capsfilter) 53 54 # Create source and sink pads 55 self._sinkPad = gst.GhostPad('sink', self._videorate.get_pad('sink')) 56 self._srcPad = gst.GhostPad('src', self._capsfilter.get_pad('src')) 57 self.add_pad(self._sinkPad) 58 self.add_pad(self._srcPad) 59 60 self._setFramerate(framerate)
61
62 - def _setFramerate(self, framerate):
63 self._framerate = framerate 64 self._capsfilter.set_property('caps', 65 gst.Caps(self.CAPS_TEMPLATE % dict(fr=self.framerateToString())))
66
67 - def do_set_property(self, property, value):
68 if property.name == 'framerate': 69 self._setFramerate(value) 70 else: 71 raise AttributeError('unknown property %s' % property.name)
72
73 - def do_get_property(self, property):
74 if property.name == 'framerate': 75 return self._framerate 76 else: 77 raise AttributeError('unknown property %s' % property.name)
78
79 - def framerateToString(self):
80 if self._framerate is None: 81 return "" 82 return ",framerate=(fraction)%d/%d" % (self._framerate.num, 83 self._framerate.denom)
84 85
86 -class Videorate(feedcomponent.PostProcEffect):
87 """ 88 I am an effect that can be added to any component that has a videorate 89 component and a way of changing the output framerate. 90 """ 91 logCategory = "videorate-effect" 92
93 - def __init__(self, name, sourcePad, pipeline, framerate):
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 framerate: output framerate 100 """ 101 feedcomponent.PostProcEffect.__init__(self, name, sourcePad, 102 VideorateBin(framerate), pipeline)
103
104 - def effect_setFramerate(self, framerate):
105 self.effectBin.set_property("framerate", framerate) 106 return framerate
107
108 - def effect_getFramerate(self):
109 return self.effectBin.get_property('framerate')
110