Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

start res settings

roryclear45c7abe4e04a
diff --git a/clearcam/SettingsViewController.m b/clearcam/SettingsViewController.m
index aa1bdbc..e6b665b 100644
--- a/clearcam/SettingsViewController.m
+++ b/clearcam/SettingsViewController.m
@@ -1,4 +1,5 @@
#import "SettingsViewController.h"
+#import "SettingsManager.h" // Import SettingsManager
@interface SettingsViewController () <UITableViewDelegate, UITableViewDataSource>
@@ -81,7 +82,25 @@
UIAlertAction *action = [UIAlertAction actionWithTitle:resolution
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
+ // Update the selected resolution
self.selectedResolution = resolution;
+
+ // Log the selected resolution
+ NSLog(@"Selected resolution: %@", self.selectedResolution);
+
+ // Update SettingsManager with the new resolution
+ SettingsManager *settingsManager = [SettingsManager sharedManager];
+ if ([self.selectedResolution isEqualToString:@"720p"]) {
+ [settingsManager updateResolutionWithWidth:@"1280" height:@"720" textSize:@"2" preset:@"AVCaptureSessionPreset1280x720"];
+ } else if ([self.selectedResolution isEqualToString:@"1080p"]) {
+ [settingsManager updateResolutionWithWidth:@"1920" height:@"1080" textSize:@"3" preset:@"AVCaptureSessionPreset1920x1080"];
+ }
+
+ // Log the updated resolution settings from SettingsManager
+ NSLog(@"Updated resolution settings: %@x%@, text size: %@, preset: %@",
+ settingsManager.width, settingsManager.height, settingsManager.text_size, settingsManager.preset);
+
+ // Reload the table view to update the UI
[self.tableView reloadData];
}];
[alert addAction:action];
diff --git a/clearcam/ViewController.m b/clearcam/ViewController.m
index b624c59..3f92007 100644
--- a/clearcam/ViewController.m
+++ b/clearcam/ViewController.m
@@ -86,10 +86,41 @@ NSMutableDictionary *classColorMap;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[self handleDeviceOrientationChange];
SettingsManager *settings = [SettingsManager sharedManager];
- [self setupCameraWithWidth:settings.width height:settings.height]; //todo, use defaults!
+
+ // Add KVO observers for resolution properties
+ [settings addObserver:self forKeyPath:@"width" options:NSKeyValueObservingOptionNew context:nil];
+ [settings addObserver:self forKeyPath:@"height" options:NSKeyValueObservingOptionNew context:nil];
+ [settings addObserver:self forKeyPath:@"text_size" options:NSKeyValueObservingOptionNew context:nil];
+ [settings addObserver:self forKeyPath:@"preset" options:NSKeyValueObservingOptionNew context:nil];
+
+ [self setupCameraWithWidth:settings.width height:settings.height];
[self setupUI];
}
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
+ if ([keyPath isEqualToString:@"preset"]) {
+ NSLog(@"Resolution settings changed");
+ [self finishRecording];
+ SettingsManager *settings = [SettingsManager sharedManager];
+ self.captureSession = [[AVCaptureSession alloc] init];
+ NSString *presetString = [NSString stringWithFormat:@"AVCaptureSessionPreset%@x%@", settings.width, settings.height];
+
+ if ([self.captureSession canSetSessionPreset:presetString]) {
+ self.captureSession.sessionPreset = presetString;
+ } else {
+ NSLog(@"Unsupported preset: %@", presetString);
+ return;
+ }
+ AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
+ output.videoSettings = @{(NSString *)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)};
+ output.alwaysDiscardsLateVideoFrames = YES;
+ [output setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
+ [self.captureSession addOutput:output];
+ [self.captureSession startRunning];
+ [self startNewRecording];
+ }
+}
+
- (void)dealloc {
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}