Package flumotion :: Package component :: Package producers :: Package firewire :: Module wizard_gtk
[hide private]

Source Code for Module flumotion.component.producers.firewire.wizard_gtk

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2008 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 gettext 
 23  import os 
 24  import math 
 25   
 26  from zope.interface import implements 
 27   
 28  from flumotion.common import errors, messages 
 29  from flumotion.common.i18n import N_, gettexter 
 30  from flumotion.wizard.basesteps import AudioProducerStep, VideoProducerStep 
 31  from flumotion.wizard.interfaces import IProducerPlugin 
 32  from flumotion.wizard.models import AudioProducer, VideoProducer, \ 
 33       AudioEncoder, VideoEncoder, VideoConverter 
 34   
 35  __pychecker__ = 'no-returnvalues' 
 36  __version__ = "$Rev: 7097 $" 
 37  _ = gettext.gettext 
 38  T_ = gettexter() 
 39   
 40   
41 -class FireWireProducer(AudioProducer, VideoProducer):
42 componentType = 'firewire-producer'
43 - def __init__(self):
44 super(FireWireProducer, self).__init__() 45 46 self.properties.is_square = False
47
48 - def getFeederName(self, component):
49 if isinstance(component, AudioEncoder): 50 return 'audio' 51 elif isinstance(component, (VideoEncoder, VideoConverter)): 52 return 'video' 53 else: 54 raise AssertionError
55 56
57 -class _FireWireCommon:
58 icon = 'firewire.png' 59 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 60 'wizard.glade') 61 componentType = 'firewire' 62 width_corrections = ['none', 'pad', 'stretch'] 63
64 - def __init__(self):
65 # options detected from the device: 66 self._dims = None 67 self._factors = [1, 2, 3, 4, 6, 8] 68 self._input_heights = None 69 self._input_widths = None 70 self._par = None 71 72 # these are instance state variables: 73 self._factor_i = None # index into self.factors 74 self._width_correction = None # currently chosen item from
75 # width_corrections 76 77 # WizardStep 78
79 - def workerChanged(self, worker):
80 self.model.worker = worker 81 self._run_checks()
82 83 # Private 84
85 - def _setSensitive(self, is_sensitive):
86 self.vbox_controls.set_sensitive(is_sensitive) 87 self.wizard.blockNext(not is_sensitive)
88
89 - def _update_output_format(self):
90 self._update_label_camera_settings() 91 92 # factor is a double 93 self._factor_i = self.combobox_scaled_height.get_selected() 94 95 self._update_width_correction() 96 self._update_label_output_format()
97
99 # update label_camera_settings 100 standard = 'Unknown' 101 aspect = 'Unknown' 102 h = self._dims[1] 103 if h == 576: 104 standard = 'PAL' 105 elif h == 480: 106 standard = 'NTSC' 107 else: 108 self.warning('Unknown capture standard for height %d' % h) 109 110 nom = self._par[0] 111 den = self._par[1] 112 if nom == 59 or nom == 10: 113 aspect = '4:3' 114 elif nom == 118 or nom == 40: 115 aspect = '16:9' 116 else: 117 self.warning('Unknown pixel aspect ratio %d/%d' % (nom, den)) 118 119 text = _('%s, %s (%d/%d pixel aspect ratio)') % (standard, aspect, 120 nom, den) 121 self.label_camera_settings.set_text(text)
122
123 - def _update_width_correction(self):
124 self._width_correction = None 125 for i in type(self).width_corrections: 126 if getattr(self,'radiobutton_width_'+i).get_active(): 127 self._width_correction = i 128 break 129 assert self._width_correction
130
132 d = self._get_width_height() 133 self.model.properties.is_square = ( 134 self.checkbutton_square_pixels.get_active()) 135 self.model.properties.width = d['ow'] 136 self.model.properties.height = d['oh'] 137 self.model.properties.scaled_width = d['sw'] 138 self.model.properties.framerate = self.spinbutton_framerate.get_value() 139 num, den = 1, 1 140 if not self.model.properties.is_square: 141 num, den = self._par[0], self._par[1] 142 143 msg = _('%dx%d, %d/%d pixel aspect ratio') % ( 144 d['ow'], d['oh'], num, den) 145 self.label_output_format.set_markup(msg)
146
147 - def _get_width_height(self):
148 # returns dict with sw, sh, ow, oh 149 # which are scaled width and height, and output width and height 150 sh = self._input_heights[self._factor_i] 151 sw = self._input_widths[self._factor_i] 152 par = 1. * self._par[0] / self._par[1] 153 154 if self.model.properties.is_square: 155 sw = int(math.ceil(sw * par)) 156 # for GStreamer element sanity, make sw an even number 157 # FIXME: check if this can now be removed 158 # sw = sw + (2 - (sw % 2)) % 2 159 160 # if scaled width (after squaring) is not multiple of 8, present 161 # width correction 162 self.frame_width_correction.set_sensitive(sw % 8 != 0) 163 164 # actual output 165 ow = sw 166 oh = sh 167 if self._width_correction == 'pad': 168 ow = sw + (8 - (sw % 8)) % 8 169 elif self._width_correction == 'stretch': 170 ow = sw + (8 - (sw % 8)) % 8 171 sw = ow 172 173 return dict(sw=sw,sh=sh,ow=ow,oh=oh)
174
175 - def _run_checks(self):
176 self._setSensitive(False) 177 msg = messages.Info(T_(N_('Checking for Firewire device...')), 178 mid='firewire-check') 179 self.wizard.add_msg(msg) 180 d = self.runInWorker('flumotion.worker.checks.gst010', 'check1394', 181 mid='firewire-check') 182 183 def firewireCheckDone(options): 184 self.wizard.clear_msg('firewire-check') 185 self._dims = (options['width'], options['height']) 186 self._par = options['par'] 187 self._input_heights = [self._dims[1]/i for i in self._factors] 188 self._input_widths = [self._dims[0]/i for i in self._factors] 189 values = [] 190 for i, height in enumerate(self._input_heights): 191 values.append(('%d pixels' % height, i)) 192 self.combobox_scaled_height.prefill(values) 193 self._setSensitive(True) 194 self._update_output_format()
195 196 def trapRemoteFailure(failure): 197 failure.trap(errors.RemoteRunFailure)
198 199 def trapRemoteError(failure): 200 failure.trap(errors.RemoteRunError) 201 d.addCallback(firewireCheckDone) 202 d.addErrback(trapRemoteError) 203 d.addErrback(trapRemoteFailure) 204 return d 205 206 # Callbacks 207
208 - def on_checkbutton_square_pixels_toggled(self, radio):
209 self._update_output_format()
210
211 - def on_combobox_scaled_height_changed(self, combo):
212 self._update_output_format()
213
214 - def on_radiobutton_width_none_toggled(self, radio):
215 self._update_output_format()
216
217 - def on_radiobutton_width_stretch_toggled(self, radio):
218 self._update_output_format()
219
220 - def on_radiobutton_width_pad_toggled(self, radio):
221 self._update_output_format()
222 223
224 -class FireWireVideoStep(_FireWireCommon, VideoProducerStep):
225 name = 'Firewire' 226 title = _('Firewire')
227 - def __init__(self, wizard, model):
230 231
232 -class FireWireAudioStep(_FireWireCommon, AudioProducerStep):
233 name = 'Firewire audio' 234 title = _('Firewire audio') 235
236 - def __init__(self, wizard, model):
239 240 # WizardStep 241
242 - def setup(self):
243 self.frame_scaling.hide() 244 self.frame_width_correction.hide() 245 self.frame_capture.hide() 246 self.frame_output_format.hide()
247
248 - def getNext(self):
249 return None
250 251
252 -class FireWireWizardPlugin(object):
253 implements(IProducerPlugin)
254 - def __init__(self, wizard):
255 self.wizard = wizard
256
257 - def getProductionStep(self, type):
258 if type == 'audio': 259 # Only show firewire audio if we're using firewire video 260 source_step = self.wizard.getStep('Production') 261 if source_step.video.get_active() == 'firewire-producer': 262 return 263 return FireWireAudioStep(self.wizard, FireWireProducer()) 264 elif type == 'video': 265 return FireWireVideoStep(self.wizard, FireWireProducer())
266