Skip to content

Commit

Permalink
fix: data race causing multiple initial events and crash with low net… (
Browse files Browse the repository at this point in the history
#40)

* fix: data race causing multiple initial events and crash with low network throughput

* invoke oncomplete
  • Loading branch information
atierian authored and phantumcode committed Jul 13, 2023
1 parent 151ceb0 commit abe085c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions Sources/FaceLiveness/AV/VideoChunker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class VideoChunker {
}

func start() {
guard state == .pending else { return }
state = .writing
assetWriter.startWriting()
assetWriter.startSession(atSourceTime: .zero)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ extension FaceLivenessDetectionViewModel: FaceDetectionResultHandler {
}
}
case .recording(ovalDisplayed: false):
drawOval()
sendInitialFaceDetectedEvent(
initialFace: normalizedFace.boundingBox,
videoStartTime: Date().timestampMilliseconds
)
drawOval(onComplete: {
self.sendInitialFaceDetectedEvent(
initialFace: normalizedFace.boundingBox,
videoStartTime: Date().timestampMilliseconds
)
})
case .recording(ovalDisplayed: true):
guard let sessionConfiguration = sessionConfiguration else { return }
let instruction = faceInOvalMatching.faceMatchState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ class FaceLivenessDetectionViewModel: ObservableObject {
}
}


func drawOval() {
func drawOval(onComplete: @escaping () -> Void) {
guard livenessState.state == .recording(ovalDisplayed: false),
let ovalParameters = sessionConfiguration?.ovalMatchChallenge.oval
else { return }
Expand All @@ -158,6 +157,7 @@ class FaceLivenessDetectionViewModel: ObservableObject {
livenessViewControllerDelegate?.drawOvalInCanvas(normalizedOvalRect)
DispatchQueue.main.async {
self.livenessState.ovalDisplayed()
onComplete()
}
ovalRect = normalizedOvalRect
}
Expand Down Expand Up @@ -212,6 +212,7 @@ class FaceLivenessDetectionViewModel: ObservableObject {
initialFace: CGRect,
videoStartTime: UInt64
) {
guard initialClientEvent == nil else { return }
videoChunker.start()

let initialFace = FaceDetection(
Expand Down

0 comments on commit abe085c

Please sign in to comment.