|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|