[
  {
    "path": ".gitignore",
    "content": "\n.svn/\nobj/\nbin/\nbuild/\n!data/\nipch/\n\n# mac Finder index files\n.DS_*\n\n# mac apps\n*.app*\n\n# xcode user project files\n*.pbxuser\n*.perspectivev3\nxcuserdata\n*.mode1*v3\n\n# codeblocks project files\n*.depend\n*.layout\n*.cbTemp\n\n# visual studio project files\n*.vcxproj.user\n*.suo\n*.sdf\n*.opensdf\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "Copyright (c) 2010, 2011 ofxKinect Team\n\nThe MIT License <http://www.opensource.org/licenses/mit-license.php>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "ofxKinect\n=========\n\n**Note: As of OpenFrameworks 0.8.0, ofxKinect has been integrated into the OF core. All future development of this addon will take place in the [main OF Github repo](https://github.com/openframeworks/openFrameworks) so please log issues there.**\n\n**This repo will be left for anyone supporting old (pre-0.8.0+) OF projects and will not be updated. The final master branch is compatible with OF 0.8.0.**\n\nCopyright (c) 2010-2013 ofxKinect Team\n\nMIT License.\n\nFor information on usage and redistribution, and for a DISCLAIMER OF ALL\nWARRANTIES, see the file, \"LICENSE.txt,\" in this distribution.\n\nSee https://github.com/ofTheo/ofxKinect for documentation as well as the [OF forums](http://forum.openframeworks.cc/index.php).\n\nThis project uses [libfreenect](https://github.com/OpenKinect/libfreenect), copyrighted by the Open Kinect Project using the Apache License v2. See the file \"APACHE20\" in libs/libfreenect.\n\nDescription\n-----------\n\nofxKinect is an Open Frameworks addon for the Xbox Kinect that runs on Mac OSX, Linux, and Windows.\nOpenFrameworks is a cross platform open source toolkit for creative coding in C++.\n\n[http://www.openframeworks.cc/](http://www.openframeworks.cc/)\n\n#### NOTE: Xbox Kinect models > 1414 (1473, etc) or Kinect4Windows devices that have been plugged into an XBox will not work with ofxKinect on  Mac OSX\n\nIf you have an Xbox Kinect model 1473+ or Kinect4Windows device and want to use it with ofxKinect on OSX, DO NOT plug it into an XBox! If you do, it will receive a firmware update which will cause it to freeze after about 20 secs with libfreenect/ofxKinect on OSX. Linux and Windows are fine. The [fix is in the works](https://github.com/OpenKinect/libfreenect/pull/325).\n\nIn the meantime, we suggest you get the *original* Xbox Kinect model 1414 and keep those new toys away from an XBox ...\n\nInstallation\n------------\n\nTo use ofxKinect, first you need to download and install [Open Frameworks](https://github.com/openframeworks/openFrameworks).\n\nTo get a copy of the repository you can download the source from [http://github.com/ofTheo/ofxKinect](http://github.com/ofTheo/ofxKinect/) or, alternatively, you can use git clone:\n<pre>\ngit clone git://github.com/ofTheo/ofxKinect.git\n</pre>\n\nThe addon should sit in `openFrameworks/addons/ofxKinect/`.\n\n#### Which version to use?\n\nIf you are using a stable version (0062, 007, ...) of OpenFrameworks then you want to use a git tag of ofxKinect for that version. You can select the tag in the Github menu or clone and check it out using git.\n\nFor example, the following commands will clone ofxKinect and switch to the OF 0062 tagged version:\n<pre>\ngit clone git://github.com/ofTheo/ofxKinect.git\ncd ofxKinect\ngit checkout 0062\n</pre>\n\n#### Using the latest ofxKinect\n\nThe master branch of ofxKinect will work with the current master of OpenFrameworks and can be considered unstable. The develop branch is used for testing new features and bugfixes before they are applied to master.\n\nIf you want to work with the latest unstable (still in development) ofxKinect, download the source from the develop branch [https://github.com/ofTheo/ofxKinect/tree/develop](https://github.com/ofTheo/ofxKinect/tree/develop) or via git clone:\n<pre>\ngit clone git://github.com/ofTheo/ofxKinect.git -b develop\n</pre> \n\nWarning: The develop branch will be in flux, so don't be surprised if things do not always work as expected!\n\n#### Bug: ofxKinect 0.7.4 + Windows CodeBlocks 12.11 missing pthread\n\nIf you're using Windows CodeBlocks 12.11 and OF/ofxKinect 0.7.4, you may see an issue where ofxKinect projects cannot compile/link due to missing the \"pthread\" library. This is due to CodeBlocks removing some built in libraries between versions 10.5 & 12.11.\n\nThe fix is to manually add the pthread-win32 library which provides \"pthread\".\n\nFirst, make sure you've followed to \"Add files to MinGW guide\" in the [CodeBlocks 12.11 setup for OF guide](http://www.openframeworks.cc/setup/codeblocks/). Then, manually add pthreads-win32:\n\n1. download the compiled version: http://www.sourceware.org/pthreads-win32/index.html\n2. rename the lib file `Pre-built.2\\lib\\x86\\libpthreadGC2.a` to `libpthread` and copy it into the MinGW folder for your CodeBlocks installation:\n`C:\\Program Files (x86)\\CodeBlocks\\MinGW\\lib`\n3. if they do not exist, copy the header (.h) files in `Pre-build.2\\include` into  your CodeBlocks installation: `C:\\Program Files (x86)\\CodeBlocks\\MinGW\\include`\n\nRunning the Example Project\n---------------------------\n\nAn example project is provided in the `kinectExample` folder. As of OF 0.8.0, ofxKinect no longer ships with the platform project files. Simply use the OpenFrameworks ProjectGenerator in `apps/projectGenerator` to generate the Xcode, VS2012, CodeBlocks projects and/or Makefiles by pointing it to the `kinectExample` folder and making sure to include the following addons:\n\n* ofxKinect (duh)\n* ofxOpenCv (for blob tracking in the example, not required by ofxKinect itself.)\n\n### OSX\n\nXcode4: Open the Xcode project, select the \"kinectExample Debug\" scheme, and hit \"Run\".\n\n### Linux\n\nInstall the libusb-1.0 library. On Ubuntu, you can do this with:\n<pre>\nsudo apt-get install libusb-1.0-0-dev\n</pre>\n\nOpen the Code::Blocks .cbp and hit F9 to build. Optionally, you can build the example with the Makefile.\n\nTo run it, use the terminal:\n<pre>\nmake\ncd bin\n./example_debug\n</pre>\n\nAlso, you can add a set of udev rules which allow you to run a kinect app without root privileges:\n\n   sudo libs\\libfreenect\\platform\\linux\\udev\\51-kinect.rules /etc/udev/rules.d\n\n### Windows\n\nPrecompiled libfreenect drivers and libusb-win32 libs are included for Windows.\n\nMake sure to install or update the libfreenect Kinect camera, motor, and audio drivers through Windows Device Manager by pointing it to the driver folder:\n<pre>\nofxKinect/libs/libfreenect/platform/windows/inf\n</pre>\n\nYou may need to manually update each driver individually if you've plugged it in before. ofxKinect will not work if the drivers are not installed.\n\n**NOTE**: You cannot use the OpenNI drivers and the libfreenect drivers included with ofxKinect at the same time. You must manually uninstall one and reinstall the other in the Device Manager. Sorry, that's just how it is. :P \n\nHow to Create a New ofxKinect Project\n-------------------------------------\n\nTo develop your own project based on ofxKinect, simply copy the example project and rename it. You probably want to put it in your apps folder, for example, after copying:\n\n`openFrameworks/addons/ofxKinect/kinectExample/ => openFrameworks/apps/myApps/kinectExample/`\n\nThen after renaming:\n\n`openFrameworks/apps/myApps/myKinectProject/`\n\n### Mac (Xcode):\n\nRename the project in Xcode (do not rename the .xcodeproj file in Finder!): Slow double click the project name and rename (Xcode4)\n\n### Codeblocks (Win & Linux):\n\nClose Codeblocks and rename the *.cbp and *.workspace files to the same name as the project folder. Open the workspace and readd the renamed project file.\n\n### Windows (Visual Studio):\n\nClose Visual Studio and rename the *.sln file. Open the solution, right click on the project in the project browser and select \"Rename ...\".\n\nAdding ofxKinect to an Existing Project\n---------------------------------------\n\nIf you want to add ofxKinect to another project, you need to make sure you include the src folder and the :\n<pre>\nopenFrameworks/addons/ofxKinect/src\n</pre>\nas well as search paths for the addons (ofxOpenCv) and libs (freenect, libusb) required by ofxKinect.\n\nDon't forget to include the ofxOpenCv addon sources and opencv libraries.\n\n### Mac (Xcode):\n\nIn the Xcode project browser:\n\n* add the ofxKinect sources to the project:\n  * create a new group \"ofxKinect\"\n  * drag these directories from ofxKinect into this new group: ofxKinect/src & ofxKinect/libs\n* add a search path to the libusb headers: `../../../addons/ofxKinect/libs/libusb/include/libusb-1.0` to your project Target build settings\n  * Xcode4: add the lib path to your Project.xconfig, see the example\n* add the path to the libusb precompiled library: `../../../addons/ofxKinect/libs/libusb-1.0/lib/osx/usb-1.0.a`\n  * Xcode4: add the lib path to your Project.xconfig, see the example\n  \n### Linux (Makefiles & Codeblocks):\n\nEdit the Makefile config files:\n \n* edit addons.make in your project folder and add the following line to the end of the file: \n\t<pre>ofxKinect</pre>\n* edit config.make in your project folder and change the lines for USER_LIBS to:\n\t<pre>\n\tUSER_LIBS = -lusb-1.0\n\t</pre>\n\n#### Windows (Visual Studio):\n\n* add the ofxPd sources to the project:\n\t* right click on the addons folder in your project tree and create a new filter named \"ofxKinect\"\n\t* drag the src directory from the ofxKinect addon folder in Explorer into the ofxKinect folder in your project tree\n* add header and library search paths:\n\t* right lick on your project and select \"Properties\"\n\t* choose \"Debug\" from the \"Configurations\" drop down box\n\t* under C/C++->General, add the following to the \"Additional Include Directories\":\n\t<pre>\n\t..\\\\..\\\\..\\addons\\ofxKinect\\src\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libfreenect\\src\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libfreenect\\include\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libfreenect\\platform\\windows\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libfreenect\\platform\\windows\\libusb10emu\\libusb-1.0\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libusb-win32\\include\n\t</pre>\n\t* under Linker->General, add the following to the \"Additional Library Directories\":\n\t<pre>\n\t..\\..\\..\\addons\\ofxKinect\\libs\\libusb-win32\\lib\\vs\n\t</pre>\n\t* repeat for the \"Release\" configuration\n\t\n#### Windows (Codeblocks):\n\n* add the ofxPd sources to the project:\n\t* right-click on your project in the project tree\n\t* select \"Add Files Recursively ...\"\n\t* navigate and choose the ofxKinect/src folder\n* add search paths and libraries to link:\n\t* right-click on your project in the project tree\n\t* select \"Build options...\"\n\t* make sure the project name is selected in the tree (not release or debug)\n\t* select the \"Search directories\" tab, click add the search paths:\n\t<pre>\n\t..\\\\..\\\\..\\addons\\ofxKinect\\src\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libfreenect\\src\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libfreenect\\include\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libfreenect\\platform\\windows\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libfreenect\\platform\\windows\\libusb10emu\\libusb-1.0\n\t..\\\\..\\\\..\\addons\\ofxKinect\\libs\\libusb-win32\\include\n\t</pre>\n\t* select the \"Linker settings\" tab, add the following to Link libraries:\n\t<pre>\n\tm\n\tpthread\n\t</pre>\n\t* select the \"Linker settings\" tab, add the following to Other liker options:\n\t<pre>\n\t..\\..\\..\\addons\\ofxKinect\\libs\\libusb-win32\\lib\\win_cb\\libusb.lib\n\t</pre>\n\nNotes\n-----\n\n### Using multiple kinects\n\nofxKinect supports multiple kinects, however stability is based on the bandwidth of your usb hardware. If you only require the depth image, it is recommended to disable the video grabbing of the rgb/ir images from your devices:\n<pre>\nkinect.init(false, false);  // disable video image (faster fps)\n</pre>\n\nFor Kinect4Windows, Microsoft states that only 2 Kinects can be supported on the same USB bus. In practice on OSX, this proves to be the case as, even with the RGB images disabled, there are transfer errors using ofxKinect and 3 Kinects simultaneously. If you need to support many Kinects, you will probably need to add extra USB controllers to your machine …\n\nDeveloping ofxKinect\n--------------------\n\nFeel free to log bug reports and issues to the ofxKinect Github page: https://github.com/ofTheo/ofxKinect/issues\n\nIf you wish to help in ofxKinect development, please refer to the wiki: https://github.com/ofTheo/ofxKinect/wiki/Developing-ofxKinect\n"
  },
  {
    "path": "addon_config.mk",
    "content": "# All variables and this file are optional, if they are not present the PG and the\n# makefiles will try to parse the correct values from the file system.\n#\n# Variables that specify exclusions can use % as a wildcard to specify that anything in\n# that position will match. A partial path can also be specified to, for example, exclude\n# a whole folder from the parsed paths from the file system\n#\n# Variables can be specified using = or +=\n# = will clear the contents of that variable both specified from the file or the ones parsed\n# from the file system\n# += will add the values to the previous ones in the file or the ones parsed from the file \n# system\n# \n# The PG can be used to detect errors in this file, just create a new project with this addon \n# and the PG will write to the console the kind of error and in which line it is\n\nmeta:\n\tADDON_NAME = ofxKinect\n\tADDON_DESCRIPTION = Addon for interfacing with microsoft kinect cameras\n\tADDON_AUTHOR = Dan Wilcox, Theo Watson, Kyle McDonald, Arturo Castro\n\tADDON_TAGS = \"computer vision\" \"3D sensing\" \"kinect\"\n\tADDON_URL = http://github.com/ofTheo/ofxKinect\n\ncommon:\n\t# dependencies with other addons, a list of them separated by spaces \n\t# or use += in several lines\n\t# ADDON_DEPENDENCIES =\n\t\n\t# include search paths, this will be usually parsed from the file system\n\t# but if the addon or addon libraries need special search paths they can be\n\t# specified here separated by spaces or one per line using +=\n\t# ADDON_INCLUDES =\n\t\n\t# any special flag that should be passed to the compiler when using this\n\t# addon\n\t# ADDON_CFLAGS =\n\t\n\t# any special flag that should be passed to the linker when using this\n\t# addon, also used for system libraries with -lname\n\t# ADDON_LDFLAGS =\n\t\n\t# linux only, any library that should be included in the project using\n\t# pkg-config\n\t# ADDON_PKG_CONFIG_LIBRARIES =\n\t\n\t# osx/iOS only, any framework that should be included in the project\n\t# ADDON_FRAMEWORKS =\n\t\n\t# source files, these will be usually parsed from the file system looking\n\t# in the src folders in libs and the root of the addon. if your addon needs\n\t# to include files in different places or a different set of files per platform\n\t# they can be specified here\n\t# ADDON_SOURCES =\n\t\n\t# some addons need resources to be copied to the bin/data folder of the project\n\t# specify here any files that need to be copied, you can use wildcards like * and ?\n\t# ADDON_DATA = \n\t\n\t# when parsing the file system looking for libraries exclude this for all or\n\t# a specific platform\n\t# ADDON_LIBS_EXCLUDE =\n\t\n\t# when parsing the file system looking for sources exclude this for all or\n\t# a specific platform\n\t# ADDON_SOURCES_EXCLUDE = \n\t\n\t# when parsing the file system looking for include paths exclude this for all or\n\t# a specific platform\n    # ADDON_INCLUDES_EXCLUDE =\n\t\nlinux64:\n\t# linux only, any library that should be included in the project using\n\t# pkg-config\n\tADDON_PKG_CONFIG_LIBRARIES = libusb-1.0\n\t\n\t# when parsing the file system looking for sources exclude this for all or\n\t# a specific platform\n\tADDON_SOURCES_EXCLUDE = libs/libfreenect/platform/%\n\tADDON_SOURCES_EXCLUDE += libs/libusb-win32/%\n\t\n\t# when parsing the file system looking for include paths exclude this for all or\n\t# a specific platform\n    ADDON_INCLUDES_EXCLUDE = libs/libfreenect/platform/%\n    ADDON_INCLUDES_EXCLUDE += libs/libusb-win32/%\n\tADDON_INCLUDES_EXCLUDE += libs/libusb-1.0/%\n\t\nlinux:\n\t# linux only, any library that should be included in the project using\n\t# pkg-config\n\tADDON_PKG_CONFIG_LIBRARIES = libusb-1.0\n\t\n\t# when parsing the file system looking for sources exclude this for all or\n\t# a specific platform\n\tADDON_SOURCES_EXCLUDE = libs/libfreenect/platform/%\n\tADDON_SOURCES_EXCLUDE += libs/libusb-win32/%\n\t\n\t# when parsing the file system looking for include paths exclude this for all or\n\t# a specific platform\n    ADDON_INCLUDES_EXCLUDE = libs/libfreenect/platform/%\n    ADDON_INCLUDES_EXCLUDE += libs/libusb-win32/%\n\tADDON_INCLUDES_EXCLUDE += libs/libusb-1.0/%\n\t\nwin_cb:\n\t# source files, these will be usually parsed from the file system looking\n\t# in the src folders in libs and the root of the addon. if your addon needs\n\t# to include files in different places or a different set of files per platform\n\t# they can be specified here\n\tADDON_SOURCES += libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/failguard.cpp\n\tADDON_SOURCES += libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/libusbemu.cpp\n\t\n\t# include search paths, this will be usually parsed from the file system\n\t# but if the addon or addon libraries need special search paths they can be\n\t# specified here separated by spaces or one per line using +=\n\tADDON_INCLUDES += libs/libfreenect/platform/windows\n\n\t# when parsing the file system looking for include paths exclude this for all or\n\t# a specific platform\n\tADDON_INCLUDES_EXCLUDE += libs/libusb-1.0/%\n\t\nvs:\n\t# source files, these will be usually parsed from the file system looking\n\t# in the src folders in libs and the root of the addon. if your addon needs\n\t# to include files in different places or a different set of files per platform\n\t# they can be specified here\n\tADDON_SOURCES += libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/failguard.cpp\n\tADDON_SOURCES += libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/libusbemu.cpp\n\t\n\t# include search paths, this will be usually parsed from the file system\n\t# but if the addon or addon libraries need special search paths they can be\n\t# specified here separated by spaces or one per line using +=\n\tADDON_INCLUDES += libs/libfreenect/platform/windows\n\t\n\t# when parsing the file system looking for include paths exclude this for all or\n\t# a specific platform\n\tADDON_INCLUDES_EXCLUDE += libs/libusb-1.0/%\n\t\nlinuxarmv6l:\n\t# linux only, any library that should be included in the project using\n\t# pkg-config\n\tADDON_PKG_CONFIG_LIBRARIES = libusb-1.0\n\t\n\t# when parsing the file system looking for sources exclude this for all or\n\t# a specific platform\n\tADDON_SOURCES_EXCLUDE = libs/libfreenect/platform/%\n\tADDON_SOURCES_EXCLUDE += libs/libusb-win32/%\n\t\n\t# when parsing the file system looking for include paths exclude this for all or\n\t# a specific platform\n    ADDON_INCLUDES_EXCLUDE = libs/libfreenect/platform/%\n    ADDON_INCLUDES_EXCLUDE += libs/libusb-win32/%\n\tADDON_INCLUDES_EXCLUDE += libs/libusb-1.0/%\n\t\n\t\nlinuxarmv7l:\n\t# linux only, any library that should be included in the project using\n\t# pkg-config\n\tADDON_PKG_CONFIG_LIBRARIES = libusb-1.0\n\t\n\t# when parsing the file system looking for sources exclude this for all or\n\t# a specific platform\n\tADDON_SOURCES_EXCLUDE = libs/libfreenect/platform/%\n\tADDON_SOURCES_EXCLUDE += libs/libusb-win32/%\n\t\n\t# when parsing the file system looking for include paths exclude this for all or\n\t# a specific platform\n    ADDON_INCLUDES_EXCLUDE = libs/libfreenect/platform/%\n    ADDON_INCLUDES_EXCLUDE += libs/libusb-win32/%\n\tADDON_INCLUDES_EXCLUDE += libs/libusb-1.0/%\n\nandroid/armeabi:\t\n\t\nandroid/armeabi-v7a:\t\n\nosx:\n\t# when parsing the file system looking for sources exclude this for all or\n\t# a specific platform\n\tADDON_SOURCES_EXCLUDE = libs/libfreenect/platform/%\n\tADDON_SOURCES_EXCLUDE += libs/libusb-win32/%\n\t\n\t# when parsing the file system looking for include paths exclude this for all or\n\t# a specific platform\n    ADDON_INCLUDES_EXCLUDE = libs/libfreenect/platform/%\n    ADDON_INCLUDES_EXCLUDE += libs/libusb-win32/%\n    \nios:\n\n\n"
  },
  {
    "path": "kinectExample/addons.make",
    "content": "ofxKinect\nofxOpenCv\n"
  },
  {
    "path": "kinectExample/src/main.cpp",
    "content": "#include \"testApp.h\"\n#include \"ofAppGlutWindow.h\"\n\nint main() {\n\tofAppGlutWindow window;\n\tofSetupOpenGL(&window, 1024, 768, OF_WINDOW);\n\tofRunApp(new testApp());\n}\n"
  },
  {
    "path": "kinectExample/src/testApp.cpp",
    "content": "#include \"testApp.h\"\n\n\n//--------------------------------------------------------------\nvoid testApp::setup() {\n\tofSetLogLevel(OF_LOG_VERBOSE);\n\t\n\t// enable depth->video image calibration\n\tkinect.setRegistration(true);\n    \n\tkinect.init();\n\t//kinect.init(true); // shows infrared instead of RGB video image\n\t//kinect.init(false, false); // disable video image (faster fps)\n\t\n\tkinect.open();\t\t// opens first available kinect\n\t//kinect.open(1);\t// open a kinect by id, starting with 0 (sorted by serial # lexicographically))\n\t//kinect.open(\"A00362A08602047A\");\t// open a kinect using it's unique serial #\n\t\n\t// print the intrinsic IR sensor values\n\tif(kinect.isConnected()) {\n\t\tofLogNotice() << \"sensor-emitter dist: \" << kinect.getSensorEmitterDistance() << \"cm\";\n\t\tofLogNotice() << \"sensor-camera dist:  \" << kinect.getSensorCameraDistance() << \"cm\";\n\t\tofLogNotice() << \"zero plane pixel size: \" << kinect.getZeroPlanePixelSize() << \"mm\";\n\t\tofLogNotice() << \"zero plane dist: \" << kinect.getZeroPlaneDistance() << \"mm\";\n\t}\n\t\n#ifdef USE_TWO_KINECTS\n\tkinect2.init();\n\tkinect2.open();\n#endif\n\t\n\tcolorImg.allocate(kinect.width, kinect.height);\n\tgrayImage.allocate(kinect.width, kinect.height);\n\tgrayThreshNear.allocate(kinect.width, kinect.height);\n\tgrayThreshFar.allocate(kinect.width, kinect.height);\n\t\n\tnearThreshold = 230;\n\tfarThreshold = 70;\n\tbThreshWithOpenCV = true;\n\t\n\tofSetFrameRate(60);\n\t\n\t// zero the tilt on startup\n\tangle = 0;\n\tkinect.setCameraTiltAngle(angle);\n\t\n\t// start from the front\n\tbDrawPointCloud = false;\n}\n\n//--------------------------------------------------------------\nvoid testApp::update() {\n\t\n\tofBackground(100, 100, 100);\n\t\n\tkinect.update();\n\t\n\t// there is a new frame and we are connected\n\tif(kinect.isFrameNew()) {\n\t\t\n\t\t// load grayscale depth image from the kinect source\n\t\tgrayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);\n\t\t\n\t\t// we do two thresholds - one for the far plane and one for the near plane\n\t\t// we then do a cvAnd to get the pixels which are a union of the two thresholds\n\t\tif(bThreshWithOpenCV) {\n\t\t\tgrayThreshNear = grayImage;\n\t\t\tgrayThreshFar = grayImage;\n\t\t\tgrayThreshNear.threshold(nearThreshold, true);\n\t\t\tgrayThreshFar.threshold(farThreshold);\n\t\t\tcvAnd(grayThreshNear.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL);\n\t\t} else {\n\t\t\t\n\t\t\t// or we do it ourselves - show people how they can work with the pixels\n\t\t\tunsigned char * pix = grayImage.getPixels();\n\t\t\t\n\t\t\tint numPixels = grayImage.getWidth() * grayImage.getHeight();\n\t\t\tfor(int i = 0; i < numPixels; i++) {\n\t\t\t\tif(pix[i] < nearThreshold && pix[i] > farThreshold) {\n\t\t\t\t\tpix[i] = 255;\n\t\t\t\t} else {\n\t\t\t\t\tpix[i] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t// update the cv images\n\t\tgrayImage.flagImageChanged();\n\t\t\n\t\t// find contours which are between the size of 20 pixels and 1/3 the w*h pixels.\n\t\t// also, find holes is set to true so we will get interior contours as well....\n\t\tcontourFinder.findContours(grayImage, 10, (kinect.width*kinect.height)/2, 20, false);\n\t}\n\t\n#ifdef USE_TWO_KINECTS\n\tkinect2.update();\n#endif\n}\n\n//--------------------------------------------------------------\nvoid testApp::draw() {\n\t\n\tofSetColor(255, 255, 255);\n\t\n\tif(bDrawPointCloud) {\n\t\teasyCam.begin();\n\t\tdrawPointCloud();\n\t\teasyCam.end();\n\t} else {\n\t\t// draw from the live kinect\n\t\tkinect.drawDepth(10, 10, 400, 300);\n\t\tkinect.draw(420, 10, 400, 300);\n\t\t\n\t\tgrayImage.draw(10, 320, 400, 300);\n\t\tcontourFinder.draw(10, 320, 400, 300);\n\t\t\n#ifdef USE_TWO_KINECTS\n\t\tkinect2.draw(420, 320, 400, 300);\n#endif\n\t}\n\t\n\t// draw instructions\n\tofSetColor(255, 255, 255);\n\tstringstream reportStream;\n        \n    if(kinect.hasAccelControl()) {\n        reportStream << \"accel is: \" << ofToString(kinect.getMksAccel().x, 2) << \" / \"\n        << ofToString(kinect.getMksAccel().y, 2) << \" / \"\n        << ofToString(kinect.getMksAccel().z, 2) << endl;\n    } else {\n        reportStream << \"Note: this is a newer Xbox Kinect or Kinect For Windows device,\" << endl\n\t\t<< \"motor / led / accel controls are not currently supported\" << endl << endl;\n    }\n    \n\treportStream << \"press p to switch between images and point cloud, rotate the point cloud with the mouse\" << endl\n\t<< \"using opencv threshold = \" << bThreshWithOpenCV <<\" (press spacebar)\" << endl\n\t<< \"set near threshold \" << nearThreshold << \" (press: + -)\" << endl\n\t<< \"set far threshold \" << farThreshold << \" (press: < >) num blobs found \" << contourFinder.nBlobs\n\t<< \", fps: \" << ofGetFrameRate() << endl\n\t<< \"press c to close the connection and o to open it again, connection is: \" << kinect.isConnected() << endl;\n\n    if(kinect.hasCamTiltControl()) {\n    \treportStream << \"press UP and DOWN to change the tilt angle: \" << angle << \" degrees\" << endl\n        << \"press 1-5 & 0 to change the led mode\" << endl;\n    }\n    \n\tofDrawBitmapString(reportStream.str(), 20, 652);\n    \n}\n\nvoid testApp::drawPointCloud() {\n\tint w = 640;\n\tint h = 480;\n\tofMesh mesh;\n\tmesh.setMode(OF_PRIMITIVE_POINTS);\n\tint step = 2;\n\tfor(int y = 0; y < h; y += step) {\n\t\tfor(int x = 0; x < w; x += step) {\n\t\t\tif(kinect.getDistanceAt(x, y) > 0) {\n\t\t\t\tmesh.addColor(kinect.getColorAt(x,y));\n\t\t\t\tmesh.addVertex(kinect.getWorldCoordinateAt(x, y));\n\t\t\t}\n\t\t}\n\t}\n\tglPointSize(3);\n\tofPushMatrix();\n\t// the projected points are 'upside down' and 'backwards' \n\tofScale(1, -1, -1);\n\tofTranslate(0, 0, -1000); // center the points a bit\n\tglEnable(GL_DEPTH_TEST);\n\tmesh.drawVertices();\n\tglDisable(GL_DEPTH_TEST);\n\tofPopMatrix();\n}\n\n//--------------------------------------------------------------\nvoid testApp::exit() {\n\tkinect.setCameraTiltAngle(0); // zero the tilt on exit\n\tkinect.close();\n\t\n#ifdef USE_TWO_KINECTS\n\tkinect2.close();\n#endif\n}\n\n//--------------------------------------------------------------\nvoid testApp::keyPressed (int key) {\n\tswitch (key) {\n\t\tcase ' ':\n\t\t\tbThreshWithOpenCV = !bThreshWithOpenCV;\n\t\t\tbreak;\n\t\t\t\n\t\tcase'p':\n\t\t\tbDrawPointCloud = !bDrawPointCloud;\n\t\t\tbreak;\n\t\t\t\n\t\tcase '>':\n\t\tcase '.':\n\t\t\tfarThreshold ++;\n\t\t\tif (farThreshold > 255) farThreshold = 255;\n\t\t\tbreak;\n\t\t\t\n\t\tcase '<':\n\t\tcase ',':\n\t\t\tfarThreshold --;\n\t\t\tif (farThreshold < 0) farThreshold = 0;\n\t\t\tbreak;\n\t\t\t\n\t\tcase '+':\n\t\tcase '=':\n\t\t\tnearThreshold ++;\n\t\t\tif (nearThreshold > 255) nearThreshold = 255;\n\t\t\tbreak;\n\t\t\t\n\t\tcase '-':\n\t\t\tnearThreshold --;\n\t\t\tif (nearThreshold < 0) nearThreshold = 0;\n\t\t\tbreak;\n\t\t\t\n\t\tcase 'w':\n\t\t\tkinect.enableDepthNearValueWhite(!kinect.isDepthNearValueWhite());\n\t\t\tbreak;\n\t\t\t\n\t\tcase 'o':\n\t\t\tkinect.setCameraTiltAngle(angle); // go back to prev tilt\n\t\t\tkinect.open();\n\t\t\tbreak;\n\t\t\t\n\t\tcase 'c':\n\t\t\tkinect.setCameraTiltAngle(0); // zero the tilt\n\t\t\tkinect.close();\n\t\t\tbreak;\n\t\t\t\n\t\tcase '1':\n\t\t\tkinect.setLed(ofxKinect::LED_GREEN);\n\t\t\tbreak;\n\t\t\t\n\t\tcase '2':\n\t\t\tkinect.setLed(ofxKinect::LED_YELLOW);\n\t\t\tbreak;\n\t\t\t\n\t\tcase '3':\n\t\t\tkinect.setLed(ofxKinect::LED_RED);\n\t\t\tbreak;\n\t\t\t\n\t\tcase '4':\n\t\t\tkinect.setLed(ofxKinect::LED_BLINK_GREEN);\n\t\t\tbreak;\n\t\t\t\n\t\tcase '5':\n\t\t\tkinect.setLed(ofxKinect::LED_BLINK_YELLOW_RED);\n\t\t\tbreak;\n\t\t\t\n\t\tcase '0':\n\t\t\tkinect.setLed(ofxKinect::LED_OFF);\n\t\t\tbreak;\n\t\t\t\n\t\tcase OF_KEY_UP:\n\t\t\tangle++;\n\t\t\tif(angle>30) angle=30;\n\t\t\tkinect.setCameraTiltAngle(angle);\n\t\t\tbreak;\n\t\t\t\n\t\tcase OF_KEY_DOWN:\n\t\t\tangle--;\n\t\t\tif(angle<-30) angle=-30;\n\t\t\tkinect.setCameraTiltAngle(angle);\n\t\t\tbreak;\n\t}\n}\n\n//--------------------------------------------------------------\nvoid testApp::mouseDragged(int x, int y, int button)\n{}\n\n//--------------------------------------------------------------\nvoid testApp::mousePressed(int x, int y, int button)\n{}\n\n//--------------------------------------------------------------\nvoid testApp::mouseReleased(int x, int y, int button)\n{}\n\n//--------------------------------------------------------------\nvoid testApp::windowResized(int w, int h)\n{}\n"
  },
  {
    "path": "kinectExample/src/testApp.h",
    "content": "#pragma once\n\n#include \"ofMain.h\"\n#include \"ofxOpenCv.h\"\n#include \"ofxKinect.h\"\n\n// Windows users:\n// You MUST install the libfreenect kinect drivers in order to be able to use\n// ofxKinect. Plug in the kinect and point your Windows Device Manager to the\n// driver folder in:\n//\n//     ofxKinect/libs/libfreenect/platform/windows/inf\n//\n// This should install the Kinect camera, motor, & audio drivers.\n//\n// You CANNOT use this driver and the OpenNI driver with the same device. You\n// will have to manually update the kinect device to use the libfreenect drivers\n// and/or uninstall/reinstall it in Device Manager.\n//\n// No way around the Windows driver dance, sorry.\n\n// uncomment this to read from two kinects simultaneously\n//#define USE_TWO_KINECTS\n\nclass testApp : public ofBaseApp {\npublic:\n\t\n\tvoid setup();\n\tvoid update();\n\tvoid draw();\n\tvoid exit();\n\t\n\tvoid drawPointCloud();\n\t\n\tvoid keyPressed(int key);\n\tvoid mouseDragged(int x, int y, int button);\n\tvoid mousePressed(int x, int y, int button);\n\tvoid mouseReleased(int x, int y, int button);\n\tvoid windowResized(int w, int h);\n\t\n\tofxKinect kinect;\n\t\n#ifdef USE_TWO_KINECTS\n\tofxKinect kinect2;\n#endif\n\t\n\tofxCvColorImage colorImg;\n\t\n\tofxCvGrayscaleImage grayImage; // grayscale depth image\n\tofxCvGrayscaleImage grayThreshNear; // the near thresholded image\n\tofxCvGrayscaleImage grayThreshFar; // the far thresholded image\n\t\n\tofxCvContourFinder contourFinder;\n\t\n\tbool bThreshWithOpenCV;\n\tbool bDrawPointCloud;\n\t\n\tint nearThreshold;\n\tint farThreshold;\n\t\n\tint angle;\n\t\n\t// used for viewing the point cloud\n\tofEasyCam easyCam;\n};\n"
  },
  {
    "path": "libs/libfreenect/APACHE20",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "libs/libfreenect/CONTRIB",
    "content": "For a list of libfreenect authors, please see the Git history of the project,\nsuch as with 'git log'. This file will contain a list of authors on release\nsnapshots of libfreenect.\n\nTHIS FILE IS NOT VALID FOR NON-GIT DISTRIBUTIONS. If you wish to redistribute\nlibfreenect source code outside of the Git infrastructure, you MUST either use\na release version or generate a complete CONTRIB file valid for the source Git\nrevision tree that you use for your distribution. Redistributions of libfreenect\nsource code without a valid CONTRIB file and without Git metadata are not\ncompliant with the license.\n"
  },
  {
    "path": "libs/libfreenect/GPL2",
    "content": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n                       51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n\t\t    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n\t    How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\n\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) year name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "libs/libfreenect/include/libfreenect-registration.h",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2011 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#ifndef LIBFREENECT_REGISTRATION_H\n#define LIBFREENECT_REGISTRATION_H\n\n#include <libfreenect.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/// Internal Kinect registration parameters.\n/// Structure matches that of the line protocol\n/// of the Kinect.\ntypedef struct {\n\tint32_t dx_center; // not used by mapping algorithm\n\n\tint32_t ax;\n\tint32_t bx;\n\tint32_t cx;\n\tint32_t dx;\n\n\tint32_t dx_start;\n\n\tint32_t ay;\n\tint32_t by;\n\tint32_t cy;\n\tint32_t dy;\n\n\tint32_t dy_start;\n\n\tint32_t dx_beta_start;\n\tint32_t dy_beta_start;\n\n\tint32_t rollout_blank; // not used by mapping algorithm\n\tint32_t rollout_size;  // not used by mapping algorithm\n\n\tint32_t dx_beta_inc;\n\tint32_t dy_beta_inc;\n\n\tint32_t dxdx_start;\n\tint32_t dxdy_start;\n\tint32_t dydx_start;\n\tint32_t dydy_start;\n\n\tint32_t dxdxdx_start;\n\tint32_t dydxdx_start;\n\tint32_t dxdxdy_start;\n\tint32_t dydxdy_start;\n\n\tint32_t back_comp1; // not used by mapping algorithm\n\n\tint32_t dydydx_start;\n\n\tint32_t back_comp2; // not used by mapping algorithm\n\n\tint32_t dydydy_start;\n} freenect_reg_info;\n\n/// registration padding info (?)\ntypedef struct {\n\tuint16_t start_lines;\n\tuint16_t end_lines;\n\tuint16_t cropping_lines;\n} freenect_reg_pad_info;\n\n/// internal Kinect zero plane data\ntypedef struct {\n\tfloat dcmos_emitter_dist;    // Distance between IR camera and IR emitter, in cm.\n\tfloat dcmos_rcmos_dist;      // Distance between IR camera and RGB camera, in cm.\n\tfloat reference_distance;    // The focal length of the IR camera, in mm.\n\tfloat reference_pixel_size;  // The size of a single pixel on the zero plane, in mm.\n} freenect_zero_plane_info;\n\n/// all data needed for depth->RGB mapping\ntypedef struct {\n\tfreenect_reg_info        reg_info;\n\tfreenect_reg_pad_info    reg_pad_info;\n\tfreenect_zero_plane_info zero_plane_info;\n\n\tdouble const_shift;\n\n\tuint16_t* raw_to_mm_shift;\n\tint32_t* depth_to_rgb_shift;\n\tint32_t (*registration_table)[2];  // A table of 640*480 pairs of x,y values.\n\t                                   // Index first by pixel, then x:0 and y:1.\n} freenect_registration;\n\n\n// These allow clients to export registration parameters; proper docs will\n// come later\nFREENECTAPI freenect_registration freenect_copy_registration(freenect_device* dev);\nFREENECTAPI int freenect_destroy_registration(freenect_registration* reg);\n\n// convenience function to convert a single x-y coordinate pair from camera\n// to world coordinates\nFREENECTAPI void freenect_camera_to_world(freenect_device* dev,\n\tint cx, int cy, int wz, double* wx, double* wy);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif // LIBFREENECT_REGISTRATION_H\n"
  },
  {
    "path": "libs/libfreenect/include/libfreenect.h",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#ifndef LIBFREENECT_H\n#define LIBFREENECT_H\n\n#include <stdint.h>\n\n/* We need struct timeval */\n#ifdef _WIN32\n#include <winsock.h>\n#else\n#include <sys/time.h>\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define FREENECT_COUNTS_PER_G 819 /**< Ticks per G for accelerometer as set per http://www.kionix.com/Product%20Sheets/KXSD9%20Product%20Brief.pdf */\n\n/// Maximum value that a uint16_t pixel will take on in the buffer of any of the FREENECT_DEPTH_MM or FREENECT_DEPTH_REGISTERED frame callbacks\n#define FREENECT_DEPTH_MM_MAX_VALUE 10000\n/// Value indicating that this pixel has no data, when using FREENECT_DEPTH_MM or FREENECT_DEPTH_REGISTERED depth modes\n#define FREENECT_DEPTH_MM_NO_VALUE 0\n/// Maximum value that a uint16_t pixel will take on in the buffer of any of the FREENECT_DEPTH_11BIT, FREENECT_DEPTH_10BIT, FREENECT_DEPTH_11BIT_PACKED, or FREENECT_DEPTH_10BIT_PACKED frame callbacks\n#define FREENECT_DEPTH_RAW_MAX_VALUE 2048\n/// Value indicating that this pixel has no data, when using FREENECT_DEPTH_11BIT, FREENECT_DEPTH_10BIT, FREENECT_DEPTH_11BIT_PACKED, or FREENECT_DEPTH_10BIT_PACKED\n#define FREENECT_DEPTH_RAW_NO_VALUE 2047\n\n/// Flags representing devices to open when freenect_open_device() is called.\n/// In particular, this allows libfreenect to grab only a subset of the devices\n/// in the Kinect, so you could (for instance) use libfreenect to handle audio\n/// and motor support while letting OpenNI have access to the cameras.\n/// If a device is not supported on a particular platform, its flag will be ignored.\ntypedef enum {\n\tFREENECT_DEVICE_MOTOR  = 0x01,\n\tFREENECT_DEVICE_CAMERA = 0x02,\n\tFREENECT_DEVICE_AUDIO  = 0x04,\n} freenect_device_flags;\n\n/// A struct used in enumeration to give access to serial numbers, so you can\n/// open a particular device by serial rather than depending on index.  This\n/// is most useful if you have more than one Kinect.\nstruct freenect_device_attributes;\nstruct freenect_device_attributes {\n\tstruct freenect_device_attributes *next; /**< Next device in the linked list */\n\tconst char* camera_serial; /**< Serial number of this device's camera subdevice */\n};\n\n/// Enumeration of available resolutions.\n/// Not all available resolutions are actually supported for all video formats.\n/// Frame modes may not perfectly match resolutions.  For instance,\n/// FREENECT_RESOLUTION_MEDIUM is 640x488 for the IR camera.\ntypedef enum {\n\tFREENECT_RESOLUTION_LOW    = 0, /**< QVGA - 320x240 */\n\tFREENECT_RESOLUTION_MEDIUM = 1, /**< VGA  - 640x480 */\n\tFREENECT_RESOLUTION_HIGH   = 2, /**< SXGA - 1280x1024 */\n\tFREENECT_RESOLUTION_DUMMY  = 2147483647, /**< Dummy value to force enum to be 32 bits wide */\n} freenect_resolution;\n\n/// Enumeration of video frame information states.\n/// See http://openkinect.org/wiki/Protocol_Documentation#RGB_Camera for more information.\ntypedef enum {\n\tFREENECT_VIDEO_RGB             = 0, /**< Decompressed RGB mode (demosaicing done by libfreenect) */\n\tFREENECT_VIDEO_BAYER           = 1, /**< Bayer compressed mode (raw information from camera) */\n\tFREENECT_VIDEO_IR_8BIT         = 2, /**< 8-bit IR mode  */\n\tFREENECT_VIDEO_IR_10BIT        = 3, /**< 10-bit IR mode */\n\tFREENECT_VIDEO_IR_10BIT_PACKED = 4, /**< 10-bit packed IR mode */\n\tFREENECT_VIDEO_YUV_RGB         = 5, /**< YUV RGB mode */\n\tFREENECT_VIDEO_YUV_RAW         = 6, /**< YUV Raw mode */\n\tFREENECT_VIDEO_DUMMY           = 2147483647, /**< Dummy value to force enum to be 32 bits wide */\n} freenect_video_format;\n\n/// Enumeration of depth frame states\n/// See http://openkinect.org/wiki/Protocol_Documentation#RGB_Camera for more information.\ntypedef enum {\n\tFREENECT_DEPTH_11BIT        = 0, /**< 11 bit depth information in one uint16_t/pixel */\n\tFREENECT_DEPTH_10BIT        = 1, /**< 10 bit depth information in one uint16_t/pixel */\n\tFREENECT_DEPTH_11BIT_PACKED = 2, /**< 11 bit packed depth information */\n\tFREENECT_DEPTH_10BIT_PACKED = 3, /**< 10 bit packed depth information */\n\tFREENECT_DEPTH_REGISTERED   = 4, /**< processed depth data in mm, aligned to 640x480 RGB */\n\tFREENECT_DEPTH_MM           = 5, /**< depth to each pixel in mm, but left unaligned to RGB image */\n\tFREENECT_DEPTH_DUMMY        = 2147483647, /**< Dummy value to force enum to be 32 bits wide */\n} freenect_depth_format;\n\n/// Structure to give information about the width, height, bitrate,\n/// framerate, and buffer size of a frame in a particular mode, as\n/// well as the total number of bytes needed to hold a single frame.\ntypedef struct {\n\tuint32_t reserved;              /**< unique ID used internally.  The meaning of values may change without notice.  Don't touch or depend on the contents of this field.  We mean it. */\n\tfreenect_resolution resolution; /**< Resolution this freenect_frame_mode describes, should you want to find it again with freenect_find_*_frame_mode(). */\n\tunion {\n\t\tint32_t dummy;\n\t\tfreenect_video_format video_format;\n\t\tfreenect_depth_format depth_format;\n\t};                              /**< The video or depth format that this freenect_frame_mode describes.  The caller should know which of video_format or depth_format to use, since they called freenect_get_*_frame_mode() */\n\tint32_t bytes;                  /**< Total buffer size in bytes to hold a single frame of data.  Should be equivalent to width * height * (data_bits_per_pixel+padding_bits_per_pixel) / 8 */\n\tint16_t width;                  /**< Width of the frame, in pixels */\n\tint16_t height;                 /**< Height of the frame, in pixels */\n\tint8_t data_bits_per_pixel;     /**< Number of bits of information needed for each pixel */\n\tint8_t padding_bits_per_pixel;  /**< Number of bits of padding for alignment used for each pixel */\n\tint8_t framerate;               /**< Approximate expected frame rate, in Hz */\n\tint8_t is_valid;                /**< If 0, this freenect_frame_mode is invalid and does not describe a supported mode.  Otherwise, the frame_mode is valid. */\n} freenect_frame_mode;\n\n/// Enumeration of LED states\n/// See http://openkinect.org/wiki/Protocol_Documentation#Setting_LED for more information.\ntypedef enum {\n\tLED_OFF              = 0, /**< Turn LED off */\n\tLED_GREEN            = 1, /**< Turn LED to Green */\n\tLED_RED              = 2, /**< Turn LED to Red */\n\tLED_YELLOW           = 3, /**< Turn LED to Yellow */\n\tLED_BLINK_GREEN      = 4, /**< Make LED blink Green */\n\t// 5 is same as 4, LED blink Green\n\tLED_BLINK_RED_YELLOW = 6, /**< Make LED blink Red/Yellow */\n} freenect_led_options;\n\n\n/// Enumeration of tilt motor status\ntypedef enum {\n\tTILT_STATUS_STOPPED = 0x00, /**< Tilt motor is stopped */\n\tTILT_STATUS_LIMIT   = 0x01, /**< Tilt motor has reached movement limit */\n\tTILT_STATUS_MOVING  = 0x04, /**< Tilt motor is currently moving to new position */\n} freenect_tilt_status_code;\n\n/// Data from the tilt motor and accelerometer\ntypedef struct {\n\tint16_t                   accelerometer_x; /**< Raw accelerometer data for X-axis, see FREENECT_COUNTS_PER_G for conversion */\n\tint16_t                   accelerometer_y; /**< Raw accelerometer data for Y-axis, see FREENECT_COUNTS_PER_G for conversion */\n\tint16_t                   accelerometer_z; /**< Raw accelerometer data for Z-axis, see FREENECT_COUNTS_PER_G for conversion */\n\tint8_t                    tilt_angle;      /**< Raw tilt motor angle encoder information */\n\tfreenect_tilt_status_code tilt_status;     /**< State of the tilt motor (stopped, moving, etc...) */\n} freenect_raw_tilt_state;\n\nstruct _freenect_context;\ntypedef struct _freenect_context freenect_context; /**< Holds information about the usb context. */\n\nstruct _freenect_device;\ntypedef struct _freenect_device freenect_device; /**< Holds device information. */\n\n// usb backend specific section\ntypedef void freenect_usb_context; /**< Holds libusb-1.0 context */\n//\n\n/// If Win32, export all functions for DLL usage\n#ifndef _WIN32\n  #define FREENECTAPI /**< DLLExport information for windows, set to nothing on other platforms */\n#else\n  /**< DLLExport information for windows, set to nothing on other platforms */\n  #ifdef __cplusplus\n    #define FREENECTAPI extern \"C\" __declspec(dllexport)\n  #else\n    // this is required when building from a Win32 port of gcc without being\n    // forced to compile all of the library files (.c) with g++...\n    #define FREENECTAPI __declspec(dllexport)\n  #endif\n#endif\n\n/// Enumeration of message logging levels\ntypedef enum {\n\tFREENECT_LOG_FATAL = 0,     /**< Log for crashing/non-recoverable errors */\n\tFREENECT_LOG_ERROR,         /**< Log for major errors */\n\tFREENECT_LOG_WARNING,       /**< Log for warning messages */\n\tFREENECT_LOG_NOTICE,        /**< Log for important messages */\n\tFREENECT_LOG_INFO,          /**< Log for normal messages */\n\tFREENECT_LOG_DEBUG,         /**< Log for useful development messages */\n\tFREENECT_LOG_SPEW,          /**< Log for slightly less useful messages */\n\tFREENECT_LOG_FLOOD,         /**< Log EVERYTHING. May slow performance. */\n} freenect_loglevel;\n\n/**\n * Initialize a freenect context and do any setup required for\n * platform specific USB libraries.\n *\n * @param ctx Address of pointer to freenect context struct to allocate and initialize\n * @param usb_ctx USB context to initialize. Can be NULL if not using multiple contexts.\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx);\n\n/**\n * Closes the device if it is open, and frees the context\n *\n * @param ctx freenect context to close/free\n *\n * @return 0 on success\n */\nFREENECTAPI int freenect_shutdown(freenect_context *ctx);\n\n/// Typedef for logging callback functions\ntypedef void (*freenect_log_cb)(freenect_context *dev, freenect_loglevel level, const char *msg);\n\n/**\n * Set the log level for the specified freenect context\n *\n * @param ctx context to set log level for\n * @param level log level to use (see freenect_loglevel enum)\n */\nFREENECTAPI void freenect_set_log_level(freenect_context *ctx, freenect_loglevel level);\n\n/**\n * Callback for log messages (i.e. for rerouting to a file instead of\n * stdout)\n *\n * @param ctx context to set log callback for\n * @param cb callback function pointer\n */\nFREENECTAPI void freenect_set_log_callback(freenect_context *ctx, freenect_log_cb cb);\n\n/**\n * Calls the platform specific usb event processor\n *\n * @param ctx context to process events for\n *\n * @return 0 on success, other values on error, platform/library dependant\n */\nFREENECTAPI int freenect_process_events(freenect_context *ctx);\n\n/**\n * Calls the platform specific usb event processor until either an event occurs\n * or the timeout parameter time has passed.  If a zero timeval is passed, this\n * function will handle any already-pending events, then return immediately.\n *\n * @param ctx Context to process events for\n * @param timeout Pointer to a timeval containing the maximum amount of time to block waiting for events, or zero for nonblocking mode\n *\n * @return 0 on success, other values on error, platform/library dependant\n */\nFREENECTAPI int freenect_process_events_timeout(freenect_context *ctx, struct timeval* timeout);\n\n/**\n * Return the number of kinect devices currently connected to the\n * system\n *\n * @param ctx Context to access device count through\n *\n * @return Number of devices connected, < 0 on error\n */\nFREENECTAPI int freenect_num_devices(freenect_context *ctx);\n\n/**\n * Scans for kinect devices and produces a linked list of their attributes\n * (namely, serial numbers), returning the number of devices.\n *\n * @param ctx Context to scan for kinect devices with\n * @param attribute_list Pointer to where this function will store the resultant linked list\n *\n * @return Number of devices connected, < 0 on error\n */\nFREENECTAPI int freenect_list_device_attributes(freenect_context *ctx, struct freenect_device_attributes** attribute_list);\n\n/**\n * Free the linked list produced by freenect_list_device_attributes().\n *\n * @param attribute_list Linked list of attributes to free.\n */\nFREENECTAPI void freenect_free_device_attributes(struct freenect_device_attributes* attribute_list);\n\n/**\n * Answer which subdevices this library supports.  This is most useful for\n * wrappers trying to determine whether the underlying library was built with\n * audio support or not, so the wrapper can avoid calling functions that do not\n * exist.\n *\n * @return Flags representing the subdevices that the library supports opening (see freenect_device_flags)\n */\nFREENECTAPI int freenect_supported_subdevices(void);\n\n/**\n * Set which subdevices any subsequent calls to freenect_open_device()\n * should open.  This will not affect devices which have already been\n * opened.  The default behavior, should you choose not to call this\n * function at all, is to open all supported subdevices - motor, cameras,\n * and audio, if supported on the platform.\n *\n * @param ctx Context to set future subdevice selection for\n * @param subdevs Flags representing the subdevices to select\n */\nFREENECTAPI void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs);\n\n/**\n * Returns the devices that are enabled after calls to freenect_open_device()\n * On newer kinects the motor and audio are automatically disabled for now\n *\n * @param ctx Context to set future subdevice selection for\n * @return Flags representing the subdevices that were actually opened (see freenect_device_flags)\n */\nFREENECTAPI freenect_device_flags freenect_enabled_subdevices(freenect_context *ctx);\n\n/**\n * Opens a kinect device via a context. Index specifies the index of\n * the device on the current state of the bus. Bus resets may cause\n * indexes to shift.\n *\n * @param ctx Context to open device through\n * @param dev Device structure to assign opened device to\n * @param index Index of the device on the bus\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_open_device(freenect_context *ctx, freenect_device **dev, int index);\n\n/**\n * Opens a kinect device (via a context) associated with a particular camera\n * subdevice serial number.  This function will fail if no device with a\n * matching serial number is found.\n *\n * @param ctx Context to open device through\n * @param dev Device structure to assign opened device to\n * @param camera_serial Null-terminated ASCII string containing the serial number of the camera subdevice in the device to open\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_open_device_by_camera_serial(freenect_context *ctx, freenect_device **dev, const char* camera_serial);\n\n/**\n * Closes a device that is currently open\n *\n * @param dev Device to close\n *\n * @return 0 on success\n */\nFREENECTAPI int freenect_close_device(freenect_device *dev);\n\n/**\n * Set the device user data, for passing generic information into\n * callbacks\n *\n * @param dev Device to attach user data to\n * @param user User data to attach\n */\nFREENECTAPI void freenect_set_user(freenect_device *dev, void *user);\n\n/**\n * Retrieve the pointer to user data from the device struct\n *\n * @param dev Device from which to get user data\n *\n * @return Pointer to user data\n */\nFREENECTAPI void *freenect_get_user(freenect_device *dev);\n\n/// Typedef for depth image received event callbacks\ntypedef void (*freenect_depth_cb)(freenect_device *dev, void *depth, uint32_t timestamp);\n/// Typedef for video image received event callbacks\ntypedef void (*freenect_video_cb)(freenect_device *dev, void *video, uint32_t timestamp);\n\n/**\n * Set callback for depth information received event\n *\n * @param dev Device to set callback for\n * @param cb Function pointer for processing depth information\n */\nFREENECTAPI void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb);\n\n/**\n * Set callback for video information received event\n *\n * @param dev Device to set callback for\n * @param cb Function pointer for processing video information\n */\nFREENECTAPI void freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb);\n\n/**\n * Set the buffer to store depth information to. Size of buffer is\n * dependant on depth format. See FREENECT_DEPTH_*_SIZE defines for\n * more information.\n *\n * @param dev Device to set depth buffer for.\n * @param buf Buffer to store depth information to.\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_set_depth_buffer(freenect_device *dev, void *buf);\n\n/**\n * Set the buffer to store depth information to. Size of buffer is\n * dependant on video format. See FREENECT_VIDEO_*_SIZE defines for\n * more information.\n *\n * @param dev Device to set video buffer for.\n * @param buf Buffer to store video information to.\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_set_video_buffer(freenect_device *dev, void *buf);\n\n/**\n * Start the depth information stream for a device.\n *\n * @param dev Device to start depth information stream for.\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_start_depth(freenect_device *dev);\n\n/**\n * Start the video information stream for a device.\n *\n * @param dev Device to start video information stream for.\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_start_video(freenect_device *dev);\n\n/**\n * Stop the depth information stream for a device\n *\n * @param dev Device to stop depth information stream on.\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_stop_depth(freenect_device *dev);\n\n/**\n * Stop the video information stream for a device\n *\n * @param dev Device to stop video information stream on.\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_stop_video(freenect_device *dev);\n\n/**\n * Updates the accelerometer state using a blocking control message\n * call.\n *\n * @param dev Device to get accelerometer data from\n *\n * @return 0 on success, < 0 on error. Accelerometer data stored to\n * device struct.\n */\nFREENECTAPI int freenect_update_tilt_state(freenect_device *dev);\n\n/**\n * Retrieve the tilt state from a device\n *\n * @param dev Device to retrieve tilt state from\n *\n * @return The tilt state struct of the device\n */\nFREENECTAPI freenect_raw_tilt_state* freenect_get_tilt_state(freenect_device *dev);\n\n/**\n * Return the tilt state, in degrees with respect to the horizon\n *\n * @param state The tilt state struct from a device\n *\n * @return Current degree of tilt of the device\n */\nFREENECTAPI double freenect_get_tilt_degs(freenect_raw_tilt_state *state);\n\n/**\n * Set the tilt state of the device, in degrees with respect to the\n * horizon. Uses blocking control message call to update\n * device. Function return does not reflect state of device, device\n * may still be moving to new position after the function returns. Use\n * freenect_get_tilt_status() to find current movement state.\n *\n * @param dev Device to set tilt state\n * @param angle Angle the device should tilt to\n *\n * @return 0 on success, < 0 on error.\n */\nFREENECTAPI int freenect_set_tilt_degs(freenect_device *dev, double angle);\n\n/**\n * Return the movement state of the tilt motor (moving, stopped, etc...)\n *\n * @param state Raw state struct to get the tilt status code from\n *\n * @return Status code of the tilt device. See\n * freenect_tilt_status_code enum for more info.\n */\nFREENECTAPI freenect_tilt_status_code freenect_get_tilt_status(freenect_raw_tilt_state *state);\n\n/**\n * Set the state of the LED. Uses blocking control message call to\n * update device.\n *\n * @param dev Device to set the LED state\n * @param option LED state to set on device. See freenect_led_options enum.\n *\n * @return 0 on success, < 0 on error\n */\nFREENECTAPI int freenect_set_led(freenect_device *dev, freenect_led_options option);\n\n/**\n * Get the axis-based gravity adjusted accelerometer state, as laid\n * out via the accelerometer data sheet, which is available at\n *\n * http://www.kionix.com/Product%20Sheets/KXSD9%20Product%20Brief.pdf\n *\n * @param state State to extract accelerometer data from\n * @param x Stores X-axis accelerometer state\n * @param y Stores Y-axis accelerometer state\n * @param z Stores Z-axis accelerometer state\n */\nFREENECTAPI void freenect_get_mks_accel(freenect_raw_tilt_state *state, double* x, double* y, double* z);\n\n/**\n * Get the number of video camera modes supported by the driver.  This includes both RGB and IR modes.\n *\n * @return Number of video modes supported by the driver\n */\nFREENECTAPI int freenect_get_video_mode_count();\n\n/**\n * Get the frame descriptor of the nth supported video mode for the\n * video camera.\n *\n * @param mode_num Which of the supported modes to return information about\n *\n * @return A freenect_frame_mode describing the nth video mode\n */\nFREENECTAPI freenect_frame_mode freenect_get_video_mode(int mode_num);\n\n/**\n * Get the frame descriptor of the current video mode for the specified\n * freenect device.\n *\n * @param dev Which device to return the currently-set video mode for\n *\n * @return A freenect_frame_mode describing the current video mode of the specified device\n */\nFREENECTAPI freenect_frame_mode freenect_get_current_video_mode(freenect_device *dev);\n\n/**\n * Convenience function to return a mode descriptor matching the\n * specified resolution and video camera pixel format, if one exists.\n *\n * @param res Resolution desired\n * @param fmt Pixel format desired\n *\n * @return A freenect_frame_mode that matches the arguments specified, if such a valid mode exists; otherwise, an invalid freenect_frame_mode.\n */\nFREENECTAPI freenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt);\n\n/**\n * Sets the current video mode for the specified device.  If the\n * freenect_frame_mode specified is not one provided by the driver\n * e.g. from freenect_get_video_mode() or freenect_find_video_mode()\n * then behavior is undefined.  The current video mode cannot be\n * changed while streaming is active.\n *\n * @param dev Device for which to set the video mode\n * @param mode Frame mode to set\n *\n * @return 0 on success, < 0 if error\n */\nFREENECTAPI int freenect_set_video_mode(freenect_device* dev, freenect_frame_mode mode);\n\n/**\n * Get the number of depth camera modes supported by the driver.  This includes both RGB and IR modes.\n *\n * @return Number of depth modes supported by the driver\n */\nFREENECTAPI int freenect_get_depth_mode_count();\n\n/**\n * Get the frame descriptor of the nth supported depth mode for the\n * depth camera.\n *\n * @param mode_num Which of the supported modes to return information about\n *\n * @return A freenect_frame_mode describing the nth depth mode\n */\nFREENECTAPI freenect_frame_mode freenect_get_depth_mode(int mode_num);\n\n/**\n * Get the frame descriptor of the current depth mode for the specified\n * freenect device.\n *\n * @param dev Which device to return the currently-set depth mode for\n *\n * @return A freenect_frame_mode describing the current depth mode of the specified device\n */\nFREENECTAPI freenect_frame_mode freenect_get_current_depth_mode(freenect_device *dev);\n\n/**\n * Convenience function to return a mode descriptor matching the\n * specified resolution and depth camera pixel format, if one exists.\n *\n * @param res Resolution desired\n * @param fmt Pixel format desired\n *\n * @return A freenect_frame_mode that matches the arguments specified, if such a valid mode exists; otherwise, an invalid freenect_frame_mode.\n */\nFREENECTAPI freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt);\n\n/**\n * Sets the current depth mode for the specified device.  The mode\n * cannot be changed while streaming is active.\n *\n * @param dev Device for which to set the depth mode\n * @param mode Frame mode to set\n *\n * @return 0 on success, < 0 if error\n */\nFREENECTAPI int freenect_set_depth_mode(freenect_device* dev, const freenect_frame_mode mode);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif //\n\n"
  },
  {
    "path": "libs/libfreenect/platform/linux/udev/51-kinect.rules",
    "content": "# ATTR{product}==\"Xbox NUI Motor\"\nSUBSYSTEM==\"usb\", ATTR{idVendor}==\"045e\", ATTR{idProduct}==\"02b0\", MODE=\"0666\"\n\n# ATTR{product}==\"Xbox NUI Audio\"\nSUBSYSTEM==\"usb\", ATTR{idVendor}==\"045e\", ATTR{idProduct}==\"02ad\", MODE=\"0666\"\n\n# ATTR{product}==\"Xbox NUI Camera\"\nSUBSYSTEM==\"usb\", ATTR{idVendor}==\"045e\", ATTR{idProduct}==\"02ae\", MODE=\"0666\"\n\n"
  },
  {
    "path": "libs/libfreenect/platform/linux/udev/README",
    "content": "Simply place this file in /etc/udev/rules.d and you'll no longer need\nto run your apps as root.\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/README.TXT",
    "content": "======================================================================================\n\nSUMMARY\n*******\n\n1) libfreenect: incompatibilities with Visual C++\n   This section is here merely for historical reasons. All of the issues documented\n   here were already fixed in the libfreenect repository and CMake should be able to\n   produce a project that is ready to build libfreenect in Windows with Visual Studio.\n   Consider browsing this section if experiencing compilation issues under different\n   platforms, compilers and/or IDEs.\n\n2) libusb-1.0 vs. libusbemu: Issues and Concept\n   The current port of libfreenect for Windows uses a libusb-1.0 emulation layer since\n   a proper port of libusb-1.0 for Windows is not yet available. Such emulation layer\n   allows Windows development to keep in sync with the official development branch of\n   libfreenect, without the need of dedicated drivers/implementations. This section\n   discusses why and how the current libfreenect Windows port moved in this direction.\n\n3) libusbemu: Tips, Hints and Best Practices\n   The current status of libusbemu is quite reliable under normal usage circumstances,\n   but by no means stable: caution is advised. This section provides some guidelines\n   to avoid potential pitfalls and keep the application running safely under Windows.\n   They are simple and natural to follow, so they should not impose any special design\n   considerations for the application.\n\n4) Overall performance of libfreenect in Windows\n   The current Windows port of libfreenect has some performance overhead over other\n   platforms and dedicated Win32 driver implementations due to the libusbemu module.\n   This section contains a benchmark scenario and a also a discussion on the results.\n   In short, the overhead is negligible and should not prevent anyone from using it.\n\n======================================================================================\n\n1) libfreenect source code: incompatibilities with Visual C++\n   **********************************************************\n\n----------------------------------------------------------------------------------\nLanguage issues: The Microsoft C compiler does not implement all the C99 standard.\n----------------------------------------------------------------------------------\n\nAn attempt to compile the current libfreenect with Visual C++ will trigger a lot\nof errors. A simple workaround is to tell Visual Studio to force compilation all the\n\".c\" files within the project using the C++ compiler:\n  Project >> Properties >> C/C++ >> Advanced >> Compile As: Compile as C++ Code (/TP)\n\nThis will get rid of most errors, except those regarding implicit pointer casts.\nHere are a few examples of such implicit pointer casts from within libfreenect:\n  tilt.c      dev->raw_state.tilt_status = buf[9];\n  core.c      *ctx = malloc(sizeof(freenect_context));\n  cameras.c   strm->raw_buf = strm->proc_buf;\nIt seems that it is not possible to force Visual C++ to perform such implicit casts\n(if anyone knows how, please share! :-)\n\nSuch implicit casts then have to be made explicit:\n              dev->raw_state.tilt_status = (freenect_tilt_status_code)buf[9];\n              *ctx = (freenect_context*)malloc(sizeof(freenect_context));\n              strm->raw_buf = (uint8_t*)strm->proc_buf;\nFortunately, they are not many, and it can be done in a couple of minutes.\nThis should impose a minimal burden to the Win32 repository maintainers.\n\nNOTE: Sometimes, even when \"Compile as C++ Code\" is specified, the build will insist\non using the C-compiler to compile .c files (this happens with MSVC versions prior to\n2010). To work around this, just set the \"Compile As\" to \"Default\", click \"Apply\" and\nthen set it back to \"Compile as C++ Code (/TP)\", click \"Apply\" and then \"OK\".\n\nAnother problem is that Visual C++ does not offer the <unistd.h> and <stdbool.h>\nheaders. However, they are pretty simple to be emulated; the <stdbool.h> will\nactually be a dummy header because C++ already defines the \"bool\" type semantics,\nwhile the <unistd.h> has to simply #include <stdint.h> and define the \"ssize_t\"\ntype. The implementation of these headers are located at:\n  \"libfreenect\\platform\\windows\"\n\nNOTE: MSVC versions prior to 2010 do not provide the <stdint.h> header. An ISO C9x\ncompilant <stdint.h> header for such MSVC versions can be found at the wikipedia entry\nof stdint.h (at the \"External links\" section of the page):\n  http://en.wikipedia.org/wiki/Stdint.h\nor directly through this link:\n  http://msinttypes.googlecode.com/svn/trunk/stdint.h\nA copy of such header will be also provided within libfreenect in the future.\n\nThe \"freenect_internal.h\" makes use of GCC's \"__attribute__\" keyword, and there is no\nsuch a thing in Visual C++. Fortunately, this header is not exposed for the library\nuser and is just required during the library build. There are a few simple solutions\nfor this issue: a) remove this keyword or b) define a dummy macro for it.\n\nAnother issue is that since all .c files were forced to be compiled as C++ code,\nthe \"libfreenect.h\" header no longer requires the \"#ifdef __cpluscplus extern C\"\nidiom. Commenting out this guard will do the trick, but better checking is possible.\n\n-----------------------------------------------------------------------------------\nLibrary issues: libfreenect uses libusb-1.0 which is not yet available for Windows.\n-----------------------------------------------------------------------------------\n\nThe final issue is regarding the default USB back-end used by libfreenect, libusb-1.0,\nwhich is not yet available for Windows. This restriction forces the Windows port of\nlibfreenect to implement its own back-end, which then splits the Windows port from the\nmain development branch of libfreenect as new device features are reverse-engineered\nand added to the library. Fortunately, such restriction can be alleviated through the\nlibusb-1.0 API \"emulator\" and keep the Windows port in sync with the current status of\nlibfreenect. More on this subject in the following section.\n\n======================================================================================\n\n2) libusb-1.0 vs. libusbemu: Issues and Concept\n   ********************************************\n\nThe libfreenect uses libusb-1.0 as its default USB back-end to communicate with Kinect\nbut libusb-1.0 is not yet available for Windows. The current libusb-1.0 implementation\nfor Windows is experimental and uses WinUSB as its USB back-end. Unfortunately, WinUSB\ndoes not support isochronous transfers, rendering it useless for Kinect purposes.\n\nHowever, all is not lost since the latest version of libusb-win32 has support for the\nisochronous transfers imposed by Kinect. There are issues too: libusb-win32 is based\non the old libusb-0.1 API which is incompatible with the libusb-1.0 API. Some of the\ninitial efforts to port libfreenect to Windows were based on the libusb-win32, being\nZephod's Win32 Kinect driver prototype a well-known instance:\n   http://ajaxorg.posterous.com/kinect-driver-for-windows-prototype\n\nThe problem with a dedicated libusb-win32 driver implementation is that it has to be\nmaintained separately from the current libfreenect development. As new Kinect features\nare reverse-engineered and implemented in the official libfreenect branch, the Windows\nport requires additional maintenance to keep it in sync with the newest updates, even\nwhen such updates don't involve USB communication at all.\n\nOne could argue that libfreenect should abandon the use of libusb-1.0 and just adopt\nthe old libusb-0.1 instead, since it is has support in a wider range of platforms...\nThis is out of question! First of all, libusb-0.1 still exists for legacy reasons, and\nit is highly recommended to move to the new API if possible. Moreover, libusb-0.1 does\nnot have built-in support for asynchronous transfers, which would force libfreenect to\nhold and manage threads internally, which would then lead to a whole set of new issues\nthat are prone to hurt performance, maintainability and portability.\n\nFortunately, libfreenect only requires a small portion of the libusb-1.0 API, and such\nsubset can be emulated, at some extent, through what is provided from libusb-win32. As\na result, the burden of maintaining dedicated development branches for a Windows port\nis eliminated and the port can keep in synch with updates made in the libfreenect. One\nmay now ask: how can libusb-win32 be of any help if it is based on the libusb-0.1 API,\nwhich has no support for asynchronous transfers? Well, that's because it happens that\nlibusb-win32 is more than just a Win32 build of libusb-0.1: it is a special branch of\nthe 0.1 API that extends it to allow asynchronous transfers.\n\nThe normal execution flow of libfreenect is something like this:\n  Application <-> libfreenect <-> libusb-1.0 <-> Kinect\nIn Windows, the flow is as follows:\n  Application <-> libfreenect <-> libusb-1.0-emu <-> libusb-win32 <-> Kinect\n\nThe source code of the emulation layer is available at:\n  libfreenect\\platform\\windows\\libusb10emu\\libusb-1.0\nKeep in mind that libusb-win32 is still required, and can be downloaded from:\n  http://sourceforge.net/apps/trac/libusb-win32/wiki\nThe latest snapshots are recommended, obtained directly from this URL:\n  http://sourceforge.net/projects/libusb-win32/files/libusb-win32-snapshots\n\nEmulation of libusb-1.0 on top of libusb-win32 is not trivial, in special because of\nsome Windows-specific issues. There will be performance overhead, but as discussed in\nthe \"Overall Performance\" section, this should not hurt the application performance at\nsignificant levels. Moreover, although the libusbemu is currently quite reliable, it\nis by no means stable and on par to the real libusb-1.0 semantics. Caution is advised,\nso be sure to read the following section for some usage considerations.\n\nThe libusbemu sits completely hidden behind libfreenect: the application does not need\nto worry or call any special functions. In fact the application is not even aware that\nlibusbemu exists.\n\n======================================================================================\n\n3) libusbemu: Tips, Hints and Best Practices\n   *****************************************\n\n---------------------------------------------------------------\nTIP: Trigger the Fail Guard if the system becomes unresponsive.\n---------------------------------------------------------------\n\nSince libusbemu is quite experimental, there is a fail guard within it. If for some\nreason your system renders unresponsive, try focusing any window of the application\nand hold [CTRL] + [ALT] for a while.\n\nThis will trigger a special synchronization event within the libusbemu which will\ninterrupt the execution of any internal thread of libusbemu and prompt a message box\nto the user asking for action. You can either resume execution (if you unintentionally\npressed [CTRL] + [ALT] in the console window) or abort libusbemu. The fail guard will\nnever trigger if there is no incoming video or depth streams.\n\nThe Fail Guard is important since in such situations one would most likely be forced\nto shutdown the computer (in a not so graceful way, by holding the power button!).\n\n----------------------------------------\nTIP: Only use a single freenect context.\n----------------------------------------\n\nMultiple freenect contexts should be no problem in the future. Having more than one\ndevice attached to the same context should work fine, but no tests were made so far.\n\n-----------------------------------------------------\nTIP: Yield the rendering thread after each iteration.\n-----------------------------------------------------\n\nIn case your application performs direct rendering (OpenGL, Direct3D), it is highly\nrecommended to yield the rendering thread after finishing rendering each frame. This\ncan alleviate a lot of CPU usage. The ideal place for this yield is right after the\nswap-buffers call (SwapBuffers(), glutSwapBuffers(), Present(), etc). The best way to\nyield is by calling Sleep(1). Note that Sleep(0) is also possible, but the former is\nmore \"democratic\".\n\nNote that some graphics drivers or platforms may already yield after swap-buffers.\nThis seems to be the case with OpenGL NVIDIA drivers for Linux. In Windows, however,\nthe same driver (version) does not yield. Maybe in Linux the \"yielder\" is not the\ndriver itself, but the underlying implementation of glXSwapBuffers()... Anyway, when\nin doubt, it will not hurt to explicitly yield again.\n\n--------------------------------------------------------------------------------------\nTIP: Perform stream operations only in the thread that calls freenect_process_events()\n--------------------------------------------------------------------------------------\n\nBy stream operations I mean these:\n  freenect_start_video()\n  freenect_start_depth()\n  freenect_stop_video()\n  freenect_stop_depth()\n\nThis tip seems to hold for other platforms as well, and it is respected through all of\nthe official libfreenect examples and should be of no burden for the application. This\nmay be due to the underlying semantics of the real libusb-1.0. Unfortunately, although\nlibusb-1.0 has an excellent API documentation it lacks on a proper specification, thus\ndifficulting the task of checking if this is indeed a restriction.\n\nIn summary, a typical libfreenect application (check the official examples) will have\na dedicated thread that calls freenect_process_events(). This function is responsible\nfor querying and dispatching incoming streams (a.k.a. video and depth frames) from the\nKinect device to the application (behind the scenes is a call the libusb-1.0 function\nlibusb_handle_events()) and it is advised that any stream operation intended by the\napplication (like switching to some different video format) should happen within the\nthread that calls the freenect_process_events(). The official libfreenect examples do\nthis, so be sure to check their source code if confused. It is also advised to have\nonly one thread calling freenect_handle_events().\n\nInterestingly, some tests were made with both the libusb-1.0 and libusbemu and mixing\nstream operations in different threads seem to work well. However, no guarantees are\ngiven if executed in such a fashion. Again, libusb-1.0 has no specification document\nand if such behavior is really to be expected is a hard task to determine.\n\n======================================================================================\n\n4) Overall performance of libfreenect in Windows\n   *********************************************\n\n---------------------------------------------\nTHIS SECTION IS OUTDATED, GOTTA REDO IT SOON!\n---------------------------------------------\n\nHardware:\n* Notebook \n* CPU: Intel Core2 Duo 32bit [T7250] @ 2.0GHz\n* RAM: 4GB RAM\n* GPU: GeForce 8600M GT 256MB VRAM\n\n\n\nTask: display of simultaneous RGB (Bayer-to-RGB) and depth streams (16bit unpadded) on\nthe screen through OpenGL textures. Application source code is identical for all tests\n(except for the Zephod's version that required some interface adaptation).\n\n\n\nResults: performance measurements refer to the average frame time (one loop iteration).\n\nLinux: Ubuntu Notebook 10.10 -- gcc 4.4.5\n* Debug:   1.22ms | CPU @ 77% | video @ 30Hz | depth @ 30Hz\n* Release: 1.15ms | CPU @ 72% | video @ 30Hz | depth @ 30Hz\n\nWin32: Windows 7 Enterprise 32bit -- VC++ (Professional) 2010\n1) libfreenect with libusbemu:\n   * Debug:   2.44ms | CPU @ 75% | video @ 30Hz | depth @ 30Hz\n   * Release: 1.93ms | CPU @ 63% | video @ 30Hz | depth @ 30Hz\n2) Zephod's dedicated driver (V16):\n   * Debug:   2.87ms | CPU @ 82% | video @ 30Hz | depth @ 30Hz\n   * Release: 2.55ms | CPU @ 77% | video @ 30Hz | depth @ 30Hz\n\n\n\nRemarks:\n\nDebug builds account for the library itself being built in Debug mode (libfreenect or\nZaphod's driver, whichever applies). Release builds also imply that the program was\nstarted without any debug information embedded.\n\nIn Windows, time was measured through the Win32 exclusive QueryPerformanceFrequency()\nand QueryPerformanceCounter() routines. In Linux, the measurement was performed via\nPOSIX gettime() function.\n\nA Win32 MinGW-based (gcc/g++ 4.5.0) build of libfreenect with libusbemu using POSIX\ngettime() also yielded to nearly identical performance results than VC++ 2010 with\nPerformance Counters.\n\nAll of the Win32 performance results were also double-checked with Fraps.\n\nIn Windows, a single thread yield call was placed after rendering each screen frame\n(as recommended in Item 3-3). In Linux, the graphics driver - possibly glXSwapBuffers\nitself - seems to be already yielding the rendering thread, and forcing it in the code\ndid not incur into any extra impact on performance.\n\n\n\nDiscussion:\n\nEven though there are no streaming frequency discrepancies between platforms, one may\ninfer, just from the frame times, that Windows clearly has an overhead disadvantage.\nHowever, this does not hold true: there is still plenty of time for the application\nlogic to run.\n\nFor a steady 60FPS (~16.66ms per frame) real-time performance, a Release build using\nlibusbemu in Windows would still have about 14.70ms per frame available for the client\ncode, while in Linux the available time would be around 15.50ms, a 0.8ms overhead\nbetween the platforms. Such a small difference should not impose any special design\nconsiderations for the client code.\n\nFurthermore, note that the CPU usage in Windows tend to be lower than in Linux. The\nreason behind this difference is quite difficult to summarize here, but it is probably\nrelated to the way Windows and Linux perform asynchronous I/O in USB-mapped files.\nThe interested reader is encouraged to refer to the following links:\n  > http://www.unwesen.de/articles/waitformultipleobjects_considered_expensive\n  > http://softwarecommunity.intel.com/articles/eng/2807.htm\n  > http://software.intel.com/en-us/blogs/2006/10/19/why-windows-threads-are-better-than-posix-threads/\nThe memory consumption overhead of libusbemu in Windows is negligible, and as far as\nthe VC++ memory leak detection goes, libusbemu has no memory leaks.\n\n======================================================================================\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/inf/xbox nui audio/libusb-win32-bin-README.txt",
    "content": "libusb-win32-bin v1.2.2.0 (10/02/2010) - [Package Information]\n\nALL ARCHITECTURES:\n  x86\\libusb0_x86.dll: x86 32-bit library. Must be renamed to libusb0.dll\n    On 64 bit, Installs to Windows\\syswow64\\libusb0.dll.\n    On 32 bit, Installs to Windows\\system32\\libusb0.dll.\n\n  x86\\inf-wizard.exe: inf-wizard application with embedded libusb-win32\n    v1.2.2.0 binaries.\n\nX86 ONLY ARCHITECTURES:\n  x86\\libusb0.sys: x86 32-bit driver.\n    Installs to Windows\\system32\\drivers\\libusb0.sys\n\nAMD64-INTEL64 ONLY ARCHITECTURES:\n  amd64\\libusb0.sys: x64 64-bit driver.\n    Installs to Windows\\system32\\drivers\\libusb0.sys\n\n  amd64\\libusb0.dll: x64 64-bit library.\n    Installs to Windows\\system32\\libusb0.dll\n\nIA64 ONLY ARCHITECTURES:\n  ia64\\libusb0.sys: IA64 64-bit driver.\n    Installs to Windows\\system32\\drivers\\libusb0.sys\n\n  ia64\\libusb0.dll: IA64 64-bit library.\n    Installs to Windows\\system32\\libusb0.dll\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/inf/xbox nui audio/license/libusb-win32/installer_license.txt",
    "content": "Copyright (c) 2002-2004 Stephan Meyer, <ste_meyer@web.de>\nCopyright (c) 2000-2004 Johannes Erdfelt, <johannes@erdfelt.com>\nCopyright (c) 2000-2004 Thomas Sailer, <sailer@ife.ee.ethz.ch>\nCopyright (c) 2010 Travis Robinson, <libusbdotnet@gmail.com>\n\nThis software is distributed under the following licenses:\nDriver:      GNU General Public License (GPL)\nLibrary, Test Files, Installer:    GNU Lesser General Public License (LGPL)\n\n***********************************************************************\n                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n\n                   GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\n  This version of the GNU Lesser General Public License incorporates\nthe terms and conditions of version 3 of the GNU General Public\nLicense, supplemented by the additional permissions listed below.\n\n  0. Additional Definitions.\n\n  As used herein, \"this License\" refers to version 3 of the GNU Lesser\nGeneral Public License, and the \"GNU GPL\" refers to version 3 of the GNU\nGeneral Public License.\n\n  \"The Library\" refers to a covered work governed by this License,\nother than an Application or a Combined Work as defined below.\n\n  An \"Application\" is any work that makes use of an interface provided\nby the Library, but which is not otherwise based on the Library.\nDefining a subclass of a class defined by the Library is deemed a mode\nof using an interface provided by the Library.\n\n  A \"Combined Work\" is a work produced by combining or linking an\nApplication with the Library.  The particular version of the Library\nwith which the Combined Work was made is also called the \"Linked\nVersion\".\n\n  The \"Minimal Corresponding Source\" for a Combined Work means the\nCorresponding Source for the Combined Work, excluding any source code\nfor portions of the Combined Work that, considered in isolation, are\nbased on the Application, and not on the Linked Version.\n\n  The \"Corresponding Application Code\" for a Combined Work means the\nobject code and/or source code for the Application, including any data\nand utility programs needed for reproducing the Combined Work from the\nApplication, but excluding the System Libraries of the Combined Work.\n\n  1. Exception to Section 3 of the GNU GPL.\n\n  You may convey a covered work under sections 3 and 4 of this License\nwithout being bound by section 3 of the GNU GPL.\n\n  2. Conveying Modified Versions.\n\n  If you modify a copy of the Library, and, in your modifications, a\nfacility refers to a function or data to be supplied by an Application\nthat uses the facility (other than as an argument passed when the\nfacility is invoked), then you may convey a copy of the modified\nversion:\n\n   a) under this License, provided that you make a good faith effort to\n   ensure that, in the event an Application does not supply the\n   function or data, the facility still operates, and performs\n   whatever part of its purpose remains meaningful, or\n\n   b) under the GNU GPL, with none of the additional permissions of\n   this License applicable to that copy.\n\n  3. Object Code Incorporating Material from Library Header Files.\n\n  The object code form of an Application may incorporate material from\na header file that is part of the Library.  You may convey such object\ncode under terms of your choice, provided that, if the incorporated\nmaterial is not limited to numerical parameters, data structure\nlayouts and accessors, or small macros, inline functions and templates\n(ten or fewer lines in length), you do both of the following:\n\n   a) Give prominent notice with each copy of the object code that the\n   Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the object code with a copy of the GNU GPL and this license\n   document.\n\n  4. Combined Works.\n\n  You may convey a Combined Work under terms of your choice that,\ntaken together, effectively do not restrict modification of the\nportions of the Library contained in the Combined Work and reverse\nengineering for debugging such modifications, if you also do each of\nthe following:\n\n   a) Give prominent notice with each copy of the Combined Work that\n   the Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the Combined Work with a copy of the GNU GPL and this license\n   document.\n\n   c) For a Combined Work that displays copyright notices during\n   execution, include the copyright notice for the Library among\n   these notices, as well as a reference directing the user to the\n   copies of the GNU GPL and this license document.\n\n   d) Do one of the following:\n\n       0) Convey the Minimal Corresponding Source under the terms of this\n       License, and the Corresponding Application Code in a form\n       suitable for, and under terms that permit, the user to\n       recombine or relink the Application with a modified version of\n       the Linked Version to produce a modified Combined Work, in the\n       manner specified by section 6 of the GNU GPL for conveying\n       Corresponding Source.\n\n       1) Use a suitable shared library mechanism for linking with the\n       Library.  A suitable mechanism is one that (a) uses at run time\n       a copy of the Library already present on the user's computer\n       system, and (b) will operate properly with a modified version\n       of the Library that is interface-compatible with the Linked\n       Version.\n\n   e) Provide Installation Information, but only if you would otherwise\n   be required to provide such information under section 6 of the\n   GNU GPL, and only to the extent that such information is\n   necessary to install and execute a modified version of the\n   Combined Work produced by recombining or relinking the\n   Application with a modified version of the Linked Version. (If\n   you use option 4d0, the Installation Information must accompany\n   the Minimal Corresponding Source and Corresponding Application\n   Code. If you use option 4d1, you must provide the Installation\n   Information in the manner specified by section 6 of the GNU GPL\n   for conveying Corresponding Source.)\n\n  5. Combined Libraries.\n\n  You may place library facilities that are a work based on the\nLibrary side by side in a single library together with other library\nfacilities that are not Applications and are not covered by this\nLicense, and convey such a combined library under terms of your\nchoice, if you do both of the following:\n\n   a) Accompany the combined library with a copy of the same work based\n   on the Library, uncombined with any other library facilities,\n   conveyed under the terms of this License.\n\n   b) Give prominent notice with the combined library that part of it\n   is a work based on the Library, and explaining where to find the\n   accompanying uncombined form of the same work.\n\n  6. Revised Versions of the GNU Lesser General Public License.\n\n  The Free Software Foundation may publish revised and/or new versions\nof the GNU Lesser General Public License from time to time. Such new\nversions will be similar in spirit to the present version, but may\ndiffer in detail to address new problems or concerns.\n\n  Each version is given a distinguishing version number. If the\nLibrary as you received it specifies that a certain numbered version\nof the GNU Lesser General Public License \"or any later version\"\napplies to it, you have the option of following the terms and\nconditions either of that published version or of any later version\npublished by the Free Software Foundation. If the Library as you\nreceived it does not specify a version number of the GNU Lesser\nGeneral Public License, you may choose any version of the GNU Lesser\nGeneral Public License ever published by the Free Software Foundation.\n\n  If the Library as you received it specifies that a proxy can decide\nwhether future versions of the GNU Lesser General Public License shall\napply, that proxy's public statement of acceptance of any version is\npermanent authorization for you to choose that version for the\nLibrary.\n\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/inf/xbox nui camera/libusb-win32-bin-README.txt",
    "content": "libusb-win32-bin v1.2.2.0 (10/02/2010) - [Package Information]\n\nALL ARCHITECTURES:\n  x86\\libusb0_x86.dll: x86 32-bit library. Must be renamed to libusb0.dll\n    On 64 bit, Installs to Windows\\syswow64\\libusb0.dll.\n    On 32 bit, Installs to Windows\\system32\\libusb0.dll.\n\n  x86\\inf-wizard.exe: inf-wizard application with embedded libusb-win32\n    v1.2.2.0 binaries.\n\nX86 ONLY ARCHITECTURES:\n  x86\\libusb0.sys: x86 32-bit driver.\n    Installs to Windows\\system32\\drivers\\libusb0.sys\n\nAMD64-INTEL64 ONLY ARCHITECTURES:\n  amd64\\libusb0.sys: x64 64-bit driver.\n    Installs to Windows\\system32\\drivers\\libusb0.sys\n\n  amd64\\libusb0.dll: x64 64-bit library.\n    Installs to Windows\\system32\\libusb0.dll\n\nIA64 ONLY ARCHITECTURES:\n  ia64\\libusb0.sys: IA64 64-bit driver.\n    Installs to Windows\\system32\\drivers\\libusb0.sys\n\n  ia64\\libusb0.dll: IA64 64-bit library.\n    Installs to Windows\\system32\\libusb0.dll\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/inf/xbox nui camera/license/libusb-win32/installer_license.txt",
    "content": "Copyright (c) 2002-2004 Stephan Meyer, <ste_meyer@web.de>\nCopyright (c) 2000-2004 Johannes Erdfelt, <johannes@erdfelt.com>\nCopyright (c) 2000-2004 Thomas Sailer, <sailer@ife.ee.ethz.ch>\nCopyright (c) 2010 Travis Robinson, <libusbdotnet@gmail.com>\n\nThis software is distributed under the following licenses:\nDriver:      GNU General Public License (GPL)\nLibrary, Test Files, Installer:    GNU Lesser General Public License (LGPL)\n\n***********************************************************************\n                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n\n                   GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\n  This version of the GNU Lesser General Public License incorporates\nthe terms and conditions of version 3 of the GNU General Public\nLicense, supplemented by the additional permissions listed below.\n\n  0. Additional Definitions.\n\n  As used herein, \"this License\" refers to version 3 of the GNU Lesser\nGeneral Public License, and the \"GNU GPL\" refers to version 3 of the GNU\nGeneral Public License.\n\n  \"The Library\" refers to a covered work governed by this License,\nother than an Application or a Combined Work as defined below.\n\n  An \"Application\" is any work that makes use of an interface provided\nby the Library, but which is not otherwise based on the Library.\nDefining a subclass of a class defined by the Library is deemed a mode\nof using an interface provided by the Library.\n\n  A \"Combined Work\" is a work produced by combining or linking an\nApplication with the Library.  The particular version of the Library\nwith which the Combined Work was made is also called the \"Linked\nVersion\".\n\n  The \"Minimal Corresponding Source\" for a Combined Work means the\nCorresponding Source for the Combined Work, excluding any source code\nfor portions of the Combined Work that, considered in isolation, are\nbased on the Application, and not on the Linked Version.\n\n  The \"Corresponding Application Code\" for a Combined Work means the\nobject code and/or source code for the Application, including any data\nand utility programs needed for reproducing the Combined Work from the\nApplication, but excluding the System Libraries of the Combined Work.\n\n  1. Exception to Section 3 of the GNU GPL.\n\n  You may convey a covered work under sections 3 and 4 of this License\nwithout being bound by section 3 of the GNU GPL.\n\n  2. Conveying Modified Versions.\n\n  If you modify a copy of the Library, and, in your modifications, a\nfacility refers to a function or data to be supplied by an Application\nthat uses the facility (other than as an argument passed when the\nfacility is invoked), then you may convey a copy of the modified\nversion:\n\n   a) under this License, provided that you make a good faith effort to\n   ensure that, in the event an Application does not supply the\n   function or data, the facility still operates, and performs\n   whatever part of its purpose remains meaningful, or\n\n   b) under the GNU GPL, with none of the additional permissions of\n   this License applicable to that copy.\n\n  3. Object Code Incorporating Material from Library Header Files.\n\n  The object code form of an Application may incorporate material from\na header file that is part of the Library.  You may convey such object\ncode under terms of your choice, provided that, if the incorporated\nmaterial is not limited to numerical parameters, data structure\nlayouts and accessors, or small macros, inline functions and templates\n(ten or fewer lines in length), you do both of the following:\n\n   a) Give prominent notice with each copy of the object code that the\n   Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the object code with a copy of the GNU GPL and this license\n   document.\n\n  4. Combined Works.\n\n  You may convey a Combined Work under terms of your choice that,\ntaken together, effectively do not restrict modification of the\nportions of the Library contained in the Combined Work and reverse\nengineering for debugging such modifications, if you also do each of\nthe following:\n\n   a) Give prominent notice with each copy of the Combined Work that\n   the Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the Combined Work with a copy of the GNU GPL and this license\n   document.\n\n   c) For a Combined Work that displays copyright notices during\n   execution, include the copyright notice for the Library among\n   these notices, as well as a reference directing the user to the\n   copies of the GNU GPL and this license document.\n\n   d) Do one of the following:\n\n       0) Convey the Minimal Corresponding Source under the terms of this\n       License, and the Corresponding Application Code in a form\n       suitable for, and under terms that permit, the user to\n       recombine or relink the Application with a modified version of\n       the Linked Version to produce a modified Combined Work, in the\n       manner specified by section 6 of the GNU GPL for conveying\n       Corresponding Source.\n\n       1) Use a suitable shared library mechanism for linking with the\n       Library.  A suitable mechanism is one that (a) uses at run time\n       a copy of the Library already present on the user's computer\n       system, and (b) will operate properly with a modified version\n       of the Library that is interface-compatible with the Linked\n       Version.\n\n   e) Provide Installation Information, but only if you would otherwise\n   be required to provide such information under section 6 of the\n   GNU GPL, and only to the extent that such information is\n   necessary to install and execute a modified version of the\n   Combined Work produced by recombining or relinking the\n   Application with a modified version of the Linked Version. (If\n   you use option 4d0, the Installation Information must accompany\n   the Minimal Corresponding Source and Corresponding Application\n   Code. If you use option 4d1, you must provide the Installation\n   Information in the manner specified by section 6 of the GNU GPL\n   for conveying Corresponding Source.)\n\n  5. Combined Libraries.\n\n  You may place library facilities that are a work based on the\nLibrary side by side in a single library together with other library\nfacilities that are not Applications and are not covered by this\nLicense, and convey such a combined library under terms of your\nchoice, if you do both of the following:\n\n   a) Accompany the combined library with a copy of the same work based\n   on the Library, uncombined with any other library facilities,\n   conveyed under the terms of this License.\n\n   b) Give prominent notice with the combined library that part of it\n   is a work based on the Library, and explaining where to find the\n   accompanying uncombined form of the same work.\n\n  6. Revised Versions of the GNU Lesser General Public License.\n\n  The Free Software Foundation may publish revised and/or new versions\nof the GNU Lesser General Public License from time to time. Such new\nversions will be similar in spirit to the present version, but may\ndiffer in detail to address new problems or concerns.\n\n  Each version is given a distinguishing version number. If the\nLibrary as you received it specifies that a certain numbered version\nof the GNU Lesser General Public License \"or any later version\"\napplies to it, you have the option of following the terms and\nconditions either of that published version or of any later version\npublished by the Free Software Foundation. If the Library as you\nreceived it does not specify a version number of the GNU Lesser\nGeneral Public License, you may choose any version of the GNU Lesser\nGeneral Public License ever published by the Free Software Foundation.\n\n  If the Library as you received it specifies that a proxy can decide\nwhether future versions of the GNU Lesser General Public License shall\napply, that proxy's public statement of acceptance of any version is\npermanent authorization for you to choose that version for the\nLibrary.\n\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/inf/xbox nui motor/libusb-win32-bin-README.txt",
    "content": "libusb-win32-bin v1.2.2.0 (10/02/2010) - [Package Information]\n\nALL ARCHITECTURES:\n  x86\\libusb0_x86.dll: x86 32-bit library. Must be renamed to libusb0.dll\n    On 64 bit, Installs to Windows\\syswow64\\libusb0.dll.\n    On 32 bit, Installs to Windows\\system32\\libusb0.dll.\n\n  x86\\inf-wizard.exe: inf-wizard application with embedded libusb-win32\n    v1.2.2.0 binaries.\n\nX86 ONLY ARCHITECTURES:\n  x86\\libusb0.sys: x86 32-bit driver.\n    Installs to Windows\\system32\\drivers\\libusb0.sys\n\nAMD64-INTEL64 ONLY ARCHITECTURES:\n  amd64\\libusb0.sys: x64 64-bit driver.\n    Installs to Windows\\system32\\drivers\\libusb0.sys\n\n  amd64\\libusb0.dll: x64 64-bit library.\n    Installs to Windows\\system32\\libusb0.dll\n\nIA64 ONLY ARCHITECTURES:\n  ia64\\libusb0.sys: IA64 64-bit driver.\n    Installs to Windows\\system32\\drivers\\libusb0.sys\n\n  ia64\\libusb0.dll: IA64 64-bit library.\n    Installs to Windows\\system32\\libusb0.dll\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/inf/xbox nui motor/license/libusb-win32/installer_license.txt",
    "content": "Copyright (c) 2002-2004 Stephan Meyer, <ste_meyer@web.de>\nCopyright (c) 2000-2004 Johannes Erdfelt, <johannes@erdfelt.com>\nCopyright (c) 2000-2004 Thomas Sailer, <sailer@ife.ee.ethz.ch>\nCopyright (c) 2010 Travis Robinson, <libusbdotnet@gmail.com>\n\nThis software is distributed under the following licenses:\nDriver:      GNU General Public License (GPL)\nLibrary, Test Files, Installer:    GNU Lesser General Public License (LGPL)\n\n***********************************************************************\n                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n\n                   GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\n  This version of the GNU Lesser General Public License incorporates\nthe terms and conditions of version 3 of the GNU General Public\nLicense, supplemented by the additional permissions listed below.\n\n  0. Additional Definitions.\n\n  As used herein, \"this License\" refers to version 3 of the GNU Lesser\nGeneral Public License, and the \"GNU GPL\" refers to version 3 of the GNU\nGeneral Public License.\n\n  \"The Library\" refers to a covered work governed by this License,\nother than an Application or a Combined Work as defined below.\n\n  An \"Application\" is any work that makes use of an interface provided\nby the Library, but which is not otherwise based on the Library.\nDefining a subclass of a class defined by the Library is deemed a mode\nof using an interface provided by the Library.\n\n  A \"Combined Work\" is a work produced by combining or linking an\nApplication with the Library.  The particular version of the Library\nwith which the Combined Work was made is also called the \"Linked\nVersion\".\n\n  The \"Minimal Corresponding Source\" for a Combined Work means the\nCorresponding Source for the Combined Work, excluding any source code\nfor portions of the Combined Work that, considered in isolation, are\nbased on the Application, and not on the Linked Version.\n\n  The \"Corresponding Application Code\" for a Combined Work means the\nobject code and/or source code for the Application, including any data\nand utility programs needed for reproducing the Combined Work from the\nApplication, but excluding the System Libraries of the Combined Work.\n\n  1. Exception to Section 3 of the GNU GPL.\n\n  You may convey a covered work under sections 3 and 4 of this License\nwithout being bound by section 3 of the GNU GPL.\n\n  2. Conveying Modified Versions.\n\n  If you modify a copy of the Library, and, in your modifications, a\nfacility refers to a function or data to be supplied by an Application\nthat uses the facility (other than as an argument passed when the\nfacility is invoked), then you may convey a copy of the modified\nversion:\n\n   a) under this License, provided that you make a good faith effort to\n   ensure that, in the event an Application does not supply the\n   function or data, the facility still operates, and performs\n   whatever part of its purpose remains meaningful, or\n\n   b) under the GNU GPL, with none of the additional permissions of\n   this License applicable to that copy.\n\n  3. Object Code Incorporating Material from Library Header Files.\n\n  The object code form of an Application may incorporate material from\na header file that is part of the Library.  You may convey such object\ncode under terms of your choice, provided that, if the incorporated\nmaterial is not limited to numerical parameters, data structure\nlayouts and accessors, or small macros, inline functions and templates\n(ten or fewer lines in length), you do both of the following:\n\n   a) Give prominent notice with each copy of the object code that the\n   Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the object code with a copy of the GNU GPL and this license\n   document.\n\n  4. Combined Works.\n\n  You may convey a Combined Work under terms of your choice that,\ntaken together, effectively do not restrict modification of the\nportions of the Library contained in the Combined Work and reverse\nengineering for debugging such modifications, if you also do each of\nthe following:\n\n   a) Give prominent notice with each copy of the Combined Work that\n   the Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the Combined Work with a copy of the GNU GPL and this license\n   document.\n\n   c) For a Combined Work that displays copyright notices during\n   execution, include the copyright notice for the Library among\n   these notices, as well as a reference directing the user to the\n   copies of the GNU GPL and this license document.\n\n   d) Do one of the following:\n\n       0) Convey the Minimal Corresponding Source under the terms of this\n       License, and the Corresponding Application Code in a form\n       suitable for, and under terms that permit, the user to\n       recombine or relink the Application with a modified version of\n       the Linked Version to produce a modified Combined Work, in the\n       manner specified by section 6 of the GNU GPL for conveying\n       Corresponding Source.\n\n       1) Use a suitable shared library mechanism for linking with the\n       Library.  A suitable mechanism is one that (a) uses at run time\n       a copy of the Library already present on the user's computer\n       system, and (b) will operate properly with a modified version\n       of the Library that is interface-compatible with the Linked\n       Version.\n\n   e) Provide Installation Information, but only if you would otherwise\n   be required to provide such information under section 6 of the\n   GNU GPL, and only to the extent that such information is\n   necessary to install and execute a modified version of the\n   Combined Work produced by recombining or relinking the\n   Application with a modified version of the Linked Version. (If\n   you use option 4d0, the Installation Information must accompany\n   the Minimal Corresponding Source and Corresponding Application\n   Code. If you use option 4d1, you must provide the Installation\n   Information in the manner specified by section 6 of the GNU GPL\n   for conveying Corresponding Source.)\n\n  5. Combined Libraries.\n\n  You may place library facilities that are a work based on the\nLibrary side by side in a single library together with other library\nfacilities that are not Applications and are not covered by this\nLicense, and convey such a combined library under terms of your\nchoice, if you do both of the following:\n\n   a) Accompany the combined library with a copy of the same work based\n   on the Library, uncombined with any other library facilities,\n   conveyed under the terms of this License.\n\n   b) Give prominent notice with the combined library that part of it\n   is a work based on the Library, and explaining where to find the\n   accompanying uncombined form of the same work.\n\n  6. Revised Versions of the GNU Lesser General Public License.\n\n  The Free Software Foundation may publish revised and/or new versions\nof the GNU Lesser General Public License from time to time. Such new\nversions will be similar in spirit to the present version, but may\ndiffer in detail to address new problems or concerns.\n\n  Each version is given a distinguishing version number. If the\nLibrary as you received it specifies that a certain numbered version\nof the GNU Lesser General Public License \"or any later version\"\napplies to it, you have the option of following the terms and\nconditions either of that published version or of any later version\npublished by the Free Software Foundation. If the Library as you\nreceived it does not specify a version number of the GNU Lesser\nGeneral Public License, you may choose any version of the GNU Lesser\nGeneral Public License ever published by the Free Software Foundation.\n\n  If the Library as you received it specifies that a proxy can decide\nwhether future versions of the GNU Lesser General Public License shall\napply, that proxy's public statement of acceptance of any version is\npermanent authorization for you to choose that version for the\nLibrary.\n\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/failguard.cpp",
    "content": "#include \"failguard.h\"\n#include \"libusbemu_threads.h\"\n\nint ThreadFailGuardProc(void* params);\n\nnamespace libusbemu\n{\n\nnamespace failguard\n{\n\nstatic volatile bool boTriggered (false);\nstatic QuickEvent hReaction;\nstatic volatile int nDecision (0);\n\nconst bool Check()\n{\n  if (failguard::boTriggered)\n    return(true);\n\n  // CTRL + ALT pressed?\n  if ((GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_MENU) & 0x8000))\n  {\n    // only one thread is allowed to activate the guard\n    static QuickMutex mutexFailGuard;\n    if (mutexFailGuard.TryEnter())\n    {\n      if (!failguard::boTriggered)\n      {\n        failguard::hReaction.Reset();\n        failguard::boTriggered = true;\n        new QuickThread(ThreadFailGuardProc, NULL, true);\n      }\n      mutexFailGuard.Leave();\n    }\n  }\n\n  return(failguard::boTriggered);\n}\n\nvoid WaitDecision()\n{\n  failguard::hReaction.Wait();\n}\n\nconst bool Abort()\n{\n  return(-1 == nDecision);\n}\n\n}\n\n}\n\nusing namespace libusbemu::failguard;\n\nint ThreadFailGuardProc(void* params)\n{\n  int user_option =\n  MessageBoxA(GetDesktopWindow(),\n              \"The libusb_handle_events() fail guard of libusbemu was reached!\\n\"\n              \"This was caused by pressing and holding the [CTRL] + [ALT] keys.\\n\"\n              \"If it was unintentional, click Cancel to resume normal execution;\\n\"\n              \"otherwise, click OK to effectively terminate the thread (note that\\n\"\n              \"the host program might run abnormally after such termination).\",\n              \"WARNING: libusbemu thread fail guard reached!\", MB_ICONWARNING | MB_OKCANCEL);\n\n  if (IDOK == user_option)\n    nDecision = -1;\n  else\n    boTriggered = false;\n\n  hReaction.Signal();\n\n  return(0);\n}\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/failguard.h",
    "content": "#ifndef LIBUSBEMU_FAIL_GUARD_H\n#define LIBUSBEMU_FAIL_GUARD_H\n\nnamespace libusbemu\n{\n  namespace failguard\n  {\n    const bool Check();\n\n    void WaitDecision();\n\n    const bool Abort();\n  }\n}\n\n#endif//LIBUSBEMU_FAIL_GUARD_H\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/libusb.h",
    "content": "/*\n* This file is part of the OpenKinect Project. http://www.openkinect.org\n*\n* Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n* for details.\n*\n* This code is licensed to you under the terms of the Apache License, version\n* 2.0, or, at your option, the terms of the GNU General Public License,\n* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n* or the following URLs:\n* http://www.apache.org/licenses/LICENSE-2.0\n* http://www.gnu.org/licenses/gpl-2.0.txt\n*\n* If you redistribute this file in source form, modified or unmodified, you\n* may:\n*   1) Leave this header intact and distribute it under the same terms,\n*      accompanying it with the APACHE20 and GPL20 files, or\n*   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n*   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n* In all cases you must keep the copyright notice intact and include a copy\n* of the CONTRIB file.\n*\n* Binary distributions must follow the binary distribution requirements of\n* either License.\n*/\n\n#ifndef LIBUSB_1_0_INTERFACE_EMULATOR_FOR_LIBUSB_0_1_H\n#define LIBUSB_1_0_INTERFACE_EMULATOR_FOR_LIBUSB_0_1_H\n\n// This interface emulator requires the libusb-win32 v1.2.2.1 (snapshot)\n// or later. Prior win32 versions of the library were not conformal to\n// the official libusb-0.1 API naming convention\n// (e.g.: usb_device_t instead of usb_device)\n// One can either workaround prior releases to match the official naming\n// or upgrade to the libusb-win32 1.2.2.1 snapshot.\n\n#include <unistd.h>\n\n#if defined(_MSC_VER)\n  typedef unsigned __int8   uint8_t;\n  typedef unsigned __int16  uint16_t;\n  // We need struct timeval.\n  #include <winsock.h>\n#else\n  #include <stdint.h>\n  #include <sys/time.h>\n#endif\n\n#define LIBUSBEMU 1\n\n// guard to enable mix of compiler semantics (C/C++ calling C++);\n// this should allow builds under VC++ and gcc/g++ profiles\n#ifdef __cplusplus\n  extern \"C\" {\n#endif\n\n// gotta use \"_t\" suffix here...\nstruct libusb_context_t;\n// ...otherwise C++ complains with such typedef declaration\ntypedef struct libusb_context_t libusb_context;\nint libusb_init(libusb_context** context);\nvoid libusb_exit(libusb_context* ctx);\nvoid libusb_set_debug(libusb_context *ctx, int level);\n\nstruct libusb_device_t;\ntypedef struct libusb_device_t libusb_device;\nssize_t libusb_get_device_list(libusb_context* ctx, libusb_device*** list);\nvoid libusb_free_device_list(libusb_device** list, int unref_devices);\n\nint libusb_get_device_descriptor(libusb_device* dev, struct libusb_device_descriptor*\tdesc);\n\nstruct libusb_device_handle_t;\ntypedef struct libusb_device_handle_t libusb_device_handle;\nint libusb_open(libusb_device* dev, libusb_device_handle** handle);\nvoid libusb_close(libusb_device_handle*\tdev_handle);\n\nint libusb_get_string_descriptor(libusb_device_handle *dev_handle, uint8_t desc_index, uint16_t langid, unsigned char *data, int length);\nint libusb_get_string_descriptor_ascii(libusb_device_handle *dev_handle, uint8_t desc_index, unsigned char *data, int length);\n\nint libusb_set_configuration(libusb_device_handle *dev, int configuration);\nint libusb_set_interface_alt_setting(libusb_device_handle *dev,int interface_number,int alternate_setting);\t\nint libusb_claim_interface(libusb_device_handle* dev, int interface_number);\nint libusb_release_interface(libusb_device_handle* dev, int interface_number);\n\nlibusb_device_handle *libusb_open_device_with_vid_pid(libusb_context *ctx,\n\tuint16_t vendor_id, uint16_t product_id);\n\nint libusb_control_transfer(libusb_device_handle* dev_handle, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char* data, uint16_t wLength, unsigned int timeout);\nint libusb_bulk_transfer(libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, int *actual_length, unsigned int timeout);\n\n\nstruct libusb_transfer* libusb_alloc_transfer(int iso_packets);\nvoid libusb_free_transfer(struct libusb_transfer* transfer);\n\ntypedef void(*libusb_transfer_cb_fn)(struct libusb_transfer *transfer);\nvoid libusb_fill_iso_transfer(struct libusb_transfer* transfer, libusb_device_handle* dev_handle, unsigned char endpoint, unsigned char* buffer, int length, int num_iso_packets, libusb_transfer_cb_fn callback, void* user_data, unsigned int timeout);\nvoid libusb_set_iso_packet_lengths(struct libusb_transfer* transfer, unsigned int length);\n\nint libusb_submit_transfer(struct libusb_transfer* transfer);\nint libusb_cancel_transfer(struct libusb_transfer* transfer);\n\nint libusb_handle_events(libusb_context* ctx);  // WORK IN PROGRESS...\nint libusb_handle_events_timeout(libusb_context* ctx, struct timeval* timeout);\n\n// the signature of libusb_device_descriptor is identical to usb_device_descriptor\n// which means that the below struct could be replaced by a typedef; however, that\n// would require #including <usb.h> in this header, polluting the scope and possibly\n// creating conflicts with existing <usb.h> declarations...\nstruct libusb_device_descriptor\n{\n\tuint8_t  bLength;\n\tuint8_t  bDescriptorType;\n\tuint16_t bcdUSB;\n\tuint8_t  bDeviceClass;\n\tuint8_t  bDeviceSubClass;\n\tuint8_t  bDeviceProtocol;\n\tuint8_t  bMaxPacketSize0;\n\tuint16_t idVendor;\n\tuint16_t idProduct;\n\tuint16_t bcdDevice;\n\tuint8_t  iManufacturer;\n\tuint8_t  iProduct;\n\tuint8_t  iSerialNumber;\n\tuint8_t  bNumConfigurations;\n};\n\nenum libusb_endpoint_direction {\n\tLIBUSB_ENDPOINT_IN = 0x80,\n\tLIBUSB_ENDPOINT_OUT = 0x00\n};\n\nenum libusb_transfer_status\n{\n\tLIBUSB_TRANSFER_COMPLETED,\n\tLIBUSB_TRANSFER_ERROR,\n\tLIBUSB_TRANSFER_TIMED_OUT,\n\tLIBUSB_TRANSFER_CANCELLED,\n\tLIBUSB_TRANSFER_STALL,\n\tLIBUSB_TRANSFER_NO_DEVICE,\n\tLIBUSB_TRANSFER_OVERFLOW\n};\n\nenum libusb_transfer_type\n{\n\tLIBUSB_TRANSFER_TYPE_CONTROL = 0,\n\tLIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,\n\tLIBUSB_TRANSFER_TYPE_BULK = 2,\n\tLIBUSB_TRANSFER_TYPE_INTERRUPT = 3,\n};\n\nenum libusb_transfer_flags {\n\tLIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,\n\tLIBUSB_TRANSFER_FREE_BUFFER = 1<<1,\n\tLIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,\n};\n\nstruct libusb_transfer\n{\n\tlibusb_device_handle *dev_handle;\n\tuint8_t flags;\n\tunsigned char endpoint;\n\tunsigned char type;\n\tunsigned int timeout;\n\tenum libusb_transfer_status status;\n\tint length;\n\tint actual_length;\n\tlibusb_transfer_cb_fn callback;\n\tvoid *user_data;\n\tunsigned char *buffer;\n\tint num_iso_packets;\n\tstruct libusb_iso_packet_descriptor* iso_packet_desc;\n};\n\nstruct libusb_iso_packet_descriptor\n{\n\tunsigned int length;\n\tunsigned int actual_length;\n\tenum libusb_transfer_status status;\n};\n\nenum libusb_error\n{\n\tLIBUSB_SUCCESS = 0,\n\tLIBUSB_ERROR_IO = -1,\n\tLIBUSB_ERROR_INVALID_PARAM = -2,\n\tLIBUSB_ERROR_ACCESS = -3,\n\tLIBUSB_ERROR_NO_DEVICE = -4,\n\tLIBUSB_ERROR_NOT_FOUND = -5,\n\tLIBUSB_ERROR_BUSY = -6,\n\tLIBUSB_ERROR_TIMEOUT = -7,\n\tLIBUSB_ERROR_OVERFLOW = -8,\n\tLIBUSB_ERROR_PIPE = -9,\n\tLIBUSB_ERROR_INTERRUPTED = -10,\n\tLIBUSB_ERROR_NO_MEM = -11,\n\tLIBUSB_ERROR_NOT_SUPPORTED = -12,\n\tLIBUSB_ERROR_OTHER = -99,\n};\n\n#ifdef __cplusplus\n  }\n#endif\n\n#endif//LIBUSB_1_0_INTERFACE_EMULATOR_FOR_LIBUSB_0_1_H\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/libusbemu.cpp",
    "content": "/*\n* This file is part of the OpenKinect Project. http://www.openkinect.org\n*\n* Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n* for details.\n*\n* This code is licensed to you under the terms of the Apache License, version\n* 2.0, or, at your option, the terms of the GNU General Public License,\n* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n* or the following URLs:\n* http://www.apache.org/licenses/LICENSE-2.0\n* http://www.gnu.org/licenses/gpl-2.0.txt\n*\n* If you redistribute this file in source form, modified or unmodified, you\n* may:\n*   1) Leave this header intact and distribute it under the same terms,\n*      accompanying it with the APACHE20 and GPL20 files, or\n*   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n*   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n* In all cases you must keep the copyright notice intact and include a copy\n* of the CONTRIB file.\n*\n* Binary distributions must follow the binary distribution requirements of\n* either License.\n*/\n\n// Headers required to enable Visual C++ Memory Leak mechanism:\n// (NOTE: this should only be activated in Debug mode!)\n#if defined(_MSC_VER) && defined(_DEBUG)\n\n  // MSVC version predefined macros:\n  // http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/17a84d56-4713-48e4-a36d-763f4dba0c1c/\n  // _MSC_VER | MSVC Edition\n  // ---------+---------------\n  //     1300 | MSVC .NET 2002\n  //     1310 | MSVC .NET 2003\n  //     1400 | MSVC 2005\n  //     1500 | MSVC 2008\n  //     1600 | MSVC 2010\n\n  // until VC71 (MSVC2003) the human-readable map/dump mode flag is CRTDBG_MAP_ALLOC:\n  // http://msdn.microsoft.com/en-us/library/x98tx3cf(v=vs.71).aspx\n  // but from VC80 (MSVC2005) and on the flag should be prefixed by a \"_\":\n  // http://msdn.microsoft.com/en-us/library/x98tx3cf(v=vs.80).aspx\n  #if _MSC_VER >= 1400\n    #define _CRTDBG_MAP_ALLOC\n  #else\n    #define CRTDBG_MAP_ALLOC\n  #endif\n  #include <stdlib.h>\n  #include <crtdbg.h>\n\n  // Also, gotta redefine the new operator ...\n  // http://support.microsoft.com/kb/140858\n  // but before redefining it, for MSVC version prior to 2010, the STL <map>\n  // header must be included in order to avoid some scary compilation issues:\n  // http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/a6a148ed-aff1-4ec0-95d2-a82cd4c29cbb\n  #if _MSC_VER < 1600\n    #include <map>\n  #endif\n  // now it is safe to redefine the new operator\n  #define LIBUSBEMU_DEBUG_NEW  new ( _NORMAL_BLOCK, __FILE__, __LINE__)\n  #define new LIBUSBEMU_DEBUG_NEW\n\n#endif\n\n#include \"libusb.h\"\n#include \"libusbemu_internal.h\"\n#include \"failguard.h\"\n#include <cassert>\n#include <algorithm>\n#include \"freenect_internal.h\"\n\nusing namespace libusbemu;\n\n#ifdef _DEBUG\n  #define LIBUSBEMU_DEBUG_BUILD\n#endif//_DEBUG\n\n#ifdef  LIBUSBEMU_DEBUG_BUILD\n  #define LIBUSB_DEBUG_CMD(cmd) cmd\n#else\n  #define LIBUSB_DEBUG_CMD(cmd)\n#endif//LIBUSBEMU_DEBUG_BUILD\n\nstatic libusb_context *default_context = NULL;\n\nint libusb_init(libusb_context** context)\n{\n\tusb_init();\n  LIBUSB_DEBUG_CMD\n  (\n    const usb_version* version = usb_get_version();\n    fprintf(stdout, \"libusb-win32: dll version %d.%d.%d.%d | driver (libusb0.sys) version %d.%d.%d.%d\\n\",\n      version->dll.major, version->dll.minor, version->dll.micro, version->dll.nano,\n      version->driver.major, version->driver.minor, version->driver.micro, version->driver.nano);\n  );\n\t// there is no such a thing like 'context' in libusb-0.1...\n\t// however, it is wise to emulate such context structure to localize and\n  // keep track of any resource and/or internal data structures, as well as\n  // to be able to clean-up itself at libusb_exit()\n  if (context == NULL)\n    context = &default_context;\n\n\t*context = new libusb_context;\n\t// 0 on success; LIBUSB_ERROR on failure\n\treturn(0);\n}\n\nvoid libusb_exit(libusb_context* ctx)\n{\n  if (ctx == NULL)\n    ctx = default_context;\n\n  ctx->mutex.Enter();\n  // before deleting the context, delete all devices/transfers still in there:\n  while (!ctx->devices.empty())\n  {\n    libusb_context::TMapDevices::iterator itDevice (ctx->devices.begin());\n    libusb_device& device (itDevice->second);\n    if (NULL != device.handles)\n    {\n      // a simple \"while(!device.handles->empty())\" loop is impossible here\n      // because after a call to libusb_close() the device may be already\n      // destroyed (that's the official libusb-1.0 semantics when the ref\n      // count reaches zero), rendering \"device.handles\" to a corrupt state.\n      // an accurate \"for\" loop on the number of handles is the way to go.\n      const int handles = device.handles->size();\n      for (int h=0; h<handles; ++h)\n      {\n        libusb_device::TMapHandles::iterator itHandle = device.handles->begin();\n        libusb_device_handle* handle (&(itHandle->second));\n        libusb_close(handle);\n      }\n    }\n  }\n  ctx->mutex.Leave();\n\tdelete(ctx);\n}\n\n\nvoid libusb_set_debug(libusb_context *ctx, int level)\n{\n\t// Note: libusb-win32 doesn't support context-specific loglevels, so this\n\t// sets the loglevel globally.  If this is actually an issue for you, I\n\t// will be surprised.\n\tusb_set_debug(level);\n\treturn;\n}\n\nssize_t libusb_get_device_list(libusb_context* ctx, libusb_device*** list)\n{\n  if (ctx == NULL)\n    ctx = default_context;\n\n\t// libusb_device*** list demystified:\n\t// libusb_device*** is the C equivalent to libusb_device**& in C++; such declaration\n\t// allows the scope of this function libusb_get_device_list() to write on a variable\n\t// of type libusb_device** declared within the function scope of the caller.\n\t// libusb_device** is better understood as libusb_device*[], which is an array of\n\t// pointers of type libusb_device*, each pointing to a struct that holds actual data.\n\tusb_find_busses();\n\tusb_find_devices();\n\tusb_bus* bus = usb_get_busses();\n\twhile (bus)\n\t{\n\t\tstruct usb_device* device = bus->devices;\n\t\twhile (device)\n\t\t{\n      libusbemu_register_device(ctx, device);\n\t\t\tdevice = device->next;\n\t\t};\n\t\tbus = bus->next;\n\t};\n  // populate the device list that will be returned to the client:\n  // the list must be NULL-terminated to follow the semantics of libusb-1.0!\n  RAIIMutex lock (ctx->mutex);\n  libusb_device**& devlist = *list;\n  devlist = new libusb_device* [ctx->devices.size()+1];   // +1 is for a finalization mark\n  libusb_context::TMapDevices::iterator it  (ctx->devices.begin());\n  libusb_context::TMapDevices::iterator end (ctx->devices.end());\n  for (int i=0; it!=end; ++it, ++i)\n    devlist[i] = &it->second;\n  // finalization mark to assist later calls to libusb_free_device_list()\n  devlist[ctx->devices.size()] = NULL;\n\t// the number of devices in the outputted list, or LIBUSB_ERROR_NO_MEM on memory allocation failure.\n\treturn(ctx->devices.size());\n}\n\nvoid libusb_free_device_list(libusb_device** list, int unref_devices)\n{\n  if (NULL == list)\n    return;\n  if (unref_devices)\n  {\n    int i (0);\n    while (list[i] != NULL)\n    {\n      libusbemu_unregister_device(list[i]);\n      ++i;\n    }\n  }\n\tdelete[](list);\n}\n\nint libusb_get_device_descriptor(libusb_device* dev, struct libusb_device_descriptor*\tdesc)\n{\n  struct usb_device* device (dev->device);\n\tusb_device_descriptor& device_desc (device->descriptor);\n\t// plain copy of one descriptor on to another: this is a safe operation because\n\t// usb_device_descriptor and libusb_device_descriptor have the same signature\n\tmemcpy(desc, &device_desc, sizeof(libusb_device_descriptor));\n\t// 0 on success; LIBUSB_ERROR on failure\n\treturn(0);\n}\n\nint libusb_open(libusb_device* dev, libusb_device_handle** handle)\n{\n  RAIIMutex lock (dev->ctx->mutex);\n\n  usb_dev_handle* usb_handle (usb_open(dev->device));\n  if (NULL == usb_handle)\n  {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return(LIBUSB_ERROR_OTHER);\n  }\n\n  if (NULL == dev->handles)\n    dev->handles = new libusb_device::TMapHandles;\n\n  libusb_device_handle_t dummy = { dev, usb_handle };\n  libusb_device::TMapHandles::iterator it = dev->handles->insert(std::make_pair(usb_handle,dummy)).first;\n  *handle = &(it->second);\n  assert((*handle)->dev == dev);\n  assert((*handle)->handle == usb_handle);\n  dev->refcount++;\n\n  if (NULL == dev->isoTransfers)\n    dev->isoTransfers = new libusb_device::TMapIsocTransfers;\n\n\t//0 on success\n\t// LIBUSB_ERROR_NO_MEM on memory allocation failure\n\t// LIBUSB_ERROR_ACCESS if the user has insufficient permissions\n\t// LIBUSB_ERROR_NO_DEVICE if the device has been disconnected\n\t// another LIBUSB_ERROR code on other failure\n\treturn(0);\n}\n\nvoid libusb_close(libusb_device_handle*\tdev_handle)\n{\n  RAIIMutex lock (dev_handle->dev->ctx->mutex);\n  libusb_device* device (dev_handle->dev);\n  if (device->handles->find(dev_handle->handle) == device->handles->end())\n  {\n    LIBUSBEMU_ERROR(\"libusb_close() attempted to close an unregistered handle!\\n\");\n    return;\n  }\n  if (0 != usb_close(dev_handle->handle))\n  {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return;\n  }\n  device->handles->erase(dev_handle->handle);\n  libusbemu_unregister_device(device);\n}\n\nint libusb_get_string_descriptor(libusb_device_handle *dev_handle, uint8_t desc_index, uint16_t langid, unsigned char *data, int length)\n{\n  RAIIMutex lock (dev_handle->dev->ctx->mutex);\n  int bytes = usb_get_string(dev_handle->handle, (int)desc_index, (int)langid, (char*)data, (size_t)length);\n  if (bytes < 0) {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n  }\n  return bytes;\n}\nint libusb_get_string_descriptor_ascii(libusb_device_handle *dev_handle, uint8_t desc_index, unsigned char *data, int length)\n{\n  RAIIMutex lock (dev_handle->dev->ctx->mutex);\n  int bytes = usb_get_string_simple(dev_handle->handle, (int)desc_index, (char*)data, (size_t)length);\n  if (bytes < 0) {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n  }\n  return bytes;\n}\n\nint libusb_set_configuration(libusb_device_handle *dev, int configuration)\n{\n  RAIIMutex lock (dev->dev->ctx->mutex);\n  int ret = usb_set_configuration(dev->handle, configuration);\n  if (0 != ret)\n  {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return ret;\n  }\n  // returns:\n  // 0 on success\n  // LIBUSB_ERROR_NOT_FOUND if the requested configuration does not exist\n  // LIBUSB_ERROR_BUSY if interfaces are currently claimed\n  // LIBUSB_ERROR_NO_DEVICE if the device has been disconnected\n  // another LIBUSB_ERROR code on other failure\n  //\n  return 0;\n}\n\nint libusb_set_interface_alt_setting(libusb_device_handle *dev, int interface_number,int alternate_setting){\n  RAIIMutex lock (dev->dev->ctx->mutex);\n  if (0 != usb_set_altinterface(dev->handle, alternate_setting))\n  {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return(LIBUSB_ERROR_OTHER);\n  }\n\t\n  return(0);\t\n}\t\n\nint libusb_claim_interface(libusb_device_handle* dev, int interface_number)\n{\n  RAIIMutex lock (dev->dev->ctx->mutex);\n  // according to the official libusb-win32 usb_set_configuration() documentation:\n  // http://sourceforge.net/apps/trac/libusb-win32/wiki/libusbwin32_documentation\n  // \"Must be called!: usb_set_configuration() must be called with a valid\n  //  configuration (not 0) before you can claim the interface. This might\n  //  not be be necessary in the future. This behavior is different from\n  //  Linux libusb-0.1.\"\n  if (0 != usb_set_configuration(dev->handle, 1))\n  {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return(LIBUSB_ERROR_OTHER);\n  }\n\tif (0 != usb_claim_interface(dev->handle, interface_number))\n  {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return(LIBUSB_ERROR_OTHER);\n  }\n\n  //if (0 != usb_set_altinterface(dev->handle, 0))\n  //  return(LIBUSB_ERROR_OTHER);\n\n  // LIBUSB_ERROR_NOT_FOUND if the requested interface does not exist\n\t// LIBUSB_ERROR_BUSY if another program or driver has claimed the interface\n\t// LIBUSB_ERROR_NO_DEVICE if the device has been disconnected\n\t// a LIBUSB_ERROR code on other failure\n\t// 0 on success\n\treturn(0);\n}\n\nint libusb_release_interface(libusb_device_handle* dev, int interface_number)\n{\n  RAIIMutex lock (dev->dev->ctx->mutex);\n\tif (0 != usb_release_interface(dev->handle, interface_number))\n  {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return(LIBUSB_ERROR_OTHER);\n  }\n\t// LIBUSB_ERROR_NOT_FOUND if the interface was not claimed\n\t// LIBUSB_ERROR_NO_DEVICE if the device has been disconnected\n\t// another LIBUSB_ERROR code on other failure\n\t// 0 on success\n\treturn(0);\n}\n\nlibusb_device_handle *libusb_open_device_with_vid_pid(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id)\n{\n\tint num_devices;\n\tlibusb_device** list;\n\tlibusb_device_handle *dev_handle = NULL;\n\n\tif (ctx == NULL)\n\t\tctx = default_context;\n\n\tnum_devices = libusb_get_device_list(ctx, &list);\n\tif (num_devices < 0)\n\t\treturn NULL;\n\n\tunsigned int i = 0;\n\twhile (list[i] != NULL) {\n\t\tstruct libusb_device_descriptor desc;\n\t\tint ret = libusb_get_device_descriptor(list[i], &desc);\n\t\tif (ret < 0)\n\t\t\tbreak;\n\n\t\tif (desc.idVendor == vendor_id && desc.idProduct == product_id) {\n\t\t\tret = libusb_open(list[i], &dev_handle);\n\t\t\tif (ret)\n\t\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\n\tlibusb_free_device_list(list, 1);\n\treturn dev_handle;\n}\n\nint libusb_control_transfer(libusb_device_handle* dev_handle, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char* data, uint16_t wLength, unsigned int timeout)\n{\n\t// in libusb-1.0 a timeout of zero it means 'wait indefinitely'; in libusb-0.1, a timeout of zero means 'return immediatelly'!\n\ttimeout = (0 == timeout) ? 60000 : timeout;   // wait 60000ms (60s = 1min) if the transfer is supposed to wait indefinitely...\n\tint bytes_transferred = usb_control_msg(dev_handle->handle, bmRequestType, bRequest, wValue, wIndex, (char*)data, wLength, timeout);\n  if (bytes_transferred < 0)\n  {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return(LIBUSB_ERROR_OTHER);\n  }\n\t// on success, the number of bytes actually transferred\n\t// LIBUSB_ERROR_TIMEOUT if the transfer timed out\n\t// LIBUSB_ERROR_PIPE if the control request was not supported by the device\n\t// LIBUSB_ERROR_NO_DEVICE if the device has been disconnected\n\t// another LIBUSB_ERROR code on other failures\n\treturn(bytes_transferred);\n}\n\nint libusb_bulk_transfer(libusb_device_handle* dev_handle, uint8_t endpoint, uint8_t *data, int length, int *transferred, unsigned int timeout)\n{\n       // in libusb-1.0 a timeout of zero it means 'wait indefinitely'; in libusb-0.1, a timeout of zero means 'return immediately'!\n       timeout = (0 == timeout) ? 60000 : timeout;   // wait 60000ms (60s = 1min) if the transfer is supposed to wait indefinitely...\n       int bytes_transferred;\n       if (endpoint & LIBUSB_ENDPOINT_IN) { // Device to Host\n               bytes_transferred = usb_bulk_read(dev_handle->handle, endpoint, (char*)data, length, timeout);\n       } else { // Host to Device\n               bytes_transferred = usb_bulk_write(dev_handle->handle, endpoint, (char*)data, length, timeout);\n       }\n       if (bytes_transferred < 0) {\n               // 0 on success (and populates transferred)\n               // LIBUSB_ERROR_TIMEOUT if the transfer timed out (and populates transferred)\n               // LIBUSB_ERROR_PIPE if the endpoint halted\n               // LIBUSB_ERROR_OVERFLOW if the device offered more data, see Packets and overflows\n               // LIBUSB_ERROR_NO_DEVICE if the device has been disconnected\n               // another LIBUSB_ERROR code on other failures\n               *transferred = 0;\n               LIBUSBEMU_ERROR_LIBUSBWIN32();\n               return(LIBUSB_ERROR_OTHER);\n       }\n       *transferred = bytes_transferred;\n       return 0;\n}\n\n// FROM HERE ON CODE BECOMES QUITE MESSY: ASYNCHRONOUS TRANSFERS MANAGEMENT\n\nstruct libusb_transfer* libusb_alloc_transfer(int iso_packets)\n{\n  transfer_wrapper* wrapper = new transfer_wrapper;\n  memset(wrapper, 0, sizeof(transfer_wrapper));\n  libusb_transfer& transfer (wrapper->libusb);\n  transfer.num_iso_packets = iso_packets;\n  transfer.iso_packet_desc = new libusb_iso_packet_descriptor [iso_packets];\n  memset(transfer.iso_packet_desc, 0, iso_packets*sizeof(libusb_iso_packet_descriptor));\n  // a newly allocated transfer, or NULL on error\n  return(&transfer);\n}\n\nvoid libusb_free_transfer(struct libusb_transfer* transfer)\n{\n  // according to the official libusb_free_transfer() documentation:\n  // \"It is legal to call this function with a NULL transfer.\n  //  In this case, the function will simply return safely.\"\n  if (NULL == transfer)\n    return;\n\n  // according to the official libusb_free_transfer() documentation:\n  // \"It is not legal to free an active transfer\n  //  (one which has been submitted and has not yet completed).\"\n  // that means that only \"orphan\" transfers can be deleted:\n  transfer_wrapper* wrapper = libusbemu_get_transfer_wrapper(transfer);\n  if (!libusb_device::TListTransfers::Orphan(wrapper))\n  {\n    LIBUSBEMU_ERROR(\"libusb_free_transfer() attempted to free an active transfer!\");\n    return;\n  }\n\n  if (0 != usb_free_async(&wrapper->usb))\n  {\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return;\n  }\n\n  if (NULL != transfer->iso_packet_desc)\n    delete[](transfer->iso_packet_desc);\n\n  // according to the official libusb_free_transfer() documentation:\n  // \"If the LIBUSB_TRANSFER_FREE_BUFFER flag is set and the transfer buffer\n  //  is non-NULL, this function will also free the transfer buffer using the\n  //  standard system memory allocator (e.g. free()).\"\n  if (transfer->flags & LIBUSB_TRANSFER_FREE_BUFFER)\n    free(transfer->buffer);\n\n  delete(wrapper);\n}\n\nvoid libusb_fill_iso_transfer(struct libusb_transfer* transfer, libusb_device_handle* dev_handle, unsigned char endpoint, unsigned char* buffer, int length, int num_iso_packets, libusb_transfer_cb_fn callback, void* user_data, unsigned int timeout)\n{\n  // according to the official libusb_fill_iso_transfer() documentation:\n  // \"libusb_fill_iso_transfer() is a helper function to populate the required\n  //  libusb_transfer fields for an isochronous transfer.\"\n  // What this means is that the library client is not required to call this\n  // helper function in order to setup the fields within the libusb_transfer\n  // struct. Thus, this is NOT the place for any sort of special processing\n  // because there are no guarantees that such function will ever be invoked.\n\ttransfer->dev_handle = dev_handle;\n\ttransfer->endpoint = endpoint;\n\ttransfer->buffer = buffer;\n\ttransfer->length = length;\n\ttransfer->num_iso_packets = num_iso_packets;\n\ttransfer->callback = callback;\n\ttransfer->timeout = timeout;\n\ttransfer->user_data = user_data;\n\ttransfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;\n\n\t// control some additonal library duties such as:\n  // LIBUSB_TRANSFER_SHORT_NOT_OK, LIBUSB_TRANSFER_FREE_BUFFER, LIBUSB_TRANSFER_FREE_TRANSFER\n\ttransfer->flags;\n\t// these two are output parameters coming from actual transfers...\n\ttransfer->actual_length;\n\ttransfer->status;\n}\n\nvoid libusb_set_iso_packet_lengths(struct libusb_transfer* transfer, unsigned int length)\n{\n  // according to the official libusb_fill_iso_transfer() documentation:\n  // \"Convenience function to set the length of all packets in an isochronous\n  //  transfer, based on the num_iso_packets field in the transfer structure.\"\n  // For the same reasons as in libusb_fill_iso_transfer(), no additional\n  // processing should ever happen withing this function...\n\tfor (int i=0; i < transfer->num_iso_packets; ++i)\n\t\ttransfer->iso_packet_desc[i].length = length;\n}\n\nint ReapThreadProc(void* params);\n\nint libusb_submit_transfer(struct libusb_transfer* transfer)\n{\n  transfer_wrapper* wrapper = libusbemu_get_transfer_wrapper(transfer);\n\n  // the first time a transfer is submitted, the libusb-0.1 transfer context\n  // (the void*) must be created and initialized with a proper call to one of\n  // the usb_***_setup_async() functions; one could thing of doing this setup\n  // within libusb_fill_***_transfer(), but the latter are just convenience\n  // functions to fill the transfer data structure: the library client is not\n  // forced to call them and could fill the fields directly within the struct.\n  if (NULL == wrapper->usb)\n    libusbemu_setup_transfer(wrapper);\n\n  libusbemu_clear_transfer(wrapper);\n\n  int ret = usb_submit_async(wrapper->usb, (char*)transfer->buffer, transfer->length);\n  if (ret < 0)\n  {\n    // TODO: better error handling...\n    // what does usb_submit_async() actually returns on error?\n    // LIBUSB_ERROR_NO_DEVICE if the device has been disconnected\n    // LIBUSB_ERROR_BUSY if the transfer has already been submitted.\n    // another LIBUSB_ERROR code on other failure\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return(ret);\n  }\n\n  libusb_device::TMapIsocTransfers& isoTransfers (*transfer->dev_handle->dev->isoTransfers);\n  libusb_device::TMapIsocTransfers::iterator it = isoTransfers.find(transfer->endpoint);\n  if (isoTransfers.end() == it)\n  {\n    libusb_device::isoc_handle dummy = { libusb_device::TListTransfers(), NULL };\n    it = isoTransfers.insert(std::make_pair(transfer->endpoint, dummy)).first;\n  }\n  libusb_device::isoc_handle& iso (it->second);\n  iso.listTransfers.Append(wrapper);\n\n  if (NULL == iso.poReapThread)\n  {\n    void** state = new void* [2];\n    state[0] = transfer->dev_handle;\n    state[1] = (void*)transfer->endpoint;\n    iso.poReapThread = new QuickThread(ReapThreadProc, (void*)state, true);\n  }\n\n  // 0 on success\n  return(0);\n}\n\nint libusb_cancel_transfer(struct libusb_transfer* transfer)\n{\n  transfer_wrapper* wrapper = libusbemu_get_transfer_wrapper(transfer);\n  // according to the official libusb_cancel_transfer() documentation:\n  // \"This function returns immediately, but this does not indicate\n  //  cancellation is complete. Your callback function will be invoked at\n  //  some later time with a transfer status of LIBUSB_TRANSFER_CANCELLED.\"\n  // This semantic can be emulated by setting the transfer->status flag to\n  // LIBUSB_TRANSFER_CANCELLED, leaving the rest to libusb_handle_events().\n\ttransfer->status = LIBUSB_TRANSFER_CANCELLED;\n\tint ret = usb_cancel_async(wrapper->usb);\n  if (ret != 0)\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n\t// 0 on success\n\t// LIBUSB_ERROR_NOT_FOUND if the transfer is already complete or cancelled.\n\t// a LIBUSB_ERROR code on failure\n\treturn(ret);\n}\n\n// FROM HERE ON CODE BECOMES REALLY REALLY REALLY MESSY: HANDLE EVENTS STUFF\n\nint libusbemu_handle_isochronous(libusb_context* ctx, const unsigned int milliseconds)\n{\n  if (ctx == NULL)\n    ctx = default_context;\n\n  //QuickThread::Myself().RaisePriority();\n  RAIIMutex lock (ctx->mutDeliveryPool);\n  int index = ctx->hWantToDeliverPool.WaitAnyUntilTimeout(milliseconds);\n  if (-1 != index)\n  {\n    EventList hDoneDeliveringPoolLocal;\n    while (-1 != (index = ctx->hWantToDeliverPool.CheckAny()))\n    {\n      ctx->hAllowDeliveryPool[index]->Signal();\n      ctx->hWantToDeliverPool[index]->Reset();\n      hDoneDeliveringPoolLocal.AttachEvent(ctx->hDoneDeliveringPool[index]);\n    }\n    hDoneDeliveringPoolLocal.WaitAll();\n  }\n  //QuickThread::Myself().LowerPriority();\n  return(0);\n}\n\nint libusb_handle_events(libusb_context* ctx)\n{\n  if (ctx == NULL)\n    ctx = default_context;\n\n  if (failguard::Abort())\n    return(LIBUSB_ERROR_INTERRUPTED);\n\n  RAIIMutex lock (ctx->mutex);\n\n  libusbemu_handle_isochronous(ctx, 60000);\n\n  // 0 on success, or a LIBUSB_ERROR code on failure\n  return(0);\n}\n\nint libusb_handle_events_timeout(libusb_context* ctx, struct timeval* timeout)\n{\n  if (ctx == NULL)\n    ctx = default_context;\n\n  if (failguard::Abort())\n    return(LIBUSB_ERROR_INTERRUPTED);\n\n  RAIIMutex lock (ctx->mutex);\n\n  if (timeout == NULL)\n    libusbemu_handle_isochronous(ctx, 0);\n  else\n    libusbemu_handle_isochronous(ctx, (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000));\n\n  // 0 on success, or a LIBUSB_ERROR code on failure\n  return(0);\n}\n\nvoid PreprocessTransferNaive(libusb_transfer* transfer, const int read);\nvoid PreprocessTransferFreenect(libusb_transfer* transfer, const int read);\nstatic void(*PreprocessTransfer)(libusb_transfer*, const int) (PreprocessTransferFreenect);\n\nvoid libusbemu_deliver_transfer(transfer_wrapper* wrapper)\n{\n  // paranoid check...\n  assert(libusb_device::TListTransfers::Orphan(wrapper));\n\n  libusb_transfer* transfer = &wrapper->libusb;\n\n  // if data is effectively acquired (non-zero bytes transfer), all of the\n  // associated iso packed descriptors must be filled properly; this is an\n  // application specific task and requires knowledge of the logic behind\n  // the streams being transferred: PreprocessTransfer() is an user-defined\n  // \"library-injected\" routine that should perform this task.\n  if (transfer->actual_length > 0)\n    PreprocessTransfer(transfer, transfer->actual_length);\n\n  // callback the library client through the callback; at this point, the\n  // client is assumed to do whatever it wants to the data and, possibly,\n  // resubmitting the transfer, which would then place the transfer at the\n  // end of its related asynchronous list (orphan transfer is adopted).\n  transfer->callback(transfer);\n}\n\nint ReapTransfer(transfer_wrapper*, unsigned int, libusb_device::TListTransfers*);\n\nint ReapThreadProc(void* params)\n{\n  LIBUSB_DEBUG_CMD(fprintf(stdout, \"Thread execution started.\\n\"));\n\n  void** state = (void**)params;\n  libusb_device_handle* dev_handle = (libusb_device_handle*)state[0];\n  const int endpoint = (int)state[1];\n  delete[](state);\n\n  libusb_device::TMapIsocTransfers& isocTransfers = *(dev_handle->dev->isoTransfers);\n  libusb_device::isoc_handle& isocHandle = isocTransfers[endpoint];\n  libusb_device::TListTransfers& listTransfers (isocHandle.listTransfers);\n  QuickThread*& poThreadObject = isocHandle.poReapThread;\n  libusb_context* ctx (dev_handle->dev->ctx);\n\n  bool boAbort (false);\n\n  bool boDeliverRequested (false);\n  QuickEvent wannaDeliver;\n  QuickEvent allowDeliver;\n  QuickEvent doneDelivering;\n  ctx->mutDeliveryPool.Enter();\n    ctx->hWantToDeliverPool.AttachEvent(&wannaDeliver);\n    ctx->hAllowDeliveryPool.AttachEvent(&allowDeliver);\n    ctx->hDoneDeliveringPool.AttachEvent(&doneDelivering);\n  ctx->mutDeliveryPool.Leave();\n\n  libusb_device::TListTransfers listReadyLocal;\n\n  // isochronous I/O must be handled in high-priority! (at least TIME_CRITICAL)\n  // otherwise, sequence losses are prone to happen...\n  QuickThread::Myself().RaisePriority();\n\n  // keep the thread alive as long as there are pending or ready transfers\n  while(!listTransfers.Empty() || !listReadyLocal.Empty())\n\t{\n    // prioritize transfers that are ready to be delivered \n    if (!listReadyLocal.Empty())\n    {\n      // signal the delivery request, if not signaled yet\n      if (!boDeliverRequested)\n      {\n        doneDelivering.Reset();\n        wannaDeliver.Signal();\n        boDeliverRequested = true;\n      }\n      // delivery request already signaled; wait for the delivery permission\n      else if (allowDeliver.WaitUntilTimeout(1))\n      {\n        boDeliverRequested = false;\n        while (!listReadyLocal.Empty())\n        {\n          transfer_wrapper* wrapper = listReadyLocal.Head();\n          listReadyLocal.Remove(wrapper);\n          libusbemu_deliver_transfer(wrapper);\n        }\n        doneDelivering.Signal();\n      }\n    }\n\n    // check for pending transfers coming from the device stream\n    if (!listTransfers.Empty())\n    {\n\t\t  transfer_wrapper* wrapper = listTransfers.Head();\n  \t  int read = ReapTransfer(wrapper, 10000, &listReadyLocal);\n      if (-5 == read)\n      {\n        while (!listTransfers.Empty())\n          listTransfers.Remove(listTransfers.Head());\n        while (!listReadyLocal.Empty())\n          listReadyLocal.Remove(listReadyLocal.Head());\n      }\n    }\n    // if there are no pending transfers, wait the ready ones to be delivered\n    else\n    {\n      LIBUSB_DEBUG_CMD(fprintf(stdout, \"ReapThreadProc(): no pending transfers, sleeping until delivery...\\n\"));\n      if (!boDeliverRequested)\n      {\n        doneDelivering.Reset();\n        wannaDeliver.Signal();\n        boDeliverRequested = true;\n      }\n      allowDeliver.Wait();\n    }\n\n    // finally, check the thread failguard\n    if (failguard::Check() && !boAbort)\n    {\n      failguard::WaitDecision();\n      if (failguard::Abort())\n      {\n        LIBUSB_DEBUG_CMD(fprintf(stderr, \"Thread is aborting: releasing transfers...\\n\"));\n        QuickThread::Myself().LowerPriority();\n        boDeliverRequested = true;\n        allowDeliver.Signal();\n        boAbort = true;\n      }\n    }\n\t}\n\n  QuickThread::Myself().LowerPriority();\n\n  LIBUSB_DEBUG_CMD\n  (\n    if (boAbort)\n      fprintf(stderr, \"Thread loop aborted.\\n\");\n  );\n\n  while(!ctx->mutDeliveryPool.TryEnter())\n    {\n      wannaDeliver.Signal();\n      doneDelivering.Signal();\n    }\n    ctx->hWantToDeliverPool.DetachEvent(&wannaDeliver);\n    ctx->hAllowDeliveryPool.DetachEvent(&allowDeliver);\n    ctx->hDoneDeliveringPool.DetachEvent(&doneDelivering);\n  ctx->mutDeliveryPool.Leave();\n\n  poThreadObject = NULL;\n\n  LIBUSB_DEBUG_CMD(fprintf(stdout, \"Thread execution finished.\\n\"));\n\treturn(0);\n}\n\nint ReapTransfer(transfer_wrapper* wrapper, unsigned int timeout, libusb_device::TListTransfers* lstReady)\n{\n  void* context (wrapper->usb);\n  libusb_transfer* transfer (&wrapper->libusb);\n\n\tconst int read = usb_reap_async_nocancel(context, timeout);\n  if (read >= 0)\n  {\n    // data successfully acquired (0 bytes is also a go!)\n    transfer->status = LIBUSB_TRANSFER_COMPLETED;\n\n    // according to the official libusb_transfer struct reference:\n    // \"int libusb_transfer::actual_length\n    //  Actual length of data that was transferred.\n    //  Read-only, and only for use within transfer callback function.\n    //  Not valid for isochronous endpoint transfers.\"\n    // since the client will allegedly not read from this field, we'll be using\n    // it here just to simplify the emulation implementation, more specifically\n    // the libusb_handle_events() and libusbemu_clear_transfer().\n    transfer->actual_length = read;\n\n    // the transfer should be removed from the head of the list and put into\n    // an orphan state; it is up to the client code to resubmit the transfer\n    // which will possibly happen during the client callback.\n    libusb_device::TListTransfers::RemoveNode(wrapper);\n\n    // two possibilities here: either deliver the transfer now or postpone the\n    // delivery to keep it in sync with libusb_handle_events(); in the latter\n    // case, a destination list must be provided.\n    if (NULL != lstReady)\n      lstReady->Append(wrapper);\n    else\n      libusbemu_deliver_transfer(wrapper);\n  }\n\telse\n\t{\n    // something bad happened:\n    // (a) the timeout passed to usb_reap_async_nocancel() expired;\n    // (b) the transfer was cancelled via usb_cancel_async();\n    // (c) some fatal error triggered.\n#undef EIO\n#undef EINVAL\n#undef ETIMEOUT\n    enum EReapResult { EIO = -5, EINVAL = -22, ETIMEOUT = -116 };\n    switch(read)\n    {\n      // When usb_reap_async_nocancel() returns ETIMEOUT, then either:\n      // (a) the timeout indeed expired;\n      // (b) the transfer was cancelled.\n      case ETIMEOUT :\n        // when usb_reap_async_nocancel() returns ETIMEOUT, then either:\n        // (a) the timeout indeed expired: in this case the transfer should\n        //     remain as the head of the transfer list (do not remove the node)\n        //     and silently return without calling back the client (or perhaps\n        //     set the transfer status to LIBUSB_TRANSFER_TIMED_OUT and then\n        //     call back - MORE INVESTIGATION REQUIRED)\n        // (b) the transfer was cancelled: in this case the transfer should be\n        //     removed from the list and reported back through the callback.\n        if (LIBUSB_TRANSFER_CANCELLED == transfer->status)\n        {\n          libusb_device::TListTransfers::RemoveNode(wrapper);\n          for (int i=0; i<transfer->num_iso_packets; ++i)\n            transfer->iso_packet_desc[i].status = LIBUSB_TRANSFER_CANCELLED;\n          transfer->callback(transfer);\n        }\n        break;\n      case EINVAL :\n        // I guess -22 is returned if one attempts to reap a context that does\n        // not exist anymore (one that has already been deleted)\n        LIBUSBEMU_ERROR_LIBUSBWIN32();\n        break;\n      case EIO :\n        // Error code -5 seems to be triggered when the device is lost...\n        LIBUSBEMU_ERROR_LIBUSBWIN32();\n        libusb_device::TListTransfers::RemoveNode(wrapper);\n        transfer->status = LIBUSB_TRANSFER_NO_DEVICE;\n        transfer->callback(transfer);\n        libusb_cancel_transfer(transfer);\n        transfer->status = LIBUSB_TRANSFER_NO_DEVICE;\n        break;\n      default :\n        // I have not stumbled into any other negative values coming from the\n        // usb_reap_async_nocancel()... Anyway, cancel seems to be a simple yet\n        // plausible preemptive approach... MORE INVESTIGATION NEEDED!\n        LIBUSBEMU_ERROR_LIBUSBWIN32();\n        libusb_cancel_transfer(transfer);\n        break;\n    }\n\t}\n\n  return(read);\n}\n\n// Naive transfer->iso_packet_desc array filler. It will probably never work\n// with any device, but it serves as a template and as a default handler...\nvoid PreprocessTransferNaive(libusb_transfer* transfer, const int read)\n{\n\tunsigned int remaining (read);\n\tconst int pkts (transfer->num_iso_packets);\n\tfor (int i=0; i<pkts; ++i)\n\t{\n\t\tlibusb_iso_packet_descriptor& desc (transfer->iso_packet_desc[i]);\n    desc.status = LIBUSB_TRANSFER_COMPLETED;\n\t\tdesc.actual_length = MIN(remaining, desc.length);\n\t\tremaining -= desc.actual_length;\n\t}\n}\n\n// This is were the transfer->iso_packet_desc array is built. Knowledge of\n// the underlying device stream protocol is required in order to properly\n// setup this array. Moreover, it is also necessary to sneak into some of\n// the libfreenect internals so that the proper length of each iso packet\n// descriptor can be inferred. Fortunately, libfreenect has this information\n// avaliable in the \"transfer->user_data\" field which holds a pointer to a\n// fnusb_isoc_stream struct with all the information required in there.\nvoid PreprocessTransferFreenect(libusb_transfer* transfer, const int read)\n{\n\tfnusb_isoc_stream* xferstrm = (fnusb_isoc_stream*)transfer->user_data;\n\tfreenect_device* dev = xferstrm->parent->parent;\n\tpacket_stream* pktstrm = (transfer->endpoint == 0x81) ? &dev->video : &dev->depth;\n\n\t// Kinect Camera Frame Packet Header (12 bytes total):\n\tstruct pkt_hdr\n\t{\n\t\tuint8_t magic[2];\n\t\tuint8_t pad;\n\t\tuint8_t flag;\n\t\tuint8_t unk1;\n\t\tuint8_t seq;\n\t\tuint8_t unk2;\n\t\tuint8_t unk3;\n\t\tuint32_t timestamp;\n\t};\n\n\t//packet sizes:\n\t//          first  middle  last\n\t// Bayer    1920    1920    24\n\t// IR       1920    1920  1180\n\t// YUV422   1920    1920    36\n\t// Depth    1760    1760  1144\n\tconst unsigned int pktlen = sizeof(pkt_hdr) + pktstrm->pkt_size;\n\tconst unsigned int pktend = sizeof(pkt_hdr) + pktstrm->last_pkt_size;\n\n\tunsigned int remaining (read);\n\tunsigned int leftover (transfer->length);\n\tunsigned char* pktbuffer (transfer->buffer);\n\tconst int pkts (transfer->num_iso_packets);\n\tfor (int i=0; i<pkts; ++i)\n\t{\n\t\tlibusb_iso_packet_descriptor& desc (transfer->iso_packet_desc[i]);\n    desc.status = LIBUSB_TRANSFER_COMPLETED;\n    const pkt_hdr& header (*(pkt_hdr*)pktbuffer);\n\t\tif ((header.magic[0] == 'R') && (header.magic[1] == 'B'))\n\t\t{\n\t\t\tswitch(header.flag & 0x0F)\n\t\t\t{\n\t\t\tcase 0x01 : // first frame packet\n\t\t\tcase 0x02 : // intermediate frame packets\n\t\t\t\tdesc.actual_length = MIN(remaining, pktlen);\n\t\t\t\tbreak;\n\t\t\tcase 0x05 : // last frame packet\n\t\t\t\tdesc.actual_length = MIN(remaining, pktend);\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\tfprintf(stdout, \"0x%02X\\n\", header.flag);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdesc.actual_length = 0;\n\t\t}\n\t\tremaining -= desc.actual_length;\n\t\tpktbuffer += desc.length;   // a.k.a: += 1920\n\t\tleftover  -= desc.length;   // a.k.a: -= 1920\n\t}\n\n  LIBUSB_DEBUG_CMD\n  (\n\t  if (remaining > 0)\n\t  {\n\t\t  fprintf(stdout, \"%d remaining out of %d\\n\", remaining, read);\n\t\t  if (remaining == read)\n        fprintf(stdout, \"no bytes consumed!\\n\");\n\t  }\n  );\n}\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/libusbemu_internal.h",
    "content": "/*\n* This file is part of the OpenKinect Project. http://www.openkinect.org\n*\n* Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n* for details.\n*\n* This code is licensed to you under the terms of the Apache License, version\n* 2.0, or, at your option, the terms of the GNU General Public License,\n* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n* or the following URLs:\n* http://www.apache.org/licenses/LICENSE-2.0\n* http://www.gnu.org/licenses/gpl-2.0.txt\n*\n* If you redistribute this file in source form, modified or unmodified, you\n* may:\n*   1) Leave this header intact and distribute it under the same terms,\n*      accompanying it with the APACHE20 and GPL20 files, or\n*   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n*   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n* In all cases you must keep the copyright notice intact and include a copy\n* of the CONTRIB file.\n*\n* Binary distributions must follow the binary distribution requirements of\n* either License.\n*/\n\n#ifndef LIBUSB_EMULATOR_INTERNAL_H\n#define LIBUSB_EMULATOR_INTERNAL_H\n\n#include \"libusbemu_threads.h\"\n#include <lusb0_usb.h>\n#include <map>\n#include <cassert>\n\nnamespace libusbemu {\n\ntemplate<typename T>\ninline T*& SAFE_DELETE(T*& p)\n{\n  if(NULL != p)\n    delete(p);\n  p = NULL;\n  return(p);\n}\n\ntemplate<typename T>\ninline T MIN(const T& v1, const T& v2)\n{\n  return((v1<v2) ? v1 : v2);\n}\n\ntemplate<typename T>\nstruct QuickList\n{\n\tT ini;\n\tT end;\n\tQuickList()\n\t{\n\t\tmemset(&ini, 0, sizeof(T));\n\t\tmemset(&end, 0, sizeof(T));\n\t\tini.prev = NULL;\n\t\tini.next = &end;\n\t\tend.prev = &ini;\n\t\tend.next = NULL;\n\t}\n  // copy-constructor is required to be safely used as a plain std::map value\n\tQuickList(const QuickList& rhs)\n\t{\n    if (!rhs.Empty())\n    {\n      fprintf(stdout, \"WARNING: Copy-constructin from a non-empty QuickList!\\n\");\n      return;\n    }\n\t\tmemset(&ini, 0, sizeof(T));\n\t\tmemset(&end, 0, sizeof(T));\n\t\tini.prev = NULL;\n\t\tini.next = &end;\n\t\tend.prev = &ini;\n\t\tend.next = NULL;\n\t}\n  ~QuickList() {};\n\tconst bool Empty() const\n\t{\n\t\treturn(ini.next == &end);  // could also be (end.prev == &ini)\n\t}\n\tvoid Append(T* node)\n\t{\n\t\tif (!Orphan(node))\n    {\n      fprintf(stdout, \"WARNING: Appending non-orphan node to list...\\n\");\n      Remove(node);\n    }\n\t\tend.prev->next = node;\n\t\tnode->prev = end.prev;\n\t\tnode->next = &end;\n\t\tend.prev = node;\n    node->list = this;\n\t}\n\tT* Head() const\n\t{\n\t\tT* head (NULL);\n\t\tif (!Empty())\n\t\t\thead = ini.next;\n\t\treturn(head);\n\t}\n\tT* Last() const\n\t{\n\t\tT* last (NULL);\n\t\tif (!Empty())\n\t\t\tlast = end.prev;\n\t\treturn(last);\n\t}\n\tconst bool Member(T* node) const\n\t{\n    return(this == node->list);\n\t}\n\tstatic T* Prev(T* node)\n\t{\n\t\tT* prev (NULL);\n\t\tif (NULL != node->prev->prev)\n\t\t\tprev = node->prev;\n\t\treturn(prev);\n\t}\n\tstatic T* Next(T* node)\n\t{\n\t\tT* next (NULL);\n\t\tif (NULL != node->next->next)\n\t\t\tnext = node->next;\n\t\treturn(next);\n\t}\n  const bool Remove (T* node)\n  {\n    if (!Member(node))\n      return(false);\n\t\tnode->prev->next = node->next;\n\t\tnode->next->prev = node->prev;\n\t\tnode->prev = NULL;\n\t\tnode->next = NULL;\n    node->list = NULL;\n    return(true);\n  }\n\tstatic void RemoveNode(T* node)\n\t{\n\t\tif (Orphan(node))\n\t\t\treturn;\n    node->list->Remove(node);\n\t}\n\tstatic const bool Orphan(T* node)\n\t{\n    return(NULL == node->list);\n\t}\n};\n\ntemplate<typename T>\nstruct QuickListMutexed : QuickList<T>\n{\nprotected:\n  // 'mutable' required to allow operations within 'const methods'\n  mutable QuickMutex mutex;\n  mutable QuickEvent chomp;   // signals whether there is (or not) transfers in the list \n\npublic:\n  QuickListMutexed() {};\n  QuickListMutexed(const QuickListMutexed& rhs) : QuickList<T>(rhs) {};\n  ~QuickListMutexed() { /*this->~QuickListMutexed()*/ mutex.Enter(); mutex.Leave(); };\n\tconst bool Empty() const\n\t{\n\t\tmutex.Enter();\n      const bool empty = QuickList<T>::Empty();\n    mutex.Leave();\n    return(empty);\n\t}\n\tvoid Append(T* node)\n\t{\n    mutex.Enter();\n      const bool empty = QuickList<T>::Empty();\n      QuickList<T>::Append(node);\n      if (empty)\n        chomp.Signal();\n    mutex.Leave();\n\t}\n\tT* Head() const\n\t{\n    mutex.Enter();\n      T* head = QuickList<T>::Head();\n    mutex.Leave();\n    return(head);\n\t}\n\tT* Last() const\n\t{\n    mutex.Enter();\n      T* last = QuickList<T>::Last();\n    mutex.Leave();\n    return(last);\n\t}\n\tconst bool Member(T* node) const\n\t{\n    mutex.Enter();\n      const bool member = QuickList<T>::Member(node);\n    mutex.Leave();\n    return(member);\n\t}\n\tconst bool Remove(T* node)\n\t{\n    mutex.Enter();\n      const bool removed = QuickList<T>::Remove(node);\n      if (QuickList<T>::Empty())\n        chomp.Reset();\n    mutex.Leave();\n    return(removed);\n\t}\n\tstatic const bool Orphan(T* node)\n\t{\n    //node->list->mutex.Enter();\n      const bool orphan = QuickList<T>::Orphan(node);\n    //node->list->mutex.Leave();\n    return(orphan);\n\t}\n\n  const bool WaitUntilTimeout(unsigned int milliseconds) const\n  {\n    return(chomp.WaitUntilTimeout(milliseconds));\n  }\n  void Wait() const\n  {\n    chomp.Wait();\n  }\n  const bool Check() const\n  {\n    return(chomp.Check());\n  }\n};\n\n} // end of 'namespace libusbemu'\n\n\n\nusing namespace libusbemu;\n\nstruct transfer_wrapper\n{\n\ttransfer_wrapper* prev;\n\ttransfer_wrapper* next;\n  QuickList<transfer_wrapper>* list;\n\tvoid* usb;\n\tlibusb_transfer libusb;\n};\n\nstruct libusb_device_handle_t\n{\n\tlibusb_device* dev;\n  usb_dev_handle* handle;\n};\n\nstruct libusb_device_t\n{\n\tlibusb_context* ctx;\n  struct usb_device* device;\n  int refcount;\n  typedef QuickList<transfer_wrapper> TListTransfers;\n  struct isoc_handle\n  {\n    TListTransfers listTransfers;\n    QuickThread* poReapThread;\n  };\n  typedef std::map<int, isoc_handle> TMapIsocTransfers;\n  TMapIsocTransfers* isoTransfers;\n  typedef std::map<usb_dev_handle*, libusb_device_handle> TMapHandles;\n  TMapHandles* handles;\n};\n\nstruct libusb_context_t\n{\n  typedef std::map<struct usb_device*, libusb_device> TMapDevices;\n  TMapDevices devices;\n  QuickMutex mutex;\n\n  QuickMutex mutDeliveryPool;\n  EventList hWantToDeliverPool;\n  EventList hAllowDeliveryPool;\n  EventList hDoneDeliveringPool;\n};\n\n\n\n#define LIBUSBEMU_ERROR(msg) libusbemu_report_error(__FILE__, __LINE__, msg)\n#define LIBUSBEMU_ERROR_LIBUSBWIN32() LIBUSBEMU_ERROR(usb_strerror())\n\nnamespace libusbemu {\n\nvoid libusbemu_report_error(const char* file, const int line, const char* msg)\n{\n  // remove source file path:\n  int i = strlen(file);\n  while (-1 != --i)\n    if ((file[i] == '/') || (file[i] == '\\\\'))\n      break;\n  file = &file[++i];\n\n  fprintf(stderr, \"ERROR in libusbemu -- source file '%s' at line %d -- %s\\n\", file, line, msg);\n}\n\ntransfer_wrapper* libusbemu_get_transfer_wrapper(libusb_transfer* transfer)\n{\n  char* raw_address ((char*)transfer);\n  char* off_address (raw_address - sizeof(void*) - 2*sizeof(transfer_wrapper*) - sizeof(QuickList<transfer_wrapper>*));\n  return((transfer_wrapper*)off_address);\n}\n\nlibusb_device* libusbemu_register_device(libusb_context* ctx, struct usb_device* dev)\n{\n  RAIIMutex lock (ctx->mutex);\n  // register the device (if not already there) ...\n  libusb_device dummy = { ctx, dev, 0, NULL, NULL };\n  libusb_context::TMapDevices::iterator it = ctx->devices.insert(std::make_pair(dev,dummy)).first;\n  // ... and increment the reference count\n  libusb_device& record (it->second);\n  record.refcount++;\n  // might as well do some paranoid checkings...\n  assert(record.ctx == ctx);\n  assert(record.device == dev);\n  return(&(it->second));\n}\n\nvoid libusbemu_unregister_device(libusb_device* dev)\n{\n  libusb_context* ctx (dev->ctx);\n  RAIIMutex lock (ctx->mutex);\n  // decrement the reference count of the device ...\n  --(dev->refcount);\n  // ... and unregister device if the reference count reaches zero\n  if (0 == dev->refcount)\n  {\n    SAFE_DELETE(dev->handles);\n    // prior to device deletion, all of its transfer lists must be deleted\n    if (NULL != dev->isoTransfers)\n    {\n      libusb_device::TMapIsocTransfers& allTransfers (*(dev->isoTransfers));\n      while (!allTransfers.empty())\n      {\n        libusb_device::TMapIsocTransfers::iterator it (allTransfers.begin());\n        libusb_device::TListTransfers& listTransfers (it->second.listTransfers);\n        while (!listTransfers.Empty())\n        {\n          transfer_wrapper* transfer (listTransfers.Head());\n          // make it orphan so that it can be deleted:\n          listTransfers.Remove(transfer);\n          // the following will free the wrapper object as well:\n          libusb_free_transfer(&transfer->libusb);\n        }\n        allTransfers.erase(it);\n      }\n      SAFE_DELETE(dev->isoTransfers);\n    }\n    ctx->devices.erase(dev->device);\n  }\n}\n\nint libusbemu_setup_transfer(transfer_wrapper* wrapper)\n{\n  void*& context = wrapper->usb;\n  // paranoid check...\n  if (NULL != context)\n    return(LIBUSB_ERROR_OTHER);\n\n  RAIIMutex lock (wrapper->libusb.dev_handle->dev->ctx->mutex);\n\n  int ret (LIBUSB_ERROR_OTHER);\n  libusb_transfer* transfer (&wrapper->libusb);\n  usb_dev_handle* handle (transfer->dev_handle->handle);\n  switch(transfer->type)\n  {\n    case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS :\n      ret = usb_isochronous_setup_async(handle, &context, transfer->endpoint, transfer->iso_packet_desc[0].length);\n      break;\n    case LIBUSB_TRANSFER_TYPE_CONTROL :\n      // libusb-0.1 does not actually support asynchronous control transfers, but this should be\n      // very easy to emulate if necessary: just stick the transfer in a special list and then\n      // libusb_handle_events() check if the list is empty or not; if it is not empty, a thread\n      // is created temporarily just to deal with such control transfer requests until the list\n      // becomes eventually empty again and the thread terminates.\n    case LIBUSB_TRANSFER_TYPE_BULK :\n    case LIBUSB_TRANSFER_TYPE_INTERRUPT :\n      // these transfer types are not being used by libfreenect. they should be fairly simple to\n      // emulate with libusb-0.1 since it already provides support for them.\n      // usb_bulk_setup_async(translate(transfer->dev_handle), &context, transfer->endpoint);\n      // usb_interrupt_setup_async(translate(transfer->dev_handle), &context, transfer->endpoint);\n    default :\n      return(LIBUSB_ERROR_INVALID_PARAM);\n  }\n\n  if (ret < 0)\n  {\n    // TODO: better error handling...\n    // what do the functions usb_***_setup_async() actually return on error?\n    LIBUSBEMU_ERROR_LIBUSBWIN32();\n    return(ret);\n  }\n\n  return(LIBUSB_SUCCESS);\n}\n\nvoid libusbemu_clear_transfer(transfer_wrapper* wrapper)\n{\n  libusb_transfer* transfer (&wrapper->libusb);\n  if (transfer->actual_length > 0)\n  {\n    transfer->actual_length = 0;\n    memset(transfer->buffer, 0, transfer->length);\n    for (int i=0; i<transfer->num_iso_packets; ++i)\n      transfer->iso_packet_desc[i].actual_length = 0;\n  }\n}\n\n} // end of 'namespace libusbemu'\n\n#endif//LIBUSB_EMULATOR_INTERNAL_H\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/libusbemu_threads.h",
    "content": "/*\n* This file is part of the OpenKinect Project. http://www.openkinect.org\n*\n* Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n* for details.\n*\n* This code is licensed to you under the terms of the Apache License, version\n* 2.0, or, at your option, the terms of the GNU General Public License,\n* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n* or the following URLs:\n* http://www.apache.org/licenses/LICENSE-2.0\n* http://www.gnu.org/licenses/gpl-2.0.txt\n*\n* If you redistribute this file in source form, modified or unmodified, you\n* may:\n*   1) Leave this header intact and distribute it under the same terms,\n*      accompanying it with the APACHE20 and GPL20 files, or\n*   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n*   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n* In all cases you must keep the copyright notice intact and include a copy\n* of the CONTRIB file.\n*\n* Binary distributions must follow the binary distribution requirements of\n* either License.\n*/\n\n#ifndef LIBUSBEMU_THREAD_INTERFACE_WRAPPER_H\n#define LIBUSBEMU_THREAD_INTERFACE_WRAPPER_H\n\n// Wrappers for platform-specific thread/synchronization objects:\n// * Thread\n// * Mutex  (Critical Section)\n// * Events (Conditional Variables)\n\n#ifdef WIN32\n  // stick to the Windows scheme for now, but this structure could be easily\n  // replaced by pthread for portability; however if real-time priority turns\n  // out to be a requirement on that platform, the pthread implementation may\n  // not have support for such scheduling.\n  // for a much more lightweight run-time, this could be replaced by dummy\n  // objects, provided that the library client is careful enough to avoid any\n  // sort of race-conditions or dead-locks...\n  #include \"libusbemu_threads_win32.h\"\n#else\n  #error LIBUSBEMU PTHREAD WRAPPER NOT YET IMPLEMENTED!\n  // #include \"libusbemu_threads_pthread.h\"\n#endif\n\nnamespace libusbemu\n{\n\nstruct RAIIMutex\n{\n  QuickMutex& m_mutex;\n  RAIIMutex(QuickMutex& mutex) : m_mutex(mutex) { m_mutex.Enter(); }\n  ~RAIIMutex() { m_mutex.Leave(); }\n};\n\n};\n\n#endif//LIBUSBEMU_THREAD_INTERFACE_WRAPPER_H\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/libusb10emu/libusb-1.0/libusbemu_threads_win32.h",
    "content": "/*\n* This file is part of the OpenKinect Project. http://www.openkinect.org\n*\n* Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n* for details.\n*\n* This code is licensed to you under the terms of the Apache License, version\n* 2.0, or, at your option, the terms of the GNU General Public License,\n* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n* or the following URLs:\n* http://www.apache.org/licenses/LICENSE-2.0\n* http://www.gnu.org/licenses/gpl-2.0.txt\n*\n* If you redistribute this file in source form, modified or unmodified, you\n* may:\n*   1) Leave this header intact and distribute it under the same terms,\n*      accompanying it with the APACHE20 and GPL20 files, or\n*   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n*   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n* In all cases you must keep the copyright notice intact and include a copy\n* of the CONTRIB file.\n*\n* Binary distributions must follow the binary distribution requirements of\n* either License.\n*/\n\n#ifndef LIBUSBEMU_THREAD_INTERFACE_WRAPPER_FOR_WIN32_THREADS_H\n#define LIBUSBEMU_THREAD_INTERFACE_WRAPPER_FOR_WIN32_THREADS_H\n\n#include <windows.h>\n#include <stdio.h>\n#include <vector>\n#include <algorithm>\n\nnamespace libusbemu {\n\nstruct QuickEvent\n{\nfriend struct EventList;\n\nprivate:\n  HANDLE hEvent;\n\npublic:\n  inline QuickEvent(const bool signaled=false) : hEvent(NULL)\n  {\n    hEvent = CreateEvent(NULL, TRUE, (BOOL)signaled, NULL);\n  }\n  inline ~QuickEvent()\n  {\n    CloseHandle(hEvent);\n  }\n  inline void Signal()\n  {\n    SetEvent(hEvent);\n  }\n  inline void Reset()\n  {\n    ResetEvent(hEvent);\n  }\n  inline bool Check()\n  {\n    return(WAIT_OBJECT_0 == WaitForSingleObject(hEvent, 0));\n  }\n  inline const bool WaitUntilTimeout(const unsigned int milliseconds)\n  {\n    return(WAIT_OBJECT_0 == WaitForSingleObject(hEvent, (DWORD)milliseconds));\n  }\n  inline void Wait()\n  {\n    WaitUntilTimeout(INFINITE);\n  }\n};\n\n\n\nstruct QuickThread\n{\nprivate:\n  HANDLE hThread;\n\n  // Type-safe wrapper that converts arbitrary function signatures into the\n  // required signature of Win32 Thread Procedures (LPTHREAD_START_ROUTINE).\n  // Any Win32 LPTHREAD_START_ROUTINE declared routine can be wrapped as well.\n  // The wrapper is also capable of cleaning up itself upon thread termination.\n  // This wrapper can be extended in the future to support member-functions\n  // to run as thread procedures.\n  template<typename F>\n  struct ThreadWrapper\n  {\n    struct State\n    {\n      F* routine;\n      void* params;\n      bool release;\n      QuickThread* instance;\n      QuickEvent* sigclone;\n    };\n    static DWORD WINAPI Thunk(LPVOID lpParameter)\n    {\n      State state = *((State*)lpParameter); // clone state (no heap alloc!)\n      state.sigclone->Signal(); // done cloning, signal back to creator\n      state.sigclone = NULL;\n\n      // start wrapped thread procedure\n      DWORD ret = (DWORD)state.routine(state.params);\n\n      // release the associated QuickThread instance if requested\n      if (state.release)\n        delete(state.instance);\n\n      return(ret);\n    }\n  };\n\n  // allow the creation of pseudo-handles to the calling thread\n  // this constructor cannot and should never be called explicitly!\n  // use QuickThread::Myself() to spawn a pseudo-handle QuickThread\n  inline QuickThread() : hThread(GetCurrentThread()) {}\n\npublic:\n  template<typename F>\n  inline QuickThread(F* proc, void* params, const bool auto_release=false) : hThread(NULL)\n  {\n    // the 'typename' is required here because of dependent names...\n    // MSVC relaxes this constraint, but it goes against the standard.\n    typename ThreadWrapper<F>::State state;\n    state.routine  = proc;\n    state.params   = params;\n    state.release  = auto_release;\n    state.instance = this;\n    // in order to prevent heap allocation, an event is created so that the\n    // thunk function can signal back when it is done cloning the state; this\n    // may look like unnecessary overhead, but the less heap memory control,\n    // the better becomes the management and maintenance of this class.\n    QuickEvent hWaitThunkCloneState;\n    state.sigclone = &hWaitThunkCloneState;\n\n    // Ready to issue the thread creation:\n    hThread = CreateThread(NULL, 0, &ThreadWrapper<F>::Thunk, (LPVOID)&state, 0, NULL);\n\n    // Wait for the thread thunk to clone the state...\n    hWaitThunkCloneState.Wait();\n    // Event object will then be automatically released upon return\n  }\n\n  inline ~QuickThread()\n  {\n    // only if not a pseudo-handle...\n    if (hThread == GetCurrentThread())\n      return;\n    CloseHandle(hThread);\n  }\n\n  static inline QuickThread Myself()\n  {\n    return(QuickThread());\n  }\n\n  inline void Join()\n  {\n    WaitForSingleObject(hThread, INFINITE);\n  }\n\n  inline bool TryJoin()\n  {\n    return(WAIT_OBJECT_0 == WaitForSingleObject(hThread, 0));\n  }\n\n  inline bool LowerPriority()\n  {\n    return(TRUE == SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL));\n  }\n\n  inline bool RaisePriority()\n  {\n    return(TRUE == SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL));\n  }\n\n  static inline void Sleep(int milliseconds)\n  {\n    ::Sleep(milliseconds);\n  }\n\n// Yield is already a Win32 macro (WinBase.h)...\n// http://winapi.freetechsecrets.com/win32/WIN32Yield.htm\n#ifdef Yield\n#undef Yield\n#endif\n// A pragma push/pop could be used instead, but it does not solve the issues\n// http://stackoverflow.com/questions/1793800/can-i-redefine-a-c-macro-for-a-few-includes-and-then-define-it-back\n//#pragma push_macro(\"Yield\")\n//#undef Yield\n  static inline void Yield()\n  {\n    // Sleep(0) or Sleep(1) ?!\n    // http://stackoverflow.com/questions/1413630/switchtothread-thread-yield-vs-thread-sleep0-vs-thead-sleep1\n    ::Sleep(1);\n    // could also use the following (but the semantics are quite shady...):\n    // http://msdn.microsoft.com/en-us/library/ms686352(v=vs.85).aspx\n    // SwitchToThread();\n  }\n//#pragma pop_macro(\"Yield\")\n};\n\n\n\nstruct QuickMutex\n{\nprivate:\n  CRITICAL_SECTION cs;\n\npublic:\n  inline QuickMutex()\n  {\n    InitializeCriticalSection(&cs);\n  }\n\n  inline ~QuickMutex()\n  {\n    DeleteCriticalSection(&cs);\n  }\n\n  inline const bool TryEnter()\n  {\n    return(0 != TryEnterCriticalSection(&cs));\n  }\n\n  inline void Enter()\n  {\n    EnterCriticalSection(&cs);\n  }\n\n  inline void Leave()\n  {\n    LeaveCriticalSection(&cs);\n  }\n};\n\n\n\nstruct EventList\n{\n  QuickMutex mutex;\n  std::vector<QuickEvent*> m_vEvents;\n  std::vector<HANDLE> m_vHandles;\n\n  EventList() {};\n  ~EventList() {};\n\n  const bool AttachEvent(QuickEvent* poEvent)\n  {\n    mutex.Enter();\n      m_vEvents.push_back(poEvent);\n      m_vHandles.push_back(poEvent->hEvent);\n    mutex.Leave();\n    return(true);\n  }\n\n  const bool DetachEvent(QuickEvent* poEvent)\n  {\n    mutex.Enter();\n      std::vector<QuickEvent*>::iterator it1 = std::find(m_vEvents.begin(), m_vEvents.end(), poEvent);\n      m_vEvents.erase(it1);\n      std::vector<HANDLE>::iterator it2 = std::find(m_vHandles.begin(), m_vHandles.end(), poEvent->hEvent);\n      m_vHandles.erase(it2);\n    mutex.Leave();\n    return(true);\n  }\n\n  int WaitAnyUntilTimeout(const unsigned int milliseconds)\n  {\n    int index (-1);\n    mutex.Enter();\n      DWORD ret (WAIT_FAILED);\n      const unsigned int nHandles (m_vHandles.size());\n      if (nHandles > 0)\n        ret = WaitForMultipleObjects(nHandles, &m_vHandles[0], FALSE, milliseconds);\n      if (ret - WAIT_OBJECT_0 < nHandles)\n        index = (int)(ret - WAIT_OBJECT_0);\n    mutex.Leave();\n    return(index);\n  }\n\n  int WaitAny()\n  {\n    return(WaitAnyUntilTimeout(INFINITE));\n  }\n\n  int CheckAny()\n  {\n    return(WaitAnyUntilTimeout(0));\n  }\n\n  const bool WaitAllUntilTimeout(const unsigned int milliseconds)\n  {\n    bool waited (false);\n    mutex.Enter();\n      const unsigned int nHandles (m_vHandles.size());\n      if (nHandles > 0)\n        waited = (WAIT_TIMEOUT != WaitForMultipleObjects(nHandles, &m_vHandles[0], FALSE, milliseconds));\n    mutex.Leave();\n    return(waited);\n  }\n\n  const bool WaitAll()\n  {\n    return(WaitAllUntilTimeout(INFINITE));\n  }\n\n  QuickEvent* operator [] (const unsigned int index)\n  {\n    QuickEvent* poEvent (NULL);\n    mutex.Enter();\n      poEvent = m_vEvents[index];\n    mutex.Leave();\n    return(poEvent);\n  }\n\n};\n\n} //end of 'namespace libusbemu'\n\n#endif//LIBUSBEMU_THREAD_INTERFACE_WRAPPER_FOR_WIN32_THREADS_H\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/stdbool.h",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#ifndef _WINDOWS_STDBOOL_EMULATED_H_\n#define _WINDOWS_STDBOOL_EMULATED_H_\n\n#endif//_WINDOWS_STDBOOL_EMULATED_H_\n"
  },
  {
    "path": "libs/libfreenect/platform/windows/unistd.h",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#ifndef _WINDOWS_UNISTD_EMULATED_H_\n#define _WINDOWS_UNISTD_EMULATED_H_\n\n#include <stdint.h>\n\n// MinGW defines _SSIZE_T_ in sys/types.h when it defines ssize_t to be a long.\n// Redefining it causes an error.\n// MSVC does not define this.\n#ifndef _SSIZE_T_\n#define _SSIZE_T_\ntypedef long ssize_t;\n#endif // _SSIZE_T_\n\n#endif//_WINDOWS_UNISTD_EMULATED_H_\n"
  },
  {
    "path": "libs/libfreenect/src/cameras.c",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n\n#include \"freenect_internal.h\"\n#include \"registration.h\"\n#include \"cameras.h\"\n\n#define MAKE_RESERVED(res, fmt) (uint32_t)(((res & 0xff) << 8) | (((fmt & 0xff))))\n#define RESERVED_TO_RESOLUTION(reserved) (freenect_resolution)((reserved >> 8) & 0xff)\n#define RESERVED_TO_FORMAT(reserved) ((reserved) & 0xff)\n\n#define video_mode_count 12\nstatic freenect_frame_mode supported_video_modes[video_mode_count] = {\n\t// reserved, resolution, format, bytes, width, height, data_bits_per_pixel, padding_bits_per_pixel, framerate, is_valid\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH,   FREENECT_VIDEO_RGB), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_RGB}, 1280*1024*3, 1280, 1024, 24, 0, 10, 1 },\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_RGB}, 640*480*3, 640,  480, 24, 0, 30, 1 },\n\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH,   FREENECT_VIDEO_BAYER), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_BAYER}, 1280*1024, 1280, 1024, 8, 0, 10, 1 },\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_BAYER), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_BAYER}, 640*480, 640, 480, 8, 0, 30, 1 },\n\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH,   FREENECT_VIDEO_IR_8BIT), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_IR_8BIT}, 1280*1024, 1280, 1024, 8, 0, 10, 1 },\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_8BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_IR_8BIT}, 640*488, 640, 488, 8, 0, 30, 1 },\n\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH,   FREENECT_VIDEO_IR_10BIT), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_IR_10BIT}, 1280*1024*2, 1280, 1024, 10, 6, 10, 1 },\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_10BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_IR_10BIT}, 640*488*2, 640, 488, 10, 6, 30, 1 },\n\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH,   FREENECT_VIDEO_IR_10BIT_PACKED), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_IR_10BIT_PACKED}, 1280*1024*10/8, 1280, 1024, 10, 0, 10, 1 },\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_10BIT_PACKED), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_IR_10BIT_PACKED}, 640*488*10/8, 640, 488, 10, 0, 30, 1 },\n\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_YUV_RGB), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_YUV_RGB}, 640*480*3, 640, 480, 24, 0, 15, 1 },\n\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_YUV_RAW), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_YUV_RAW}, 640*480*2, 640, 480, 16, 0, 15, 1 },\n};\n\n#define depth_mode_count 6\nstatic freenect_frame_mode supported_depth_modes[depth_mode_count] = {\n\t// reserved, resolution, format, bytes, width, height, data_bits_per_pixel, padding_bits_per_pixel, framerate, is_valid\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_11BIT}, 640*480*2, 640, 480, 11, 5, 30, 1},\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_10BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_10BIT}, 640*480*2, 640, 480, 10, 6, 30, 1},\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT_PACKED), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_11BIT_PACKED}, 640*480*11/8, 640, 480, 11, 0, 30, 1},\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_10BIT_PACKED), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_10BIT_PACKED}, 640*480*10/8, 640, 480, 10, 0, 30, 1},\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_REGISTERED), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_REGISTERED}, 640*480*2, 640, 480, 16, 0, 30, 1},\n\t{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_MM), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_MM}, 640*480*2, 640, 480, 16, 0, 30, 1},\n};\nstatic const freenect_frame_mode invalid_mode = {0, (freenect_resolution)0, {(freenect_video_format)0}, 0, 0, 0, 0, 0, 0, 0};\n\nstruct pkt_hdr {\n\tuint8_t magic[2];\n\tuint8_t pad;\n\tuint8_t flag;\n\tuint8_t unk1;\n\tuint8_t seq;\n\tuint8_t unk2;\n\tuint8_t unk3;\n\tuint32_t timestamp;\n};\n\nstatic int stream_process(freenect_context *ctx, packet_stream *strm, uint8_t *pkt, int len)\n{\n\tif (len < 12)\n\t\treturn 0;\n\n\tstruct pkt_hdr *hdr = (struct pkt_hdr*)pkt;\n\tuint8_t *data = pkt + sizeof(*hdr);\n\tint datalen = len - sizeof(*hdr);\n\n\tfreenect_loglevel l_info = LL_INFO;\n\tfreenect_loglevel l_notice = LL_NOTICE;\n\tfreenect_loglevel l_warning = LL_WARNING;\n\tif (strm->valid_frames < 2)\n\t\tl_info = l_notice = l_warning = LL_SPEW;\n\n\tif (hdr->magic[0] != 'R' || hdr->magic[1] != 'B') {\n\t\tFN_LOG(l_notice, \"[Stream %02x] Invalid magic %02x%02x\\n\",\n\t\t       strm->flag, hdr->magic[0], hdr->magic[1]);\n\t\treturn 0;\n\t}\n\n\tFN_FLOOD(\"[Stream %02x] Packet with flag: %02x\\n\", strm->flag, hdr->flag);\n\n\tuint8_t sof = strm->flag|1;\n\tuint8_t mof = strm->flag|2;\n\tuint8_t eof = strm->flag|5;\n\n\t// sync if required, dropping packets until SOF\n\tif (!strm->synced) {\n\t\tif (hdr->flag != sof) {\n\t\t\tFN_SPEW(\"[Stream %02x] Not synced yet...\\n\", strm->flag);\n\t\t\treturn 0;\n\t\t}\n\t\tstrm->synced = 1;\n\t\tstrm->seq = hdr->seq;\n\t\tstrm->pkt_num = 0;\n\t\tstrm->valid_pkts = 0;\n\t\tstrm->got_pkts = 0;\n\t}\n\n\tint got_frame_size = 0;\n\n\t// handle lost packets\n\tif (strm->seq != hdr->seq) {\n\t\tuint8_t lost = hdr->seq - strm->seq;\n\t\tFN_LOG(l_info, \"[Stream %02x] Lost %d packets\\n\", strm->flag, lost);\n\t\tif (lost > 5 || strm->variable_length) {\n\t\t\tFN_LOG(l_notice, \"[Stream %02x] Lost too many packets, resyncing...\\n\", strm->flag);\n\t\t\tstrm->synced = 0;\n\t\t\treturn 0;\n\t\t}\n\t\tstrm->seq = hdr->seq;\n\t\tint left = strm->pkts_per_frame - strm->pkt_num;\n\t\tif (left <= lost) {\n\t\t\tstrm->pkt_num = lost - left;\n\t\t\tstrm->valid_pkts = strm->got_pkts;\n\t\t\tstrm->got_pkts = 0;\n\t\t\tgot_frame_size = strm->frame_size;\n\t\t\tstrm->timestamp = strm->last_timestamp;\n\t\t\tstrm->valid_frames++;\n\t\t} else {\n\t\t\tstrm->pkt_num += lost;\n\t\t}\n\t}\n\n\tint expected_pkt_size = (strm->pkt_num == strm->pkts_per_frame-1) ? strm->last_pkt_size : strm->pkt_size;\n\n\tif (!strm->variable_length) {\n\t\t// check the header to make sure it's what we expect\n\t\tif (!(strm->pkt_num == 0 && hdr->flag == sof) &&\n\t\t    !(strm->pkt_num == strm->pkts_per_frame-1 && hdr->flag == eof) &&\n\t\t    !(strm->pkt_num > 0 && strm->pkt_num < strm->pkts_per_frame-1 && hdr->flag == mof)) {\n\t\t\tFN_LOG(l_notice, \"[Stream %02x] Inconsistent flag %02x with %d packets in buf (%d total), resyncing...\\n\",\n\t\t\t       strm->flag, hdr->flag, strm->pkt_num, strm->pkts_per_frame);\n\t\t\tstrm->synced = 0;\n\t\t\treturn got_frame_size;\n\t\t}\n\t\t// check data length\n\t\tif (datalen > expected_pkt_size) {\n\t\t\tFN_LOG(l_warning, \"[Stream %02x] Expected max %d data bytes, but got %d. Dropping...\\n\",\n\t\t\t       strm->flag, expected_pkt_size, datalen);\n\t\t\treturn got_frame_size;\n\t\t}\n\t\tif (datalen < expected_pkt_size)\n\t\t\tFN_LOG(l_warning, \"[Stream %02x] Expected %d data bytes, but got %d\\n\",\n\t\t\t       strm->flag, expected_pkt_size, datalen);\n\t} else {\n\t\t// check the header to make sure it's what we expect\n\t\tif (!(strm->pkt_num == 0 && hdr->flag == sof) &&\n\t\t    !(strm->pkt_num < strm->pkts_per_frame && (hdr->flag == eof || hdr->flag == mof))) {\n\t\t\tFN_LOG(l_notice, \"[Stream %02x] Inconsistent flag %02x with %d packets in buf (%d total), resyncing...\\n\",\n\t\t\t       strm->flag, hdr->flag, strm->pkt_num, strm->pkts_per_frame);\n\t\t\tstrm->synced = 0;\n\t\t\treturn got_frame_size;\n\t\t}\n\t\t// check data length\n\t\tif (datalen > expected_pkt_size) {\n\t\t\tFN_LOG(l_warning, \"[Stream %02x] Expected max %d data bytes, but got %d. Resyncng...\\n\",\n\t\t\t       strm->flag, expected_pkt_size, datalen);\n\t\t\tstrm->synced = 0;\n\t\t\treturn got_frame_size;\n\t\t}\n\t\tif (datalen < expected_pkt_size && hdr->flag != eof) {\n\t\t\tFN_LOG(l_warning, \"[Stream %02x] Expected %d data bytes, but got %d. Resyncing...\\n\",\n\t\t\t       strm->flag, expected_pkt_size, datalen);\n\t\t\tstrm->synced = 0;\n\t\t\treturn got_frame_size;\n\t\t}\n\t}\n\n\t// copy data\n\tuint8_t *dbuf = strm->raw_buf + strm->pkt_num * strm->pkt_size;\n\tmemcpy(dbuf, data, datalen);\n\n\tstrm->pkt_num++;\n\tstrm->seq++;\n\tstrm->got_pkts++;\n\n\tstrm->last_timestamp = fn_le32(hdr->timestamp);\n\n\tif (hdr->flag == eof) {\n\t\tif (strm->variable_length)\n\t\t\tgot_frame_size = (dbuf - strm->raw_buf) + datalen;\n\t\telse\n\t\t\tgot_frame_size = (dbuf - strm->raw_buf) + strm->last_pkt_size;\n\t\tstrm->pkt_num = 0;\n\t\tstrm->valid_pkts = strm->got_pkts;\n\t\tstrm->got_pkts = 0;\n\t\tstrm->timestamp = strm->last_timestamp;\n\t\tstrm->valid_frames++;\n\t}\n\treturn got_frame_size;\n}\n\nstatic void stream_init(freenect_context *ctx, packet_stream *strm, int rlen, int plen)\n{\n\tstrm->valid_frames = 0;\n\tstrm->synced = 0;\n\n\tif (strm->usr_buf) {\n\t\tstrm->lib_buf = NULL;\n\t\tstrm->proc_buf = strm->usr_buf;\n\t} else {\n\t\tstrm->lib_buf = malloc(plen);\n\t\tstrm->proc_buf = strm->lib_buf;\n\t}\n\n\tif (rlen == 0) {\n\t\tstrm->split_bufs = 0;\n\t\tstrm->raw_buf = (uint8_t*)strm->proc_buf;\n\t\tstrm->frame_size = plen;\n\t} else {\n\t\tstrm->split_bufs = 1;\n\t\tstrm->raw_buf = (uint8_t*)malloc(rlen);\n\t\tstrm->frame_size = rlen;\n\t}\n\n\tstrm->last_pkt_size = strm->frame_size % strm->pkt_size;\n\tif (strm->last_pkt_size == 0)\n\t\tstrm->last_pkt_size = strm->pkt_size;\n\tstrm->pkts_per_frame = (strm->frame_size + strm->pkt_size - 1) / strm->pkt_size;\n}\n\nstatic void stream_freebufs(freenect_context *ctx, packet_stream *strm)\n{\n\tif (strm->split_bufs)\n\t\tfree(strm->raw_buf);\n\tif (strm->lib_buf)\n\t\tfree(strm->lib_buf);\n\n\tstrm->raw_buf = NULL;\n\tstrm->proc_buf = NULL;\n\tstrm->lib_buf = NULL;\n}\n\nstatic int stream_setbuf(freenect_context *ctx, packet_stream *strm, void *pbuf)\n{\n\tif (!strm->running) {\n\t\tstrm->usr_buf = pbuf;\n\t\treturn 0;\n\t} else {\n\t\tif (!pbuf && !strm->lib_buf) {\n\t\t\tFN_ERROR(\"Attempted to set buffer to NULL but stream was started with no internal buffer\\n\");\n\t\t\treturn -1;\n\t\t}\n\t\tstrm->usr_buf = pbuf;\n\n\t\tif (!pbuf)\n\t\t\tstrm->proc_buf = strm->lib_buf;\n\t\telse\n\t\t\tstrm->proc_buf = pbuf;\n\n\t\tif (!strm->split_bufs)\n\t\t\tstrm->raw_buf = (uint8_t*)strm->proc_buf;\n\t\treturn 0;\n\t}\n}\n\n/**\n * Convert a packed array of n elements with vw useful bits into array of\n * zero-padded 16bit elements.\n *\n * @param src The source packed array, of size (n * vw / 8) bytes\n * @param dest The destination unpacked array, of size (n * 2) bytes\n * @param vw The virtual width of elements, that is the number of useful bits for each of them\n * @param n The number of elements (in particular, of the destination array), NOT a length in bytes\n */\nstatic inline void convert_packed_to_16bit(uint8_t *src, uint16_t *dest, int vw, int n)\n{\n\tunsigned int mask = (1 << vw) - 1;\n\tuint32_t buffer = 0;\n\tint bitsIn = 0;\n\twhile (n--) {\n\t\twhile (bitsIn < vw) {\n\t\t\tbuffer = (buffer << 8) | *(src++);\n\t\t\tbitsIn += 8;\n\t\t}\n\t\tbitsIn -= vw;\n\t\t*(dest++) = (buffer >> bitsIn) & mask;\n\t}\n}\n\n/**\n * Convert a packed array of n elements with vw useful bits into array of\n * 8bit elements, dropping LSB.\n *\n * @param src The source packed array, of size (n * vw / 8) bytes\n * @param dest The destination unpacked array, of size (n * 2) bytes\n * @param vw The virtual width of elements, that is the number of useful bits for each of them\n * @param n The number of elements (in particular, of the destination array), NOT a length in bytes\n *\n * @pre vw is expected to be >= 8.\n */\nstatic inline void convert_packed_to_8bit(uint8_t *src, uint8_t *dest, int vw, int n)\n{\n\tuint32_t buffer = 0;\n\tint bitsIn = 0;\n\twhile (n--) {\n\t\twhile (bitsIn < vw) {\n\t\t\tbuffer = (buffer << 8) | *(src++);\n\t\t\tbitsIn += 8;\n\t\t}\n\t\tbitsIn -= vw;\n\t\t*(dest++) = buffer >> (bitsIn + vw - 8);\n\t}\n}\n\n// Loop-unrolled version of the 11-to-16 bit unpacker.  n must be a multiple of 8.\nstatic void convert_packed11_to_16bit(uint8_t *raw, uint16_t *frame, int n)\n{\n\tuint16_t baseMask = (1 << 11) - 1;\n\twhile(n >= 8)\n\t{\n\t\tuint8_t r0  = *(raw+0);\n\t\tuint8_t r1  = *(raw+1);\n\t\tuint8_t r2  = *(raw+2);\n\t\tuint8_t r3  = *(raw+3);\n\t\tuint8_t r4  = *(raw+4);\n\t\tuint8_t r5  = *(raw+5);\n\t\tuint8_t r6  = *(raw+6);\n\t\tuint8_t r7  = *(raw+7);\n\t\tuint8_t r8  = *(raw+8);\n\t\tuint8_t r9  = *(raw+9);\n\t\tuint8_t r10 = *(raw+10);\n\n\t\tframe[0] =  (r0<<3)  | (r1>>5);\n\t\tframe[1] = ((r1<<6)  | (r2>>2) )           & baseMask;\n\t\tframe[2] = ((r2<<9)  | (r3<<1) | (r4>>7) ) & baseMask;\n\t\tframe[3] = ((r4<<4)  | (r5>>4) )           & baseMask;\n\t\tframe[4] = ((r5<<7)  | (r6>>1) )           & baseMask;\n\t\tframe[5] = ((r6<<10) | (r7<<2) | (r8>>6) ) & baseMask;\n\t\tframe[6] = ((r8<<5)  | (r9>>3) )           & baseMask;\n\t\tframe[7] = ((r9<<8)  | (r10)   )           & baseMask;\n\n\t\tn -= 8;\n\t\traw += 11;\n\t\tframe += 8;\n\t}\n}\n\nstatic void depth_process(freenect_device *dev, uint8_t *pkt, int len)\n{\n\tfreenect_context *ctx = dev->parent;\n\n\tif (len == 0)\n\t\treturn;\n\n\tif (!dev->depth.running)\n\t\treturn;\n\n\tint got_frame_size = stream_process(ctx, &dev->depth, pkt, len);\n\n\tif (!got_frame_size)\n\t\treturn;\n\n\tFN_SPEW(\"Got depth frame of size %d/%d, %d/%d packets arrived, TS %08x\\n\", got_frame_size,\n\t        dev->depth.frame_size, dev->depth.valid_pkts, dev->depth.pkts_per_frame, dev->depth.timestamp);\n\n\tswitch (dev->depth_format) {\n\t\tcase FREENECT_DEPTH_11BIT:\n\t\t\tconvert_packed11_to_16bit(dev->depth.raw_buf, (uint16_t*)dev->depth.proc_buf, 640*480);\n\t\t\tbreak;\n\t\tcase FREENECT_DEPTH_REGISTERED:\n\t\t\tfreenect_apply_registration(dev, dev->depth.raw_buf, (uint16_t*)dev->depth.proc_buf );\n\t\t\tbreak;\n\t\tcase FREENECT_DEPTH_MM:\n\t\t\tfreenect_apply_depth_to_mm(dev, dev->depth.raw_buf, (uint16_t*)dev->depth.proc_buf );\n\t\t\tbreak;\n\t\tcase FREENECT_DEPTH_10BIT:\n\t\t\tconvert_packed_to_16bit(dev->depth.raw_buf, (uint16_t*)dev->depth.proc_buf, 10, 640*480);\n\t\t\tbreak;\n\t\tcase FREENECT_DEPTH_10BIT_PACKED:\n\t\tcase FREENECT_DEPTH_11BIT_PACKED:\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tFN_ERROR(\"depth_process() was called, but an invalid depth_format is set\\n\");\n\t\t\tbreak;\n\t}\n\tif (dev->depth_cb)\n\t\tdev->depth_cb(dev, dev->depth.proc_buf, dev->depth.timestamp);\n}\n\n#define CLAMP(x) if (x < 0) {x = 0;} if (x > 255) {x = 255;}\nstatic void convert_uyvy_to_rgb(uint8_t *raw_buf, uint8_t *proc_buf, freenect_frame_mode frame_mode)\n{\n\tint x, y;\n\tfor(y = 0; y < frame_mode.height; ++y) {\n\t\tfor(x = 0; x < frame_mode.width; x+=2) {\n\t\t\tint i = (frame_mode.width * y + x);\n\t\t\tint u  = raw_buf[2*i];\n\t\t\tint y1 = raw_buf[2*i+1];\n\t\t\tint v  = raw_buf[2*i+2];\n\t\t\tint y2 = raw_buf[2*i+3];\n\t\t\tint r1 = (y1-16)*1164/1000 + (v-128)*1596/1000;\n\t\t\tint g1 = (y1-16)*1164/1000 - (v-128)*813/1000 - (u-128)*391/1000;\n\t\t\tint b1 = (y1-16)*1164/1000 + (u-128)*2018/1000;\n\t\t\tint r2 = (y2-16)*1164/1000 + (v-128)*1596/1000;\n\t\t\tint g2 = (y2-16)*1164/1000 - (v-128)*813/1000 - (u-128)*391/1000;\n\t\t\tint b2 = (y2-16)*1164/1000 + (u-128)*2018/1000;\n\t\t\tCLAMP(r1)\n\t\t\tCLAMP(g1)\n\t\t\tCLAMP(b1)\n\t\t\tCLAMP(r2)\n\t\t\tCLAMP(g2)\n\t\t\tCLAMP(b2)\n\t\t\tproc_buf[3*i]  =r1;\n\t\t\tproc_buf[3*i+1]=g1;\n\t\t\tproc_buf[3*i+2]=b1;\n\t\t\tproc_buf[3*i+3]=r2;\n\t\t\tproc_buf[3*i+4]=g2;\n\t\t\tproc_buf[3*i+5]=b2;\n\t\t}\n\t}\n}\n#undef CLAMP\n\nstatic void convert_bayer_to_rgb(uint8_t *raw_buf, uint8_t *proc_buf, freenect_frame_mode frame_mode)\n{\n\tint x,y;\n\t/* Pixel arrangement:\n\t * G R G R G R G R\n\t * B G B G B G B G\n\t * G R G R G R G R\n\t * B G B G B G B G\n\t * G R G R G R G R\n\t * B G B G B G B G\n\t *\n\t * To convert a Bayer-pattern into RGB you have to handle four pattern\n\t * configurations:\n\t * 1)         2)         3)         4)\n\t *      B1      B1 G1 B2   R1 G1 R2      R1       <- previous line\n\t *   R1 G1 R2   G2 R1 G3   G2 B1 G3   B1 G1 B2    <- current line\n\t *      B2      B3 G4 B4   R3 G4 R4      R2       <- next line\n\t *   ^  ^  ^\n\t *   |  |  next pixel\n\t *   |  current pixel\n\t *   previous pixel\n\t *\n\t * The RGB values (r,g,b) for each configuration are calculated as\n\t * follows:\n\t *\n\t * 1) r = (R1 + R2) / 2\n\t *    g =  G1\n\t *    b = (B1 + B2) / 2\n\t *\n\t * 2) r =  R1\n\t *    g = (G1 + G2 + G3 + G4) / 4\n\t *    b = (B1 + B2 + B3 + B4) / 4\n\t *\n\t * 3) r = (R1 + R2 + R3 + R4) / 4\n\t *    g = (G1 + G2 + G3 + G4) / 4\n\t *    b =  B1\n\t *\n\t * 4) r = (R1 + R2) / 2\n\t *    g =  G1\n\t *    b = (B1 + B2) / 2\n\t *\n\t * To efficiently calculate these values, two 32bit integers are used\n\t * as \"shift-buffers\". One integer to store the 3 horizontal bayer pixel\n\t * values (previous, current, next) of the current line. The other\n\t * integer to store the vertical average value of the bayer pixels\n\t * (previous, current, next) of the previous and next line.\n\t *\n\t * The boundary conditions for the first and last line and the first\n\t * and last column are solved via mirroring the second and second last\n\t * line and the second and second last column.\n\t *\n\t * To reduce slow memory access, the values of a rgb pixel are packet\n\t * into a 32bit variable and transfered together.\n\t */\n\n\tuint8_t *dst = proc_buf; // pointer to destination\n\n\tuint8_t *prevLine;        // pointer to previous, current and next line\n\tuint8_t *curLine;         // of the source bayer pattern\n\tuint8_t *nextLine;\n\n\t// storing horizontal values in hVals:\n\t// previous << 16, current << 8, next\n\tuint32_t hVals;\n\t// storing vertical averages in vSums:\n\t// previous << 16, current << 8, next\n\tuint32_t vSums;\n\n\t// init curLine and nextLine pointers\n\tcurLine  = raw_buf;\n\tnextLine = curLine + frame_mode.width;\n\tfor (y = 0; y < frame_mode.height; ++y) {\n\n\t\tif ((y > 0) && (y < frame_mode.height-1))\n\t\t\tprevLine = curLine - frame_mode.width; // normal case\n\t\telse if (y == 0)\n\t\t\tprevLine = nextLine;      // top boundary case\n\t\telse\n\t\t\tnextLine = prevLine;      // bottom boundary case\n\n\t\t// init horizontal shift-buffer with current value\n\t\thVals  = (*(curLine++) << 8);\n\t\t// handle left column boundary case\n\t\thVals |= (*curLine << 16);\n\t\t// init vertical average shift-buffer with current values average\n\t\tvSums = ((*(prevLine++) + *(nextLine++)) << 7) & 0xFF00;\n\t\t// handle left column boundary case\n\t\tvSums |= ((*prevLine + *nextLine) << 15) & 0xFF0000;\n\n\t\t// store if line is odd or not\n\t\tuint8_t yOdd = y & 1;\n\t\t// the right column boundary case is not handled inside this loop\n\t\t// thus the \"639\"\n\t\tfor (x = 0; x < frame_mode.width-1; ++x) {\n\t\t\t// place next value in shift buffers\n\t\t\thVals |= *(curLine++);\n\t\t\tvSums |= (*(prevLine++) + *(nextLine++)) >> 1;\n\n\t\t\t// calculate the horizontal sum as this sum is needed in\n\t\t\t// any configuration\n\t\t\tuint8_t hSum = ((uint8_t)(hVals >> 16) + (uint8_t)(hVals)) >> 1;\n\n\t\t\tif (yOdd == 0) {\n\t\t\t\tif ((x & 1) == 0) {\n\t\t\t\t\t// Configuration 1\n\t\t\t\t\t*(dst++) = hSum;\t\t// r\n\t\t\t\t\t*(dst++) = hVals >> 8;\t// g\n\t\t\t\t\t*(dst++) = vSums >> 8;\t// b\n\t\t\t\t} else {\n\t\t\t\t\t// Configuration 2\n\t\t\t\t\t*(dst++) = hVals >> 8;\n\t\t\t\t\t*(dst++) = (hSum + (uint8_t)(vSums >> 8)) >> 1;\n\t\t\t\t\t*(dst++) = ((uint8_t)(vSums >> 16) + (uint8_t)(vSums)) >> 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif ((x & 1) == 0) {\n\t\t\t\t\t// Configuration 3\n\t\t\t\t\t*(dst++) = ((uint8_t)(vSums >> 16) + (uint8_t)(vSums)) >> 1;\n\t\t\t\t\t*(dst++) = (hSum + (uint8_t)(vSums >> 8)) >> 1;\n\t\t\t\t\t*(dst++) = hVals >> 8;\n\t\t\t\t} else {\n\t\t\t\t\t// Configuration 4\n\t\t\t\t\t*(dst++) = vSums >> 8;\n\t\t\t\t\t*(dst++) = hVals >> 8;\n\t\t\t\t\t*(dst++) = hSum;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// shift the shift-buffers\n\t\t\thVals <<= 8;\n\t\t\tvSums <<= 8;\n\t\t} // end of for x loop\n\t\t// right column boundary case, mirroring second last column\n\t\thVals |= (uint8_t)(hVals >> 16);\n\t\tvSums |= (uint8_t)(vSums >> 16);\n\n\t\t// the horizontal sum simplifies to the second last column value\n\t\tuint8_t hSum = (uint8_t)(hVals);\n\n\t\tif (yOdd == 0) {\n\t\t\tif ((x & 1) == 0) {\n\t\t\t\t*(dst++) = hSum;\n\t\t\t\t*(dst++) = hVals >> 8;\n\t\t\t\t*(dst++) = vSums >> 8;\n\t\t\t} else {\n\t\t\t\t*(dst++) = hVals >> 8;\n\t\t\t\t*(dst++) = (hSum + (uint8_t)(vSums >> 8)) >> 1;\n\t\t\t\t*(dst++) = vSums;\n\t\t\t}\n\t\t} else {\n\t\t\tif ((x & 1) == 0) {\n\t\t\t\t*(dst++) = vSums;\n\t\t\t\t*(dst++) = (hSum + (uint8_t)(vSums >> 8)) >> 1;\n\t\t\t\t*(dst++) = hVals >> 8;\n\t\t\t} else {\n\t\t\t\t*(dst++) = vSums >> 8;\n\t\t\t\t*(dst++) = hVals >> 8;\n\t\t\t\t*(dst++) = hSum;\n\t\t\t}\n\t\t}\n\n\t} // end of for y loop\n}\n\nstatic void video_process(freenect_device *dev, uint8_t *pkt, int len)\n{\n\tfreenect_context *ctx = dev->parent;\n\n\tif (len == 0)\n\t\treturn;\n\n\tif (!dev->video.running)\n\t\treturn;\n\n\tint got_frame_size = stream_process(ctx, &dev->video, pkt, len);\n\n\tif (!got_frame_size)\n\t\treturn;\n\n\tFN_SPEW(\"Got video frame of size %d/%d, %d/%d packets arrived, TS %08x\\n\", got_frame_size,\n\t        dev->video.frame_size, dev->video.valid_pkts, dev->video.pkts_per_frame, dev->video.timestamp);\n\n\tfreenect_frame_mode frame_mode = freenect_get_current_video_mode(dev);\n\tswitch (dev->video_format) {\n\t\tcase FREENECT_VIDEO_RGB:\n\t\t\tconvert_bayer_to_rgb(dev->video.raw_buf, (uint8_t*)dev->video.proc_buf, frame_mode);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_BAYER:\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_IR_10BIT:\n\t\t\tconvert_packed_to_16bit(dev->video.raw_buf, (uint16_t*)dev->video.proc_buf, 10, frame_mode.width * frame_mode.height);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_IR_10BIT_PACKED:\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_IR_8BIT:\n\t\t\tconvert_packed_to_8bit(dev->video.raw_buf, (uint8_t*)dev->video.proc_buf, 10, frame_mode.width * frame_mode.height);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_YUV_RGB:\n\t\t\tconvert_uyvy_to_rgb(dev->video.raw_buf, (uint8_t*)dev->video.proc_buf, frame_mode);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_YUV_RAW:\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tFN_ERROR(\"video_process() was called, but an invalid video_format is set\\n\");\n\t\t\tbreak;\n\t}\n\n\tif (dev->video_cb)\n\t\tdev->video_cb(dev, dev->video.proc_buf, dev->video.timestamp);\n}\n\ntypedef struct {\n\tuint8_t magic[2];\n\tuint16_t len;\n\tuint16_t cmd;\n\tuint16_t tag;\n} cam_hdr;\n\nstatic int send_cmd(freenect_device *dev, uint16_t cmd, void *cmdbuf, unsigned int cmd_len, void *replybuf, int reply_len)\n{\n\tfreenect_context *ctx = dev->parent;\n\tint res, actual_len;\n\tuint8_t obuf[0x400];\n\tuint8_t ibuf[0x200];\n\tcam_hdr *chdr = (cam_hdr*)obuf;\n\tcam_hdr *rhdr = (cam_hdr*)ibuf;\n\n\tif (cmd_len & 1 || cmd_len > (0x400 - sizeof(*chdr))) {\n\t\tFN_ERROR(\"send_cmd: Invalid command length (0x%x)\\n\", cmd_len);\n\t\treturn -1;\n\t}\n\n\tchdr->magic[0] = 0x47;\n\tchdr->magic[1] = 0x4d;\n\tchdr->cmd = fn_le16(cmd);\n\tchdr->tag = fn_le16(dev->cam_tag);\n\tchdr->len = fn_le16(cmd_len / 2);\n\n\tmemcpy(obuf+sizeof(*chdr), cmdbuf, cmd_len);\n\n\tres = fnusb_control(&dev->usb_cam, 0x40, 0, 0, 0, obuf, cmd_len + sizeof(*chdr));\n\tFN_SPEW(\"Control cmd=%04x tag=%04x len=%04x: %d\\n\", cmd, dev->cam_tag, cmd_len, res);\n\tif (res < 0) {\n\t\tFN_ERROR(\"send_cmd: Output control transfer failed (%d)\\n\", res);\n\t\treturn res;\n\t}\n\n\tdo {\n\t\tactual_len = fnusb_control(&dev->usb_cam, 0xc0, 0, 0, 0, ibuf, 0x200);\n\t\tFN_FLOOD(\"actual_len: %d\\n\", actual_len);\n\t} while ((actual_len == 0) || (actual_len == 0x200));\n\tFN_SPEW(\"Control reply: %d\\n\", res);\n\tif (actual_len < (int)sizeof(*rhdr)) {\n\t\tFN_ERROR(\"send_cmd: Input control transfer failed (%d)\\n\", res);\n\t\treturn res;\n\t}\n\tactual_len -= sizeof(*rhdr);\n\n\tif (rhdr->magic[0] != 0x52 || rhdr->magic[1] != 0x42) {\n\t\tFN_ERROR(\"send_cmd: Bad magic %02x %02x\\n\", rhdr->magic[0], rhdr->magic[1]);\n\t\treturn -1;\n\t}\n\tif (rhdr->cmd != chdr->cmd) {\n\t\tFN_ERROR(\"send_cmd: Bad cmd %02x != %02x\\n\", rhdr->cmd, chdr->cmd);\n\t\treturn -1;\n\t}\n\tif (rhdr->tag != chdr->tag) {\n\t\tFN_ERROR(\"send_cmd: Bad tag %04x != %04x\\n\", rhdr->tag, chdr->tag);\n\t\treturn -1;\n\t}\n\tif (fn_le16(rhdr->len) != (actual_len/2)) {\n\t\tFN_ERROR(\"send_cmd: Bad len %04x != %04x\\n\", fn_le16(rhdr->len), (int)(actual_len/2));\n\t\treturn -1;\n\t}\n\n\tif (actual_len > reply_len) {\n\t\tFN_WARNING(\"send_cmd: Data buffer is %d bytes long, but got %d bytes\\n\", reply_len, actual_len);\n\t\tmemcpy(replybuf, ibuf+sizeof(*rhdr), reply_len);\n\t} else {\n\t\tmemcpy(replybuf, ibuf+sizeof(*rhdr), actual_len);\n\t}\n\n\tdev->cam_tag++;\n\n\treturn actual_len;\n}\n\nstatic int write_register(freenect_device *dev, uint16_t reg, uint16_t data)\n{\n\tfreenect_context *ctx = dev->parent;\n\tuint16_t reply[2];\n\tuint16_t cmd[2];\n\tint res;\n\n\tcmd[0] = fn_le16(reg);\n\tcmd[1] = fn_le16(data);\n\n\tFN_DEBUG(\"Write Reg 0x%04x <= 0x%02x\\n\", reg, data);\n\tres = send_cmd(dev, 0x03, cmd, 4, reply, 4);\n\tif (res < 0)\n\t\treturn res;\n\tif (res != 2) {\n\t\tFN_WARNING(\"send_cmd returned %d [%04x %04x], 0000 expected\\n\", res, reply[0], reply[1]);\n\t}\n\treturn 0;\n}\n\n// This function is here for completeness.  We don't actually use it for anything right now.\nstatic uint16_t read_register(freenect_device *dev, uint16_t reg)\n{\n\tfreenect_context *ctx = dev->parent;\n\tuint16_t reply[2];\n\tuint16_t cmd;\n\tint res;\n\n\tcmd = fn_le16(reg);\n\n\tFN_DEBUG(\"Read Reg 0x%04x =>\\n\", reg);\n\tres = send_cmd(dev, 0x02, &cmd, 2, reply, 4);\n\tif (res < 0)\n\t\tFN_ERROR(\"read_register: send_cmd() failed: %d\\n\", res);\n\tif (res != 4)\n\t\tFN_WARNING(\"send_cmd returned %d [%04x %04x], 0000 expected\\n\", res, reply[0], reply[1]);\n\n\treturn reply[1];\n}\n\nstatic int freenect_fetch_reg_info(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tchar reply[0x200];\n\tuint16_t cmd[5];\n\tfreenect_frame_mode mode = freenect_get_current_video_mode(dev);\n\tcmd[0] = fn_le16(0x40); // ParamID - in this scenario, XN_HOST_PROTOCOL_ALGORITHM_REGISTRATION\n\tcmd[1] = fn_le16(0); // Format\n\tcmd[2] = fn_le16((uint16_t)mode.resolution); // Resolution\n\tcmd[3] = fn_le16((uint16_t)mode.framerate); // FPS\n\tcmd[4] = fn_le16(0); // Offset\n\n\tint res;\n\tres = send_cmd(dev, 0x16, cmd, 10, reply, 118); // OPCODE_ALGORITHM_PARAMS\n\tif(res != 118) {\n\t\tFN_ERROR(\"freenect_fetch_reg_info: send_cmd read %d bytes (expected 118)\\n\", res);\n\t\treturn -1;\n\t}\n\tmemcpy(&dev->registration.reg_info, reply + 2, sizeof(dev->registration.reg_info));\n\tdev->registration.reg_info.ax            = fn_le32s(dev->registration.reg_info.ax);\n\tdev->registration.reg_info.bx            = fn_le32s(dev->registration.reg_info.bx);\n\tdev->registration.reg_info.cx            = fn_le32s(dev->registration.reg_info.cx);\n\tdev->registration.reg_info.dx            = fn_le32s(dev->registration.reg_info.dx);\n\tdev->registration.reg_info.ay            = fn_le32s(dev->registration.reg_info.ay);\n\tdev->registration.reg_info.by            = fn_le32s(dev->registration.reg_info.by);\n\tdev->registration.reg_info.cy            = fn_le32s(dev->registration.reg_info.cy);\n\tdev->registration.reg_info.dy            = fn_le32s(dev->registration.reg_info.dy);\n\tdev->registration.reg_info.dx_start      = fn_le32s(dev->registration.reg_info.dx_start);\n\tdev->registration.reg_info.dy_start      = fn_le32s(dev->registration.reg_info.dy_start);\n\tdev->registration.reg_info.dx_beta_start = fn_le32s(dev->registration.reg_info.dx_beta_start);\n\tdev->registration.reg_info.dy_beta_start = fn_le32s(dev->registration.reg_info.dy_beta_start);\n\tdev->registration.reg_info.dx_beta_inc   = fn_le32s(dev->registration.reg_info.dx_beta_inc);\n\tdev->registration.reg_info.dy_beta_inc   = fn_le32s(dev->registration.reg_info.dy_beta_inc);\n\tdev->registration.reg_info.dxdx_start    = fn_le32s(dev->registration.reg_info.dxdx_start);\n\tdev->registration.reg_info.dxdy_start    = fn_le32s(dev->registration.reg_info.dxdy_start);\n\tdev->registration.reg_info.dydx_start    = fn_le32s(dev->registration.reg_info.dydx_start);\n\tdev->registration.reg_info.dydy_start    = fn_le32s(dev->registration.reg_info.dydy_start);\n\tdev->registration.reg_info.dxdxdx_start  = fn_le32s(dev->registration.reg_info.dxdxdx_start);\n\tdev->registration.reg_info.dydxdx_start  = fn_le32s(dev->registration.reg_info.dydxdx_start);\n\tdev->registration.reg_info.dxdxdy_start  = fn_le32s(dev->registration.reg_info.dxdxdy_start);\n\tdev->registration.reg_info.dydxdy_start  = fn_le32s(dev->registration.reg_info.dydxdy_start);\n\tdev->registration.reg_info.dydydx_start  = fn_le32s(dev->registration.reg_info.dydydx_start);\n\tdev->registration.reg_info.dydydy_start  = fn_le32s(dev->registration.reg_info.dydydy_start);\n\tFN_SPEW(\"ax:                %d\\n\", dev->registration.reg_info.ax);\n\tFN_SPEW(\"bx:                %d\\n\", dev->registration.reg_info.bx);\n\tFN_SPEW(\"cx:                %d\\n\", dev->registration.reg_info.cx);\n\tFN_SPEW(\"dx:                %d\\n\", dev->registration.reg_info.dx);\n\tFN_SPEW(\"ay:                %d\\n\", dev->registration.reg_info.ay);\n\tFN_SPEW(\"by:                %d\\n\", dev->registration.reg_info.by);\n\tFN_SPEW(\"cy:                %d\\n\", dev->registration.reg_info.cy);\n\tFN_SPEW(\"dy:                %d\\n\", dev->registration.reg_info.dy);\n\tFN_SPEW(\"dx_start:          %d\\n\", dev->registration.reg_info.dx_start);\n\tFN_SPEW(\"dy_start:          %d\\n\", dev->registration.reg_info.dy_start);\n\tFN_SPEW(\"dx_beta_start:     %d\\n\", dev->registration.reg_info.dx_beta_start);\n\tFN_SPEW(\"dy_beta_start:     %d\\n\", dev->registration.reg_info.dy_beta_start);\n\tFN_SPEW(\"dx_beta_inc:       %d\\n\", dev->registration.reg_info.dx_beta_inc);\n\tFN_SPEW(\"dy_beta_inc:       %d\\n\", dev->registration.reg_info.dy_beta_inc);\n\tFN_SPEW(\"dxdx_start:        %d\\n\", dev->registration.reg_info.dxdx_start);\n\tFN_SPEW(\"dxdy_start:        %d\\n\", dev->registration.reg_info.dxdy_start);\n\tFN_SPEW(\"dydx_start:        %d\\n\", dev->registration.reg_info.dydx_start);\n\tFN_SPEW(\"dydy_start:        %d\\n\", dev->registration.reg_info.dydy_start);\n\tFN_SPEW(\"dxdxdx_start:      %d\\n\", dev->registration.reg_info.dxdxdx_start);\n\tFN_SPEW(\"dydxdx_start:      %d\\n\", dev->registration.reg_info.dydxdx_start);\n\tFN_SPEW(\"dxdxdy_start:      %d\\n\", dev->registration.reg_info.dxdxdy_start);\n\tFN_SPEW(\"dydxdy_start:      %d\\n\", dev->registration.reg_info.dydxdy_start);\n\tFN_SPEW(\"dydydx_start:      %d\\n\", dev->registration.reg_info.dydydx_start);\n\tFN_SPEW(\"dydydy_start:      %d\\n\", dev->registration.reg_info.dydydy_start);\n\t/*\n\t// NOTE: Not assigned above\n\tFN_SPEW(\"dx_center:         %d\\n\", dev_reg_info->dx_center);\n\tFN_SPEW(\"rollout_blank:     %d\\n\", dev_reg_info->rollout_blank);\n\tFN_SPEW(\"rollout_size:      %d\\n\", dev_reg_info->rollout_size);\n\tFN_SPEW(\"back_comp1:            %d\\n\", dev_reg_info->back_comp1);\n\tFN_SPEW(\"back_comp2:            %d\\n\", dev_reg_info->back_comp2);\n\t*/\n\treturn 0;\n}\n\nstatic int freenect_fetch_reg_pad_info(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tchar reply[0x200];\n\tuint16_t cmd[5];\n\tfreenect_frame_mode mode = freenect_get_current_video_mode(dev);\n\tcmd[0] = fn_le16(0x41); // ParamID\n\tcmd[1] = fn_le16(0); // Format\n\tcmd[2] = fn_le16((uint16_t)mode.resolution); // Resolution\n\tcmd[3] = fn_le16((uint16_t)mode.framerate); // FPS\n\tcmd[4] = fn_le16(0); // Offset\n\tint res;\n\tres = send_cmd(dev, 0x16, cmd, 10, reply, 8); // OPCODE_ALGORITHM_PARAMS\n\tif(res != 8) {\n\t\tFN_ERROR(\"freenect_fetch_reg_pad_info: send_cmd read %d bytes (expected 8)\\n\", res);\n\t\treturn -1;\n\t}\n\tmemcpy(&dev->registration.reg_pad_info, reply+2, sizeof(dev->registration.reg_pad_info));\n\tdev->registration.reg_pad_info.start_lines    = fn_le16s(dev->registration.reg_pad_info.start_lines);\n\tdev->registration.reg_pad_info.end_lines      = fn_le16s(dev->registration.reg_pad_info.end_lines);\n\tdev->registration.reg_pad_info.cropping_lines = fn_le16s(dev->registration.reg_pad_info.cropping_lines);\n\tFN_SPEW(\"start_lines:    %u\\n\",dev->registration.reg_pad_info.start_lines);\n\tFN_SPEW(\"end_lines:      %u\\n\",dev->registration.reg_pad_info.end_lines);\n\tFN_SPEW(\"cropping_lines: %u\\n\",dev->registration.reg_pad_info.cropping_lines);\n\treturn 0;\n}\n\nstatic int freenect_fetch_reg_const_shift(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tchar reply[0x200];\n\tuint16_t cmd[5];\n\tfreenect_frame_mode mode = freenect_get_current_video_mode(dev);\n\tcmd[0] = fn_le16(0x00); // ParamID\n\tcmd[1] = fn_le16(0); // Format\n\tcmd[2] = fn_le16((uint16_t)mode.resolution); // Resolution\n\tcmd[3] = fn_le16((uint16_t)mode.framerate); // FPS\n\tcmd[4] = fn_le16(0); // Offset\n\tint res;\n\tres = send_cmd(dev, 0x16, cmd, 10, reply, 4); // OPCODE_ALGORITHM_PARAMS\n\tif(res != 4) {\n\t\tFN_ERROR(\"freenect_fetch_reg_const_shift: send_cmd read %d bytes (expected 8)\\n\", res);\n\t\treturn -1;\n\t}\n\tuint16_t shift;\n\tmemcpy(&shift, reply+2, sizeof(shift));\n\tshift = fn_le16(shift);\n\tdev->registration.const_shift = (double)shift;\n\tFN_SPEW(\"const_shift: %f\\n\",dev->registration.const_shift);\n\treturn 0;\n}\n\nstatic int freenect_fetch_zero_plane_info(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\n\tchar reply[0x200];\n\tuint16_t cmd[5] = {0}; // Offset is the only field in this command, and it's 0\n\n\tint res;\n\tres = send_cmd(dev, 0x04, cmd, 10, reply, ctx->zero_plane_res); //OPCODE_GET_FIXED_PARAMS = 4,\n\tif (res != ctx->zero_plane_res) {\n\t\tFN_ERROR(\"freenect_fetch_zero_plane_info: send_cmd read %d bytes (expected %d)\\n\", res,ctx->zero_plane_res);\n\t\treturn -1;\n\t}\n\n\tmemcpy(&(dev->registration.zero_plane_info), reply + 94, sizeof(dev->registration.zero_plane_info));\n\tunion {\n\t\tuint32_t ui;\n\t\tfloat f;\n\t} conversion_union;\n\tconversion_union.f = dev->registration.zero_plane_info.dcmos_emitter_dist;\n\tconversion_union.ui = fn_le32(conversion_union.ui);\n\tdev->registration.zero_plane_info.dcmos_emitter_dist = conversion_union.f;\n\n\tconversion_union.f = dev->registration.zero_plane_info.dcmos_rcmos_dist;\n\tconversion_union.ui = fn_le32(conversion_union.ui);\n\tdev->registration.zero_plane_info.dcmos_rcmos_dist = conversion_union.f;\n\n\tconversion_union.f = dev->registration.zero_plane_info.reference_distance;\n\tconversion_union.ui = fn_le32(conversion_union.ui);\n\tdev->registration.zero_plane_info.reference_distance = conversion_union.f;\n\n\tconversion_union.f = dev->registration.zero_plane_info.reference_pixel_size;\n\tconversion_union.ui = fn_le32(conversion_union.ui);\n\tdev->registration.zero_plane_info.reference_pixel_size = conversion_union.f;\n\n\t// WTF is all this data?  it's way bigger than sizeof(XnFixedParams)...\n\tFN_SPEW(\"dcmos_emitter_distance: %f\\n\", dev->registration.zero_plane_info.dcmos_emitter_dist);\n\tFN_SPEW(\"dcmos_rcmos_distance:   %f\\n\", dev->registration.zero_plane_info.dcmos_rcmos_dist);\n\tFN_SPEW(\"reference_distance:     %f\\n\", dev->registration.zero_plane_info.reference_distance);\n\tFN_SPEW(\"reference_pixel_size:   %f\\n\", dev->registration.zero_plane_info.reference_pixel_size);\n\n\t// FIXME: OpenNI seems to use a hardcoded value of 2.4 instead of 2.3 as reported by Kinect\n\tdev->registration.zero_plane_info.dcmos_rcmos_dist = 2.4;\n\n\treturn 0;\n}\n\nint freenect_start_depth(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tint res;\n\n\tif (dev->depth.running)\n\t\treturn -1;\n\n\tdev->depth.pkt_size = DEPTH_PKTDSIZE;\n\tdev->depth.flag = 0x70;\n\tdev->depth.variable_length = 0;\n\n\tswitch (dev->depth_format) {\n\t\tcase FREENECT_DEPTH_REGISTERED:\n\t\tcase FREENECT_DEPTH_MM:\n\t\t\tfreenect_init_registration(dev);\n\t\tcase FREENECT_DEPTH_11BIT:\n\t\t\tstream_init(ctx, &dev->depth, freenect_find_depth_mode(dev->depth_resolution, FREENECT_DEPTH_11BIT_PACKED).bytes, freenect_find_depth_mode(dev->depth_resolution, FREENECT_DEPTH_11BIT).bytes);\n\t\t\tbreak;\n\t\tcase FREENECT_DEPTH_10BIT:\n\t\t\tstream_init(ctx, &dev->depth, freenect_find_depth_mode(dev->depth_resolution, FREENECT_DEPTH_10BIT_PACKED).bytes, freenect_find_depth_mode(dev->depth_resolution, FREENECT_DEPTH_10BIT).bytes);\n\t\t\tbreak;\n\t\tcase FREENECT_DEPTH_11BIT_PACKED:\n\t\tcase FREENECT_DEPTH_10BIT_PACKED:\n\t\t\tstream_init(ctx, &dev->depth, 0, freenect_find_depth_mode(dev->depth_resolution, dev->depth_format).bytes);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tFN_ERROR(\"freenect_start_depth() called with invalid depth format %d\\n\", dev->depth_format);\n\t\t\treturn -1;\n\t}\n\n\tres = fnusb_start_iso(&dev->usb_cam, &dev->depth_isoc, depth_process, 0x82, NUM_XFERS, PKTS_PER_XFER, DEPTH_PKTBUF);\n\tif (res < 0)\n\t\treturn res;\n\n\twrite_register(dev, 0x105, 0x00); // Disable auto-cycle of projector\n\twrite_register(dev, 0x06, 0x00); // reset depth stream\n\tswitch (dev->depth_format) {\n\t\tcase FREENECT_DEPTH_11BIT:\n\t\tcase FREENECT_DEPTH_11BIT_PACKED:\n\t\tcase FREENECT_DEPTH_REGISTERED:\n\t\tcase FREENECT_DEPTH_MM:\n\t\t\twrite_register(dev, 0x12, 0x03);\n\t\t\tbreak;\n\t\tcase FREENECT_DEPTH_10BIT:\n\t\tcase FREENECT_DEPTH_10BIT_PACKED:\n\t\t\twrite_register(dev, 0x12, 0x02);\n\t\t\tbreak;\n\t\tcase FREENECT_DEPTH_DUMMY: // Returned already, hush gcc\n\t\t\tbreak;\n\t}\n\twrite_register(dev, 0x13, 0x01);\n\twrite_register(dev, 0x14, 0x1e);\n\twrite_register(dev, 0x06, 0x02); // start depth stream\n\twrite_register(dev, 0x17, 0x00); // disable depth hflip\n\n\tdev->depth.running = 1;\n\treturn 0;\n}\n\nint freenect_start_video(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tint res;\n\n\tif (dev->video.running)\n\t\treturn -1;\n\n\tdev->video.pkt_size = VIDEO_PKTDSIZE;\n\tdev->video.flag = 0x80;\n\tdev->video.variable_length = 0;\n\n\tuint16_t mode_reg, mode_value;\n\tuint16_t res_reg, res_value;\n\tuint16_t fps_reg, fps_value;\n\tuint16_t hflip_reg;\n\n\tswitch(dev->video_format) {\n\t\tcase FREENECT_VIDEO_RGB:\n\t\tcase FREENECT_VIDEO_BAYER:\n\t\t\tif(dev->video_resolution == FREENECT_RESOLUTION_HIGH) {\n\t\t\t\tmode_value = 0x00; // Bayer\n\t\t\t\tres_value = 0x02; // 1280x1024\n\t\t\t\tfps_value = 0x0f; // \"15\" Hz\n\t\t\t} else if (dev->video_resolution == FREENECT_RESOLUTION_MEDIUM) {\n\t\t\t\tmode_value = 0x00; // Bayer\n\t\t\t\tres_value = 0x01; // 640x480\n\t\t\t\tfps_value = 0x1e; // 30 Hz\n\t\t\t} else {\n\t\t\t\tFN_ERROR(\"freenect_start_video(): called with invalid format/resolution combination\\n\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tmode_reg = 0x0c;\n\t\t\tres_reg = 0x0d;\n\t\t\tfps_reg = 0x0e;\n\t\t\thflip_reg = 0x47;\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_IR_8BIT:\n\t\tcase FREENECT_VIDEO_IR_10BIT:\n\t\tcase FREENECT_VIDEO_IR_10BIT_PACKED:\n\t\t\tif(dev->video_resolution == FREENECT_RESOLUTION_HIGH) {\n\t\t\t\tif(dev->depth.running) {\n\t\t\t\t\tFN_ERROR(\"freenect_start_video(): cannot stream high-resolution IR at same time as depth stream\\n\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\n\t\t\t\t// Due to some ridiculous condition in the firmware, we have to start and stop the\n\t\t\t\t// depth stream before the camera will hand us 1280x1024 IR.  This is a stupid\n\t\t\t\t// workaround, but we've yet to find a better solution.\n\t\t\t\twrite_register(dev, 0x13, 0x01); // set depth camera resolution (640x480)\n\t\t\t\twrite_register(dev, 0x14, 0x1e); // set depth camera FPS (30)\n\t\t\t\twrite_register(dev, 0x06, 0x02); // start depth camera\n\t\t\t\twrite_register(dev, 0x06, 0x00); // stop depth camera\n\n\t\t\t\tmode_value = 0x00; // Luminance, 10-bit packed\n\t\t\t\tres_value = 0x02; // 1280x1024\n\t\t\t\tfps_value = 0x0f; // \"15\" Hz\n\t\t\t} else if (dev->video_resolution == FREENECT_RESOLUTION_MEDIUM) {\n\t\t\t\tmode_value = 0x00; // Luminance, 10-bit packed\n\t\t\t\tres_value = 0x01; // 640x480\n\t\t\t\tfps_value = 0x1e; // 30 Hz\n\t\t\t} else {\n\t\t\t\tFN_ERROR(\"freenect_start_video(): called with invalid format/resolution combination\\n\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tmode_reg = 0x19;\n\t\t\tres_reg = 0x1a;\n\t\t\tfps_reg = 0x1b;\n\t\t\thflip_reg = 0x48;\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_YUV_RGB:\n\t\tcase FREENECT_VIDEO_YUV_RAW:\n\t\t\tif(dev->video_resolution == FREENECT_RESOLUTION_MEDIUM) {\n\t\t\t\tmode_value = 0x05; // UYUV mode\n\t\t\t\tres_value = 0x01; // 640x480\n\t\t\t\tfps_value = 0x0f; // 15Hz\n\t\t\t} else {\n\t\t\t\tFN_ERROR(\"freenect_start_video(): called with invalid format/resolution combination\\n\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tmode_reg = 0x0c;\n\t\t\tres_reg = 0x0d;\n\t\t\tfps_reg = 0x0e;\n\t\t\thflip_reg = 0x47;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tFN_ERROR(\"freenect_start_video(): called with invalid video format %d\\n\", dev->video_format);\n\t\t\treturn -1;\n\t}\n\n\tfreenect_frame_mode frame_mode = freenect_get_current_video_mode(dev);\n\tswitch (dev->video_format) {\n\t\tcase FREENECT_VIDEO_RGB:\n\t\t\tstream_init(ctx, &dev->video, freenect_find_video_mode(dev->video_resolution, FREENECT_VIDEO_BAYER).bytes, frame_mode.bytes);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_BAYER:\n\t\t\tstream_init(ctx, &dev->video, 0, frame_mode.bytes);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_IR_8BIT:\n\t\t\tstream_init(ctx, &dev->video, freenect_find_video_mode(dev->video_resolution, FREENECT_VIDEO_IR_10BIT_PACKED).bytes, frame_mode.bytes);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_IR_10BIT:\n\t\t\tstream_init(ctx, &dev->video, freenect_find_video_mode(dev->video_resolution, FREENECT_VIDEO_IR_10BIT_PACKED).bytes, frame_mode.bytes);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_IR_10BIT_PACKED:\n\t\t\tstream_init(ctx, &dev->video, 0, frame_mode.bytes);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_YUV_RGB:\n\t\t\tstream_init(ctx, &dev->video, freenect_find_video_mode(dev->video_resolution, FREENECT_VIDEO_YUV_RAW).bytes, frame_mode.bytes);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_YUV_RAW:\n\t\t\tstream_init(ctx, &dev->video, 0, frame_mode.bytes);\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_DUMMY: // Silence compiler\n\t\t\tbreak;\n\t}\n\n\tres = fnusb_start_iso(&dev->usb_cam, &dev->video_isoc, video_process, 0x81, NUM_XFERS, PKTS_PER_XFER, VIDEO_PKTBUF);\n\tif (res < 0)\n\t\treturn res;\n\n\twrite_register(dev, mode_reg, mode_value);\n\twrite_register(dev, res_reg, res_value);\n\twrite_register(dev, fps_reg, fps_value);\n\n\tswitch (dev->video_format) {\n\t\tcase FREENECT_VIDEO_RGB:\n\t\tcase FREENECT_VIDEO_BAYER:\n\t\tcase FREENECT_VIDEO_YUV_RGB:\n\t\tcase FREENECT_VIDEO_YUV_RAW:\n\t\t\twrite_register(dev, 0x05, 0x01); // start video stream\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_IR_8BIT:\n\t\tcase FREENECT_VIDEO_IR_10BIT:\n\t\tcase FREENECT_VIDEO_IR_10BIT_PACKED:\n\t\t\twrite_register(dev, 0x105, 0x00); // Disable auto-cycle of projector\n\t\t\twrite_register(dev, 0x05, 0x03); // start video stream\n\t\t\tbreak;\n\t\tcase FREENECT_VIDEO_DUMMY: // Silence compiler\n\t\t\tbreak;\n\t}\n\twrite_register(dev, hflip_reg, 0x00); // disable Hflip\n\n\tdev->video.running = 1;\n\treturn 0;\n}\n\nint freenect_stop_depth(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tint res;\n\n\tif (!dev->depth.running)\n\t\treturn -1;\n\n\tdev->depth.running = 0;\n\tfreenect_destroy_registration(&(dev->registration));\n\twrite_register(dev, 0x06, 0x00); // stop depth stream\n\n\tres = fnusb_stop_iso(&dev->usb_cam, &dev->depth_isoc);\n\tif (res < 0) {\n\t\tFN_ERROR(\"Failed to stop depth isochronous stream: %d\\n\", res);\n\t\treturn res;\n\t}\n\n\tstream_freebufs(ctx, &dev->depth);\n\treturn 0;\n}\n\nint freenect_stop_video(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tint res;\n\n\tif (!dev->video.running)\n\t\treturn -1;\n\n\tdev->video.running = 0;\n\twrite_register(dev, 0x05, 0x00); // stop video stream\n\n\tres = fnusb_stop_iso(&dev->usb_cam, &dev->video_isoc);\n\tif (res < 0) {\n\t\tFN_ERROR(\"Failed to stop RGB isochronous stream: %d\\n\", res);\n\t\treturn res;\n\t}\n\n\tstream_freebufs(ctx, &dev->video);\n\treturn 0;\n}\n\nvoid freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb)\n{\n\tdev->depth_cb = cb;\n}\n\nvoid freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb)\n{\n\tdev->video_cb = cb;\n}\n\nint freenect_get_video_mode_count()\n{\n\treturn video_mode_count;\n}\n\nfreenect_frame_mode freenect_get_video_mode(int mode_num)\n{\n\tif (mode_num >= 0 && mode_num < video_mode_count)\n\t\treturn supported_video_modes[mode_num];\n\tfreenect_frame_mode retval;\n\tretval.is_valid = 0;\n\treturn retval;\n}\n\nfreenect_frame_mode freenect_get_current_video_mode(freenect_device *dev)\n{\n\treturn freenect_find_video_mode(dev->video_resolution, dev->video_format);\n}\n\nfreenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt)\n{\n\tuint32_t unique_id = MAKE_RESERVED(res, fmt);\n\tint i;\n\tfor(i = 0 ; i < video_mode_count; i++) {\n\t\tif (supported_video_modes[i].reserved == unique_id)\n\t\t\treturn supported_video_modes[i];\n\t}\n\tfreenect_frame_mode retval;\n\tretval.is_valid = 0;\n\treturn retval;\n}\n\nint freenect_set_video_mode(freenect_device* dev, const freenect_frame_mode mode)\n{\n\tfreenect_context *ctx = dev->parent;\n\tif (dev->video.running) {\n\t\tFN_ERROR(\"Tried to set video mode while stream is active\\n\");\n\t\treturn -1;\n\t}\n\t// Verify that the mode passed in is actually in the supported mode list\n\tint found = 0;\n\tint i;\n\tfor(i = 0 ; i < video_mode_count; i++) {\n\t\tif (supported_video_modes[i].reserved == mode.reserved) {\n\t\t\tfound = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (!found) {\n\t\tFN_ERROR(\"freenect_set_video_mode: freenect_frame_mode provided is invalid\\n\");\n\t\treturn -1;\n\t}\n\n\tfreenect_resolution res = RESERVED_TO_RESOLUTION(mode.reserved);\n\tfreenect_video_format fmt = (freenect_video_format)RESERVED_TO_FORMAT(mode.reserved);\n\tdev->video_format = fmt;\n\tdev->video_resolution = res;\n\t// Now that we've changed video format and resolution, we need to update\n\t// registration tables.\n\tfreenect_fetch_reg_info(dev);\n\treturn 0;\n}\n\nint freenect_get_depth_mode_count()\n{\n\treturn depth_mode_count;\n}\n\nfreenect_frame_mode freenect_get_depth_mode(int mode_num)\n{\n\tif (mode_num >= 0 && mode_num < depth_mode_count)\n\t\treturn supported_depth_modes[mode_num];\n\tfreenect_frame_mode retval;\n\tretval.is_valid = 0;\n\treturn retval;\n}\n\nfreenect_frame_mode freenect_get_current_depth_mode(freenect_device *dev)\n{\n\treturn freenect_find_depth_mode(dev->depth_resolution, dev->depth_format);\n}\n\nfreenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt)\n{\n\tuint32_t unique_id = MAKE_RESERVED(res, fmt);\n\tint i;\n\tfor(i = 0 ; i < depth_mode_count; i++) {\n\t\tif (supported_depth_modes[i].reserved == unique_id)\n\t\t\treturn supported_depth_modes[i];\n\t}\n\tfreenect_frame_mode retval;\n\tretval.is_valid = 0;\n\treturn retval;\n}\n\nint freenect_set_depth_mode(freenect_device* dev, const freenect_frame_mode mode)\n{\n\tfreenect_context *ctx = dev->parent;\n\tif (dev->depth.running) {\n\t\tFN_ERROR(\"Tried to set depth mode while stream is active\\n\");\n\t\treturn -1;\n\t}\n\t// Verify that the mode passed in is actually in the supported mode list\n\tint found = 0;\n\tint i;\n\tfor(i = 0 ; i < depth_mode_count; i++) {\n\t\tif (supported_depth_modes[i].reserved == mode.reserved) {\n\t\t\tfound = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (!found) {\n\t\tFN_ERROR(\"freenect_set_depth_mode: freenect_frame_mode provided is invalid\\n\");\n\t\treturn -1;\n\t}\n\tfreenect_resolution res = RESERVED_TO_RESOLUTION(mode.reserved);\n\tfreenect_depth_format fmt = (freenect_depth_format)RESERVED_TO_FORMAT(mode.reserved);\n\tdev->depth_format = fmt;\n\tdev->depth_resolution = res;\n\treturn 0;\n}\nint freenect_set_depth_buffer(freenect_device *dev, void *buf)\n{\n\treturn stream_setbuf(dev->parent, &dev->depth, buf);\n}\n\nint freenect_set_video_buffer(freenect_device *dev, void *buf)\n{\n\treturn stream_setbuf(dev->parent, &dev->video, buf);\n}\n\nFN_INTERNAL int freenect_camera_init(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tint res;\n\tres = freenect_fetch_reg_pad_info(dev);\n\tif (res < 0) {\n\t\tFN_ERROR(\"freenect_camera_init(): Failed to fetch registration pad info for device\\n\");\n\t\treturn res;\n\t}\n\tres = freenect_fetch_zero_plane_info(dev);\n\tif (res < 0) {\n\t\tFN_ERROR(\"freenect_camera_init(): Failed to fetch zero plane info for device\\n\");\n\t\treturn res;\n\t}\n\tres = freenect_set_video_mode(dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));\n\tres = freenect_set_depth_mode(dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));\n\tres = freenect_fetch_reg_const_shift(dev);\n\tif (res < 0) {\n\t\tFN_ERROR(\"freenect_camera_init(): Failed to fetch const shift for device\\n\");\n\t\treturn res;\n\t}\n\treturn 0;\n}\n\nFN_INTERNAL int freenect_camera_teardown(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tint res = 0;\n\tif (dev->depth.running) {\n\t\tres = freenect_stop_depth(dev);\n\t\tif (res < 0) {\n\t\t\tFN_ERROR(\"freenect_camera_teardown(): Failed to stop depth camera\\n\");\n\t\t}\n\t\treturn res;\n\t}\n\tif (dev->video.running) {\n\t\tres = freenect_stop_video(dev);\n\t\tif (res < 0) {\n\t\t\tFN_ERROR(\"freenect_camera_teardown(): Failed to stop video camera\\n\");\n\t\t}\n\t\treturn res;\n\t}\n\tfreenect_destroy_registration(&(dev->registration));\n\treturn 0;\n}\n"
  },
  {
    "path": "libs/libfreenect/src/cameras.h",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010-2011 individual OpenKinect contributors. See the CONTRIB\n * file for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#ifndef CAMERAS_H\n#define CAMERAS_H\n\n#include \"libfreenect.h\"\n\n// Just a couple function declarations.\n\n// These are called by core.c to do camera-specific initialization that needs\n// camera-specific protocol support.\nint freenect_camera_init(freenect_device *dev);\nint freenect_camera_teardown(freenect_device *dev);\n\n#endif\n\n"
  },
  {
    "path": "libs/libfreenect/src/core.c",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdarg.h>\n\n#include <unistd.h>\n\n#include \"freenect_internal.h\"\n#include \"registration.h\"\n#include \"cameras.h\"\n#ifdef BUILD_AUDIO\n#include \"loader.h\"\n#endif\n\nFREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)\n{\n\tint res;\n\n\t*ctx = (freenect_context*)malloc(sizeof(freenect_context));\n\tif (!ctx)\n\t\treturn -1;\n\n\tmemset(*ctx, 0, sizeof(freenect_context));\n\n\t(*ctx)->log_level = LL_WARNING;\n\t(*ctx)->enabled_subdevices = (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA\n#ifdef BUILD_AUDIO\n\t\t\t| FREENECT_DEVICE_AUDIO\n#endif\n\t\t\t);\n\tres = fnusb_init(&(*ctx)->usb, usb_ctx);\n\tif (res < 0) {\n\t\tfree(*ctx);\n\t\t*ctx = NULL;\n\t}\n\treturn res;\n}\n\nFREENECTAPI int freenect_shutdown(freenect_context *ctx)\n{\n\twhile (ctx->first) {\n\t\tFN_NOTICE(\"Device %p open during shutdown, closing...\\n\", ctx->first);\n\t\tfreenect_close_device(ctx->first);\n\t}\n\n\tfnusb_shutdown(&ctx->usb);\n\tfree(ctx);\n\treturn 0;\n}\n\nFREENECTAPI int freenect_process_events(freenect_context *ctx)\n{\n\tstruct timeval timeout;\n\ttimeout.tv_sec = 60;\n\ttimeout.tv_usec = 0;\n\treturn freenect_process_events_timeout(ctx, &timeout);\n}\n\nFREENECTAPI int freenect_process_events_timeout(freenect_context *ctx, struct timeval *timeout)\n{\n\tint res = fnusb_process_events_timeout(&ctx->usb, timeout);\n\t// Iterate over the devices in ctx.  If any of them are flagged as\n\tfreenect_device* dev = ctx->first;\n\twhile(dev) {\n\t\tif (dev->usb_cam.device_dead) {\n\t\t\tFN_ERROR(\"USB camera marked dead, stopping streams\\n\");\n\t\t\tres = -1;\n\t\t\tfreenect_stop_video(dev);\n\t\t\tfreenect_stop_depth(dev);\n\t\t}\n#ifdef BUILD_AUDIO\n\t\tif (dev->usb_audio.device_dead) {\n\t\t\tFN_ERROR(\"USB audio marked dead, stopping streams\\n\");\n\t\t\tres = -1; // Or something else to tell the user that the device just vanished.\n\t\t\tfreenect_stop_audio(dev);\n\t\t}\n#endif\n\t\tdev = dev->next;\n\t}\n\treturn res;\n}\n\nFREENECTAPI int freenect_num_devices(freenect_context *ctx)\n{\n\treturn fnusb_num_devices(&ctx->usb);\n}\n\nFREENECTAPI int freenect_list_device_attributes(freenect_context *ctx, struct freenect_device_attributes **attribute_list)\n{\n\treturn fnusb_list_device_attributes(&ctx->usb, attribute_list);\n}\n\nFREENECTAPI void freenect_free_device_attributes(struct freenect_device_attributes *attribute_list)\n{\n\t// Iterate over list, freeing contents of each item as we go.\n\tstruct freenect_device_attributes* to_free;\n\twhile(attribute_list != NULL) {\n\t\tto_free = attribute_list;\n\t\tif (attribute_list->camera_serial != NULL) {\n\t\t\tfree((char*)attribute_list->camera_serial);\n\t\t\tattribute_list->camera_serial = NULL;\n\t\t}\n\t\tattribute_list = attribute_list->next;\n\t\tfree(to_free);\n\t}\n\treturn;\n}\n\nFREENECTAPI int freenect_supported_subdevices(void) {\n#ifdef BUILD_AUDIO\n\treturn FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA | FREENECT_DEVICE_AUDIO;\n#else\n\treturn FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA;\n#endif\n}\n\nFREENECTAPI void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs) {\n\tctx->enabled_subdevices = (freenect_device_flags)(subdevs & (FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA\n#ifdef BUILD_AUDIO\n\t\t\t| FREENECT_DEVICE_AUDIO\n#endif\n\t\t\t));\n}\n\nFREENECTAPI freenect_device_flags freenect_enabled_subdevices(freenect_context *ctx) {\n\treturn ctx->enabled_subdevices;\n}\n\nFREENECTAPI int freenect_open_device(freenect_context *ctx, freenect_device **dev, int index)\n{\n\tint res;\n\tfreenect_device *pdev = (freenect_device*)malloc(sizeof(freenect_device));\n\tif (!pdev)\n\t\treturn -1;\n\n\tmemset(pdev, 0, sizeof(*pdev));\n\n\tpdev->parent = ctx;\n\n\tres = fnusb_open_subdevices(pdev, index);\n\tif (res < 0) {\n\t\tfree(pdev);\n\t\treturn res;\n\t}\n\n\tif (!ctx->first) {\n\t\tctx->first = pdev;\n\t} else {\n\t\tfreenect_device *prev = ctx->first;\n\t\twhile (prev->next)\n\t\t\tprev = prev->next;\n\t\tprev->next = pdev;\n\t}\n\n\t*dev = pdev;\n\n\t// Do device-specific initialization\n\tif (pdev->usb_cam.dev) {\n\t\tif (freenect_camera_init(pdev) < 0) {\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\nFREENECTAPI int freenect_open_device_by_camera_serial(freenect_context *ctx, freenect_device **dev, const char* camera_serial)\n{\n\t// This is implemented by listing the devices and seeing which index (if\n\t// any) has a camera with a matching serial number, and then punting to\n\t// freenect_open_device with that index.\n\tstruct freenect_device_attributes* attrlist;\n\tstruct freenect_device_attributes* item;\n\tint count = fnusb_list_device_attributes(&ctx->usb, &attrlist);\n\tif (count < 0) {\n\t\tFN_ERROR(\"freenect_open_device_by_camera_serial: Couldn't enumerate serial numbers\\n\");\n\t\treturn -1;\n\t}\n\tint index = 0;\n\tfor(item = attrlist ; item != NULL; item = item->next , index++) {\n\t\tif (strlen(item->camera_serial) == strlen(camera_serial) && strcmp(item->camera_serial, camera_serial) == 0) {\n\t\t\tfreenect_free_device_attributes(attrlist);\n\t\t\treturn freenect_open_device(ctx, dev, index);\n\t\t}\n\t}\n\tfreenect_free_device_attributes(attrlist);\n\tFN_ERROR(\"freenect_open_device_by_camera_serial: Couldn't find a device with serial %s\\n\", camera_serial);\n\treturn -1;\n}\n\nFREENECTAPI int freenect_close_device(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\tint res;\n\n\tif (dev->usb_cam.dev) {\n\t\tfreenect_camera_teardown(dev);\n\t}\n\n\tres = fnusb_close_subdevices(dev);\n\tif (res < 0) {\n\t\tFN_ERROR(\"fnusb_close_subdevices failed: %d\\n\", res);\n\t\treturn res;\n\t}\n\n\tfreenect_device *last = NULL;\n\tfreenect_device *cur = ctx->first;\n\n\twhile (cur && cur != dev) {\n\t\tlast = cur;\n\t\tcur = cur->next;\n\t}\n\n\tif (!cur) {\n\t\tFN_ERROR(\"device %p not found in linked list for this context!\\n\", dev);\n\t\treturn -1;\n\t}\n\n\tif (last)\n\t\tlast->next = cur->next;\n\telse\n\t\tctx->first = cur->next;\n\n\tfree(dev);\n\treturn 0;\n}\n\nFREENECTAPI void freenect_set_user(freenect_device *dev, void *user)\n{\n\tdev->user_data = user;\n}\n\nFREENECTAPI void *freenect_get_user(freenect_device *dev)\n{\n\treturn dev->user_data;\n}\n\nFREENECTAPI void freenect_set_log_level(freenect_context *ctx, freenect_loglevel level)\n{\n\tctx->log_level = level;\n}\n\nFREENECTAPI void freenect_set_log_callback(freenect_context *ctx, freenect_log_cb cb)\n{\n\tctx->log_cb = cb;\n}\n\nFN_INTERNAL void fn_log(freenect_context *ctx, freenect_loglevel level, const char *fmt, ...)\n{\n\tva_list ap;\n\n\tif (level > ctx->log_level)\n\t\treturn;\n\n\tif (ctx->log_cb) {\n\t\tchar msgbuf[1024];\n\n\t\tva_start(ap, fmt);\n\t\tvsnprintf(msgbuf, 1024, fmt, ap);\n\t\tmsgbuf[1023] = 0;\n\t\tva_end(ap);\n\n\t\tctx->log_cb(ctx, level, msgbuf);\n\t} else {\n\t\tva_start(ap, fmt);\n\t\tvfprintf(stderr, fmt, ap);\n\t\tva_end(ap);\n\t}\n}\n"
  },
  {
    "path": "libs/libfreenect/src/freenect_internal.h",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010-2011 individual OpenKinect contributors. See the CONTRIB\n * file for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#ifndef FREENECT_INTERNAL_H\n#define FREENECT_INTERNAL_H\n\n#include <stdint.h>\n\n#include \"libfreenect.h\"\n#include \"libfreenect-registration.h\"\n\n#ifdef BUILD_AUDIO\n#include \"libfreenect-audio.h\"\n#endif\n\n#ifdef __ELF__\n#define FN_INTERNAL\t__attribute__ ((visibility (\"hidden\")))\n#else\n#define FN_INTERNAL\n#endif\n\n\ntypedef void (*fnusb_iso_cb)(freenect_device *dev, uint8_t *buf, int len);\n\n#include \"usb_libusb10.h\"\n\nstruct _freenect_context {\n\tfreenect_loglevel log_level;\n\tfreenect_log_cb log_cb;\n\tfnusb_ctx usb;\n\tfreenect_device_flags enabled_subdevices;\n\tfreenect_device *first;\n\tint zero_plane_res;\n};\n\n#define LL_FATAL FREENECT_LOG_FATAL\n#define LL_ERROR FREENECT_LOG_ERROR\n#define LL_WARNING FREENECT_LOG_WARNING\n#define LL_NOTICE FREENECT_LOG_NOTICE\n#define LL_INFO FREENECT_LOG_INFO\n#define LL_DEBUG FREENECT_LOG_DEBUG\n#define LL_SPEW FREENECT_LOG_SPEW\n#define LL_FLOOD FREENECT_LOG_FLOOD\n\n\n#ifdef _WIN32\n#include <stdarg.h>\n#include <stdio.h>\nvoid fn_log(freenect_context *ctx, freenect_loglevel level, const char *fmt, ...);\n#else\nvoid fn_log(freenect_context *ctx, freenect_loglevel level, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));\n#endif\n\n#define FN_LOG(level, ...) fn_log(ctx, level, __VA_ARGS__)\n\n#define FN_FATAL(...) FN_LOG(LL_FATAL, __VA_ARGS__)\n#define FN_ERROR(...) FN_LOG(LL_ERROR, __VA_ARGS__)\n#define FN_WARNING(...) FN_LOG(LL_WARNING, __VA_ARGS__)\n#define FN_NOTICE(...) FN_LOG(LL_NOTICE, __VA_ARGS__)\n#define FN_INFO(...) FN_LOG(LL_INFO, __VA_ARGS__)\n#define FN_DEBUG(...) FN_LOG(LL_DEBUG, __VA_ARGS__)\n#define FN_SPEW(...) FN_LOG(LL_SPEW, __VA_ARGS__)\n#define FN_FLOOD(...) FN_LOG(LL_FLOOD, __VA_ARGS__)\n\n#ifdef FN_BIGENDIAN\nstatic inline uint16_t fn_le16(uint16_t d)\n{\n\treturn (d<<8) | (d>>8);\n}\nstatic inline uint32_t fn_le32(uint32_t d)\n{\n\treturn (d<<24) | ((d<<8)&0xFF0000) | ((d>>8)&0xFF00) | (d>>24);\n}\nstatic inline int16_t fn_le16s(int16_t s)\n{\n\t// reinterpret cast to unsigned, use the normal fn_le16, and then reinterpret cast back\n\tunion {\n\t\tint16_t s;\n\t\tuint16_t u;\n\t} conversion_union;\n\tconversion_union.s = s;\n\tconversion_union.u = fn_le16(conversion_union.u);\n\treturn conversion_union.s;\n}\nstatic inline int32_t fn_le32s(int32_t s)\n{\n\t// reinterpret cast to unsigned, use the normal fn_le32, and then reinterpret cast back\n\tunion {\n\t\tint32_t s;\n\t\tuint32_t u;\n\t} conversion_union;\n\tconversion_union.s = s;\n\tconversion_union.u = fn_le32(conversion_union.u);\n\treturn conversion_union.s;\n}\n#else\n#define fn_le16(x) (x)\n#define fn_le32(x) (x)\n#define fn_le16s(x) (x)\n#define fn_le32s(x) (x)\n#endif\n\n#define DEPTH_PKTSIZE 1760\n#define VIDEO_PKTSIZE 1920\n\n#define DEPTH_PKTDSIZE (DEPTH_PKTSIZE-12)\n#define VIDEO_PKTDSIZE (VIDEO_PKTSIZE-12)\n\n#define VID_MICROSOFT 0x45e\n#define PID_NUI_AUDIO 0x02ad\n#define PID_NUI_CAMERA 0x02ae\n#define PID_NUI_MOTOR 0x02b0\n#define PID_K4W_CAMERA 0x02bf\n#define PID_K4W_AUDIO 0x02be\n\ntypedef struct {\n\tint running;\n\tuint8_t flag;\n\tint synced;\n\tuint8_t seq;\n\tint got_pkts;\n\tint pkt_num;\n\tint pkts_per_frame;\n\tint pkt_size;\n\tint frame_size;\n\tint last_pkt_size;\n\tint valid_pkts;\n\tint valid_frames;\n\tint variable_length;\n\tuint32_t last_timestamp;\n\tuint32_t timestamp;\n\tint split_bufs;\n\tvoid *lib_buf;\n\tvoid *usr_buf;\n\tuint8_t *raw_buf;\n\tvoid *proc_buf;\n} packet_stream;\n\n#ifdef BUILD_AUDIO\ntypedef struct {\n\tint running;\n\n\tfreenect_sample_51* audio_out_ring; // TODO: implement sending user-provided data in callbacks\n\tint ring_reader_idx; // Index in audio_out_ring of the last sent sample\n\tint ring_writer_idx; // Index in audio_out_ring of the next sample we haven't received from the client yet\n\n\tuint16_t out_window;\n\tuint8_t out_seq;\n\tuint8_t out_counter_within_window;\n\tuint16_t out_weird_timestamp;\n\tuint8_t out_window_parity;\n\n\tuint16_t in_window;\n\tuint16_t last_seen_window[10];\n\tuint8_t in_counter;\n\tint32_t* mic_buffer[4];\n\tint16_t* cancelled_buffer;\n\tvoid* in_unknown;\n\n\t// TODO: timestamps\n} audio_stream;\n\ntypedef struct {\n\tuint32_t magic;    // 0x80000080\n\tuint16_t channel;  // Values between 0x1 and 0xa indicate audio channel\n\tuint16_t len;      // packet length\n\tuint16_t window;   // timestamp\n\tuint16_t unknown;  // ???\n\tint32_t samples[]; // Size depends on len\n} audio_in_block;\n\ntypedef struct {\n\tuint16_t window;       // Kinda like a timestamp.\n\tuint8_t seq;           // Values from 0x00 to 0x7f\n\tuint8_t weird;         // Has an odd cyclic behavior.\n\tfreenect_sample_51 samples[6];  // Audio samples - 6 samples per transfer\n} audio_out_block;\n\n#endif\n\nstruct _freenect_device {\n\tfreenect_context *parent;\n\tfreenect_device *next;\n\tvoid *user_data;\n\n\t// Cameras\n\tfnusb_dev usb_cam;\n\tfnusb_isoc_stream depth_isoc;\n\tfnusb_isoc_stream video_isoc;\n\n\tfreenect_depth_cb depth_cb;\n\tfreenect_video_cb video_cb;\n\tfreenect_video_format video_format;\n\tfreenect_depth_format depth_format;\n\tfreenect_resolution video_resolution;\n\tfreenect_resolution depth_resolution;\n\n\tint cam_inited;\n\tuint16_t cam_tag;\n\n\tpacket_stream depth;\n\tpacket_stream video;\n\n\t// Registration\n\tfreenect_registration registration;\n\n#ifdef BUILD_AUDIO\n\t// Audio\n\tfnusb_dev usb_audio;\n\tfnusb_isoc_stream audio_out_isoc;\n\tfnusb_isoc_stream audio_in_isoc;\n\n\tfreenect_audio_in_cb audio_in_cb;\n\tfreenect_audio_out_cb audio_out_cb;\n\n\taudio_stream audio;\n\tuint32_t audio_tag;\n#endif\n\t// Motor\n\tfnusb_dev usb_motor;\n\tfreenect_raw_tilt_state raw_state;\n};\n\n#endif\n"
  },
  {
    "path": "libs/libfreenect/src/loader.h",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2011 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#ifndef __LOADER_H__\n#define __LOADER_H__\n\n#include <stdint.h>\n#include \"usb_libusb10.h\"\n\ntypedef struct {\n\tuint32_t magic;\n\tuint32_t tag;\n\tuint32_t bytes;\n\tuint32_t cmd;\n\tuint32_t addr;\n\tuint32_t unk;\n} bootloader_command;\n\ntypedef struct {\n\tuint32_t magic;\n\tuint32_t tag;\n\tuint32_t arg1; // initial command: 0.  Firmware blocks: byte count.\n\tuint32_t cmd;\n\tuint32_t arg2; // initial command: byte count.  Firmware blocks: target address.\n\tuint32_t zeros[8];\n} cemdloader_command;\n\ntypedef struct {\n\tuint32_t magic;\n\tuint32_t tag;\n\tuint32_t status;\n} bootloader_status_code;\n\nint upload_firmware(fnusb_dev* dev);\nint upload_cemd_data(fnusb_dev* dev);\n\n#endif //__LOADER_H__\n"
  },
  {
    "path": "libs/libfreenect/src/registration.c",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2011 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#include <libfreenect.h>\n#include <freenect_internal.h>\n#include \"registration.h\"\n#include <stdlib.h>\n#include <string.h>\n#include <stdio.h>\n#include <math.h>\n\n\n#define REG_X_VAL_SCALE 256 // \"fixed-point\" precision for double -> int32_t conversion\n\n#define S2D_PIXEL_CONST 10\n#define S2D_CONST_OFFSET 0.375\n\n#define DEPTH_SENSOR_X_RES 1280\n#define DEPTH_MIRROR_X 0\n\n#define DEPTH_MAX_METRIC_VALUE FREENECT_DEPTH_MM_MAX_VALUE\n#define DEPTH_NO_MM_VALUE      FREENECT_DEPTH_MM_NO_VALUE\n#define DEPTH_MAX_RAW_VALUE    FREENECT_DEPTH_RAW_MAX_VALUE\n#define DEPTH_NO_RAW_VALUE     FREENECT_DEPTH_RAW_NO_VALUE\n\n#define DEPTH_X_OFFSET 1\n#define DEPTH_Y_OFFSET 1\n#define DEPTH_X_RES 640\n#define DEPTH_Y_RES 480\n\n// try to fill single empty pixels AKA \"salt-and-pepper noise\"\n// disabled by default, noise removal better handled in later stages\n// #define DENSE_REGISTRATION\n\n\n/// fill the table of horizontal shift values for metric depth -> RGB conversion\nstatic void freenect_init_depth_to_rgb(int32_t* depth_to_rgb, freenect_zero_plane_info* zpi)\n{\n\tuint32_t i,x_scale = DEPTH_SENSOR_X_RES / DEPTH_X_RES;\n\n\tdouble pixel_size = 1.0 / (zpi->reference_pixel_size * x_scale * S2D_PIXEL_CONST);\n\tdouble pixels_between_rgb_and_ir_cmos = zpi->dcmos_rcmos_dist * pixel_size * S2D_PIXEL_CONST;\n\tdouble reference_distance_in_pixels = zpi->reference_distance * pixel_size * S2D_PIXEL_CONST;\n\n\tmemset(depth_to_rgb, DEPTH_NO_MM_VALUE, DEPTH_MAX_METRIC_VALUE * sizeof(int32_t));\n\n\tfor (i = 0; i < DEPTH_MAX_METRIC_VALUE; i++) {\n\t\tdouble current_depth_in_pixels = i * pixel_size;\n\t\tdepth_to_rgb[i] = (( pixels_between_rgb_and_ir_cmos * (current_depth_in_pixels - reference_distance_in_pixels) / current_depth_in_pixels) + S2D_CONST_OFFSET) * REG_X_VAL_SCALE;\n\t}\n}\n\n// unrolled inner loop of the 11-bit unpacker\nstatic inline void unpack_8_pixels(uint8_t *raw, uint16_t *frame)\n{\n\tuint16_t baseMask = 0x7FF;\n\n\tuint8_t r0  = *(raw+0);\n\tuint8_t r1  = *(raw+1);\n\tuint8_t r2  = *(raw+2);\n\tuint8_t r3  = *(raw+3);\n\tuint8_t r4  = *(raw+4);\n\tuint8_t r5  = *(raw+5);\n\tuint8_t r6  = *(raw+6);\n\tuint8_t r7  = *(raw+7);\n\tuint8_t r8  = *(raw+8);\n\tuint8_t r9  = *(raw+9);\n\tuint8_t r10 = *(raw+10);\n\n\tframe[0] =  (r0<<3)  | (r1>>5);\n\tframe[1] = ((r1<<6)  | (r2>>2) )           & baseMask;\n\tframe[2] = ((r2<<9)  | (r3<<1) | (r4>>7) ) & baseMask;\n\tframe[3] = ((r4<<4)  | (r5>>4) )           & baseMask;\n\tframe[4] = ((r5<<7)  | (r6>>1) )           & baseMask;\n\tframe[5] = ((r6<<10) | (r7<<2) | (r8>>6) ) & baseMask;\n\tframe[6] = ((r8<<5)  | (r9>>3) )           & baseMask;\n\tframe[7] = ((r9<<8)  | (r10)   )           & baseMask;\n}\n\n// apply registration data to a single packed frame\nFN_INTERNAL int freenect_apply_registration(freenect_device* dev, uint8_t* input_packed, uint16_t* output_mm)\n{\n\tfreenect_registration* reg = &(dev->registration);\n\t// set output buffer to zero using pointer-sized memory access (~ 30-40% faster than memset)\n\tsize_t i, *wipe = (size_t*)output_mm;\n\tfor (i = 0; i < DEPTH_X_RES * DEPTH_Y_RES * sizeof(uint16_t) / sizeof(size_t); i++) wipe[i] = DEPTH_NO_MM_VALUE;\n\n\tuint16_t unpack[8];\n\n\tuint32_t target_offset = DEPTH_Y_RES * reg->reg_pad_info.start_lines;\n\tuint32_t x,y,source_index = 8;\n\n\tfor (y = 0; y < DEPTH_Y_RES; y++) {\n\t\tfor (x = 0; x < DEPTH_X_RES; x++) {\n\n\t\t\t// get 8 pixels from the packed frame\n\t\t\tif (source_index == 8) {\n\t\t\t\tunpack_8_pixels( input_packed, unpack );\n\t\t\t\tsource_index = 0;\n\t\t\t\tinput_packed += 11;\n\t\t\t}\n\n\t\t\t// get the value at the current depth pixel, convert to millimeters\n\t\t\tuint16_t metric_depth = reg->raw_to_mm_shift[ unpack[source_index++] ];\n\n\t\t\t// so long as the current pixel has a depth value\n\t\t\tif (metric_depth == DEPTH_NO_MM_VALUE) continue;\n\t\t\tif (metric_depth >= DEPTH_MAX_METRIC_VALUE) continue;\n\n\t\t\t// calculate the new x and y location for that pixel\n\t\t\t// using registration_table for the basic rectification\n\t\t\t// and depth_to_rgb_shift for determining the x shift\n\t\t\tuint32_t reg_index = DEPTH_MIRROR_X ? ((y + 1) * DEPTH_X_RES - x - 1) : (y * DEPTH_X_RES + x);\n\t\t\tuint32_t nx = (reg->registration_table[reg_index][0] + reg->depth_to_rgb_shift[metric_depth]) / REG_X_VAL_SCALE;\n\t\t\tuint32_t ny =  reg->registration_table[reg_index][1];\n\n\t\t\t// ignore anything outside the image bounds\n\t\t\tif (nx >= DEPTH_X_RES) continue;\n\n\t\t\t// convert nx, ny to an index in the depth image array\n\t\t\tuint32_t target_index = (DEPTH_MIRROR_X ? ((ny + 1) * DEPTH_X_RES - nx - 1) : (ny * DEPTH_X_RES + nx)) - target_offset;\n\n\t\t\t// get the current value at the new location\n\t\t\tuint16_t current_depth = output_mm[target_index];\n\n\t\t\t// make sure the new location is empty, or the new value is closer\n\t\t\tif ((current_depth == DEPTH_NO_MM_VALUE) || (current_depth > metric_depth)) {\n\t\t\t\toutput_mm[target_index] = metric_depth; // always save depth at current location\n\n\t\t\t\t#ifdef DENSE_REGISTRATION\n\t\t\t\t\t// if we're not on the first row, or the first column\n\t\t\t\t\tif ((nx > 0) && (ny > 0)) {\n\t\t\t\t\t\toutput_mm[target_index - DEPTH_X_RES    ] = metric_depth; // save depth at (x,y-1)\n\t\t\t\t\t\toutput_mm[target_index - DEPTH_X_RES - 1] = metric_depth; // save depth at (x-1,y-1)\n\t\t\t\t\t\toutput_mm[target_index               - 1] = metric_depth; // save depth at (x-1,y)\n\t\t\t\t\t} else if (ny > 0) {\n\t\t\t\t\t\toutput_mm[target_index - DEPTH_X_RES] = metric_depth; // save depth at (x,y-1)\n\t\t\t\t\t} else if (nx > 0) {\n\t\t\t\t\t\toutput_mm[target_index - 1] = metric_depth; // save depth at (x-1,y)\n\t\t\t\t\t}\n\t\t\t\t#endif\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n\n// Same as freenect_apply_registration, but don't bother aligning to the RGB image\nFN_INTERNAL int freenect_apply_depth_to_mm(freenect_device* dev, uint8_t* input_packed, uint16_t* output_mm)\n{\n\tfreenect_registration* reg = &(dev->registration);\n\tuint16_t unpack[8];\n\tuint32_t x,y,source_index = 8;\n\tfor (y = 0; y < DEPTH_Y_RES; y++) {\n\t\tfor (x = 0; x < DEPTH_X_RES; x++) {\n\t\t\t// get 8 pixels from the packed frame\n\t\t\tif (source_index == 8) {\n\t\t\t\tunpack_8_pixels( input_packed, unpack );\n\t\t\t\tsource_index = 0;\n\t\t\t\tinput_packed += 11;\n\t\t\t}\n\t\t\t// get the value at the current depth pixel, convert to millimeters\n\t\t\tuint16_t metric_depth = reg->raw_to_mm_shift[ unpack[source_index++] ];\n\t\t\toutput_mm[y * DEPTH_X_RES + x] = metric_depth < DEPTH_MAX_METRIC_VALUE ? metric_depth : DEPTH_MAX_METRIC_VALUE;\n\t\t}\n\t}\n\treturn 0;\n}\n\n// create temporary x/y shift tables\nstatic void freenect_create_dxdy_tables(double* reg_x_table, double* reg_y_table, int32_t resolution_x, int32_t resolution_y, freenect_reg_info* regdata )\n{\n\n\tint64_t AX6 = regdata->ax;\n\tint64_t BX6 = regdata->bx;\n\tint64_t CX2 = regdata->cx;\n\tint64_t DX2 = regdata->dx;\n\n\tint64_t AY6 = regdata->ay;\n\tint64_t BY6 = regdata->by;\n\tint64_t CY2 = regdata->cy;\n\tint64_t DY2 = regdata->dy;\n\n\t// don't merge the shift operations - necessary for proper 32-bit clamping of extracted values\n\tint64_t dX0 = (regdata->dx_start << 13) >> 4;\n\tint64_t dY0 = (regdata->dy_start << 13) >> 4;\n\n\tint64_t dXdX0 = (regdata->dxdx_start << 11) >> 3;\n\tint64_t dXdY0 = (regdata->dxdy_start << 11) >> 3;\n\tint64_t dYdX0 = (regdata->dydx_start << 11) >> 3;\n\tint64_t dYdY0 = (regdata->dydy_start << 11) >> 3;\n\n\tint64_t dXdXdX0 = (regdata->dxdxdx_start << 5) << 3;\n\tint64_t dYdXdX0 = (regdata->dydxdx_start << 5) << 3;\n\tint64_t dYdXdY0 = (regdata->dydxdy_start << 5) << 3;\n\tint64_t dXdXdY0 = (regdata->dxdxdy_start << 5) << 3;\n\tint64_t dYdYdX0 = (regdata->dydydx_start << 5) << 3;\n\tint64_t dYdYdY0 = (regdata->dydydy_start << 5) << 3;\n\n\tint32_t row,col,tOffs = 0;\n\n\tfor (row = 0 ; row < resolution_y ; row++) {\n\n\t\tdXdXdX0 += CX2;\n\n\t\tdXdX0   += dYdXdX0 >> 8;\n\t\tdYdXdX0 += DX2;\n\n\t\tdX0     += dYdX0 >> 6;\n\t\tdYdX0   += dYdYdX0 >> 8;\n\t\tdYdYdX0 += BX6;\n\n\t\tdXdXdY0 += CY2;\n\n\t\tdXdY0   += dYdXdY0 >> 8;\n\t\tdYdXdY0 += DY2;\n\n\t\tdY0     += dYdY0 >> 6;\n\t\tdYdY0   += dYdYdY0 >> 8;\n\t\tdYdYdY0 += BY6;\n\n\t\tint64_t coldXdXdY0 = dXdXdY0, coldXdY0 = dXdY0, coldY0 = dY0;\n\n\t\tint64_t coldXdXdX0 = dXdXdX0, coldXdX0 = dXdX0, coldX0 = dX0;\n\n\t\tfor (col = 0 ; col < resolution_x ; col++, tOffs++) {\n\t\t\treg_x_table[tOffs] = coldX0 * (1.0/(1<<17));\n\t\t\treg_y_table[tOffs] = coldY0 * (1.0/(1<<17));\n\n\t\t\tcoldX0     += coldXdX0 >> 6;\n\t\t\tcoldXdX0   += coldXdXdX0 >> 8;\n\t\t\tcoldXdXdX0 += AX6;\n\n\t\t\tcoldY0     += coldXdY0 >> 6;\n\t\t\tcoldXdY0   += coldXdXdY0 >> 8;\n\t\t\tcoldXdXdY0 += AY6;\n\t\t}\n\t}\n}\n\nstatic void freenect_init_registration_table(int32_t (*registration_table)[2], freenect_reg_info* reg_info) {\n\n\tdouble* regtable_dx = (double*)malloc(DEPTH_X_RES*DEPTH_Y_RES*sizeof(double));\n\tdouble* regtable_dy = (double*)malloc(DEPTH_X_RES*DEPTH_Y_RES*sizeof(double));\n\tmemset(regtable_dx, 0, DEPTH_X_RES*DEPTH_Y_RES * sizeof(double));\n\tmemset(regtable_dy, 0, DEPTH_X_RES*DEPTH_Y_RES * sizeof(double));\n\tint32_t x,y,index = 0;\n\n\t// create temporary dx/dy tables\n\tfreenect_create_dxdy_tables( regtable_dx, regtable_dy, DEPTH_X_RES, DEPTH_Y_RES, reg_info );\n\n\tfor (y = 0; y < DEPTH_Y_RES; y++) {\n\t\tfor (x = 0; x < DEPTH_X_RES; x++, index++) {\n\t\t\tdouble new_x = x + regtable_dx[index] + DEPTH_X_OFFSET;\n\t\t\tdouble new_y = y + regtable_dy[index] + DEPTH_Y_OFFSET;\n\n\t\t\tif ((new_x < 0) || (new_y < 0) || (new_x >= DEPTH_X_RES) || (new_y >= DEPTH_Y_RES))\n\t\t\t\tnew_x = 2 * DEPTH_X_RES; // intentionally set value outside image bounds\n\n\t\t\tregistration_table[index][0] = new_x * REG_X_VAL_SCALE;\n\t\t\tregistration_table[index][1] = new_y;\n\t\t}\n\t}\n\tfree(regtable_dx);\n\tfree(regtable_dy);\n}\n\n// These are just constants.\nstatic double parameter_coefficient = 4;\nstatic double shift_scale = 10;\nstatic double pixel_size_factor = 1;\n\n/// convert raw shift value to metric depth (in mm)\nstatic uint16_t freenect_raw_to_mm(uint16_t raw, freenect_registration* reg)\n{\n\tfreenect_zero_plane_info* zpi = &(reg->zero_plane_info);\n\tdouble fixed_ref_x = ((raw - (parameter_coefficient * reg->const_shift / pixel_size_factor)) / parameter_coefficient) - S2D_CONST_OFFSET;\n\tdouble metric = fixed_ref_x * zpi->reference_pixel_size * pixel_size_factor;\n\treturn shift_scale * ((metric * zpi->reference_distance / (zpi->dcmos_emitter_dist - metric)) + zpi->reference_distance);\n}\n\n/// Compute registration tables.\nstatic void complete_tables(freenect_registration* reg) {\n\tuint16_t i;\n\tfor (i = 0; i < DEPTH_MAX_RAW_VALUE; i++)\n\t\treg->raw_to_mm_shift[i] = freenect_raw_to_mm( i, reg);\n\treg->raw_to_mm_shift[DEPTH_NO_RAW_VALUE] = DEPTH_NO_MM_VALUE;\n\n\tfreenect_init_depth_to_rgb( reg->depth_to_rgb_shift, &(reg->zero_plane_info) );\n\n\tfreenect_init_registration_table( reg->registration_table, &(reg->reg_info) );\n}\n\n/// camera -> world coordinate helper function\nvoid freenect_camera_to_world(freenect_device* dev, int cx, int cy, int wz, double* wx, double* wy)\n{\n\tdouble ref_pix_size = dev->registration.zero_plane_info.reference_pixel_size;\n\tdouble ref_distance = dev->registration.zero_plane_info.reference_distance;\n\t// We multiply cx and cy by these factors because they come from a 640x480 image,\n\t// but the zero plane pixel size is for a 1280x1024 image.\n\t// However, the 640x480 image is produced by cropping the 1280x1024 image\n\t// to 1280x960 and then scaling by .5, so aspect ratio is maintained, and\n\t// we should simply multiply by two in each dimension.\n\tdouble factor = 2 * ref_pix_size * wz / ref_distance;\n\t*wx = (double)(cx - DEPTH_X_RES/2) * factor;\n\t*wy = (double)(cy - DEPTH_Y_RES/2) * factor;\n}\n\n/// Allocate and fill registration tables\n/// This function should be called every time a new video (not depth!) mode is\n/// activated.\nFN_INTERNAL int freenect_init_registration(freenect_device* dev)\n{\n\tfreenect_registration* reg = &(dev->registration);\n\n\t// Ensure that we free the previous tables before dropping the pointers, if there were any.\n\tfreenect_destroy_registration(&(dev->registration));\n\n\t// Allocate tables.\n\treg->raw_to_mm_shift    = (uint16_t*)malloc( sizeof(uint16_t) * DEPTH_MAX_RAW_VALUE );\n\treg->depth_to_rgb_shift = (int32_t*)malloc( sizeof( int32_t) * DEPTH_MAX_METRIC_VALUE );\n\treg->registration_table = (int32_t (*)[2])malloc( sizeof( int32_t) * DEPTH_X_RES * DEPTH_Y_RES * 2 );\n\n\t// Fill tables.\n\tcomplete_tables(reg);\n\n\treturn 0;\n}\n\nfreenect_registration freenect_copy_registration(freenect_device* dev)\n{\n\tfreenect_registration retval;\n\tretval.reg_info = dev->registration.reg_info;\n\tretval.reg_pad_info = dev->registration.reg_pad_info;\n\tretval.zero_plane_info = dev->registration.zero_plane_info;\n\tretval.const_shift = dev->registration.const_shift;\n\tretval.raw_to_mm_shift    = (uint16_t*)malloc( sizeof(uint16_t) * DEPTH_MAX_RAW_VALUE );\n\tretval.depth_to_rgb_shift = (int32_t*)malloc( sizeof( int32_t) * DEPTH_MAX_METRIC_VALUE );\n\tretval.registration_table = (int32_t (*)[2])malloc( sizeof( int32_t) * DEPTH_X_RES * DEPTH_Y_RES * 2 );\n\tcomplete_tables(&retval);\n\treturn retval;\n}\n\nint freenect_destroy_registration(freenect_registration* reg)\n{\n\tif (reg->raw_to_mm_shift) {\n\t\tfree(reg->raw_to_mm_shift);\n\t\treg->raw_to_mm_shift = NULL;\n\t}\n\tif (reg->depth_to_rgb_shift) {\n\t\tfree(reg->depth_to_rgb_shift);\n\t\treg->depth_to_rgb_shift = NULL;\n\t}\n\tif (reg->registration_table) {\n\t\tfree(reg->registration_table);\n\t\treg->registration_table = NULL;\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "libs/libfreenect/src/registration.h",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2011 individual OpenKinect contributors. See the CONTRIB\n * file for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#ifndef REGISTRATION_H\n#define REGISTRATION_H\n\n#include \"libfreenect.h\"\n\n// Internal function declarations relating to registration\nint freenect_init_registration(freenect_device* dev);\nint freenect_apply_registration(freenect_device* dev, uint8_t* input_packed, uint16_t* output_mm);\nint freenect_apply_depth_to_mm(freenect_device* dev, uint8_t* input_packed, uint16_t* output_mm);\n\n#endif\n"
  },
  {
    "path": "libs/libfreenect/src/tilt.c",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <math.h>\n\n#include \"freenect_internal.h\"\n\n// The kinect can tilt from +31 to -31 degrees in what looks like 1 degree increments\n// The control input looks like 2*desired_degrees\n#define MAX_TILT_ANGLE 31\n#define MIN_TILT_ANGLE (-31)\n\n#define GRAVITY 9.80665\n\nfreenect_raw_tilt_state* freenect_get_tilt_state(freenect_device *dev)\n{\n\treturn &dev->raw_state;\n}\n\nint freenect_update_tilt_state(freenect_device *dev)\n{\n\tfreenect_context *ctx = dev->parent;\n\n    uint8_t buf[10];\n\tuint16_t ux, uy, uz;\n    \n\tif(!(ctx->enabled_subdevices & FREENECT_DEVICE_MOTOR)){\n        //this is needed for OS X. without it the camera timesout within 2-3 seconds\n        #ifdef TARGET_OS_MAC\n    \tint ret = fnusb_control(&dev->usb_cam, 0xC0, 0x32, 0x0, 0x0, buf, 10);\n        #endif \n\t\treturn 0;\n\t}\n\n\tint ret = fnusb_control(&dev->usb_motor, 0xC0, 0x32, 0x0, 0x0, buf, 10);\n\tif (ret != 10) {\n\t\tFN_ERROR(\"Error in accelerometer reading, libusb_control_transfer returned %d\\n\", ret);\n\t\treturn ret < 0 ? ret : -1;\n\t}\n\n\tux = ((uint16_t)buf[2] << 8) | buf[3];\n\tuy = ((uint16_t)buf[4] << 8) | buf[5];\n\tuz = ((uint16_t)buf[6] << 8) | buf[7];\n\n\tdev->raw_state.accelerometer_x = (int16_t)ux;\n\tdev->raw_state.accelerometer_y = (int16_t)uy;\n\tdev->raw_state.accelerometer_z = (int16_t)uz;\n\tdev->raw_state.tilt_angle = (int8_t)buf[8];\n\tdev->raw_state.tilt_status = (freenect_tilt_status_code)buf[9];\n\n\treturn ret;\n}\nint freenect_set_tilt_degs(freenect_device *dev, double angle)\n{\n\tfreenect_context *ctx = dev->parent;\n\tif(!(ctx->enabled_subdevices & FREENECT_DEVICE_MOTOR))\n\t\treturn 0;\n\tint ret;\n\tuint8_t empty[0x1];\n\n\tangle = (angle<MIN_TILT_ANGLE) ? MIN_TILT_ANGLE : ((angle>MAX_TILT_ANGLE) ? MAX_TILT_ANGLE : angle);\n\tangle = angle * 2;\n\n\tret = fnusb_control(&dev->usb_motor, 0x40, 0x31, (uint16_t)angle, 0x0, empty, 0x0);\n\treturn ret;\n}\n\nint freenect_set_led(freenect_device *dev, freenect_led_options option)\n{\n\tfreenect_context *ctx = dev->parent;\n\tif(!(ctx->enabled_subdevices & FREENECT_DEVICE_MOTOR))\n\t\treturn 0;\n\tint ret;\n\tuint8_t empty[0x1];\n\tret = fnusb_control(&dev->usb_motor, 0x40, 0x06, (uint16_t)option, 0x0, empty, 0x0);\n\treturn ret;\n}\n\ndouble freenect_get_tilt_degs(freenect_raw_tilt_state *state)\n{\n\treturn ((double)state->tilt_angle) / 2.;\n}\n\nfreenect_tilt_status_code freenect_get_tilt_status(freenect_raw_tilt_state *state)\n{\n\treturn state->tilt_status;\n}\n\nvoid freenect_get_mks_accel(freenect_raw_tilt_state *state, double* x, double* y, double* z)\n{\n\t//the documentation for the accelerometer (http://www.kionix.com/Product%20Sheets/KXSD9%20Product%20Brief.pdf)\n\t//states there are 819 counts/g\n\t*x = (double)state->accelerometer_x/FREENECT_COUNTS_PER_G*GRAVITY;\n\t*y = (double)state->accelerometer_y/FREENECT_COUNTS_PER_G*GRAVITY;\n\t*z = (double)state->accelerometer_z/FREENECT_COUNTS_PER_G*GRAVITY;\n}\n"
  },
  {
    "path": "libs/libfreenect/src/usb_libusb10.c",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#include <stdio.h>\n#include <stdbool.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <libusb.h>\n#include \"freenect_internal.h\"\n#include \"loader.h\"\n\nFN_INTERNAL int fnusb_num_devices(fnusb_ctx *ctx)\n{\n\tlibusb_device **devs; \n\t//pointer to pointer of device, used to retrieve a list of devices\t\n\tssize_t cnt = libusb_get_device_list (ctx->ctx, &devs); \n\t//get the list of devices\t\n\tif (cnt < 0)\n\t\treturn (-1);\n\tint nr = 0, i = 0;\n\tstruct libusb_device_descriptor desc;\n\tfor (i = 0; i < cnt; ++i)\n\t{\n\t\tint r = libusb_get_device_descriptor (devs[i], &desc);\n\t\tif (r < 0)\n\t\t\tcontinue;\n\t\tif (desc.idVendor == VID_MICROSOFT && (desc.idProduct == PID_NUI_CAMERA || desc.idProduct == PID_K4W_CAMERA))\n\t\t\tnr++;\n\t}\n\tlibusb_free_device_list (devs, 1);\n\t// free the list, unref the devices in it\n\treturn nr;\n}\n\nFN_INTERNAL int fnusb_list_device_attributes(fnusb_ctx *ctx, struct freenect_device_attributes** attribute_list)\n{\n\t*attribute_list = NULL; // initialize some return value in case the user is careless.\n\tlibusb_device **devs;\n\t//pointer to pointer of device, used to retrieve a list of devices\n\tssize_t count = libusb_get_device_list (ctx->ctx, &devs);\n\tif (count < 0)\n\t\treturn -1;\n\n\tstruct freenect_device_attributes** camera_prev_next = attribute_list;\n\n\t// Pass over the list.  For each camera seen, if we already have a camera\n\t// for the newest_camera device, allocate a new one and append it to the list,\n\t// incrementing num_devs.  Likewise for each audio device.\n\tstruct libusb_device_descriptor desc;\n\tint num_cams = 0;\n\tint i;\n\tfor (i = 0; i < count; i++) {\n\t\tint r = libusb_get_device_descriptor (devs[i], &desc);\n\t\tif (r < 0)\n\t\t\tcontinue;\n\t\tif (desc.idVendor == VID_MICROSOFT && (desc.idProduct == PID_NUI_CAMERA || desc.idProduct == PID_K4W_CAMERA)) {\n\t\t\t// Verify that a serial number exists to query.  If not, don't touch the device.\n\t\t\tif (desc.iSerialNumber == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Open device.\n\t\t\tint res;\n\t\t\tlibusb_device_handle *this_device;\n\t\t\tres = libusb_open(devs[i], &this_device);\n\t\t\tunsigned char string_desc[256]; // String descriptors are at most 256 bytes.\n\t\t\tif (res != 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Read string descriptor referring to serial number.\n\t\t\tres = libusb_get_string_descriptor_ascii(this_device, desc.iSerialNumber, string_desc, 256);\n\t\t\tlibusb_close(this_device);\n\t\t\tif (res < 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Add item to linked list.\n\t\t\tstruct freenect_device_attributes* new_dev_attrs = (struct freenect_device_attributes*)malloc(sizeof(struct freenect_device_attributes));\n\t\t\tmemset(new_dev_attrs, 0, sizeof(*new_dev_attrs));\n\n\t\t\t*camera_prev_next = new_dev_attrs;\n\t\t\t// Copy string with serial number\n\t\t\tnew_dev_attrs->camera_serial = strdup((char*)string_desc);\n\t\t\tcamera_prev_next = &(new_dev_attrs->next);\n\t\t\t// Increment number of cameras found\n\t\t\tnum_cams++;\n\t\t}\n\t}\n\n\tlibusb_free_device_list(devs, 1);\n\treturn num_cams;\n}\n\nFN_INTERNAL int fnusb_init(fnusb_ctx *ctx, freenect_usb_context *usb_ctx)\n{\n\tint res;\n\tif (!usb_ctx) {\n\t\tres = libusb_init(&ctx->ctx);\n\t\tif (res >= 0) {\n\t\t\tctx->should_free_ctx = 1;\n\t\t\treturn 0;\n\t\t} else {\n\t\t\tctx->should_free_ctx = 0;\n\t\t\tctx->ctx = NULL;\n\t\t\treturn res;\n\t\t}\n\t} else {\n    // explicit cast required: in WIN32, freenect_usb_context* maps to void*\n    ctx->ctx = (libusb_context*)usb_ctx;\n\t\tctx->should_free_ctx = 0;\n\t\treturn 0;\n\t}\n}\n\nFN_INTERNAL int fnusb_shutdown(fnusb_ctx *ctx)\n{\n\t//int res;\n\tif (ctx->should_free_ctx) {\n\t\tlibusb_exit(ctx->ctx);\n\t\tctx->ctx = NULL;\n\t}\n\treturn 0;\n}\n\nFN_INTERNAL int fnusb_process_events(fnusb_ctx *ctx)\n{\n\treturn libusb_handle_events(ctx->ctx);\n}\n\nFN_INTERNAL int fnusb_process_events_timeout(fnusb_ctx *ctx, struct timeval* timeout)\n{\n\treturn libusb_handle_events_timeout(ctx->ctx, timeout);\n}\n\nFN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)\n{\n\tfreenect_context *ctx = dev->parent;\n\n\tdev->usb_cam.parent = dev;\n\tdev->usb_cam.dev = NULL;\n\tdev->usb_motor.parent = dev;\n\tdev->usb_motor.dev = NULL;\n#ifdef BUILD_AUDIO\n\tdev->usb_audio.parent = dev;\n\tdev->usb_audio.dev = NULL;\n#endif\n\n\tlibusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices\n\tssize_t cnt = libusb_get_device_list (dev->parent->usb.ctx, &devs); //get the list of devices\n\tif (cnt < 0)\n\t\treturn -1;\n\n\tint i = 0, nr_cam = 0, nr_mot = 0;\n#ifdef BUILD_AUDIO\n\tint nr_audio = 0;\n#endif\n\tint res;\n\tstruct libusb_device_descriptor desc;\n\n\tfor (i = 0; i < cnt; i++) {\n\t\tint r = libusb_get_device_descriptor (devs[i], &desc);\n\t\tif (r < 0)\n\t\t\tcontinue;\n\n\t\tif (desc.idVendor != VID_MICROSOFT)\n\t\t\tcontinue;\n\t\tres = 0;\n\t\t// Search for the camera\n\t\tif ((ctx->enabled_subdevices & FREENECT_DEVICE_CAMERA) && !dev->usb_cam.dev && (desc.idProduct == PID_NUI_CAMERA || desc.idProduct == PID_K4W_CAMERA)) {\n\t\t\t// If the index given by the user matches our camera index\n\t\t\tif (nr_cam == index) {\n\t\t\t\tres = libusb_open (devs[i], &dev->usb_cam.dev);\n\t\t\t\tif (res < 0 || !dev->usb_cam.dev) {\n\t\t\t\t\tFN_ERROR(\"Could not open camera: %d\\n\", res);\n\t\t\t\t\tdev->usb_cam.dev = NULL;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(desc.idProduct == PID_K4W_CAMERA || desc.bcdDevice != fn_le32(267)){\n\t\t\t\t\t/* Not the old kinect so we only set up the camera*/ \n\t\t\t\t\tctx->enabled_subdevices = FREENECT_DEVICE_CAMERA;\n\t\t\t\t\tctx->zero_plane_res = 334;\n\t\t\t\t}else{\n\t\t\t\t\t/* The good old kinect that tilts and tweets */\n\t\t\t\t\tctx->zero_plane_res = 322;\n\t\t\t\t}\n\t\t\t\t\n#ifndef _WIN32\n\t\t\t\t// Detach an existing kernel driver for the device\n\t\t\t\tres = libusb_kernel_driver_active(dev->usb_cam.dev, 0);\n\t\t\t\tif (res == 1) {\n\t\t\t\t\tres = libusb_detach_kernel_driver(dev->usb_cam.dev, 0);\n\t\t\t\t\tif (res < 0) {\n\t\t\t\t\t\tFN_ERROR(\"Could not detach kernel driver for camera: %d\\n\", res);\n\t\t\t\t\t\tlibusb_close(dev->usb_cam.dev);\n\t\t\t\t\t\tdev->usb_cam.dev = NULL;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n#endif\n\t\t\t\tres = libusb_claim_interface (dev->usb_cam.dev, 0);\n\t\t\t\tif (res < 0) {\n\t\t\t\t\tFN_ERROR(\"Could not claim interface on camera: %d\\n\", res);\n\t\t\t\t\tlibusb_close(dev->usb_cam.dev);\n\t\t\t\t\tdev->usb_cam.dev = NULL;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(desc.idProduct == PID_K4W_CAMERA){\n\t\t\t\t\tres = libusb_set_interface_alt_setting(dev->usb_cam.dev, 0, 1);\n         \t\t\t\tif (res != 0) {\n           \t\t\t\t\tFN_ERROR(\"Failed to set alternate interface #1 for K4W: %d\\n\", res);\n           \t\t\t\t\tlibusb_close(dev->usb_cam.dev);\n          \t\t\t\t\tdev->usb_cam.dev = NULL;\n           \t\t\t\t\tbreak;\n          \t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnr_cam++;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tif(ctx->enabled_subdevices == FREENECT_DEVICE_CAMERA || res < 0) cnt = 0;\n\t\n\t\t// Search for the motor\n\t\n\tfor (i = 0; i < cnt; i++) {\n\t\tint r = libusb_get_device_descriptor (devs[i], &desc);\n\t\tif (r < 0)\n\t\t\tcontinue;\n\n\t\tif (desc.idVendor != VID_MICROSOFT)\n\t\t\tcontinue;\n\t\tif ((ctx->enabled_subdevices & FREENECT_DEVICE_MOTOR) && !dev->usb_motor.dev && desc.idProduct == PID_NUI_MOTOR) {\n\t\t\t// If the index given by the user matches our camera index\n\t\t\tif (nr_mot == index) {\n\t\t\t\tres = libusb_open (devs[i], &dev->usb_motor.dev);\n\t\t\t\tif (res < 0 || !dev->usb_motor.dev) {\n\t\t\t\t\tFN_ERROR(\"Could not open motor: %d\\n\", res);\n\t\t\t\t\tdev->usb_motor.dev = NULL;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tres = libusb_claim_interface (dev->usb_motor.dev, 0);\n\t\t\t\tif (res < 0) {\n\t\t\t\t\tFN_ERROR(\"Could not claim interface on motor: %d\\n\", res);\n\t\t\t\t\tlibusb_close(dev->usb_motor.dev);\n\t\t\t\t\tdev->usb_motor.dev = NULL;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnr_mot++;\n\t\t\t}\n\t\t}\n\n#ifdef BUILD_AUDIO\n\t\t// TODO: check that the firmware has already been loaded; if not, upload firmware.\n\t\t// Search for the audio\n\t\tif ((ctx->enabled_subdevices & FREENECT_DEVICE_AUDIO) && !dev->usb_audio.dev && (desc.idProduct == PID_NUI_AUDIO || desc.idProduct == PID_K4W_AUDIO)) {\n\t\t\t// If the index given by the user matches our audio index\n\t\t\tif (nr_audio == index) {\n\t\t\t\tres = libusb_open (devs[i], &dev->usb_audio.dev);\n\t\t\t\tif (res < 0 || !dev->usb_audio.dev) {\n\t\t\t\t\tFN_ERROR(\"Could not open audio: %d\\n\", res);\n\t\t\t\t\tdev->usb_audio.dev = NULL;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tres = libusb_claim_interface (dev->usb_audio.dev, 0);\n\t\t\t\tif (res < 0) {\n\t\t\t\t\tFN_ERROR(\"Could not claim interface on audio: %d\\n\", res);\n\t\t\t\t\tlibusb_close(dev->usb_audio.dev);\n\t\t\t\t\tdev->usb_audio.dev = NULL;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// Using the device handle that we've claimed, see if this\n\t\t\t\t// device has already uploaded firmware (has 2 interfaces).  If\n\t\t\t\t// not, save the serial number (by reading the appropriate\n\t\t\t\t// descriptor), upload the firmware, and then enter a loop\n\t\t\t\t// waiting for a device with the same serial number to\n\t\t\t\t// reappear.\n\t\t\t\tint num_interfaces = fnusb_num_interfaces(&dev->usb_audio);\n\t\t\t\tif (num_interfaces == 1) {\n\t\t\t\t\t// Read the serial number from the string descriptor and save it.\n\t\t\t\t\tunsigned char string_desc[256]; // String descriptors are at most 256 bytes\n\t\t\t\t\tres = libusb_get_string_descriptor_ascii(dev->usb_audio.dev, desc.iSerialNumber, string_desc, 256);\n\t\t\t\t\tif (res < 0) {\n\t\t\t\t\t\tFN_ERROR(\"Failed to retrieve serial number for audio device in bootloader state\\n\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tchar* audio_serial = strdup((char*)string_desc);\n\n\t\t\t\t\tFN_SPEW(\"Uploading firmware to audio device in bootloader state.\\n\");\n\t\t\t\t\tres = upload_firmware(&dev->usb_audio);\n\t\t\t\t\tif (res < 0) {\n\t\t\t\t\t\tFN_ERROR(\"upload_firmware failed: %d\\n\", res);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tlibusb_close(dev->usb_audio.dev);\n\t\t\t\t\tdev->usb_audio.dev = NULL;\n\t\t\t\t\t// Wait for the device to reappear.\n\t\t\t\t\tint loops = 0;\n\t\t\t\t\tfor (loops = 0; loops < 10; loops++) { // Loop for at most 10 tries.\n\t\t\t\t\t\tFN_SPEW(\"Try %d: Looking for new audio device matching serial %s\\n\", loops, audio_serial);\n\t\t\t\t\t\t// Scan devices.\n\t\t\t\t\t\tlibusb_device **new_dev_list;\n\t\t\t\t\t\tint dev_index;\n\t\t\t\t\t\tssize_t num_new_devs = libusb_get_device_list(ctx->usb.ctx, &new_dev_list);\n\t\t\t\t\t\tfor (dev_index = 0; dev_index < num_new_devs; ++dev_index) {\n\t\t\t\t\t\t\tstruct libusb_device_descriptor new_dev_desc;\n\t\t\t\t\t\t\tint r;\n\t\t\t\t\t\t\tr = libusb_get_device_descriptor (new_dev_list[dev_index], &new_dev_desc);\n\t\t\t\t\t\t\tif (r < 0)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t// If this dev is a Kinect audio device, open device, read serial, and compare.\n\t\t\t\t\t\t\tif (new_dev_desc.idVendor == VID_MICROSOFT && new_dev_desc.idProduct == PID_NUI_AUDIO) {\n\t\t\t\t\t\t\t\tFN_SPEW(\"Matched VID/PID!\\n\");\n\t\t\t\t\t\t\t\tlibusb_device_handle* new_dev_handle;\n\t\t\t\t\t\t\t\t// Open device\n\t\t\t\t\t\t\t\tr = libusb_open(new_dev_list[dev_index], &new_dev_handle);\n\t\t\t\t\t\t\t\tif (r < 0)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t// Read serial\n\t\t\t\t\t\t\t\tr = libusb_get_string_descriptor_ascii(new_dev_handle, new_dev_desc.iSerialNumber, string_desc, 256);\n\t\t\t\t\t\t\t\tif (r < 0) {\n\t\t\t\t\t\t\t\t\tFN_SPEW(\"Lost new audio device while fetching serial number.\\n\");\n\t\t\t\t\t\t\t\t\tlibusb_close(new_dev_handle);\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Compare to expected serial\n\t\t\t\t\t\t\t\tif (r == strlen(audio_serial) && strcmp((char*)string_desc, audio_serial) == 0) {\n\t\t\t\t\t\t\t\t\t// We found it!\n\t\t\t\t\t\t\t\t\tr = libusb_claim_interface(new_dev_handle, 0);\n\t\t\t\t\t\t\t\t\tif (r != 0) {\n\t\t\t\t\t\t\t\t\t\t// Ouch, found the device but couldn't claim the interface.\n\t\t\t\t\t\t\t\t\t\tFN_SPEW(\"Device with serial %s reappeared but couldn't claim interface 0\\n\", audio_serial);\n\t\t\t\t\t\t\t\t\t\tlibusb_close(new_dev_handle);\n\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Save the device handle.\n\t\t\t\t\t\t\t\t\tdev->usb_audio.dev = new_dev_handle;\n\t\t\t\t\t\t\t\t\t// Verify that we've actually found a device running the right firmware.\n\t\t\t\t\t\t\t\t\tif (fnusb_num_interfaces(&dev->usb_audio) != 2) {\n\t\t\t\t\t\t\t\t\t\tFN_SPEW(\"Opened audio with matching serial but too few interfaces.\\n\");\n\t\t\t\t\t\t\t\t\t\tdev->usb_audio.dev = NULL;\n\t\t\t\t\t\t\t\t\t\tlibusb_close(new_dev_handle);\n\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tFN_SPEW(\"Got serial %s, expected serial %s\\n\", (char*)string_desc, audio_serial);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlibusb_free_device_list(new_dev_list, 1);\n\t\t\t\t\t\t// If we found the right device, break out of this loop.\n\t\t\t\t\t\tif (dev->usb_audio.dev)\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t// Sleep for a second to give the device more time to reenumerate.\n\t\t\t\t\t\tsleep(1);\n\t\t\t\t\t}\n\t\t\t\t\tfree(audio_serial);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnr_audio++;\n\t\t\t}\n\t\t}\n#endif\n\n\t}\n\n\tlibusb_free_device_list (devs, 1);  // free the list, unref the devices in it\n\n\t// Check that each subdevice is either opened or not enabled.\n\tif ( (dev->usb_cam.dev || !(ctx->enabled_subdevices & FREENECT_DEVICE_CAMERA))\n\t\t&& (dev->usb_motor.dev || !(ctx->enabled_subdevices & FREENECT_DEVICE_MOTOR))\n#ifdef BUILD_AUDIO\n\t\t&& (dev->usb_audio.dev || !(ctx->enabled_subdevices & FREENECT_DEVICE_AUDIO))\n#endif\n\t\t) {\n\t\treturn 0;\n\t} else {\n\t\tif (dev->usb_cam.dev) {\n\t\t\tlibusb_release_interface(dev->usb_cam.dev, 0);\n\t\t\tlibusb_close(dev->usb_cam.dev);\n\t\t}\n\t\tif (dev->usb_motor.dev) {\n\t\t\tlibusb_release_interface(dev->usb_motor.dev, 0);\n\t\t\tlibusb_close(dev->usb_motor.dev);\n\t\t}\n#ifdef BUILD_AUDIO\n\t\tif (dev->usb_audio.dev) {\n\t\t\tlibusb_release_interface(dev->usb_audio.dev, 0);\n\t\t\tlibusb_close(dev->usb_audio.dev);\n\t\t}\n#endif\n\t\treturn -1;\n\t}\n}\n\nFN_INTERNAL int fnusb_close_subdevices(freenect_device *dev)\n{\n\tif (dev->usb_cam.dev) {\n\t\tlibusb_release_interface(dev->usb_cam.dev, 0);\n#ifndef _WIN32\n\t\tlibusb_attach_kernel_driver(dev->usb_cam.dev, 0);\n#endif\n\t\tlibusb_close(dev->usb_cam.dev);\n\t\tdev->usb_cam.dev = NULL;\n\t}\n\tif (dev->usb_motor.dev) {\n\t\tlibusb_release_interface(dev->usb_motor.dev, 0);\n\t\tlibusb_close(dev->usb_motor.dev);\n\t\tdev->usb_motor.dev = NULL;\n\t}\n#ifdef BUILD_AUDIO\n\tif (dev->usb_audio.dev) {\n\t\tlibusb_release_interface(dev->usb_audio.dev, 0);\n\t\tlibusb_close(dev->usb_audio.dev);\n\t\tdev->usb_audio.dev = NULL;\n\t}\n#endif\n\treturn 0;\n}\n\nstatic void iso_callback(struct libusb_transfer *xfer)\n{\n\tint i;\n\tfnusb_isoc_stream *strm = (fnusb_isoc_stream*)xfer->user_data;\n\tfreenect_context *ctx = strm->parent->parent->parent;\n\n\tif (strm->dead) {\n\t\tstrm->dead_xfers++;\n\t\tFN_SPEW(\"EP %02x transfer complete, %d left\\n\", xfer->endpoint, strm->num_xfers - strm->dead_xfers);\n\t\treturn;\n\t}\n\n\tswitch(xfer->status) {\n\t\tcase LIBUSB_TRANSFER_COMPLETED: // Normal operation.\n\t\t{\n\t\t\tuint8_t *buf = (uint8_t*)xfer->buffer;\n\t\t\tfor (i=0; i<strm->pkts; i++) {\n\t\t\t\tstrm->cb(strm->parent->parent, buf, xfer->iso_packet_desc[i].actual_length);\n\t\t\t\tbuf += strm->len;\n\t\t\t}\n\t\t\tint res;\n\t\t\tres = libusb_submit_transfer(xfer);\n\t\t\tif (res != 0) {\n\t\t\t\tFN_ERROR(\"iso_callback(): failed to resubmit transfer after successful completion: %d\\n\", res);\n\t\t\t\tstrm->dead_xfers++;\n\t\t\t\tif (res == LIBUSB_ERROR_NO_DEVICE) {\n\t\t\t\t\tstrm->parent->device_dead = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase LIBUSB_TRANSFER_NO_DEVICE:\n\t\t{\n\t\t\t// We lost the device we were talking to.  This is a large problem,\n\t\t\t// and one that we should eventually come up with a way to\n\t\t\t// properly propagate up to the caller.\n\t\t\tif(!strm->parent->device_dead) {\n\t\t\t\tFN_ERROR(\"USB device disappeared, cancelling stream %02x :(\\n\", xfer->endpoint);\n\t\t\t}\n\t\t\tstrm->dead_xfers++;\n\t\t\tstrm->parent->device_dead = 1;\n\t\t\tbreak;\n\t\t}\n\t\tcase LIBUSB_TRANSFER_CANCELLED:\n\t\t{\n\t\t\tif(strm->dead) {\n\t\t\t\tFN_SPEW(\"EP %02x transfer cancelled\\n\", xfer->endpoint);\n\t\t\t} else {\n\t\t\t\t// This seems to be a libusb bug on OSX - instead of completing\n\t\t\t\t// the transfer with LIBUSB_TRANSFER_NO_DEVICE, the transfers\n\t\t\t\t// simply come back cancelled by the OS.  We can detect this,\n\t\t\t\t// though - the stream should be marked dead if we're\n\t\t\t\t// intentionally cancelling transfers.\n\t\t\t\tif(!strm->parent->device_dead) {\n\t\t\t\t\tFN_ERROR(\"Got cancelled transfer, but we didn't request it - device disconnected?\\n\");\n\t\t\t\t}\n\t\t\t\tstrm->parent->device_dead = 1;\n\t\t\t}\n\t\t\tstrm->dead_xfers++;\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t{\n\t\t\t// On other errors, resubmit the transfer - in particular, libusb\n\t\t\t// on OSX tends to hit random errors a lot.  If we don't resubmit\n\t\t\t// the transfers, eventually all of them die and then we don't get\n\t\t\t// any more data from the Kinect.\n\t\t\tFN_WARNING(\"Isochronous transfer error: %d\\n\", xfer->status);\n\t\t\tint res;\n\t\t\tres = libusb_submit_transfer(xfer);\n\t\t\tif (res != 0) {\n\t\t\t\tFN_ERROR(\"Isochronous transfer resubmission failed after unknown error: %d\\n\", res);\n\t\t\t\tstrm->dead_xfers++;\n\t\t\t\tif (res == LIBUSB_ERROR_NO_DEVICE) {\n\t\t\t\t\tstrm->parent->device_dead = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nFN_INTERNAL int fnusb_start_iso(fnusb_dev *dev, fnusb_isoc_stream *strm, fnusb_iso_cb cb, int ep, int xfers, int pkts, int len)\n{\n\tfreenect_context *ctx = dev->parent->parent;\n\tint ret, i;\n\n\tstrm->parent = dev;\n\tstrm->cb = cb;\n\tstrm->num_xfers = xfers;\n\tstrm->pkts = pkts;\n\tstrm->len = len;\n\tstrm->buffer = (uint8_t*)malloc(xfers * pkts * len);\n\tstrm->xfers = (struct libusb_transfer**)malloc(sizeof(struct libusb_transfer*) * xfers);\n\tstrm->dead = 0;\n\tstrm->dead_xfers = 0;\n\n\tuint8_t *bufp = strm->buffer;\n\n\tfor (i=0; i<xfers; i++) {\n\t\tFN_SPEW(\"Creating EP %02x transfer #%d\\n\", ep, i);\n\t\tstrm->xfers[i] = libusb_alloc_transfer(pkts);\n\n\t\tlibusb_fill_iso_transfer(strm->xfers[i], dev->dev, ep, bufp, pkts * len, pkts, iso_callback, strm, 0);\n\n\t\tlibusb_set_iso_packet_lengths(strm->xfers[i], len);\n\n\t\tret = libusb_submit_transfer(strm->xfers[i]);\n\t\tif (ret < 0) {\n\t\t\tFN_WARNING(\"Failed to submit isochronous transfer %d: %d\\n\", i, ret);\n\t\t\tstrm->dead_xfers++;\n\t\t}\n\n\t\tbufp += pkts*len;\n\t}\n\n\treturn 0;\n\n}\n\nFN_INTERNAL int fnusb_stop_iso(fnusb_dev *dev, fnusb_isoc_stream *strm)\n{\n\tfreenect_context *ctx = dev->parent->parent;\n\tint i;\n\n\tFN_FLOOD(\"fnusb_stop_iso() called\\n\");\n\n\tstrm->dead = 1;\n\n\tfor (i=0; i<strm->num_xfers; i++)\n\t\tlibusb_cancel_transfer(strm->xfers[i]);\n\tFN_FLOOD(\"fnusb_stop_iso() cancelled all transfers\\n\");\n\n\twhile (strm->dead_xfers < strm->num_xfers) {\n\t\tFN_FLOOD(\"fnusb_stop_iso() dead = %d\\tnum = %d\\n\", strm->dead_xfers, strm->num_xfers);\n\t\tlibusb_handle_events(ctx->usb.ctx);\n\t}\n\n\tfor (i=0; i<strm->num_xfers; i++)\n\t\tlibusb_free_transfer(strm->xfers[i]);\n\tFN_FLOOD(\"fnusb_stop_iso() freed all transfers\\n\");\n\n\tfree(strm->buffer);\n\tfree(strm->xfers);\n\n\tFN_FLOOD(\"fnusb_stop_iso() freed buffers and stream\\n\");\n\tmemset(strm, 0, sizeof(*strm));\n\tFN_FLOOD(\"fnusb_stop_iso() done\\n\");\n\treturn 0;\n}\n\nFN_INTERNAL int fnusb_control(fnusb_dev *dev, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t *data, uint16_t wLength)\n{\n\treturn libusb_control_transfer(dev->dev, bmRequestType, bRequest, wValue, wIndex, data, wLength, 0);\n}\n\n#ifdef BUILD_AUDIO\nFN_INTERNAL int fnusb_bulk(fnusb_dev *dev, uint8_t endpoint, uint8_t *data, int len, int *transferred) {\n\t*transferred = 0;\n\treturn libusb_bulk_transfer(dev->dev, endpoint, data, len, transferred, 0);\n}\n\nFN_INTERNAL int fnusb_num_interfaces(fnusb_dev *dev) {\n\tint retval = 0;\n\tint res;\n\tlibusb_device* d = libusb_get_device(dev->dev);\n\tstruct libusb_config_descriptor* config;\n\tres = libusb_get_active_config_descriptor(d, &config);\n\tif (res < 0) // Something went wrong\n\t\treturn res;\n\tretval = config->bNumInterfaces;\n\tlibusb_free_config_descriptor(config);\n\treturn retval;\n}\n#endif\n"
  },
  {
    "path": "libs/libfreenect/src/usb_libusb10.h",
    "content": "/*\n * This file is part of the OpenKinect Project. http://www.openkinect.org\n *\n * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file\n * for details.\n *\n * This code is licensed to you under the terms of the Apache License, version\n * 2.0, or, at your option, the terms of the GNU General Public License,\n * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,\n * or the following URLs:\n * http://www.apache.org/licenses/LICENSE-2.0\n * http://www.gnu.org/licenses/gpl-2.0.txt\n *\n * If you redistribute this file in source form, modified or unmodified, you\n * may:\n *   1) Leave this header intact and distribute it under the same terms,\n *      accompanying it with the APACHE20 and GPL20 files, or\n *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or\n *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file\n * In all cases you must keep the copyright notice intact and include a copy\n * of the CONTRIB file.\n *\n * Binary distributions must follow the binary distribution requirements of\n * either License.\n */\n\n#ifndef USB_LIBUSB10\n#define USB_LIBUSB10\n\n#include \"libfreenect.h\"\n#include <libusb.h>\n\n#if defined(__APPLE__)\n/*\n  From Github Issue 22 by Roefer -\n  https://github.com/OpenKinect/libfreenect/issues/#issue/22\n\n  The current implementation still does not reach 30 Hz on MacOS. This\n  is due to bad scheduling of USB transfers in libusb (Ed Note: libusb\n  1.0.8). A fix can be found at\n  http://www.informatik.uni-bremen.de/~roefer/libusb/libusb-osx-kinect.diff\n\n  (Ed Note: patch applies to libusb repo at 7da756e09fd)\n\n  In camera.c, I use PKTS_PER_XFER = 128, NUM_XFERS = 4. There are a\n  few rules: PKTS_PER_XFER * NUM_XFERS <= 1000, PKTS_PER_XFER % 8 == 0.\n*/\n#define PKTS_PER_XFER 128\n#define NUM_XFERS 4\n#define DEPTH_PKTBUF 2048\n#define VIDEO_PKTBUF 2048\n#else\n#ifdef _WIN32\n  #define PKTS_PER_XFER 32\n  #define NUM_XFERS 8\n#else\n  #define PKTS_PER_XFER 16\n  #define NUM_XFERS 16\n#endif\n#define DEPTH_PKTBUF 1920\n#define VIDEO_PKTBUF 1920\n#endif\n\ntypedef struct {\n\tlibusb_context *ctx;\n\tint should_free_ctx;\n} fnusb_ctx;\n\ntypedef struct {\n\tfreenect_device *parent; //so we can go up from the libusb userdata\n\tlibusb_device_handle *dev;\n\tint device_dead; // set to 1 when the underlying libusb_device_handle vanishes (ie, Kinect was unplugged)\n} fnusb_dev;\n\ntypedef struct {\n\tfnusb_dev *parent; //so we can go up from the libusb userdata\n\tstruct libusb_transfer **xfers;\n\tuint8_t *buffer;\n\tfnusb_iso_cb cb;\n\tint num_xfers;\n\tint pkts;\n\tint len;\n\tint dead;\n\tint dead_xfers;\n} fnusb_isoc_stream;\n\nint fnusb_num_devices(fnusb_ctx *ctx);\nint fnusb_list_device_attributes(fnusb_ctx *ctx, struct freenect_device_attributes** attribute_list);\n\nint fnusb_init(fnusb_ctx *ctx, freenect_usb_context *usb_ctx);\nint fnusb_shutdown(fnusb_ctx *ctx);\nint fnusb_process_events(fnusb_ctx *ctx);\nint fnusb_process_events_timeout(fnusb_ctx *ctx, struct timeval* timeout);\n\nint fnusb_open_subdevices(freenect_device *dev, int index);\nint fnusb_close_subdevices(freenect_device *dev);\n\nint fnusb_start_iso(fnusb_dev *dev, fnusb_isoc_stream *strm, fnusb_iso_cb cb, int ep, int xfers, int pkts, int len);\nint fnusb_stop_iso(fnusb_dev *dev, fnusb_isoc_stream *strm);\n\nint fnusb_control(fnusb_dev *dev, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t *data, uint16_t wLength);\n#ifdef BUILD_AUDIO\nint fnusb_bulk(fnusb_dev *dev, uint8_t endpoint, uint8_t *data, int len, int *transferred);\nint fnusb_num_interfaces(fnusb_dev *dev);\n#endif\n\n#endif\n"
  },
  {
    "path": "libs/libusb-1.0/include/libusb-1.0/libusb.h",
    "content": "/*\n * Public libusb header file\n * Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>\n * Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n */\n\n#ifndef __LIBUSB_H__\n#define __LIBUSB_H__\n\n/* MSVC doesn't like inline, but does accept __inline ?? */\n#ifdef _MSC_VER\n#define inline __inline\n#endif\n\n#include <stdint.h>\n#include <sys/types.h>\n#include <time.h>\n#include <limits.h>\n\n#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)\n#include <sys/time.h>\n#endif\n\n/* 'interface' might be defined as a macro on Windows, so we need to\n * undefine it so as not to break the current libusb API, because\n * libusb_config_descriptor has an 'interface' member\n * As this can be problematic if you include windows.h after libusb.h\n * in your sources, we force windows.h to be included first. */\n#if defined(_WIN32) || defined(__CYGWIN__)\n#include <windows.h>\n#if defined(interface)\n#undef interface\n#endif\n#endif\n\n/** \\def LIBUSB_CALL\n * \\ingroup misc\n * libusb's Windows calling convention.\n *\n * Under Windows, the selection of available compilers and configurations\n * means that, unlike other platforms, there is not <em>one true calling\n * convention</em> (calling convention: the manner in which parameters are\n * passed to funcions in the generated assembly code).\n *\n * Matching the Windows API itself, libusb uses the WINAPI convention (which\n * translates to the <tt>stdcall</tt> convention) and guarantees that the\n * library is compiled in this way. The public header file also includes\n * appropriate annotations so that your own software will use the right\n * convention, even if another convention is being used by default within\n * your codebase.\n *\n * The one consideration that you must apply in your software is to mark\n * all functions which you use as libusb callbacks with this LIBUSB_CALL\n * annotation, so that they too get compiled for the correct calling\n * convention.\n *\n * On non-Windows operating systems, this macro is defined as nothing. This\n * means that you can apply it to your code without worrying about\n * cross-platform compatibility.\n */\n/* LIBUSB_CALL must be defined on both definition and declaration of libusb\n * functions. You'd think that declaration would be enough, but cygwin will\n * complain about conflicting types unless both are marked this way.\n * The placement of this macro is important too; it must appear after the\n * return type, before the function name. See internal documentation for\n * API_EXPORTED.\n */\n#if defined(_WIN32) || defined(__CYGWIN__)\n#define LIBUSB_CALL WINAPI\n#else\n#define LIBUSB_CALL\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/** \\def libusb_cpu_to_le16\n * \\ingroup misc\n * Convert a 16-bit value from host-endian to little-endian format. On\n * little endian systems, this function does nothing. On big endian systems,\n * the bytes are swapped.\n * \\param x the host-endian value to convert\n * \\returns the value in little-endian byte order\n */\nstatic inline uint16_t libusb_cpu_to_le16(const uint16_t x)\n{\n\tunion {\n\t\tuint8_t  b8[2];\n\t\tuint16_t b16;\n\t} _tmp;\n\t_tmp.b8[1] = x >> 8;\n\t_tmp.b8[0] = x & 0xff;\n\treturn _tmp.b16;\n}\n\n/** \\def libusb_le16_to_cpu\n * \\ingroup misc\n * Convert a 16-bit value from little-endian to host-endian format. On\n * little endian systems, this function does nothing. On big endian systems,\n * the bytes are swapped.\n * \\param x the little-endian value to convert\n * \\returns the value in host-endian byte order\n */\n#define libusb_le16_to_cpu libusb_cpu_to_le16\n\n/* standard USB stuff */\n\n/** \\ingroup desc\n * Device and/or Interface Class codes */\nenum libusb_class_code {\n\t/** In the context of a \\ref libusb_device_descriptor \"device descriptor\",\n\t * this bDeviceClass value indicates that each interface specifies its\n\t * own class information and all interfaces operate independently.\n\t */\n\tLIBUSB_CLASS_PER_INTERFACE = 0,\n\n\t/** Audio class */\n\tLIBUSB_CLASS_AUDIO = 1,\n\n\t/** Communications class */\n\tLIBUSB_CLASS_COMM = 2,\n\n\t/** Human Interface Device class */\n\tLIBUSB_CLASS_HID = 3,\n\n\t/** Printer dclass */\n\tLIBUSB_CLASS_PRINTER = 7,\n\n\t/** Picture transfer protocol class */\n\tLIBUSB_CLASS_PTP = 6,\n\n\t/** Mass storage class */\n\tLIBUSB_CLASS_MASS_STORAGE = 8,\n\n\t/** Hub class */\n\tLIBUSB_CLASS_HUB = 9,\n\n\t/** Data class */\n\tLIBUSB_CLASS_DATA = 10,\n\n\t/** Wireless class */\n\tLIBUSB_CLASS_WIRELESS = 0xe0,\n\n\t/** Application class */\n\tLIBUSB_CLASS_APPLICATION = 0xfe,\n\n\t/** Class is vendor-specific */\n\tLIBUSB_CLASS_VENDOR_SPEC = 0xff\n};\n\n/** \\ingroup desc\n * Descriptor types as defined by the USB specification. */\nenum libusb_descriptor_type {\n\t/** Device descriptor. See libusb_device_descriptor. */\n\tLIBUSB_DT_DEVICE = 0x01,\n\n\t/** Configuration descriptor. See libusb_config_descriptor. */\n\tLIBUSB_DT_CONFIG = 0x02,\n\n\t/** String descriptor */\n\tLIBUSB_DT_STRING = 0x03,\n\n\t/** Interface descriptor. See libusb_interface_descriptor. */\n\tLIBUSB_DT_INTERFACE = 0x04,\n\n\t/** Endpoint descriptor. See libusb_endpoint_descriptor. */\n\tLIBUSB_DT_ENDPOINT = 0x05,\n\n\t/** HID descriptor */\n\tLIBUSB_DT_HID = 0x21,\n\n\t/** HID report descriptor */\n\tLIBUSB_DT_REPORT = 0x22,\n\n\t/** Physical descriptor */\n\tLIBUSB_DT_PHYSICAL = 0x23,\n\n\t/** Hub descriptor */\n\tLIBUSB_DT_HUB = 0x29\n};\n\n/* Descriptor sizes per descriptor type */\n#define LIBUSB_DT_DEVICE_SIZE\t\t\t18\n#define LIBUSB_DT_CONFIG_SIZE\t\t\t9\n#define LIBUSB_DT_INTERFACE_SIZE\t\t9\n#define LIBUSB_DT_ENDPOINT_SIZE\t\t7\n#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE\t9\t/* Audio extension */\n#define LIBUSB_DT_HUB_NONVAR_SIZE\t\t7\n\n#define LIBUSB_ENDPOINT_ADDRESS_MASK\t0x0f    /* in bEndpointAddress */\n#define LIBUSB_ENDPOINT_DIR_MASK\t\t0x80\n\n/** \\ingroup desc\n * Endpoint direction. Values for bit 7 of the\n * \\ref libusb_endpoint_descriptor::bEndpointAddress \"endpoint address\" scheme.\n */\nenum libusb_endpoint_direction {\n\t/** In: device-to-host */\n\tLIBUSB_ENDPOINT_IN = 0x80,\n\n\t/** Out: host-to-device */\n\tLIBUSB_ENDPOINT_OUT = 0x00\n};\n\n#define LIBUSB_TRANSFER_TYPE_MASK\t\t\t0x03    /* in bmAttributes */\n\n/** \\ingroup desc\n * Endpoint transfer type. Values for bits 0:1 of the\n * \\ref libusb_endpoint_descriptor::bmAttributes \"endpoint attributes\" field.\n */\nenum libusb_transfer_type {\n\t/** Control endpoint */\n\tLIBUSB_TRANSFER_TYPE_CONTROL = 0,\n\n\t/** Isochronous endpoint */\n\tLIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,\n\n\t/** Bulk endpoint */\n\tLIBUSB_TRANSFER_TYPE_BULK = 2,\n\n\t/** Interrupt endpoint */\n\tLIBUSB_TRANSFER_TYPE_INTERRUPT = 3\n};\n\n/** \\ingroup misc\n * Standard requests, as defined in table 9-3 of the USB2 specifications */\nenum libusb_standard_request {\n\t/** Request status of the specific recipient */\n\tLIBUSB_REQUEST_GET_STATUS = 0x00,\n\n\t/** Clear or disable a specific feature */\n\tLIBUSB_REQUEST_CLEAR_FEATURE = 0x01,\n\n\t/* 0x02 is reserved */\n\n\t/** Set or enable a specific feature */\n\tLIBUSB_REQUEST_SET_FEATURE = 0x03,\n\n\t/* 0x04 is reserved */\n\n\t/** Set device address for all future accesses */\n\tLIBUSB_REQUEST_SET_ADDRESS = 0x05,\n\n\t/** Get the specified descriptor */\n\tLIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,\n\n\t/** Used to update existing descriptors or add new descriptors */\n\tLIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,\n\n\t/** Get the current device configuration value */\n\tLIBUSB_REQUEST_GET_CONFIGURATION = 0x08,\n\n\t/** Set device configuration */\n\tLIBUSB_REQUEST_SET_CONFIGURATION = 0x09,\n\n\t/** Return the selected alternate setting for the specified interface */\n\tLIBUSB_REQUEST_GET_INTERFACE = 0x0A,\n\n\t/** Select an alternate interface for the specified interface */\n\tLIBUSB_REQUEST_SET_INTERFACE = 0x0B,\n\n\t/** Set then report an endpoint's synchronization frame */\n\tLIBUSB_REQUEST_SYNCH_FRAME = 0x0C\n};\n\n/** \\ingroup misc\n * Request type bits of the\n * \\ref libusb_control_setup::bmRequestType \"bmRequestType\" field in control\n * transfers. */\nenum libusb_request_type {\n\t/** Standard */\n\tLIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),\n\n\t/** Class */\n\tLIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),\n\n\t/** Vendor */\n\tLIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),\n\n\t/** Reserved */\n\tLIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)\n};\n\n/** \\ingroup misc\n * Recipient bits of the\n * \\ref libusb_control_setup::bmRequestType \"bmRequestType\" field in control\n * transfers. Values 4 through 31 are reserved. */\nenum libusb_request_recipient {\n\t/** Device */\n\tLIBUSB_RECIPIENT_DEVICE = 0x00,\n\n\t/** Interface */\n\tLIBUSB_RECIPIENT_INTERFACE = 0x01,\n\n\t/** Endpoint */\n\tLIBUSB_RECIPIENT_ENDPOINT = 0x02,\n\n\t/** Other */\n\tLIBUSB_RECIPIENT_OTHER = 0x03\n};\n\n#define LIBUSB_ISO_SYNC_TYPE_MASK\t\t0x0C\n\n/** \\ingroup desc\n * Synchronization type for isochronous endpoints. Values for bits 2:3 of the\n * \\ref libusb_endpoint_descriptor::bmAttributes \"bmAttributes\" field in\n * libusb_endpoint_descriptor.\n */\nenum libusb_iso_sync_type {\n\t/** No synchronization */\n\tLIBUSB_ISO_SYNC_TYPE_NONE = 0,\n\n\t/** Asynchronous */\n\tLIBUSB_ISO_SYNC_TYPE_ASYNC = 1,\n\n\t/** Adaptive */\n\tLIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,\n\n\t/** Synchronous */\n\tLIBUSB_ISO_SYNC_TYPE_SYNC = 3\n};\n\n#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30\n\n/** \\ingroup desc\n * Usage type for isochronous endpoints. Values for bits 4:5 of the\n * \\ref libusb_endpoint_descriptor::bmAttributes \"bmAttributes\" field in\n * libusb_endpoint_descriptor.\n */\nenum libusb_iso_usage_type {\n\t/** Data endpoint */\n\tLIBUSB_ISO_USAGE_TYPE_DATA = 0,\n\n\t/** Feedback endpoint */\n\tLIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,\n\n\t/** Implicit feedback Data endpoint */\n\tLIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2\n};\n\n/** \\ingroup desc\n * A structure representing the standard USB device descriptor. This\n * descriptor is documented in section 9.6.1 of the USB 2.0 specification.\n * All multiple-byte fields are represented in host-endian format.\n */\nstruct libusb_device_descriptor {\n\t/** Size of this descriptor (in bytes) */\n\tuint8_t  bLength;\n\n\t/** Descriptor type. Will have value\n\t * \\ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this\n\t * context. */\n\tuint8_t  bDescriptorType;\n\n\t/** USB specification release number in binary-coded decimal. A value of\n\t * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */\n\tuint16_t bcdUSB;\n\n\t/** USB-IF class code for the device. See \\ref libusb_class_code. */\n\tuint8_t  bDeviceClass;\n\n\t/** USB-IF subclass code for the device, qualified by the bDeviceClass\n\t * value */\n\tuint8_t  bDeviceSubClass;\n\n\t/** USB-IF protocol code for the device, qualified by the bDeviceClass and\n\t * bDeviceSubClass values */\n\tuint8_t  bDeviceProtocol;\n\n\t/** Maximum packet size for endpoint 0 */\n\tuint8_t  bMaxPacketSize0;\n\n\t/** USB-IF vendor ID */\n\tuint16_t idVendor;\n\n\t/** USB-IF product ID */\n\tuint16_t idProduct;\n\n\t/** Device release number in binary-coded decimal */\n\tuint16_t bcdDevice;\n\n\t/** Index of string descriptor describing manufacturer */\n\tuint8_t  iManufacturer;\n\n\t/** Index of string descriptor describing product */\n\tuint8_t  iProduct;\n\n\t/** Index of string descriptor containing device serial number */\n\tuint8_t  iSerialNumber;\n\n\t/** Number of possible configurations */\n\tuint8_t  bNumConfigurations;\n};\n\n/** \\ingroup desc\n * A structure representing the standard USB endpoint descriptor. This\n * descriptor is documented in section 9.6.3 of the USB 2.0 specification.\n * All multiple-byte fields are represented in host-endian format.\n */\nstruct libusb_endpoint_descriptor {\n\t/** Size of this descriptor (in bytes) */\n\tuint8_t  bLength;\n\n\t/** Descriptor type. Will have value\n\t * \\ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in\n\t * this context. */\n\tuint8_t  bDescriptorType;\n\n\t/** The address of the endpoint described by this descriptor. Bits 0:3 are\n\t * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,\n\t * see \\ref libusb_endpoint_direction.\n\t */\n\tuint8_t  bEndpointAddress;\n\n\t/** Attributes which apply to the endpoint when it is configured using\n\t * the bConfigurationValue. Bits 0:1 determine the transfer type and\n\t * correspond to \\ref libusb_transfer_type. Bits 2:3 are only used for\n\t * isochronous endpoints and correspond to \\ref libusb_iso_sync_type.\n\t * Bits 4:5 are also only used for isochronous endpoints and correspond to\n\t * \\ref libusb_iso_usage_type. Bits 6:7 are reserved.\n\t */\n\tuint8_t  bmAttributes;\n\n\t/** Maximum packet size this endpoint is capable of sending/receiving. */\n\tuint16_t wMaxPacketSize;\n\n\t/** Interval for polling endpoint for data transfers. */\n\tuint8_t  bInterval;\n\n\t/** For audio devices only: the rate at which synchronization feedback\n\t * is provided. */\n\tuint8_t  bRefresh;\n\n\t/** For audio devices only: the address if the synch endpoint */\n\tuint8_t  bSynchAddress;\n\n\t/** Extra descriptors. If libusb encounters unknown endpoint descriptors,\n\t * it will store them here, should you wish to parse them. */\n\tconst unsigned char *extra;\n\n\t/** Length of the extra descriptors, in bytes. */\n\tint extra_length;\n};\n\n/** \\ingroup desc\n * A structure representing the standard USB interface descriptor. This\n * descriptor is documented in section 9.6.5 of the USB 2.0 specification.\n * All multiple-byte fields are represented in host-endian format.\n */\nstruct libusb_interface_descriptor {\n\t/** Size of this descriptor (in bytes) */\n\tuint8_t  bLength;\n\n\t/** Descriptor type. Will have value\n\t * \\ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE\n\t * in this context. */\n\tuint8_t  bDescriptorType;\n\n\t/** Number of this interface */\n\tuint8_t  bInterfaceNumber;\n\n\t/** Value used to select this alternate setting for this interface */\n\tuint8_t  bAlternateSetting;\n\n\t/** Number of endpoints used by this interface (excluding the control\n\t * endpoint). */\n\tuint8_t  bNumEndpoints;\n\n\t/** USB-IF class code for this interface. See \\ref libusb_class_code. */\n\tuint8_t  bInterfaceClass;\n\n\t/** USB-IF subclass code for this interface, qualified by the\n\t * bInterfaceClass value */\n\tuint8_t  bInterfaceSubClass;\n\n\t/** USB-IF protocol code for this interface, qualified by the\n\t * bInterfaceClass and bInterfaceSubClass values */\n\tuint8_t  bInterfaceProtocol;\n\n\t/** Index of string descriptor describing this interface */\n\tuint8_t  iInterface;\n\n\t/** Array of endpoint descriptors. This length of this array is determined\n\t * by the bNumEndpoints field. */\n\tconst struct libusb_endpoint_descriptor *endpoint;\n\n\t/** Extra descriptors. If libusb encounters unknown interface descriptors,\n\t * it will store them here, should you wish to parse them. */\n\tconst unsigned char *extra;\n\n\t/** Length of the extra descriptors, in bytes. */\n\tint extra_length;\n};\n\n/** \\ingroup desc\n * A collection of alternate settings for a particular USB interface.\n */\nstruct libusb_interface {\n\t/** Array of interface descriptors. The length of this array is determined\n\t * by the num_altsetting field. */\n\tconst struct libusb_interface_descriptor *altsetting;\n\n\t/** The number of alternate settings that belong to this interface */\n\tint num_altsetting;\n};\n\n/** \\ingroup desc\n * A structure representing the standard USB configuration descriptor. This\n * descriptor is documented in section 9.6.3 of the USB 2.0 specification.\n * All multiple-byte fields are represented in host-endian format.\n */\nstruct libusb_config_descriptor {\n\t/** Size of this descriptor (in bytes) */\n\tuint8_t  bLength;\n\n\t/** Descriptor type. Will have value\n\t * \\ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG\n\t * in this context. */\n\tuint8_t  bDescriptorType;\n\n\t/** Total length of data returned for this configuration */\n\tuint16_t wTotalLength;\n\n\t/** Number of interfaces supported by this configuration */\n\tuint8_t  bNumInterfaces;\n\n\t/** Identifier value for this configuration */\n\tuint8_t  bConfigurationValue;\n\n\t/** Index of string descriptor describing this configuration */\n\tuint8_t  iConfiguration;\n\n\t/** Configuration characteristics */\n\tuint8_t  bmAttributes;\n\n\t/** Maximum power consumption of the USB device from this bus in this\n\t * configuration when the device is fully opreation. Expressed in units\n\t * of 2 mA. */\n\tuint8_t  MaxPower;\n\n\t/** Array of interfaces supported by this configuration. The length of\n\t * this array is determined by the bNumInterfaces field. */\n\tconst struct libusb_interface *interface;\n\n\t/** Extra descriptors. If libusb encounters unknown configuration\n\t * descriptors, it will store them here, should you wish to parse them. */\n\tconst unsigned char *extra;\n\n\t/** Length of the extra descriptors, in bytes. */\n\tint extra_length;\n};\n\n/** \\ingroup asyncio\n * Setup packet for control transfers. */\nstruct libusb_control_setup {\n\t/** Request type. Bits 0:4 determine recipient, see\n\t * \\ref libusb_request_recipient. Bits 5:6 determine type, see\n\t * \\ref libusb_request_type. Bit 7 determines data transfer direction, see\n\t * \\ref libusb_endpoint_direction.\n\t */\n\tuint8_t  bmRequestType;\n\n\t/** Request. If the type bits of bmRequestType are equal to\n\t * \\ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD\n\t * \"LIBUSB_REQUEST_TYPE_STANDARD\" then this field refers to\n\t * \\ref libusb_standard_request. For other cases, use of this field is\n\t * application-specific. */\n\tuint8_t  bRequest;\n\n\t/** Value. Varies according to request */\n\tuint16_t wValue;\n\n\t/** Index. Varies according to request, typically used to pass an index\n\t * or offset */\n\tuint16_t wIndex;\n\n\t/** Number of bytes to transfer */\n\tuint16_t wLength;\n};\n\n#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))\n\n/* libusb */\n\nstruct libusb_context;\nstruct libusb_device;\nstruct libusb_device_handle;\n\n/** \\ingroup lib\n * Structure representing a libusb session. The concept of individual libusb\n * sessions allows for your program to use two libraries (or dynamically\n * load two modules) which both independently use libusb. This will prevent\n * interference between the individual libusb users - for example\n * libusb_set_debug() will not affect the other user of the library, and\n * libusb_exit() will not destroy resources that the other user is still\n * using.\n *\n * Sessions are created by libusb_init() and destroyed through libusb_exit().\n * If your application is guaranteed to only ever include a single libusb\n * user (i.e. you), you do not have to worry about contexts: pass NULL in\n * every function call where a context is required. The default context\n * will be used.\n *\n * For more information, see \\ref contexts.\n */\ntypedef struct libusb_context libusb_context;\n\n/** \\ingroup dev\n * Structure representing a USB device detected on the system. This is an\n * opaque type for which you are only ever provided with a pointer, usually\n * originating from libusb_get_device_list().\n *\n * Certain operations can be performed on a device, but in order to do any\n * I/O you will have to first obtain a device handle using libusb_open().\n *\n * Devices are reference counted with libusb_device_ref() and\n * libusb_device_unref(), and are freed when the reference count reaches 0.\n * New devices presented by libusb_get_device_list() have a reference count of\n * 1, and libusb_free_device_list() can optionally decrease the reference count\n * on all devices in the list. libusb_open() adds another reference which is\n * later destroyed by libusb_close().\n */\ntypedef struct libusb_device libusb_device;\n\n\n/** \\ingroup dev\n * Structure representing a handle on a USB device. This is an opaque type for\n * which you are only ever provided with a pointer, usually originating from\n * libusb_open().\n *\n * A device handle is used to perform I/O and other operations. When finished\n * with a device handle, you should call libusb_close().\n */\ntypedef struct libusb_device_handle libusb_device_handle;\n\n/** \\ingroup misc\n * Error codes. Most libusb functions return 0 on success or one of these\n * codes on failure.\n * You can use libusb_strerror() to retrieve a short string description of\n * a libusb_error enumeration value.\n */\nenum libusb_error {\n\t/** Success (no error) */\n\tLIBUSB_SUCCESS = 0,\n\n\t/** Input/output error */\n\tLIBUSB_ERROR_IO = -1,\n\n\t/** Invalid parameter */\n\tLIBUSB_ERROR_INVALID_PARAM = -2,\n\n\t/** Access denied (insufficient permissions) */\n\tLIBUSB_ERROR_ACCESS = -3,\n\n\t/** No such device (it may have been disconnected) */\n\tLIBUSB_ERROR_NO_DEVICE = -4,\n\n\t/** Entity not found */\n\tLIBUSB_ERROR_NOT_FOUND = -5,\n\n\t/** Resource busy */\n\tLIBUSB_ERROR_BUSY = -6,\n\n\t/** Operation timed out */\n\tLIBUSB_ERROR_TIMEOUT = -7,\n\n\t/** Overflow */\n\tLIBUSB_ERROR_OVERFLOW = -8,\n\n\t/** Pipe error */\n\tLIBUSB_ERROR_PIPE = -9,\n\n\t/** System call interrupted (perhaps due to signal) */\n\tLIBUSB_ERROR_INTERRUPTED = -10,\n\n\t/** Insufficient memory */\n\tLIBUSB_ERROR_NO_MEM = -11,\n\n\t/** Operation not supported or unimplemented on this platform */\n\tLIBUSB_ERROR_NOT_SUPPORTED = -12,\n\n\t/** Other error */\n\tLIBUSB_ERROR_OTHER = -99\n\n\t/* IMPORTANT: when adding new values to this enum, remember to\n\t   update the libusb_strerror() function implementation! */\n};\n\n/** \\ingroup asyncio\n * Transfer status codes */\nenum libusb_transfer_status {\n\t/** Transfer completed without error. Note that this does not indicate\n\t * that the entire amount of requested data was transferred. */\n\tLIBUSB_TRANSFER_COMPLETED,\n\n\t/** Transfer failed */\n\tLIBUSB_TRANSFER_ERROR,\n\n\t/** Transfer timed out */\n\tLIBUSB_TRANSFER_TIMED_OUT,\n\n\t/** Transfer was cancelled */\n\tLIBUSB_TRANSFER_CANCELLED,\n\n\t/** For bulk/interrupt endpoints: halt condition detected (endpoint\n\t * stalled). For control endpoints: control request not supported. */\n\tLIBUSB_TRANSFER_STALL,\n\n\t/** Device was disconnected */\n\tLIBUSB_TRANSFER_NO_DEVICE,\n\n\t/** Device sent more data than requested */\n\tLIBUSB_TRANSFER_OVERFLOW\n};\n\n/** \\ingroup asyncio\n * libusb_transfer.flags values */\nenum libusb_transfer_flags {\n\t/** Report short frames as errors */\n\tLIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,\n\n\t/** Automatically free() transfer buffer during libusb_free_transfer() */\n\tLIBUSB_TRANSFER_FREE_BUFFER = 1<<1,\n\n\t/** Automatically call libusb_free_transfer() after callback returns.\n\t * If this flag is set, it is illegal to call libusb_free_transfer()\n\t * from your transfer callback, as this will result in a double-free\n\t * when this flag is acted upon. */\n\tLIBUSB_TRANSFER_FREE_TRANSFER = 1<<2\n};\n\n/** \\ingroup asyncio\n * Isochronous packet descriptor. */\nstruct libusb_iso_packet_descriptor {\n\t/** Length of data to request in this packet */\n\tunsigned int length;\n\n\t/** Amount of data that was actually transferred */\n\tunsigned int actual_length;\n\n\t/** Status code for this packet */\n\tenum libusb_transfer_status status;\n};\n\nstruct libusb_transfer;\n\n/** \\ingroup asyncio\n * Asynchronous transfer callback function type. When submitting asynchronous\n * transfers, you pass a pointer to a callback function of this type via the\n * \\ref libusb_transfer::callback \"callback\" member of the libusb_transfer\n * structure. libusb will call this function later, when the transfer has\n * completed or failed. See \\ref asyncio for more information.\n * \\param transfer The libusb_transfer struct the callback function is being\n * notified about.\n */\ntypedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);\n\n/** \\ingroup asyncio\n * The generic USB transfer structure. The user populates this structure and\n * then submits it in order to request a transfer. After the transfer has\n * completed, the library populates the transfer with the results and passes\n * it back to the user.\n */\nstruct libusb_transfer {\n\t/** Handle of the device that this transfer will be submitted to */\n\tlibusb_device_handle *dev_handle;\n\n\t/** A bitwise OR combination of \\ref libusb_transfer_flags. */\n\tuint8_t flags;\n\n\t/** Address of the endpoint where this transfer will be sent. */\n\tunsigned char endpoint;\n\n\t/** Type of the endpoint from \\ref libusb_transfer_type */\n\tunsigned char type;\n\n\t/** Timeout for this transfer in millseconds. A value of 0 indicates no\n\t * timeout. */\n\tunsigned int timeout;\n\n\t/** The status of the transfer. Read-only, and only for use within\n\t * transfer callback function.\n\t *\n\t * If this is an isochronous transfer, this field may read COMPLETED even\n\t * if there were errors in the frames. Use the\n\t * \\ref libusb_iso_packet_descriptor::status \"status\" field in each packet\n\t * to determine if errors occurred. */\n\tenum libusb_transfer_status status;\n\n\t/** Length of the data buffer */\n\tint length;\n\n\t/** Actual length of data that was transferred. Read-only, and only for\n\t * use within transfer callback function. Not valid for isochronous\n\t * endpoint transfers. */\n\tint actual_length;\n\n\t/** Callback function. This will be invoked when the transfer completes,\n\t * fails, or is cancelled. */\n\tlibusb_transfer_cb_fn callback;\n\n\t/** User context data to pass to the callback function. */\n\tvoid *user_data;\n\n\t/** Data buffer */\n\tunsigned char *buffer;\n\n\t/** Number of isochronous packets. Only used for I/O with isochronous\n\t * endpoints. */\n\tint num_iso_packets;\n\n\t/** Isochronous packet descriptors, for isochronous transfers only. */\n\tstruct libusb_iso_packet_descriptor iso_packet_desc\n#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)\n\t[] /* valid C99 code */\n#else\n\t[0] /* non-standard, but usually working code */\n#endif\n\t;\n};\n\nint LIBUSB_CALL libusb_init(libusb_context **ctx);\nvoid LIBUSB_CALL libusb_exit(libusb_context *ctx);\nvoid LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);\nconst char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode);\n\nssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,\n\tlibusb_device ***list);\nvoid LIBUSB_CALL libusb_free_device_list(libusb_device **list,\n\tint unref_devices);\nlibusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);\nvoid LIBUSB_CALL libusb_unref_device(libusb_device *dev);\n\nint LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,\n\tint *config);\nint LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,\n\tstruct libusb_device_descriptor *desc);\nint LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,\n\tstruct libusb_config_descriptor **config);\nint LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,\n\tuint8_t config_index, struct libusb_config_descriptor **config);\nint LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,\n\tuint8_t bConfigurationValue, struct libusb_config_descriptor **config);\nvoid LIBUSB_CALL libusb_free_config_descriptor(\n\tstruct libusb_config_descriptor *config);\nuint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);\nuint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);\nint LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,\n\tunsigned char endpoint);\nint LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,\n\tunsigned char endpoint);\n\nint LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle);\nvoid LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);\nlibusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);\n\nint LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,\n\tint configuration);\nint LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,\n\tint interface_number);\nint LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,\n\tint interface_number);\n\nlibusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(\n\tlibusb_context *ctx, uint16_t vendor_id, uint16_t product_id);\n\nint LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,\n\tint interface_number, int alternate_setting);\nint LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,\n\tunsigned char endpoint);\nint LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev);\n\nint LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,\n\tint interface_number);\nint LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,\n\tint interface_number);\nint LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,\n\tint interface_number);\n\n/* async I/O */\n\n/** \\ingroup asyncio\n * Get the data section of a control transfer. This convenience function is here\n * to remind you that the data does not start until 8 bytes into the actual\n * buffer, as the setup packet comes first.\n *\n * Calling this function only makes sense from a transfer callback function,\n * or situations where you have already allocated a suitably sized buffer at\n * transfer->buffer.\n *\n * \\param transfer a transfer\n * \\returns pointer to the first byte of the data section\n */\nstatic inline unsigned char *libusb_control_transfer_get_data(\n\tstruct libusb_transfer *transfer)\n{\n\treturn transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;\n}\n\n/** \\ingroup asyncio\n * Get the control setup packet of a control transfer. This convenience\n * function is here to remind you that the control setup occupies the first\n * 8 bytes of the transfer data buffer.\n *\n * Calling this function only makes sense from a transfer callback function,\n * or situations where you have already allocated a suitably sized buffer at\n * transfer->buffer.\n *\n * \\param transfer a transfer\n * \\returns a casted pointer to the start of the transfer data buffer\n */\nstatic inline struct libusb_control_setup *libusb_control_transfer_get_setup(\n\tstruct libusb_transfer *transfer)\n{\n\treturn (struct libusb_control_setup *) transfer->buffer;\n}\n\n/** \\ingroup asyncio\n * Helper function to populate the setup packet (first 8 bytes of the data\n * buffer) for a control transfer. The wIndex, wValue and wLength values should\n * be given in host-endian byte order.\n *\n * \\param buffer buffer to output the setup packet into\n * \\param bmRequestType see the\n * \\ref libusb_control_setup::bmRequestType \"bmRequestType\" field of\n * \\ref libusb_control_setup\n * \\param bRequest see the\n * \\ref libusb_control_setup::bRequest \"bRequest\" field of\n * \\ref libusb_control_setup\n * \\param wValue see the\n * \\ref libusb_control_setup::wValue \"wValue\" field of\n * \\ref libusb_control_setup\n * \\param wIndex see the\n * \\ref libusb_control_setup::wIndex \"wIndex\" field of\n * \\ref libusb_control_setup\n * \\param wLength see the\n * \\ref libusb_control_setup::wLength \"wLength\" field of\n * \\ref libusb_control_setup\n */\nstatic inline void libusb_fill_control_setup(unsigned char *buffer,\n\tuint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,\n\tuint16_t wLength)\n{\n\tstruct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;\n\tsetup->bmRequestType = bmRequestType;\n\tsetup->bRequest = bRequest;\n\tsetup->wValue = libusb_cpu_to_le16(wValue);\n\tsetup->wIndex = libusb_cpu_to_le16(wIndex);\n\tsetup->wLength = libusb_cpu_to_le16(wLength);\n}\n\nstruct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);\nint LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);\nint LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);\nvoid LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);\n\n/** \\ingroup asyncio\n * Helper function to populate the required \\ref libusb_transfer fields\n * for a control transfer.\n *\n * If you pass a transfer buffer to this function, the first 8 bytes will\n * be interpreted as a control setup packet, and the wLength field will be\n * used to automatically populate the \\ref libusb_transfer::length \"length\"\n * field of the transfer. Therefore the recommended approach is:\n * -# Allocate a suitably sized data buffer (including space for control setup)\n * -# Call libusb_fill_control_setup()\n * -# If this is a host-to-device transfer with a data stage, put the data\n *    in place after the setup packet\n * -# Call this function\n * -# Call libusb_submit_transfer()\n *\n * It is also legal to pass a NULL buffer to this function, in which case this\n * function will not attempt to populate the length field. Remember that you\n * must then populate the buffer and length fields later.\n *\n * \\param transfer the transfer to populate\n * \\param dev_handle handle of the device that will handle the transfer\n * \\param buffer data buffer. If provided, this function will interpret the\n * first 8 bytes as a setup packet and infer the transfer length from that.\n * \\param callback callback function to be invoked on transfer completion\n * \\param user_data user data to pass to callback function\n * \\param timeout timeout for the transfer in milliseconds\n */\nstatic inline void libusb_fill_control_transfer(\n\tstruct libusb_transfer *transfer, libusb_device_handle *dev_handle,\n\tunsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,\n\tunsigned int timeout)\n{\n\tstruct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;\n\ttransfer->dev_handle = dev_handle;\n\ttransfer->endpoint = 0;\n\ttransfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;\n\ttransfer->timeout = timeout;\n\ttransfer->buffer = buffer;\n\tif (setup)\n\t\ttransfer->length = LIBUSB_CONTROL_SETUP_SIZE\n\t\t\t+ libusb_le16_to_cpu(setup->wLength);\n\ttransfer->user_data = user_data;\n\ttransfer->callback = callback;\n}\n\n/** \\ingroup asyncio\n * Helper function to populate the required \\ref libusb_transfer fields\n * for a bulk transfer.\n *\n * \\param transfer the transfer to populate\n * \\param dev_handle handle of the device that will handle the transfer\n * \\param endpoint address of the endpoint where this transfer will be sent\n * \\param buffer data buffer\n * \\param length length of data buffer\n * \\param callback callback function to be invoked on transfer completion\n * \\param user_data user data to pass to callback function\n * \\param timeout timeout for the transfer in milliseconds\n */\nstatic inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,\n\tlibusb_device_handle *dev_handle, unsigned char endpoint,\n\tunsigned char *buffer, int length, libusb_transfer_cb_fn callback,\n\tvoid *user_data, unsigned int timeout)\n{\n\ttransfer->dev_handle = dev_handle;\n\ttransfer->endpoint = endpoint;\n\ttransfer->type = LIBUSB_TRANSFER_TYPE_BULK;\n\ttransfer->timeout = timeout;\n\ttransfer->buffer = buffer;\n\ttransfer->length = length;\n\ttransfer->user_data = user_data;\n\ttransfer->callback = callback;\n}\n\n/** \\ingroup asyncio\n * Helper function to populate the required \\ref libusb_transfer fields\n * for an interrupt transfer.\n *\n * \\param transfer the transfer to populate\n * \\param dev_handle handle of the device that will handle the transfer\n * \\param endpoint address of the endpoint where this transfer will be sent\n * \\param buffer data buffer\n * \\param length length of data buffer\n * \\param callback callback function to be invoked on transfer completion\n * \\param user_data user data to pass to callback function\n * \\param timeout timeout for the transfer in milliseconds\n */\nstatic inline void libusb_fill_interrupt_transfer(\n\tstruct libusb_transfer *transfer, libusb_device_handle *dev_handle,\n\tunsigned char endpoint, unsigned char *buffer, int length,\n\tlibusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)\n{\n\ttransfer->dev_handle = dev_handle;\n\ttransfer->endpoint = endpoint;\n\ttransfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;\n\ttransfer->timeout = timeout;\n\ttransfer->buffer = buffer;\n\ttransfer->length = length;\n\ttransfer->user_data = user_data;\n\ttransfer->callback = callback;\n}\n\n/** \\ingroup asyncio\n * Helper function to populate the required \\ref libusb_transfer fields\n * for an isochronous transfer.\n *\n * \\param transfer the transfer to populate\n * \\param dev_handle handle of the device that will handle the transfer\n * \\param endpoint address of the endpoint where this transfer will be sent\n * \\param buffer data buffer\n * \\param length length of data buffer\n * \\param num_iso_packets the number of isochronous packets\n * \\param callback callback function to be invoked on transfer completion\n * \\param user_data user data to pass to callback function\n * \\param timeout timeout for the transfer in milliseconds\n */\nstatic inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,\n\tlibusb_device_handle *dev_handle, unsigned char endpoint,\n\tunsigned char *buffer, int length, int num_iso_packets,\n\tlibusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)\n{\n\ttransfer->dev_handle = dev_handle;\n\ttransfer->endpoint = endpoint;\n\ttransfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;\n\ttransfer->timeout = timeout;\n\ttransfer->buffer = buffer;\n\ttransfer->length = length;\n\ttransfer->num_iso_packets = num_iso_packets;\n\ttransfer->user_data = user_data;\n\ttransfer->callback = callback;\n}\n\n/** \\ingroup asyncio\n * Convenience function to set the length of all packets in an isochronous\n * transfer, based on the num_iso_packets field in the transfer structure.\n *\n * \\param transfer a transfer\n * \\param length the length to set in each isochronous packet descriptor\n * \\see libusb_get_max_packet_size()\n */\nstatic inline void libusb_set_iso_packet_lengths(\n\tstruct libusb_transfer *transfer, unsigned int length)\n{\n\tint i;\n\tfor (i = 0; i < transfer->num_iso_packets; i++)\n\t\ttransfer->iso_packet_desc[i].length = length;\n}\n\n/** \\ingroup asyncio\n * Convenience function to locate the position of an isochronous packet\n * within the buffer of an isochronous transfer.\n *\n * This is a thorough function which loops through all preceding packets,\n * accumulating their lengths to find the position of the specified packet.\n * Typically you will assign equal lengths to each packet in the transfer,\n * and hence the above method is sub-optimal. You may wish to use\n * libusb_get_iso_packet_buffer_simple() instead.\n *\n * \\param transfer a transfer\n * \\param packet the packet to return the address of\n * \\returns the base address of the packet buffer inside the transfer buffer,\n * or NULL if the packet does not exist.\n * \\see libusb_get_iso_packet_buffer_simple()\n */\nstatic inline unsigned char *libusb_get_iso_packet_buffer(\n\tstruct libusb_transfer *transfer, unsigned int packet)\n{\n\tint i;\n\tsize_t offset = 0;\n\tint _packet;\n\n\t/* oops..slight bug in the API. packet is an unsigned int, but we use\n\t * signed integers almost everywhere else. range-check and convert to\n\t * signed to avoid compiler warnings. FIXME for libusb-2. */\n\tif (packet > INT_MAX)\n\t\treturn NULL;\n\t_packet = packet;\n\n\tif (_packet >= transfer->num_iso_packets)\n\t\treturn NULL;\n\n\tfor (i = 0; i < _packet; i++)\n\t\toffset += transfer->iso_packet_desc[i].length;\n\n\treturn transfer->buffer + offset;\n}\n\n/** \\ingroup asyncio\n * Convenience function to locate the position of an isochronous packet\n * within the buffer of an isochronous transfer, for transfers where each\n * packet is of identical size.\n *\n * This function relies on the assumption that every packet within the transfer\n * is of identical size to the first packet. Calculating the location of\n * the packet buffer is then just a simple calculation:\n * <tt>buffer + (packet_size * packet)</tt>\n *\n * Do not use this function on transfers other than those that have identical\n * packet lengths for each packet.\n *\n * \\param transfer a transfer\n * \\param packet the packet to return the address of\n * \\returns the base address of the packet buffer inside the transfer buffer,\n * or NULL if the packet does not exist.\n * \\see libusb_get_iso_packet_buffer()\n */\nstatic inline unsigned char *libusb_get_iso_packet_buffer_simple(\n\tstruct libusb_transfer *transfer, unsigned int packet)\n{\n\tint _packet;\n\n\t/* oops..slight bug in the API. packet is an unsigned int, but we use\n\t * signed integers almost everywhere else. range-check and convert to\n\t * signed to avoid compiler warnings. FIXME for libusb-2. */\n\tif (packet > INT_MAX)\n\t\treturn NULL;\n\t_packet = packet;\n\n\tif (_packet >= transfer->num_iso_packets)\n\t\treturn NULL;\n\n\treturn transfer->buffer + (transfer->iso_packet_desc[0].length * _packet);\n}\n\n/* sync I/O */\n\nint LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,\n\tuint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,\n\tunsigned char *data, uint16_t wLength, unsigned int timeout);\n\nint LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,\n\tunsigned char endpoint, unsigned char *data, int length,\n\tint *actual_length, unsigned int timeout);\n\nint LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,\n\tunsigned char endpoint, unsigned char *data, int length,\n\tint *actual_length, unsigned int timeout);\n\n/** \\ingroup desc\n * Retrieve a descriptor from the default control pipe.\n * This is a convenience function which formulates the appropriate control\n * message to retrieve the descriptor.\n *\n * \\param dev a device handle\n * \\param desc_type the descriptor type, see \\ref libusb_descriptor_type\n * \\param desc_index the index of the descriptor to retrieve\n * \\param data output buffer for descriptor\n * \\param length size of data buffer\n * \\returns number of bytes returned in data, or LIBUSB_ERROR code on failure\n */\nstatic inline int libusb_get_descriptor(libusb_device_handle *dev,\n\tuint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)\n{\n\treturn libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,\n\t\tLIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,\n\t\t(uint16_t) length, 1000);\n}\n\n/** \\ingroup desc\n * Retrieve a descriptor from a device.\n * This is a convenience function which formulates the appropriate control\n * message to retrieve the descriptor. The string returned is Unicode, as\n * detailed in the USB specifications.\n *\n * \\param dev a device handle\n * \\param desc_index the index of the descriptor to retrieve\n * \\param langid the language ID for the string descriptor\n * \\param data output buffer for descriptor\n * \\param length size of data buffer\n * \\returns number of bytes returned in data, or LIBUSB_ERROR code on failure\n * \\see libusb_get_string_descriptor_ascii()\n */\nstatic inline int libusb_get_string_descriptor(libusb_device_handle *dev,\n\tuint8_t desc_index, uint16_t langid, unsigned char *data, int length)\n{\n\treturn libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,\n\t\tLIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | desc_index,\n\t\tlangid, data, (uint16_t) length, 1000);\n}\n\nint LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev,\n\tuint8_t desc_index, unsigned char *data, int length);\n\n/* polling and timeouts */\n\nint LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);\nvoid LIBUSB_CALL libusb_lock_events(libusb_context *ctx);\nvoid LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);\nint LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);\nint LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);\nvoid LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);\nvoid LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);\nint LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);\n\nint LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,\n\tstruct timeval *tv);\nint LIBUSB_CALL libusb_handle_events(libusb_context *ctx);\nint LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,\n\tstruct timeval *tv);\nint LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);\nint LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,\n\tstruct timeval *tv);\n\n/** \\ingroup poll\n * File descriptor for polling\n */\nstruct libusb_pollfd {\n\t/** Numeric file descriptor */\n\tint fd;\n\n\t/** Event flags to poll for from <poll.h>. POLLIN indicates that you\n\t * should monitor this file descriptor for becoming ready to read from,\n\t * and POLLOUT indicates that you should monitor this file descriptor for\n\t * nonblocking write readiness. */\n\tshort events;\n};\n\n/** \\ingroup poll\n * Callback function, invoked when a new file descriptor should be added\n * to the set of file descriptors monitored for events.\n * \\param fd the new file descriptor\n * \\param events events to monitor for, see \\ref libusb_pollfd for a\n * description\n * \\param user_data User data pointer specified in\n * libusb_set_pollfd_notifiers() call\n * \\see libusb_set_pollfd_notifiers()\n */\ntypedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,\n\tvoid *user_data);\n\n/** \\ingroup poll\n * Callback function, invoked when a file descriptor should be removed from\n * the set of file descriptors being monitored for events. After returning\n * from this callback, do not use that file descriptor again.\n * \\param fd the file descriptor to stop monitoring\n * \\param user_data User data pointer specified in\n * libusb_set_pollfd_notifiers() call\n * \\see libusb_set_pollfd_notifiers()\n */\ntypedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);\n\nconst struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(\n\tlibusb_context *ctx);\nvoid LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,\n\tlibusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,\n\tvoid *user_data);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "libs/libusb-win32/AUTHORS.txt",
    "content": "\nLibrary, Test Programs:\n\nStephan Meyer, <ste_meyer@web.de>\nJohannes Erdfelt, <johannes@erdfelt.com>\nThomas Sailer, <sailer@ife.ee.ethz.ch>\n\nDrivers, Installer:\n\nStephan Meyer, <ste_meyer@web.de>\nTravis Robinson, <libusbdotnet@gmail.com>\n\nTesting, Technical support:\n\nXiaofan Chen, <xiaofanc@gmail.com>\n\n"
  },
  {
    "path": "libs/libusb-win32/COPYING_LGPL.txt",
    "content": "                   GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\n  This version of the GNU Lesser General Public License incorporates\nthe terms and conditions of version 3 of the GNU General Public\nLicense, supplemented by the additional permissions listed below.\n\n  0. Additional Definitions.\n\n  As used herein, \"this License\" refers to version 3 of the GNU Lesser\nGeneral Public License, and the \"GNU GPL\" refers to version 3 of the GNU\nGeneral Public License.\n\n  \"The Library\" refers to a covered work governed by this License,\nother than an Application or a Combined Work as defined below.\n\n  An \"Application\" is any work that makes use of an interface provided\nby the Library, but which is not otherwise based on the Library.\nDefining a subclass of a class defined by the Library is deemed a mode\nof using an interface provided by the Library.\n\n  A \"Combined Work\" is a work produced by combining or linking an\nApplication with the Library.  The particular version of the Library\nwith which the Combined Work was made is also called the \"Linked\nVersion\".\n\n  The \"Minimal Corresponding Source\" for a Combined Work means the\nCorresponding Source for the Combined Work, excluding any source code\nfor portions of the Combined Work that, considered in isolation, are\nbased on the Application, and not on the Linked Version.\n\n  The \"Corresponding Application Code\" for a Combined Work means the\nobject code and/or source code for the Application, including any data\nand utility programs needed for reproducing the Combined Work from the\nApplication, but excluding the System Libraries of the Combined Work.\n\n  1. Exception to Section 3 of the GNU GPL.\n\n  You may convey a covered work under sections 3 and 4 of this License\nwithout being bound by section 3 of the GNU GPL.\n\n  2. Conveying Modified Versions.\n\n  If you modify a copy of the Library, and, in your modifications, a\nfacility refers to a function or data to be supplied by an Application\nthat uses the facility (other than as an argument passed when the\nfacility is invoked), then you may convey a copy of the modified\nversion:\n\n   a) under this License, provided that you make a good faith effort to\n   ensure that, in the event an Application does not supply the\n   function or data, the facility still operates, and performs\n   whatever part of its purpose remains meaningful, or\n\n   b) under the GNU GPL, with none of the additional permissions of\n   this License applicable to that copy.\n\n  3. Object Code Incorporating Material from Library Header Files.\n\n  The object code form of an Application may incorporate material from\na header file that is part of the Library.  You may convey such object\ncode under terms of your choice, provided that, if the incorporated\nmaterial is not limited to numerical parameters, data structure\nlayouts and accessors, or small macros, inline functions and templates\n(ten or fewer lines in length), you do both of the following:\n\n   a) Give prominent notice with each copy of the object code that the\n   Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the object code with a copy of the GNU GPL and this license\n   document.\n\n  4. Combined Works.\n\n  You may convey a Combined Work under terms of your choice that,\ntaken together, effectively do not restrict modification of the\nportions of the Library contained in the Combined Work and reverse\nengineering for debugging such modifications, if you also do each of\nthe following:\n\n   a) Give prominent notice with each copy of the Combined Work that\n   the Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the Combined Work with a copy of the GNU GPL and this license\n   document.\n\n   c) For a Combined Work that displays copyright notices during\n   execution, include the copyright notice for the Library among\n   these notices, as well as a reference directing the user to the\n   copies of the GNU GPL and this license document.\n\n   d) Do one of the following:\n\n       0) Convey the Minimal Corresponding Source under the terms of this\n       License, and the Corresponding Application Code in a form\n       suitable for, and under terms that permit, the user to\n       recombine or relink the Application with a modified version of\n       the Linked Version to produce a modified Combined Work, in the\n       manner specified by section 6 of the GNU GPL for conveying\n       Corresponding Source.\n\n       1) Use a suitable shared library mechanism for linking with the\n       Library.  A suitable mechanism is one that (a) uses at run time\n       a copy of the Library already present on the user's computer\n       system, and (b) will operate properly with a modified version\n       of the Library that is interface-compatible with the Linked\n       Version.\n\n   e) Provide Installation Information, but only if you would otherwise\n   be required to provide such information under section 6 of the\n   GNU GPL, and only to the extent that such information is\n   necessary to install and execute a modified version of the\n   Combined Work produced by recombining or relinking the\n   Application with a modified version of the Linked Version. (If\n   you use option 4d0, the Installation Information must accompany\n   the Minimal Corresponding Source and Corresponding Application\n   Code. If you use option 4d1, you must provide the Installation\n   Information in the manner specified by section 6 of the GNU GPL\n   for conveying Corresponding Source.)\n\n  5. Combined Libraries.\n\n  You may place library facilities that are a work based on the\nLibrary side by side in a single library together with other library\nfacilities that are not Applications and are not covered by this\nLicense, and convey such a combined library under terms of your\nchoice, if you do both of the following:\n\n   a) Accompany the combined library with a copy of the same work based\n   on the Library, uncombined with any other library facilities,\n   conveyed under the terms of this License.\n\n   b) Give prominent notice with the combined library that part of it\n   is a work based on the Library, and explaining where to find the\n   accompanying uncombined form of the same work.\n\n  6. Revised Versions of the GNU Lesser General Public License.\n\n  The Free Software Foundation may publish revised and/or new versions\nof the GNU Lesser General Public License from time to time. Such new\nversions will be similar in spirit to the present version, but may\ndiffer in detail to address new problems or concerns.\n\n  Each version is given a distinguishing version number. If the\nLibrary as you received it specifies that a certain numbered version\nof the GNU Lesser General Public License \"or any later version\"\napplies to it, you have the option of following the terms and\nconditions either of that published version or of any later version\npublished by the Free Software Foundation. If the Library as you\nreceived it does not specify a version number of the GNU Lesser\nGeneral Public License, you may choose any version of the GNU Lesser\nGeneral Public License ever published by the Free Software Foundation.\n\n  If the Library as you received it specifies that a proxy can decide\nwhether future versions of the GNU Lesser General Public License shall\napply, that proxy's public statement of acceptance of any version is\npermanent authorization for you to choose that version for the\nLibrary.\n"
  },
  {
    "path": "libs/libusb-win32/README.txt",
    "content": "\nThis is libusb-win32 (http://libusb-win32.sourceforge.net) version 1.2.6.0. \nLibusb-win32 is a library that allows userspace application to access USB \ndevices on Windows operation systems (Win2k, WinXP, Vista, Win7). \nIt is derived from and fully API compatible to libusb available at \nhttp://libusb.sourceforge.net.\n\nFor more information visit the project's web site at:\n\nhttp://libusb-win32.sourceforge.net\nhttp://sourceforge.net/projects/libusb-win32\n\n"
  },
  {
    "path": "libs/libusb-win32/include/lusb0_usb.h",
    "content": "#ifndef __USB_H__\n#define __USB_H__\n\n#include <stdlib.h>\n#include <windows.h>\n\n/*\n * 'interface' is defined somewhere in the Windows header files. This macro\n * is deleted here to avoid conflicts and compile errors.\n */\n\n#ifdef interface\n#undef interface\n#endif\n\n/*\n * PATH_MAX from limits.h can't be used on Windows if the dll and\n * import libraries are build/used by different compilers\n */\n\n#define LIBUSB_PATH_MAX 512\n\n\n/*\n * USB spec information\n *\n * This is all stuff grabbed from various USB specs and is pretty much\n * not subject to change\n */\n\n/*\n * Device and/or Interface Class codes\n */\n#define USB_CLASS_PER_INTERFACE\t\t0\t/* for DeviceClass */\n#define USB_CLASS_AUDIO\t\t\t      1\n#define USB_CLASS_COMM\t\t\t      2\n#define USB_CLASS_HID\t\t\t        3\n#define USB_CLASS_PRINTER\t\t      7\n#define USB_CLASS_MASS_STORAGE\t\t8\n#define USB_CLASS_HUB\t\t\t        9\n#define USB_CLASS_DATA\t\t\t      10\n#define USB_CLASS_VENDOR_SPEC\t\t  0xff\n\n/*\n * Descriptor types\n */\n#define USB_DT_DEVICE\t\t\t0x01\n#define USB_DT_CONFIG\t\t\t0x02\n#define USB_DT_STRING\t\t\t0x03\n#define USB_DT_INTERFACE\t0x04\n#define USB_DT_ENDPOINT\t\t0x05\n\n#define USB_DT_HID\t\t\t0x21\n#define USB_DT_REPORT\t\t0x22\n#define USB_DT_PHYSICAL\t0x23\n#define USB_DT_HUB\t\t\t0x29\n\n/*\n * Descriptor sizes per descriptor type\n */\n#define USB_DT_DEVICE_SIZE\t\t18\n#define USB_DT_CONFIG_SIZE\t\t9\n#define USB_DT_INTERFACE_SIZE\t\t9\n#define USB_DT_ENDPOINT_SIZE\t\t7\n#define USB_DT_ENDPOINT_AUDIO_SIZE\t9\t/* Audio extension */\n#define USB_DT_HUB_NONVAR_SIZE\t\t7\n\n\n/* ensure byte-packed structures */\n#include <pshpack1.h>\n\n\n/* All standard descriptors have these 2 fields in common */\nstruct usb_descriptor_header\n{\n    unsigned char  bLength;\n    unsigned char  bDescriptorType;\n};\n\n/* String descriptor */\nstruct usb_string_descriptor\n{\n    unsigned char  bLength;\n    unsigned char  bDescriptorType;\n    unsigned short wData[1];\n};\n\n/* HID descriptor */\nstruct usb_hid_descriptor\n{\n    unsigned char  bLength;\n    unsigned char  bDescriptorType;\n    unsigned short bcdHID;\n    unsigned char  bCountryCode;\n    unsigned char  bNumDescriptors;\n};\n\n/* Endpoint descriptor */\n#define USB_MAXENDPOINTS\t32\nstruct usb_endpoint_descriptor\n{\n    unsigned char  bLength;\n    unsigned char  bDescriptorType;\n    unsigned char  bEndpointAddress;\n    unsigned char  bmAttributes;\n    unsigned short wMaxPacketSize;\n    unsigned char  bInterval;\n    unsigned char  bRefresh;\n    unsigned char  bSynchAddress;\n\n    unsigned char *extra;\t/* Extra descriptors */\n    int extralen;\n};\n\n#define USB_ENDPOINT_ADDRESS_MASK\t0x0f    /* in bEndpointAddress */\n#define USB_ENDPOINT_DIR_MASK\t\t  0x80\n\n#define USB_ENDPOINT_TYPE_MASK\t\t0x03    /* in bmAttributes */\n#define USB_ENDPOINT_TYPE_CONTROL\t    0\n#define USB_ENDPOINT_TYPE_ISOCHRONOUS\t1\n#define USB_ENDPOINT_TYPE_BULK\t\t    2\n#define USB_ENDPOINT_TYPE_INTERRUPT\t  3\n\n/* Interface descriptor */\n#define USB_MAXINTERFACES\t32\nstruct usb_interface_descriptor\n{\n    unsigned char  bLength;\n    unsigned char  bDescriptorType;\n    unsigned char  bInterfaceNumber;\n    unsigned char  bAlternateSetting;\n    unsigned char  bNumEndpoints;\n    unsigned char  bInterfaceClass;\n    unsigned char  bInterfaceSubClass;\n    unsigned char  bInterfaceProtocol;\n    unsigned char  iInterface;\n\n    struct usb_endpoint_descriptor *endpoint;\n\n    unsigned char *extra;\t/* Extra descriptors */\n    int extralen;\n};\n\n#define USB_MAXALTSETTING\t128\t/* Hard limit */\n\nstruct usb_interface\n{\n    struct usb_interface_descriptor *altsetting;\n\n    int num_altsetting;\n};\n\n/* Configuration descriptor information.. */\n#define USB_MAXCONFIG\t\t8\nstruct usb_config_descriptor\n{\n    unsigned char  bLength;\n    unsigned char  bDescriptorType;\n    unsigned short wTotalLength;\n    unsigned char  bNumInterfaces;\n    unsigned char  bConfigurationValue;\n    unsigned char  iConfiguration;\n    unsigned char  bmAttributes;\n    unsigned char  MaxPower;\n\n    struct usb_interface *interface;\n\n    unsigned char *extra;\t/* Extra descriptors */\n    int extralen;\n};\n\n/* Device descriptor */\nstruct usb_device_descriptor\n{\n    unsigned char  bLength;\n    unsigned char  bDescriptorType;\n    unsigned short bcdUSB;\n    unsigned char  bDeviceClass;\n    unsigned char  bDeviceSubClass;\n    unsigned char  bDeviceProtocol;\n    unsigned char  bMaxPacketSize0;\n    unsigned short idVendor;\n    unsigned short idProduct;\n    unsigned short bcdDevice;\n    unsigned char  iManufacturer;\n    unsigned char  iProduct;\n    unsigned char  iSerialNumber;\n    unsigned char  bNumConfigurations;\n};\n\nstruct usb_ctrl_setup\n{\n    unsigned char  bRequestType;\n    unsigned char  bRequest;\n    unsigned short wValue;\n    unsigned short wIndex;\n    unsigned short wLength;\n};\n\n/*\n * Standard requests\n */\n#define USB_REQ_GET_STATUS\t\t    0x00\n#define USB_REQ_CLEAR_FEATURE\t    0x01\n/* 0x02 is reserved */\n#define USB_REQ_SET_FEATURE\t\t    0x03\n/* 0x04 is reserved */\n#define USB_REQ_SET_ADDRESS\t\t    0x05\n#define USB_REQ_GET_DESCRIPTOR\t\t0x06\n#define USB_REQ_SET_DESCRIPTOR\t\t0x07\n#define USB_REQ_GET_CONFIGURATION\t0x08\n#define USB_REQ_SET_CONFIGURATION\t0x09\n#define USB_REQ_GET_INTERFACE\t\t  0x0A\n#define USB_REQ_SET_INTERFACE\t\t  0x0B\n#define USB_REQ_SYNCH_FRAME\t\t    0x0C\n\n#define USB_TYPE_STANDARD\t\t(0x00 << 5)\n#define USB_TYPE_CLASS\t\t\t(0x01 << 5)\n#define USB_TYPE_VENDOR\t\t\t(0x02 << 5)\n#define USB_TYPE_RESERVED\t\t(0x03 << 5)\n\n#define USB_RECIP_DEVICE\t\t0x00\n#define USB_RECIP_INTERFACE\t0x01\n#define USB_RECIP_ENDPOINT\t0x02\n#define USB_RECIP_OTHER\t\t\t0x03\n\n/*\n * Various libusb API related stuff\n */\n\n#define USB_ENDPOINT_IN\t\t\t0x80\n#define USB_ENDPOINT_OUT\t\t0x00\n\n/* Error codes */\n#define USB_ERROR_BEGIN\t\t\t500000\n\n/*\n * This is supposed to look weird. This file is generated from autoconf\n * and I didn't want to make this too complicated.\n */\n#define USB_LE16_TO_CPU(x)\n\n/*\n * Device reset types for usb_reset_ex.\n * http://msdn.microsoft.com/en-us/library/ff537269%28VS.85%29.aspx\n * http://msdn.microsoft.com/en-us/library/ff537243%28v=vs.85%29.aspx\n */\n#define USB_RESET_TYPE_RESET_PORT (1 << 0)\n#define USB_RESET_TYPE_CYCLE_PORT (1 << 1)\n#define USB_RESET_TYPE_FULL_RESET (USB_RESET_TYPE_CYCLE_PORT | USB_RESET_TYPE_RESET_PORT)\n\n\n/* Data types */\n/* struct usb_device; */\n/* struct usb_bus; */\n\nstruct usb_device\n{\n    struct usb_device *next, *prev;\n\n    char filename[LIBUSB_PATH_MAX];\n\n    struct usb_bus *bus;\n\n    struct usb_device_descriptor descriptor;\n    struct usb_config_descriptor *config;\n\n    void *dev;\t\t/* Darwin support */\n\n    unsigned char devnum;\n\n    unsigned char num_children;\n    struct usb_device **children;\n};\n\nstruct usb_bus\n{\n    struct usb_bus *next, *prev;\n\n    char dirname[LIBUSB_PATH_MAX];\n\n    struct usb_device *devices;\n    unsigned long location;\n\n    struct usb_device *root_dev;\n};\n\n/* Version information, Windows specific */\nstruct usb_version\n{\n    struct\n    {\n        int major;\n        int minor;\n        int micro;\n        int nano;\n    } dll;\n    struct\n    {\n        int major;\n        int minor;\n        int micro;\n        int nano;\n    } driver;\n};\n\n\nstruct usb_dev_handle;\ntypedef struct usb_dev_handle usb_dev_handle;\n\n/* Variables */\n#ifndef __USB_C__\n#define usb_busses usb_get_busses()\n#endif\n\n\n\n#include <poppack.h>\n\n\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif\n\n    /* Function prototypes */\n\n    /* usb.c */\n    usb_dev_handle *usb_open(struct usb_device *dev);\n    int usb_close(usb_dev_handle *dev);\n    int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,\n                       size_t buflen);\n    int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,\n                              size_t buflen);\n\n    /* descriptors.c */\n    int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,\n                                       unsigned char type, unsigned char index,\n                                       void *buf, int size);\n    int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,\n                           unsigned char index, void *buf, int size);\n\n    /* <arch>.c */\n    int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,\n                       int timeout);\n    int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,\n                      int timeout);\n    int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,\n                            int timeout);\n    int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,\n                           int timeout);\n    int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,\n                        int value, int index, char *bytes, int size,\n                        int timeout);\n    int usb_set_configuration(usb_dev_handle *dev, int configuration);\n    int usb_claim_interface(usb_dev_handle *dev, int interface);\n    int usb_release_interface(usb_dev_handle *dev, int interface);\n    int usb_set_altinterface(usb_dev_handle *dev, int alternate);\n    int usb_resetep(usb_dev_handle *dev, unsigned int ep);\n    int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);\n    int usb_reset(usb_dev_handle *dev);\n    int usb_reset_ex(usb_dev_handle *dev, unsigned int reset_type);\n\n    char *usb_strerror(void);\n\n    void usb_init(void);\n    void usb_set_debug(int level);\n    int usb_find_busses(void);\n    int usb_find_devices(void);\n    struct usb_device *usb_device(usb_dev_handle *dev);\n    struct usb_bus *usb_get_busses(void);\n\n\n    /* Windows specific functions */\n\n#define LIBUSB_HAS_INSTALL_SERVICE_NP 1\n    int usb_install_service_np(void);\n    void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance,\n            LPSTR cmd_line, int cmd_show);\n\n#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1\n    int usb_uninstall_service_np(void);\n    void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,\n            LPSTR cmd_line, int cmd_show);\n\n#define LIBUSB_HAS_INSTALL_DRIVER_NP 1\n    int usb_install_driver_np(const char *inf_file);\n    void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance,\n            LPSTR cmd_line, int cmd_show);\n\n#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1\n    int usb_touch_inf_file_np(const char *inf_file);\n    void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance,\n            LPSTR cmd_line, int cmd_show);\n\n#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1\n    int usb_install_needs_restart_np(void);\n\n#define LIBUSB_HAS_INSTALL_NP 1\n    int usb_install_npW(HWND hwnd, HINSTANCE instance, LPCWSTR cmd_line, int starg_arg);\n    int usb_install_npA(HWND hwnd, HINSTANCE instance, LPCSTR cmd_line, int starg_arg);\n\t#define usb_install_np usb_install_npA\n    void CALLBACK usb_install_np_rundll(HWND wnd, HINSTANCE instance, \n            LPSTR cmd_line, int cmd_show);\n\n    const struct usb_version *usb_get_version(void);\n\n    int usb_isochronous_setup_async(usb_dev_handle *dev, void **context,\n                                    unsigned char ep, int pktsize);\n    int usb_bulk_setup_async(usb_dev_handle *dev, void **context,\n                             unsigned char ep);\n    int usb_interrupt_setup_async(usb_dev_handle *dev, void **context,\n                                  unsigned char ep);\n\n    int usb_submit_async(void *context, char *bytes, int size);\n    int usb_reap_async(void *context, int timeout);\n    int usb_reap_async_nocancel(void *context, int timeout);\n    int usb_cancel_async(void *context);\n    int usb_free_async(void **context);\n\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* __USB_H__ */\n\n"
  },
  {
    "path": "scripts/update_freenect.sh",
    "content": "#! /bin/bash\n\nWD=$(dirname $0)\n\nDEST=../libs/libfreenect\nSRC=libfreenect\n\n###\n\ncd $WD\n\n# get latest source\n#git clone git://github.com/OpenKinect/libfreenect.git\ngit clone git://github.com/wizgrav/libfreenect.git\n\n# remove uneeded makefiles\nrm $SRC/src/CMakeLists.txt\nrm $SRC/src/libfreenect.pc.in\n\n# we dont need freenect audio\nrm $SRC/include/libfreenect-audio.h\nrm $SRC/src/audio.c\nrm $SRC/src/loader.c\n\n# no python either\nrm $SRC/src/fwfetcher.py\n\n# make folders\nmkdir -p $DEST/include\nmkdir -p $DEST/src\nmkdir -p $DEST/platform\n\n# copy licenses, etc\ncp -v $SRC/APACHE20 $DEST\ncp -v $SRC/CONTRIB $DEST\ncp -v $SRC/GPL2 $DEST\n\n# copy headers\ncp -Rv $SRC/include/* $DEST/include\n\n# copy sources\ncp -Rv $SRC/src/* $DEST/src\n\n# copy platform specfic stuff\ncp -Rv $SRC/platform/linux $DEST/platform\ncp -Rv $SRC/platform/windows $DEST/platform\n\n# cleanup\nrm -rf $SRC\n"
  },
  {
    "path": "scripts/update_libusb-win32.sh",
    "content": "#! /bin/bash\n\nWD=$(dirname $0)\n\nVER=1.2.6.0\n\nDEST=../libs/libusb-win32\nSRC=libusb-win32-bin-$VER\n\n###\n\ncd $WD\n\n# make folders\nmkdir -p $DEST/include\nmkdir -p $DEST/lib/vs2010\nmkdir -p $DEST/lib/win_cb\n\n### Debug\n\n# get source\ncurl -LO http://downloads.sourceforge.net/project/libusb-win32/libusb-win32-releases/$VER/libusb-win32-bin-debug-$VER.zip\nunzip -oq libusb-win32-bin-debug-$VER.zip\n\n# copy libs\ncp -v $SRC/lib/msvc/libusb.lib $DEST/lib/vs2010/libusbd.lib\ncp -v $SRC/lib/msvc/libusb.lib $DEST/lib/win_cb/libusbd.lib\n\n# cleanup\nrm -rf libusb-win32-bin-debug-$VER\nrm libusb-win32-bin-debug-$VER.zip\n\n### Release\n\n# get source\ncurl -LO http://downloads.sourceforge.net/project/libusb-win32/libusb-win32-releases/$VER/$SRC.zip\nunzip -oq $SRC.zip\n\n# copy licenses, etc\ncp -v $SRC/AUTHORS.txt $DEST\ncp -v $SRC/COPYING_LGPL.txt $DEST\ncp -v $SRC/README.txt $DEST\n\n# copy headers\ncp -Rv $SRC/include/* $DEST/include\n\n# copy libs\ncp -v $SRC/lib/msvc/libusb.lib $DEST/lib/vs2010\ncp -v $SRC/lib/msvc/libusb.lib $DEST/lib/win_cb\n\n# cleanup\nrm -rf $SRC\nrm $SRC.zip"
  },
  {
    "path": "src/ofxBase3DVideo.h",
    "content": "/*==============================================================================\n\n    Copyright (c) 2010, 2011 ofxKinect Team\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n    \n==============================================================================*/\n#pragma once\n\n/// \\class ofxBase3DVideo\n///\n/// a base class for 3D video devices\nclass ofxBase3DVideo: public ofBaseVideo {\n\npublic:\n    \n    /// get the pixels of the most recent depth frame\n    virtual unsigned char* getDepthPixels()=0;\n    \n    /// get the distance in millimeters to a given point as a float array\n    virtual float* getDistancePixels()=0;\n    \n    /// get the grayscale depth texture\n    virtual ofTexture& getDepthTextureReference()=0;\n};\n"
  },
  {
    "path": "src/ofxKinect.cpp",
    "content": "/*==============================================================================\n\n    Copyright (c) 2010, 2011 ofxKinect Team\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n    \n    ----------------------------------------------------------------------------\n    \n    This project uses libfreenect, copyrighted by the Open Kinect Project using\n    the Apache License v2. See the file \"APACHE20\" in libs/libfreenect.\n    \n    See http://www.openkinect.org & https://github.com/OpenKinect/libfreenect \n    for documentation\n    \n==============================================================================*/\n#include \"ofxKinect.h\"\n#include \"ofMain.h\"\n\n#include \"libfreenect-registration.h\"\n#include \"freenect_internal.h\" // for access to freenect_device.registration.zero_plane_info\n\n#define OFX_KINECT_GRAVITY 9.80665\n\n// context static\nofxKinectContext ofxKinect::kinectContext;\n\n//--------------------------------------------------------------------\nofxKinect::ofxKinect() {\n\tofLogVerbose(\"ofxKinect\") <<\" creating ofxKinect\";\n\n\tdeviceId = -1;\n\tserial = \"\";\n\t\n\tbUseTexture = true;\n\tbGrabVideo = true;\n\n\t// set defaults\n\tbGrabberInited = false;\n\n\tbNeedsUpdateVideo = false;\n\tbNeedsUpdateDepth = false;\n\tbIsFrameNewVideo = false;\n\tbIsFrameNewDepth = false;\n    \n\tbIsVideoInfrared = false;\n\tvideoBytesPerPixel = 3;\n\n\tkinectDevice = NULL;\n\n\ttargetTiltAngleDeg = 0;\n\tcurrentTiltAngleDeg = 0;\n\tbTiltNeedsApplying = false;\n    \n    currentLed = -1;\n    bLedNeedsApplying = false;\n\tbHasMotorControl = false;\n\t\n\tlastDeviceId = -1;\n\ttryCount = 0;\n\ttimeSinceOpen = 0;\n\tbGotData = false;\n\n\tbUseRegistration = false;\n\tbNearWhite = true;\n\n\tsetDepthClipping();\n}\n\n//--------------------------------------------------------------------\nofxKinect::~ofxKinect() {\n\tclose();\n\tclear();\n}\n\n//--------------------------------------------------------------------\nbool ofxKinect::init(bool infrared, bool video, bool texture) {\n\tif(isConnected()) {\n\t\tofLogWarning(\"ofxKinect\") << \"init(): do not call init while ofxKinect is running!\";\n\t\treturn false;\n\t}\n\n\tclear();\n\n\tbIsVideoInfrared = infrared;\n\tbGrabVideo = video;\n\tvideoBytesPerPixel = infrared?1:3;\n\n\tbUseTexture = texture;\n\n\t// allocate\n\tdepthPixelsRaw.allocate(width, height, 1);\n\tdepthPixelsRawBack.allocate(width, height, 1);\n\tdepthPixelsRawIntra.allocate(width, height, 1);\n\n\tvideoPixels.allocate(width, height, videoBytesPerPixel);\n\tvideoPixelsBack.allocate(width, height, videoBytesPerPixel);\n\tvideoPixelsIntra.allocate(width, height, videoBytesPerPixel);\n\n\tdepthPixels.allocate(width, height, 1);\n\tdistancePixels.allocate(width, height, 1);\n\n\t // set\n\tdepthPixelsRaw.set(0);\n\tdepthPixelsRawBack.set(0);\n\n\tvideoPixels.set(0);\n\tvideoPixelsBack.set(0);\n\n\tdepthPixels.set(0);    \n\tdistancePixels.set(0);\n\n\tif(bUseTexture) {\n\t\tdepthTex.allocate(width, height, GL_LUMINANCE);\n\t\tvideoTex.allocate(width, height, infrared ? GL_LUMINANCE : GL_RGB);\n\t}\n\n\tif(!kinectContext.isInited()) {\n\t\tif(!kinectContext.init()) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tbGrabberInited = true;\n\n\treturn bGrabberInited;\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinect::clear() {\n\tif(isConnected()) {\n\t\tofLogWarning(\"ofxKinect\") << \"clear(): do not call clear while ofxKinect is running!\";\n\t\treturn;\n\t}\n\n\tdepthPixelsRaw.clear();\n\tdepthPixelsRawBack.clear();\n\n\tvideoPixels.clear();\n\tvideoPixelsBack.clear();\n\n\tdepthPixels.clear();\n\tdistancePixels.clear();\n\n\tdepthTex.clear();\n\tvideoTex.clear();\n\n\tbGrabberInited = false;\n}\n\n//--------------------------------------------------------------------\nvoid ofxKinect::setRegistration(bool bUseRegistration) {\n\tthis->bUseRegistration = bUseRegistration;\n}\n\n//--------------------------------------------------------------------\nbool ofxKinect::open(int id) {\n\tif(!bGrabberInited) {\n\t\tofLogWarning(\"ofxKinect\") << \"open(): cannot open, init not called\";\n\t\treturn false;\n\t}\n\n\tif(!kinectContext.open(*this, id)) {\n\t\treturn false;\n\t}\n\n\tif(serial == \"0000000000000000\") {\n\t\tofLogVerbose(\"ofxKinect\") << \"open(): device \" << deviceId << \" does not have motor control\";\n\t\tbHasMotorControl = false;\n\t}\n\telse {\n\t\tbHasMotorControl = true;\n\t}\n\n\tlastDeviceId = deviceId;\n\ttimeSinceOpen = ofGetElapsedTimef();\n\tbGotData = false;\n\n\tfreenect_set_user(kinectDevice, this);\n\tfreenect_set_depth_buffer(kinectDevice, depthPixelsRawBack.getPixels());\n\tfreenect_set_video_buffer(kinectDevice, videoPixelsBack.getPixels());\n\tfreenect_set_depth_callback(kinectDevice, &grabDepthFrame);\n\tfreenect_set_video_callback(kinectDevice, &grabVideoFrame);\n\n\tstartThread(true, false); // blocking, not verbose\n\n\treturn true;\n}\n\n//--------------------------------------------------------------------\nbool ofxKinect::open(string serial) {\n\tif(!bGrabberInited) {\n\t\tofLogVerbose(\"ofxKinect\") << \"open(): cannot open, init not called\";\n\t\treturn false;\n\t}\n\t\n\tif(!kinectContext.open(*this, serial)) {\n\t\treturn false;\n\t}\n\t\n\tif(serial == \"0000000000000000\") {\n\t\tofLogVerbose(\"ofxKinect\") << \"open(): device \" << deviceId << \" does not have motor control\";\n\t\tbHasMotorControl = false;\n\t}\n\telse {\n\t\tbHasMotorControl = true;\n\t}\n\t\n\tlastDeviceId = deviceId;\n\ttimeSinceOpen = ofGetElapsedTimef();\n\tbGotData = false;\n\t\n\tfreenect_set_user(kinectDevice, this);\n\tfreenect_set_depth_callback(kinectDevice, &grabDepthFrame);\n\tfreenect_set_video_callback(kinectDevice, &grabVideoFrame);\n\t\n\tstartThread(true, false); // blocking, not verbose\n\t\n\treturn true;\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinect::close() {\n\tif(isThreadRunning()) {\n\t\tstopThread();\n\t\tofSleepMillis(10);\n\t\twaitForThread(false);\n\t}\n\n\tdeviceId = -1;\n\tserial = \"\";\n\tbIsFrameNewVideo = false;\n\tbNeedsUpdateVideo = false;\n\tbIsFrameNewDepth = false;\n\tbNeedsUpdateDepth = false;\n}\n\n//---------------------------------------------------------------------------\nbool ofxKinect::isConnected() {\n\treturn isThreadRunning();\n}\n\n//--------------------------------------------------------------------\nbool ofxKinect::isFrameNew() {\n\treturn isFrameNewVideo() || isFrameNewDepth();\n}\n\n//--------------------------------------------------------------------\nbool ofxKinect::isFrameNewVideo(){\n\treturn bIsFrameNewVideo;\n}\n\n//--------------------------------------------------------------------\nbool ofxKinect::isFrameNewDepth(){\n\treturn bIsFrameNewDepth;\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::update() {\n\tif(!bGrabberInited) {\n\t\treturn;\n\t}\n\n\tif(!bNeedsUpdateVideo && !bNeedsUpdateDepth && !bGotData && tryCount < 5 && ofGetElapsedTimef() - timeSinceOpen > 2.0 ){\n\t\tclose();\n\t\tofLogWarning(\"ofxKinect\") << \"update(): device \" << lastDeviceId << \" isn't delivering data, reconnecting tries: \" << tryCount+1;\n\t\tkinectContext.buildDeviceList();\n\t\topen(lastDeviceId);\n\t\ttryCount++;\n\t\ttimeSinceOpen = ofGetElapsedTimef();\n\t\treturn;\n\t}\n\n\tif(bNeedsUpdateVideo){\n\t\tbIsFrameNewVideo = true;\n\t\tbGotData = true;\n\t\ttryCount = 0;\n\t\tif(this->lock()) {\n\t\t\tswap(videoPixels,videoPixelsIntra);\n\t\t\tbNeedsUpdateVideo = false;\n\t\t\tthis->unlock();\n\t\t}\n\n\t\tif(bUseTexture) {\n\t\t\tvideoTex.loadData(videoPixels.getPixels(), width, height, bIsVideoInfrared?GL_LUMINANCE:GL_RGB);\n\t\t}\n\t} else {\n\t\tbIsFrameNewVideo = false;\n\t}\n\n\tif(bNeedsUpdateDepth){\n\t\tbIsFrameNewDepth = true;\n\t\tbGotData = true;\n\t\ttryCount = 0;\n\t\tif(this->lock()) {\n\t\t\tswap(depthPixelsRaw, depthPixelsRawIntra);\n\t\t\tbNeedsUpdateDepth = false;\n\t\t\tthis->unlock();\n\n\t\t\tupdateDepthPixels();\n\t\t}\n\n\t\tif(bUseTexture) {\n\t\t\tdepthTex.loadData(depthPixels.getPixels(), width, height, GL_LUMINANCE);\n\t\t}\n\t} else {\n\t\tbIsFrameNewDepth = false;\n\t}\n\n}\n\n//------------------------------------\nfloat ofxKinect::getDistanceAt(int x, int y) {\n\treturn depthPixelsRaw[y * width + x];\n}\n\n//------------------------------------\nfloat ofxKinect::getDistanceAt(const ofPoint & p) {\n\treturn getDistanceAt(p.x, p.y);\n}\n\n//------------------------------------\nofVec3f ofxKinect::getWorldCoordinateAt(int x, int y) {\n\treturn getWorldCoordinateAt(x, y, getDistanceAt(x, y));\n}\n\n//------------------------------------\nofVec3f ofxKinect::getWorldCoordinateAt(float cx, float cy, float wz) {\n\tdouble wx, wy;\n\tfreenect_camera_to_world(kinectDevice, cx, cy, wz, &wx, &wy);\n\treturn ofVec3f(wx, wy, wz);\n}\n\n//------------------------------------\nfloat ofxKinect::getSensorEmitterDistance() {\n\treturn kinectDevice->registration.zero_plane_info.dcmos_emitter_dist;\n}\n\n//------------------------------------\nfloat ofxKinect::getSensorCameraDistance() {\n\treturn kinectDevice->registration.zero_plane_info.dcmos_rcmos_dist;\n}\n\n//------------------------------------\nfloat ofxKinect::getZeroPlanePixelSize() {\n\treturn kinectDevice->registration.zero_plane_info.reference_pixel_size;\n}\n\n//------------------------------------\nfloat ofxKinect::getZeroPlaneDistance() {\n\treturn kinectDevice->registration.zero_plane_info.reference_distance;\n}\n\n//------------------------------------\nofColor ofxKinect::getColorAt(int x, int y) {\n\tint index = (y * width + x) * videoBytesPerPixel;\n\tofColor c;\n\tc.r = videoPixels[index + 0];\n\tc.g = videoPixels[index + (videoBytesPerPixel-1)/2];\n\tc.b = videoPixels[index + (videoBytesPerPixel-1)];\n\tc.a = 255;\n\n\treturn c;\n}\n\n//------------------------------------\nofColor ofxKinect::getColorAt(const ofPoint & p) {\n\treturn getColorAt(p.x, p.y);\n}\n\n//---------------------------------------------------------------------------\nunsigned char * ofxKinect::getPixels() {\n\treturn videoPixels.getPixels();\n}\n\n//---------------------------------------------------------------------------\nunsigned char * ofxKinect::getDepthPixels() {\n\treturn depthPixels.getPixels();\n}\n\n//---------------------------------------------------------------------------\nunsigned short * ofxKinect::getRawDepthPixels() {\n\treturn depthPixelsRaw.getPixels();\n}\n\n//---------------------------------------------------------------------------\nfloat* ofxKinect::getDistancePixels() {\n\treturn distancePixels.getPixels();\n}\n\nofPixels & ofxKinect::getPixelsRef(){\n\treturn videoPixels;\n}\n\nofPixels & ofxKinect::getDepthPixelsRef(){\n\treturn depthPixels;\n}\n\nofShortPixels & ofxKinect::getRawDepthPixelsRef(){\n\treturn depthPixelsRaw;\n}\n\nofFloatPixels & ofxKinect::getDistancePixelsRef(){\n\treturn distancePixels;\n}\n\n//------------------------------------\nofTexture& ofxKinect::getTextureReference(){\n\tif(!videoTex.bAllocated()){\n\t\tofLogWarning(\"ofxKinect\") << \"getTextureReference(): device \" << deviceId << \" video texture not allocated\";\n\t}\n\treturn videoTex;\n}\n\n//---------------------------------------------------------------------------\nofTexture& ofxKinect::getDepthTextureReference(){\n\tif(!depthTex.bAllocated()){\n\t\tofLogWarning(\"ofxKinect\") << \"getDepthTextureReference(): device \" << deviceId << \" depth texture not allocated\";\n\t}\n\treturn depthTex;\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinect::enableDepthNearValueWhite(bool bEnabled) {\n\tbNearWhite = bEnabled;\n\tupdateDepthLookupTable();\n}\n\n//---------------------------------------------------------------------------\nbool ofxKinect::isDepthNearValueWhite() {\n\treturn bNearWhite;\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinect::setDepthClipping(float nearClip, float farClip) {\n\tnearClipping = nearClip;\n\tfarClipping = farClip;\n\tupdateDepthLookupTable();\n}\n\n//---------------------------------------------------------------------------\nfloat ofxKinect::getNearClipping() {\n    return nearClipping;\n}\n\n//---------------------------------------------------------------------------\nfloat ofxKinect::getFarClipping() {\n    return farClipping;\n}\n\n//--------------------------------------------------------------------\nbool ofxKinect::hasAccelControl() {\n\treturn bHasMotorControl; // depends on motor for now\n}\n\nbool ofxKinect::hasCamTiltControl() {\n\treturn bHasMotorControl; // depends on motor for now\n}\n\nbool ofxKinect::hasLedControl() {\n\treturn bHasMotorControl; // depends on motor for now\n}\n\n//---------------------------------------------------------------------------\nofPoint ofxKinect::getRawAccel() {\n\treturn rawAccel;\n}\n\n//---------------------------------------------------------------------------\nofPoint ofxKinect::getMksAccel() {\n\treturn mksAccel;\n}\n\n//---------------------------------------------------------------------------\nfloat ofxKinect::getAccelPitch(){\n\treturn ofRadToDeg(asin(getMksAccel().z/OFX_KINECT_GRAVITY));\n}\n\n//---------------------------------------------------------------------------\nfloat ofxKinect::getAccelRoll(){\n\treturn ofRadToDeg(asin(getMksAccel().x/OFX_KINECT_GRAVITY));\n}\n\n// we update the value here, but apply it in kinect thread\n//--------------------------------------------------------------------\nbool ofxKinect::setCameraTiltAngle(float angleInDegrees) {\n\n\tif(!hasCamTiltControl() || !bGrabberInited) {\n\t\treturn false;\n\t}\n\n\ttargetTiltAngleDeg = ofClamp(angleInDegrees, -30, 30);\n\tbTiltNeedsApplying = true;\n\n\treturn true;\n}\n\n//--------------------------------------------------------------------\nfloat ofxKinect::getTargetCameraTiltAngle() {\n\treturn targetTiltAngleDeg;\n}\n\nfloat ofxKinect::getCurrentCameraTiltAngle() {\n\treturn currentTiltAngleDeg;\n}\n\n//--------------------------------------------------------------------\n\nvoid ofxKinect::setLed(ofxKinect::LedMode mode) {\n\tif(!hasLedControl() || mode == currentLed) {\n\t\treturn;\n\t}\n    bLedNeedsApplying = true;\n    currentLed = mode;\n}\n\n//------------------------------------\nvoid ofxKinect::setUseTexture(bool bUse){\n\tbUseTexture = bUse;\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::draw(float _x, float _y, float _w, float _h) {\n\tif(bUseTexture && bGrabVideo) {\n\t\tvideoTex.draw(_x, _y, _w, _h);\n\t}\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::draw(float _x, float _y) {\n\tdraw(_x, _y, (float)width, (float)height);\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::draw(const ofPoint & point) {\n\tdraw(point.x, point.y);\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::draw(const ofRectangle & rect) {\n\tdraw(rect.x, rect.y, rect.width, rect.height);\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::drawDepth(float _x, float _y, float _w, float _h) {\n\tif(bUseTexture) {\n\t\tdepthTex.draw(_x, _y, _w, _h);\n\t}\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinect::drawDepth(float _x, float _y) {\n\tdrawDepth(_x, _y, (float)width, (float)height);\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::drawDepth(const ofPoint & point) {\n\tdrawDepth(point.x, point.y);\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::drawDepth(const ofRectangle & rect) {\n\tdrawDepth(rect.x, rect.y, rect.width, rect.height);\n}\n\n//---------------------------------------------------------------------------\nint ofxKinect::getDeviceId() {\n\treturn deviceId;\n}\n\n//---------------------------------------------------------------------------\nstring ofxKinect::getSerial() {\n\treturn serial;\n}\n\n//----------------------------------------------------------\nfloat ofxKinect::getHeight() {\n\treturn (float) height;\n}\n\n//---------------------------------------------------------------------------\nfloat ofxKinect::getWidth() {\n\treturn (float) width;\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::listDevices() {\n\tkinectContext.listDevices();\n}\n\n//---------------------------------------------------------------------------\nint ofxKinect::numTotalDevices() {\n\treturn kinectContext.numTotal();\n}\n\n//---------------------------------------------------------------------------\nint ofxKinect::numAvailableDevices() {\n\treturn kinectContext.numAvailable();\n}\n\n//---------------------------------------------------------------------------\nint ofxKinect::numConnectedDevices() {\n\treturn kinectContext.numConnected();\n}\n\n//---------------------------------------------------------------------------\nbool ofxKinect::isDeviceConnected(int id) {\n\treturn kinectContext.isConnected(id);\n}\n\n//---------------------------------------------------------------------------\nbool ofxKinect::isDeviceConnected(string serial) {\n\treturn kinectContext.isConnected(serial);\n}\n\n//---------------------------------------------------------------------------\nint ofxKinect::nextAvailableId() {\n\treturn kinectContext.nextAvailableId();\n}\n\n//---------------------------------------------------------------------------\nstring ofxKinect::nextAvailableSerial() {\n\treturn kinectContext.nextAvailableSerial();\n}\n\n/* ***** PRIVATE ***** */\n\n//---------------------------------------------------------------------------\nvoid ofxKinect::updateDepthLookupTable() {\n\tunsigned char nearColor = bNearWhite ? 255 : 0;\n\tunsigned char farColor = bNearWhite ? 0 : 255;\n\tunsigned int maxDepthLevels = 10001;\n\tdepthLookupTable.resize(maxDepthLevels);\n\tdepthLookupTable[0] = 0;\n\tfor(unsigned int i = 1; i < maxDepthLevels; i++) {\n\t\tdepthLookupTable[i] = ofMap(i, nearClipping, farClipping, nearColor, farColor, true);\n\t}\n}\n\n//----------------------------------------------------------\nvoid ofxKinect::updateDepthPixels() {\n\tint n = width * height;\n\tfor(int i = 0; i < n; i++) {\n\t\tdistancePixels[i] = depthPixelsRaw[i];\n\t}\n\tfor(int i = 0; i < n; i++) {\n\t\tdepthPixels[i] = depthLookupTable[depthPixelsRaw[i]];\n\t}\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinect::grabDepthFrame(freenect_device *dev, void *depth, uint32_t timestamp) {\n\n\tofxKinect* kinect = kinectContext.getKinect(dev);\n\n\tif(kinect->kinectDevice == dev) {\n\t\tkinect->lock();\n\t\tswap(kinect->depthPixelsRawBack,kinect->depthPixelsRawIntra);\n\t\tkinect->bNeedsUpdateDepth = true;\n\t\tkinect->unlock();\n\t\tfreenect_set_depth_buffer(kinect->kinectDevice,kinect->depthPixelsRawBack.getPixels());\n    }\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinect::grabVideoFrame(freenect_device *dev, void *video, uint32_t timestamp) {\n\n\tofxKinect* kinect = kinectContext.getKinect(dev);\n\n\tif(kinect->kinectDevice == dev) {\n\t\tkinect->lock();\n\t\tswap(kinect->videoPixelsBack,kinect->videoPixelsIntra);\n\t\tkinect->bNeedsUpdateVideo = true;\n\t\tkinect->unlock();\n\t\tfreenect_set_video_buffer(kinect->kinectDevice,kinect->videoPixelsBack.getPixels());\n\t}\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinect::threadedFunction(){\n\n\tif(currentLed < 0) { \n        freenect_set_led(kinectDevice, (freenect_led_options)ofxKinect::LED_GREEN); \n    }\n\t\n\tfreenect_frame_mode videoMode = freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, bIsVideoInfrared?FREENECT_VIDEO_IR_8BIT:FREENECT_VIDEO_RGB);\n\tfreenect_set_video_mode(kinectDevice, videoMode);\n\tfreenect_frame_mode depthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, bUseRegistration?FREENECT_DEPTH_REGISTERED:FREENECT_DEPTH_MM);\n\tfreenect_set_depth_mode(kinectDevice, depthMode);\n\n\tofLogVerbose(\"ofxKinect\") << \"device \" << deviceId << \" \" << serial << \" connection opened\";\n\n\tfreenect_start_depth(kinectDevice);\n\tif(bGrabVideo) {\n\t\tfreenect_start_video(kinectDevice);\n\t}\n\n\twhile(isThreadRunning() && freenect_process_events(kinectContext.getContext()) >= 0) {\n\t\t\n\t\tif(bTiltNeedsApplying) {\n\t\t\tfreenect_set_tilt_degs(kinectDevice, targetTiltAngleDeg);\n\t\t\tbTiltNeedsApplying = false;\n\t\t}\n\t\t\n\t\tif(bLedNeedsApplying) {\n\t\t\tif(currentLed == ofxKinect::LED_DEFAULT) {\n\t\t\t\tfreenect_set_led(kinectDevice, (freenect_led_options)ofxKinect::LED_GREEN);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfreenect_set_led(kinectDevice, (freenect_led_options)currentLed);\n\t\t\t}\n\t\t\tbLedNeedsApplying = false;\n\t\t}\n\n\t\tfreenect_update_tilt_state(kinectDevice);\n\t\tfreenect_raw_tilt_state * tilt = freenect_get_tilt_state(kinectDevice);\n\t\tcurrentTiltAngleDeg = freenect_get_tilt_degs(tilt);\n\n\t\trawAccel.set(tilt->accelerometer_x, tilt->accelerometer_y, tilt->accelerometer_z);\n\n\t\tdouble dx,dy,dz;\n\t\tfreenect_get_mks_accel(tilt, &dx, &dy, &dz);\n\t\tmksAccel.set(dx, dy, dz);\n\t}\n\n\t// finish up a tilt on exit\n\tif(bTiltNeedsApplying) {\n\t\tfreenect_set_tilt_degs(kinectDevice, targetTiltAngleDeg);\n\t\tbTiltNeedsApplying = false;\n\t}\n\n\tfreenect_stop_depth(kinectDevice);\n\tfreenect_stop_video(kinectDevice);\n\tif(currentLed < 0) { \n        freenect_set_led(kinectDevice, (freenect_led_options)ofxKinect::LED_YELLOW); \n    }\n\n\tkinectContext.close(*this);\n\tofLogVerbose(\"ofxKinect\") << \"device \" << deviceId << \" connection closed\";\n}\n\n//---------------------------------------------------------------------------\n// ofxKinectContext\n//---------------------------------------------------------------------------\n\n//---------------------------------------------------------------------------\nofxKinectContext::ofxKinectContext() {\n\tbInited = false;\n\tkinectContext = NULL;\n}\nofxKinectContext::~ofxKinectContext() {\n\tcloseAll();\n\tclear();\n}\n\n//---------------------------------------------------------------------------\nstatic bool sortKinectPairs(ofxKinectContext::KinectPair A, ofxKinectContext::KinectPair B){\n\treturn A.serial < B.serial;\n}\n        \n//---------------------------------------------------------------------------\nbool ofxKinectContext::init() {\n\t\n\tif(freenect_init(&kinectContext, NULL) < 0) {\n\t\tofLogError(\"ofxKinect\") << \"init(): freenect_init failed\";\n\t\tbInited = false;\n\t\treturn false;\n\t}\n\tfreenect_set_log_level(kinectContext, FREENECT_LOG_WARNING);\n\tfreenect_select_subdevices(kinectContext, (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA));\n\n\tbInited = true;\n\tofLogVerbose(\"ofxKinect\") << \"context inited\";\n\t\n\tbuildDeviceList();\n\tlistDevices(true);\n\n\treturn true;\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinectContext::clear() {\n\tif(isInited() && numConnected() < 1) {\n\t\tfreenect_shutdown(kinectContext);\n\t\tkinectContext = NULL;\n\t\tbInited = false;\n\t\tofLogVerbose(\"ofxKinect\") << \"context cleared\";\n\t}\n}\n\nbool ofxKinectContext::isInited() {\n\treturn bInited;\n}\n\nbool ofxKinectContext::open(ofxKinect& kinect, int id) {\n\t\n\t// rebuild if necessary (aka new kinects plugged in)\n\tbuildDeviceList();\n\t\n\tif(numConnected() >= numTotal()) {\n\t\tofLogWarning(\"ofxKinect\") << \"no available devices found\";\n\t\treturn false;\n\t}\n\t\n\t// is the id available?\n\tif(id < 0) {\n\t\tid = nextAvailableId();\n\t}\n\tif(isConnected(id)) {\n\t\tofLogWarning(\"ofxKinect\") << \"device \" << id << \" already connected\";\n\t\treturn false;\n\t}\n\t\n\t// open and add to vector\n\tif(freenect_open_device(kinectContext, &kinect.kinectDevice, id) < 0) {\n\t\tofLogError(\"ofxKinect\") << \"could not open device \" <<  id;\n\t\treturn false;\n\t}\n\tkinects.insert(pair<int,ofxKinect*>(id, &kinect));\n\t\n\t// set kinect id & serial from bus id\n\tkinect.deviceId = id;\n\tkinect.serial = deviceList[getDeviceIndex(id)].serial;\n\n\treturn true;\n}\n\nbool ofxKinectContext::open(ofxKinect& kinect, string serial) {\n\t\n\t// rebuild if necessary (aka new kinects plugged in)\n\tbuildDeviceList();\n\t\n\tif(numConnected() >= numTotal()) {\n\t\tofLogWarning(\"ofxKinect\") << \"no available devices found\";\n\t\treturn false;\n\t}\n\t\n\t// is the serial available?\n\tif(isConnected(serial)) {\n\t\tofLogWarning(\"ofxKinect\") << \"device \" << serial << \" already connected\";\n\t\treturn false;\n\t}\n\t\n\t// open and add to vector\n\tif(freenect_open_device_by_camera_serial(kinectContext, &kinect.kinectDevice, serial.c_str()) < 0) {\n\t\tofLogError(\"ofxKinect\") << \"could not open device \" << serial;\n\t\treturn false;\n\t}\n\tint index = getDeviceIndex(serial);\n\tkinects.insert(pair<int,ofxKinect*>(deviceList[index].id, &kinect));\n\tkinect.deviceId = deviceList[index].id;\n\tkinect.serial = serial;\n\t\n\treturn true;\n}\n\nvoid ofxKinectContext::close(ofxKinect& kinect) {\n\n\t// check if it's already closed\n\tint id = -1;\n\tstd::map<int,ofxKinect*>::iterator iter;\n\tfor(iter = kinects.begin(); iter != kinects.end(); ++iter) {\n\t\tif(iter->second == &kinect) {\n\t\t\tid = iter->first;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif(id == -1)\n\t\treturn;\n\n\t// remove connected device and close\n\titer = kinects.find(id);\n\tif(iter != kinects.end()) {\n\t\tkinects.erase(iter);\n\t\tfreenect_close_device(kinect.kinectDevice);\n\t}\n}\n\nvoid ofxKinectContext::closeAll() {\n\t// make copy of map to avoid invalidating iter when calling close()\n\tstd::map<int,ofxKinect*> kinectsCopy(kinects);\n    std::map<int,ofxKinect*>::iterator iter;\n    for(iter = kinectsCopy.begin(); iter != kinectsCopy.end(); ++iter) {\n        iter->second->close();\n    }\n}\n\n//---------------------------------------------------------------------------\nvoid ofxKinectContext::buildDeviceList() {\n\t\n\tdeviceList.clear();\n\t\n\t// build the device list from freenect\n\tfreenect_device_attributes * devAttrib; \n\tint numDevices = freenect_list_device_attributes(kinectContext, &devAttrib);\n\t\n\t// save bus ids ...\n\tfor(int i = 0; i < numDevices; i++){\n\t\tKinectPair kp;\n\t\tkp.id = i;\n\t\tkp.serial = (string) devAttrib->camera_serial; \n\t\tdeviceList.push_back(kp);\n\t\tdevAttrib = devAttrib->next;\n\t}\n\tfreenect_free_device_attributes(devAttrib);\n\t\n\t// sort devices by serial number\n\tsort(deviceList.begin(), deviceList.end(), sortKinectPairs);\n}\n\nvoid ofxKinectContext::listDevices(bool verbose) {\n    if(!isInited())\n\t\tinit();\n\t\n\tstringstream stream;\n\t\n\tif(numTotal() == 0) {\n\t\tstream << \"no devices found\";\n\t\treturn;\n\t}\n\telse if(numTotal() == 1) {\n\t\tstream << 1 << \" device found\";\n\t}\n\telse {\n\t\tstream << deviceList.size() << \" devices found\";\n\t}\n\t\n\tif(verbose) {\n\t\tofLogVerbose(\"ofxKinect\") << stream.str();\n\t}\n\telse {\n\t\tofLogNotice(\"ofxKinect\") << stream.str();\n\t}\n\tstream.str(\"\");\n\t\n\tfor(unsigned int i = 0; i < deviceList.size(); ++i) {\n\t\tstream << \"    id: \" << deviceList[i].id << \" serial: \" << deviceList[i].serial;\n\t\tif(verbose) {\n\t\t\tofLogVerbose(\"ofxKinect\") << stream.str();\n\t\t}\n\t\telse {\n\t\t\tofLogNotice(\"ofxKinect\") << stream.str();\n\t\t}\n\t\tstream.str(\"\");\n\t}\n}\n\nint ofxKinectContext::numTotal() {\n    if(!isInited())\n\t\tinit();\n    return freenect_num_devices(kinectContext);\n}\n\nint ofxKinectContext::numAvailable() {\n\tif(!isInited())\n\t\tinit();\n    return freenect_num_devices(kinectContext) - kinects.size();\n}\n\nint ofxKinectContext::numConnected() {\n\treturn kinects.size();\n}\n\nofxKinect* ofxKinectContext::getKinect(freenect_device* dev) {\n\tstd::map<int,ofxKinect*>::iterator iter;\n\tfor(iter = kinects.begin(); iter != kinects.end(); ++iter) {\n\t\tif(iter->second->kinectDevice == dev)\n\t\t\treturn iter->second;\n\t}\n\treturn NULL;\n}\n\nint ofxKinectContext::getDeviceIndex(int id) {\n\tfor(unsigned int i = 0; i < deviceList.size(); ++i) {\n\t\tif(deviceList[i].id == id)\n\t\t\treturn i;\n\t}\n\treturn -1;\n}\n\nint ofxKinectContext::getDeviceIndex(string serial) {\n\tfor(unsigned int i = 0; i < deviceList.size(); ++i) {\n\t\tif(deviceList[i].serial == serial)\n\t\t\treturn i;\n\t}\n\treturn -1;\n}\n\nbool ofxKinectContext::isConnected(int id) {\n\tstd::map<int,ofxKinect*>::iterator iter = kinects.find(id);\n\treturn iter != kinects.end();\n}\n\nbool ofxKinectContext::isConnected(string serial) {\n\tstd::map<int,ofxKinect*>::iterator iter;\n\tfor(iter = kinects.begin(); iter != kinects.end(); ++iter) {\n\t\tif(iter->second->getSerial() == serial)\n\t\t\treturn true;\n\t}\n\treturn false;\n}\n\nint ofxKinectContext::nextAvailableId() {\n\tif(!isInited())\n\t\tinit();\n\t\n\t// a brute force free index finder :D\n\tstd::map<int,ofxKinect*>::iterator iter;\n\tfor(unsigned int i = 0; i < deviceList.size(); ++i) {\n\t\titer = kinects.find(deviceList[i].id);\n\t\tif(iter == kinects.end())\n\t\t\treturn deviceList[i].id;\n\t}\n\treturn -1;\n}\n\nstring ofxKinectContext::nextAvailableSerial() {\n\tif(!isInited())\n\t\tinit();\n\t\n\tint id = nextAvailableId();\n\tif(id == -1) {\n\t\treturn \"\";\n\t}\n\treturn deviceList[getDeviceIndex(id)].serial;\n}\n\n"
  },
  {
    "path": "src/ofxKinect.h",
    "content": "/*==============================================================================\n\n    Copyright (c) 2010, 2011 ofxKinect Team\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n    \n    ----------------------------------------------------------------------------\n    \n    This project uses libfreenect, copyrighted by the Open Kinect Project using\n    the Apache License v2. See the file \"APACHE20\" in libs/libfreenect.\n    \n    See http://www.openkinect.org & https://github.com/OpenKinect/libfreenect \n    for documentation\n    \n==============================================================================*/\n#pragma once\n\n#include \"ofMain.h\"\n#include \"libfreenect.h\"\n\n#include \"ofxBase3DVideo.h\"\n\n#if defined(_MSC_VER) || defined(_WIN32) || defined(WIN32) || defined(__MINGW32__)\n    // do windows stuff\n#else\n    // mac and linux need this\n    #include <libusb.h>\n#endif\n\nclass ofxKinectContext;\n\n/// \\class ofxKinect\n///\n/// wrapper for a freenect kinect device\n///\n/// references:\n/// - http://openkinect.org/wiki/Main_Page\n/// - https://github.com/OpenKinect/libfreenect/blob/master/include/libfreenect.h\n///\nclass ofxKinect : public ofxBase3DVideo, protected ofThread {\n\npublic:\n\n\tofxKinect();\n\tvirtual ~ofxKinect();\n\n/// \\section Main\n\n\t/// initialize resources, must be called before open()\n\t/// infrared controls whether the video image is rgb or IR\n\t/// set video to false to disable video image grabbing (saves bandwidth)\n\t/// set texture to false if you don't need to use the internal textures\n\t///\n\t/// naturally, if you disable the video image the video pixels and\n\t/// RGB color will be 0\n\tbool init(bool infrared=false, bool video=true, bool texture=true);\n\n\t/// clear resources, do not call this while ofxKinect is running!\n\tvoid clear();\n\n\t/// calibrates the depth image to align with the rgb image, disabled by default\n\t///\n\t/// call this before open(), has no effect while the connection is running\n\t///\n\t/// note: this calculation uses some cpu, leave off if not needed\n\tvoid setRegistration(bool bUseRegistration=false);\n\n\t/// open the connection and start grabbing images\n\t///\n\t/// set the id to choose a kinect, see numAvailableDevices()\n\t/// if you don't set the id (ie id=-1), the first available kinect will be used\n\t///\n\t/// note: this is the freenct bus id and may change each time the app is run\n\tbool open(int id=-1);\n\t\n\t/// open using a kinect unique serial number\n\t///\n\t/// NOTE: currently, libfreenect returns a serial number with all 0s for\n\t/// kinect models > 1414, so this will only work with the original xbox kinect\n\tbool open(string serial);\n\n\t/// close the connection and stop grabbing images\n\tvoid close();\n\n\t/// is the connection currently open?\n\tbool isConnected();\n\n\t/// is the current frame new?\n\tbool isFrameNew();\n\tbool isFrameNewVideo();\n\tbool isFrameNewDepth();\n\n\t/// updates the pixel buffers and textures\n\t///\n\t/// make sure to call this to update to the latest incoming frames\n\tvoid update();\n\n/// \\section Depth Data\n\n\t/// get the calulated distance for a depth point\n\tfloat getDistanceAt(int x, int y);\n\tfloat getDistanceAt(const ofPoint & p);\n\n\t/// calculates the coordinate in the world for the depth point (perspective calculation)\n\t///\n\t/// center of image is (0.0)\n\tofVec3f getWorldCoordinateAt(int cx, int cy);\n\tofVec3f getWorldCoordinateAt(float cx, float cy, float wz);\n\n/// \\section Intrinsic IR Sensor Parameters\n\n\t/// these values are used when depth registration is enabled to align the\n\t/// depth image to the rgb image, see http://www.ros.org/wiki/kinect_calibration/technical\n\t///\n\t/// they could also be useful for real world accurate point clouds ... weee!\n\t\n\t/// get the distance between the IR sensor and IR emitter in cm\n\tfloat getSensorEmitterDistance();\n\t\n\t/// get the distance between the IR sensor and the RGB camera in cm\n\tfloat getSensorCameraDistance();\n\t\n\t/// get the size of a single pixel on the zero plane in mm\n\tfloat getZeroPlanePixelSize();\n\t\n\t/// get the focal length of the IR sensor in mm\n\tfloat getZeroPlaneDistance();\n\n/// \\section RGB Data\n\n\t/// get the RGB value for a depth point\n\t///\n\t/// see setRegistration() for calibrated depth->RGB points\n\tofColor getColorAt(int x, int y);\n\tofColor getColorAt(const ofPoint & p);\n\n/// \\section Pixel Data\n\n\t/// get the pixels of the most recent rgb frame\n\t///\n\t/// see setRegistration() for a calibrated depth->RGB image\n\tunsigned char* getPixels();\n\n\t/// get the pixels of the most recent depth frame\n\tunsigned char* getDepthPixels();       ///< grayscale values\n\tunsigned short* getRawDepthPixels();   ///< raw 11 bit values\n\n\t/// get the distance in millimeters to a given point as a float array\n\tfloat* getDistancePixels();\n\n\t/// get the video pixels reference\n\tofPixels & getPixelsRef();\n\n\t/// get the pixels of the most recent depth frame\n\tofPixels & getDepthPixelsRef();       \t///< grayscale values\n\tofShortPixels & getRawDepthPixelsRef();\t///< raw 11 bit values\n\n\t/// get the distance in millimeters to a given point as a float array\n\tofFloatPixels & getDistancePixelsRef();\n\n\t/// get the video (ir or rgb) texture\n\tofTexture& getTextureReference();\n\n\t/// get the grayscale depth texture\n\tofTexture& getDepthTextureReference();\n\n/// \\section Grayscale Depth Value\n\n\t/// set the near value of the pixels in the grayscale depth image to white\n\t///\n\t/// bEnabled = true:  pixels closer to the camera are brighter (default)\n\t/// bEnabled = false: pixels closer to the camera are darker\n\tvoid enableDepthNearValueWhite(bool bEnabled=true);\n\tbool isDepthNearValueWhite();\n\n\t/// set the clipping planes for the depth calculations in millimeters\n\t///\n\t/// these are used for the depth value (12bit) -> grayscale (1 byte) conversion\n\t/// ie setting a short range will give you greater sensitivity from 0-255\n\t///\n\t/// default is 50cm - 4m\n\t/// note: you won't get any data < 50cm and distances > 4m start to get noisy\n\tvoid setDepthClipping(float nearClip=500, float farClip=4000);\n\tfloat getNearClipping();\n\tfloat getFarClipping();\n\n/// \\section Query Capabilities\n\n\t/// check for device capabilites ...\n\t/// motor, led, or accelerometer control isn't currently supported \n\t/// by libfreenect with newer Kinect models (> 1414)\n\tbool hasAccelControl();\n\tbool hasCamTiltControl();\n\tbool hasLedControl();\n\n/// \\section Accelerometer Data\n\n\t/// get the XYZ accelerometer values\n\t///\n\t/// ... yes, the kinect has an accelerometer\n\t\n\t/// raw axis values\n\tofPoint getRawAccel();\n\t\n\t/// axis-based gravity adjusted accelerometer values\n\t///\n\t/// from libfreeenect:\n\t///\n\t/// as laid out via the accelerometer data sheet, which is available at\n\t///\n\t/// http://www.kionix.com/Product%20Sheets/KXSD9%20Product%20Brief.pdf\n\t///\n\tofPoint getMksAccel();\n\n    /// get the current pitch (x axis) & roll (z axis) of the kinect in degrees\n    ///\n    /// useful to correct the 3d scene based on the camera inclination\n    ///\n\tfloat getAccelPitch();\n\tfloat getAccelRoll();\n\n/// \\section Camera Tilt Motor\n\n\t/// set tilt angle of the camera in degrees\n\t/// 0 is flat, the range is -30 to 30\n\tbool setCameraTiltAngle(float angleInDegrees);\n\n\t/// get the current angle\n\tfloat getCurrentCameraTiltAngle();\n\n\t/// get the target angle (if the camera is currently moving)\n\tfloat getTargetCameraTiltAngle();\n        \n/// \\section LED\n    \n\tenum LedMode {\n\t\tLED_DEFAULT = -1, // yellow when not running, green when running\n\t\tLED_OFF = 0,\n\t\tLED_GREEN = 1,\n\t\tLED_RED = 2,\n\t\tLED_YELLOW = 3,\n\t\tLED_BLINK_GREEN = 4,\n\t\tLED_BLINK_YELLOW_RED = 6\n\t};\n\t\n    /// set the current led color and/or blink mode,\n\t/// only applied while the kinect is open\n    void setLed(ofxKinect::LedMode mode);\n\n/// \\section Draw\n\n\t/// enable/disable frame loading into textures on update()\n\tvoid setUseTexture(bool bUse);\n\n\t/// draw the video texture\n\tvoid draw(float x, float y, float w, float h);\n\tvoid draw(float x, float y);\n\tvoid draw(const ofPoint& point);\n\tvoid draw(const ofRectangle& rect);\n\n\t/// draw the grayscale depth texture\n\tvoid drawDepth(float x, float y, float w, float h);\n\tvoid drawDepth(float x, float y);\n\tvoid drawDepth(const ofPoint& point);\n\tvoid drawDepth(const ofRectangle& rect);\n\n/// \\section Util\n\n\t/// get the device id\n\t/// returns -1 if not connected\n\tint getDeviceId();\n\t\n\t/// get the unique serial number\n\t/// returns an empty string \"\" if not connected\n\t///\n\t/// NOTE: currently, libfreenect returns a serial number with all 0s for\n\t/// kinect models > 1414, so this will only work with the original xbox kinect\n\tstring getSerial();\n\n\t/// static kinect image size\n\tconst static int width = 640;\n\tconst static int height = 480;\n\tfloat getHeight();\n\tfloat getWidth();\n\n/// \\section Static global kinect context functions\n\n\t/// print the device list\n\tstatic void listDevices();\n\t\n\t/// get the total number of devices\n\tstatic int numTotalDevices();\n\n\t/// get the number of available devices (not connected)\n\tstatic int numAvailableDevices();\n\n\t/// get the number of currently connected devices\n\tstatic int numConnectedDevices();\n\n\t/// is a device already connected?\n\tstatic bool isDeviceConnected(int id);\n\tstatic bool isDeviceConnected(string serial);\n\n\t/// get the id of the next available device,\n\t/// returns -1 if nothing found\n\tstatic int nextAvailableId();\n\t\n\t/// get the serial number of the next available device,\n\t/// returns an empty string \"\" if nothing found\n\tstatic string nextAvailableSerial();\n\nprotected:\n\n\tint deviceId;\t///< -1 when not connected\n\tstring serial;\t///< unique serial number, \"\" when not connected\n\t\n\tbool bUseTexture;\n\tofTexture depthTex; ///< the depth texture\n\tofTexture videoTex; ///< the RGB texture\n\tbool bGrabberInited;\n\n\tofPixels videoPixels;\n\tofPixels depthPixels;\n\tofShortPixels depthPixelsRaw;\n\tofFloatPixels distancePixels;\n\n\tofPoint rawAccel;\n\tofPoint mksAccel;\n\n\tfloat targetTiltAngleDeg;\n\tfloat currentTiltAngleDeg;\n\tbool bTiltNeedsApplying;\n    \n    int currentLed;\n    bool bLedNeedsApplying;\n    bool bHasMotorControl; // cam tilt motor\n\t//bool bHasAccelContol; // for future use\n\t//bool bHasLedControl; // for future use\n\t\n\t// for auto connect tries\n\tfloat timeSinceOpen;\n\tint lastDeviceId;\n\tbool bGotData;\n\tint tryCount;\n\nprivate:\n\n\tfriend class ofxKinectContext;\n\n\t/// global statics shared between kinect instances\n\tstatic ofxKinectContext kinectContext;\n\n\tfreenect_device* kinectDevice;      ///< kinect device handle\n\n\tofShortPixels depthPixelsRawIntra;\t///< depth back\n\tofPixels videoPixelsIntra;\t\t\t///< rgb back\n\tofShortPixels depthPixelsRawBack;\t///< depth back\n\tofPixels videoPixelsBack;\t\t\t///< rgb back\n\n\tvector<unsigned char> depthLookupTable;\n\tvoid updateDepthLookupTable();\n\tvoid updateDepthPixels();\n\n\tbool bIsFrameNewVideo, bIsFrameNewDepth;\n\tbool bNeedsUpdateVideo, bNeedsUpdateDepth;\n\tbool bGrabVideo;\n\tbool bUseRegistration;\n\tbool bNearWhite;\n\n\tfloat nearClipping, farClipping;\n\n\tbool bIsVideoInfrared;  ///< is the video image infrared or RGB?\n\tint videoBytesPerPixel; ///< how many bytes per pixel in the video image\n\n\t/// libfreenect callbacks\n\tstatic void grabDepthFrame(freenect_device* dev, void* depth, uint32_t timestamp);\n\tstatic void grabVideoFrame(freenect_device* dev, void* video, uint32_t timestamp);\n\n\t/// thread function\n\tvoid threadedFunction();\n};\n\n/// \\class ofxKinectContext\n///\n/// wrapper for the freenect context\n///\n/// do not use this directly\n///\nclass ofxKinectContext {\n\npublic:\n\n\tofxKinectContext();\n\t~ofxKinectContext();\n\n/// \\section Main\n\n\t/// init the freenect context\n\tbool init();\n\n\t/// clear the freenect context\n\t/// closes all currently connected devices\n\tvoid clear();\n\n\t/// is the context inited?\n\tbool isInited();\n\n\t/// open a kinect device\n\t/// an id of -1 will open the first available\n\tbool open(ofxKinect& kinect, int id=-1);\n\t\n\t/// open a kinect device by it's unique serial number\n\tbool open(ofxKinect& kinect, string serial);\n\n\t/// close a kinect device\n\tvoid close(ofxKinect& kinect);\n\n\t/// closes all currently connected kinects\n\tvoid closeAll();\n\n/// \\section Util\n\t\n\t/// (re)build the list of devices\n\tvoid buildDeviceList();\n\t\n\t/// print the device list\n\tvoid listDevices(bool verbose=false);\n\t\n\t/// get the total number of devices\n\tint numTotal();\n\n\t/// get the number of available devices (not connected)\n\tint numAvailable();\n\n\t/// get the number of currently connected devices\n\tint numConnected();\n\n\t/// get the kinect object from a device pointer\n\t/// returns NULL if not found\n\tofxKinect* getKinect(freenect_device* dev);\n\t\n\t/// get the deviceList index from an id\n\t/// returns -1 if not found\n\tint getDeviceIndex(int id);\n\t\n\t/// get the deviceList index from an id\n\t/// returns -1 if not found\n\tint getDeviceIndex(string serial);\n\n\t/// is a device with this id already connected?\n\tbool isConnected(int id);\n\t\n\t/// is a device with this serial already connected?\n\tbool isConnected(string serial);\n\n\t/// get the id of the next available device,\n\t/// returns -1 if nothing found\n\tint nextAvailableId();\n\t\n\t/// get the serial number of the next available device,\n\t/// returns an empty string \"\" if nothing found\n\tstring nextAvailableSerial();\n\n\t/// get the raw pointer\n\tfreenect_context* getContext() {return kinectContext;}\n\n\t// for auto-enumeration\n    struct KinectPair{\n\t\tstring serial;\t///< unique serial number\n\t\tint id;\t\t\t///< freenect bus id\n    };\n\t\nprivate:\n    \n\tbool bInited;\t\t\t\t\t\t///< has the context been initialized?\n\tfreenect_context* kinectContext;    ///< kinect context handle\n\tstd::vector<KinectPair> deviceList;\t///< list of available devices, sorted by serial lexicographically\n\tstd::map<int,ofxKinect*> kinects;   ///< the connected kinects\n};\n"
  }
]