def on_running(self, _element): if self.underrun_timeout: ddebug("running: cancelling underrun timer") self.underrun_timeout.cancel() self.underrun_timeout = None else: ddebug("running: no outstanding underrun timers; ignoring")
def on_underrun(self, _element): if self.underrun_timeout: ddebug("underrun: I already saw a recent underrun; ignoring") else: ddebug("underrun: scheduling 'restart_source' in 2s") self.underrun_timeout = GObjectTimeout(2, self.restart_source) self.underrun_timeout.start()
def frames(self, timeout_secs=None): if timeout_secs is not None: end_time = self._time.time() + timeout_secs timestamp = None first = True while True: if self._use_old_threading_behaviour: timestamp = self._last_grabbed_frame_time ddebug("user thread: Getting sample at %s" % self._time.time()) frame = self._display.get_frame(max(10, timeout_secs), since=timestamp) ddebug("user thread: Got sample at %s" % self._time.time()) timestamp = frame.time if self._use_old_threading_behaviour: self._last_grabbed_frame_time = timestamp if not first and timeout_secs is not None and timestamp > end_time: debug("timed out: %.3f > %.3f" % (timestamp, end_time)) return yield frame first = False
def tell_user_thread(self, frame_or_exception): # `self.last_frame` is how we communicate from this thread (the GLib # main loop) to the main application thread running the user's script. # Note that only this thread writes to self.last_frame. if isinstance(frame_or_exception, Exception): ddebug("glib thread: reporting exception to user thread: %s" % frame_or_exception) else: ddebug("glib thread: new sample (time=%s)." % frame_or_exception.time) with self._condition: self.last_frame = frame_or_exception self._condition.notify_all()
def frames(self, timeout_secs=None): if timeout_secs is not None: end_time = self._time.time() + timeout_secs timestamp = None first = True while True: ddebug("user thread: Getting sample at %s" % self._time.time()) frame = self._display.get_frame( max(10, timeout_secs), since=timestamp) ddebug("user thread: Got sample at %s" % self._time.time()) timestamp = frame.time if not first and timeout_secs is not None and timestamp > end_time: debug("timed out: %.3f > %.3f" % (timestamp, end_time)) return yield frame first = False