Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
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
14const uint16_t VID_INTEL_CAMERA = 0x8086;
15const uint16_t ZR300_CX3_PID = 0x0acb;
16const uint16_t ZR300_FISHEYE_PID = 0x0ad0;
17
18namespace rsimpl
19{
20 namespace uvc
21 {
22 struct guid { uint32_t data1; uint16_t data2, data3; uint8_t data4[8]; };
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
option
Defines general configuration controls.
Definition: rs.hpp:88
control
Definition: ds-private.h:260
bool is_pu_control(rs_option option)
Definition: uvc.h:46
void bulk_transfer(device &device, unsigned char endpoint, void *data, int length, int *actual_length, unsigned int timeout)
bool is_device_connected(device &device, int vid, int pid)
void set_subdevice_data_channel_handler(device &device, int subdevice_index, data_channel_callback callback)
void set_subdevice_mode(device &device, int subdevice_index, int width, int height, uint32_t fourcc, int fps, video_channel_callback callback)
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_control_with_retry(device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
Definition: uvc.h:94
void claim_aux_interface(device &device, const guid &interface_guid, int interface_number)
std::function< void(const unsigned char *data, const int size)> data_channel_callback
Definition: uvc.h:57
int get_product_id(const device &device)
void set_pu_control(device &device, int subdevice, rs_option option, int value)
std::vector< std::shared_ptr< device > > query_devices(std::shared_ptr< context > context)
void start_streaming(device &device, int num_transfer_bufs)
void stop_streaming(device &device)
void set_control(device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
void start_data_acquisition(device &device)
std::string get_usb_port_id(const device &device)
void get_control(const device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
std::shared_ptr< context > create_context()
int get_pu_control_with_retry(const device &device, int subdevice, rs_option option)
Definition: uvc.h:83
void get_pu_control_range(const device &device, int subdevice, rs_option option, int *min, int *max, int *step, int *def)
int get_vendor_id(const device &device)
std::function< void(const void *frame, std::function< void()> continuation)> video_channel_callback
Definition: uvc.h:64
void claim_interface(device &device, const guid &interface_guid, int interface_number)
void set_pu_control_with_retry(device &device, int subdevice, rs_option option, int value)
Definition: uvc.h:71
int get_pu_control(const device &device, int subdevice, rs_option option)
void stop_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)
Definition: archive.h:13
rs_option
Defines general configuration controls.
Definition: rs.h:129
@ RS_OPTION_COLOR_ENABLE_AUTO_WHITE_BALANCE
Definition: rs.h:141
Definition: uvc.h:23
int node
Definition: uvc.h:23
int unit
Definition: uvc.h:23
int subdevice
Definition: uvc.h:23
guid id
Definition: uvc.h:23
Definition: uvc.h:22
uint32_t data1
Definition: uvc.h:22
uint16_t data3
Definition: uvc.h:22
uint16_t data2
Definition: uvc.h:22
uint8_t data4[8]
Definition: uvc.h:22
const uint16_t ZR300_FISHEYE_PID
Definition: uvc.h:16
const uint16_t ZR300_CX3_PID
Definition: uvc.h:15
const uint16_t VID_INTEL_CAMERA
Definition: uvc.h:14