-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXVideoThread.cpp
More file actions
127 lines (112 loc) · 2.06 KB
/
XVideoThread.cpp
File metadata and controls
127 lines (112 loc) · 2.06 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
#include "XVideoThread.h"
#include "XDecode.h"
#include <iostream>
using namespace std;
//打开,成功与否都要清理资源
bool XVideoThread::Open(AVCodecParameters* para, IVideoCall* call, int width, int herght)
{
if (!para) return false;
Clear();
vmux.lock();
synpts = 0;
//初始化显示窗口
this->call = call;
if (call) {
call->Init(width,herght);
}
vmux.unlock();
int re = true;
if (!decode->Open(para)) {
cout << "audio XDecode open failed !" << endl;
re = false;
}
cout << "XAudioThread open :" << re << endl;
return re;
}
void XVideoThread::SetPause(bool isPause)
{
vmux.lock();
this->isPause = isPause;
vmux.unlock();
}
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;
}
AVPacket *pkt = Pop();
/*if (!pkt) {
vmux.unlock();
continue;
}*/
////如果没有数据
//if (packs.empty() || !decode) {
// vmux.unlock();
// msleep(1);
// continue;
//}
//AVPacket* pkt = packs.front();
//packs.pop_front();
bool re = decode->Send(pkt);
if (!re) {
vmux.unlock();
msleep(1);
continue;
}
//一次send,多次recv
while (!isExit)
{
AVFrame* frame = decode->Recv();
if (!frame) break;
//显示视频
if (call) {
//刷新画面
call->Repaint(frame);
}
}
vmux.unlock();
}
};
//解码pts,如果接收到的解码数据 pts >= seekpts return true,并且显示画面
bool XVideoThread::RepaintPts(AVPacket* pkt, long long seekpts)
{
vmux.lock();
bool re = decode->Send(pkt);
if (!re) {//表示结束解码
vmux.unlock();
return false;
}
AVFrame* frame = decode->Recv();
if (!frame) {//false继续下一次处理
vmux.unlock();
return false;
}
//到达位置
if (decode->pts >= seekpts) {
if (call) {
call->Repaint(frame);
vmux.unlock();
return true;//到了最后一帧
}
}
XFreeFrame(&frame);
vmux.unlock();
return false;
}
XVideoThread::XVideoThread()
{
};
XVideoThread::~XVideoThread()
{
};