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