no message

master
zcy 2022-05-13 00:58:26 +08:00
parent 6dc338bad5
commit b1f865dda7
6 changed files with 66 additions and 40 deletions

View File

@ -108,6 +108,7 @@ CPlayWidget::CPlayWidget(QWidget *parent):QOpenGLWidget(parent) {
m_nVideoH = 0; m_nVideoH = 0;
m_nVideoW = 0; m_nVideoW = 0;
mType = TYPE_I420; mType = TYPE_I420;
m_start_render = false;
} }
CPlayWidget::~CPlayWidget() { CPlayWidget::~CPlayWidget() {
@ -116,7 +117,19 @@ CPlayWidget::~CPlayWidget() {
int CPlayWidget::SetDataType(CPlayWidget::IMG_TYPE type){ int CPlayWidget::SetDataType(CPlayWidget::IMG_TYPE type){
this->mType = 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; return 0;
} }
@ -230,16 +243,18 @@ void CPlayWidget::resizeGL(int w, int h)
void CPlayWidget::paintGL() void CPlayWidget::paintGL()
{ {
if(mType == TYPE_YUV420P) if(m_start_render){
loadYuvTexture(); if(mType == TYPE_YUV420P)
if(mType == TYPE_RGB32){ loadYuvTexture();
loadRgbTexture(); if(mType == TYPE_RGB32){
} loadRgbTexture();
if(mType == TYPE_I420){ }
loadYuvTexture(); if(mType == TYPE_I420){
} loadYuvTexture();
}
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
return; return;
} }

View File

@ -39,7 +39,8 @@ public:
CPlayWidget(QWidget* parent); CPlayWidget(QWidget* parent);
~CPlayWidget(); ~CPlayWidget();
int SetDataType(IMG_TYPE); int SetDataType(IMG_TYPE);
int StartRender();
int StopRender();
int OnCameraData(uint8_t *); int OnCameraData(uint8_t *);
int SetImgSize(uint32_t width,uint32_t ); int SetImgSize(uint32_t width,uint32_t );
protected: protected:
@ -82,5 +83,6 @@ private:
int loadRtcI420Texture(); int loadRtcI420Texture();
int loadRgbTexture(); int loadRgbTexture();
rtc::scoped_refptr<webrtc::I420BufferInterface> m_buffer; rtc::scoped_refptr<webrtc::I420BufferInterface> m_buffer;
bool m_start_render;
}; };
#endif #endif

View File

@ -56,6 +56,8 @@ void EnumCapture()
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>");
qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>&");
rtc::WinsockInitializer winsock_init; rtc::WinsockInitializer winsock_init;
rtc::Win32SocketServer w32_ss; rtc::Win32SocketServer w32_ss;
@ -63,25 +65,11 @@ int main(int argc, char *argv[])
rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread); rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
rtc::InitializeSSL(); rtc::InitializeSSL();
// std::unique_ptr<CameraVideoSink> 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); setbuf(stdout, NULL);
qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>");
qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>&");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
// QObject::connect((CameraVideoSink*)capturer.get(),SIGNAL(UpdateFrame(rtc::scoped_refptr<webrtc::I420BufferInterface>&)),&w, w.setWindowTitle("webrtc easy demo");
// SLOT(OnUpdateFrame( rtc::scoped_refptr<webrtc::I420BufferInterface>&)),Qt::ConnectionType::AutoConnection);
w.show(); w.show();
return a.exec(); return a.exec();
} }

View File

@ -45,21 +45,19 @@ MainWindow::MainWindow(QWidget *parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
// ui->openGLWidget->SetImgSize(640,480); ui->openGLWidget->show();
ui->openGLWidget->show();
std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info( std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info(
webrtc::VideoCaptureFactory::CreateDeviceInfo()); webrtc::VideoCaptureFactory::CreateDeviceInfo());
if (!info) { if (!info) {
RTC_LOG(LERROR) << "CreateDeviceInfo failed"; RTC_LOG(LERROR) << "CreateDeviceInfo failed";
} }
int num_devices = info->NumberOfDevices(); int num_devices = info->NumberOfDevices();
for (int i = 0; i < num_devices; ++i) { for (int i = 0; i < num_devices; ++i) {
char name[100]; char name[100];
info->GetDeviceName(i,name,100,nullptr,0,nullptr,0); info->GetDeviceName(i,name,100,nullptr,0,nullptr,0);
ui->comboBox->addItem(QString::asprintf("%s",name),i); ui->comboBox->addItem(QString::asprintf("%s",name),i);
} }
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -92,6 +90,7 @@ void MainWindow::on_pushButton_clicked()
ui->openGLWidget->SetDataType(CPlayWidget::TYPE_YUV420P); ui->openGLWidget->SetDataType(CPlayWidget::TYPE_YUV420P);
ui->openGLWidget->SetImgSize(m_capturer->Capability().width, ui->openGLWidget->SetImgSize(m_capturer->Capability().width,
m_capturer->Capability().height); m_capturer->Capability().height);
ui->openGLWidget->StartRender();
// ui->openGLWidget->moveToThread(&gRender->Thread()); // ui->openGLWidget->moveToThread(&gRender->Thread());
if(gRender == nullptr){ if(gRender == nullptr){
gRender = new AsyncRennder(this,m_capturer->VideoBuffer(),ui->openGLWidget); 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);
}

View File

@ -21,6 +21,8 @@ public slots:
private slots: private slots:
void on_pushButton_clicked(); void on_pushButton_clicked();
void RenderDone(); void RenderDone();
void on_pushButton_2_clicked();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
std::unique_ptr<CameraVideoSink> m_capturer; std::unique_ptr<CameraVideoSink> m_capturer;

View File

@ -22,7 +22,7 @@
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,9"> <layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,9">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,1,1,1,1,3"> <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,1,1,1,1,0,3">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@ -56,6 +56,13 @@
<item> <item>
<widget class="QComboBox" name="comboBox_2"/> <widget class="QComboBox" name="comboBox_2"/>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>增加窗口</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">