Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
stream.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 "core/streaming.h"
6 #include "core/video.h"
7 #include "core/motion.h"
8 #include "context.h"
9 #include "image.h"
10 #include "environment.h"
11 
12 namespace librealsense
13 {
14  class stream : public stream_interface
15  {
16  public:
17  stream(rs2_stream stream_type, int index = 0);
18 
19  int get_stream_index() const override;
20  void set_stream_index(int index) override;
21 
22  rs2_stream get_stream_type() const override;
23  void set_stream_type(rs2_stream stream) override;
24 
25  int get_unique_id() const override { return _uid; }
26  void set_unique_id(int uid) override { _uid = uid; };
27 
28  private:
29  int _index = 0;
30  int _uid = 0;
31  rs2_stream _type = RS2_STREAM_ANY;
32  };
33 
35  {
36  public:
37  explicit backend_stream_profile(platform::stream_profile sp) : _sp(std::move(sp)) {}
38 
40 
41  virtual ~backend_stream_profile() = default;
42  private:
44  };
45 
47  {
48  public:
50 
51  int get_stream_index() const override;
52  void set_stream_index(int index) override;
53 
54  rs2_stream get_stream_type() const override;
55  void set_stream_type(rs2_stream stream) override;
56 
57  rs2_format get_format() const override;
58  void set_format(rs2_format format) override;
59 
60  uint32_t get_framerate() const override;
61  void set_framerate(uint32_t val) override;
62 
63  bool is_default() const override;
64  void make_default() override;
65 
66  int get_unique_id() const override { return _uid; }
67  void set_unique_id(int uid) override
68  {
69  _uid = uid;
70  };
71 
72  std::shared_ptr<stream_profile_interface> clone() const override;
73 
74  rs2_stream_profile* get_c_wrapper() const override;
75 
76  void set_c_wrapper(rs2_stream_profile* wrapper) override;
77 
78  void create_snapshot(std::shared_ptr<stream_profile_interface>& snapshot) const override;
79  void enable_recording(std::function<void(const stream_profile_interface&)> record_action) override;
80  private:
81  int _index = 1;
82  int _uid = 0;
83  rs2_stream _type = RS2_STREAM_ANY;
84  rs2_format _format = RS2_FORMAT_ANY;
85  uint32_t _framerate = 0;
86  bool _is_default = false;
87  rs2_stream_profile _c_wrapper;
88  rs2_stream_profile* _c_ptr = nullptr;
89  };
90 
92  {
93  public:
95  : stream_profile_base( std::move(sp)),
96  _calc_intrinsics([]() -> rs2_intrinsics { throw not_implemented_exception("No intrinsics are available for this stream profile!"); }),
97  _width(0), _height(0)
98  {
99  }
100 
101  rs2_intrinsics get_intrinsics() const override { return _calc_intrinsics(); }
102  void set_intrinsics(std::function<rs2_intrinsics()> calc) override { _calc_intrinsics = calc; }
103 
104  uint32_t get_width() const override { return _width; }
105  uint32_t get_height() const override { return _height; }
106  void set_dims(uint32_t width, uint32_t height) override
107  {
108  _width = width;
109  _height = height;
110  }
111 
112  std::shared_ptr<stream_profile_interface> clone() const override
113  {
114  auto res = std::make_shared<video_stream_profile>(platform::stream_profile{});
115  res->set_unique_id(environment::get_instance().generate_stream_id());
116  res->set_dims(get_width(), get_height());
117  std::function<rs2_intrinsics()> int_func = _calc_intrinsics;
118  res->set_intrinsics([int_func]() { return int_func(); });
119  res->set_framerate(get_framerate());
120  return res;
121  }
122 
123  bool operator==(const video_stream_profile& other) const
124  {
125  return get_height() == other.get_height() &&
126  get_width() == other.get_width() &&
127  get_framerate() == other.get_framerate() &&
128  get_stream_index() == other.get_stream_index() &&
129  get_stream_type() == other.get_stream_type() &&
130  get_unique_id() == other.get_unique_id() &&
131  get_format() == other.get_format();
132  }
133 
134  void update(std::shared_ptr<extension_snapshot> ext) override
135  {
136  return; //TODO: apply changes here
137  }
138  private:
139  std::function<rs2_intrinsics()> _calc_intrinsics;
140  uint32_t _width, _height;
141  };
142 
143 
145  {
146  public:
148  : stream_profile_base(std::move(sp)),
149  _calc_intrinsics([]() -> rs2_motion_device_intrinsic { throw not_implemented_exception("No intrinsics are available for this stream profile!"); })
150  {
151  }
152  rs2_motion_device_intrinsic get_intrinsics() const override { return _calc_intrinsics(); }
153  void set_intrinsics(std::function<rs2_motion_device_intrinsic()> calc) override { _calc_intrinsics = calc; }
154 
155  void update(std::shared_ptr<extension_snapshot> ext) override
156  {
157  return; //TODO: apply changes here
158  }
159  private:
160  std::function<rs2_motion_device_intrinsic()> _calc_intrinsics;
161  };
162 
164  {
165  public:
167  void update(std::shared_ptr<extension_snapshot> ext) override { /*Nothing to do here*/ }
168  };
169 
171  {
172  auto fps = static_cast<uint32_t>(sp->get_framerate());
173  if (auto vid = dynamic_cast<const video_stream_profile*>(sp))
174  {
175  return{ sp->get_stream_type(), sp->get_stream_index(), vid->get_width(), vid->get_height(), fps, sp->get_format() };
176  }
177  return{ sp->get_stream_type(), sp->get_stream_index(), 0, 0, fps, sp->get_format() };
178  }
179 
180  inline std::vector<stream_profile> to_profiles(const std::vector<std::shared_ptr<stream_profile_interface>>& vec)
181  {
182  std::vector<stream_profile> res;
183  for (auto&& p : vec) res.push_back(to_profile(p.get()));
184  return res;
185  }
186 }
187 
188 namespace std
189 {
190  template<>
191  struct hash<std::shared_ptr<librealsense::video_stream_profile>>
192  {
193  size_t operator()(const std::shared_ptr<librealsense::video_stream_profile>& k) const
194  {
195  using std::hash;
196 
197  return (hash<uint32_t>()(k->get_height()))
198  ^ (hash<uint32_t>()(k->get_width()))
199  ^ (hash<uint32_t>()(k->get_framerate()))
200  ^ (hash<uint32_t>()(k->get_stream_index()))
201  ^ (hash<uint32_t>()(k->get_stream_type()))
202  ^ (hash<uint32_t>()(k->get_unique_id()))
203  ^ (hash<uint32_t>()(k->get_format()));
204  }
205  };
206 
207  inline bool operator==(const std::shared_ptr<librealsense::video_stream_profile>& a, const std::shared_ptr<librealsense::video_stream_profile>& b)
208  {
209  if (!a.get() || !b.get()) return a.get() == b.get();
210  return *a == *b;
211  }
212 }
virtual rs2_format get_format() const =0
virtual rs2_stream get_stream_type() const =0
int get_stream_index() const override
void set_c_wrapper(rs2_stream_profile *wrapper) override
rs2_stream get_stream_type() const override
platform::stream_profile get_backend_profile() const
Definition: stream.h:39
void set_intrinsics(std::function< rs2_intrinsics()> calc) override
Definition: stream.h:102
void enable_recording(std::function< void(const stream_profile_interface &)> record_action) override
stream_profile_base(platform::stream_profile sp)
Definition: stream.h:163
uint32_t get_height() const override
Definition: stream.h:105
Definition: stream.h:46
virtual ~backend_stream_profile()=default
motion_stream_profile(platform::stream_profile sp)
Definition: stream.h:147
std::vector< stream_profile > to_profiles(const std::vector< std::shared_ptr< stream_profile_interface >> &vec)
Definition: stream.h:180
void set_framerate(uint32_t val) override
Definition: stream.h:188
void set_stream_index(int index) override
void set_format(rs2_format format) override
uint32_t get_framerate() const override
void set_unique_id(int uid) override
Definition: stream.h:26
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: stream.h:155
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: stream.h:134
rs2_stream_profile * get_c_wrapper() const override
Definition: algo.h:16
Definition: streaming.h:31
rs2_motion_device_intrinsic get_intrinsics() const override
Definition: stream.h:152
int get_unique_id() const override
Definition: stream.h:25
Definition: streaming.h:46
void set_stream_index(int index) override
void set_stream_type(rs2_stream stream) override
rs2_stream get_stream_type() const override
struct rs2_motion_device_intrinsic rs2_motion_device_intrinsic
Motion device intrinsics: scale, bias, and variances.
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: stream.h:167
Definition: rs_sensor.h:54
void set_dims(uint32_t width, uint32_t height) override
Definition: stream.h:106
rs2_format
Format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:52
Definition: stream.h:144
size_t operator()(const std::shared_ptr< librealsense::video_stream_profile > &k) const
Definition: stream.h:193
bool operator==(const std::shared_ptr< librealsense::video_stream_profile > &a, const std::shared_ptr< librealsense::video_stream_profile > &b)
Definition: stream.h:207
std::shared_ptr< stream_profile_interface > clone() const override
Definition: stream.h:112
rs2_intrinsics get_intrinsics() const override
Definition: stream.h:101
int get_stream_index() const override
stream(rs2_stream stream_type, int index=0)
int get_unique_id() const override
Definition: stream.h:66
pose_stream_profile(platform::stream_profile sp)
Definition: stream.h:166
uint32_t get_width() const override
Definition: stream.h:104
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:36
Definition: context.h:35
std::shared_ptr< stream_profile_interface > clone() const override
video_stream_profile(platform::stream_profile sp)
Definition: stream.h:94
struct rs2_intrinsics rs2_intrinsics
Video stream intrinsics.
Definition: stream.h:91
Definition: types.h:469
bool is_default() const override
Definition: rs_sensor.h:38
stream_profile to_profile(const stream_profile_interface *sp)
Definition: stream.h:170
Definition: stream.h:14
void set_intrinsics(std::function< rs2_motion_device_intrinsic()> calc) override
Definition: stream.h:153
backend_stream_profile(platform::stream_profile sp)
Definition: stream.h:37
virtual int get_stream_index() const =0
Video stream intrinsics.
Definition: rs_types.h:55
void set_unique_id(int uid) override
Definition: stream.h:67
void create_snapshot(std::shared_ptr< stream_profile_interface > &snapshot) const override
Motion device intrinsics: scale, bias, and variances.
Definition: rs_types.h:68
virtual uint32_t get_framerate() const =0
rs2_format get_format() const override
void set_stream_type(rs2_stream stream) override
Definition: extension.h:33
bool operator==(const video_stream_profile &other) const
Definition: stream.h:123
static environment & get_instance()