Compare commits

...

2 Commits

@ -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);
}

@ -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
* 11
@ -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

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>761</width>
<height>360</height>
<height>342</height>
</rect>
</property>
<property name="windowTitle">
@ -22,7 +22,7 @@
<x>30</x>
<y>10</y>
<width>701</width>
<height>181</height>
<height>141</height>
</rect>
</property>
<property name="title">
@ -34,8 +34,8 @@
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<x>440</x>
<y>60</y>
<width>61</width>
<height>21</height>
</rect>
@ -47,8 +47,8 @@
<widget class="QComboBox" name="comboBox_streamType">
<property name="geometry">
<rect>
<x>90</x>
<y>30</y>
<x>510</x>
<y>60</y>
<width>72</width>
<height>23</height>
</rect>
@ -58,7 +58,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<y>30</y>
<width>61</width>
<height>16</height>
</rect>
@ -71,7 +71,7 @@
<property name="geometry">
<rect>
<x>20</x>
<y>100</y>
<y>60</y>
<width>71</width>
<height>21</height>
</rect>
@ -84,8 +84,8 @@
<property name="geometry">
<rect>
<x>90</x>
<y>100</y>
<width>491</width>
<y>60</y>
<width>331</width>
<height>23</height>
</rect>
</property>
@ -94,7 +94,7 @@
<property name="geometry">
<rect>
<x>600</x>
<y>100</y>
<y>60</y>
<width>80</width>
<height>23</height>
</rect>
@ -156,7 +156,7 @@
<property name="geometry">
<rect>
<x>20</x>
<y>140</y>
<y>100</y>
<width>71</width>
<height>21</height>
</rect>
@ -169,7 +169,7 @@
<property name="geometry">
<rect>
<x>90</x>
<y>140</y>
<y>100</y>
<width>491</width>
<height>23</height>
</rect>
@ -179,7 +179,7 @@
<property name="geometry">
<rect>
<x>600</x>
<y>140</y>
<y>100</y>
<width>80</width>
<height>23</height>
</rect>
@ -281,9 +281,9 @@
<property name="geometry">
<rect>
<x>30</x>
<y>200</y>
<y>166</y>
<width>701</width>
<height>141</height>
<height>131</height>
</rect>
</property>
<property name="title">
@ -309,7 +309,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>28</y>
<y>30</y>
<width>97</width>
<height>21</height>
</rect>
@ -322,7 +322,7 @@
<property name="geometry">
<rect>
<x>500</x>
<y>98</y>
<y>90</y>
<width>81</width>
<height>23</height>
</rect>
@ -332,7 +332,7 @@
<property name="geometry">
<rect>
<x>420</x>
<y>68</y>
<y>60</y>
<width>71</width>
<height>21</height>
</rect>
@ -345,7 +345,7 @@
<property name="geometry">
<rect>
<x>500</x>
<y>68</y>
<y>60</y>
<width>81</width>
<height>23</height>
</rect>
@ -355,7 +355,7 @@
<property name="geometry">
<rect>
<x>30</x>
<y>68</y>
<y>60</y>
<width>53</width>
<height>15</height>
</rect>
@ -368,7 +368,7 @@
<property name="geometry">
<rect>
<x>90</x>
<y>68</y>
<y>60</y>
<width>301</width>
<height>23</height>
</rect>
@ -378,7 +378,7 @@
<property name="geometry">
<rect>
<x>90</x>
<y>98</y>
<y>90</y>
<width>301</width>
<height>23</height>
</rect>
@ -388,7 +388,7 @@
<property name="geometry">
<rect>
<x>30</x>
<y>98</y>
<y>90</y>
<width>53</width>
<height>15</height>
</rect>
@ -401,7 +401,7 @@
<property name="geometry">
<rect>
<x>90</x>
<y>28</y>
<y>30</y>
<width>97</width>
<height>21</height>
</rect>
@ -414,7 +414,7 @@
<property name="geometry">
<rect>
<x>420</x>
<y>103</y>
<y>90</y>
<width>71</width>
<height>20</height>
</rect>

@ -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;
}
}

@ -23,6 +23,8 @@
// #include "ui_gddcSet.h"
#include "QProcess"
#include <QThread>
#include <QMessageBox>
#define cmdLength 44
namespace Ui {
class GDDCdlg;

@ -98,6 +98,7 @@ void HomePageSetingWidget::on_oneKeyButton_clicked() {
on_lLinkButton_clicked();
on_netButton_clicked();
on_sateliteButton_clicked();
on_modelCameraButton_clicked();
}
/*************************************************
* @func getAllParam

@ -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;
}

@ -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();

@ -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()) // 推流
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;
}

@ -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);

Loading…
Cancel
Save