Esempio n. 1
0
 def main(self):
     theCat = coordinatingassistanttracker.getcat()
     service, inboxname = theCat.retrieveService(self.service)
     self.link((self, "todb"), (service, inboxname))
     # send self and my inbox name to the cursor server
     self.send((self, "inbox"), "todb")
     while 1:
         self.pause()
         yield 1
         while self.dataReady("control"):
             msg = self.recv("control")
             if isinstance(msg, shutdownMicroprocess):
                 self.send(msg, "signal")
                 return
             else:
                 self.send(msg, "signal")
         if self.dataReady("inbox"):
             conn = self.recv()
             if isinstance(conn, self.cursortype):
                 self.send(conn)
             else:
                 raise ValueError("Expected %s, got %s" %
                                  (self.cursortype, conn))
             self.send(producerFinished(), "signal")
             self.unlink()
             return
Esempio n. 2
0
 def main(self):
     cat = CAT.getcat()
     service = cat.retrieveService(self.servicename)
     self.link((self,"outbox"),service)
     
     nextchangetime = self.scheduler.time + random.randrange(5,10)
     self.notyetreceived = self.subscribed[:]
     while 1:
         while self.dataReady("inbox"):
             packet = self.recv("inbox")
             pid = ((ord(packet[1]) << 8) + ord(packet[2])) & 0x1fff
             if pid not in self.subscribed:
                 print self.spacing,"Shouldn't have received pid:",pid
             else:
                 if pid in self.notyetreceived:
                     print self.spacing,"Received 1st of pid:",pid
                     self.notyetreceived.remove(pid)
                 
         if self.scheduler.time >= nextchangetime:
             nextchangetime = self.scheduler.time + random.randrange(10,20)
             self.changeSubscription()
             self.notyetreceived = self.subscribed[:]
         
         if self.subscribed:
             self.pause()
         yield 1
Esempio n. 3
0
 def main(self):
     cat = CAT.getcat()
     service = cat.retrieveService("Backplane_I_" + self.destination)
     self.link((self, "inbox"), service, passthrough=1)
     while 1:
         self.pause()
         yield 1
Esempio n. 4
0
        def main(self):
            cat = CAT.getcat()
            service = cat.retrieveService(self.servicename)
            self.link((self, "outbox"), service)

            nextchangetime = self.scheduler.time + random.randrange(5, 10)
            self.notyetreceived = self.subscribed[:]
            while 1:
                while self.dataReady("inbox"):
                    packet = self.recv("inbox")
                    pid = ((ord(packet[1]) << 8) + ord(packet[2])) & 0x1fff
                    if pid not in self.subscribed:
                        print(self.spacing, "Shouldn't have received pid:",
                              pid)
                    else:
                        if pid in self.notyetreceived:
                            print(self.spacing, "Received 1st of pid:", pid)
                            self.notyetreceived.remove(pid)

                if self.scheduler.time >= nextchangetime:
                    nextchangetime = self.scheduler.time + random.randrange(
                        10, 20)
                    self.changeSubscription()
                    self.notyetreceived = self.subscribed[:]

                if self.subscribed:
                    self.pause()
                yield 1
Esempio n. 5
0
    def main(self):
        """Main loop."""
        cat = CAT.getcat()
        service = cat.retrieveService("Backplane_I_"+self.destination)
        if not self.forwarder:
            self.link((self,"inbox"), service, passthrough=1)
        else:
            self.link((self,"_outbox"), service)
        # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
        # FIXME: then this while loop here would be irrelevent, which would be cool.
        # FIXME: especially if we could exec in such a way that passthrough linkages
        # FIXME: still operated as you'd expect.
        shutdown=False
        while not shutdown:
            while self.dataReady("control"):
                msg=self.recv("control")
                self.send(msg,"signal")
                if isinstance(msg, (producerFinished,shutdownMicroprocess)):
                    shutdown=True
            if self.forwarder:
                for msg in self.Inbox("inbox"):
                    self.send(msg, "outbox")
                    self.send(msg, "_outbox")

            if not shutdown:
                self.pause()
                yield 1            
