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