代码拉取完成,页面将自动刷新
#include "XVideoThread.h"
XVideoThread::XVideoThread()
{
}
XVideoThread::~XVideoThread()
{
}
bool XVideoThread::Open(AVCodecParameters *_pParam,IVideoWidget *_piVideoWidget,int _iWidth,int _iHeight)
{
if(_pParam == nullptr)
{
qDebug()<<"_pParam == nullptr";
return false;
}
if(_piVideoWidget == nullptr)
{
qDebug()<<"_piVideoWidget == nullptr";
return false;
}
if(m_pxDecode == nullptr)
{
qDebug()<<"m_pxDecode == nullptr";
return false;
}
Clear();
qi64Synpts = 0;
m_qmtxVideoThread.lock();
m_piVideoWidget = _piVideoWidget;
m_piVideoWidget->Init(_iWidth, _iHeight);
m_qmtxVideoThread.unlock();
int iResult = m_pxDecode->Open(_pParam);
if(!iResult)
{
qDebug()<<"Video XDecode open failed";
return false;
}
qDebug()<<"Video XDecode open success";
return true;
}
void XVideoThread::run()
{
while(!m_blIsExit)
{
m_qmtxVideoThread.lock();
//音视频同步
//qDebug()<<"111111==yxl== qi64Synpts = "<<qi64Synpts<<" m_pxDecode->qi64Pts=="<<m_pxDecode->qi64Pts;
if(qi64Synpts > 0 && qi64Synpts < m_pxDecode->qi64Pts)
{
//qDebug()<<"2222222==yxl== qi64Synpts = "<<qi64Synpts<<" m_pxDecode->qi64Pts=="<<m_pxDecode->qi64Pts;
m_qmtxVideoThread.unlock();
QThread::msleep(1);
continue;
}
//获取一帧数据
AVPacket *avPacket = Pop();
if(avPacket == nullptr)
{
m_qmtxVideoThread.unlock();
//qDebug()<<"XVideoThread avPacket == nullptr";
continue;
}
bool blResult = m_pxDecode->Send(avPacket);
if(!blResult)
{
qDebug()<<"m_pxDecode->Send error";
m_qmtxVideoThread.unlock();
QThread::msleep(1);
continue;
}
//一次send,多次recv
while(!m_blIsExit)
{
AVFrame *avFrame = m_pxDecode->Recv();
if(avFrame == nullptr)
{
//qDebug()<<"avFrame == nullptr";
break;
}
//显示视频
if(m_piVideoWidget)
{
m_piVideoWidget->Repaint(avFrame);
}
}
//40毫秒25帧每秒
QThread::msleep(40);
m_qmtxVideoThread.unlock();
}
return;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。