#include "mainwindow.h" #include "ui_mainwindow.h" #include "commonhelper.h" #include "frameless_helper.h" #include #include 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()); }