Skip to content

Commit

Permalink
7.0.016
Browse files Browse the repository at this point in the history
  • Loading branch information
yangrtc committed Aug 8, 2023
1 parent 995e8fe commit 8663858
Show file tree
Hide file tree
Showing 25 changed files with 1,312 additions and 44 deletions.
3 changes: 2 additions & 1 deletion demo/metaplayer7/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ void MainWindow::initVideoThread(YangRecordThread *prt){
m_videoThread->m_video=m_videoWin;
m_videoThread->initPara();
m_videoThread->m_syn= m_context->synMgr.session->playBuffer;

m_videoWin->resize(700,500);
qDebug()<<"win width=="<<m_videoWin->width()<<" height="<<m_videoWin->height();
}

void MainWindow::on_m_b_play_clicked()
Expand Down
73 changes: 72 additions & 1 deletion demo/metaplayer7/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,77 @@
<property name="windowTitle">
<string>webrtc拉流播放demo</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">QWidget, QLabel{
color:white;
border: 1px solid white;
padding:0;
border-radius:5px;
background-color:rgb(20,50,70);
/** background-color:rgba(250,170,0,150);**/
}


QTabWidget{

border: 1px solid white;
background-color:rgb(20,50,70);
}
QTabWidget::tab-bar{
alignment:left;
left:1px;
}
QTabWidget::pane {
/*background-color:rgb(20,50,70);*/
border:1px solid white;
}
QTabBar{

background-color:white;
}
QTabBar::tab{
min-height:28px;
padding:0 10px;
border:0;
margin:1px 1px 0 0;
background-color:rgb(20,50,70);
}
QTabBar::tab:first{
margin-left:1px;
}
QTabBar::tab:hover{
color:cyan;
}
QTabBar::tab:selected{
background-color: rgb(20, 100, 150);
}
QTabBar::tab:selected:hover{
}

QTabBar::tear{
}
QTabBar::scroller{
}
QMenu {
background-color: rgb(20,50,70);
border: 1px solid white;
}

QMenu::item {

background-color: transparent;
padding:8px 32px;
margin:0px 8px;
border-bottom:1px solid #DBDBDB;
}

QMenu::item:selected {
background-color: #2dabf9;
}</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="m_l_url">
<property name="geometry">
Expand Down Expand Up @@ -73,7 +144,7 @@
<x>0</x>
<y>0</y>
<width>1101</width>
<height>48</height>
<height>24</height>
</rect>
</property>
</widget>
Expand Down
6 changes: 5 additions & 1 deletion demo/metaplayer7/metaplayer7.pro
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ unix{
}
LIBS += -L$$HOME_BASE/thirdparty/lib

LIBS += -lmetartc7 -lmetartccore7 -lyuv -lspeexdsp -lopus -lopenh264 -lusrsctp -lpthread -lasound -ldl
LIBS += -lmetartc7 -lmetartccore7 -lyuv -lspeexdsp -lopus -lyangh264decoder -lusrsctp -lpthread -ldl
#mac/ios
#LIBS += -framework CoreAudio -framework AudioUnit
#linux
LIBS += -lasound
#openssl
LIBS += -lssl2 -lcrypto2 -lsrtp2

Expand Down
7 changes: 5 additions & 2 deletions demo/metaplayer7/video/yangrecordthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ YangRecordThread::YangRecordThread()
m_playHeight=480;
m_playBuffer=new uint8_t[m_playWidth*m_playHeight*3/2];
memset(m_playBuffer,0,m_playWidth*m_playHeight);
memset(m_playBuffer+m_playWidth*m_playHeight,128,(m_playWidth*m_playHeight)>>1);
// memset(m_playBuffer+m_playWidth*m_playHeight,128,(m_playWidth*m_playHeight)>>1);
memset(m_playBuffer+m_playWidth*m_playHeight,0,(m_playWidth*m_playHeight)>>1);
}

YangRecordThread::~YangRecordThread(){
Expand Down Expand Up @@ -60,11 +61,13 @@ void YangRecordThread::render(){
uint8_t* t_vb=m_syn->getVideoRef(m_syn->session,&m_frame);

if(t_vb&&m_video){

m_video->playVideo(t_vb,m_syn->width(m_syn->session),m_syn->height(m_syn->session));
}

t_vb=NULL;
}else{

if(m_video) m_video->playVideo(m_playBuffer,m_playWidth,m_playHeight);
}
}
Expand All @@ -82,5 +85,5 @@ void YangRecordThread::run(){
render();
}
m_isStart=0;
// closeAll();

}
118 changes: 105 additions & 13 deletions demo/metaplayer7/yangplayer/YangPlayWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ YangPlayWidget::YangPlayWidget(QWidget *parent) : QOpenGLWidget(parent)

