|
| 1 | +// License: Apache 2.0. See LICENSE file in root directory. |
| 2 | +// Copyright(c) 2021 Intel Corporation. All Rights Reserved. |
| 3 | + |
| 4 | +#pragma once |
| 5 | +#include <iostream> |
| 6 | +#include <string> |
| 7 | +#include <map> |
| 8 | +#include <librealsense2/rs.hpp> |
| 9 | + |
| 10 | +////////////////////////////// |
| 11 | +// Demos Helpers // |
| 12 | +////////////////////////////// |
| 13 | + |
| 14 | +// Find devices with specified streams |
| 15 | +bool device_with_streams(std::vector <rs2_stream> stream_requests, std::string& out_serial) |
| 16 | +{ |
| 17 | + rs2::context ctx; |
| 18 | + auto devs = ctx.query_devices(); |
| 19 | + std::vector <rs2_stream> unavailable_streams = stream_requests; |
| 20 | + for (auto& dev : devs) |
| 21 | + { |
| 22 | + std::map<rs2_stream, bool> found_streams; |
| 23 | + for (auto& type : stream_requests) |
| 24 | + { |
| 25 | + found_streams[type] = false; |
| 26 | + for (auto& sensor : dev.query_sensors()) |
| 27 | + { |
| 28 | + for (auto& profile : sensor.get_stream_profiles()) |
| 29 | + { |
| 30 | + if (profile.stream_type() == type) |
| 31 | + { |
| 32 | + found_streams[type] = true; |
| 33 | + unavailable_streams.erase(std::remove(unavailable_streams.begin(), unavailable_streams.end(), type), unavailable_streams.end()); |
| 34 | + if (dev.supports(RS2_CAMERA_INFO_SERIAL_NUMBER)) |
| 35 | + out_serial = dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + // Check if all streams are found in current device |
| 41 | + bool found_all_streams = true; |
| 42 | + for (auto& stream : found_streams) |
| 43 | + { |
| 44 | + if (!stream.second) |
| 45 | + { |
| 46 | + found_all_streams = false; |
| 47 | + break; |
| 48 | + } |
| 49 | + } |
| 50 | + if (found_all_streams) |
| 51 | + return true; |
| 52 | + } |
| 53 | + // After scanning all devices, not all requested streams were found |
| 54 | + for (auto& type : unavailable_streams) |
| 55 | + { |
| 56 | + switch (type) |
| 57 | + { |
| 58 | + case RS2_STREAM_POSE: |
| 59 | + case RS2_STREAM_FISHEYE: |
| 60 | + std::cerr << "Connect T26X and rerun the demo" << std::endl; |
| 61 | + break; |
| 62 | + case RS2_STREAM_DEPTH: |
| 63 | + std::cerr << "The demo requires Realsense camera with DEPTH sensor" << std::endl; |
| 64 | + break; |
| 65 | + case RS2_STREAM_COLOR: |
| 66 | + std::cerr << "The demo requires Realsense camera with RGB sensor" << std::endl; |
| 67 | + break; |
| 68 | + default: |
| 69 | + throw std::runtime_error("The requested stream: " + std::to_string(type) + ", for the demo is not supported by connected devices!"); // stream type |
| 70 | + } |
| 71 | + } |
| 72 | + return false; |
| 73 | +} |
0 commit comments