Esempio n. 6
0
    def __init__(self, name):
        super(Backplane, self).__init__()
        assert name == str(name)
        self.name = name
        self.splitter = Splitter()

        splitter = self.splitter
        cat = CAT.getcat()
        try:
            cat.registerService("Backplane_I_" + self.name, splitter, "inbox")
            cat.registerService("Backplane_O_" + self.name, splitter,
                                "configuration")
        except Axon.AxonExceptions.ServiceAlreadyExists:
            e = sys.exc_info()[1]
            print(
                "***************************** ERROR *****************************"
            )
            print(
                "An attempt to make a second backplane with the same name happened."
            )
            print("This is incorrect usage.")
            print("")
            traceback.print_exc(3)
            print(
                "***************************** ERROR *****************************"
            )

            raise e
Esempio n. 7
0
 def main(self):
     cat = CAT.getcat()
     service = cat.retrieveService("Backplane_I_"+self.destination)
     self.link((self,"inbox"), service, passthrough=1)
     while 1:
         self.pause()
         yield 1            
Esempio n. 8
0
    def main(self):
        """Main loop."""
        cat = CAT.getcat()
        service = cat.retrieveService("Backplane_I_" + self.destination)
        if not self.forwarder:
            self.link((self, "inbox"), service, passthrough=1)
        else:
            self.link((self, "_outbox"), service)
        # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
        # FIXME: then this while loop here would be irrelevent, which would be cool.
        # FIXME: especially if we could exec in such a way that passthrough linkages
        # FIXME: still operated as you'd expect.
        shutdown = False
        while not shutdown:
            while self.dataReady("control"):
                msg = self.recv("control")
                self.send(msg, "signal")
                if isinstance(msg, (producerFinished, shutdownMicroprocess)):
                    shutdown = True
            if self.forwarder:
                for msg in self.Inbox("inbox"):
                    self.send(msg, "outbox")
                    self.send(msg, "_outbox")

            if not shutdown:
                self.pause()
                yield 1
Esempio n. 9
0
 def main(self):
     cat = CAT.getcat()
     splitter, configbox = cat.retrieveService("Backplane_O_" + self.source)
     Plug(splitter, self).activate()
     while 1:
         while self.dataReady("inbox"):
             d = self.recv("inbox")
             self.send(d, "outbox")
         yield 1
Esempio n. 10
0
 def main(self):
     cat = CAT.getcat()
     splitter,configbox = cat.retrieveService("Backplane_O_"+self.source)
     Plug(splitter, self).activate()
     while 1:
         while self.dataReady("inbox"):
             d = self.recv("inbox")
             self.send(d, "outbox")
         yield 1            
Esempio n. 11
0
 def releasecursor(self):
     theCat = coordinatingassistanttracker.getcat()
     service, inboxname = theCat.retrieveService(self.service)
     self.unlinkcursor()
     self.link((self, "todb"), (service, inboxname))
     self.send(self.cursor, "todb")
     self.unlink(service)
     self.cursor = None
     self.cursorFinished = False
Esempio n. 12
0
 def main(self):
     cat = CAT.getcat()
     service = cat.retrieveService(self.serviceName)
     
     linkage = self.link( (self, "inbox"), service, passthrough=1 )
     
     shutdown=False
     while not shutdown:
         shutdown = self.shutdown()
         self.pause()
         yield 1
Esempio n. 13
0
    def setTimerServices(timer, tracker = None):
        """\
        Sets the given timer as the service for the selected tracker or the
        default one.

        (static method)
        """
        if not tracker:
            tracker = CAT.getcat()
        tracker.registerService("TimerRegister", timer, "register")
        tracker.registerService("TimerRequest", timer, "inbox")
Esempio n. 14
0
    def main(self):
        cat = CAT.getcat()
        service = cat.retrieveService(self.serviceName)

        linkage = self.link((self, "inbox"), service, passthrough=1)

        shutdown = False
        while not shutdown:
            shutdown = self.shutdown()
            self.pause()
            yield 1
Esempio n. 15
0
 def initialiseComponent(self):
     self.cat = coordinatingassistanttracker.getcat()
     self.isactivereceiver = False
     try:
         self.cat.registerService("streamingtextreceiver", self, "inbox")
     except ServiceAlreadyExists: # There is already a connected client sending data.
         self.send(socketShutdown(),"signal")
         return 0
     self.isactivereceiver = True
     # Find the splitter and passthrough link to it.
     self.splitter, self.splitterbox = self.cat.retrieveService("thesink")
     self.link((self, "inbox"),(self.splitter, self.splitterbox), passthrough=1)
