@@ -35,7 +35,6 @@ import AcuantImagePreparation
3535 private var devicePreviewResolutionLongerSide = CaptureConstants . CAMERA_PREVIEW_LONGER_SIDE_STANDARD
3636 weak private var frameDelegate : FrameAnalysisDelegate ? = nil
3737
38-
3938 public class func getDocumentCaptureSession( delegate: DocumentCaptureDelegate ? , frameDelegate: FrameAnalysisDelegate , autoCapture: Bool , captureDevice: AVCaptureDevice ? ) -> DocumentCaptureSession {
4039 return DocumentCaptureSession ( ) . getDocumentCaptureSession ( delegate: delegate!, frameDelegate: frameDelegate, autoCapture: autoCapture, captureDevice: captureDevice)
4140 }
@@ -58,52 +57,50 @@ import AcuantImagePreparation
5857 }
5958
6059 public func start( ) {
61- DispatchQueue . main. async {
62- self . automaticallyConfiguresApplicationAudioSession = false
63- self . usesApplicationAudioSession = false
64- if ( self . captureDevice? . isFocusModeSupported ( . continuousAutoFocus) ) ! {
65- try ! self . captureDevice? . lockForConfiguration ( )
66- self . captureDevice? . focusMode = . continuousAutoFocus
67- self . captureDevice? . unlockForConfiguration ( )
60+ self . automaticallyConfiguresApplicationAudioSession = false
61+ self . usesApplicationAudioSession = false
62+ if ( self . captureDevice? . isFocusModeSupported ( . continuousAutoFocus) ) ! {
63+ try ? self . captureDevice? . lockForConfiguration ( )
64+ self . captureDevice? . focusMode = . continuousAutoFocus
65+ self . captureDevice? . unlockForConfiguration ( )
66+ }
67+ do {
68+ self . input = try AVCaptureDeviceInput ( device: self . captureDevice!)
69+ if ( self . canAddInput ( self . input!) ) {
70+ self . addInput ( self . input!)
6871 }
69- do {
70- self . input = try AVCaptureDeviceInput ( device: self . captureDevice!)
71- if ( self . canAddInput ( self . input!) ) {
72- self . addInput ( self . input!)
73- }
74- } catch _ as NSError {
75- return
76- }
77-
78- self . sessionPreset = AVCaptureSession . Preset. photo
72+ } catch _ as NSError {
73+ return
74+ }
75+
76+ self . sessionPreset = AVCaptureSession . Preset. photo
7977
80- if let formatDescription = self . captureDevice? . activeFormat. formatDescription {
81- let dimensions = CMVideoFormatDescriptionGetDimensions ( formatDescription)
82- self . devicePreviewResolutionLongerSide = max ( Int ( dimensions. width) , Int ( dimensions. height) )
83- }
84-
85- self . videoOutput = AVCaptureVideoDataOutput ( )
86- self . videoOutput? . alwaysDiscardsLateVideoFrames = true
87- let frameQueue = DispatchQueue ( label: " com.acuant.frame.queue " , qos: . userInteractive, attributes: . concurrent)
88- self . videoOutput? . setSampleBufferDelegate ( self , queue: frameQueue)
89- if ( self . canAddOutput ( self . videoOutput!) ) {
90- self . addOutput ( self . videoOutput!)
91- }
92- if ( self . canAddOutput ( self . stillImageOutput) ) {
93- self . stillImageOutput. isLivePhotoCaptureEnabled = false
94- self . addOutput ( self . stillImageOutput)
95- }
78+ if let formatDescription = self . captureDevice? . activeFormat. formatDescription {
79+ let dimensions = CMVideoFormatDescriptionGetDimensions ( formatDescription)
80+ self . devicePreviewResolutionLongerSide = max ( Int ( dimensions. width) , Int ( dimensions. height) )
81+ }
82+
83+ self . videoOutput = AVCaptureVideoDataOutput ( )
84+ self . videoOutput? . alwaysDiscardsLateVideoFrames = true
85+ let frameQueue = DispatchQueue ( label: " com.acuant.frame.queue " , qos: . userInteractive, attributes: . concurrent)
86+ self . videoOutput? . setSampleBufferDelegate ( self , queue: frameQueue)
87+ if ( self . canAddOutput ( self . videoOutput!) ) {
88+ self . addOutput ( self . videoOutput!)
89+ }
90+ if ( self . canAddOutput ( self . stillImageOutput) ) {
91+ self . stillImageOutput. isLivePhotoCaptureEnabled = false
92+ self . addOutput ( self . stillImageOutput)
93+ }
9694
97- /* Check for metadata */
98- self . captureMetadataOutput = AVCaptureMetadataOutput ( )
99- let metadataQueue = DispatchQueue ( label: " com.acuant.metadata.queue " , qos: . userInteractive, attributes: . concurrent)
100- self . captureMetadataOutput? . setMetadataObjectsDelegate ( self , queue: metadataQueue)
101- if ( self . canAddOutput ( self . captureMetadataOutput!) ) {
102- self . addOutput ( self . captureMetadataOutput!)
103- self . captureMetadataOutput? . metadataObjectTypes = [ . pdf417]
104- }
105- self . startRunning ( )
106- }
95+ /* Check for metadata */
96+ self . captureMetadataOutput = AVCaptureMetadataOutput ( )
97+ let metadataQueue = DispatchQueue ( label: " com.acuant.metadata.queue " , qos: . userInteractive, attributes: . concurrent)
98+ self . captureMetadataOutput? . setMetadataObjectsDelegate ( self , queue: metadataQueue)
99+ if ( self . canAddOutput ( self . captureMetadataOutput!) ) {
100+ self . addOutput ( self . captureMetadataOutput!)
101+ self . captureMetadataOutput? . metadataObjectTypes = [ . pdf417]
102+ }
103+ self . startRunning ( )
107104 }
108105
109106 // MARK: Sample buffer to UIImage conversion
0 commit comments