m_nVideoH = 0;
m_nVideoW = 0;
// QPalette pal(palette());
#if defined (__APPLE__)
// QSurfaceFormat format;
// format.setVersion(2,0);
// format.setProfile(QSurfaceFormat::CoreProfile);
//QSurfaceFormat::setDefaultFormat(format);
#endif

// QPalette pal(palette());
// pal.setColor(QPalette::Background, Qt::black);
// setAutoFillBackground(true);
// setPalette(pal);
Expand Down Expand Up @@ -59,6 +66,7 @@ void YangPlayWidget::playVideo(unsigned char *p,int wid,int hei)
m_nVideoW = wid;
m_nVideoH = hei;
}

m_pBufYuv420p=p;
update();
// m_pBufYuv420p=NULL;
Expand All @@ -70,7 +78,36 @@ void YangPlayWidget::initializeGL()
initializeOpenGLFunctions();
glEnable(GL_DEPTH_TEST);
m_vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
#if !defined (__APPLE__)
const char *vsrc = R"(attribute highp vec4 vertexIn;
attribute highp vec2 textureIn;
varying highp vec2 textureOut;
void main(void)
{
textureOut = textureIn;
gl_Position = vertexIn;
})";

const char *fsrc = R"(varying highp vec2 textureOut;
uniform lowp sampler2D tex_y;
uniform lowp sampler2D tex_u;
uniform lowp sampler2D tex_v;
void main(void)
{
mediump vec3 yuv;
lowp vec3 rgb;
yuv.x = (texture2D(tex_y, textureOut).r - (16.0 / 255.0));
yuv.y = (texture2D(tex_u, textureOut).r - 0.5);
yuv.z = (texture2D(tex_v, textureOut).r - 0.5);
rgb = mat3( 1.164, 1.164, 1.164,
0.0, -0.213, 2.112,
1.793, -0.533, 0.0 ) * yuv;
gl_FragColor = vec4(rgb, 1.0);
})";


#else
const char *vsrc = "attribute vec4 vertexIn; \
attribute vec2 textureIn; \
varying vec2 textureOut; \
Expand All @@ -80,12 +117,6 @@ void YangPlayWidget::initializeGL()
textureOut = textureIn; \
}";

bool bCompile = m_vshader->compileSourceCode(vsrc);
if(!bCompile)
{
}

m_fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
const char *fsrc = "varying vec2 textureOut; \
uniform sampler2D tex_y; \
uniform sampler2D tex_u; \
Expand All @@ -102,15 +133,31 @@ void YangPlayWidget::initializeGL()
1.402, -0.71414, 0) * yuv; \
gl_FragColor = vec4(rgb, 1); \
}";
#endif
bool bCompile = m_vshader->compileSourceCode(vsrc);
if(!bCompile)
{
yang_error("opengl compile source vsrc fail!");
qDebug()<<"opengl compile source vsrc fail!";
}else{
qDebug()<<"opengl compile source vsrc success!";
}

m_fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);

//将glsl源码送入编译器编译着色器程序
bCompile = m_fshader->compileSourceCode(fsrc);
if(!bCompile)
{
yang_error("opengl compile source fsrc fail!");
qDebug()<<"opengl compile source fsrc fail!";
}else{
qDebug()<<"opengl compile source fsrc success!";
}
#define PROGRAM_VERTEX_ATTRIBUTE 0
#define PROGRAM_TEXCOORD_ATTRIBUTE 1

m_shaderProgram = new QOpenGLShaderProgram;
m_shaderProgram = new QOpenGLShaderProgram();
m_shaderProgram->addShader(m_fshader);
m_shaderProgram->addShader(m_vshader);
m_shaderProgram->bindAttributeLocation("vertexIn", ATTRIB_VERTEX);
Expand All @@ -137,24 +184,50 @@ void YangPlayWidget::initializeGL()
};

glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices);
glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, textureVertices);

glEnableVertexAttribArray(ATTRIB_VERTEX);

glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, textureVertices);
glEnableVertexAttribArray(ATTRIB_TEXTURE);

#if defined(__APPLE__)
glGenTextures(1, &id_y);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, id_y);
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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glUniform1i(textureUniformY, 0);

glGenTextures(1, &id_u);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, id_u);
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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glUniform1i(textureUniformU, 1);

glGenTextures(1, &id_v);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, id_v);
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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glUniform1i(textureUniformV, 2);
#else
m_textureY = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_textureU = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_textureV = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_textureY->create();
m_textureU->create();
m_textureV->create();

id_y = m_textureY->textureId();
id_u = m_textureU->textureId();
id_v = m_textureV->textureId();
// glClearColor(0,0,0,0.0);
#endif
glClearColor(0.3,0.3,0.3,0.0);//设置背景色

}

