Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: kickoff release #94

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Sources/FaceLiveness/AV/LivenessCaptureSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import AVFoundation
class LivenessCaptureSession {
let captureDevice: LivenessCaptureDevice
private let captureQueue = DispatchQueue(label: "com.amazonaws.faceliveness.cameracapturequeue")
private let configurationQueue = DispatchQueue(label: "com.amazonaws.faceliveness.sessionconfiguration", qos: .userInitiated)
let outputDelegate: AVCaptureVideoDataOutputSampleBufferDelegate
var captureSession: AVCaptureSession?

Expand Down Expand Up @@ -43,6 +44,7 @@ class LivenessCaptureSession {
else { throw LivenessCaptureSessionError.cameraUnavailable }

let cameraInput = try AVCaptureDeviceInput(device: camera)
let videoOutput = AVCaptureVideoDataOutput()

teardownExistingSession(input: cameraInput)
captureSession = AVCaptureSession()
Expand All @@ -53,13 +55,10 @@ class LivenessCaptureSession {

try setupInput(cameraInput, for: captureSession)
captureSession.sessionPreset = captureDevice.preset

let videoOutput = AVCaptureVideoDataOutput()
try setupOutput(videoOutput, for: captureSession)

try captureDevice.configure()

DispatchQueue.global().async {
configurationQueue.async {
captureSession.startRunning()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public struct FaceLivenessDetectorView: View {
UIScreen.main.brightness = 1.0
}
}
.onDisappear() {
viewModel.stopRecording()
}
.onReceive(viewModel.$livenessState) { output in
switch output.state {
case .completed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ final class _LivenessViewController: UIViewController {
}
}
}

deinit {
self.previewLayer.removeFromSuperlayer()
(self.previewLayer as? AVCaptureVideoPreviewLayer)?.session = nil
self.previewLayer = nil
}

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -110,6 +116,7 @@ extension _LivenessViewController: FaceLivenessViewControllerPresenter {
imageView.frame = self.previewLayer.frame
self.view.addSubview(imageView)
self.previewLayer.removeFromSuperlayer()
(self.previewLayer as? AVCaptureVideoPreviewLayer)?.session = nil
self.viewModel.stopRecording()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ class CreateLivenessSessionUITests: XCTestCase {
Thread.sleep(forTimeInterval: 2)
XCTAssert(app!.buttons[UIConstants.BeginCheck.primaryButton].exists)
XCTAssertFalse(app!.buttons[UIConstants.primaryButton].exists)
let scrollViewsQuery = app!.scrollViews
let elementsQuery = scrollViewsQuery.otherElements
XCTAssertEqual(elementsQuery.staticTexts.element(boundBy: 1).label, UIConstants.BeginCheck.description)
XCTAssert(elementsQuery.buttons[UIConstants.BeginCheck.warning].exists)
XCTAssert(elementsQuery.staticTexts[UIConstants.BeginCheck.instruction].exists)
XCTAssert(app!.staticTexts[UIConstants.BeginCheck.warningTitle].exists)
XCTAssert(app!.staticTexts[UIConstants.BeginCheck.warningDescription].exists)
XCTAssert(app!.staticTexts[UIConstants.BeginCheck.instruction].exists)
}

func testStartLivenessIntegration() throws {
Expand All @@ -40,14 +38,11 @@ class CreateLivenessSessionUITests: XCTestCase {
app?.buttons[UIConstants.primaryButton].tap()
Thread.sleep(forTimeInterval: 2)
XCTAssert(app!.buttons[UIConstants.BeginCheck.primaryButton].exists)
XCTAssertFalse(app!.buttons[UIConstants.primaryButton].exists)
app!.buttons[UIConstants.BeginCheck.primaryButton].tap()
Thread.sleep(forTimeInterval: 2)
XCTAssert(app!.staticTexts[UIConstants.LivenessCheck.countdownInstruction].exists)
XCTAssert(app!.buttons[UIConstants.LivenessCheck.closeButton].exists)
Thread.sleep(forTimeInterval: 3)
XCTAssert(app!.staticTexts[UIConstants.LivenessCheck.moveInstruction].exists)
Thread.sleep(forTimeInterval: 3)
Thread.sleep(forTimeInterval: 4)
XCTAssert(app!.staticTexts[UIConstants.LivenessCheck.holdInstruction].exists)
Thread.sleep(forTimeInterval: 8)
XCTAssert(app!.buttons[UIConstants.LivenessResult.primaryButton].exists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ struct UIConstants {
static let primaryButton = "Create Liveness Session"

struct BeginCheck {
static let primaryButton = "Begin Check"
static let description = "You will go through a face verification process to prove that you are a real person. Your screen's brightness will temporarily be set to 100% for highest accuracy."
static let warning = "Photosensitivity Warning, This check displays colored lights. Use caution if you are photosensitive."
static let instruction = "Follow the instructions to complete the check:"
static let primaryButton = "Start video check"
static let warningTitle = "Photosensitivity Warning"
static let warningDescription = "This check flashes different colors. Use caution if you are photosensitive."
static let instruction = "Center your face"
}

struct LivenessCheck {
static let countdownInstruction = "Hold face position during countdown."
static let moveInstruction = "Move closer"
static let holdInstruction = "Hold still"
static let closeButton = "Close"
Expand Down
Loading