/** * Init the freenect library. This only has to be done once. * * @throws KinectException */ private static synchronized void init() throws KinectException { if (KinectController.CONTEXT == null) { final Pointer<Pointer<freenect_context>> ctxPointer = Pointer.pointerToPointer(null); libfreenectLibrary.freenect_init(ctxPointer, Pointer.NULL); if (ctxPointer == null) throw new KinectException("Unable to initialise libfreenect."); CONTEXT = ctxPointer.get(); if (CONTEXT == null) throw new KinectException("Unable to initialise libfreenect."); if (libfreenectLibrary.freenect_num_devices(CONTEXT) == 0) { libfreenectLibrary.freenect_shutdown(CONTEXT); throw new KinectException("Unable to initialise libfreenect; No devices found."); } EVENT_THREAD = new EventThread(); EVENT_THREAD.start(); // turn off the devices on shutdown Runtime.getRuntime().addShutdownHook(new Thread() { @Override public synchronized void run() { shutdownFreenect(); } }); } }
/** * Init the freenect library. This only has to be done once. * * @throws KinectException */ private static synchronized void init() throws KinectException { if (KinectController.CONTEXT == null) { final Pointer<Pointer<freenect_context>> ctxPointer = Pointer.pointerToPointer(null); libfreenectLibrary.freenect_init(ctxPointer, Pointer.NULL); if (ctxPointer == null) throw new KinectException("Unable to initialise libfreenect."); CONTEXT = ctxPointer.get(); if (CONTEXT == null) throw new KinectException("Unable to initialise libfreenect."); if (libfreenectLibrary.freenect_num_devices(CONTEXT) == 0) { libfreenectLibrary.freenect_shutdown(CONTEXT); throw new KinectException("Unable to initialise libfreenect; No devices found."); } EVENT_THREAD = new EventThread(); EVENT_THREAD.start(); // turn off the devices on shutdown Runtime.getRuntime().addShutdownHook(new Thread() { @Override public synchronized void run() { shutdownFreenect(); } }); } }