mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 22:23:56 +08:00
replay: pause/resume using spacebar (#22278)
* pause/resume using spacebar * Update selfdrive/ui/replay/replay.cc Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user