Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
Loading...
Searching...
No Matches
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
13namespace rsimpl
14{
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 {
27 ++_frame_counter;
28 if (_frame_counter == _number_of_frames_to_sample || _frame_counter == 1)
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>(
34 _time_samples[1] - _time_samples[0]).count();
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
56 rs_stream key_stream;
57 std::vector<rs_stream> other_streams;
58
59 // This data will be read and written exclusively from the application thread
60 frameset frontbuffer;
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
71 timestamp_corrector ts_corrector;
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
83
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
97
98 // Frame callback thread API
99 void commit_frame(rs_stream stream);
100
101 void flush() override;
102
105
106 };
107}
108
109#endif
Definition sync.h:16
double calc_fps(std::chrono::time_point< std::chrono::system_clock > &now_time)
Definition sync.h:25
fps_calc(unsigned long long in_number_of_frames_to_sampling, int expected_fps)
Definition sync.h:18
Definition archive.h:186
Definition archive.h:16
std::chrono::high_resolution_clock::time_point capture_started
Definition archive.h:226
Definition sync.h:52
void correct_timestamp(rs_stream stream)
double get_frame_metadata(rs_stream stream, rs_frame_metadata frame_metadata) const
void on_timestamp(rs_timestamp_data data)
void commit_frame(rs_stream stream)
int get_frame_stride(rs_stream stream) const
long long get_frame_system_time(rs_stream stream) const
unsigned long long get_frame_number(rs_stream stream) const
syncronizing_archive(const std::vector< subdevice_mode_selection > &selection, rs_stream key_stream, std::atomic< uint32_t > *max_size, std::atomic< uint32_t > *event_queue_size, std::atomic< uint32_t > *events_timeout, std::chrono::high_resolution_clock::time_point capture_started=std::chrono::high_resolution_clock::now())
bool supports_frame_metadata(rs_stream stream, rs_frame_metadata frame_metadata) const
const byte * get_frame_data(rs_stream stream) const
bool poll_for_frames_safe(frameset **frames)
double get_frame_timestamp(rs_stream stream) const
int get_frame_bpp(rs_stream stream) const
Definition timestamps.h:49
Definition archive.h:13
rs_stream
Streams are different types of data provided by RealSense devices.
Definition rs.h:34
rs_frame_metadata
Types of value provided from the device with each frame.
Definition rs.h:204
Timestamp data from the motion microcontroller.
Definition rs.h:340
Definition types.h:294
const uint8_t RS_STREAM_NATIVE_COUNT
Definition types.h:27