@@ -38,6 +38,7 @@ typedef struct buffer_ring {
38
38
uint32_t timestamp ;
39
39
int valid ; // True if middle buffer is valid
40
40
int fmt ;
41
+ int res ;
41
42
} buffer_ring_t ;
42
43
43
44
typedef struct sync_kinect {
@@ -68,7 +69,7 @@ static pthread_cond_t pending_runloop_tasks_cond = PTHREAD_COND_INITIALIZER;
68
69
- runloop_lock, buffer_ring_t.lock (NOTE: You may only have one)
69
70
*/
70
71
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 )
72
73
{
73
74
int sz , i ;
74
75
switch (fmt ) {
@@ -77,7 +78,7 @@ static int alloc_buffer_ring_video(freenect_video_format fmt, buffer_ring_t *buf
77
78
case FREENECT_VIDEO_IR_8BIT :
78
79
case FREENECT_VIDEO_IR_10BIT :
79
80
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 ;
81
82
break ;
82
83
default :
83
84
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
88
89
buf -> timestamp = 0 ;
89
90
buf -> valid = 0 ;
90
91
buf -> fmt = fmt ;
92
+ buf -> res = res ;
91
93
return 0 ;
92
94
}
93
95
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 )
95
97
{
96
98
int sz , i ;
97
99
switch (fmt ) {
@@ -101,7 +103,7 @@ static int alloc_buffer_ring_depth(freenect_depth_format fmt, buffer_ring_t *buf
101
103
case FREENECT_DEPTH_10BIT_PACKED :
102
104
case FREENECT_DEPTH_REGISTERED :
103
105
case FREENECT_DEPTH_MM :
104
- sz = freenect_find_depth_mode (FREENECT_RESOLUTION_MEDIUM , fmt ).bytes ;
106
+ sz = freenect_find_depth_mode (res , fmt ).bytes ;
105
107
break ;
106
108
default :
107
109
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
112
114
buf -> timestamp = 0 ;
113
115
buf -> valid = 0 ;
114
116
buf -> fmt = fmt ;
117
+ buf -> res = res ;
115
118
return 0 ;
116
119
}
117
120
@@ -125,6 +128,7 @@ static void free_buffer_ring(buffer_ring_t *buf)
125
128
buf -> timestamp = 0 ;
126
129
buf -> valid = 0 ;
127
130
buf -> fmt = -1 ;
131
+ buf -> res = -1 ;
128
132
}
129
133
130
134
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)
218
222
pthread_create (& thread , NULL , init , NULL );
219
223
}
220
224
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 )
222
226
{
223
227
freenect_stop_video (kinect -> dev );
224
228
free_buffer_ring (& kinect -> video );
225
- if (alloc_buffer_ring_video (fmt , & kinect -> video ))
229
+ if (alloc_buffer_ring_video (res , fmt , & kinect -> video ))
226
230
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 ));
228
232
freenect_set_video_buffer (kinect -> dev , kinect -> video .bufs [2 ]);
229
233
freenect_start_video (kinect -> dev );
230
234
return 0 ;
231
235
}
232
236
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 )
234
243
{
235
244
freenect_stop_depth (kinect -> dev );
236
245
free_buffer_ring (& kinect -> depth );
237
- if (alloc_buffer_ring_depth (fmt , & kinect -> depth ))
246
+ if (alloc_buffer_ring_depth (res , fmt , & kinect -> depth ))
238
247
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 ));
240
249
freenect_set_depth_buffer (kinect -> dev , kinect -> depth .bufs [2 ]);
241
250
freenect_start_depth (kinect -> dev );
242
251
return 0 ;
243
252
}
244
253
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
+
245
259
static sync_kinect_t * alloc_kinect (int index )
246
260
{
247
261
sync_kinect_t * kinect = (sync_kinect_t * )malloc (sizeof (sync_kinect_t ));
@@ -255,7 +269,9 @@ static sync_kinect_t *alloc_kinect(int index)
255
269
kinect -> depth .bufs [i ] = NULL ;
256
270
}
257
271
kinect -> video .fmt = -1 ;
272
+ kinect -> video .res = -1 ;
258
273
kinect -> depth .fmt = -1 ;
274
+ kinect -> depth .res = -1 ;
259
275
freenect_set_video_callback (kinect -> dev , video_producer_cb );
260
276
freenect_set_depth_callback (kinect -> dev , depth_producer_cb );
261
277
pthread_mutex_init (& kinect -> video .lock , NULL );
@@ -265,7 +281,7 @@ static sync_kinect_t *alloc_kinect(int index)
265
281
return kinect ;
266
282
}
267
283
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 )
269
285
{
270
286
pending_runloop_tasks_inc ();
271
287
pthread_mutex_lock (& runloop_lock );
@@ -296,18 +312,23 @@ static int setup_kinect(int index, int fmt, int is_depth)
296
312
else
297
313
buf = & kinects [index ]-> video ;
298
314
pthread_mutex_lock (& buf -> lock );
299
- if (buf -> fmt != fmt ) {
315
+ if ((buf -> fmt != fmt ) || (buf -> res != res ))
316
+ {
300
317
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 );
302
319
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 );
304
321
}
305
322
pthread_mutex_unlock (& buf -> lock );
306
323
pthread_mutex_unlock (& runloop_lock );
307
324
pending_runloop_tasks_dec ();
308
325
return 0 ;
309
326
}
310
327
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
+
311
332
static int sync_get (void * * data , uint32_t * timestamp , buffer_ring_t * buf )
312
333
{
313
334
pthread_mutex_lock (& buf -> lock );
@@ -340,7 +361,7 @@ static int runloop_enter(int index)
340
361
return -1 ;
341
362
}
342
363
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 ))
344
365
return -1 ;
345
366
346
367
pending_runloop_tasks_inc ();
@@ -354,32 +375,45 @@ static void runloop_exit()
354
375
pending_runloop_tasks_dec ();
355
376
}
356
377
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 )
358
380
{
359
381
if (index < 0 || index >= MAX_KINECTS ) {
360
382
printf ("Error: Invalid index [%d]\n" , index );
361
383
return -1 ;
362
384
}
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 ))
365
387
return -1 ;
366
388
sync_get (video , timestamp , & kinects [index ]-> video );
367
389
return 0 ;
368
390
}
369
391
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 )
371
399
{
372
400
if (index < 0 || index >= MAX_KINECTS ) {
373
401
printf ("Error: Invalid index [%d]\n" , index );
374
402
return -1 ;
375
403
}
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 ))
378
407
return -1 ;
379
408
sync_get (depth , timestamp , & kinects [index ]-> depth );
380
409
return 0 ;
381
410
}
382
411
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
+
383
417
int freenect_sync_get_tilt_state (freenect_raw_tilt_state * * state , int index )
384
418
{
385
419
if (runloop_enter (index )) return -1 ;
0 commit comments