6 #define UVC_AE_MODE_D0_MANUAL ( 1 << 0 ) 7 #define UVC_AE_MODE_D1_AUTO ( 1 << 1 ) 8 #define UVC_AE_MODE_D2_SP ( 1 << 2 ) 9 #define UVC_AE_MODE_D3_AP ( 1 << 3 ) 11 #define SWAP_UINT32(x) (((x) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | ((x) << 24)) 29 static std::recursive_mutex
m;
42 std::vector<platform::uvc_device_info> rv;
43 auto usb_devices = platform::usb_enumerator::query_devices_info();
44 for (
auto&&
info : usb_devices)
57 rv.push_back(device_info);
64 auto devices = usb_enumerator::query_devices_info();
67 if(usb_info.id != info.
id)
70 auto dev = usb_enumerator::create_usb_device(usb_info);
72 return std::make_shared<rs_uvc_device>(
dev,
info);
79 _usb_device(usb_device),
81 _action_dispatcher(10),
82 _usb_request_count(usb_request_count)
84 _parser = std::make_shared<uvc_parser>(usb_device,
info);
94 LOG_WARNING(
"rs_uvc_device failed to switch power state on destructor");
102 throw std::runtime_error(
"Device is already streaming!");
111 throw std::runtime_error(
"Stream not configured");
114 throw std::runtime_error(
"Device is already streaming!");
138 s->enable_user_callbacks();
144 s->disable_user_callbacks();
155 return (pac.profile == profile && (pac.callback));
159 throw std::runtime_error(
"Camera is not streaming!");
181 }
catch(
const std::exception& exception) {
183 LOG_WARNING(
"rs_uvc_device exception in listen_to_interrupts method: " << exception.what());
201 throw std::runtime_error(
"failed to set power state");
235 throw std::runtime_error(
"uvc_get_ctrl(UVC_GET_MAX) failed");
240 throw std::runtime_error(
"uvc_get_ctrl(UVC_GET_MIN) failed");
245 throw std::runtime_error(
"uvc_get_ctrl(UVC_GET_RES) failed");
250 throw std::runtime_error(
"uvc_get_ctrl(UVC_GET_DEF) failed");
282 int min, max, step, def;
304 std::vector<stream_profile> results;
310 throw std::runtime_error(
"Device must be powered to query supported profiles!");
315 for(
auto&&
f : formats)
322 results.push_back(sp);
361 translated_value = 1;
364 translated_value = 0;
367 throw std::runtime_error(
368 "Unsupported GET value for RS2_OPTION_ENABLE_AUTO_EXPOSURE");
385 throw std::runtime_error(
386 "Unsupported SET value for RS2_OPTION_ENABLE_AUTO_EXPOSURE");
393 translated_value = 0;
399 translated_value = 1;
405 translated_value = 1;
411 translated_value = 1;
416 throw std::runtime_error(
"Unsupported action translation");
418 return translated_value;
422 bool foundFormat =
false;
428 for(
auto&&
f : formats)
430 if ((profile.
format ==
f.fourcc) &&
431 (profile.
fps ==
f.fps) &&
432 (profile.
height ==
f.height) &&
433 (profile.
width ==
f.width)) {
440 if (foundFormat ==
false) {
441 throw std::runtime_error(
"Failed to find supported format!");
444 auto ctrl = std::make_shared<uvc_stream_ctrl_t>();
447 throw std::runtime_error(
"Failed to get control format size!");
452 throw std::runtime_error(
"Failed to start streaming!");
456 auto streamer = std::make_shared<uvc_streamer>(usc);
467 std::vector<profile_and_callback>::iterator &elem) {
469 elem->callback =
nullptr;
470 elem->profile.format = 0;
471 elem->profile.fps = 0;
472 elem->profile.width = 0;
473 elem->profile.height = 0;
485 unsigned int length)
const {
486 unsigned char buffer[4] = {0};
511 if (transferred !=
sizeof(
int32_t))
512 throw std::runtime_error(
"insufficient data read from USB");
526 throw std::runtime_error(
"unsupported length");
535 unit =
_parser->get_processing_unit().bUnitID;
544 unit =
_parser->get_input_terminal().bTerminalID;
559 unit =
_parser->get_input_terminal().bTerminalID;
566 unit =
_parser->get_input_terminal().bTerminalID;
601 if (transferred !=
sizeof(
int32_t))
602 throw std::runtime_error(
"insufficient data writen to USB");
617 static_cast<unsigned char *>(data),
623 throw std::runtime_error(
"usb device disconnected");
640 static_cast<unsigned char *>(data),
646 throw std::runtime_error(
"usb device disconnected");
664 if (response->get_actual_length() > 0)
667 for (
int i = 0;
i < response->get_actual_length();
i++)
669 LOG_DEBUG(
"interrupt event received: " << buff.c_str());
683 auto sts =
_messenger->submit_request(_interrupt_request);
685 throw std::runtime_error(
"failed to submit interrupt request, error: " +
usb_status_to_string.at(sts));
719 std::vector<uvc_format_t> rv;
720 for(
auto&&
s :
_parser->get_formats())
728 cur_format.width =
fd.wWidth;
731 cur_format.interfaceNumber =
s.first;
733 for(
auto&&
i :
fd.intervals)
737 cur_format.fps = 10000000 /
i;
738 rv.push_back(cur_format);
748 for(
auto&&
s :
_parser->get_formats())
750 for(
auto&& curr_format :
s.second)
759 for(
auto&&
fd : curr_format.frame_descs)
764 for(
auto&&
i :
fd.intervals)
766 if (10000000 /
i == (
unsigned int) format.
fps || format.
fps == 0) {
770 control->bInterfaceNumber =
s.first;
775 control->bmHint = (1 << 0);
776 control->bFormatIndex = curr_format.bFormatIndex;
777 control->bFrameIndex =
fd.bFrameIndex;
778 control->dwFrameInterval =
i;
794 memset(buf, 0,
sizeof(buf));
795 switch (
_parser->get_bcd_uvc()) {
810 buf[2] = ctrl->bFormatIndex;
811 buf[3] = ctrl->bFrameIndex;
812 INT_TO_DW(ctrl->dwFrameInterval, buf + 4);
818 INT_TO_DW(ctrl->dwMaxVideoFrameSize, buf + 18);
819 INT_TO_DW(ctrl->dwMaxPayloadTransferSize, buf + 22);
824 INT_TO_DW(ctrl->dwClockFrequency, buf + 26);
825 buf[30] = ctrl->bmFramingInfo;
826 buf[31] = ctrl->bPreferredVersion;
827 buf[32] = ctrl->bMinVersion;
828 buf[33] = ctrl->bMaxVersion;
833 buf[34] = ctrl->bUsage;
834 buf[35] = ctrl->bBitDepthLuma;
835 buf[36] = ctrl->bmSettings;
836 buf[37] = ctrl->bMaxNumberOfRefFramesPlus1;
838 QUAD_TO_QW(ctrl->bmLayoutPerStream, buf + 40);
854 ctrl->bInterfaceNumber,
855 buf, len, transferred, 0);
869 ctrl->bFormatIndex = buf[2];
870 ctrl->bFrameIndex = buf[3];
871 ctrl->dwFrameInterval =
DW_TO_INT(buf + 4);
877 ctrl->dwMaxVideoFrameSize =
DW_TO_INT(buf + 18);
878 ctrl->dwMaxPayloadTransferSize =
DW_TO_INT(buf + 22);
881 ctrl->dwClockFrequency =
DW_TO_INT(buf + 26);
882 ctrl->bmFramingInfo = buf[30];
883 ctrl->bPreferredVersion = buf[31];
884 ctrl->bMinVersion = buf[32];
885 ctrl->bMaxVersion = buf[33];
890 ctrl->bUsage = buf[34];
891 ctrl->bBitDepthLuma = buf[35];
892 ctrl->bmSettings = buf[36];
893 ctrl->bMaxNumberOfRefFramesPlus1 = buf[37];
894 ctrl->bmRateControlModes =
DW_TO_INT(buf + 38);
895 ctrl->bmLayoutPerStream =
QW_TO_QUAD(buf + 40);
898 ctrl->dwClockFrequency =
_parser->get_clock_frequency();
906 for (
auto&& usb_info :
devices)
911 throw std::runtime_error(
"Camera is no longer connected!");
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
static std::recursive_mutex m
#define UVC_AE_MODE_D0_MANUAL
const int FIRST_FRAME_MILLISECONDS_TIMEOUT
GLsizei const GLchar *const * string
status
Defines return codes that SDK interfaces use. Negative values indicate errors, a zero value indicates...
#define UVC_AE_MODE_D3_AP
GLenum GLuint GLenum GLsizei const GLchar * buf
def info(name, value, persistent=False)
const std::unordered_map< uint32_t, uint32_t > fourcc_map
const int INTERRUPT_BUFFER_SIZE
GLint GLint GLsizei GLint GLenum format
const base::type::char_t * unit
#define SHORT_TO_SW(s, p)
const int CONTROL_TRANSFER_TIMEOUT
void invoke(T item, bool is_blocking=false)
GLenum GLuint GLenum GLsizei length
static lock_singleton & instance()
void invoke_and_wait(T item, std::function< bool()> exit_condition, bool is_blocking=false)
std::string to_string(T value)