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, log.Loggable):
55
56 - def init(self):
57 self.factory = None 58 self.socketPath = None 59 self.currentTransport = None
60
61 - def do_setup(self):
62 props = self.config['properties'] 63 self.socketPath = props.get('path') 64 feedcomponent.ParseLaunchComponent.do_setup(self)
65
66 - def setUnixTransport(self, transport):
67 self.debug("got transport %r [fd:%d]" % (transport, transport.fileno())) 68 self.currentTransport = transport 69 # we should set that fd on the fdsrc now 70 71 fdsrc = self.pipeline.get_by_name("fdsrc") 72 fdsrc.props.fd = transport.fileno() 73 # create pipeline 74 75 # call self.link() 76 self.link()
77
78 - def get_pipeline_string(self, properties):
79 """ return the pipeline """ 80 return 'fdsrc name=fdsrc ! gdpdepay'
81
82 - def do_stop(self):
83 # FIXME : do I need to implement something here ? 84 return feedcomponent.ParseLaunchComponent.do_stop(self)
85
86 - def do_start(self, clocking):
87 self.factory = UnixDomainDumbFactory(self) 88 if clocking: 89 self.set_master_clock(*clocking) 90 91 # We need to set the pipeline to READY so the multifdsink gets start'ed 92 self.pipeline.set_state(gst.STATE_READY) 93 94 # remove the existing socket 95 if os.path.exists(self.socketPath): 96 os.unlink(self.socketPath) 97 98 self.log("Starting to listen on UNIX : %s" % self.socketPath) 99 reactor.listenUNIX(self.socketPath, self.factory) 100 # we will link once we have a valid FD 101 102 return defer.succeed(None)
103