uvc.h
Go to the documentation of this file.
00001 // License: Apache 2.0. See LICENSE file in root directory.
00002 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
00003 
00004 #pragma once
00005 #ifndef LIBREALSENSE_UVC_H
00006 #define LIBREALSENSE_UVC_H
00007 
00008 #include "types.h"
00009 
00010 #include <memory>       // For shared_ptr
00011 #include <functional>   // For function
00012 #include <thread>       // For this_thread::sleep_for
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; // Opaque type representing access to the underlying UVC implementation
00026         struct device;  // Opaque type representing access to a specific UVC device
00027 
00028         // Enumerate devices
00029         std::shared_ptr<context> create_context();
00030         std::vector<std::shared_ptr<device>> query_devices(std::shared_ptr<context> context);
00031 
00032         // Check for connected device
00033         bool is_device_connected(device & device, int vid, int pid);
00034 
00035         // Static device properties
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         // Direct USB controls
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         // Access CT (Camera Terminal) and PU (Processing Units) controls
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         // Access XU controls
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         // Control data channels
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         // Control streaming
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         // Access CT, PU, and XU controls, and retry if failure occurs
00071         inline void set_pu_control_with_retry(device & device, int subdevice, rs_option option, int value)
00072         {
00073             // Try writing a control, if it fails, retry several times
00074             // TODO: We may wish to tune the retry counts and sleep times based on camera, platform, firmware, etc.
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             // Try reading a control, if it fails, retry several times
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             // Try writing a control, if it fails, retry several times
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             // Try reading a control, if it fails, retry several times
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


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Tue Jun 25 2019 19:54:39