sync.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 #ifndef LIBREALSENSE_SYNC_H
6 #define LIBREALSENSE_SYNC_H
7 
8 #include "archive.h"
9 #include <atomic>
10 #include "timestamps.h"
11 #include <chrono>
12 
13 namespace rsimpl
14 {
15  class fps_calc
16  {
17  public:
18  fps_calc(unsigned long long in_number_of_frames_to_sampling, int expected_fps)
19  : _number_of_frames_to_sample(in_number_of_frames_to_sampling),
20  _frame_counter(0),
21  _actual_fps(expected_fps)
22  {
23  _time_samples.reserve(2);
24  }
25  double calc_fps(std::chrono::time_point<std::chrono::system_clock>& now_time)
26  {
29  {
30  _time_samples.push_back(now_time);
31  if (_time_samples.size() == 2)
32  {
33  auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
35  _actual_fps = (((double)_frame_counter - 1.) / duration) * 1000.;
36  _frame_counter = 0;
37  _time_samples.clear();
38  }
39  }
40 
41  return _actual_fps;
42  }
43 
44  private:
45  double _actual_fps;
46  unsigned long long _number_of_frames_to_sample;
47  unsigned long long _frame_counter;
48  std::vector<std::chrono::time_point<std::chrono::system_clock>> _time_samples;
49  };
50 
52  {
53  private:
54  // This data will be left constant after creation, and accessed from all threads
57  std::vector<rs_stream> other_streams;
58 
59  // This data will be read and written exclusively from the application thread
61 
62  // This data will be read and written by all threads, and synchronized with a mutex
63  std::vector<frame> frames[RS_STREAM_NATIVE_COUNT];
64  std::condition_variable_any cv;
65 
66  void get_next_frames();
67  void dequeue_frame(rs_stream stream);
68  void discard_frame(rs_stream stream);
69  void cull_frames();
70 
72  public:
73  syncronizing_archive(const std::vector<subdevice_mode_selection> & selection,
74  rs_stream key_stream,
75  std::atomic<uint32_t>* max_size,
76  std::atomic<uint32_t>* event_queue_size,
77  std::atomic<uint32_t>* events_timeout,
78  std::chrono::high_resolution_clock::time_point capture_started = std::chrono::high_resolution_clock::now());
79 
80  // Application thread API
81  void wait_for_frames();
82  bool poll_for_frames();
83 
84  frameset * wait_for_frames_safe();
85  bool poll_for_frames_safe(frameset ** frames);
86 
87  double get_frame_metadata(rs_stream stream, rs_frame_metadata frame_metadata) const;
88  bool supports_frame_metadata(rs_stream stream, rs_frame_metadata frame_metadata) const;
89  const byte * get_frame_data(rs_stream stream) const;
90  double get_frame_timestamp(rs_stream stream) const;
91  unsigned long long get_frame_number(rs_stream stream) const;
92  long long get_frame_system_time(rs_stream stream) const;
93  int get_frame_stride(rs_stream stream) const;
94  int get_frame_bpp(rs_stream stream) const;
95 
96  frameset * clone_frontbuffer();
97 
98  // Frame callback thread API
99  void commit_frame(rs_stream stream);
100 
101  void flush() override;
102 
103  void correct_timestamp(rs_stream stream);
104  void on_timestamp(rs_timestamp_data data);
105 
106  };
107 }
108 
109 #endif
frame_metadata
Types of value provided from the device with each frame.
Definition: rs.hpp:160
std::vector< std::chrono::time_point< std::chrono::system_clock > > _time_samples
Definition: sync.h:48
Definition: archive.h:12
GLuint GLuint stream
Definition: glext.h:1774
std::condition_variable_any cv
Definition: sync.h:64
const uint8_t RS_STREAM_NATIVE_COUNT
Definition: types.h:27
fps_calc(unsigned long long in_number_of_frames_to_sampling, int expected_fps)
Definition: sync.h:18
GLuint GLuint GLsizei count
Definition: glext.h:111
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
Definition: glext.h:223
double _actual_fps
Definition: sync.h:45
double calc_fps(std::chrono::time_point< std::chrono::system_clock > &now_time)
Definition: sync.h:25
Timestamp data from the motion microcontroller.
Definition: rs.h:339
unsigned long long _frame_counter
Definition: sync.h:47
unsigned long long _number_of_frames_to_sample
Definition: sync.h:46
uint8_t byte
Definition: types.h:42
rs_stream
Streams are different types of data provided by RealSense devices.
Definition: rs.h:33
std::vector< rs_stream > other_streams
Definition: sync.h:57
rs_frame_metadata
Types of value provided from the device with each frame.
Definition: rs.h:203
timestamp_corrector ts_corrector
Definition: sync.h:71


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