CGR Localization
 All Classes Namespaces Files Functions Variables Macros Pages
usb_libusb10.h
1 /*
2  * This file is part of the OpenKinect Project. http://www.openkinect.org
3  *
4  * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
5  * for details.
6  *
7  * This code is licensed to you under the terms of the Apache License, version
8  * 2.0, or, at your option, the terms of the GNU General Public License,
9  * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
10  * or the following URLs:
11  * http://www.apache.org/licenses/LICENSE-2.0
12  * http://www.gnu.org/licenses/gpl-2.0.txt
13  *
14  * If you redistribute this file in source form, modified or unmodified, you
15  * may:
16  * 1) Leave this header intact and distribute it under the same terms,
17  * accompanying it with the APACHE20 and GPL20 files, or
18  * 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
19  * 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
20  * In all cases you must keep the copyright notice intact and include a copy
21  * of the CONTRIB file.
22  *
23  * Binary distributions must follow the binary distribution requirements of
24  * either License.
25  */
26 
27 #ifndef USB_LIBUSB10
28 #define USB_LIBUSB10
29 
30 #include <libusb.h>
31 
32 #if defined(__APPLE__)
33 /*
34  From Github Issue 22 by Roefer -
35  https://github.com/OpenKinect/libfreenect/issues/#issue/22
36 
37  The current implementation still does not reach 30 Hz on MacOS. This
38  is due to bad scheduling of USB transfers in libusb (Ed Note: libusb
39  1.0.8). A fix can be found at
40  http://www.informatik.uni-bremen.de/~roefer/libusb/libusb-osx-kinect.diff
41 
42  (Ed Note: patch applies to libusb repo at 7da756e09fd)
43 
44  In camera.c, I use PKTS_PER_XFER = 128, NUM_XFERS = 4. There are a
45  few rules: PKTS_PER_XFER * NUM_XFERS <= 1000, PKTS_PER_XFER % 8 == 0.
46 */
47 #define PKTS_PER_XFER 128
48 #define NUM_XFERS 4
49 #define DEPTH_PKTBUF 2048
50 #define RGB_PKTBUF 2048
51 #else
52 #define PKTS_PER_XFER 16
53 #define NUM_XFERS 16
54 #define DEPTH_PKTBUF 1920
55 #define RGB_PKTBUF 1920
56 #endif
57 
58 
59 typedef struct {
60  libusb_context *ctx;
61  int should_free_ctx;
62 } fnusb_ctx;
63 
64 typedef struct {
65  freenect_device *parent; //so we can go up from the libusb userdata
66  libusb_device_handle *dev;
67 } fnusb_dev;
68 
69 typedef struct {
70  fnusb_dev *parent; //so we can go up from the libusb userdata
71  struct libusb_transfer **xfers;
72  uint8_t *buffer;
73  fnusb_iso_cb cb;
74  int num_xfers;
75  int pkts;
76  int len;
78 
79 int fnusb_init(fnusb_ctx *ctx, freenect_usb_context *usb_ctx);
80 int fnusb_shutdown(fnusb_ctx *ctx);
81 int fnusb_process_events(fnusb_ctx *ctx);
82 
83 int fnusb_open_subdevices(freenect_device *dev, int index);
84 
85 int fnusb_start_iso(fnusb_dev *dev, fnusb_isoc_stream *strm, fnusb_iso_cb cb, int ep, int xfers, int pkts, int len);
86 int fnusb_stop_iso(fnusb_dev *dev, fnusb_isoc_stream *strm);
87 
88 int fnusb_control(fnusb_dev *dev, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t *data, uint16_t wLength);
89 
90 
91 #endif