Example #1
0
    def test_isActive(self):
        """ Test isActive() """
        ac = Action()

        self.assertEquals(ac.isActive(), False)

        # Here we cheat, setting manually the state !
        ac.state = STATE_ACTIVE

        self.assertEquals(ac.isActive(), True)
Example #2
0
    def test_isActive(self):
        """ Test isActive() """
        ac = Action()

        self.assertEquals(ac.isActive(), False)

        # Here we cheat, setting manually the state !
        ac.state = STATE_ACTIVE

        self.assertEquals(ac.isActive(), True)
Example #3
0
    def testPendingLink(self):
        a = Action()
        p = Pipeline()
        src = common.FakeGnlFactory()
        src.addOutputStream(VideoStream(gst.Caps("video/x-raw-yuv"),
                                        pad_name="src"))
        sink = common.FakeSinkFactory()
        sink.addInputStream(MultimediaStream(gst.Caps("any"),
                                             pad_name="sink"))

        # set the link, it will be activated once the pad is added
        a.setLink(src, sink)
        # Let's see if the link is present
        self.assertEquals(a._links, [(src, sink, None, None)])

        p.setAction(a)

        gst.debug("about to activate action")
        a.activate()
        # only the producer and the consumer are created, the other elements are
        # created dinamically
        self.assertEquals(len(list(p._pipeline.elements())), 2)

        p.setState(STATE_PLAYING)
        time.sleep(1)
        # and make sure that all other elements were created (4)
        # FIXME  if it's failing here, run the test a few times trying to raise
        # the time.sleep() above, it may just be racy...
        self.assertEquals(len(list(p._pipeline.elements())), 4)

        a.deactivate()
        p.setState(STATE_NULL)
        self.assertEquals(len(list(p._pipeline.elements())), 0)
        p.release()
Example #4
0
    def getDynamicLinks(self, producer, stream):
        links = Action.getDynamicLinks(self, producer, stream)
        consumer = common.FakeSinkFactory()

        links.append((producer, consumer, stream, None))
        gst.debug("Returning link")
        return links
Example #5
0
 def testBasic(self):
     # let's make sure Actions are properly created
     ac = Action()
     self.assertEquals(ac.state, STATE_NOT_ACTIVE)
     self.assertEquals(ac.producers, [])
     self.assertEquals(ac.consumers, [])
     self.assertEquals(ac.pipeline, None)
Example #6
0
    def testLinksSimple(self):
        """ Testing simple usage of Links """
        a = Action()
        src = common.FakeSourceFactory()
        src.addOutputStream(MultimediaStream(gst.Caps("any"), pad_name="src"))
        sink = common.FakeSinkFactory()
        sink.addInputStream(MultimediaStream(gst.Caps("any"), pad_name="sink"))

        a.setLink(src, sink)
        # Let's see if the link is present
        self.assertEquals(a._links, [(src, sink, None, None)])

        # It should have added both the producer and consumer
        self.assertEquals(a.producers, [src])
        self.assertEquals(a.consumers, [sink])

        # adding it again  should raise an exception
        self.failUnlessRaises(ActionError, a.setLink, src, sink)

        # remove the link
        a.removeLink(src, sink)
        self.assertEquals(a._links, [])
Example #7
0
    def testLinksSimple(self):
        """ Testing simple usage of Links """
        a = Action()
        src = common.FakeSourceFactory()
        src.addOutputStream(MultimediaStream(gst.Caps("any"), pad_name="src"))
        sink = common.FakeSinkFactory()
        sink.addInputStream(MultimediaStream(gst.Caps("any"), pad_name="sink"))

        a.setLink(src, sink)
        # Let's see if the link is present
        self.assertEquals(a._links, [(src, sink, None, None)])

        # It should have added both the producer and consumer
        self.assertEquals(a.producers, [src])
        self.assertEquals(a.consumers, [sink])

        # adding it again  should raise an exception
        self.failUnlessRaises(ActionError, a.setLink, src, sink)

        # remove the link
        a.removeLink(src, sink)
        self.assertEquals(a._links, [])
