Skip to content

Commit 5237641

Browse files
Fix calculation for when to send a keepalive image. Possible fixes #4101
1 parent 7aa473b commit 5237641

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/zm_eventstream.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -940,12 +940,13 @@ void EventStream::runStream() {
940940
Microseconds delta = Microseconds(0);
941941

942942
while (!zm_terminate) {
943-
start = std::chrono::steady_clock::now();
943+
now = start = std::chrono::steady_clock::now();
944944

945945
{
946946
std::scoped_lock lck{mutex};
947947

948948
send_frame = false;
949+
TimePoint::duration time_since_last_send = now - last_frame_sent;
949950

950951
if (!paused) {
951952
// Figure out if we should send this frame
@@ -964,16 +965,22 @@ void EventStream::runStream() {
964965
send_frame = true;
965966
} else if (!send_frame) {
966967
// We are paused, not stepping and doing nothing, meaning that comms didn't set send_frame to true
967-
if (now - last_frame_sent > MAX_STREAM_DELAY) {
968+
if (time_since_last_send > MAX_STREAM_DELAY) {
968969
// Send keepalive
969970
Debug(2, "Sending keepalive frame");
970971
send_frame = true;
972+
} else {
973+
Debug(4, "Not Sending keepalive frame now %.2f - %.2f last = %.2f > Max %.2f",
974+
FPSeconds(now.time_since_epoch()).count(),
975+
FPSeconds(last_frame_sent.time_since_epoch()).count(),
976+
FPSeconds(time_since_last_send).count(),
977+
FPSeconds(MAX_STREAM_DELAY).count()
978+
);
971979
}
972980
} // end if streaming stepping or doing nothing
973981

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

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

0 commit comments

Comments
 (0)