rs_pipeline.hpp
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 #ifndef LIBREALSENSE_RS2_PIPELINE_HPP
5 #define LIBREALSENSE_RS2_PIPELINE_HPP
6 
7 #include "rs_types.hpp"
8 #include "rs_frame.hpp"
9 #include "rs_context.hpp"
10 
11 namespace rs2
12 {
19  {
20  public:
21 
23 
29  std::vector<stream_profile> get_streams() const
30  {
31  std::vector<stream_profile> results;
32 
33  rs2_error* e = nullptr;
34  std::shared_ptr<rs2_stream_profile_list> list(
37  error::handle(e);
38 
39  auto size = rs2_get_stream_profiles_count(list.get(), &e);
40  error::handle(e);
41 
42  for (auto i = 0; i < size; i++)
43  {
45  error::handle(e);
46  results.push_back(profile);
47  }
48 
49  return results;
50  }
51 
60  stream_profile get_stream(rs2_stream stream_type, int stream_index = -1) const
61  {
62  for (auto&& s : get_streams())
63  {
64  if (s.stream_type() == stream_type && (stream_index == -1 || s.stream_index() == stream_index))
65  {
66  return s;
67  }
68  }
69  throw std::runtime_error("Profile does not contain the requested stream");
70  }
71 
84  {
85  rs2_error* e = nullptr;
86  std::shared_ptr<rs2_device> dev(
89 
90  error::handle(e);
91 
92  return device(dev);
93  }
94 
100  operator bool() const
101  {
102  return _pipeline_profile != nullptr;
103  }
104 
105  explicit operator std::shared_ptr<rs2_pipeline_profile>() { return _pipeline_profile; }
106  pipeline_profile(std::shared_ptr<rs2_pipeline_profile> profile) :
107  _pipeline_profile(profile){}
108  private:
109 
110  std::shared_ptr<rs2_pipeline_profile> _pipeline_profile;
111  friend class config;
112  friend class pipeline;
113  };
114 
115  class pipeline;
116 
124  class config
125  {
126  public:
128  {
129  rs2_error* e = nullptr;
130  _config = std::shared_ptr<rs2_config>(
131  rs2_create_config(&e),
133  error::handle(e);
134  }
135 
156  void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format = RS2_FORMAT_ANY, int framerate = 0)
157  {
158  rs2_error* e = nullptr;
159  rs2_config_enable_stream(_config.get(), stream_type, stream_index, width, height, format, framerate, &e);
160  error::handle(e);
161  }
162 
169  void enable_stream(rs2_stream stream_type, int stream_index = -1)
170  {
171  enable_stream(stream_type, stream_index, 0, 0, RS2_FORMAT_ANY, 0);
172  }
173 
183  void enable_stream(rs2_stream stream_type, int width, int height, rs2_format format = RS2_FORMAT_ANY, int framerate = 0)
184  {
185  enable_stream(stream_type, -1, width, height, format, framerate);
186  }
187 
195  void enable_stream(rs2_stream stream_type, rs2_format format, int framerate = 0)
196  {
197  enable_stream(stream_type, -1, 0, 0, format, framerate);
198  }
199 
208  void enable_stream(rs2_stream stream_type, int stream_index, rs2_format format, int framerate = 0)
209  {
210  enable_stream(stream_type, stream_index, 0, 0, format, framerate);
211  }
212 
220  {
221  rs2_error* e = nullptr;
223  error::handle(e);
224  }
225 
234  void enable_device(const std::string& serial)
235  {
236  rs2_error* e = nullptr;
237  rs2_config_enable_device(_config.get(), serial.c_str(), &e);
238  error::handle(e);
239  }
240 
250  {
251  rs2_error* e = nullptr;
253  error::handle(e);
254  }
255 
264  {
265  rs2_error* e = nullptr;
266  rs2_config_enable_record_to_file(_config.get(), file_name.c_str(), &e);
267  error::handle(e);
268  }
269 
278  {
279  rs2_error* e = nullptr;
281  error::handle(e);
282  }
283 
290  {
291  rs2_error* e = nullptr;
293  error::handle(e);
294  }
295 
314  pipeline_profile resolve(std::shared_ptr<rs2_pipeline> p) const
315  {
316  rs2_error* e = nullptr;
317  auto profile = std::shared_ptr<rs2_pipeline_profile>(
318  rs2_config_resolve(_config.get(), p.get(), &e),
320 
321  error::handle(e);
322  return pipeline_profile(profile);
323  }
324 
332  bool can_resolve(std::shared_ptr<rs2_pipeline> p) const
333  {
334  rs2_error* e = nullptr;
335  int res = rs2_config_can_resolve(_config.get(), p.get(), &e);
336  error::handle(e);
337  return res != 0;
338  }
339 
340  std::shared_ptr<rs2_config> get() const
341  {
342  return _config;
343  }
344  explicit operator std::shared_ptr<rs2_config>() const
345  {
346  return _config;
347  }
348 
349  config(std::shared_ptr<rs2_config> cfg) : _config(cfg) {}
350  private:
351  std::shared_ptr<rs2_config> _config;
352  };
353 
362  class pipeline
363  {
364  public:
365 
373  {
374  rs2_error* e = nullptr;
375  _pipeline = std::shared_ptr<rs2_pipeline>(
376  rs2_create_pipeline(ctx._context.get(), &e),
378  error::handle(e);
379  }
380 
393  {
394  rs2_error* e = nullptr;
395  auto p = std::shared_ptr<rs2_pipeline_profile>(
396  rs2_pipeline_start(_pipeline.get(), &e),
398 
399  error::handle(e);
400  return pipeline_profile(p);
401  }
402 
422  {
423  rs2_error* e = nullptr;
424  auto p = std::shared_ptr<rs2_pipeline_profile>(
425  rs2_pipeline_start_with_config(_pipeline.get(), config.get().get(), &e),
427 
428  error::handle(e);
429  return pipeline_profile(p);
430  }
431 
441  template<class S>
443  {
444  rs2_error* e = nullptr;
445  auto p = std::shared_ptr<rs2_pipeline_profile>(
448 
449  error::handle(e);
450  return pipeline_profile(p);
451  }
452 
469  template<class S>
471  {
472  rs2_error* e = nullptr;
473  auto p = std::shared_ptr<rs2_pipeline_profile>(
474  rs2_pipeline_start_with_config_and_callback_cpp(_pipeline.get(), config.get().get(), new frame_callback<S>(callback), &e),
476 
477  error::handle(e);
478  return pipeline_profile(p);
479  }
480 
488  void stop()
489  {
490  rs2_error* e = nullptr;
491  rs2_pipeline_stop(_pipeline.get(), &e);
492  error::handle(e);
493  }
494 
510  frameset wait_for_frames(unsigned int timeout_ms = RS2_DEFAULT_TIMEOUT) const
511  {
512  rs2_error* e = nullptr;
513  frame f(rs2_pipeline_wait_for_frames(_pipeline.get(), timeout_ms, &e));
514  error::handle(e);
515 
516  return frameset(f);
517  }
518 
534  {
535  if (!f)
536  {
537  throw std::invalid_argument("null frameset");
538  }
539  rs2_error* e = nullptr;
540  rs2_frame* frame_ref = nullptr;
541  auto res = rs2_pipeline_poll_for_frames(_pipeline.get(), &frame_ref, &e);
542  error::handle(e);
543 
544  if (res) *f = frameset(frame(frame_ref));
545  return res > 0;
546  }
547 
548  bool try_wait_for_frames(frameset* f, unsigned int timeout_ms = RS2_DEFAULT_TIMEOUT) const
549  {
550  if (!f)
551  {
552  throw std::invalid_argument("null frameset");
553  }
554  rs2_error* e = nullptr;
555  rs2_frame* frame_ref = nullptr;
556  auto res = rs2_pipeline_try_wait_for_frames(_pipeline.get(), &frame_ref, timeout_ms, &e);
557  error::handle(e);
558  if (res) *f = frameset(frame(frame_ref));
559  return res > 0;
560  }
561 
572  {
573  rs2_error* e = nullptr;
574  auto p = std::shared_ptr<rs2_pipeline_profile>(
575  rs2_pipeline_get_active_profile(_pipeline.get(), &e),
577 
578  error::handle(e);
579  return pipeline_profile(p);
580  }
581 
582  operator std::shared_ptr<rs2_pipeline>() const
583  {
584  return _pipeline;
585  }
586  explicit pipeline(std::shared_ptr<rs2_pipeline> ptr) : _pipeline(ptr) {}
587 
588  private:
589  std::shared_ptr<rs2_pipeline> _pipeline;
590  friend class config;
591  };
592 }
593 #endif // LIBREALSENSE_RS2_PROCESSING_HPP
config(std::shared_ptr< rs2_config > cfg)
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
int rs2_pipeline_poll_for_frames(rs2_pipeline *pipe, rs2_frame **output_frame, rs2_error **error)
Definition: rs.cpp:1785
void rs2_config_enable_stream(rs2_config *config, rs2_stream stream, int index, int width, int height, rs2_format format, int framerate, rs2_error **error)
Definition: rs.cpp:1928
int rs2_pipeline_try_wait_for_frames(rs2_pipeline *pipe, rs2_frame **output_frame, unsigned int timeout_ms, rs2_error **error)
Definition: rs.cpp:1802
rs2_pipeline_profile * rs2_config_resolve(rs2_config *config, rs2_pipeline *pipe, rs2_error **error)
Definition: rs.cpp:2007
rs2_pipeline_profile * rs2_pipeline_start_with_callback_cpp(rs2_pipeline *pipe, rs2_frame_callback *callback, rs2_error **error)
Definition: rs.cpp:1859
GLdouble s
pipeline_profile start(const config &config)
rs2_pipeline_profile * rs2_pipeline_start(rs2_pipeline *pipe, rs2_error **error)
Definition: rs.cpp:1827
GLfloat GLfloat p
Definition: glext.h:12687
void rs2_delete_device(rs2_device *device)
Definition: rs.cpp:301
void rs2_config_disable_indexed_stream(rs2_config *config, rs2_stream stream, int index, rs2_error **error)
Definition: rs.cpp:1993
rs2_config * rs2_create_config(rs2_error **error)
Definition: rs.cpp:1914
rs2_pipeline * rs2_create_pipeline(rs2_context *ctx, rs2_error **error)
Definition: rs.cpp:1756
pipeline(std::shared_ptr< rs2_pipeline > ptr)
pipeline_profile start(const config &config, S callback)
void rs2_config_enable_record_to_file(rs2_config *config, const char *file, rs2_error **error)
Definition: rs.cpp:1977
std::shared_ptr< rs2_pipeline > _pipeline
pipeline(context ctx=context())
bool try_wait_for_frames(frameset *f, unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
Definition: cah-model.h:10
GLsizei const GLchar *const * string
void enable_device(const std::string &serial)
rs2_pipeline_profile * rs2_pipeline_get_active_profile(rs2_pipeline *pipe, rs2_error **error)
Definition: rs.cpp:1880
GLuint GLuint stream
Definition: glext.h:1790
e
Definition: rmse.py:177
void rs2_config_enable_all_stream(rs2_config *config, rs2_error **error)
Definition: rs.cpp:1942
void enable_stream(rs2_stream stream_type, int stream_index, rs2_format format, int framerate=0)
rs2_device * rs2_pipeline_profile_get_device(rs2_pipeline_profile *profile, rs2_error **error)
Definition: rs.cpp:1888
rs2_pipeline_profile * rs2_pipeline_start_with_config_and_callback_cpp(rs2_pipeline *pipe, rs2_config *config, rs2_frame_callback *callback, rs2_error **error)
Definition: rs.cpp:1869
GLuint index
pipeline_profile start(S callback)
GLdouble f
bool poll_for_frames(frameset *f) const
rs2_stream_profile_list * rs2_pipeline_profile_get_streams(rs2_pipeline_profile *profile, rs2_error **error)
Definition: rs.cpp:1898
rs2_frame * rs2_pipeline_wait_for_frames(rs2_pipeline *pipe, unsigned int timeout_ms, rs2_error **error)
Definition: rs.cpp:1774
GLsizeiptr size
void rs2_config_disable_all_streams(rs2_config *config, rs2_error **error)
Definition: rs.cpp:2000
std::shared_ptr< rs2_config > get() const
void disable_all_streams()
GLint GLsizei GLsizei height
int rs2_config_can_resolve(rs2_config *config, rs2_pipeline *pipe, rs2_error **error)
Definition: rs.cpp:2015
GLint GLint GLsizei GLint GLenum format
const rs2_stream_profile * rs2_get_stream_profile(const rs2_stream_profile_list *list, int index, rs2_error **error)
Definition: rs.cpp:351
stream_profile get_stream(rs2_stream stream_type, int stream_index=-1) const
Definition: rs_pipeline.hpp:60
def callback(frame)
Definition: t265_stereo.py:91
void disable_stream(rs2_stream stream, int index=-1)
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
#define RS2_DEFAULT_TIMEOUT
Definition: rs_config.h:13
pipeline_profile(std::shared_ptr< rs2_pipeline_profile > profile)
void rs2_config_enable_device_from_file_repeat_option(rs2_config *config, const char *file, int repeat_playback, rs2_error **error)
Definition: rs.cpp:1959
void enable_all_streams()
void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
bool can_resolve(std::shared_ptr< rs2_pipeline > p) const
static void handle(rs2_error *e)
Definition: rs_types.hpp:144
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
device get_device() const
Definition: rs_pipeline.hpp:83
rs2_pipeline_profile * rs2_pipeline_start_with_config(rs2_pipeline *pipe, rs2_config *config, rs2_error **error)
Definition: rs.cpp:1834
void enable_stream(rs2_stream stream_type, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
pipeline_profile resolve(std::shared_ptr< rs2_pipeline > p) const
std::vector< stream_profile > get_streams() const
Definition: rs_pipeline.hpp:29
void enable_record_to_file(const std::string &file_name)
std::shared_ptr< rs2_config > _config
void rs2_delete_stream_profiles_list(rs2_stream_profile_list *list)
Definition: rs.cpp:367
void rs2_pipeline_stop(rs2_pipeline *pipe, rs2_error **error)
Definition: rs.cpp:1766
std::shared_ptr< rs2_pipeline_profile > _pipeline_profile
void enable_stream(rs2_stream stream_type, int stream_index=-1)
void rs2_delete_config(rs2_config *config)
Definition: rs.cpp:1920
void enable_device_from_file(const std::string &file_name, bool repeat_playback=true)
int i
void rs2_config_enable_device(rs2_config *config, const char *serial, rs2_error **error)
Definition: rs.cpp:1949
GLuint res
Definition: glext.h:8856
pipeline_profile get_active_profile() const
pipeline_profile start()
int rs2_get_stream_profiles_count(const rs2_stream_profile_list *list, rs2_error **error)
Definition: rs.cpp:360
void rs2_delete_pipeline_profile(rs2_pipeline_profile *profile)
Definition: rs.cpp:1905
auto device
Definition: pyrs_net.cpp:17
void rs2_delete_pipeline(rs2_pipeline *pipe)
Definition: rs.cpp:1819
struct rs2_frame rs2_frame
Definition: rs_types.h:261
GLint GLsizei width
void enable_stream(rs2_stream stream_type, rs2_format format, int framerate=0)


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