Trees | Indices | Help |
---|
|
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,2009 Fluendo, S.L. 6 # Copyright (C) 2010,2011 Flumotion Services, S.A. 7 # All rights reserved. 8 # 9 # This file may be distributed and/or modified under the terms of 10 # the GNU Lesser General Public License version 2.1 as published by 11 # the Free Software Foundation. 12 # This file is distributed without any warranty; without even the implied 13 # warranty of merchantability or fitness for a particular purpose. 14 # See "LICENSE.LGPL" in the source distribution for more information. 15 # 16 # Headers in this file shall remain intact. 17 18 from twisted.web.resource import Resource 19 from twisted.web.static import Data 20 21 from flumotion.common import log 22 from flumotion.common.errors import ComponentStartError 23 from flumotion.component.misc.httpserver.httpserver import HTTPFileStreamer 24 from flumotion.component.plugs.base import ComponentPlug 25 26 __version__ = "$Rev$" 27 28 HTML5TEMPLATE = \ 29 """ 30 <html> 31 <head><title>Flumotion Stream</title></head> 32 <body> 33 <video height="%(height)d" width="%(width)d" controls autoplay> 34 <source type='%(mime-type)s; codecs="%(codecs)s"' src="%(stream-url)s"> 35 </source> 36 </video> 37 </body> 38 """ 39 40 45 4648 """I generate the directory used to serve an html5 viewing page 49 It contains:: 50 - a html file, usually called index.html. 51 """ 5285 8654 Resource.__init__(self) 55 56 index_name = properties.get('index', 'index.html') 57 58 root = mount_point 59 if not root.endswith("/"): 60 root += "/" 61 if index_name != 'index.html': 62 root = None 63 self._mount_point_root = root 64 self._properties = properties 65 self._index_content = self._get_index_content() 66 self._index_name = index_name 67 self._addChildren()6870 self.putChild(self._index_name, 71 self._index_content) 72 self.putChild('', self._index_content)7375 ns = {} 76 for attribute in ['codecs', 77 'mime-type', 78 'width', 79 'height', 80 'stream-url']: 81 ns[attribute] = self._properties[attribute] 82 83 content = HTML5TEMPLATE % ns 84 return Data(content, 'text/html')88 """I am a component plug for a http-server which plugs in a 89 http resource containing a html5 viewing page. 90 """ 91105 10693 """ 94 @type component: L{HTTPFileStreamer} 95 """ 96 if not isinstance(component, HTTPFileStreamer): 97 raise ComponentStartError( 98 "An HTML5Plug %s must be plugged into a " 99 " HTTPFileStreamer component, not a %s" % ( 100 self, component.__class__.__name__)) 101 log.debug('html5', 'Attaching to %r' % (component, )) 102 resource = Html5DirectoryResource(component.getMountPoint(), 103 self.args['properties']) 104 component.setRootResource(resource)108 import sys 109 from twisted.internet import reactor 110 from twisted.python.log import startLogging 111 from twisted.web.server import Site 112 startLogging(sys.stderr) 113 114 properties = {'width': 320, 115 'height': 240, 116 'stream-url': '/stream.ogg', 117 'buffer-size': 40} 118 root = Html5DirectoryResource('/', properties) 119 site = Site(root) 120 121 reactor.listenTCP(8080, site) 122 reactor.run()123 124 if __name__ == "__main__": 125 test() 126
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Tue Aug 13 06:17:16 2013 | http://epydoc.sourceforge.net |