2 Star 0 Fork 1

南风博文/QtForOpenCV4Tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
VideoRenderViewController.cpp 2.64 KB
一键复制 编辑 原始数据 按行查看 历史
DBF-DEV-103 提交于 2025-05-19 17:31 +08:00 . 1.添加二进制读取类BinaryFileWriter
#include "VideoRenderViewController.h"
void VideoRenderViewController::Start()
{
// 创建并启动后台线程
renderThread = std::make_unique<std::thread>(&VideoRenderViewController::Draw, this);
}
QString VideoRenderViewController::Init()
{
binaryFileReader = BinaryFileReader::Create();
iVideoRenderView = IVideoRenderView::Create(IVideoRenderView::SDL);
if (mWidth <= 0 || mHeight <= 0 || win_id == NULL)
{
qDebug() << "请设要播放文件的宽高";
QString errorMsg = "请设要播放文件的宽高";
return errorMsg;
}
binaryFileReader->filename = mFilePath.toStdString();
binaryFileReader->width = mWidth;
binaryFileReader->height = mHeight;
binaryFileReader->Init();
IVideoRenderView::PixFormat mFormat = IVideoRenderView::PixFormat::RGBA;
switch (mPixFormat) {
case 0:
mFormat = IVideoRenderView::PixFormat::RGBA;
data = new char[mWidth * mHeight * 4];
linesize = mWidth * mHeight * 4;
break;
case 1:
mFormat = IVideoRenderView::PixFormat::ARGB;
data = new char[mWidth * mHeight * 4];
linesize = mWidth * mHeight * 4;
break;
case 2:
mFormat = IVideoRenderView::PixFormat::RGB24;
data = new char[mWidth * mHeight * 3];
linesize = mWidth * mHeight * 3;
break;
case 3:
mFormat = IVideoRenderView::PixFormat::YUV420P;
data = new char[mWidth * mHeight * 1.5];
linesize = mWidth * mHeight * 1.5;
break;
}
iVideoRenderView->Init(mWidth, mHeight, mFormat, win_id);
return NULL;
}
/// <summary>
/// 线程函数,执行了线程
/// </summary>
void VideoRenderViewController::Draw()
{
for (;;)
{
if (!isRunning)break;
bool ret = binaryFileReader->Read(data, linesize);
if (!ret) {
break;
}
iVideoRenderView->Draw(data);
int secondMs = (int)(1000 / fps);
//std::this_thread::sleep_for(33ms);
std::this_thread::sleep_for(std::chrono::milliseconds(secondMs));
}
/*if (data) {
delete data;
}*/
qDebug() << "已释放了data内存";
}
void VideoRenderViewController::Close()
{
if (!mFilePath.isEmpty()) {
isRunning = false;
// 等待线程结束
if (renderThread && renderThread->joinable()) {
renderThread->join();
}
if (iVideoRenderView) {
iVideoRenderView->Close();
iVideoRenderView = NULL;
}
binaryFileReader ->Close();
//iVideoRenderView = NULL;
isRunning = true;
//renderThread = nullptr;
//linesize = 0;
//mWidth = 0;
//mHeight = 0;
//fps = 25;//fps默认25帧每秒
//mPixFormat = IVideoRenderView::PixFormat::RGBA;
//win_id = NULL;
//mFilePath = nullptr;
if (data) {
delete data;
data = NULL;
}
}
}
void VideoRenderViewController::Resize(int width, int height)
{
if (iVideoRenderView) {
iVideoRenderView->Scale(width, height);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ywtony/qt-for-open-cv4-tool.git
git@gitee.com:ywtony/qt-for-open-cv4-tool.git
ywtony
qt-for-open-cv4-tool
QtForOpenCV4Tool
master

搜索帮助