Skip to content

Commit 6d0698a

Browse files
committed
Merge branch 'signed-master' of git://github.com/mcteo/libfreenect into master
Reviewed-by: Benn Snyder <[email protected]> Conflicts: wrappers/c_sync/libfreenect_sync.h
2 parents 80f7423 + 36eae29 commit 6d0698a

File tree

2 files changed

+72
-23
lines changed

2 files changed

+72
-23
lines changed

wrappers/c_sync/libfreenect_sync.c

+55-21
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef struct buffer_ring {
3838
uint32_t timestamp;
3939
int valid; // True if middle buffer is valid
4040
int fmt;
41+
int res;
4142
} buffer_ring_t;
4243

4344
typedef struct sync_kinect {
@@ -68,7 +69,7 @@ static pthread_cond_t pending_runloop_tasks_cond = PTHREAD_COND_INITIALIZER;
6869
- runloop_lock, buffer_ring_t.lock (NOTE: You may only have one)
6970
*/
7071

71-
static int alloc_buffer_ring_video(freenect_video_format fmt, buffer_ring_t *buf)
72+
static int alloc_buffer_ring_video(freenect_resolution res, freenect_video_format fmt, buffer_ring_t *buf)
7273
{
7374
int sz, i;
7475
switch (fmt) {
@@ -77,7 +78,7 @@ static int alloc_buffer_ring_video(freenect_video_format fmt, buffer_ring_t *buf
7778
case FREENECT_VIDEO_IR_8BIT:
7879
case FREENECT_VIDEO_IR_10BIT:
7980
case FREENECT_VIDEO_IR_10BIT_PACKED:
80-
sz = freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, fmt).bytes;
81+
sz = freenect_find_video_mode(res, fmt).bytes;
8182
break;
8283
default:
8384
printf("Invalid video format %d\n", fmt);
@@ -88,10 +89,11 @@ static int alloc_buffer_ring_video(freenect_video_format fmt, buffer_ring_t *buf
8889
buf->timestamp = 0;
8990
buf->valid = 0;
9091
buf->fmt = fmt;
92+
buf->res = res;
9193
return 0;
9294
}
9395

94-
static int alloc_buffer_ring_depth(freenect_depth_format fmt, buffer_ring_t *buf)
96+
static int alloc_buffer_ring_depth(freenect_resolution res, freenect_depth_format fmt, buffer_ring_t *buf)
9597
{
9698
int sz, i;
9799
switch (fmt) {
@@ -101,7 +103,7 @@ static int alloc_buffer_ring_depth(freenect_depth_format fmt, buffer_ring_t *buf
101103
case FREENECT_DEPTH_10BIT_PACKED:
102104
case FREENECT_DEPTH_REGISTERED:
103105
case FREENECT_DEPTH_MM:
104-
sz = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, fmt).bytes;
106+
sz = freenect_find_depth_mode(res, fmt).bytes;
105107
break;
106108
default:
107109
printf("Invalid depth format %d\n", fmt);
@@ -112,6 +114,7 @@ static int alloc_buffer_ring_depth(freenect_depth_format fmt, buffer_ring_t *buf
112114
buf->timestamp = 0;
113115
buf->valid = 0;
114116
buf->fmt = fmt;
117+
buf->res = res;
115118
return 0;
116119
}
117120

@@ -125,6 +128,7 @@ static void free_buffer_ring(buffer_ring_t *buf)
125128
buf->timestamp = 0;
126129
buf->valid = 0;
127130
buf->fmt = -1;
131+
buf->res = -1;
128132
}
129133

130134
static void producer_cb_inner(freenect_device *dev, void *data, uint32_t timestamp, buffer_ring_t *buf, set_buffer_t set_buffer)
@@ -218,30 +222,40 @@ static void init_thread(void)
218222
pthread_create(&thread, NULL, init, NULL);
219223
}
220224

221-
static int change_video_format(sync_kinect_t *kinect, freenect_video_format fmt)
225+
static int change_video_format_with_res(sync_kinect_t *kinect, freenect_resolution res, freenect_video_format fmt)
222226
{
223227
freenect_stop_video(kinect->dev);
224228
free_buffer_ring(&kinect->video);
225-
if (alloc_buffer_ring_video(fmt, &kinect->video))
229+
if (alloc_buffer_ring_video(res, fmt, &kinect->video))
226230
return -1;
227-
freenect_set_video_mode(kinect->dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, fmt));
231+
freenect_set_video_mode(kinect->dev, freenect_find_video_mode(res, fmt));
228232
freenect_set_video_buffer(kinect->dev, kinect->video.bufs[2]);
229233
freenect_start_video(kinect->dev);
230234
return 0;
231235
}
232236

233-
static int change_depth_format(sync_kinect_t *kinect, freenect_depth_format fmt)
237+
static int change_video_format(sync_kinect_t *kinect, freenect_resolution res, freenect_video_format fmt)
238+
{
239+
return change_video_format_with_res(kinect, FREENECT_RESOLUTION_MEDIUM, fmt);
240+
}
241+
242+
static int change_depth_format_with_res(sync_kinect_t *kinect, freenect_resolution res, freenect_depth_format fmt)
234243
{
235244
freenect_stop_depth(kinect->dev);
236245
free_buffer_ring(&kinect->depth);
237-
if (alloc_buffer_ring_depth(fmt, &kinect->depth))
246+
if (alloc_buffer_ring_depth(res, fmt, &kinect->depth))
238247
return -1;
239-
freenect_set_depth_mode(kinect->dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, fmt));
248+
freenect_set_depth_mode(kinect->dev, freenect_find_depth_mode(res, fmt));
240249
freenect_set_depth_buffer(kinect->dev, kinect->depth.bufs[2]);
241250
freenect_start_depth(kinect->dev);
242251
return 0;
243252
}
244253

254+
static int change_depth_format(sync_kinect_t *kinect, freenect_resolution res, freenect_depth_format fmt)
255+
{
256+
return change_depth_format_with_res(kinect, FREENECT_RESOLUTION_MEDIUM, fmt);
257+
}
258+
245259
static sync_kinect_t *alloc_kinect(int index)
246260
{
247261
sync_kinect_t *kinect = (sync_kinect_t*)malloc(sizeof(sync_kinect_t));
@@ -255,7 +269,9 @@ static sync_kinect_t *alloc_kinect(int index)
255269
kinect->depth.bufs[i] = NULL;
256270
}
257271
kinect->video.fmt = -1;
272+
kinect->video.res = -1;
258273
kinect->depth.fmt = -1;
274+
kinect->depth.res = -1;
259275
freenect_set_video_callback(kinect->dev, video_producer_cb);
260276
freenect_set_depth_callback(kinect->dev, depth_producer_cb);
261277
pthread_mutex_init(&kinect->video.lock, NULL);
@@ -265,7 +281,7 @@ static sync_kinect_t *alloc_kinect(int index)
265281
return kinect;
266282
}
267283

