From 70d858299bc4b6a30a558a37d365d146f83a3ef8 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Sat, 28 Oct 2023 01:27:20 +0800 Subject: [PATCH] no message --- .../webrtc_capture/src/camera_video_sink.cpp | 2 +- client/webrtc_capture/src/cplaywidget.cpp | 117 ++++++++++-------- client/webrtc_capture/src/main.cpp | 8 +- client/webrtc_capture/src/mainwindow.cpp | 19 ++- client/webrtc_capture/src/mainwindow.h | 2 +- client/webrtc_capture/src/mainwindow.ui | 4 +- 6 files changed, 81 insertions(+), 71 deletions(-) diff --git a/client/webrtc_capture/src/camera_video_sink.cpp b/client/webrtc_capture/src/camera_video_sink.cpp index f71f45d..93a114f 100644 --- a/client/webrtc_capture/src/camera_video_sink.cpp +++ b/client/webrtc_capture/src/camera_video_sink.cpp @@ -84,7 +84,7 @@ void CameraVideoSink::OnFrame(const webrtc::VideoFrame& frame) { int height = this->m_capability.height; uint8_t *data = new uint8_t[width * height*4]; -// qDebug()<GetI420()->type()); + qDebug()<GetI420()->type()); memcpy(data,frameBuffer->GetI420()->DataY(),width*height); memcpy(data + width*height ,frameBuffer->GetI420()->DataU(), width*height/4); diff --git a/client/webrtc_capture/src/cplaywidget.cpp b/client/webrtc_capture/src/cplaywidget.cpp index 00c47d0..5ff2d77 100644 --- a/client/webrtc_capture/src/cplaywidget.cpp +++ b/client/webrtc_capture/src/cplaywidget.cpp @@ -214,58 +214,63 @@ B = Y + 1.772 (Cb-128) */ void CPlayWidget::initializeGL() { - initializeOpenGLFunctions(); - glEnable(GL_DEPTH_TEST); - m_pVSHader = new QOpenGLShader(QOpenGLShader::Vertex, this); - bool bCompile = m_pVSHader->compileSourceCode(vsrcyuv); - if(!bCompile) - { + initializeOpenGLFunctions(); +// glEnable(GL_DEPTH_TEST); - } - m_pFSHader = new QOpenGLShader(QOpenGLShader::Fragment, this); - if(mType == TYPE_RGB32){ - bCompile = m_pFSHader->compileSourceCode(fsrcrgb); - } - if(mType == TYPE_YUV420P){ - bCompile = m_pFSHader->compileSourceCode(fsrcyuv); - } - if(mType == TYPE_I420){ - bCompile = m_pFSHader->compileSourceCode(kI420FragmentShaderSource); - } - if(!bCompile) - { + m_pVSHader = new QOpenGLShader(QOpenGLShader::Vertex, this); + bool bCompile = m_pVSHader->compileSourceCode(vsrcyuv); + if(!bCompile) + { - } -#define PROGRAM_VERTEX_ATTRIBUTE 0 -#define PROGRAM_TEXCOORD_ATTRIBUTE 1 - m_pShaderProgram = new QOpenGLShaderProgram; - m_pShaderProgram->addShader(m_pFSHader); - m_pShaderProgram->addShader(m_pVSHader); - m_pShaderProgram->bindAttributeLocation("vertexIn", ATTRIB_VERTEX); - m_pShaderProgram->bindAttributeLocation("textureIn", ATTRIB_TEXTURE); - m_pShaderProgram->link(); - m_pShaderProgram->bind(); - if(this->mType == TYPE_YUV420P){ - initShaderYuv(); - } - if(this->mType == TYPE_RGB32){ - initShaderRgb(); - } - if(this->mType == TYPE_I420){ - initShaderI420(); - } - glClearColor(0.0,0.0,0.0,0.0); + } + m_pFSHader = new QOpenGLShader(QOpenGLShader::Fragment, this); + if(mType == TYPE_RGB32){ + bCompile = m_pFSHader->compileSourceCode(fsrcrgb); + } + if(mType == TYPE_YUV420P){ + bCompile = m_pFSHader->compileSourceCode(fsrcyuv); + } + if(mType == TYPE_I420){ + bCompile = m_pFSHader->compileSourceCode(kI420FragmentShaderSource); + } + if(!bCompile) + { + qDebug()<<"compile error"; + }else{ + qDebug()<<"compile ok"; + } + #define PROGRAM_VERTEX_ATTRIBUTE 0 + #define PROGRAM_TEXCOORD_ATTRIBUTE 1 + m_pShaderProgram = new QOpenGLShaderProgram; + m_pShaderProgram->addShader(m_pFSHader); + m_pShaderProgram->addShader(m_pVSHader); + m_pShaderProgram->bindAttributeLocation("vertexIn", ATTRIB_VERTEX); + m_pShaderProgram->bindAttributeLocation("textureIn", ATTRIB_TEXTURE); + m_pShaderProgram->link(); + m_pShaderProgram->bind(); + if(this->mType == TYPE_YUV420P){ + initShaderYuv(); + } + if(this->mType == TYPE_RGB32){ + initShaderRgb(); + } + if(this->mType == TYPE_I420){ + initShaderI420(); + } + glClearColor(0.0,0.0,0.0,0.0); } void CPlayWidget::resizeGL(int w, int h) { - if(h == 0) - { - h = 1; + if(this->m_nVideoH > 0){ + if(h == 0) + { + h = 1; + } + glViewport(0,0, w,h); } - glViewport(0,0, w,h); } void CPlayWidget::paintGL() @@ -282,6 +287,7 @@ void CPlayWidget::paintGL() glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } + return; } @@ -322,10 +328,10 @@ void CPlayWidget::initShaderRgb() { textureUniformRGB = m_pShaderProgram->uniformLocation("rgbdata"); static const GLfloat vertexVertices[] = { - -1.0f, -1.0f, - 1.0f, -1.0f, - -1.0f, 1.0f, - 1.0f, 1.0f, + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, }; static const GLfloat textureVertices[] = { @@ -350,16 +356,16 @@ void CPlayWidget::initShaderI420() textureUniformU = m_pShaderProgram->uniformLocation("tex_u"); textureUniformV = m_pShaderProgram->uniformLocation("tex_v"); static const GLfloat vertexVertices[] = { - -1.0f, -1.0f, - 1.0f, -1.0f, - -1.0f, 1.0f, - 1.0f, 1.0f, + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, }; static const GLfloat textureVertices[] = { - 0.0f, 1.0f, - 1.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 0.0f, }; glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices); glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, textureVertices); @@ -436,6 +442,7 @@ int CPlayWidget::loadRtcI420Texture() { if(nullptr == m_buffer) return 0; + m_pShaderProgram->bind(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, id_y); diff --git a/client/webrtc_capture/src/main.cpp b/client/webrtc_capture/src/main.cpp index b6df6b1..b239a37 100644 --- a/client/webrtc_capture/src/main.cpp +++ b/client/webrtc_capture/src/main.cpp @@ -12,6 +12,7 @@ #include "video_source_impl.h" #include #include "cv_ssd.h" +#include # pragma comment(lib, "secur32.lib") # pragma comment(lib, "winmm.lib") @@ -69,11 +70,7 @@ void EnumCapture() int main(int argc, char *argv[]) { - int p[5] = {3,1,49,23,23}; - BubbleSort(p,5); - for(int i = 0;i< 5;i++){ - qDebug()<>("rtc::scoped_refptr"); qRegisterMetaType>("rtc::scoped_refptr&"); @@ -83,7 +80,6 @@ int main(int argc, char *argv[]) rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread); rtc::InitializeSSL(); - setbuf(stdout, NULL); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication a(argc, argv); MainWindow w; diff --git a/client/webrtc_capture/src/mainwindow.cpp b/client/webrtc_capture/src/mainwindow.cpp index a7ac5c6..a702bc6 100644 --- a/client/webrtc_capture/src/mainwindow.cpp +++ b/client/webrtc_capture/src/mainwindow.cpp @@ -13,6 +13,8 @@ #include #include #include "Qss.h" +#include + class ASyncDetectAndRenderThread :public QSSASyncProcess{ public: @@ -66,7 +68,6 @@ public: cv::cvtColor(*result, yuvData, cv::COLOR_BGR2YUV_I420); this->m_render->OnCameraData(yuvData.data); - } delete c; } @@ -114,7 +115,7 @@ public: qtimer->setSingleShot(false); QObject::connect(qtimer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); - qtimer->start(22); + qtimer->start(10); while(state){ if(mfbs ->Size() > 0){ @@ -126,6 +127,7 @@ public: } } eventLoop.exec(); // 渲染一次 + delete frame; } } @@ -141,7 +143,7 @@ AsyncRennder *gRender = nullptr; MainWindow::MainWindow(QWidget *parent) - : QssMainWindow(parent) + : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); @@ -185,17 +187,20 @@ void MainWindow::on_pushButton_clicked() char ids[128]; info->GetDeviceName(id,nullptr,0,ids,128,nullptr,0); info->GetCapability(ids,id,p); - qDebug()<openGLWidget->SetDataType(CPlayWidget::TYPE_YUV420P); + qDebug()<<"size is "<Capability().width<Capability().height; ui->openGLWidget->SetImgSize(m_capturer->Capability().width, m_capturer->Capability().height); + ui->openGLWidget->SetDataType(CPlayWidget::TYPE_YUV420P); + ui->openGLWidget->StartRender(); - // ui->openGLWidget->moveToThread(&gRender->Thread()); +// ui->openGLWidget->moveToThread(&gRender->Thread()); if(gRender == nullptr){ gRender = new AsyncRennder(this,m_capturer->VideoBuffer(),ui->openGLWidget); gRender->Start(this); @@ -205,6 +210,8 @@ void MainWindow::on_pushButton_clicked() mDetectResut->StartRender(); ui->pushButton->setText(QString::asprintf("正在采集")); + + qDebug()<openGLWidget->geometry(); }else{ ui->openGLWidget->StopRender(); } diff --git a/client/webrtc_capture/src/mainwindow.h b/client/webrtc_capture/src/mainwindow.h index 89a6d49..a0d53f1 100644 --- a/client/webrtc_capture/src/mainwindow.h +++ b/client/webrtc_capture/src/mainwindow.h @@ -10,7 +10,7 @@ QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE -class MainWindow : public QssMainWindow +class MainWindow : public QMainWindow { Q_OBJECT diff --git a/client/webrtc_capture/src/mainwindow.ui b/client/webrtc_capture/src/mainwindow.ui index 4d1bfc9..9769837 100644 --- a/client/webrtc_capture/src/mainwindow.ui +++ b/client/webrtc_capture/src/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 1280 - 800 + 1297 + 842