-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.cpp
50 lines (35 loc) · 1.05 KB
/
output.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
#include "output.h"
#include "frame.h"
#include <cassert>
Output::Output(int width, int height)
: m_width(width), m_height(height) {
m_currentFrame = new Frame;
m_lastFrame = new Frame;
m_nextFrame = nullptr;
m_currentFrame->data = allocate_frame_buffer<uint8_t>(width, height);
m_lastFrame->data = allocate_frame_buffer<uint8_t>(width, height);
}
void Output::send_frame(Frame* frame) {
std::unique_lock lock{m_frameLock};
m_frameCondition.wait(lock, [this]{return !m_nextFrame;});
assert(!m_nextFrame);
m_nextFrame = frame;
lock.unlock();
m_frameCondition.notify_all();
}
Frame* Output::acquire_frame() {
Frame* frame;
// Reuse the last processed frame
std::unique_lock lock{m_frameLock};
m_frameCondition.wait(lock, [this]{return m_lastFrame;});
assert(m_lastFrame);
frame = m_lastFrame;
m_lastFrame = nullptr;
lock.unlock();
m_frameCondition.notify_all();
return frame;
}
void Output::set_interlacing(bool enabled) {
m_interlaced = enabled;
}
void Output::finish() {}