From 36eae29fca143b9bee0ab47954ff7baef9d62463 Mon Sep 17 00:00:00 2001 From: mcteo Date: Wed, 1 Aug 2012 15:44:07 +0100 Subject: [PATCH] Changed the names of the modified functions, and added wrapper functions (under original names) that maintain backwards compatibilty, and functionality Signed-off-by: Thomas Dunne --- examples/glpclview.c | 4 +-- examples/regtest.c | 8 +++--- wrappers/c_sync/libfreenect_sync.c | 44 +++++++++++++++++++++++------- wrappers/c_sync/libfreenect_sync.h | 18 ++++++++++-- 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/examples/glpclview.c b/examples/glpclview.c index dd535333..40b59c42 100644 --- a/examples/glpclview.c +++ b/examples/glpclview.c @@ -117,9 +117,9 @@ void DrawGLScene() short *depth = 0; char *rgb = 0; uint32_t ts; - if (freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT) < 0) + if (freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_11BIT) < 0) no_kinect_quit(); - if (freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB) < 0) + if (freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_VIDEO_RGB) < 0) no_kinect_quit(); static unsigned int indices[480][640]; diff --git a/examples/regtest.c b/examples/regtest.c index 08391ae5..ecae9be7 100644 --- a/examples/regtest.c +++ b/examples/regtest.c @@ -67,7 +67,7 @@ int main(void) FILE *fp; int ret; - ret = freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB); + ret = freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_VIDEO_RGB); if (ret < 0) no_kinect_quit(); @@ -75,7 +75,7 @@ int main(void) dump_rgb(fp, rgb, 640, 480); fclose(fp); - ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT); + ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_11BIT); if (ret < 0) no_kinect_quit(); @@ -83,7 +83,7 @@ int main(void) dump_depth(fp, depth, 640, 480); fclose(fp); - ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_REGISTERED); + ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_REGISTERED); if (ret < 0) no_kinect_quit(); @@ -91,7 +91,7 @@ int main(void) dump_depth(fp, depth, 640, 480); fclose(fp); - ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_MM); + ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_MM); if (ret < 0) no_kinect_quit(); diff --git a/wrappers/c_sync/libfreenect_sync.c b/wrappers/c_sync/libfreenect_sync.c index ca59370d..34ecfd94 100644 --- a/wrappers/c_sync/libfreenect_sync.c +++ b/wrappers/c_sync/libfreenect_sync.c @@ -221,7 +221,7 @@ static void init_thread(void) pthread_create(&thread, NULL, init, NULL); } -static int change_video_format(sync_kinect_t *kinect, freenect_resolution res, freenect_video_format fmt) +static int change_video_format_with_res(sync_kinect_t *kinect, freenect_resolution res, freenect_video_format fmt) { freenect_stop_video(kinect->dev); free_buffer_ring(&kinect->video); @@ -233,7 +233,12 @@ static int change_video_format(sync_kinect_t *kinect, freenect_resolution res, f return 0; } -static int change_depth_format(sync_kinect_t *kinect, freenect_resolution res, freenect_depth_format fmt) +static int change_video_format(sync_kinect_t *kinect, freenect_resolution res, freenect_video_format fmt) +{ + return change_video_format_with_res(kinect, FREENECT_RESOLUTION_MEDIUM, fmt); +} + +static int change_depth_format_with_res(sync_kinect_t *kinect, freenect_resolution res, freenect_depth_format fmt) { freenect_stop_depth(kinect->dev); free_buffer_ring(&kinect->depth); @@ -245,6 +250,11 @@ static int change_depth_format(sync_kinect_t *kinect, freenect_resolution res, f return 0; } +static int change_depth_format(sync_kinect_t *kinect, freenect_resolution res, freenect_depth_format fmt) +{ + return change_depth_format_with_res(kinect, FREENECT_RESOLUTION_MEDIUM, fmt); +} + static sync_kinect_t *alloc_kinect(int index) { sync_kinect_t *kinect = (sync_kinect_t*)malloc(sizeof(sync_kinect_t)); @@ -270,7 +280,7 @@ static sync_kinect_t *alloc_kinect(int index) return kinect; } -static int setup_kinect(int index, int res, int fmt, int is_depth) +static int setup_kinect_with_res(int index, int res, int fmt, int is_depth) { pending_runloop_tasks_inc(); pthread_mutex_lock(&runloop_lock); @@ -303,9 +313,9 @@ static int setup_kinect(int index, int res, int fmt, int is_depth) pthread_mutex_lock(&buf->lock); if ((buf->fmt != fmt) || (buf->res != res)) { if (is_depth) - change_depth_format(kinects[index], (freenect_resolution)res, (freenect_depth_format)fmt); + change_depth_format_with_res(kinects[index], (freenect_resolution)res, (freenect_depth_format)fmt); else - change_video_format(kinects[index], (freenect_resolution)res, (freenect_video_format)fmt); + change_video_format_with_res(kinects[index], (freenect_resolution)res, (freenect_video_format)fmt); } pthread_mutex_unlock(&buf->lock); pthread_mutex_unlock(&runloop_lock); @@ -313,6 +323,10 @@ static int setup_kinect(int index, int res, int fmt, int is_depth) return 0; } +static int setup_kinect(int index, int fmt, int is_depth) { + return setup_kinect_with_res(index, FREENECT_RESOLUTION_MEDIUM, fmt, is_depth); +} + static int sync_get(void **data, uint32_t *timestamp, buffer_ring_t *buf) { pthread_mutex_lock(&buf->lock); @@ -345,7 +359,7 @@ static int runloop_enter(int index) return -1; } if (!thread_running || !kinects[index]) - if (setup_kinect(index, FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT, 1)) + if (setup_kinect_with_res(index, FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT, 1)) return -1; pending_runloop_tasks_inc(); @@ -359,7 +373,7 @@ static void runloop_exit() pending_runloop_tasks_dec(); } -int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, +int freenect_sync_get_video_with_res(void **video, uint32_t *timestamp, int index, freenect_resolution res, freenect_video_format fmt) { if (index < 0 || index >= MAX_KINECTS) { @@ -368,13 +382,18 @@ int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, } if (!thread_running || !kinects[index] || kinects[index]->video.fmt != fmt || kinects[index]->video.res != res) - if (setup_kinect(index, res, fmt, 0)) + if (setup_kinect_with_res(index, res, fmt, 0)) return -1; sync_get(video, timestamp, &kinects[index]->video); return 0; } -int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, +int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt) +{ + return freenect_sync_get_video_with_res(video, timestamp, index, FREENECT_RESOLUTION_MEDIUM, fmt); +} + +int freenect_sync_get_depth_with_res(void **depth, uint32_t *timestamp, int index, freenect_resolution res, freenect_depth_format fmt) { if (index < 0 || index >= MAX_KINECTS) { @@ -383,12 +402,17 @@ int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, } if (!thread_running || !kinects[index] || kinects[index]->depth.fmt != fmt || kinects[index]->depth.res != res) - if (setup_kinect(index, res, fmt, 1)) + if (setup_kinect_with_res(index, res, fmt, 1)) return -1; sync_get(depth, timestamp, &kinects[index]->depth); return 0; } +int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt) +{ + return freenect_sync_get_depth_with_res(depth, timestamp, index, FREENECT_RESOLUTION_MEDIUM, fmt); +} + int freenect_sync_get_tilt_state(freenect_raw_tilt_state **state, int index) { if (runloop_enter(index)) return -1; diff --git a/wrappers/c_sync/libfreenect_sync.h b/wrappers/c_sync/libfreenect_sync.h index 64214265..ef2680e0 100644 --- a/wrappers/c_sync/libfreenect_sync.h +++ b/wrappers/c_sync/libfreenect_sync.h @@ -33,7 +33,7 @@ extern "C" { #endif -int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, +int freenect_sync_get_video_with_res(void **video, uint32_t *timestamp, int index, freenect_resolution res, freenect_video_format fmt); /* Synchronous video function, starts the runloop if it isn't running @@ -44,13 +44,20 @@ int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, video: Populated with a pointer to a video buffer with a size of the requested type timestamp: Populated with the associated timestamp index: Device index (0 is the first) + res: Valid resolution fmt: Valid format Returns: Nonzero on error. */ -int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, +int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt); +/* Does the exact same as above, but with a default resolution, + so backwards compatibilty is maintained. + The Resolution is kept at the default FREENECT_RESOLUTION_MEDIUM +*/ + +int freenect_sync_get_depth_with_res(void **depth, uint32_t *timestamp, int index, freenect_resolution res, freenect_depth_format fmt); /* Synchronous depth function, starts the runloop if it isn't running @@ -61,12 +68,19 @@ int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, depth: Populated with a pointer to a depth buffer with a size of the requested type timestamp: Populated with the associated timestamp index: Device index (0 is the first) + res: Valid resolution fmt: Valid format Returns: Nonzero on error. */ +int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt); +/* Again, a wrapper function to keep backward compatibility. + The Resolution is kept at the default FREENECT_RESOLUTION_MEDIUM + +*/ + int freenect_sync_set_tilt_degs(int angle, int index); /* Tilt function, starts the runloop if it isn't running