Skip to content

Commit

Permalink
chore: kickoff release
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode authored Apr 11, 2024
2 parents e24762b + c318f91 commit 325a062
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
18 changes: 10 additions & 8 deletions Sources/FaceLiveness/AV/LivenessCaptureSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class LivenessCaptureSession {
self.outputDelegate = outputDelegate
}

func startSession(frame: CGRect) throws -> CALayer {
try startSession()
func configureCamera(frame: CGRect) throws -> CALayer {
try configureCamera()

guard let captureSession = captureSession else {
throw LivenessCaptureSessionError.captureSessionUnavailable
Expand All @@ -39,7 +39,7 @@ class LivenessCaptureSession {
return previewLayer
}

func startSession() throws {
func configureCamera() throws {
guard let camera = captureDevice.avCaptureDevice
else { throw LivenessCaptureSessionError.cameraUnavailable }

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

configurationQueue.async {
captureSession.startRunning()
}

videoOutput.setSampleBufferDelegate(
outputDelegate,
queue: captureQueue
)
}

func stopRunning() {
func startSession() {
guard let session = captureSession else { return }
configurationQueue.async {
session.startRunning()
}
}

func stopRunning() {
guard let session = captureSession else { return }
defer {
captureSession = nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class CameraPreviewViewModel: NSObject, ObservableObject {
)

do {
try previewCaptureSession?.startSession()
try previewCaptureSession?.configureCamera()
previewCaptureSession?.startSession()
} catch {
Amplify.Logging.default.error("Error starting preview capture session with error: \(error)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,17 @@ class FaceLivenessDetectionViewModel: ObservableObject {
}
}

func startSession() {
captureSession.startSession()
}

func stopRecording() {
captureSession.stopRunning()
}

func startCamera(withinFrame frame: CGRect) -> CALayer? {
func configureCamera(withinFrame frame: CGRect) -> CALayer? {
do {
let avLayer = try captureSession.startSession(frame: frame)
let avLayer = try captureSession.configureCamera(frame: frame)
DispatchQueue.main.async {
self.livenessState.checkIsFacePrepared()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ final class _LivenessViewController: UIViewController {
super.viewDidLoad()
view.backgroundColor = .black
layoutSubviews()
}

override func viewDidAppear(_ animated: Bool) {
setupAVLayer()
}

Expand All @@ -69,13 +66,14 @@ final class _LivenessViewController: UIViewController {
}

private func setupAVLayer() {
guard previewLayer == nil else { return }
let x = view.frame.minX
let y = view.frame.minY
let width = view.frame.width
let height = width / 3 * 4
let cameraFrame = CGRect(x: x, y: y, width: width, height: height)

guard let avLayer = viewModel.startCamera(withinFrame: cameraFrame) else {
guard let avLayer = viewModel.configureCamera(withinFrame: cameraFrame) else {
DispatchQueue.main.async {
self.viewModel.livenessState
.unrecoverableStateEncountered(.missingVideoPermission)
Expand All @@ -92,6 +90,8 @@ final class _LivenessViewController: UIViewController {
DispatchQueue.main.async {
self.view.layer.insertSublayer(avLayer, at: 0)
self.view.layoutIfNeeded()

self.viewModel.startSession()
}
}

Expand Down

0 comments on commit 325a062

Please sign in to comment.