Package flumotion :: Package component :: Package plugs :: Package cortado :: Module wizard_gtk
[hide private]

Source Code for Module flumotion.component.plugs.cortado.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) 2004,2005,2006,2007,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  """Wizard plugin for the cortado http plug 
 23  """ 
 24   
 25  from zope.interface import implements 
 26   
 27  from flumotion.common.fraction import fractionAsFloat, fractionFromValue 
 28  from flumotion.wizard.interfaces import IHTTPConsumerPlugin 
 29  from flumotion.wizard.models import HTTPServer, HTTPPlug 
 30   
 31  __version__ = "$Rev: 6780 $" 
 32   
 33  # Copied from posixpath.py 
34 -def slashjoin(a, *p):
35 """Join two or more pathname components, inserting '/' as needed""" 36 path = a 37 for b in p: 38 if b.startswith('/'): 39 path = b 40 elif path == '' or path.endswith('/'): 41 path += b 42 else: 43 path += '/' + b 44 return path
45 46
47 -class CortadoHTTPPlug(HTTPPlug):
48 """I am a model representing the configuration file for a 49 Cortado HTTP streaming plug. 50 """ 51 plugType = "cortado-plug" 52 53 # Component 54
55 - def getProperties(self):
56 p = super(CortadoHTTPPlug, self).getProperties() 57 58 p.codebase = self.server.getCodebase() 59 p.stream_url = self.streamer.getURL() 60 p.has_video = self.videoProducer is not None 61 p.has_audio = self.audioProducer is not None 62 63 width = 320 64 height = 240 65 framerate = 1 66 if self.videoProducer: 67 width = self.videoProducer.properties.width 68 height = self.videoProducer.properties.height 69 framerate = self.videoProducer.properties.framerate 70 # FIXME: Why do we get floats and strings randomly? 71 if type(framerate) == str and '/' in framerate: 72 nom, denom = framerate.split('/') 73 framerate = int(float(nom)/float(denom)) 74 75 p.width = width 76 p.height = height 77 p.framerate = fractionAsFloat(fractionFromValue(framerate)) 78 p.buffer_size = 40 79 80 return p
81 82
83 -class CortadoHTTPServer(HTTPServer):
84 """I am a model representing the configuration file for a 85 HTTP server component which will be used to serve a cortado 86 java applet. 87 Most of the interesting logic here is actually in a plug. 88 """ 89 componentType = 'http-server'
90 - def __init__(self, streamer, audioProducer, videoProducer, mountPoint):
91 """ 92 @param streamer: streamer 93 @type streamer: L{HTTPStreamer} 94 @param audioProducer: audio producer 95 @type audioProducer: L{flumotion.wizard.models.AudioProducer} 96 subclass or None 97 @param videoProducer: video producer 98 @type videoProducer: L{flumotion.wizard.models.VideoProducer} 99 subclass or None 100 @param mountPoint: 101 @type mountPoint: 102 """ 103 self.streamer = streamer 104 105 super(CortadoHTTPServer, self).__init__(mountPoint=mountPoint, 106 worker=streamer.worker) 107 108 porter = streamer.getPorter() 109 self.properties.porter_socket_path = porter.getSocketPath() 110 self.properties.porter_username = porter.getUsername() 111 self.properties.porter_password = porter.getPassword() 112 self.properties.port = porter.getPort() 113 self.properties.type = 'slave' 114 115 plug = CortadoHTTPPlug(self, streamer, audioProducer, videoProducer) 116 self.addPlug(plug)
117
118 - def getCodebase(self):
119 """Returns the base of directory of the applet 120 @returns: directory 121 """ 122 return 'http://%s:%d%s' % (self.streamer.hostname, 123 self.properties.port, 124 self.properties.mount_point)
125 126
127 -class CortadoWizardPlugin(object):
128 implements(IHTTPConsumerPlugin)
129 - def __init__(self, wizard):
130 self.wizard = wizard
131
132 - def workerChanged(self, worker):
133 d = self.wizard.runInWorker( 134 worker, 135 'flumotion.worker.checks.cortado', 'checkCortado') 136 def check(found): 137 return bool(found)
138 d.addCallback(check) 139 return d
140
141 - def getConsumer(self, streamer, audioProducer, videoProducer):
142 mountPoint = slashjoin(streamer.properties.mount_point, 143 "cortado/") 144 return CortadoHTTPServer(streamer, audioProducer, 145 videoProducer, 146 mountPoint)
147