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

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

  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  import gst.interfaces 
 20   
 21  from flumotion.common import log 
 22   
 23  from flumotion.component import feedcomponent 
 24  from flumotion.component.effects.colorbalance import colorbalance 
 25   
 26  # FIXME: rename to TVCard 
 27  __all__ = ['BTTV'] 
 28  __version__ = "$Rev$" 
 29   
 30   
31 -def arg_filtered(proc, *args):
32 33 def ret(*_args): 34 for spec in args: 35 if len(spec) == 3: 36 key = spec[2] 37 else: 38 key = lambda x: x 39 index = spec[0] 40 value = spec[1] 41 if len(_args) <= index or key(_args[index]) != value: 42 return 43 return proc(*_args)
44 return ret 45 46
47 -def call_on_state_change(element, from_state, to_state, proc, *args, **kwargs):
48 49 def bus_watch_func(bus, message): 50 proc(*args, **kwargs)
51 bus_watch_func = arg_filtered(bus_watch_func, 52 (1, element, lambda x: x.src), 53 (1, [from_state, to_state, gst.STATE_VOID_PENDING], 54 lambda x: x.parse_state_changed())) 55 parent = element 56 while parent.get_parent(): 57 parent = parent.get_parent() 58 b = parent.get_bus() 59 b.connect('message::state-changed', bus_watch_func) 60 61
62 -class BTTV(feedcomponent.ParseLaunchComponent):
63
64 - def get_pipeline_string(self, properties):
65 device = properties['device'] 66 width = properties.get('width', 320) 67 height = properties.get('height', 240) 68 69 # This needs to be done properly 70 device_width = width 71 device_height = height 72 #device_width = properties['device-width'] 73 #device_height = properties['device-height'] 74 75 framerate = properties.get('framerate', (25, 1)) 76 framerate_string = '%d/%d' % (framerate[0], framerate[1]) 77 78 pipeline = ('v4lsrc name=source device=%s copy-mode=true ! ' 79 'video/x-raw-yuv,width=%d,height=%d ! videoscale ! ' 80 'video/x-raw-yuv,width=%d,height=%d ! videorate ! ' 81 'video/x-raw-yuv,framerate=%s') % (device, 82 device_width, 83 device_height, 84 width, height, 85 framerate_string) 86 return pipeline
87
88 - def configure_pipeline(self, pipeline, properties):
89 # create and add colorbalance effect 90 source = pipeline.get_by_name('source') 91 hue = properties.get('hue', None) 92 saturation = properties.get('saturation', None) 93 brightness = properties.get('brightness', None) 94 contrast = properties.get('contrast', None) 95 cb = colorbalance.Colorbalance('outputColorbalance', source, 96 hue, saturation, brightness, contrast, pipeline) 97 self.addEffect(cb) 98 99 # register state change notify to set channel and norm 100 element = pipeline.get_by_name('source') 101 channel = properties.get('channel', None) 102 norm = properties.get('signal', None) 103 104 call_on_state_change(element, gst.STATE_READY, gst.STATE_PAUSED, 105 self.set_channel_and_norm, element, channel, norm)
106
107 - def set_channel_and_norm(self, element, channel, norm):
108 self.debug("bttv READY->PAUSED, setting channel %s and norm %s" % ( 109 channel, norm)) 110 if channel: 111 c = element.find_channel_by_name(channel) 112 if c: 113 self.debug("set channel to %s" % channel) 114 element.set_channel(c) 115 if norm: 116 c = element.find_norm_by_name(norm) 117 if c: 118 self.debug("set norm to %s" % norm) 119 element.set_norm(c)
120