From b1f865dda706e2d49b95fe76cb66756668349193 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Fri, 13 May 2022 00:58:26 +0800 Subject: [PATCH] no message --- client/webrtc_capture/src/cplaywidget.cpp | 35 +++++++++++++++------ client/webrtc_capture/src/cplaywidget.h | 4 ++- client/webrtc_capture/src/main.cpp | 18 ++--------- client/webrtc_capture/src/mainwindow.cpp | 38 +++++++++++++++-------- client/webrtc_capture/src/mainwindow.h | 2 ++ client/webrtc_capture/src/mainwindow.ui | 9 +++++- 6 files changed, 66 insertions(+), 40 deletions(-) diff --git a/client/webrtc_capture/src/cplaywidget.cpp b/client/webrtc_capture/src/cplaywidget.cpp index 4a344e1..12323f5 100644 --- a/client/webrtc_capture/src/cplaywidget.cpp +++ b/client/webrtc_capture/src/cplaywidget.cpp @@ -108,6 +108,7 @@ CPlayWidget::CPlayWidget(QWidget *parent):QOpenGLWidget(parent) { m_nVideoH = 0; m_nVideoW = 0; mType = TYPE_I420; + m_start_render = false; } CPlayWidget::~CPlayWidget() { @@ -116,7 +117,19 @@ CPlayWidget::~CPlayWidget() { int CPlayWidget::SetDataType(CPlayWidget::IMG_TYPE type){ this->mType = type; -// initializeGL(); + initializeGL(); + return 0; +} + +int CPlayWidget::StartRender() +{ + this->m_start_render = true; + return 0; +} + +int CPlayWidget::StopRender() +{ + this->m_start_render = false; return 0; } @@ -230,16 +243,18 @@ void CPlayWidget::resizeGL(int w, int h) void CPlayWidget::paintGL() { - if(mType == TYPE_YUV420P) - loadYuvTexture(); - if(mType == TYPE_RGB32){ - loadRgbTexture(); - } - if(mType == TYPE_I420){ - loadYuvTexture(); - } + if(m_start_render){ + if(mType == TYPE_YUV420P) + loadYuvTexture(); + if(mType == TYPE_RGB32){ + loadRgbTexture(); + } + if(mType == TYPE_I420){ + loadYuvTexture(); + } - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } return; } diff --git a/client/webrtc_capture/src/cplaywidget.h b/client/webrtc_capture/src/cplaywidget.h index 86298e0..4d04020 100644 --- a/client/webrtc_capture/src/cplaywidget.h +++ b/client/webrtc_capture/src/cplaywidget.h @@ -39,7 +39,8 @@ public: CPlayWidget(QWidget* parent); ~CPlayWidget(); int SetDataType(IMG_TYPE); - + int StartRender(); + int StopRender(); int OnCameraData(uint8_t *); int SetImgSize(uint32_t width,uint32_t ); protected: @@ -82,5 +83,6 @@ private: int loadRtcI420Texture(); int loadRgbTexture(); rtc::scoped_refptr m_buffer; + bool m_start_render; }; #endif diff --git a/client/webrtc_capture/src/main.cpp b/client/webrtc_capture/src/main.cpp index bc8a5d4..ebbfe32 100644 --- a/client/webrtc_capture/src/main.cpp +++ b/client/webrtc_capture/src/main.cpp @@ -56,6 +56,8 @@ void EnumCapture() int main(int argc, char *argv[]) { + qRegisterMetaType>("rtc::scoped_refptr"); + qRegisterMetaType>("rtc::scoped_refptr&"); rtc::WinsockInitializer winsock_init; rtc::Win32SocketServer w32_ss; @@ -63,25 +65,11 @@ int main(int argc, char *argv[]) rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread); rtc::InitializeSSL(); -// std::unique_ptr capturer; - -// int num_devices = info->NumberOfDevices(); -// for (int i = 0; i < num_devices; ++i) { -//// capturer.reset(CameraVideoSink::Create(kWidth, kHeight, kFps, i)); -//// if (capturer) { -//// break; -//// } -// } setbuf(stdout, NULL); - - qRegisterMetaType>("rtc::scoped_refptr"); - qRegisterMetaType>("rtc::scoped_refptr&"); - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication a(argc, argv); MainWindow w; -// QObject::connect((CameraVideoSink*)capturer.get(),SIGNAL(UpdateFrame(rtc::scoped_refptr&)),&w, -// SLOT(OnUpdateFrame( rtc::scoped_refptr&)),Qt::ConnectionType::AutoConnection); + w.setWindowTitle("webrtc easy demo"); w.show(); return a.exec(); } diff --git a/client/webrtc_capture/src/mainwindow.cpp b/client/webrtc_capture/src/mainwindow.cpp index b837274..13f4d29 100644 --- a/client/webrtc_capture/src/mainwindow.cpp +++ b/client/webrtc_capture/src/mainwindow.cpp @@ -45,21 +45,19 @@ MainWindow::MainWindow(QWidget *parent) , ui(new Ui::MainWindow) { ui->setupUi(this); -// ui->openGLWidget->SetImgSize(640,480); - ui->openGLWidget->show(); + ui->openGLWidget->show(); - std::unique_ptr info( - webrtc::VideoCaptureFactory::CreateDeviceInfo()); - if (!info) { + std::unique_ptr info( + webrtc::VideoCaptureFactory::CreateDeviceInfo()); + if (!info) { RTC_LOG(LERROR) << "CreateDeviceInfo failed"; - } - int num_devices = info->NumberOfDevices(); - for (int i = 0; i < num_devices; ++i) { - char name[100]; - info->GetDeviceName(i,name,100,nullptr,0,nullptr,0); - ui->comboBox->addItem(QString::asprintf("%s",name),i); - } - + } + int num_devices = info->NumberOfDevices(); + for (int i = 0; i < num_devices; ++i) { + char name[100]; + info->GetDeviceName(i,name,100,nullptr,0,nullptr,0); + ui->comboBox->addItem(QString::asprintf("%s",name),i); + } } MainWindow::~MainWindow() @@ -92,6 +90,7 @@ void MainWindow::on_pushButton_clicked() ui->openGLWidget->SetDataType(CPlayWidget::TYPE_YUV420P); ui->openGLWidget->SetImgSize(m_capturer->Capability().width, m_capturer->Capability().height); + ui->openGLWidget->StartRender(); // ui->openGLWidget->moveToThread(&gRender->Thread()); if(gRender == nullptr){ gRender = new AsyncRennder(this,m_capturer->VideoBuffer(),ui->openGLWidget); @@ -105,3 +104,16 @@ void MainWindow::RenderDone() } + +void MainWindow::on_pushButton_2_clicked() +{ + CPlayWidget *ptr = new CPlayWidget(this); + CPlayWidget *ptr1 = new CPlayWidget(this); + CPlayWidget *ptr2 = new CPlayWidget(this); + + ui->gridLayout->addWidget(ptr,0,1); + ui->gridLayout->addWidget(ptr1,1,0); + ui->gridLayout->addWidget(ptr2,1,1); + +} + diff --git a/client/webrtc_capture/src/mainwindow.h b/client/webrtc_capture/src/mainwindow.h index dac11ee..a6e215d 100644 --- a/client/webrtc_capture/src/mainwindow.h +++ b/client/webrtc_capture/src/mainwindow.h @@ -21,6 +21,8 @@ public slots: private slots: void on_pushButton_clicked(); void RenderDone(); + void on_pushButton_2_clicked(); + private: Ui::MainWindow *ui; std::unique_ptr m_capturer; diff --git a/client/webrtc_capture/src/mainwindow.ui b/client/webrtc_capture/src/mainwindow.ui index a7586e5..3843a54 100644 --- a/client/webrtc_capture/src/mainwindow.ui +++ b/client/webrtc_capture/src/mainwindow.ui @@ -22,7 +22,7 @@ - + @@ -56,6 +56,13 @@ + + + + 增加窗口 + + +