Esempio n. 16
0
    def main(self):
        cat = CAT.getcat()
        theservice_D = cat.retrieveService("SS_D_" + self.Name)
        theservice_C = cat.retrieveService("SS_C_" + self.Name)
        self.link((self, "outbox"), theservice_D)
        self.link((self, "signal"), theservice_C)
        while 1:
            for data in self.inboxcontents("inbox"):
                self.send(data,"outbox")

            for data in self.inboxcontents("control"):
                self.send(data, "signal")

            yield self.pauseSafely()
Esempio n. 17
0
def RegisterService(component, services):
    cat = CAT.getcat()
    for (name, boxname) in services.items():
        
        try:
            cat.registerService(name, component, boxname)
        except ServiceAlreadyExists, e:
            print "***************************** ERROR *****************************"
            print "An attempt to reuse service names happened."
            print "This is incorrect usage."
            print 
            traceback.print_exc(3)
            print "***************************** ERROR *****************************"

            raise e
Esempio n. 18
0
def RegisterService(component, services):
    cat = CAT.getcat()
    for (name, boxname) in services.items():
        
        try:
            cat.registerService(name, component, boxname)
        except ServiceAlreadyExists, e:
            print "***************************** ERROR *****************************"
            print "An attempt to reuse service names happened."
            print "This is incorrect usage."
            print 
            traceback.print_exc(3)
            print "***************************** ERROR *****************************"

            raise e
Esempio n. 19
0
    def main(self):
        splitter = self.splitter
        cat = CAT.getcat()
        try:
            cat.registerService("Backplane_I_" + self.name, splitter, "inbox")
            cat.registerService("Backplane_O_" + self.name, splitter,
                                "configuration")
        except Axon.AxonExceptions.ServiceAlreadyExists, e:
            print "***************************** ERROR *****************************"
            print "An attempt to make a second backplane with the same name happened."
            print "This is incorrect usage."
            print
            traceback.print_exc(3)
            print "***************************** ERROR *****************************"

            raise e
Esempio n. 20
0
    def main(self):
        splitter = self.splitter
        cat = CAT.getcat()
        try:
            cat.registerService("Backplane_I_"+self.name, splitter, "inbox")
            cat.registerService("Backplane_O_"+self.name, splitter, "configuration")
        except Axon.AxonExceptions.ServiceAlreadyExists, e:
            print "***************************** ERROR *****************************"
            print "An attempt to make a second backplane with the same name happened."
            print "This is incorrect usage."
            print 
            traceback.print_exc(3)
            print "***************************** ERROR *****************************"


            raise e
Esempio n. 21
0
 def main(self):
     """Main loop."""
     self.link((self,"control"),(self.splitter,"control"), passthrough=1)
     self.link((self.splitter,"signal"),(self,"signal"), passthrough=2)
     
     yield newComponent(self.splitter)
     self.addChildren(self.splitter)
     self.splitter = None
     # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
     # FIXME: then this while loop here would be irrelevent, which would be cool.
     while not self.childrenDone():
         self.pause()
         yield 1
         
     cat = CAT.getcat()
     cat.deRegisterService("Backplane_I_"+self.name)
     cat.deRegisterService("Backplane_O_"+self.name)
Esempio n. 22
0
    def main(self):
        """Main loop."""
        self.link((self, "control"), (self.splitter, "control"), passthrough=1)
        self.link((self.splitter, "signal"), (self, "signal"), passthrough=2)

        yield newComponent(self.splitter)
        self.addChildren(self.splitter)
        self.splitter = None
        # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
        # FIXME: then this while loop here would be irrelevent, which would be cool.
        while not self.childrenDone():
            self.pause()
            yield 1

        cat = CAT.getcat()
        cat.deRegisterService("Backplane_I_" + self.name)
        cat.deRegisterService("Backplane_O_" + self.name)
Esempio n. 23
0
 def initialiseComponent(self):
     """Finds the splitter and connects to it and passes the data through the
     SubtitleFilterComponent to produce the right output which is passed out
     of the outbox to be sent to the client.
     
     Note:  The Filtering should be moved to the input so that it only has to
     be done once.""" 
     cat = coordinatingassistanttracker.getcat()
     # Find the splitter.
     self.splitter,self.splitterbox = cat.retrieveService("thesource")
     self.link((self, "splittercontrol"),(self.splitter,self.splitterbox))
     # Why is the filter here?  It should be in the receiver so that it only
     # gets done only once instead of once/client.  DOHHH!
     self.filter = SubtitleFilterComponent()
     self.link((self.filter, "outbox"), (self, "outbox"),passthrough = 2)
     self.send(Kamaelia.Util.Splitter.addsink(self.filter, "inbox"),"splittercontrol")
     return newComponent(self.filter)
