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()
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
def testMultiple(self): """Test a dual stream encoding with separates sources""" settings = RenderSettings(settings=[self.asettings, self.vsettings], muxer="oggmux") sf = RenderSinkFactory(RenderFactory(settings=settings), common.FakeSinkFactory()) a = RenderAction() a.addConsumers(sf) a.addProducers(self.vsrc, self.asrc) p = Pipeline() a.setPipeline(p) a.activate() self.assertEquals(len(a._links), 2) p.play() time.sleep(3) p.getState() p.stop() a.deactivate() a.unsetPipeline() p.release()
def testSimpleStreams(self): """Test a RenderSettings with exact stream settings""" # let's force the video to some unusual size outs = VideoStream( gst.Caps("video/x-raw-yuv,width=624,height=230,framerate=10/1")) fset = StreamEncodeSettings(encoder="theoraenc", input_stream=outs) settings = RenderSettings(settings=[fset], muxer="oggmux") sf = RenderSinkFactory(RenderFactory(settings=settings), common.FakeSinkFactory()) a = RenderAction() a.addConsumers(sf) a.addProducers(self.vsrc) p = Pipeline() a.setPipeline(p) a.activate() self.assertEquals(len(a._links), 1) p.play() time.sleep(3) p.getState() p.stop() a.deactivate() p.release()
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()
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, [])
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()
def setUp(self): self.mainloop = gobject.MainLoop() samples = os.path.join(os.path.dirname(__file__), "samples") self.facs = [] self.facs.append([ PictureFileSourceFactory( 'file://' + os.path.join(samples, "flat_colour1_640x480.png")), VideoStream( gst.Caps( "video/x-raw-rgb,bpp=(int)24,depth=(int)24,endianness=(int)4321,red_mask=(int)16711680,green_mask=(int)65280,blue_mask=(int)255" )) ]) self.facs.append([ PictureFileSourceFactory( 'file://' + os.path.join(samples, "flat_colour2_640x480.png")), VideoStream( gst.Caps( "video/x-raw-rgb,bpp=(int)24,depth=(int)24,endianness=(int)4321,red_mask=(int)16711680,green_mask=(int)65280,blue_mask=(int)255" )) ]) self.facs.append([ PictureFileSourceFactory( 'file://' + os.path.join(samples, "flat_colour3_320x180.png")), VideoStream( gst.Caps( "video/x-raw-rgb,bpp=(int)24,depth=(int)24,endianness=(int)4321,red_mask=(int)16711680,green_mask=(int)65280,blue_mask=(int)255" )) ]) # one video with a different resolution self.facs.append([ VideoTestSourceFactory(), VideoStream( gst.Caps( 'video/x-raw-yuv,width=(int)640,height=(int)480,format=(fourcc)I420' )) ]) # configure durations and add output streams to factories for fac in self.facs: factory = fac[0] stream = fac[1] factory.duration = self.clip_duration factory.addOutputStream(stream) self.track_objects = [] self.track = Track(self.facs[0][1]) self.timeline = Timeline() self.timeline.addTrack(self.track) vsettings = StreamEncodeSettings(encoder="theoraenc") rsettings = RenderSettings(settings=[vsettings], muxer="oggmux") self.fakesink = common.FakeSinkFactory() rendersink = RenderSinkFactory(RenderFactory(settings=rsettings), self.fakesink) self.render = RenderAction() self.pipeline = Pipeline() self.pipeline.connect("eos", self._renderEOSCb) self.pipeline.connect("error", self._renderErrorCb) self.pipeline.addAction(self.render) self.render.addConsumers(rendersink) timeline_factory = TimelineSourceFactory(self.timeline) self.render.addProducers(timeline_factory)