Cliff Biffle avatar 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.

Comments (0)

Files changed (1)


 @interface KVDepthRecorder ()
+@property dispatch_queue_t dispatchQueue;
 @property NSFileHandle *fileHandle;
 @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 {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.