Skip to content

Commit 09473a5

Browse files
authored
fix: send the final video event at a delayed time interval (#87)
* fix: send the final video event at a delayed time interval * update dispatching of final video event
1 parent 6230ae6 commit 09473a5

File tree

3 files changed

+8
-28
lines changed

3 files changed

+8
-28
lines changed

Sources/FaceLiveness/AV/VideoChunker.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ final class VideoChunker {
5656
}
5757

5858
guard state == .writing else { return }
59-
let timestamp = CMSampleBufferGetPresentationTimeStamp(buffer).seconds
60-
61-
if startTimeSeconds == nil { startTimeSeconds = timestamp }
62-
guard let startTimeSeconds else {
63-
return
64-
}
6559

6660
if assetWriterInput.isReadyForMoreMediaData {
6761
let timestamp = CMSampleBufferGetPresentationTimeStamp(buffer).seconds
62+
if startTimeSeconds == nil { startTimeSeconds = timestamp }
63+
guard let startTimeSeconds else {
64+
return
65+
}
6866
let presentationTime = CMTime(seconds: timestamp - startTimeSeconds, preferredTimescale: 600)
6967
guard let imageBuffer = buffer.imageBuffer else { return }
7068

Sources/FaceLiveness/Views/Liveness/FaceLivenessDetectionViewModel+VideoSegmentProcessor.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ extension FaceLivenessDetectionViewModel: VideoSegmentProcessor {
1313
sendVideoEvent(data: chunk, videoEventTime: .zero)
1414
if !hasSentFinalVideoEvent,
1515
case .completedDisplayingFreshness = livenessState.state {
16-
sendFinalVideoChunk(data: chunk, videoEventTime: .zero)
16+
DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + 0.9) {
17+
self.sendFinalVideoEvent()
18+
}
1719
}
1820
}
1921
}

Sources/FaceLiveness/Views/Liveness/FaceLivenessDetectionViewModel.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -289,27 +289,7 @@ class FaceLivenessDetectionViewModel: ObservableObject {
289289
}
290290
}
291291

292-
func sendVideoEvent(data: Data, videoEventTime: UInt64, n: UInt8 = 1) {
293-
guard !hasSentFinalVideoEvent else { return }
294-
let eventDate = Date()
295-
let timestamp = eventDate.timestampMilliseconds
296-
297-
let videoEvent = VideoEvent.init(chunk: data, timestamp: timestamp)
298-
299-
do {
300-
try livenessService?.send(
301-
.video(event: videoEvent),
302-
eventDate: { eventDate }
303-
)
304-
} catch {
305-
DispatchQueue.main.async {
306-
self.livenessState.unrecoverableStateEncountered(.unknown)
307-
}
308-
}
309-
}
310-
311-
func sendFinalVideoChunk(data: Data, videoEventTime: UInt64) {
312-
sendVideoEvent(data: data, videoEventTime: videoEventTime)
292+
func sendFinalVideoEvent() {
313293
sendFinalEvent(
314294
targetFaceRect: faceGuideRect,
315295
viewSize: videoSize,

0 commit comments

Comments
 (0)