mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-24 07:22:04 +08:00
replay: cleanup functions (#23655)
* cleanup function seek * cleanup signals&slots * use false * add comment back
This commit is contained in:
@@ -31,10 +31,6 @@ Replay::Replay(QString route, QStringList allow, QStringList block, SubMaster *s
|
||||
route_ = std::make_unique<Route>(route, data_dir);
|
||||
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() {
|
||||
@@ -94,13 +90,9 @@ void Replay::updateEvents(const std::function<bool()> &lambda) {
|
||||
stream_cv_.notify_one();
|
||||
}
|
||||
|
||||
void Replay::doSeek(int seconds, bool relative) {
|
||||
if (segments_.empty()) return;
|
||||
|
||||
void Replay::seekTo(int seconds, bool relative) {
|
||||
seconds = relative ? seconds + currentSeconds() : seconds;
|
||||
updateEvents([&]() {
|
||||
if (relative) {
|
||||
seconds += currentSeconds();
|
||||
}
|
||||
seconds = std::max(0, seconds);
|
||||
int seg = seconds / 60;
|
||||
if (segments_.find(seg) == segments_.end()) {
|
||||
@@ -108,7 +100,7 @@ void Replay::doSeek(int seconds, bool relative) {
|
||||
return true;
|
||||
}
|
||||
|
||||
rWarning("seeking to %d s, segment %d", seconds, seg);
|
||||
rInfo("seeking to %d s, segment %d", seconds, seg);
|
||||
current_segment_ = seg;
|
||||
cur_mono_time_ = route_start_ts_ + seconds * 1e9;
|
||||
return isSegmentMerged(seg);
|
||||
@@ -117,23 +109,9 @@ void Replay::doSeek(int seconds, bool relative) {
|
||||
}
|
||||
|
||||
void Replay::seekToFlag(FindFlag flag) {
|
||||
if (flag == FindFlag::nextEngagement) {
|
||||
rWarning("seeking to the next engagement...");
|
||||
} else if (flag == FindFlag::nextDisEngagement) {
|
||||
rWarning("seeking to the disengagement...");
|
||||
if (auto next = find(flag)) {
|
||||
seekTo(*next - 2, false); // seek to 2 seconds before next
|
||||
}
|
||||
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() {
|
||||
@@ -199,7 +177,7 @@ void Replay::pause(bool pause) {
|
||||
|
||||
void Replay::setCurrentSegment(int 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;
|
||||
if (current_segment_ >= last_segment && isSegmentMerged(last_segment)) {
|
||||
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 pause(bool pause);
|
||||
void seekToFlag(FindFlag flag);
|
||||
void seekTo(int seconds, bool relative);
|
||||
inline bool isPaused() const { return paused_; }
|
||||
inline bool hasFlag(REPLAY_FLAGS flag) const { return flags_ & flag; }
|
||||
inline void addFlag(REPLAY_FLAGS flag) { flags_ |= flag; }
|
||||
@@ -57,13 +58,9 @@ public:
|
||||
}
|
||||
|
||||
signals:
|
||||
void segmentChanged();
|
||||
void seekTo(int seconds, bool relative);
|
||||
void streamStarted();
|
||||
|
||||
protected slots:
|
||||
void queueSegment();
|
||||
void doSeek(int seconds, bool relative);
|
||||
void segmentLoadFinished(bool sucess);
|
||||
|
||||
protected:
|
||||
@@ -72,6 +69,7 @@ protected:
|
||||
void startStream(const Segment *cur_segment);
|
||||
void stream();
|
||||
void setCurrentSegment(int n);
|
||||
void queueSegment();
|
||||
void mergeSegments(const SegmentMap::iterator &begin, const SegmentMap::iterator &end);
|
||||
void updateEvents(const std::function<bool()>& lambda);
|
||||
void publishMessage(const Event *e);
|
||||
|
||||
Reference in New Issue
Block a user