Skip to content

Commit

Permalink
Improved camera performance by reducing quality. Stopped sending out …
Browse files Browse the repository at this point in the history
…distributed notifications, as they seem really slow in 10.9. Checking for accessibility access.
  • Loading branch information
Nick Winter authored and Nick Winter committed Oct 31, 2013
1 parent 25d083e commit 0a0b3db
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Telepath.xcodeproj/project.pbxproj
Expand Up @@ -14,6 +14,7 @@
C8A1949417DD145100C0F7FC /* TPTrackerBrunchBuilds.m in Sources */ = {isa = PBXBuildFile; fileRef = C8A1949317DD145100C0F7FC /* TPTrackerBrunchBuilds.m */; };
C8A1949717DD272E00C0F7FC /* TPTrackerEmail.m in Sources */ = {isa = PBXBuildFile; fileRef = C8A1949617DD272E00C0F7FC /* TPTrackerEmail.m */; };
C8A1949C17DEDDCC00C0F7FC /* TPTrackerWorkHours.m in Sources */ = {isa = PBXBuildFile; fileRef = C8A1949B17DEDDCC00C0F7FC /* TPTrackerWorkHours.m */; };
C8AF4BF518221E870007835F /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8AF4BF418221E870007835F /* ApplicationServices.framework */; };
C8E5F62717E8186E00129E0D /* TPTrackerScreen.m in Sources */ = {isa = PBXBuildFile; fileRef = C8E5F62617E8186E00129E0D /* TPTrackerScreen.m */; };
C8E9BEE417EEA27100049672 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8E9BEE317EEA27100049672 /* WebKit.framework */; };
C8F6325917D1053800330DFD /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8F6325817D1053800330DFD /* Cocoa.framework */; };
Expand Down Expand Up @@ -66,6 +67,7 @@
C8A1949617DD272E00C0F7FC /* TPTrackerEmail.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPTrackerEmail.m; sourceTree = "<group>"; };
C8A1949A17DEDDCC00C0F7FC /* TPTrackerWorkHours.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPTrackerWorkHours.h; sourceTree = "<group>"; };
C8A1949B17DEDDCC00C0F7FC /* TPTrackerWorkHours.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPTrackerWorkHours.m; sourceTree = "<group>"; };
C8AF4BF418221E870007835F /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; };
C8E5F62517E8186E00129E0D /* TPTrackerScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPTrackerScreen.h; sourceTree = "<group>"; };
C8E5F62617E8186E00129E0D /* TPTrackerScreen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPTrackerScreen.m; sourceTree = "<group>"; };
C8E9BEE317EEA27100049672 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -120,6 +122,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
C8AF4BF518221E870007835F /* ApplicationServices.framework in Frameworks */,
C8E9BEE417EEA27100049672 /* WebKit.framework in Frameworks */,
C83B4D1A17E11B81009F5DCC /* IOKit.framework in Frameworks */,
C83B4D1817E11B57009F5DCC /* QuartzCore.framework in Frameworks */,
Expand Down Expand Up @@ -162,6 +165,7 @@
C8F6325717D1053800330DFD /* Frameworks */ = {
isa = PBXGroup;
children = (
C8AF4BF418221E870007835F /* ApplicationServices.framework */,
C8E9BEE317EEA27100049672 /* WebKit.framework */,
C83B4D1917E11B81009F5DCC /* IOKit.framework */,
C83B4D1717E11B57009F5DCC /* QuartzCore.framework */,
Expand Down
1 change: 1 addition & 0 deletions Telepath/ImageSnap.h
Expand Up @@ -14,6 +14,7 @@
QTCaptureSession *mCaptureSession;
QTCaptureDeviceInput *mCaptureDeviceInput;
QTCaptureDecompressedVideoOutput *mCaptureDecompressedVideoOutput;
QTCaptureVideoPreviewOutput *mCaptureVideoPreviewOutput;
CVImageBufferRef mCurrentImageBuffer;
}

Expand Down
36 changes: 28 additions & 8 deletions Telepath/ImageSnap.m
Expand Up @@ -38,6 +38,7 @@ - (id)init{
mCaptureSession = nil;
mCaptureDeviceInput = nil;
mCaptureDecompressedVideoOutput = nil;
mCaptureVideoPreviewOutput = nil;
mCurrentImageBuffer = nil;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDeviceDisconnected:) name:QTCaptureDeviceWasDisconnectedNotification object:nil];
return self;
Expand All @@ -48,6 +49,7 @@ - (void)dealloc{
if( mCaptureSession ) [mCaptureSession release];
if( mCaptureDeviceInput ) [mCaptureDeviceInput release];
if( mCaptureDecompressedVideoOutput ) [mCaptureDecompressedVideoOutput release];
if( mCaptureVideoPreviewOutput ) [mCaptureVideoPreviewOutput release];
CVBufferRelease(mCurrentImageBuffer);
[[NSNotificationCenter defaultCenter] removeObserver:self];

Expand Down Expand Up @@ -314,10 +316,12 @@ -(void)stopSession{
if( mCaptureSession ) [mCaptureSession release];
if( mCaptureDeviceInput ) [mCaptureDeviceInput release];
if( mCaptureDecompressedVideoOutput ) [mCaptureDecompressedVideoOutput release];
if( mCaptureVideoPreviewOutput ) [mCaptureVideoPreviewOutput release];

mCaptureSession = nil;
mCaptureDeviceInput = nil;
mCaptureDecompressedVideoOutput = nil;
mCaptureVideoPreviewOutput = nil;
} // end if: stopped

} // end while: not stopped
Expand Down Expand Up @@ -377,22 +381,38 @@ -(BOOL)startSession:(QTCaptureDevice *)device{
}


