@@ -12,14 +12,14 @@ import Flutter
12
12
let avMetadataObjectTypes : [ String : AVMetadataObject . ObjectType ] =
13
13
[
14
14
" aztec " : . aztec,
15
- " code128 " : . code128,
15
+ " code128 " : . code128,
16
16
" code39 " : . code39,
17
17
" code39mod43 " : . code39Mod43,
18
18
" code93 " : . code93,
19
19
" dataMatrix " : . dataMatrix,
20
20
" ean13 " : . ean13,
21
21
" ean8 " : . ean8,
22
- " itf " : . itf14,
22
+ " itf " : . itf14,
23
23
" pdf417 " : . pdf417,
24
24
" qr " : . qr,
25
25
" upcE " : . upce,
@@ -94,7 +94,9 @@ class BarcodeReader: NSObject {
94
94
var torchActiveBeforeStop = false
95
95
var previewSize : CMVideoDimensions !
96
96
97
- init ( textureRegistry: FlutterTextureRegistry , arguments: StartArgs , codeCallback: @escaping ( [ String ] ) -> Void ) throws {
97
+ init ( textureRegistry: FlutterTextureRegistry ,
98
+ arguments: StartArgs ,
99
+ codeCallback: @escaping ( [ String ] ) -> Void ) throws {
98
100
self . textureRegistry = textureRegistry
99
101
self . codeCallback = codeCallback
100
102
self . captureSession = AVCaptureSession ( )
@@ -125,7 +127,7 @@ class BarcodeReader: NSObject {
125
127
captureSession. addOutput ( metadataOutput)
126
128
127
129
dataOutput. videoSettings = [ kCVPixelBufferPixelFormatTypeKey as String : kCVPixelFormatType_32BGRA]
128
- dataOutput. connection ( with: . video) ? . videoOrientation = . portrait // TODO: Get real interface orientation
130
+ dataOutput. connection ( with: . video) ? . videoOrientation = . portrait
129
131
dataOutput. alwaysDiscardsLateVideoFrames = true
130
132
dataOutput. setSampleBufferDelegate ( self , queue: DispatchQueue . global ( qos: . default) )
131
133
@@ -144,6 +146,7 @@ class BarcodeReader: NSObject {
144
146
throw ReaderError . cameraNotSuitable ( arguments. resolution, arguments. framerate)
145
147
}
146
148
149
+ // swiftlint:disable:next force_try
147
150
try ! captureDevice. lockForConfiguration ( )
148
151
captureDevice. activeFormat = optimalFormat
149
152
captureDevice. activeVideoMinFrameDuration = optimalFormat. videoSupportedFrameRateRanges. first!. minFrameDuration
@@ -160,7 +163,8 @@ class BarcodeReader: NSObject {
160
163
self . textureId = textureRegistry. register ( self )
161
164
}
162
165
163
- if ( torchActiveBeforeStop) {
166
+ if torchActiveBeforeStop {
167
+ // swiftlint:disable:next force_try
164
168
try ! captureDevice. lockForConfiguration ( )
165
169
captureDevice. torchMode = . on
166
170
captureDevice. unlockForConfiguration ( )
@@ -179,6 +183,7 @@ class BarcodeReader: NSObject {
179
183
}
180
184
181
185
func toggleTorch( ) -> Bool {
186
+ // swiftlint:disable:next force_try
182
187
try ! captureDevice. lockForConfiguration ( )
183
188
captureDevice. torchMode = captureDevice. isTorchActive ? . off : . on
184
189
captureDevice. unlockForConfiguration ( )
@@ -215,15 +220,19 @@ extension BarcodeReader: FlutterTexture {
215
220
216
221
extension BarcodeReader : AVCaptureVideoDataOutputSampleBufferDelegate {
217
222
// runs on dispatch queue
218
- func captureOutput( _ output: AVCaptureOutput , didOutput sampleBuffer: CMSampleBuffer , from connection: AVCaptureConnection ) {
223
+ func captureOutput( _ output: AVCaptureOutput ,
224
+ didOutput sampleBuffer: CMSampleBuffer ,
225
+ from connection: AVCaptureConnection ) {
219
226
pixelBuffer = CMSampleBufferGetImageBuffer ( sampleBuffer)
220
227
textureRegistry. textureFrameAvailable ( textureId)
221
228
}
222
229
}
223
230
224
231
extension BarcodeReader : AVCaptureMetadataOutputObjectsDelegate {
225
232
// runs on dispatch queue
226
- func metadataOutput( _ output: AVCaptureMetadataOutput , didOutput metadataObjects: [ AVMetadataObject ] , from connection: AVCaptureConnection ) {
233
+ func metadataOutput( _ output: AVCaptureMetadataOutput ,
234
+ didOutput metadataObjects: [ AVMetadataObject ] ,
235
+ from connection: AVCaptureConnection ) {
227
236
guard
228
237
let metadata = metadataObjects. first,
229
238
let readableCode = metadata as? AVMetadataMachineReadableCodeObject
@@ -246,4 +255,3 @@ extension FourCharCode {
246
255
] )
247
256
}
248
257
}
249
-
0 commit comments