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