-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoFrame.ixx
More file actions
72 lines (56 loc) · 1.4 KB
/
VideoFrame.ixx
File metadata and controls
72 lines (56 loc) · 1.4 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
module;
#include <queue>
#include <mutex>
#include <condition_variable>
export module VideoFrame;
template <typename T>
class TSQueue {
private:
// Underlying queue
std::queue<T> m_queue;
// mutex for thread synchronization
std::mutex m_mutex;
// Condition variable for signaling
std::condition_variable m_cond;
public:
// Pushes an element to the queue
void push(T item)
{
// Acquire lock
std::unique_lock<std::mutex> lock(m_mutex);
// Add item
m_queue.push(item);
// Notify one thread that
// is waiting
m_cond.notify_one();
}
// Pops an element off the queue
T pop()
{
// acquire lock
std::unique_lock<std::mutex> lock(m_mutex);
// wait until queue is not empty
m_cond.wait(lock,
[this]() { return !m_queue.empty(); });
// retrieve item
T item = m_queue.front();
m_queue.pop();
// return item
return item;
}
};
export namespace VideoFrame {
struct Frame {
int strideY;
int strideU;
int strideV;
std::vector<uint8_t> dataY;
std::vector<uint8_t> dataU;
std::vector<uint8_t> dataV;
};
struct EncodedFrame {
std::vector<uint8_t> data;
};
using VideoFramesQueue = TSQueue<Frame>;
using EncodedVideoFramesQueue = TSQueue<EncodedFrame>;
}