global_timestamp_reader.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include "sensor.h"
7 #include "error-handling.h"
8 #include <deque>
9 
10 namespace librealsense
11 {
13  {
14  public:
16  // TODO: expose this outwards
17  const char* get_description() const override { return "Enable/Disable global timestamp"; }
18  };
19 
20  class CSample
21  {
22  public:
23  CSample(double x, double y) :
24  _x(x), _y(y) {};
25  CSample& operator-=(const CSample& other);
26  CSample& operator+=(const CSample& other);
27 
28  public:
29  double _x;
30  double _y;
31  };
32 
34  {
35  public:
36  CLinearCoefficients(unsigned int buffer_size);
37  void reset();
38  void add_value(CSample val);
39  void add_const_y_coefs(double dy);
40  bool update_samples_base(double x);
41  void update_last_sample_time(double x);
42  double calc_value(double x) const;
43  bool is_full() const;
44 
45  private:
46  void calc_linear_coefs();
47  void get_a_b(double x, double& a, double& b) const;
48 
49  private:
50  unsigned int _buffer_size;
51  std::deque<CSample> _last_values;
53  double _prev_a, _prev_b; //Linear regression coeffitions - previously used values.
54  double _dest_a, _dest_b; //Linear regression coeffitions - recently calculated.
55  double _prev_time, _time_span_ms;
57  };
58 
60 
62  {
63  public:
64  explicit time_diff_keeper(global_time_interface* dev, const unsigned int sampling_interval_ms);
65  void start(); // must be called AFTER ALL initializations of _hw_monitor.
66  void stop();
68  double get_system_hw_time(double crnt_hw_time, bool& is_ready);
69 
70  private:
71  bool update_diff_time();
72  void polling(dispatcher::cancellable_timer cancellable_timer);
73 
74  private:
76  unsigned int _poll_intervals_ms;
79  mutable std::recursive_mutex _read_mtx; // Watch only 1 reader at a time.
80  mutable std::recursive_mutex _enable_mtx; // Watch only 1 start/stop operation at a time.
83  bool _is_ready;
84  };
85 
87  {
88  public:
89  global_timestamp_reader(std::unique_ptr<frame_timestamp_reader> device_timestamp_reader,
90  std::shared_ptr<time_diff_keeper> timediff,
91  std::shared_ptr<global_time_option>);
92 
93  rs2_time_t get_frame_timestamp(const std::shared_ptr<frame_interface>& frame) override;
94  unsigned long long get_frame_counter(const std::shared_ptr<frame_interface>& frame) const override;
95  rs2_timestamp_domain get_frame_timestamp_domain(const std::shared_ptr<frame_interface>& frame) const override;
96  void reset() override;
97 
98  private:
99  std::unique_ptr<frame_timestamp_reader> _device_timestamp_reader;
100  std::weak_ptr<time_diff_keeper> _time_diff_keeper;
101  mutable std::recursive_mutex _mtx;
102  std::shared_ptr<global_time_option> _option_is_enabled;
104  };
105 
106  class global_time_interface : public recordable<global_time_interface>
107  {
108  protected:
109  std::shared_ptr<time_diff_keeper> _tf_keeper;
110 
111  public:
113  ~global_time_interface() { _tf_keeper.reset(); }
114  void enable_time_diff_keeper(bool is_enable);
115  virtual double get_device_time_ms() = 0; // Returns time in miliseconds.
116  virtual void create_snapshot(std::shared_ptr<global_time_interface>& snapshot) const override {}
117  virtual void enable_recording(std::function<void(const global_time_interface&)> record_action) override {}
118  };
120 
121 }
virtual void create_snapshot(std::shared_ptr< global_time_interface > &snapshot) const override
GLboolean GLboolean GLboolean b
GLint y
GLboolean reset
const char * get_description() const override
std::shared_ptr< global_time_option > _option_is_enabled
#define LRS_EXTENSION_API
Definition: src/types.h:20
virtual void enable_recording(std::function< void(const global_time_interface &)> record_action) override
static const textual_icon stop
Definition: model-views.h:225
GLboolean GLboolean GLboolean GLboolean a
GLuint GLfloat * val
std::shared_ptr< time_diff_keeper > _tf_keeper
std::unique_ptr< frame_timestamp_reader > _device_timestamp_reader
GLdouble x
GLuint start
std::weak_ptr< time_diff_keeper > _time_diff_keeper
auto operator+=(std::string &lhs, StringRef const &sr) -> std::string &
double rs2_time_t
Definition: rs_types.h:300
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)
CSample(double x, double y)
rs2_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs_frame.h:19


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