-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrameWriter.cpp
42 lines (40 loc) · 1.05 KB
/
FrameWriter.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
class KinectFrameWriter
{
public:
enum DataType
{
DEPTH,
COLOR
};
std::future<std::vector<uint8_t>> compressed_stream;
std::future<void> writebacktofile;
DataType dtype;
std::vector<uint8_t> uncompressed_stream;
uint64_t timestamp;
std::mutex& iomutex;
KinectFrameWriter(DataType dtype,const void* data,size_t length, uint64_t timestamp, std::mutex& m):
dtype(dtype),
uncompressed_stream(reinterpret_cast<const uint8_t*>(data),reinterpret_cast<const uint8_t*>(data)+length),
timestamp(timestamp),
iomutex(m)
{
compressed_stream=std::async(std::launch::async,KinectFrameWriter::compress,this);
writebacktofile=std::async(std::launch::async,KinectFrameWriter::writeback,this);
}
};
class KinectFrameWriterPool
{
public:
std::mutex poolmutex;
std::forward_list<std::shared_ptr<KinectFrameWriter> > pool;
std::atomic<bool> keeprunning;
void run()
{
while(keeprunning)
{
std::lock_guard lg(poolmutex);
pool.remove_if([](std::shared_ptr<KinectFrameWriter> ptr){ ptr->writebacktofile.valid(); });
std::this_thread::yield();
}
}
};