converter.hpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2018 Intel Corporation. All Rights Reserved.
3 
4 #ifndef __RS_CONVERTER_CONVERTER_H
5 #define __RS_CONVERTER_CONVERTER_H
6 
7 #include <unordered_map>
8 #include <unordered_set>
9 #include <thread>
10 #include <string>
11 #include <sstream>
12 
13 #include "librealsense2/rs.hpp"
14 
15 
16 namespace rs2 {
17  namespace tools {
18  namespace converter {
19 
21  {
22  std::ofstream file;
23 
24  file.open(filename);
25 
26  file << "Stream: " << rs2_stream_to_string(frm.get_profile().stream_type()) << "\n";
27 
28  // Record all the available metadata attributes
29  for (size_t i = 0; i < RS2_FRAME_METADATA_COUNT; i++)
30  {
32  if (frm.supports_frame_metadata(metadata_val))
33  {
34  file << rs2_frame_metadata_to_string(metadata_val) << ": "
35  << frm.get_frame_metadata(metadata_val) << "\n";
36  }
37  }
38 
39  file.close();
40  }
41 
42  typedef unsigned long long frame_number_t;
43 
45  protected:
46  std::thread _worker;
47  std::vector<std::thread> _subWorkers;
48  std::unordered_map<int, std::unordered_set<frame_number_t>> _framesMap;
49 
50  protected:
51  bool frames_map_get_and_set(rs2_stream streamType, frame_number_t frameNumber)
52  {
53  if (_framesMap.find(streamType) == _framesMap.end()) {
54  _framesMap.emplace(streamType, std::unordered_set<frame_number_t>());
55  }
56 
57  auto & set = _framesMap[streamType];
58  bool result = (set.find(frameNumber) != set.end());
59 
60  if (!result) {
61  set.emplace(frameNumber);
62  }
63 
64  return result;
65  }
66 
67  template <typename F> void start_worker(const F& f)
68  {
69  _worker = std::thread(f);
70  }
71 
72  template <typename F> void add_sub_worker(const F& f)
73  {
74  _subWorkers.emplace_back(f);
75  }
76 
78  {
79  for_each(_subWorkers.begin(), _subWorkers.end(),
80  [] (std::thread& t) {
81  t.join();
82  });
83 
84  _subWorkers.clear();
85  }
86 
87  public:
88  virtual void convert(rs2::frame& frame) = 0;
89  virtual std::string name() const = 0;
90 
92  {
93  std::stringstream result;
94  result << name() << '\n';
95 
96  for (auto& i : _framesMap) {
97  result << '\t'
98  << i.second.size() << ' '
99  << (static_cast<rs2_stream>(i.first) != rs2_stream::RS2_STREAM_ANY ? rs2_stream_to_string(static_cast<rs2_stream>(i.first)) : "")
100  << " frame(s) processed"
101  << '\n';
102  }
103 
104  return (result.str());
105  }
106 
107  void wait()
108  {
109  _worker.join();
110  }
111  };
112 
113  }
114  }
115 }
116 
117 
118 #endif
const char * rs2_frame_metadata_to_string(rs2_frame_metadata_value metadata)
Definition: rs.cpp:1275
virtual std::string get_statistics()
Definition: converter.hpp:91
virtual void convert(rs2::frame &frame)=0
rs2_metadata_type get_frame_metadata(rs2_frame_metadata_value frame_metadata) const
Definition: rs_frame.hpp:497
stream_profile get_profile() const
Definition: rs_frame.hpp:557
bool supports_frame_metadata(rs2_frame_metadata_value frame_metadata) const
Definition: rs_frame.hpp:509
Definition: cah-model.h:10
GLsizei const GLchar *const * string
GLdouble t
GLdouble f
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
void metadata_to_txtfile(const rs2::frame &frm, const std::string &filename)
Definition: converter.hpp:20
std::vector< std::thread > _subWorkers
Definition: converter.hpp:47
const char * rs2_stream_to_string(rs2_stream stream)
Definition: rs.cpp:1262
bool frames_map_get_and_set(rs2_stream streamType, frame_number_t frameNumber)
Definition: converter.hpp:51
virtual std::string name() const =0
int i
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
unsigned long long frame_number_t
Definition: converter.hpp:42
GLuint64EXT * result
Definition: glext.h:10921
std::unordered_map< int, std::unordered_set< frame_number_t > > _framesMap
Definition: converter.hpp:48
rs2_frame_metadata_value
Per-Frame-Metadata is the set of read-only properties that might be exposed for each individual frame...
Definition: rs_frame.h:29


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:12