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  import gobject 
 19  import gst 
 20   
 21  from flumotion.component import feedcomponent 
 22  from flumotion.common import gstreamer 
 23   
 24  __version__ = "$Rev$" 
 25   
 26   
27 -class VideorateBin(gst.Bin):
28 """ 29 I am a GStreamer bin that can change the framerate of a video stream. 30 """ 31 logCategory = "videosrate" 32 CAPS_TEMPLATE = "video/x-raw-yuv%(fr)s;"\ 33 "video/x-raw-rgb%(fr)s" 34 35 __gproperties__ = { 36 'framerate': (gobject.TYPE_OBJECT, 'framerate', 37 'Video framerate', gobject.PARAM_READWRITE)} 38
39 - def __init__(self, framerate=gst.Fraction(25, 1)):
40 gst.Bin.__init__(self) 41 self._framerate = framerate 42 43 self._videorate = gst.element_factory_make("videorate") 44 self._capsfilter = gst.element_factory_make("capsfilter") 45 self.add(self._videorate, self._capsfilter) 46 47 self._videorate.link(self._capsfilter) 48 49 # Set properties 50 if gstreamer.element_has_property(self._videorate, 'skip-to-first'): 51 self._videorate.set_property('skip-to-first', True) 52 53 # Create source and sink pads 54 self._sinkPad = gst.GhostPad('sink', self._videorate.get_pad('sink')) 55 self._srcPad = gst.GhostPad('src', self._capsfilter.get_pad('src')) 56 self.add_pad(self._sinkPad) 57 self.add_pad(self._srcPad) 58 59 self._sinkPad.set_event_function(self.eventfunc) 60 61 self._setFramerate(framerate)
62
63 - def _setFramerate(self, framerate):
64 self._framerate = framerate 65 self._capsfilter.set_property('caps', 66 gst.Caps(self.CAPS_TEMPLATE % dict(fr=self.framerateToString())))
67
68 - def do_set_property(self, property, value):
69 if property.name == 'framerate': 70 self._setFramerate(value) 71 else: 72 raise AttributeError('unknown property %s' % property.name)
73
74 - def do_get_property(self, property):
75 if property.name == 'framerate': 76 return self._framerate 77 else: 78 raise AttributeError('unknown property %s' % property.name)
79
80 - def eventfunc(self, pad, event):
81 self.debug("Received event %r from %s" % (event, event.src)) 82 if gstreamer.event_is_flumotion_reset(event): 83 self._videorate.set_state(gst.STATE_READY) 84 self._videorate.set_state(gst.STATE_PLAYING) 85 return self._srcPad.push_event(event)
86
87 - def framerateToString(self):
88 if self._framerate is None: 89 return "" 90 return ",framerate=(fraction)%d/%d" % (self._framerate.num, 91 self._framerate.denom)
92 93
94 -class Videorate(feedcomponent.PostProcEffect):
95 """ 96 I am an effect that can be added to any component that has a videorate 97 component and a way of changing the output framerate. 98 """ 99 logCategory = "videorate-effect" 100
101 - def __init__(self, name, sourcePad, pipeline, framerate):
102 """ 103 @param element: the video source element on which the post 104 processing effect will be added 105 @param sourcePad: source pad used for linking the effect 106 @param pipeline: the pipeline of the element 107 @param framerate: output framerate 108 """ 109 feedcomponent.PostProcEffect.__init__(self, name, sourcePad, 110 VideorateBin(framerate), pipeline)
111
112 - def effect_setFramerate(self, framerate):
113 self.effectBin.set_property("framerate", framerate) 114 return framerate
115
116 - def effect_getFramerate(self):
117 return self.effectBin.get_property('framerate')
118