Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Navaron Bracke
2023-10-16 13:24:22 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
bb1a328cc325ecf2d43dbcf1c2fa088475dc0685
bb1a328c
1 parent
690a331f
port scan timeout to iOS
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
ios/Classes/MobileScanner.swift
ios/Classes/SwiftMobileScannerPlugin.swift
ios/Classes/MobileScanner.swift
View file @
bb1a328
...
...
@@ -54,6 +54,12 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
private
let
backgroundQueue
=
DispatchQueue
(
label
:
"camera-handling"
)
var
standardZoomFactor
:
CGFloat
=
1
private
var
nextScanTime
=
0.0
private
var
imagesCurrentlyBeingProcessed
=
0
public
var
timeoutSeconds
:
Double
=
0
init
(
registry
:
FlutterTextureRegistry
?,
mobileScannerCallback
:
@escaping
MobileScannerCallback
,
torchModeChangeCallback
:
@escaping
TorchModeChangeCallback
,
zoomScaleChangeCallback
:
@escaping
ZoomScaleChangeCallback
)
{
self
.
registry
=
registry
...
...
@@ -89,8 +95,15 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
}
latestBuffer
=
imageBuffer
registry
?
.
textureFrameAvailable
(
textureId
)
if
((
detectionSpeed
==
DetectionSpeed
.
normal
||
detectionSpeed
==
DetectionSpeed
.
noDuplicates
)
&&
i
>
10
||
detectionSpeed
==
DetectionSpeed
.
unrestricted
)
{
i
=
0
let
currentTime
=
Date
()
.
timeIntervalSince1970
let
eligibleForScan
=
currentTime
>
nextScanTime
&&
imagesCurrentlyBeingProcessed
==
0
if
((
detectionSpeed
==
DetectionSpeed
.
normal
||
detectionSpeed
==
DetectionSpeed
.
noDuplicates
)
&&
eligibleForScan
||
detectionSpeed
==
DetectionSpeed
.
unrestricted
)
{
nextScanTime
=
currentTime
+
timeoutSeconds
imagesCurrentlyBeingProcessed
+=
1
let
ciImage
=
latestBuffer
.
image
let
image
=
VisionImage
(
image
:
ciImage
)
...
...
@@ -101,6 +114,8 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
)
scanner
.
process
(
image
)
{
[
self
]
barcodes
,
error
in
imagesCurrentlyBeingProcessed
-=
1
if
(
detectionSpeed
==
DetectionSpeed
.
noDuplicates
)
{
let
newScannedBarcodes
=
barcodes
?
.
map
{
barcode
in
return
barcode
.
rawValue
...
...
@@ -114,8 +129,6 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
mobileScannerCallback
(
barcodes
,
error
,
ciImage
)
}
}
else
{
i
+=
1
}
}
...
...
@@ -301,7 +314,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
do
{
try
device
.
lockForConfiguration
()
var
maxZoomFactor
=
device
.
activeFormat
.
videoMaxZoomFactor
let
maxZoomFactor
=
device
.
activeFormat
.
videoMaxZoomFactor
var
actualScale
=
(
scale
*
4
)
+
1
...
...
@@ -348,8 +361,6 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
scanner
.
process
(
image
,
completion
:
callback
)
}
var
i
=
0
var
barcodesString
:
Array
<
String
?
>
?
...
...
ios/Classes/SwiftMobileScannerPlugin.swift
View file @
bb1a328
...
...
@@ -12,8 +12,9 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
/// The handler sends all information via an event channel back to Flutter
private
let
barcodeHandler
:
BarcodeHandler
/// The points for the scan window.
static
var
scanWindow
:
[
CGFloat
]?
private
static
func
isBarcodeInScanWindow
(
barcode
:
Barcode
,
imageSize
:
CGSize
)
->
Bool
{
let
scanwindow
=
SwiftMobileScannerPlugin
.
scanWindow
!
let
barcodeminX
=
barcode
.
cornerPoints
!
[
0
]
.
cgPointValue
.
x
...
...
@@ -103,7 +104,9 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
let
formats
:
Array
<
Int
>
=
(
call
.
arguments
as!
Dictionary
<
String
,
Any
?
>
)[
"formats"
]
as?
Array
??
[]
let
returnImage
:
Bool
=
(
call
.
arguments
as!
Dictionary
<
String
,
Any
?
>
)[
"returnImage"
]
as?
Bool
??
false
let
speed
:
Int
=
(
call
.
arguments
as!
Dictionary
<
String
,
Any
?
>
)[
"speed"
]
as?
Int
??
0
let
timeoutMs
:
Int
=
(
call
.
arguments
as!
Dictionary
<
String
,
Any
?
>
)[
"timeout"
]
as?
Int
??
0
self
.
mobileScanner
.
timeoutSeconds
=
Double
(
timeoutMs
/
1000
)
let
formatList
=
formats
.
map
{
format
in
return
BarcodeFormat
(
rawValue
:
format
)}
var
barcodeOptions
:
BarcodeScannerOptions
?
=
nil
...
...
@@ -168,7 +171,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
/// Toggles the zoomScale
private
func
setScale
(
_
call
:
FlutterMethodCall
,
_
result
:
@escaping
FlutterResult
)
{
var
scale
=
call
.
arguments
as?
CGFloat
let
scale
=
call
.
arguments
as?
CGFloat
if
(
scale
==
nil
)
{
result
(
FlutterError
(
code
:
"MobileScanner"
,
message
:
"You must provide a scale when calling setScale!"
,
...
...
Please
register
or
login
to post a comment