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