@@ -56,6 +56,8 @@ static pthread_mutex_t runloop_lock = PTHREAD_MUTEX_INITIALIZER;
5656static int pending_runloop_tasks = 0 ;
5757static pthread_mutex_t pending_runloop_tasks_lock = PTHREAD_MUTEX_INITIALIZER ;
5858static pthread_cond_t pending_runloop_tasks_cond = PTHREAD_COND_INITIALIZER ;
59+ static freenect_resolution m_video_resolution = FREENECT_RESOLUTION_MEDIUM ;
60+ static freenect_resolution m_depth_resolution = FREENECT_RESOLUTION_MEDIUM ;
5961
6062/* Locking Convention
6163 Rules:
@@ -76,7 +78,7 @@ static int alloc_buffer_ring_video(freenect_video_format fmt, buffer_ring_t *buf
7678 case FREENECT_VIDEO_IR_8BIT :
7779 case FREENECT_VIDEO_IR_10BIT :
7880 case FREENECT_VIDEO_IR_10BIT_PACKED :
79- sz = freenect_find_video_mode (FREENECT_RESOLUTION_MEDIUM , fmt ).bytes ;
81+ sz = freenect_find_video_mode (m_video_resolution , fmt ).bytes ;
8082 break ;
8183 default :
8284 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
100102 case FREENECT_DEPTH_10BIT_PACKED :
101103 case FREENECT_DEPTH_REGISTERED :
102104 case FREENECT_DEPTH_MM :
103- sz = freenect_find_depth_mode (FREENECT_RESOLUTION_MEDIUM , fmt ).bytes ;
105+ sz = freenect_find_depth_mode (m_depth_resolution , fmt ).bytes ;
104106 break ;
105107 default :
106108 printf ("Invalid depth format %d\n" , fmt );
@@ -217,27 +219,29 @@ static void init_thread(void)
217219 pthread_create (& thread , NULL , init , NULL );
218220}
219221
220- static int change_video_format (sync_kinect_t * kinect , freenect_video_format fmt )
222+ static int change_video_format (sync_kinect_t * kinect , freenect_video_format fmt , freenect_resolution requested_resolution )
221223{
222224 freenect_stop_video (kinect -> dev );
223225 free_buffer_ring (& kinect -> video );
224226 if (alloc_buffer_ring_video (fmt , & kinect -> video ))
225227 return -1 ;
226- freenect_set_video_mode (kinect -> dev , freenect_find_video_mode (FREENECT_RESOLUTION_MEDIUM , fmt ));
228+ freenect_set_video_mode (kinect -> dev , freenect_find_video_mode (requested_resolution , fmt ));
227229 freenect_set_video_buffer (kinect -> dev , kinect -> video .bufs [2 ]);
228230 freenect_start_video (kinect -> dev );
231+ m_video_resolution = requested_resolution ;
229232 return 0 ;
230233}
231234
232- static int change_depth_format (sync_kinect_t * kinect , freenect_depth_format fmt )
235+ static int change_depth_format (sync_kinect_t * kinect , freenect_depth_format fmt , freenect_resolution requested_resolution )
233236{
234237 freenect_stop_depth (kinect -> dev );
235238 free_buffer_ring (& kinect -> depth );
236239 if (alloc_buffer_ring_depth (fmt , & kinect -> depth ))
237240 return -1 ;
238- freenect_set_depth_mode (kinect -> dev , freenect_find_depth_mode (FREENECT_RESOLUTION_MEDIUM , fmt ));
241+ freenect_set_depth_mode (kinect -> dev , freenect_find_depth_mode (requested_resolution , fmt ));
239242 freenect_set_depth_buffer (kinect -> dev , kinect -> depth .bufs [2 ]);
240243 freenect_start_depth (kinect -> dev );
244+ m_depth_resolution = requested_resolution ;
241245 return 0 ;
242246}
243247
@@ -297,9 +301,9 @@ static int setup_kinect(int index, int fmt, int is_depth)
297301 pthread_mutex_lock (& buf -> lock );
298302 if (buf -> fmt != fmt ) {
299303 if (is_depth )
300- change_depth_format (kinects [index ], (freenect_depth_format )fmt );
304+ change_depth_format (kinects [index ], (freenect_depth_format )fmt , m_video_resolution );
301305 else
302- change_video_format (kinects [index ], (freenect_video_format )fmt );
306+ change_video_format (kinects [index ], (freenect_video_format )fmt , m_video_resolution );
303307 }
304308 pthread_mutex_unlock (& buf -> lock );
305309 pthread_mutex_unlock (& runloop_lock );
0 commit comments