From ef1b56d0db9536b84e8612049e74a110734eb054 Mon Sep 17 00:00:00 2001 From: wanghaoyu <1580258873@qq.com> Date: Wed, 12 Mar 2025 18:23:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9EUDP=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=E4=BA=BA=E6=9C=BA=E4=BA=A4=E4=BA=92=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/GDDC/GDDC.pri | 4 +- Src/GDDC/gddcSet.cpp | 51 ++++++++++++ Src/GDDC/gddcSet.h | 8 +- Src/GDDC/gddcdlg.cpp | 3 + Src/GDDC/udppushdlg.cpp | 87 ++++++++++++++++++++ Src/GDDC/udppushdlg.h | 38 +++++++++ Src/GDDC/udppushdlg.ui | 157 ++++++++++++++++++++++++++++++++++++ Src/HomePage/udppushdlg.cpp | 59 ++++++++++++++ Src/HomePage/udppushdlg.h | 33 ++++++++ Src/HomePage/udppushdlg.ui | 157 ++++++++++++++++++++++++++++++++++++ Src/VideoGL/pushstream.cpp | 2 +- 11 files changed, 596 insertions(+), 3 deletions(-) create mode 100644 Src/GDDC/udppushdlg.cpp create mode 100644 Src/GDDC/udppushdlg.h create mode 100644 Src/GDDC/udppushdlg.ui create mode 100644 Src/HomePage/udppushdlg.cpp create mode 100644 Src/HomePage/udppushdlg.h create mode 100644 Src/HomePage/udppushdlg.ui diff --git a/Src/GDDC/GDDC.pri b/Src/GDDC/GDDC.pri index 4c70390..3263ccc 100644 --- a/Src/GDDC/GDDC.pri +++ b/Src/GDDC/GDDC.pri @@ -3,6 +3,7 @@ SOURCES += \ $$PWD/gddcdlg.cpp \ $$PWD/gddcSet.cpp \ $$PWD/gddcStateInfo.cpp \ + $$PWD/udppushdlg.cpp \ HEADERS += \ $$PWD/gddcCmdDlg.h \ @@ -11,13 +12,14 @@ HEADERS += \ $$PWD/gddcStateInfo.h \ $$PWD/structDefineMyslef.h \ $$PWD/DCFrameCkCmd.h \ + $$PWD/udppushdlg.h \ FORMS += \ $$PWD/gddcCmdDlg.ui \ $$PWD/gddcdlg.ui \ $$PWD/gddcSet.ui \ $$PWD/gddcStateInfo.ui \ - + $$PWD/udppushdlg.ui \ RESOURCES += \ $$PWD/res.qrc diff --git a/Src/GDDC/gddcSet.cpp b/Src/GDDC/gddcSet.cpp index 97f4d3c..df0c43c 100644 --- a/Src/GDDC/gddcSet.cpp +++ b/Src/GDDC/gddcSet.cpp @@ -18,6 +18,11 @@ GDDCSet::GDDCSet(QWidget *parent) : QWidget(parent), ui(new Ui::GDDCSet) { std::unique_ptr configIni = std::make_unique(urlFile, QSettings::IniFormat); QString podIp = configIni->value("Pod/IP").toString(); initPullURL(podIp); + + m_udpPushDlg = new udpPushDlg(this); + m_udpPushDlg->setWindowFlags(Qt::Dialog); + m_udpPushDlg->setWindowModality(Qt::WindowModal);//设置为模态对话框 + connect(this->m_udpPushDlg,&udpPushDlg::sendUdpPushUrl,this,&GDDCSet::processUdpUrl); } GDDCSet::~GDDCSet() { @@ -56,12 +61,14 @@ void GDDCSet::initParam() { ui->comboBox_playURL1->setEditable(true); ui->comboBox_streamSource->addItem("地面端"); ui->comboBox_streamSource->addItem("载荷端"); + ui->comboBox_streamSource->addItem("局域网"); ui->comboBox_streamSource->setCurrentIndex(0); // 应急厅指挥平台----->push.uavideo.cn ui->comboBox_pushURL->addItem(QStringLiteral("应急厅指挥平台")); // 应急厅铁塔平台----->182.92.130.23 ui->comboBox_pushURL->addItem(QStringLiteral("应急厅铁塔平台")); + ui->comboBox_pushURL->addItem(QStringLiteral("局域网设备平台")); ui->radioButton_NetCtrlUDP->setChecked(true); ui->radioButton_NetCtrlTCP->setChecked(false); @@ -118,6 +125,7 @@ void GDDCSet::initParam() { // 视频连接-显示窗口1-连接 void GDDCSet::on_pushButton_ConnectURL1_clicked() { ui->pushButton_ConnectURL1->setEnabled(false); + qDebug() << "点击后的拉流地址" << ui->comboBox_playURL1->currentText(); saveDataToLocalIni(); if (ui->pushButton_ConnectURL1->text() == "连接") { emit SignalStartConnect(1); @@ -403,3 +411,46 @@ void GDDCSet::on_radioButton_clicked() { ui->uavIDSpinBox->setEnabled(true); } } + +void GDDCSet::on_comboBox_pushURL_activated(int index) +{ + if(index == 2)//下拉列表选中局域网设备推流 + { + if(!m_udpPushDlg->isVisible()) + { + m_udpPushDlg->show(); + } + qDebug()<<"当前索引:"<< index; + m_udpPushDlg->setStateByPushOrPull(udpPushDlg::pushStreamUrl); + } +} + +void GDDCSet::processUdpUrl(QString udpUrl, int index) +{ + switch(index) + { + case udpPushDlg::pushStreamUrl: + m_pushURL = udpUrl; + break; + case udpPushDlg::pullStreamUrl: + ui->comboBox_playURL1->setCurrentText(udpUrl); + break; + default: + break; + } +} + + +void GDDCSet::on_comboBox_streamSource_activated(int index) +{ + if(index == 2)//下拉列表选中局域网设备拉流 + { + if(!m_udpPushDlg->isVisible()) + { + m_udpPushDlg->show(); + } + qDebug()<<"当前索引:"<< index; + m_udpPushDlg->setStateByPushOrPull(udpPushDlg::pullStreamUrl); + } +} + diff --git a/Src/GDDC/gddcSet.h b/Src/GDDC/gddcSet.h index f79edb4..af006cd 100644 --- a/Src/GDDC/gddcSet.h +++ b/Src/GDDC/gddcSet.h @@ -10,6 +10,8 @@ #include "Src/GDDC/structDefineMyslef.h" #include "global.h" +#include "udppushdlg.h" + namespace Ui { class GDDCSet; } @@ -26,7 +28,8 @@ private: std::map mapPushURL_yjzh; std::map mapPushURL_yjtt; - +public: + udpPushDlg* m_udpPushDlg; public: void initUDPSocket(); // 初始化UDPSocket void initWindow(); // 初始化窗口 @@ -72,6 +75,9 @@ private slots: void on_uavIDSpinBox_valueChanged(int arg1); void on_comboBox_streamSource_currentIndexChanged(int index); void on_radioButton_clicked(); + void on_comboBox_pushURL_activated(int index); + void processUdpUrl(QString udpUrl, int index); + void on_comboBox_streamSource_activated(int index); }; #endif // GDDCSET_H diff --git a/Src/GDDC/gddcdlg.cpp b/Src/GDDC/gddcdlg.cpp index a7665f0..74650be 100644 --- a/Src/GDDC/gddcdlg.cpp +++ b/Src/GDDC/gddcdlg.cpp @@ -95,6 +95,8 @@ void GDDCdlg::initWindow() { // Qt::UniqueConnection); connect(ui->WgtffmpegVideo, &VideoWidget::sendErrorMessageSignal, this, &GDDCdlg::showErrorMessage, Qt::UniqueConnection); + connect(m_DlgGDDCSet->m_udpPushDlg,&udpPushDlg::sendErrorMessageSignal,this, + &GDDCdlg::showErrorMessage); ui->WgtffmpegVideo->setVedioSaveFileDirPath("./Video"); } @@ -522,6 +524,7 @@ void GDDCdlg::startConnectURL1() { */ VideoWidget *videoWidget = ui->WgtffmpegVideo; + qDebug() << "当前拉流地址" << m_DlgGDDCSet->m_playURL1; if (!videoWidget->play(m_DlgGDDCSet->m_playURL1,true)) { g_notifyManager->notify("获取视频流失败!", "", 2, 3000); // ui->WgtffmpegVideo->stopPlay(); diff --git a/Src/GDDC/udppushdlg.cpp b/Src/GDDC/udppushdlg.cpp new file mode 100644 index 0000000..233cf1f --- /dev/null +++ b/Src/GDDC/udppushdlg.cpp @@ -0,0 +1,87 @@ +#include "udppushdlg.h" +#include "ui_udppushdlg.h" + +#include +#include + +udpPushDlg::udpPushDlg(QWidget *parent) + : QWidget(parent) + , ui(new Ui::udpPushDlg) +{ + ui->setupUi(this); + this->setFixedSize(400,300); + initLineEdit(); + QString urlFile = QCoreApplication::applicationDirPath() + "/config.ini"; + _configIni = std::make_unique(urlFile, QSettings::IniFormat); + showParam4Ini(); +} + +udpPushDlg::~udpPushDlg() +{ + delete ui; +} + +void udpPushDlg::initLineEdit() +{ + // 定义正则表达式:允许大写字母、小写字母、数字和特殊符号 + QRegularExpression regExp("^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"); + // 创建验证器 + QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this); + + QRegularExpression rx("[0-9]+"); // 只允许数字 + QRegularExpressionValidator *validator1 = new QRegularExpressionValidator(rx, this); + + // 设置验证器 + ui->lineEdit->setValidator(validator); + ui->lineEdit_2->setValidator(validator1); +} + +void udpPushDlg::showParam4Ini() +{ + QString udpPushIp = _configIni->value("UDPPushStream/IP").toString(); + int udpPushPort = _configIni->value("UDPPushStream/Port").toInt(); + ui->lineEdit->setText(udpPushIp); + ui->lineEdit_2->setText(QString::number(udpPushPort)); +} + +void udpPushDlg::setStateByPushOrPull(udpUrlType tpye) +{ + m_state = tpye; +} + +//保存界面IP及端口号参数 +void udpPushDlg::saveParam2Ini() +{ + _configIni->setValue("UDPPushStream/IP", ui->lineEdit->text()); + _configIni->setValue("UDPPushStream/Port", ui->lineEdit_2->text()); +} + +//点击确定按钮 +void udpPushDlg::on_okPushBtn_clicked() +{ + if(ui->lineEdit->text().isEmpty()) + { + emit sendErrorMessageSignal("输入IP地址不能为空",3); + return; + } + + if(ui->lineEdit_2->text().isEmpty()) + { + emit sendErrorMessageSignal("输入端口号不能为空",3); + return; + } + + if(this->isVisible()) + this->hide(); + m_udpPushUrl = QString("udp://%1:%2").arg(ui->lineEdit->text()).arg(ui->lineEdit_2->text()); + + if(m_state == pushStreamUrl) + emit sendUdpPushUrl(m_udpPushUrl, pushStreamUrl); + else if(m_state == pullStreamUrl) + emit sendUdpPushUrl(m_udpPushUrl, pullStreamUrl); + saveParam2Ini(); +} + diff --git a/Src/GDDC/udppushdlg.h b/Src/GDDC/udppushdlg.h new file mode 100644 index 0000000..b037642 --- /dev/null +++ b/Src/GDDC/udppushdlg.h @@ -0,0 +1,38 @@ +#ifndef UDPPUSHDLG_H +#define UDPPUSHDLG_H + +#include +#include + +namespace Ui { +class udpPushDlg; +} + +class udpPushDlg : public QWidget +{ + Q_OBJECT + +public: + explicit udpPushDlg(QWidget *parent = nullptr); + ~udpPushDlg(); + + enum udpUrlType{ pullStreamUrl=0, pushStreamUrl=1}; + void setStateByPushOrPull(udpUrlType tpye); //设置推拉流状态 +private slots: + void on_okPushBtn_clicked(); + +private: + Ui::udpPushDlg *ui; + QString m_udpPushUrl;//udp推流地址 + + void initLineEdit(); + void saveParam2Ini(); + void showParam4Ini(); + std::unique_ptr _configIni; //配置文件写入 + int m_state = -1; //推拉流状态初始化为-1 +signals: + void sendErrorMessageSignal(QString message, int type); + void sendUdpPushUrl(QString udpUrl, int index); +}; + +#endif // UDPPUSHDLG_H diff --git a/Src/GDDC/udppushdlg.ui b/Src/GDDC/udppushdlg.ui new file mode 100644 index 0000000..71643d3 --- /dev/null +++ b/Src/GDDC/udppushdlg.ui @@ -0,0 +1,157 @@ + + + udpPushDlg + + + + 0 + 0 + 400 + 300 + + + + + 0 + 0 + + + + 网络设置 + + + + + + Qt::Orientation::Vertical + + + QSizePolicy::Policy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Orientation::Horizontal + + + QSizePolicy::Policy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Orientation::Horizontal + + + QSizePolicy::Policy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Orientation::Vertical + + + QSizePolicy::Policy::Fixed + + + + 20 + 20 + + + + + + + + 局域网视频流网络设置 + + + + + 90 + 57 + 201 + 22 + + + + + + + 20 + 113 + 51 + 16 + + + + 端口号: + + + + + + 20 + 57 + 36 + 16 + + + + IP: + + + + + + 90 + 113 + 201 + 22 + + + + + + + 200 + 169 + 80 + 21 + + + + 确定 + + + + + + + + + diff --git a/Src/HomePage/udppushdlg.cpp b/Src/HomePage/udppushdlg.cpp new file mode 100644 index 0000000..8ae5531 --- /dev/null +++ b/Src/HomePage/udppushdlg.cpp @@ -0,0 +1,59 @@ +#include "udppushdlg.h" +#include "ui_udppushdlg.h" + +#include +#include + +udpPushDlg::udpPushDlg(QWidget *parent) + : QWidget(parent) + , ui(new Ui::udpPushDlg) +{ + ui->setupUi(this); + this->setFixedSize(400,300); + initLineEdit(); +} + +udpPushDlg::~udpPushDlg() +{ + delete ui; +} + +void udpPushDlg::initLineEdit() +{ + // 定义正则表达式:允许大写字母、小写字母、数字和特殊符号 + QRegularExpression regExp("^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"); + // 创建验证器 + QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this); + + QRegularExpression rx("[0-9]+"); // 只允许数字 + QRegularExpressionValidator *validator1 = new QRegularExpressionValidator(rx, this); + + // 设置验证器 + ui->lineEdit->setValidator(validator); + ui->lineEdit_2->setValidator(validator1); +} + +//点击确定按钮 +void udpPushDlg::on_okPushBtn_clicked() +{ + if(ui->lineEdit->text().isEmpty()) + { + emit sendErrorMessageSignal("输入IP地址不能为空",3); + return; + } + + if(ui->lineEdit_2->text().isEmpty()) + { + emit sendErrorMessageSignal("输入端口号不能为空",3); + return; + } + + if(this->isVisible()) + this->hide(); + m_udpPushUrl = QString("udp://%1:%2").arg(ui->lineEdit->text()).arg(ui->lineEdit_2->text()); + emit sendUdpPushUrl(m_udpPushUrl, pushStreamUrl); +} + diff --git a/Src/HomePage/udppushdlg.h b/Src/HomePage/udppushdlg.h new file mode 100644 index 0000000..6ccd288 --- /dev/null +++ b/Src/HomePage/udppushdlg.h @@ -0,0 +1,33 @@ +#ifndef UDPPUSHDLG_H +#define UDPPUSHDLG_H + +#include + +namespace Ui { +class udpPushDlg; +} + +class udpPushDlg : public QWidget +{ + Q_OBJECT + +public: + explicit udpPushDlg(QWidget *parent = nullptr); + ~udpPushDlg(); + + enum udpUrlType{ pullStreamUrl=0, pushStreamUrl=1}; + +private slots: + void on_okPushBtn_clicked(); + +private: + Ui::udpPushDlg *ui; + QString m_udpPushUrl;//udp推流地址 + + void initLineEdit(); +signals: + void sendErrorMessageSignal(QString message, int type); + void sendUdpPushUrl(QString url, int index); +}; + +#endif // UDPPUSHDLG_H diff --git a/Src/HomePage/udppushdlg.ui b/Src/HomePage/udppushdlg.ui new file mode 100644 index 0000000..71643d3 --- /dev/null +++ b/Src/HomePage/udppushdlg.ui @@ -0,0 +1,157 @@ + + + udpPushDlg + + + + 0 + 0 + 400 + 300 + + + + + 0 + 0 + + + + 网络设置 + + + + + + Qt::Orientation::Vertical + + + QSizePolicy::Policy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Orientation::Horizontal + + + QSizePolicy::Policy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Orientation::Horizontal + + + QSizePolicy::Policy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Orientation::Vertical + + + QSizePolicy::Policy::Fixed + + + + 20 + 20 + + + + + + + + 局域网视频流网络设置 + + + + + 90 + 57 + 201 + 22 + + + + + + + 20 + 113 + 51 + 16 + + + + 端口号: + + + + + + 20 + 57 + 36 + 16 + + + + IP: + + + + + + 90 + 113 + 201 + 22 + + + + + + + 200 + 169 + 80 + 21 + + + + 确定 + + + + + + + + + diff --git a/Src/VideoGL/pushstream.cpp b/Src/VideoGL/pushstream.cpp index ccf0d5e..768fc3f 100644 --- a/Src/VideoGL/pushstream.cpp +++ b/Src/VideoGL/pushstream.cpp @@ -254,7 +254,7 @@ void PushStream::pushStream(int64_t startTime) { av_packet_unref(inputPacket); av_packet_free(&inputPacket); } else { - QThread::usleep(1000); + av_usleep(1000); } }