feat: 新增通信开始,udp原始数据文件保存

map
cbwu 2 weeks ago
parent 5e3ef6ffa2
commit 42098d14b4

@ -1,5 +1,7 @@
#include "global.h"
// bool g_videoPlayStatus[5];
QSettings* g_networkSettingInfo;
PullStreamInfoStruct g_pullStreamInfoStruct;

@ -34,6 +34,8 @@ struct PushStreamInfoStruct {
QString pushStreamIP;
};
// extern bool g_videoPlayStatus[5];
extern QSettings* g_networkSettingInfo;
extern PullStreamInfoStruct g_pullStreamInfoStruct;
@ -48,12 +50,7 @@ extern bool isValidIPAddress(const QString& ip);
extern bool isMulticastAddress(const QString& ip);
// enum NotificationType {
// NOTIFICATION_INFORMATION = 0,
// NOTIFICATION_SUCCESS = 1,
// NOTIFICATION_ERROR = 2,
// NOTIFICATION_WARNING = 3
// };
enum NotifyType { INFORMATION = 0, SUCCESS = 1, ERROR = 2, WARNING = 3 };
/**
* @brief calCRC16

@ -112,9 +112,14 @@ void MainWindow::initSignalConnection() {
connect(&streamAddrSettingsDlg,
&StreamAddrSettingsDlg::startPushStreamSignal, this,
&MainWindow::pushStreamSlot);
connect(ui->videoControlWidget, &VideoControl::stopVideoSignal, this,
&MainWindow::closeVideoSlot);
}
void MainWindow::initNotifyMessageConnection() {
connect(this, &MainWindow::sendErrorMessage, this,
&MainWindow::showMessageSlots);
connect(ui->videoWidget, &VideoWidget::sendErrorMessageSignal, this,
&MainWindow::showMessageSlots);
connect(ui->commandWidget, &CommandWidget::sendErrorMessage, this,
@ -326,27 +331,57 @@ void MainWindow::openSavedVideoDirSlot() {
void MainWindow::pullStreamSlot(bool bPull) {
if (!g_networkSettingInfo) return;
if (bPull) {
QString podPullStreamIP =
g_networkSettingInfo->value("NetworkStreamSettings/podPullAddress")
.toString();
QString pullStreamIP1 =
g_networkSettingInfo->value("NetworkStreamSettings/pullAddress1")
.toString();
QString pullStreamIP2 =
g_networkSettingInfo->value("NetworkStreamSettings/pullAddress2")
.toString();
QString pullStreamIP3 =
g_networkSettingInfo->value("NetworkStreamSettings/pullAddress3")
.toString();
QString pullStreamIP4 =
g_networkSettingInfo->value("NetworkStreamSettings/pullAddress4")
.toString();
// QString podPullStreamIP =
// g_networkSettingInfo->value("NetworkStreamSettings/podPullAddress")
// .toString();
// QString pullStreamIP1 =
// g_networkSettingInfo->value("NetworkStreamSettings/pullAddress1")
// .toString();
// QString pullStreamIP2 =
// g_networkSettingInfo->value("NetworkStreamSettings/pullAddress2")
// .toString();
// QString pullStreamIP3 =
// g_networkSettingInfo->value("NetworkStreamSettings/pullAddress3")
// .toString();
// QString pullStreamIP4 =
// g_networkSettingInfo->value("NetworkStreamSettings/pullAddress4")
// .toString();
if (!ui->videoWidget->getPlayStatus()) {
ui->videoWidget->play(g_pullStreamInfoStruct.podPullIP);
} else {
emit sendErrorMessage("吊舱视频正在播放,请先暂停!",
NotifyType::WARNING);
}
if (!ui->videoWidget1->getPlayStatus()) {
ui->videoWidget1->play(g_pullStreamInfoStruct.pullIP1);
} else {
emit sendErrorMessage("备用视频1正在播放请先暂停!",
NotifyType::WARNING);
}
if (!ui->videoWidget2->getPlayStatus()) {
ui->videoWidget2->play(g_pullStreamInfoStruct.pullIP2);
} else {
emit sendErrorMessage("备用视频2正在播放请先暂停!",
NotifyType::WARNING);
}
if (!ui->videoWidget3->getPlayStatus()) {
ui->videoWidget3->play(g_pullStreamInfoStruct.pullIP3);
} else {
emit sendErrorMessage("备用视频3正在播放请先暂停!",
NotifyType::WARNING);
}
if (!ui->videoWidget4->getPlayStatus()) {
ui->videoWidget4->play(g_pullStreamInfoStruct.pullIP4);
} else {
emit sendErrorMessage("备用视频4正在播放请先暂停!",
NotifyType::WARNING);
}
} else {
ui->videoWidget->stopPlay();
ui->videoWidget1->stopPlay();
@ -398,3 +433,13 @@ void MainWindow::pushStreamSlot(bool bPush) {
// ui->videoWidget4->stopPushStream();
}
}
void MainWindow::closeVideoSlot() {
ui->videoWidget->stopPlay();
ui->videoWidget1->stopPlay();
ui->videoWidget2->stopPlay();
ui->videoWidget3->stopPlay();
ui->videoWidget4->stopPlay();
emit sendErrorMessage("视频流已关闭!", NotifyType::SUCCESS);
}

@ -50,6 +50,7 @@ protected:
void paintEvent(QPaintEvent *ev) override;
signals:
void themeChanged();
void sendErrorMessage(QString message, int type);
private:
void initSignalConnection();
@ -64,6 +65,7 @@ private:
void setSavedVideoDir();
void initHideButton();
private slots:
void showSettingDlgSlot();
void showStreamSettingsDlgSlot();
@ -73,6 +75,8 @@ private slots:
void pullStreamSlot(bool bPull);
void pushStreamSlot(bool bPush);
void closeVideoSlot();
private:
Ui::MainWindow *ui;
VideoWidget *videoWidget1 = nullptr;

@ -12,6 +12,10 @@ ReadStream::~ReadStream() {
udpSocket->abort();
udpSocket->deleteLater();
}
if (m_saveFile.isOpen()) {
m_saveFile.close();
}
}
bool ReadStream::openFile(const QString &url) {
@ -187,6 +191,19 @@ bool ReadStream::initSocket(QString ip, int port) {
}
}
bool ReadStream::initSavedRawFile(QString fileDir, QString uavName) {
QDir dir;
if (!dir.exists(fileDir)) {
dir.mkdir(fileDir);
}
QString strName = QString("%1.dat").arg(
QDateTime::currentDateTime().toString("yyyyMMddHHmmss"));
QString filename = fileDir + "/" + uavName + "_" + strName;
m_saveFile.setFileName(filename);
bool bOopen = m_saveFile.open(QIODevice::WriteOnly | QIODevice::Append);
return bOopen;
}
void ReadStream::startPullStream() {
// 如果没有打开则返回
if (!m_formatContext) {
@ -260,6 +277,8 @@ void ReadStream::startPullUDPStream() {
return;
}
initSavedRawFile();
const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);
codec_ctx = avcodec_alloc_context3(codec);
codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
@ -282,6 +301,10 @@ void ReadStream::closeUDPConnectionSLot() {
delete udpSocket;
udpSocket = nullptr;
}
if (m_saveFile.isOpen()) {
m_saveFile.close();
}
}
void ReadStream::initFFmpeg() {
@ -430,6 +453,11 @@ void ReadStream::udpDataReceivedSlot() {
QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagram.data(), datagram.size());
// 保存原始数据
if (m_saveFile.isOpen()) {
m_saveFile.write(datagram.toHex());
}
if (static_cast<uint8_t>(datagram.at(0)) == 0xEB &&
static_cast<uint8_t>(datagram[1]) == 0x90 &&
static_cast<uint8_t>(datagram[4]) == 0xD5) {

@ -2,6 +2,7 @@
#define READSTREAM_H
#include <QDebug>
#include <QFile>
#include <QMutex>
#include <QObject>
#include <QQueue>
@ -29,6 +30,8 @@ public:
void setUDPParms(QString ip, int port);
bool initSocket(QString ip, int port);
bool initSavedRawFile(QString fileDir = "./dat", QString uavName = "fp98");
public slots:
void startPullStream();
void startPullUDPStream();
@ -89,6 +92,7 @@ private:
AVPacketQueueManager m_queueManager;
private:
QFile m_saveFile;
QUdpSocket *udpSocket = nullptr;
QString m_UDPIP;
int m_UDPPort;

@ -52,7 +52,7 @@ VideoWidget::~VideoWidget() {
}
bool VideoWidget::play(const QString &url) {
// if (url.isEmpty()) return;
if (url.isEmpty()) return false;
if (!m_pullFlag) {
m_pullFlag = pullStream(url);
if (!m_pullFlag) {
@ -215,6 +215,10 @@ void VideoWidget::setVedioSaveFileDirPath(const QString &dirPath) {
m_videoSaveDirPath = dirPath;
}
bool VideoWidget::getPlayStatus() {
return this->m_playFlag;
}
void VideoWidget::repaint(AVFrame *frame) {
try {
QMutexLocker locker(&m_mutex);

@ -46,12 +46,12 @@ public:
bool play(const QString &url);
bool udpPlay(QString ip, int port);
void stopPlay();
// void stopUDPPlay();
bool pushStream(const QString &url);
void stopPushStream();
void setPullURL(const QString &url);
void setPushURL(const QString &url);
void setVedioSaveFileDirPath(const QString &dirPath);
bool getPlayStatus();
protected:
void initializeGL() override; // 初始化gl

@ -115,3 +115,10 @@ void VideoControl::on_pbPlayer_clicked() {
ui->pbPlayer->setDisabled(false);
}
// 停止
void VideoControl::on_pbStop_clicked() {
ui->pbStop->setDisabled(true);
emit stopVideoSignal();
ui->pbStop->setDisabled(false);
}

@ -23,6 +23,8 @@ signals:
void stopConnectionSignal();
void sendErrorMessage(QString message, int type);
void changeVideoLayout(int index);
void stopVideoSignal();
private slots:
void receiveMessageSlots(QString message, int type);
@ -32,6 +34,8 @@ private slots:
void on_pbPlayer_clicked();
void on_pbStop_clicked();
private:
Ui::VideoControl *ui;

Loading…
Cancel
Save