@momo-kits/camerakit 0.162.2-test.9 → 0.162.3-fontscale.2
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.
|
@@ -72,6 +72,23 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
|
|
|
72
72
|
|
|
73
73
|
// MARK: - Lifecycle
|
|
74
74
|
|
|
75
|
+
override init() {
|
|
76
|
+
super.init()
|
|
77
|
+
#if DEBUG
|
|
78
|
+
assert(Thread.isMainThread, "RealCamera must be initialized on the main thread (it wires the preview CALayer).")
|
|
79
|
+
#endif
|
|
80
|
+
// Wire the preview to the (idle, never-started) session AND set its gravity
|
|
81
|
+
// ONCE here at init, on the main thread, before anything starts. Benefits:
|
|
82
|
+
// (a) the preview renders the instant the first frame arrives (~camera warm-up)
|
|
83
|
+
// instead of waiting for a late post-setup attach → less black.
|
|
84
|
+
// (b) assigning previewLayer.session opens an implicit AVFoundation config
|
|
85
|
+
// transaction; doing it now (session idle, no startRunning yet, never
|
|
86
|
+
// reassigned) makes it impossible to race startRunning() → the begin/commit
|
|
87
|
+
// crash class is closed by construction, on every device.
|
|
88
|
+
cameraPreview.session = session
|
|
89
|
+
cameraPreview.previewLayer.videoGravity = .resizeAspectFill
|
|
90
|
+
}
|
|
91
|
+
|
|
75
92
|
func cameraRemovedFromSuperview() {
|
|
76
93
|
sessionQueue.async { [weak self] in
|
|
77
94
|
guard let self, self.setupResult == .success else { return }
|
|
@@ -136,21 +153,22 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
|
|
|
136
153
|
|
|
137
154
|
guard self.setupResult == .success else { return }
|
|
138
155
|
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
// sanctioned by AVFoundation (see Apple's AVCam) and does NOT open a
|
|
147
|
-
// session configuration transaction, so it cannot race startRunning().
|
|
156
|
+
// Set the preview orientation on the main queue NOW — BEFORE the (~145ms)
|
|
157
|
+
// startRunning below — so the very first frame renders at the correct
|
|
158
|
+
// orientation instead of appearing once and then snapping ("giật 1 nhịp").
|
|
159
|
+
// The preview's `.session` and gravity are already wired at init; this is a
|
|
160
|
+
// pure connection-property write (no session config transaction → no race
|
|
161
|
+
// with startRunning). The connection exists because configureSession has
|
|
162
|
+
// committed the video input above.
|
|
148
163
|
DispatchQueue.main.async { [weak self] in
|
|
149
164
|
guard let self else { return }
|
|
150
|
-
self.cameraPreview.session = self.session
|
|
151
|
-
self.cameraPreview.previewLayer.videoGravity = .resizeAspectFill
|
|
152
165
|
self.setVideoOrientationToInterfaceOrientation()
|
|
153
166
|
}
|
|
167
|
+
|
|
168
|
+
// Order matches the previous behaviour: start, then observe, then torch.
|
|
169
|
+
self.startSessionIfNeeded()
|
|
170
|
+
self.addObservers()
|
|
171
|
+
self.update(torchMode: self.torchMode)
|
|
154
172
|
}
|
|
155
173
|
|
|
156
174
|
DispatchQueue.global(qos: .utility).async { [weak self] in
|