Files
CodeRepository/Samples/Sample.Vlc/mainwindow.cpp
chenzhen 222dda1e43 1,新增“App_ThermalImageSystem”;
2,新增“Apps”;
3,新增“Common”;
4,新增“FileList”;
5,新增“MediaX”;
6,新增“OpenSource”;
7,新增“Samples”;
8,新增“SoftwareBusinessLines”.
2026-02-14 23:03:23 +08:00

134 lines
3.4 KiB
C++

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "commonhelper.h"
#include "frameless_helper.h"
#include <QDebug>
#include <QImage>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_nImageWidth = 1920;
m_nImageHeight = 1080;
InitStyle();
m_pVlcModule = new GdVlcModule;
GdVlcModule::Init(0, NULL);
}
MainWindow::~MainWindow()
{
if (m_pVlcModule)
{
if (m_pVlcModule->IsPlay())
{
m_pVlcModule->StopVideoPlay();
}
delete m_pVlcModule;
m_pVlcModule = NULL;
}
GdVlcModule::UnInit();
delete ui;
}
void MainWindow::InitStyle()
{
//安装事件监听器,让标题栏识别鼠标双击
/*
this->setWindowFlags(/*Qt::FramelessWindowHint |*
Qt::WindowTitleHint |
Qt::WindowSystemMenuHint);
*/
FramelessHelper *pHelper = new FramelessHelper(this);
pHelper->activateOn(this); //激活当前窗体
CommonHelper::SetStyle("blue");//"blue"//"dark"
}
void MainWindow::on_pushButton_clicked()
{
QString strUrl = ui->lineEdit->text();
if (strUrl.isEmpty())
{
return;
}
QByteArray varByteArr = strUrl.toUtf8();
char* cUrl = varByteArr.data();
QString strText = ui->pushButton->text();
if ("开始预览" == strText)
{
VIDEO_PLAY_PARAM stParam;
stParam.pUserData = this;
#ifdef USE_WINDOW_HAND
stParam.ePlayMode = VideoPlayModeWindow;
stParam.pWindowHand = (void*)ui->widget->winId();
stParam.pVideoCallback = NULL;
#else
stParam.ePlayMode = VideoPlayModeCallbackData;
stParam.pWindowHand = NULL;
stParam.pVideoCallback = &MainWindow::VideoDataCallback;
//创建openglview
m_pVideoOpenGLView = new OpenGLView;
m_pVideoOpenGLView->Init(m_nImageWidth, m_nImageHeight);
QVBoxLayout* layoutVL = new QVBoxLayout(ui->widget);
layoutVL->addWidget(m_pVideoOpenGLView);
layoutVL->setMargin(0);
layoutVL->setSpacing(0);
#endif
if (VLCMODULE_FAILED(m_pVlcModule->StartVideoPlay(cUrl, stParam)))
{
CommonHelper::ShowMessageBoxError("预览失败,请检查网络连接", this);
return;
}
ui->pushButton->setText("停止预览");
}
else if ("停止预览" == strText)
{
if (m_pVlcModule->IsPlay())
{
m_pVlcModule->StopVideoPlay();
}
ui->pushButton->setText("开始预览");
}
}
void MainWindow::VideoDataCallback(unsigned char* pFrame, long lFrameWidth, long lFrameHeight, long lFrameSize, VideoDataFormat eType, void* pUser)
{
MainWindow* pMain = (MainWindow*)pUser;
if (pMain)
{
pMain->ProcessVideoDataCallback(pFrame, lFrameWidth, lFrameHeight, lFrameSize, eType);
}
}
void MainWindow::ProcessVideoDataCallback(unsigned char* pFrame, long lFrameWidth, long lFrameHeight, long lFrameSize, VideoDataFormat eType)
{
if (lFrameWidth != m_nImageWidth || lFrameHeight != m_nImageHeight)
{
m_nImageWidth = lFrameWidth;
m_nImageHeight = lFrameHeight;
m_pVideoOpenGLView->Init(m_nImageWidth, m_nImageHeight);
}
QImage::Format imgFmt = QImage::Format_RGBA8888;
QImage varImage = QImage(pFrame, lFrameWidth, lFrameHeight, imgFmt);
m_pVideoOpenGLView->UpdateImageData(varImage.bits());
}