replay: pause/resume using spacebar (#22278)

* pause/resume using spacebar

* Update selfdrive/ui/replay/replay.cc

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
pull/21273/head
Dean Lee 4 years ago committed by GitHub
parent 9b302488f9
commit ec67d2b8f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      selfdrive/ui/replay/main.cc
  2. 10
      selfdrive/ui/replay/replay.cc
  3. 4
      selfdrive/ui/replay/replay.h

@ -55,6 +55,8 @@ void keyboardThread(Replay *replay) {
replay->relativeSeek(-10);
} else if (c == 'G') {
replay->relativeSeek(0);
} else if (c == ' ') {
replay->pause(!replay->isPaused());
}
}
}

@ -66,6 +66,15 @@ void Replay::relativeSeek(int seconds) {
seekTo(current_ts + seconds);
}
void Replay::pause(bool pause) {
updating_events = true;
std::unique_lock lk(lock);
qDebug() << (pause ? "paused..." : "resuming");
paused_ = pause;
updating_events = false;
stream_cv_.notify_one();
}
void Replay::setCurrentSegment(int n) {
if (current_segment.exchange(n) != n) {
emit segmentChanged(n);
@ -160,6 +169,7 @@ void Replay::stream() {
while (true) {
std::unique_lock lk(lock);
stream_cv_.wait(lk, [=]() { return paused_ == false; });
uint64_t evt_start_ts = seek_ts != -1 ? route_start_ts + (seek_ts * 1e9) : cur_mono_time;
Event cur_event(cur_which, evt_start_ts);

@ -20,6 +20,8 @@ public:
void start(int seconds = 0);
void relativeSeek(int seconds);
void seekTo(int seconds);
void pause(bool pause);
bool isPaused() const { return paused_; }
signals:
void segmentChanged(int);
@ -42,6 +44,8 @@ protected:
// logs
std::mutex lock;
bool paused_ = false;
std::condition_variable stream_cv_;
std::atomic<bool> updating_events = false;
std::vector<Event *> *events = nullptr;
std::unordered_map<uint32_t, EncodeIdx> *eidx = nullptr;

Loading…
Cancel
Save