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" 43 const std::vector<T>& list2,
44 std::function<
bool(
T,
T)>
equal = [](
T first,
T second) {
return first == second; })
46 if (list1.size() != list2.size())
49 for (
auto dev1 : list1)
52 for (
auto dev2 : list2)
83 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)
87 std::vector<uint8_t>
min;
88 std::vector<uint8_t>
max;
90 std::vector<uint8_t>
def;
133 return std::make_tuple(width, height, fps, format);
147 #pragma pack(push, 1) 177 typedef std::function<void(stream_profile, frame_object, std::function<void()>)>
frame_callback;
190 bool has_metadata_node =
false;
197 "\nvid- " << std::hex << vid <<
198 "\npid- " << std::hex << pid <<
200 "\nunique_id- " << unique_id <<
201 "\npath- " << device_path <<
202 "\nsusb specification- " << std::hex << (
uint16_t)conn_spec << std::dec <<
203 (has_metadata_node ? (
"\nmetadata node-" + metadata_node_id) :
"");
210 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));
218 return (a.
vid == b.
vid) &&
230 return (a.
id == b.
id) &&
262 std::ostringstream oss;
313 #pragma pack(push, 1) 333 virtual void register_profiles(
const std::vector<hid_profile>& hid_profiles) = 0;
334 virtual void open(
const std::vector<hid_profile>& hid_profiles) = 0;
335 virtual void close() = 0;
336 virtual void stop_capture() = 0;
337 virtual void start_capture(hid_callback
callback) = 0;
338 virtual std::vector<hid_sensor> get_sensors() = 0;
339 virtual std::vector<uint8_t> get_custom_report_data(
const std::string& custom_sensor_name,
344 struct request_mapping;
351 virtual void start_callbacks() = 0;
352 virtual void stop_callbacks() = 0;
367 virtual std::vector<stream_profile> get_profiles()
const = 0;
369 virtual void lock()
const = 0;
370 virtual void unlock()
const = 0;
372 virtual std::string get_device_location()
const = 0;
373 virtual usb_spec get_usb_specification()
const = 0;
389 _dev->probe_and_commit(profile, callback, buffers);
394 _dev->stream_on(error_handler);
399 _dev->start_callbacks();
404 _dev->stop_callbacks();
409 _dev->close(profile);
414 _dev->set_power_state(state);
419 return _dev->get_power_state();
431 if (_dev->set_xu(xu, ctrl, data, len))
443 if (_dev->get_xu(xu, ctrl, data, len))
453 return _dev->get_xu_range(xu, ctrl, len);
460 if (_dev->get_pu(opt, value))
472 if (_dev->set_pu(opt, value))
482 return _dev->get_pu_range(opt);
487 return _dev->get_profiles();
492 return _dev->get_device_location();
497 return _dev->get_usb_specification();
500 void lock()
const override { _dev->lock(); }
501 void unlock()
const override { _dev->unlock(); }
504 std::shared_ptr<uvc_device>
_dev;
514 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)
515 :uvc_devices(uvc_devices), usb_devices(usb_devices), hid_devices(hid_devices) {}
518 :usb_devices(usb_devices) {}
520 backend_device_group(
const std::vector<uvc_device_info>& uvc_devices,
const std::vector<usb_device_info>& usb_devices)
521 :uvc_devices(uvc_devices), usb_devices(usb_devices) {}
523 backend_device_group(
const std::vector<playback_device_info>& playback_devices) : playback_devices(playback_devices) {}
540 s = uvc_devices.size()>0 ?
"uvc devices:\n" :
"";
541 for (
auto uvc : uvc_devices)
547 s += usb_devices.size()>0 ?
"usb devices:\n" :
"";
548 for (
auto usb : usb_devices)
554 s += hid_devices.size()>0 ?
"hid devices: \n" :
"";
555 for (
auto hid : hid_devices)
561 s += playback_devices.size()>0 ?
"playback devices: \n" :
"";
588 virtual std::shared_ptr<time_service> create_time_service()
const = 0;
590 virtual std::shared_ptr<device_watcher> create_device_watcher()
const = 0;
604 void register_profiles(
const std::vector<hid_profile>& hid_profiles)
override { _hid_profiles = hid_profiles; }
605 void open(
const std::vector<hid_profile>& sensor_iio)
override 607 for (
auto&&
dev : _dev)
dev->open(sensor_iio);
612 for (
auto&&
dev : _dev)
dev->close();
617 _dev.front()->stop_capture();
622 _dev.front()->start_capture(callback);
627 return _dev.front()->get_sensors();
639 return _dev.front()->get_custom_report_data(custom_sensor_name, report_name, report_field);
643 std::vector<std::shared_ptr<hid_device>>
_dev;
656 auto dev_index = get_dev_index_by_profiles(profile);
657 _configured_indexes.insert(dev_index);
658 _dev[dev_index]->probe_and_commit(profile, callback, buffers);
664 for (
auto& elem : _configured_indexes)
666 _dev[elem]->stream_on(error_handler);
671 for (
auto& elem : _configured_indexes)
673 _dev[elem]->start_callbacks();
679 for (
auto& elem : _configured_indexes)
681 _dev[elem]->stop_callbacks();
687 auto dev_index = get_dev_index_by_profiles(profile);
688 _dev[dev_index]->close(profile);
689 _configured_indexes.erase(dev_index);
694 for (
auto& elem : _dev)
696 elem->set_power_state(state);
702 return _dev.front()->get_power_state();
707 _dev.front()->init_xu(xu);
712 return _dev.front()->set_xu(xu, ctrl, data, len);
717 return _dev.front()->get_xu(xu, ctrl, data, len);
722 return _dev.front()->get_xu_range(xu, ctrl, len);
727 return _dev.front()->get_pu(opt, value);
732 return _dev.front()->set_pu(opt, value);
737 return _dev.front()->get_pu_range(opt);
742 std::vector<stream_profile> all_stream_profiles;
743 for (
auto& elem : _dev)
745 auto pin_stream_profiles = elem->get_profiles();
746 all_stream_profiles.insert(all_stream_profiles.end(),
747 pin_stream_profiles.begin(), pin_stream_profiles.end());
749 return all_stream_profiles;
754 return _dev.front()->get_device_location();
759 return _dev.front()->get_usb_specification();
764 std::vector<uvc_device*> locked_dev;
766 for (
auto& elem : _dev)
769 locked_dev.push_back(elem.get());
774 for (
auto& elem : locked_dev)
784 for (
auto& elem : _dev)
794 for (
auto& elem : _dev)
796 auto pin_stream_profiles = elem->get_profiles();
797 auto it =
find(pin_stream_profiles.begin(), pin_stream_profiles.end(),
profile);
798 if (
it != pin_stream_profiles.end())
804 throw std::runtime_error(
"profile not found");
807 std::vector<std::shared_ptr<uvc_device>>
_dev;
819 virtual void stop() = 0;
static const textual_icon lock
GLboolean GLboolean GLboolean b
static const textual_icon unlock
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;})
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
const uint8_t MAX_META_DATA_SIZE
GLsizei const GLchar *const * string
static const textual_icon stop
GLboolean GLboolean GLboolean GLboolean a
def info(name, value, persistent=False)
const uint16_t MAX_RETRIES
const uint16_t DELAY_FOR_RETRIES
bool operator<(const stream_profile &lhs, const stream_profile &rhs)
unsigned __int64 uint64_t
double monotonic_to_realtime(double monotonic)
const uint8_t DEFAULT_V4L2_FRAME_BUFFERS