-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXVideoThread.cpp
More file actions
139 lines (116 loc) · 2.55 KB
/
XVideoThread.cpp
File metadata and controls
139 lines (116 loc) · 2.55 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "XVideoThread.h"
#include "XDecode.h"
#include <iostream>
using namespace std;
XVideoThread::XVideoThread()
{
}
XVideoThread::~XVideoThread()
{
}
bool XVideoThread::Open(AVCodecParameters *para, IVideoCall *call, int width, int height)
{
if(!para)
return false;
Clear();
vmux.lock();
synpts = 0;
// 初始化显示窗口
this->call = call;
if(call)
{
call->Init(width, height);
}
vmux.unlock();
bool ret = true;
if(!decode->Open(para))
{
cout << "audio XDecode open failed !" << endl;
ret = false;
}
cout << "XAudioThread::Open = " << ret << endl;
return ret;
}
void XVideoThread::run()
{
while(!isExit)
{
vmux.lock();
if(this->isPause)
{
vmux.unlock();
msleep(5);
continue;
}
// 音视频同步
if(synpts > 0 && synpts < decode->pts)
{
vmux.unlock();
msleep(1);
continue;
}
// // 没有数据
// if(packs.empty() || !decode)
// {
// vmux.unlock();
// msleep(1);
// continue;
// }
// AVPacket *pkt = packs.front();
// packs.pop_front();
AVPacket *pkt = Pop();
bool ret = decode->Send(pkt);
if(!ret)
{
vmux.unlock();
msleep(1);
continue;
}
// 一次send 多次recv
while(!isExit)
{
AVFrame *frame = decode->Recv();
if(!frame)
break;
// 显示视频
if(call)
{
call->Repaint(frame);
}
}
vmux.unlock();
}
}
bool XVideoThread::RepaintPts(AVPacket *pkt, long long seekpts)
{
vmux.lock();
bool ret = decode->Send(pkt);
if(!ret)
{
vmux.unlock();
return true;
}
AVFrame *frame = decode->Recv();
if(!frame)
{
vmux.unlock();
return false;
}
// 到达位置
if(decode->pts >= seekpts)
{
if(call)
call->Repaint(frame);
vmux.unlock();
return true;
}
XFreeFrame(&frame);
vmux.unlock();
return false;
}
void XVideoThread::SetPause(bool isPause)
{
vmux.lock();
this->isPause = isPause;
vmux.unlock();
}