268-
static int setup_kinect(int index, int fmt, int is_depth)
284+
static int setup_kinect_with_res(int index, int res, int fmt, int is_depth)
269285
{
270286
pending_runloop_tasks_inc();
271287
pthread_mutex_lock(&runloop_lock);
@@ -296,18 +312,23 @@ static int setup_kinect(int index, int fmt, int is_depth)
296312
else
297313
buf = &kinects[index]->video;
298314
pthread_mutex_lock(&buf->lock);
299-
if (buf->fmt != fmt) {
315+
if ((buf->fmt != fmt) || (buf->res != res))
316+
{
300317
if (is_depth)
301-
change_depth_format(kinects[index], (freenect_depth_format)fmt);
318+
change_depth_format_with_res(kinects[index], (freenect_resolution)res, (freenect_depth_format)fmt);
302319
else
303-
change_video_format(kinects[index], (freenect_video_format)fmt);
320+
change_video_format_with_res(kinects[index], (freenect_resolution)res, (freenect_video_format)fmt);
304321
}
305322
pthread_mutex_unlock(&buf->lock);
306323
pthread_mutex_unlock(&runloop_lock);
307324
pending_runloop_tasks_dec();
308325
return 0;
309326
}
310327

328+
static int setup_kinect(int index, int fmt, int is_depth) {
329+
return setup_kinect_with_res(index, FREENECT_RESOLUTION_MEDIUM, fmt, is_depth);
330+
}
331+
311332
static int sync_get(void **data, uint32_t *timestamp, buffer_ring_t *buf)
312333
{
313334
pthread_mutex_lock(&buf->lock);
@@ -340,7 +361,7 @@ static int runloop_enter(int index)
340361
return -1;
341362
}
342363
if (!thread_running || !kinects[index])
343-
if (setup_kinect(index, FREENECT_DEPTH_11BIT, 1))
364+
if (setup_kinect_with_res(index, FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT, 1))
344365
return -1;
345366

346367
pending_runloop_tasks_inc();
@@ -354,32 +375,45 @@ static void runloop_exit()
354375
pending_runloop_tasks_dec();
355376
}
356377

