From a1233ca81281db4734a7ab51dbc684c5b7af3f1a Mon Sep 17 00:00:00 2001 From: mcteo Date: Mon, 30 Jul 2012 00:35:54 +0100 Subject: [PATCH 1/3] Tweaked C_Sync wrapper to allow for resolution to be set Signed-off-by: Thomas Dunne --- wrappers/c_sync/libfreenect_sync.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/wrappers/c_sync/libfreenect_sync.c b/wrappers/c_sync/libfreenect_sync.c index 6fe55bd7..b48304b1 100644 --- a/wrappers/c_sync/libfreenect_sync.c +++ b/wrappers/c_sync/libfreenect_sync.c @@ -56,6 +56,8 @@ static pthread_mutex_t runloop_lock = PTHREAD_MUTEX_INITIALIZER; static int pending_runloop_tasks = 0; static pthread_mutex_t pending_runloop_tasks_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t pending_runloop_tasks_cond = PTHREAD_COND_INITIALIZER; +static freenect_resolution m_video_resolution = FREENECT_RESOLUTION_MEDIUM; +static freenect_resolution m_depth_resolution = FREENECT_RESOLUTION_MEDIUM; /* Locking Convention Rules: @@ -76,7 +78,7 @@ static int alloc_buffer_ring_video(freenect_video_format fmt, buffer_ring_t *buf case FREENECT_VIDEO_IR_8BIT: case FREENECT_VIDEO_IR_10BIT: case FREENECT_VIDEO_IR_10BIT_PACKED: - sz = freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, fmt).bytes; + sz = freenect_find_video_mode(m_video_resolution, fmt).bytes; break; default: printf("Invalid video format %d\n", fmt); @@ -100,7 +102,7 @@ static int alloc_buffer_ring_depth(freenect_depth_format fmt, buffer_ring_t *buf case FREENECT_DEPTH_10BIT_PACKED: case FREENECT_DEPTH_REGISTERED: case FREENECT_DEPTH_MM: - sz = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, fmt).bytes; + sz = freenect_find_depth_mode(m_depth_resolution, fmt).bytes; break; default: printf("Invalid depth format %d\n", fmt); @@ -217,27 +219,29 @@ static void init_thread(void) pthread_create(&thread, NULL, init, NULL); } -static int change_video_format(sync_kinect_t *kinect, freenect_video_format fmt) +static int change_video_format(sync_kinect_t *kinect, freenect_video_format fmt, freenect_resolution requested_resolution) { freenect_stop_video(kinect->dev); free_buffer_ring(&kinect->video); if (alloc_buffer_ring_video(fmt, &kinect->video)) return -1; - freenect_set_video_mode(kinect->dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, fmt)); + freenect_set_video_mode(kinect->dev, freenect_find_video_mode(requested_resolution, fmt)); freenect_set_video_buffer(kinect->dev, kinect->video.bufs[2]); freenect_start_video(kinect->dev); + m_video_resolution = requested_resolution; return 0; } -static int change_depth_format(sync_kinect_t *kinect, freenect_depth_format fmt) +static int change_depth_format(sync_kinect_t *kinect, freenect_depth_format fmt, freenect_resolution requested_resolution) { freenect_stop_depth(kinect->dev); free_buffer_ring(&kinect->depth); if (alloc_buffer_ring_depth(fmt, &kinect->depth)) return -1; - freenect_set_depth_mode(kinect->dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, fmt)); + freenect_set_depth_mode(kinect->dev, freenect_find_depth_mode(requested_resolution, fmt)); freenect_set_depth_buffer(kinect->dev, kinect->depth.bufs[2]); freenect_start_depth(kinect->dev); + m_depth_resolution = requested_resolution; return 0; } @@ -297,9 +301,9 @@ static int setup_kinect(int index, int fmt, int is_depth) pthread_mutex_lock(&buf->lock); if (buf->fmt != fmt) { if (is_depth) - change_depth_format(kinects[index], (freenect_depth_format)fmt); + change_depth_format(kinects[index], (freenect_depth_format)fmt, m_video_resolution); else - change_video_format(kinects[index], (freenect_video_format)fmt); + change_video_format(kinects[index], (freenect_video_format)fmt, m_video_resolution); } pthread_mutex_unlock(&buf->lock); pthread_mutex_unlock(&runloop_lock); From ae32bfb7291dd2442914c55b33ee9831373e5a0d Mon Sep 17 00:00:00 2001 From: mcteo Date: Wed, 1 Aug 2012 10:28:44 +0100 Subject: [PATCH 2/3] A slightly more aggressive form of allowing resolution to be set through c_sync wrapper Signed-off-by: Thomas Dunne --- examples/glpclview.c | 4 +-- examples/regtest.c | 8 ++--- wrappers/c_sync/libfreenect_sync.c | 58 ++++++++++++++++-------------- wrappers/c_sync/libfreenect_sync.h | 7 ++-- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/examples/glpclview.c b/examples/glpclview.c index 40b59c42..dd535333 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_DEPTH_11BIT) < 0) + if (freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT) < 0) no_kinect_quit(); - if (freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_VIDEO_RGB) < 0) + if (freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB) < 0) no_kinect_quit(); static unsigned int indices[480][640]; diff --git a/examples/regtest.c b/examples/regtest.c index ecae9be7..08391ae5 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_VIDEO_RGB); + ret = freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_RESOLUTION_MEDIUM, 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_DEPTH_11BIT); + ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_RESOLUTION_MEDIUM, 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_DEPTH_REGISTERED); + ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_RESOLUTION_MEDIUM, 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_DEPTH_MM); + ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_RESOLUTION_MEDIUM, 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 b48304b1..ca59370d 100644 --- a/wrappers/c_sync/libfreenect_sync.c +++ b/wrappers/c_sync/libfreenect_sync.c @@ -37,6 +37,7 @@ typedef struct buffer_ring { uint32_t timestamp; int valid; // True if middle buffer is valid int fmt; + int res; } buffer_ring_t; typedef struct sync_kinect { @@ -56,8 +57,6 @@ static pthread_mutex_t runloop_lock = PTHREAD_MUTEX_INITIALIZER; static int pending_runloop_tasks = 0; static pthread_mutex_t pending_runloop_tasks_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t pending_runloop_tasks_cond = PTHREAD_COND_INITIALIZER; -static freenect_resolution m_video_resolution = FREENECT_RESOLUTION_MEDIUM; -static freenect_resolution m_depth_resolution = FREENECT_RESOLUTION_MEDIUM; /* Locking Convention Rules: @@ -69,7 +68,7 @@ static freenect_resolution m_depth_resolution = FREENECT_RESOLUTION_MEDIUM; - runloop_lock, buffer_ring_t.lock (NOTE: You may only have one) */ -static int alloc_buffer_ring_video(freenect_video_format fmt, buffer_ring_t *buf) +static int alloc_buffer_ring_video(freenect_resolution res, freenect_video_format fmt, buffer_ring_t *buf) { int sz, i; switch (fmt) { @@ -78,7 +77,7 @@ static int alloc_buffer_ring_video(freenect_video_format fmt, buffer_ring_t *buf case FREENECT_VIDEO_IR_8BIT: case FREENECT_VIDEO_IR_10BIT: case FREENECT_VIDEO_IR_10BIT_PACKED: - sz = freenect_find_video_mode(m_video_resolution, fmt).bytes; + sz = freenect_find_video_mode(res, fmt).bytes; break; default: printf("Invalid video format %d\n", fmt); @@ -89,10 +88,11 @@ static int alloc_buffer_ring_video(freenect_video_format fmt, buffer_ring_t *buf buf->timestamp = 0; buf->valid = 0; buf->fmt = fmt; + buf->res = res; return 0; } -static int alloc_buffer_ring_depth(freenect_depth_format fmt, buffer_ring_t *buf) +static int alloc_buffer_ring_depth(freenect_resolution res, freenect_depth_format fmt, buffer_ring_t *buf) { int sz, i; switch (fmt) { @@ -102,7 +102,7 @@ static int alloc_buffer_ring_depth(freenect_depth_format fmt, buffer_ring_t *buf case FREENECT_DEPTH_10BIT_PACKED: case FREENECT_DEPTH_REGISTERED: case FREENECT_DEPTH_MM: - sz = freenect_find_depth_mode(m_depth_resolution, fmt).bytes; + sz = freenect_find_depth_mode(res, fmt).bytes; break; default: printf("Invalid depth format %d\n", fmt); @@ -113,6 +113,7 @@ static int alloc_buffer_ring_depth(freenect_depth_format fmt, buffer_ring_t *buf buf->timestamp = 0; buf->valid = 0; buf->fmt = fmt; + buf->res = res; return 0; } @@ -126,6 +127,7 @@ static void free_buffer_ring(buffer_ring_t *buf) buf->timestamp = 0; buf->valid = 0; buf->fmt = -1; + buf->res = -1; } static void producer_cb_inner(freenect_device *dev, void *data, uint32_t timestamp, buffer_ring_t *buf, set_buffer_t set_buffer) @@ -219,29 +221,27 @@ static void init_thread(void) pthread_create(&thread, NULL, init, NULL); } -static int change_video_format(sync_kinect_t *kinect, freenect_video_format fmt, freenect_resolution requested_resolution) +static int change_video_format(sync_kinect_t *kinect, freenect_resolution res, freenect_video_format fmt) { freenect_stop_video(kinect->dev); free_buffer_ring(&kinect->video); - if (alloc_buffer_ring_video(fmt, &kinect->video)) + if (alloc_buffer_ring_video(res, fmt, &kinect->video)) return -1; - freenect_set_video_mode(kinect->dev, freenect_find_video_mode(requested_resolution, fmt)); + freenect_set_video_mode(kinect->dev, freenect_find_video_mode(res, fmt)); freenect_set_video_buffer(kinect->dev, kinect->video.bufs[2]); freenect_start_video(kinect->dev); - m_video_resolution = requested_resolution; return 0; } -static int change_depth_format(sync_kinect_t *kinect, freenect_depth_format fmt, freenect_resolution requested_resolution) +static int change_depth_format(sync_kinect_t *kinect, freenect_resolution res, freenect_depth_format fmt) { freenect_stop_depth(kinect->dev); free_buffer_ring(&kinect->depth); - if (alloc_buffer_ring_depth(fmt, &kinect->depth)) + if (alloc_buffer_ring_depth(res, fmt, &kinect->depth)) return -1; - freenect_set_depth_mode(kinect->dev, freenect_find_depth_mode(requested_resolution, fmt)); + freenect_set_depth_mode(kinect->dev, freenect_find_depth_mode(res, fmt)); freenect_set_depth_buffer(kinect->dev, kinect->depth.bufs[2]); freenect_start_depth(kinect->dev); - m_depth_resolution = requested_resolution; return 0; } @@ -258,7 +258,9 @@ static sync_kinect_t *alloc_kinect(int index) kinect->depth.bufs[i] = NULL; } kinect->video.fmt = -1; + kinect->video.res = -1; kinect->depth.fmt = -1; + kinect->depth.res = -1; freenect_set_video_callback(kinect->dev, video_producer_cb); freenect_set_depth_callback(kinect->dev, depth_producer_cb); pthread_mutex_init(&kinect->video.lock, NULL); @@ -268,7 +270,7 @@ static sync_kinect_t *alloc_kinect(int index) return kinect; } -static int setup_kinect(int index, int fmt, int is_depth) +static int setup_kinect(int index, int res, int fmt, int is_depth) { pending_runloop_tasks_inc(); pthread_mutex_lock(&runloop_lock); @@ -299,12 +301,12 @@ static int setup_kinect(int index, int fmt, int is_depth) else buf = &kinects[index]->video; pthread_mutex_lock(&buf->lock); - if (buf->fmt != fmt) { + if ((buf->fmt != fmt) || (buf->res != res)) { if (is_depth) - change_depth_format(kinects[index], (freenect_depth_format)fmt, m_video_resolution); + change_depth_format(kinects[index], (freenect_resolution)res, (freenect_depth_format)fmt); else - change_video_format(kinects[index], (freenect_video_format)fmt, m_video_resolution); - } + change_video_format(kinects[index], (freenect_resolution)res, (freenect_video_format)fmt); + } pthread_mutex_unlock(&buf->lock); pthread_mutex_unlock(&runloop_lock); pending_runloop_tasks_dec(); @@ -343,7 +345,7 @@ static int runloop_enter(int index) return -1; } if (!thread_running || !kinects[index]) - if (setup_kinect(index, FREENECT_DEPTH_11BIT, 1)) + if (setup_kinect(index, FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT, 1)) return -1; pending_runloop_tasks_inc(); @@ -357,27 +359,31 @@ static void runloop_exit() pending_runloop_tasks_dec(); } -int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt) +int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, + freenect_resolution res, freenect_video_format fmt) { if (index < 0 || index >= MAX_KINECTS) { printf("Error: Invalid index [%d]\n", index); return -1; } - if (!thread_running || !kinects[index] || kinects[index]->video.fmt != fmt) - if (setup_kinect(index, fmt, 0)) + if (!thread_running || !kinects[index] || kinects[index]->video.fmt != fmt + || kinects[index]->video.res != res) + if (setup_kinect(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, freenect_depth_format fmt) +int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, + freenect_resolution res, freenect_depth_format fmt) { if (index < 0 || index >= MAX_KINECTS) { printf("Error: Invalid index [%d]\n", index); return -1; } - if (!thread_running || !kinects[index] || kinects[index]->depth.fmt != fmt) - if (setup_kinect(index, fmt, 1)) + if (!thread_running || !kinects[index] || kinects[index]->depth.fmt != fmt + || kinects[index]->depth.res != res) + if (setup_kinect(index, res, fmt, 1)) return -1; sync_get(depth, timestamp, &kinects[index]->depth); return 0; diff --git a/wrappers/c_sync/libfreenect_sync.h b/wrappers/c_sync/libfreenect_sync.h index 35e76c40..64214265 100644 --- a/wrappers/c_sync/libfreenect_sync.h +++ b/wrappers/c_sync/libfreenect_sync.h @@ -33,7 +33,8 @@ extern "C" { #endif -int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt); +int freenect_sync_get_video(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 The returned buffer is valid until this function is called again, after which the buffer must not @@ -49,8 +50,8 @@ int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freene Nonzero on error. */ - -int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt); +int freenect_sync_get_depth(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 The returned buffer is valid until this function is called again, after which the buffer must not From 36eae29fca143b9bee0ab47954ff7baef9d62463 Mon Sep 17 00:00:00 2001 From: mcteo Date: Wed, 1 Aug 2012 15:44:07 +0100 Subject: [PATCH 3/3] 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