Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions selfdrive/ui/replay/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ void keyboardThread(Replay *replay_) {
replay_->seekTo(-10, true);
} else if (c == 'G') {
replay_->seekTo(0, true);
} else if (c == 'x') {
if (replay_->hasFlag(REPLAY_FLAG_FULL_SPEED)) {
replay_->removeFlag(REPLAY_FLAG_FULL_SPEED);
qInfo() << "replay at normal speed";
} else {
replay_->addFlag(REPLAY_FLAG_FULL_SPEED);
qInfo() << "replay at full speed";
}
} else if (c == ' ') {
replay_->pause(!replay_->isPaused());
}
Expand Down
13 changes: 8 additions & 5 deletions selfdrive/ui/replay/replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void Replay::startStream(const Segment *cur_segment) {
camera_size[type] = {fr->width, fr->height};
}
}
camera_server_ = std::make_unique<CameraServer>(camera_size, flags_ & REPLAY_FLAG_SEND_YUV);
camera_server_ = std::make_unique<CameraServer>(camera_size, hasFlag(REPLAY_FLAG_SEND_YUV));

// start stream thread
stream_thread_ = new QThread();
Expand Down Expand Up @@ -256,8 +256,8 @@ void Replay::publishFrame(const Event *e) {
{cereal::Event::DRIVER_ENCODE_IDX, DriverCam},
{cereal::Event::WIDE_ROAD_ENCODE_IDX, WideRoadCam},
};
if ((e->which == cereal::Event::DRIVER_ENCODE_IDX && !(flags_ & REPLAY_FLAG_DCAM)) ||
(e->which == cereal::Event::WIDE_ROAD_ENCODE_IDX && !(flags_ & REPLAY_FLAG_ECAM))) {
if ((e->which == cereal::Event::DRIVER_ENCODE_IDX && !hasFlag(REPLAY_FLAG_DCAM)) ||
(e->which == cereal::Event::WIDE_ROAD_ENCODE_IDX && !hasFlag(REPLAY_FLAG_ECAM))) {
return;
}
auto eidx = capnp::AnyStruct::Reader(e->event).getPointerSection()[0].getAs<cereal::EncodeIndex>();
Expand Down Expand Up @@ -318,11 +318,14 @@ void Replay::stream() {
// reset start times
evt_start_ts = cur_mono_time_;
loop_start_ts = nanos_since_boot();
} else if (behind_ns > 0) {
} else if (behind_ns > 0 && !hasFlag(REPLAY_FLAG_FULL_SPEED)) {
precise_nano_sleep(behind_ns);
}

if (evt->frame) {
if (hasFlag(REPLAY_FLAG_FULL_SPEED)) {
camera_server_->waitFinish();
}
publishFrame(evt);
} else {
publishMessage(evt);
Expand All @@ -332,7 +335,7 @@ void Replay::stream() {
// wait for frame to be sent before unlock.(frameReader may be deleted after unlock)
camera_server_->waitFinish();

if (eit == events_->end() && !(flags_ & REPLAY_FLAG_NO_LOOP)) {
if (eit == events_->end() && !hasFlag(REPLAY_FLAG_NO_LOOP)) {
int last_segment = segments_.rbegin()->first;
if (current_segment_ >= last_segment && isSegmentMerged(last_segment)) {
qInfo() << "reaches the end of route, restart from beginning";
Expand Down
6 changes: 5 additions & 1 deletion selfdrive/ui/replay/replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum REPLAY_FLAGS {
REPLAY_FLAG_QCAMERA = 0x0040,
REPLAY_FLAG_SEND_YUV = 0x0080,
REPLAY_FLAG_NO_CUDA = 0x0100,
REPLAY_FLAG_FULL_SPEED = 0x0200,
};

class Replay : public QObject {
Expand All @@ -31,6 +32,9 @@ class Replay : public QObject {
void stop();
void pause(bool pause);
bool isPaused() const { return paused_; }
inline bool hasFlag(REPLAY_FLAGS flag) const { return flags_ & flag; }
inline void addFlag(REPLAY_FLAGS flag) { flags_ |= flag; }
inline void removeFlag(REPLAY_FLAGS flag) { flags_ &= ~flag; }

signals:
void segmentChanged();
Expand Down Expand Up @@ -79,5 +83,5 @@ protected slots:
std::vector<const char*> sockets_;
std::unique_ptr<Route> route_;
std::unique_ptr<CameraServer> camera_server_;
uint32_t flags_ = REPLAY_FLAG_NONE;
std::atomic<uint32_t> flags_ = REPLAY_FLAG_NONE;
};