357-
int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt)
378+
int freenect_sync_get_video_with_res(void **video, uint32_t *timestamp, int index,
379+
freenect_resolution res, freenect_video_format fmt)
358380
{
359381
if (index < 0 || index >= MAX_KINECTS) {
360382
printf("Error: Invalid index [%d]\n", index);
361383
return -1;
362384
}
363-
if (!thread_running || !kinects[index] || kinects[index]->video.fmt != fmt)
364-
if (setup_kinect(index, fmt, 0))
385+
if (!thread_running || !kinects[index] || kinects[index]->video.fmt != fmt || kinects[index]->video.res != res)
386+
if (setup_kinect_with_res(index, res, fmt, 0))
365387
return -1;
366388
sync_get(video, timestamp, &kinects[index]->video);
367389
return 0;
368390
}
369391

370-
int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt)
392+
int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt)
393+
{
394+
return freenect_sync_get_video_with_res(video, timestamp, index, FREENECT_RESOLUTION_MEDIUM, fmt);
395+
}
396+
397+
int freenect_sync_get_depth_with_res(void **depth, uint32_t *timestamp, int index,
398+
freenect_resolution res, freenect_depth_format fmt)
371399
{
372400
if (index < 0 || index >= MAX_KINECTS) {
373401
printf("Error: Invalid index [%d]\n", index);
374402
return -1;
375403
}
376-
if (!thread_running || !kinects[index] || kinects[index]->depth.fmt != fmt)
377-
if (setup_kinect(index, fmt, 1))
404+
if (!thread_running || !kinects[index] || kinects[index]->depth.fmt != fmt
405+
|| kinects[index]->depth.res != res)
406+
if (setup_kinect_with_res(index, res, fmt, 1))
378407
return -1;
379408
sync_get(depth, timestamp, &kinects[index]->depth);
380409
return 0;
381410
}
382411

412+
int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt)
413+
{
414+
return freenect_sync_get_depth_with_res(depth, timestamp, index, FREENECT_RESOLUTION_MEDIUM, fmt);
415+
}
416+
383417
int freenect_sync_get_tilt_state(freenect_raw_tilt_state **state, int index)
384418
{
385419
if (runloop_enter(index)) return -1;

wrappers/c_sync/libfreenect_sync.h

+17-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
extern "C" {
4848
#endif
4949

50-
FREENECTAPI_SYNC int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt);
50+
FREENECTAPI_SYNC int freenect_sync_get_video_with_res(void **video, uint32_t *timestamp, int index,
51+
freenect_resolution res, freenect_video_format fmt);
5152
/* Synchronous video function, starts the runloop if it isn't running
5253
5354
The returned buffer is valid until this function is called again, after which the buffer must not
@@ -57,14 +58,21 @@ FREENECTAPI_SYNC int freenect_sync_get_video(void **video, uint32_t *timestamp,
5758
video: Populated with a pointer to a video buffer with a size of the requested type
5859
timestamp: Populated with the associated timestamp
5960
index: Device index (0 is the first)
61+
res: Valid resolution
6062
fmt: Valid format
6163
6264
Returns:
6365
Nonzero on error.
6466
*/
6567

68+
int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt);
69+
/* Does the exact same as above, but with a default resolution,
70+
so backwards compatibilty is maintained.
71+
The Resolution is kept at the default FREENECT_RESOLUTION_MEDIUM
72+
*/
6673

67-
FREENECTAPI_SYNC int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt);
74+
FREENECTAPI_SYNC int freenect_sync_get_depth_with_res(void **depth, uint32_t *timestamp, int index,
75+
freenect_resolution res, freenect_depth_format fmt);
6876
/* Synchronous depth function, starts the runloop if it isn't running
6977
7078
The returned buffer is valid until this function is called again, after which the buffer must not
@@ -74,12 +82,19 @@ FREENECTAPI_SYNC int freenect_sync_get_depth(void **depth, uint32_t *timestamp,
7482
depth: Populated with a pointer to a depth buffer with a size of the requested type
7583
timestamp: Populated with the associated timestamp
7684
index: Device index (0 is the first)
85+
res: Valid resolution
7786
fmt: Valid format
7887
7988
Returns:
8089
Nonzero on error.
8190
*/
8291

92+
int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt);
93+
/* Again, a wrapper function to keep backward compatibility.
94+
The Resolution is kept at the default FREENECT_RESOLUTION_MEDIUM
95+
96+
*/
97+
8398
FREENECTAPI_SYNC int freenect_sync_set_tilt_degs(int angle, int index);
8499
/* Tilt function, starts the runloop if it isn't running
85100

0 commit comments

Comments
 (0)