Package flumotion :: Package component :: Package producers :: Package videotest :: Module videotest
[hide private]

Source Code for Module flumotion.component.producers.videotest.videotest

  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 gst 
 19   
 20  from flumotion.common import errors, gstreamer, messages 
 21  from flumotion.common.i18n import N_, gettexter 
 22  from flumotion.component import feedcomponent 
 23   
 24  __version__ = "$Rev$" 
 25  T_ = gettexter() 
 26   
 27   
28 -class VideoTestMedium(feedcomponent.FeedComponentMedium):
29
30 - def remote_setPattern(self, pattern):
31 return self.comp.set_element_property('source', 'pattern', 32 pattern)
33 34
35 -class VideoTest(feedcomponent.ParseLaunchComponent):
36 componentMediumClass = VideoTestMedium 37
38 - def init(self):
39 self.uiState.addKey('pattern', 0)
40
41 - def get_pipeline_string(self, properties):
42 capsString = properties.get('format', 'video/x-raw-yuv') 43 44 if capsString == 'video/x-raw-yuv': 45 capsString = '%s,format=(fourcc)I420' % capsString 46 47 # Filtered caps 48 struct = gst.structure_from_string(capsString) 49 for k in 'width', 'height': 50 if k in properties: 51 struct[k] = properties[k] 52 53 if 'framerate' in properties: 54 framerate = properties['framerate'] 55 struct['framerate'] = gst.Fraction(framerate[0], framerate[1]) 56 57 # always set par 58 struct['pixel-aspect-ratio']= gst.Fraction(1, 1) 59 if 'pixel-aspect-ratio' in properties: 60 par = properties['pixel-aspect-ratio'] 61 struct['pixel-aspect-ratio'] = gst.Fraction(par[0], par[1]) 62 63 # If RGB, set something ffmpegcolorspace can convert. 64 if capsString == 'video/x-raw-rgb': 65 struct['red_mask'] = 0xff00 66 caps = gst.Caps(struct) 67 68 is_live = 'is-live=true' 69 70 overlay = "" 71 overlayTimestamps = properties.get('overlay-timestamps', False) 72 if overlayTimestamps: 73 overlay = " timeoverlay ! " 74 75 return "videotestsrc %s name=source ! " % is_live + overlay + \ 76 "identity name=identity silent=TRUE ! %s" % caps
77 78 # Set properties 79
80 - def configure_pipeline(self, pipeline, properties):
81 82 def notify_pattern(obj, pspec): 83 self.uiState.set('pattern', int(obj.get_property('pattern')))
84 85 source = self.get_element('source') 86 source.connect('notify::pattern', notify_pattern) 87 if 'pattern' in properties: 88 source.set_property('pattern', properties['pattern']) 89 90 if 'drop-probability' in properties: 91 vt = gstreamer.get_plugin_version('coreelements') 92 if not vt: 93 raise errors.MissingElementError('identity') 94 if not vt > (0, 10, 12, 0): 95 self.addMessage( 96 messages.Warning(T_(N_( 97 "The 'drop-probability' property is specified, but " 98 "it only works with GStreamer core newer than 0.10.12." 99 " You should update your version of GStreamer.")))) 100 else: 101 drop_probability = properties['drop-probability'] 102 if drop_probability < 0.0 or drop_probability > 1.0: 103 self.addMessage( 104 messages.Warning(T_(N_( 105 "The 'drop-probability' property can only be " 106 "between 0.0 and 1.0.")))) 107 else: 108 identity = self.get_element('identity') 109 identity.set_property('drop-probability', 110 drop_probability)
111