Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
l500.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2018 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include <vector>
7 #include <mutex>
8 #include <string>
9 
10 #include "device.h"
11 #include "context.h"
12 #include "backend.h"
13 #include "hw-monitor.h"
14 #include "image.h"
15 #include "stream.h"
16 #include "environment.h"
17 #include "core/debug.h"
18 #include "l500-private.h"
19 
20 namespace librealsense
21 {
22  const uint16_t L500_PID = 0x0b0d;
23 
24  class l500_device;
25 
27  {
28  static const int pins = 3;
29  mutable std::vector<int64_t> counter;
30  std::shared_ptr<platform::time_service> _ts;
31  mutable std::recursive_mutex _mtx;
32  public:
33  l500_timestamp_reader(std::shared_ptr<platform::time_service> ts)
34  : counter(pins), _ts(ts)
35  {
36  reset();
37  }
38 
39  void reset() override
40  {
41  std::lock_guard<std::recursive_mutex> lock(_mtx);
42  for (auto i = 0; i < pins; ++i)
43  {
44  counter[i] = 0;
45  }
46  }
47 
49  {
50  std::lock_guard<std::recursive_mutex> lock(_mtx);
51  return _ts->get_time();
52  }
53 
54  unsigned long long get_frame_counter(const request_mapping & mode, const platform::frame_object& fo) const override
55  {
56  std::lock_guard<std::recursive_mutex> lock(_mtx);
57  auto pin_index = 0;
58  if (mode.pf->fourcc == 0x5a313620) // Z16
59  pin_index = 1;
60  else if (mode.pf->fourcc == 0x43202020) // Confidence
61  pin_index = 2;
62 
63  return ++counter[pin_index];
64  }
65 
67  {
69  }
70  };
71 
72  class l500_info : public device_info
73  {
74  public:
75  std::shared_ptr<device_interface> create(std::shared_ptr<context> ctx,
76  bool register_device_notifications) const override;
77 
78  l500_info(std::shared_ptr<context> ctx,
79  std::vector<platform::uvc_device_info> depth,
81  : device_info(ctx),
82  _depth(std::move(depth)),
83  _hwm(std::move(hwm))
84  {}
85 
86  static std::vector<std::shared_ptr<device_info>> pick_l500_devices(
87  std::shared_ptr<context> ctx,
88  std::vector<platform::uvc_device_info>& platform,
89  std::vector<platform::usb_device_info>& usb);
90 
92  {
93  return platform::backend_device_group({ _depth }, { _hwm });
94  }
95 
96  private:
97  std::vector<platform::uvc_device_info> _depth;
99  };
100 
101  class l500_device final : public virtual device, public debug_interface
102  {
103  public:
105  {
106  public:
107  explicit l500_depth_sensor(l500_device* owner, std::shared_ptr<platform::uvc_device> uvc_device,
108  std::unique_ptr<frame_timestamp_reader> timestamp_reader)
109  : uvc_sensor("L500 Depth Sensor", uvc_device, move(timestamp_reader), owner), _owner(owner)
110  {}
111 
112  rs2_intrinsics get_intrinsics(const stream_profile& profile) const override
113  {
114  // TODO
115  return rs2_intrinsics{};
116  }
117 
119  {
121 
122  auto results = uvc_sensor::init_stream_profiles();
123  for (auto p : results)
124  {
125  // Register stream types
126  if (p->get_stream_type() == RS2_STREAM_DEPTH)
127  {
128  assign_stream(_owner->_depth_stream, p);
129  }
130  else if (p->get_stream_type() == RS2_STREAM_INFRARED)
131  {
132  assign_stream(_owner->_ir_stream, p);
133  }
134  else if (p->get_stream_type() == RS2_STREAM_CONFIDENCE)
135  {
136  assign_stream(_owner->_confidence_stream, p);
137  }
138 
139  // Register intrinsics
140  auto video = dynamic_cast<video_stream_profile_interface*>(p.get());
141  if (video->get_width() == 640 && video->get_height() == 480 && video->get_format() == RS2_FORMAT_Z16 && video->get_framerate() == 30)
142  video->make_default();
143 
144  if (video->get_width() == 640 && video->get_height() == 480 && video->get_format() == RS2_FORMAT_Y8 && video->get_framerate() == 30)
145  video->make_default();
146 
147  if (video->get_width() == 640 && video->get_height() == 480 && video->get_format() == RS2_FORMAT_RAW8 && video->get_framerate() == 30)
148  video->make_default();
149 
150  auto profile = to_profile(p.get());
151  std::weak_ptr<l500_depth_sensor> wp =
152  std::dynamic_pointer_cast<l500_depth_sensor>(this->shared_from_this());
153 
154  video->set_intrinsics([profile, wp]()
155  {
156  auto sp = wp.lock();
157  if (sp)
158  return sp->get_intrinsics(profile);
159  else
160  return rs2_intrinsics{};
161  });
162  }
163 
164  return results;
165  }
166 
167  float get_depth_scale() const override { return 0.001f; } // TODO
168 
169  void create_snapshot(std::shared_ptr<depth_sensor>& snapshot) const override
170  {
171  snapshot = std::make_shared<depth_sensor_snapshot>(get_depth_scale());
172  }
173  void enable_recording(std::function<void(const depth_sensor&)> recording_function) override
174  {
175  get_option(RS2_OPTION_DEPTH_UNITS).enable_recording([this, recording_function](const option& o) {
176  recording_function(*this);
177  });
178  }
179  private:
180  const l500_device* _owner;
181  };
182 
183  std::shared_ptr<uvc_sensor> create_depth_device(std::shared_ptr<context> ctx,
184  const std::vector<platform::uvc_device_info>& all_device_infos)
185  {
186  using namespace ivcam2;
187  auto&& backend = ctx->get_backend();
188 
189  std::vector<std::shared_ptr<platform::uvc_device>> depth_devices;
190  for (auto&& info : filter_by_mi(all_device_infos, 0)) // Filter just mi=0, DEPTH
191  depth_devices.push_back(backend.create_uvc_device(info));
192 
193  auto depth_ep = std::make_shared<l500_depth_sensor>(this, std::make_shared<platform::multi_pins_uvc_device>(depth_devices),
194  std::unique_ptr<frame_timestamp_reader>(new l500_timestamp_reader(backend.create_time_service())));
195 
196  depth_ep->register_xu(depth_xu);
197  depth_ep->register_pixel_format(pf_z16_l500);
198  depth_ep->register_pixel_format(pf_confidence_l500);
199  depth_ep->register_pixel_format(pf_y8_l500);
200 
201  return depth_ep;
202  }
203 
204  std::vector<uint8_t> send_receive_raw_data(const std::vector<uint8_t>& input) override
205  {
206  return _hw_monitor->send(input);
207  }
208 
209  void hardware_reset() override
210  {
211  force_hardware_reset();
212  }
213 
214  uvc_sensor& get_depth_sensor() { return dynamic_cast<uvc_sensor&>(get_sensor(_depth_device_idx)); }
215 
216 
217  l500_device(std::shared_ptr<context> ctx,
218  const platform::backend_device_group& group,
219  bool register_device_notifications);
220 
221  void create_snapshot(std::shared_ptr<debug_interface>& snapshot) const override;
222  void enable_recording(std::function<void(const debug_interface&)> record_action) override;
223 
224 
225  virtual std::shared_ptr<matcher> create_matcher(const frame_holder& frame) const override;
226  private:
227  const uint8_t _depth_device_idx;
228  std::shared_ptr<hw_monitor> _hw_monitor;
229  std::shared_ptr<stream_interface> _depth_stream;
230  std::shared_ptr<stream_interface> _ir_stream;
231  std::shared_ptr<stream_interface> _confidence_stream;
232 
233  void force_hardware_reset() const;
234  };
235 }
const native_pixel_format pf_z16_l500
rs2_intrinsics get_intrinsics(const stream_profile &profile) const override
Definition: l500.h:112
stream_profiles init_stream_profiles() override
Definition: options.h:20
platform::backend_device_group get_device_data() const override
Definition: l500.h:91
Definition: rs_sensor.h:57
Definition: stream.h:188
Definition: rs_option.h:52
native_pixel_format * pf
Definition: types.h:609
Definition: archive.h:63
Definition: algo.h:16
uvc_sensor & get_depth_sensor()
Definition: l500.h:214
void reset() override
Definition: l500.h:39
const native_pixel_format pf_y8_l500
Definition: backend.h:167
Definition: rs_sensor.h:48
Definition: context.h:46
std::shared_ptr< uvc_sensor > create_depth_device(std::shared_ptr< context > ctx, const std::vector< platform::uvc_device_info > &all_device_infos)
Definition: l500.h:183
void enable_recording(std::function< void(const depth_sensor &)> recording_function) override
Definition: l500.h:173
std::vector< uint8_t > send_receive_raw_data(const std::vector< uint8_t > &input) override
Definition: l500.h:204
Definition: debug.h:11
const native_pixel_format pf_confidence_l500
const platform::extension_unit depth_xu
Definition: ds5-private.h:80
l500_timestamp_reader(std::shared_ptr< platform::time_service > ts)
Definition: l500.h:33
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
Definition: streaming.h:104
Definition: rs_sensor.h:40
uint32_t fourcc
Definition: types.h:591
Definition: rs_sensor.h:42
Definition: l500.h:101
void hardware_reset() override
Definition: l500.h:209
rs2_timestamp_domain get_frame_timestamp_domain(const request_mapping &mode, const platform::frame_object &fo) const override
Definition: l500.h:66
std::vector< platform::uvc_device_info > filter_by_mi(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
Definition: types.h:470
extrinsics_graph & get_extrinsics_graph()
stream_profile to_profile(const stream_profile_interface *sp)
Definition: stream.h:170
Definition: types.h:637
Video stream intrinsics.
Definition: rs_types.h:55
void create_snapshot(std::shared_ptr< depth_sensor > &snapshot) const override
Definition: l500.h:169
l500_depth_sensor(l500_device *owner, std::shared_ptr< platform::uvc_device > uvc_device, std::unique_ptr< frame_timestamp_reader > timestamp_reader)
Definition: l500.h:107
stream_profiles init_stream_profiles() override
Definition: l500.h:118
rs2_time_t get_frame_timestamp(const request_mapping &mode, const platform::frame_object &fo) override
Definition: l500.h:48
Definition: streaming.h:158
double rs2_time_t
Definition: rs_types.h:179
Definition: sensor.h:112
l500_info(std::shared_ptr< context > ctx, std::vector< platform::uvc_device_info > depth, platform::usb_device_info hwm)
Definition: l500.h:78
Definition: rs_sensor.h:69
Definition: types.h:606
float get_depth_scale() const override
Definition: l500.h:167
static environment & get_instance()
const uint16_t L500_PID
Definition: l500.h:22
Definition: device.h:43
Definition: rs_frame.h:22
Definition: sensor.h:174
Definition: rs_sensor.h:65
Definition: l500.h:72
unsigned long long get_frame_counter(const request_mapping &mode, const platform::frame_object &fo) const override
Definition: l500.h:54
rs2_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs_frame.h:19