From d3a6ab5d1d062cd9b82cfd4e29a966b445d57459 Mon Sep 17 00:00:00 2001 From: cbwu <504-wuchengbo@htsdfp.com> Date: Thu, 29 Aug 2024 15:43:30 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=89=E7=BB=B4?= =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E8=B7=A8=E7=BA=BF=E7=A8=8B=E4=BC=A0=E6=95=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/ModelCamera/encodemodelcamera.cpp | 1 - Src/ModelCamera/encodemodelcamera.h | 1 + Src/ModelCamera/modelcameradlg.cpp | 42 ++++++++++++--------------- Src/ModelCamera/modelcameradlg.h | 5 ++-- mainwindow.cpp | 5 ++-- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/Src/ModelCamera/encodemodelcamera.cpp b/Src/ModelCamera/encodemodelcamera.cpp index 0e86d6b..bae1c4e 100644 --- a/Src/ModelCamera/encodemodelcamera.cpp +++ b/Src/ModelCamera/encodemodelcamera.cpp @@ -4,7 +4,6 @@ EncodeModelCamera::EncodeModelCamera(QObject *parent) : QObject{parent} { cameraUDP = new QUdpSocket(this); // cameraUDP->bind(QHostAddress("172.10.1.104"), 8899); - cmdArray.insert(0, 0xFA); cmdArray.insert(1, 0xFA); connect(cameraUDP, SIGNAL(readyRead()), this, SLOT(ReadData())); diff --git a/Src/ModelCamera/encodemodelcamera.h b/Src/ModelCamera/encodemodelcamera.h index c8eec49..b7dcedb 100644 --- a/Src/ModelCamera/encodemodelcamera.h +++ b/Src/ModelCamera/encodemodelcamera.h @@ -11,6 +11,7 @@ class EncodeModelCamera : public QObject { public: explicit EncodeModelCamera(QObject *parent = nullptr); // ~EncodeModelCamera(); +public slots: void setIPandPort(netStruct); // 设置ip和端口 private: diff --git a/Src/ModelCamera/modelcameradlg.cpp b/Src/ModelCamera/modelcameradlg.cpp index c4d1175..eadada2 100644 --- a/Src/ModelCamera/modelcameradlg.cpp +++ b/Src/ModelCamera/modelcameradlg.cpp @@ -11,10 +11,12 @@ ModelCameraDlg::ModelCameraDlg(QWidget *parent) encodeModelCamera = new EncodeModelCamera(); encodeModelCamera->moveToThread(cameraCMDThread); cameraCMDThread->start(); - connect(this, &ModelCameraDlg::on_sendCmdData_signal, encodeModelCamera, + connect(this, &ModelCameraDlg::sendCmdData_signal, encodeModelCamera, &EncodeModelCamera::SendCMD); connect(encodeModelCamera, &EncodeModelCamera::UDP_Receive, this, &ModelCameraDlg::on_receiveUDP); + connect(this, &ModelCameraDlg::sendNetParam_signal, encodeModelCamera, + &EncodeModelCamera::setIPandPort); } ModelCameraDlg::~ModelCameraDlg() { @@ -27,12 +29,6 @@ ModelCameraDlg::~ModelCameraDlg() { } } -void ModelCameraDlg::setNetParam(netStruct net) { - if (encodeModelCamera != nullptr) { - encodeModelCamera->setIPandPort(net); - } -} - void ModelCameraDlg::InitialComboBox() { ui->photoTimeDbSpinBox->setSuffix("s"); @@ -133,7 +129,7 @@ void ModelCameraDlg::on_startPhotoBtn_clicked() { cmdDataArray.insert(2, 0x03); cmdDataArray.insert(3, 0x01); cmdDataArray.insert(4, photoTime); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 停止拍照 @@ -143,7 +139,7 @@ void ModelCameraDlg::on_stopPhotoBtn_clicked() { cmdDataArray.insert(1, 0xA1); cmdDataArray.insert(2, 0x03); cmdDataArray.insert(3, QByteArray(1, char(0x00))); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 开机 @@ -153,7 +149,7 @@ void ModelCameraDlg::on_ONBtn_clicked() { cmdDataArray.insert(1, 0xA1); cmdDataArray.insert(2, 0x01); cmdDataArray.insert(3, 0x01); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 关机 @@ -163,7 +159,7 @@ void ModelCameraDlg::on_OFFBtn_clicked() { cmdDataArray.insert(1, 0xA1); cmdDataArray.insert(2, 0x01); cmdDataArray.insert(3, QByteArray(1, char(0x00))); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 播放视频 @@ -198,7 +194,7 @@ void ModelCameraDlg::on_SSComboBox_activated(int index) { cmdDataArray.append(byteArray); cmdDataArray.insert(6, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // ISO @@ -223,7 +219,7 @@ void ModelCameraDlg::on_ISOComboBox_activated(int index) { cmdDataArray.append(byteArray); cmdDataArray.insert(6, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // AWB白平衡 @@ -243,7 +239,7 @@ void ModelCameraDlg::on_AWBComboBox_activated(int index) { cmdDataArray.append(byteArray); cmdDataArray.insert(6, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 相机模式 @@ -259,7 +255,7 @@ void ModelCameraDlg::on_cameraModelComboBox_activated(int index) { else if (index == 1) cmdDataArray.insert(3, 0x01); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 色彩模式 @@ -279,7 +275,7 @@ void ModelCameraDlg::on_ColorModelComboBox_activated(int index) { cmdDataArray.append(byteArray); cmdDataArray.insert(6, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 获取开关机状态 @@ -289,7 +285,7 @@ void ModelCameraDlg::quireOnorOff() { cmdDataArray.insert(1, 0xA1); cmdDataArray.insert(2, 0x01); cmdDataArray.insert(3, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 查询图传状态 @@ -302,7 +298,7 @@ void ModelCameraDlg::quireShutterSpeed() { cmdDataArray.insert(2, 0x01); cmdDataArray.insert(3, 0xFF); cmdDataArray.insert(4, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 查询ISO void ModelCameraDlg::quireISO() { @@ -312,7 +308,7 @@ void ModelCameraDlg::quireISO() { cmdDataArray.insert(2, 0x02); cmdDataArray.insert(3, 0xFF); cmdDataArray.insert(4, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 查询白平衡 void ModelCameraDlg::quireAWB() { @@ -322,7 +318,7 @@ void ModelCameraDlg::quireAWB() { cmdDataArray.insert(2, 0x06); cmdDataArray.insert(3, 0xFF); cmdDataArray.insert(4, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 查询相机模式 void ModelCameraDlg::quireCameraMode() { @@ -331,7 +327,7 @@ void ModelCameraDlg::quireCameraMode() { cmdDataArray.insert(1, 0xA1); cmdDataArray.insert(2, 0x02); cmdDataArray.insert(3, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 查询色彩(饱和度)模式 void ModelCameraDlg::quireColorMode() { @@ -341,7 +337,7 @@ void ModelCameraDlg::quireColorMode() { cmdDataArray.insert(2, 0x08); cmdDataArray.insert(3, 0xFF); cmdDataArray.insert(4, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } // 查询温度 void ModelCameraDlg::quireTempe() {} @@ -352,5 +348,5 @@ void ModelCameraDlg::quirePicNumAll() { cmdDataArray.insert(1, 0xA1); cmdDataArray.insert(2, 0x07); cmdDataArray.insert(3, 0xFF); - emit on_sendCmdData_signal(cmdDataArray); + emit sendCmdData_signal(cmdDataArray); } diff --git a/Src/ModelCamera/modelcameradlg.h b/Src/ModelCamera/modelcameradlg.h index b213238..7aac316 100644 --- a/Src/ModelCamera/modelcameradlg.h +++ b/Src/ModelCamera/modelcameradlg.h @@ -17,10 +17,11 @@ class ModelCameraDlg : public QDialog { public: explicit ModelCameraDlg(QWidget *parent = nullptr); ~ModelCameraDlg(); - void setNetParam(netStruct); + // void setNetParam(netStruct); signals: - void on_sendCmdData_signal(QByteArray cmdDataArray); + void sendCmdData_signal(QByteArray cmdDataArray); + void sendNetParam_signal(netStruct netParam); private slots: void on_startPhotoBtn_clicked(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 0a26ad3..afb5ef9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -113,8 +113,7 @@ void MainWindow::initWindow() { satelliteCommWeb->load(QUrl(m_allSetMap["机载卫通"].url)); m_ModelCameraDlg = new ModelCameraDlg(this); - m_ModelCameraDlg->setNetParam(m_allSetMap["三维建模"].net); - + emit m_ModelCameraDlg->sendNetParam_signal(m_allSetMap["三维建模"].net); // 接收主页面设置窗口的url数据传递并设置 connect(m_HomePagedlg->settingWidget, &HomePageSetingWidget::sendOneSet, this, [&](unsigned char urlIndex, settingStruct settings) { @@ -132,7 +131,7 @@ void MainWindow::initWindow() { satelliteCommWeb->load(QUrl(settings.url)); break; case HomePageSetingWidget::ModelCamera: - m_ModelCameraDlg->setNetParam(settings.net); + m_ModelCameraDlg->sendNetParam_signal(settings.net); break; default: break; From 725faf4bb41d001ae7161a89fcbc4c75aeecc6e6 Mon Sep 17 00:00:00 2001 From: shiyi Date: Mon, 2 Sep 2024 17:34:12 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=90=9C=E6=95=91?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=96=B0=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=80=89=E4=B8=AD=E6=95=B0=E6=8D=AE=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=94=BE=E5=A4=A7=E5=9C=B0=E5=9B=BE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/RescueLoad/RescueLoad.pri | 1 + Src/RescueLoad/map/places_map.qml | 17 ++++++++++++--- .../map/tianditu/include/tibingmapprovider.h | 19 +---------------- .../map/tianditu/include/tiesrimapprovider.h | 19 +---------------- .../map/tianditu/include/tigeotilefetcher.h | 20 +----------------- .../tianditu/include/tigooglemapprovider.h | 19 +---------------- .../map/tianditu/include/timapcacheworker.h | 21 +------------------ .../map/tianditu/include/timapengine.h | 20 +----------------- .../map/tianditu/include/timapenginedata.h | 19 +---------------- .../map/tianditu/include/timapjsonengine.h | 20 +----------------- .../map/tianditu/include/timapprovider.h | 19 +---------------- .../map/tianditu/include/timapurlengine.h | 20 +----------------- .../map/tianditu/include/tiqgeocodereply.h | 20 +----------------- .../tianditu/include/tiqgeofiletilecache.h | 20 +----------------- .../include/tiqgeoserviceproviderfactory.h | 19 +---------------- .../include/tiqgeotiledmappingmanagerengine.h | 19 +---------------- .../tianditu/include/tiqgeotiledmapreply.h | 20 +----------------- .../tianditu/include/titianditumapprovider.h | 19 +---------------- Src/RescueLoad/rescueload.cpp | 3 ++- 19 files changed, 33 insertions(+), 301 deletions(-) diff --git a/Src/RescueLoad/RescueLoad.pri b/Src/RescueLoad/RescueLoad.pri index 161c2c7..af5e1ec 100644 --- a/Src/RescueLoad/RescueLoad.pri +++ b/Src/RescueLoad/RescueLoad.pri @@ -15,6 +15,7 @@ RESOURCES += \ # 指定库文件的头文件路径 INCLUDEPATH += $$PWD/map/tianditu/include +DEPENDPATH += $$PWD/map/tianditu/include # 指定库文件的路径 CONFIG(debug, debug|release){ diff --git a/Src/RescueLoad/map/places_map.qml b/Src/RescueLoad/map/places_map.qml index b0c358b..d848a8a 100644 --- a/Src/RescueLoad/map/places_map.qml +++ b/Src/RescueLoad/map/places_map.qml @@ -150,15 +150,27 @@ Map{ updateSelect(imsiSelectModel) } } + Connections { + // 数据发生更改是,比如imsi对应的数据位置发生变化,选中的状态也应该随之变化 target: imsiDataModel function onDataChanged(topLeft, bottomRight,roles) { - updateSelect(imsiSelectModel) + var indexs = imsiSelectModel.selectedIndexes + listSelectModel.clear() + if (indexs.length === 0) return; + for (var i = 0; i #include diff --git a/Src/RescueLoad/map/tianditu/include/tigooglemapprovider.h b/Src/RescueLoad/map/tianditu/include/tigooglemapprovider.h index 6b29154..b5d7f19 100644 --- a/Src/RescueLoad/map/tianditu/include/tigooglemapprovider.h +++ b/Src/RescueLoad/map/tianditu/include/tigooglemapprovider.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :tigooglemapprovider.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-8-30 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include "timapprovider.h" #include diff --git a/Src/RescueLoad/map/tianditu/include/timapcacheworker.h b/Src/RescueLoad/map/tianditu/include/timapcacheworker.h index ef1c182..5aba0fc 100644 --- a/Src/RescueLoad/map/tianditu/include/timapcacheworker.h +++ b/Src/RescueLoad/map/tianditu/include/timapcacheworker.h @@ -1,23 +1,4 @@ -/************************************************************************** - * 文件名 :TiMapCacheWorker.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-5-14 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * 使用说明 - *:任何人或机构要使用、修改、发布本源代码,都必须要获得的授权 - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/timapengine.h b/Src/RescueLoad/map/tianditu/include/timapengine.h index 12530f0..9817c6b 100644 --- a/Src/RescueLoad/map/tianditu/include/timapengine.h +++ b/Src/RescueLoad/map/tianditu/include/timapengine.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :timapengine.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-16 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * 使用说明 - *:任何人或机构要使用、修改、发布本源代码,都必须要获得的授权 - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include #include diff --git a/Src/RescueLoad/map/tianditu/include/timapenginedata.h b/Src/RescueLoad/map/tianditu/include/timapenginedata.h index 3ab7e5b..1629a1e 100644 --- a/Src/RescueLoad/map/tianditu/include/timapenginedata.h +++ b/Src/RescueLoad/map/tianditu/include/timapenginedata.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :TiMapEngineData.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-30 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include /** * @brief The TiMapCacheTile class 瓦片数据 diff --git a/Src/RescueLoad/map/tianditu/include/timapjsonengine.h b/Src/RescueLoad/map/tianditu/include/timapjsonengine.h index 9aa340a..cfab07c 100644 --- a/Src/RescueLoad/map/tianditu/include/timapjsonengine.h +++ b/Src/RescueLoad/map/tianditu/include/timapjsonengine.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :timapjsonengine.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-29 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include diff --git a/Src/RescueLoad/map/tianditu/include/timapprovider.h b/Src/RescueLoad/map/tianditu/include/timapprovider.h index d70e3c5..2a7be8e 100644 --- a/Src/RescueLoad/map/tianditu/include/timapprovider.h +++ b/Src/RescueLoad/map/tianditu/include/timapprovider.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :timapprovider.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-16 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/timapurlengine.h b/Src/RescueLoad/map/tianditu/include/timapurlengine.h index f97af13..712559b 100644 --- a/Src/RescueLoad/map/tianditu/include/timapurlengine.h +++ b/Src/RescueLoad/map/tianditu/include/timapurlengine.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :timapurlengine.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-17 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeocodereply.h b/Src/RescueLoad/map/tianditu/include/tiqgeocodereply.h index 550678b..e4bfef7 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeocodereply.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeocodereply.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :tiqgeocodereply.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-5-17 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeofiletilecache.h b/Src/RescueLoad/map/tianditu/include/tiqgeofiletilecache.h index dafb96c..9bc7407 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeofiletilecache.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeofiletilecache.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :tiqgeofiletilecache.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-5-13 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeoserviceproviderfactory.h b/Src/RescueLoad/map/tianditu/include/tiqgeoserviceproviderfactory.h index e11f6e7..cf9e1f2 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeoserviceproviderfactory.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeoserviceproviderfactory.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :tiqeoserviceproviderfactory.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-4-27 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeotiledmappingmanagerengine.h b/Src/RescueLoad/map/tianditu/include/tiqgeotiledmappingmanagerengine.h index 16f5023..33c6987 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeotiledmappingmanagerengine.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeotiledmappingmanagerengine.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :tiqgeotiledmappingmanagerengine.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-4-27 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeotiledmapreply.h b/Src/RescueLoad/map/tianditu/include/tiqgeotiledmapreply.h index 03da7d7..c7faf49 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeotiledmapreply.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeotiledmapreply.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :tiqgeotiledmapreply.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-5-12 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/titianditumapprovider.h b/Src/RescueLoad/map/tianditu/include/titianditumapprovider.h index 99042c6..ee2abfb 100644 --- a/Src/RescueLoad/map/tianditu/include/titianditumapprovider.h +++ b/Src/RescueLoad/map/tianditu/include/titianditumapprovider.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :titianditumapprovider.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-16 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include "timapprovider.h" class TiTiandituMapProvider : public TiMapProvider diff --git a/Src/RescueLoad/rescueload.cpp b/Src/RescueLoad/rescueload.cpp index 86d3898..e6f8c0d 100644 --- a/Src/RescueLoad/rescueload.cpp +++ b/Src/RescueLoad/rescueload.cpp @@ -24,7 +24,8 @@ ImsiData::ImsiData(const QJsonObject& json) if (json.contains("altitude")) this->altitude = json.value("altitude").toInt(); if (json.contains("create_date")) - this->createDate = json.value("create_date").toString(); + // this->createDate = json.value("create_date").toString(); // 传过来的数据不准 + this->createDate = QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm:ss"); if (json.contains("rssi")) this->rssi = json.value("rssi").toInt(); if (json.contains("fcn")) From 1f5324cbf880fa91e6a6e4a2347f126a19b71f79 Mon Sep 17 00:00:00 2001 From: caoyuhui <1152604503@qq.com> Date: Mon, 2 Sep 2024 09:31:08 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E7=9B=91=E6=B5=8B=E5=BB=B6=E8=BF=9F=E6=98=BE=E7=A4=BA=EF=BC=9B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0rtsp=E6=B5=81=E6=9C=AC=E5=9C=B0=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=8A=9F=E8=83=BD=EF=BC=88=E8=BF=9B=E8=A1=8C=E4=B8=AD?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/HomePage/deviceStateDlg.cpp | 63 ++++--- Src/HomePage/deviceStateDlg.h | 4 +- Src/HomePage/networkDetection.cpp | 14 +- Src/HomePage/networkDetection.h | 3 +- Src/Video/Video.pri | 4 +- Src/Video/cffmpeg_decode.cpp | 292 +++++++++++++++++++++++------- Src/Video/cffmpeg_decode.h | 25 ++- Src/Video/myVideoProc.cpp | 0 mainwindow.cpp | 1 - 9 files changed, 304 insertions(+), 102 deletions(-) create mode 100644 Src/Video/myVideoProc.cpp diff --git a/Src/HomePage/deviceStateDlg.cpp b/Src/HomePage/deviceStateDlg.cpp index 814112a..ecdbaab 100644 --- a/Src/HomePage/deviceStateDlg.cpp +++ b/Src/HomePage/deviceStateDlg.cpp @@ -19,6 +19,10 @@ void deviceStateDlg::initWindow() { setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); hide(); + m_greyIcon.addFile(":/res/lamp/grey.png"); + m_greenIcon.addFile(":/res/lamp/green.png"); + m_redIcon.addFile(":/res/lamp/red.png"); + QString stateButtonStyle = /*正常情况下样式*/ "QPushButton{" @@ -36,14 +40,16 @@ void deviceStateDlg::initWindow() { ui->pushButton_state_adHocNetwork->setStyleSheet(stateButtonStyle); ui->pushButton_state_rescue->setStyleSheet(stateButtonStyle); //"image: url(:/res/lamp/grey.png)-23px 0px no-repeat;" - QIcon greyIcon(":/res/lamp/grey.png"); - ui->pushButton_state_GDDC->setIcon(greyIcon); - ui->pushButton_state_LLink->setIcon(greyIcon); - ui->pushButton_state_3DCamra->setIcon(greyIcon); - ui->pushButton_state_KuSatelliteComm->setIcon(greyIcon); - ui->pushButton_state_PDT->setIcon(greyIcon); - ui->pushButton_state_adHocNetwork->setIcon(greyIcon); - ui->pushButton_state_rescue->setIcon(greyIcon); + + + ui->pushButton_state_GDDC->setIcon(m_greyIcon); + ui->pushButton_state_LLink->setIcon(m_greyIcon); + ui->pushButton_state_3DCamra->setIcon(m_greyIcon); + ui->pushButton_state_KuSatelliteComm->setIcon(m_greyIcon); + ui->pushButton_state_PDT->setIcon(m_greyIcon); + ui->pushButton_state_adHocNetwork->setIcon(m_greyIcon); + ui->pushButton_state_rescue->setIcon(m_greyIcon); + ui->pushButton_state_GDDC->setIconSize(QSize(35, 35)); ui->pushButton_state_LLink->setIconSize(QSize(35, 35)); ui->pushButton_state_3DCamra->setIconSize(QSize(35, 35)); @@ -52,6 +58,14 @@ void deviceStateDlg::initWindow() { ui->pushButton_state_adHocNetwork->setIconSize(QSize(35, 35)); ui->pushButton_state_rescue->setIconSize(QSize(35, 35)); + ui->pushButton_state_GDDC->setToolTip("未知"); + ui->pushButton_state_LLink->setToolTip("未知"); + ui->pushButton_state_3DCamra->setToolTip("未知"); + ui->pushButton_state_KuSatelliteComm->setToolTip("未知"); + ui->pushButton_state_PDT->setToolTip("未知"); + ui->pushButton_state_adHocNetwork->setToolTip("未知"); + ui->pushButton_state_rescue->setToolTip("未知"); + ui->lineEdit_1_GDDC->setText("--"); ui->lineEdit_2_GDDC->setText("--"); ui->lineEdit_3_GDDC->setText("--"); @@ -91,45 +105,48 @@ void deviceStateDlg::initParam() { } // 接收线程结果 -void deviceStateDlg::receiveResult(int id, QString result) { +void deviceStateDlg::receiveResult(int id, QString result,QString delay) { // qDebug() << result; switch (id) { case 0: if (result == "在线") { - ui->pushButton_state_GDDC->setIcon(QIcon(":/res/lamp/green.png")); + ui->pushButton_state_GDDC->setIcon(m_greenIcon); } else { - ui->pushButton_state_GDDC->setIcon(QIcon(":/res/lamp/red.png")); + ui->pushButton_state_GDDC->setIcon(m_redIcon); } + ui->pushButton_state_GDDC->setToolTip(delay); break; case 1: if (result == "在线") { - ui->pushButton_state_LLink->setIcon(QIcon(":/res/lamp/green.png")); + ui->pushButton_state_LLink->setIcon(m_greenIcon); } else { - ui->pushButton_state_LLink->setIcon(QIcon(":/res/lamp/red.png")); + ui->pushButton_state_LLink->setIcon(m_redIcon); } + ui->pushButton_state_LLink->setToolTip(delay); break; case 2: if (result == "在线") { - ui->pushButton_state_adHocNetwork->setIcon(QIcon(":/res/lamp/green.png")); + ui->pushButton_state_adHocNetwork->setIcon(m_greenIcon); } else { - ui->pushButton_state_adHocNetwork->setIcon(QIcon(":/res/lamp/red.png")); + ui->pushButton_state_adHocNetwork->setIcon(m_redIcon); } + ui->pushButton_state_adHocNetwork->setToolTip(delay); break; case 3: if (result == "在线") { - ui->pushButton_state_KuSatelliteComm->setIcon( - QIcon(":/res/lamp/green.png")); + ui->pushButton_state_KuSatelliteComm->setIcon(m_greenIcon); } else { - ui->pushButton_state_KuSatelliteComm->setIcon( - QIcon(":/res/lamp/red.png")); + ui->pushButton_state_KuSatelliteComm->setIcon(m_redIcon); } + ui->pushButton_state_KuSatelliteComm->setToolTip(delay); break; case 4: if (result == "在线") { - ui->pushButton_state_3DCamra->setIcon(QIcon(":/res/lamp/green.png")); + ui->pushButton_state_3DCamra->setIcon(m_greenIcon); } else { - ui->pushButton_state_3DCamra->setIcon(QIcon(":/res/lamp/red.png")); + ui->pushButton_state_3DCamra->setIcon(m_redIcon); } + ui->pushButton_state_3DCamra->setToolTip(delay); break; default: break; @@ -219,8 +236,8 @@ void deviceStateDlg::startNetDetn() { m_workerThread[i] = new QThread(); m_networkDetection[i]->moveToThread(m_workerThread[i]); m_workerThread[i]->start(); - connect(m_networkDetection[i], SIGNAL(resultReady(int, QString)), this, - SLOT(receiveResult(int, QString))); // 接收线程运行结果 + connect(m_networkDetection[i], SIGNAL(resultReady(int, QString, QString)), this, + SLOT(receiveResult(int, QString, QString))); // 接收线程运行结果 switch (i) { case 0: connect(this, &deviceStateDlg::startThread0, m_networkDetection[i], diff --git a/Src/HomePage/deviceStateDlg.h b/Src/HomePage/deviceStateDlg.h index b205935..1033ff5 100644 --- a/Src/HomePage/deviceStateDlg.h +++ b/Src/HomePage/deviceStateDlg.h @@ -44,7 +44,7 @@ private slots: void on_pushButton_homePage_KuSatelliteComm_clicked(); - void receiveResult(int, QString); // 接收线程结果 + void receiveResult(int, QString, QString); // 接收线程结果 private: Ui::deviceStateDlg *ui; @@ -55,7 +55,7 @@ public: // 3ku卫通 // 4三维相机 QStringList cmdlist[deviceNum]; - + QIcon m_greyIcon,m_greenIcon,m_redIcon; networkDetection *m_networkDetection[deviceNum]; QThread *m_workerThread[deviceNum]; QTimer *m_timer; diff --git a/Src/HomePage/networkDetection.cpp b/Src/HomePage/networkDetection.cpp index 1f6de4b..def07db 100644 --- a/Src/HomePage/networkDetection.cpp +++ b/Src/HomePage/networkDetection.cpp @@ -15,15 +15,16 @@ void networkDetection::dowork(int id, QStringList cmdlist) { while (flagRun) { m_process->start("cmd", m_cmd); m_process->waitForFinished(); // 等待指令执行完毕 - result = m_process->readAll(); // 获取指令执行结果 + result = QString::fromLocal8Bit(m_process->readAll()); // 获取指令执行结果 // qDebug() << result; if (result.contains(QString("TTL="))) // 若包含TTL=字符串则认为网络在线 { // qDebug() << "在线"; - emit resultReady(m_id, "在线"); + QString delay = selectTTL(result); + emit resultReady(m_id, "在线",delay); } else { // qDebug() << "离线"; - emit resultReady(m_id, "离线"); + emit resultReady(m_id, "离线","通信异常"); } // if (CmdListChanged) { // CmdListChanged = false; @@ -40,3 +41,10 @@ void networkDetection::DyChangeCmdList(QStringList changeCmdList) { m_cmd = changeCmdList; CmdListChanged = true; } + +//查找延迟 +QString networkDetection::selectTTL(QString str) { + str = str.remove(0,str.indexOf("平均 = ")+5); + str = str.left(str.indexOf("ms")+2); + return "通信正常\n"+str; +} diff --git a/Src/HomePage/networkDetection.h b/Src/HomePage/networkDetection.h index 74e29ec..8a05259 100644 --- a/Src/HomePage/networkDetection.h +++ b/Src/HomePage/networkDetection.h @@ -17,7 +17,7 @@ public slots: void dowork(int, QStringList); void stop(); signals: - void resultReady(int, QString); + void resultReady(int, QString, QString); public: void DyChangeCmdList(QStringList); @@ -30,6 +30,7 @@ public: bool flagRun; // 运行标志 bool CmdListChanged; // 指令列表改变标志 QProcess *m_process; // 执行CMD + QString selectTTL(QString str);//查找延迟 }; #endif // NETWORKDETECTION_H diff --git a/Src/Video/Video.pri b/Src/Video/Video.pri index 30b4e0b..2b4a055 100644 --- a/Src/Video/Video.pri +++ b/Src/Video/Video.pri @@ -1,7 +1,7 @@ SOURCES += \ $$PWD/cffmpeg_decode.cpp \ - $$PWD/ffmpegvideodlg.cpp \ - + $$PWD/ffmpegvideodlg.cpp + HEADERS += \ $$PWD/cffmpeg_decode.h \ $$PWD/ffmpegvideodlg.h \ diff --git a/Src/Video/cffmpeg_decode.cpp b/Src/Video/cffmpeg_decode.cpp index 7dfbc33..4ffb279 100644 --- a/Src/Video/cffmpeg_decode.cpp +++ b/Src/Video/cffmpeg_decode.cpp @@ -1,25 +1,36 @@ #include "cffmpeg_decode.h" // Cffmpeg_decode::Cffmpeg_decode() { Cffmpeg_decode::Cffmpeg_decode(QObject *parent) : QObject(parent) { - fmtCtx = avformat_alloc_context(); - pkt = av_packet_alloc(); + inputFormatCtx = avformat_alloc_context(); + outputFormatCtx = avformat_alloc_context(); + inputPacket = av_packet_alloc(); + outputPacket = av_packet_alloc(); yuvFrame = av_frame_alloc(); rgbFrame = av_frame_alloc(); + avformat_network_init(); } Cffmpeg_decode::~Cffmpeg_decode() { - if (!pkt) - av_packet_free(&pkt); + if (!inputPacket) + av_packet_free(&inputPacket); + if (!outputPacket) + av_packet_free(&outputPacket); if (!yuvFrame) av_frame_free(&yuvFrame); if (!rgbFrame) av_frame_free(&rgbFrame); - if (!videoCodecCtx) - avcodec_free_context(&videoCodecCtx); - if (!videoCodecCtx) - avcodec_close(videoCodecCtx); - if (!fmtCtx) - avformat_close_input(&fmtCtx); + if (!encoderCtx) + avcodec_free_context(&encoderCtx); + if (!encoderCtx) + avcodec_close(encoderCtx); + if (!decoderCtx) + avcodec_free_context(&decoderCtx); + if (!decoderCtx) + avcodec_close(decoderCtx); + if (!inputFormatCtx) + avformat_close_input(&inputFormatCtx); + if (!outputFormatCtx) + avformat_close_input(&outputFormatCtx); } void Cffmpeg_decode::setUrl(QString url) { _url = url; } @@ -28,76 +39,196 @@ bool Cffmpeg_decode::open_input_file() { if (_url.isEmpty()) return 0; + //========================解码============================ AVDictionary *avdic = NULL; // 设置缓存大小,1080p可将值调大 av_dict_set(&avdic, "buffer_size", "2048000", 0); // 以udp方式打开,如果以tcp方式打开将udp替换为tcp av_dict_set(&avdic, "rtsp_transport", "udp", 0); // 设置超时断开连接时间,单位微秒//listen_timeout - av_dict_set(&avdic, "listen_timeout", "200000", 0); - // av_dict_set(&avdic, "stimeout", "200000", 0); + //av_dict_set(&avdic, "listen_timeout", "200000", 0); + av_dict_set(&avdic, "stimeout", "200000", 0); av_dict_set(&avdic, "max_delay", "3", 0); // 设置最大时延 av_dict_set(&avdic, "tune", "zerolatency", 0); av_dict_set(&avdic, "preset", "ultrafast", 0); - fmtCtx->flags |= AVFMT_FLAG_NONBLOCK; - if (avformat_open_input(&fmtCtx, _url.toUtf8().data(), NULL, &avdic) < 0) { + + inputFormatCtx->flags |= AVFMT_FLAG_NONBLOCK; + + // 打开输入流 + if (avformat_open_input(&inputFormatCtx, _url.toUtf8().data(), NULL, &avdic) <0) { printf("Cannot open input file.\n"); return 0; } - - if (avformat_find_stream_info(fmtCtx, NULL) < 0) { + // 查找流信息 + if (avformat_find_stream_info(inputFormatCtx, NULL) < 0) { printf("Cannot find any stream in file.\n"); return 0; } - - int streamCnt = fmtCtx->nb_streams; - for (int i = 0; i < streamCnt; i++) { - if (fmtCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + // 从输入流中找到第一个视频流 + for (int i = 0; i < inputFormatCtx->nb_streams; i++) { + if (inputFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { videoStreamIndex = i; continue; } } - if (videoStreamIndex == -1) { printf("Cannot find video stream in file.\n"); return 0; } - AVCodecParameters *videoCodecPara = - fmtCtx->streams[videoStreamIndex]->codecpar; + // 获取视频流的解码器参数 + videoCodecPara = inputFormatCtx->streams[videoStreamIndex]->codecpar; - if (!(videoCodec = avcodec_find_decoder(videoCodecPara->codec_id))) { + decoder = avcodec_find_decoder(videoCodecPara->codec_id); + if (!decoder) { printf("Cannot find valid decode codec.\n"); return 0; } - - if (!(videoCodecCtx = avcodec_alloc_context3(videoCodec))) { + // 为解码器上下文分配空间 + decoderCtx = avcodec_alloc_context3(decoder); + if (!decoderCtx) { printf("Cannot find valid decode codec context.\n"); return 0; } - - if (avcodec_parameters_to_context(videoCodecCtx, videoCodecPara) < 0) { + // 初始化解码器上下文 + if (avcodec_parameters_to_context(decoderCtx, videoCodecPara) < 0) { printf("Cannot initialize parameters.\n"); return 0; } - if (avcodec_open2(videoCodecCtx, videoCodec, NULL) < 0) { + // 打开解码器 + if (avcodec_open2(decoderCtx, decoder, NULL) < 0) { printf("Cannot open codec.\n"); return 0; } - img_ctx = sws_getContext(videoCodecCtx->width, videoCodecCtx->height, - videoCodecCtx->pix_fmt, videoCodecCtx->width, - videoCodecCtx->height, AV_PIX_FMT_RGB32, SWS_BICUBIC, - NULL, NULL, NULL); - numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB32, videoCodecCtx->width, - videoCodecCtx->height, 1); + //===============================编码================================ + // 1、输出文件设置 + if (avformat_alloc_output_context2(&outputFormatCtx, NULL, NULL, "output_video.mp4") < 0) { + qDebug() << "Could not create output context.\n"; + return 0; + } + + // 从输入流中找到第一个视频流 + for (int i = 0; i < inputFormatCtx->nb_streams; i++) { + if (inputFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + videoStreamIndexOut = i; + continue; + } + } + if (videoStreamIndexOut == -1) { + printf("Cannot find video stream in file.\n"); + return 0; + } + // 获取视频流的解码器参数 + videoCodecPara2 = inputFormatCtx->streams[videoStreamIndexOut]->codecpar; + + // 3、创建输出视频流 + outStream = avformat_new_stream(outputFormatCtx, NULL); + if (!outStream) { + qDebug() << "Failed allocating output stream.\n"; + return 0; + } + //4、查找编码器 + encoder = avcodec_find_encoder(videoCodecPara2->codec_id); + if(!encoder){ + return 0; + } + + //5、分配解码器上下文 + encoderCtx = avcodec_alloc_context3(encoder); + if (!encoderCtx) { + return 0; + } + + //初始化视频AVCodecContext + encoderCtx->height = videoCodecPara2->height; + encoderCtx->width = videoCodecPara2->width; + videoCodecPara2->framerate = av_guess_frame_rate(inputFormatCtx,inputFormatCtx->streams[videoStreamIndexOut],NULL); + + //视频流的时间基是1 / 帧率 + encoderCtx->time_base = av_inv_q(inputFormatCtx->streams[videoStreamIndexOut]->codecpar->framerate); + encoderCtx->sample_aspect_ratio = inputFormatCtx->streams[videoStreamIndexOut]->codecpar->sample_aspect_ratio; + if (encoder->pix_fmts) + { + encoderCtx->pix_fmt = encoder->pix_fmts[0]; + } + encoderCtx->codec_type = AVMEDIA_TYPE_VIDEO; + encoderCtx->codec_id = AV_CODEC_ID_H264; + encoderCtx->bit_rate = 2000000; + encoderCtx->time_base.num = 1; + encoderCtx->time_base.den = 20; + + //全局头 + if (outputFormatCtx->oformat->flags & AVFMT_GLOBALHEADER) + { + encoderCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + } + + // //设置选项 + // AVDictionary *param = 0; + // //H.264 + // if(videoCodecPara->codec_id == AV_CODEC_ID_H264) { + // av_dict_set(¶m, "preset", "slow", 0); + // av_dict_set(¶m, "tune", "zerolatency", 0); + // av_dict_set(¶m, "profile", "main", 0); + // } + // //H.265 + // if(videoCodecPara->codec_id == AV_CODEC_ID_H265){ + // av_dict_set(¶m, "preset", "ultrafast", 0); + // av_dict_set(¶m, "tune", "zero-latency", 0); + // } + + //6、打开编码器 + if (avcodec_open2(encoderCtx, encoder, NULL) < 0) { + qDebug() << "Error occurred when opening encoder.\n"; + //return 0; + } + + avcodec_parameters_from_context(outputFormatCtx->streams[0]->codecpar, encoderCtx); + //avcodec_parameters_to_context(encoderCtx,outStream->codecpar); + + // 打开输出文件 + if (!(outputFormatCtx->oformat->flags & AVFMT_NOFILE)) { + if (avio_open(&outputFormatCtx->pb, + outputFormatCtx->url /* "output_video.mp4"*/, + AVIO_FLAG_WRITE) < 0) { + printf("Could not open output file.\n"); + return 0; + } + } + + //写入输出文件的头信息 + if (avformat_write_header(outputFormatCtx, NULL) < 0) { + qDebug() << "Error occurred when opening output file.\n"; + //return 0; + } + //格式化输出输出文件信息 + av_dump_format(outputFormatCtx,0,outputFormatCtx->url,1); + + + + // 初始化图像转换器 + swsCtx = sws_getContext(decoderCtx->width, // + decoderCtx->height, // + decoderCtx->pix_fmt, // + decoderCtx->width, // + decoderCtx->height, // + AV_PIX_FMT_RGB32, // + SWS_BICUBIC, NULL, NULL, NULL); + numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB32, // + decoderCtx->width, // + decoderCtx->height, // + 1); out_buffer = (unsigned char *)av_malloc(numBytes * sizeof(unsigned char)); - int res = av_image_fill_arrays(rgbFrame->data, rgbFrame->linesize, out_buffer, - AV_PIX_FMT_RGB32, videoCodecCtx->width, - videoCodecCtx->height, 1); + int res = av_image_fill_arrays(rgbFrame->data, // + rgbFrame->linesize, // + out_buffer, // + AV_PIX_FMT_RGB32, // + decoderCtx->width, // + decoderCtx->height, 1); if (res < 0) { - qDebug() << "Fill arrays failed."; + qDebug() << "Fill arrays failed.\n"; return 0; } @@ -113,52 +244,83 @@ void Cffmpeg_decode::run() { return; } - while (av_read_frame(fmtCtx, pkt) >= 0) { - if (pkt->stream_index == videoStreamIndex) { - if (avcodec_send_packet(videoCodecCtx, pkt) >= 0) { + // 读取数据包 + while (av_read_frame(inputFormatCtx, inputPacket) >= 0) { + if (IsstopPlay) { + qDebug() << "video play stop"; + break; + } + + if (inputPacket->stream_index == videoStreamIndex) { + // 解码数据包 + if (avcodec_send_packet(decoderCtx, inputPacket) >= 0) { int ret; - while ((ret = avcodec_receive_frame(videoCodecCtx, yuvFrame)) >= 0) { - if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) + while ((ret = avcodec_receive_frame(decoderCtx, yuvFrame)) >= 0) { + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { return; - else if (ret < 0) { + } else if (ret < 0) { fprintf(stderr, "Error during decoding\n"); exit(1); } - sws_scale(img_ctx, yuvFrame->data, yuvFrame->linesize, 0, - videoCodecCtx->height, rgbFrame->data, rgbFrame->linesize); + sws_scale(swsCtx, // + yuvFrame->data, // + yuvFrame->linesize, // + 0, // + decoderCtx->height, // + rgbFrame->data, // + rgbFrame->linesize); - QImage img(out_buffer, videoCodecCtx->width, videoCodecCtx->height, + QImage img(out_buffer, // + decoderCtx->width, // + decoderCtx->height, // QImage::Format_RGB32); emit sendQImage(img); - - // int m_timeframe= ((double)videoCodecCtx->framerate.den / - // videoCodecCtx->framerate.num)*1000; QThread::msleep(28); + + + + //将解码后的帧写入输出文件 + if (av_write_frame(outputFormatCtx, inputPacket) < 0) { + //qDebug() << "Error muxing packet.\n"; + break; + } + + } } - av_packet_unref(pkt); - } - if (IsstopPlay) { - break; + av_packet_unref(inputPacket); } + //花屏 + // if (av_read_frame(inputFormatCtx, inputPacket) < 0) { + // break; // 达到文件末尾 + // } } - - qDebug() << "All video play done"; } // 退出 void Cffmpeg_decode::stop() { + + // 写入输出文件的尾信息 + // av_write_trailer(outputFormatCtx); IsstopPlay = true; - if (!pkt) - av_packet_free(&pkt); + if (!inputPacket) + av_packet_free(&inputPacket); + if (!outputPacket) + av_packet_free(&outputPacket); if (!yuvFrame) av_frame_free(&yuvFrame); if (!rgbFrame) av_frame_free(&rgbFrame); - if (!videoCodecCtx) - avcodec_free_context(&videoCodecCtx); - if (!videoCodecCtx) - avcodec_close(videoCodecCtx); - if (!fmtCtx) - avformat_close_input(&fmtCtx); + if (!encoderCtx) + avcodec_free_context(&encoderCtx); + if (!encoderCtx) + avcodec_close(encoderCtx); + if (!decoderCtx) + avcodec_free_context(&decoderCtx); + if (!decoderCtx) + avcodec_close(decoderCtx); + if (!inputFormatCtx) + avformat_close_input(&inputFormatCtx); + if (!outputFormatCtx) + avformat_close_input(&outputFormatCtx); } diff --git a/Src/Video/cffmpeg_decode.h b/Src/Video/cffmpeg_decode.h index 74d5673..93c54d9 100644 --- a/Src/Video/cffmpeg_decode.h +++ b/Src/Video/cffmpeg_decode.h @@ -46,18 +46,33 @@ signals: void sendConnectFail(int); private: - AVFormatContext *fmtCtx = NULL; - const AVCodec *videoCodec = NULL; - AVCodecContext *videoCodecCtx = NULL; - AVPacket *pkt = NULL; + AVFormatContext *inputFormatCtx = NULL; // + AVFormatContext *outputFormatCtx = NULL; // + + AVCodecContext *decoderCtx = NULL; // + AVCodecContext *encoderCtx = NULL;// + + const AVCodec *decoder = NULL; // 解码器 + const AVCodec *encoder = NULL; // + + AVPacket *inputPacket = NULL; // + AVPacket *outputPacket = NULL; // + AVFrame *yuvFrame = NULL; AVFrame *rgbFrame = NULL; - struct SwsContext *img_ctx = NULL; + struct SwsContext *swsCtx = NULL; + + AVCodecParameters *videoCodecPara = nullptr; + AVCodecParameters *videoCodecPara2 = nullptr; + + + AVStream *outStream; unsigned char *out_buffer = nullptr; int videoStreamIndex = -1; + int videoStreamIndexOut = -1; int numBytes = -1; QString _url; diff --git a/Src/Video/myVideoProc.cpp b/Src/Video/myVideoProc.cpp new file mode 100644 index 0000000..e69de29 diff --git a/mainwindow.cpp b/mainwindow.cpp index afb5ef9..2227688 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -36,7 +36,6 @@ MainWindow::MainWindow(QWidget *parent) } QString appDir = QCoreApplication::applicationDirPath() + "/app"; - qDebug() << "Open file fail " << appDir; } From f4695b5d5f221f90fea4b0fad94310e1a08f4470 Mon Sep 17 00:00:00 2001 From: shiyi Date: Mon, 2 Sep 2024 17:34:12 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=90=9C=E6=95=91?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=96=B0=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=80=89=E4=B8=AD=E6=95=B0=E6=8D=AE=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=94=BE=E5=A4=A7=E5=9C=B0=E5=9B=BE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/RescueLoad/RescueLoad.pri | 1 + Src/RescueLoad/map/places_map.qml | 17 ++++++++++++--- .../map/tianditu/include/tibingmapprovider.h | 19 +---------------- .../map/tianditu/include/tiesrimapprovider.h | 19 +---------------- .../map/tianditu/include/tigeotilefetcher.h | 20 +----------------- .../tianditu/include/tigooglemapprovider.h | 19 +---------------- .../map/tianditu/include/timapcacheworker.h | 21 +------------------ .../map/tianditu/include/timapengine.h | 20 +----------------- .../map/tianditu/include/timapenginedata.h | 19 +---------------- .../map/tianditu/include/timapjsonengine.h | 20 +----------------- .../map/tianditu/include/timapprovider.h | 19 +---------------- .../map/tianditu/include/timapurlengine.h | 20 +----------------- .../map/tianditu/include/tiqgeocodereply.h | 20 +----------------- .../tianditu/include/tiqgeofiletilecache.h | 20 +----------------- .../include/tiqgeoserviceproviderfactory.h | 19 +---------------- .../include/tiqgeotiledmappingmanagerengine.h | 19 +---------------- .../tianditu/include/tiqgeotiledmapreply.h | 20 +----------------- .../tianditu/include/titianditumapprovider.h | 19 +---------------- Src/RescueLoad/rescueload.cpp | 3 ++- 19 files changed, 33 insertions(+), 301 deletions(-) diff --git a/Src/RescueLoad/RescueLoad.pri b/Src/RescueLoad/RescueLoad.pri index 161c2c7..af5e1ec 100644 --- a/Src/RescueLoad/RescueLoad.pri +++ b/Src/RescueLoad/RescueLoad.pri @@ -15,6 +15,7 @@ RESOURCES += \ # 指定库文件的头文件路径 INCLUDEPATH += $$PWD/map/tianditu/include +DEPENDPATH += $$PWD/map/tianditu/include # 指定库文件的路径 CONFIG(debug, debug|release){ diff --git a/Src/RescueLoad/map/places_map.qml b/Src/RescueLoad/map/places_map.qml index b0c358b..d848a8a 100644 --- a/Src/RescueLoad/map/places_map.qml +++ b/Src/RescueLoad/map/places_map.qml @@ -150,15 +150,27 @@ Map{ updateSelect(imsiSelectModel) } } + Connections { + // 数据发生更改是,比如imsi对应的数据位置发生变化,选中的状态也应该随之变化 target: imsiDataModel function onDataChanged(topLeft, bottomRight,roles) { - updateSelect(imsiSelectModel) + var indexs = imsiSelectModel.selectedIndexes + listSelectModel.clear() + if (indexs.length === 0) return; + for (var i = 0; i #include diff --git a/Src/RescueLoad/map/tianditu/include/tigooglemapprovider.h b/Src/RescueLoad/map/tianditu/include/tigooglemapprovider.h index 6b29154..b5d7f19 100644 --- a/Src/RescueLoad/map/tianditu/include/tigooglemapprovider.h +++ b/Src/RescueLoad/map/tianditu/include/tigooglemapprovider.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :tigooglemapprovider.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-8-30 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include "timapprovider.h" #include diff --git a/Src/RescueLoad/map/tianditu/include/timapcacheworker.h b/Src/RescueLoad/map/tianditu/include/timapcacheworker.h index ef1c182..5aba0fc 100644 --- a/Src/RescueLoad/map/tianditu/include/timapcacheworker.h +++ b/Src/RescueLoad/map/tianditu/include/timapcacheworker.h @@ -1,23 +1,4 @@ -/************************************************************************** - * 文件名 :TiMapCacheWorker.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-5-14 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * 使用说明 - *:任何人或机构要使用、修改、发布本源代码,都必须要获得的授权 - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/timapengine.h b/Src/RescueLoad/map/tianditu/include/timapengine.h index 12530f0..9817c6b 100644 --- a/Src/RescueLoad/map/tianditu/include/timapengine.h +++ b/Src/RescueLoad/map/tianditu/include/timapengine.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :timapengine.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-16 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * 使用说明 - *:任何人或机构要使用、修改、发布本源代码,都必须要获得的授权 - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include #include diff --git a/Src/RescueLoad/map/tianditu/include/timapenginedata.h b/Src/RescueLoad/map/tianditu/include/timapenginedata.h index 3ab7e5b..1629a1e 100644 --- a/Src/RescueLoad/map/tianditu/include/timapenginedata.h +++ b/Src/RescueLoad/map/tianditu/include/timapenginedata.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :TiMapEngineData.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-30 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include /** * @brief The TiMapCacheTile class 瓦片数据 diff --git a/Src/RescueLoad/map/tianditu/include/timapjsonengine.h b/Src/RescueLoad/map/tianditu/include/timapjsonengine.h index 9aa340a..cfab07c 100644 --- a/Src/RescueLoad/map/tianditu/include/timapjsonengine.h +++ b/Src/RescueLoad/map/tianditu/include/timapjsonengine.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :timapjsonengine.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-29 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include diff --git a/Src/RescueLoad/map/tianditu/include/timapprovider.h b/Src/RescueLoad/map/tianditu/include/timapprovider.h index d70e3c5..2a7be8e 100644 --- a/Src/RescueLoad/map/tianditu/include/timapprovider.h +++ b/Src/RescueLoad/map/tianditu/include/timapprovider.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :timapprovider.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-16 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/timapurlengine.h b/Src/RescueLoad/map/tianditu/include/timapurlengine.h index f97af13..712559b 100644 --- a/Src/RescueLoad/map/tianditu/include/timapurlengine.h +++ b/Src/RescueLoad/map/tianditu/include/timapurlengine.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :timapurlengine.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-17 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeocodereply.h b/Src/RescueLoad/map/tianditu/include/tiqgeocodereply.h index 550678b..e4bfef7 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeocodereply.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeocodereply.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :tiqgeocodereply.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-5-17 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeofiletilecache.h b/Src/RescueLoad/map/tianditu/include/tiqgeofiletilecache.h index dafb96c..9bc7407 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeofiletilecache.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeofiletilecache.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :tiqgeofiletilecache.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-5-13 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeoserviceproviderfactory.h b/Src/RescueLoad/map/tianditu/include/tiqgeoserviceproviderfactory.h index e11f6e7..cf9e1f2 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeoserviceproviderfactory.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeoserviceproviderfactory.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :tiqeoserviceproviderfactory.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-4-27 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeotiledmappingmanagerengine.h b/Src/RescueLoad/map/tianditu/include/tiqgeotiledmappingmanagerengine.h index 16f5023..33c6987 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeotiledmappingmanagerengine.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeotiledmappingmanagerengine.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :tiqgeotiledmappingmanagerengine.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-4-27 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include #include diff --git a/Src/RescueLoad/map/tianditu/include/tiqgeotiledmapreply.h b/Src/RescueLoad/map/tianditu/include/tiqgeotiledmapreply.h index 03da7d7..c7faf49 100644 --- a/Src/RescueLoad/map/tianditu/include/tiqgeotiledmapreply.h +++ b/Src/RescueLoad/map/tianditu/include/tiqgeotiledmapreply.h @@ -1,22 +1,4 @@ -/************************************************************************** - * 文件名 :tiqgeotiledmapreply.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-5-12 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ - -#pragma once +#pragma once #include #include #include diff --git a/Src/RescueLoad/map/tianditu/include/titianditumapprovider.h b/Src/RescueLoad/map/tianditu/include/titianditumapprovider.h index 99042c6..ee2abfb 100644 --- a/Src/RescueLoad/map/tianditu/include/titianditumapprovider.h +++ b/Src/RescueLoad/map/tianditu/include/titianditumapprovider.h @@ -1,21 +1,4 @@ -/************************************************************************** - * 文件名 :titianditumapprovider.h - * ======================================================================= - * 创 建 者 :田小帆 - * 创建日期 :2021-6-16 - * 邮 箱 :499131808@qq.com - * Q Q :499131808 - * 公 司 : - * 功能描述 : - * - * ====================================================================== - * 修改者 : - * 修改日期 : - * 修改内容 : - * ====================================================================== - * - ***************************************************************************/ -#pragma once +#pragma once #include "timapprovider.h" class TiTiandituMapProvider : public TiMapProvider diff --git a/Src/RescueLoad/rescueload.cpp b/Src/RescueLoad/rescueload.cpp index 86d3898..e6f8c0d 100644 --- a/Src/RescueLoad/rescueload.cpp +++ b/Src/RescueLoad/rescueload.cpp @@ -24,7 +24,8 @@ ImsiData::ImsiData(const QJsonObject& json) if (json.contains("altitude")) this->altitude = json.value("altitude").toInt(); if (json.contains("create_date")) - this->createDate = json.value("create_date").toString(); + // this->createDate = json.value("create_date").toString(); // 传过来的数据不准 + this->createDate = QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm:ss"); if (json.contains("rssi")) this->rssi = json.value("rssi").toInt(); if (json.contains("fcn")) From c49efb509c6e995f94fc80df33a5e963683bb689 Mon Sep 17 00:00:00 2001 From: caoyuhui <1152604503@qq.com> Date: Mon, 2 Sep 2024 09:31:08 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E7=9B=91=E6=B5=8B=E5=BB=B6=E8=BF=9F=E6=98=BE=E7=A4=BA=EF=BC=9B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0rtsp=E6=B5=81=E6=9C=AC=E5=9C=B0=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=8A=9F=E8=83=BD=EF=BC=88=E8=BF=9B=E8=A1=8C=E4=B8=AD?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/HomePage/deviceStateDlg.cpp | 63 ++++--- Src/HomePage/deviceStateDlg.h | 4 +- Src/HomePage/networkDetection.cpp | 14 +- Src/HomePage/networkDetection.h | 3 +- Src/Video/Video.pri | 4 +- Src/Video/cffmpeg_decode.cpp | 292 +++++++++++++++++++++++------- Src/Video/cffmpeg_decode.h | 25 ++- Src/Video/myVideoProc.cpp | 0 mainwindow.cpp | 1 - 9 files changed, 304 insertions(+), 102 deletions(-) create mode 100644 Src/Video/myVideoProc.cpp diff --git a/Src/HomePage/deviceStateDlg.cpp b/Src/HomePage/deviceStateDlg.cpp index 814112a..ecdbaab 100644 --- a/Src/HomePage/deviceStateDlg.cpp +++ b/Src/HomePage/deviceStateDlg.cpp @@ -19,6 +19,10 @@ void deviceStateDlg::initWindow() { setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); hide(); + m_greyIcon.addFile(":/res/lamp/grey.png"); + m_greenIcon.addFile(":/res/lamp/green.png"); + m_redIcon.addFile(":/res/lamp/red.png"); + QString stateButtonStyle = /*正常情况下样式*/ "QPushButton{" @@ -36,14 +40,16 @@ void deviceStateDlg::initWindow() { ui->pushButton_state_adHocNetwork->setStyleSheet(stateButtonStyle); ui->pushButton_state_rescue->setStyleSheet(stateButtonStyle); //"image: url(:/res/lamp/grey.png)-23px 0px no-repeat;" - QIcon greyIcon(":/res/lamp/grey.png"); - ui->pushButton_state_GDDC->setIcon(greyIcon); - ui->pushButton_state_LLink->setIcon(greyIcon); - ui->pushButton_state_3DCamra->setIcon(greyIcon); - ui->pushButton_state_KuSatelliteComm->setIcon(greyIcon); - ui->pushButton_state_PDT->setIcon(greyIcon); - ui->pushButton_state_adHocNetwork->setIcon(greyIcon); - ui->pushButton_state_rescue->setIcon(greyIcon); + + + ui->pushButton_state_GDDC->setIcon(m_greyIcon); + ui->pushButton_state_LLink->setIcon(m_greyIcon); + ui->pushButton_state_3DCamra->setIcon(m_greyIcon); + ui->pushButton_state_KuSatelliteComm->setIcon(m_greyIcon); + ui->pushButton_state_PDT->setIcon(m_greyIcon); + ui->pushButton_state_adHocNetwork->setIcon(m_greyIcon); + ui->pushButton_state_rescue->setIcon(m_greyIcon); + ui->pushButton_state_GDDC->setIconSize(QSize(35, 35)); ui->pushButton_state_LLink->setIconSize(QSize(35, 35)); ui->pushButton_state_3DCamra->setIconSize(QSize(35, 35)); @@ -52,6 +58,14 @@ void deviceStateDlg::initWindow() { ui->pushButton_state_adHocNetwork->setIconSize(QSize(35, 35)); ui->pushButton_state_rescue->setIconSize(QSize(35, 35)); + ui->pushButton_state_GDDC->setToolTip("未知"); + ui->pushButton_state_LLink->setToolTip("未知"); + ui->pushButton_state_3DCamra->setToolTip("未知"); + ui->pushButton_state_KuSatelliteComm->setToolTip("未知"); + ui->pushButton_state_PDT->setToolTip("未知"); + ui->pushButton_state_adHocNetwork->setToolTip("未知"); + ui->pushButton_state_rescue->setToolTip("未知"); + ui->lineEdit_1_GDDC->setText("--"); ui->lineEdit_2_GDDC->setText("--"); ui->lineEdit_3_GDDC->setText("--"); @@ -91,45 +105,48 @@ void deviceStateDlg::initParam() { } // 接收线程结果 -void deviceStateDlg::receiveResult(int id, QString result) { +void deviceStateDlg::receiveResult(int id, QString result,QString delay) { // qDebug() << result; switch (id) { case 0: if (result == "在线") { - ui->pushButton_state_GDDC->setIcon(QIcon(":/res/lamp/green.png")); + ui->pushButton_state_GDDC->setIcon(m_greenIcon); } else { - ui->pushButton_state_GDDC->setIcon(QIcon(":/res/lamp/red.png")); + ui->pushButton_state_GDDC->setIcon(m_redIcon); } + ui->pushButton_state_GDDC->setToolTip(delay); break; case 1: if (result == "在线") { - ui->pushButton_state_LLink->setIcon(QIcon(":/res/lamp/green.png")); + ui->pushButton_state_LLink->setIcon(m_greenIcon); } else { - ui->pushButton_state_LLink->setIcon(QIcon(":/res/lamp/red.png")); + ui->pushButton_state_LLink->setIcon(m_redIcon); } + ui->pushButton_state_LLink->setToolTip(delay); break; case 2: if (result == "在线") { - ui->pushButton_state_adHocNetwork->setIcon(QIcon(":/res/lamp/green.png")); + ui->pushButton_state_adHocNetwork->setIcon(m_greenIcon); } else { - ui->pushButton_state_adHocNetwork->setIcon(QIcon(":/res/lamp/red.png")); + ui->pushButton_state_adHocNetwork->setIcon(m_redIcon); } + ui->pushButton_state_adHocNetwork->setToolTip(delay); break; case 3: if (result == "在线") { - ui->pushButton_state_KuSatelliteComm->setIcon( - QIcon(":/res/lamp/green.png")); + ui->pushButton_state_KuSatelliteComm->setIcon(m_greenIcon); } else { - ui->pushButton_state_KuSatelliteComm->setIcon( - QIcon(":/res/lamp/red.png")); + ui->pushButton_state_KuSatelliteComm->setIcon(m_redIcon); } + ui->pushButton_state_KuSatelliteComm->setToolTip(delay); break; case 4: if (result == "在线") { - ui->pushButton_state_3DCamra->setIcon(QIcon(":/res/lamp/green.png")); + ui->pushButton_state_3DCamra->setIcon(m_greenIcon); } else { - ui->pushButton_state_3DCamra->setIcon(QIcon(":/res/lamp/red.png")); + ui->pushButton_state_3DCamra->setIcon(m_redIcon); } + ui->pushButton_state_3DCamra->setToolTip(delay); break; default: break; @@ -219,8 +236,8 @@ void deviceStateDlg::startNetDetn() { m_workerThread[i] = new QThread(); m_networkDetection[i]->moveToThread(m_workerThread[i]); m_workerThread[i]->start(); - connect(m_networkDetection[i], SIGNAL(resultReady(int, QString)), this, - SLOT(receiveResult(int, QString))); // 接收线程运行结果 + connect(m_networkDetection[i], SIGNAL(resultReady(int, QString, QString)), this, + SLOT(receiveResult(int, QString, QString))); // 接收线程运行结果 switch (i) { case 0: connect(this, &deviceStateDlg::startThread0, m_networkDetection[i], diff --git a/Src/HomePage/deviceStateDlg.h b/Src/HomePage/deviceStateDlg.h index b205935..1033ff5 100644 --- a/Src/HomePage/deviceStateDlg.h +++ b/Src/HomePage/deviceStateDlg.h @@ -44,7 +44,7 @@ private slots: void on_pushButton_homePage_KuSatelliteComm_clicked(); - void receiveResult(int, QString); // 接收线程结果 + void receiveResult(int, QString, QString); // 接收线程结果 private: Ui::deviceStateDlg *ui; @@ -55,7 +55,7 @@ public: // 3ku卫通 // 4三维相机 QStringList cmdlist[deviceNum]; - + QIcon m_greyIcon,m_greenIcon,m_redIcon; networkDetection *m_networkDetection[deviceNum]; QThread *m_workerThread[deviceNum]; QTimer *m_timer; diff --git a/Src/HomePage/networkDetection.cpp b/Src/HomePage/networkDetection.cpp index 1f6de4b..def07db 100644 --- a/Src/HomePage/networkDetection.cpp +++ b/Src/HomePage/networkDetection.cpp @@ -15,15 +15,16 @@ void networkDetection::dowork(int id, QStringList cmdlist) { while (flagRun) { m_process->start("cmd", m_cmd); m_process->waitForFinished(); // 等待指令执行完毕 - result = m_process->readAll(); // 获取指令执行结果 + result = QString::fromLocal8Bit(m_process->readAll()); // 获取指令执行结果 // qDebug() << result; if (result.contains(QString("TTL="))) // 若包含TTL=字符串则认为网络在线 { // qDebug() << "在线"; - emit resultReady(m_id, "在线"); + QString delay = selectTTL(result); + emit resultReady(m_id, "在线",delay); } else { // qDebug() << "离线"; - emit resultReady(m_id, "离线"); + emit resultReady(m_id, "离线","通信异常"); } // if (CmdListChanged) { // CmdListChanged = false; @@ -40,3 +41,10 @@ void networkDetection::DyChangeCmdList(QStringList changeCmdList) { m_cmd = changeCmdList; CmdListChanged = true; } + +//查找延迟 +QString networkDetection::selectTTL(QString str) { + str = str.remove(0,str.indexOf("平均 = ")+5); + str = str.left(str.indexOf("ms")+2); + return "通信正常\n"+str; +} diff --git a/Src/HomePage/networkDetection.h b/Src/HomePage/networkDetection.h index 74e29ec..8a05259 100644 --- a/Src/HomePage/networkDetection.h +++ b/Src/HomePage/networkDetection.h @@ -17,7 +17,7 @@ public slots: void dowork(int, QStringList); void stop(); signals: - void resultReady(int, QString); + void resultReady(int, QString, QString); public: void DyChangeCmdList(QStringList); @@ -30,6 +30,7 @@ public: bool flagRun; // 运行标志 bool CmdListChanged; // 指令列表改变标志 QProcess *m_process; // 执行CMD + QString selectTTL(QString str);//查找延迟 }; #endif // NETWORKDETECTION_H diff --git a/Src/Video/Video.pri b/Src/Video/Video.pri index 30b4e0b..2b4a055 100644 --- a/Src/Video/Video.pri +++ b/Src/Video/Video.pri @@ -1,7 +1,7 @@ SOURCES += \ $$PWD/cffmpeg_decode.cpp \ - $$PWD/ffmpegvideodlg.cpp \ - + $$PWD/ffmpegvideodlg.cpp + HEADERS += \ $$PWD/cffmpeg_decode.h \ $$PWD/ffmpegvideodlg.h \ diff --git a/Src/Video/cffmpeg_decode.cpp b/Src/Video/cffmpeg_decode.cpp index 7dfbc33..4ffb279 100644 --- a/Src/Video/cffmpeg_decode.cpp +++ b/Src/Video/cffmpeg_decode.cpp @@ -1,25 +1,36 @@ #include "cffmpeg_decode.h" // Cffmpeg_decode::Cffmpeg_decode() { Cffmpeg_decode::Cffmpeg_decode(QObject *parent) : QObject(parent) { - fmtCtx = avformat_alloc_context(); - pkt = av_packet_alloc(); + inputFormatCtx = avformat_alloc_context(); + outputFormatCtx = avformat_alloc_context(); + inputPacket = av_packet_alloc(); + outputPacket = av_packet_alloc(); yuvFrame = av_frame_alloc(); rgbFrame = av_frame_alloc(); + avformat_network_init(); } Cffmpeg_decode::~Cffmpeg_decode() { - if (!pkt) - av_packet_free(&pkt); + if (!inputPacket) + av_packet_free(&inputPacket); + if (!outputPacket) + av_packet_free(&outputPacket); if (!yuvFrame) av_frame_free(&yuvFrame); if (!rgbFrame) av_frame_free(&rgbFrame); - if (!videoCodecCtx) - avcodec_free_context(&videoCodecCtx); - if (!videoCodecCtx) - avcodec_close(videoCodecCtx); - if (!fmtCtx) - avformat_close_input(&fmtCtx); + if (!encoderCtx) + avcodec_free_context(&encoderCtx); + if (!encoderCtx) + avcodec_close(encoderCtx); + if (!decoderCtx) + avcodec_free_context(&decoderCtx); + if (!decoderCtx) + avcodec_close(decoderCtx); + if (!inputFormatCtx) + avformat_close_input(&inputFormatCtx); + if (!outputFormatCtx) + avformat_close_input(&outputFormatCtx); } void Cffmpeg_decode::setUrl(QString url) { _url = url; } @@ -28,76 +39,196 @@ bool Cffmpeg_decode::open_input_file() { if (_url.isEmpty()) return 0; + //========================解码============================ AVDictionary *avdic = NULL; // 设置缓存大小,1080p可将值调大 av_dict_set(&avdic, "buffer_size", "2048000", 0); // 以udp方式打开,如果以tcp方式打开将udp替换为tcp av_dict_set(&avdic, "rtsp_transport", "udp", 0); // 设置超时断开连接时间,单位微秒//listen_timeout - av_dict_set(&avdic, "listen_timeout", "200000", 0); - // av_dict_set(&avdic, "stimeout", "200000", 0); + //av_dict_set(&avdic, "listen_timeout", "200000", 0); + av_dict_set(&avdic, "stimeout", "200000", 0); av_dict_set(&avdic, "max_delay", "3", 0); // 设置最大时延 av_dict_set(&avdic, "tune", "zerolatency", 0); av_dict_set(&avdic, "preset", "ultrafast", 0); - fmtCtx->flags |= AVFMT_FLAG_NONBLOCK; - if (avformat_open_input(&fmtCtx, _url.toUtf8().data(), NULL, &avdic) < 0) { + + inputFormatCtx->flags |= AVFMT_FLAG_NONBLOCK; + + // 打开输入流 + if (avformat_open_input(&inputFormatCtx, _url.toUtf8().data(), NULL, &avdic) <0) { printf("Cannot open input file.\n"); return 0; } - - if (avformat_find_stream_info(fmtCtx, NULL) < 0) { + // 查找流信息 + if (avformat_find_stream_info(inputFormatCtx, NULL) < 0) { printf("Cannot find any stream in file.\n"); return 0; } - - int streamCnt = fmtCtx->nb_streams; - for (int i = 0; i < streamCnt; i++) { - if (fmtCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + // 从输入流中找到第一个视频流 + for (int i = 0; i < inputFormatCtx->nb_streams; i++) { + if (inputFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { videoStreamIndex = i; continue; } } - if (videoStreamIndex == -1) { printf("Cannot find video stream in file.\n"); return 0; } - AVCodecParameters *videoCodecPara = - fmtCtx->streams[videoStreamIndex]->codecpar; + // 获取视频流的解码器参数 + videoCodecPara = inputFormatCtx->streams[videoStreamIndex]->codecpar; - if (!(videoCodec = avcodec_find_decoder(videoCodecPara->codec_id))) { + decoder = avcodec_find_decoder(videoCodecPara->codec_id); + if (!decoder) { printf("Cannot find valid decode codec.\n"); return 0; } - - if (!(videoCodecCtx = avcodec_alloc_context3(videoCodec))) { + // 为解码器上下文分配空间 + decoderCtx = avcodec_alloc_context3(decoder); + if (!decoderCtx) { printf("Cannot find valid decode codec context.\n"); return 0; } - - if (avcodec_parameters_to_context(videoCodecCtx, videoCodecPara) < 0) { + // 初始化解码器上下文 + if (avcodec_parameters_to_context(decoderCtx, videoCodecPara) < 0) { printf("Cannot initialize parameters.\n"); return 0; } - if (avcodec_open2(videoCodecCtx, videoCodec, NULL) < 0) { + // 打开解码器 + if (avcodec_open2(decoderCtx, decoder, NULL) < 0) { printf("Cannot open codec.\n"); return 0; } - img_ctx = sws_getContext(videoCodecCtx->width, videoCodecCtx->height, - videoCodecCtx->pix_fmt, videoCodecCtx->width, - videoCodecCtx->height, AV_PIX_FMT_RGB32, SWS_BICUBIC, - NULL, NULL, NULL); - numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB32, videoCodecCtx->width, - videoCodecCtx->height, 1); + //===============================编码================================ + // 1、输出文件设置 + if (avformat_alloc_output_context2(&outputFormatCtx, NULL, NULL, "output_video.mp4") < 0) { + qDebug() << "Could not create output context.\n"; + return 0; + } + + // 从输入流中找到第一个视频流 + for (int i = 0; i < inputFormatCtx->nb_streams; i++) { + if (inputFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + videoStreamIndexOut = i; + continue; + } + } + if (videoStreamIndexOut == -1) { + printf("Cannot find video stream in file.\n"); + return 0; + } + // 获取视频流的解码器参数 + videoCodecPara2 = inputFormatCtx->streams[videoStreamIndexOut]->codecpar; + + // 3、创建输出视频流 + outStream = avformat_new_stream(outputFormatCtx, NULL); + if (!outStream) { + qDebug() << "Failed allocating output stream.\n"; + return 0; + } + //4、查找编码器 + encoder = avcodec_find_encoder(videoCodecPara2->codec_id); + if(!encoder){ + return 0; + } + + //5、分配解码器上下文 + encoderCtx = avcodec_alloc_context3(encoder); + if (!encoderCtx) { + return 0; + } + + //初始化视频AVCodecContext + encoderCtx->height = videoCodecPara2->height; + encoderCtx->width = videoCodecPara2->width; + videoCodecPara2->framerate = av_guess_frame_rate(inputFormatCtx,inputFormatCtx->streams[videoStreamIndexOut],NULL); + + //视频流的时间基是1 / 帧率 + encoderCtx->time_base = av_inv_q(inputFormatCtx->streams[videoStreamIndexOut]->codecpar->framerate); + encoderCtx->sample_aspect_ratio = inputFormatCtx->streams[videoStreamIndexOut]->codecpar->sample_aspect_ratio; + if (encoder->pix_fmts) + { + encoderCtx->pix_fmt = encoder->pix_fmts[0]; + } + encoderCtx->codec_type = AVMEDIA_TYPE_VIDEO; + encoderCtx->codec_id = AV_CODEC_ID_H264; + encoderCtx->bit_rate = 2000000; + encoderCtx->time_base.num = 1; + encoderCtx->time_base.den = 20; + + //全局头 + if (outputFormatCtx->oformat->flags & AVFMT_GLOBALHEADER) + { + encoderCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + } + + // //设置选项 + // AVDictionary *param = 0; + // //H.264 + // if(videoCodecPara->codec_id == AV_CODEC_ID_H264) { + // av_dict_set(¶m, "preset", "slow", 0); + // av_dict_set(¶m, "tune", "zerolatency", 0); + // av_dict_set(¶m, "profile", "main", 0); + // } + // //H.265 + // if(videoCodecPara->codec_id == AV_CODEC_ID_H265){ + // av_dict_set(¶m, "preset", "ultrafast", 0); + // av_dict_set(¶m, "tune", "zero-latency", 0); + // } + + //6、打开编码器 + if (avcodec_open2(encoderCtx, encoder, NULL) < 0) { + qDebug() << "Error occurred when opening encoder.\n"; + //return 0; + } + + avcodec_parameters_from_context(outputFormatCtx->streams[0]->codecpar, encoderCtx); + //avcodec_parameters_to_context(encoderCtx,outStream->codecpar); + + // 打开输出文件 + if (!(outputFormatCtx->oformat->flags & AVFMT_NOFILE)) { + if (avio_open(&outputFormatCtx->pb, + outputFormatCtx->url /* "output_video.mp4"*/, + AVIO_FLAG_WRITE) < 0) { + printf("Could not open output file.\n"); + return 0; + } + } + + //写入输出文件的头信息 + if (avformat_write_header(outputFormatCtx, NULL) < 0) { + qDebug() << "Error occurred when opening output file.\n"; + //return 0; + } + //格式化输出输出文件信息 + av_dump_format(outputFormatCtx,0,outputFormatCtx->url,1); + + + + // 初始化图像转换器 + swsCtx = sws_getContext(decoderCtx->width, // + decoderCtx->height, // + decoderCtx->pix_fmt, // + decoderCtx->width, // + decoderCtx->height, // + AV_PIX_FMT_RGB32, // + SWS_BICUBIC, NULL, NULL, NULL); + numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB32, // + decoderCtx->width, // + decoderCtx->height, // + 1); out_buffer = (unsigned char *)av_malloc(numBytes * sizeof(unsigned char)); - int res = av_image_fill_arrays(rgbFrame->data, rgbFrame->linesize, out_buffer, - AV_PIX_FMT_RGB32, videoCodecCtx->width, - videoCodecCtx->height, 1); + int res = av_image_fill_arrays(rgbFrame->data, // + rgbFrame->linesize, // + out_buffer, // + AV_PIX_FMT_RGB32, // + decoderCtx->width, // + decoderCtx->height, 1); if (res < 0) { - qDebug() << "Fill arrays failed."; + qDebug() << "Fill arrays failed.\n"; return 0; } @@ -113,52 +244,83 @@ void Cffmpeg_decode::run() { return; } - while (av_read_frame(fmtCtx, pkt) >= 0) { - if (pkt->stream_index == videoStreamIndex) { - if (avcodec_send_packet(videoCodecCtx, pkt) >= 0) { + // 读取数据包 + while (av_read_frame(inputFormatCtx, inputPacket) >= 0) { + if (IsstopPlay) { + qDebug() << "video play stop"; + break; + } + + if (inputPacket->stream_index == videoStreamIndex) { + // 解码数据包 + if (avcodec_send_packet(decoderCtx, inputPacket) >= 0) { int ret; - while ((ret = avcodec_receive_frame(videoCodecCtx, yuvFrame)) >= 0) { - if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) + while ((ret = avcodec_receive_frame(decoderCtx, yuvFrame)) >= 0) { + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { return; - else if (ret < 0) { + } else if (ret < 0) { fprintf(stderr, "Error during decoding\n"); exit(1); } - sws_scale(img_ctx, yuvFrame->data, yuvFrame->linesize, 0, - videoCodecCtx->height, rgbFrame->data, rgbFrame->linesize); + sws_scale(swsCtx, // + yuvFrame->data, // + yuvFrame->linesize, // + 0, // + decoderCtx->height, // + rgbFrame->data, // + rgbFrame->linesize); - QImage img(out_buffer, videoCodecCtx->width, videoCodecCtx->height, + QImage img(out_buffer, // + decoderCtx->width, // + decoderCtx->height, // QImage::Format_RGB32); emit sendQImage(img); - - // int m_timeframe= ((double)videoCodecCtx->framerate.den / - // videoCodecCtx->framerate.num)*1000; QThread::msleep(28); + + + + //将解码后的帧写入输出文件 + if (av_write_frame(outputFormatCtx, inputPacket) < 0) { + //qDebug() << "Error muxing packet.\n"; + break; + } + + } } - av_packet_unref(pkt); - } - if (IsstopPlay) { - break; + av_packet_unref(inputPacket); } + //花屏 + // if (av_read_frame(inputFormatCtx, inputPacket) < 0) { + // break; // 达到文件末尾 + // } } - - qDebug() << "All video play done"; } // 退出 void Cffmpeg_decode::stop() { + + // 写入输出文件的尾信息 + // av_write_trailer(outputFormatCtx); IsstopPlay = true; - if (!pkt) - av_packet_free(&pkt); + if (!inputPacket) + av_packet_free(&inputPacket); + if (!outputPacket) + av_packet_free(&outputPacket); if (!yuvFrame) av_frame_free(&yuvFrame); if (!rgbFrame) av_frame_free(&rgbFrame); - if (!videoCodecCtx) - avcodec_free_context(&videoCodecCtx); - if (!videoCodecCtx) - avcodec_close(videoCodecCtx); - if (!fmtCtx) - avformat_close_input(&fmtCtx); + if (!encoderCtx) + avcodec_free_context(&encoderCtx); + if (!encoderCtx) + avcodec_close(encoderCtx); + if (!decoderCtx) + avcodec_free_context(&decoderCtx); + if (!decoderCtx) + avcodec_close(decoderCtx); + if (!inputFormatCtx) + avformat_close_input(&inputFormatCtx); + if (!outputFormatCtx) + avformat_close_input(&outputFormatCtx); } diff --git a/Src/Video/cffmpeg_decode.h b/Src/Video/cffmpeg_decode.h index 74d5673..93c54d9 100644 --- a/Src/Video/cffmpeg_decode.h +++ b/Src/Video/cffmpeg_decode.h @@ -46,18 +46,33 @@ signals: void sendConnectFail(int); private: - AVFormatContext *fmtCtx = NULL; - const AVCodec *videoCodec = NULL; - AVCodecContext *videoCodecCtx = NULL; - AVPacket *pkt = NULL; + AVFormatContext *inputFormatCtx = NULL; // + AVFormatContext *outputFormatCtx = NULL; // + + AVCodecContext *decoderCtx = NULL; // + AVCodecContext *encoderCtx = NULL;// + + const AVCodec *decoder = NULL; // 解码器 + const AVCodec *encoder = NULL; // + + AVPacket *inputPacket = NULL; // + AVPacket *outputPacket = NULL; // + AVFrame *yuvFrame = NULL; AVFrame *rgbFrame = NULL; - struct SwsContext *img_ctx = NULL; + struct SwsContext *swsCtx = NULL; + + AVCodecParameters *videoCodecPara = nullptr; + AVCodecParameters *videoCodecPara2 = nullptr; + + + AVStream *outStream; unsigned char *out_buffer = nullptr; int videoStreamIndex = -1; + int videoStreamIndexOut = -1; int numBytes = -1; QString _url; diff --git a/Src/Video/myVideoProc.cpp b/Src/Video/myVideoProc.cpp new file mode 100644 index 0000000..e69de29 diff --git a/mainwindow.cpp b/mainwindow.cpp index afb5ef9..2227688 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -36,7 +36,6 @@ MainWindow::MainWindow(QWidget *parent) } QString appDir = QCoreApplication::applicationDirPath() + "/app"; - qDebug() << "Open file fail " << appDir; } From f70fb6115eaedeaf7d45e7cbc773bb6b3d6f7fee Mon Sep 17 00:00:00 2001 From: cbwu <504-wuchengbo@htsdfp.com> Date: Tue, 3 Sep 2024 09:26:32 +0800 Subject: [PATCH 6/6] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8B=89?= =?UTF-8?q?=E6=B5=81=E8=A7=86=E9=A2=91=E4=BF=9D=E5=AD=98(=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E5=AD=98=E4=B8=BAh264=E6=A0=BC=E5=BC=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/GDDC/gddcdlg.cpp | 2 + Src/ModelCamera/modelcameradlg.cpp | 3 +- Src/Video/cffmpeg_decode.cpp | 245 +++++++++++++---------------- Src/Video/cffmpeg_decode.h | 32 ++-- Src/Video/ffmpegvideodlg.cpp | 8 +- Src/Video/ffmpegvideodlg.h | 2 + 6 files changed, 143 insertions(+), 149 deletions(-) diff --git a/Src/GDDC/gddcdlg.cpp b/Src/GDDC/gddcdlg.cpp index 2934e9f..f77fde0 100644 --- a/Src/GDDC/gddcdlg.cpp +++ b/Src/GDDC/gddcdlg.cpp @@ -79,6 +79,8 @@ void GDDCdlg::initWindow() { m_GDDCStateDlg = new GDDCStateInfo(this); ui->pushButShowStatePage->setIcon(QIcon(":/res/right.png")); ui->pushButShowCmdPage->setIcon(QIcon(":/res/down.png")); + + ui->WgtffmpegVideo->setVedioSaveFileDirPath("./Video"); } // 初始化参数 diff --git a/Src/ModelCamera/modelcameradlg.cpp b/Src/ModelCamera/modelcameradlg.cpp index eadada2..45a264e 100644 --- a/Src/ModelCamera/modelcameradlg.cpp +++ b/Src/ModelCamera/modelcameradlg.cpp @@ -4,9 +4,8 @@ ModelCameraDlg::ModelCameraDlg(QWidget *parent) : QDialog(parent), ui(new Ui::ModelCameraDlg) { ui->setupUi(this); - + ui->cameraVideoWidget->setVedioSaveFileDirPath("./3DCameraVideo"); InitialComboBox(); - cameraCMDThread = new QThread(); encodeModelCamera = new EncodeModelCamera(); encodeModelCamera->moveToThread(cameraCMDThread); diff --git a/Src/Video/cffmpeg_decode.cpp b/Src/Video/cffmpeg_decode.cpp index 4ffb279..8ee3d70 100644 --- a/Src/Video/cffmpeg_decode.cpp +++ b/Src/Video/cffmpeg_decode.cpp @@ -2,9 +2,7 @@ // Cffmpeg_decode::Cffmpeg_decode() { Cffmpeg_decode::Cffmpeg_decode(QObject *parent) : QObject(parent) { inputFormatCtx = avformat_alloc_context(); - outputFormatCtx = avformat_alloc_context(); inputPacket = av_packet_alloc(); - outputPacket = av_packet_alloc(); yuvFrame = av_frame_alloc(); rgbFrame = av_frame_alloc(); avformat_network_init(); @@ -13,8 +11,6 @@ Cffmpeg_decode::Cffmpeg_decode(QObject *parent) : QObject(parent) { Cffmpeg_decode::~Cffmpeg_decode() { if (!inputPacket) av_packet_free(&inputPacket); - if (!outputPacket) - av_packet_free(&outputPacket); if (!yuvFrame) av_frame_free(&yuvFrame); if (!rgbFrame) @@ -29,8 +25,6 @@ Cffmpeg_decode::~Cffmpeg_decode() { avcodec_close(decoderCtx); if (!inputFormatCtx) avformat_close_input(&inputFormatCtx); - if (!outputFormatCtx) - avformat_close_input(&outputFormatCtx); } void Cffmpeg_decode::setUrl(QString url) { _url = url; } @@ -46,7 +40,7 @@ bool Cffmpeg_decode::open_input_file() { // 以udp方式打开,如果以tcp方式打开将udp替换为tcp av_dict_set(&avdic, "rtsp_transport", "udp", 0); // 设置超时断开连接时间,单位微秒//listen_timeout - //av_dict_set(&avdic, "listen_timeout", "200000", 0); + // av_dict_set(&avdic, "listen_timeout", "200000", 0); av_dict_set(&avdic, "stimeout", "200000", 0); av_dict_set(&avdic, "max_delay", "3", 0); // 设置最大时延 av_dict_set(&avdic, "tune", "zerolatency", 0); @@ -55,7 +49,8 @@ bool Cffmpeg_decode::open_input_file() { inputFormatCtx->flags |= AVFMT_FLAG_NONBLOCK; // 打开输入流 - if (avformat_open_input(&inputFormatCtx, _url.toUtf8().data(), NULL, &avdic) <0) { + if (avformat_open_input(&inputFormatCtx, _url.toUtf8().data(), NULL, &avdic) < + 0) { printf("Cannot open input file.\n"); return 0; } @@ -66,7 +61,8 @@ bool Cffmpeg_decode::open_input_file() { } // 从输入流中找到第一个视频流 for (int i = 0; i < inputFormatCtx->nb_streams; i++) { - if (inputFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (inputFormatCtx->streams[i]->codecpar->codec_type == + AVMEDIA_TYPE_VIDEO) { videoStreamIndex = i; continue; } @@ -101,112 +97,6 @@ bool Cffmpeg_decode::open_input_file() { return 0; } - //===============================编码================================ - // 1、输出文件设置 - if (avformat_alloc_output_context2(&outputFormatCtx, NULL, NULL, "output_video.mp4") < 0) { - qDebug() << "Could not create output context.\n"; - return 0; - } - - // 从输入流中找到第一个视频流 - for (int i = 0; i < inputFormatCtx->nb_streams; i++) { - if (inputFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - videoStreamIndexOut = i; - continue; - } - } - if (videoStreamIndexOut == -1) { - printf("Cannot find video stream in file.\n"); - return 0; - } - // 获取视频流的解码器参数 - videoCodecPara2 = inputFormatCtx->streams[videoStreamIndexOut]->codecpar; - - // 3、创建输出视频流 - outStream = avformat_new_stream(outputFormatCtx, NULL); - if (!outStream) { - qDebug() << "Failed allocating output stream.\n"; - return 0; - } - //4、查找编码器 - encoder = avcodec_find_encoder(videoCodecPara2->codec_id); - if(!encoder){ - return 0; - } - - //5、分配解码器上下文 - encoderCtx = avcodec_alloc_context3(encoder); - if (!encoderCtx) { - return 0; - } - - //初始化视频AVCodecContext - encoderCtx->height = videoCodecPara2->height; - encoderCtx->width = videoCodecPara2->width; - videoCodecPara2->framerate = av_guess_frame_rate(inputFormatCtx,inputFormatCtx->streams[videoStreamIndexOut],NULL); - - //视频流的时间基是1 / 帧率 - encoderCtx->time_base = av_inv_q(inputFormatCtx->streams[videoStreamIndexOut]->codecpar->framerate); - encoderCtx->sample_aspect_ratio = inputFormatCtx->streams[videoStreamIndexOut]->codecpar->sample_aspect_ratio; - if (encoder->pix_fmts) - { - encoderCtx->pix_fmt = encoder->pix_fmts[0]; - } - encoderCtx->codec_type = AVMEDIA_TYPE_VIDEO; - encoderCtx->codec_id = AV_CODEC_ID_H264; - encoderCtx->bit_rate = 2000000; - encoderCtx->time_base.num = 1; - encoderCtx->time_base.den = 20; - - //全局头 - if (outputFormatCtx->oformat->flags & AVFMT_GLOBALHEADER) - { - encoderCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - } - - // //设置选项 - // AVDictionary *param = 0; - // //H.264 - // if(videoCodecPara->codec_id == AV_CODEC_ID_H264) { - // av_dict_set(¶m, "preset", "slow", 0); - // av_dict_set(¶m, "tune", "zerolatency", 0); - // av_dict_set(¶m, "profile", "main", 0); - // } - // //H.265 - // if(videoCodecPara->codec_id == AV_CODEC_ID_H265){ - // av_dict_set(¶m, "preset", "ultrafast", 0); - // av_dict_set(¶m, "tune", "zero-latency", 0); - // } - - //6、打开编码器 - if (avcodec_open2(encoderCtx, encoder, NULL) < 0) { - qDebug() << "Error occurred when opening encoder.\n"; - //return 0; - } - - avcodec_parameters_from_context(outputFormatCtx->streams[0]->codecpar, encoderCtx); - //avcodec_parameters_to_context(encoderCtx,outStream->codecpar); - - // 打开输出文件 - if (!(outputFormatCtx->oformat->flags & AVFMT_NOFILE)) { - if (avio_open(&outputFormatCtx->pb, - outputFormatCtx->url /* "output_video.mp4"*/, - AVIO_FLAG_WRITE) < 0) { - printf("Could not open output file.\n"); - return 0; - } - } - - //写入输出文件的头信息 - if (avformat_write_header(outputFormatCtx, NULL) < 0) { - qDebug() << "Error occurred when opening output file.\n"; - //return 0; - } - //格式化输出输出文件信息 - av_dump_format(outputFormatCtx,0,outputFormatCtx->url,1); - - - // 初始化图像转换器 swsCtx = sws_getContext(decoderCtx->width, // decoderCtx->height, // @@ -219,6 +109,7 @@ bool Cffmpeg_decode::open_input_file() { decoderCtx->width, // decoderCtx->height, // 1); + out_buffer = (unsigned char *)av_malloc(numBytes * sizeof(unsigned char)); int res = av_image_fill_arrays(rgbFrame->data, // @@ -231,7 +122,9 @@ bool Cffmpeg_decode::open_input_file() { qDebug() << "Fill arrays failed.\n"; return 0; } - + if (!openSave()) { + return false; + }; return true; } @@ -252,6 +145,15 @@ void Cffmpeg_decode::run() { } if (inputPacket->stream_index == videoStreamIndex) { + // 保存裸流 + if (m_formatContextSave) { + // 由于保存的m_formatContextSave只创建了一个视频流,而读取到的图像的流索引不一定为0,可能会出现错误【Invalid + // packet stream index: 1】 + // 所以这里需要将stream_index指定为和m_formatContextSave中视频流索引相同,因为就一个流,所以直接设置为0 + inputPacket->stream_index = 0; + av_write_frame(m_formatContextSave, + inputPacket); // 将数据包写入输出媒体文件 + } // 解码数据包 if (avcodec_send_packet(decoderCtx, inputPacket) >= 0) { int ret; @@ -276,25 +178,25 @@ void Cffmpeg_decode::run() { QImage::Format_RGB32); emit sendQImage(img); QThread::msleep(28); - - - - //将解码后的帧写入输出文件 - if (av_write_frame(outputFormatCtx, inputPacket) < 0) { - //qDebug() << "Error muxing packet.\n"; - break; - } - - } } av_packet_unref(inputPacket); } - //花屏 - // if (av_read_frame(inputFormatCtx, inputPacket) < 0) { - // break; // 达到文件末尾 - // } + if (IsstopPlay) { + if (m_formatContextSave) { + saveDone(); + } + break; + } + // 花屏 + // if (av_read_frame(inputFormatCtx, inputPacket) < 0) { + // break; // 达到文件末尾 + // } + } + if (m_formatContextSave) { + saveDone(); } + qDebug() << "All video play done"; } // 退出 @@ -305,8 +207,6 @@ void Cffmpeg_decode::stop() { IsstopPlay = true; if (!inputPacket) av_packet_free(&inputPacket); - if (!outputPacket) - av_packet_free(&outputPacket); if (!yuvFrame) av_frame_free(&yuvFrame); if (!rgbFrame) @@ -321,6 +221,83 @@ void Cffmpeg_decode::stop() { avcodec_close(decoderCtx); if (!inputFormatCtx) avformat_close_input(&inputFormatCtx); - if (!outputFormatCtx) - avformat_close_input(&outputFormatCtx); +} + +void Cffmpeg_decode::setSaveFileDirPath(QString fileDirPath) { + saveFileDirPath = fileDirPath; +} + +bool Cffmpeg_decode::openSave() { + QDir dir; + if (!dir.exists(saveFileDirPath)) { + dir.mkdir(saveFileDirPath); + } + QString strName = + QString("/%1.h264") + .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH-mm-ss")); + strName = saveFileDirPath + strName; + // const AVOutputFormat *ofmt = av_guess_format("mp4", NULL, NULL); + int ret = avformat_alloc_output_context2( + &m_formatContextSave, nullptr, nullptr, strName.toStdString().data()); + if (ret < 0) { + // free(); + qWarning() << "DecodeVideo Error"; + return false; + } + // m_videoStreamOut->codecpar->codec_tag = 0; + // if (m_formatContextSave->oformat->flags & AVFMT_GLOBALHEADER) { + // m_formatContextSave->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + // // m_videoStreamOut->codecpar->extradata = (uint8_t *)av_malloc(1024); + // // m_videoStreamOut->codecpar->extradata_size = 0; + // } + // 创建并初始化AVIOContext以访问url所指示的资源。 + ret = avio_open(&m_formatContextSave->pb, strName.toStdString().data(), + AVIO_FLAG_WRITE); + if (ret < 0) { + // free(); + qWarning() << "DecodeVideo Error"; + return false; + } + // 向媒体文件添加新流 + m_videoStreamOut = avformat_new_stream(m_formatContextSave, nullptr); + if (!m_videoStreamOut) { + qWarning() << "DecodeVideo Error"; + return false; + } + // 拷贝一些参数,给codecpar赋值(这里使用编码器上下文进行赋值) + ret = avcodec_parameters_from_context(m_videoStreamOut->codecpar, decoderCtx); + if (ret < 0) { + // free(); + qWarning() << "DecodeVideo Error"; + return false; + } + + // 写入文件头 + ret = avformat_write_header(m_formatContextSave, nullptr); + if (ret < 0) { + // free(); + qWarning() << "DecodeVideo Error"; + return false; + } + + m_writeHeader = true; + qDebug() << "开始录制视频!"; + return true; +} + +void Cffmpeg_decode::saveDone() { + if (m_formatContextSave && m_writeHeader) { + av_write_trailer(m_formatContextSave); // 写入文件尾 + m_writeHeader = false; + } + // 关闭文件 + if (m_formatContextSave && !(m_formatContextSave->flags & AVFMT_NOFILE)) { + avio_close(m_formatContextSave->pb); + // av_freep(m_videoStreamOut); + if (m_formatContextSave) { + avformat_free_context(m_formatContextSave); + m_formatContextSave = nullptr; + } + // m_videoStreamOut = nullptr; + } } diff --git a/Src/Video/cffmpeg_decode.h b/Src/Video/cffmpeg_decode.h index 93c54d9..0543a22 100644 --- a/Src/Video/cffmpeg_decode.h +++ b/Src/Video/cffmpeg_decode.h @@ -1,7 +1,9 @@ #ifndef CFFMPEG_DECODE_H #define CFFMPEG_DECODE_H +#include #include +#include #include #include #include @@ -38,6 +40,11 @@ public: bool open_input_file(); bool IsstopPlay = false; void stop(); + /** + * @brief 设置拉流保存文件夹路径 + * @param fileDirPath 文件夹路径 + */ + void setSaveFileDirPath(QString fileDirPath); public slots: void run(); @@ -46,36 +53,37 @@ signals: void sendConnectFail(int); private: - AVFormatContext *inputFormatCtx = NULL; // - AVFormatContext *outputFormatCtx = NULL; // + AVFormatContext *inputFormatCtx = NULL; // AVCodecContext *decoderCtx = NULL; // - AVCodecContext *encoderCtx = NULL;// + AVCodecContext *encoderCtx = NULL; // const AVCodec *decoder = NULL; // 解码器 - const AVCodec *encoder = NULL; // - AVPacket *inputPacket = NULL; // - AVPacket *outputPacket = NULL; // + AVPacket *inputPacket = NULL; // AVFrame *yuvFrame = NULL; AVFrame *rgbFrame = NULL; - struct SwsContext *swsCtx = NULL; + struct SwsContext *swsCtx = NULL; // 图像转换上下文 AVCodecParameters *videoCodecPara = nullptr; - AVCodecParameters *videoCodecPara2 = nullptr; - - - AVStream *outStream; unsigned char *out_buffer = nullptr; int videoStreamIndex = -1; - int videoStreamIndexOut = -1; int numBytes = -1; QString _url; + QString saveFileDirPath; + /******** 保存裸流使用 ******************/ + AVFormatContext *m_formatContextSave = nullptr; // 封装上下文 + QString m_strCodecName; // 编解码器名称 + AVStream *m_videoStreamOut = nullptr; // 输出视频流 + bool m_writeHeader = false; // 是否写入文件头 +private: + bool openSave(); + void saveDone(); }; #endif // CFFMPEG_DECODE_H diff --git a/Src/Video/ffmpegvideodlg.cpp b/Src/Video/ffmpegvideodlg.cpp index 079cc7b..67e5dff 100644 --- a/Src/Video/ffmpegvideodlg.cpp +++ b/Src/Video/ffmpegvideodlg.cpp @@ -5,7 +5,7 @@ ffmpegvideoDlg::ffmpegvideoDlg(QWidget *parent) : QWidget(parent), ui(new Ui::ffmpegvideoDlg) { ui->setupUi(this); - iniWindow(); + // iniWindow(); } ffmpegvideoDlg::~ffmpegvideoDlg() { @@ -13,6 +13,7 @@ ffmpegvideoDlg::~ffmpegvideoDlg() { delete ui; } +// 暂未使用 void ffmpegvideoDlg::iniWindow() { QString VideoFilePath = QDir::currentPath() + "./Video"; QDir VideoDir(VideoFilePath); @@ -23,10 +24,15 @@ void ffmpegvideoDlg::iniWindow() { } void ffmpegvideoDlg::setUrl(QString url) { ffmpeg->setUrl(url); } +void ffmpegvideoDlg::setVedioSaveFileDirPath(QString saveDirPath) { + videoSaveDirPath = saveDirPath; +} + void ffmpegvideoDlg::play() { if (!m_PlayStatus) { m_PlayStatus = true; ffmpeg = new Cffmpeg_decode; + ffmpeg->setSaveFileDirPath(videoSaveDirPath); ffmpeg->IsstopPlay = false; ffmpeg->moveToThread(&workerThread); connect(&workerThread, &QThread::finished, ffmpeg, diff --git a/Src/Video/ffmpegvideodlg.h b/Src/Video/ffmpegvideodlg.h index 428f8ce..e91386b 100644 --- a/Src/Video/ffmpegvideodlg.h +++ b/Src/Video/ffmpegvideodlg.h @@ -44,6 +44,7 @@ private: public: void iniWindow(); void setUrl(QString url); + void setVedioSaveFileDirPath(QString saveDirPath); void play(); void stop(); @@ -69,6 +70,7 @@ private: Cffmpeg_decode *ffmpeg; QThread workerThread; QImage img; + QString videoSaveDirPath; }; #endif // FFMPEGVIDEODLG_H