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);
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)
154 if (is_recovery_pid(usb.pid))
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;
213 :
synthetic_sensor(
"RGB Camera", uvc_sensor, owner,platform_color_fourcc_to_rs2_format,platform_color_fourcc_to_rs2_stream),
224 for (
auto&&
p : results)
227 assign_stream(_default_stream,
p);
243 const std::vector<platform::uvc_device_info>& uvc_infos,
245 bool register_device_notifications)
246 :
device(ctx, group, 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);
258 add_sensor(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);
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();
363 if (mask & RS2_PRODUCT_LINE_D400 || mask & RS2_PRODUCT_LINE_SR300 || mask & RS2_PRODUCT_LINE_L500)
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] });
405 LOG_DEBUG(
"\nDevice disconnected:\n\n" << std::string(devices_info_removed[
i]->get_device_data()));
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] });
412 LOG_DEBUG(
"\nDevice connected:\n\n" << std::string(devices_info_added[
i]->get_device_data()));
415 std::map<uint64_t, devices_changed_callback_ptr> 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");
448 LOG_ERROR(
"Exception thrown from user callback handler");
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;
500 for (
auto&&
info : devices)
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;
512 for (
auto&&
info : devices)
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));
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);
570 auto file = dev->get_device_data().playback_devices.front().file_path;
597 void context::unload_tracking_module()
604 std::map<std::string, std::vector<platform::uvc_device_info>>
map;
605 for (
auto&&
info : devices)
607 map[
info.unique_id].push_back(
info);
609 std::vector<std::vector<platform::uvc_device_info>> result;
610 for (
auto&&
kvp : map)
612 result.push_back(
kvp.second);
626 return find(chosen.begin(), chosen.end(),
info) != chosen.end();
628 devices.erase(std::remove_if(devices.begin(), devices.end(), was_chosen), devices.end());
638 return find(chosen.begin(), chosen.end(),
info) != chosen.end();
640 devices.erase(std::remove_if(devices.begin(), devices.end(), was_chosen), devices.end());
645 for (
auto&&
info : devices)
655 for (
auto&&
info : devices)
665 std::vector<platform::uvc_device_info> results;
666 for (
auto&&
info : devices)
669 results.push_back(
info);
void on_device_changed(platform::backend_device_group old, platform::backend_device_group curr, const std::map< std::string, std::weak_ptr< device_info >> &old_playback_devices, const std::map< std::string, std::weak_ptr< device_info >> &new_playback_devices)
static const textual_icon lock
static bool is_recovery_pid(uint16_t pid)
std::vector< std::shared_ptr< device_info > > create_devices(platform::backend_device_group devices, const std::map< std::string, std::weak_ptr< device_info >> &playback_devices, int mask) const
std::vector< platform::uvc_device_info > filter_by_product(const std::vector< platform::uvc_device_info > &devices, const std::set< uint16_t > &pid_list)
std::map< std::string, std::weak_ptr< device_info > > _playback_devices
void trim_device_list(std::vector< platform::usb_device_info > &devices, const std::vector< platform::usb_device_info > &chosen)
virtual stream_profiles init_stream_profiles() override
std::vector< std::shared_ptr< device_info > > query_devices(int mask) const
const uint16_t VID_INTEL_CAMERA
void register_same_extrinsics(const stream_interface &from, const stream_interface &to)
bool Is(std::shared_ptr< P > ptr)
std::mutex _devices_changed_callbacks_mtx
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;})
void remove_device(const std::string &file)
def info(name, value, persistent=False)
#define RS2_PRODUCT_LINE_NON_INTEL
platform::usb_device_info _dfu
bool contains(const std::shared_ptr< librealsense::device_info > &first, const std::shared_ptr< librealsense::device_info > &second)
std::vector< std::pair< std::vector< platform::uvc_device_info >, std::vector< platform::hid_device_info > > > group_devices_and_hids_by_unique_id(const std::vector< std::vector< platform::uvc_device_info >> &devices, const std::vector< platform::hid_device_info > &hids)
std::vector< std::vector< platform::uvc_device_info > > group_devices_by_unique_id(const std::vector< platform::uvc_device_info > &devices)
#define assert(condition)
std::vector< std::shared_ptr< T > > subtract_sets(const std::vector< std::shared_ptr< T >> &first, const std::vector< std::shared_ptr< T >> &second)
#define RS2_PRODUCT_LINE_D400
uint32_t rs_fourcc(const T a, const T b, const T c, const T d)
void set_time_service(std::shared_ptr< platform::time_service > ts)
platform::uvc_device_info get_mi(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
static processing_block_factory create_id_pbf(rs2_format format, rs2_stream stream, int idx=0)
recovery_info(std::shared_ptr< context > ctx, platform::usb_device_info dfu)
unsigned __int64 uint64_t
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.
#define RS2_PRODUCT_LINE_L500
#define RS2_PRODUCT_LINE_T200
std::shared_ptr< platform::device_watcher > _device_watcher
static environment & get_instance()
extrinsics_graph & get_extrinsics_graph()
void start_device_watcher()
float3 transform(const rs2_extrinsics *extrin, const float3 &point)
#define RS2_PRODUCT_LINE_ANY
LOG_INFO("Log message using LOG_INFO()")
constexpr std::array< char const, N1+N2-1 > concat(char const (&a1)[N1], char const (&a2)[N2], seq< I1... >, seq< I2... >)
static std::vector< std::shared_ptr< device_info > > pick_recovery_devices(std::shared_ptr< context > ctx, const std::vector< platform::usb_device_info > &usb_devices, int mask)
platform::backend_device_group get_device_data() const override
void add_software_device(std::shared_ptr< device_info > software_device)
static std::vector< std::shared_ptr< device_info > > pick_ds5_devices(std::shared_ptr< context > ctx, platform::backend_device_group &gproup)
void raise_devices_changed(const std::vector< rs2_device_info > &removed, const std::vector< rs2_device_info > &added)
#define RS2_API_VERSION_STR
static std::vector< std::shared_ptr< device_info > > pick_l500_devices(std::shared_ptr< context > ctx, platform::backend_device_group &group)
std::map< uint64_t, devices_changed_callback_ptr > _devices_changed_callbacks
static std::vector< std::shared_ptr< device_info > > pick_tm2_devices(std::shared_ptr< context > ctx, std::vector< platform::usb_device_info > &usb)
std::vector< std::shared_ptr< stream_profile_interface > > stream_profiles
typename ::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
uint64_t register_internal_device_callback(devices_changed_callback_ptr callback)
detail::group1< detail::group0 > group()
void set_devices_changed_callback(devices_changed_callback_ptr callback)
std::shared_ptr< platform::backend > _backend
std::shared_ptr< rs2_devices_changed_callback > devices_changed_callback_ptr
static uint64_t generate_id()
std::shared_ptr< device_interface > create(std::shared_ptr< context >, bool) const override
struct rs2_device_list rs2_device_list
constexpr auto rs2_api_version
static std::vector< std::shared_ptr< device_info > > pick_recovery_devices(std::shared_ptr< context > ctx, const std::vector< platform::usb_device_info > &usb_devices)
std::vector< platform::uvc_device_info > filter_by_mi(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
static std::vector< std::shared_ptr< device_info > > pick_sr300_devices(std::shared_ptr< context > ctx, std::vector< platform::uvc_device_info > &platform, std::vector< platform::usb_device_info > &usb)
const std::map< uint32_t, rs2_stream > platform_color_fourcc_to_rs2_stream
#define RS2_PRODUCT_LINE_SR300
void unregister_internal_device_callback(uint64_t cb_id)
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)
devices_changed_callback_ptr _devices_changed_callback
const std::map< uint32_t, rs2_format > platform_color_fourcc_to_rs2_format
void copy(void *dst, void const *src, size_t size)
bool mi_present(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
std::shared_ptr< playback_device_info > add_device(const std::string &file)
std::string to_string(T value)