diff --git a/Src/GDDC/gddcSet.cpp b/Src/GDDC/gddcSet.cpp index e97e5c3..d935778 100644 --- a/Src/GDDC/gddcSet.cpp +++ b/Src/GDDC/gddcSet.cpp @@ -26,11 +26,14 @@ void GDDCSet::initWindow() { } void GDDCSet::initUDPSocket() {} void GDDCSet::initParam() { + m_FlowType = ""; + // m_myPairNetwork("",0,"",0); // QSettings setting("./sentence.ini",QSettings::IniFormat); // setting.setIniCodec(QTextCodec::codecForName("UTF-8")); //重点 ui->comboBox_streamType->addItem("RTSP"); + ui->comboBox_streamType->addItem("RTMP"); // ui->comboBox_streamType->addItem("UDP Raw"); // ui->comboBox_streamType->addItem("UDP 422"); // ui->comboBox_streamType->addItem("UDP TS"); @@ -52,10 +55,20 @@ void GDDCSet::initParam() { char *strSysIniName = m_configIniPath.data(); // 系统配置文件路径 char inBuf[100]; - ::GetPrivateProfileStringA("光电吊舱-视频连接-显示窗口2", "播放URL", "-1", + ::GetPrivateProfileStringA("光电吊舱-视频连接-显示窗口1", "流类型", "-1", + inBuf, 100, strSysIniName); + m_FlowType = streamTypeToflowType(QString::fromUtf8(inBuf)); + ui->comboBox_streamType->setCurrentText(flowTypeTostreamType(m_FlowType)); + + ::GetPrivateProfileStringA("光电吊舱-视频连接-显示窗口1", "播放URL", "-1", inBuf, 100, strSysIniName); - m_playURL2 = QString::fromUtf8(inBuf); - ui->lineEdit_playURL2->setText(m_playURL2); + m_playURL1 = QString::fromUtf8(inBuf); + ui->comboBox_playURL1->setCurrentText(m_playURL1); + + // ::GetPrivateProfileStringA("光电吊舱-视频连接-显示窗口2", "播放URL", "-1", + // inBuf, 100, strSysIniName); + // m_playURL2 = QString::fromUtf8(inBuf); + // ui->lineEdit_playURL2->setText(m_playURL2); ::GetPrivateProfileStringA("光电吊舱-推流", "推流URL", "-1", inBuf, 100, strSysIniName); @@ -145,10 +158,10 @@ void GDDCSet::on_pushButton_pushURL_clicked() { saveDataToLocalIni(); if (ui->pushButton_pushURL->text() == "推送") { emit SignalStartConnect(6); - ui->pushButton_pushURL->setText("停止推送"); + //ui->pushButton_pushURL->setText("停止推送"); } else { emit SignalStopConnect(6); - ui->pushButton_pushURL->setText("推送"); + //ui->pushButton_pushURL->setText("推送"); } } @@ -182,12 +195,26 @@ void GDDCSet::saveDataToLocalIni() { ::WritePrivateProfileStringA("光电吊舱-网络控制", "远端Port", inBuf, strSysIniName); - m_playURL2 = ui->lineEdit_playURL2->text(); - ba = m_playURL2.toLocal8Bit(); + QString streamType = ui->comboBox_streamType->currentText(); + m_FlowType = streamTypeToflowType(streamType); + ba = streamType.toLocal8Bit(); inBuf = ba.data(); - ::WritePrivateProfileStringA("光电吊舱-视频连接-显示窗口2", "播放URL", inBuf, + ::WritePrivateProfileStringA("光电吊舱-视频连接-显示窗口1", "流类型", inBuf, strSysIniName); + m_playURL1 = ui->comboBox_playURL1->currentText(); + ba = m_playURL1.toLocal8Bit(); + inBuf = ba.data(); + ::WritePrivateProfileStringA("光电吊舱-视频连接-显示窗口1", "播放URL", inBuf, + strSysIniName); + + + // m_playURL2 = ui->lineEdit_playURL2->text(); + // ba = m_playURL2.toLocal8Bit(); + // inBuf = ba.data(); + // ::WritePrivateProfileStringA("光电吊舱-视频连接-显示窗口2", "播放URL", inBuf, + // strSysIniName); + m_pushURL = ui->lineEdit_pushURL->text(); ba = m_pushURL.toLocal8Bit(); inBuf = ba.data(); @@ -196,3 +223,65 @@ void GDDCSet::saveDataToLocalIni() { m_playURL1 = ui->comboBox_playURL1->currentText(); } + +// //流类型 +// void GDDCSet::on_comboBox_streamType_currentIndexChanged(int index) +// { +// switch(index) +// { +// case 0: +// m_FlowType = "TCP"; +// break; +// case 1: +// m_FlowType = "UDP"; +// break; +// default: +// break; +// } +// } +QString GDDCSet::streamTypeToflowType(QString type) +{ + if(type == "RTSP") + { + return "TCP"; + } + else if(type == "RTMP") + { + return "UDP"; + } + else + return "TCP"; +} +QString GDDCSet::flowTypeTostreamType(QString type) +{ + if(type == "TCP") + { + return "RTSP"; + } + else if(type == "UDP") + { + return "RTMP"; + } + else + return "RTSP"; +} + +void GDDCSet::setConnectURL1Text(QString param) +{ + ui->pushButton_ConnectURL1->setText(param); +} + +void GDDCSet::setConnectURL2Text(QString param) +{ + ui->pushButton_ConnectURL1->setText(param); +} + +void GDDCSet::setNetCtrlText(QString param) +{ + ui->pushButton_NetCtrlConnect->setText(param); +} + +void GDDCSet::setPushStreamText(QString param) +{ + ui->pushButton_pushURL->setText(param); +} diff --git a/Src/GDDC/gddcSet.h b/Src/GDDC/gddcSet.h index 8659e26..9135104 100644 --- a/Src/GDDC/gddcSet.h +++ b/Src/GDDC/gddcSet.h @@ -32,6 +32,17 @@ public: QString m_playURL2; // 光电吊舱-视频连接-显示窗口2-URL地址 QString m_pushURL; // 光电吊舱-推流URL地址 MyPairNetwork m_myPairNetwork; // 网络通信结构体 + QString m_FlowType; // 流类型 + + QString streamTypeToflowType(QString); + QString flowTypeTostreamType(QString); + + + void setConnectURL1Text(QString); + void setConnectURL2Text(QString); + void setNetCtrlText(QString); + void setPushStreamText(QString); + signals: /* int a * 1视频连接1 @@ -50,6 +61,7 @@ private slots: void on_pushButton_serialControlConnect_clicked(); // 串口控制-连接 void on_pushButton_NetCtrlConnect_clicked(); // 网络控制-连接 void on_pushButton_pushURL_clicked(); // 推流 + //void on_comboBox_streamType_currentIndexChanged(int index); }; #endif // GDDCSET_H diff --git a/Src/GDDC/gddcSet.ui b/Src/GDDC/gddcSet.ui index 5ef7698..bb5b352 100644 --- a/Src/GDDC/gddcSet.ui +++ b/Src/GDDC/gddcSet.ui @@ -7,7 +7,7 @@ 0 0 761 - 360 + 342 @@ -22,7 +22,7 @@ 30 10 701 - 181 + 141 @@ -34,8 +34,8 @@ - 10 - 30 + 440 + 60 61 21 @@ -47,8 +47,8 @@ - 90 - 30 + 510 + 60 72 23 @@ -58,7 +58,7 @@ 10 - 70 + 30 61 16 @@ -71,7 +71,7 @@ 20 - 100 + 60 71 21 @@ -84,8 +84,8 @@ 90 - 100 - 491 + 60 + 331 23 @@ -94,7 +94,7 @@ 600 - 100 + 60 80 23 @@ -156,7 +156,7 @@ 20 - 140 + 100 71 21 @@ -169,7 +169,7 @@ 90 - 140 + 100 491 23 @@ -179,7 +179,7 @@ 600 - 140 + 100 80 23 @@ -281,9 +281,9 @@ 30 - 200 + 166 701 - 141 + 131 @@ -309,7 +309,7 @@ 10 - 28 + 30 97 21 @@ -322,7 +322,7 @@ 500 - 98 + 90 81 23 @@ -332,7 +332,7 @@ 420 - 68 + 60 71 21 @@ -345,7 +345,7 @@ 500 - 68 + 60 81 23 @@ -355,7 +355,7 @@ 30 - 68 + 60 53 15 @@ -368,7 +368,7 @@ 90 - 68 + 60 301 23 @@ -378,7 +378,7 @@ 90 - 98 + 90 301 23 @@ -388,7 +388,7 @@ 30 - 98 + 90 53 15 @@ -401,7 +401,7 @@ 90 - 28 + 30 97 21 @@ -414,7 +414,7 @@ 420 - 103 + 90 71 20 diff --git a/Src/GDDC/gddcdlg.cpp b/Src/GDDC/gddcdlg.cpp index abb00d5..0243e55 100644 --- a/Src/GDDC/gddcdlg.cpp +++ b/Src/GDDC/gddcdlg.cpp @@ -51,6 +51,7 @@ GDDCdlg::GDDCdlg(QWidget *parent) : QWidget(parent), ui(new Ui::GDDCdlg) { GDDCdlg::~GDDCdlg() { // 停止所有通信 + stopPushURL(); stopConnectURL1(); stopConnectURL2(); stopConnectSerialCtrl(); @@ -375,9 +376,9 @@ void GDDCdlg::GDDCControlTimeOut() { void GDDCdlg::startConnectURL1() { if (!connectFlag[0]) { connectFlag[0] = true; - // Is_openVideo = true; - // ui->WgtffmpegVideo->Isplay(Is_openVideo); - // ui->WgtffmpegVideo->m_PlayStatus = Is_openVideo; + + // 开始拉流 + ui->WgtffmpegVideo->m_flowType = m_DlgGDDCSet->m_FlowType; ui->WgtffmpegVideo->play(m_DlgGDDCSet->m_playURL1); } } @@ -468,61 +469,77 @@ void GDDCdlg::stopConnectTCPCtrl() { // 开始视频推流 void GDDCdlg::startPushURL() { if (!connectFlag[5]) { - process = new QProcess(); - connect(process, &QProcess::readyReadStandardOutput, this, [=]() mutable { - QString Output = process->readAllStandardOutput(); - qDebug() << "Output:" << Output; - }); - connect(process, &QProcess::readyReadStandardError, this, [=]() mutable { - QString Error = process->readAllStandardError(); - qDebug() << "Error Output:" << Error; - }); - - // process->start("cmd",QStringList()<<"/c"<<"ffmpeg -i - // rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid -c copy -f flv - // rtmp://182.92.130.23/app/test"); - - QStringList m_cmd; - QString str; - str = "ffmpeg -i " + m_DlgGDDCSet->m_playURL1 + " -c copy -f flv " + - m_DlgGDDCSet->m_pushURL; - // str = "TaskList"; - m_cmd << "/c" << str; - // m_cmd<<"/c"<<"ping"<<"baidu.com"; - process->start("cmd", m_cmd); - connectFlag[5] = true; - // process->waitForStarted(); //等待程序启动 - // process->waitForFinished(); //等待程序关闭 + // //方式1:命令行推流 + // process = new QProcess(); + // connect(process, &QProcess::readyReadStandardOutput, this, [=]() mutable { + // QString Output = process->readAllStandardOutput(); + // qDebug() << "Output:" << Output; + // }); + // connect(process, &QProcess::readyReadStandardError, this, [=]() mutable { + // QString Error = process->readAllStandardError(); + // qDebug() << "Error Output:" << Error; + // }); + + // // process->start("cmd",QStringList()<<"/c"<<"ffmpeg -i + // // rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid -c copy -f flv + // // rtmp://182.92.130.23/app/test"); + + // QStringList m_cmd; + // QString str; + // // str = "ffmpeg -i " + m_DlgGDDCSet->m_playURL1 + " -c copy -f flv " + + // // m_DlgGDDCSet->m_pushURL; + // str = "ffmpeg -rtsp_transport tcp -i " + m_DlgGDDCSet->m_playURL1 + " -c:v libx264 -c:a copy -f flv " + + // m_DlgGDDCSet->m_pushURL; + // m_cmd << "/c" << str; + // process->start("cmd", m_cmd); + + // //方式2:代码推流 + // if(!connectFlag[0]) + // { + // QMessageBox::information(NULL, tr("提示"), "请先开始连接", QMessageBox::Ok); + // m_DlgGDDCSet->setPushStreamText("推送"); + // return; + // } + ui->WgtffmpegVideo->setPushStreamIP(m_DlgGDDCSet->m_pushURL); + m_DlgGDDCSet->setPushStreamText("停止推送"); + + connectFlag[5] = true; } } // 停止视频推流 void GDDCdlg::stopPushURL() { if (connectFlag[5]) { - if (process != nullptr) { - process->terminate(); - process->close(); - process->kill(); - // 检查进程退出状态 - if (process->exitStatus() == QProcess::CrashExit) { - qDebug() << "Process crashed"; - } else { - qDebug() << "Process exited normally"; - } - delete process; - - // 推流进程未自动关闭,手动关闭 - int pids = GetmPid(L"ffmpeg.exe"); - qDebug() << "ffmpeg.exe进程的pid为:" << pids; - if (pids != 0) { - // QString cmd; - // cmd = "taskkill /pid "+QString::number(pids)+" -f"; - QStringList m_cmd; - m_cmd << "/c" << "taskkill /pid " << QString::number(pids) << " -f"; - QProcess::startDetached("cmd", m_cmd); - } - } + + // //方式1:命令行推流 + // if (process != nullptr) { + // process->terminate(); + // process->close(); + // process->kill(); + // // 检查进程退出状态 + // if (process->exitStatus() == QProcess::CrashExit) { + // qDebug() << "Process crashed"; + // } else { + // qDebug() << "Process exited normally"; + // } + // delete process; + + // // 推流进程未自动关闭,手动关闭 + // int pids = GetmPid(L"ffmpeg.exe"); + // qDebug() << "ffmpeg.exe进程的pid为:" << pids; + // if (pids != 0) { + // QStringList m_cmd; + // m_cmd << "/c" << "taskkill /pid " << QString::number(pids) << " -f"; + // QProcess::startDetached("cmd", m_cmd); + // } + // } + + + //方式2:代码推流 + ui->WgtffmpegVideo->setPushStreamIP(""); + m_DlgGDDCSet->setPushStreamText("推送"); + connectFlag[5] = false; } } diff --git a/Src/GDDC/gddcdlg.h b/Src/GDDC/gddcdlg.h index e7256f0..c8139f0 100644 --- a/Src/GDDC/gddcdlg.h +++ b/Src/GDDC/gddcdlg.h @@ -23,6 +23,8 @@ // #include "ui_gddcSet.h" #include "QProcess" #include +#include + #define cmdLength 44 namespace Ui { class GDDCdlg; diff --git a/Src/HomePage/homepagesetingwidget.cpp b/Src/HomePage/homepagesetingwidget.cpp index 285ec37..1d26536 100644 --- a/Src/HomePage/homepagesetingwidget.cpp +++ b/Src/HomePage/homepagesetingwidget.cpp @@ -98,6 +98,7 @@ void HomePageSetingWidget::on_oneKeyButton_clicked() { on_lLinkButton_clicked(); on_netButton_clicked(); on_sateliteButton_clicked(); + on_modelCameraButton_clicked(); } /************************************************* * @func getAllParam diff --git a/Src/Video/cffmpeg_decode.cpp b/Src/Video/cffmpeg_decode.cpp index 54c657d..1b80d58 100644 --- a/Src/Video/cffmpeg_decode.cpp +++ b/Src/Video/cffmpeg_decode.cpp @@ -38,7 +38,7 @@ bool Cffmpeg_decode::open_input_file() { // 设置缓存大小,1080p可将值调大 av_dict_set(&avdic, "buffer_size", "2048000", 0); // 以udp方式打开,如果以tcp方式打开将udp替换为tcp - av_dict_set(&avdic, "rtsp_transport", "tcp", 0); + av_dict_set(&avdic, "rtsp_transport", m_rtsp_transport.toUtf8().data(), 0); // 设置超时断开连接时间,单位微秒//listen_timeout // av_dict_set(&avdic, "listen_timeout", "200000", 0); av_dict_set(&avdic, "stimeout", "200000", 0); @@ -333,3 +333,8 @@ void Cffmpeg_decode::saveDone() { // m_videoStreamOut = nullptr; } } + +void Cffmpeg_decode::setFlowType(QString param) +{ + m_rtsp_transport = param; +} diff --git a/Src/Video/cffmpeg_decode.h b/Src/Video/cffmpeg_decode.h index 1b8d922..9512b61 100644 --- a/Src/Video/cffmpeg_decode.h +++ b/Src/Video/cffmpeg_decode.h @@ -27,6 +27,7 @@ public: * @param fileDirPath 文件夹路径 */ void setSaveFileDirPath(QString fileDirPath); + void setFlowType(QString);//设置拉流打开方式 public slots: void run(); void setUrl(QString url); @@ -76,6 +77,9 @@ private: QString m_strCodecName; // 编解码器名称 AVStream *m_videoStreamOut = nullptr; // 输出视频流 bool m_writeHeader = false; // 是否写入文件头 + + + QString m_rtsp_transport = ""; //拉流打开方式,UDP或TCP private: bool openSave(); void saveDone(); diff --git a/Src/Video/ffmpegvideodlg.cpp b/Src/Video/ffmpegvideodlg.cpp index 8be5b8e..6e72b05 100644 --- a/Src/Video/ffmpegvideodlg.cpp +++ b/Src/Video/ffmpegvideodlg.cpp @@ -7,6 +7,8 @@ ffmpegvideoDlg::ffmpegvideoDlg(QWidget *parent) ui->setupUi(this); ffmpegPushStream = nullptr; pushStreamThread = nullptr; + // iniWindow(); + m_flowType = ""; } ffmpegvideoDlg::~ffmpegvideoDlg() { @@ -31,8 +33,12 @@ void ffmpegvideoDlg::play(QString url) { ffmpeg = new Cffmpeg_decode; ffmpeg->setSaveFileDirPath(videoSaveDirPath); ffmpeg->IsstopPlay = false; - if (!pushStreamIP.isEmpty()) // 推流 - startPushStream(); + + if (!pushStreamIP.isEmpty()){ + startPushStream(); + } + + ffmpeg->setFlowType(m_flowType); ffmpeg->moveToThread(&workerThread); connect(&workerThread, &QThread::finished, ffmpeg, @@ -45,7 +51,6 @@ void ffmpegvideoDlg::play(QString url) { SLOT(receiveQImage(QImage))); // 发送解析的图片 connect(ffmpeg, SIGNAL(sendConnectFail(int)), this, SLOT(showMessagBox(int))); // 发送错误信息提示 - workerThread.start(); emit this->setUrlSign(url); // 设置URL emit this->operate(); // 启用线程信号 @@ -111,6 +116,12 @@ bool ffmpegvideoDlg::Isplay(bool IsstopPlay) { return ffmpeg->IsstopPlay = IsstopPlay; } +// 设置推流地址 +void ffmpegvideoDlg::setPushStreamIP(QString pushStreamURL) { + pushStreamIP = pushStreamURL; +} + +// 开始推流 void ffmpegvideoDlg::startPushStream() { if (ffmpegPushStream == nullptr) { ffmpegPushStream = new FFmpegPushStream; @@ -128,9 +139,6 @@ void ffmpegvideoDlg::startPushStream() { &FFmpegPushStream::pushStream); connect(ffmpeg, &Cffmpeg_decode::sendStopPushStream_Signal, ffmpegPushStream, &FFmpegPushStream::stopPush); - ffmpeg->bPushStreamFlag = true; -} -void ffmpegvideoDlg::setPushStreamIP(QString pushStreamURL) { - pushStreamIP = pushStreamURL; + ffmpeg->bPushStreamFlag = true; } diff --git a/Src/Video/ffmpegvideodlg.h b/Src/Video/ffmpegvideodlg.h index 9dbfc74..2f2ece5 100644 --- a/Src/Video/ffmpegvideodlg.h +++ b/Src/Video/ffmpegvideodlg.h @@ -25,11 +25,14 @@ public: void setVedioSaveFileDirPath(QString saveDirPath); + //拉流 void play(QString); void stop(); bool Isplay(bool IsstopPlay); - void startPushStream(); + + //推流 void setPushStreamIP(QString pushStreamURL); + void startPushStream(); private: Ui::ffmpegvideoDlg *ui; @@ -41,6 +44,7 @@ public: double m_ax; double m_ay; + QString m_flowType; protected: void paintEvent(QPaintEvent *); void resizeEvent(QResizeEvent *event);