dev.c
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (C) 2010-2012 Ken Tossell
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the author nor other contributors may be
18 * used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
39 #include "libuvc.h"
40 #include "libuvc_internal.h"
41 
42 int uvc_already_open(uvc_context_t *ctx, struct libusb_device *usb_dev);
44 
45 uvc_error_t uvc_get_device_info(uvc_device_t *dev, uvc_device_info_t **info);
46 uvc_error_t uvc_get_device_info2(uvc_device_t *dev, uvc_device_info_t **info, int camera_number);
47 void uvc_free_device_info(uvc_device_info_t *info);
48 
49 uvc_error_t uvc_scan_control(uvc_device_t *dev, uvc_device_info_t *info);
51  uvc_device_info_t *info,
52  const unsigned char *block, size_t block_size);
54  uvc_device_info_t *info,
55  const unsigned char *block,
56  size_t block_size);
58  uvc_device_info_t *info,
59  const unsigned char *block, size_t block_size);
61  uvc_device_info_t *info,
62  const unsigned char *block,
63  size_t block_size);
65  uvc_device_info_t *info,
66  const unsigned char *block,
67  size_t block_size);
68 
70  uvc_device_info_t *info,
71  int interface_idx);
73  uvc_device_info_t *info,
74  uvc_streaming_interface_t *stream_if,
75  const unsigned char *block, size_t block_size);
76 uvc_error_t uvc_parse_vs_format_uncompressed(uvc_streaming_interface_t *stream_if,
77  const unsigned char *block,
78  size_t block_size);
79 uvc_error_t uvc_parse_vs_format_mjpeg(uvc_streaming_interface_t *stream_if,
80  const unsigned char *block,
81  size_t block_size);
82 uvc_error_t uvc_parse_vs_frame_uncompressed(uvc_streaming_interface_t *stream_if,
83  const unsigned char *block,
84  size_t block_size);
85 uvc_error_t uvc_parse_vs_frame_format(uvc_streaming_interface_t *stream_if,
86  const unsigned char *block,
87  size_t block_size);
88 uvc_error_t uvc_parse_vs_frame_frame(uvc_streaming_interface_t *stream_if,
89  const unsigned char *block,
90  size_t block_size);
91 uvc_error_t uvc_parse_vs_input_header(uvc_streaming_interface_t *stream_if,
92  const unsigned char *block,
93  size_t block_size);
94 
95 void LIBUSB_CALL _uvc_status_callback(struct libusb_transfer *transfer);
96 
105 int uvc_already_open(uvc_context_t *ctx, struct libusb_device *usb_dev) {
106  uvc_device_handle_t *devh;
107 
108  DL_FOREACH(ctx->open_devices, devh) {
109  if (usb_dev == devh->dev->usb_dev)
110  return 1;
111  }
112 
113  return 0;
114 }
115 
128  int vid, int pid, const char *sn) {
129  uvc_error_t ret = UVC_SUCCESS;
130 
131  uvc_device_t **list;
132  uvc_device_t *test_dev;
133  int dev_idx;
134  int found_dev;
135 
136  UVC_ENTER();
137 
138  ret = uvc_get_device_list(ctx, &list);
139 
140  if (ret != UVC_SUCCESS) {
141  UVC_EXIT(ret);
142  return ret;
143  }
144 
145  dev_idx = 0;
146  found_dev = 0;
147 
148  while (!found_dev && (test_dev = list[dev_idx++]) != NULL) {
150 
151  if (uvc_get_device_descriptor(test_dev, &desc) != UVC_SUCCESS)
152  continue;
153 
154  if ((!vid || desc->idVendor == vid)
155  && (!pid || desc->idProduct == pid)
156  && (!sn || (desc->serialNumber && !strcmp(desc->serialNumber, sn))))
157  found_dev = 1;
158 
160  }
161 
162  if (found_dev)
163  uvc_ref_device(test_dev);
164 
165  uvc_free_device_list(list, 1);
166 
167  if (found_dev) {
168  *dev = test_dev;
169  UVC_EXIT(UVC_SUCCESS);
170  return UVC_SUCCESS;
171  } else {
172  UVC_EXIT(UVC_ERROR_NO_DEVICE);
173  return UVC_ERROR_NO_DEVICE;
174  }
175 }
176 
181  return libusb_get_bus_number(dev->usb_dev);
182 }
183 
188  return libusb_get_device_address(dev->usb_dev);
189 }
190 
191 
201  uvc_device_t *dev,
202  uvc_device_handle_t **devh) {
203  return uvc_open2(dev, devh, 0);
204 }
205 
216  uvc_device_t *dev,
217  uvc_device_handle_t **devh,
218  int camera_number) {
219  uvc_error_t ret;
220  struct libusb_device_handle *usb_devh;
221  uvc_device_handle_t *internal_devh;
222  struct libusb_device_descriptor desc;
223 
224  UVC_ENTER();
225 
226  ret = libusb_open(dev->usb_dev, &usb_devh);
227  UVC_DEBUG("libusb_open() = %d", ret);
228 
229  if (ret != UVC_SUCCESS) {
230  UVC_EXIT(ret);
231  return ret;
232  }
233 
234  uvc_ref_device(dev);
235 
236  internal_devh = calloc(1, sizeof(*internal_devh));
237  internal_devh->dev = dev;
238  internal_devh->usb_devh = usb_devh;
239 
240  ret = uvc_get_device_info2(dev, &(internal_devh->info), camera_number);
241 
242  if (ret != UVC_SUCCESS)
243  goto fail;
244 
245  UVC_DEBUG("claiming control interface %d", internal_devh->info->ctrl_if.bInterfaceNumber);
246  ret = uvc_claim_if(internal_devh, internal_devh->info->ctrl_if.bInterfaceNumber);
247  if (ret != UVC_SUCCESS)
248  goto fail;
249 
250  libusb_get_device_descriptor(dev->usb_dev, &desc);
251  internal_devh->is_isight = (desc.idVendor == 0x05ac && desc.idProduct == 0x8501);
252 
253  if (internal_devh->info->ctrl_if.bEndpointAddress) {
254  internal_devh->status_xfer = libusb_alloc_transfer(0);
255  if (!internal_devh->status_xfer) {
256  ret = UVC_ERROR_NO_MEM;
257  goto fail;
258  }
259 
260  libusb_fill_interrupt_transfer(internal_devh->status_xfer,
261  usb_devh,
262  internal_devh->info->ctrl_if.bEndpointAddress,
263  internal_devh->status_buf,
264  sizeof(internal_devh->status_buf),
266  internal_devh,
267  0);
268  ret = libusb_submit_transfer(internal_devh->status_xfer);
269  UVC_DEBUG("libusb_submit_transfer() = %d", ret);
270 
271  if (ret) {
272  UVC_DEBUG("device has a status interrupt endpoint, but unable to read from it",);
273  goto fail;
274  }
275  }
276 
277  if (dev->ctx->own_usb_ctx && dev->ctx->open_devices == NULL) {
278  /* Since this is our first device, we need to spawn the event handler thread */
279  uvc_start_handler_thread(dev->ctx);
280  }
281 
282  DL_APPEND(dev->ctx->open_devices, internal_devh);
283  *devh = internal_devh;
284 
285  UVC_EXIT(ret);
286 
287  return ret;
288 
289  fail:
290  if ( internal_devh->info ) {
291  uvc_release_if(internal_devh, internal_devh->info->ctrl_if.bInterfaceNumber);
292  }
293  libusb_close(usb_devh);
294  uvc_unref_device(dev);
295  uvc_free_devh(internal_devh);
296 
297  UVC_EXIT(ret);
298 
299  return ret;
300 }
301 
313  uvc_device_info_t **info) {
314  return uvc_get_device_info2(dev, info, 0);
315 }
316 
329  uvc_device_info_t **info,
330  int camera_number) {
331  uvc_error_t ret;
332  uvc_device_info_t *internal_info;
333 
334  UVC_ENTER();
335 
336  internal_info = calloc(1, sizeof(*internal_info));
337  if (!internal_info) {
338  UVC_EXIT(UVC_ERROR_NO_MEM);
339  return UVC_ERROR_NO_MEM;
340  }
341 
342  if (libusb_get_config_descriptor(dev->usb_dev,
343  0,
344  &(internal_info->config)) != 0) {
345  free(internal_info);
346  UVC_EXIT(UVC_ERROR_IO);
347  return UVC_ERROR_IO;
348  }
349 
350  if (camera_number*2 > internal_info->config->bNumInterfaces)
351  {
352  free(internal_info);
353  UVC_EXIT(UVC_ERROR_NO_DEVICE);
354  return UVC_ERROR_NO_DEVICE;
355  }
356 
357  //Which camera interface to pick up
358  internal_info->camera_number = camera_number;
359 
360 
361  ret = uvc_scan_control(dev, internal_info);
362  if (ret != UVC_SUCCESS) {
363  uvc_free_device_info(internal_info);
364  UVC_EXIT(ret);
365  return ret;
366  }
367 
368  *info = internal_info;
369 
370  UVC_EXIT(ret);
371  return ret;
372 }
373 
381 void uvc_free_device_info(uvc_device_info_t *info) {
382  uvc_input_terminal_t *input_term, *input_term_tmp;
383  uvc_processing_unit_t *proc_unit, *proc_unit_tmp;
384  uvc_extension_unit_t *ext_unit, *ext_unit_tmp;
385 
386  uvc_streaming_interface_t *stream_if, *stream_if_tmp;
387  uvc_format_desc_t *format, *format_tmp;
388  uvc_frame_desc_t *frame, *frame_tmp;
389 
390  UVC_ENTER();
391 
392  DL_FOREACH_SAFE(info->ctrl_if.input_term_descs, input_term, input_term_tmp) {
393  DL_DELETE(info->ctrl_if.input_term_descs, input_term);
394  free(input_term);
395  }
396 
397  DL_FOREACH_SAFE(info->ctrl_if.processing_unit_descs, proc_unit, proc_unit_tmp) {
398  DL_DELETE(info->ctrl_if.processing_unit_descs, proc_unit);
399  free(proc_unit);
400  }
401 
402  DL_FOREACH_SAFE(info->ctrl_if.extension_unit_descs, ext_unit, ext_unit_tmp) {
403  DL_DELETE(info->ctrl_if.extension_unit_descs, ext_unit);
404  free(ext_unit);
405  }
406 
407  DL_FOREACH_SAFE(info->stream_ifs, stream_if, stream_if_tmp) {
408  DL_FOREACH_SAFE(stream_if->format_descs, format, format_tmp) {
409  DL_FOREACH_SAFE(format->frame_descs, frame, frame_tmp) {
410  if (frame->intervals)
411  free(frame->intervals);
412 
413  DL_DELETE(format->frame_descs, frame);
414  free(frame);
415  }
416 
417  DL_DELETE(stream_if->format_descs, format);
418  free(format);
419  }
420 
421  DL_DELETE(info->stream_ifs, stream_if);
422  free(stream_if);
423  }
424 
425  if (info->config)
426  libusb_free_config_descriptor(info->config);
427 
428  free(info);
429 
430  UVC_EXIT_VOID();
431 }
432 
445  uvc_device_t *dev,
446  uvc_device_descriptor_t **desc) {
447  uvc_device_descriptor_t *desc_internal;
448  struct libusb_device_descriptor usb_desc;
449  struct libusb_device_handle *usb_devh;
450  uvc_error_t ret;
451 
452  UVC_ENTER();
453 
454  ret = libusb_get_device_descriptor(dev->usb_dev, &usb_desc);
455 
456  if (ret != UVC_SUCCESS) {
457  UVC_EXIT(ret);
458  return ret;
459  }
460 
461  desc_internal = calloc(1, sizeof(*desc_internal));
462  desc_internal->idVendor = usb_desc.idVendor;
463  desc_internal->idProduct = usb_desc.idProduct;
464 
465  if (libusb_open(dev->usb_dev, &usb_devh) == 0) {
466  unsigned char buf[64];
467 
468  int bytes = libusb_get_string_descriptor_ascii(
469  usb_devh, usb_desc.iSerialNumber, buf, sizeof(buf));
470 
471  if (bytes > 0)
472  desc_internal->serialNumber = strdup((const char*) buf);
473 
474  bytes = libusb_get_string_descriptor_ascii(
475  usb_devh, usb_desc.iManufacturer, buf, sizeof(buf));
476 
477  if (bytes > 0)
478  desc_internal->manufacturer = strdup((const char*) buf);
479 
480  bytes = libusb_get_string_descriptor_ascii(
481  usb_devh, usb_desc.iProduct, buf, sizeof(buf));
482 
483  if (bytes > 0)
484  desc_internal->product = strdup((const char*) buf);
485 
486  libusb_close(usb_devh);
487  } else {
488  UVC_DEBUG("can't open device %04x:%04x, not fetching serial etc.",
489  usb_desc.idVendor, usb_desc.idProduct);
490  }
491 
492  *desc = desc_internal;
493 
494  UVC_EXIT(ret);
495  return ret;
496 }
497 
505  uvc_device_descriptor_t *desc) {
506  UVC_ENTER();
507 
508  if (desc->serialNumber)
509  free((void*) desc->serialNumber);
510 
511  if (desc->manufacturer)
512  free((void*) desc->manufacturer);
513 
514  if (desc->product)
515  free((void*) desc->product);
516 
517  free(desc);
518 
519  UVC_EXIT_VOID();
520 }
521 
534  uvc_device_t ***list) {
535  uvc_error_t ret;
536  struct libusb_device **usb_dev_list;
537  struct libusb_device *usb_dev;
538  int num_usb_devices;
539 
540  uvc_device_t **list_internal;
541  int num_uvc_devices;
542 
543  /* per device */
544  int dev_idx;
545  struct libusb_device_handle *usb_devh;
546  struct libusb_config_descriptor *config;
547  struct libusb_device_descriptor desc;
548  uint8_t got_interface;
549 
550  /* per interface */
551  int interface_idx;
552  const struct libusb_interface *interface;
553 
554  /* per altsetting */
555  int altsetting_idx;
556  const struct libusb_interface_descriptor *if_desc;
557 
558  UVC_ENTER();
559 
560  num_usb_devices = libusb_get_device_list(ctx->usb_ctx, &usb_dev_list);
561 
562  if (num_usb_devices < 0) {
563  UVC_EXIT(UVC_ERROR_IO);
564  return UVC_ERROR_IO;
565  }
566 
567  list_internal = malloc(sizeof(*list_internal));
568  *list_internal = NULL;
569 
570  num_uvc_devices = 0;
571  dev_idx = -1;
572 
573  while ((usb_dev = usb_dev_list[++dev_idx]) != NULL) {
574  usb_devh = NULL;
575  got_interface = 0;
576 
577  if (libusb_get_config_descriptor(usb_dev, 0, &config) != 0)
578  continue;
579 
580  if ( libusb_get_device_descriptor ( usb_dev, &desc ) != LIBUSB_SUCCESS )
581  continue;
582 
583  // Special case for Imaging Source cameras
584  if ( 0x199e == desc.idVendor && 0x8101 == desc.idProduct ) {
585  got_interface = 1;
586  } else {
587 
588  for (interface_idx = 0;
589  !got_interface && interface_idx < config->bNumInterfaces;
590  ++interface_idx) {
591  interface = &config->interface[interface_idx];
592 
593  for (altsetting_idx = 0;
594  !got_interface && altsetting_idx < interface->num_altsetting;
595  ++altsetting_idx) {
596  if_desc = &interface->altsetting[altsetting_idx];
597 
598  /* Video, Streaming */
599  if (if_desc->bInterfaceClass == 14 && if_desc->bInterfaceSubClass == 2) {
600  got_interface = 1;
601  }
602  }
603  }
604  }
605 
606  libusb_free_config_descriptor(config);
607 
608  if (got_interface) {
609  uvc_device_t *uvc_dev = malloc(sizeof(*uvc_dev));
610  uvc_dev->ctx = ctx;
611  uvc_dev->ref = 0;
612  uvc_dev->usb_dev = usb_dev;
613  uvc_ref_device(uvc_dev);
614 
615  num_uvc_devices++;
616  list_internal = realloc(list_internal, (num_uvc_devices + 1) * sizeof(*list_internal));
617 
618  list_internal[num_uvc_devices - 1] = uvc_dev;
619  list_internal[num_uvc_devices] = NULL;
620 
621  UVC_DEBUG(" UVC: %d", dev_idx);
622  } else {
623  UVC_DEBUG("non-UVC: %d", dev_idx);
624  }
625  }
626 
627  libusb_free_device_list(usb_dev_list, 1);
628 
629  *list = list_internal;
630 
631  UVC_EXIT(UVC_SUCCESS);
632  return UVC_SUCCESS;
633 }
634 
643 void uvc_free_device_list(uvc_device_t **list, uint8_t unref_devices) {
644  uvc_device_t *dev;
645  int dev_idx = 0;
646 
647  UVC_ENTER();
648 
649  if (unref_devices) {
650  while ((dev = list[dev_idx++]) != NULL) {
651  uvc_unref_device(dev);
652  }
653  }
654 
655  free(list);
656 
657  UVC_EXIT_VOID();
658 }
659 
669  uvc_ref_device(devh->dev);
670  return devh->dev;
671 }
672 
685 libusb_device_handle *uvc_get_libusb_handle(uvc_device_handle_t *devh) {
686  return devh->usb_devh;
687 }
688 
699  return devh->info->ctrl_if.input_term_descs;
700 }
701 
712  return NULL; /* @todo */
713 }
714 
725  return devh->info->ctrl_if.processing_unit_descs;
726 }
727 
738  return devh->info->ctrl_if.extension_unit_descs;
739 }
740 
748  UVC_ENTER();
749 
750  dev->ref++;
751  libusb_ref_device(dev->usb_dev);
752 
753  UVC_EXIT_VOID();
754 }
755 
764  UVC_ENTER();
765 
766  libusb_unref_device(dev->usb_dev);
767  dev->ref--;
768 
769  if (dev->ref == 0)
770  free(dev);
771 
772  UVC_EXIT_VOID();
773 }
774 
783  int ret;
784 
785  UVC_ENTER();
786 
787  /* Tell libusb to detach any active kernel drivers. libusb will keep track of whether
788  * it found a kernel driver for this interface. */
789  ret = libusb_detach_kernel_driver(devh->usb_devh, idx);
790 
791  if (ret == UVC_SUCCESS || ret == LIBUSB_ERROR_NOT_FOUND || ret == LIBUSB_ERROR_NOT_SUPPORTED) {
792  UVC_DEBUG("claiming interface %d", idx);
793  ret = libusb_claim_interface(devh->usb_devh, idx);
794  } else {
795  UVC_DEBUG("not claiming interface %d: unable to detach kernel driver (%s)",
796  idx, uvc_strerror(ret));
797  }
798 
799  UVC_EXIT(ret);
800  return ret;
801 }
802 
811  int ret;
812 
813  UVC_ENTER();
814  UVC_DEBUG("releasing interface %d", idx);
815  /* libusb_release_interface *should* reset the alternate setting to the first available,
816  but sometimes (e.g. on Darwin) it doesn't. Thus, we do it explicitly here.
817  This is needed to de-initialize certain cameras. */
818  libusb_set_interface_alt_setting(devh->usb_devh, idx, 0);
819  ret = libusb_release_interface(devh->usb_devh, idx);
820 
821  if (UVC_SUCCESS == ret) {
822  /* Reattach any kernel drivers that were disabled when we claimed this interface */
823  ret = libusb_attach_kernel_driver(devh->usb_devh, idx);
824 
825  if (ret == UVC_SUCCESS) {
826  UVC_DEBUG("reattached kernel driver to interface %d", idx);
827  } else if (ret == LIBUSB_ERROR_NOT_FOUND || ret == LIBUSB_ERROR_NOT_SUPPORTED) {
828  ret = UVC_SUCCESS; /* NOT_FOUND and NOT_SUPPORTED are OK: nothing to do */
829  } else {
830  UVC_DEBUG("error reattaching kernel driver to interface %d: %s",
831  idx, uvc_strerror(ret));
832  }
833  }
834 
835  UVC_EXIT(ret);
836  return ret;
837 }
838 
843 uvc_error_t uvc_scan_control(uvc_device_t *dev, uvc_device_info_t *info) {
844  const struct libusb_interface_descriptor *if_desc;
845  uvc_error_t parse_ret, ret;
846  int interface_idx;
847  const unsigned char *buffer;
848  size_t buffer_left, block_size;
849 
850  UVC_ENTER();
851 
852  ret = UVC_SUCCESS;
853  if_desc = NULL;
854 
855  //Start looking for the control interface at the given camera number
856 
857  for (interface_idx = info->camera_number*2; interface_idx < info->config->bNumInterfaces; ++interface_idx) {
858  if_desc = &info->config->interface[interface_idx].altsetting[0];
859 
860  if (if_desc->bInterfaceClass == 14 && if_desc->bInterfaceSubClass == 1) // Video, Control
861  break;
862 
863  // Another TIS camera hack.
864  if ( if_desc->bInterfaceClass == 255 && if_desc->bInterfaceSubClass == 1 ) {
865  uvc_device_descriptor_t* dev_desc;
866  int haveTISCamera = 0;
867  uvc_get_device_descriptor ( dev, &dev_desc );
868  if ( dev_desc->idVendor == 0x199e && dev_desc->idProduct == 0x8101 ) {
869  haveTISCamera = 1;
870  }
871  uvc_free_device_descriptor ( dev_desc );
872  if ( haveTISCamera ) {
873  break;
874  }
875  }
876 
877  if_desc = NULL;
878  }
879 
880  if (if_desc == NULL) {
881  UVC_EXIT(UVC_ERROR_INVALID_DEVICE);
883  }
884 
885  info->ctrl_if.bInterfaceNumber = interface_idx;
886  if (if_desc->bNumEndpoints != 0) {
887  info->ctrl_if.bEndpointAddress = if_desc->endpoint[0].bEndpointAddress;
888  }
889 
890  buffer = if_desc->extra;
891  buffer_left = if_desc->extra_length;
892 
893  while (buffer_left >= 3) { // parseX needs to see buf[0,2] = length,type
894  block_size = buffer[0];
895  parse_ret = uvc_parse_vc(dev, info, buffer, block_size);
896 
897  if (parse_ret != UVC_SUCCESS) {
898  ret = parse_ret;
899  break;
900  }
901 
902  buffer_left -= block_size;
903  buffer += block_size;
904  }
905 
906  UVC_EXIT(ret);
907  return ret;
908 }
909 
915  uvc_device_info_t *info,
916  const unsigned char *block, size_t block_size) {
917  size_t i;
918  uvc_error_t scan_ret, ret = UVC_SUCCESS;
919 
920  UVC_ENTER();
921 
922  /*
923  int uvc_version;
924  uvc_version = (block[4] >> 4) * 1000 + (block[4] & 0x0f) * 100
925  + (block[3] >> 4) * 10 + (block[3] & 0x0f);
926  */
927 
928  info->ctrl_if.bcdUVC = SW_TO_SHORT(&block[3]);
929 
930  switch (info->ctrl_if.bcdUVC) {
931  case 0x0100:
932  case 0x010a:
933  case 0x0110:
934  break;
935  default:
936  UVC_EXIT(UVC_ERROR_NOT_SUPPORTED);
938  }
939 
940  for (i = 12; i < block_size; ++i) {
941  scan_ret = uvc_scan_streaming(dev, info, block[i]);
942  if (scan_ret != UVC_SUCCESS) {
943  ret = scan_ret;
944  break;
945  }
946  }
947 
948  UVC_EXIT(ret);
949  return ret;
950 }
951 
957  uvc_device_info_t *info,
958  const unsigned char *block, size_t block_size) {
959  uvc_input_terminal_t *term;
960  size_t i;
961 
962  UVC_ENTER();
963 
964  /* only supporting camera-type input terminals */
965  if (SW_TO_SHORT(&block[4]) != UVC_ITT_CAMERA) {
966  UVC_EXIT(UVC_SUCCESS);
967  return UVC_SUCCESS;
968  }
969 
970  term = calloc(1, sizeof(*term));
971 
972  term->bTerminalID = block[3];
973  term->wTerminalType = SW_TO_SHORT(&block[4]);
974  term->wObjectiveFocalLengthMin = SW_TO_SHORT(&block[8]);
975  term->wObjectiveFocalLengthMax = SW_TO_SHORT(&block[10]);
976  term->wOcularFocalLength = SW_TO_SHORT(&block[12]);
977 
978  for (i = 14 + block[14]; i >= 15; --i)
979  term->bmControls = block[i] + (term->bmControls << 8);
980 
981  DL_APPEND(info->ctrl_if.input_term_descs, term);
982 
983  UVC_EXIT(UVC_SUCCESS);
984  return UVC_SUCCESS;
985 }
986 
992  uvc_device_info_t *info,
993  const unsigned char *block, size_t block_size) {
994  uvc_processing_unit_t *unit;
995  size_t i;
996 
997  UVC_ENTER();
998 
999  unit = calloc(1, sizeof(*unit));
1000  unit->bUnitID = block[3];
1001  unit->bSourceID = block[4];
1002 
1003  for (i = 7 + block[7]; i >= 8; --i)
1004  unit->bmControls = block[i] + (unit->bmControls << 8);
1005 
1006  DL_APPEND(info->ctrl_if.processing_unit_descs, unit);
1007 
1008  UVC_EXIT(UVC_SUCCESS);
1009  return UVC_SUCCESS;
1010 }
1011 
1017  uvc_device_info_t *info,
1018  const unsigned char *block, size_t block_size) {
1019  uvc_extension_unit_t *unit = calloc(1, sizeof(*unit));
1020  const uint8_t *start_of_controls;
1021  int size_of_controls, num_in_pins;
1022  int i;
1023 
1024  UVC_ENTER();
1025 
1026  unit->bUnitID = block[3];
1027  memcpy(unit->guidExtensionCode, &block[4], 16);
1028 
1029  num_in_pins = block[21];
1030  size_of_controls = block[22 + num_in_pins];
1031  start_of_controls = &block[23 + num_in_pins];
1032 
1033  for (i = size_of_controls - 1; i >= 0; --i)
1034  unit->bmControls = start_of_controls[i] + (unit->bmControls << 8);
1035 
1036  DL_APPEND(info->ctrl_if.extension_unit_descs, unit);
1037 
1038  UVC_EXIT(UVC_SUCCESS);
1039  return UVC_SUCCESS;
1040 }
1041 
1047  uvc_device_t *dev,
1048  uvc_device_info_t *info,
1049  const unsigned char *block, size_t block_size) {
1050  int descriptor_subtype;
1051  uvc_error_t ret = UVC_SUCCESS;
1052 
1053  UVC_ENTER();
1054 
1055  if (block[1] != 36) { // not a CS_INTERFACE descriptor??
1056  UVC_EXIT(UVC_SUCCESS);
1057  return UVC_SUCCESS; // UVC_ERROR_INVALID_DEVICE;
1058  }
1059 
1060  descriptor_subtype = block[2];
1061 
1062  switch (descriptor_subtype) {
1063  case UVC_VC_HEADER:
1064  ret = uvc_parse_vc_header(dev, info, block, block_size);
1065  break;
1066  case UVC_VC_INPUT_TERMINAL:
1067  ret = uvc_parse_vc_input_terminal(dev, info, block, block_size);
1068  break;
1069  case UVC_VC_OUTPUT_TERMINAL:
1070  break;
1071  case UVC_VC_SELECTOR_UNIT:
1072  break;
1073  case UVC_VC_PROCESSING_UNIT:
1074  ret = uvc_parse_vc_processing_unit(dev, info, block, block_size);
1075  break;
1076  case UVC_VC_EXTENSION_UNIT:
1077  ret = uvc_parse_vc_extension_unit(dev, info, block, block_size);
1078  break;
1079  default:
1081  }
1082 
1083  UVC_EXIT(ret);
1084  return ret;
1085 }
1086 
1092  uvc_device_info_t *info,
1093  int interface_idx) {
1094  const struct libusb_interface_descriptor *if_desc;
1095  const unsigned char *buffer;
1096  size_t buffer_left, block_size;
1097  uvc_error_t ret, parse_ret;
1098  uvc_streaming_interface_t *stream_if;
1099 
1100  UVC_ENTER();
1101 
1102  ret = UVC_SUCCESS;
1103 
1104  if_desc = &(info->config->interface[interface_idx].altsetting[0]);
1105  buffer = if_desc->extra;
1106  buffer_left = if_desc->extra_length;
1107 
1108  stream_if = calloc(1, sizeof(*stream_if));
1109  stream_if->parent = info;
1110  stream_if->bInterfaceNumber = if_desc->bInterfaceNumber;
1111  DL_APPEND(info->stream_ifs, stream_if);
1112 
1113  while (buffer_left >= 3) {
1114  block_size = buffer[0];
1115  parse_ret = uvc_parse_vs(dev, info, stream_if, buffer, block_size);
1116 
1117  if (parse_ret != UVC_SUCCESS) {
1118  ret = parse_ret;
1119  break;
1120  }
1121 
1122  buffer_left -= block_size;
1123  buffer += block_size;
1124  }
1125 
1126  UVC_EXIT(ret);
1127  return ret;
1128 }
1129 
1134 uvc_error_t uvc_parse_vs_input_header(uvc_streaming_interface_t *stream_if,
1135  const unsigned char *block,
1136  size_t block_size) {
1137  UVC_ENTER();
1138 
1139  stream_if->bEndpointAddress = block[6] & 0x8f;
1140  stream_if->bTerminalLink = block[8];
1141 
1142  UVC_EXIT(UVC_SUCCESS);
1143  return UVC_SUCCESS;
1144 }
1145 
1150 uvc_error_t uvc_parse_vs_format_uncompressed(uvc_streaming_interface_t *stream_if,
1151  const unsigned char *block,
1152  size_t block_size) {
1153  UVC_ENTER();
1154 
1155  uvc_format_desc_t *format = calloc(1, sizeof(*format));
1156 
1157  format->parent = stream_if;
1158  format->bDescriptorSubtype = block[2];
1159  format->bFormatIndex = block[3];
1160  //format->bmCapabilities = block[4];
1161  //format->bmFlags = block[5];
1162  memcpy(format->guidFormat, &block[5], 16);
1163  format->bBitsPerPixel = block[21];
1164  format->bDefaultFrameIndex = block[22];
1165  format->bAspectRatioX = block[23];
1166  format->bAspectRatioY = block[24];
1167  format->bmInterlaceFlags = block[25];
1168  format->bCopyProtect = block[26];
1169 
1170  DL_APPEND(stream_if->format_descs, format);
1171 
1172  UVC_EXIT(UVC_SUCCESS);
1173  return UVC_SUCCESS;
1174 }
1175 
1180 uvc_error_t uvc_parse_vs_frame_format(uvc_streaming_interface_t *stream_if,
1181  const unsigned char *block,
1182  size_t block_size) {
1183  UVC_ENTER();
1184 
1185  uvc_format_desc_t *format = calloc(1, sizeof(*format));
1186 
1187  format->parent = stream_if;
1188  format->bDescriptorSubtype = block[2];
1189  format->bFormatIndex = block[3];
1190  format->bNumFrameDescriptors = block[4];
1191  memcpy(format->guidFormat, &block[5], 16);
1192  format->bBitsPerPixel = block[21];
1193  format->bDefaultFrameIndex = block[22];
1194  format->bAspectRatioX = block[23];
1195  format->bAspectRatioY = block[24];
1196  format->bmInterlaceFlags = block[25];
1197  format->bCopyProtect = block[26];
1198  format->bVariableSize = block[27];
1199 
1200  DL_APPEND(stream_if->format_descs, format);
1201 
1202  UVC_EXIT(UVC_SUCCESS);
1203  return UVC_SUCCESS;
1204 }
1205 
1210 uvc_error_t uvc_parse_vs_format_mjpeg(uvc_streaming_interface_t *stream_if,
1211  const unsigned char *block,
1212  size_t block_size) {
1213  UVC_ENTER();
1214 
1215  uvc_format_desc_t *format = calloc(1, sizeof(*format));
1216 
1217  format->parent = stream_if;
1218  format->bDescriptorSubtype = block[2];
1219  format->bFormatIndex = block[3];
1220  memcpy(format->fourccFormat, "MJPG", 4);
1221  format->bmFlags = block[5];
1222  format->bBitsPerPixel = 0;
1223  format->bDefaultFrameIndex = block[6];
1224  format->bAspectRatioX = block[7];
1225  format->bAspectRatioY = block[8];
1226  format->bmInterlaceFlags = block[9];
1227  format->bCopyProtect = block[10];
1228 
1229  DL_APPEND(stream_if->format_descs, format);
1230 
1231  UVC_EXIT(UVC_SUCCESS);
1232  return UVC_SUCCESS;
1233 }
1234 
1239 uvc_error_t uvc_parse_vs_frame_frame(uvc_streaming_interface_t *stream_if,
1240  const unsigned char *block,
1241  size_t block_size) {
1243  uvc_frame_desc_t *frame;
1244 
1245  const unsigned char *p;
1246  int i;
1247 
1248  UVC_ENTER();
1249 
1250  format = stream_if->format_descs->prev;
1251  frame = calloc(1, sizeof(*frame));
1252 
1253  frame->parent = format;
1254 
1255  frame->bDescriptorSubtype = block[2];
1256  frame->bFrameIndex = block[3];
1257  frame->bmCapabilities = block[4];
1258  frame->wWidth = block[5] + (block[6] << 8);
1259  frame->wHeight = block[7] + (block[8] << 8);
1260  frame->dwMinBitRate = DW_TO_INT(&block[9]);
1261  frame->dwMaxBitRate = DW_TO_INT(&block[13]);
1262  frame->dwDefaultFrameInterval = DW_TO_INT(&block[17]);
1263  frame->bFrameIntervalType = block[21];
1264  frame->dwBytesPerLine = DW_TO_INT(&block[22]);
1265 
1266  if (block[21] == 0) {
1267  frame->dwMinFrameInterval = DW_TO_INT(&block[26]);
1268  frame->dwMaxFrameInterval = DW_TO_INT(&block[30]);
1269  frame->dwFrameIntervalStep = DW_TO_INT(&block[34]);
1270  } else {
1271  frame->intervals = calloc(block[21] + 1, sizeof(frame->intervals[0]));
1272  p = &block[26];
1273 
1274  for (i = 0; i < block[21]; ++i) {
1275  frame->intervals[i] = DW_TO_INT(p);
1276  p += 4;
1277  }
1278  frame->intervals[block[21]] = 0;
1279  }
1280 
1281  DL_APPEND(format->frame_descs, frame);
1282 
1283  UVC_EXIT(UVC_SUCCESS);
1284  return UVC_SUCCESS;
1285 }
1286 
1291 uvc_error_t uvc_parse_vs_frame_uncompressed(uvc_streaming_interface_t *stream_if,
1292  const unsigned char *block,
1293  size_t block_size) {
1295  uvc_frame_desc_t *frame;
1296 
1297  const unsigned char *p;
1298  int i;
1299 
1300  UVC_ENTER();
1301 
1302  format = stream_if->format_descs->prev;
1303  frame = calloc(1, sizeof(*frame));
1304 
1305  frame->parent = format;
1306 
1307  frame->bDescriptorSubtype = block[2];
1308  frame->bFrameIndex = block[3];
1309  frame->bmCapabilities = block[4];
1310  frame->wWidth = block[5] + (block[6] << 8);
1311  frame->wHeight = block[7] + (block[8] << 8);
1312  frame->dwMinBitRate = DW_TO_INT(&block[9]);
1313  frame->dwMaxBitRate = DW_TO_INT(&block[13]);
1314  frame->dwMaxVideoFrameBufferSize = DW_TO_INT(&block[17]);
1315  frame->dwDefaultFrameInterval = DW_TO_INT(&block[21]);
1316  frame->bFrameIntervalType = block[25];
1317 
1318  if (block[25] == 0) {
1319  frame->dwMinFrameInterval = DW_TO_INT(&block[26]);
1320  frame->dwMaxFrameInterval = DW_TO_INT(&block[30]);
1321  frame->dwFrameIntervalStep = DW_TO_INT(&block[34]);
1322  } else {
1323  frame->intervals = calloc(block[25] + 1, sizeof(frame->intervals[0]));
1324  p = &block[26];
1325 
1326  for (i = 0; i < block[25]; ++i) {
1327  frame->intervals[i] = DW_TO_INT(p);
1328  p += 4;
1329  }
1330  frame->intervals[block[25]] = 0;
1331  }
1332 
1333  DL_APPEND(format->frame_descs, frame);
1334 
1335  UVC_EXIT(UVC_SUCCESS);
1336  return UVC_SUCCESS;
1337 }
1338 
1344  uvc_device_t *dev,
1345  uvc_device_info_t *info,
1346  uvc_streaming_interface_t *stream_if,
1347  const unsigned char *block, size_t block_size) {
1348  uvc_error_t ret;
1349  int descriptor_subtype;
1350 
1351  UVC_ENTER();
1352 
1353  ret = UVC_SUCCESS;
1354  descriptor_subtype = block[2];
1355 
1356  switch (descriptor_subtype) {
1357  case UVC_VS_INPUT_HEADER:
1358  ret = uvc_parse_vs_input_header(stream_if, block, block_size);
1359  break;
1361  ret = uvc_parse_vs_format_uncompressed(stream_if, block, block_size);
1362  break;
1363  case UVC_VS_FORMAT_MJPEG:
1364  ret = uvc_parse_vs_format_mjpeg(stream_if, block, block_size);
1365  break;
1367  case UVC_VS_FRAME_MJPEG:
1368  ret = uvc_parse_vs_frame_uncompressed(stream_if, block, block_size);
1369  break;
1371  ret = uvc_parse_vs_frame_format ( stream_if, block, block_size );
1372  break;
1374  ret = uvc_parse_vs_frame_frame ( stream_if, block, block_size );
1375  break;
1376  default:
1378  UVC_DEBUG ("unsupported descriptor subtype: %d\n", descriptor_subtype);
1379  break;
1380  }
1381 
1382  UVC_EXIT(ret);
1383  return ret;
1384 }
1385 
1391  UVC_ENTER();
1392 
1393  if (devh->info)
1394  uvc_free_device_info(devh->info);
1395 
1396  if (devh->status_xfer)
1397  libusb_free_transfer(devh->status_xfer);
1398 
1399  free(devh);
1400 
1401  UVC_EXIT_VOID();
1402 }
1403 
1413  UVC_ENTER();
1414  uvc_context_t *ctx = devh->dev->ctx;
1415 
1416  if (devh->streams)
1417  uvc_stop_streaming(devh);
1418 
1419  uvc_release_if(devh, devh->info->ctrl_if.bInterfaceNumber);
1420 
1421  /* If we are managing the libusb context and this is the last open device,
1422  * then we need to cancel the handler thread. When we call libusb_close,
1423  * it'll cause a return from the thread's libusb_handle_events call, after
1424  * which the handler thread will check the flag we set and then exit. */
1425  if (ctx->own_usb_ctx && ctx->open_devices == devh && devh->next == NULL) {
1426  ctx->kill_handler_thread = 1;
1427  libusb_close(devh->usb_devh);
1428  pthread_join(ctx->handler_thread, NULL);
1429  } else {
1430  libusb_close(devh->usb_devh);
1431  }
1432 
1433  DL_DELETE(ctx->open_devices, devh);
1434 
1435  uvc_unref_device(devh->dev);
1436 
1437  uvc_free_devh(devh);
1438 
1439  UVC_EXIT_VOID();
1440 }
1441 
1446  size_t count = 0;
1447 
1448  uvc_device_handle_t *devh;
1449 
1450  UVC_ENTER();
1451 
1452  DL_FOREACH(ctx->open_devices, devh) {
1453  count++;
1454  }
1455 
1456  UVC_EXIT((int) count);
1457  return count;
1458 }
1459 
1460 void uvc_process_status_xfer(uvc_device_handle_t *devh, struct libusb_transfer *transfer) {
1461  enum uvc_status_class status_class;
1462  uint8_t originator = 0, selector = 0, event = 0;
1464  void *data = NULL;
1465  size_t data_len = 0;
1466 
1467  UVC_ENTER();
1468 
1469  /* printf("Got transfer of aLen = %d\n", transfer->actual_length); */
1470 
1471  if (transfer->actual_length < 4) {
1472  UVC_DEBUG("Short read of status update (%d bytes)", transfer->actual_length);
1473  UVC_EXIT_VOID();
1474  return;
1475  }
1476 
1477  originator = transfer->buffer[1];
1478 
1479  switch (transfer->buffer[0] & 0x0f) {
1480  case 1: { /* VideoControl interface */
1481  int found_entity = 0;
1482  struct uvc_input_terminal *input_terminal;
1483  struct uvc_processing_unit *processing_unit;
1484 
1485  if (transfer->actual_length < 5) {
1486  UVC_DEBUG("Short read of VideoControl status update (%d bytes)",
1487  transfer->actual_length);
1488  UVC_EXIT_VOID();
1489  return;
1490  }
1491 
1492  event = transfer->buffer[2];
1493  selector = transfer->buffer[3];
1494 
1495  if (originator == 0) {
1496  UVC_DEBUG("Unhandled update from VC interface", );
1497  UVC_EXIT_VOID();
1498  return; /* @todo VideoControl virtual entity interface updates */
1499  }
1500 
1501  if (event != 0) {
1502  UVC_DEBUG("Unhandled VC event %d", (int) event);
1503  UVC_EXIT_VOID();
1504  return;
1505  }
1506 
1507  /* printf("bSelector: %d\n", selector); */
1508 
1509  DL_FOREACH(devh->info->ctrl_if.input_term_descs, input_terminal) {
1510  if (input_terminal->bTerminalID == originator) {
1511  status_class = UVC_STATUS_CLASS_CONTROL_CAMERA;
1512  found_entity = 1;
1513  break;
1514  }
1515  }
1516 
1517  if (!found_entity) {
1518  DL_FOREACH(devh->info->ctrl_if.processing_unit_descs, processing_unit) {
1519  if (processing_unit->bUnitID == originator) {
1520  status_class = UVC_STATUS_CLASS_CONTROL_PROCESSING;
1521  found_entity = 1;
1522  break;
1523  }
1524  }
1525  }
1526 
1527  if (!found_entity) {
1528  UVC_DEBUG("Got status update for unknown VideoControl entity %d",
1529  (int) originator);
1530  UVC_EXIT_VOID();
1531  return;
1532  }
1533 
1534  attribute = transfer->buffer[4];
1535  data = transfer->buffer + 5;
1536  data_len = transfer->actual_length - 5;
1537  break;
1538  }
1539  case 2: /* VideoStreaming interface */
1540  UVC_DEBUG("Unhandled update from VideoStreaming interface",);
1541  UVC_EXIT_VOID();
1542  return; /* @todo VideoStreaming updates */
1543  }
1544 
1545  UVC_DEBUG("Event: class=%d, event=%d, selector=%d, attribute=%d, data_len=%zd",
1546  status_class, event, selector, attribute, data_len);
1547 
1548  if(devh->status_cb) {
1549  UVC_DEBUG("Running user-supplied status callback",);
1550  devh->status_cb(status_class,
1551  event,
1552  selector,
1553  attribute,
1554  data, data_len,
1555  devh->status_user_ptr);
1556  }
1557 
1558  UVC_EXIT_VOID();
1559 }
1560 
1564 void LIBUSB_CALL _uvc_status_callback(struct libusb_transfer *transfer) {
1565  UVC_ENTER();
1566 
1567  uvc_device_handle_t *devh = (uvc_device_handle_t *) transfer->user_data;
1568 
1569  switch (transfer->status) {
1570  case LIBUSB_TRANSFER_ERROR:
1571  case LIBUSB_TRANSFER_CANCELLED:
1572  case LIBUSB_TRANSFER_NO_DEVICE:
1573  UVC_DEBUG("retrying transfer, status = %s", libusb_error_name(transfer->status));
1574  break;
1575  case LIBUSB_TRANSFER_COMPLETED:
1576  uvc_process_status_xfer(devh, transfer);
1577  break;
1578  case LIBUSB_TRANSFER_TIMED_OUT:
1579  case LIBUSB_TRANSFER_STALL:
1580  case LIBUSB_TRANSFER_OVERFLOW:
1581  UVC_DEBUG("retrying transfer, status = %s", libusb_error_name(transfer->status));
1582  break;
1583  }
1584 
1585  uvc_error_t ret = libusb_submit_transfer(transfer);
1586  UVC_DEBUG("libusb_submit_transfer() = %d", ret);
1587 
1588  UVC_EXIT_VOID();
1589 }
1590 
1597  void *user_ptr) {
1598  UVC_ENTER();
1599 
1600  devh->status_cb = cb;
1601  devh->status_user_ptr = user_ptr;
1602 
1603  UVC_EXIT_VOID();
1604 }
1605 
1606 
1615  return devh->info->stream_ifs->format_descs;
1616 }
1617 
void uvc_ref_device(uvc_device_t *dev)
Increment the reference count for a device.
Definition: dev.c:747
uint16_t wOcularFocalLength
Definition: libuvc.h:287
uvc_error_t uvc_parse_vs_frame_format(uvc_streaming_interface_t *stream_if, const unsigned char *block, size_t block_size)
Definition: dev.c:1180
uvc_error_t uvc_open(uvc_device_t *dev, uvc_device_handle_t **devh)
Open a UVC device, defaulting to the first interface found.
Definition: dev.c:200
uint16_t wObjectiveFocalLengthMin
Definition: libuvc.h:285
uint8_t bUnitID
Definition: libuvc.h:312
enum uvc_vs_desc_subtype bDescriptorSubtype
Definition: libuvc.h:124
uvc_error_t uvc_find_device(uvc_context_t *ctx, uvc_device_t **dev, int vid, int pid, const char *sn)
Finds a camera identified by vendor, product and/or serial number.
Definition: dev.c:126
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
const uvc_format_desc_t * uvc_get_format_descs(uvc_device_handle_t *devh)
Get format descriptions for the open device.
Definition: dev.c:1614
uint8_t bSourceID
Definition: libuvc.h:303
enum uvc_error uvc_error_t
enum uvc_it_type wTerminalType
Definition: libuvc.h:284
const char * manufacturer
Definition: libuvc.h:356
uint16_t wWidth
Definition: libuvc.h:90
uint32_t * intervals
Definition: libuvc.h:112
#define DL_FOREACH(head, el)
Definition: utlist.h:76
void uvc_stop_streaming(uvc_device_handle_t *devh)
Stop streaming videoCloses all streams, ends threads and cancels pollers.
Definition: stream.c:1043
uint8_t guidExtensionCode[16]
Definition: libuvc.h:314
uvc_device_t * uvc_get_device(uvc_device_handle_t *devh)
Get the uvc_device_t corresponding to an open device.
Definition: dev.c:668
uint16_t wHeight
Definition: libuvc.h:92
const char * serialNumber
Definition: libuvc.h:354
uint16_t idProduct
Definition: libuvc.h:350
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:2479
struct uvc_format_desc * prev
Definition: libuvc.h:122
struct uvc_device uvc_device_t
Definition: libuvc.h:260
const char * product
Definition: libuvc.h:358
size_t uvc_num_devices(uvc_context_t *ctx)
Definition: dev.c:1445
uvc_error_t uvc_scan_streaming(uvc_device_t *dev, uvc_device_info_t *info, int interface_idx)
Definition: dev.c:1091
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
void uvc_free_device_descriptor(uvc_device_descriptor_t *desc)
Frees a device descriptor created with uvc_get_device_descriptor.
Definition: dev.c:504
uvc_error_t uvc_parse_vs_frame_frame(uvc_streaming_interface_t *stream_if, const unsigned char *block, size_t block_size)
Definition: dev.c:1239
uint32_t dwMinBitRate
Definition: libuvc.h:94
void uvc_process_status_xfer(uvc_device_handle_t *devh, struct libusb_transfer *transfer)
Definition: dev.c:1460
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)
uvc_error_t uvc_parse_vc_processing_unit(uvc_device_t *dev, uvc_device_info_t *info, const unsigned char *block, size_t block_size)
Definition: dev.c:991
GLuint buffer
Definition: glext.h:528
uint32_t dwFrameIntervalStep
Definition: libuvc.h:106
struct uvc_format_desc * parent
Definition: libuvc.h:82
uint16_t wObjectiveFocalLengthMax
Definition: libuvc.h:286
uint32_t dwMaxVideoFrameBufferSize
Definition: libuvc.h:98
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
uvc_error_t uvc_parse_vc(uvc_device_t *dev, uvc_device_info_t *info, const unsigned char *block, size_t block_size)
Definition: dev.c:1046
uint8_t bFrameIntervalType
Definition: libuvc.h:108
libusb_device_handle * uvc_get_libusb_handle(uvc_device_handle_t *devh)
Get the underlying libusb device handle for an open deviceThis can be used to access other interfaces...
Definition: dev.c:685
enum uvc_vs_desc_subtype bDescriptorSubtype
Definition: libuvc.h:85
const uvc_output_terminal_t * uvc_get_output_terminals(uvc_device_handle_t *devh)
Get output terminal descriptors for the open device.
Definition: dev.c:711
uint8_t bBitsPerPixel
Definition: libuvc.h:136
uvc_status_class
Definition: libuvc.h:319
uvc_error_t uvc_parse_vs_format_mjpeg(uvc_streaming_interface_t *stream_if, const unsigned char *block, size_t block_size)
Definition: dev.c:1210
uvc_error_t uvc_parse_vs_frame_uncompressed(uvc_streaming_interface_t *stream_if, const unsigned char *block, size_t block_size)
Definition: dev.c:1291
GLuint GLuint GLsizei count
Definition: glext.h:111
void uvc_unref_device(uvc_device_t *dev)
Decrement the reference count for a device device.
Definition: dev.c:763
void uvc_free_device_info(uvc_device_info_t *info)
Definition: dev.c:381
#define DL_DELETE(head, del)
Definition: utlist.h:58
uint8_t bFormatIndex
Definition: libuvc.h:126
uvc_error_t uvc_get_device_info2(uvc_device_t *dev, uvc_device_info_t **info, int camera_number)
Definition: dev.c:328
uint32_t dwMaxBitRate
Definition: libuvc.h:96
uint8_t bDefaultFrameIndex
Definition: libuvc.h:141
const uvc_extension_unit_t * uvc_get_extension_units(uvc_device_handle_t *devh)
Get extension unit descriptors for the open device.
Definition: dev.c:737
uvc_error_t uvc_claim_if(uvc_device_handle_t *devh, int idx)
Definition: dev.c:782
void LIBUSB_CALL _uvc_status_callback(struct libusb_transfer *transfer)
Definition: dev.c:1564
format
Formats: defines how each stream can be encoded. rs_format specifies how a frame is represented in me...
Definition: rs.hpp:42
uvc_error_t uvc_parse_vc_header(uvc_device_t *dev, uvc_device_info_t *info, const unsigned char *block, size_t block_size)
Definition: dev.c:914
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
uint8_t bAspectRatioY
Definition: libuvc.h:143
uint8_t bCopyProtect
Definition: libuvc.h:145
uint8_t guidFormat[16]
Definition: libuvc.h:130
uint8_t fourccFormat[4]
Definition: libuvc.h:131
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_parse_vs_format_uncompressed(uvc_streaming_interface_t *stream_if, const unsigned char *block, size_t block_size)
Definition: dev.c:1150
void uvc_set_status_callback(uvc_device_handle_t *devh, uvc_status_callback_t cb, void *user_ptr)
Set a callback function to receive status updates.
Definition: dev.c:1595
auto ctx
uint64_t bmControls
Definition: libuvc.h:316
uint64_t bmControls
Definition: libuvc.h:305
void uvc_close(uvc_device_handle_t *devh)
Close a device.
Definition: dev.c:1412
uint8_t bmCapabilities
Definition: libuvc.h:88
uvc_error_t uvc_parse_vc_input_terminal(uvc_device_t *dev, uvc_device_info_t *info, const unsigned char *block, size_t block_size)
Definition: dev.c:956
struct _cl_event * event
Definition: glext.h:2917
uint32_t dwBytesPerLine
Definition: libuvc.h:110
uint8_t bAspectRatioX
Definition: libuvc.h:142
void uvc_start_handler_thread(uvc_context_t *ctx)
uvc_error_t uvc_parse_vc_extension_unit(uvc_device_t *dev, uvc_device_info_t *info, const unsigned char *block, size_t block_size)
Definition: dev.c:1016
uint8_t bFrameIndex
Definition: libuvc.h:87
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
uint8_t uvc_get_device_address(uvc_device_t *dev)
Get the number assigned to the device within its bus.
Definition: dev.c:187
struct uvc_context uvc_context_t
Definition: libuvc.h:253
uint64_t bmControls
Definition: libuvc.h:289
rs_device * dev
uint8_t bNumFrameDescriptors
Definition: libuvc.h:127
void uvc_free_devh(uvc_device_handle_t *devh)
Definition: dev.c:1390
int uvc_already_open(uvc_context_t *ctx, struct libusb_device *usb_dev)
Definition: dev.c:105
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
uint8_t bmFlags
Definition: libuvc.h:138
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
uvc_status_attribute
Definition: libuvc.h:325
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glext.h:112
uint8_t bUnitID
Definition: libuvc.h:301
#define DL_APPEND(head, add)
Definition: utlist.h:44
uvc_error_t uvc_scan_control(uvc_device_t *dev, uvc_device_info_t *info)
Definition: dev.c:843
uvc_error_t uvc_parse_vs(uvc_device_t *dev, uvc_device_info_t *info, uvc_streaming_interface_t *stream_if, const unsigned char *block, size_t block_size)
Definition: dev.c:1343
struct uvc_device_handle uvc_device_handle_t
Definition: libuvc.h:268
#define DL_FOREACH_SAFE(head, el, tmp)
Definition: utlist.h:80
uint32_t dwMinFrameInterval
Definition: libuvc.h:102
uint8_t bmInterlaceFlags
Definition: libuvc.h:144
uvc_error_t uvc_get_device_info(uvc_device_t *dev, uvc_device_info_t **info)
Definition: dev.c:312
GLfloat GLfloat p
Definition: glext.h:11539
uint16_t idVendor
Definition: libuvc.h:348
struct uvc_frame_desc * frame_descs
Definition: libuvc.h:148
uint32_t dwMaxFrameInterval
Definition: libuvc.h:104
uint32_t dwDefaultFrameInterval
Definition: libuvc.h:100
struct uvc_streaming_interface * parent
Definition: libuvc.h:121
uvc_error_t uvc_parse_vs_input_header(uvc_streaming_interface_t *stream_if, const unsigned char *block, size_t block_size)
Definition: dev.c:1134
uvc_error_t uvc_release_if(uvc_device_handle_t *devh, int idx)
Definition: dev.c:810
uint8_t bVariableSize
Definition: libuvc.h:146
uint8_t bTerminalID
Definition: libuvc.h:282


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