OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef IOS_CHROME_BROWSER_UI_QR_SCANNER_CAMERA_CONTROLLER_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_QR_SCANNER_CAMERA_CONTROLLER_H_ |
| 7 |
| 8 #import <AVFoundation/AVFoundation.h> |
| 9 #import <UIKit/UIKit.h> |
| 10 |
| 11 #include "base/ios/block_types.h" |
| 12 |
| 13 namespace qr_scanner { |
| 14 |
| 15 // Values to distinguish between different camera states to display the correct |
| 16 // view controller or system alert. |
| 17 // Note: no state encodes the state where the usage of the camera is prohibited |
| 18 // because the app is in the background. The reason is that iOS transparently |
| 19 // stops/starts the camera when the app enter/leaves the background. |
| 20 // See AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableInBackground for |
| 21 // more information. |
| 22 enum CameraState { |
| 23 // Camera is loaded and available; |
| 24 CAMERA_AVAILABLE = 0, |
| 25 // The application cannot use the camera because it is in use exclusively by |
| 26 // another application. |
| 27 CAMERA_IN_USE_BY_ANOTHER_APPLICATION, |
| 28 // The application cannot use the camera because video input is not supported |
| 29 // if there are multiple foreground apps running. |
| 30 MULTIPLE_FOREGROUND_APPS, |
| 31 // The application does not have the permission to use the camera. |
| 32 CAMERA_PERMISSION_DENIED, |
| 33 // The camera is unavailable. |
| 34 CAMERA_UNAVAILABLE, |
| 35 // The camera was not yet loaded. |
| 36 CAMERA_NOT_LOADED, |
| 37 }; |
| 38 |
| 39 } // namespace qr_scanner |
| 40 |
| 41 @protocol CameraControllerDelegate |
| 42 |
| 43 // Called on the main queue when the capture session is connected to the |
| 44 // preview. |
| 45 - (void)captureSessionIsConnected; |
| 46 // Called on the main queue when the camera state changes. |
| 47 - (void)cameraStateChanged:(qr_scanner::CameraState)state; |
| 48 // Called on the main queue when the torch state changes. |
| 49 - (void)torchStateChanged:(BOOL)torchIsOn; |
| 50 // Called on the main queue when the torch availability changes. |
| 51 - (void)torchAvailabilityChanged:(BOOL)torchIsAvailable; |
| 52 // Called when the scanner detects a valid code. The camera controller stops |
| 53 // recording when a result is scanned. A valid code is any non-empty string. If |
| 54 // |load| is YES, the result should be loaded immediately without requiring |
| 55 // additional user input. The value of |load| will only be YES for barcodes |
| 56 // which can only encode digits. |
| 57 - (void)receiveQRScannerResult:(NSString*)result loadImmediately:(BOOL)load; |
| 58 |
| 59 @end |
| 60 |
| 61 // The CameraController manages the AVCaptureSession, its inputs, outputs, and |
| 62 // notifications for the QRScannerViewController. |
| 63 @interface CameraController : NSObject |
| 64 |
| 65 // The current state of the torch. |
| 66 @property(nonatomic, readonly, assign, getter=isTorchActive) BOOL torchActive; |
| 67 |
| 68 - (instancetype)init NS_UNAVAILABLE; |
| 69 |
| 70 // Initializes the controller with the |delegate|. |
| 71 - (instancetype)initWithDelegate:(id<CameraControllerDelegate>)delegate |
| 72 NS_DESIGNATED_INITIALIZER; |
| 73 |
| 74 // Returns the app's authorization in regards to the camera. |
| 75 - (AVAuthorizationStatus)getAuthorizationStatus; |
| 76 |
| 77 // Asks the user to grant the authorization to access the camera. |
| 78 // Should only be called when the current authorization status is |
| 79 // AVAuthorizationStatusNotDetermined. |
| 80 - (void)requestAuthorizationAndLoadCaptureSession: |
| 81 (AVCaptureVideoPreviewLayer*)previewLayer; |
| 82 |
| 83 // Loads the camera and sets the value of |cameraState|. |
| 84 // Should only be called when the current authorization status is |
| 85 // AVAuthorizationStatusAuthorized. |
| 86 - (void)loadCaptureSession:(AVCaptureVideoPreviewLayer*)previewLayer; |
| 87 |
| 88 // Sets the rectangle in which codes are recognized to |viewportRect|. If the |
| 89 // metadata output object is not loaded, |viewportRect| will be set when the |
| 90 // output loads. |
| 91 - (void)setViewport:(CGRect)viewportRect; |
| 92 |
| 93 // Resets the video orientation to the current interface orientation. |
| 94 - (void)resetVideoOrientation:(AVCaptureVideoPreviewLayer*)previewLayer; |
| 95 |
| 96 // Starts the camera capture session. Does nothing if the camera is not |
| 97 // available. |
| 98 - (void)startRecording; |
| 99 |
| 100 // Stops the camera capture session. Does nothing if the camera is not |
| 101 // available. |
| 102 - (void)stopRecording; |
| 103 |
| 104 // Sets the camera's torch mode to |mode|. Does nothing if the camera is not |
| 105 // available or the torch mode is not supported. |
| 106 - (void)setTorchMode:(AVCaptureTorchMode)mode; |
| 107 |
| 108 @end |
| 109 |
| 110 #endif // IOS_CHROME_BROWSER_UI_QR_SCANNER_CAMERA_CONTROLLER_H_ |
OLD | NEW |