mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-07-08 22:42:05 +08:00
replay: add flag REPLAY_FLAG_FULL_SPEED to play at full speed (#23324)
* add flag REPLAY_FLAG_FULL_SPEED * use hasFlag
This commit is contained in:
@@ -65,6 +65,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());
|
||||
}
|
||||
|
||||
@@ -224,7 +224,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();
|
||||
@@ -252,8 +252,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>();
|
||||
@@ -314,11 +314,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);
|
||||
@@ -328,7 +331,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";
|
||||
|
||||
@@ -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 {
|
||||
@@ -30,6 +31,9 @@ public:
|
||||
void start(int seconds = 0);
|
||||
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();
|
||||
@@ -78,5 +82,5 @@ protected:
|
||||
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user