4 #if (_MSC_VER <= 1800) // constexpr is not supported in MSVC2013
5 #error( "Librealsense requires MSVC2015 or later to build. Compilation will be aborted" )
28 template<
unsigned...
Is>
struct seq{};
29 template<
unsigned N,
unsigned...
Is>
31 template<
unsigned...
Is>
34 template<
unsigned N1,
unsigned... I1,
unsigned N2,
unsigned... I2>
36 return {{ a1[I1]..., a2[I2]... }};
39 template<
unsigned N1,
unsigned N2>
40 constexpr std::array<
char const, N1+N2-1>
concat(
char const (&a1)[N1],
char const (&a2)[N2]){
49 const std::shared_ptr<librealsense::device_info>& second)
51 auto first_data =
first->get_device_data();
52 auto second_data = second->get_device_data();
54 for (
auto&& uvc : first_data.uvc_devices)
56 if (
std::find(second_data.uvc_devices.begin(),
57 second_data.uvc_devices.end(), uvc) ==
58 second_data.uvc_devices.end())
61 for (
auto&& usb : first_data.usb_devices)
63 if (
std::find(second_data.usb_devices.begin(),
64 second_data.usb_devices.end(), usb) ==
65 second_data.usb_devices.end())
68 for (
auto&& hid : first_data.hid_devices)
70 if (
std::find(second_data.hid_devices.begin(),
71 second_data.hid_devices.end(), hid) ==
72 second_data.hid_devices.end())
75 for (
auto&& pd : first_data.playback_devices)
77 if (
std::find(second_data.playback_devices.begin(),
78 second_data.playback_devices.end(), pd) ==
79 second_data.playback_devices.end())
102 std::string min_api_version)
105 static bool version_logged=
false;
108 version_logged =
true;
121 _backend = std::make_shared<platform::playback_backend>(
filename,
section, min_api_version);
128 _device_watcher = _backend->create_device_watcher();
129 assert(_device_watcher->is_stopped());
136 std::shared_ptr<device_interface>
create(std::shared_ptr<context>,
bool)
const override
144 return pid == 0x0ADB ||
pid == 0x0AB3;
148 std::shared_ptr<context>
ctx,
149 const std::vector<platform::usb_device_info>& usb_devices)
151 std::vector<std::shared_ptr<device_info>> list;
152 for (
auto&& usb : usb_devices)
156 list.push_back(std::make_shared<recovery_info>(
ctx, usb));
172 const char*
RECOVERY_MESSAGE =
"Selected RealSense device is in recovery mode!\nEither perform a firmware update or reconnect the camera to fall-back to last working firmware if available!";
178 std::shared_ptr<device_interface>
create(std::shared_ptr<context>,
bool)
const override;
181 const std::shared_ptr<context>&
ctx,
182 const std::vector<platform::uvc_device_info>& uvc_devices)
184 std::vector<std::shared_ptr<device_info>> list;
187 for (
auto&&
g : groups)
190 list.push_back(std::make_shared<platform_camera_info>(
ctx,
g));
196 std::vector<platform::uvc_device_info> uvcs)
205 std::vector<platform::uvc_device_info>
_uvcs;
224 for (
auto&&
p : results)
243 const std::vector<platform::uvc_device_info>& uvc_infos,
245 bool register_device_notifications)
248 std::vector<std::shared_ptr<platform::uvc_device>> devs;
249 for (
auto&&
info : uvc_infos)
250 devs.push_back(
ctx->get_backend().create_uvc_device(
info));
253 auto raw_color_ep = std::make_shared<uvc_sensor>(
"Raw RGB Camera",
254 std::make_shared<platform::multi_pins_uvc_device>(devs),
257 auto color_ep = std::make_shared<platform_camera_sensor>(
this, raw_color_ep);
261 std::string pid_str(
to_string() << std::setfill(
'0') << std::setw(4) << std::hex << uvc_infos.front().pid);
262 std::transform(pid_str.begin(), pid_str.end(), pid_str.begin(), ::toupper);
264 using namespace platform;
265 auto usb_mode = raw_color_ep->get_usb_specification();
266 std::string usb_type_str(
"USB");
303 std::vector<tagged_profile> markers;
310 bool register_device_notifications)
const
312 return std::make_shared<platform_camera>(
ctx, _uvcs, this->
get_device_data(), register_device_notifications);
317 _device_watcher->stop();
324 return create_devices(
devices, _playback_devices,
mask);
328 const std::map<std::string, std::weak_ptr<device_info>>& playback_devices,
331 std::vector<std::shared_ptr<device_info>> list;
333 auto t =
const_cast<context*
>(
this);
335 auto ctx =
t->shared_from_this();
366 std::copy(
begin(recovery_devices),
end(recovery_devices), std::back_inserter(list));
375 for (
auto&& item : playback_devices)
377 if (
auto dev = item.second.lock())
382 LOG_INFO(
"Found " << list.size() <<
" RealSense devices (mask 0x" << std::hex <<
mask <<
")" );
389 const std::map<std::string, std::weak_ptr<device_info>>& old_playback_devices,
390 const std::map<std::string, std::weak_ptr<device_info>>& new_playback_devices)
395 if (
librealsense::list_changed<std::shared_ptr<device_info>>(old_list, new_list, [](std::shared_ptr<device_info>
first, std::shared_ptr<device_info> second) {
return *
first == *second; }))
397 std::vector<rs2_device_info> rs2_devices_info_added;
398 std::vector<rs2_device_info> rs2_devices_info_removed;
400 auto devices_info_removed =
subtract_sets(old_list, new_list);
402 for (
size_t i = 0;
i < devices_info_removed.size();
i++)
404 rs2_devices_info_removed.push_back({ shared_from_this(), devices_info_removed[
i] });
409 for (
size_t i = 0;
i < devices_info_added.size();
i++)
411 rs2_devices_info_added.push_back({ shared_from_this(), devices_info_added[
i] });
415 std::map<uint64_t, devices_changed_callback_ptr> devices_changed_callbacks;
417 std::lock_guard<std::mutex>
lock(_devices_changed_callbacks_mtx);
418 devices_changed_callbacks = _devices_changed_callbacks;
421 for (
auto&
kvp : devices_changed_callbacks)
425 kvp.second->on_devices_changed(
new rs2_device_list({ shared_from_this(), rs2_devices_info_removed }),
430 LOG_ERROR(
"Exception thrown from user callback handler");
434 raise_devices_changed(rs2_devices_info_removed, rs2_devices_info_added);
439 if (_devices_changed_callback)
443 _devices_changed_callback->on_devices_changed(
new rs2_device_list({ shared_from_this(), removed }),
448 LOG_ERROR(
"Exception thrown from user callback handler");
457 on_device_changed(old, curr, _playback_devices, _playback_devices);
463 std::lock_guard<std::mutex>
lock(_devices_changed_callbacks_mtx);
465 _devices_changed_callbacks.insert(std::make_pair(callback_id,
std::move(
callback)));
467 if (_device_watcher->is_stopped())
469 start_device_watcher();
477 std::lock_guard<std::mutex>
lock(_devices_changed_callbacks_mtx);
478 _devices_changed_callbacks.erase(cb_id);
480 if (_devices_changed_callback ==
nullptr && _devices_changed_callbacks.size() == 0)
482 _device_watcher->stop();
488 std::lock_guard<std::mutex>
lock(_devices_changed_callbacks_mtx);
491 if (_device_watcher->is_stopped())
493 start_device_watcher();
497 std::vector<platform::uvc_device_info>
filter_by_product(
const std::vector<platform::uvc_device_info>&
devices,
const std::set<uint16_t>& pid_list)
499 std::vector<platform::uvc_device_info> result;
502 if (pid_list.count(
info.pid))
503 result.push_back(
info);
509 std::vector<platform::usb_device_info>
filter_by_product(
const std::vector<platform::usb_device_info>&
devices,
const std::set<uint16_t>& pid_list)
511 std::vector<platform::usb_device_info> result;
514 if (pid_list.count(
info.pid))
515 result.push_back(
info);
521 const std::vector<std::vector<platform::uvc_device_info>>&
devices,
522 const std::vector<platform::hid_device_info>& hids)
524 std::vector<std::pair<std::vector<platform::uvc_device_info>, std::vector<platform::hid_device_info>>> results;
530 std::vector<platform::hid_device_info> hid_group;
532 auto device_serial =
dev.front().serial;
534 for (
auto&& hid : hids)
536 if( ! hid.unique_id.empty() )
538 std::stringstream(hid.vid) >> std::hex >> vid;
539 std::stringstream(hid.pid) >> std::hex >>
pid;
543 hid_group.push_back(hid);
547 results.push_back(std::make_pair(
dev, hid_group));
554 auto it = _playback_devices.find(file);
555 if (
it != _playback_devices.end() &&
it->second.lock())
560 auto playback_dev = std::make_shared<playback_device>(shared_from_this(), std::make_shared<ros_reader>(file, shared_from_this()));
561 auto dinfo = std::make_shared<playback_device_info>(playback_dev);
562 auto prev_playback_devices = _playback_devices;
563 _playback_devices[file] = dinfo;
564 on_device_changed({}, {}, prev_playback_devices, _playback_devices);
570 auto file =
dev->get_device_data().playback_devices.front().file_path;
572 auto it = _playback_devices.find(file);
573 if (
it != _playback_devices.end() &&
it->second.lock())
578 auto prev_playback_devices = _playback_devices;
579 _playback_devices[file] =
dev;
580 on_device_changed({}, {}, prev_playback_devices, _playback_devices);
585 auto it = _playback_devices.find(file);
586 if(
it == _playback_devices.end() || !
it->second.lock())
591 auto prev_playback_devices =_playback_devices;
592 _playback_devices.erase(
it);
593 on_device_changed({},{}, prev_playback_devices, _playback_devices);
597 void context::unload_tracking_module()
604 std::map<std::string, std::vector<platform::uvc_device_info>>
map;
609 std::vector<std::vector<platform::uvc_device_info>> result;
612 result.push_back(
kvp.second);
626 return find(chosen.begin(), chosen.end(),
info) != chosen.end();
638 return find(chosen.begin(), chosen.end(),
info) != chosen.end();
665 std::vector<platform::uvc_device_info> results;
669 results.push_back(
info);