no message

master
zcy 2022-05-10 00:05:45 +08:00
parent e6e4422172
commit cb09fb77c5
3 changed files with 21 additions and 65 deletions

View File

@ -107,7 +107,7 @@ CPlayWidget::CPlayWidget(QWidget *parent):QOpenGLWidget(parent) {
m_pTextureV = NULL; m_pTextureV = NULL;
m_nVideoH = 0; m_nVideoH = 0;
m_nVideoW = 0; m_nVideoW = 0;
mType = TYPE_YUV420P; mType = TYPE_UNSET;
} }
CPlayWidget::~CPlayWidget() { CPlayWidget::~CPlayWidget() {
@ -175,20 +175,13 @@ void CPlayWidget::initializeGL()
initializeOpenGLFunctions(); initializeOpenGLFunctions();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
//???opengl???????????????????????????????
//??????????????openGL???????(OpenGL Shading Language, GLSL)??д?????С????,
// GLSL?ǹ???????OpenGL???????????,?????GLSL????????????????????????
//?????????????? ????
m_pVSHader = new QOpenGLShader(QOpenGLShader::Vertex, this); m_pVSHader = new QOpenGLShader(QOpenGLShader::Vertex, this);
//???????????????
bool bCompile = m_pVSHader->compileSourceCode(vsrcyuv); bool bCompile = m_pVSHader->compileSourceCode(vsrcyuv);
if(!bCompile) if(!bCompile)
{ {
// todo ????????? // todo ?????????
} }
//????????????? ????gpu??yuv?????rgb
m_pFSHader = new QOpenGLShader(QOpenGLShader::Fragment, this); m_pFSHader = new QOpenGLShader(QOpenGLShader::Fragment, this);
if(mType == TYPE_RGB32){ if(mType == TYPE_RGB32){
bCompile = m_pFSHader->compileSourceCode(fsrcrgb); bCompile = m_pFSHader->compileSourceCode(fsrcrgb);
@ -201,33 +194,22 @@ void CPlayWidget::initializeGL()
} }
if(!bCompile) if(!bCompile)
{ {
// todo ?????????
} }
#define PROGRAM_VERTEX_ATTRIBUTE 0 #define PROGRAM_VERTEX_ATTRIBUTE 0
#define PROGRAM_TEXCOORD_ATTRIBUTE 1 #define PROGRAM_TEXCOORD_ATTRIBUTE 1
//?????????????????
m_pShaderProgram = new QOpenGLShaderProgram; m_pShaderProgram = new QOpenGLShaderProgram;
//???????????????????????
m_pShaderProgram->addShader(m_pFSHader); m_pShaderProgram->addShader(m_pFSHader);
//????????????????????????
m_pShaderProgram->addShader(m_pVSHader); m_pShaderProgram->addShader(m_pVSHader);
//??????vertexIn?????λ??ATTRIB_VERTEX,???????????????????????????
m_pShaderProgram->bindAttributeLocation("vertexIn", ATTRIB_VERTEX); m_pShaderProgram->bindAttributeLocation("vertexIn", ATTRIB_VERTEX);
//??????textureIn?????λ??ATTRIB_TEXTURE,???????????????????????????
m_pShaderProgram->bindAttributeLocation("textureIn", ATTRIB_TEXTURE); m_pShaderProgram->bindAttributeLocation("textureIn", ATTRIB_TEXTURE);
//???????????????????????????
m_pShaderProgram->link(); m_pShaderProgram->link();
//????????????
m_pShaderProgram->bind(); m_pShaderProgram->bind();
if(this->mType == TYPE_YUV420P){ if(this->mType == TYPE_YUV420P){
initShaderYuv(); initShaderYuv();
} }
@ -237,25 +219,21 @@ void CPlayWidget::initializeGL()
if(this->mType == TYPE_I420){ if(this->mType == TYPE_I420){
initShaderI420(); initShaderI420();
} }
glClearColor(0.0,0.0,0.0,0.0);//???????? glClearColor(0.0,0.0,0.0,0.0);
} }
void CPlayWidget::resizeGL(int w, int h) void CPlayWidget::resizeGL(int w, int h)
{ {
if(h == 0)// ???????? if(h == 0)
{ {
h = 1;// ???????1 h = 1;
} }
//???????
glViewport(0,0, w,h); glViewport(0,0, w,h);
} }
void CPlayWidget::paintGL() void CPlayWidget::paintGL()
{ {
// if(!m_buffer) {
// return;
// }
if(mType == TYPE_YUV420P) if(mType == TYPE_YUV420P)
loadYuvTexture(); loadYuvTexture();
if(mType == TYPE_RGB32){ if(mType == TYPE_RGB32){
@ -264,59 +242,47 @@ void CPlayWidget::paintGL()
if(mType == TYPE_I420){ if(mType == TYPE_I420){
loadYuvTexture(); loadYuvTexture();
} }
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
return; return;
} }
void CPlayWidget::initShaderYuv() void CPlayWidget::initShaderYuv()
{ {
//?????????е????????tex_y, tex_u, tex_v??λ??,??Щ????????????????
textureUniformY = m_pShaderProgram->uniformLocation("tex_y"); textureUniformY = m_pShaderProgram->uniformLocation("tex_y");
textureUniformU = m_pShaderProgram->uniformLocation("tex_u"); textureUniformU = m_pShaderProgram->uniformLocation("tex_u");
textureUniformV = m_pShaderProgram->uniformLocation("tex_v"); textureUniformV = m_pShaderProgram->uniformLocation("tex_v");
// ???????
static const GLfloat vertexVertices[] = { 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[] = { static const GLfloat textureVertices[] = {
0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
0.0f, 0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 1.0f, 0.0f,
}; };
//????????ATTRIB_VERTEX???????????????
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices); glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices);
//????????ATTRIB_TEXTURE?????????????????
glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, textureVertices); glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, textureVertices);
//????ATTRIB_VERTEX?????????,????ǹ???
glEnableVertexAttribArray(ATTRIB_VERTEX); glEnableVertexAttribArray(ATTRIB_VERTEX);
//????ATTRIB_TEXTURE?????????,????ǹ???
glEnableVertexAttribArray(ATTRIB_TEXTURE); glEnableVertexAttribArray(ATTRIB_TEXTURE);
//????y,u,v????????
m_pTextureY = new QOpenGLTexture(QOpenGLTexture::Target2D); m_pTextureY = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_pTextureU = new QOpenGLTexture(QOpenGLTexture::Target2D); m_pTextureU = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_pTextureV = new QOpenGLTexture(QOpenGLTexture::Target2D); m_pTextureV = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_pTextureY->create(); m_pTextureY->create();
m_pTextureU->create(); m_pTextureU->create();
m_pTextureV->create(); m_pTextureV->create();
//???????y???????????????
id_y = m_pTextureY->textureId(); id_y = m_pTextureY->textureId();
//???????u???????????????
id_u = m_pTextureU->textureId(); id_u = m_pTextureU->textureId();
//???????v???????????????
id_v = m_pTextureV->textureId(); id_v = m_pTextureV->textureId();
} }
void CPlayWidget::initShaderRgb() void CPlayWidget::initShaderRgb()
{ {
//?????????е????????tex_y, tex_u, tex_v??λ??,??Щ????????????????
//????????????п??????
textureUniformRGB = m_pShaderProgram->uniformLocation("rgbdata"); textureUniformRGB = m_pShaderProgram->uniformLocation("rgbdata");
// ???????
static const GLfloat vertexVertices[] = { static const GLfloat vertexVertices[] = {
-1.0f, -1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f, -1.0f,
@ -324,26 +290,18 @@ void CPlayWidget::initShaderRgb()
1.0f, 1.0f, 1.0f, 1.0f,
}; };
//????????
static const GLfloat textureVertices[] = { static const GLfloat textureVertices[] = {
0.0f, 0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
}; };
//????????ATTRIB_VERTEX???????????????
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices); glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices);
//????????ATTRIB_TEXTURE?????????????????
glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, textureVertices); glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, textureVertices);
//????ATTRIB_VERTEX?????????,????ǹ???
glEnableVertexAttribArray(ATTRIB_VERTEX); glEnableVertexAttribArray(ATTRIB_VERTEX);
//????ATTRIB_TEXTURE?????????,????ǹ???
glEnableVertexAttribArray(ATTRIB_TEXTURE); glEnableVertexAttribArray(ATTRIB_TEXTURE);
//????y,u,v????????
m_pTextureRGB = new QOpenGLTexture(QOpenGLTexture::Target2D); m_pTextureRGB = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_pTextureRGB->create(); m_pTextureRGB->create();
//???????y???????????????
id_rgb = m_pTextureRGB->textureId(); id_rgb = m_pTextureRGB->textureId();
} }
@ -387,7 +345,6 @@ int CPlayWidget::loadYuvTexture()
return 0; return 0;
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, id_y); glBindTexture(GL_TEXTURE_2D, id_y);
// glPixelStorei(GL_UNPACK_ROW_LENGTH, m_buffer->StrideY());
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
GL_RED, GL_RED,
@ -417,7 +374,7 @@ int CPlayWidget::loadYuvTexture()
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_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); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// v分量 // v分量
glActiveTexture(GL_TEXTURE2);//???????????GL_TEXTURE2 glActiveTexture(GL_TEXTURE2);//???????????GL_TEXTURE2
glBindTexture(GL_TEXTURE_2D, id_v); glBindTexture(GL_TEXTURE_2D, id_v);
// glPixelStorei(GL_UNPACK_ROW_LENGTH, m_buffer->StrideV()); // glPixelStorei(GL_UNPACK_ROW_LENGTH, m_buffer->StrideV());
@ -434,9 +391,7 @@ int CPlayWidget::loadYuvTexture()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glUniform1i(textureUniformY, 0); glUniform1i(textureUniformY, 0);
//???u???????????
glUniform1i(textureUniformU, 1); glUniform1i(textureUniformU, 1);
//???v???????????
glUniform1i(textureUniformV, 2); glUniform1i(textureUniformV, 2);
return 0; return 0;
} }
@ -480,7 +435,7 @@ int CPlayWidget::loadRtcI420Texture()
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_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); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// v分量 // v分量
glActiveTexture(GL_TEXTURE2);//???????????GL_TEXTURE2 glActiveTexture(GL_TEXTURE2);//???????????GL_TEXTURE2
glBindTexture(GL_TEXTURE_2D, id_v); glBindTexture(GL_TEXTURE_2D, id_v);
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_buffer->StrideV()); glPixelStorei(GL_UNPACK_ROW_LENGTH, m_buffer->StrideV());
@ -497,9 +452,7 @@ int CPlayWidget::loadRtcI420Texture()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glUniform1i(textureUniformY, 0); glUniform1i(textureUniformY, 0);
//???u???????????
glUniform1i(textureUniformU, 1); glUniform1i(textureUniformU, 1);
//???v???????????
glUniform1i(textureUniformV, 2); glUniform1i(textureUniformV, 2);
return 0; return 0;
} }

