replay: Update video immediately after seek when paused. (#34237)

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.
pull/34296/head
Angus Gratton 4 months ago committed by GitHub
parent ce4ebbde64
commit 3363881844
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      tools/replay/replay.cc
  2. 1
      tools/replay/replay.h

@ -89,7 +89,7 @@ void Replay::interruptStream(const std::function<bool()> &update_fn) {
interrupt_requested_ = true; interrupt_requested_ = true;
std::unique_lock lock(stream_lock_); std::unique_lock lock(stream_lock_);
events_ready_ = update_fn(); events_ready_ = update_fn();
interrupt_requested_ = user_paused_; interrupt_requested_ = user_paused_ && !pause_after_next_frame_;
} }
stream_cv_.notify_one(); stream_cv_.notify_one();
} }
@ -116,6 +116,9 @@ void Replay::seekTo(double seconds, bool relative) {
seeked_to_sec = *seeking_to_; seeked_to_sec = *seeking_to_;
seeking_to_.reset(); seeking_to_.reset();
} }
// if paused, resume for exactly one frame to update
pause_after_next_frame_ = user_paused_;
return false; return false;
}); });
@ -144,6 +147,7 @@ void Replay::pause(bool pause) {
interruptStream([=]() { interruptStream([=]() {
rWarning("%s at %.2f s", pause ? "paused..." : "resuming", currentSeconds()); rWarning("%s at %.2f s", pause ? "paused..." : "resuming", currentSeconds());
user_paused_ = pause; user_paused_ = pause;
pause_after_next_frame_ = false;
return !pause; return !pause;
}); });
} }
@ -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 evt_start_ts = cur_mono_time_;
uint64_t loop_start_ts = nanos_since_boot(); uint64_t loop_start_ts = nanos_since_boot();
double prev_replay_speed = speed_; double prev_replay_speed = speed_;
uint64_t first_mono_time = first->mono_time;
for (; !interrupt_requested_ && first != last; ++first) { for (; !interrupt_requested_ && first != last; ++first) {
const Event &evt = *first; const Event &evt = *first;
@ -343,6 +348,12 @@ std::vector<Event>::const_iterator Replay::publishEvents(std::vector<Event>::con
} }
publishFrame(&evt); 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; return first;

@ -85,6 +85,7 @@ private:
std::thread stream_thread_; std::thread stream_thread_;
std::mutex stream_lock_; std::mutex stream_lock_;
bool user_paused_ = false; bool user_paused_ = false;
bool pause_after_next_frame_ = false;
std::condition_variable stream_cv_; std::condition_variable stream_cv_;
int current_segment_ = 0; int current_segment_ = 0;
std::optional<double> seeking_to_; std::optional<double> seeking_to_;

Loading…
Cancel
Save