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 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  import gst 
 23  import gst.interfaces 
 24   
 25  from flumotion.common import log 
 26   
 27  from flumotion.component import feedcomponent 
 28  from flumotion.component.effects.colorbalance import colorbalance 
 29   
 30  # FIXME: rename to TVCard 
 31  __all__ = ['BTTV'] 
 32  __version__ = "$Rev: 6654 $" 
 33   
 34   
35 -def arg_filtered(proc, *args):
36 def ret(*_args): 37 for spec in args: 38 if len(spec) == 3: 39 key = spec[2] 40 else: 41 key = lambda x: x 42 index = spec[0] 43 value = spec[1] 44 if len(_args) <= index or key(_args[index]) != value: 45 return 46 return proc (*_args)
47 return ret 48
49 -def call_on_state_change(element, from_state, to_state, proc, *args, **kwargs):
50 def bus_watch_func(bus, message): 51 proc(*args, **kwargs)
52 bus_watch_func = arg_filtered(bus_watch_func, 53 (1, element, lambda x: x.src), 54 (1, [from_state, to_state, gst.STATE_VOID_PENDING], 55 lambda x: x.parse_state_changed())) 56 parent = element 57 while parent.get_parent(): 58 parent = parent.get_parent() 59 b = parent.get_bus() 60 b.connect('message::state-changed', bus_watch_func) 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