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

map
cbwu 2 weeks ago
parent 5e3ef6ffa2
commit 42098d14b4

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

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

@ -112,9 +112,14 @@ void MainWindow::initSignalConnection() {
connect(&streamAddrSettingsDlg, connect(&streamAddrSettingsDlg,
&StreamAddrSettingsDlg::startPushStreamSignal, this, &StreamAddrSettingsDlg::startPushStreamSignal, this,
&MainWindow::pushStreamSlot); &MainWindow::pushStreamSlot);
connect(ui->videoControlWidget, &VideoControl::stopVideoSignal, this,
&MainWindow::closeVideoSlot);
} }
void MainWindow::initNotifyMessageConnection() { void MainWindow::initNotifyMessageConnection() {
connect(this, &MainWindow::sendErrorMessage, this,
&MainWindow::showMessageSlots);
connect(ui->videoWidget, &VideoWidget::sendErrorMessageSignal, this, connect(ui->videoWidget, &VideoWidget::sendErrorMessageSignal, this,
&MainWindow::showMessageSlots); &MainWindow::showMessageSlots);
connect(ui->commandWidget, &CommandWidget::sendErrorMessage, this, connect(ui->commandWidget, &CommandWidget::sendErrorMessage, this,
@ -326,27 +331,57 @@ void MainWindow::openSavedVideoDirSlot() {
void MainWindow::pullStreamSlot(bool bPull) { void MainWindow::pullStreamSlot(bool bPull) {
if (!g_networkSettingInfo) return; if (!g_networkSettingInfo) return;
if (bPull) { if (bPull) {
QString podPullStreamIP = // QString podPullStreamIP =
g_networkSettingInfo->value("NetworkStreamSettings/podPullAddress") // g_networkSettingInfo->value("NetworkStreamSettings/podPullAddress")
.toString(); // .toString();
QString pullStreamIP1 = // QString pullStreamIP1 =
g_networkSettingInfo->value("NetworkStreamSettings/pullAddress1") // g_networkSettingInfo->value("NetworkStreamSettings/pullAddress1")
.toString(); // .toString();
QString pullStreamIP2 = // QString pullStreamIP2 =
g_networkSettingInfo->value("NetworkStreamSettings/pullAddress2") // g_networkSettingInfo->value("NetworkStreamSettings/pullAddress2")
.toString(); // .toString();
QString pullStreamIP3 = // QString pullStreamIP3 =
g_networkSettingInfo->value("NetworkStreamSettings/pullAddress3") // g_networkSettingInfo->value("NetworkStreamSettings/pullAddress3")
.toString(); // .toString();
QString pullStreamIP4 = // QString pullStreamIP4 =
g_networkSettingInfo->value("NetworkStreamSettings/pullAddress4") // g_networkSettingInfo->value("NetworkStreamSettings/pullAddress4")
.toString(); // .toString();
if (!ui->videoWidget->getPlayStatus()) {
ui->videoWidget->play(g_pullStreamInfoStruct.podPullIP); ui->videoWidget->play(g_pullStreamInfoStruct.podPullIP);
} else {
emit sendErrorMessage("吊舱视频正在播放,请先暂停!",
NotifyType::WARNING);
}
if (!ui->videoWidget1->getPlayStatus()) {
ui->videoWidget1->play(g_pullStreamInfoStruct.pullIP1); ui->videoWidget1->play(g_pullStreamInfoStruct.pullIP1);
} else {
emit sendErrorMessage("备用视频1正在播放请先暂停!",
NotifyType::WARNING);
}
if (!ui->videoWidget2->getPlayStatus()) {
ui->videoWidget2->play(g_pullStreamInfoStruct.pullIP2); ui->videoWidget2->play(g_pullStreamInfoStruct.pullIP2);
} else {
emit sendErrorMessage("备用视频2正在播放请先暂停!",
NotifyType::WARNING);
}
if (!ui->videoWidget3->getPlayStatus()) {
ui->videoWidget3->play(g_pullStreamInfoStruct.pullIP3); ui->videoWidget3->play(g_pullStreamInfoStruct.pullIP3);
} else {
emit sendErrorMessage("备用视频3正在播放请先暂停!",
NotifyType::WARNING);
}
if (!ui->videoWidget4->getPlayStatus()) {
ui->videoWidget4->play(g_pullStreamInfoStruct.pullIP4); ui->videoWidget4->play(g_pullStreamInfoStruct.pullIP4);
} else {
emit sendErrorMessage("备用视频4正在播放请先暂停!",
NotifyType::WARNING);
}
} else { } else {
ui->videoWidget->stopPlay(); ui->videoWidget->stopPlay();
ui->videoWidget1->stopPlay(); ui->videoWidget1->stopPlay();
@ -398,3 +433,13 @@ void MainWindow::pushStreamSlot(bool bPush) {
// ui->videoWidget4->stopPushStream(); // 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; void paintEvent(QPaintEvent *ev) override;
signals: signals:
void themeChanged(); void themeChanged();
void sendErrorMessage(QString message, int type);
private: private:
void initSignalConnection(); void initSignalConnection();
@ -64,6 +65,7 @@ private:
void setSavedVideoDir(); void setSavedVideoDir();
void initHideButton(); void initHideButton();
private slots: private slots:
void showSettingDlgSlot(); void showSettingDlgSlot();
void showStreamSettingsDlgSlot(); void showStreamSettingsDlgSlot();
@ -73,6 +75,8 @@ private slots:
void pullStreamSlot(bool bPull); void pullStreamSlot(bool bPull);
void pushStreamSlot(bool bPush); void pushStreamSlot(bool bPush);
void closeVideoSlot();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
VideoWidget *videoWidget1 = nullptr; VideoWidget *videoWidget1 = nullptr;

@ -12,6 +12,10 @@ ReadStream::~ReadStream() {
udpSocket->abort(); udpSocket->abort();
udpSocket->deleteLater(); udpSocket->deleteLater();
} }
if (m_saveFile.isOpen()) {
m_saveFile.close();
}
} }
bool ReadStream::openFile(const QString &url) { 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() { void ReadStream::startPullStream() {
// 如果没有打开则返回 // 如果没有打开则返回
if (!m_formatContext) { if (!m_formatContext) {
@ -260,6 +277,8 @@ void ReadStream::startPullUDPStream() {
return; return;
} }
initSavedRawFile();
const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264); const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);
codec_ctx = avcodec_alloc_context3(codec); codec_ctx = avcodec_alloc_context3(codec);
codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
@ -282,6 +301,10 @@ void ReadStream::closeUDPConnectionSLot() {
delete udpSocket; delete udpSocket;
udpSocket = nullptr; udpSocket = nullptr;
} }
if (m_saveFile.isOpen()) {
m_saveFile.close();
}
} }
void ReadStream::initFFmpeg() { void ReadStream::initFFmpeg() {
@ -430,6 +453,11 @@ void ReadStream::udpDataReceivedSlot() {
QByteArray datagram; QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize()); datagram.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagram.data(), datagram.size()); udpSocket->readDatagram(datagram.data(), datagram.size());
// 保存原始数据
if (m_saveFile.isOpen()) {
m_saveFile.write(datagram.toHex());
}
if (static_cast<uint8_t>(datagram.at(0)) == 0xEB && if (static_cast<uint8_t>(datagram.at(0)) == 0xEB &&
static_cast<uint8_t>(datagram[1]) == 0x90 && static_cast<uint8_t>(datagram[1]) == 0x90 &&
static_cast<uint8_t>(datagram[4]) == 0xD5) { static_cast<uint8_t>(datagram[4]) == 0xD5) {

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

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

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

@ -115,3 +115,10 @@ void VideoControl::on_pbPlayer_clicked() {
ui->pbPlayer->setDisabled(false); 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 stopConnectionSignal();
void sendErrorMessage(QString message, int type); void sendErrorMessage(QString message, int type);
void changeVideoLayout(int index); void changeVideoLayout(int index);
void stopVideoSignal();
private slots: private slots:
void receiveMessageSlots(QString message, int type); void receiveMessageSlots(QString message, int type);
@ -32,6 +34,8 @@ private slots:
void on_pbPlayer_clicked(); void on_pbPlayer_clicked();
void on_pbStop_clicked();
private: private:
Ui::VideoControl *ui; Ui::VideoControl *ui;

Loading…
Cancel
Save