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  class processing_block_interface;
21 
23  {
24  public:
25  virtual std::shared_ptr<sensor_interface> get_sensor() const = 0;
26  virtual void set_sensor(std::shared_ptr<sensor_interface> s) = 0;
27  virtual ~sensor_part() = default;
28  };
29 
30  class context;
31 
32  typedef enum profile_tag
33  {
34  PROFILE_TAG_SUPERSET = 1, // to be included in enable_all
35  PROFILE_TAG_DEFAULT = 2, // to be included in default pipeline start
36  PROFILE_TAG_ANY = 4, // does not include PROFILE_TAG_DEBUG
37  PROFILE_TAG_DEBUG = 8, // tag for debug formats
38  } profile_tag;
39 
41  {
44  int width, height;
46  int fps;
47  int tag;
48  };
49 
50  class stream_interface : public std::enable_shared_from_this<stream_interface>
51  {
52  public:
53  virtual ~stream_interface() = default;
54 
55  virtual int get_stream_index() const = 0;
56  virtual void set_stream_index(int index) = 0;
57 
58  virtual int get_unique_id() const = 0;
59  virtual void set_unique_id(int uid) = 0;
60 
61  virtual rs2_stream get_stream_type() const = 0;
62  virtual void set_stream_type(rs2_stream stream) = 0;
63  };
64 
65  class stream_profile_interface : public stream_interface, public recordable<stream_profile_interface>
66  {
67  public:
68  virtual rs2_format get_format() const = 0;
69  virtual void set_format(rs2_format format) = 0;
70 
71  virtual uint32_t get_framerate() const = 0;
72  virtual void set_framerate(uint32_t val) = 0;
73 
74  virtual int get_tag() const = 0;
75  virtual void tag_profile(int tag) = 0;
76 
77  virtual std::shared_ptr<stream_profile_interface> clone() const = 0;
78  virtual rs2_stream_profile* get_c_wrapper() const = 0;
79  virtual void set_c_wrapper(rs2_stream_profile* wrapper) = 0;
80  };
81 
83  {
84  public:
85  virtual rs2_metadata_type get_frame_metadata(const rs2_frame_metadata_value& frame_metadata) const = 0;
86  virtual bool supports_frame_metadata(const rs2_frame_metadata_value& frame_metadata) const = 0;
87  virtual int get_frame_data_size() const = 0;
88  virtual const byte* get_frame_data() const = 0;
89  virtual rs2_time_t get_frame_timestamp() const = 0;
90  virtual rs2_timestamp_domain get_frame_timestamp_domain() const = 0;
91  virtual void set_timestamp(double new_ts) = 0;
92  virtual unsigned long long get_frame_number() const = 0;
93 
94  virtual void set_timestamp_domain(rs2_timestamp_domain timestamp_domain) = 0;
95  virtual rs2_time_t get_frame_system_time() const = 0;
96  virtual std::shared_ptr<stream_profile_interface> get_stream() const = 0;
97  virtual void set_stream(std::shared_ptr<stream_profile_interface> sp) = 0;
98 
99  virtual rs2_time_t get_frame_callback_start_time_point() const = 0;
100  virtual void update_frame_callback_start_ts(rs2_time_t ts) = 0;
101 
102  virtual void acquire() = 0;
103  virtual void release() = 0;
104  virtual frame_interface* publish(std::shared_ptr<archive_interface> new_owner) = 0;
105  virtual void unpublish() = 0;
106  virtual void attach_continuation(frame_continuation&& continuation) = 0;
107  virtual void disable_continuation() = 0;
108 
109  virtual void log_callback_start(rs2_time_t timestamp) = 0;
110  virtual void log_callback_end(rs2_time_t timestamp) const = 0;
111 
112  virtual archive_interface* get_owner() const = 0;
113 
114  virtual void mark_fixed() = 0;
115  virtual bool is_fixed() const = 0;
116  virtual void set_blocking(bool state) = 0;
117  virtual bool is_blocking() const = 0;
118 
119  virtual void keep() = 0;
120 
121  virtual ~frame_interface() = default;
122  };
123 
125  {
127 
129  {
130  return frame;
131  }
132 
133  operator bool() const { return frame != nullptr; }
134 
135  operator frame_interface*() const { return frame; }
136 
138  {
139  frame = f;
140  }
141 
142  ~frame_holder();
143 
145  : frame(other.frame)
146  {
147  other.frame = nullptr;
148  }
149 
150  frame_holder() : frame(nullptr) {}
151 
152 
153  frame_holder& operator=(frame_holder&& other);
154 
155  frame_holder clone() const;
156 
157  bool is_blocking() const { return frame->is_blocking(); };
158 
159  private:
160  frame_holder& operator=(const frame_holder& other) = delete;
161  frame_holder(const frame_holder& other);
162  };
163 
164  using on_frame = std::function<void(frame_interface*)>;
165  using stream_profiles = std::vector<std::shared_ptr<stream_profile_interface>>;
166  using processing_blocks = std::vector<std::shared_ptr<processing_block_interface>>;
167 
168  inline std::ostream& operator << (std::ostream& os, const stream_profiles& profiles)
169  {
170  for (auto&& p : profiles)
171  {
172  os << rs2_format_to_string(p->get_format()) << " " << rs2_stream_to_string(p->get_stream_type()) << ", ";
173  }
174  return os;
175  }
176 
178 
180 
181  inline std::ostream& operator<<(std::ostream& out, const frame_interface & f)
182  {
183  return out << frame_to_string(f);
184  }
185 
187  {
188  public:
189  virtual processing_blocks get_recommended_processing_blocks() const = 0;
190  virtual ~recommended_proccesing_blocks_interface() = default;
191  };
193 
195  {
196  public:
198  :_blocks(blocks) {}
199 
201  {
202  return _blocks;
203  }
204 
205  void update(std::shared_ptr<extension_snapshot> ext) override {}
206 
208  };
209 
210 
211  class recommended_proccesing_blocks_base : public virtual recommended_proccesing_blocks_interface, public virtual recordable<recommended_proccesing_blocks_interface>
212  {
213  public:
215  :_owner(owner)
216  {}
217 
218  virtual processing_blocks get_recommended_processing_blocks() const override { return _owner->get_recommended_processing_blocks(); };
219 
220  virtual void create_snapshot(std::shared_ptr<recommended_proccesing_blocks_interface>& snapshot) const override
221  {
222  snapshot = std::make_shared<recommended_proccesing_blocks_snapshot>(get_recommended_processing_blocks());
223  }
224 
225  virtual void enable_recording(std::function<void(const recommended_proccesing_blocks_interface&)> recording_function) override {}
226 
227  private:
229  };
230 
231  class sensor_interface : public virtual info_interface, public virtual options_interface, public virtual recommended_proccesing_blocks_interface
232  {
233  public:
234  virtual stream_profiles get_stream_profiles(int tag = profile_tag::PROFILE_TAG_ANY) const = 0;
235  virtual stream_profiles get_active_streams() const = 0;
236  virtual void open(const stream_profiles& requests) = 0;
237  virtual void close() = 0;
238  virtual notifications_callback_ptr get_notifications_callback() const = 0;
239 
240  virtual void register_notifications_callback(notifications_callback_ptr callback) = 0;
241  virtual int register_before_streaming_changes_callback(std::function<void(bool)> callback) = 0;
242  virtual void unregister_before_start_callback(int token) = 0;
243  virtual void start(frame_callback_ptr callback) = 0;
244  virtual void stop() = 0;
245  virtual frame_callback_ptr get_frames_callback() const = 0;
246  virtual void set_frames_callback(frame_callback_ptr cb) = 0;
247  virtual bool is_streaming() const = 0;
248  virtual device_interface& get_device() = 0;
249 
250  virtual ~sensor_interface() = default;
251  };
252 
253 
254  class matcher;
255 
256  class device_interface : public virtual info_interface, public std::enable_shared_from_this<device_interface>
257  {
258  public:
259  virtual sensor_interface& get_sensor(size_t i) = 0;
260 
261  virtual const sensor_interface& get_sensor(size_t i) const = 0;
262 
263  virtual size_t get_sensors_count() const = 0;
264 
265  virtual void hardware_reset() = 0;
266 
267  virtual std::shared_ptr<matcher> create_matcher(const frame_holder& frame) const = 0;
268 
269  virtual std::shared_ptr<context> get_context() const = 0;
270 
271  virtual platform::backend_device_group get_device_data() const = 0;
272 
273  virtual std::pair<uint32_t, rs2_extrinsics> get_extrinsics(const stream_interface& stream) const = 0;
274 
275  virtual bool is_valid() const = 0;
276 
277  virtual ~device_interface() = default;
278 
279  virtual std::vector<tagged_profile> get_profiles_tags() const = 0;
280 
281  virtual void tag_profiles(stream_profiles profiles) const = 0;
282 
283  virtual bool compress_while_record() const = 0;
284 
285  virtual bool contradicts(const stream_profile_interface* a, const std::vector<stream_profile>& others) const = 0;
286  };
287 
288  class depth_stereo_sensor;
289 
290  class color_sensor : public recordable<color_sensor>
291  {
292  public:
293  virtual ~color_sensor() = default;
294 
295  void create_snapshot(std::shared_ptr<color_sensor>& snapshot) const override;
296  void enable_recording(std::function<void(const color_sensor&)> recording_function) override {};
297  };
298 
300 
302  {
303  public:
305 
306  void update(std::shared_ptr<extension_snapshot> ext) override
307  {
308  }
309 
310  void create_snapshot(std::shared_ptr<color_sensor>& snapshot) const override
311  {
312  snapshot = std::make_shared<color_sensor_snapshot>(*this);
313  }
314  void enable_recording(std::function<void(const color_sensor&)> recording_function) override
315  {
316  //empty
317  }
318  };
319 
320 
321  class depth_sensor : public recordable<depth_sensor>
322  {
323  public:
324  virtual float get_depth_scale() const = 0;
325  virtual ~depth_sensor() = default;
326  };
327 
329 
331  {
332  public:
333  depth_sensor_snapshot(float depth_units) : m_depth_units(depth_units) {}
334  float get_depth_scale() const override
335  {
336  return m_depth_units;
337  }
338 
339  void update(std::shared_ptr<extension_snapshot> ext) override
340  {
341  if (auto api = As<depth_sensor>(ext))
342  {
343  m_depth_units = api->get_depth_scale();
344  }
345  }
346  void create_snapshot(std::shared_ptr<depth_sensor>& snapshot) const override
347  {
348  snapshot = std::make_shared<depth_sensor_snapshot>(*this);
349  }
350  void enable_recording(std::function<void(const depth_sensor&)> recording_function) override
351  {
352  //empty
353  }
354 
355  protected:
357  };
358 
359  class depth_stereo_sensor : public virtual depth_sensor, public recordable<depth_stereo_sensor>
360  {
361  public:
362  virtual float get_stereo_baseline_mm() const = 0;
363  };
364 
366 
368  {
369  public:
370  depth_stereo_sensor_snapshot(float depth_units, float stereo_bl_mm) :
371  depth_sensor_snapshot(depth_units),
372  m_stereo_baseline_mm(stereo_bl_mm) {}
373 
374  float get_stereo_baseline_mm() const override
375  {
376  return m_stereo_baseline_mm;
377  }
378 
379  void update(std::shared_ptr<extension_snapshot> ext) override
380  {
382 
383  if (auto api = As<depth_stereo_sensor>(ext))
384  {
385  m_stereo_baseline_mm = api->get_stereo_baseline_mm();
386  }
387  }
388 
389  void create_snapshot(std::shared_ptr<depth_stereo_sensor>& snapshot) const override
390  {
391  snapshot = std::make_shared<depth_stereo_sensor_snapshot>(*this);
392  }
393 
394  void enable_recording(std::function<void(const depth_stereo_sensor&)> recording_function) override
395  {
396  //empty
397  }
398 
399  private:
401  };
402 }
virtual processing_blocks get_recommended_processing_blocks() const override
Definition: streaming.h:218
void create_snapshot(std::shared_ptr< depth_stereo_sensor > &snapshot) const override
Definition: streaming.h:389
void create_snapshot(std::shared_ptr< depth_sensor > &snapshot) const override
Definition: streaming.h:346
const char * rs2_format_to_string(rs2_format format)
Definition: rs.cpp:1263
float get_stereo_baseline_mm() const override
Definition: streaming.h:374
void create_snapshot(std::shared_ptr< color_sensor > &snapshot) const override
Definition: streaming.h:310
boost_foreach_argument_dependent_lookup_hack tag
Definition: foreach_fwd.hpp:31
void enable_recording(std::function< void(const depth_sensor &)> recording_function) override
Definition: streaming.h:350
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: streaming.h:339
virtual void enable_recording(std::function< void(const recommended_proccesing_blocks_interface &)> recording_function) override
Definition: streaming.h:225
GLdouble s
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
Definition: src/types.h:1071
GLfloat GLfloat p
Definition: glext.h:12687
frame_holder(frame_holder &&other)
Definition: streaming.h:144
std::function< void(frame_interface *)> on_frame
Definition: streaming.h:164
virtual bool is_blocking() const =0
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: streaming.h:379
virtual processing_blocks get_recommended_processing_blocks() const override
Definition: streaming.h:200
GLsizei const GLchar *const * string
void enable_recording(std::function< void(const color_sensor &)> recording_function) override
Definition: streaming.h:296
#define LRS_EXTENSION_API
Definition: src/types.h:20
static const textual_icon stop
Definition: model-views.h:225
depth_sensor_snapshot(float depth_units)
Definition: streaming.h:333
recommended_proccesing_blocks_interface * _owner
Definition: streaming.h:228
bool is_valid(const plane_3d &p)
Definition: rendering.h:243
GLuint index
depth_stereo_sensor_snapshot(float depth_units, float stereo_bl_mm)
Definition: streaming.h:370
std::ostream & operator<<(std::ostream &os, const stream_profiles &profiles)
Definition: streaming.h:168
GLboolean GLboolean GLboolean GLboolean a
GLuint GLfloat * val
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: streaming.h:306
GLdouble f
unsigned int uint32_t
Definition: stdint.h:80
std::shared_ptr< rs2_notifications_callback > notifications_callback_ptr
Definition: src/types.h:1073
recommended_proccesing_blocks_snapshot(const processing_blocks blocks)
Definition: streaming.h:197
GLint GLsizei GLsizei height
void enable_recording(std::function< void(const color_sensor &)> recording_function) override
Definition: streaming.h:314
GLint GLint GLsizei GLint GLenum format
std::string frame_to_string(const frame_interface &f)
Definition: streaming.cpp:14
def callback(frame)
Definition: t265_stereo.py:91
GLuint start
virtual void create_snapshot(std::shared_ptr< recommended_proccesing_blocks_interface > &snapshot) const override
Definition: streaming.h:220
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
float get_depth_scale(rs2::device dev)
void enable_recording(std::function< void(const depth_stereo_sensor &)> recording_function) override
Definition: streaming.h:394
float get_depth_scale() const override
Definition: streaming.h:334
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: streaming.h:205
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
Definition: streaming.h:165
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
unsigned char byte
Definition: src/types.h:52
frame_interface * frame
Definition: streaming.h:126
const char * rs2_stream_to_string(rs2_stream stream)
Definition: rs.cpp:1262
long long rs2_metadata_type
Definition: rs_types.h:301
std::string frame_holder_to_string(const frame_holder &f)
Definition: streaming.cpp:9
static rs2::device get_device()
int i
frame_interface * operator->() const
Definition: streaming.h:128
def get_extrinsics(src, dst)
Definition: t265_stereo.py:57
bool is_blocking() const
Definition: streaming.h:157
double rs2_time_t
Definition: rs_types.h:300
recommended_proccesing_blocks_base(recommended_proccesing_blocks_interface *owner)
Definition: streaming.h:214
rs2_frame_metadata_value
Per-Frame-Metadata is the set of read-only properties that might be exposed for each individual frame...
Definition: rs_frame.h:29
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)
frame_holder(frame_interface *f)
Definition: streaming.h:137
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:50:11