加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MainWgt.cpp 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
cNull 提交于 2022-11-28 16:38 . mediasoup 修改内存泄露
#include "MainWgt.h"
#include <QPushButton>
#include <QDebug>
#include <QPainter>
#include <QMessageBox>
MainWgt::MainWgt(QWidget *parent): QWidget(parent)
{
ui.setupUi(this);
setFixedSize(983,705);
setWindowTitle("mediasoup demo");
connect(ui.videoBtn, &QPushButton::clicked, this, [=] {
m_mediaCtrl->pauseVideo(m_pauseVideo);
m_pauseVideo = !m_pauseVideo;
});
connect(ui.audioBtn, &QPushButton::clicked, this, [=] {
m_mediaCtrl->pauseAudio(m_pauseAudio);
m_pauseAudio = !m_pauseAudio;
});
m_mediaCtrl = new vi::MediaCtroller;
m_mediaCtrl->regiestCallback(this);
m_mediaCtrl->regiestRemoteVideo(std::bind(&MainWgt::remoteVideoCb,this,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
connect(ui.start, &QPushButton::clicked, this, &MainWgt::onConnectWss);
}
void MainWgt::onConnectWss()
{
//wss://192.168.20.59:4443/?roomId=1&peerId=1
if (ui.wssEdit->text().isEmpty() || ui.roomEdit->text().isEmpty() || ui.peerEdit->text().isEmpty()) {
QMessageBox::question(this, "warning", u8"ֶβΪ");
return;
}
QString wssUrl = ui.wssEdit->text() + QString("/?roomId=") + ui.roomEdit->text() + QString("&peerId=") + ui.peerEdit->text();
QString rtspUrl = ui.rtspEdit->text().toStdString().c_str();
m_mediaCtrl->setRtspUrl(rtspUrl.toUtf8().data());
m_mediaCtrl->connectServer(wssUrl.toUtf8());
}
MainWgt::~MainWgt()
{
}
void MainWgt::remoteVideoCb(QString peerId, unsigned char* yuv, int width, int height)
{
YangPlayWidget* canvas = nullptr;
if (m_canvasMap.find(peerId) == m_canvasMap.end()) {
if (m_index == 2){
canvas = ui.canvas2;
}
else if (m_index == 3){
canvas = ui.canvas3;
}
else if (m_index == 4){
canvas = ui.canvas4;
}
else if (m_index == 5){
canvas = ui.canvas5;
}
else if (m_index == 6){
canvas = ui.canvas6;
}
m_canvasMap.insert(peerId, canvas);
m_index++;
}
else {
canvas = m_canvasMap.value(peerId);
}
canvas->playVideo(yuv, width, height);
}
void MainWgt::onNewPeer(QString peerId)
{
}
void MainWgt::onLocalVideoFrame(unsigned char* pdata, int width, int height)
{
ui.canvas1->playVideo(pdata,width,height);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化