synthetic-stream.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include "core/processing.h"
7 #include "image.h"
8 #include "source.h"
9 #include "../include/librealsense2/hpp/rs_frame.hpp"
10 #include "../include/librealsense2/hpp/rs_processing.hpp"
11 
12 namespace librealsense
13 {
15  {
16  public:
18  : _actual_source(actual), _c_wrapper(new rs2_source{ this })
19  {
20  }
21 
22  frame_interface* allocate_video_frame(std::shared_ptr<stream_profile_interface> stream,
23  frame_interface* original,
24  int new_bpp = 0,
25  int new_width = 0,
26  int new_height = 0,
27  int new_stride = 0,
28  rs2_extension frame_type = RS2_EXTENSION_VIDEO_FRAME) override;
29 
30  frame_interface* allocate_motion_frame(std::shared_ptr<stream_profile_interface> stream,
31  frame_interface* original,
32  rs2_extension frame_type = RS2_EXTENSION_MOTION_FRAME) override;
33 
34  frame_interface* allocate_composite_frame(std::vector<frame_holder> frames) override;
35 
36  frame_interface* allocate_points(std::shared_ptr<stream_profile_interface> stream,
37  frame_interface* original, rs2_extension frame_type = RS2_EXTENSION_POINTS) override;
38 
39  void frame_ready(frame_holder result) override;
40 
41  rs2_source* get_c_wrapper() override { return _c_wrapper.get(); }
42 
43  private:
45  std::shared_ptr<rs2_source> _c_wrapper;
46  };
47 
49  {
50  public:
51  processing_block(const char* name);
52 
53  void set_processing_callback(frame_processor_callback_ptr callback) override;
54  void set_output_callback(frame_callback_ptr callback) override;
55  void invoke(frame_holder frames) override;
56  synthetic_source_interface& get_source() override { return _source_wrapper; }
57 
58  virtual ~processing_block() { _source.flush(); }
59  protected:
61  std::mutex _mutex;
64  };
65 
67  {
68  public:
69  generic_processing_block(const char* name);
70  virtual ~generic_processing_block() { _source.flush(); }
71 
72  protected:
73  virtual rs2::frame prepare_output(const rs2::frame_source& source, rs2::frame input, std::vector<rs2::frame> results);
74 
75  virtual bool should_process(const rs2::frame& frame) = 0;
76  virtual rs2::frame process_frame(const rs2::frame_source& source, const rs2::frame& f) = 0;
77  };
78 
80  {
83  int index;
84 
85  stream_filter() : stream(RS2_STREAM_ANY), format(RS2_FORMAT_ANY), index(-1) {}
86  stream_filter(rs2_stream s, rs2_format f, int i) : stream(s), format(f), index(i) {}
87 
88  bool match(const rs2::frame& frame)
89  {
91  return match(filter);
92  }
93 
94  bool match(const stream_filter& other)
95  {
96  if (stream != RS2_STREAM_ANY && stream != other.stream)
97  return false;
98  if (format != RS2_FORMAT_ANY && format != other.format)
99  return false;
100  if (index != -1 && index != other.index)
101  return false;
102  return true;
103  }
104 
105  bool operator==(const stream_filter& other)
106  {
107  if (stream != other.stream)
108  return false;
109  if (format != other.format)
110  return false;
111  if (index != other.index)
112  return false;
113  return true;
114  }
115 
116  bool operator!=(const stream_filter& other)
117  {
118  return !(*this == other);
119  }
120 
121  void operator=(const stream_filter& other)
122  {
123  stream = other.stream;
124  format = other.format;
125  index = other.index;
126  }
127  };
128 
130  {
131  public:
133  virtual ~stream_filter_processing_block() { _source.flush(); }
134 
135  protected:
137 
138  bool should_process(const rs2::frame& frame) override;
139  };
140 
141  // process frames with a given function
143  {
144  public:
145  functional_processing_block(const char* name, rs2_format target_format, rs2_stream target_stream = RS2_STREAM_ANY, rs2_extension extension_type = RS2_EXTENSION_VIDEO_FRAME);
146 
147  protected:
148  virtual void init_profiles_info(const rs2::frame* f);
149  rs2::frame process_frame(const rs2::frame_source & source, const rs2::frame & f) override;
150  virtual rs2::frame prepare_frame(const rs2::frame_source& source, const rs2::frame& f);
151  virtual void process_function(byte * const dest[], const byte * source, int width, int height, int actual_size, int input_size) = 0;
152 
158  int _target_bpp = 0;
159  };
160 
161  // process interleaved frames with a given function
163  {
164  public:
166  rs2_format source_format,
167  rs2_format left_target_format,
168  rs2_stream left_target_stream,
169  rs2_extension left_extension_type,
170  int left_idx,
171  rs2_format right_target_format,
172  rs2_stream right_target_stream,
173  rs2_extension right_extension_type,
174  int right_idx);
175 
176  protected:
177  virtual void process_function(byte * const dest[], const byte * source, int width, int height, int actual_size, int input_size) = 0;
178  void configure_processing_callback();
179 
180  std::shared_ptr<stream_profile_interface> _source_stream_profile;
181  std::shared_ptr<stream_profile_interface> _left_target_stream_profile;
182  std::shared_ptr<stream_profile_interface> _right_target_stream_profile;
190  int _left_target_bpp = 0;
191  int _right_target_bpp = 0;
192  int _left_target_profile_idx = 1;
193  int _right_target_profile_idx = 2;
194  };
195 
197  {
198  public:
200 
201  virtual ~depth_processing_block() { _source.flush(); }
202 
203  protected:
204  bool should_process(const rs2::frame& frame) override;
205  };
206 
207  // Sequential chained processing blocks
208  // The order of the processing blocks defines the execution flow.
210  {
211  public:
212  class bypass_option : public option
213  {
214  public:
216  : _parent(parent), _opt(opt) {}
217 
218  void set(float value) override {
219  // While query and other read operations
220  // will only read from the currently selected
221  // block, setting an option will propogate
222  // to all blocks in the group
223  for (size_t i = 0; i < _parent->_processing_blocks.size(); i++)
224  {
225  if (_parent->_processing_blocks[i]->supports_option(_opt))
226  {
227  _parent->_processing_blocks[i]->get_option(_opt).set(value);
228  }
229  }
230  }
231  float query() const override { return get().query(); }
232  option_range get_range() const override { return get().get_range(); }
233  bool is_enabled() const override { return get().is_enabled(); }
234  bool is_read_only() const override { return get().is_read_only(); }
235  const char* get_description() const override { return get().get_description(); }
236  const char* get_value_description(float v) const override { return get().get_value_description(v); }
237  void enable_recording(std::function<void(const option &)> record_action) override {}
238 
239  option& get() { return _parent->get(_opt).get_option(_opt); }
240  const option& get() const { return _parent->get(_opt).get_option(_opt); }
241  private:
244  };
245 
247  composite_processing_block(const char* name);
248  virtual ~composite_processing_block() { _source.flush(); };
249 
251  void add(std::shared_ptr<processing_block> block);
252  void set_output_callback(frame_callback_ptr callback) override;
253  void invoke(frame_holder frames) override;
254 
255  protected:
256  std::vector<std::shared_ptr<processing_block>> _processing_blocks;
257  };
258 }
259 
260 // API structures
262 {
263  rs2_options(librealsense::options_interface* options) : options(options) { }
264 
266 
267  virtual ~rs2_options() = default;
268 };
269 
271 {
272  std::vector<rs2_option> list;
273 };
274 
276 {
277  rs2_processing_block(std::shared_ptr<librealsense::processing_block_interface> block)
278  : rs2_options((librealsense::options_interface*)block.get()),
279  block(block) { }
280 
281  std::shared_ptr<librealsense::processing_block_interface> block;
282 
283  rs2_processing_block& operator=(const rs2_processing_block&) = delete;
285 };
rs2_processing_block(std::shared_ptr< librealsense::processing_block_interface > block)
std::vector< rs2_option > list
synthetic_source(frame_source &actual)
GLuint const GLchar * name
bool match(const stream_filter &other)
std::vector< std::shared_ptr< processing_block > > _processing_blocks
bool operator==(const stream_filter &other)
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
frame_interface * allocate_motion_frame(std::shared_ptr< stream_profile_interface > stream, frame_interface *original, rs2_extension frame_type=RS2_EXTENSION_MOTION_FRAME) override
GLdouble s
std::shared_ptr< librealsense::processing_block_interface > block
stream_filter(rs2_stream s, rs2_format f, int i)
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
Definition: src/types.h:1071
std::shared_ptr< stream_profile_interface > _left_target_stream_profile
GLfloat value
stream_profile get_profile() const
Definition: rs_frame.hpp:557
bool operator!=(const stream_filter &other)
#define LRS_EXTENSION_API
Definition: src/types.h:20
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
frame_processor_callback_ptr _callback
std::shared_ptr< stream_profile_interface > _right_target_stream_profile
rs2_source * get_c_wrapper() override
GLdouble f
frame_interface * allocate_video_frame(std::shared_ptr< stream_profile_interface > stream, frame_interface *original, int new_bpp=0, int new_width=0, int new_height=0, int new_stride=0, rs2_extension frame_type=RS2_EXTENSION_VIDEO_FRAME) override
bypass_option(composite_processing_block *parent, rs2_option opt)
GLuint GLenum option
Definition: glext.h:5923
std::shared_ptr< rs2_source > _c_wrapper
std::shared_ptr< rs2_frame_processor_callback > frame_processor_callback_ptr
Definition: src/types.h:1072
synthetic_source_interface & get_source() override
GLint GLsizei GLsizei height
bool match(const rs2::frame &frame)
rs2_options(librealsense::options_interface *options)
def callback(frame)
Definition: t265_stereo.py:91
BOOST_DEDUCED_TYPENAME optional< T >::reference_const_type get(optional< T > const &opt)
void frame_ready(frame_holder result) override
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
int stream_index() const
Definition: rs_frame.hpp:34
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
rs2_format format() const
Definition: rs_frame.hpp:44
frame_interface * allocate_composite_frame(std::vector< frame_holder > frames) override
unsigned char byte
Definition: src/types.h:52
struct rs2_processing_block rs2_processing_block
Definition: rs_types.h:275
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:166
GLenum GLenum GLenum input
Definition: glext.h:10805
const char * get_value_description(float v) const override
GLsizei GLsizei GLchar * source
LZ4LIB_API char * dest
Definition: lz4.h:438
librealsense::options_interface * options
void operator=(const stream_filter &other)
int i
void enable_recording(std::function< void(const option &)> record_action) override
frame_interface * allocate_points(std::shared_ptr< stream_profile_interface > stream, frame_interface *original, rs2_extension frame_type=RS2_EXTENSION_POINTS) override
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
GLuint64EXT * result
Definition: glext.h:10921
GLdouble v
GLint GLsizei width
std::shared_ptr< stream_profile_interface > _source_stream_profile


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