Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Prepared codebase for adding libusbemu:

Updated various libfreenect and examples to compile in Visual Studio
Added an updated FindThreads.cmake that looks for pthread-win32
Updated CMake

Signed-off-by: Joshua Blake <joshblake@gmail.com>
  • Loading branch information...
commit 38e3a09180135d448f1fc4313611eabe93d3c32a 1 parent f29b6e3
@JoshBlake JoshBlake authored
View
5 CMakeLists.txt
@@ -98,6 +98,11 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
# libfreenect.h includes libusb.h, so everyone needs this too
include_directories(${LIBUSB_1_INCLUDE_DIRS})
+if(WIN32)
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/platform/windows")
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/platform/windows/libusb10emu")
+endif()
+
# Add library project
add_subdirectory (src)
View
246 cmake_modules/FindThreads.cmake
@@ -0,0 +1,246 @@
+# Updated FindThreads.cmake that supports pthread-win32
+# Downloaded from http://www.vtk.org/Bug/bug_view_advanced_page.php?bug_id=6399
+
+# - This module determines the thread library of the system.
+#
+# The following variables are set
+# CMAKE_THREAD_LIBS_INIT - the thread library
+# CMAKE_USE_SPROC_INIT - are we using sproc?
+# CMAKE_USE_WIN32_THREADS_INIT - using WIN32 threads?
+# CMAKE_USE_PTHREADS_INIT - are we using pthreads
+# CMAKE_HP_PTHREADS_INIT - are we using hp pthreads
+#
+# If use of pthreads-win32 is desired, the following variables
+# can be set.
+#
+# THREADS_USE_PTHREADS_WIN32 -
+# Setting this to true searches for the pthreads-win32
+# port (since CMake 2.8.0)
+#
+# THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME
+# C = no exceptions (default)
+# (NOTE: This is the default scheme on most POSIX thread
+# implementations and what you should probably be using)
+# CE = C++ Exception Handling
+# SE = Structure Exception Handling (MSVC only)
+# (NOTE: Changing this option from the default may affect
+# the portability of your application. See pthreads-win32
+# documentation for more details.)
+#
+#======================================================
+# Example usage where threading library
+# is provided by the system:
+#
+# find_package(Threads REQUIRED)
+# add_executable(foo foo.cc)
+# target_link_libraries(foo ${CMAKE_THREAD_LIBS_INIT})
+#
+# Example usage if pthreads-win32 is desired on Windows
+# or a system provided thread library:
+#
+# set(THREADS_USE_PTHREADS_WIN32 true)
+# find_package(Threads REQUIRED)
+# include_directories(${THREADS_PTHREADS_INCLUDE_DIR})
+#
+# add_executable(foo foo.cc)
+# target_link_libraries(foo ${CMAKE_THREAD_LIBS_INIT})
+#
+
+INCLUDE (CheckIncludeFiles)
+INCLUDE (CheckLibraryExists)
+SET(Threads_FOUND FALSE)
+
+IF(WIN32 AND NOT CYGWIN AND THREADS_USE_PTHREADS_WIN32)
+ SET(_Threads_ptwin32 true)
+ENDIF()
+
+# Do we have sproc?
+IF(CMAKE_SYSTEM MATCHES IRIX)
+ CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H)
+ENDIF()
+
+IF(CMAKE_HAVE_SPROC_H)
+ # We have sproc
+ SET(CMAKE_USE_SPROC_INIT 1)
+
+ELSEIF(_Threads_ptwin32)
+
+ IF(NOT DEFINED THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME)
+ # Assign the default scheme
+ SET(THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME "C")
+ ELSE()
+ # Validate the scheme specified by the user
+ IF(NOT THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "C" AND
+ NOT THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "CE" AND
+ NOT THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "SE")
+ MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")
+ ENDIF()
+ IF(NOT MSVC AND THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "SE")
+ MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")
+ ENDIF(NOT MSVC AND THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "SE")
+ ENDIF()
+
+ FIND_PATH(THREADS_PTHREADS_INCLUDE_DIR pthread.h)
+
+ # Determine the library filename
+ IF(MSVC)
+ SET(_Threads_pthreads_libname
+ pthreadV${THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME}2)
+ ELSEIF(MINGW)
+ SET(_Threads_pthreads_libname
+ pthreadG${THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME}2)
+ ELSE()
+ MESSAGE(FATAL_ERROR "This should never happen")
+ ENDIF()
+
+ # Use the include path to help find the library if possible
+ SET(_Threads_lib_paths "")
+ IF(THREADS_PTHREADS_INCLUDE_DIR)
+ GET_FILENAME_COMPONENT(_Threads_root_dir
+ ${THREADS_PTHREADS_INCLUDE_DIR} PATH)
+ SET(_Threads_lib_paths ${_Threads_root_dir}/lib)
+ ENDIF()
+ FIND_LIBRARY(THREADS_PTHREADS_WIN32_LIBRARY
+ NAMES ${_Threads_pthreads_libname}
+ PATHS ${_Threads_lib_paths}
+ DOC "The Portable Threads Library for Win32"
+ NO_SYSTEM_PATH
+ )
+
+ IF(THREADS_PTHREADS_INCLUDE_DIR AND THREADS_PTHREADS_WIN32_LIBRARY)
+ MARK_AS_ADVANCED(THREADS_PTHREADS_INCLUDE_DIR)
+ SET(CMAKE_THREAD_LIBS_INIT ${THREADS_PTHREADS_WIN32_LIBRARY})
+ SET(CMAKE_HAVE_THREADS_LIBRARY 1)
+ SET(Threads_FOUND TRUE)
+ ENDIF()
+
+ MARK_AS_ADVANCED(THREADS_PTHREADS_WIN32_LIBRARY)
+
+ELSE()
+ # Do we have pthreads?
+ CHECK_INCLUDE_FILES("pthread.h" CMAKE_HAVE_PTHREAD_H)
+ IF(CMAKE_HAVE_PTHREAD_H)
+
+ #
+ # We have pthread.h
+ # Let's check for the library now.
+ #
+ SET(CMAKE_HAVE_THREADS_LIBRARY)
+ IF(NOT THREADS_HAVE_PTHREAD_ARG)
+
+ # Do we have -lpthreads
+ CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE)
+ IF(CMAKE_HAVE_PTHREADS_CREATE)
+ SET(CMAKE_THREAD_LIBS_INIT "-lpthreads")
+ SET(CMAKE_HAVE_THREADS_LIBRARY 1)
+ SET(Threads_FOUND TRUE)
+ ENDIF()
+
+ # Ok, how about -lpthread
+ CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE)
+ IF(CMAKE_HAVE_PTHREAD_CREATE)
+ SET(CMAKE_THREAD_LIBS_INIT "-lpthread")
+ SET(Threads_FOUND TRUE)
+ SET(CMAKE_HAVE_THREADS_LIBRARY 1)
+ ENDIF()
+
+ IF(CMAKE_SYSTEM MATCHES "SunOS.*")
+ # On sun also check for -lthread
+ CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE)
+ IF(CMAKE_HAVE_THR_CREATE)
+ SET(CMAKE_THREAD_LIBS_INIT "-lthread")
+ SET(CMAKE_HAVE_THREADS_LIBRARY 1)
+ SET(Threads_FOUND TRUE)
+ ENDIF()
+ ENDIF(CMAKE_SYSTEM MATCHES "SunOS.*")
+
+ ENDIF(NOT THREADS_HAVE_PTHREAD_ARG)
+
+ IF(NOT CMAKE_HAVE_THREADS_LIBRARY)
+ # If we did not found -lpthread, -lpthread, or -lthread, look for -pthread
+ IF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
+ MESSAGE(STATUS "Check if compiler accepts -pthread")
+ TRY_RUN(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_ROOT}/Modules/CheckForPthreads.c
+ CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread
+ COMPILE_OUTPUT_VARIABLE OUTPUT)
+
+ IF(THREADS_HAVE_PTHREAD_ARG)
+ IF(THREADS_PTHREAD_ARG MATCHES "^2$")
+ SET(Threads_FOUND TRUE)
+ MESSAGE(STATUS "Check if compiler accepts -pthread - yes")
+ ELSE()
+ MESSAGE(STATUS "Check if compiler accepts -pthread - no")
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n")
+ ENDIF()
+ ELSE()
+ MESSAGE(STATUS "Check if compiler accepts -pthread - no")
+ FILE(APPEND
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n")
+ ENDIF()
+
+ ENDIF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
+
+ IF(THREADS_HAVE_PTHREAD_ARG)
+ SET(Threads_FOUND TRUE)
+ SET(CMAKE_THREAD_LIBS_INIT "-pthread")
+ ENDIF()
+
+ ENDIF(NOT CMAKE_HAVE_THREADS_LIBRARY)
+ ENDIF(CMAKE_HAVE_PTHREAD_H)
+ENDIF()
+
+IF(CMAKE_THREAD_LIBS_INIT)
+ SET(CMAKE_USE_PTHREADS_INIT 1)
+ SET(Threads_FOUND TRUE)
+ENDIF()
+
+IF(CMAKE_SYSTEM MATCHES "Windows"
+ AND NOT THREADS_USE_PTHREADS_WIN32)
+ SET(CMAKE_USE_WIN32_THREADS_INIT 1)
+ SET(Threads_FOUND TRUE)
+ENDIF()
+
+IF(CMAKE_USE_PTHREADS_INIT)
+ IF(CMAKE_SYSTEM MATCHES "HP-UX-*")
+ # Use libcma if it exists and can be used. It provides more
+ # symbols than the plain pthread library. CMA threads
+ # have actually been deprecated:
+ # http://docs.hp.com/en/B3920-90091/ch12s03.html#d0e11395
+ # http://docs.hp.com/en/947/d8.html
+ # but we need to maintain compatibility here.
+ # The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads
+ # are available.
+ CHECK_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA)
+ IF(CMAKE_HAVE_HP_CMA)
+ SET(CMAKE_THREAD_LIBS_INIT "-lcma")
+ SET(CMAKE_HP_PTHREADS_INIT 1)
+ SET(Threads_FOUND TRUE)
+ ENDIF(CMAKE_HAVE_HP_CMA)
+ SET(CMAKE_USE_PTHREADS_INIT 1)
+ ENDIF()
+
+ IF(CMAKE_SYSTEM MATCHES "OSF1-V*")
+ SET(CMAKE_USE_PTHREADS_INIT 0)
+ SET(CMAKE_THREAD_LIBS_INIT )
+ ENDIF()
+
+ IF(CMAKE_SYSTEM MATCHES "CYGWIN_NT*")
+ SET(CMAKE_USE_PTHREADS_INIT 1)
+ SET(Threads_FOUND TRUE)
+ SET(CMAKE_THREAD_LIBS_INIT )
+ SET(CMAKE_USE_WIN32_THREADS_INIT 0)
+ ENDIF()
+ENDIF(CMAKE_USE_PTHREADS_INIT)
+
+INCLUDE(FindPackageHandleStandardArgs)
+IF(_Threads_ptwin32)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG
+ THREADS_PTHREADS_WIN32_LIBRARY THREADS_PTHREADS_INCLUDE_DIR)
+ELSE()
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG Threads_FOUND)
+ENDIF()
View
39 examples/CMakeLists.txt
@@ -7,11 +7,19 @@ set(CMAKE_C_FLAGS "-Wall")
if (WIN32)
set_source_files_properties(glview.c PROPERTIES LANGUAGE CXX)
set_source_files_properties(glpclview.c PROPERTIES LANGUAGE CXX)
+
+ set(THREADS_USE_PTHREADS_WIN32 true)
+ find_package(Threads REQUIRED)
+
+ include_directories(${THREADS_PTHREADS_INCLUDE_DIR})
endif()
add_executable(glview glview.c)
add_executable(cppview cppview.cpp)
-add_executable(glpclview glpclview.c)
+
+if (BUILD_C_SYNC)
+ add_executable(glpclview glpclview.c)
+endif()
# We need to include libfreenect_sync.h for glpclview
include_directories (../wrappers/c_sync/)
@@ -21,20 +29,39 @@ if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-framework OpenGL -framework GLUT")
target_link_libraries(glview freenect)
target_link_libraries(cppview freenect)
- target_link_libraries(glpclview freenect_sync)
+ if (BUILD_C_SYNC)
+ target_link_libraries(glpclview freenect_sync)
+ endif()
# Linux, not so much
else()
+
find_package(Threads REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
+
include_directories(${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${USB_INCLUDE_DIRS})
- target_link_libraries(glview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} m)
- target_link_libraries(cppview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} m)
- target_link_libraries(glpclview freenect_sync ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} m)
+
+ if (WIN32)
+ set(MATH_LIB "")
+ else(WIN32)
+ set(MATH_LIB "m")
+ endif()
+
+ target_link_libraries(glview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
+ target_link_libraries(cppview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
+ if (BUILD_C_SYNC)
+ target_link_libraries(glpclview freenect_sync ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
+ endif()
endif()
-install (TARGETS glview glpclview
+
+install (TARGETS glview
DESTINATION bin)
install (TARGETS cppview
DESTINATION bin)
+
+if (BUILD_C_SYNC)
+ install (TARGETS glpclview
+ DESTINATION bin)
+endif()
View
1  examples/glpclview.c
@@ -29,6 +29,7 @@
#include "libfreenect.h"
#include "libfreenect_sync.h"
#include <stdio.h>
+#include <stdlib.h>
#if defined(__APPLE__)
#include <GLUT/glut.h>
View
16 examples/glview.c
@@ -97,7 +97,7 @@ void DrawGLScene()
return;
}
- void *tmp;
+ uint8_t *tmp;
if (got_depth) {
tmp = depth_front;
@@ -265,7 +265,7 @@ uint16_t t_gamma[2048];
void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
{
int i;
- uint16_t *depth = v_depth;
+ uint16_t *depth = (uint16_t*)v_depth;
pthread_mutex_lock(&gl_backbuf_mutex);
for (i=0; i<FREENECT_FRAME_PIX; i++) {
@@ -322,7 +322,7 @@ void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp)
assert (rgb_back == rgb);
rgb_back = rgb_mid;
freenect_set_video_buffer(dev, rgb_back);
- rgb_mid = rgb;
+ rgb_mid = (uint8_t*)rgb;
got_rgb++;
pthread_cond_signal(&gl_frame_cond);
@@ -377,11 +377,11 @@ int main(int argc, char **argv)
{
int res;
- depth_mid = malloc(640*480*3);
- depth_front = malloc(640*480*3);
- rgb_back = malloc(640*480*3);
- rgb_mid = malloc(640*480*3);
- rgb_front = malloc(640*480*3);
+ depth_mid = (uint8_t*)malloc(640*480*3);
+ depth_front = (uint8_t*)malloc(640*480*3);
+ rgb_back = (uint8_t*)malloc(640*480*3);
+ rgb_mid = (uint8_t*)malloc(640*480*3);
+ rgb_front = (uint8_t*)malloc(640*480*3);
printf("Kinect camera test\n");
View
4 src/CMakeLists.txt
@@ -7,9 +7,11 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_C_FLAGS "-Wall")
include_directories(${LIBUSB_1_INCLUDE_DIRS})
-LIST(APPEND SRC core.c tilt.c cameras.c usb_libusb10.c)
IF(WIN32)
+ LIST(APPEND SRC core.c tilt.c cameras.c usb_libusb10.c ../platform/windows/libusb10emu/libusb-1.0/libusbemu.cpp)
set_source_files_properties(${SRC} PROPERTIES LANGUAGE CXX)
+ELSE(WIN32)
+ LIST(APPEND SRC core.c tilt.c cameras.c usb_libusb10.c)
ENDIF(WIN32)
add_library (freenect SHARED ${SRC})
View
24 src/cameras.c
@@ -47,7 +47,7 @@ static int stream_process(freenect_context *ctx, packet_stream *strm, uint8_t *p
if (len < 12)
return 0;
- struct pkt_hdr *hdr = (void*)pkt;
+ struct pkt_hdr *hdr = (pkt_hdr*)(void*)pkt;
uint8_t *data = pkt + sizeof(*hdr);
int datalen = len - sizeof(*hdr);
@@ -191,11 +191,11 @@ static void stream_init(freenect_context *ctx, packet_stream *strm, int rlen, in
if (rlen == 0) {
strm->split_bufs = 0;
- strm->raw_buf = strm->proc_buf;
+ strm->raw_buf = (uint8_t*)strm->proc_buf;
strm->frame_size = plen;
} else {
strm->split_bufs = 1;
- strm->raw_buf = malloc(rlen);
+ strm->raw_buf = (uint8_t*)malloc(rlen);
strm->frame_size = rlen;
}
@@ -235,7 +235,7 @@ static int stream_setbuf(freenect_context *ctx, packet_stream *strm, void *pbuf)
strm->proc_buf = pbuf;
if (!strm->split_bufs)
- strm->raw_buf = strm->proc_buf;
+ strm->raw_buf = (uint8_t*)strm->proc_buf;
return 0;
}
}
@@ -291,10 +291,10 @@ static void depth_process(freenect_device *dev, uint8_t *pkt, int len)
switch (dev->depth_format) {
case FREENECT_DEPTH_11BIT:
- convert_packed_to_16bit(dev->depth.raw_buf, dev->depth.proc_buf, 11, FREENECT_FRAME_PIX);
+ convert_packed_to_16bit(dev->depth.raw_buf, (uint16_t*)dev->depth.proc_buf, 11, FREENECT_FRAME_PIX);
break;
case FREENECT_DEPTH_10BIT:
- convert_packed_to_16bit(dev->depth.raw_buf, dev->depth.proc_buf, 10, FREENECT_FRAME_PIX);
+ convert_packed_to_16bit(dev->depth.raw_buf, (uint16_t*)dev->depth.proc_buf, 10, FREENECT_FRAME_PIX);
break;
case FREENECT_DEPTH_10BIT_PACKED:
case FREENECT_DEPTH_11BIT_PACKED:
@@ -522,20 +522,20 @@ static void video_process(freenect_device *dev, uint8_t *pkt, int len)
switch (dev->video_format) {
case FREENECT_VIDEO_RGB:
- convert_bayer_to_rgb(dev->video.raw_buf, dev->video.proc_buf);
+ convert_bayer_to_rgb(dev->video.raw_buf, (uint8_t*)dev->video.proc_buf);
break;
case FREENECT_VIDEO_BAYER:
break;
case FREENECT_VIDEO_IR_10BIT:
- convert_packed_to_16bit(dev->video.raw_buf, dev->video.proc_buf, 10, FREENECT_IR_FRAME_PIX);
+ convert_packed_to_16bit(dev->video.raw_buf, (uint16_t*)dev->video.proc_buf, 10, FREENECT_IR_FRAME_PIX);
break;
case FREENECT_VIDEO_IR_10BIT_PACKED:
break;
case FREENECT_VIDEO_IR_8BIT:
- convert_packed_to_8bit(dev->video.raw_buf, dev->video.proc_buf, 10, FREENECT_IR_FRAME_PIX);
+ convert_packed_to_8bit(dev->video.raw_buf, (uint8_t*)dev->video.proc_buf, 10, FREENECT_IR_FRAME_PIX);
break;
case FREENECT_VIDEO_YUV_RGB:
- convert_uyvy_to_rgb(dev->video.raw_buf, dev->video.proc_buf);
+ convert_uyvy_to_rgb(dev->video.raw_buf, (uint8_t*)dev->video.proc_buf);
break;
case FREENECT_VIDEO_YUV_RAW:
break;
@@ -558,8 +558,8 @@ static int send_cmd(freenect_device *dev, uint16_t cmd, void *cmdbuf, unsigned i
int res, actual_len;
uint8_t obuf[0x400];
uint8_t ibuf[0x200];
- cam_hdr *chdr = (void*)obuf;
- cam_hdr *rhdr = (void*)ibuf;
+ cam_hdr *chdr = (cam_hdr*)(void*)obuf;
+ cam_hdr *rhdr = (cam_hdr*)(void*)ibuf;
if (cmd_len & 1 || cmd_len > (0x400 - sizeof(*chdr))) {
FN_ERROR("send_cmd: Invalid command length (0x%x)\n", cmd_len);
View
26 src/core.c
@@ -28,13 +28,14 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+
#include <unistd.h>
#include "freenect_internal.h"
int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)
{
- *ctx = malloc(sizeof(freenect_context));
+ *ctx = (freenect_context*)malloc(sizeof(freenect_context));
if (!ctx)
return -1;
@@ -63,32 +64,13 @@ int freenect_process_events(freenect_context *ctx)
int freenect_num_devices(freenect_context *ctx)
{
- libusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices
- ssize_t cnt = libusb_get_device_list (ctx->usb.ctx, &devs); //get the list of devices
-
- if (cnt < 0)
- return (-1);
-
- int nr = 0, i = 0;
- struct libusb_device_descriptor desc;
- for (i = 0; i < cnt; ++i)
- {
- int r = libusb_get_device_descriptor (devs[i], &desc);
- if (r < 0)
- continue;
- if (desc.idVendor == VID_MICROSOFT && desc.idProduct == PID_NUI_CAMERA)
- nr++;
- }
-
- libusb_free_device_list (devs, 1); // free the list, unref the devices in it
-
- return (nr);
+ return fnusb_num_devices(&ctx->usb);
}
int freenect_open_device(freenect_context *ctx, freenect_device **dev, int index)
{
int res;
- freenect_device *pdev = malloc(sizeof(freenect_device));
+ freenect_device *pdev = (freenect_device*)malloc(sizeof(freenect_device));
if (!pdev)
return -1;
View
7 src/freenect_internal.h
@@ -51,7 +51,14 @@ struct _freenect_context {
#define LL_SPEW FREENECT_LOG_SPEW
#define LL_FLOOD FREENECT_LOG_FLOOD
+
+#ifdef _WIN32
+#include <stdarg.h>
+#include <stdio.h>
+void fn_log(freenect_context *ctx, freenect_loglevel level, const char *fmt, ...);
+#else
void fn_log(freenect_context *ctx, freenect_loglevel level, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
+#endif
#define FN_LOG(level, ...) fn_log(ctx, level, __VA_ARGS__)
View
2  src/tilt.c
@@ -63,7 +63,7 @@ int freenect_update_tilt_state(freenect_device *dev)
dev->raw_state.accelerometer_y = (int16_t)uy;
dev->raw_state.accelerometer_z = (int16_t)uz;
dev->raw_state.tilt_angle = (int8_t)buf[8];
- dev->raw_state.tilt_status = buf[9];
+ dev->raw_state.tilt_status = (freenect_tilt_status_code)buf[9];
return ret;
}
View
31 src/usb_libusb10.c
@@ -31,6 +31,29 @@
#include <libusb-1.0/libusb.h>
#include "freenect_internal.h"
+int fnusb_num_devices(fnusb_ctx *ctx)
+{
+ libusb_device **devs;
+ //pointer to pointer of device, used to retrieve a list of devices
+ ssize_t cnt = libusb_get_device_list (ctx->ctx, &devs);
+ //get the list of devices
+ if (cnt < 0)
+ return (-1);
+ int nr = 0, i = 0;
+ struct libusb_device_descriptor desc;
+ for (i = 0; i < cnt; ++i)
+ {
+ int r = libusb_get_device_descriptor (devs[i], &desc);
+ if (r < 0)
+ continue;
+ if (desc.idVendor == VID_MICROSOFT && desc.idProduct == PID_NUI_CAMERA)
+ nr++;
+ }
+ libusb_free_device_list (devs, 1);
+ // free the list, unref the devices in it
+ return nr;
+}
+
int fnusb_init(fnusb_ctx *ctx, freenect_usb_context *usb_ctx)
{
int res;
@@ -172,7 +195,7 @@ int fnusb_close_subdevices(freenect_device *dev)
static void iso_callback(struct libusb_transfer *xfer)
{
int i;
- fnusb_isoc_stream *strm = xfer->user_data;
+ fnusb_isoc_stream *strm = (fnusb_isoc_stream*)xfer->user_data;
if (strm->dead) {
freenect_context *ctx = strm->parent->parent->parent;
@@ -182,7 +205,7 @@ static void iso_callback(struct libusb_transfer *xfer)
}
if(xfer->status == LIBUSB_TRANSFER_COMPLETED) {
- uint8_t *buf = (void*)xfer->buffer;
+ uint8_t *buf = (uint8_t*)(void*)xfer->buffer;
for (i=0; i<strm->pkts; i++) {
strm->cb(strm->parent->parent, buf, xfer->iso_packet_desc[i].actual_length);
buf += strm->len;
@@ -205,8 +228,8 @@ int fnusb_start_iso(fnusb_dev *dev, fnusb_isoc_stream *strm, fnusb_iso_cb cb, in
strm->num_xfers = xfers;
strm->pkts = pkts;
strm->len = len;
- strm->buffer = malloc(xfers * pkts * len);
- strm->xfers = malloc(sizeof(struct libusb_transfer*) * xfers);
+ strm->buffer = (uint8_t*)malloc(xfers * pkts * len);
+ strm->xfers = (libusb_transfer**)malloc(sizeof(struct libusb_transfer*) * xfers);
strm->dead = 0;
strm->dead_xfers = 0;
View
2  src/usb_libusb10.h
@@ -77,6 +77,8 @@ typedef struct {
int dead_xfers;
} fnusb_isoc_stream;
+int fnusb_num_devices(fnusb_ctx *ctx);
+
int fnusb_init(fnusb_ctx *ctx, freenect_usb_context *usb_ctx);
int fnusb_shutdown(fnusb_ctx *ctx);
int fnusb_process_events(fnusb_ctx *ctx);
Please sign in to comment.
Something went wrong with that request. Please try again.