Add object detection, tracking, mobile notifications, and search to any security camera.
less slow live loading
roryclear10e777969942
diff --git a/clearcam/DeviceStreamViewController.m b/clearcam/DeviceStreamViewController.mindex 8585465..5f2c86d 100644--- a/clearcam/DeviceStreamViewController.m+++ b/clearcam/DeviceStreamViewController.m@@ -4,6 +4,7 @@#import <AVFoundation/AVFoundation.h>#import <Security/Security.h>#import <CommonCrypto/CommonCryptor.h>+#import <CommonCrypto/CommonDigest.h>@interface DeviceStreamViewController ()@property (nonatomic, strong) AVQueuePlayer *player;@@ -86,6 +87,7 @@];NSURL *url = components.URL;+ NSLog(@"rory new url = %@",url);NSURLSessionDataTask *linkTask = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {if (error) {@@ -141,11 +143,6 @@return;}- if ([self.lastSegmentData isEqualToData:data]) {- NSLog(@"π Same segment, skipping");- return;- }-// Only set lastSegmentData after successful decryptionNSLog(@"π₯ New segment downloaded, attempting decryption");@@ -155,14 +152,12 @@return;}- // Success: now save the segment as "lastSegmentData"- NSUInteger hash = data.hash;- NSData *hashData = [NSData dataWithBytes:&hash length:sizeof(hash)];- if ([self.seenSegmentHashes containsObject:hashData]) {- NSLog(@"π Duplicate decrypted segment, skipping queue");+ NSData *segmentHash = [self sha256DigestForData:data];+ if ([self.seenSegmentHashes containsObject:segmentHash]) {+ NSLog(@"π Duplicate segment (SHA-256), skipping queue");return;}- [self.seenSegmentHashes addObject:hashData];+ [self.seenSegmentHashes addObject:segmentHash];self.successfullyQueuedSegmentCount += 1;self.lastSegmentData = data;self.decryptionFailedOnce = NO; // Only reset on success@@ -226,6 +221,11 @@[task resume];}+- (NSData *)sha256DigestForData:(NSData *)data {+ uint8_t hash[CC_SHA256_DIGEST_LENGTH];+ CC_SHA256(data.bytes, (CC_LONG)data.length, hash);+ return [NSData dataWithBytes:hash length:CC_SHA256_DIGEST_LENGTH];+}- (void)decryptAndQueueSegment:(NSData *)encryptedData withCompletion:(void (^)(NSData *))completion {if (self.decryptionKey) {diff --git a/clearcam/ViewController.m b/clearcam/ViewController.mindex 6f25dbf..f8337b9 100644--- a/clearcam/ViewController.m+++ b/clearcam/ViewController.m@@ -873,11 +873,7 @@ NSMutableDictionary *classColorMap;}if (self.assetWriter.outputURL) {- if ([fileManager copyItemAtURL:self.assetWriter.outputURL toURL:[NSURL fileURLWithPath:tempFilePath] error:&fileError]) {- NSLog(@"β Copied video to temp path for upload: %@", tempFilePath);- } else {- NSLog(@"β Failed to copy video to temp path: %@", fileError);- }+ [fileManager copyItemAtURL:self.assetWriter.outputURL toURL:[NSURL fileURLWithPath:tempFilePath] error:&fileError];// Trigger upload if file was successfully copiedif ([fileManager fileExistsAtPath:tempFilePath]) {@@ -997,7 +993,6 @@ NSMutableDictionary *classColorMap;fromData:fileDatacompletionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;- NSLog(@"size of segment.mp4.aes: %.2f KB", (float)fileData.length / 1024.0);if (error) {NSLog(@"β Upload failed: %@", error);} else if (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300) {@@ -1202,7 +1197,7 @@ NSMutableDictionary *classColorMap;[FileServer sharedInstance].segment_length = 60;}if([[NSUserDefaults standardUserDefaults] boolForKey:@"live_stream_internet_enabled"]) {- if ([[NSDate date] timeIntervalSince1970] - self.last_check_time > 10.0) {+ if ([[NSDate date] timeIntervalSince1970] - self.last_check_time > 5.0) {self.last_check_time = [[NSDate date] timeIntervalSince1970];NSDate *expiry = [[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"];BOOL isSubscribed = [[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"];@@ -1453,7 +1448,6 @@ NSMutableDictionary *classColorMap;];NSURL *url = components.URL;- NSLog(@"url = %@",url);NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:urlcompletionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {