use one deque with pairs and uint32_t

pull/24335/head
Shane Smiskol 3 years ago
parent d753b041c3
commit 98fdc43a4c
  1. 2
      selfdrive/ui/qt/onroad.cc
  2. 21
      selfdrive/ui/qt/widgets/cameraview.cc
  3. 12
      selfdrive/ui/qt/widgets/cameraview.h

@ -374,7 +374,7 @@ void NvgWindow::drawLead(QPainter &painter, const cereal::ModelDataV2::LeadDataV
void NvgWindow::paintGL() { void NvgWindow::paintGL() {
UIState *s = uiState(); UIState *s = uiState();
const cereal::ModelDataV2::Reader &model = (*s->sm)["modelV2"].getModelV2(); const cereal::ModelDataV2::Reader &model = (*s->sm)["modelV2"].getModelV2();
CameraViewWidget::draw_frame_id = model.getFrameId(); CameraViewWidget::setFrameId(model.getFrameId());
CameraViewWidget::paintGL(); CameraViewWidget::paintGL();
QPainter painter(this); QPainter painter(this);

@ -104,6 +104,7 @@ mat4 get_fit_view_transform(float widget_aspect_ratio, float frame_aspect_ratio)
CameraViewWidget::CameraViewWidget(std::string stream_name, VisionStreamType type, bool zoom, QWidget* parent) : CameraViewWidget::CameraViewWidget(std::string stream_name, VisionStreamType type, bool zoom, QWidget* parent) :
stream_name(stream_name), stream_type(type), zoomed_view(zoom), QOpenGLWidget(parent) { stream_name(stream_name), stream_type(type), zoomed_view(zoom), QOpenGLWidget(parent) {
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);
qRegisterMetaType<uint32_t>("uint32_t");
connect(this, &CameraViewWidget::vipcThreadConnected, this, &CameraViewWidget::vipcConnected, Qt::BlockingQueuedConnection); connect(this, &CameraViewWidget::vipcThreadConnected, this, &CameraViewWidget::vipcConnected, Qt::BlockingQueuedConnection);
connect(this, &CameraViewWidget::vipcThreadFrameReceived, this, &CameraViewWidget::vipcFrameReceived); connect(this, &CameraViewWidget::vipcThreadFrameReceived, this, &CameraViewWidget::vipcFrameReceived);
} }
@ -167,7 +168,6 @@ void CameraViewWidget::initializeGL() {
void CameraViewWidget::showEvent(QShowEvent *event) { void CameraViewWidget::showEvent(QShowEvent *event) {
frames.clear(); frames.clear();
frame_ids.clear();
if (!vipc_thread) { if (!vipc_thread) {
vipc_thread = new QThread(); vipc_thread = new QThread();
connect(vipc_thread, &QThread::started, [=]() { vipcThread(); }); connect(vipc_thread, &QThread::started, [=]() { vipcThread(); });
@ -218,13 +218,13 @@ void CameraViewWidget::paintGL() {
glClearColor(bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF()); glClearColor(bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF());
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
assert(frames.size() == frame_ids.size());
if (frames.size() == 0) return; if (frames.size() == 0) return;
VisionBuf *frame; auto it = std::find_if(frames.begin(), frames.end(), [this](const std::pair <uint32_t, VisionBuf*>& element) {
std::deque<quint32>::iterator it = std::find(frame_ids.begin(), frame_ids.end(), draw_frame_id); return element.first == draw_frame_id;
int frame_idx = (it == frame_ids.end()) ? (frames.size() - 1) : (it - frame_ids.begin()); });
frame = frames[frame_idx]; int frame_idx = (it == frames.end()) ? (frames.size() - 1) : (it - frames.begin());
VisionBuf *frame = frames[frame_idx].second;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glViewport(0, 0, width(), height()); glViewport(0, 0, width(), height());
@ -255,7 +255,6 @@ void CameraViewWidget::paintGL() {
void CameraViewWidget::vipcConnected(VisionIpcClient *vipc_client) { void CameraViewWidget::vipcConnected(VisionIpcClient *vipc_client) {
makeCurrent(); makeCurrent();
frames.clear(); frames.clear();
frame_ids.clear();
stream_width = vipc_client->buffers[0].width; stream_width = vipc_client->buffers[0].width;
stream_height = vipc_client->buffers[0].height; stream_height = vipc_client->buffers[0].height;
@ -274,15 +273,11 @@ void CameraViewWidget::vipcConnected(VisionIpcClient *vipc_client) {
updateFrameMat(width(), height()); updateFrameMat(width(), height());
} }
void CameraViewWidget::vipcFrameReceived(VisionBuf *buf, quint32 frame_id) { void CameraViewWidget::vipcFrameReceived(VisionBuf *buf, uint32_t frame_id) {
frames.push_back(buf); frames.push_back(std::make_pair(frame_id, buf));
frame_ids.push_back(frame_id);
while (frames.size() > FRAME_BUFFER_SIZE) { while (frames.size() > FRAME_BUFFER_SIZE) {
frames.pop_front(); frames.pop_front();
} }
while (frame_ids.size() > FRAME_BUFFER_SIZE) {
frame_ids.pop_front();
}
update(); update();
} }

@ -19,12 +19,12 @@ public:
~CameraViewWidget(); ~CameraViewWidget();
void setStreamType(VisionStreamType type) { stream_type = type; } void setStreamType(VisionStreamType type) { stream_type = type; }
void setBackgroundColor(const QColor &color) { bg = color; } void setBackgroundColor(const QColor &color) { bg = color; }
quint32 draw_frame_id; void setFrameId(int frame_id) { draw_frame_id = frame_id; }
signals: signals:
void clicked(); void clicked();
void vipcThreadConnected(VisionIpcClient *); void vipcThreadConnected(VisionIpcClient *);
void vipcThreadFrameReceived(VisionBuf *, quint32); void vipcThreadFrameReceived(VisionBuf *, uint32_t);
protected: protected:
void paintGL() override; void paintGL() override;
@ -37,9 +37,8 @@ protected:
void vipcThread(); void vipcThread();
bool zoomed_view; bool zoomed_view;
std::deque<VisionBuf*> frames;
std::deque<quint32> frame_ids;
GLuint frame_vao, frame_vbo, frame_ibo; GLuint frame_vao, frame_vbo, frame_ibo;
GLuint textures[3];
mat4 frame_mat; mat4 frame_mat;
std::unique_ptr<QOpenGLShaderProgram> program; std::unique_ptr<QOpenGLShaderProgram> program;
QColor bg = QColor("#000000"); QColor bg = QColor("#000000");
@ -50,9 +49,10 @@ protected:
std::atomic<VisionStreamType> stream_type; std::atomic<VisionStreamType> stream_type;
QThread *vipc_thread = nullptr; QThread *vipc_thread = nullptr;
GLuint textures[3]; std::deque<std::pair<uint32_t, VisionBuf*>> frames;
uint32_t draw_frame_id;
protected slots: protected slots:
void vipcConnected(VisionIpcClient *vipc_client); void vipcConnected(VisionIpcClient *vipc_client);
void vipcFrameReceived(VisionBuf *vipc_client, quint32 frame_id); void vipcFrameReceived(VisionBuf *vipc_client, uint32_t frame_id);
}; };

Loading…
Cancel
Save