Commits

Cliff Biffle  committed 0416bfa

Replay support: given a file of raw unlinearized 16-bit depth samples in the order generated by libfreenect, the viewer can now display a movie.

  • Participants
  • Parent commits 1c419a3

Comments (0)

Files changed (1)

File KinectViewerAppDelegate.m

 @synthesize depthView;
 
 - (void)applicationDidFinishLaunching: (NSNotification *)aNotification {
-  kinect = [[KFKinect alloc] init];
-  kinect.delegate = depthView;
-  [kinect openWithDepthBuffer: [[depthView rawDepthField] mutableBytes] rgbBuffer: nil];
+  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+  NSString *replayFile = [defaults stringForKey: @"replay"];
+  
+  if (replayFile) {
+    [NSThread detachNewThreadSelector:@selector(replayThread:) toTarget:self withObject:replayFile];
+  } else {
+    kinect = [[KFKinect alloc] init];
+    kinect.delegate = depthView;
+    [kinect openWithDepthBuffer: [[depthView rawDepthField] mutableBytes] rgbBuffer: nil];
+  }
+}
+
+- (void)replayThread: (NSString *)replayFile {
+  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+  
+  uint8_t *bytes = [[depthView rawDepthField] mutableBytes];
+  while (true) {
+    int fd = open([replayFile cStringUsingEncoding: NSASCIIStringEncoding], O_RDONLY);
+    do {
+      int r = 0;
+      r = read(fd, bytes, 640*480*2);
+      if (r < 640*480*2) break;
+      [depthView depthFieldUpdated: nil];
+      usleep(1000000 / 30);
+    } while (YES);
+    close(fd);
+  }
+  
+  [pool drain];
 }
 
 @end