From e18bbf38afacd2931b817c2d7d3d9b6f37b55878 Mon Sep 17 00:00:00 2001 From: ut001910 Date: Fri, 20 Dec 2024 15:47:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E7=9B=B8=E6=9C=BA?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=8E=E5=BD=95=E5=88=B6=E5=8D=A1=E9=A1=BF?= =?UTF-8?q?=E5=9B=9E=E8=B7=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化相机显示与录制卡顿回跳问题 Bug: https://pms.uniontech.com/bug-view-293127.html Log: 优化相机显示与录制卡顿回跳问题 --- libcam/libcam_encoder/encoder.c | 2 +- src/src/majorimageprocessingthread.cpp | 1 - src/src/previewopenglwidget.cpp | 22 ++++++++++++++++++---- src/src/previewopenglwidget.h | 1 + src/src/videowidget.cpp | 5 +++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/libcam/libcam_encoder/encoder.c b/libcam/libcam_encoder/encoder.c index ce200ba1..372e6f8e 100644 --- a/libcam/libcam_encoder/encoder.c +++ b/libcam/libcam_encoder/encoder.c @@ -581,7 +581,7 @@ static encoder_video_context_t *encoder_video_init(encoder_context_t *encoder_ct if (video_defaults->gop_size > 0) { - if (pgux == 1) { + if (pgux == 1 || is_forceGles()) { video_codec_data->codec_context->gop_size = 3; } else { video_codec_data->codec_context->gop_size = video_defaults->gop_size; diff --git a/src/src/majorimageprocessingthread.cpp b/src/src/majorimageprocessingthread.cpp index 872be145..8a7535cb 100644 --- a/src/src/majorimageprocessingthread.cpp +++ b/src/src/majorimageprocessingthread.cpp @@ -443,7 +443,6 @@ void MajorImageProcessingThread::run() } } else if (m_frame->yuv_frame){ #ifndef __mips__ - emit sigRenderYuv(true); emit sigYUVFrame(m_yuvPtr, m_nVdWidth, m_nVdHeight); #endif } diff --git a/src/src/previewopenglwidget.cpp b/src/src/previewopenglwidget.cpp index 245ea910..0e292810 100644 --- a/src/src/previewopenglwidget.cpp +++ b/src/src/previewopenglwidget.cpp @@ -156,12 +156,20 @@ void PreviewOpenglWidget::paintGL() { if (m_yuvPtr == nullptr) return; - + bool bReBuildImage = false; + if(m_imgSize != QSize(m_videoWidth, m_videoHeight)) { + bReBuildImage = true; + m_imgSize = QSize(m_videoWidth, m_videoHeight); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } glActiveTexture(GL_TEXTURE0); //激活纹理单元GL_TEXTURE0,系统里面的 glBindTexture(GL_TEXTURE_2D, m_idY); //绑定y分量纹理对象id到激活的纹理单元 //使用内存中的数据创建真正的y分量纹理数据,https://blog.csdn.net/xipiaoyouzi/article/details/53584798 纹理参数解析 - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, static_cast(m_videoWidth), static_cast(m_videoHeight), 0, GL_RED, GL_UNSIGNED_BYTE, m_yuvPtr); + if( bReBuildImage ) { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, static_cast(m_videoWidth), static_cast(m_videoHeight), 0, GL_RED, GL_UNSIGNED_BYTE, 0); + } + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, static_cast(m_videoWidth), static_cast(m_videoHeight), GL_RED, GL_UNSIGNED_BYTE, m_yuvPtr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -171,7 +179,10 @@ void PreviewOpenglWidget::paintGL() glBindTexture(GL_TEXTURE_2D, m_idU); //使用内存中的数据创建真正的u分量纹理数据 - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, m_videoWidth >> 1, m_videoHeight >> 1, 0, GL_RED, GL_UNSIGNED_BYTE, m_yuvPtr + m_videoWidth * m_videoHeight); + if( bReBuildImage ) { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, m_videoWidth >> 1, m_videoHeight >> 1, 0, GL_RED, GL_UNSIGNED_BYTE, 0); + } + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_videoWidth >> 1, m_videoHeight >> 1, GL_RED, GL_UNSIGNED_BYTE, m_yuvPtr + m_videoWidth * m_videoHeight); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -181,7 +192,10 @@ void PreviewOpenglWidget::paintGL() glBindTexture(GL_TEXTURE_2D, m_idV); //使用内存中的数据创建真正的v分量纹理数据 - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, m_videoWidth >> 1, m_videoHeight >> 1, 0, GL_RED, GL_UNSIGNED_BYTE, m_yuvPtr + m_videoWidth * m_videoHeight * 5 / 4); + if( bReBuildImage ) { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, m_videoWidth >> 1, m_videoHeight >> 1, 0, GL_RED, GL_UNSIGNED_BYTE, 0); + } + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_videoWidth >> 1, m_videoHeight >> 1, GL_RED, GL_UNSIGNED_BYTE, m_yuvPtr + m_videoWidth * m_videoHeight * 5 / 4); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); diff --git a/src/src/previewopenglwidget.h b/src/src/previewopenglwidget.h index 1fb0789b..554eeda9 100644 --- a/src/src/previewopenglwidget.h +++ b/src/src/previewopenglwidget.h @@ -91,6 +91,7 @@ public slots: uint m_videoHeight; uchar *m_yuvPtr; + QSize m_imgSize; }; #endif // PREVIEWOPENGLWIDGET_H diff --git a/src/src/videowidget.cpp b/src/src/videowidget.cpp index 3fb4cdd6..c198fb83 100644 --- a/src/src/videowidget.cpp +++ b/src/src/videowidget.cpp @@ -244,6 +244,7 @@ void videowidget::delayInit() } else { connect(m_imgPrcThread, SIGNAL(SendMajorImageProcessing(QImage *, int)), this, SLOT(ReceiveMajorImage(QImage *, int))); + ReceiveOpenGLstatus(true); connect(m_imgPrcThread, SIGNAL(sigRenderYuv(bool)), this, SLOT(ReceiveOpenGLstatus(bool))); connect(m_imgPrcThread, SIGNAL(sigYUVFrame(uchar *, uint, uint)), m_openglwidget, SLOT(slotShowYuv(uchar *, uint, uint))); @@ -616,6 +617,10 @@ void videowidget::resizeEvent(QResizeEvent *size) if (m_gridlinewidget) m_gridlinewidget->resize(rect().size()); + + if(m_openglwidget && m_openglwidget->isVisible()) { + ReceiveOpenGLstatus(true); + } } void videowidget::showCountdown()