Esempio n. 24
0
def RegisterService(component, services):
    cat = CAT.getcat()
    for (name, boxname) in services.items():
        
        try:
            cat.registerService(name, component, boxname)
        except ServiceAlreadyExists:
            e = sys.exc_info()[1]
            print ("***************************** ERROR *****************************")
            print ("An attempt to reuse service names happened.")
            print ("This is incorrect usage.")
            print ("")
            traceback.print_exc(3)
            print ("***************************** ERROR *****************************")

            raise e

    return component
Esempio n. 25
0
 def main(self):
     """Main loop."""
     cat = CAT.getcat()
     splitter,configbox = cat.retrieveService("Backplane_O_"+self.source)
     p = PassThrough()
     plug = Plug(splitter, p)
     self.link( (self, "control"), (plug, "control"), passthrough=1)
     self.link( (plug,"outbox"), (self,"outbox"), passthrough=2)
     self.link( (plug,"signal"), (self,"signal"), passthrough=2)
     self.addChildren(plug)
     yield newComponent(plug)
     # wait until all child component has terminated
     # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
     # FIXME: then this while loop here would be irrelevent, which would be cool.
     # FIXME: especially if we could exec in such a way that passthrough linkages
     # FIXME: still operated as you'd expect.
     while not self.childrenDone():
         self.pause()
         yield 1
Esempio n. 26
0
    def getTimerServices(tracker=None): # STATIC METHOD
      """\
      Returns any live timer registered with the specified (or default) tracker,
      or creates one for the system to use.

      (static method)
      """
      if tracker is None:
         tracker = CAT.getcat()
      try:
         registerservice = tracker.retrieveService("TimerRegister")
         requestservice  = tracker.retrieveService("TimerRequest")
         return registerservice, requestservice, None
      except KeyError:
         timer = _TimerCore()
         _TimerCore.setTimerServices(timer, tracker)
         registerservice=(timer,"register")
         requestservice=(timer,"inbox")
         return registerservice, requestservice, timer
Esempio n. 27
0
 def main(self):
     """Main loop."""
     cat = CAT.getcat()
     splitter, configbox = cat.retrieveService("Backplane_O_" + self.source)
     p = PassThrough()
     plug = Plug(splitter, p)
     self.link((self, "control"), (plug, "control"), passthrough=1)
     self.link((plug, "outbox"), (self, "outbox"), passthrough=2)
     self.link((plug, "signal"), (self, "signal"), passthrough=2)
     self.addChildren(plug)
     yield newComponent(plug)
     # wait until all child component has terminated
     # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
     # FIXME: then this while loop here would be irrelevent, which would be cool.
     # FIXME: especially if we could exec in such a way that passthrough linkages
     # FIXME: still operated as you'd expect.
     while not self.childrenDone():
         self.pause()
         yield 1
Esempio n. 28
0
    def __init__(self, name):
        super(Backplane,self).__init__()
        assert name == str(name)
        self.name = name
        self.splitter = Splitter()

        splitter = self.splitter
        cat = CAT.getcat()
        try:
            cat.registerService("Backplane_I_"+self.name, splitter, "inbox")
            cat.registerService("Backplane_O_"+self.name, splitter, "configuration")
        except Axon.AxonExceptions.ServiceAlreadyExists, e:
            print "***************************** ERROR *****************************"
            print "An attempt to make a second backplane with the same name happened."
            print "This is incorrect usage."
            print 
            traceback.print_exc(3)
            print "***************************** ERROR *****************************"


            raise e
Esempio n. 29
0
    def initialiseComponent(self):
        """Setting up all the components and activating them.  Also registers
        the splitter with the CoordinatingAssistantTracker.
        
        Would be better to rewrite so that instead of activating directly the
        new components would be returned in a newComponents object.  At the
        moment the returned values are just ignored."""
#        testfile = "/usr/share/doc/packages/subversion/html/svn-book.html"
#        rfa = ReadFileAdaptor(filename = testfile, readsize = 5, steptime = 1.5).activate()
#        rfa = ReadFileAdaptor(command = "netcat -l -p 1400")
        splitter = Splitter().activate()
