Skip to content

Commit 325a062

Browse files
authored
chore: kickoff release
2 parents e24762b + c318f91 commit 325a062

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

Sources/FaceLiveness/AV/LivenessCaptureSession.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class LivenessCaptureSession {
2424
self.outputDelegate = outputDelegate
2525
}
2626

27-
func startSession(frame: CGRect) throws -> CALayer {
28-
try startSession()
27+
func configureCamera(frame: CGRect) throws -> CALayer {
28+
try configureCamera()
2929

3030
guard let captureSession = captureSession else {
3131
throw LivenessCaptureSessionError.captureSessionUnavailable
@@ -39,7 +39,7 @@ class LivenessCaptureSession {
3939
return previewLayer
4040
}
4141

42-
func startSession() throws {
42+
func configureCamera() throws {
4343
guard let camera = captureDevice.avCaptureDevice
4444
else { throw LivenessCaptureSessionError.cameraUnavailable }
4545

@@ -58,19 +58,21 @@ class LivenessCaptureSession {
5858
try setupOutput(videoOutput, for: captureSession)
5959
try captureDevice.configure()
6060

61-
configurationQueue.async {
62-
captureSession.startRunning()
63-
}
64-
6561
videoOutput.setSampleBufferDelegate(
6662
outputDelegate,
6763
queue: captureQueue
6864
)
6965
}
7066

71-
func stopRunning() {
67+
func startSession() {
7268
guard let session = captureSession else { return }
69+
configurationQueue.async {
70+
session.startRunning()
71+
}
72+
}
7373

74+
func stopRunning() {
75+
guard let session = captureSession else { return }
7476
defer {
7577
captureSession = nil
7678
}

Sources/FaceLiveness/Views/GetReadyPage/CameraPreviewViewModel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class CameraPreviewViewModel: NSObject, ObservableObject {
3333
)
3434

3535
do {
36-
try previewCaptureSession?.startSession()
36+
try previewCaptureSession?.configureCamera()
37+
previewCaptureSession?.startSession()
3738
} catch {
3839
Amplify.Logging.default.error("Error starting preview capture session with error: \(error)")
3940
}

Sources/FaceLiveness/Views/Liveness/FaceLivenessDetectionViewModel.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,17 @@ class FaceLivenessDetectionViewModel: ObservableObject {
122122
}
123123
}
124124

125+
func startSession() {
126+
captureSession.startSession()
127+
}
125128

126129
func stopRecording() {
127130
captureSession.stopRunning()
128131
}
129132

130-
func startCamera(withinFrame frame: CGRect) -> CALayer? {
133+
func configureCamera(withinFrame frame: CGRect) -> CALayer? {
131134
do {
132-
let avLayer = try captureSession.startSession(frame: frame)
135+
let avLayer = try captureSession.configureCamera(frame: frame)
133136
DispatchQueue.main.async {
134137
self.livenessState.checkIsFacePrepared()
135138
}

Sources/FaceLiveness/Views/Liveness/LivenessViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ final class _LivenessViewController: UIViewController {
4949
super.viewDidLoad()
5050
view.backgroundColor = .black
5151
layoutSubviews()
52-
}
53-
54-
override func viewDidAppear(_ animated: Bool) {
5552
setupAVLayer()
5653
}
5754

@@ -69,13 +66,14 @@ final class _LivenessViewController: UIViewController {
6966
}
7067

7168
private func setupAVLayer() {
69+
guard previewLayer == nil else { return }
7270
let x = view.frame.minX
7371
let y = view.frame.minY
7472
let width = view.frame.width
7573
let height = width / 3 * 4
7674
let cameraFrame = CGRect(x: x, y: y, width: width, height: height)
7775

78-
guard let avLayer = viewModel.startCamera(withinFrame: cameraFrame) else {
76+
guard let avLayer = viewModel.configureCamera(withinFrame: cameraFrame) else {
7977
DispatchQueue.main.async {
8078
self.viewModel.livenessState
8179
.unrecoverableStateEncountered(.missingVideoPermission)
@@ -92,6 +90,8 @@ final class _LivenessViewController: UIViewController {
9290
DispatchQueue.main.async {
9391
self.view.layer.insertSublayer(avLayer, at: 0)
9492
self.view.layoutIfNeeded()
93+
94+
self.viewModel.startSession()
9595
}
9696
}
9797

0 commit comments

Comments
 (0)