replay: support for setting a custom playback speed (#30462)

* support for setting a custom playback speed

* rename to playback speed
pull/30493/head
Dean Lee 1 year ago committed by GitHub
parent 3527c1da67
commit c5f73a748e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      tools/replay/consoleui.cc
  2. 1
      tools/replay/consoleui.h
  3. 6
      tools/replay/main.cc
  4. 6
      tools/replay/replay.cc
  5. 1
      tools/replay/replay.h

@ -29,7 +29,7 @@ const std::initializer_list<std::pair<std::string, std::string>> keyboard_shortc
}, },
{ {
{"enter", "Enter seek request"}, {"enter", "Enter seek request"},
{"x", "+/-Replay speed"}, {"+/-", "Playback speed"},
{"q", "Exit"}, {"q", "Exit"},
}, },
}; };
@ -331,13 +331,18 @@ void ConsoleUI::handleKey(char c) {
refresh(); refresh();
getch_timer.start(1000, this); getch_timer.start(1000, this);
} else if (c == 'x') { } else if (c == '+' || c == '=') {
if (replay->hasFlag(REPLAY_FLAG_FULL_SPEED)) { auto it = std::upper_bound(speed_array.begin(), speed_array.end(), replay->getSpeed());
replay->removeFlag(REPLAY_FLAG_FULL_SPEED); if (it != speed_array.end()) {
rWarning("replay at normal speed"); rWarning("playback speed: %.1fx", *it);
} else { replay->setSpeed(*it);
replay->addFlag(REPLAY_FLAG_FULL_SPEED); }
rWarning("replay at full speed"); } else if (c == '_' || c == '-') {
auto it = std::lower_bound(speed_array.begin(), speed_array.end(), replay->getSpeed());
if (it != speed_array.begin()) {
auto prev = std::prev(it);
rWarning("playback speed: %.1fx", *prev);
replay->setSpeed(*prev);
} }
} else if (c == 'e') { } else if (c == 'e') {
replay->seekToFlag(FindFlag::nextEngagement); replay->seekToFlag(FindFlag::nextEngagement);

@ -16,6 +16,7 @@ class ConsoleUI : public QObject {
public: public:
ConsoleUI(Replay *replay, QObject *parent = 0); ConsoleUI(Replay *replay, QObject *parent = 0);
~ConsoleUI(); ~ConsoleUI();
inline static const std::array speed_array = {0.2f, 0.5f, 1.0f, 2.0f, 3.0f};
private: private:
void initWindows(); void initWindows();

@ -33,6 +33,8 @@ int main(int argc, char *argv[]) {
parser.addOption({{"b", "block"}, "blacklist of services to send", "block"}); parser.addOption({{"b", "block"}, "blacklist of services to send", "block"});
parser.addOption({{"c", "cache"}, "cache <n> segments in memory. default is 5", "n"}); parser.addOption({{"c", "cache"}, "cache <n> segments in memory. default is 5", "n"});
parser.addOption({{"s", "start"}, "start from <seconds>", "seconds"}); parser.addOption({{"s", "start"}, "start from <seconds>", "seconds"});
parser.addOption({"x", QString("playback <speed>. between %1 - %2")
.arg(ConsoleUI::speed_array.front()).arg(ConsoleUI::speed_array.back()), "speed"});
parser.addOption({"demo", "use a demo route instead of providing your own"}); parser.addOption({"demo", "use a demo route instead of providing your own"});
parser.addOption({"data_dir", "local directory with routes", "data_dir"}); parser.addOption({"data_dir", "local directory with routes", "data_dir"});
parser.addOption({"prefix", "set OPENPILOT_PREFIX", "prefix"}); parser.addOption({"prefix", "set OPENPILOT_PREFIX", "prefix"});
@ -67,6 +69,10 @@ int main(int argc, char *argv[]) {
if (!parser.value("c").isEmpty()) { if (!parser.value("c").isEmpty()) {
replay->setSegmentCacheLimit(parser.value("c").toInt()); replay->setSegmentCacheLimit(parser.value("c").toInt());
} }
if (!parser.value("x").isEmpty()) {
replay->setSpeed(std::clamp(parser.value("x").toFloat(),
ConsoleUI::speed_array.front(), ConsoleUI::speed_array.back()));
}
if (!replay->load()) { if (!replay->load()) {
return 0; return 0;
} }

@ -363,7 +363,7 @@ void Replay::publishFrame(const Event *e) {
void Replay::stream() { void Replay::stream() {
cereal::Event::Which cur_which = cereal::Event::Which::INIT_DATA; cereal::Event::Which cur_which = cereal::Event::Which::INIT_DATA;
double prev_replay_speed = 1.0; double prev_replay_speed = speed_;
std::unique_lock lk(stream_lock_); std::unique_lock lk(stream_lock_);
while (true) { while (true) {
@ -398,14 +398,14 @@ void Replay::stream() {
evt_start_ts = cur_mono_time_; evt_start_ts = cur_mono_time_;
loop_start_ts = nanos_since_boot(); loop_start_ts = nanos_since_boot();
prev_replay_speed = speed_; prev_replay_speed = speed_;
} else if (behind_ns > 0 && !hasFlag(REPLAY_FLAG_FULL_SPEED)) { } else if (behind_ns > 0) {
precise_nano_sleep(behind_ns); precise_nano_sleep(behind_ns);
} }
if (!evt->frame) { if (!evt->frame) {
publishMessage(evt); publishMessage(evt);
} else if (camera_server_) { } else if (camera_server_) {
if (hasFlag(REPLAY_FLAG_FULL_SPEED)) { if (speed_ > 1.0) {
camera_server_->waitForSent(); camera_server_->waitForSent();
} }
publishFrame(evt); publishFrame(evt);

@ -27,7 +27,6 @@ enum REPLAY_FLAGS {
REPLAY_FLAG_NO_FILE_CACHE = 0x0020, REPLAY_FLAG_NO_FILE_CACHE = 0x0020,
REPLAY_FLAG_QCAMERA = 0x0040, REPLAY_FLAG_QCAMERA = 0x0040,
REPLAY_FLAG_NO_HW_DECODER = 0x0100, REPLAY_FLAG_NO_HW_DECODER = 0x0100,
REPLAY_FLAG_FULL_SPEED = 0x0200,
REPLAY_FLAG_NO_VIPC = 0x0400, REPLAY_FLAG_NO_VIPC = 0x0400,
REPLAY_FLAG_ALL_SERVICES = 0x0800, REPLAY_FLAG_ALL_SERVICES = 0x0800,
}; };

Loading…
Cancel
Save