#        self.link((rfa,"outbox"),(splitter, "inbox"))
        str = SimpleServer(protocol=streamingTextReceiverProtocol, port=1400).activate()
        cat = coordinatingassistanttracker.getcat()
        cat.registerService("thesource", splitter, "configuration")
        cat.registerService("thesink", splitter, "inbox")
        ss = SimpleServer(protocol=streamingTextServerProtocol, port=1500).activate()
#        self.addChildren(rfa,splitter, ss)
        self.addChildren(str,splitter, ss)
#        return rfa, ss, splitter
        return str, ss, splitter
Esempio n. 30
0
def RegisterService(component, services):
    cat = CAT.getcat()
    for (name, boxname) in services.items():

        try:
            cat.registerService(name, component, boxname)
        except ServiceAlreadyExists:
            e = sys.exc_info()[1]
            print(
                "***************************** ERROR *****************************"
            )
            print("An attempt to reuse service names happened.")
            print("This is incorrect usage.")
            print("")
            traceback.print_exc(3)
            print(
                "***************************** ERROR *****************************"
            )

            raise e

    return component
Esempio n. 31
0
    def main(self):

        cat = CAT.getcat()
        service = cat.retrieveService(self.servicename)
        linkage = self.link((self, "_toService"), service)

        # subscribe
        for request in self.requests:
            self.send(("ADD", request, (self, "inbox")), "_toService")

        # now go quiescent and simply forward data
        shutdown = False
        while not shutdown:
            while self.dataReady("inbox"):
                self.send(self.recv("inbox"), "outbox")

            shutdown = self.shutdown()

            self.pause()
            yield 1

        # unsubscribe
        for request in self.requests[-1:-len(self.requests) - 1:-1]:
            self.send(("REMOVE", request, (self, "inbox")), "_toService")
Esempio n. 32
0
 def main(self):
     
     cat = CAT.getcat()
     service = cat.retrieveService(self.servicename)
     linkage = self.link((self,"_toService"),service)
     
     # subscribe
     for request in self.requests:
         self.send( ("ADD", request, (self,"inbox")) , "_toService")
         
     # now go quiescent and simply forward data
     shutdown=False
     while not shutdown:
         while self.dataReady("inbox"):
             self.send(self.recv("inbox"), "outbox")
             
         shutdown = self.shutdown()
         
         self.pause()
         yield 1
     
     # unsubscribe
     for request in self.requests[-1:-len(self.requests)-1:-1]:
         self.send( ("REMOVE", request, (self,"inbox")) , "_toService")
Esempio n. 33
0
    def main(self):
        # first, get the service ID for this channel
        #
        channelLookup = Subscribe(self.fromChannelLookup, [self.channel_name]).activate()
        self.link( (channelLookup,"outbox"), (self, "_fromChannelLookup") )
        while not self.dataReady("_fromChannelLookup"):
            self.pause()
            yield 1
        
        channel_name, service_id, ts_id = self.recv("_fromChannelLookup")
        assert(channel_name == self.channel_name, service_id)
        
        # stage 2, find out which PID contains the PMT for the service,
        # so we'll query the PAT
        pat_parser = Pipeline( Subscribe(self.fromPSI, [PAT_PID]),
                               ParseProgramAssociationTable()
                             ).activate()
        
        fromPAT_linkage = self.link( (pat_parser,"outbox"),(self,"_fromPAT") )
        
        # wait until we get data back from the PAT
        PMT_PID = None
        while PMT_PID == None:
            while not self.dataReady("_fromPAT"):
                self.pause()
                yield 1
        
            pat_table = self.recv("_fromPAT")
            # see if we can find our service's PMT
            for transport_stream_id in pat_table['transport_streams']:
                ts_services = pat_table['transport_streams'][transport_stream_id]
                if service_id in ts_services:
                    PMT_PID = ts_services[service_id]
                    break
            
        print "Found PMT PID for this service:",PMT_PID
            
        # stage 3, find out which PIDs contain AV data, so we'll query this
        # service's PMT
        pmt_parser = Pipeline( Subscribe(self.fromPSI, [PMT_PID]),
                               ParseProgramMapTable()
                             ).activate()
        
        fromPMT_linkage = self.link( (pmt_parser,"outbox"),(self,"_fromPMT") )
        
        # wait until we get data back from the PMT
        audio_pid = None
        video_pid = None
        while audio_pid == None and video_pid == None:
            while not self.dataReady("_fromPMT"):
                self.pause()
                yield 1

            pmt_table = self.recv("_fromPMT")
            if service_id in pmt_table['services']:
                service = pmt_table['services'][service_id]
                for stream in service['streams']:
                    if   stream['type'] in [3,4] and not audio_pid:
                        audio_pid = stream['pid']
                    elif stream['type'] in [1,2] and not video_pid:
                        video_pid = stream['pid']

        print "Found audio PID:",audio_pid
        print "Found video PID:",video_pid
        print "Waiting to start recording..."
        
        yield 1
        
        # get the demuxer service
        cat = CAT.getcat()
        service = cat.retrieveService(self.fromDemuxer)
        self.link((self,"_toDemuxer"),service)
        
        while 1:
            # now wait for the go signal
            recording = False
            while not recording:
                if self.dataReady("inbox"):
                    recording = self.recv("inbox") == "START"
                else:
                    self.pause()
                yield 1
        
        
            # request audio and video data
            self.send( ("ADD",[audio_pid,video_pid], (self,"_av_packets")), "_toDemuxer")
            print time.asctime(), "Recording ",audio_pid,video_pid
            
            while recording:
                while self.dataReady("_av_packets"):
                    packet = self.recv("_av_packets")
                    self.send(packet,"outbox")
                    
                while self.dataReady("inbox"):
                    recording = not ( self.recv("inbox") == "STOP" )
                    
                if recording:
                    self.pause()
                yield 1
                
            self.send( ("REMOVE", [audio_pid,video_pid], (self,"_av_packets")), "_toDemuxer")
            print time.asctime(), "Stopped",audio_pid,video_pid
