libuvc_internal.h
Go to the documentation of this file.
1 
5 #ifndef LIBUVC_INTERNAL_H
6 #define LIBUVC_INTERNAL_H
7 
8 #include <assert.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <pthread.h>
13 #include <signal.h>
14 #include "utlist.h"
15 
17 #define DW_TO_INT(p) ((p)[0] | ((p)[1] << 8) | ((p)[2] << 16) | ((p)[3] << 24))
18 
19 #define SW_TO_SHORT(p) ((p)[0] | ((p)[1] << 8))
20 
21 #define SHORT_TO_SW(s, p) \
22  (p)[0] = (s); \
23  (p)[1] = (s) >> 8;
24 
25 #define INT_TO_DW(i, p) \
26  (p)[0] = (i); \
27  (p)[1] = (i) >> 8; \
28  (p)[2] = (i) >> 16; \
29  (p)[3] = (i) >> 24;
30 
32 #define DL_NTH(head, out, n) \
33  do { \
34  int dl_nth_i = 0; \
35  LDECLTYPE(head) dl_nth_p = (head); \
36  if ((n) < 0) { \
37  while (dl_nth_p && dl_nth_i > (n)) { \
38  dl_nth_p = dl_nth_p->prev; \
39  dl_nth_i--; \
40  } \
41  } else { \
42  while (dl_nth_p && dl_nth_i < (n)) { \
43  dl_nth_p = dl_nth_p->next; \
44  dl_nth_i++; \
45  } \
46  } \
47  (out) = dl_nth_p; \
48  } while (0);
49 
50 #ifdef UVC_DEBUGGING
51 #include <libgen.h>
52 #define UVC_DEBUG(format, ...) fprintf(stderr, "[%s:%d/%s] " format "\n", basename(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
53 #define UVC_ENTER() fprintf(stderr, "[%s:%d] begin %s\n", basename(__FILE__), __LINE__, __FUNCTION__)
54 #define UVC_EXIT(code) fprintf(stderr, "[%s:%d] end %s (%d)\n", basename(__FILE__), __LINE__, __FUNCTION__, code)
55 #define UVC_EXIT_VOID() fprintf(stderr, "[%s:%d] end %s\n", basename(__FILE__), __LINE__, __FUNCTION__)
56 #else
57 #define UVC_DEBUG(format, ...)
58 #define UVC_ENTER()
59 #define UVC_EXIT_VOID()
60 #define UVC_EXIT(code)
61 #endif
62 
63 /* http://stackoverflow.com/questions/19452971/array-size-macro-that-rejects-pointers */
64 #define IS_INDEXABLE(arg) (sizeof(arg[0]))
65 #define IS_ARRAY(arg) (IS_INDEXABLE(arg) && (((void *) &arg) == ((void *) arg)))
66 #define ARRAYSIZE(arr) (sizeof(arr) / (IS_ARRAY(arr) ? sizeof(arr[0]) : 0))
67 
69 enum uvc_int_subclass_code {
70  UVC_SC_UNDEFINED = 0x00,
71  UVC_SC_VIDEOCONTROL = 0x01,
72  UVC_SC_VIDEOSTREAMING = 0x02,
73  UVC_SC_VIDEO_INTERFACE_COLLECTION = 0x03
74 };
75 
77 enum uvc_int_proto_code {
78  UVC_PC_PROTOCOL_UNDEFINED = 0x00
79 };
80 
82 enum uvc_vc_desc_subtype {
83  UVC_VC_DESCRIPTOR_UNDEFINED = 0x00,
84  UVC_VC_HEADER = 0x01,
85  UVC_VC_INPUT_TERMINAL = 0x02,
86  UVC_VC_OUTPUT_TERMINAL = 0x03,
87  UVC_VC_SELECTOR_UNIT = 0x04,
88  UVC_VC_PROCESSING_UNIT = 0x05,
89  UVC_VC_EXTENSION_UNIT = 0x06
90 };
91 
93 enum uvc_ep_desc_subtype {
94  UVC_EP_UNDEFINED = 0x00,
95  UVC_EP_GENERAL = 0x01,
96  UVC_EP_ENDPOINT = 0x02,
97  UVC_EP_INTERRUPT = 0x03
98 };
99 
101 enum uvc_vc_ctrl_selector {
102  UVC_VC_CONTROL_UNDEFINED = 0x00,
103  UVC_VC_VIDEO_POWER_MODE_CONTROL = 0x01,
104  UVC_VC_REQUEST_ERROR_CODE_CONTROL = 0x02
105 };
106 
108 enum uvc_term_ctrl_selector {
109  UVC_TE_CONTROL_UNDEFINED = 0x00
110 };
111 
113 enum uvc_su_ctrl_selector {
114  UVC_SU_CONTROL_UNDEFINED = 0x00,
115  UVC_SU_INPUT_SELECT_CONTROL = 0x01
116 };
117 
119 enum uvc_xu_ctrl_selector {
120  UVC_XU_CONTROL_UNDEFINED = 0x00
121 };
122 
124 enum uvc_vs_ctrl_selector {
125  UVC_VS_CONTROL_UNDEFINED = 0x00,
126  UVC_VS_PROBE_CONTROL = 0x01,
127  UVC_VS_COMMIT_CONTROL = 0x02,
128  UVC_VS_STILL_PROBE_CONTROL = 0x03,
129  UVC_VS_STILL_COMMIT_CONTROL = 0x04,
130  UVC_VS_STILL_IMAGE_TRIGGER_CONTROL = 0x05,
131  UVC_VS_STREAM_ERROR_CODE_CONTROL = 0x06,
132  UVC_VS_GENERATE_KEY_FRAME_CONTROL = 0x07,
133  UVC_VS_UPDATE_FRAME_SEGMENT_CONTROL = 0x08,
134  UVC_VS_SYNC_DELAY_CONTROL = 0x09
135 };
136 
138 enum uvc_status_type {
139  UVC_STATUS_TYPE_CONTROL = 1,
140  UVC_STATUS_TYPE_STREAMING = 2
141 };
142 
144 #define UVC_STREAM_EOH (1 << 7)
145 #define UVC_STREAM_ERR (1 << 6)
146 #define UVC_STREAM_STI (1 << 5)
147 #define UVC_STREAM_RES (1 << 4)
148 #define UVC_STREAM_SCR (1 << 3)
149 #define UVC_STREAM_PTS (1 << 2)
150 #define UVC_STREAM_EOF (1 << 1)
151 #define UVC_STREAM_FID (1 << 0)
152 
154 #define UVC_CONTROL_CAP_GET (1 << 0)
155 #define UVC_CONTROL_CAP_SET (1 << 1)
156 #define UVC_CONTROL_CAP_DISABLED (1 << 2)
157 #define UVC_CONTROL_CAP_AUTOUPDATE (1 << 3)
158 #define UVC_CONTROL_CAP_ASYNCHRONOUS (1 << 4)
159 
160 struct uvc_streaming_interface;
161 struct uvc_device_info;
162 
164 typedef struct uvc_streaming_interface {
165  struct uvc_device_info *parent;
166  struct uvc_streaming_interface *prev, *next;
168  uint8_t bInterfaceNumber;
170  struct uvc_format_desc *format_descs;
172  uint8_t bEndpointAddress;
173  uint8_t bTerminalLink;
174 } uvc_streaming_interface_t;
175 
177 typedef struct uvc_control_interface {
178  struct uvc_device_info *parent;
179  struct uvc_input_terminal *input_term_descs;
180  // struct uvc_output_terminal *output_term_descs;
181  struct uvc_processing_unit *processing_unit_descs;
182  struct uvc_extension_unit *extension_unit_descs;
183  uint16_t bcdUVC;
184  uint8_t bEndpointAddress;
186  uint8_t bInterfaceNumber;
187 } uvc_control_interface_t;
188 
189 struct uvc_stream_ctrl;
190 
191 struct uvc_device {
192  struct uvc_context *ctx;
193  int ref;
194  libusb_device *usb_dev;
195 };
196 
197 typedef struct uvc_device_info {
199  struct libusb_config_descriptor *config;
201  uvc_control_interface_t ctrl_if;
203  uvc_streaming_interface_t *stream_ifs;
204 
205  /* Store the interface for multiple UVCs on a single VID/PID device (Intel RealSense, VF200, e.g) */
206  int camera_number;
207 } uvc_device_info_t;
208 
209 /*
210  set a high number of transfer buffers. This uses a lot of ram, but
211  avoids problems with scheduling delays on slow boards causing missed
212  transfers. A better approach may be to make the transfer thread FIFO
213  scheduled (if we have root).
214  We could/should change this to allow reduce it to, say, 5 by default
215  and then allow the user to change the number of buffers as required.
216  */
217 #define LIBUVC_XFER_BUF_SIZE (64 * 1024 * 1024)
218 
219 struct uvc_stream_handle {
220  struct uvc_device_handle *devh;
221  struct uvc_stream_handle *prev, *next;
222  struct uvc_streaming_interface *stream_if;
223 
225  uint8_t running;
227  struct uvc_stream_ctrl cur_ctrl;
228 
229  /* listeners may only access hold*, and only when holding a
230  * lock on cb_mutex (probably signaled with cb_cond) */
231  uint8_t fid;
232  uint32_t seq, hold_seq;
233  uint32_t pts, hold_pts;
234  uint32_t last_scr, hold_last_scr;
235  size_t got_bytes, hold_bytes;
236  uint8_t *outbuf, *holdbuf;
237  pthread_mutex_t cb_mutex;
238  pthread_cond_t cb_cond;
239  pthread_t cb_thread;
240  uint32_t last_polled_seq;
241  uvc_frame_callback_t *user_cb;
242  void *user_ptr;
243  struct libusb_transfer **transfers; // num_transfer_bufs
244  uint8_t **transfer_bufs; // num_transfer_bufs
245  struct uvc_frame frame;
246  uint32_t fourcc;
247  int num_transfer_bufs;
248 };
249 
254 struct uvc_device_handle {
255  struct uvc_device *dev;
256  struct uvc_device_handle *prev, *next;
258  libusb_device_handle *usb_devh;
259  struct uvc_device_info *info;
260  struct libusb_transfer *status_xfer;
261  uint8_t status_buf[32];
263  uvc_status_callback_t *status_cb;
264  void *status_user_ptr;
265 
266  uvc_stream_handle_t *streams;
268  uint8_t is_isight;
269 };
270 
272 struct uvc_context {
274  struct libusb_context *usb_ctx;
276  uint8_t own_usb_ctx;
278  uvc_device_handle_t *open_devices;
279  pthread_t handler_thread;
280  uint8_t kill_handler_thread;
281 };
282 
284  uvc_device_handle_t *devh,
285  uvc_stream_ctrl_t *ctrl,
286  uint8_t probe,
287  enum uvc_req_code req);
288 
292 
293 #endif // !def(LIBUVC_INTERNAL_H)
294 
uvc_req_code
Definition: libuvc.h:152
uvc_error_t uvc_query_stream_ctrl(uvc_device_handle_t *devh, uvc_stream_ctrl_t *ctrl, uint8_t probe, enum uvc_req_code req)
Definition: stream.c:91
enum uvc_error uvc_error_t
Definition: context.cpp:26
void config(uvc::device &device, uint8_t gyro_bw, uint8_t gyro_range, uint8_t accel_bw, uint8_t accel_range, uint32_t time_seed)
void( uvc_status_callback_t)(enum uvc_status_class status_class, int event, int selector, enum uvc_status_attribute status_attribute, void *data, size_t data_len, void *user_ptr)
Definition: libuvc.h:335
GLenum GLint ref
Definition: glext.h:652
uint32_t fourcc
Definition: libuvc.h:374
uvc_error_t uvc_claim_if(uvc_device_handle_t *devh, int idx)
Definition: dev.c:782
struct uvc_stream_handle uvc_stream_handle_t
Definition: libuvc.h:276
auto ctx
void uvc_start_handler_thread(uvc_context_t *ctx)
struct uvc_context uvc_context_t
Definition: libuvc.h:253
rs_device * dev
struct uvc_device_handle uvc_device_handle_t
Definition: libuvc.h:268
void( uvc_frame_callback_t)(struct uvc_frame *frame, void *user_ptr)
Definition: libuvc.h:396
uvc_error_t uvc_release_if(uvc_device_handle_t *devh, int idx)
Definition: dev.c:810


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