uvc-libuvc.cpp
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 #ifdef RS_USE_LIBUVC_BACKEND
5 
6 //#define ENABLE_DEBUG_SPAM
7 
8 #include "uvc.h"
9 #include "libuvc/libuvc.h"
10 #include "libuvc/libuvc_internal.h" // For LibUSB punchthrough
11 #include <thread>
12 
13 namespace rsimpl
14 {
15  namespace uvc
16  {
17  static void check(const char * call, uvc_error_t status)
18  {
19  if (status < 0) throw std::runtime_error(to_string() << call << "(...) returned " << uvc_strerror(status));
20  }
21  #define CALL_UVC(name, ...) check(#name, name(__VA_ARGS__))
22 
23  struct context
24  {
26  libusb_context * usb_context;
27 
28  context() : ctx()
29  {
30  check("uvc_init", uvc_init(&ctx, nullptr));
31 
32  int status = libusb_init(&usb_context);
33  if (status < 0) throw std::runtime_error(to_string() << "libusb_init(...) returned " << libusb_error_name(status));
34  }
35  ~context()
36  {
37  libusb_exit(usb_context);
38  if (ctx) uvc_exit(ctx);
39  }
40  };
41 
42  struct subdevice
43  {
44  uvc_device_handle_t * handle = nullptr;
45  uvc_stream_ctrl_t ctrl;
46  uint8_t unit;
47  video_channel_callback callback = nullptr;
48  data_channel_callback channel_data_callback = nullptr;
49 
50  void set_data_channel_cfg(data_channel_callback callback)
51  {
52  this->channel_data_callback = callback;
53  }
54 
55  static void poll_interrupts(libusb_device_handle *handle, const std::vector<subdevice *> & subdevices, uint16_t timeout)
56  {
57  static const unsigned short interrupt_buf_size = 0x400;
58  uint8_t buffer[interrupt_buf_size]; /* 64 byte transfer buffer - dedicated channel */
59  int num_bytes = 0; /* Actual bytes transferred */
60 
61  // TODO - replace hard-coded values : 0x82 and 1000
62  int res = libusb_interrupt_transfer(handle, 0x84, buffer, interrupt_buf_size, &num_bytes, timeout);
63  if (0 == res)
64  {
65  // Propagate the data to device layer
66  for (auto & sub : subdevices)
67  if (sub->channel_data_callback)
68  sub->channel_data_callback(buffer, num_bytes);
69  }
70  else
71  {
72  if (res == LIBUSB_ERROR_TIMEOUT)
73  LOG_WARNING("interrupt e.p. timeout");
74  else
75  throw std::runtime_error(to_string() << "USB Interrupt end-point error " << libusb_strerror((libusb_error)res));
76  }
77  }
78 
79  };
80 
81  struct device
82  {
83  const std::shared_ptr<context> parent;
84  uvc_device_t * uvcdevice;
85  int vid, pid;
86  std::vector<subdevice> subdevices;
87  std::vector<int> claimed_interfaces;
88 
89  std::thread data_channel_thread;
90  volatile bool data_stop;
91 
92 
93  std::shared_ptr<device> aux_device;
94 
95  libusb_device_handle * usb_handle;
96 
97  device(std::shared_ptr<context> parent, uvc_device_t * uvcdevice) : parent(parent), uvcdevice(uvcdevice), usb_handle()
98  {
99  get_subdevice(0);
100 
102  CALL_UVC(uvc_get_device_descriptor, uvcdevice, &desc);
103  vid = desc->idVendor;
104  pid = desc->idProduct;
106  }
107  ~device()
108  {
109  for(auto interface_number : claimed_interfaces)
110  {
111  int status = libusb_release_interface(get_subdevice(0).handle->usb_devh, interface_number);
112  if(status < 0) LOG_ERROR("libusb_release_interface(...) returned " << libusb_error_name(status));
113  }
114 
115  for(auto & sub : subdevices) if(sub.handle) uvc_close(sub.handle);
116  if(claimed_interfaces.size()) if(uvcdevice) uvc_unref_device(uvcdevice);
117  }
118 
119  subdevice & get_subdevice(int subdevice_index)
120  {
121  if (subdevice_index >= subdevices.size()) subdevices.resize(subdevice_index + 1);
122 
123  if (subdevice_index == 3 && aux_device)
124  {
125  auto& sub = aux_device->get_subdevice(0);
126  subdevices[subdevice_index] = sub;
127  return sub;
128  }
129 
130  if (!subdevices[subdevice_index].handle) check("uvc_open2", uvc_open2(uvcdevice, &subdevices[subdevice_index].handle, subdevice_index));
131  return subdevices[subdevice_index];
132  }
133 
135  {
136  data_stop = false;
137  std::vector<subdevice *> data_channel_subs;
138  for (auto & sub : subdevices)
139  {
140  if (sub.channel_data_callback)
141  {
142  data_channel_subs.push_back(&sub);
143  }
144  }
145 
146  // Motion events polling pipe
147  if (claimed_interfaces.size())
148  {
149  data_channel_thread = std::thread([this, data_channel_subs]()
150  {
151  // Polling 100ms timeout
152  while (!data_stop)
153  {
154  subdevice::poll_interrupts(this->usb_handle, data_channel_subs, 100);
155  }
156  });
157  }
158  }
159 
160  void stop_data_acquisition()
161  {
162  if (data_channel_thread.joinable())
163  {
164  data_stop = true;
165  data_channel_thread.join();
166  data_stop = false;
167  }
168  }
169  };
170 
172  // device //
174 
175  int get_vendor_id(const device & device) { return device.vid; }
176  int get_product_id(const device & device) { return device.pid; }
177 
178  std::string get_usb_port_id(const device & device)
179  {
180  std::string usb_port = std::to_string(libusb_get_bus_number(device.uvcdevice->usb_dev)) + "-" +
181  std::to_string(libusb_get_port_number(device.uvcdevice->usb_dev));
182  return usb_port;
183  }
184 
185  void get_control(const device & dev, const extension_unit & xu, uint8_t ctrl, void * data, int len)
186  {
187  int status = uvc_get_ctrl(const_cast<device &>(dev).get_subdevice(xu.subdevice).handle, xu.unit, ctrl, data, len, UVC_GET_CUR);
188  if(status < 0) throw std::runtime_error(to_string() << "uvc_get_ctrl(...) returned " << libusb_error_name(status));
189  }
190 
191  void set_control(device & device, const extension_unit & xu, uint8_t ctrl, void * data, int len)
192  {
193  int status = uvc_set_ctrl(device.get_subdevice(xu.subdevice).handle, xu.unit, ctrl, data, len);
194  if(status < 0) throw std::runtime_error(to_string() << "uvc_set_ctrl(...) returned " << libusb_error_name(status));
195  }
196 
197  void claim_interface(device & device, const guid & interface_guid, int interface_number)
198  {
199  libusb_device_handle* dev_h = nullptr;
200 
201  if (device.pid == ZR300_CX3_PID)
202  {
203  dev_h = device.usb_handle;
204  }
205  else
206  {
207  dev_h = device.get_subdevice(0).handle->usb_devh;
208  }
209  int status = libusb_claim_interface(dev_h, interface_number);
210  if (status < 0) throw std::runtime_error(to_string() << "libusb_claim_interface(...) returned " << libusb_error_name(status));
211  device.claimed_interfaces.push_back(interface_number);
212  }
213 
214  void claim_aux_interface(device & device, const guid & interface_guid, int interface_number)
215  {
216  claim_interface(device, interface_guid, interface_number);
217  }
218 
219  void bulk_transfer(device & device, unsigned char endpoint, void * data, int length, int *actual_length, unsigned int timeout)
220  {
221 
222  libusb_device_handle* dev_h = nullptr;
223 
224  if (device.pid == ZR300_CX3_PID) // W/A for ZR300 fish-eye
225  {
226  dev_h = device.usb_handle;
227  }
228  else
229  {
230  dev_h = device.get_subdevice(0).handle->usb_devh;
231  }
232 
233  int status = libusb_bulk_transfer(dev_h, endpoint, (unsigned char *)data, length, actual_length, timeout);
234 
235  if (status < 0) throw std::runtime_error(to_string() << "libusb_bulk_transfer(...) returned " << libusb_error_name(status));
236 
237  }
238 
239  void set_subdevice_mode(device & device, int subdevice_index, int width, int height, uint32_t fourcc, int fps, video_channel_callback callback)
240  {
241  auto & sub = device.get_subdevice(subdevice_index);
242  check("get_stream_ctrl_format_size", uvc_get_stream_ctrl_format_size(sub.handle, &sub.ctrl, reinterpret_cast<const big_endian<uint32_t> &>(fourcc), width, height, fps));
243  sub.callback = callback;
244  }
245 
246  void set_subdevice_data_channel_handler(device & device, int subdevice_index, data_channel_callback callback)
247  {
248  device.subdevices[subdevice_index].set_data_channel_cfg(callback);
249  }
250 
251  void start_streaming(device & device, int num_transfer_bufs)
252  {
253  for(auto i = 0; i < device.subdevices.size(); i++)
254  {
255  auto& sub = device.get_subdevice(i);
256  if (sub.callback)
257  {
258  #if defined (ENABLE_DEBUG_SPAM)
259  uvc_print_stream_ctrl(&sub.ctrl, stdout);
260  #endif
261 
262  check("uvc_start_streaming", uvc_start_streaming(sub.handle, &sub.ctrl, [](uvc_frame * frame, void * user)
263  {
264  reinterpret_cast<subdevice *>(user)->callback(frame->data, []{});
265  }, &sub, 0, num_transfer_bufs));
266  }
267  }
268  }
269 
270  void stop_streaming(device & device)
271  {
272  // Stop all streaming
273  for(auto & sub : device.subdevices)
274  {
275  if(sub.handle) uvc_stop_streaming(sub.handle);
276  sub.ctrl = {};
277  sub.callback = {};
278  }
279  }
280 
281  void start_data_acquisition(device & device)
282  {
283  device.start_data_acquisition();
284  }
285 
286  void stop_data_acquisition(device & device)
287  {
288  device.stop_data_acquisition();
289  }
290 
291  template<class T> void set_pu(uvc_device_handle_t * devh, int subdevice, uint8_t unit, uint8_t control, int value)
292  {
293  const int REQ_TYPE_SET = 0x21;
294  unsigned char buffer[4];
295  if(sizeof(T)==1) buffer[0] = value;
296  if(sizeof(T)==2) SHORT_TO_SW(value, buffer);
297  if(sizeof(T)==4) INT_TO_DW(value, buffer);
298  int status = libusb_control_transfer(devh->usb_devh, REQ_TYPE_SET, UVC_SET_CUR, control << 8, unit << 8 | (subdevice * 2), buffer, sizeof(T), 0);
299  if(status < 0) throw std::runtime_error(to_string() << "libusb_control_transfer(...) returned " << libusb_error_name(status));
300  if(status != sizeof(T)) throw std::runtime_error("insufficient data written to usb");
301  }
302 
303  template<class T> int get_pu(uvc_device_handle_t * devh, int subdevice, uint8_t unit, uint8_t control, int uvc_get_thing)
304  {
305  const int REQ_TYPE_GET = 0xa1;
306  unsigned char buffer[4];
307  int status = libusb_control_transfer(devh->usb_devh, REQ_TYPE_GET, uvc_get_thing, control << 8, unit << 8 | (subdevice * 2), buffer, sizeof(T), 0);
308  if(status < 0) throw std::runtime_error(to_string() << "libusb_control_transfer(...) returned " << libusb_error_name(status));
309  if(status != sizeof(T)) throw std::runtime_error("insufficient data read from usb");
310  if(sizeof(T)==1) return buffer[0];
311  if(sizeof(T)==2) return SW_TO_SHORT(buffer);
312  if(sizeof(T)==4) return DW_TO_INT(buffer);
313  }
314  template<class T> void get_pu_range(uvc_device_handle_t * devh, int subdevice, uint8_t unit, uint8_t control, int * min, int * max, int * step, int * def)
315  {
316  if(min) *min = get_pu<T>(devh, subdevice, unit, control, UVC_GET_MIN);
317  if(max) *max = get_pu<T>(devh, subdevice, unit, control, UVC_GET_MAX);
318  if(step) *step = get_pu<T>(devh, subdevice, unit, control, UVC_GET_RES);
319  if(def) *def = get_pu<T>(devh, subdevice, unit, control, UVC_GET_DEF);
320  }
321 
322  void get_pu_control_range(const device & device, int subdevice, rs_option option, int * min, int * max, int * step, int * def)
323  {
324  auto handle = const_cast<uvc::device &>(device).get_subdevice(subdevice).handle;
325  int ct_unit = 0, pu_unit = 0;
326  for(auto ct = uvc_get_input_terminals(handle); ct; ct = ct->next) ct_unit = ct->bTerminalID; // todo - Check supported caps
327  for(auto pu = uvc_get_processing_units(handle); pu; pu = pu->next) pu_unit = pu->bUnitID; // todo - Check supported caps
328 
329  switch(option)
330  {
331  case RS_OPTION_COLOR_BACKLIGHT_COMPENSATION: return get_pu_range<uint16_t>(handle, subdevice, pu_unit, UVC_PU_BACKLIGHT_COMPENSATION_CONTROL, min, max, step, def);
332  case RS_OPTION_COLOR_BRIGHTNESS: return get_pu_range<int16_t>(handle, subdevice, pu_unit, UVC_PU_BRIGHTNESS_CONTROL, min, max, step, def);
333  case RS_OPTION_COLOR_CONTRAST: return get_pu_range<uint16_t>(handle, subdevice, pu_unit, UVC_PU_CONTRAST_CONTROL, min, max, step, def);
334  case RS_OPTION_COLOR_EXPOSURE: return get_pu_range<uint32_t>(handle, subdevice, ct_unit, UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, min, max, step, def);
335  case RS_OPTION_COLOR_GAIN: return get_pu_range<uint16_t>(handle, subdevice, pu_unit, UVC_PU_GAIN_CONTROL, min, max, step, def);
336  case RS_OPTION_COLOR_GAMMA: return get_pu_range<uint16_t>(handle, subdevice, pu_unit, UVC_PU_GAMMA_CONTROL, min, max, step, def);
337  case RS_OPTION_COLOR_HUE: if(min) *min = 0; if(max) *max = 0; return; //return get_pu_range<int16_t>(handle, subdevice, pu_unit, UVC_PU_HUE_CONTROL, min, max, step, def);
338  case RS_OPTION_COLOR_SATURATION: return get_pu_range<uint16_t>(handle, subdevice, pu_unit, UVC_PU_SATURATION_CONTROL, min, max, step, def);
339  case RS_OPTION_COLOR_SHARPNESS: return get_pu_range<uint16_t>(handle, subdevice, pu_unit, UVC_PU_SHARPNESS_CONTROL, min, max, step, def);
340  case RS_OPTION_COLOR_WHITE_BALANCE: return get_pu_range<uint16_t>(handle, subdevice, pu_unit, UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL, min, max, step, def);
341  case RS_OPTION_COLOR_ENABLE_AUTO_EXPOSURE: if(min) *min = 0; if(max) *max = 1; if (step) *step = 1; if (def) *def = 1; return; // The next 2 options do not support range operations
342  case RS_OPTION_COLOR_ENABLE_AUTO_WHITE_BALANCE: if(min) *min = 0; if(max) *max = 1; if (step) *step = 1; if (def) *def = 1; return;
343  default: throw std::logic_error("invalid option");
344  }
345  }
346 
347  void get_extension_control_range(const device & device, const extension_unit & xu, char control, int * min, int * max, int * step, int * def)
348  {
349  throw std::logic_error("get_extension_control_range(...) is not implemented for this backend");
350  }
351 
352  void set_pu_control(device & device, int subdevice, rs_option option, int value)
353  {
354  auto handle = device.get_subdevice(subdevice).handle;
355  int ct_unit = 0, pu_unit = 0;
356  for(auto ct = uvc_get_input_terminals(handle); ct; ct = ct->next) ct_unit = ct->bTerminalID; // todo - Check supported caps
357  for(auto pu = uvc_get_processing_units(handle); pu; pu = pu->next) pu_unit = pu->bUnitID; // todo - Check supported caps
358 
359  switch(option)
360  {
361  case RS_OPTION_COLOR_BACKLIGHT_COMPENSATION: return set_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_BACKLIGHT_COMPENSATION_CONTROL, value);
362  case RS_OPTION_COLOR_BRIGHTNESS: return set_pu<int16_t>(handle, subdevice, pu_unit, UVC_PU_BRIGHTNESS_CONTROL, value);
363  case RS_OPTION_COLOR_CONTRAST: return set_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_CONTRAST_CONTROL, value);
364  case RS_OPTION_COLOR_EXPOSURE: return set_pu<uint32_t>(handle, subdevice, ct_unit, UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, value);
365  case RS_OPTION_COLOR_GAIN: return set_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_GAIN_CONTROL, value);
366  case RS_OPTION_COLOR_GAMMA: return set_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_GAMMA_CONTROL, value);
367  case RS_OPTION_COLOR_HUE: return; // set_pu<int16_t>(handle, subdevice, pu_unit, UVC_PU_HUE_CONTROL, value); // Causes LIBUSB_ERROR_PIPE, may be related to not being able to set UVC_PU_HUE_AUTO_CONTROL
368  case RS_OPTION_COLOR_SATURATION: return set_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_SATURATION_CONTROL, value);
369  case RS_OPTION_COLOR_SHARPNESS: return set_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_SHARPNESS_CONTROL, value);
370  case RS_OPTION_COLOR_WHITE_BALANCE: return set_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL, value);
371  case RS_OPTION_COLOR_ENABLE_AUTO_EXPOSURE: return set_pu<uint8_t>(handle, subdevice, ct_unit, UVC_CT_AE_MODE_CONTROL, value ? 2 : 1); // Modes - (1: manual) (2: auto) (4: shutter priority) (8: aperture priority)
372  case RS_OPTION_COLOR_ENABLE_AUTO_WHITE_BALANCE: return set_pu<uint8_t>(handle, subdevice, pu_unit, UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, value);
373  case RS_OPTION_FISHEYE_GAIN: {
374  assert(subdevice == 3);
375  return set_pu<uint16_t>(handle, 0, pu_unit, UVC_PU_GAIN_CONTROL, value);
376  }
377  default: throw std::logic_error("invalid option");
378  }
379  }
380 
381  int get_pu_control(const device & device, int subdevice, rs_option option)
382  {
383  auto handle = const_cast<uvc::device &>(device).get_subdevice(subdevice).handle;
384  int ct_unit = 0, pu_unit = 0;
385  for(auto ct = uvc_get_input_terminals(handle); ct; ct = ct->next) ct_unit = ct->bTerminalID; // todo - Check supported caps
386  for(auto pu = uvc_get_processing_units(handle); pu; pu = pu->next) pu_unit = pu->bUnitID; // todo - Check supported caps
387 
388  switch(option)
389  {
390  case RS_OPTION_COLOR_BACKLIGHT_COMPENSATION: return get_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_BACKLIGHT_COMPENSATION_CONTROL, UVC_GET_CUR);
391  case RS_OPTION_COLOR_BRIGHTNESS: return get_pu<int16_t>(handle, subdevice, pu_unit, UVC_PU_BRIGHTNESS_CONTROL, UVC_GET_CUR);
392  case RS_OPTION_COLOR_CONTRAST: return get_pu<uint16_t>(handle, subdevice, pu_unit,UVC_PU_CONTRAST_CONTROL, UVC_GET_CUR);
393  case RS_OPTION_COLOR_EXPOSURE: return get_pu<uint32_t>(handle, subdevice, ct_unit, UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, UVC_GET_CUR);
394  case RS_OPTION_COLOR_GAIN: return get_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_GAIN_CONTROL, UVC_GET_CUR);
395  case RS_OPTION_COLOR_GAMMA: return get_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_GAMMA_CONTROL, UVC_GET_CUR);
396  case RS_OPTION_COLOR_HUE: return 0; //get_pu<int16_t>(handle, subdevice, pu_unit, UVC_PU_HUE_CONTROL, UVC_GET_CUR);
397  case RS_OPTION_COLOR_SATURATION: return get_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_SATURATION_CONTROL, UVC_GET_CUR);
398  case RS_OPTION_COLOR_SHARPNESS: return get_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_SHARPNESS_CONTROL, UVC_GET_CUR);
399  case RS_OPTION_COLOR_WHITE_BALANCE: return get_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL, UVC_GET_CUR);
400  case RS_OPTION_COLOR_ENABLE_AUTO_EXPOSURE: return get_pu<uint8_t>(handle, subdevice, ct_unit, UVC_CT_AE_MODE_CONTROL, UVC_GET_CUR) > 1; // Modes - (1: manual) (2: auto) (4: shutter priority) (8: aperture priority)
401  case RS_OPTION_COLOR_ENABLE_AUTO_WHITE_BALANCE: return get_pu<uint8_t>(handle, subdevice, pu_unit, UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, UVC_GET_CUR);
402  case RS_OPTION_FISHEYE_GAIN: return get_pu<uint16_t>(handle, subdevice, pu_unit, UVC_PU_GAIN_CONTROL, UVC_GET_CUR);
403  default: throw std::logic_error("invalid option");
404  }
405  }
406 
408  // context //
410 
411  std::shared_ptr<context> create_context()
412  {
413  return std::make_shared<context>();
414  }
415 
416  bool is_device_connected(device & device, int vid, int pid)
417  {
418  return true;
419  }
420 
421  std::vector<std::shared_ptr<device>> query_devices(std::shared_ptr<context> context)
422  {
423  std::vector<std::shared_ptr<device>> devices;
424 
425  uvc_device_t ** list;
426  CALL_UVC(uvc_get_device_list, context->ctx, &list);
427  for (auto it = list; *it; ++it)
428  try
429  {
430  auto dev = std::make_shared<device>(context, *it);
431  dev->usb_handle = libusb_open_device_with_vid_pid(context->usb_context, VID_INTEL_CAMERA, ZR300_FISHEYE_PID);
432  devices.push_back(dev);
433  }
434  catch (std::runtime_error &e)
435  {
436  LOG_WARNING("usb:" << (int)uvc_get_bus_number(*it) << ':' << (int)uvc_get_device_address(*it) << ": " << e.what());
437  }
438  uvc_free_device_list(list, 1);
439 
440  std::shared_ptr<device> fisheye = nullptr; // Currently ZR300 supports only a single device on OSX
441 
442  for (auto& dev : devices)
443  {
444  if (dev->pid == ZR300_FISHEYE_PID)
445  {
446  fisheye = dev;
447  }
448  }
449 
450  for (auto& dev : devices)
451  {
452  dev->aux_device = fisheye;
453  }
454 
455  return devices;
456  }
457  }
458 }
459 
460 #endif
std::shared_ptr< context > create_context()
uvc_error_t uvc_init(uvc_context_t **pctx, struct libusb_context *usb_ctx)
Initializes the UVC context.
void get_pu_control_range(const device &device, int subdevice, rs_option option, int *min, int *max, int *step, int *def)
uvc_error_t uvc_get_device_list(uvc_context_t *ctx, uvc_device_t ***list)
Get a list of the UVC devices attached to the system.
Definition: dev.c:532
const uvc_input_terminal_t * uvc_get_input_terminals(uvc_device_handle_t *devh)
Get input terminal descriptors for the open device.
Definition: dev.c:698
enum uvc_error uvc_error_t
void claim_aux_interface(device &device, const guid &interface_guid, int interface_number)
int uvc_set_ctrl(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl, void *data, int len)
Perform a SET_CUR request to a terminal or unit.
Definition: ctrl.c:113
void set_subdevice_mode(device &device, int subdevice_index, int width, int height, uint32_t fourcc, int fps, video_channel_callback callback)
rs_error * e
GLint GLint GLsizei GLsizei height
Definition: glext.h:112
struct uvc_processing_unit * next
Definition: libuvc.h:299
void uvc_stop_streaming(uvc_device_handle_t *devh)
Stop streaming videoCloses all streams, ends threads and cancels pollers.
Definition: stream.c:1043
#define LOG_WARNING(...)
Definition: types.h:79
bool is_device_connected(device &device, int vid, int pid)
uvc_error_t uvc_start_streaming(uvc_device_handle_t *devh, uvc_stream_ctrl_t *ctrl, uvc_frame_callback_t *cb, void *user_ptr, uint8_t flags, int num_transfer_buffers)
Definition: stream.c:581
const uint16_t VID_INTEL_CAMERA
Definition: uvc.h:14
GLsizei const GLchar *const * string
Definition: glext.h:683
uint16_t idProduct
Definition: libuvc.h:350
static const int REQ_TYPE_GET
Definition: ctrl.c:46
Definition: archive.h:12
struct uvc_device uvc_device_t
Definition: libuvc.h:260
rs_option
Defines general configuration controls.
Definition: rs.h:128
GLbitfield GLuint64 timeout
Definition: glext.h:1481
void uvc_free_device_list(uvc_device_t **list, uint8_t unref_devices)
Frees a list of device structures created with uvc_get_device_list.
Definition: dev.c:643
std::string get_usb_port_id(const device &device)
void uvc_free_device_descriptor(uvc_device_descriptor_t *desc)
Frees a device descriptor created with uvc_get_device_descriptor.
Definition: dev.c:504
const uint16_t ZR300_FISHEYE_PID
Definition: uvc.h:16
GLuint buffer
Definition: glext.h:528
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 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)
void uvc_unref_device(uvc_device_t *dev)
Decrement the reference count for a device device.
Definition: dev.c:763
Implementation-specific UVC constants and structures.
const char * uvc_strerror(uvc_error_t err)
Return a string explaining an error in the UVC driver.
Definition: diag.c:88
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
Definition: glext.h:223
void stop_streaming(device &device)
uint8_t uvc_get_bus_number(uvc_device_t *dev)
Get the number of the bus to which the device is attached.
Definition: dev.c:180
uvc_error_t uvc_get_stream_ctrl_format_size(uvc_device_handle_t *devh, uvc_stream_ctrl_t *ctrl, uint32_t fourcc, int width, int height, int fps)
Definition: stream.c:268
auto ctx
GLsizei const GLfloat * value
Definition: glext.h:693
const uint16_t ZR300_CX3_PID
Definition: uvc.h:15
void uvc_close(uvc_device_handle_t *devh)
Close a device.
Definition: dev.c:1412
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 bulk_transfer(device &device, unsigned char endpoint, void *data, int length, int *actual_length, unsigned int timeout)
uvc_error_t uvc_open2(uvc_device_t *dev, uvc_device_handle_t **devh, int camera_number)
Open a UVC device, specifying the camera number, zero-based.
Definition: dev.c:215
GLint GLint GLsizei width
Definition: glext.h:112
void set_control(device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
uint8_t uvc_get_device_address(uvc_device_t *dev)
Get the number assigned to the device within its bus.
Definition: dev.c:187
int uvc_get_ctrl(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl, void *data, int len, enum uvc_req_code req_code)
Perform a GET_* request from an extension unit.
Definition: ctrl.c:90
void uvc_print_stream_ctrl(uvc_stream_ctrl_t *ctrl, FILE *stream)
Print the values in a stream control block.
Definition: diag.c:106
struct uvc_context uvc_context_t
Definition: libuvc.h:253
rs_device * dev
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)
const uvc_processing_unit_t * uvc_get_processing_units(uvc_device_handle_t *devh)
Get processing unit descriptors for the open device.
Definition: dev.c:724
uvc_error_t uvc_get_device_descriptor(uvc_device_t *dev, uvc_device_descriptor_t **desc)
Get a descriptor that contains the general information about a deviceFree *desc with uvc_free_device_...
Definition: dev.c:444
void uvc_exit(uvc_context_t *ctx)
Closes the UVC context, shutting down any active cameras.
GLuint res
Definition: glext.h:8310
struct uvc_device_handle uvc_device_handle_t
Definition: libuvc.h:268
void get_control(const device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
void stop_data_acquisition(device &device)
static const int REQ_TYPE_SET
Definition: ctrl.c:45
uint16_t idVendor
Definition: libuvc.h:348
struct uvc_input_terminal * next
Definition: libuvc.h:280
std::function< void(const void *frame, std::function< void()> continuation)> video_channel_callback
Definition: uvc.h:64
#define LOG_ERROR(...)
Definition: types.h:80
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