-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathren_thread.cpp
More file actions
120 lines (102 loc) · 1.99 KB
/
Copy pathren_thread.cpp
File metadata and controls
120 lines (102 loc) · 1.99 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
#include "ren_thread.h"
extern "C"
{
#include "libavformat/avformat.h"
};
ren_thread::ren_thread()
: m_head(NULL)
{
}
ren_thread::~ren_thread()
{
this->ClearQue();
}
AVFrame* ren_thread::Deque()
{
AVFrame* pkt = NULL;
while (true)
{
RLock();
if(m_exit_flag)
{
this->ClearQue();
RUnlock();
return NULL;
}
if(m_head)
{
pkt = m_head->m_frame;
if(m_head->m_next)
{
frame_queue* temp = m_head;
m_head = m_head->m_next;
free(temp);
}
else
{
free(m_head);
m_head = NULL;
}
RUnlock();
return pkt;
}
else
{
RUnlock();
Sleep(10);
}
}
}
int ren_thread::Run()
{
AVFrame* frame = this->Deque();
while(frame)
{
this->Render(frame);
av_frame_unref(frame);
av_frame_free(&frame);
frame = this->Deque();
}
this->DestroyRender();
return 0;
}
void ren_thread::ClearQue()
{
while (m_head)
{
frame_queue* p = m_head;
m_head = m_head->m_next;
av_frame_unref(p->m_frame);
av_frame_free(&p->m_frame);
free(p);
}
}
void ren_thread::Enque(AVFrame* frame)
{
RLock();
if(m_exit_flag)
{
RUnlock();
av_frame_unref(frame);
av_frame_free(&frame);
return;
}
if (!m_head) {
frame_queue* pp = (frame_queue*)malloc(sizeof(frame_queue));
pp->m_frame = frame;
pp->m_next = NULL;
m_head = pp;
}
else
{
frame_queue* p = m_head;
while(p->m_next) {
p = p->m_next;
}
frame_queue* pp = (frame_queue*)malloc(sizeof(frame_queue));
pp->m_frame = frame;
pp->m_next = NULL;
p->m_next = pp;
}
RUnlock();
}