def play(self) -> None: if self.main.current_frame == self.main.current_output.end_frame: return if self.main.statusbar.label.text() == 'Ready': self.main.statusbar.label.setText('Playing') if not self.main.current_output.has_alpha: play_buffer_size = int( min( self.main.PLAY_BUFFER_SIZE, self.main.current_output.end_frame - self.main.current_frame)) self.play_buffer = deque([], play_buffer_size) for i in range(cast(int, self.play_buffer.maxlen)): future = self.main.current_output.vs_output.get_frame_async( int(self.main.current_frame + FrameInterval(i) + FrameInterval(1))) self.play_buffer.appendleft(future) else: play_buffer_size = int( min(self.main.PLAY_BUFFER_SIZE, (self.main.current_output.end_frame - self.main.current_frame) * 2)) # buffer size needs to be even in case alpha is present play_buffer_size -= play_buffer_size % 2 self.play_buffer = deque([], play_buffer_size) for i in range(cast(int, self.play_buffer.maxlen) // 2): frame = (self.main.current_frame + FrameInterval(i) + FrameInterval(1)) future = self.main.current_output.vs_output.get_frame_async( int(frame)) self.play_buffer.appendleft(future) future = self.main.current_output.vs_alpha.get_frame_async( int(frame)) self.play_buffer.appendleft(future) if self.fps_unlimited_checkbox.isChecked() or self.main.DEBUG_PLAY_FPS: self.play_timer.start(0) if self.main.DEBUG_PLAY_FPS: self.play_start_time = debug.perf_counter_ns() self.play_start_frame = self.main.current_frame else: self.fps_timer.start(self.main.FPS_REFRESH_INTERVAL) else: self.play_timer.start( round(1000 / self.main.current_output.play_fps))
def stop(self) -> None: self.play_timer.stop() if self.main.DEBUG_PLAY_FPS and self.play_start_time is not None: self.play_end_time = debug.perf_counter_ns() self.play_end_frame = self.main.current_frame if self.main.statusbar.label.text() == 'Playing': self.main.statusbar.label.setText('Ready') for future in self.play_buffer: future.add_done_callback(lambda future: future.result()) self.play_buffer.clear() self.fps_history.clear() self.fps_timer.stop() if self.main.DEBUG_PLAY_FPS and self.play_start_time is not None: time_interval = ((self.play_end_time - self.play_start_time) / 1_000_000_000) frame_interval = self.play_end_frame - self.play_start_frame logging.debug( f'{time_interval:.3f} s, {frame_interval} frames, {int(frame_interval) / time_interval:.3f} fps') self.play_start_time = None