Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
rs_internal.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_INTERNAL_HPP
5 #define LIBREALSENSE_RS2_INTERNAL_HPP
6 
7 #include "rs_types.hpp"
8 #include "rs_device.hpp"
9 #include "rs_context.hpp"
10 #include "../h/rs_internal.h"
11 
12 namespace rs2
13 {
14  class recording_context : public context
15  {
16  public:
21  recording_context(const std::string& filename,
22  const std::string& section = "",
24  {
25  rs2_error* e = nullptr;
26  _context = std::shared_ptr<rs2_context>(
27  rs2_create_recording_context(RS2_API_VERSION, filename.c_str(), section.c_str(), mode, &e),
29  error::handle(e);
30  }
31 
32  recording_context() = delete;
33  };
34 
35  class mock_context : public context
36  {
37  public:
43  mock_context(const std::string& filename,
44  const std::string& section = "",
45  const std::string& min_api_version = "0.0.0")
46  {
47  rs2_error* e = nullptr;
48  _context = std::shared_ptr<rs2_context>(
49  rs2_create_mock_context_versioned(RS2_API_VERSION, filename.c_str(), section.c_str(), min_api_version.c_str(), &e),
51  error::handle(e);
52  }
53 
54  mock_context() = delete;
55  };
56 
57  namespace internal
58  {
62  inline double get_time()
63  {
64  rs2_error* e = nullptr;
65  auto time = rs2_get_time( &e);
66 
67  error::handle(e);
68 
69  return time;
70  }
71  }
72 
73  class software_sensor : public sensor
74  {
75  public:
82  {
83  rs2_error* e = nullptr;
84 
85  stream_profile stream(rs2_software_sensor_add_video_stream(_sensor.get(),video_stream, &e));
86  error::handle(e);
87 
88  return stream;
89  }
90 
97  {
98  rs2_error* e = nullptr;
100  error::handle(e);
101  }
102 
109  {
110  rs2_error* e = nullptr;
111  rs2_software_sensor_set_metadata(_sensor.get(), value, type, &e);
112  error::handle(e);
113  }
114 
121  void add_read_only_option(rs2_option option, float val)
122  {
123  rs2_error* e = nullptr;
124  rs2_software_sensor_add_read_only_option(_sensor.get(), option, val, &e);
125  error::handle(e);
126  }
127 
134  void set_read_only_option(rs2_option option, float val)
135  {
136  rs2_error* e = nullptr;
138  error::handle(e);
139  }
140  private:
141  friend class software_device;
142 
143  software_sensor(std::shared_ptr<rs2_sensor> s)
144  : rs2::sensor(s)
145  {
146  rs2_error* e = nullptr;
148  {
149  _sensor = nullptr;
150  }
152  }
153  };
154 
155 
156  class software_device : public device
157  {
158  std::shared_ptr<rs2_device> create_device_ptr()
159  {
160  rs2_error* e = nullptr;
161  std::shared_ptr<rs2_device> dev(
164  error::handle(e);
165  return dev;
166  }
167 
168  public:
170  : device(create_device_ptr())
171  {}
172 
178  software_sensor add_sensor(std::string name)
179  {
180  rs2_error* e = nullptr;
181  std::shared_ptr<rs2_sensor> sensor(
182  rs2_software_device_add_sensor(_dev.get(), name.c_str(), &e),
184  error::handle(e);
185 
186  return software_sensor(sensor);
187  }
188 
194  {
195  rs2_error* e = nullptr;
196  rs2_software_device_create_matcher(_dev.get(), matcher, &e);
197  error::handle(e);
198  }
199  };
200 
201 }
202 #endif // LIBREALSENSE_RS2_INTERNAL_HPP
void rs2_software_sensor_set_metadata(rs2_sensor *sensor, rs2_frame_metadata_value value, rs2_metadata_type type, rs2_error **error)
Definition: rs_frame.hpp:21
recording_context(const std::string &filename, const std::string &section="", rs2_recording_mode mode=RS2_RECORDING_MODE_BLANK_FRAMES)
Definition: rs_internal.hpp:21
Definition: rs_sensor.hpp:232
Definition: rs_frame.hpp:286
#define RS2_API_VERSION
Definition: rs.h:37
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
rs2_recording_mode
Definition: rs_internal.h:25
void rs2_delete_device(rs2_device *device)
void rs2_delete_context(rs2_context *context)
Frees the relevant context object.
void on_video_frame(rs2_software_video_frame frame)
Definition: rs_internal.hpp:96
All the parameters are requaired to defind video stream.
Definition: rs_internal.h:34
void set_metadata(rs2_frame_metadata_value value, rs2_metadata_type type)
Definition: rs_internal.hpp:108
software_device()
Definition: rs_internal.hpp:169
Definition: rs_context.hpp:11
software_sensor add_sensor(std::string name)
Definition: rs_internal.hpp:178
Definition: rs_context.hpp:104
void set_read_only_option(rs2_option option, float val)
Definition: rs_internal.hpp:134
Definition: rs_internal.hpp:35
rs2_context * rs2_create_recording_context(int api_version, const char *filename, const char *section, rs2_recording_mode mode, rs2_error **error)
stream_profile add_video_stream(rs2_video_stream video_stream)
Definition: rs_internal.hpp:81
Definition: rs_types.h:120
rs2_time_t rs2_get_time(rs2_error **error)
std::shared_ptr< rs2_sensor > _sensor
Definition: rs_sensor.hpp:421
Definition: rs_internal.hpp:14
std::shared_ptr< rs2_context > _context
Definition: rs_context.hpp:202
Definition: rs_internal.hpp:73
void rs2_delete_sensor(rs2_sensor *sensor)
rs2_matchers
Specifies types of different matchers.
Definition: rs_types.h:127
std::shared_ptr< rs2_device > _dev
Definition: rs_device.hpp:143
rs2_device * rs2_create_software_device(rs2_error **error)
void rs2_software_sensor_add_read_only_option(rs2_sensor *sensor, rs2_option option, float val, rs2_error **error)
mock_context()=delete
void create_matcher(rs2_matchers matcher)
Definition: rs_internal.hpp:193
Definition: rs_internal.hpp:156
static void handle(rs2_error *e)
Definition: rs_types.hpp:121
rs2_sensor * rs2_software_device_add_sensor(rs2_device *dev, const char *sensor_name, rs2_error **error)
void rs2_software_sensor_update_read_only_option(rs2_sensor *sensor, rs2_option option, float val, rs2_error **error)
Definition: rs_internal.h:27
rs2_stream_profile * rs2_software_sensor_add_video_stream(rs2_sensor *sensor, rs2_video_stream video_stream, rs2_error **error)
void rs2_software_device_create_matcher(rs2_device *dev, rs2_matchers matcher, rs2_error **error)
int rs2_is_sensor_extendable_to(const rs2_sensor *sensor, rs2_extension extension, rs2_error **error)
long long rs2_metadata_type
Definition: rs_types.h:181
rs2_context * rs2_create_mock_context_versioned(int api_version, const char *filename, const char *section, const char *min_api_version, rs2_error **error)
void add_read_only_option(rs2_option option, float val)
Definition: rs_internal.hpp:121
void rs2_software_sensor_on_video_frame(rs2_sensor *sensor, rs2_software_video_frame frame, rs2_error **error)
All the parameters are requaired to define video frame.
Definition: rs_internal.h:48
struct rs2_error rs2_error
Definition: rs_types.h:149
Definition: rs_device.hpp:18
double get_time()
Definition: rs_internal.hpp:62
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
mock_context(const std::string &filename, const std::string &section="", const std::string &min_api_version="0.0.0")
Definition: rs_internal.hpp:43