mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 18:53:55 +08:00
UI: don't block UI on vipc recv (#22644)
* UI: don't block UI on vipc recv
* use a timer
* move that
old-commit-hash: c4de1fef4f
This commit is contained in:
@@ -114,7 +114,7 @@ if arch in ['x86_64', 'Darwin'] and os.path.exists(Dir("#tools/").get_abspath())
|
||||
replay_libs = [replay_lib, 'avutil', 'avcodec', 'avformat', 'bz2', 'curl', 'yuv'] + qt_libs
|
||||
qt_env.Program("replay/replay", ["replay/main.cc"], LIBS=replay_libs)
|
||||
|
||||
qt_env.Program("watch3", ["watch3.cc"], LIBS=qt_libs)
|
||||
qt_env.Program("watch3", ["watch3.cc"], LIBS=qt_libs + ['common', 'json11'])
|
||||
|
||||
if GetOption('test'):
|
||||
qt_env.Program('replay/tests/test_replay', ['replay/tests/test_runner.cc', 'replay/tests/test_replay.cc'], LIBS=[replay_libs])
|
||||
|
||||
@@ -18,7 +18,6 @@ OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent) {
|
||||
main_layout->addLayout(stacked_layout);
|
||||
|
||||
nvg = new NvgWindow(VISION_STREAM_RGB_BACK, this);
|
||||
QObject::connect(this, &OnroadWindow::updateStateSignal, nvg, &NvgWindow::updateState);
|
||||
|
||||
QWidget * split_wrapper = new QWidget;
|
||||
split = new QHBoxLayout(split_wrapper);
|
||||
@@ -179,18 +178,7 @@ void NvgWindow::initializeGL() {
|
||||
|
||||
ui_nvg_init(&QUIState::ui_state);
|
||||
prev_draw_t = millis_since_boot();
|
||||
}
|
||||
|
||||
void NvgWindow::updateState(const UIState &s) {
|
||||
// TODO: make camerad startup faster then remove this
|
||||
if (s.scene.started) {
|
||||
if (isVisible() != vipc_client->connected) {
|
||||
setVisible(vipc_client->connected);
|
||||
}
|
||||
if (!isVisible()) {
|
||||
updateFrame();
|
||||
}
|
||||
}
|
||||
setBackgroundColor(bg_colors[STATUS_DISENGAGED]);
|
||||
}
|
||||
|
||||
void NvgWindow::paintGL() {
|
||||
|
||||
@@ -30,7 +30,6 @@ class NvgWindow : public CameraViewWidget {
|
||||
|
||||
public:
|
||||
explicit NvgWindow(VisionStreamType type, QWidget* parent = 0) : CameraViewWidget(type, true, parent) {}
|
||||
void updateState(const UIState &s);
|
||||
|
||||
protected:
|
||||
void paintGL() override;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "selfdrive/ui/qt/widgets/cameraview.h"
|
||||
|
||||
#include "selfdrive/common/swaglog.h"
|
||||
|
||||
namespace {
|
||||
|
||||
const char frame_vertex_shader[] =
|
||||
@@ -96,7 +94,10 @@ mat4 get_fit_view_transform(float widget_aspect_ratio, float frame_aspect_ratio)
|
||||
CameraViewWidget::CameraViewWidget(VisionStreamType stream_type, bool zoom, QWidget* parent) :
|
||||
stream_type(stream_type), zoomed_view(zoom), QOpenGLWidget(parent) {
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
connect(this, &QOpenGLWidget::frameSwapped, this, &CameraViewWidget::updateFrame);
|
||||
|
||||
QTimer *t = new QTimer(this);
|
||||
connect(t, &QTimer::timeout, this, &CameraViewWidget::updateFrame);
|
||||
t->start(1000 / UI_FREQ);
|
||||
}
|
||||
|
||||
CameraViewWidget::~CameraViewWidget() {
|
||||
@@ -173,6 +174,10 @@ void CameraViewWidget::setStreamType(VisionStreamType type) {
|
||||
}
|
||||
}
|
||||
|
||||
void CameraViewWidget::setBackgroundColor(QColor color) {
|
||||
bg = color;
|
||||
}
|
||||
|
||||
void CameraViewWidget::updateFrameMat(int w, int h) {
|
||||
if (zoomed_view) {
|
||||
if (stream_type == VISION_STREAM_RGB_FRONT) {
|
||||
@@ -204,7 +209,7 @@ void CameraViewWidget::updateFrameMat(int w, int h) {
|
||||
|
||||
void CameraViewWidget::paintGL() {
|
||||
if (!latest_frame) {
|
||||
glClearColor(0, 0, 0, 1.0);
|
||||
glClearColor(bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF());
|
||||
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
return;
|
||||
}
|
||||
@@ -233,6 +238,10 @@ void CameraViewWidget::paintGL() {
|
||||
}
|
||||
|
||||
void CameraViewWidget::updateFrame() {
|
||||
if (!isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!vipc_client->connected) {
|
||||
makeCurrent();
|
||||
if (vipc_client->connect(false)) {
|
||||
@@ -257,17 +266,11 @@ void CameraViewWidget::updateFrame() {
|
||||
|
||||
VisionBuf *buf = nullptr;
|
||||
if (vipc_client->connected) {
|
||||
buf = vipc_client->recv();
|
||||
buf = vipc_client->recv(nullptr, 0);
|
||||
if (buf != nullptr) {
|
||||
latest_frame = buf;
|
||||
update();
|
||||
emit frameUpdated();
|
||||
} else {
|
||||
LOGE("visionIPC receive timeout");
|
||||
}
|
||||
}
|
||||
if (buf == nullptr && isVisible()) {
|
||||
// try to connect or recv again
|
||||
QTimer::singleShot(1000. / UI_FREQ, this, &CameraViewWidget::updateFrame);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
explicit CameraViewWidget(VisionStreamType stream_type, bool zoom, QWidget* parent = nullptr);
|
||||
~CameraViewWidget();
|
||||
void setStreamType(VisionStreamType type);
|
||||
void setBackgroundColor(QColor color);
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
@@ -45,4 +46,5 @@ private:
|
||||
QOpenGLShaderProgram *program;
|
||||
|
||||
VisionStreamType stream_type;
|
||||
QColor bg = QColor("#000000");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user