Esempio n. 34
0
def starttestcursorserver():
    cursorServer = CursorServer()
    cursorServer.activate()
    theCat = coordinatingassistanttracker.getcat()
    theCat.registerService("SEDNA_CURSORS", cursorServer, "inbox")
Esempio n. 35
0
    def main(self):
        # first, get the service ID for this channel
        #
        channelLookup = Subscribe(self.fromChannelLookup,
                                  [self.channel_name]).activate()
        self.link((channelLookup, "outbox"), (self, "_fromChannelLookup"))
        while not self.dataReady("_fromChannelLookup"):
            self.pause()
            yield 1

        channel_name, service_id, ts_id = self.recv("_fromChannelLookup")
        assert (channel_name == self.channel_name, service_id)

        # stage 2, find out which PID contains the PMT for the service,
        # so we'll query the PAT
        pat_parser = Pipeline(Subscribe(self.fromPSI, [PAT_PID]),
                              ParseProgramAssociationTable()).activate()

        fromPAT_linkage = self.link((pat_parser, "outbox"), (self, "_fromPAT"))

        # wait until we get data back from the PAT
        PMT_PID = None
        while PMT_PID == None:
            while not self.dataReady("_fromPAT"):
                self.pause()
                yield 1

            pat_table = self.recv("_fromPAT")
            # see if we can find our service's PMT
            for transport_stream_id in pat_table['transport_streams']:
                ts_services = pat_table['transport_streams'][
                    transport_stream_id]
                if service_id in ts_services:
                    PMT_PID = ts_services[service_id]
                    break

        print "Found PMT PID for this service:", PMT_PID

        # stage 3, find out which PIDs contain AV data, so we'll query this
        # service's PMT
        pmt_parser = Pipeline(Subscribe(self.fromPSI, [PMT_PID]),
                              ParseProgramMapTable()).activate()

        fromPMT_linkage = self.link((pmt_parser, "outbox"), (self, "_fromPMT"))

        # wait until we get data back from the PMT
        audio_pid = None
        video_pid = None
        while audio_pid == None and video_pid == None:
            while not self.dataReady("_fromPMT"):
                self.pause()
                yield 1

            pmt_table = self.recv("_fromPMT")
            if service_id in pmt_table['services']:
                service = pmt_table['services'][service_id]
                for stream in service['streams']:
                    if stream['type'] in [3, 4] and not audio_pid:
                        audio_pid = stream['pid']
                    elif stream['type'] in [1, 2] and not video_pid:
                        video_pid = stream['pid']

        print "Found audio PID:", audio_pid
        print "Found video PID:", video_pid
        print "Waiting to start recording..."

        yield 1

        # get the demuxer service
        cat = CAT.getcat()
        service = cat.retrieveService(self.fromDemuxer)
        self.link((self, "_toDemuxer"), service)

        while 1:
            # now wait for the go signal
            recording = False
            while not recording:
                if self.dataReady("inbox"):
                    recording = self.recv("inbox") == "START"
                else:
                    self.pause()
                yield 1

            # request audio and video data
            self.send(("ADD", [audio_pid, video_pid], (self, "_av_packets")),
                      "_toDemuxer")
            print time.asctime(), "Recording ", audio_pid, video_pid

            while recording:
                while self.dataReady("_av_packets"):
                    packet = self.recv("_av_packets")
                    self.send(packet, "outbox")

                while self.dataReady("inbox"):
                    recording = not (self.recv("inbox") == "STOP")

                if recording:
                    self.pause()
                yield 1

            self.send(
                ("REMOVE", [audio_pid, video_pid], (self, "_av_packets")),
                "_toDemuxer")
            print time.asctime(), "Stopped", audio_pid, video_pid
