Package flumotion :: Package component :: Package producers :: Package unixdomain :: Module unixdomain
[hide private]

Source Code for Module flumotion.component.producers.unixdomain.unixdomain

 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 os 
23  import gst 
24   
25  from flumotion.component import feedcomponent 
26  from flumotion.common import log, messages, errors 
27  from twisted.internet.protocol import ServerFactory, Protocol 
28  from twisted.internet import defer, reactor 
29   
30  # Fake Protocol 
31 -class DumbProtocol(Protocol):
32 """ Dumb Protocol, doesn't do anything """ 33
34 - def connectionMade(self):
35 """ Stop reading/writing """ 36 if self.factory.component.currentTransport: 37 38 self.transport.loseConnection() 39 return 40 self.transport.stopReading() 41 self.transport.stopWriting() 42 self.factory.component.setUnixTransport(self.transport)
43 # FIXME : We should maybe lose connection here .... 44 45 # UnixDomainDumbFactory
46 -class UnixDomainDumbFactory(ServerFactory):
47 48 protocol = DumbProtocol 49
50 - def __init__(self, component):
51 self.component = component
52 53 # Component
54 -class UnixDomainProvider(feedcomponent.ParseLaunchComponent):
55
56 - def init(self):
57 self.factory = None 58 self.socketPath = None 59 self.currentTransport = None
60
61 - def setUnixTransport(self, transport):
62 self.debug("got transport %r [fd:%d]" % (transport, transport.fileno())) 63 self.currentTransport = transport 64 # we should set that fd on the fdsrc now 65 66 fdsrc = self.pipeline.get_by_name("fdsrc") 67 fdsrc.props.fd = transport.fileno() 68 # create pipeline 69 70 # call self.link() 71 self.link()
72
73 - def get_pipeline_string(self, properties):
74 """ return the pipeline """ 75 return 'fdsrc name=fdsrc ! gdpdepay'
76
77 - def do_setup(self):
78 props = self.config['properties'] 79 self.socketPath = props.get('path') 80 self.factory = UnixDomainDumbFactory(self) 81 82 # We need to set the pipeline to READY so the multifdsink gets start'ed 83 self.pipeline.set_state(gst.STATE_READY) 84 85 # remove the existing socket 86 if os.path.exists(self.socketPath): 87 os.unlink(self.socketPath) 88 89 self.log("Starting to listen on UNIX : %s" % self.socketPath) 90 reactor.listenUNIX(self.socketPath, self.factory)
91 # we will link once we have a valid FD 92