Skip to content

Commit

Permalink
Fix calculation for when to send a keepalive image. Possible fixes #4101
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor committed Aug 13, 2024
1 parent 7aa473b commit 5237641
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/zm_eventstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,12 +940,13 @@ void EventStream::runStream() {
Microseconds delta = Microseconds(0);

while (!zm_terminate) {
start = std::chrono::steady_clock::now();
now = start = std::chrono::steady_clock::now();

{
std::scoped_lock lck{mutex};

send_frame = false;
TimePoint::duration time_since_last_send = now - last_frame_sent;

if (!paused) {
// Figure out if we should send this frame
Expand All @@ -964,16 +965,22 @@ void EventStream::runStream() {
send_frame = true;
} else if (!send_frame) {
// We are paused, not stepping and doing nothing, meaning that comms didn't set send_frame to true
if (now - last_frame_sent > MAX_STREAM_DELAY) {
if (time_since_last_send > MAX_STREAM_DELAY) {
// Send keepalive
Debug(2, "Sending keepalive frame");
send_frame = true;
} else {
Debug(4, "Not Sending keepalive frame now %.2f - %.2f last = %.2f > Max %.2f",
FPSeconds(now.time_since_epoch()).count(),
FPSeconds(last_frame_sent.time_since_epoch()).count(),
FPSeconds(time_since_last_send).count(),
FPSeconds(MAX_STREAM_DELAY).count()
);
}
} // end if streaming stepping or doing nothing

// time_to_event > 0 means that we are not in the event
if (time_to_event > Seconds(0) and mode == MODE_ALL) {
TimePoint::duration time_since_last_send = now - last_frame_sent;
Debug(1, "Time since last send = %.2f s", FPSeconds(time_since_last_send).count());
if (time_since_last_send > Seconds(1)) {
char frame_text[64];
Expand Down Expand Up @@ -1069,8 +1076,7 @@ void EventStream::runStream() {
base_fps,
effective_fps);
}
now = std::chrono::steady_clock::now();
TimePoint::duration elapsed = now - start;
TimePoint::duration elapsed = std::chrono::steady_clock::now() - start;
delta -= std::chrono::duration_cast<Microseconds>(elapsed); // sending frames takes time, so remove it from the sleep time

Debug(2, "New delta: %fs from last frame offset %fs - next_frame_offset %fs - elapsed %fs",
Expand Down

0 comments on commit 5237641

Please sign in to comment.