Esempio n. 36
0
    def main(self):
        # get the demuxer service
        toDemuxer = self.addOutbox("toDemuxer")
        cat = CAT.getcat()
        service = cat.retrieveService(self.demuxerservice)
        self.link((self,toDemuxer),service)
        
        # create a PSI packet reconstructor, and wire it so it can ask
        # the demuxer for PIDs as required.
        psi = ReassemblePSITablesService()
        psi_service = RegisterService(psi,{"PSI":"request"}).activate()
        self.link( (psi,"pid_request"), service )
        
        # stage 1, we need to get the service ID, so we'll query the SDT
        sdt_parser = Pipeline( Subscribe("PSI", [SDT_PID]),
                               ParseServiceDescriptionTable_ActualTS()
                             ).activate()
        
        fromSDT = self.addInbox("fromSDT")
        fromSDT_linkage = self.link( (sdt_parser,"outbox"),(self,fromSDT) )
        
        # wait until we get data back from the SDT
        # note that we wait until we find our service, there's no timeout
        service_id = None
        while service_id == None:
            while not self.dataReady(fromSDT):
                self.pause()
                yield 1
        
            sdt_table = self.recv(fromSDT)
            
            transport_stream_id = sdt_table['transport_stream_id']
            
            # see if we can find our services channel name
            for (sid,service) in sdt_table['services'].items():
                for (dtype,descriptor) in service['descriptors']:
                    if descriptor['type'] == "service":
                        if descriptor['service_name'].lower() == self.channelname.lower():
                            service_id = sid
                            break
        
        print "Found service id:",service_id
        print "Its in transport stream id:",transport_stream_id
            
            
        # stage 2, find out which PID contains the PMT for the service,
        # so we'll query the PAT
        pat_parser = Pipeline( Subscribe("PSI", [PAT_PID]),
                               ParseProgramAssociationTable()
                             ).activate()
        
        fromPAT = self.addInbox("fromPAT")
        fromPAT_linkage = self.link( (pat_parser,"outbox"),(self,fromPAT) )
        
        # wait until we get data back from the PAT
        PMT_PID = None
        while PMT_PID == None:
            while not self.dataReady(fromPAT):
                self.pause()
                yield 1
        
            sdt_table = self.recv(fromPAT)
            # see if we can find our service's PMT
            ts_services = sdt_table['transport_streams'][transport_stream_id]
            if service_id in ts_services:
                PMT_PID = ts_services[service_id]
                break
            
        print "Found PMT PID for this service:",PMT_PID
            
        # stage 3, find out which PIDs contain AV data, so we'll query this
        # service's PMT
        pmt_parser = Pipeline( Subscribe("PSI", [PMT_PID]),
                               ParseProgramMapTable()
                             ).activate()
        
        fromPMT = self.addInbox("fromPMT")
        fromPMT_linkage = self.link( (pmt_parser,"outbox"),(self,fromPMT) )
        
        # wait until we get data back from the PMT
        audio_pid = None
        video_pid = None
        while audio_pid == None and video_pid == None:
            while not self.dataReady(fromPMT):
                self.pause()
                yield 1

            pmt_table = self.recv(fromPMT)
            if service_id in pmt_table['services']:
                service = pmt_table['services'][service_id]
                for stream in service['streams']:
                    if   stream['type'] in [3,4] and not audio_pid:
                        audio_pid = stream['pid']
                    elif stream['type'] in [1,2] and not video_pid:
                        video_pid = stream['pid']

        print "Found audio PID:",audio_pid
        print "Found video PID:",video_pid
        
        yield 1
        # now set up to receive those pids and forward them on for all eternity
        
        fromDemuxer = self.addInbox("fromDemuxer")
        self.send( ("ADD",[audio_pid,video_pid], (self,fromDemuxer)), toDemuxer)
        
        while 1:
            while self.dataReady(fromDemuxer):
                packet = self.recv(fromDemuxer)
                self.send(packet,"outbox")
                
            self.pause()
            yield 1
