forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.hpp
96 lines (73 loc) · 2.78 KB
/
converter.hpp
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
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2018 Intel Corporation. All Rights Reserved.
#ifndef __RS_CONVERTER_CONVERTER_H
#define __RS_CONVERTER_CONVERTER_H
#include <unordered_map>
#include <unordered_set>
#include <thread>
#include <string>
#include <sstream>
#include "librealsense2/rs.hpp"
namespace rs2 {
namespace tools {
namespace converter {
typedef unsigned long long frame_number_t;
class converter_base {
protected:
std::thread _worker;
std::vector<std::thread> _subWorkers;
std::unordered_map<int, std::unordered_set<frame_number_t>> _framesMap;
protected:
bool frames_map_get_and_set(rs2_stream streamType, frame_number_t frameNumber)
{
if (_framesMap.find(streamType) == _framesMap.end()) {
_framesMap.emplace(streamType, std::unordered_set<frame_number_t>());
}
auto & set = _framesMap[streamType];
bool result = (set.find(frameNumber) != set.end());
if (!result) {
set.emplace(frameNumber);
}
return result;
}
template <typename F> void start_worker(const F& f)
{
_worker = std::thread(f);
}
template <typename F> void add_sub_worker(const F& f)
{
_subWorkers.emplace_back(f);
}
void wait_sub_workers()
{
for_each(_subWorkers.begin(), _subWorkers.end(),
[] (std::thread& t) {
t.join();
});
_subWorkers.clear();
}
public:
virtual void convert(rs2::frameset& frameset) = 0;
virtual std::string name() const = 0;
virtual std::string get_statistics()
{
std::stringstream result;
result << name() << '\n';
for (auto& i : _framesMap) {
result << '\t'
<< i.second.size() << ' '
<< (static_cast<rs2_stream>(i.first) != rs2_stream::RS2_STREAM_ANY ? rs2_stream_to_string(static_cast<rs2_stream>(i.first)) : "")
<< " frame(s) processed"
<< '\n';
}
return (result.str());
}
void wait()
{
_worker.join();
}
};
}
}
}
#endif