// Decompressed video output
verbose( "\tCreating QTCaptureDecompressedVideoOutput...");
mCaptureDecompressedVideoOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
[mCaptureDecompressedVideoOutput setDelegate:self];
// // Decompressed video output
// verbose( "\tCreating QTCaptureDecompressedVideoOutput...");
// mCaptureDecompressedVideoOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
// [mCaptureDecompressedVideoOutput setDelegate:self];
// verbose( "Done.\n" );
// if (![mCaptureSession addOutput:mCaptureDecompressedVideoOutput error:&error]) {
// error( "\tCould not create decompressed output.\n");
// [mCaptureSession release];
// [mCaptureDeviceInput release];
// [mCaptureDecompressedVideoOutput release];
// mCaptureSession = nil;
// mCaptureDeviceInput = nil;
// mCaptureDecompressedVideoOutput = nil;
// return NO;
// }

// Preview video output
verbose( "\tCreating QTCaptureVideoPreviewOutput...");
mCaptureVideoPreviewOutput = [[QTCaptureVideoPreviewOutput alloc] init];
[mCaptureVideoPreviewOutput setDelegate:self];
verbose( "Done.\n" );
if (![mCaptureSession addOutput:mCaptureDecompressedVideoOutput error:&error]) {
if (![mCaptureSession addOutput:mCaptureVideoPreviewOutput error:&error]) {
error( "\tCould not create decompressed output.\n");
[mCaptureSession release];
[mCaptureDeviceInput release];
[mCaptureDecompressedVideoOutput release];
[mCaptureVideoPreviewOutput release];
mCaptureSession = nil;
mCaptureDeviceInput = nil;
mCaptureDecompressedVideoOutput = nil;
mCaptureVideoPreviewOutput = nil;
return NO;
}

// Clear old image?
verbose("\tEntering synchronized block to clear memory...");
@synchronized(self){
Expand Down
11 changes: 7 additions & 4 deletions Telepath/TPTracker.m
Expand Up @@ -85,7 +85,8 @@ - (id)init
self.trackerWindow = [TPTrackerWindow new];
self.trackerLight = [TPTrackerLight new];
NSTimeInterval cameraRecordingInterval = 86400.0 / 30.0 / 60.0; // Default: one minute per day at 30 FPS (1 shot every 48s)
NSTimeInterval cameraPreviewInterval = 1 / 10.0;
//NSTimeInterval cameraPreviewInterval = 1 / 10.0;
NSTimeInterval cameraPreviewInterval = 1 / 2.0;
//cameraRecordingInterval = 10; // Testing: every 10s.
self.trackerCamera = [[TPTrackerCamera alloc] initWithRecordingInterval:cameraRecordingInterval andPreviewInterval:cameraPreviewInterval];
self.trackerGitHub = [TPTrackerGitHub new];
Expand Down Expand Up @@ -134,7 +135,8 @@ - (void)logEvent:(NSArray *)event {
[self.eventsToLog addObject:JSONRepresentation(event)];
[[NSUserDefaults standardUserDefaults] setObject:@(++self.totalEvents) forKey:@"totalEvents"];
[[NSNotificationCenter defaultCenter] postNotificationName:TPActivityAny object:self];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"net.nickwinter.Telepath.TrackerEvent" object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:event, @"event", nil]];
// Distributed notifications got really slow in 10.9?
//[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"net.nickwinter.Telepath.TrackerEvent" object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:event, @"event", nil]];
}

- (void)onActivityKeyboard:(NSNotification *)note {
Expand Down Expand Up @@ -165,8 +167,9 @@ - (void)onActivityScreen:(NSNotification *)note {
#pragma mark - File writing

- (void)ensureOutputDirExists {
if([[NSFileManager defaultManager] fileExistsAtPath:@"/volumes/Like Donkey Kong"])
self.outputDir = @"/volumes/Like Donkey Kong/Hog/Storage/Telepath/winter/Telepath"; // External drive has more space.
NSString *path = [@"~/Desktop/Hog/Storage/Telepath/winter/Telepath" stringByExpandingTildeInPath];
if([[NSFileManager defaultManager] fileExistsAtPath:path])
self.outputDir = path;
else
self.outputDir = [@"~/Library/Application Support/Telepath/" stringByExpandingTildeInPath]; // If you're not me.
[[NSFileManager defaultManager] createDirectoryAtPath:self.outputDir withIntermediateDirectories:YES attributes:nil error:nil];
Expand Down
5 changes: 5 additions & 0 deletions Telepath/TPTrackerKeyboard.m
Expand Up @@ -9,6 +9,7 @@
#import "TPTrackerKeyboard.h"
#import "TPUtilities.h"
#import "TPTracker.h"
#include <ApplicationServices/ApplicationServices.h>

@interface TPTrackerKeyboard ()
@property NSMutableString *recentCharacters;
Expand All @@ -32,6 +33,10 @@ - (id)init
self.recentCharacters = [NSMutableString new];
[self loadModifierKeys];
[self loadReallyBadStuff];

NSDictionary *options = @{(__bridge id)kAXTrustedCheckOptionPrompt: @YES};
BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options);
NSLog(@"Accessibility is enabled? %d", accessibilityEnabled);

uint logMask = (NSKeyDownMask|NSKeyUpMask|NSFlagsChangedMask);
self.eventMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:logMask handler:^(NSEvent *e) { [self onInputEvent:e]; }];
Expand Down

0 comments on commit 0a0b3db

Please sign in to comment.