replay: add flag REPLAY_FLAG_FULL_SPEED to play at full speed (#23324)

* add flag REPLAY_FLAG_FULL_SPEED

* use hasFlag
old-commit-hash: de6126ba06
commatwo_master
Dean Lee 3 years ago committed by GitHub
parent 70b297f5db
commit 9191452120
  1. 8
      selfdrive/ui/replay/main.cc
  2. 13
      selfdrive/ui/replay/replay.cc
  3. 6
      selfdrive/ui/replay/replay.h

@ -65,6 +65,14 @@ void keyboardThread(Replay *replay_) {
replay_->seekTo(-10, true); replay_->seekTo(-10, true);
} else if (c == 'G') { } else if (c == 'G') {
replay_->seekTo(0, true); 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 == ' ') { } else if (c == ' ') {
replay_->pause(!replay_->isPaused()); replay_->pause(!replay_->isPaused());
} }

@ -224,7 +224,7 @@ void Replay::startStream(const Segment *cur_segment) {
camera_size[type] = {fr->width, fr->height}; 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 // start stream thread
stream_thread_ = new QThread(); stream_thread_ = new QThread();
@ -252,8 +252,8 @@ void Replay::publishFrame(const Event *e) {
{cereal::Event::DRIVER_ENCODE_IDX, DriverCam}, {cereal::Event::DRIVER_ENCODE_IDX, DriverCam},
{cereal::Event::WIDE_ROAD_ENCODE_IDX, WideRoadCam}, {cereal::Event::WIDE_ROAD_ENCODE_IDX, WideRoadCam},
}; };
if ((e->which == cereal::Event::DRIVER_ENCODE_IDX && !(flags_ & REPLAY_FLAG_DCAM)) || if ((e->which == cereal::Event::DRIVER_ENCODE_IDX && !hasFlag(REPLAY_FLAG_DCAM)) ||
(e->which == cereal::Event::WIDE_ROAD_ENCODE_IDX && !(flags_ & REPLAY_FLAG_ECAM))) { (e->which == cereal::Event::WIDE_ROAD_ENCODE_IDX && !hasFlag(REPLAY_FLAG_ECAM))) {
return; return;
} }
auto eidx = capnp::AnyStruct::Reader(e->event).getPointerSection()[0].getAs<cereal::EncodeIndex>(); auto eidx = capnp::AnyStruct::Reader(e->event).getPointerSection()[0].getAs<cereal::EncodeIndex>();
@ -314,11 +314,14 @@ void Replay::stream() {
// reset start times // reset start times
evt_start_ts = cur_mono_time_; evt_start_ts = cur_mono_time_;
loop_start_ts = nanos_since_boot(); 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); precise_nano_sleep(behind_ns);
} }
if (evt->frame) { if (evt->frame) {
if (hasFlag(REPLAY_FLAG_FULL_SPEED)) {
camera_server_->waitFinish();
}
publishFrame(evt); publishFrame(evt);
} else { } else {
publishMessage(evt); publishMessage(evt);
@ -328,7 +331,7 @@ void Replay::stream() {
// wait for frame to be sent before unlock.(frameReader may be deleted after unlock) // wait for frame to be sent before unlock.(frameReader may be deleted after unlock)
camera_server_->waitFinish(); 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; int last_segment = segments_.rbegin()->first;
if (current_segment_ >= last_segment && isSegmentMerged(last_segment)) { if (current_segment_ >= last_segment && isSegmentMerged(last_segment)) {
qInfo() << "reaches the end of route, restart from beginning"; qInfo() << "reaches the end of route, restart from beginning";

@ -17,6 +17,7 @@ enum REPLAY_FLAGS {
REPLAY_FLAG_QCAMERA = 0x0040, REPLAY_FLAG_QCAMERA = 0x0040,
REPLAY_FLAG_SEND_YUV = 0x0080, REPLAY_FLAG_SEND_YUV = 0x0080,
REPLAY_FLAG_NO_CUDA = 0x0100, REPLAY_FLAG_NO_CUDA = 0x0100,
REPLAY_FLAG_FULL_SPEED = 0x0200,
}; };
class Replay : public QObject { class Replay : public QObject {
@ -30,6 +31,9 @@ public:
void start(int seconds = 0); void start(int seconds = 0);
void pause(bool pause); void pause(bool pause);
bool isPaused() const { return paused_; } 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: signals:
void segmentChanged(); void segmentChanged();
@ -78,5 +82,5 @@ protected:
std::vector<const char*> sockets_; std::vector<const char*> sockets_;
std::unique_ptr<Route> route_; std::unique_ptr<Route> route_;
std::unique_ptr<CameraServer> camera_server_; std::unique_ptr<CameraServer> camera_server_;
uint32_t flags_ = REPLAY_FLAG_NONE; std::atomic<uint32_t> flags_ = REPLAY_FLAG_NONE;
}; };

Loading…
Cancel
Save