uvc.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 #ifndef LIBREALSENSE_UVC_H
6 #define LIBREALSENSE_UVC_H
7 
8 #include "types.h"
9 
10 #include <memory> // For shared_ptr
11 #include <functional> // For function
12 #include <thread> // For this_thread::sleep_for
13 
14 const uint16_t VID_INTEL_CAMERA = 0x8086;
15 const uint16_t ZR300_CX3_PID = 0x0acb;
16 const uint16_t ZR300_FISHEYE_PID = 0x0ad0;
17 
18 namespace rsimpl
19 {
20  namespace uvc
21  {
22  struct guid { uint32_t data1; uint16_t data2, data3; uint8_t data4[8]; };
23  struct extension_unit { int subdevice, unit, node; guid id; };
24 
25  struct context; // Opaque type representing access to the underlying UVC implementation
26  struct device; // Opaque type representing access to a specific UVC device
27 
28  // Enumerate devices
29  std::shared_ptr<context> create_context();
30  std::vector<std::shared_ptr<device>> query_devices(std::shared_ptr<context> context);
31 
32  // Check for connected device
33  bool is_device_connected(device & device, int vid, int pid);
34 
35  // Static device properties
36  int get_vendor_id(const device & device);
37  int get_product_id(const device & device);
38  std::string get_usb_port_id(const device & device);
39 
40  // Direct USB controls
41  void claim_interface(device & device, const guid & interface_guid, int interface_number);
42  void claim_aux_interface(device & device, const guid & interface_guid, int interface_number);
43  void bulk_transfer(device & device, unsigned char endpoint, void * data, int length, int *actual_length, unsigned int timeout);
44 
45  // Access CT (Camera Terminal) and PU (Processing Units) controls
47  void get_pu_control_range(const device & device, int subdevice, rs_option option, int * min, int * max, int * step, int * def);
48  void get_extension_control_range(const device & device, const extension_unit & xu, char control, int * min, int * max, int * step, int * def);
49  void set_pu_control(device & device, int subdevice, rs_option option, int value);
50  int get_pu_control(const device & device, int subdevice, rs_option option);
51 
52  // Access XU controls
53  void set_control(device & device, const extension_unit & xu, uint8_t ctrl, void * data, int len);
54  void get_control(const device & device, const extension_unit & xu, uint8_t ctrl, void * data, int len);
55 
56  // Control data channels
57  typedef std::function<void(const unsigned char * data, const int size)> data_channel_callback;
58 
59  void set_subdevice_data_channel_handler(device & device, int subdevice_index, data_channel_callback callback);
60  void start_data_acquisition(device & device);
61  void stop_data_acquisition(device & device);
62 
63  // Control streaming
64  typedef std::function<void(const void * frame, std::function<void()> continuation)> video_channel_callback;
65 
66  void set_subdevice_mode(device & device, int subdevice_index, int width, int height, uint32_t fourcc, int fps, video_channel_callback callback);
67  void start_streaming(device & device, int num_transfer_bufs);
68  void stop_streaming(device & device);
69 
70  // Access CT, PU, and XU controls, and retry if failure occurs
71  inline void set_pu_control_with_retry(device & device, int subdevice, rs_option option, int value)
72  {
73  // Try writing a control, if it fails, retry several times
74  // TODO: We may wish to tune the retry counts and sleep times based on camera, platform, firmware, etc.
75  for(int i=0; i<20; ++i)
76  {
77  try { set_pu_control(device, subdevice, option, value); return; }
78  catch(...) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); }
79  }
80  set_pu_control(device, subdevice, option, value);
81  }
82 
83  inline int get_pu_control_with_retry(const device & device, int subdevice, rs_option option)
84  {
85  // Try reading a control, if it fails, retry several times
86  for(int i=0; i<20; ++i)
87  {
88  try { return get_pu_control(device, subdevice, option); }
89  catch(...) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); }
90  }
91  return get_pu_control(device, subdevice, option);
92  }
93 
94  inline void set_control_with_retry(device & device, const extension_unit & xu, uint8_t ctrl, void * data, int len)
95  {
96  // Try writing a control, if it fails, retry several times
97  for(int i=0; i<20; ++i)
98  {
99  try { set_control(device, xu, ctrl, data, len); return; }
100  catch(...) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); }
101  }
102  set_control(device, xu, ctrl, data, len);
103  }
104 
105  inline void get_control_with_retry(const device & device, const extension_unit & xu, uint8_t ctrl, void * data, int len)
106  {
107  // Try reading a control, if it fails, retry several times
108  for(int i=0; i<20; ++i)
109  {
110  try { get_control(device, xu, ctrl, data, len); return; }
111  catch(...) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); }
112  }
113  get_control(device, xu, ctrl, data, len);
114  }
115  }
116 }
117 
118 #endif
std::shared_ptr< context > create_context()
uint32_t data1
Definition: uvc.h:22
void get_pu_control_range(const device &device, int subdevice, rs_option option, int *min, int *max, int *step, int *def)
void claim_aux_interface(device &device, const guid &interface_guid, int interface_number)
void set_subdevice_mode(device &device, int subdevice_index, int width, int height, uint32_t fourcc, int fps, video_channel_callback callback)
GLint GLint GLsizei GLsizei height
Definition: glext.h:112
bool is_device_connected(device &device, int vid, int pid)
const uint16_t VID_INTEL_CAMERA
Definition: uvc.h:14
GLsizei const GLchar *const * string
Definition: glext.h:683
Definition: archive.h:12
uint16_t data3
Definition: uvc.h:22
rs_option
Defines general configuration controls.
Definition: rs.h:128
GLbitfield GLuint64 timeout
Definition: glext.h:1481
std::string get_usb_port_id(const device &device)
const uint16_t ZR300_FISHEYE_PID
Definition: uvc.h:16
std::function< void(const unsigned char *data, const int size)> data_channel_callback
Definition: uvc.h:57
GLenum GLsizei len
Definition: glext.h:3213
void get_control_with_retry(const device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
Definition: uvc.h:105
void set_subdevice_data_channel_handler(device &device, int subdevice_index, data_channel_callback callback)
void start_streaming(device &device, int num_transfer_bufs)
void start_data_acquisition(device &device)
void get_extension_control_range(const device &device, const extension_unit &xu, char control, int *min, int *max, int *step, int *def)
uint8_t data4[8]
Definition: uvc.h:22
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
Definition: glext.h:223
void stop_streaming(device &device)
uint16_t data2
Definition: uvc.h:22
GLsizei const GLfloat * value
Definition: glext.h:693
const uint16_t ZR300_CX3_PID
Definition: uvc.h:15
void claim_interface(device &device, const guid &interface_guid, int interface_number)
int get_pu_control(const device &device, int subdevice, rs_option option)
int get_product_id(const device &device)
void set_pu_control_with_retry(device &device, int subdevice, rs_option option, int value)
Definition: uvc.h:71
GLuint id
Definition: glext.h:523
void bulk_transfer(device &device, unsigned char endpoint, void *data, int length, int *actual_length, unsigned int timeout)
GLint GLint GLsizei width
Definition: glext.h:112
void set_control(device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
void set_control_with_retry(device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
Definition: uvc.h:94
std::vector< std::shared_ptr< device > > query_devices(std::shared_ptr< context > context)
GLuint GLsizei GLsizei * length
Definition: glext.h:664
void set_pu_control(device &device, int subdevice, rs_option option, int value)
int get_pu_control_with_retry(const device &device, int subdevice, rs_option option)
Definition: uvc.h:83
bool is_pu_control(rs_option option)
Definition: uvc.h:46
void get_control(const device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
void stop_data_acquisition(device &device)
std::function< void(const void *frame, std::function< void()> continuation)> video_channel_callback
Definition: uvc.h:64
int get_vendor_id(const device &device)


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:18