Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
streaming.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 #pragma once
4 
5 #include "options.h"
6 #include "types.h"
7 #include "info.h"
8 #include <functional>
9 
10 namespace librealsense
11 {
12  namespace platform
13  {
14  class time_source;
15  }
16 
17  class sensor_interface;
18  class archive_interface;
19  class device_interface;
20 
22  {
23  public:
24  virtual std::shared_ptr<sensor_interface> get_sensor() const = 0;
25  virtual void set_sensor(std::shared_ptr<sensor_interface> s) = 0;
26  virtual ~sensor_part() = default;
27  };
28 
29  class context;
30 
31  class stream_interface : public std::enable_shared_from_this<stream_interface>
32  {
33  public:
34  virtual ~stream_interface() = default;
35 
36  virtual int get_stream_index() const = 0;
37  virtual void set_stream_index(int index) = 0;
38 
39  virtual int get_unique_id() const = 0;
40  virtual void set_unique_id(int uid) = 0;
41 
42  virtual rs2_stream get_stream_type() const = 0;
43  virtual void set_stream_type(rs2_stream stream) = 0;
44  };
45 
46  class stream_profile_interface : public stream_interface, public recordable<stream_profile_interface>
47  {
48  public:
49  virtual rs2_format get_format() const = 0;
50  virtual void set_format(rs2_format format) = 0;
51 
52  virtual uint32_t get_framerate() const = 0;
53  virtual void set_framerate(uint32_t val) = 0;
54 
55  virtual bool is_default() const = 0;
56  virtual void make_default() = 0;
57 
58  virtual std::shared_ptr<stream_profile_interface> clone() const = 0;
59  virtual rs2_stream_profile* get_c_wrapper() const = 0;
60  virtual void set_c_wrapper(rs2_stream_profile* wrapper) = 0;
61  };
62 
64  {
65  public:
66  virtual rs2_metadata_type get_frame_metadata(const rs2_frame_metadata_value& frame_metadata) const = 0;
67  virtual bool supports_frame_metadata(const rs2_frame_metadata_value& frame_metadata) const = 0;
68  virtual const byte* get_frame_data() const = 0;
69  //TODO: add virtual uint64_t get_frame_data_size() const = 0;
70  virtual rs2_time_t get_frame_timestamp() const = 0;
72  virtual void set_timestamp(double new_ts) = 0;
73  virtual unsigned long long get_frame_number() const = 0;
74 
75  virtual void set_timestamp_domain(rs2_timestamp_domain timestamp_domain) = 0;
76  virtual rs2_time_t get_frame_system_time() const = 0;
77 
78  virtual std::shared_ptr<stream_profile_interface> get_stream() const = 0;
79  virtual void set_stream(std::shared_ptr<stream_profile_interface> sp) = 0;
80 
82  virtual void update_frame_callback_start_ts(rs2_time_t ts) = 0;
83 
84  virtual void acquire() = 0;
85  virtual void release() = 0;
86  virtual frame_interface* publish(std::shared_ptr<archive_interface> new_owner) = 0;
87  virtual void attach_continuation(frame_continuation&& continuation) = 0;
88  virtual void disable_continuation() = 0;
89 
90  virtual void log_callback_start(rs2_time_t timestamp) = 0;
91  virtual void log_callback_end(rs2_time_t timestamp) const = 0;
92 
93  virtual archive_interface* get_owner() const = 0;
94 
95  virtual void mark_fixed() = 0;
96  virtual bool is_fixed() const = 0;
97 
98  virtual void keep() = 0;
99 
100  virtual ~frame_interface() = default;
101  };
102 
103  using on_frame = std::function<void(frame_interface*)>;
104  using stream_profiles = std::vector<std::shared_ptr<stream_profile_interface>>;
105 
106  class sensor_interface : public virtual info_interface, public virtual options_interface
107  {
108  public:
109  virtual stream_profiles get_stream_profiles() const = 0;
110  virtual stream_profiles get_active_streams() const = 0;
111  virtual void open(const stream_profiles& requests) = 0;
112  virtual void close() = 0;
114 
116  virtual int register_before_streaming_changes_callback(std::function<void(bool)> callback) = 0;
117  virtual void unregister_before_start_callback(int token) = 0;
118  virtual void start(frame_callback_ptr callback) = 0;
119  virtual void stop() = 0;
120  virtual frame_callback_ptr get_frames_callback() const = 0;
121  virtual void set_frames_callback(frame_callback_ptr cb) = 0;
122  virtual bool is_streaming() const = 0;
123 
124  virtual const device_interface& get_device() = 0;
125 
126  virtual ~sensor_interface() = default;
127  };
128 
129  class matcher;
130 
131  class device_interface : public virtual info_interface, public std::enable_shared_from_this<device_interface>
132  {
133  public:
134  virtual sensor_interface& get_sensor(size_t i) = 0;
135 
136  virtual const sensor_interface& get_sensor(size_t i) const = 0;
137 
138  virtual size_t get_sensors_count() const = 0;
139 
140  virtual void hardware_reset() = 0;
141 
142  virtual std::shared_ptr<matcher> create_matcher(const frame_holder& frame) const = 0;
143 
144  virtual std::shared_ptr<context> get_context() const = 0;
145 
147 
148  virtual std::pair<uint32_t, rs2_extrinsics> get_extrinsics(const stream_interface& stream) const = 0;
149 
150  virtual bool is_valid() const = 0;
151 
152  virtual ~device_interface() = default;
153 
154  };
155 
156  class depth_stereo_sensor;
157 
158  class depth_sensor : public recordable<depth_sensor>
159  {
160  public:
161  virtual float get_depth_scale() const = 0;
162  virtual ~depth_sensor() = default;
163  };
164 
166 
168  {
169  public:
170  depth_sensor_snapshot(float depth_units) : m_depth_units(depth_units) {}
171  float get_depth_scale() const override
172  {
173  return m_depth_units;
174  }
175 
176  void update(std::shared_ptr<extension_snapshot> ext) override
177  {
178  if (auto api = As<depth_sensor>(ext))
179  {
180  m_depth_units = api->get_depth_scale();
181  }
182  }
183  void create_snapshot(std::shared_ptr<depth_sensor>& snapshot) const override
184  {
185  snapshot = std::make_shared<depth_sensor_snapshot>(*this);
186  }
187  void enable_recording(std::function<void(const depth_sensor&)> recording_function) override
188  {
189  //empty
190  }
191 
192  protected:
194  };
195 
196  class depth_stereo_sensor : public virtual depth_sensor, public recordable<depth_stereo_sensor>
197  {
198  public:
199  virtual float get_stereo_baseline_mm() const = 0;
200  };
201 
203 
205  {
206  public:
207  depth_stereo_sensor_snapshot(float depth_units, float stereo_bl_mm) :
208  depth_sensor_snapshot(depth_units),
209  m_stereo_baseline_mm(stereo_bl_mm) {}
210 
212  {
213  return m_stereo_baseline_mm;
214  }
215 
216  void update(std::shared_ptr<extension_snapshot> ext) override
217  {
219 
220  if (auto api = As<depth_stereo_sensor>(ext))
221  {
222  m_stereo_baseline_mm = api->get_stereo_baseline_mm();
223  }
224  }
225 
226  void create_snapshot(std::shared_ptr<depth_stereo_sensor>& snapshot) const override
227  {
228  snapshot = std::make_shared<depth_stereo_sensor_snapshot>(*this);
229  }
230 
231  void enable_recording(std::function<void(const depth_stereo_sensor&)> recording_function) override
232  {
233  //empty
234  }
235 
236  private:
237  float m_stereo_baseline_mm;
238  };
239 }
void create_snapshot(std::shared_ptr< depth_stereo_sensor > &snapshot) const override
Definition: streaming.h:226
virtual rs2_metadata_type get_frame_metadata(const rs2_frame_metadata_value &frame_metadata) const =0
virtual rs2_format get_format() const =0
void create_snapshot(std::shared_ptr< depth_sensor > &snapshot) const override
Definition: streaming.h:183
virtual rs2_stream get_stream_type() const =0
virtual const byte * get_frame_data() const =0
virtual rs2_timestamp_domain get_frame_timestamp_domain() const =0
virtual frame_callback_ptr get_frames_callback() const =0
Definition: sync.h:78
virtual ~depth_sensor()=default
virtual size_t get_sensors_count() const =0
void enable_recording(std::function< void(const depth_sensor &)> recording_function) override
Definition: streaming.h:187
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: streaming.h:176
unsigned char byte
Definition: types.h:33
Definition: streaming.h:63
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
Definition: types.h:822
virtual void register_notifications_callback(notifications_callback_ptr callback)=0
virtual std::pair< uint32_t, rs2_extrinsics > get_extrinsics(const stream_interface &stream) const =0
virtual void start(frame_callback_ptr callback)=0
Definition: context.h:109
std::function< void(frame_interface *)> on_frame
Definition: streaming.h:103
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: streaming.h:216
virtual void update_frame_callback_start_ts(rs2_time_t ts)=0
virtual void hardware_reset()=0
virtual rs2_stream_profile * get_c_wrapper() const =0
virtual bool is_fixed() const =0
Definition: rs_types.h:102
virtual void log_callback_end(rs2_time_t timestamp) const =0
virtual ~sensor_interface()=default
Definition: streaming.h:131
virtual void unregister_before_start_callback(int token)=0
depth_sensor_snapshot(float depth_units)
Definition: streaming.h:170
depth_stereo_sensor_snapshot(float depth_units, float stereo_bl_mm)
Definition: streaming.h:207
virtual bool is_streaming() const =0
virtual float get_depth_scale() const =0
virtual std::shared_ptr< stream_profile_interface > clone() const =0
Definition: archive.h:63
Definition: algo.h:16
Definition: streaming.h:31
Definition: streaming.h:21
virtual ~frame_interface()=default
virtual void set_stream_type(rs2_stream stream)=0
virtual std::shared_ptr< context > get_context() const =0
float get_stereo_baseline_mm() const
Definition: streaming.h:211
virtual bool is_valid() const =0
Definition: rs_types.h:112
virtual rs2_time_t get_frame_callback_start_time_point() const =0
Definition: streaming.h:46
virtual sensor_interface & get_sensor(size_t i)=0
virtual archive_interface * get_owner() const =0
std::shared_ptr< rs2_notifications_callback > notifications_callback_ptr
Definition: types.h:824
virtual stream_profiles get_stream_profiles() const =0
virtual void open(const stream_profiles &requests)=0
virtual void set_timestamp(double new_ts)=0
virtual void set_framerate(uint32_t val)=0
virtual float get_stereo_baseline_mm() const =0
Definition: options.h:36
rs2_format
Format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:52
void enable_recording(std::function< void(const depth_stereo_sensor &)> recording_function) override
Definition: streaming.h:231
float get_depth_scale() const override
Definition: streaming.h:171
virtual frame_interface * publish(std::shared_ptr< archive_interface > new_owner)=0
virtual rs2_time_t get_frame_timestamp() const =0
virtual void set_sensor(std::shared_ptr< sensor_interface > s)=0
virtual void set_frames_callback(frame_callback_ptr cb)=0
virtual void set_stream_index(int index)=0
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:36
Definition: context.h:35
virtual std::shared_ptr< sensor_interface > get_sensor() const =0
virtual void disable_continuation()=0
Definition: info.h:11
Definition: streaming.h:167
virtual std::shared_ptr< stream_profile_interface > get_stream() const =0
virtual ~device_interface()=default
virtual void log_callback_start(rs2_time_t timestamp)=0
virtual rs2_time_t get_frame_system_time() const =0
Definition: types.h:1190
virtual void set_c_wrapper(rs2_stream_profile *wrapper)=0
long long rs2_metadata_type
Definition: rs_types.h:180
Definition: stream.h:14
Definition: types.h:587
virtual int get_stream_index() const =0
virtual platform::backend_device_group get_device_data() const =0
std::vector< std::shared_ptr< stream_profile_interface > > stream_profiles
Definition: streaming.h:104
virtual const device_interface & get_device()=0
Definition: streaming.h:106
virtual ~sensor_part()=default
Definition: extension.h:46
virtual void set_unique_id(int uid)=0
virtual uint32_t get_framerate() const =0
Definition: archive.h:462
virtual void set_timestamp_domain(rs2_timestamp_domain timestamp_domain)=0
virtual notifications_callback_ptr get_notifications_callback() const =0
virtual ~stream_interface()=default
Definition: streaming.h:158
Definition: extension.h:33
float m_depth_units
Definition: streaming.h:193
virtual stream_profiles get_active_streams() const =0
virtual void set_format(rs2_format format)=0
double rs2_time_t
Definition: rs_types.h:179
virtual std::shared_ptr< matcher > create_matcher(const frame_holder &frame) const =0
virtual void attach_continuation(frame_continuation &&continuation)=0
virtual int get_unique_id() const =0
virtual unsigned long long get_frame_number() const =0
rs2_frame_metadata_value
Per-Frame-Metadata are set of read-only properties that might be exposed for each individual frame...
Definition: rs_frame.h:28
virtual int register_before_streaming_changes_callback(std::function< void(bool)> callback)=0
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)
Definition: streaming.h:196
virtual bool supports_frame_metadata(const rs2_frame_metadata_value &frame_metadata) const =0
virtual void set_stream(std::shared_ptr< stream_profile_interface > sp)=0
virtual bool is_default() const =0
rs2_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs_frame.h:19