Esempio n. 37
0
 def __init__(self, **args):
     super(SingleService, self).__init__(**args)
     cat = CAT.getcat()
     cat.registerService("SS_D_" + self.Name, self, self.DataBox)
     cat.registerService("SS_C_" + self.Name, self, self.ControlBox)
Esempio n. 38
0
    def main(self):
        # get the demuxer service
        toDemuxer = self.addOutbox("toDemuxer")
        cat = CAT.getcat()
        service = cat.retrieveService(self.demuxerservice)
        self.link((self, toDemuxer), service)

        # create a PSI packet reconstructor, and wire it so it can ask
        # the demuxer for PIDs as required.
        psi = ReassemblePSITablesService()
        psi_service = RegisterService(psi, {"PSI": "request"}).activate()
        self.link((psi, "pid_request"), service)

        # stage 1, we need to get the service ID, so we'll query the SDT
        sdt_parser = Pipeline(
            Subscribe("PSI", [SDT_PID]),
            ParseServiceDescriptionTable_ActualTS()).activate()

        fromSDT = self.addInbox("fromSDT")
        fromSDT_linkage = self.link((sdt_parser, "outbox"), (self, fromSDT))

        # wait until we get data back from the SDT
        # note that we wait until we find our service, there's no timeout
        service_id = None
        while service_id == None:
            while not self.dataReady(fromSDT):
                self.pause()
                yield 1

            sdt_table = self.recv(fromSDT)

            transport_stream_id = sdt_table['transport_stream_id']

            # see if we can find our services channel name
            for (sid, service) in sdt_table['services'].items():
                for (dtype, descriptor) in service['descriptors']:
                    if descriptor['type'] == "service":
                        if descriptor['service_name'].lower(
                        ) == self.channelname.lower():
                            service_id = sid
                            break

        print "Found service id:", service_id
        print "Its in transport stream id:", transport_stream_id

        # stage 2, find out which PID contains the PMT for the service,
        # so we'll query the PAT
        pat_parser = Pipeline(Subscribe("PSI", [PAT_PID]),
                              ParseProgramAssociationTable()).activate()

        fromPAT = self.addInbox("fromPAT")
        fromPAT_linkage = self.link((pat_parser, "outbox"), (self, fromPAT))

        # wait until we get data back from the PAT
        PMT_PID = None
        while PMT_PID == None:
            while not self.dataReady(fromPAT):
                self.pause()
                yield 1

            sdt_table = self.recv(fromPAT)
            # see if we can find our service's PMT
            ts_services = sdt_table['transport_streams'][transport_stream_id]
            if service_id in ts_services:
                PMT_PID = ts_services[service_id]
                break

        print "Found PMT PID for this service:", PMT_PID

        # stage 3, find out which PIDs contain AV data, so we'll query this
        # service's PMT
        pmt_parser = Pipeline(Subscribe("PSI", [PMT_PID]),
                              ParseProgramMapTable()).activate()

        fromPMT = self.addInbox("fromPMT")
        fromPMT_linkage = self.link((pmt_parser, "outbox"), (self, fromPMT))

        # wait until we get data back from the PMT
        audio_pid = None
        video_pid = None
        while audio_pid == None and video_pid == None:
            while not self.dataReady(fromPMT):
                self.pause()
                yield 1

            pmt_table = self.recv(fromPMT)
            if service_id in pmt_table['services']:
                service = pmt_table['services'][service_id]
                for stream in service['streams']:
                    if stream['type'] in [3, 4] and not audio_pid:
                        audio_pid = stream['pid']
                    elif stream['type'] in [1, 2] and not video_pid:
                        video_pid = stream['pid']

        print "Found audio PID:", audio_pid
        print "Found video PID:", video_pid

        yield 1
        # now set up to receive those pids and forward them on for all eternity

        fromDemuxer = self.addInbox("fromDemuxer")
        self.send(("ADD", [audio_pid, video_pid], (self, fromDemuxer)),
                  toDemuxer)

        while 1:
            while self.dataReady(fromDemuxer):
                packet = self.recv(fromDemuxer)
                self.send(packet, "outbox")

            self.pause()
            yield 1