|  |  | @ -1,7 +1,5 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "selfdrive/ui/qt/widgets/cameraview.h" |  |  |  | #include "selfdrive/ui/qt/widgets/cameraview.h" | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "selfdrive/common/swaglog.h" |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | namespace { |  |  |  | namespace { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | const char frame_vertex_shader[] = |  |  |  | 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) : |  |  |  | CameraViewWidget::CameraViewWidget(VisionStreamType stream_type, bool zoom, QWidget* parent) : | 
			
		
	
		
		
			
				
					
					|  |  |  |                                    stream_type(stream_type), zoomed_view(zoom), QOpenGLWidget(parent) { |  |  |  |                                    stream_type(stream_type), zoomed_view(zoom), QOpenGLWidget(parent) { | 
			
		
	
		
		
			
				
					
					|  |  |  |   setAttribute(Qt::WA_OpaquePaintEvent); |  |  |  |   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() { |  |  |  | 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) { |  |  |  | void CameraViewWidget::updateFrameMat(int w, int h) { | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (zoomed_view) { |  |  |  |   if (zoomed_view) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (stream_type == VISION_STREAM_RGB_FRONT) { |  |  |  |     if (stream_type == VISION_STREAM_RGB_FRONT) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -204,7 +209,7 @@ void CameraViewWidget::updateFrameMat(int w, int h) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void CameraViewWidget::paintGL() { |  |  |  | void CameraViewWidget::paintGL() { | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (!latest_frame) { |  |  |  |   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); |  |  |  |     glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); | 
			
		
	
		
		
			
				
					
					|  |  |  |     return; |  |  |  |     return; | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
	
		
		
			
				
					|  |  | @ -233,6 +238,10 @@ void CameraViewWidget::paintGL() { | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void CameraViewWidget::updateFrame() { |  |  |  | void CameraViewWidget::updateFrame() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   if (!isVisible()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     return; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (!vipc_client->connected) { |  |  |  |   if (!vipc_client->connected) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     makeCurrent(); |  |  |  |     makeCurrent(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (vipc_client->connect(false)) { |  |  |  |     if (vipc_client->connect(false)) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -257,17 +266,11 @@ void CameraViewWidget::updateFrame() { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   VisionBuf *buf = nullptr; |  |  |  |   VisionBuf *buf = nullptr; | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (vipc_client->connected) { |  |  |  |   if (vipc_client->connected) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     buf = vipc_client->recv(); |  |  |  |     buf = vipc_client->recv(nullptr, 0); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     if (buf != nullptr) { |  |  |  |     if (buf != nullptr) { | 
			
		
	
		
		
			
				
					
					|  |  |  |       latest_frame = buf; |  |  |  |       latest_frame = buf; | 
			
		
	
		
		
			
				
					
					|  |  |  |       update(); |  |  |  |       update(); | 
			
		
	
		
		
			
				
					
					|  |  |  |       emit frameUpdated(); |  |  |  |       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); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |