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.admin.assistant.interfaces import IProducerPlugin 
 29  from flumotion.admin.assistant.models import AudioProducer, VideoProducer, \ 
 30       AudioEncoder, VideoEncoder, VideoConverter 
 31  from flumotion.common import errors, messages 
 32  from flumotion.common.i18n import N_, gettexter 
 33  from flumotion.admin.gtk.basesteps import AudioProducerStep, VideoProducerStep 
 34   
 35  __pychecker__ = 'no-returnvalues' 
 36  __version__ = "$Rev: 7782 $" 
 37  _ = gettext.gettext 
 38  T_ = gettexter() 
 39   
 40   
41 -class FireWireProducer(AudioProducer, VideoProducer):
42 componentType = 'firewire-producer' 43
44 - def __init__(self):
45 super(FireWireProducer, self).__init__() 46 47 self.properties.is_square = True 48 self.properties.framerate = 12.5
49
50 - def getFeederName(self, component):
51 if isinstance(component, AudioEncoder): 52 return 'audio' 53 elif isinstance(component, (VideoEncoder, VideoConverter)): 54 return 'video' 55 else: 56 raise AssertionError
57 58
59 -class _FireWireCommon:
60 icon = 'firewire.png' 61 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 62 'wizard.glade') 63 componentType = 'firewire' 64 width_corrections = ['none', 'pad', 'stretch'] 65
66 - def __init__(self):
67 # options detected from the device: 68 self._dims = None 69 self._factors = [1, 2, 3, 4, 6, 8] 70 self._input_heights = None 71 self._input_widths = None 72 self._par = None 73 74 # these are instance state variables: 75 self._factor_i = 0 # index into self.factors 76 self._width_correction = None # currently chosen item from
77 # width_corrections 78 79 # WizardStep 80
81 - def workerChanged(self, worker):
82 self.model.worker = worker 83 self._populateDevices()
84 85 # Private 86
87 - def _setSensitive(self, is_sensitive):
88 self.vbox_controls.set_sensitive(is_sensitive) 89 self.wizard.blockNext(not is_sensitive)
90
91 - def _update_output_format(self):
92 self._update_label_camera_settings() 93 94 # factor is a double 95 if self.combobox_scaled_height.get_selected() is not None: 96 self._factor_i = self.combobox_scaled_height.get_selected() 97 98 self._update_width_correction() 99 self._update_label_output_format()
100
102 # update label_camera_settings 103 standard = 'Unknown' 104 aspect = 'Unknown' 105 h = self._dims[1] 106 if h == 576: 107 standard = 'PAL' 108 elif h == 480: 109 standard = 'NTSC' 110 else: 111 self.warning('Unknown capture standard for height %d' % h) 112 113 nom = self._par[0] 114 den = self._par[1] 115 if nom == 59 or nom == 10: 116 aspect = '4:3' 117 elif nom == 118 or nom == 40: 118 aspect = '16:9' 119 else: 120 self.warning('Unknown pixel aspect ratio %d/%d' % (nom, den)) 121 122 text = _('%s, %s (%d/%d pixel aspect ratio)') % (standard, aspect, 123 nom, den) 124 self.label_camera_settings.set_text(text)
125
126 - def _update_width_correction(self):
127 self._width_correction = None 128 for i in type(self).width_corrections: 129 if getattr(self, 'radiobutton_width_' + i).get_active(): 130 self._width_correction = i 131 break 132 assert self._width_correction
133
135 d = self._get_width_height() 136 self.model.properties.width = d['ow'] 137 self.model.properties.height = d['oh'] 138 self.model.properties.scaled_width = d['sw'] 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 and select padding as default. 162 self.frame_width_correction.set_sensitive(sw % 8 != 0) 163 self.radiobutton_width_none.set_active(sw % 8 == 0) 164 self.radiobutton_width_pad.set_active(sw % 8 != 0) 165 166 # actual output 167 ow = sw 168 oh = sh 169 170 if self._width_correction == 'pad': 171 ow = sw + (8 - (sw % 8)) % 8 172 elif self._width_correction == 'stretch': 173 ow = sw + (8 - (sw % 8)) % 8 174 sw = ow 175 176 return dict(sw=sw, sh=sh, ow=ow, oh=oh)
177
178 - def _populateDevices(self):
179 self._setSensitive(False) 180 msg = messages.Info(T_(N_('Checking for Firewire devices...')), 181 mid='firewire-check') 182 self.wizard.add_msg(msg) 183 d = self.runInWorker('flumotion.worker.checks.gst010', 184 'check1394devices', mid='firewire-check') 185 186 def firewireCheckDone(devices): 187 self.wizard.clear_msg('firewire-check') 188 self.guid.prefill(devices)
189 190 def trapRemoteFailure(failure): 191 failure.trap(errors.RemoteRunFailure)
192 193 def trapRemoteError(failure): 194 failure.trap(errors.RemoteRunError) 195 196 d.addCallback(firewireCheckDone) 197 d.addErrback(trapRemoteError) 198 d.addErrback(trapRemoteFailure) 199 200 return d 201
202 - def _runChecks(self):
203 self._setSensitive(False) 204 msg = messages.Info(T_(N_('Checking for Firewire device...')), 205 mid='firewire-check') 206 self.wizard.add_msg(msg) 207 208 d = self.runInWorker('flumotion.worker.checks.gst010', 'check1394', 209 mid='firewire-check', guid=self.guid.get_selected()) 210 211 def firewireCheckDone(options): 212 self.wizard.clear_msg('firewire-check') 213 self._dims = (options['width'], options['height']) 214 self._par = options['par'] 215 self._input_heights = [self._dims[1]/i for i in self._factors] 216 self._input_widths = [self._dims[0]/i for i in self._factors] 217 values = [] 218 for i, height in enumerate(self._input_heights): 219 values.append(('%d pixels' % height, i)) 220 self.combobox_scaled_height.prefill(values) 221 if len(values) > 2: 222 self.combobox_scaled_height.set_active(1) 223 self._setSensitive(True) 224 self._update_output_format()
225 226 def trapRemoteFailure(failure): 227 failure.trap(errors.RemoteRunFailure) 228 229 def trapRemoteError(failure): 230 failure.trap(errors.RemoteRunError) 231 232 d.addCallback(firewireCheckDone) 233 d.addErrback(trapRemoteError) 234 d.addErrback(trapRemoteFailure) 235 return d 236 237 # Callbacks 238
239 - def on_is_square_toggled(self, radio):
240 self._update_output_format()
241
242 - def on_guid_changed(self, combo):
243 self._runChecks()
244
245 - def on_combobox_scaled_height_changed(self, combo):
246 self._update_output_format()
247
248 - def on_radiobutton_width_none_toggled(self, radio):
249 self._update_output_format()
250
251 - def on_radiobutton_width_stretch_toggled(self, radio):
252 self._update_output_format()
253
254 - def on_radiobutton_width_pad_toggled(self, radio):
255 self._update_output_format()
256 257
258 -class FireWireVideoStep(_FireWireCommon, VideoProducerStep):
259 name = 'Firewire' 260 title = _('Firewire Video') 261 docSection = 'help-configuration-assistant-producer-video-firewire' 262 docAnchor = '' 263 docVersion = 'local' 264
265 - def __init__(self, wizard, model):
266 VideoProducerStep.__init__(self, wizard, model) 267 _FireWireCommon.__init__(self)
268
269 - def setup(self):
270 self.guid.data_type = int 271 self.framerate.data_type = float 272 self.add_proxy(self.model.properties, 273 ['guid', 'framerate', 'is_square'])
274 275
276 -class FireWireAudioStep(_FireWireCommon, AudioProducerStep):
277 name = 'Firewire audio' 278 title = _('Firewire Audio') 279 docSection = 'help-configuration-assistant-producer-audio-firewire' 280 docAnchor = '' 281 docVersion = 'local' 282
283 - def __init__(self, wizard, model):
284 AudioProducerStep.__init__(self, wizard, model) 285 _FireWireCommon.__init__(self)
286 287 # WizardStep 288
289 - def setup(self):
290 self.frame_scaling.hide() 291 self.frame_width_correction.hide() 292 self.frame_capture.hide() 293 self.frame_output_format.hide()
294
295 - def getNext(self):
296 return None
297 298
299 -class FireWireWizardPlugin(object):
300 implements(IProducerPlugin) 301
302 - def __init__(self, wizard):
303 self.wizard = wizard
304
305 - def getProductionStep(self, type):
306 if type == 'audio': 307 return FireWireAudioStep(self.wizard, FireWireProducer()) 308 elif type == 'video': 309 return FireWireVideoStep(self.wizard, FireWireProducer())
310