wip not working

pull/34892/head
Trey Moen 5 months ago
parent 78c125d946
commit ea2c4f8be9
  1. 2
      selfdrive/ui/qt/onroad/onroad_home.cc
  2. 6
      selfdrive/ui/qt/onroad/onroad_home.h
  3. 3
      tools/clip/.gitignore
  4. 78
      tools/clip/application.cc
  5. 9
      tools/clip/application.h
  6. 11
      tools/clip/main.cc
  7. 6
      tools/clip/recorder/ffmpeg.cc
  8. 2
      tools/clip/recorder/ffmpeg.h
  9. 6
      tools/clip/recorder/widget.cc
  10. 2
      tools/clip/recorder/widget.h
  11. 2
      tools/replay/replay.cc
  12. 2
      tools/replay/seg_mgr.h

@ -56,7 +56,7 @@ void OnroadWindow::updateState(const UIState &s) {
update();
}
emit drewOnroadFrame(std::make_shared<QPixmap>(std::move(grab())));
emit redrew();
}
void OnroadWindow::offroadTransition(bool offroad) {

@ -10,15 +10,17 @@ public:
OnroadWindow(QWidget* parent = 0);
signals:
void drewOnroadFrame(const std::shared_ptr<QPixmap> &frame);
void redrew();
private:
void paintEvent(QPaintEvent *event);
OnroadAlerts *alerts;
AnnotatedCameraWidget *nvg;
QColor bg = bg_colors[STATUS_DISENGAGED];
QHBoxLayout* split;
protected:
void paintEvent(QPaintEvent *event) override;
private slots:
void offroadTransition(bool offroad);
void updateState(const UIState &s);

@ -1 +1,4 @@
moc_*
*.moc
clip

@ -7,12 +7,53 @@
#include "recorder/widget.h"
Application::Application(int argc, char *argv[]) {
Application::Application(int argc, char *argv[], QObject *parent) : QObject(parent) {
initApp(argc, argv);
app = new QApplication(argc, argv);
QString outputFile = "/Users/trey/Desktop/out.mp4";
QCommandLineParser parser;
parser.setApplicationDescription("Clip your ride!");
parser.addHelpOption();
const QCommandLineOption start({"s", "start"}, "start time", "start");
parser.addOption(start);
const QCommandLineOption output({"o", "output"}, "output file", "output");
parser.addOption(output);
parser.addPositionalArgument("route", "route string");
parser.process(*app);
int startTime = 0;
if (parser.isSet(start)) {
bool ok;
int parsed = parser.value(start).toInt(&ok);
if (!ok) {
qDebug() << "start time must be an integer\n";
fprintf(stderr, "%s", parser.helpText().toStdString().c_str());
exit(1);
}
startTime = parsed;
}
if (!parser.isSet(output)) {
qDebug() << "output is required\n";
fprintf(stderr, "%s", parser.helpText().toStdString().c_str());
exit(1);
}
QString outputFile = parser.value(output);
QString route;
QStringList positionalArgs = parser.positionalArguments();
if (!positionalArgs.isEmpty()) {
route = positionalArgs.at(0);
} else {
qDebug() << "No file specified\n";
fprintf(stderr, "%s", parser.helpText().toStdString().c_str());
exit(1);
}
QTranslator translator;
QString translation_file = QString::fromStdString(Params().get("LanguageSetting"));
@ -25,10 +66,14 @@ Application::Application(int argc, char *argv[]) {
window = new OnroadWindow();
recorderThread = new QThread;
recorder = new Recorder;
recorder = new Recorder(outputFile.toStdString());
recorder->moveToThread(recorderThread);
QObject::connect(recorderThread, &QThread::finished, recorder, &QObject::deleteLater);
QObject::connect(window, &OnroadWindow::drewOnroadFrame, recorder, &Recorder::saveFrame, Qt::QueuedConnection);
QObject::connect(window, &OnroadWindow::redrew, this, [&]() {
recorder->saveFrame(std::make_shared<QPixmap>(std::move(window->grab())));
}, Qt::DirectConnection);
QObject::connect(app, &QCoreApplication::aboutToQuit, recorderThread, &QThread::quit);
window->setAttribute(Qt::WA_DontShowOnScreen);
@ -37,29 +82,28 @@ Application::Application(int argc, char *argv[]) {
recorderThread->start();
// Initialize and start replay
initReplay();
replayThread = QThread::create([this] { startReplay(); });
initReplay(route.toStdString());
replayThread = QThread::create([this, startTime] { startReplay(startTime); });
replayThread->start();
}
void Application::initReplay() {
void Application::initReplay(const std::string& route) {
std::vector<std::string> allow;
std::vector<std::string> block;
replay = std::make_unique<Replay>("a2a0ccea32023010|2023-07-27--13-01-19", allow, block, nullptr,
REPLAY_FLAG_NONE);
replay->setSegmentCacheLimit(10);
replay = std::make_unique<Replay>(route, allow, block, nullptr, REPLAY_FLAG_NONE);
replay->setSegmentCacheLimit(1);
}
void Application::startReplay() {
void Application::startReplay(int start) {
if (!replay || !replay->load()) {
qWarning() << "Failed to load replay";
return;
QApplication::instance()->quit();
}
qInfo() << "Replay started.";
replayRunning = true;
replay->setEndSeconds(120);
replay->start(60);
replay->setEndSeconds(start + 60);
replay->start(start + 2);
replay->waitUntilEnd();
qInfo() << "Replay ended.";
replayRunning = false;
@ -83,10 +127,10 @@ Application::~Application() {
}
int Application::exec() const {
std::this_thread::sleep_for(std::chrono::seconds(3));
// TODO: modify Replay to block until all OnroadWindow required messages have been broadcast at least once
std::this_thread::sleep_for(std::chrono::seconds(5));
setMainWindow(window);
app->exec();
return 0;
return app->exec();
}

@ -6,16 +6,17 @@
#include "recorder/widget.h"
class Application {
class Application : public QObject {
Q_OBJECT
public:
Application(int argc, char* argv[]);
Application(int argc, char* argv[], QObject *parent = nullptr);
~Application();
int exec() const;
void close() const;
private:
void initReplay();
void startReplay();
void initReplay(const std::string& route);
void startReplay(int start = 0);
QApplication *app;
QThread *recorderThread = nullptr;

@ -2,11 +2,10 @@
#include "application.h"
int main(int argc, char *argv[]) {
#ifdef __APPLE__
// With all sockets opened, we might hit the default limit of 256 on macOS
util::set_file_descriptor_limit(1024);
#endif
Application a(argc, argv);
if (a.exec()) {
std::cerr << "Failed to start app." << std::endl;
}
return 0;
return a.exec();
}

@ -1,9 +1,9 @@
#include "tools/clip/recorder/ffmpeg.h"
#include <QDebug>
FFmpegEncoder::FFmpegEncoder(const QString& outputFile, int width, int height, int fps) {
FFmpegEncoder::FFmpegEncoder(const std::string& outputFile, int width, int height, int fps) {
// Allocate output context
if (avformat_alloc_output_context2(&format_ctx, nullptr, nullptr, outputFile.toStdString().c_str()) < 0) {
if (avformat_alloc_output_context2(&format_ctx, nullptr, nullptr, outputFile.c_str()) < 0) {
return;
}
@ -60,7 +60,7 @@ FFmpegEncoder::FFmpegEncoder(const QString& outputFile, int width, int height, i
// Open output file
if (!(format_ctx->oformat->flags & AVFMT_NOFILE)) {
if (avio_open(&format_ctx->pb, outputFile.toStdString().c_str(), AVIO_FLAG_WRITE) < 0) {
if (avio_open(&format_ctx->pb, outputFile.c_str(), AVIO_FLAG_WRITE) < 0) {
return;
}
}

@ -11,7 +11,7 @@ extern "C" {
class FFmpegEncoder {
public:
FFmpegEncoder(const QString& outputFile, int width, int height, int fps);
FFmpegEncoder(const std::string& outputFile, int width, int height, int fps);
~FFmpegEncoder();
bool writeFrame(const QImage& image);

@ -2,8 +2,8 @@
#include "tools/clip/recorder/ffmpeg.h"
Recorder::Recorder(QObject *parent) : QObject(parent) {
encoder = new FFmpegEncoder("/Users/trey/Desktop/out.mp4", DEVICE_SCREEN_SIZE.width(), DEVICE_SCREEN_SIZE.height(), UI_FREQ);
Recorder::Recorder(const std::string& outputFile, QObject *parent) : QObject(parent) {
encoder = new FFmpegEncoder(outputFile, DEVICE_SCREEN_SIZE.width(), DEVICE_SCREEN_SIZE.height(), UI_FREQ);
}
Recorder::~Recorder() {
@ -12,7 +12,7 @@ Recorder::~Recorder() {
void Recorder::saveFrame(const std::shared_ptr<QPixmap> &frame) {
QMutexLocker locker(&mutex);
frameQueue.enqueue(frame); // Add frame to queue
frameQueue.enqueue(frame);
if (!isProcessing) {
isProcessing = true;
QMetaObject::invokeMethod(this, &Recorder::processQueue, Qt::QueuedConnection);

@ -12,7 +12,7 @@ class Recorder : public QObject {
Q_OBJECT
public:
Recorder(QObject *parent = nullptr);
Recorder(const std::string& outputFile, QObject *parent = nullptr);
~Recorder() override;
public slots:

@ -215,8 +215,6 @@ void Replay::startStream(const std::shared_ptr<Segment> segment) {
}
void Replay::publishMessage(const Event *e) {
if (event_filter_ && event_filter_(e)) return;
if (!sm_) {
auto bytes = e->data.asBytes();
int ret = pm_->send(sockets_[e->which], (capnp::byte *)bytes.begin(), bytes.size());

@ -20,7 +20,7 @@ public:
bool isSegmentLoaded(int n) const { return segments.find(n) != segments.end(); }
};
SegmentManager(const std::string &route_name, uint32_t flags, const std::string &data_dir = "/tmp/clip")
SegmentManager(const std::string &route_name, uint32_t flags, const std::string &data_dir = "")
: flags_(flags), route_(route_name, data_dir), event_data_(std::make_shared<EventData>()) {}
~SegmentManager();

Loading…
Cancel
Save