Skip to content

Commit

Permalink
Changed the names of the modified functions, and added wrapper functi…
Browse files Browse the repository at this point in the history
…ons (under original names) that maintain backwards compatibilty, and functionality

Signed-off-by: Thomas Dunne <thomasdunne999@gmail.com>
  • Loading branch information
mcteo authored and mcteo committed Aug 2, 2012
1 parent ae32bfb commit 36eae29
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/glpclview.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions examples/regtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,31 @@ 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();

fp = open_dump("registration_test_rgb.ppm");
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();

fp = open_dump("registration_test_depth_raw.pgm");
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();

fp = open_dump("registration_test_depth_registered.pgm");
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();

Expand Down
44 changes: 34 additions & 10 deletions wrappers/c_sync/libfreenect_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -303,16 +313,20 @@ 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);
pending_runloop_tasks_dec();
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);
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions wrappers/c_sync/libfreenect_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 36eae29

Please sign in to comment.