replay: cleanup functions (#23655)

* cleanup function seek

* cleanup signals&slots

* use false

* add comment back
pull/23656/head
Dean Lee 3 years ago committed by GitHub
parent 06541abddc
commit 2f91441382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      selfdrive/ui/replay/replay.cc
  2. 6
      selfdrive/ui/replay/replay.h

@ -31,10 +31,6 @@ Replay::Replay(QString route, QStringList allow, QStringList block, SubMaster *s
route_ = std::make_unique<Route>(route, data_dir); route_ = std::make_unique<Route>(route, data_dir);
events_ = std::make_unique<std::vector<Event *>>(); events_ = std::make_unique<std::vector<Event *>>();
new_events_ = std::make_unique<std::vector<Event *>>(); new_events_ = std::make_unique<std::vector<Event *>>();
qRegisterMetaType<FindFlag>("FindFlag");
connect(this, &Replay::seekTo, this, &Replay::doSeek);
connect(this, &Replay::segmentChanged, this, &Replay::queueSegment);
} }
Replay::~Replay() { Replay::~Replay() {
@ -94,13 +90,9 @@ void Replay::updateEvents(const std::function<bool()> &lambda) {
stream_cv_.notify_one(); stream_cv_.notify_one();
} }
void Replay::doSeek(int seconds, bool relative) { void Replay::seekTo(int seconds, bool relative) {
if (segments_.empty()) return; seconds = relative ? seconds + currentSeconds() : seconds;
updateEvents([&]() { updateEvents([&]() {
if (relative) {
seconds += currentSeconds();
}
seconds = std::max(0, seconds); seconds = std::max(0, seconds);
int seg = seconds / 60; int seg = seconds / 60;
if (segments_.find(seg) == segments_.end()) { if (segments_.find(seg) == segments_.end()) {
@ -108,7 +100,7 @@ void Replay::doSeek(int seconds, bool relative) {
return true; return true;
} }
rWarning("seeking to %d s, segment %d", seconds, seg); rInfo("seeking to %d s, segment %d", seconds, seg);
current_segment_ = seg; current_segment_ = seg;
cur_mono_time_ = route_start_ts_ + seconds * 1e9; cur_mono_time_ = route_start_ts_ + seconds * 1e9;
return isSegmentMerged(seg); return isSegmentMerged(seg);
@ -117,23 +109,9 @@ void Replay::doSeek(int seconds, bool relative) {
} }
void Replay::seekToFlag(FindFlag flag) { void Replay::seekToFlag(FindFlag flag) {
if (flag == FindFlag::nextEngagement) { if (auto next = find(flag)) {
rWarning("seeking to the next engagement..."); seekTo(*next - 2, false); // seek to 2 seconds before next
} else if (flag == FindFlag::nextDisEngagement) {
rWarning("seeking to the disengagement...");
} }
updateEvents([&]() {
if (auto next = find(flag)) {
int tm = *next - 2; // seek to 2 seconds before next
cur_mono_time_ = (route_start_ts_ + tm * 1e9);
current_segment_ = currentSeconds() / 60;
} else {
rWarning("seeking failed");
}
return isSegmentMerged(current_segment_);
});
queueSegment();
} }
void Replay::buildTimeline() { void Replay::buildTimeline() {
@ -199,7 +177,7 @@ void Replay::pause(bool pause) {
void Replay::setCurrentSegment(int n) { void Replay::setCurrentSegment(int n) {
if (current_segment_.exchange(n) != n) { if (current_segment_.exchange(n) != n) {
emit segmentChanged(); QMetaObject::invokeMethod(this, &Replay::queueSegment, Qt::QueuedConnection);
} }
} }
@ -419,7 +397,7 @@ void Replay::stream() {
int last_segment = segments_.rbegin()->first; int last_segment = segments_.rbegin()->first;
if (current_segment_ >= last_segment && isSegmentMerged(last_segment)) { if (current_segment_ >= last_segment && isSegmentMerged(last_segment)) {
rInfo("reaches the end of route, restart from beginning"); rInfo("reaches the end of route, restart from beginning");
emit seekTo(0, false); QMetaObject::invokeMethod(this, std::bind(&Replay::seekTo, this, 0, false), Qt::QueuedConnection);
} }
} }
} }

@ -42,6 +42,7 @@ public:
void stop(); void stop();
void pause(bool pause); void pause(bool pause);
void seekToFlag(FindFlag flag); void seekToFlag(FindFlag flag);
void seekTo(int seconds, bool relative);
inline bool isPaused() const { return paused_; } inline bool isPaused() const { return paused_; }
inline bool hasFlag(REPLAY_FLAGS flag) const { return flags_ & flag; } inline bool hasFlag(REPLAY_FLAGS flag) const { return flags_ & flag; }
inline void addFlag(REPLAY_FLAGS flag) { flags_ |= flag; } inline void addFlag(REPLAY_FLAGS flag) { flags_ |= flag; }
@ -57,13 +58,9 @@ public:
} }
signals: signals:
void segmentChanged();
void seekTo(int seconds, bool relative);
void streamStarted(); void streamStarted();
protected slots: protected slots:
void queueSegment();
void doSeek(int seconds, bool relative);
void segmentLoadFinished(bool sucess); void segmentLoadFinished(bool sucess);
protected: protected:
@ -72,6 +69,7 @@ protected:
void startStream(const Segment *cur_segment); void startStream(const Segment *cur_segment);
void stream(); void stream();
void setCurrentSegment(int n); void setCurrentSegment(int n);
void queueSegment();
void mergeSegments(const SegmentMap::iterator &begin, const SegmentMap::iterator &end); void mergeSegments(const SegmentMap::iterator &begin, const SegmentMap::iterator &end);
void updateEvents(const std::function<bool()>& lambda); void updateEvents(const std::function<bool()>& lambda);
void publishMessage(const Event *e); void publishMessage(const Event *e);

Loading…
Cancel
Save