Skip to content

Commit

Permalink
replay: Update video immediately after seek when paused. (#34237)
Browse files Browse the repository at this point in the history
replay: Update video immediately after seeking when paused.

Otherwise, if paused then have to resume playback for the video
frame to update and show the new location.

Implemented by temporarily un-pausing replay for a single
frame time.
  • Loading branch information
projectgus authored Dec 20, 2024
1 parent ce4ebbd commit 3363881
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tools/replay/replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void Replay::interruptStream(const std::function<bool()> &update_fn) {
interrupt_requested_ = true;
std::unique_lock lock(stream_lock_);
events_ready_ = update_fn();
interrupt_requested_ = user_paused_;
interrupt_requested_ = user_paused_ && !pause_after_next_frame_;
}
stream_cv_.notify_one();
}
Expand All @@ -116,6 +116,9 @@ void Replay::seekTo(double seconds, bool relative) {
seeked_to_sec = *seeking_to_;
seeking_to_.reset();
}

// if paused, resume for exactly one frame to update
pause_after_next_frame_ = user_paused_;
return false;
});

Expand Down Expand Up @@ -144,6 +147,7 @@ void Replay::pause(bool pause) {
interruptStream([=]() {
rWarning("%s at %.2f s", pause ? "paused..." : "resuming", currentSeconds());
user_paused_ = pause;
pause_after_next_frame_ = false;
return !pause;
});
}
Expand Down Expand Up @@ -305,6 +309,7 @@ std::vector<Event>::const_iterator Replay::publishEvents(std::vector<Event>::con
uint64_t evt_start_ts = cur_mono_time_;
uint64_t loop_start_ts = nanos_since_boot();
double prev_replay_speed = speed_;
uint64_t first_mono_time = first->mono_time;

for (; !interrupt_requested_ && first != last; ++first) {
const Event &evt = *first;
Expand Down Expand Up @@ -343,6 +348,12 @@ std::vector<Event>::const_iterator Replay::publishEvents(std::vector<Event>::con
}
publishFrame(&evt);
}

const auto T_ONE_FRAME = 0.050;
if (pause_after_next_frame_ && abs(toSeconds(evt.mono_time) - toSeconds(first_mono_time)) > T_ONE_FRAME) {
pause_after_next_frame_ = false;
interrupt_requested_ = true;
}
}

return first;
Expand Down
1 change: 1 addition & 0 deletions tools/replay/replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Replay {
std::thread stream_thread_;
std::mutex stream_lock_;
bool user_paused_ = false;
bool pause_after_next_frame_ = false;
std::condition_variable stream_cv_;
int current_segment_ = 0;
std::optional<double> seeking_to_;
Expand Down

0 comments on commit 3363881

Please sign in to comment.