34
34
#include <math.h>
35
35
#include <unistd.h>
36
36
#include <assert.h>
37
+ #include <stdbool.h>
38
+ #include <ctype.h>
37
39
38
40
#define GRAVITY 9.80665
39
41
@@ -56,6 +58,7 @@ static void *user_video_buf = NULL;
56
58
static int depth_running = 0 ;
57
59
static int rgb_running = 0 ;
58
60
static void * user_ptr = NULL ;
61
+ static bool loop_playback = true;
59
62
60
63
#define MAKE_RESERVED (res , fmt ) (uint32_t)(((res & 0xff) << 8) | (((fmt & 0xff))))
61
64
#define RESERVED_TO_RESOLUTION (reserved ) (freenect_resolution)((reserved >> 8) & 0xff)
@@ -157,6 +160,14 @@ static void open_index()
157
160
free (index_path );
158
161
}
159
162
163
+ static void close_index ()
164
+ {
165
+ fclose (index_fp );
166
+ index_fp = NULL ;
167
+ record_prev_time = 0 ;
168
+ playback_prev_time = 0 ;
169
+ }
170
+
160
171
static char * skip_line (char * str )
161
172
{
162
173
char * out = strchr (str , '\n' );
@@ -211,8 +222,13 @@ int freenect_process_events(freenect_context *ctx)
211
222
double record_cur_time ;
212
223
unsigned int timestamp , data_size ;
213
224
char * data = NULL ;
214
- if (parse_line (& type , & record_cur_time , & timestamp , & data_size , & data ))
215
- return -1 ;
225
+ if (parse_line (& type , & record_cur_time , & timestamp , & data_size , & data )) {
226
+ if (loop_playback ) {
227
+ close_index ();
228
+ return 0 ;
229
+ } else
230
+ return -1 ;
231
+ }
216
232
// Sleep an amount that compensates for the original and current delays
217
233
// playback_ is w.r.t. the current time
218
234
// record_ is w.r.t. the original time period during the recording
@@ -509,6 +525,21 @@ int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)
509
525
exit (1 );
510
526
}
511
527
528
+ char * var = getenv ("FAKENECT_LOOP" );
529
+ if (var ) {
530
+ int len = strlen (var );
531
+ char tmp [len + 1 ];
532
+ for (int i = 0 ; i < len ; i ++ )
533
+ tmp [i ] = tolower (var [i ]);
534
+ tmp [len ] = '\0' ;
535
+ if (strcmp (tmp , "0" ) == 0 ||
536
+ strcmp (tmp , "false" ) == 0 ||
537
+ strcmp (tmp , "no" ) == 0 ||
538
+ strcmp (tmp , "off" ) == 0 ) {
539
+ loop_playback = false;
540
+ }
541
+ }
542
+
512
543
* ctx = fake_ctx ;
513
544
514
545
read_device_info (fake_dev );
0 commit comments