View File

@ -34,6 +34,7 @@ public:
TYPE_YUV420P, TYPE_YUV420P,
TYPE_RGB32, TYPE_RGB32,
TYPE_I420, TYPE_I420,
TYPE_UNSET,
}IMG_TYPE; }IMG_TYPE;
CPlayWidget(QWidget* parent); CPlayWidget(QWidget* parent);
~CPlayWidget(); ~CPlayWidget();
@ -59,7 +60,7 @@ private:
GLuint id_rgb; GLuint id_rgb;
GLuint id_y; GLuint id_y;
GLuint id_u; GLuint id_u;
GLuint id_v; //v<><76><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID GLuint id_v;
QOpenGLTexture* m_pTextureRGB; //RGB QOpenGLTexture* m_pTextureRGB; //RGB

View File

@ -5,6 +5,11 @@
#include "video_capturer_test.h" #include "video_capturer_test.h"
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QMetaType>
#include <QStandardItemModel>
#include <Windows.h>
#include <QMainWindow>
#include "modules/video_capture/video_capture_factory.h" #include "modules/video_capture/video_capture_factory.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "video_capture.h" #include "video_capture.h"
@ -15,7 +20,6 @@
#include "rtc_base/ssl_adapter.h" #include "rtc_base/ssl_adapter.h"
#include "rtc_base/win32_socket_init.h" #include "rtc_base/win32_socket_init.h"
#include "rtc_base/win32_socket_server.h" #include "rtc_base/win32_socket_server.h"
#include <QMetaType>
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
@ -41,11 +45,9 @@
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/ref_counted_object.h" #include "rtc_base/ref_counted_object.h"
#include "rtc_base/rtc_certificate_generator.h" #include "rtc_base/rtc_certificate_generator.h"
#include <QMainWindow>
#include "api/video/i420_buffer.h" #include "api/video/i420_buffer.h"
#include "signal_client.h" #include "signal_client.h"
#include <QStandardItemModel>
#include <Windows.h>
#pragma comment (lib,"advapi32.lib") #pragma comment (lib,"advapi32.lib")