Commits

Cliff Biffle committed 334f1da

KVDepthRecorder now writes frames asynchronously using GCD. There are no safeguards against buffering all of RAM if the disk is slow, but previously we'd drop frames and that was lame.

  • Participants
  • Parent commits 01e6772

Comments (0)

Files changed (1)

File KVDepthRecorder.m

 
 @interface KVDepthRecorder ()
 
+@property dispatch_queue_t dispatchQueue;
 @property NSFileHandle *fileHandle;
 
 @end
 
 @implementation KVDepthRecorder
 @synthesize fileHandle;
+@synthesize dispatchQueue;
+
+- init {
+  if (!(self = [super init])) return nil;
+  
+  dispatchQueue = dispatch_queue_create("org.mg8.kinect.depth-recorder", 0);
+
+  return self;
+}
+
+- (void)finalize {
+  dispatch_release(dispatchQueue);
+  [super finalize];
+}
 
 - (void) open: (NSString *) path {
   @synchronized (self) {
 }
 
 - (void) setLatestDepthSamples: (NSData *) data {
-  @synchronized (self) {
-    [fileHandle writeData: data];
-  }
+  NSData *copy = [NSData dataWithBytes: [data bytes] length: [data length]];
+  dispatch_async(dispatchQueue, ^{
+    [fileHandle writeData: copy];
+  });
 }
 
 - (NSData *) latestDepthSamples {