-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFFFrameQueue.cpp
99 lines (88 loc) · 1.67 KB
/
FFFrameQueue.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
#include "FFFrameQueue.h"
AVFrame* ffmpeg::FrameQueue::alloc()
{
std::lock_guard<std::mutex> lk(mutex);
// only alloc when received because it can be discarded
if(received)
{
queue.push_back(newFramePtr());
received = false;
}
if (maxSize > 0)
{
while (queue.size() > maxSize)
queue.pop_front();
}
assert(!queue.empty());
return queue.back().get();
}
void ffmpeg::FrameQueue::receive(AVFrame* frame, MetaData* metaData)
{
assert(!received);
assert(!frame || frame == queue.back().get());
if(frame)
received = true;
}
void ffmpeg::FrameQueue::end()
{
}
void ffmpeg::FrameQueue::clear()
{
std::lock_guard<std::mutex> lk(mutex);
queue.clear();
received = true;
}
bool ffmpeg::FrameQueue::prepare()
{
return true;
}
void ffmpeg::FrameQueue::setMaxSize(int size)
{
maxSize = size;
}
bool ffmpeg::FrameQueue::empty() const
{
if (queue.size() == 1 && !received)
return true;
return queue.empty();
}
size_t ffmpeg::FrameQueue::size() const
{
if (queue.size() == 1 && !received)
return 0;
return queue.size();
}
ffmpeg::frame_ptr ffmpeg::FrameQueue::pop()
{
std::lock_guard<std::mutex> lk(mutex);
if (queue.empty())
return nullptr;
// not ready to use
if (queue.size() == 1 && !received)
return nullptr;
auto f = std::move(queue.front());
queue.pop_front();
return f;
}
ffmpeg::AudioFrameQueue* ffmpeg::AudioFrameQueue::create()
{
auto ret = new (std::nothrow) AudioFrameQueue();
if (ret)
{
ret->autorelease();
return ret;
}
delete ret;
return nullptr;
}
ffmpeg::VideoFrameQueue* ffmpeg::VideoFrameQueue::create()
{
auto ret = new (std::nothrow) VideoFrameQueue();
if (ret)
{
ret->autorelease();
return ret;
}
delete ret;
return nullptr;
}