Example #8
0
    def testPipelineSimple(self):
        """ Test setPipeline and unsetPipeline """
        ac = Action()
        p = Pipeline()
        p2 = Pipeline()

        # set a Pipeline
        ac.setPipeline(p)
        self.assertEquals(ac.pipeline, p)

        # Setting a different Pipeline should fail...
        self.failUnlessRaises(ActionError, ac.setPipeline, p2)

        # ... but setting the same Pipeline again should silently succeed
        ac.setPipeline(p)

        # remove the Pipeline
        ac.unsetPipeline()
        self.assertEquals(ac.pipeline, None)

        # and now setting the other Pipeline should succeed
        ac.setPipeline(p2)
        self.assertEquals(ac.pipeline, p2)

        # remove the Pipeline again
        ac.unsetPipeline()
        self.assertEquals(ac.pipeline, None)

        # internally set the state to ACTIVE
        ac.state = STATE_ACTIVE
        # now setting any Pipeline should fail !
        self.failUnlessRaises(ActionError, ac.setPipeline, p)

        # internally set the state to NOT_ACTIVE
        ac.state = STATE_NOT_ACTIVE
        self.assertEquals(ac.isActive(), False)

        # Set a pipeline
        ac.setPipeline(p)
        self.assertEquals(ac.pipeline, p)

        # interally set the state to ACTIVE
        ac.state = STATE_ACTIVE
        # we shouldn't be able to unset a pipeline from an active Action
        self.failUnlessRaises(ActionError, ac.unsetPipeline)

        # cleanup
        ac.state = STATE_NOT_ACTIVE
        ac.unsetPipeline()

        p.release()
        p2.release()
Example #9
0
    def testSettingFactoriesSimple(self):
        """Simple add/remove Factory tests"""
        ac = Action()
        p = Pipeline()

        src = common.FakeSourceFactory()
        sink = common.FakeSinkFactory()

        # you can't set a Sink element as a producer
        self.failUnlessRaises(ActionError, ac.addProducers, sink)
        # you can't set a Source element as a consumer
        self.failUnlessRaises(ActionError, ac.addConsumers, src)

        # if the action is active, you can't add anything
        ac.state = STATE_ACTIVE
        self.failUnlessRaises(ActionError, ac.addProducers, src)
        self.failUnlessRaises(ActionError, ac.addConsumers, sink)
        ac.state = STATE_NOT_ACTIVE

        # Set a producer and consumer on the action
        ac.addProducers(src)
        ac.addConsumers(sink)

        self.assertEquals(ac.producers, [src])
        self.assertEquals(ac.consumers, [sink])

        self.failUnlessRaises(ActionError, ac.removeProducers, sink)
        self.failUnlessRaises(ActionError, ac.removeConsumers, src)
        self.assertEquals(ac.producers, [src])
        self.assertEquals(ac.consumers, [sink])

        # you can't remove anything from an active action
        ac.state = STATE_ACTIVE
        self.failUnlessRaises(ActionError, ac.removeProducers, src)
        self.failUnlessRaises(ActionError, ac.removeConsumers, sink)
        ac.state = STATE_NOT_ACTIVE

        # finally, attempt correct removal
        ac.removeProducers(src)
        self.assertEquals(ac.producers, [])
        self.assertEquals(ac.consumers, [sink])

        ac.removeConsumers(sink)
        self.assertEquals(ac.producers, [])
        self.assertEquals(ac.consumers, [])

        p.release()
Example #10
0
    def testPipelineAction(self):
        """Testing pipeline state interaction"""
        p = Pipeline()
        a = Action()
        src = VideoTestSourceFactory()
        sink = common.FakeSinkFactory()
        sink.addInputStream(MultimediaStream(gst.Caps("any"), pad_name="sink"))

        # set the Action on the Pipeline
        p.setAction(a)
        self.assertEquals(p.actions, [a])

        # set the Producer and Consumer
        a.addProducers(src)
        a.addConsumers(sink)

        a.setLink(src, sink)

        # activate the Action
        a.activate()

        self.failUnlessEqual(src.current_bins, 1)
        self.failUnlessEqual(sink.current_bins, 1)

        # call get*ForFactoryStream(..., automake=False). They will raise
        # exceptions if the action didn't create the elements.
        bin = p.getBinForFactoryStream(src, automake=False)
        p.releaseBinForFactoryStream(src)

        tee = p.getTeeForFactoryStream(src, automake=False)
        p.releaseTeeForFactoryStream(src)

        bin = p.getBinForFactoryStream(sink, automake=False)

        queue = p.getQueueForFactoryStream(sink, automake=False)

        self.failUnlessEqual(queue.get_pad('src').get_peer().get_parent(), bin)

        p.releaseBinForFactoryStream(sink)
        p.releaseQueueForFactoryStream(sink)

        # switch to PLAYING
        p.setState(STATE_PLAYING)

        # wait half a second

        # switch to READY
        p.setState(STATE_READY)

        # deactivate action
        a.deactivate()

        # since we're the last Action to be release, the tees
        # and queues should have gone
        self.failUnlessEqual(src.current_bins, 0)
        self.failUnlessEqual(sink.current_bins, 0)

        # remove the action from the pipeline
        p.removeAction(a)

        # the gst.Pipeline should be empty !
        self.assertEquals(list(p._pipeline.elements()), [])

        p.release()
