From bf2b90f651e4473ef4c66a8454ac181aeae1df13 Mon Sep 17 00:00:00 2001
From: caoyuhui <1152604503@qq.com>
Date: Wed, 14 Aug 2024 17:52:02 +0800
Subject: [PATCH] =?UTF-8?q?=E5=85=89=E7=94=B5=E5=90=8A=E8=88=B1=E8=AE=BE?=
=?UTF-8?q?=E7=BD=AE=E9=A1=B5=E9=9D=A2=E4=BA=A4=E4=BB=98=E4=BF=AE=E6=94=B9?=
=?UTF-8?q?=EF=BC=8C=E9=9A=90=E8=97=8F=E6=9C=AA=E5=BC=80=E5=8F=91=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=EF=BC=9B=E8=A7=A3=E5=86=B3rtsp=E6=B5=81=E5=86=8D?=
=?UTF-8?q?=E6=AC=A1=E8=BF=9E=E6=8E=A5=E6=97=B6=E8=BD=AF=E4=BB=B6=E5=B4=A9?=
=?UTF-8?q?=E6=BA=83=E9=97=AE=E9=A2=98=EF=BC=9B=E8=A7=A3=E5=86=B3rtsp?=
=?UTF-8?q?=E5=9C=B0=E5=9D=80=E9=94=99=E8=AF=AF=E6=97=B6=E8=BD=AF=E4=BB=B6?=
=?UTF-8?q?=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98=EF=BC=9B=E8=A7=86=E9=A2=91?=
=?UTF-8?q?=E6=B5=81=E8=A7=A3=E6=9E=90=E7=B1=BB=E6=98=BE=E7=A4=BA=E9=A1=B5?=
=?UTF-8?q?=E9=9D=A2=E5=A2=9E=E5=8A=A0=E8=87=AA=E9=80=82=E5=BA=94=E6=AF=94?=
=?UTF-8?q?=E4=BE=8B=E5=8F=98=E6=8D=A2=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Src/GDDC/gddcSet.cpp | 19 ++++++-
Src/GDDC/gddcSet.ui | 14 ++---
Src/GDDC/gddcStateInfo.cpp | 3 +-
Src/GDDC/gddcdlg.cpp | 36 ++++++------
Src/GDDC/gddcdlg.h | 2 +-
Src/GDDC/gddcdlg.ui | 23 ++++----
cffmpeg_decode.cpp | 5 +-
cffmpeg_decode.h | 14 ++---
config.ini | 10 ----
ffmpegvideodlg.cpp | 114 +++++++++++++++++++++++--------------
ffmpegvideodlg.h | 11 +++-
res/Qss/qss.qss | 2 +-
12 files changed, 148 insertions(+), 105 deletions(-)
delete mode 100644 config.ini
diff --git a/Src/GDDC/gddcSet.cpp b/Src/GDDC/gddcSet.cpp
index 687916c..639b21f 100644
--- a/Src/GDDC/gddcSet.cpp
+++ b/Src/GDDC/gddcSet.cpp
@@ -24,6 +24,18 @@ void GDDCSet::initWindow()
{
this->setWindowTitle("通信设置");
setAttribute(Qt::WA_QuitOnClose,false);
+
+ //交付时隐藏部分未开发接口
+ ui->label_2->hide();
+ ui->label_5->hide();
+ ui->label_6->hide();
+ ui->lineEdit_playURL2->hide();
+ ui->lineEdit_playport2->hide();
+ ui->pushButton_ConnectURL2->hide();
+ ui->groupBox_2->hide();
+ ui->radioButton_NetCtrlTCP->hide();
+ ui->label->hide();
+ ui->lineEdit_playport1->hide();
}
void GDDCSet::initUDPSocket()
{
@@ -36,10 +48,11 @@ void GDDCSet::initParam()
// setting.setIniCodec(QTextCodec::codecForName("UTF-8")); //重点
ui->comboBox_streamType->addItem("RTSP");
- ui->comboBox_streamType->addItem("UDP Raw");
- ui->comboBox_streamType->addItem("UDP 422");
- ui->comboBox_streamType->addItem("UDP TS");
+ //ui->comboBox_streamType->addItem("UDP Raw");
+ //ui->comboBox_streamType->addItem("UDP 422");
+ //ui->comboBox_streamType->addItem("UDP TS");
ui->comboBox_playURL1->addItem("rtsp://192.168.1.160:554/live/track0");
+ ui->comboBox_playURL1->addItem("rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid");
ui->comboBox_playURL1->setEditable(true);
/*"rtsp://192.168.1.160:554/live/track0"*/
diff --git a/Src/GDDC/gddcSet.ui b/Src/GDDC/gddcSet.ui
index ada1d90..9e0e017 100644
--- a/Src/GDDC/gddcSet.ui
+++ b/Src/GDDC/gddcSet.ui
@@ -7,7 +7,7 @@
0
0
761
- 506
+ 387
@@ -22,14 +22,14 @@
30
10
701
- 211
+ 141
视频连接
- Qt::AlignCenter
+ Qt::AlignmentFlag::AlignCenter
@@ -203,7 +203,7 @@
30
- 230
+ 280
701
80
@@ -212,7 +212,7 @@
串口控制
- Qt::AlignCenter
+ Qt::AlignmentFlag::AlignCenter
@@ -291,7 +291,7 @@
30
- 330
+ 180
701
141
@@ -300,7 +300,7 @@
网络控制
- Qt::AlignCenter
+ Qt::AlignmentFlag::AlignCenter
diff --git a/Src/GDDC/gddcStateInfo.cpp b/Src/GDDC/gddcStateInfo.cpp
index 6dc545c..92f22ef 100644
--- a/Src/GDDC/gddcStateInfo.cpp
+++ b/Src/GDDC/gddcStateInfo.cpp
@@ -31,14 +31,13 @@ void GDDCStateInfo::initParam()
//ui->tableViewShowIState->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
// 表格宽度自动根据UI进行计算,不可手动调整宽度
//ui->tableViewShowIState->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
-
// 固定表格高度不可扩展,不可手动调整高度
ui->tableViewShowIState->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
// 表格高度随内容自动扩展
//ui->tableViewShowIState->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
// 表格高度自动根据UI进行计算,不可手动调整高度
//ui->tableViewShowIState->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
-
+ ui->tableViewShowIState->setEditTriggers(QAbstractItemView::NoEditTriggers); // 不可编辑
ui->tableViewShowIState->setColumnWidth(0,100);
ui->tableViewShowIState->setColumnWidth(1,100);
diff --git a/Src/GDDC/gddcdlg.cpp b/Src/GDDC/gddcdlg.cpp
index 11164fe..7493b72 100644
--- a/Src/GDDC/gddcdlg.cpp
+++ b/Src/GDDC/gddcdlg.cpp
@@ -273,20 +273,21 @@ void GDDCdlg::resizeUI()
/*******视频区位置和大小设置********/
double VideoAreaHeight = GDDCPageHeight-cmdAreaHeight; //视频区高度
double VideoAreaWidth = GDDCPageWidth-stateAreaWidth; //视频区宽度
- //高度值相对比较大
- if(VideoAreaHeight*16>VideoAreaWidth*9)
- {
- double setVideoAreaWidth = VideoAreaWidth;//等于吊舱页面宽度-状态区高度
- double setVideoAreaHeight = VideoAreaWidth*9/16;
- ui->WgtffmpegVideo->setGeometry(0,0.5*(VideoAreaHeight-setVideoAreaHeight),(int)setVideoAreaWidth,(int)setVideoAreaHeight);
- }
- //宽度值相对比较大
- else
- {
- double setVideoAreaHeight = VideoAreaHeight;//等于吊舱页面高度-控制区高度
- double setVideoAreaWidth = VideoAreaHeight*16/9;
- ui->WgtffmpegVideo->setGeometry(0.5*(VideoAreaWidth-setVideoAreaWidth),0,(int)setVideoAreaWidth,(int)setVideoAreaHeight);
- }
+ // //高度值相对比较大
+ // if(VideoAreaHeight*16>VideoAreaWidth*9)
+ // {
+ // double setVideoAreaWidth = VideoAreaWidth;//等于吊舱页面宽度-状态区高度
+ // double setVideoAreaHeight = VideoAreaWidth*9/16;
+ // ui->WgtffmpegVideo->setGeometry(0,0.5*(VideoAreaHeight-setVideoAreaHeight),(int)setVideoAreaWidth,(int)setVideoAreaHeight);
+ // }
+ // //宽度值相对比较大
+ // else
+ // {
+ // double setVideoAreaHeight = VideoAreaHeight;//等于吊舱页面高度-控制区高度
+ // double setVideoAreaWidth = VideoAreaHeight*16/9;
+ // ui->WgtffmpegVideo->setGeometry(0.5*(VideoAreaWidth-setVideoAreaWidth),0,(int)setVideoAreaWidth,(int)setVideoAreaHeight);
+ // }
+ ui->WgtffmpegVideo->setGeometry(0,0,(int)VideoAreaWidth,(int)VideoAreaHeight);
/**************设置按钮****************/
ui->pushButtonSet->setGeometry(GDDCPageWidth-stateAreaWidth-45,0,40,40);
@@ -374,10 +375,12 @@ 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->play();
ui->WgtffmpegVideo->setUrl(m_DlgGDDCSet->m_playURL1);
- ui->WgtffmpegVideo->m_PlayStatus =Is_openVideo;
+
}
}
@@ -387,7 +390,8 @@ void GDDCdlg::stopConnectURL1()
if(connectFlag[0])
{
connectFlag[0] = false ;
- ui->WgtffmpegVideo->m_PlayStatus = Is_openVideo;
+ //Is_openVideo = false;
+ //ui->WgtffmpegVideo->m_PlayStatus = Is_openVideo;
ui->WgtffmpegVideo->stop();
}
}
diff --git a/Src/GDDC/gddcdlg.h b/Src/GDDC/gddcdlg.h
index db820c0..f5067be 100644
--- a/Src/GDDC/gddcdlg.h
+++ b/Src/GDDC/gddcdlg.h
@@ -82,7 +82,7 @@ public:
public:
bool pointSelectionTracking; //选点跟踪
bool Is_openVideo; //视频是否已打开,默认未打开
- std::vector connectFlag; // 0,视频流1;1,视频流2;2,串口通信,3网口通信
+ std::vector connectFlag; // 0视频流1;1视频流2;2串口通信,3网口通信
bool isCmdPageShow; //控制页是否显示
bool isStatePageShow; //状态页是否显示
bool detectionAreaSetting; //检测区域设置
diff --git a/Src/GDDC/gddcdlg.ui b/Src/GDDC/gddcdlg.ui
index 2d891ac..f6d8fdd 100644
--- a/Src/GDDC/gddcdlg.ui
+++ b/Src/GDDC/gddcdlg.ui
@@ -41,7 +41,7 @@
Form
- Qt::LeftToRight
+ Qt::LayoutDirection::LeftToRight
@@ -83,16 +83,16 @@
- Qt::NoFocus
+ Qt::FocusPolicy::NoFocus
- Qt::NoContextMenu
+ Qt::ContextMenuPolicy::NoContextMenu
false
- Qt::LeftToRight
+ Qt::LayoutDirection::LeftToRight
false
@@ -104,8 +104,8 @@
- 470
- 380
+ 480
+ 310
80
20
@@ -146,12 +146,15 @@
192
+
+
+
- 350
- 410
+ 260
+ 380
331
71
@@ -160,8 +163,8 @@
- 630
- 320
+ 640
+ 310
80
20
diff --git a/cffmpeg_decode.cpp b/cffmpeg_decode.cpp
index 1315a2d..77b5c5a 100644
--- a/cffmpeg_decode.cpp
+++ b/cffmpeg_decode.cpp
@@ -1,5 +1,4 @@
#include "cffmpeg_decode.h"
-
Cffmpeg_decode::Cffmpeg_decode()
{
fmtCtx = avformat_alloc_context();
@@ -30,7 +29,7 @@ bool Cffmpeg_decode::open_input_file()
AVDictionary* avdic = NULL;
av_dict_set(&avdic, "buffer_size", "2048000", 0); //设置缓存大小,1080p可将值调大
av_dict_set(&avdic, "rtsp_transport", "udp", 0); //以udp方式打开,如果以tcp方式打开将udp替换为tcp
- av_dict_set(&avdic, "stimeout", "2000000", 0); //设置超时断开连接时间,单位微秒
+ av_dict_set(&avdic, "listen_timeout", "200000", 0); //设置超时断开连接时间,单位微秒
av_dict_set(&avdic, "max_delay", "3000", 0); //设置最大时延
av_dict_set(&avdic, "tune", "zerolatency", 0);
av_dict_set(&avdic, "preset", "ultrafast", 0);
@@ -101,10 +100,12 @@ bool Cffmpeg_decode::open_input_file()
return true;
}
+//线程里持续执行
void Cffmpeg_decode::run()
{
if(!open_input_file()){
qDebug()<<"Please open video file first.";
+ emit sendConnectFail(1);
IsstopPlay = true;
return;
}
diff --git a/cffmpeg_decode.h b/cffmpeg_decode.h
index da46ebb..ede763f 100644
--- a/cffmpeg_decode.h
+++ b/cffmpeg_decode.h
@@ -27,7 +27,8 @@ extern "C"{
}
-class Cffmpeg_decode: public QThread
+//class Cffmpeg_decode: public QThread
+class Cffmpeg_decode: public QObject
{
public:
explicit Cffmpeg_decode();
@@ -35,22 +36,19 @@ public:
Q_OBJECT
public:
-
-
void setUrl(QString url);
-
bool open_input_file();
- bool IsstopPlay= false;
+ bool IsstopPlay= false;
-protected:
+public slots:
void run();
-
signals:
void sendQImage(QImage);
+ void sendConnectFail(int);
private:
AVFormatContext *fmtCtx =NULL;
- const AVCodec *videoCodec =NULL;
+ const AVCodec *videoCodec =NULL;
AVCodecContext *videoCodecCtx=NULL;
AVPacket *pkt = NULL;
AVFrame *yuvFrame = NULL;
diff --git a/config.ini b/config.ini
deleted file mode 100644
index 088e0be..0000000
--- a/config.ini
+++ /dev/null
@@ -1,10 +0,0 @@
-[光电吊舱-网络控制]
-本地IP=-1
-本地Port=65535
-远端IP=-1
-远端Port=65535
-[光电吊舱-视频连接-显示窗口2]
-播放URL=33333
-播放Port=-1
-[光电吊舱-视频连接-显示窗口1]
-播放Port=-1
diff --git a/ffmpegvideodlg.cpp b/ffmpegvideodlg.cpp
index 61329a8..776efc0 100644
--- a/ffmpegvideodlg.cpp
+++ b/ffmpegvideodlg.cpp
@@ -1,5 +1,6 @@
#include "ffmpegvideodlg.h"
#include "ui_ffmpegvideodlg.h"
+#include
ffmpegvideoDlg::ffmpegvideoDlg(QWidget *parent)
: QWidget(parent)
@@ -7,25 +8,25 @@ ffmpegvideoDlg::ffmpegvideoDlg(QWidget *parent)
{
ui->setupUi(this);
iniWindow();
- ffmpeg = new Cffmpeg_decode;
- // this->resize(640,480);
-
}
ffmpegvideoDlg::~ffmpegvideoDlg()
{
- if(ffmpeg->isRunning()){
- stop();
- }
- delete ffmpeg;
+ stop();
delete ui;
}
void ffmpegvideoDlg::iniWindow()
{
-
- }
+ QString VideoFilePath = QDir::currentPath()+"./Video";
+ QDir VideoDir (VideoFilePath);
+ if(!VideoDir.exists())
+ {
+ VideoDir.mkdir(VideoFilePath);
+ qDebug()<<"文件夹创建成功";
+ }
+}
void ffmpegvideoDlg::setUrl(QString url)
{
ffmpeg->setUrl(url);
@@ -33,61 +34,86 @@ void ffmpegvideoDlg::setUrl(QString url)
void ffmpegvideoDlg::play()
{
- QString VideoFilePath = QDir::currentPath()+"./Video";
- QDir VideoDir (VideoFilePath);
- if(!VideoDir.exists())
- {
- VideoDir.mkdir(VideoFilePath);
- qDebug()<<"文件夹创建成功";
- }
-
-
-
if(!m_PlayStatus)
- {
- connect(ffmpeg,SIGNAL(sendQImage(QImage)),this,SLOT(receiveQImage(QImage)));
- connect(ffmpeg,&Cffmpeg_decode::finished,ffmpeg,&Cffmpeg_decode::deleteLater);
-
- }
-
- if(!ffmpeg->isRunning())
{
-
- ffmpeg->start();
+ m_PlayStatus = true;
+ ffmpeg = new Cffmpeg_decode;
+ ffmpeg->IsstopPlay = false;
+ ffmpeg->moveToThread(&workerThread);
+ connect(&workerThread,&QThread::finished,ffmpeg,&QObject::deleteLater); //线程发送结束标志
+ connect(this, &ffmpegvideoDlg::operate, ffmpeg, &Cffmpeg_decode::run); //线程开始处理数据
+ connect(ffmpeg,SIGNAL(sendQImage(QImage)),this,SLOT(receiveQImage(QImage))); //发送解析的图片
+ connect(ffmpeg,SIGNAL(sendConnectFail(int)),this,SLOT(showMessagBox(int))); //发送错误信息提示
+ workerThread.start();
+ emit this->operate(); //启用线程信号
}
-
-
}
-
void ffmpegvideoDlg::stop()
{
- if(ffmpeg->isRunning() && !ffmpeg->IsstopPlay ){
-
- ffmpeg->IsstopPlay = true;
- ffmpeg->requestInterruption();
- ffmpeg->quit();
- ffmpeg->wait();
-
- ffmpeg = nullptr;
-
-
+ if(m_PlayStatus)
+ {
+ m_PlayStatus = false;
+ ffmpeg->IsstopPlay = true; //线程结束标志
+ workerThread.quit(); //线程退出时自动delete线程里的类
+ workerThread.wait();
+ img.fill(Qt::black);
}
- img.fill(Qt::black);
}
+//绘图事件
void ffmpegvideoDlg::paintEvent(QPaintEvent *)
{
QPainter painter(this);
- painter.drawImage(0,0,img);
+ painter.drawImage(m_ax,m_ay,img);
+}
+
+//区域大小改变事件
+void ffmpegvideoDlg::resizeEvent(QResizeEvent *event)
+{
+ //区域1920*1080自适应
+ double VideoAreaHeight = this->height();
+ double VideoAreaWidth = this->width();
+ //高度值相对比较大
+ if(VideoAreaHeight*16>VideoAreaWidth*9)
+ {
+ m_setVideoAreaWidth = VideoAreaWidth;
+ m_setVideoAreaHeight = VideoAreaWidth*9/16;
+ m_ax = 0;
+ m_ay = 0.5*(VideoAreaHeight-m_setVideoAreaHeight);
+ }
+ //宽度值相对比较大
+ else
+ {
+ m_setVideoAreaHeight = VideoAreaHeight;
+ m_setVideoAreaWidth = VideoAreaHeight*16/9;
+ m_ax = 0.5*(VideoAreaWidth-m_setVideoAreaWidth);
+ m_ay = 0;
+ }
}
void ffmpegvideoDlg::receiveQImage(const QImage &rImg)
{
- img = rImg.scaled(this->size());
+
+ //img = rImg.scaled(this->size());
+ QSize imgsize(m_setVideoAreaWidth,m_setVideoAreaHeight);
+ img = rImg.scaled(imgsize);
update();
}
+//显示不同提示消息
+void ffmpegvideoDlg::showMessagBox(int type)
+{
+ switch (type) {
+ case 1:
+ QMessageBox::information(NULL,tr("提示"),"获取视频失败",QMessageBox::Ok);
+ break;
+ default:
+ break;
+ }
+}
bool ffmpegvideoDlg::Isplay(bool IsstopPlay)
{
return ffmpeg->IsstopPlay = IsstopPlay;
}
+
+
diff --git a/ffmpegvideodlg.h b/ffmpegvideodlg.h
index 4a7972f..707c408 100644
--- a/ffmpegvideodlg.h
+++ b/ffmpegvideodlg.h
@@ -54,15 +54,24 @@ public:
bool Isplay(bool IsstopPlay);
bool m_PlayStatus =false;
+ double m_setVideoAreaWidth;
+ double m_setVideoAreaHeight;
+ double m_ax;
+ double m_ay;
+
protected:
void paintEvent(QPaintEvent *);
+ void resizeEvent(QResizeEvent *event);
private slots:
void receiveQImage(const QImage &rImg);
+ void showMessagBox(int);
+signals:
+ void operate();
private:
Cffmpeg_decode *ffmpeg;
-
+ QThread workerThread;
QImage img;
};
diff --git a/res/Qss/qss.qss b/res/Qss/qss.qss
index 0e4698d..554adb8 100644
--- a/res/Qss/qss.qss
+++ b/res/Qss/qss.qss
@@ -200,7 +200,7 @@ QFrame#frameGDDCPage
QTableView
{
color: rgb(255, 255, 255);
- font: 12pt "Microsoft YaHei UI";
+ font: 10pt "Microsoft YaHei UI";
border:none;
background-color: rgba(50, 50, 50, 50); /*rgba(150, 223, 155, 50)*/
selection-background-color: rgba(96, 96, 96, 0); /*选中区域的背景色,设置成透明96,96,96*/