代码拉取完成,页面将自动刷新
#include "networkcamerachannel1.h"
#include "ui_networkcamerachannel1.h"
#include <QPainterPath>
#include <QGraphicsOpacityEffect>
#include <QPainter>
#include <QSizePolicy>
#define RTSP_URL_HEAD tr("rtsp://")
#define INFO_WIDTH (150)
#define INFO_HEIGHT (40)
#define SWAP_SMALL (33)
#define SWAP_BIG (54)
#define FULL_SCREEN_SMALL (33)
#define FULL_SCREEN_BIG (65)
#define EXIT_FULL_SCREEN_BIG (65)
//static NetWorkCameraChannel1 *m_NetWorkCameraChannel1 = nullptr;
NetWorkCameraChannel1::NetWorkCameraChannel1(NetWorkCameraInfo netWorkCameraInfo,QWidget *parent) :
QWidget(parent),
ui(new Ui::NetWorkCameraChannel1),
m_netWorkCameraInfo(netWorkCameraInfo)
{
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
// ui->m_pBtnExitFullScreen->hide();//退出全屏隐藏
m_viewList=new ViewList(this);
m_viewList->hide();
m_InfoShowLabel = new InfoShowLabel(this);
m_InfoShowLabel->resize(INFO_WIDTH,INFO_HEIGHT);
m_DataDictionary = DataDictionary::GetInstance();
m_DataDictionary->SetMisData(MIS_CAMERA_STA1,CAMERA_OFFLINE);
m_Url.clear();
m_Player = new QTimer();
m_Player->setInterval(1000);
m_MyFFmpeg = new MyFFmpeg;
m_RtspPlayer = new RTSP_Player(m_MyFFmpeg);
m_playThread = new QThread();
m_RtspPlayer->moveToThread(m_playThread);
m_playThread->start();
m_DisconnectTimer = new QTimer;
m_DisconnectTimer->setInterval(1000 * 15);
m_Shoting = false;
m_DisplayInterval = m_DataDictionary->GetMisData(MIS_DISPLAY_INTERVAL1).toInt();
HideCentre();
BuildUrl();
// connect(m_MyFFmpeg,SIGNAL(MyFFmpegSigGetOneFrame(QImage)),this,SLOT(NetCameraShow(QImage)),Qt::QueuedConnection);
connect(m_MyFFmpeg,SIGNAL(MyFFmpegSigGetOneFrame(QImage)),this,SLOT(NetCameraShow(QImage)),Qt::BlockingQueuedConnection);
connect(m_Player,SIGNAL(timeout()),m_RtspPlayer,SLOT(PlayerStart()));
connect(m_DisconnectTimer,SIGNAL(timeout()),this,SLOT(DisconnectDisplay()));
connect(m_RtspPlayer,SIGNAL(SigOpenUrlResult(int)),this,SLOT(PlayerStatus(int)));
connect(m_DataDictionary,SIGNAL(SystemDataChange(SystemDataIndex_t)),this,SLOT(SystemDataChangeProcess(SystemDataIndex_t)));
connect(m_DataDictionary,SIGNAL(MisDataChange(MisDataIndex_t)),this,SLOT(MisDataChange(MisDataIndex_t)));
}
NetWorkCameraChannel1::~NetWorkCameraChannel1()
{
delete ui;
}
ViewList* NetWorkCameraChannel1::getViewList()
{
return m_viewList;
}
QString NetWorkCameraChannel1::UrlGetIp(QString Str)
{
QRegExp regEx("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");
QRegExpValidator V(regEx);
int32_t pos = 0;
QValidator::State res;
QString Ip ;
res = V.validate(Str,pos);
regEx.indexIn(Str,0);
Ip = regEx.cap(0);
return Ip;
}
void NetWorkCameraChannel1::BuildUrl()
{
if(!m_DataDictionary)
return ;
// m_RtspPlayer->PlayerStop();
QString passWord = m_netWorkCameraInfo.passWord;
QString userName = m_netWorkCameraInfo.userName;
QString ip = m_netWorkCameraInfo.ip;
QString port = m_netWorkCameraInfo.port;
QString path = m_netWorkCameraInfo.path;
QString url = m_netWorkCameraInfo.url;
if(url.isEmpty())
m_Url = RTSP_URL_HEAD + userName + ":" + passWord + "@" + ip + ":" + port + path;
else
m_Url = url;
qDebug() << m_Url;
m_MyFFmpeg->MyFFmpegSetUrl(m_Url);
m_RtspPlayer->Play();
ip = UrlGetIp(m_Url);
m_InfoShowLabel->SetInfo(ip);
}
//NetWorkCameraChannel1 *NetWorkCameraChannel1::GetInstance()
//{
// if(m_NetWorkCameraChannel1 == nullptr){
// m_NetWorkCameraChannel1 = new NetWorkCameraChannel1;
// }
// return m_NetWorkCameraChannel1;
//}
void NetWorkCameraChannel1::resizeEvent(QResizeEvent *event)
{
// qDebug() << "aaaaaaaaaaaaa" << event->size();
// this->resize(event->size());
// ui->DisplayLabel->resize(event->size());
// m_InfoShowLabel->move(event->size().width()-INFO_WIDTH - 30,event->size().height()-INFO_HEIGHT-20);
// m_FullScreenButton->move(event->size().width() - m_FullScreenButton->width() - 20,40);
if((this->width()>700)&&(this->width()<800))
{
// ui->pushButton->setGeometry(this->width()-SWAP_BIG,0,SWAP_BIG,SWAP_BIG);
// ui->pushButton->setStyleSheet("background:transparent;border-image:url(:/image/GroupBig.png);");
// ui->pushButton_2->setGeometry(this->width()-FULL_SCREEN_BIG,this->height()-FULL_SCREEN_BIG,FULL_SCREEN_BIG,FULL_SCREEN_BIG);
// ui->pushButton_2->setStyleSheet("background:transparent;border-image:url(:/image/FullScreen.png);");
ui->DisplayLabel->setStyleSheet("font: 23px '等线';color: #FE6240;");
// ui->pushButton_2->move(this->width()-TOP_BUTTON_WIDTH,this->height()-TOP_BUTTON_HEIGHT);
}else if(this->width()<700){
// ui->pushButton->setGeometry(this->width()-SWAP_SMALL,0,SWAP_SMALL,SWAP_SMALL);
// ui->pushButton->setStyleSheet("background:transparent;border-image:url(:/image/GroupSmall.png);");
// ui->pushButton_2->setGeometry(this->width()-FULL_SCREEN_SMALL,this->height()-FULL_SCREEN_SMALL,FULL_SCREEN_SMALL,FULL_SCREEN_SMALL);
// ui->pushButton_2->setStyleSheet("background:transparent;border-image:url(:/image/fullScreenSmall.png);");
ui->DisplayLabel->setStyleSheet("font: 13px '等线';color: #FE6240;");
}else {
// ui->pushButton->setGeometry(this->width()-SWAP_BIG,0,SWAP_BIG,SWAP_BIG);
// ui->pushButton->setStyleSheet("background:transparent;border-image:url(:/image/GroupBig.png);");
ui->DisplayLabel->setStyleSheet("font: 23px '等线';color: #FE6240;");
// ui->m_pBtnExitFullScreen->setGeometry(this->width()-EXIT_FULL_SCREEN_BIG,this->height()-EXIT_FULL_SCREEN_BIG,EXIT_FULL_SCREEN_BIG,EXIT_FULL_SCREEN_BIG);
}
}
void NetWorkCameraChannel1::NetCameraShow(QImage Img)
{
static int cnt = 0;
cnt++;
if(cnt < m_DisplayInterval)
{
return;
}
cnt = 0;
// ui->DisplayLabel->setPixmap(QPixmap::fromImage(Img));
// ui->DisplayLabel->setPixmap(QPixmap::fromImage(Img).scaled(ui->DisplayLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); // 保持比例 & 平滑缩放(无锯齿)
ui->DisplayLabel->setPixmap(QPixmap::fromImage(Img).scaled(ui->DisplayLabel->size(), Qt::KeepAspectRatio)); // 保持比例
if(m_Shoting){
m_DataDictionary->SetMisData(MIS_SHOT_NET_CAM1_RES,Img);
m_Shoting = false;
}
}
void NetWorkCameraChannel1::PlayerStatus(int Sta)
{
qDebug() << __FUNCTION__ << Sta;
switch(Sta)
{
case RTSP_Player::FFmpegInitFail:
BuildUrl();
if(!m_DisconnectTimer->isActive())
m_DisconnectTimer->start();
m_DataDictionary->SetMisData(MIS_CAMERA_STA1,CAMERA_OFFLINE);
break;
case RTSP_Player::FFmpegInitSucc:
qDebug() << __FUNCTION__ << Sta;
m_DisconnectTimer->stop();
m_DataDictionary->SetMisData(MIS_CAMERA_STA1,CAMERA_ONLINE);
break;
case RTSP_Player::FFmpegStoped:
BuildUrl();
//m_RtspPlayer->PlayerStart();
//m_playThread->start();
m_DisconnectTimer->stop();
m_DataDictionary->SetMisData(MIS_CAMERA_STA1,CAMERA_OFFLINE);
break;
}
}
void NetWorkCameraChannel1::PicLabelRepaint()
{
ui->DisplayLabel->repaint();
}
void NetWorkCameraChannel1::SystemDataChangeProcess(SystemDataIndex_t Index)
{
switch(Index)
{
case SYS_CAMERA_PASSWORD1:
case SYS_CAMERA_USERNAME1:
case SYS_CAMERA_IP1:
case SYS_CAMERA_PORT1:
case SYS_CAMERA_PATH:
case SYS_CAMERA_URL1:
m_RtspPlayer->PlayerStop();
break;
default:
break;
}
}
void NetWorkCameraChannel1::MisDataChange(MisDataIndex_t Index)
{
switch (Index) {
case MIS_DISPLAY_INTERVAL1:
m_DisplayInterval = m_DataDictionary->GetMisData(MIS_DISPLAY_INTERVAL1).toInt();
break;
case MIS_SHOT_NET_CAM1:
if(m_DataDictionary->GetMisData(MIS_CAMERA_STA1).toUInt() == CAMERA_OFFLINE){
m_DataDictionary->SetMisData(MIS_SHOT_NET_CAM1_RES,QImage());
}else {
m_Shoting = true;
}
break;
default:
break;
}
}
void NetWorkCameraChannel1::DisconnectDisplay()
{
ui->DisplayLabel->clear();
ui->DisplayLabel->setText("摄像头连接失败,请检测网络或登录信息\n重连中… …");
m_DisconnectTimer->stop();
}
void NetWorkCameraChannel1::Show(QWidget *parent,int ax, int ay)
{
this->setParent(parent);
this->move(ax,ay);
this->show();
ui->DisplayLabel->resize(parent->size());
m_Player->start();
}
void NetWorkCameraChannel1::ShowCentre()
{
// ui->CentreA->show();
// ui->CentreB->show();
}
void NetWorkCameraChannel1::HideCentre()
{
// ui->CentreA->hide();
// ui->CentreB->hide();
}
void NetWorkCameraChannel1::on_pushButton_clicked()
{
if(this->width()<700)
{
emit swapScreensButtonClicked();
return;
}
int wi=this->width();
int he=this->height();
m_viewList->setGeometry(wi-160,55,140,220);
m_viewList->show();
}
void NetWorkCameraChannel1:: paintEvent(QPaintEvent *event)
{
QPainterPath PainterPath; //绘制一个QPainter路径对象
PainterPath.addRoundedRect(this->rect(), 5.4, 5.4); //对它设置路径为四周圆角。10即圆角的深度,可以修改
QRegion mask = QRegion(PainterPath.toFillPolygon().toPolygon()); //创建遮罩对象,内容即该QPainter路径
this->setMask(mask);
}
void NetWorkCameraChannel1::on_pushButton_2_clicked()
{
emit fullScreenButtonClicked();
//ui->pushButton_2->hide();
//ui->m_pBtnExitFullScreen->show();
}
void NetWorkCameraChannel1::on_m_pBtnExitFullScreen_clicked()
{
emit exitFullScreenClicked();
//ui->m_pBtnExitFullScreen->hide();
//ui->pushButton_2->show();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。