From 38b116bfd234fe9e21e516ffdc8c9c06b9df72db Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Fri, 19 Jul 2013 06:56:15 +0000
Subject: [PATCH] SP-751 BIS-478 Faster Barcode View Loading - 2

SVN: 29564
---
 .../objc/openBIS/ZXingObjC/client/ZXCapture.m |  4 +--
 .../openBIS/CISDOBBarcodeViewController.m     | 28 +++++++++++++++++--
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/openbis-ipad/source/objc/openBIS/ZXingObjC/client/ZXCapture.m b/openbis-ipad/source/objc/openBIS/ZXingObjC/client/ZXCapture.m
index 1f4e6d93341..67502b1cdf9 100644
--- a/openbis-ipad/source/objc/openBIS/ZXingObjC/client/ZXCapture.m
+++ b/openbis-ipad/source/objc/openBIS/ZXingObjC/client/ZXCapture.m
@@ -161,7 +161,6 @@ static bool isIPad();
       if (camera == self.front) {
         position = AVCaptureDevicePositionFront;
       }
-
       for(unsigned int i=0; i < [devices count]; ++i) {
         ZXCaptureDevice *dev = [devices objectAtIndex:i];
         if (dev.position == position) {
@@ -248,6 +247,7 @@ static bool isIPad();
         preset = AVCaptureSessionPresetMedium;
       }
       session.sessionPreset = preset;
+      
     });
     [session addInput:input ZXQT(error:nil)];
   }
@@ -635,7 +635,7 @@ ZXAV(didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer)
 }
 
 - (int)front {
-  return 0;
+  return 1;
 }
 
 - (int)back {
diff --git a/openbis-ipad/source/objc/openBIS/openBIS/CISDOBBarcodeViewController.m b/openbis-ipad/source/objc/openBIS/openBIS/CISDOBBarcodeViewController.m
index 95daadd86ea..e261da96932 100644
--- a/openbis-ipad/source/objc/openBIS/openBIS/CISDOBBarcodeViewController.m
+++ b/openbis-ipad/source/objc/openBIS/openBIS/CISDOBBarcodeViewController.m
@@ -21,9 +21,15 @@
 @interface CISDOBBarcodeViewController ()
 
 @property (nonatomic, retain) ZXCapture* capture;
+@property (nonatomic, retain) AVCaptureSession* cameraSession;
+@property (nonatomic, retain) AVCaptureVideoPreviewLayer* previewLayer;
+@property (nonatomic, retain) AVCaptureDevice *videoDevice;
+@property (nonatomic, retain) AVCaptureDeviceInput *videoIn;
+
 @property (nonatomic, retain) IBOutlet UILabel* decodedLabel;
 @property (nonatomic, retain) IBOutlet UIView* cameraView;
 
+
 - (NSString*)displayForResult:(ZXResult*)result;
 
 @end
@@ -53,6 +59,19 @@
 #pragma mark - View Controller Methods
 
 - (void)viewWillAppear:(BOOL)animated {
+    /*
+    self.videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
+    NSError *error;
+    self.videoIn = [AVCaptureDeviceInput deviceInputWithDevice:self.videoDevice error:&error];
+    self.cameraSession = [[AVCaptureSession alloc] init];
+    [self.cameraSession addInput:self.videoIn];
+    self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.cameraSession];
+    self.previewLayer.frame = CGRectMake(0.f, 0.f, 360.f, 360.f);
+    [self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
+    
+    [self.cameraView.layer addSublayer: self.previewLayer];
+    [self.cameraSession startRunning];
+    */
     [NSThread detachNewThreadSelector:@selector(loadBarcodeReader) toTarget:self withObject:nil];
     [super viewWillAppear:animated];
 }
@@ -60,12 +79,17 @@
 - (void)loadBarcodeReader {
     self.capture = [[ZXCapture alloc] init];
     self.capture.delegate = self;
-    self.capture.rotation = 90.0f;
+    // self.capture.rotation = 90.0f;
     
     // Use the back camera
-    self.capture.camera = self.capture.back;
+    // self.capture.camera = self.capture.back;
     self.capture.layer.frame = CGRectMake(0.f, 0.f, 360.f, 360.f);
+    
     [self.cameraView.layer addSublayer: self.capture.layer];
+    
+    
+    //[self.cameraSession stopRunning];
+    //[self.previewLayer removeFromSuperlayer];
 }
 
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
-- 
GitLab