Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 优化相机显示与录制卡顿回跳问题 #340

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcam/libcam_encoder/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/src/majorimageprocessingthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
22 changes: 18 additions & 4 deletions src/src/previewopenglwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(m_videoWidth), static_cast<int>(m_videoHeight), 0, GL_RED, GL_UNSIGNED_BYTE, m_yuvPtr);
if( bReBuildImage ) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, static_cast<int>(m_videoWidth), static_cast<int>(m_videoHeight), 0, GL_RED, GL_UNSIGNED_BYTE, 0);
}
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, static_cast<int>(m_videoWidth), static_cast<int>(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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/src/previewopenglwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public slots:
uint m_videoHeight;

uchar *m_yuvPtr;
QSize m_imgSize;
};

#endif // PREVIEWOPENGLWIDGET_H
5 changes: 5 additions & 0 deletions src/src/videowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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()
Expand Down
Loading