dragonpilot - 基於 openpilot 的開源駕駛輔助系統
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1 KiB

#pragma once
#include <memory>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLWidget>
#include <QThread>
#ifdef QCOM2
#define EGL_EGLEXT_PROTOTYPES
#define EGL_NO_X11
#define GL_TEXTURE_EXTERNAL_OES 0x8D65
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <drm/drm_fourcc.h>
#endif
#include "cereal/visionipc/visionipc_client.h"
#include "selfdrive/camerad/cameras/camera_common.h"
#include "selfdrive/ui/ui.h"
UI: draw camera on same frame from modelV2 (#24335) * draw camera on same frame from modelV2 * fix reversing * optimze * sleep shorter * heavy debugging * clean up * fix ui hang * try this * more generic implementation * add unused flag back * draw latest frames when camerad is coming up with no modeld * only get modelV2 once * fix drawing * conflate, reduce buffer, and remove special case when starting * make tests pass * remove comments * frame_id is a uint32_t * not sure why passing to cameraview causes overflow * ternary, not too complicated * change to size * rename to frame * use unique_ptr * Revert "use unique_ptr" This reverts commit 955842d9511a26468d4deedd1807f096540cb40c. * Assert buffer size Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * use one deque with pairs and uint32_t * formatting * frame offset * Revert "frame offset" This reverts commit a2cff8a2d57a02f314d9f6adb7221b193a150e4c. * use array * add prints * Revert "add prints" This reverts commit d6978746e5c316fb2d5a619091c9aaf849c31967. * clean up * this handles all cases * we want to clip * fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames * fix rare case where camera is behind model simpler comment * draw latest frames if we start with no model, then hang on current frame until model catches up fix * store if it's updated * accurate comment * reset to latest on connect and showevent * better order * use quint32 for sending signal function * use empty * draft * kinda works * works * one line * debug * clean up * revert this * to preserve behavior, think we need to poll these * revert * no timeout when modeld is not alive * Update selfdrive/ui/qt/onroad.cc * changes from other PR * see if we're drawing dup model or camera frames * looks good, just need to clean up * debug * clean up * clean up * revert these changes * fix * pretty simple, test on device * clean up * revert this Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
const int FRAME_BUFFER_SIZE = 5;
static_assert(FRAME_BUFFER_SIZE <= YUV_BUFFER_COUNT);
class CameraViewWidget : public QOpenGLWidget, protected QOpenGLFunctions {
Q_OBJECT
public:
using QOpenGLWidget::QOpenGLWidget;
explicit CameraViewWidget(std::string stream_name, VisionStreamType stream_type, bool zoom, QWidget* parent = nullptr);
~CameraViewWidget();
void setStreamType(VisionStreamType type) { stream_type = type; }
void setBackgroundColor(const QColor &color) { bg = color; }
UI: draw camera on same frame from modelV2 (#24335) * draw camera on same frame from modelV2 * fix reversing * optimze * sleep shorter * heavy debugging * clean up * fix ui hang * try this * more generic implementation * add unused flag back * draw latest frames when camerad is coming up with no modeld * only get modelV2 once * fix drawing * conflate, reduce buffer, and remove special case when starting * make tests pass * remove comments * frame_id is a uint32_t * not sure why passing to cameraview causes overflow * ternary, not too complicated * change to size * rename to frame * use unique_ptr * Revert "use unique_ptr" This reverts commit 955842d9511a26468d4deedd1807f096540cb40c. * Assert buffer size Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * use one deque with pairs and uint32_t * formatting * frame offset * Revert "frame offset" This reverts commit a2cff8a2d57a02f314d9f6adb7221b193a150e4c. * use array * add prints * Revert "add prints" This reverts commit d6978746e5c316fb2d5a619091c9aaf849c31967. * clean up * this handles all cases * we want to clip * fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames * fix rare case where camera is behind model simpler comment * draw latest frames if we start with no model, then hang on current frame until model catches up fix * store if it's updated * accurate comment * reset to latest on connect and showevent * better order * use quint32 for sending signal function * use empty * draft * kinda works * works * one line * debug * clean up * revert this * to preserve behavior, think we need to poll these * revert * no timeout when modeld is not alive * Update selfdrive/ui/qt/onroad.cc * changes from other PR * see if we're drawing dup model or camera frames * looks good, just need to clean up * debug * clean up * clean up * revert these changes * fix * pretty simple, test on device * clean up * revert this Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
void setFrameId(int frame_id) { draw_frame_id = frame_id; }
signals:
void clicked();
void vipcThreadConnected(VisionIpcClient *);
UI: draw camera on same frame from modelV2 (#24335) * draw camera on same frame from modelV2 * fix reversing * optimze * sleep shorter * heavy debugging * clean up * fix ui hang * try this * more generic implementation * add unused flag back * draw latest frames when camerad is coming up with no modeld * only get modelV2 once * fix drawing * conflate, reduce buffer, and remove special case when starting * make tests pass * remove comments * frame_id is a uint32_t * not sure why passing to cameraview causes overflow * ternary, not too complicated * change to size * rename to frame * use unique_ptr * Revert "use unique_ptr" This reverts commit 955842d9511a26468d4deedd1807f096540cb40c. * Assert buffer size Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * use one deque with pairs and uint32_t * formatting * frame offset * Revert "frame offset" This reverts commit a2cff8a2d57a02f314d9f6adb7221b193a150e4c. * use array * add prints * Revert "add prints" This reverts commit d6978746e5c316fb2d5a619091c9aaf849c31967. * clean up * this handles all cases * we want to clip * fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames * fix rare case where camera is behind model simpler comment * draw latest frames if we start with no model, then hang on current frame until model catches up fix * store if it's updated * accurate comment * reset to latest on connect and showevent * better order * use quint32 for sending signal function * use empty * draft * kinda works * works * one line * debug * clean up * revert this * to preserve behavior, think we need to poll these * revert * no timeout when modeld is not alive * Update selfdrive/ui/qt/onroad.cc * changes from other PR * see if we're drawing dup model or camera frames * looks good, just need to clean up * debug * clean up * clean up * revert these changes * fix * pretty simple, test on device * clean up * revert this Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
void vipcThreadFrameReceived(VisionBuf *, quint32);
protected:
void paintGL() override;
void initializeGL() override;
void resizeGL(int w, int h) override { updateFrameMat(w, h); }
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override { emit clicked(); }
virtual void updateFrameMat(int w, int h);
void vipcThread();
bool zoomed_view;
GLuint frame_vao, frame_vbo, frame_ibo;
GLuint textures[2];
mat4 frame_mat;
std::unique_ptr<QOpenGLShaderProgram> program;
QColor bg = QColor("#000000");
#ifdef QCOM2
EGLDisplay egl_display;
std::map<int, EGLImageKHR> egl_images;
#endif
std::string stream_name;
int stream_width = 0;
int stream_height = 0;
int stream_stride = 0;
std::atomic<VisionStreamType> stream_type;
QThread *vipc_thread = nullptr;
UI: draw camera on same frame from modelV2 (#24335) * draw camera on same frame from modelV2 * fix reversing * optimze * sleep shorter * heavy debugging * clean up * fix ui hang * try this * more generic implementation * add unused flag back * draw latest frames when camerad is coming up with no modeld * only get modelV2 once * fix drawing * conflate, reduce buffer, and remove special case when starting * make tests pass * remove comments * frame_id is a uint32_t * not sure why passing to cameraview causes overflow * ternary, not too complicated * change to size * rename to frame * use unique_ptr * Revert "use unique_ptr" This reverts commit 955842d9511a26468d4deedd1807f096540cb40c. * Assert buffer size Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * use one deque with pairs and uint32_t * formatting * frame offset * Revert "frame offset" This reverts commit a2cff8a2d57a02f314d9f6adb7221b193a150e4c. * use array * add prints * Revert "add prints" This reverts commit d6978746e5c316fb2d5a619091c9aaf849c31967. * clean up * this handles all cases * we want to clip * fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames * fix rare case where camera is behind model simpler comment * draw latest frames if we start with no model, then hang on current frame until model catches up fix * store if it's updated * accurate comment * reset to latest on connect and showevent * better order * use quint32 for sending signal function * use empty * draft * kinda works * works * one line * debug * clean up * revert this * to preserve behavior, think we need to poll these * revert * no timeout when modeld is not alive * Update selfdrive/ui/qt/onroad.cc * changes from other PR * see if we're drawing dup model or camera frames * looks good, just need to clean up * debug * clean up * clean up * revert these changes * fix * pretty simple, test on device * clean up * revert this Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
std::deque<std::pair<uint32_t, VisionBuf*>> frames;
uint32_t draw_frame_id = 0;
protected slots:
void vipcConnected(VisionIpcClient *vipc_client);
UI: draw camera on same frame from modelV2 (#24335) * draw camera on same frame from modelV2 * fix reversing * optimze * sleep shorter * heavy debugging * clean up * fix ui hang * try this * more generic implementation * add unused flag back * draw latest frames when camerad is coming up with no modeld * only get modelV2 once * fix drawing * conflate, reduce buffer, and remove special case when starting * make tests pass * remove comments * frame_id is a uint32_t * not sure why passing to cameraview causes overflow * ternary, not too complicated * change to size * rename to frame * use unique_ptr * Revert "use unique_ptr" This reverts commit 955842d9511a26468d4deedd1807f096540cb40c. * Assert buffer size Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * use one deque with pairs and uint32_t * formatting * frame offset * Revert "frame offset" This reverts commit a2cff8a2d57a02f314d9f6adb7221b193a150e4c. * use array * add prints * Revert "add prints" This reverts commit d6978746e5c316fb2d5a619091c9aaf849c31967. * clean up * this handles all cases * we want to clip * fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames fixes going backwards when replay or modeld lags multiple frames, then skips multiple frames * fix rare case where camera is behind model simpler comment * draw latest frames if we start with no model, then hang on current frame until model catches up fix * store if it's updated * accurate comment * reset to latest on connect and showevent * better order * use quint32 for sending signal function * use empty * draft * kinda works * works * one line * debug * clean up * revert this * to preserve behavior, think we need to poll these * revert * no timeout when modeld is not alive * Update selfdrive/ui/qt/onroad.cc * changes from other PR * see if we're drawing dup model or camera frames * looks good, just need to clean up * debug * clean up * clean up * revert these changes * fix * pretty simple, test on device * clean up * revert this Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
void vipcFrameReceived(VisionBuf *vipc_client, uint32_t frame_id);
};