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