ds5-color.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2016 Intel Corporation. All Rights Reserved.
3 
4 #include <cstddef>
5 #include "metadata.h"
6 
7 #include "ds5-timestamp.h"
8 #include "ds5-thermal-monitor.h"
10 #include "ds5-color.h"
11 
12 namespace librealsense
13 {
14  std::map<uint32_t, rs2_format> ds5_color_fourcc_to_rs2_format = {
15  {rs_fourcc('Y','U','Y','2'), RS2_FORMAT_YUYV},
16  {rs_fourcc('Y','U','Y','V'), RS2_FORMAT_YUYV},
17  {rs_fourcc('U','Y','V','Y'), RS2_FORMAT_UYVY},
18  {rs_fourcc('M','J','P','G'), RS2_FORMAT_MJPEG},
19  {rs_fourcc('B','Y','R','2'), RS2_FORMAT_RAW16}
20  };
21  std::map<uint32_t, rs2_stream> ds5_color_fourcc_to_rs2_stream = {
22  {rs_fourcc('Y','U','Y','2'), RS2_STREAM_COLOR},
23  {rs_fourcc('Y','U','Y','V'), RS2_STREAM_COLOR},
24  {rs_fourcc('U','Y','V','Y'), RS2_STREAM_COLOR},
25  {rs_fourcc('B','Y','R','2'), RS2_STREAM_COLOR},
26  {rs_fourcc('M','J','P','G'), RS2_STREAM_COLOR},
27  };
28 
29  ds5_color::ds5_color(std::shared_ptr<context> ctx,
31  : ds5_device(ctx, group), device(ctx, group),
32  _color_stream(new stream(RS2_STREAM_COLOR)),
33  _separate_color(true)
34  {
35  create_color_device(ctx, group);
36  init();
37  }
38 
40  {
41  using namespace ds;
42  auto&& backend = ctx->get_backend();
43 
44  _color_calib_table_raw = [this]()
45  {
47  };
48 
49  _color_extrinsic = std::make_shared<lazy<rs2_extrinsics>>([this]() { return from_pose(get_color_stream_extrinsic(*_color_calib_table_raw)); });
52 
53  std::vector<platform::uvc_device_info> color_devs_info;
54  // end point 3 is used for color sensor
55  // except for D405, in which the color is part of the depth unit
56  // and it will then been found in end point 0 (the depth's one)
57  auto color_devs_info_mi3 = filter_by_mi(group.uvc_devices, 3);
58  if (color_devs_info_mi3.size() == 1)
59  {
60  // means color end point in part of a separate color sensor (e.g. D435)
61  color_devs_info = color_devs_info_mi3;
62  std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
63  std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup)));
64 
65  auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
66  auto raw_color_ep = std::make_shared<uvc_sensor>("Raw RGB Camera",
67  backend.create_uvc_device(color_devs_info.front()),
68  std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper, enable_global_time_option)),
69  this);
70 
71  auto color_ep = std::make_shared<ds5_color_sensor>(this,
72  raw_color_ep,
75 
76  color_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
77 
78  color_ep->register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, color_devs_info.front().device_path);
79 
80  _color_device_idx = add_sensor(color_ep);
81  }
82  else
83  {
84  auto color_devs_info_mi0 = filter_by_mi(group.uvc_devices, 0);
85  // one uvc device is seen over Windows and 3 uvc devices are seen over linux
86  if (color_devs_info_mi0.size() == 1 || color_devs_info_mi0.size() == 3)
87  {
88  // means color end point is part of the depth sensor (e.g. D405)
89  color_devs_info = color_devs_info_mi0;
92  _separate_color = false;
93  }
94  else
95  throw invalid_value_exception(to_string() << "RS4XX: RGB modules inconsistency - "
96  << color_devs_info.size() << " found");
97  }
98  }
99 
101  {
102  auto& color_ep = get_color_sensor();
103  auto& raw_color_ep = get_raw_color_sensor();
104 
105  color_ep.register_pu(RS2_OPTION_BRIGHTNESS);
106  color_ep.register_pu(RS2_OPTION_CONTRAST);
107  color_ep.register_pu(RS2_OPTION_SATURATION);
108  color_ep.register_pu(RS2_OPTION_GAMMA);
109  color_ep.register_pu(RS2_OPTION_SHARPNESS);
110  color_ep.register_pu(RS2_OPTION_BACKLIGHT_COMPENSATION);
111 
112  auto white_balance_option = std::make_shared<uvc_pu_option>(raw_color_ep, RS2_OPTION_WHITE_BALANCE);
113  color_ep.register_option(RS2_OPTION_WHITE_BALANCE, white_balance_option);
114  auto auto_white_balance_option = std::make_shared<uvc_pu_option>(raw_color_ep, RS2_OPTION_ENABLE_AUTO_WHITE_BALANCE);
115  color_ep.register_option(RS2_OPTION_ENABLE_AUTO_WHITE_BALANCE, auto_white_balance_option);
116  color_ep.register_option(RS2_OPTION_WHITE_BALANCE,
117  std::make_shared<auto_disabling_control>(
118  white_balance_option,
119  auto_white_balance_option));
120 
121  // Currently disabled for certain sensors
122  if (!val_in_range(_pid, { ds::RS465_PID }))
123  {
124  color_ep.register_pu(RS2_OPTION_HUE);
125  }
126 
127  color_ep.register_option(RS2_OPTION_POWER_LINE_FREQUENCY,
128  std::make_shared<uvc_pu_option>(raw_color_ep, RS2_OPTION_POWER_LINE_FREQUENCY,
129  std::map<float, std::string>{ { 0.f, "Disabled"},
130  { 1.f, "50Hz" },
131  { 2.f, "60Hz" },
132  { 3.f, "Auto" }, }));
133 
134  if (_separate_color)
135  {
136  // Currently disabled for certain sensors
137  if (!val_in_range(_pid, { ds::RS465_PID }))
138  {
139  color_ep.register_pu(RS2_OPTION_AUTO_EXPOSURE_PRIORITY);
140  }
141  // From 5.11.15 auto-exposure priority is supported on the D465
142  else if (_fw_version >= firmware_version("5.11.15.0"))
143  {
144  color_ep.register_pu(RS2_OPTION_AUTO_EXPOSURE_PRIORITY);
145  }
146 
147  auto gain_option = std::make_shared<uvc_pu_option>(raw_color_ep, RS2_OPTION_GAIN);
148  auto exposure_option = std::make_shared<uvc_pu_option>(raw_color_ep, RS2_OPTION_EXPOSURE);
149  auto auto_exposure_option = std::make_shared<uvc_pu_option>(raw_color_ep, RS2_OPTION_ENABLE_AUTO_EXPOSURE);
150  color_ep.register_option(RS2_OPTION_GAIN, gain_option);
151  color_ep.register_option(RS2_OPTION_EXPOSURE, exposure_option);
152  color_ep.register_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE, auto_exposure_option);
153  color_ep.register_option(RS2_OPTION_EXPOSURE,
154  std::make_shared<auto_disabling_control>(
155  exposure_option,
156  auto_exposure_option));
157  color_ep.register_option(RS2_OPTION_GAIN,
158  std::make_shared<auto_disabling_control>(
159  gain_option,
160  auto_exposure_option));
161 
162  // Starting with firmware 5.10.9, auto-exposure ROI is available for color sensor
163  if (_fw_version >= firmware_version("5.10.9.0"))
164  {
165  roi_sensor_interface* roi_sensor;
166  if ((roi_sensor = dynamic_cast<roi_sensor_interface*>(&color_ep)))
167  roi_sensor->set_roi_method(std::make_shared<ds5_auto_exposure_roi_method>(*_hw_monitor, ds::fw_cmd::SETRGBAEROI));
168  }
169 
170  // Register for tracking of thermal compensation changes
171  if (val_in_range(_pid, { ds::RS455_PID }))
172  {
173  if (_thermal_monitor)
174  _thermal_monitor->add_observer([&](float){
176  }
177 
178  auto md_prop_offset = offsetof(metadata_raw, mode) +
179  offsetof(md_rgb_mode, rgb_mode) +
180  offsetof(md_rgb_normal_mode, intel_rgb_control);
181 
183  [](rs2_metadata_type param) { return (param != 1); })); // OFF value via UVC is 1 (ON is 8)
184  }
185  else
186  {
187  // attributes of md_rgb_control
188  auto md_prop_offset = offsetof(metadata_raw, mode) +
189  offsetof(md_rgb_mode, rgb_mode) +
190  offsetof(md_rgb_normal_mode, intel_rgb_control);
191 
193  }
194 
196  color_ep.register_metadata(RS2_FRAME_METADATA_ACTUAL_FPS, std::make_shared<ds5_md_attribute_actual_fps>(false, [](const rs2_metadata_type& param)
197  {return param * 100; })); //the units of the exposure of the RGB sensor are 100 microseconds so the md_attribute_actual_fps need the lambda to convert it to microseconds
198 
199  // attributes of md_capture_timing
200  auto md_prop_offset = offsetof(metadata_raw, mode) +
201  offsetof(md_rgb_mode, rgb_mode) +
202  offsetof(md_rgb_normal_mode, intel_capture_timing);
203 
207 
208  // attributes of md_rgb_control
209  md_prop_offset = offsetof(metadata_raw, mode) +
210  offsetof(md_rgb_mode, rgb_mode) +
211  offsetof(md_rgb_normal_mode, intel_rgb_control);
212 
215 
216  // attributes of md_capture_stats
217  md_prop_offset = offsetof(metadata_raw, mode) +
218  offsetof(md_rgb_mode, rgb_mode) +
219  offsetof(md_rgb_normal_mode, intel_capture_stats);
220 
222 
223  // attributes of md_rgb_control
224  md_prop_offset = offsetof(metadata_raw, mode) +
225  offsetof(md_rgb_mode, rgb_mode) +
226  offsetof(md_rgb_normal_mode, intel_rgb_control);
227 
228  color_ep.register_metadata(RS2_FRAME_METADATA_BRIGHTNESS,
230  [](const rs2_metadata_type& param) {
231  // cast to short in order to return negative values
232  return *(short*)&(param);
233  }));
241  [](const rs2_metadata_type& param) {
242  // cast to short in order to return negative values
243  return *(short*)&(param);
244  }));
248 
249 
250  color_ep.register_processing_block(processing_block_factory::create_pbf_vector<yuy2_converter>(RS2_FORMAT_YUYV, map_supported_color_formats(RS2_FORMAT_YUYV), RS2_STREAM_COLOR));
251  color_ep.register_processing_block(processing_block_factory::create_id_pbf(RS2_FORMAT_RAW16, RS2_STREAM_COLOR));
252 
253  if (_pid == ds::RS465_PID)
254  {
255  color_ep.register_processing_block({ {RS2_FORMAT_MJPEG} }, { {RS2_FORMAT_RGB8, RS2_STREAM_COLOR} }, []() { return std::make_shared<mjpeg_converter>(RS2_FORMAT_RGB8); });
256  color_ep.register_processing_block(processing_block_factory::create_id_pbf(RS2_FORMAT_MJPEG, RS2_STREAM_COLOR));
257  }
258  }
259 
261  {
263  *_owner->_color_calib_table_raw,
265  profile.width, profile.height);
266  }
267 
269  {
271  auto&& results = synthetic_sensor::init_stream_profiles();
272 
273  for (auto&& p : results)
274  {
275  // Register stream types
276  if (p->get_stream_type() == RS2_STREAM_COLOR)
277  {
278  assign_stream(_owner->_color_stream, p);
279  }
280 
281  auto&& video = dynamic_cast<video_stream_profile_interface*>(p.get());
282  const auto&& profile = to_profile(p.get());
283 
284  std::weak_ptr<ds5_color_sensor> wp =
285  std::dynamic_pointer_cast<ds5_color_sensor>(this->shared_from_this());
286  video->set_intrinsics([profile, wp]()
287  {
288  auto sp = wp.lock();
289  if (sp)
290  return sp->get_intrinsics(profile);
291  else
292  return rs2_intrinsics{};
293  });
294  }
295 
296  return results;
297  }
298 
300  {
302  }
303 }
synthetic_sensor & get_color_sensor()
Definition: ds5-color.h:20
static const textual_icon lock
Definition: model-views.h:218
std::shared_ptr< lazy< rs2_extrinsics > > _color_extrinsic
Definition: ds5-color.h:45
std::shared_ptr< md_attribute_parser_base > make_rs400_sensor_ts_parser(std::shared_ptr< md_attribute_parser_base > frame_ts_parser, std::shared_ptr< md_attribute_parser_base > sensor_ts_parser)
A helper function to create a specialized parser for RS4xx sensor timestamp.
std::shared_ptr< stream_interface > _color_stream
Definition: ds5-color.h:32
firmware_version _fw_version
Definition: ds5-device.h:88
std::shared_ptr< hw_monitor > _hw_monitor
Definition: ds5-device.h:87
rs2_extrinsics from_pose(pose a)
Definition: src/types.h:602
metadata_raw - metadata structure layout as transmitted and received by backend
Definition: src/metadata.h:678
std::map< uint32_t, rs2_format > ds5_color_fourcc_to_rs2_format
Definition: ds5-color.cpp:14
GLfloat GLfloat p
Definition: glext.h:12687
std::shared_ptr< stream_interface > _color_stream
Definition: ds5-device.h:95
bool val_in_range(const T &val, const std::initializer_list< T > &list)
Definition: src/types.h:174
processing_blocks get_color_recommended_proccesing_blocks()
Definition: sensor.cpp:216
virtual stream_profiles init_stream_profiles() override
Definition: sensor.cpp:1225
uvc_sensor & get_raw_color_sensor()
Definition: ds5-color.h:25
ds5_color(std::shared_ptr< context > ctx, const platform::backend_device_group &group)
Definition: ds5-color.cpp:29
void create_color_device(std::shared_ptr< context > ctx, const platform::backend_device_group &group)
Definition: ds5-color.cpp:39
std::shared_ptr< time_diff_keeper > _tf_keeper
std::shared_ptr< ds5_thermal_monitor > _thermal_monitor
Definition: ds5-device.h:104
void register_extrinsics(const stream_interface &from, const stream_interface &to, std::weak_ptr< lazy< rs2_extrinsics >> extr)
Definition: environment.cpp:28
GLenum mode
const uint16_t RS455_PID
Definition: ds5-private.h:48
GLboolean GLuint group
Definition: glext.h:5688
uint32_t rs_fourcc(const T a, const T b, const T c, const T d)
Definition: src/types.h:1846
lazy< std::vector< uint8_t > > _color_calib_table_raw
Definition: ds5-color.h:44
static processing_block_factory create_id_pbf(rs2_format format, rs2_stream stream, int idx=0)
std::shared_ptr< stream_interface > _depth_stream
Definition: ds5-device.h:92
std::map< uint32_t, rs2_stream > ds5_color_fourcc_to_rs2_stream
Definition: ds5-color.cpp:21
rs2_intrinsics get_intrinsic_by_resolution(const vector< uint8_t > &raw_data, calibration_table_id table_id, uint32_t width, uint32_t height)
std::shared_ptr< md_attribute_parser_base > make_uvc_header_parser(Attribute St::*attribute, attrib_modifyer mod=nullptr)
A utility function to create UVC metadata header parser.
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
Definition: streaming.h:165
static environment & get_instance()
int add_sensor(const std::shared_ptr< sensor_interface > &sensor_base)
Definition: device.cpp:163
extrinsics_graph & get_extrinsics_graph()
processing_blocks get_recommended_processing_blocks() const override
Definition: ds5-color.cpp:299
std::shared_ptr< md_attribute_parser_base > make_attribute_parser(Attribute S::*attribute, Flag flag, unsigned long long offset, attrib_modifyer mod=nullptr)
A helper function to create a specialized attribute parser. Return it as a pointer to a base-class...
stream_profile to_profile(const stream_profile_interface *sp)
Definition: src/stream.h:185
long long rs2_metadata_type
Definition: rs_types.h:301
GLenum GLfloat param
std::vector< rs2_format > map_supported_color_formats(rs2_format source_format)
Definition: device.cpp:263
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
Video stream intrinsics.
Definition: rs_types.h:58
void register_stream_to_extrinsic_group(const stream_interface &stream, uint32_t groupd_index)
Definition: device.cpp:246
#define offsetof(STRUCTURE, FIELD)
Definition: sqlite3.c:11372
stream_profiles init_stream_profiles() override
Definition: ds5-color.cpp:268
void reset() const
Definition: src/types.h:466
std::vector< platform::uvc_device_info > filter_by_mi(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
Definition: context.cpp:644
std::vector< uvc_device_info > uvc_devices
Definition: backend.h:525
rs2_intrinsics get_intrinsics(const stream_profile &profile) const override
Definition: ds5-color.cpp:260
pose get_color_stream_extrinsic(const std::vector< uint8_t > &raw_data)
const uint16_t RS465_PID
Definition: ds5-private.h:45
std::vector< uint8_t > get_raw_calibration_table(ds::calibration_table_id table_id) const
Definition: ds5-device.cpp:554
virtual void set_roi_method(std::shared_ptr< region_of_interest_method > roi_method)=0
std::string to_string(T value)


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