def _onUnderrun(self, element): """ Cancel test_timeout as messages are obviously received on the bus. """ self._debugger.ddebug("onUnderrun/") if self._testTimeout: self._testTimeout.cancel() self._testTimeout = None if self._underrunTimeout: self._debugger.ddebug( "underrun: I already saw a recent underrun; ignoring") else: self._debugger.ddebug( "underrun: scheduling 'restartSourceBin' in 2s") self._underrunTimeout = GObjectTimeout(2, self._restartSourceBin) self._underrunTimeout.start() self._debugger.ddebug("/onUnderrun")
def detect(self, elementName, params, timeoutSecs, checkAborted=lambda: False): """ Generator that yields the messages emitted by the named gstreamer element configured with the parameters `params`. "elementName" is the name of the gstreamer element as specified in the pipeline. The name must be the same in the pipeline and in the messages returned by gstreamer. "params" is a dictionary of parameters to setup the element. The original parameters will be restored at the end of the call. "timeoutSecs" is in seconds elapsed, from the method call. Note that stopping iterating also enables to interrupt the method. For every frame processed, a tuple is returned: (message, screenshot). """ self._debugger.debug(">> detect <<") element = self._pipeline.get_by_name(elementName) paramsBackup = {} for key in params.keys(): try: paramsBackup[key] = getattr(element.props, key) except: self._debugger.debug("FIXME!") pass try: for key in params.keys(): try: setattr(element.props, key, params[key]) except: self._debugger.debug("FIXME!") pass """ Timeout after 5s in case no messages are received on the bus. This happens when starting a new instance of stbt when the Hauppauge HDPVR capture device is stopping. """ with GObjectTimeout(timeoutSecs=5, handler=self._onTimeout) as t: checkAborted() self._testTimeout = t self._startTimestamp = None for message in MessageIterator(self._bus, "message::element", self._mainloop, checkAborted): # Cancel test_timeout as messages are obviously received. if self._testTimeout: self._testTimeout.cancel() self._testTimeout = None st = message.structure if st.get_name() == elementName: buf = self._screenshot.get_property("last-buffer") if not buf: continue if not self._startTimestamp: self._startTimestamp = buf.timestamp try: if ((buf.timestamp - self._startTimestamp) > (timeoutSecs * 100000000000)): return except Exception, _e: pass yield (st, buf) finally: for key in params.keys(): try: setattr(element.props, key, paramsBackup[key]) except: self._debugger.debug("FIXME!") pass