Example #11
0
    def testPipelineSimple(self):
        """ Test setPipeline and unsetPipeline """
        ac = Action()
        p = Pipeline()
        p2 = Pipeline()

        # set a Pipeline
        ac.setPipeline(p)
        self.assertEquals(ac.pipeline, p)

        # Setting a different Pipeline should fail...
        self.failUnlessRaises(ActionError, ac.setPipeline, p2)

        # ... but setting the same Pipeline again should silently succeed
        ac.setPipeline(p)

        # remove the Pipeline
        ac.unsetPipeline()
        self.assertEquals(ac.pipeline, None)

        # and now setting the other Pipeline should succeed
        ac.setPipeline(p2)
        self.assertEquals(ac.pipeline, p2)

        # remove the Pipeline again
        ac.unsetPipeline()
        self.assertEquals(ac.pipeline, None)

        # internally set the state to ACTIVE
        ac.state = STATE_ACTIVE
        # now setting any Pipeline should fail !
        self.failUnlessRaises(ActionError, ac.setPipeline, p)

        # internally set the state to NOT_ACTIVE
        ac.state = STATE_NOT_ACTIVE
        self.assertEquals(ac.isActive(), False)

        # Set a pipeline
        ac.setPipeline(p)
        self.assertEquals(ac.pipeline, p)

        # interally set the state to ACTIVE
        ac.state = STATE_ACTIVE
        # we shouldn't be able to unset a pipeline from an active Action
        self.failUnlessRaises(ActionError, ac.unsetPipeline)

        # cleanup
        ac.state = STATE_NOT_ACTIVE
        ac.unsetPipeline()

        p.release()
        p2.release()
Example #12
0
    def testSettingFactoriesSimple(self):
        """Simple add/remove Factory tests"""
        ac = Action()
        p = Pipeline()

        src = common.FakeSourceFactory()
        sink = common.FakeSinkFactory()

        # you can't set a Sink element as a producer
        self.failUnlessRaises(ActionError, ac.addProducers, sink)
        # you can't set a Source element as a consumer
        self.failUnlessRaises(ActionError, ac.addConsumers, src)

        # if the action is active, you can't add anything
        ac.state = STATE_ACTIVE
        self.failUnlessRaises(ActionError, ac.addProducers, src)
        self.failUnlessRaises(ActionError, ac.addConsumers, sink)
        ac.state = STATE_NOT_ACTIVE

        # Set a producer and consumer on the action
        ac.addProducers(src)
        ac.addConsumers(sink)

        self.assertEquals(ac.producers, [src])
        self.assertEquals(ac.consumers, [sink])

        self.failUnlessRaises(ActionError, ac.removeProducers, sink)
        self.failUnlessRaises(ActionError, ac.removeConsumers, src)
        self.assertEquals(ac.producers, [src])
        self.assertEquals(ac.consumers, [sink])

        # you can't remove anything from an active action
        ac.state = STATE_ACTIVE
        self.failUnlessRaises(ActionError, ac.removeProducers, src)
        self.failUnlessRaises(ActionError, ac.removeConsumers, sink)
        ac.state = STATE_NOT_ACTIVE

        # finally, attempt correct removal
        ac.removeProducers(src)
        self.assertEquals(ac.producers, [])
        self.assertEquals(ac.consumers, [sink])

        ac.removeConsumers(sink)
        self.assertEquals(ac.producers, [])
        self.assertEquals(ac.consumers, [])

        p.release()