-
Notifications
You must be signed in to change notification settings - Fork 0
/
videothreadutil.cpp
124 lines (116 loc) · 2.72 KB
/
videothreadutil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "videothreadutil.h"
VideoThreadUtil::VideoThreadUtil()
{
}
VideoThreadUtil::~VideoThreadUtil()
{
}
// 视频播放
void VideoThreadUtil::run()
{
while (!isExit)
{
videoLock.lock();
if(isPause)
{
videoLock.unlock();
msleep(5);
continue;
}
qDebug() << QString::fromLocal8Bit("Video sync_pts值") << sync_pts << QString::fromLocal8Bit("decodeUtil standard_pts值") << decodeUtil->standard_pts;
// 音画同步
if (sync_pts > 0 && sync_pts < decodeUtil->standard_pts)
{
videoLock.unlock();
msleep(1);
continue;
}
AVPacket* pkt = PopPacket();
bool result = decodeUtil->Send(pkt);
if (!result)
{
videoLock.unlock();
msleep(1);
continue;
}
// 有可能一次Send对应多次Receive
while (!isExit)
{
AVFrame* frame = decodeUtil->Receive();
if (!frame)
{
break;
}
// 显示视频
if (widget)
{
widget->Repaint(frame);
}
}
videoLock.unlock();
}
}
// 初始化
bool VideoThreadUtil::Open(AVCodecParameters* codec_param, VideoPlayWidget* widget, int width, int height)
{
if (!codec_param)
{
return false;
}
Clear();
videoLock.lock();
sync_pts = 0;
// 初始化显示窗口
this->widget = widget;
if (widget)
{
widget->Init(width, height);
}
videoLock.unlock();
bool result = true;
if (!decodeUtil->Open(codec_param))
{
result = false;
}
return result;
}
// 快进后刷新显示画面
bool VideoThreadUtil::RepaintSeekPts(AVPacket* pkt, long long seekPts)
{
videoLock.lock();
bool result = decodeUtil->Send(pkt);
if (!result)
{
videoLock.unlock();
return true;
}
AVFrame* frame = decodeUtil->Receive();
if (!frame)
{
videoLock.unlock();
return false;
}
if (decodeUtil->standard_pts >= seekPts)
{
qDebug() << QString::fromLocal8Bit("到达位置");
if (widget)
{
widget->Repaint(frame);
}
qDebug() << QString::fromLocal8Bit("到达位置绘画完成");
videoLock.unlock();
qDebug() << QString::fromLocal8Bit("解锁完成");
return true;
}
av_frame_free(&frame);
videoLock.unlock();
return false;
}
// 设置暂停
void VideoThreadUtil::SetPause(bool isPause)
{
qDebug() << QString::fromLocal8Bit("VideoThreadUtil::SetPause") << isPause;
videoLock.lock();
this->isPause = isPause;
videoLock.unlock();
}