timestamps.cpp
Go to the documentation of this file.
1 #include "timestamps.h"
2 #include "sync.h"
3 #include <algorithm>
4 
5 using namespace rsimpl;
6 using namespace std;
7 
8 
9 
11 {
12  lock_guard<mutex> lock(mtx);
13 
14  data_queue.push_back(data);
15 }
16 
18 {
19  lock_guard<mutex> lock(mtx);
20 
21  if (!data_queue.size())
22  return false;
23 
24  data_queue.pop_front();
25 
26  return true;
27 }
28 
30 {
31  lock_guard<mutex> lock(mtx);
32 
33  auto it = find_if(data_queue.begin(), data_queue.end(),
34  [&](const rs_timestamp_data& element) {
35  return (data.frame_number == element.frame_number);
36  });
37 
38  if (it != data_queue.end())
39  {
40  data_queue.erase(it);
41  return true;
42  }
43 
44  return false;
45 }
46 
48 {
49  lock_guard<mutex> lock(mtx);
50 
51  return data_queue.size();
52 }
53 
55 {
56  lock_guard<mutex> lock(mtx);
57 
58  auto it = find_if(data_queue.begin(), data_queue.end(),
59  [&](const rs_timestamp_data& element) {
60  return ((frame.get_frame_number() == element.frame_number));
61  });
62 
63  if (it != data_queue.end())
64  {
65  frame.set_timestamp(it->timestamp);
66  return true;
67  }
68  return false;
69 }
70 
71 timestamp_corrector::timestamp_corrector(std::atomic<uint32_t>* queue_size, std::atomic<uint32_t>* timeout)
72  :event_queue_size(queue_size), events_timeout(timeout)
73 {
74 }
75 
77 {
78 }
79 
81 {
82  lock_guard<mutex> lock(mtx);
83 
84  if (data_queue[data.source_id].size() <= *event_queue_size)
88 
89  cv.notify_one();
90 }
91 
93 {
94  switch(stream)
95  {
96  case RS_STREAM_DEPTH:
97  case RS_STREAM_COLOR:
98  case RS_STREAM_INFRARED:
100  source_id = RS_EVENT_IMU_DEPTH_CAM;
101  break;
102  case RS_STREAM_FISHEYE:
103  source_id = RS_EVENT_IMU_MOTION_CAM;
104  break;
105  default:
106  throw std::runtime_error(to_string() << "Unsupported source stream requested " << rs_stream_to_string(stream));
107  }
108 }
109 
111 {
112  unique_lock<mutex> lock(mtx);
113 
114  bool res;
115  rs_event_source source_id;
116  update_source_id(source_id, stream);
117  if (!(res = data_queue[source_id].correct(frame)))
118  {
119  const auto ready = [&]() { return data_queue[source_id].correct(frame); };
120  res = cv.wait_for(lock, std::chrono::milliseconds(*events_timeout), ready);
121  }
122 
123  if (res)
124  {
126  }
127  lock.unlock();
128 }
std::atomic< uint32_t > * event_queue_size
Definition: timestamps.h:63
const char * rs_stream_to_string(rs_stream stream)
Definition: rs.cpp:754
rs_event_source source_id
Definition: rs.h:342
std::atomic< uint32_t > * events_timeout
Definition: timestamps.h:64
void update_source_id(rs_event_source &source_id, const rs_stream stream)
Definition: timestamps.cpp:92
std::mutex mtx
concurrent_queue data_queue[RS_EVENT_SOURCE_COUNT]
Definition: timestamps.h:61
Definition: archive.h:12
void correct_timestamp(frame_interface &frame, rs_stream stream) override
Definition: timestamps.cpp:110
GLbitfield GLuint64 timeout
Definition: glext.h:1481
GLuint GLuint stream
Definition: glext.h:1774
virtual void set_timestamp(double new_ts)=0
bool correct(frame_interface &frame)
Definition: timestamps.cpp:54
virtual void set_timestamp_domain(rs_timestamp_domain timestamp_domain)=0
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
Definition: glext.h:223
bool erase(rs_timestamp_data data)
Definition: timestamps.cpp:29
Timestamp data from the motion microcontroller.
Definition: rs.h:339
timestamp_corrector(std::atomic< uint32_t > *event_queue_size, std::atomic< uint32_t > *events_timeout)
Definition: timestamps.cpp:71
void push_back_data(rs_timestamp_data data)
Definition: timestamps.cpp:10
rs_stream
Streams are different types of data provided by RealSense devices.
Definition: rs.h:33
std::condition_variable cv
Definition: timestamps.h:62
virtual unsigned long long get_frame_number() const =0
unsigned long long frame_number
Definition: rs.h:343
GLuint res
Definition: glext.h:8310
void on_timestamp(rs_timestamp_data data) override
Definition: timestamps.cpp:80
rs_event_source
Source device that triggered a specific timestamp event from the motion module.
Definition: rs.h:276


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:17