Package flumotion :: Package component :: Package common :: Package avproducer :: Module avproducer
[hide private]

Source Code for Module flumotion.component.common.avproducer.avproducer

  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  from twisted.internet import defer 
 20   
 21  from flumotion.common import errors, messages 
 22  from flumotion.common.i18n import N_, gettexter 
 23  from flumotion.component import feedcomponent 
 24  from flumotion.component.effects.deinterlace import deinterlace 
 25  from flumotion.component.effects.videorate import videorate 
 26  from flumotion.component.effects.videoscale import videoscale 
 27  from flumotion.component.effects.audioconvert import audioconvert 
 28  from flumotion.component.effects.kuscheduler import kuscheduler 
 29  from flumotion.component.effects.volume import volume 
 30   
 31  __version__ = "$Rev$" 
 32  T_ = gettexter() 
 33   
 34   
35 -class AVProducerBase(feedcomponent.ParseLaunchComponent):
36
37 - def get_raw_video_element(self):
38 raise NotImplementedError("Subclasses must implement " 39 "'get_raw_video_element'")
40
41 - def get_pipeline_template(self, props):
42 raise NotImplementedError("Subclasses must implement " 43 "'get_pipeline_template'")
44
45 - def do_check(self):
46 self.debug('running PyGTK/PyGST and configuration checks') 47 from flumotion.component.producers import checks 48 d1 = checks.checkTicket347() 49 d2 = checks.checkTicket348() 50 l = self._do_extra_checks() 51 l.extend([d1, d2]) 52 dl = defer.DeferredList(l) 53 dl.addCallback(self._checkCallback) 54 return dl
55
56 - def check_properties(self, props, addMessage):
57 deintMode = props.get('deinterlace-mode', 'auto') 58 deintMethod = props.get('deinterlace-method', 'ffmpeg') 59 60 if deintMode not in deinterlace.DEINTERLACE_MODE: 61 msg = messages.Error(T_(N_("Configuration error: '%s' " \ 62 "is not a valid deinterlace mode." % deintMode))) 63 addMessage(msg) 64 raise errors.ConfigError(msg) 65 66 if deintMethod not in deinterlace.DEINTERLACE_METHOD: 67 msg = messages.Error(T_(N_("Configuration error: '%s' " \ 68 "is not a valid deinterlace method." % deintMethod))) 69 self.debug("'%s' is not a valid deinterlace method", 70 deintMethod) 71 addMessage(msg) 72 raise errors.ConfigError(msg)
73
74 - def get_pipeline_string(self, props):
75 self.is_square = props.get('is-square', False) 76 self.width = props.get('width', None) 77 self.height = props.get('height', None) 78 self.add_borders = props.get('add-borders', True) 79 self.deintMode = props.get('deinterlace-mode', 'auto') 80 self.deintMethod = props.get('deinterlace-method', 'ffmpeg') 81 self.kuinterval = props.get('keyunits-interval', 0) * gst.MSECOND 82 self.volume_level = props.get('volume', 1) 83 fr = props.get('framerate', None) 84 self.framerate = fr and gst.Fraction(fr[0], fr[1]) or None 85 self._parse_aditional_properties(props) 86 return self.get_pipeline_template(props)
87
88 - def configure_pipeline(self, pipeline, properties):
89 if self.get_raw_video_element() is not None: 90 self._add_video_effects(pipeline) 91 self._add_audio_effects(pipeline)
92
93 - def getVolume(self):
94 return self.volume.get_property('volume')
95
96 - def setVolume(self, value):
97 """ 98 @param value: float between 0.0 and 4.0 99 """ 100 self.debug("Setting volume to %f" % (value)) 101 self.volume.set_property('volume', value)
102
103 - def _checkCallback(self, results):
104 for (state, result) in results: 105 for m in result.messages: 106 self.addMessage(m)
107
108 - def _do_extra_checks(self):
109 ''' 110 Subclasses should override this method to perform aditional checks 111 112 @returns: A list of checks' defers 113 @rtype: list 114 ''' 115 return []
116
117 - def _parse_aditional_properties(self, props):
118 ''' 119 Subclasses should overrride this method to parse aditional properties 120 ''' 121 pass
122
123 - def _add_video_effects(self, pipeline):
124 # Add deinterlacer 125 deinterlacer = deinterlace.Deinterlace('deinterlace', 126 self.get_raw_video_element().get_pad("src"), pipeline, 127 self.deintMode, self.deintMethod) 128 self.addEffect(deinterlacer) 129 deinterlacer.plug() 130 131 # Add video rate converter 132 rateconverter = videorate.Videorate('videorate', 133 deinterlacer.effectBin.get_pad("src"), pipeline, 134 self.framerate) 135 self.addEffect(rateconverter) 136 rateconverter.plug() 137 138 # Add video scaler 139 videoscaler = videoscale.Videoscale('videoscale', self, 140 rateconverter.effectBin.get_pad("src"), pipeline, 141 self.width, self.height, self.is_square, self.add_borders) 142 self.addEffect(videoscaler) 143 videoscaler.plug() 144 145 # Add key units scheduler 146 scheduler = kuscheduler.KeyUnitsScheduler('video-kuscheduler', 147 videoscaler.effectBin.get_pad("src"), pipeline, self.kuinterval) 148 self.addEffect(scheduler) 149 scheduler.plug()
150
151 - def _add_audio_effects(self, pipeline):
152 # Add volume setter 153 self.volume = pipeline.get_by_name("setvolume") 154 comp_level = pipeline.get_by_name('volumelevel') 155 vol = volume.Volume('inputVolume', comp_level, pipeline) 156 self.addEffect(vol) 157 self.setVolume(self.volume_level) 158 159 # Add audio converter 160 audioconverter = audioconvert.Audioconvert('audioconvert', 161 comp_level.get_pad("src"), pipeline, tolerance=40 * gst.MSECOND) 162 self.addEffect(audioconverter) 163 audioconverter.plug() 164 165 # Add key units scheduler 166 scheduler = kuscheduler.KeyUnitsScheduler('audio-kuscheduler', 167 audioconverter.effectBin.get_pad("src"), pipeline, self.kuinterval) 168 self.addEffect(scheduler) 169 scheduler.plug()
170