52 #define MAX_KINECTS 64 84 printf(
"Invalid video format %d\n", fmt);
87 for (i = 0; i < 3; ++i)
88 buf->
bufs[i] = malloc(sz);
109 printf(
"Invalid depth format %d\n", fmt);
112 for (i = 0; i < 3; ++i)
113 buf->
bufs[i] = malloc(sz);
124 for (i = 0; i < 3; ++i) {
136 pthread_mutex_lock(&buf->
lock);
137 assert(data == buf->
bufs[2]);
138 void *temp_buf = buf->
bufs[1];
140 buf->
bufs[2] = temp_buf;
141 set_buffer(dev, temp_buf);
144 pthread_cond_signal(&buf->
cb_cond);
145 pthread_mutex_unlock(&buf->
lock);
185 static void *
init(
void *unused)
257 for (i = 0; i < 3; ++i) {
267 pthread_mutex_init(&kinect->
video.
lock, NULL);
268 pthread_mutex_init(&kinect->
depth.
lock, NULL);
281 if (!kinects[index]) {
284 if (!kinects[index]) {
285 printf(
"Error: Invalid index [%d]\n", index);
287 if (!thread_running_prev) {
291 pthread_join(
thread, NULL);
301 buf = &kinects[index]->
depth;
303 buf = &kinects[index]->
video;
304 pthread_mutex_lock(&buf->
lock);
305 if ((buf->
fmt != fmt) || (buf->
res != res))
312 pthread_mutex_unlock(&buf->
lock);
320 pthread_mutex_lock(&buf->
lock);
324 void *temp_buf = buf->
bufs[0];
325 *data = buf->
bufs[0] = buf->
bufs[1];
326 buf->
bufs[1] = temp_buf;
329 pthread_mutex_unlock(&buf->
lock);
346 printf(
"Error: Invalid index [%d]\n", index);
368 printf(
"Error: Invalid index [%d]\n", index);
371 if (!
thread_running || !kinects[index] || kinects[index]->video.fmt != fmt || kinects[index]->
video.
res != res)
374 sync_get(video, timestamp, &kinects[index]->video);
387 printf(
"Error: Invalid index [%d]\n", index);
390 if (!
thread_running || !kinects[index] || kinects[index]->depth.fmt != fmt
391 || kinects[index]->
depth.
res != res)
394 sync_get(depth, timestamp, &kinects[index]->depth);
437 pthread_join(
thread, NULL);
void freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb)
int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt)
int(* set_buffer_t)(freenect_device *dev, void *buf)
void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs)
int freenect_stop_video(freenect_device *dev)
struct buffer_ring buffer_ring_t
static sync_kinect_t * kinects[MAX_KINECTS]
static int pending_runloop_tasks
static void runloop_exit()
struct sync_kinect sync_kinect_t
static void init_thread(void)
int freenect_start_depth(freenect_device *dev)
int freenect_set_led(freenect_device *dev, freenect_led_options option)
static int sync_get(void **data, uint32_t *timestamp, buffer_ring_t *buf)
int freenect_set_video_buffer(freenect_device *dev, void *buf)
static sync_kinect_t * alloc_kinect(int index)
static pthread_mutex_t pending_runloop_tasks_lock
int freenect_shutdown(freenect_context *ctx)
int freenect_sync_set_tilt_degs(int angle, int index)
static void pending_runloop_tasks_dec(void)
int freenect_set_video_mode(freenect_device *dev, const freenect_frame_mode mode)
int freenect_set_tilt_degs(freenect_device *dev, double angle)
int freenect_sync_get_tilt_state(freenect_raw_tilt_state **state, int index)
void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb)
static void producer_cb_inner(freenect_device *dev, void *data, uint32_t timestamp, buffer_ring_t *buf, set_buffer_t set_buffer)
int freenect_start_video(freenect_device *dev)
freenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt)
static void free_buffer_ring(buffer_ring_t *buf)
void * freenect_get_user(freenect_device *dev)
freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt)
static int thread_running
void freenect_sync_stop(void)
static void video_producer_cb(freenect_device *dev, void *data, uint32_t timestamp)
freenect_raw_tilt_state * freenect_get_tilt_state(freenect_device *dev)
int freenect_sync_get_video_with_res(void **video, uint32_t *timestamp, int index, freenect_resolution res, freenect_video_format fmt)
static int change_depth_format(sync_kinect_t *kinect, freenect_resolution res, freenect_depth_format fmt)
int freenect_update_tilt_state(freenect_device *dev)
static int alloc_buffer_ring_video(freenect_resolution res, freenect_video_format fmt, buffer_ring_t *buf)
static void * init(void *unused)
int freenect_close_device(freenect_device *dev)
int freenect_set_depth_mode(freenect_device *dev, const freenect_frame_mode mode)
int freenect_open_device(freenect_context *ctx, freenect_device **dev, int index)
static pthread_mutex_t runloop_lock
static void pending_runloop_tasks_inc(void)
static freenect_context * ctx
int freenect_sync_get_depth_with_res(void **depth, uint32_t *timestamp, int index, freenect_resolution res, freenect_depth_format fmt)
Data from the tilt motor and accelerometer.
static void depth_producer_cb(freenect_device *dev, void *data, uint32_t timestamp)
int freenect_sync_camera_to_world(int cx, int cy, int wz, double *wx, double *wy, int index)
static int runloop_enter(int index)
int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt)
static pthread_cond_t pending_runloop_tasks_cond
int freenect_sync_set_led(freenect_led_options led, int index)
int freenect_stop_depth(freenect_device *dev)
static int setup_kinect(int index, int res, int fmt, int is_depth)
int freenect_process_events(freenect_context *ctx)
FREENECTAPI void freenect_camera_to_world(freenect_device *dev, int cx, int cy, int wz, double *wx, double *wy)
camera -> world coordinate helper function
int freenect_set_depth_buffer(freenect_device *dev, void *buf)
static void pending_runloop_tasks_wait_zero(void)
void freenect_set_user(freenect_device *dev, void *user)
static int alloc_buffer_ring_depth(freenect_resolution res, freenect_depth_format fmt, buffer_ring_t *buf)
int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)
static int change_video_format(sync_kinect_t *kinect, freenect_resolution res, freenect_video_format fmt)