void YangPlayWidget::resizeGL(int w, int h)
Expand All @@ -170,6 +243,23 @@ void YangPlayWidget::resizeGL(int w, int h)
void YangPlayWidget::paintGL()
{
//if(m_pBufYuv420p==NULL) return;
#if defined (__APPLE__)
glBindTexture(GL_TEXTURE_2D, id_y);

glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,m_nVideoW,m_nVideoH,
0,GL_LUMINANCE, GL_UNSIGNED_BYTE,m_pBufYuv420p);

glBindTexture(GL_TEXTURE_2D, id_u);
glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE, m_nVideoW >> 1,m_nVideoH >> 1,
0,GL_LUMINANCE,GL_UNSIGNED_BYTE,m_pBufYuv420p+m_nVideoW*m_nVideoH);

glBindTexture(GL_TEXTURE_2D, id_v);
glTexImage2D(GL_TEXTURE_2D,0, GL_LUMINANCE, m_nVideoW >> 1,m_nVideoH >> 1,
0,GL_LUMINANCE,GL_UNSIGNED_BYTE,m_pBufYuv420p+m_nVideoW*m_nVideoH*5/4);

glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
#else
glActiveTexture(GL_TEXTURE0);

glBindTexture(GL_TEXTURE_2D, id_y);
Expand Down Expand Up @@ -199,6 +289,8 @@ void YangPlayWidget::paintGL()
glUniform1i(textureUniformU, 1);
glUniform1i(textureUniformV, 2);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
#endif

return;
}

6 changes: 5 additions & 1 deletion demo/metaplayer7/yangplayer/YangPlayerPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ void YangPlayerPlay::initAudioPlay(YangContext* paudio){
#ifdef __ANDROID__
m_audioPlay = new YangAudioPlayAndroid(&paudio->avinfo,&paudio->synMgr);
#else
m_audioPlay = new YangAudioPlayLinux(&paudio->avinfo,&paudio->synMgr);
#if defined(__APPLE__)
m_audioPlay = new YangAudioPlayMac(&paudio->avinfo,&paudio->synMgr);
#else
m_audioPlay = new YangAudioPlayLinux(&paudio->avinfo,&paudio->synMgr);
#endif
#endif
#endif
m_audioPlay->init();
Expand Down
7 changes: 5 additions & 2 deletions demo/metapushstream7/metapushstream7.pro
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ unix{
DESTDIR += $$HOME_BASE/bin/app_release
}

LIBS += -L$$HOME_BASE/thirdparty/lib -lmetartc7 -lmetartccore7 -lyuv -lopenh264 -lspeexdsp -lopus -lusrsctp -lpthread -lasound -ldl

LIBS += -L$$HOME_BASE/thirdparty/lib -lmetartc7 -lmetartccore7 -lyuv -lopenh264 -lspeexdsp -lopus -lusrsctp -lpthread -ldl
#linux
LIBS += -lasound
#mac/ios
#LIBS += -framework CoreAudio -framework AudioUnit
#openssl
LIBS += -lssl2 -lcrypto2 -lsrtp2
#mbtls
Expand Down
1 change: 1 addition & 0 deletions demo/metapushstream7/yangpush/YangPushCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void YangPushCapture::setInAudioBuffer(vector<YangAudioPlayBuffer*> *pbuf){
if(m_audioCapture!=NULL) m_audioCapture->setInAudioBuffer(pbuf);
}
void YangPushCapture::startAudioCapture() {

if (m_audioCapture && !m_audioCapture->m_isStart)
m_audioCapture->start();
}
Expand Down
1 change: 1 addition & 0 deletions demo/metapushstream7/yangpush/YangPushHandleImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ int YangPushHandleImpl::publish(char* url,yangbool isWhip) {
m_rtcPub = new YangRtcPublish(m_context);

}

if(m_hasAudio) {
m_hasAudio=bool(m_cap->startAudioCapture()==Yang_Ok);
}
Expand Down
3 changes: 2 additions & 1 deletion demo/metapushstream7/yangpush/YangPushPublish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ YangPushCapture* YangPushPublish::getPushCapture(){
}

int32_t YangPushPublish::startAudioCapture() {
int32_t err=Yang_Ok;
if (isStartAudioCapture == 1) return Yang_Ok;
if (m_capture == NULL) m_capture=new YangPushCapture(m_context);
int32_t err=Yang_Ok;

if((err=m_capture->initAudio(NULL))!=Yang_Ok) return yang_error_wrap(err,"init audioCapture fail");

m_capture->startAudioCapture();
Expand Down
Loading

0 comments on commit 8663858

Please sign in to comment.