def testLoop(self): def onEOF(): self.eof = True def onFrame(): if self.eof: if not threaded: self.compareImage("testVideoLoop") player.stop() for audio, threaded in [(False, False), (False, True), (True, True)]: self.eof = False if audio: player.setFakeFPS(-1) else: player.setFakeFPS(25) root = self.loadEmptyScene() if audio: node = avg.SoundNode(parent=root, loop=True, href="48kHz_16bit_mono.wav") else: node = avg.VideoNode(parent=root, loop=True, fps=25, size=(96,96), threaded=threaded, href="mpeg1-48x48.mov") node.subscribe(avg.Node.END_OF_FILE, onEOF) node.play() player.subscribe(player.ON_FRAME, onFrame) player.play()
def testBitmapManager(self): WAIT_TIMEOUT = 2000 def expectException(returnValue, nextAction): if isinstance(returnValue, Exception): nextAction() else: raise RuntimeError("Expected exception, got %s (%s)" % (returnValue, type(returnValue))) def loadValidBitmap(): def validBitmapCb(bitmap): self.assert_(not isinstance(bitmap, Exception)) player.setTimeout(0, loadBitmapWithPixelFormat) avg.BitmapManager.get().loadBitmap("media/rgb24alpha-64x64.png", validBitmapCb) def loadBitmapWithPixelFormat(): def validBitmapCb(bitmap): self.assert_(not isinstance(bitmap, Exception)) self.assert_(bitmap.getFormat() == avg.B5G6R5) player.setTimeout(0, loadUnexistentBitmap) avg.BitmapManager.get().loadBitmap("media/rgb24alpha-64x64.png", validBitmapCb, avg.B5G6R5) def loadUnexistentBitmap(): avg.BitmapManager.get().loadBitmap( "nonexistent.png", lambda bmp: expectException( returnValue=bmp, nextAction=lambda: player.setTimeout(0, loadBrokenBitmap))) def loadBrokenBitmap(): import tempfile tempFileName = os.path.join(tempfile.gettempdir(), "broken.png") open(tempFileName, "w") def cleanupAndTestReturnValue(returnValue): os.unlink(tempFileName) expectException(returnValue=returnValue, nextAction=player.stop) avg.BitmapManager.get().loadBitmap(tempFileName, cleanupAndTestReturnValue) def reportStuck(): raise RuntimeError("BitmapManager didn't reply " "within %dms timeout" % WAIT_TIMEOUT) player.stop() for multithread in [False, True]: self.loadEmptyScene() if multithread: avg.BitmapManager.get().setNumThreads(2) player.setTimeout(WAIT_TIMEOUT, reportStuck) player.setResolution(0, 0, 0, 0) loadValidBitmap() player.play() avg.BitmapManager.get().setNumThreads(1)
def testBitmapManager(self): WAIT_TIMEOUT = 2000 def expectException(returnValue, nextAction): if isinstance(returnValue, Exception): nextAction() else: raise RuntimeError("Expected exception, got %s (%s)" % ( returnValue, type(returnValue))) def loadValidBitmap(): def validBitmapCb(bitmap): self.assert_(not isinstance(bitmap, Exception)) player.setTimeout(0, loadBitmapWithPixelFormat) avg.BitmapManager.get().loadBitmap("media/rgb24alpha-64x64.png", validBitmapCb) def loadBitmapWithPixelFormat(): def validBitmapCb(bitmap): self.assert_(not isinstance(bitmap, Exception)) self.assert_(bitmap.getFormat() == avg.B5G6R5) player.setTimeout(0, loadUnexistentBitmap) avg.BitmapManager.get().loadBitmap("media/rgb24alpha-64x64.png", validBitmapCb, avg.B5G6R5) def loadUnexistentBitmap(): avg.BitmapManager.get().loadBitmap("nonexistent.png", lambda bmp: expectException( returnValue=bmp, nextAction=lambda: player.setTimeout(0, loadBrokenBitmap))) def loadBrokenBitmap(): import tempfile tempFileName = os.path.join(tempfile.gettempdir(), "broken.png") open(tempFileName, "w") def cleanupAndTestReturnValue(returnValue): os.unlink(tempFileName) expectException(returnValue=returnValue, nextAction=player.stop) avg.BitmapManager.get().loadBitmap(tempFileName, cleanupAndTestReturnValue) def reportStuck(): raise RuntimeError("BitmapManager didn't reply " "within %dms timeout" % WAIT_TIMEOUT) player.stop() for multithread in [False, True]: self.loadEmptyScene() if multithread: avg.BitmapManager.get().setNumThreads(2) player.setTimeout(WAIT_TIMEOUT, reportStuck) player.setResolution(0, 0, 0, 0) loadValidBitmap() player.play() avg.BitmapManager.get().setNumThreads(1)
def testError(self): self.initDefaultImageScene() player.setTimeout(1, lambda: undefinedFunction) player.setTimeout(50, player.stop) try: player.play() except NameError: self.assert_(1) else: self.assert_(0)
def isOffscreenSupported(): def testOffscreenSupported(): global offscreenSupported offscreenSupported = avg.OffscreenCanvas.isSupported() player.stop() global offscreenSupported sceneString = """<avg id="avg" width="160" height="120"/>""" player.loadString(sceneString) player.setTimeout(0, testOffscreenSupported) player.play() return offscreenSupported
def __dumpConfig(self): player.enableGLErrorChecks(True) avg.logger.pushCategories() avg.logger.setCategories(avg.logger.APP | avg.logger.CONFIG | avg.logger.DEPRECATION) player.loadString(""" <avg id="avg" width="160" height="120"> </avg> """) player.setTimeout(0, player.stop) player.setFramerate(10000) player.play() avg.logger.popCategories()
def _startApp(self, appClass): self._onBeforePlay() player.setTimeout(0, self._onStart) self._appInstance = appClass(self._appNode) g_KbManager.setup(self._appInstance.onKeyDown, self._appInstance.onKeyUp) self._setupDefaultKeys() self._appInstance.setStarter(self) player.play() self._appInstance.exit() g_KbManager.teardown()
def _startApp(self, appClass): self._onBeforePlay() player.setTimeout(0, self._onStart) self._appInstance = appClass(self._appNode) g_KbManager.setup( self._appInstance.onKeyDown, self._appInstance.onKeyUp) self._setupDefaultKeys() self._appInstance.setStarter(self) player.play() self._appInstance.exit() g_KbManager.teardown()
def start(self, warnOnImageDiff, actions): self.__setupPlayer() self.__dumpTestFrames = (os.getenv("AVG_DUMP_TEST_FRAMES") is not None) self.__delaying = False self.__warnOnImageDiff = warnOnImageDiff self.assert_(player.isPlaying() == 0) self.actions = flatten(actions) self.curFrame = 0 player.subscribe(player.ON_FRAME, self.__nextAction) player.setFramerate(10000) player.assumePixelsPerMM(1) player.play() self.assert_(player.isPlaying() == 0)
def start(self, warnOnImageDiff, actions): self.__setupPlayer() self.__dumpTestFrames = (os.getenv("AVG_DUMP_TEST_FRAMES") != None) self.__delaying = False self.__warnOnImageDiff = warnOnImageDiff self.assert_(player.isPlaying() == 0) self.actions = flatten(actions) self.curFrame = 0 player.subscribe(player.ON_FRAME, self.__nextAction) player.setFramerate(10000) player.assumePixelsPerMM(1) player.play() self.assert_(player.isPlaying() == 0)
def __dumpConfig(self): player.enableGLErrorChecks(True) cats = avg.logger.getCategories() for cat in [avg.logger.Category.APP, avg.logger.Category.CONFIG, avg.logger.Category.DEPREC]: avg.logger.configureCategory(cat, avg.logger.Severity.INFO) player.loadString(""" <avg id="avg" width="160" height="120"> </avg> """) player.setTimeout(0, player.stop) player.setFramerate(10000) player.play() for cat, severity in cats.iteritems(): avg.logger.configureCategory(cat, severity)
def __dumpConfig(self): player.enableGLErrorChecks(True) cats = avg.logger.getCategories() for cat in [ avg.logger.Category.APP, avg.logger.Category.CONFIG, avg.logger.Category.DEPREC ]: avg.logger.configureCategory(cat, avg.logger.Severity.INFO) player.loadString(""" <avg id="avg" width="160" height="120"> </avg> """) player.setTimeout(0, player.stop) player.setFramerate(10000) player.play() for cat, severity in cats.iteritems(): avg.logger.configureCategory(cat, severity)
def testEOF(self, node): def onEOF(): player.stop() def onNoEOF(): self.fail("No EOF") def onSubscribeEOF(): self.eofCalled = True self.eofCalled = False root = self.loadEmptyScene() root.appendChild(node) node.play() node.setEOFCallback(onEOF) node.subscribe(avg.Node.END_OF_FILE, onSubscribeEOF) player.setTimeout(100000, onNoEOF) player.play() self.assert_(self.eofCalled)
def testVideoSeekAfterEOF(self): def onEOF(): node.seekToTime(0) player.subscribe(avg.Player.ON_FRAME, onFrame) def onFrame(): if node.getCurTime() < 100: self.compareImage("testSeekAfterEOF") player.stop() def onNoEOF(): self.fail("No EOF") player.setFakeFPS(25) root = self.loadEmptyScene() node = avg.VideoNode(href="mpeg1-48x48.mov", parent=root) node.play() node.subscribe(avg.VideoNode.END_OF_FILE, onEOF) player.setTimeout(100000, onNoEOF) player.play()
def testVideoLoop(self): def onEOF(): self.eof = True def onFrame(): if self.eof: if not(threaded): self.compareImage("testVideoLoop") player.stop() for threaded in [False, True]: self.eof = False player.setFakeFPS(25) root = self.loadEmptyScene() videoNode = avg.VideoNode(parent=root, loop=True, fps=25, size=(96,96), threaded=threaded, href="mpeg1-48x48.mov") videoNode.subscribe(avg.Node.END_OF_FILE, onEOF) videoNode.play() player.subscribe(player.ON_FRAME, onFrame) player.play()
def testVideoLoop(self): def onEOF(): self.eof = True def onFrame(): if self.eof: if not(threaded): self.compareImage("testVideoLoop") player.stop() for threaded in [False, True]: self.eof = False player.setFakeFPS(25) root = self.loadEmptyScene() videoNode = avg.VideoNode(parent=root, loop=True, fps=25, size=(96,96), threaded=threaded, href="mpeg1-48x48.mpg") videoNode.subscribe(avg.Node.END_OF_FILE, onEOF) videoNode.play() player.subscribe(player.ON_FRAME, onFrame) player.play()
#!/usr/bin/env python # -*- coding: utf-8 -*- from libavg import avg, player canvas = player.createMainCanvas(size=(160,120)) rootNode = canvas.getRootNode() avg.ImageNode(pos=(40,30), size=(80,60), href="rgb24-64x64.png", parent=rootNode) player.play()
#!/usr/bin/env python # -*- coding: utf-8 -*- from libavg import avg, player canvas = player.createMainCanvas(size=(640, 480)) rootNode = canvas.getRootNode() avg.WordsNode(pos=(10, 10), text="Hello World", parent=rootNode) player.play()