diff options
Diffstat (limited to 'thread_kinect.c')
-rw-r--r-- | thread_kinect.c | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/thread_kinect.c b/thread_kinect.c deleted file mode 100644 index bd70679..0000000 --- a/thread_kinect.c +++ /dev/null @@ -1,122 +0,0 @@ -#include <error.h> -#include <libfreenect/libfreenect.h> -#include <libusb-1.0/libusb.h> -#include <pthread.h> -#include <stdio.h> -#include <unistd.h> - -#include "main.h" - -FILE *depth_stream = NULL; -FILE *video_stream = NULL; -FILE *accel_stream = NULL; - -static -void dump_ffmpeg_24(FILE *stream, uint32_t timestamp UNUSED, void *data, - size_t data_size) -{ - fwrite(data, data_size, 1, stream); -} - -static -void dump_ffmpeg_pad16(FILE *stream, uint32_t timestamp UNUSED, void *data_anon, - size_t data_size) -{ - uint16_t* data = data_anon; - uint16_t* end = (void*)&((char*)data_anon)[data_size]; - while (data < end) { - uint32_t z = *data; - fwrite(((char*)(&z)), 3, 1, stream); - data = &data[1]; - } -} - -static -void handle_accel(freenect_device *dev UNUSED, freenect_raw_tilt_state* data) -{ - double x, y, z; - freenect_get_mks_accel(data, &x, &y, &z); - //fprintf(accel_stream, "x=%f\ty=%f\tz=%f\n", x, y, z); -} - -static -void handle_depth(freenect_device *dev UNUSED, void *depth, uint32_t timestamp) -{ - printf("handle depth\n"); - dump_ffmpeg_pad16(depth_stream, timestamp, depth, - freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, - FREENECT_DEPTH_11BIT).bytes); -} - -static -void handle_video(freenect_device *dev, void *rgb, uint32_t timestamp) -{ - printf("handle depth\n"); - dump_ffmpeg_24(video_stream, timestamp, rgb, - freenect_get_current_video_mode(dev).bytes); -} - -static -void print_mode(const char *name, freenect_frame_mode mode) { - /* This is just a courtesy function to let the user know the mode - if it becomes a bother for maintainability just comment out the - code in its body. It will only break if struct entries go missing. - */ - printf("%s Mode: {%d, %d, {%d}, %d, %d, %d, %d, %d, %d, %d}\n", name, - mode.reserved, (int)mode.resolution, (int)mode.video_format, mode.bytes, mode.width, - mode.height, mode.data_bits_per_pixel, mode.padding_bits_per_pixel, - mode.framerate, mode.is_valid); -} - -void thread_kinect(int video_fd, int depth_fd, int accel_fd) { - int res = 0; - - freenect_context *ctx; - freenect_device *dev; - - pthread_setname_np(pthread_self(), "libusb"); - res = freenect_init(&ctx, 0); - pthread_setname_np(pthread_self(), "kinect"); - if (res) { - error(0, 0, "freenect_init: %s", libusb_strerror(res)); - goto end; - } - - freenect_select_subdevices(ctx, (freenect_device_flags)(FREENECT_DEVICE_CAMERA | FREENECT_DEVICE_MOTOR)); - if ((res = freenect_open_device(ctx, &dev, 0))) { - error(0, 0, "freenect_open_device: %s", libusb_strerror(res)); - goto end; - } - - print_mode("Depth", freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT)); - freenect_set_depth_mode(dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT)); - freenect_start_depth(dev); - - print_mode("Video", freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB)); - freenect_set_video_mode(dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB)); - freenect_start_video(dev); - - depth_stream = fdopen(depth_fd, "w"); - video_stream = fdopen(video_fd, "w"); - accel_stream = fdopen(accel_fd, "w"); - - freenect_set_depth_callback(dev, handle_depth); - freenect_set_video_callback(dev, handle_video); - - while (running && freenect_process_events(ctx) >= 0) { - freenect_raw_tilt_state* state; - freenect_update_tilt_state(dev); - state = freenect_get_tilt_state(dev); - handle_accel(dev, state); - } - - freenect_stop_depth(dev); - freenect_stop_video(dev); - freenect_close_device(dev); - - end: - freenect_shutdown(ctx); - close(video_fd); - close(depth_fd); - close(accel_fd); -} |