代码拉取完成,页面将自动刷新
#include "vpdecodevideothread.h"
#include <QDebug>
#include "vpentrance.h"
VpDecodeVideoThread::VpDecodeVideoThread()
{
m_stop = false;
}
bool VpDecodeVideoThread::start(AVCodecContext *codec_ctx, VpPacketQueue *video_pkt_queue, VpFrameQueue *video_fme_queue)
{
m_stop = false;
bool res = true;
if(!codec_ctx)
res = false;
thread decode_video_th(work, this, codec_ctx, video_pkt_queue, video_fme_queue);
decode_video_th.detach();
return res;
}
void VpDecodeVideoThread::stop()
{
m_stop = true;
}
void VpDecodeVideoThread::work(VpDecodeVideoThread* vp_decode_video_th, AVCodecContext *codec_ctx, VpPacketQueue *video_pkt_queue, VpFrameQueue *video_fme_queue)
{
qDebug()<<"decode video thread start";
VpEntrance::s_RUNNING_THREAD_NUM += 1;
int ret = -1;
while(!vp_decode_video_th->m_stop)
{
{
unique_lock<mutex> lock(video_fme_queue->m_mutex);
while(video_fme_queue->get_size() > MAX_VIDEO_FRAME_NUM && !vp_decode_video_th->m_stop)
video_fme_queue->m_cond.wait_for(lock, chrono::milliseconds(20));
}
VpPacket pkt;
VpFrame srcframe ;
do
{
ret = avcodec_receive_frame(codec_ctx, srcframe.m_frame);
if(ret == 0)
{
srcframe.setSerial(video_fme_queue->serial());
srcframe.m_pts = (srcframe.m_frame->pts == AV_NOPTS_VALUE) ? NAN : srcframe.m_frame->pts * av_q2d(video_fme_queue->m_tb);
srcframe.m_duration = (srcframe.m_frame->duration == AV_NOPTS_VALUE) ? NAN : srcframe.m_frame->duration * av_q2d(video_fme_queue->m_tb);
video_fme_queue->push(srcframe);
}
else if(ret == AVERROR_EOF)
{
avcodec_flush_buffers(codec_ctx);
break;
}
}while(ret != AVERROR(EAGAIN));
pkt = video_pkt_queue->pop();
if(pkt.serial() != video_fme_queue->serial())
{
video_fme_queue->flush_queue();
video_fme_queue->setSerial(pkt.serial());
}
ret = avcodec_send_packet(codec_ctx, pkt.m_packet);
if(ret == AVERROR_EOF) {
avcodec_flush_buffers(codec_ctx);
}else if(ret == AVERROR(EAGAIN)){
continue;
}
if(ret < 0) {
qDebug()<<"error"<<ret;
break;
}
}
{
lock_guard<mutex> lock(vp_decode_video_th->m_mutex);
VpEntrance::s_RUNNING_THREAD_NUM -= 1;
qDebug()<<"decode video thread end";
}
return;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。