00001
00002
00003
00004 #pragma once
00005 #ifndef LIBREALSENSE_UVC_H
00006 #define LIBREALSENSE_UVC_H
00007
00008 #include "types.h"
00009
00010 #include <memory>
00011 #include <functional>
00012 #include <thread>
00013
00014 const uint16_t VID_INTEL_CAMERA = 0x8086;
00015 const uint16_t ZR300_CX3_PID = 0x0acb;
00016 const uint16_t ZR300_FISHEYE_PID = 0x0ad0;
00017
00018 namespace rsimpl
00019 {
00020 namespace uvc
00021 {
00022 struct guid { uint32_t data1; uint16_t data2, data3; uint8_t data4[8]; };
00023 struct extension_unit { int subdevice, unit, node; guid id; };
00024
00025 struct context;
00026 struct device;
00027
00028
00029 std::shared_ptr<context> create_context();
00030 std::vector<std::shared_ptr<device>> query_devices(std::shared_ptr<context> context);
00031
00032
00033 bool is_device_connected(device & device, int vid, int pid);
00034
00035
00036 int get_vendor_id(const device & device);
00037 int get_product_id(const device & device);
00038 std::string get_usb_port_id(const device & device);
00039
00040
00041 void claim_interface(device & device, const guid & interface_guid, int interface_number);
00042 void claim_aux_interface(device & device, const guid & interface_guid, int interface_number);
00043 void bulk_transfer(device & device, unsigned char endpoint, void * data, int length, int *actual_length, unsigned int timeout);
00044
00045
00046 inline bool is_pu_control(rs_option option) { return option <= RS_OPTION_COLOR_ENABLE_AUTO_WHITE_BALANCE; }
00047 void get_pu_control_range(const device & device, int subdevice, rs_option option, int * min, int * max, int * step, int * def);
00048 void get_extension_control_range(const device & device, const extension_unit & xu, char control, int * min, int * max, int * step, int * def);
00049 void set_pu_control(device & device, int subdevice, rs_option option, int value);
00050 int get_pu_control(const device & device, int subdevice, rs_option option);
00051
00052
00053 void set_control(device & device, const extension_unit & xu, uint8_t ctrl, void * data, int len);
00054 void get_control(const device & device, const extension_unit & xu, uint8_t ctrl, void * data, int len);
00055
00056
00057 typedef std::function<void(const unsigned char * data, const int size)> data_channel_callback;
00058
00059 void set_subdevice_data_channel_handler(device & device, int subdevice_index, data_channel_callback callback);
00060 void start_data_acquisition(device & device);
00061 void stop_data_acquisition(device & device);
00062
00063
00064 typedef std::function<void(const void * frame, std::function<void()> continuation)> video_channel_callback;
00065
00066 void set_subdevice_mode(device & device, int subdevice_index, int width, int height, uint32_t fourcc, int fps, video_channel_callback callback);
00067 void start_streaming(device & device, int num_transfer_bufs);
00068 void stop_streaming(device & device);
00069
00070
00071 inline void set_pu_control_with_retry(device & device, int subdevice, rs_option option, int value)
00072 {
00073
00074
00075 for(int i=0; i<20; ++i)
00076 {
00077 try { set_pu_control(device, subdevice, option, value); return; }
00078 catch(...) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); }
00079 }
00080 set_pu_control(device, subdevice, option, value);
00081 }
00082
00083 inline int get_pu_control_with_retry(const device & device, int subdevice, rs_option option)
00084 {
00085
00086 for(int i=0; i<20; ++i)
00087 {
00088 try { return get_pu_control(device, subdevice, option); }
00089 catch(...) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); }
00090 }
00091 return get_pu_control(device, subdevice, option);
00092 }
00093
00094 inline void set_control_with_retry(device & device, const extension_unit & xu, uint8_t ctrl, void * data, int len)
00095 {
00096
00097 for(int i=0; i<20; ++i)
00098 {
00099 try { set_control(device, xu, ctrl, data, len); return; }
00100 catch(...) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); }
00101 }
00102 set_control(device, xu, ctrl, data, len);
00103 }
00104
00105 inline void get_control_with_retry(const device & device, const extension_unit & xu, uint8_t ctrl, void * data, int len)
00106 {
00107
00108 for(int i=0; i<20; ++i)
00109 {
00110 try { get_control(device, xu, ctrl, data, len); return; }
00111 catch(...) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); }
00112 }
00113 get_control(device, xu, ctrl, data, len);
00114 }
00115 }
00116 }
00117
00118 #endif