Skip to content

Commit

Permalink
iPhone: reduce controller present and dismiss latency
Browse files Browse the repository at this point in the history
    - add simple shutter to mask video start
  • Loading branch information
spadix0 committed Aug 22, 2011
1 parent 98fe10d commit 93560e8
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 8 deletions.
4 changes: 4 additions & 0 deletions iphone/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
version 1.2.2:
* reduce controller present and dismiss latency
- add simple shutter to mask video start

version 1.2.1:
* fix overlay resizing bug

Expand Down
41 changes: 38 additions & 3 deletions iphone/ZBarReaderViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ - (void) cleanup
readerView = nil;
[controls release];
controls = nil;
[shutter release];
shutter = nil;
}

- (void) dealloc
Expand Down Expand Up @@ -355,6 +357,15 @@ - (void) viewDidLoad
readerView.enableCache = enableCache;
[view addSubview: readerView];

shutter = [[UIView alloc]
initWithFrame: r];
shutter.backgroundColor = [UIColor blackColor];
shutter.opaque = NO;
shutter.autoresizingMask =
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
[view addSubview: shutter];

if(cameraOverlayView) {
assert(!cameraOverlayView.superview);
[cameraOverlayView removeFromSuperview];
Expand Down Expand Up @@ -386,7 +397,11 @@ - (void) viewWillAppear: (BOOL) animated

[readerView willRotateToInterfaceOrientation: self.interfaceOrientation
duration: 0];
[readerView start];
[readerView performSelector: @selector(start)
withObject: nil
afterDelay: .001];
shutter.alpha = 1;
shutter.hidden = NO;

UIApplication *app = [UIApplication sharedApplication];
BOOL willHideStatusBar =
Expand All @@ -410,7 +425,7 @@ - (void) dismissModalViewControllerAnimated: (BOOL) animated

- (void) viewWillDisappear: (BOOL) animated
{
[readerView stop];
readerView.captureReader.enableReader = NO;

if(didHideStatusBar) {
[[UIApplication sharedApplication]
Expand All @@ -422,6 +437,13 @@ - (void) viewWillDisappear: (BOOL) animated
[super viewWillDisappear: animated];
}

- (void) viewDidDisappear: (BOOL) animated
{
// stopRunning can take a really long time (>1s observed),
// so defer until the view transitions are complete
[readerView stop];
}

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orient
{
return((supportedOrientationsMask >> orient) & 1);
Expand Down Expand Up @@ -620,7 +642,7 @@ - (void) removeHelp: (NSString*) tag

// ZBarReaderViewDelegate

- (void) readerView: (ZBarReaderView*) view
- (void) readerView: (ZBarReaderView*) readerView
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) image
{
Expand All @@ -633,6 +655,19 @@ - (void) readerView: (ZBarReaderView*) view
nil]];
}

- (void) readerViewDidStart: (ZBarReaderView*) readerView
{
if(!shutter.hidden)
[UIView animateWithDuration: .25
animations: ^{
shutter.alpha = 0;
}
completion: ^(BOOL finished) {
shutter.hidden = YES;
}];
}


// "deprecated" properties

#define DEPRECATED_PROPERTY(getter, setter, type, val, ignore) \
Expand Down
20 changes: 17 additions & 3 deletions iphone/ZBarReaderViewImpl_Capture.m
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ - (void) onVideoStart: (NSNotification*) note
}
else
zlog(@"failed to lock device: %@", error);

if([readerDelegate respondsToSelector: @selector(readerViewDidStart:)])
[readerDelegate readerViewDidStart: self];
}

- (void) onVideoStop: (NSNotification*) note
Expand All @@ -277,6 +280,11 @@ - (void) onVideoStop: (NSNotification*) note

[device unlockForConfiguration];
running = NO;

if([readerDelegate respondsToSelector:
@selector(readerView:didStopWithError:)])
[readerDelegate readerView: self
didStopWithError: nil];
}

- (void) onVideoError: (NSNotification*) note
Expand All @@ -289,9 +297,15 @@ - (void) onVideoError: (NSNotification*) note
}
NSError *err =
[note.userInfo objectForKey: AVCaptureSessionErrorKey];
NSLog(@"ZBarReaderView: ERROR during capture: %@: %@",
[err localizedDescription],
[err localizedFailureReason]);

if([readerDelegate respondsToSelector:
@selector(readerView:didStopWithError:)])
[readerDelegate readerView: self
didStopWithError: err];
else
NSLog(@"ZBarReaderView: ERROR during capture: %@: %@",
[err localizedDescription],
[err localizedFailureReason]);
}

// NSKeyValueObserving
Expand Down
24 changes: 24 additions & 0 deletions iphone/ZBarReaderViewImpl_Simulator.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ - (void) start
return;
[super start];
running = YES;

[self performSelector: @selector(onVideoStart)
withObject: nil
afterDelay: 0.5];
}

- (void) stop
Expand All @@ -133,6 +137,10 @@ - (void) stop
return;
[super stop];
running = NO;

[self performSelector: @selector(onVideoStop)
withObject: nil
afterDelay: 0.5];
}

- (void) scanImage: (UIImage*) image
Expand Down Expand Up @@ -192,4 +200,20 @@ - (void) didReadSymbols: (ZBarSymbolSet*) syms
scanImage = nil;
}

- (void) onVideoStart
{
if(running &&
[readerDelegate respondsToSelector: @selector(readerViewDidStart:)])
[readerDelegate readerViewDidStart: self];
}

- (void) onVideoStop
{
if(!running &&
[readerDelegate respondsToSelector:
@selector(readerView:didStopWithError:)])
[readerDelegate readerView: self
didStopWithError: nil];
}

@end
5 changes: 5 additions & 0 deletions iphone/include/ZBarSDK/ZBarReaderView.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
didReadSymbols: (ZBarSymbolSet*) symbols
fromImage: (UIImage*) image;

@optional
- (void) readerViewDidStart: (ZBarReaderView*) readerView;
- (void) readerView: (ZBarReaderView*) readerView
didStopWithError: (NSError*) error;

@end

// read barcodes from the displayed video preview. the view maintains
Expand Down
2 changes: 1 addition & 1 deletion iphone/include/ZBarSDK/ZBarReaderViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
BOOL showsZBarControls, tracksSymbols, enableCache;

ZBarHelpController *helpController;
UIView *controls;
UIView *controls, *shutter;
BOOL didHideStatusBar, rotating;
ZBarCameraSimulator *cameraSim;
}
Expand Down
2 changes: 1 addition & 1 deletion iphone/res/ZBarSDK-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleName</key>
<string>ZBarSDK</string>
<key>CFBundleVersion</key>
<string>1.2.1</string>
<string>1.2.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>NSHumanReadableCopyright</key>
Expand Down

0 comments on commit 93560e8

Please sign in to comment.