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