@momo-kits/camerakit 0.161.2-beta.2 → 0.161.2-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -123,34 +123,40 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
|
|
|
123
123
|
// handled by startCamera() -> startSessionIfNeeded().
|
|
124
124
|
guard self.setupResult == .notStarted else { return }
|
|
125
125
|
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
// calls to beginConfiguration and commitConfiguration".
|
|
134
|
-
self.setupResult = self.configureSession(cameraType: cameraType,
|
|
135
|
-
supportedBarcodeType: supportedBarcodeType)
|
|
136
|
-
|
|
126
|
+
// PHASE 1 — minimal config so the preview renders ASAP. Only the video
|
|
127
|
+
// input + a lightweight (.high) preview preset go in this first
|
|
128
|
+
// transaction. The heavier work (.photo preset + photo / barcode / OCR
|
|
129
|
+
// outputs) is deferred to phase 2 below, AFTER the session is already
|
|
130
|
+
// running and the preview layer is attached. This restores the
|
|
131
|
+
// "camera shows up instantly" feel without weakening the crash fix.
|
|
132
|
+
self.setupResult = self.configureBaseSession(cameraType: cameraType)
|
|
137
133
|
guard self.setupResult == .success else { return }
|
|
138
134
|
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
self.addObservers()
|
|
142
|
-
self.update(torchMode: self.torchMode)
|
|
143
|
-
|
|
144
|
-
// Only the preview LAYER is touched on the main queue. Connecting an
|
|
135
|
+
// Attach the preview LAYER on the main queue BEFORE startRunning so the
|
|
136
|
+
// first frames render the moment the session starts. Connecting an
|
|
145
137
|
// AVCaptureVideoPreviewLayer to a session from the main thread is
|
|
146
|
-
// sanctioned by AVFoundation (see Apple's AVCam)
|
|
147
|
-
// session configuration transaction,
|
|
138
|
+
// sanctioned by AVFoundation (see Apple's AVCam), does NOT open a
|
|
139
|
+
// session configuration transaction, and cannot race startRunning().
|
|
148
140
|
DispatchQueue.main.async { [weak self] in
|
|
149
141
|
guard let self else { return }
|
|
150
142
|
self.cameraPreview.session = self.session
|
|
151
143
|
self.cameraPreview.previewLayer.videoGravity = .resizeAspectFill
|
|
152
144
|
self.setVideoOrientationToInterfaceOrientation()
|
|
153
145
|
}
|
|
146
|
+
|
|
147
|
+
// Start running with just the preview-friendly config → fast first frame.
|
|
148
|
+
self.startSessionIfNeeded()
|
|
149
|
+
|
|
150
|
+
// PHASE 2 — add the heavier outputs and upgrade to the .photo preset in a
|
|
151
|
+
// SECOND transaction on this same serial queue, now that preview is live.
|
|
152
|
+
// Adding outputs to an already-running session inside begin/commit is
|
|
153
|
+
// legal; because startRunning() is NEVER called while configurationDepth
|
|
154
|
+
// > 0 (see startSessionIfNeeded), the "startRunning may not be called
|
|
155
|
+
// between beginConfiguration and commitConfiguration" crash stays fixed.
|
|
156
|
+
self.configureAdditionalOutputs(supportedBarcodeType: supportedBarcodeType)
|
|
157
|
+
|
|
158
|
+
self.addObservers()
|
|
159
|
+
self.update(torchMode: self.torchMode)
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
DispatchQueue.global(qos: .utility).async { [weak self] in
|
|
@@ -160,10 +166,11 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
|
|
|
160
166
|
|
|
161
167
|
// MARK: - Private optimization methods
|
|
162
168
|
|
|
163
|
-
///
|
|
164
|
-
/// transaction. Must
|
|
165
|
-
///
|
|
166
|
-
|
|
169
|
+
/// Phase 1 of setup: video input + a lightweight (.high) preview preset, in ONE
|
|
170
|
+
/// transaction. Must run on `sessionQueue`. Kept deliberately minimal so
|
|
171
|
+
/// `startRunning()` — and therefore the first preview frame — is not delayed by
|
|
172
|
+
/// wiring up the photo / barcode / OCR outputs (that is `configureAdditionalOutputs`).
|
|
173
|
+
private func configureBaseSession(cameraType: CameraType) -> SetupResult {
|
|
167
174
|
assertOnSessionQueue()
|
|
168
175
|
guard let videoDevice = self.getBestDevice(for: cameraType),
|
|
169
176
|
let videoDeviceInput = try? AVCaptureDeviceInput(device: videoDevice) else {
|
|
@@ -173,7 +180,7 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
|
|
|
173
180
|
beginConfiguration()
|
|
174
181
|
defer { commitConfiguration() }
|
|
175
182
|
|
|
176
|
-
//
|
|
183
|
+
// Video input
|
|
177
184
|
guard session.canAddInput(videoDeviceInput) else {
|
|
178
185
|
return .sessionConfigurationFailed
|
|
179
186
|
}
|
|
@@ -181,15 +188,33 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
|
|
|
181
188
|
self.videoDeviceInput = videoDeviceInput
|
|
182
189
|
self.resetZoom(forDevice: videoDevice)
|
|
183
190
|
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
191
|
+
// Lightweight preset for the fastest possible first frame. Upgraded to
|
|
192
|
+
// `.photo` in configureAdditionalOutputs() once the preview is live.
|
|
193
|
+
if session.canSetSessionPreset(.high) {
|
|
194
|
+
session.sessionPreset = .high
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return .success
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/// Phase 2 of setup: the .photo preset + photo / barcode / OCR outputs, in ONE
|
|
201
|
+
/// transaction on `sessionQueue`. Runs AFTER the session is already running and
|
|
202
|
+
/// the preview is attached, so none of this work delays the first frame. Adding
|
|
203
|
+
/// outputs to a running session inside begin/commit is legal; the crash fix is
|
|
204
|
+
/// preserved because startRunning() is never called while a transaction is open.
|
|
205
|
+
private func configureAdditionalOutputs(supportedBarcodeType: [CodeFormat]) {
|
|
206
|
+
assertOnSessionQueue()
|
|
207
|
+
beginConfiguration()
|
|
208
|
+
defer { commitConfiguration() }
|
|
209
|
+
|
|
210
|
+
// Upgrade to the full still-capture preset now that preview is rendering.
|
|
211
|
+
// `.photo` is supported by every camera device; if it somehow is not, we
|
|
212
|
+
// keep the `.high` preset from phase 1 rather than crashing.
|
|
188
213
|
if session.canSetSessionPreset(.photo) {
|
|
189
214
|
session.sessionPreset = .photo
|
|
190
215
|
}
|
|
191
216
|
|
|
192
|
-
//
|
|
217
|
+
// Photo output
|
|
193
218
|
if #available(iOS 13.0, *) {
|
|
194
219
|
if let maxPhotoQualityPrioritization = maxPhotoQualityPrioritization {
|
|
195
220
|
photoOutput.maxPhotoQualityPrioritization = maxPhotoQualityPrioritization.avQualityPrioritization
|
|
@@ -204,7 +229,7 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
|
|
|
204
229
|
}
|
|
205
230
|
}
|
|
206
231
|
|
|
207
|
-
//
|
|
232
|
+
// Metadata output for barcode scanning
|
|
208
233
|
if self.session.canAddOutput(metadataOutput) {
|
|
209
234
|
self.session.addOutput(metadataOutput)
|
|
210
235
|
metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
|
|
@@ -217,12 +242,10 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
|
|
|
217
242
|
metadataOutput.metadataObjectTypes = filteredTypes
|
|
218
243
|
}
|
|
219
244
|
|
|
220
|
-
//
|
|
245
|
+
// Video data output for text / MRZ detection
|
|
221
246
|
if textRequest != nil && self.session.canAddOutput(self.videoDataOutput) {
|
|
222
247
|
self.session.addOutput(self.videoDataOutput)
|
|
223
248
|
}
|
|
224
|
-
|
|
225
|
-
return .success
|
|
226
249
|
}
|
|
227
250
|
|
|
228
251
|
// MARK: - Pause / Resume non-essential outputs
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
2
|
+
"name": "@momo-kits/camerakit",
|
|
3
|
+
"version": "0.161.2-beta.25",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/teslamotors/react-native-camera-kit.git"
|
|
7
|
+
},
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"registry": "https://registry.npmjs.org/"
|
|
10
|
+
},
|
|
11
|
+
"description": "A high performance, fully featured, rock solid camera library for React Native applications",
|
|
12
|
+
"nativePackage": true,
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "echo",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"lint": "yarn eslint -c .eslintrc.js"
|
|
17
|
+
},
|
|
18
|
+
"main": "./src/index.ts",
|
|
19
|
+
"dependencies": {},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"react": "19.0.0",
|
|
23
|
+
"react-native": "0.80.1"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "*",
|
|
27
|
+
"react-native": "*"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"codegenConfig": {
|
|
33
|
+
"name": "rncamerakit_specs",
|
|
34
|
+
"type": "all",
|
|
35
|
+
"jsSrcsDir": "src/specs",
|
|
36
|
+
"android": {
|
|
37
|
+
"javaPackageName": "com.rncamerakit"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"packageManager": "yarn@1.22.22"
|
|
41
|
+
}
|