Skip to content

Commit

Permalink
Add option to not have any delays between anim/movie frames.
Browse files Browse the repository at this point in the history
Not advertised in synopsis, this is mostly useful to create
canned terminal outputs, but not useful enough to warrant
confusing users.
  • Loading branch information
hzeller committed Mar 28, 2021
1 parent 370a18e commit 59a2bd9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/buffered-write-sequencer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ struct BufferedWriteSequencer::MemBlock {
};

BufferedWriteSequencer::BufferedWriteSequencer(
int fd, bool allow_frame_skip, int max_queu_len,
int fd, bool allow_frame_skip, int max_queu_len, bool debug_no_frame_delay,
const volatile sig_atomic_t &interrupt_received)
: fd_(fd), allow_frame_skipping_(allow_frame_skip),
max_queue_len_(max_queu_len),
debug_no_frame_delay_(debug_no_frame_delay),
interrupt_received_(interrupt_received),
work_executor_(new std::thread(&BufferedWriteSequencer::ProcessQueue,
this)) {
Expand Down Expand Up @@ -144,7 +145,8 @@ void BufferedWriteSequencer::ProcessQueue() {
static constexpr Duration kAllowedSkew = Duration::Millis(250);
do_skip = (allow_frame_skipping_ &&
finish_time + kAllowedSkew < Time::Now());
finish_time.WaitUntil();
if (!debug_no_frame_delay_)
finish_time.WaitUntil();
}
break;
case SeqType::FrameImmediate:
Expand Down
5 changes: 4 additions & 1 deletion src/buffered-write-sequencer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ class BufferedWriteSequencer {
// filedescriptor "fd". The "allow_frame_skipping" tells the sequencer
// if it is ok to skip frames that can't be shown in time anymore.
// The "max_queue_len" determines the number of the queued-up requests.
// If "debug_no_frame_delay" is set, frames are written as fast as possible
// without time between frames.
//
// Writes that are still pending when the "interrupt_received" flag
// is set externally (e.g. through a signal handler) are discarded to
// finish quickly (except ControlWrite calls).
BufferedWriteSequencer(int fd, bool allow_frame_skipping,
int max_queue_len,
int max_queue_len, bool debug_no_frame_delay,
const volatile sig_atomic_t &interrupt_received);
~BufferedWriteSequencer();

Expand Down Expand Up @@ -119,6 +121,7 @@ class BufferedWriteSequencer {
const int fd_;
const bool allow_frame_skipping_;
const size_t max_queue_len_;
const bool debug_no_frame_delay_;
const volatile sig_atomic_t &interrupt_received_;

// Work queue
Expand Down
7 changes: 7 additions & 0 deletions src/timg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ int main(int argc, char *argv[]) {
int thread_count = kDefaultThreadCount;
int geometry_width = (term.cols - 2);
int geometry_height = (term.rows - 2);
bool debug_no_frame_delay = false;

// Convenience predicate: pixelation sending high-res images, no blocks.
const auto is_pixel_direct_p = [](Pixelation p) {
Expand All @@ -326,6 +327,7 @@ int main(int argc, char *argv[]) {
OPT_CLEAR_SCREEN = 1000,
OPT_COLOR_256,
OPT_COMPRESS_PIXEL,
OPT_DEBUG_NO_FRAME_DELAY,
OPT_FRAME_COUNT,
OPT_FRAME_OFFSET,
OPT_GRID,
Expand All @@ -345,6 +347,7 @@ int main(int argc, char *argv[]) {
{ "color8", no_argument, NULL, OPT_COLOR_256 },
{ "compress", no_argument, NULL, OPT_COMPRESS_PIXEL },
{ "delta-move", required_argument, NULL, 'd' },
{ "debug-no-frame-delay", no_argument, NULL, OPT_DEBUG_NO_FRAME_DELAY },
{ "experimental-frame-offset",required_argument, NULL, OPT_FRAME_OFFSET },
{ "fit-width", no_argument, NULL, 'W' },
{ "frames", required_argument, NULL, OPT_FRAME_COUNT },
Expand Down Expand Up @@ -555,6 +558,9 @@ int main(int argc, char *argv[]) {
case OPT_VERBOSE:
verbose = true;
break;
case OPT_DEBUG_NO_FRAME_DELAY:
debug_no_frame_delay = true;
break;
case 'h':
default:
return usage(argv[0], (opt == 'h'
Expand Down Expand Up @@ -760,6 +766,7 @@ int main(int argc, char *argv[]) {
timg::BufferedWriteSequencer sequencer(output_fd,
buffer_allow_skipping,
kAsyncWriteQueueSize,
debug_no_frame_delay,
interrupt_received);
const Time start_show = Time::Now();
PresentImages(loaded_sources, display_opts, present, &sequencer);
Expand Down

0 comments on commit 59a2bd9

Please sign in to comment.