5 #ifndef LIBREALSENSE_BACKEND_H 6 #define LIBREALSENSE_BACKEND_H 8 #include "../include/librealsense2/h/rs_types.h" 9 #include "../include/librealsense2/h/rs_option.h" 39 const std::vector<T>& list2,
40 std::function<
bool(T, T)> equal = [](T first, T second) {
return first == second; })
42 if (list1.size() != list2.size())
45 for (
auto dev1 : list1)
48 for (
auto dev2 : list2)
72 control_range(int32_t in_min, int32_t in_max, int32_t in_step, int32_t in_def)
74 populate_raw_data(
min, in_min);
75 populate_raw_data(
max, in_max);
76 populate_raw_data(
step, in_step);
77 populate_raw_data(
def, in_def);
79 control_range(std::vector<uint8_t> in_min, std::vector<uint8_t> in_max, std::vector<uint8_t> in_step, std::vector<uint8_t> in_def)
83 std::vector<uint8_t>
min;
84 std::vector<uint8_t>
max;
86 std::vector<uint8_t>
def;
89 void populate_raw_data(std::vector<uint8_t>& vec, int32_t
value);
104 return std::chrono::duration<double, std::milli>(std::chrono::system_clock::now().time_since_epoch()).count();
108 struct guid { uint32_t data1; uint16_t data2, data3; uint8_t data4[8]; };
115 virtual std::vector<uint8_t> send_receive(
116 const std::vector<uint8_t>& data,
117 int timeout_ms = 5000,
118 bool require_response =
true) = 0;
140 return std::make_tuple(width, height, fps, format);
154 #pragma pack(push, 1) 161 uint8_t source_clock[6];
177 typedef std::function<void(stream_profile, frame_object, std::function<void()>)>
frame_callback;
190 static const std::map<usb_spec, std::string> usb_spec_names = {
207 std::string device_path =
"";
210 operator std::string()
214 "\nvid- " << std::hex << vid <<
215 "\npid- " << std::hex << pid <<
217 "\nunique_id- " << unique_id <<
218 "\npath- " << device_path <<
219 "\nsusb specification- " << std::hex << (uint16_t)conn_spec << std::dec;
226 return (std::make_tuple(
id, vid, pid, mi, unique_id, device_path) < std::make_tuple(obj.
id, obj.
vid, obj.
pid, obj.
mi, obj.
unique_id, obj.
device_path));
233 return (a.
vid == b.
vid) &&
252 operator std::string()
256 s <<
"vid- " << std::hex << vid <<
257 "\npid- " << std::hex << pid <<
259 "\nsusb specification- " << std::hex << (uint16_t)conn_spec << std::dec <<
260 "\nunique_id- " << unique_id;
269 return (a.
id == b.
id) &&
285 operator std::string()
289 "\nvid- " << std::hex << vid <<
290 "\npid- " << std::hex << pid <<
291 "\nunique_id- " << unique_id <<
292 "\npath- " << device_path;
301 return (a.
id == b.
id) &&
312 operator std::string()
328 operator std::string()
330 std::ostringstream oss;
399 virtual void open(
const std::vector<hid_profile>& hid_profiles) = 0;
400 virtual void close() = 0;
401 virtual void stop_capture() = 0;
402 virtual void start_capture(hid_callback callback) = 0;
403 virtual std::vector<hid_sensor> get_sensors() = 0;
404 virtual std::vector<uint8_t> get_custom_report_data(
const std::string& custom_sensor_name,
405 const std::string& report_name,
416 virtual void start_callbacks() = 0;
417 virtual void stop_callbacks() = 0;
420 virtual void set_power_state(
power_state state) = 0;
424 virtual bool set_xu(
const extension_unit& xu, uint8_t ctrl,
const uint8_t* data,
int len) = 0;
425 virtual bool get_xu(
const extension_unit& xu, uint8_t ctrl, uint8_t* data,
int len)
const = 0;
429 virtual bool set_pu(
rs2_option opt, int32_t value) = 0;
432 virtual std::vector<stream_profile> get_profiles()
const = 0;
434 virtual void lock()
const = 0;
435 virtual void unlock()
const = 0;
437 virtual std::string get_device_location()
const = 0;
438 virtual usb_spec get_usb_specification()
const = 0;
454 _dev->probe_and_commit(profile, callback, buffers);
459 _dev->stream_on(error_handler);
464 _dev->start_callbacks();
469 _dev->stop_callbacks();
474 _dev->close(profile);
479 _dev->set_power_state(state);
484 return _dev->get_power_state();
496 if (_dev->set_xu(xu, ctrl, data, len))
508 if (_dev->get_xu(xu, ctrl, data, len))
518 return _dev->get_xu_range(xu, ctrl, len);
525 if (_dev->get_pu(opt, value))
537 if (_dev->set_pu(opt, value))
547 return _dev->get_pu_range(opt);
552 return _dev->get_profiles();
557 return _dev->get_device_location();
562 return _dev->get_usb_specification();
565 void lock()
const override { _dev->lock(); }
566 void unlock()
const override { _dev->unlock(); }
569 std::shared_ptr<uvc_device> _dev;
586 backend_device_group(
const std::vector<uvc_device_info>& uvc_devices,
const std::vector<usb_device_info>& usb_devices,
const std::vector<hid_device_info>& hid_devices)
587 :uvc_devices(uvc_devices), usb_devices(usb_devices), hid_devices(hid_devices) {}
590 :usb_devices(usb_devices) {}
592 backend_device_group(
const std::vector<uvc_device_info>& uvc_devices,
const std::vector<usb_device_info>& usb_devices)
593 :uvc_devices(uvc_devices), usb_devices(usb_devices) {}
595 backend_device_group(
const std::vector<playback_device_info>& playback_devices) : playback_devices(playback_devices) {}
611 operator std::string()
614 s = uvc_devices.size()>0 ?
"uvc devices:\n" :
"";
615 for (
auto uvc : uvc_devices)
621 s += usb_devices.size()>0 ?
"usb devices:\n" :
"";
622 for (
auto usb : usb_devices)
628 s += hid_devices.size()>0 ?
"hid devices: \n" :
"";
629 for (
auto hid : hid_devices)
635 s += playback_devices.size()>0 ?
"playback devices: \n" :
"";
662 virtual std::shared_ptr<time_service> create_time_service()
const = 0;
664 virtual std::shared_ptr<device_watcher> create_device_watcher()
const = 0;
672 void open(
const std::vector<hid_profile>& sensor_iio)
override 674 for (
auto&& dev : _dev) dev->open(sensor_iio);
679 for (
auto&& dev : _dev) dev->close();
684 _dev.front()->stop_capture();
689 _dev.front()->start_capture(callback);
694 return _dev.front()->get_sensors();
703 const std::string& report_name,
706 return _dev.front()->get_custom_report_data(custom_sensor_name, report_name, report_field);
710 std::vector<std::shared_ptr<hid_device>> _dev;
722 auto dev_index = get_dev_index_by_profiles(profile);
723 _configured_indexes.insert(dev_index);
724 _dev[dev_index]->probe_and_commit(profile, callback, buffers);
730 for (
auto& elem : _configured_indexes)
732 _dev[elem]->stream_on(error_handler);
737 for (
auto& elem : _configured_indexes)
739 _dev[elem]->start_callbacks();
745 for (
auto& elem : _configured_indexes)
747 _dev[elem]->stop_callbacks();
753 auto dev_index = get_dev_index_by_profiles(profile);
754 _dev[dev_index]->close(profile);
755 _configured_indexes.erase(dev_index);
760 for (
auto& elem : _dev)
762 elem->set_power_state(state);
768 return _dev.front()->get_power_state();
773 _dev.front()->init_xu(xu);
778 return _dev.front()->set_xu(xu, ctrl, data, len);
783 return _dev.front()->get_xu(xu, ctrl, data, len);
788 return _dev.front()->get_xu_range(xu, ctrl, len);
793 return _dev.front()->get_pu(opt, value);
798 return _dev.front()->set_pu(opt, value);
803 return _dev.front()->get_pu_range(opt);
808 std::vector<stream_profile> all_stream_profiles;
809 for (
auto& elem : _dev)
811 auto pin_stream_profiles = elem->get_profiles();
812 all_stream_profiles.insert(all_stream_profiles.end(),
813 pin_stream_profiles.begin(), pin_stream_profiles.end());
815 return all_stream_profiles;
820 return _dev.front()->get_device_location();
825 return _dev.front()->get_usb_specification();
830 std::vector<uvc_device*> locked_dev;
832 for (
auto& elem : _dev)
835 locked_dev.push_back(elem.get());
840 for (
auto& elem : locked_dev)
850 for (
auto& elem : _dev)
857 uint32_t get_dev_index_by_profiles(
const stream_profile& profile)
const 859 uint32_t dev_index = 0;
860 for (
auto& elem : _dev)
862 auto pin_stream_profiles = elem->get_profiles();
863 auto it = find(pin_stream_profiles.begin(), pin_stream_profiles.end(), profile);
864 if (it != pin_stream_profiles.end())
870 throw std::runtime_error(
"profile not found");
873 std::vector<std::shared_ptr<uvc_device>> _dev;
874 std::set<uint32_t> _configured_indexes;
884 virtual void start(device_changed_callback callback) = 0;
885 virtual void stop() = 0;
bool operator<(const request_mapping &first, const request_mapping &second)
Definition: types.h:624
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
const uint8_t MAX_META_DATA_SIZE
Definition: backend.h:30
bool list_changed(const std::vector< T > &list1, const std::vector< T > &list2, std::function< bool(T, T)> equal=[](T first, T second) { return first==second;})
Definition: backend.h:38
const uint16_t MAX_RETRIES
Definition: backend.h:25
const uint16_t VID_INTEL_CAMERA
Definition: backend.h:26
const uint16_t DELAY_FOR_RETRIES
Definition: backend.h:28
double monotonic_to_realtime(double monotonic)
const uint8_t DEFAULT_V4L2_FRAME_BUFFERS
Definition: backend.h:27
double rs2_time_t
Definition: rs_types.h:179
double get_time()
Definition: rs_internal.hpp:61
Definition: playback_device.h:17